[gtk+] Add some tests for GdkRectangle
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add some tests for GdkRectangle
- Date: Mon, 28 Mar 2016 23:55:29 +0000 (UTC)
commit 43a568395baf035b237edf6f2ddbb45977d21491
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Mar 28 19:54:55 2016 -0400
Add some tests for GdkRectangle
In particular, we're testing corner cases with empty rectangles
here.
testsuite/gdk/Makefile.am | 1 +
testsuite/gdk/rectangle.c | 82 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 83 insertions(+), 0 deletions(-)
---
diff --git a/testsuite/gdk/Makefile.am b/testsuite/gdk/Makefile.am
index beb3cac..73b4beb 100644
--- a/testsuite/gdk/Makefile.am
+++ b/testsuite/gdk/Makefile.am
@@ -22,6 +22,7 @@ TEST_PROGS += \
display \
encoding \
keysyms \
+ rectangle \
rgba \
seat \
visual \
diff --git a/testsuite/gdk/rectangle.c b/testsuite/gdk/rectangle.c
new file mode 100644
index 0000000..6089ff6
--- /dev/null
+++ b/testsuite/gdk/rectangle.c
@@ -0,0 +1,82 @@
+#include <gdk/gdk.h>
+
+static void
+test_rectangle_equal (void)
+{
+ GdkRectangle a = { 0, 0, 1, 1 };
+ GdkRectangle b = { 1, 1, 2, 2 };
+ GdkRectangle c = { 0, 0, 2, 2 };
+ GdkRectangle d = { 0, 0, 1, 1 };
+ GdkRectangle e = { 0, 0, 0, 0 };
+ GdkRectangle f = { 1, 1, 0, 0 };
+
+ g_assert_true (!gdk_rectangle_equal (&a, &b));
+ g_assert_true (!gdk_rectangle_equal (&a, &c));
+ g_assert_true (!gdk_rectangle_equal (&b, &c));
+ g_assert_true ( gdk_rectangle_equal (&a, &d));
+ g_assert_true (!gdk_rectangle_equal (&e, &f));
+}
+
+static void
+test_rectangle_intersect (void)
+{
+ GdkRectangle a = { 0, 0, 10, 10 };
+ GdkRectangle b = { 5, 5, 10, 10 };
+ GdkRectangle c = { 0, 0, 0, 0 };
+ GdkRectangle d = { 5, 5, 5, 5 };
+ GdkRectangle e = { 0, 0, 10, 10 };
+ GdkRectangle f = { 20, 20, 10, 10 };
+ GdkRectangle g = { 0, 0, 0, 0 };
+ GdkRectangle h = { 10, 10, 0, 0 };
+ gboolean res;
+
+ res = gdk_rectangle_intersect (&a, &b, &c);
+ g_assert_true (res);
+ g_assert_true (gdk_rectangle_equal (&c, &d));
+
+ /* non-empty, non-intersecting rectangles */
+ res = gdk_rectangle_intersect (&e, &f, &f);
+ g_assert_cmpint (f.width, ==, 0);
+ g_assert_cmpint (f.height, ==, 0);
+
+ /* empty rectangles */
+ res = gdk_rectangle_intersect (&g, &h, NULL);
+ g_assert_true (!res);
+}
+
+static void
+test_rectangle_union (void)
+{
+ GdkRectangle a = { 0, 0, 10, 10 };
+ GdkRectangle b = { 5, 5, 10, 10 };
+ GdkRectangle c = { 0, 0, 0, 0 };
+ GdkRectangle d = { 0, 0, 15, 15 };
+ GdkRectangle e = { 0, 0, 0, 0 };
+ GdkRectangle f = { 50, 50, 0, 0 };
+ GdkRectangle g = { 0, 0, 50, 50 };
+
+ gdk_rectangle_union (&a, &b, &c);
+ g_assert_true (gdk_rectangle_equal (&c, &d));
+
+ gdk_rectangle_union (&a, &b, &b);
+ g_assert_true (gdk_rectangle_equal (&b, &d));
+
+ gdk_rectangle_union (&e, &f, &f);
+ g_assert_true (gdk_rectangle_equal (&f, &g));
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+
+ gdk_init (NULL, NULL);
+
+ g_test_bug_base ("http://bugzilla.gnome.org/");
+
+ g_test_add_func ("/rectangle/equal", test_rectangle_equal);
+ g_test_add_func ("/rectangle/intersect", test_rectangle_intersect);
+ g_test_add_func ("/rectangle/union", test_rectangle_union);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]