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("::1:0", "::1", 0, 0);
123 parse_display_pass("::1:0.1", "::1", 0, 1);
124 parse_display_pass("2002:83fc:d052::1:0", "2002:83fc:d052::1", 0, 0);
125 parse_display_pass("2002:83fc:d052::1:0.1", "2002:83fc:d052::1", 0, 1);
129 START_TEST(parse_display_decnet)
131 parse_display_pass("myws::0", "myws:", 0, 0);
132 parse_display_pass("big::1", "big:", 1, 0);
133 parse_display_pass("hydra::0.1", "hydra:", 0, 1);
137 START_TEST(parse_display_negative)
139 parse_display_fail(0);
140 parse_display_fail("");
141 parse_display_fail(":");
142 parse_display_fail("::");
143 parse_display_fail(":.");
144 parse_display_fail(":a");
145 parse_display_fail(":a.");
146 parse_display_fail(":0.");
147 parse_display_fail(":0.a");
148 parse_display_fail(":0.0.");
150 parse_display_fail("localhost");
151 parse_display_fail("localhost:");
157 Suite *public_suite(void)
159 Suite *s = suite_create("Public API");
161 suite_add_test(s, parse_display_unix, "xcb_parse_display unix");
162 suite_add_test(s, parse_display_ip, "xcb_parse_display ip");
163 suite_add_test(s, parse_display_ipv4, "xcb_parse_display ipv4");
164 suite_add_test(s, parse_display_ipv6, "xcb_parse_display ipv6");
165 suite_add_test(s, parse_display_decnet, "xcb_parse_display decnet");
166 suite_add_test(s, parse_display_negative, "xcb_parse_display negative");