[Xcb-commit] tests

Ian Osgood iano at kemper.freedesktop.org
Sat Nov 25 11:00:34 PST 2006


 tests/check_public.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+)

New commits:
diff-tree e74cdcd02e6814222a76c0a237efca16c423bb26 (from 05d23a724d4dde42b11d6e9dec9ccaf5a516e287)
Author: Ian Osgood <iano at quirkster.com>
Date:   Sat Nov 25 11:00:14 2006 -0800

    Bug #9119: test xcb_popcount

diff --git a/tests/check_public.c b/tests/check_public.c
index a28fb49..e222221 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 {{{ */
 
@@ -179,6 +180,28 @@ 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");
@@ -189,5 +212,6 @@ Suite *public_suite(void)
 	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;
 }


More information about the xcb-commit mailing list