diff options
Diffstat (limited to 'testsuite/gsk/rounded-rect.c')
-rw-r--r-- | testsuite/gsk/rounded-rect.c | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/testsuite/gsk/rounded-rect.c b/testsuite/gsk/rounded-rect.c index 5a72928257..552bed49d9 100644 --- a/testsuite/gsk/rounded-rect.c +++ b/testsuite/gsk/rounded-rect.c @@ -241,6 +241,145 @@ test_intersect_with_rect (void) } } +static void +test_intersect (void) +{ + struct { + GskRoundedRect a; + GskRoundedRect b; + GskRoundedRectIntersection result; + GskRoundedRect expected; + } test[] = { + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 0), + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(50, 50, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT_UNIFORM(50, 50, 50, 50, 20, 0, 20, 0), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(50, 0, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(50, 0, 50, 100, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(0, 50, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(0, 50, 100, 50, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(-50, -50, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT_UNIFORM(0, 0, 50, 50, 20, 0, 20, 0), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(0, -50, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(0, 0, 100, 50, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(-50, 0, 100, 100, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(0, 0, 50, 100, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(10, 10, 80, 80, 20), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(10, 10, 80, 80, 20), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 20), + ROUNDED_RECT_INIT(10, 10, 80, 80, 10), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT(10, 10, 80, 80, 10), + }, + { + ROUNDED_RECT_INIT(0, 0, 100, 100, 40), + ROUNDED_RECT_INIT(10, 10, 80, 80, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, + }, + { + ROUNDED_RECT_INIT(10, 10, 100, 100, 40), + ROUNDED_RECT_INIT(30, 0, 40, 40, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, + }, + { + ROUNDED_RECT_INIT(10, 10, 100, 100, 40), + ROUNDED_RECT_INIT(0, 0, 100, 20, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, + }, + { + ROUNDED_RECT_INIT_UNIFORM(647, 18, 133, 35, 5, 0, 0, 5), + ROUNDED_RECT_INIT_UNIFORM(14, 12, 1666, 889, 8, 8, 0, 0), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT_UNIFORM(647, 18, 133, 35, 5, 0, 0, 5), + }, + { + ROUNDED_RECT_INIT_UNIFORM(0, 0, 100, 100, 100, 0, 0, 0), + ROUNDED_RECT_INIT_UNIFORM(0, 0, 100, 100, 0, 0, 100, 0), + GSK_INTERSECTION_NONEMPTY, + ROUNDED_RECT_INIT_UNIFORM(0, 0, 100, 100, 100, 0, 100, 0), + }, + { + ROUNDED_RECT_INIT_UNIFORM(0, 0, 100, 100, 100, 0, 0, 0), + ROUNDED_RECT_INIT_UNIFORM(-20, -20, 100, 100, 0, 0, 100, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, + }, + { + ROUNDED_RECT_INIT_UNIFORM(0, 0, 50, 50, 0, 0, 50, 0), + ROUNDED_RECT_INIT_UNIFORM(0, 0, 20, 20, 20, 0, 0, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, /* FIXME: should be empty */ + }, + { + ROUNDED_RECT_INIT_UNIFORM(0, 0, 50, 50, 0, 0, 50, 0), + ROUNDED_RECT_INIT_UNIFORM(0, 0, 21, 21, 21, 0, 0, 0), + GSK_INTERSECTION_NOT_REPRESENTABLE, + }, + }; + gsize i; + + for (i = 0; i < G_N_ELEMENTS (test); i++) + { + GskRoundedRect out; + GskRoundedRectIntersection res; + + if (g_test_verbose ()) + g_test_message ("intersection test %zu", i); + + memset (&out, 0, sizeof (GskRoundedRect)); + + res = gsk_rounded_rect_intersection (&test[i].a, &test[i].b, &out); + g_assert_cmpint (res, ==, test[i].result); + if (res == GSK_INTERSECTION_NONEMPTY) + { + if (!gsk_rounded_rect_equal (&out, &test[i].expected)) + { + char *a = gsk_rounded_rect_to_string (&test[i].a); + char *b = gsk_rounded_rect_to_string (&test[i].b); + char *expected = gsk_rounded_rect_to_string (&test[i].expected); + char *result = gsk_rounded_rect_to_string (&out); + g_test_message (" A = %s\n" + " B = %s\n" + "expected %s\n" + " got %s\n", + a, b, expected, result); + } + g_assert_true (gsk_rounded_rect_equal (&out, &test[i].expected)); + } + } +} + int main (int argc, char *argv[]) @@ -253,6 +392,7 @@ main (int argc, g_test_add_func ("/rounded-rect/is-circular", test_is_circular); g_test_add_func ("/rounded-rect/to-float", test_to_float); g_test_add_func ("/rounded-rect/intersect-with-rect", test_intersect_with_rect); + g_test_add_func ("/rounded-rect/intersect", test_intersect); return g_test_run (); } |