blob: 00026e614eddce7f978086aac8fc4a30ebbeb129 [file] [log] [blame]
Pierre Ossmand175da72016-07-11 10:05:05 +02001/* Copyright 2016 Pierre Ossman <ossman@cendio.se> for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <stdio.h>
20
21#include <rfb/Hostname.h>
22
23static void doTest(const char* hostAndPort,
24 const char* expectedHost, int expectedPort)
25{
26 char* host;
27 int port;
28
29 printf("\"%s\": ", hostAndPort);
30
31 rfb::getHostAndPort(hostAndPort, &host, &port);
32
33 if (strcmp(host, expectedHost) != 0)
34 printf("FAILED (\"%s\" != \"%s\")", host, expectedHost);
35 else if (port != expectedPort)
36 printf("FAILED (%d != %d)", port, expectedPort);
37 else
38 printf("OK");
39 printf("\n");
40 fflush(stdout);
41
42 rfb::strFree(host);
43}
44
45int main(int argc, char** argv)
46{
47 doTest(":5", "localhost", 5905);
48
49 doTest("1.2.3.4", "1.2.3.4", 5900);
50
51 doTest("1.2.3.4:5", "1.2.3.4", 5905);
52 doTest("1.2.3.4:99", "1.2.3.4", 5999);
53 doTest("1.2.3.4:100", "1.2.3.4", 100);
54 doTest("1.2.3.4:5901", "1.2.3.4", 5901);
55
56 doTest("1.2.3.4::5", "1.2.3.4", 5);
57 doTest("1.2.3.4::99", "1.2.3.4", 99);
58 doTest("1.2.3.4::5901", "1.2.3.4", 5901);
59
60 doTest("[1.2.3.4]", "1.2.3.4", 5900);
61 doTest("[1.2.3.4]:5", "1.2.3.4", 5905);
62 doTest("[1.2.3.4]:100", "1.2.3.4", 100);
63 doTest("[1.2.3.4]::5", "1.2.3.4", 5);
64 doTest("[1.2.3.4]::100", "1.2.3.4", 100);
65
66 // Ambigiuous. For now we'll keep the old behaviour...
67 doTest("::1", "localhost", 1);
68
69 doTest("2001:1234::20:1", "2001:1234::20:1", 5900);
70
71 doTest("[::1]", "::1", 5900);
72 doTest("[2001:1234::20:1]", "2001:1234::20:1", 5900);
73
74 doTest("[2001:1234::20:1]:5", "2001:1234::20:1", 5905);
75 doTest("[2001:1234::20:1]:99", "2001:1234::20:1", 5999);
76 doTest("[2001:1234::20:1]:100", "2001:1234::20:1", 100);
77 doTest("[2001:1234::20:1]:5901", "2001:1234::20:1", 5901);
78
79 return 0;
80}