4 #include "check_suites.h"
7 /* xcb_parse_display tests {{{ */
9 typedef enum test_type_t {
10 TEST_ARGUMENT, TEST_ENVIRONMENT, TEST_END
12 static const char *const test_string[] = { "", "via $DISPLAY " };
14 static void parse_display_pass(const char *name, const char *host, const int display, const int screen)
18 int got_display, got_screen;
19 const char *argument = 0;
20 test_type_t test_type;
22 for(test_type = TEST_ARGUMENT; test_type != TEST_END; test_type++)
24 if(test_type == TEST_ARGUMENT)
29 else if(test_type == TEST_ENVIRONMENT)
32 setenv("DISPLAY", name, 1);
35 got_host = (char *) -1;
36 got_display = got_screen = -42;
38 success = xcb_parse_display(argument, &got_host, &got_display, &got_screen);
39 fail_unless(success, "unexpected parse failure %sfor '%s'", test_string[test_type], name);
40 fail_unless(strcmp(host, got_host) == 0, "parse %sproduced unexpected hostname '%s' for '%s': expected '%s'", test_string[test_type], got_host, name, host);
41 fail_unless(display == got_display, "parse %sproduced unexpected display '%d' for '%s': expected '%d'", test_string[test_type], got_display, name, display);
42 fail_unless(screen == got_screen, "parse %sproduced unexpected screen '%d' for '%s': expected '%d'", test_string[test_type], got_screen, name, screen);
44 got_host = (char *) -1;
45 got_display = got_screen = -42;
47 success = xcb_parse_display(argument, &got_host, &got_display, 0);
48 fail_unless(success, "unexpected screenless parse failure %sfor '%s'", test_string[test_type], name);
49 fail_unless(strcmp(host, got_host) == 0, "screenless parse %sproduced unexpected hostname '%s' for '%s': expected '%s'", test_string[test_type], got_host, name, host);
50 fail_unless(display == got_display, "screenless parse %sproduced unexpected display '%d' for '%s': expected '%d'", test_string[test_type], got_display, name, display);
55 static void parse_display_fail(const char *name)
59 int got_display, got_screen;
60 const char *argument = 0;
61 test_type_t test_type;
63 for(test_type = TEST_ARGUMENT; test_type != TEST_END; test_type++)
65 if(test_type == TEST_ARGUMENT)
70 else if(test_type == TEST_ENVIRONMENT)
73 setenv("DISPLAY", name, 1);
76 got_host = (char *) -1;
77 got_display = got_screen = -42;
79 success = xcb_parse_display(argument, &got_host, &got_display, &got_screen);
80 fail_unless(!success, "unexpected parse success %sfor '%s'", test_string[test_type], name);
81 fail_unless(got_host == (char *) -1, "host changed on parse failure %sfor '%s': got %p", test_string[test_type], name, got_host);
82 fail_unless(got_display == -42, "display changed on parse failure %sfor '%s': got %d", test_string[test_type], name, got_display);
83 fail_unless(got_screen == -42, "screen changed on parse failure %sfor '%s': got %d", test_string[test_type], name, got_screen);
85 got_host = (char *) -1;
86 got_display = got_screen = -42;
88 success = xcb_parse_display(argument, &got_host, &got_display, 0);
89 fail_unless(!success, "unexpected screenless parse success %sfor '%s'", test_string[test_type], name);
90 fail_unless(got_host == (char *) -1, "host changed on parse failure %sfor '%s': got %p", test_string[test_type], name, got_host);
91 fail_unless(got_display == -42, "display changed on parse failure %sfor '%s': got %d", test_string[test_type], name, got_display);
96 START_TEST(parse_display_unix)
98 parse_display_pass(":0", "", 0, 0);
99 parse_display_pass(":1", "", 1, 0);
100 parse_display_pass(":0.1", "", 0, 1);
104 START_TEST(parse_display_ip)
106 parse_display_pass("x.org:0", "x.org", 0, 0);
107 parse_display_pass("expo:0", "expo", 0, 0);
108 parse_display_pass("bigmachine:1", "bigmachine", 1, 0);
109 parse_display_pass("hydra:0.1", "hydra", 0, 1);
113 START_TEST(parse_display_ipv4)
115 parse_display_pass("198.112.45.11:0", "198.112.45.11", 0, 0);
116 parse_display_pass("198.112.45.11:0.1", "198.112.45.11", 0, 1);
120 START_TEST(parse_display_ipv6)
122 parse_display_pass(":::0", "::", 0, 0);
123 parse_display_pass("1:::0", "1::", 0, 0);
124 parse_display_pass("::1:0", "::1", 0, 0);
125 parse_display_pass("::1:0.1", "::1", 0, 1);
126 parse_display_pass("::127.0.0.1:0", "::127.0.0.1", 0, 0);
127 parse_display_pass("::ffff:127.0.0.1:0", "::ffff:127.0.0.1", 0, 0);
128 parse_display_pass("2002:83fc:d052::1:0", "2002:83fc:d052::1", 0, 0);
129 parse_display_pass("2002:83fc:d052::1:0.1", "2002:83fc:d052::1", 0, 1);
130 parse_display_pass("[::]:0", "[::]", 0, 0);
131 parse_display_pass("[1::]:0", "[1::]", 0, 0);
132 parse_display_pass("[::1]:0", "[::1]", 0, 0);
133 parse_display_pass("[::1]:0.1", "[::1]", 0, 1);
134 parse_display_pass("[::127.0.0.1]:0", "[::127.0.0.1]", 0, 0);
135 parse_display_pass("[::ffff:127.0.0.1]:0", "[::ffff:127.0.0.1]", 0, 0);
136 parse_display_pass("[2002:83fc:d052::1]:0", "[2002:83fc:d052::1]", 0, 0);
137 parse_display_pass("[2002:83fc:d052::1]:0.1", "[2002:83fc:d052::1]", 0, 1);
141 START_TEST(parse_display_decnet)
143 parse_display_pass("myws::0", "myws:", 0, 0);
144 parse_display_pass("big::1", "big:", 1, 0);
145 parse_display_pass("hydra::0.1", "hydra:", 0, 1);
149 START_TEST(parse_display_negative)
151 parse_display_fail(0);
152 parse_display_fail("");
153 parse_display_fail(":");
154 parse_display_fail("::");
155 parse_display_fail(":::");
156 parse_display_fail(":.");
157 parse_display_fail(":a");
158 parse_display_fail(":a.");
159 parse_display_fail(":0.");
160 parse_display_fail(":.a");
161 parse_display_fail(":.0");
162 parse_display_fail(":0.a");
163 parse_display_fail(":0.0.");
165 parse_display_fail("127.0.0.1");
166 parse_display_fail("127.0.0.1:");
167 parse_display_fail("127.0.0.1::");
168 parse_display_fail("::127.0.0.1");
169 parse_display_fail("::127.0.0.1:");
170 parse_display_fail("::127.0.0.1::");
171 parse_display_fail("::ffff:127.0.0.1");
172 parse_display_fail("::ffff:127.0.0.1:");
173 parse_display_fail("::ffff:127.0.0.1::");
174 parse_display_fail("localhost");
175 parse_display_fail("localhost:");
176 parse_display_fail("localhost::");
182 Suite *public_suite(void)
184 Suite *s = suite_create("Public API");
186 suite_add_test(s, parse_display_unix, "xcb_parse_display unix");
187 suite_add_test(s, parse_display_ip, "xcb_parse_display ip");
188 suite_add_test(s, parse_display_ipv4, "xcb_parse_display ipv4");
189 suite_add_test(s, parse_display_ipv6, "xcb_parse_display ipv6");
190 suite_add_test(s, parse_display_decnet, "xcb_parse_display decnet");
191 suite_add_test(s, parse_display_negative, "xcb_parse_display negative");