diff options
author | Benjamin Otte <otte@redhat.com> | 2015-09-07 14:31:26 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2015-09-07 14:32:09 +0200 |
commit | c8c666c87c827323a128264ecf1943f8107713f9 (patch) | |
tree | a080485793252b78e45994bad21e85863bda4d7c /testsuite | |
parent | f5fe1e3a06b6ea9160f9b05aaadd228a813bafb9 (diff) | |
download | gtk+-c8c666c87c827323a128264ecf1943f8107713f9.tar.gz |
bitmask: Fix broken invert_range() implementation
The speed-up in 7da1f8a1ce145f48b6299fd8be86a64389ff0b0d was wrong in
certain conditions, even though it didn't trigger the existing
testsuite.
New testcase /bitmask/invert_range_hardcoded included.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/gtk/bitmask.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/testsuite/gtk/bitmask.c b/testsuite/gtk/bitmask.c index 9385ecff93..d6c1267eee 100644 --- a/testsuite/gtk/bitmask.c +++ b/testsuite/gtk/bitmask.c @@ -334,6 +334,49 @@ test_subtract_hardcoded (void) }G_STMT_END static void +test_invert_range_hardcoded (void) +{ + guint t, l, r, i; + gsize r_len, l_len, ref_len; + char *ref_str; + GtkBitmask *bitmask, *ref; + + for (t = 0; t < G_N_ELEMENTS (tests); t++) + { + for (l = 0; l < G_N_ELEMENTS (tests); l++) + { + l_len = strlen (tests[l]); + + for (r = 0; r < G_N_ELEMENTS (tests); r++) + { + r_len = strlen (tests[r]); + if (r_len < l_len) + continue; + + ref_len = MAX (r_len, strlen (tests[t])); + ref_str = g_strdup_printf ("%*s", (int) ref_len, tests[t]); + for (i = 0; i < ref_len && ref_str[i] == ' '; i++) + ref_str[i] = '0'; + for (i = l_len - 1; i < r_len; i++) + { + ref_str[ref_len-i-1] = ref_str[ref_len-i-1] == '0' ? '1' : '0'; + } + ref = gtk_bitmask_new_parse (ref_str); + g_free (ref_str); + + bitmask = gtk_bitmask_new_parse (tests[t]); + bitmask = _gtk_bitmask_invert_range (bitmask, l_len - 1, r_len); + + assert_cmpmasks (bitmask, ref); + + _gtk_bitmask_free (bitmask); + _gtk_bitmask_free (ref); + } + } + } +} + +static void test_invert_range (void) { GtkBitmask *left, *right, *intersection, *expected; @@ -424,6 +467,7 @@ main (int argc, char *argv[]) g_test_add_func ("/bitmask/intersect_hardcoded", test_intersect_hardcoded); g_test_add_func ("/bitmask/subtract_hardcoded", test_subtract_hardcoded); g_test_add_func ("/bitmask/invert_range", test_invert_range); + g_test_add_func ("/bitmask/invert_range_hardcoded", test_invert_range_hardcoded); result = g_test_run (); |