Improve package descriptions.
[free-sw/xcb/libxcb] / tests / check_public.c
1 #include <check.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include "check_suites.h"
5 #include "xcb.h"
6
7 /* XCBParseDisplay tests {{{ */
8
9 static void parse_display_pass(const char *name, const char *host, const int display, const int screen)
10 {
11         int success;
12         char *got_host;
13         int got_display, got_screen;
14
15         got_host = (char *) -1;
16         got_display = got_screen = -42;
17         mark_point();
18         success = XCBParseDisplay(name, &got_host, &got_display, &got_screen);
19         fail_unless(success, "unexpected parse failure for '%s'", name);
20         fail_unless(strcmp(host, got_host) == 0, "parse produced unexpected hostname '%s' for '%s': expected '%s'", got_host, name, host);
21         fail_unless(display == got_display, "parse produced unexpected display '%d' for '%s': expected '%d'", got_display, name, display);
22         fail_unless(screen == got_screen, "parse produced unexpected screen '%d' for '%s': expected '%d'", got_screen, name, screen);
23
24         got_host = (char *) -1;
25         got_display = got_screen = -42;
26         mark_point();
27         success = XCBParseDisplay(name, &got_host, &got_display, 0);
28         fail_unless(success, "unexpected screenless parse failure for '%s'", name);
29         fail_unless(strcmp(host, got_host) == 0, "screenless parse produced unexpected hostname '%s' for '%s': expected '%s'", got_host, name, host);
30         fail_unless(display == got_display, "screenless parse produced unexpected display '%d' for '%s': expected '%d'", got_display, name, display);
31 }
32
33 static void parse_display_fail(const char *name)
34 {
35         int success;
36         char *got_host;
37         int got_display, got_screen;
38
39         got_host = (char *) -1;
40         got_display = got_screen = -42;
41         mark_point();
42         success = XCBParseDisplay(name, &got_host, &got_display, &got_screen);
43         fail_unless(!success, "unexpected parse success for '%s'", name);
44         fail_unless(got_host == (char *) -1, "host changed on failure for '%s': got %p", got_host);
45         fail_unless(got_display == -42, "display changed on failure for '%s': got %d", got_display);
46         fail_unless(got_screen == -42, "screen changed on failure for '%s': got %d", got_screen);
47
48         got_host = (char *) -1;
49         got_display = got_screen = -42;
50         mark_point();
51         success = XCBParseDisplay(name, &got_host, &got_display, 0);
52         fail_unless(!success, "unexpected screenless parse success for '%s'", name);
53         fail_unless(got_host == (char *) -1, "host changed on failure for '%s': got %p", got_host);
54         fail_unless(got_display == -42, "display changed on failure for '%s': got %d", got_display);
55 }
56
57 START_TEST(parse_display_unix)
58 {
59         parse_display_pass(":0", "", 0, 0);
60         parse_display_pass(":1", "", 1, 0);
61         parse_display_pass(":0.1", "", 0, 1);
62 }
63 END_TEST
64
65 START_TEST(parse_display_ip)
66 {
67         parse_display_pass("x.org:0", "x.org", 0, 0);
68         parse_display_pass("expo:0", "expo", 0, 0);
69         parse_display_pass("bigmachine:1", "bigmachine", 1, 0);
70         parse_display_pass("hydra:0.1", "hydra", 0, 1);
71 }
72 END_TEST
73
74 START_TEST(parse_display_ipv4)
75 {
76         parse_display_pass("198.112.45.11:0", "198.112.45.11", 0, 0);
77         parse_display_pass("198.112.45.11:0.1", "198.112.45.11", 0, 1);
78 }
79 END_TEST
80
81 START_TEST(parse_display_ipv6)
82 {
83         parse_display_pass("::1:0", "::1", 0, 0);
84         parse_display_pass("::1:0.1", "::1", 0, 1);
85         parse_display_pass("2002:83fc:d052::1:0", "2002:83fc:d052::1", 0, 0);
86         parse_display_pass("2002:83fc:d052::1:0.1", "2002:83fc:d052::1", 0, 1);
87 }
88 END_TEST
89
90 START_TEST(parse_display_decnet)
91 {
92         parse_display_pass("myws::0", "myws:", 0, 0);
93         parse_display_pass("big::1", "big:", 1, 0);
94         parse_display_pass("hydra::0.1", "hydra:", 0, 1);
95 }
96 END_TEST
97
98 START_TEST(parse_display_negative)
99 {
100         parse_display_fail(0);
101         parse_display_fail("");
102         parse_display_fail(":");
103         parse_display_fail("::");
104         parse_display_fail(":.");
105         parse_display_fail(":a");
106         parse_display_fail(":a.");
107         parse_display_fail(":0.");
108         parse_display_fail(":0.a");
109         parse_display_fail(":0.0.");
110
111         parse_display_fail("localhost");
112         parse_display_fail("localhost:");
113 }
114 END_TEST
115
116 /* }}} */
117
118 Suite *public_suite(void)
119 {
120         Suite *s = suite_create("Public API");
121         putenv("DISPLAY");
122         suite_add_test(s, parse_display_unix, "XCBParseDisplay unix");
123         suite_add_test(s, parse_display_ip, "XCBParseDisplay ip");
124         suite_add_test(s, parse_display_ipv4, "XCBParseDisplay ipv4");
125         suite_add_test(s, parse_display_ipv6, "XCBParseDisplay ipv6");
126         suite_add_test(s, parse_display_decnet, "XCBParseDisplay decnet");
127         suite_add_test(s, parse_display_negative, "XCBParseDisplay negative");
128         return s;
129 }