diff options
Diffstat (limited to 'tests/check_public.c')
-rw-r--r-- | tests/check_public.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/tests/check_public.c b/tests/check_public.c index a28fb49..2094bfe 100644 --- a/tests/check_public.c +++ b/tests/check_public.c @@ -3,6 +3,7 @@ #include <stdlib.h> #include "check_suites.h" #include "xcb.h" +#include "xcbext.h" /* xcb_parse_display tests {{{ */ @@ -24,7 +25,7 @@ static void parse_display_pass(const char *name, const char *host, const int dis if(test_type == TEST_ARGUMENT) { argument = name; - putenv("DISPLAY"); + putenv("DISPLAY="); } else if(test_type == TEST_ENVIRONMENT) { @@ -49,7 +50,7 @@ static void parse_display_pass(const char *name, const char *host, const int dis 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); fail_unless(display == got_display, "screenless parse %sproduced unexpected display '%d' for '%s': expected '%d'", test_string[test_type], got_display, name, display); } - putenv("DISPLAY"); + putenv("DISPLAY="); } static void parse_display_fail(const char *name) @@ -65,10 +66,11 @@ static void parse_display_fail(const char *name) if(test_type == TEST_ARGUMENT) { argument = name; - putenv("DISPLAY"); + putenv("DISPLAY="); } else if(test_type == TEST_ENVIRONMENT) { + if (!name) break; argument = 0; setenv("DISPLAY", name, 1); } @@ -90,7 +92,7 @@ static void parse_display_fail(const char *name) fail_unless(got_host == (char *) -1, "host changed on parse failure %sfor '%s': got %p", test_string[test_type], name, got_host); fail_unless(got_display == -42, "display changed on parse failure %sfor '%s': got %d", test_string[test_type], name, got_display); } - putenv("DISPLAY"); + putenv("DISPLAY="); } START_TEST(parse_display_unix) @@ -179,15 +181,38 @@ END_TEST /* }}} */ +static void popcount_eq(uint32_t bits, int count) +{ + fail_unless(xcb_popcount(bits) == count, "unexpected popcount(%08x) != %d", bits, count); +} + +START_TEST(popcount) +{ + uint32_t mask; + int count; + + for (mask = 0xffffffff, count = 32; count >= 0; mask >>= 1, --count) { + popcount_eq(mask, count); + } + for (mask = 0x80000000; mask; mask >>= 1) { + popcount_eq(mask, 1); + } + for (mask = 0x80000000; mask > 1; mask >>= 1) { + popcount_eq(mask | 1, 2); + } +} +END_TEST + Suite *public_suite(void) { Suite *s = suite_create("Public API"); - putenv("DISPLAY"); + putenv("DISPLAY="); suite_add_test(s, parse_display_unix, "xcb_parse_display unix"); suite_add_test(s, parse_display_ip, "xcb_parse_display ip"); suite_add_test(s, parse_display_ipv4, "xcb_parse_display ipv4"); suite_add_test(s, parse_display_ipv6, "xcb_parse_display ipv6"); suite_add_test(s, parse_display_decnet, "xcb_parse_display decnet"); suite_add_test(s, parse_display_negative, "xcb_parse_display negative"); + suite_add_test(s, popcount, "xcb_popcount"); return s; } |