Debian Codegraph @

testsuite/gdk/rectangle.c

raw
1 #include <gdk/gdk.h>
2
3 static void
4 test_rectangle_equal (void)
5 {
6 GdkRectangle a = { 0, 0, 1, 1 };
7 GdkRectangle b = { 1, 1, 2, 2 };
8 GdkRectangle c = { 0, 0, 2, 2 };
9 GdkRectangle d = { 0, 0, 1, 1 };
10 GdkRectangle e = { 0, 0, 0, 0 };
11 GdkRectangle f = { 1, 1, 0, 0 };
12
13 g_assert_true (!gdk_rectangle_equal (&a, &b));
14 g_assert_true (!gdk_rectangle_equal (&a, &c));
15 g_assert_true (!gdk_rectangle_equal (&b, &c));
16 g_assert_true ( gdk_rectangle_equal (&a, &d));
17 g_assert_true (!gdk_rectangle_equal (&e, &f));
18 }
19
20 static void
21 test_rectangle_intersect (void)
22 {
23 GdkRectangle a = { 0, 0, 10, 10 };
24 GdkRectangle b = { 5, 5, 10, 10 };
25 GdkRectangle c = { 0, 0, 0, 0 };
26 GdkRectangle d = { 5, 5, 5, 5 };
27 GdkRectangle e = { 0, 0, 10, 10 };
28 GdkRectangle f = { 20, 20, 10, 10 };
29 GdkRectangle g = { 0, 0, 0, 0 };
30 GdkRectangle h = { 10, 10, 0, 0 };
31 gboolean res;
32
33 res = gdk_rectangle_intersect (&a, &b, &c);
34 g_assert_true (res);
35 g_assert_true (gdk_rectangle_equal (&c, &d));
36
37 /* non-empty, non-intersecting rectangles */
38 res = gdk_rectangle_intersect (&e, &f, &f);
39 g_assert_cmpint (f.width, ==, 0);
40 g_assert_cmpint (f.height, ==, 0);
41
42 /* empty rectangles */
43 res = gdk_rectangle_intersect (&g, &h, NULL);
44 g_assert_true (!res);
45 }
46
47 static void
48 test_rectangle_union (void)
49 {
50 GdkRectangle a = { 0, 0, 10, 10 };
51 GdkRectangle b = { 5, 5, 10, 10 };
52 GdkRectangle c = { 0, 0, 0, 0 };
53 GdkRectangle d = { 0, 0, 15, 15 };
54 GdkRectangle e = { 0, 0, 0, 0 };
55 GdkRectangle f = { 50, 50, 0, 0 };
56 GdkRectangle g = { 0, 0, 50, 50 };
57
58 gdk_rectangle_union (&a, &b, &c);
59 g_assert_true (gdk_rectangle_equal (&c, &d));
60
61 gdk_rectangle_union (&a, &b, &b);
62 g_assert_true (gdk_rectangle_equal (&b, &d));
63
64 gdk_rectangle_union (&e, &f, &f);
65 g_assert_true (gdk_rectangle_equal (&f, &g));
66 }
67
68 int
69 main (int argc, char *argv[])
70 {
71 g_test_init (&argc, &argv, NULL);
72
73 gdk_init (NULL, NULL);
74
75 g_test_bug_base ("http://bugzilla.gnome.org/");
76
77 g_test_add_func ("/rectangle/equal", test_rectangle_equal);
78 g_test_add_func ("/rectangle/intersect", test_rectangle_intersect);
79 g_test_add_func ("/rectangle/union", test_rectangle_union);
80
81 return g_test_run ();
82 }