Improve gdk test coverage
authorMatthias Clasen <mclasen@redhat.com>
Sun, 14 May 2023 01:32:11 +0000 (21:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 14 May 2023 01:56:29 +0000 (21:56 -0400)
Add tests for GdkToplevvelLayout and
GdkPopupLayout.

testsuite/gdk/meson.build
testsuite/gdk/popuplayout.c [new file with mode: 0644]
testsuite/gdk/toplevellayout.c [new file with mode: 0644]

index 13ed1ff31c963b67a482b99dab5ed32ae2e14e8b..157c9d4daaa0dd2453bc398ba50d45d49cb795bf 100644 (file)
@@ -24,6 +24,8 @@ tests = [
   { 'name': 'rgba' },
   { 'name': 'seat' },
   { 'name': 'texture-threads' },
+  { 'name': 'toplevellayout' },
+  { 'name': 'popuplayout' },
 ]
 
 foreach t : tests
diff --git a/testsuite/gdk/popuplayout.c b/testsuite/gdk/popuplayout.c
new file mode 100644 (file)
index 0000000..e48ce47
--- /dev/null
@@ -0,0 +1,63 @@
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+static void
+test_popup_layout_basic (void)
+{
+  GdkPopupLayout *layout;
+  GdkPopupLayout *layout2;
+  GdkRectangle anchor = { 0, 0, 20, 20 };
+  const GdkRectangle *rect;
+  int dx, dy;
+  int l, r, t, b;
+
+  layout = gdk_popup_layout_new (&anchor, GDK_GRAVITY_SOUTH, GDK_GRAVITY_NORTH);
+
+  rect = gdk_popup_layout_get_anchor_rect (layout);
+  g_assert_true (gdk_rectangle_equal (&anchor, rect));
+
+  layout2 = gdk_popup_layout_copy (layout);
+
+  gdk_popup_layout_ref (layout2);
+  g_assert_true (gdk_popup_layout_equal (layout, layout2));
+  gdk_popup_layout_unref (layout2);
+
+  gdk_popup_layout_set_offset (layout, 10, 10);
+  g_assert_false (gdk_popup_layout_equal (layout, layout2));
+  gdk_popup_layout_get_offset (layout, &dx, &dy);
+  g_assert_true (dx == 10 && dy == 10);
+
+  gdk_popup_layout_set_shadow_width (layout, 1, 2, 3, 4);
+  gdk_popup_layout_get_shadow_width (layout, &l, &r, &t, &b);
+  g_assert_true (l == 1 && r == 2 && t == 3 && b == 4);
+
+  anchor.x = 1;
+  anchor.y = 2;
+  gdk_popup_layout_set_anchor_rect (layout, &anchor);
+  rect = gdk_popup_layout_get_anchor_rect (layout);
+  g_assert_true (gdk_rectangle_equal (&anchor, rect));
+
+  gdk_popup_layout_set_rect_anchor (layout, GDK_GRAVITY_NORTH_WEST);
+  g_assert_true (gdk_popup_layout_get_rect_anchor (layout) == GDK_GRAVITY_NORTH_WEST);
+
+  gdk_popup_layout_set_surface_anchor (layout, GDK_GRAVITY_SOUTH_EAST);
+  g_assert_true (gdk_popup_layout_get_surface_anchor (layout) == GDK_GRAVITY_SOUTH_EAST);
+
+  gdk_popup_layout_set_anchor_hints (layout, GDK_ANCHOR_FLIP_X | GDK_ANCHOR_RESIZE_Y);
+  g_assert_true (gdk_popup_layout_get_anchor_hints (layout) == (GDK_ANCHOR_FLIP_X | GDK_ANCHOR_RESIZE_Y));
+
+  gdk_popup_layout_unref (layout2);
+  gdk_popup_layout_unref (layout);
+}
+
+int
+main (int argc, char *argv[])
+{
+  (g_test_init) (&argc, &argv, NULL);
+
+  gtk_init ();
+
+  g_test_add_func ("/popuplayout/basic", test_popup_layout_basic);
+
+  return g_test_run ();
+}
diff --git a/testsuite/gdk/toplevellayout.c b/testsuite/gdk/toplevellayout.c
new file mode 100644 (file)
index 0000000..512e6f2
--- /dev/null
@@ -0,0 +1,53 @@
+#include <stdlib.h>
+#include <gtk/gtk.h>
+
+static void
+test_toplevel_layout_basic (void)
+{
+  GdkToplevelLayout *layout;
+  GdkToplevelLayout *layout2;
+  gboolean max;
+  gboolean full;
+  GdkMonitor *monitor;
+
+  layout = gdk_toplevel_layout_new ();
+
+  g_assert_false (gdk_toplevel_layout_get_maximized (layout, &max));
+  g_assert_false (gdk_toplevel_layout_get_fullscreen (layout, &full));
+
+  gdk_toplevel_layout_set_maximized (layout, TRUE);
+  g_assert_true (gdk_toplevel_layout_get_maximized (layout, &max));
+  g_assert_true (max);
+
+  layout2 = gdk_toplevel_layout_copy (layout);
+  gdk_toplevel_layout_ref (layout2);
+  g_assert_true (gdk_toplevel_layout_equal (layout, layout2));
+  gdk_toplevel_layout_unref (layout2);
+
+  gdk_toplevel_layout_set_maximized (layout, FALSE);
+  g_assert_false (gdk_toplevel_layout_equal (layout, layout2));
+
+  monitor = g_list_model_get_item (gdk_display_get_monitors (gdk_display_get_default ()), 0);
+  gdk_toplevel_layout_set_fullscreen (layout, TRUE, monitor);
+
+  g_assert_true (gdk_toplevel_layout_get_fullscreen (layout, &full));
+  g_assert_true (full);
+  g_assert_true (monitor == gdk_toplevel_layout_get_fullscreen_monitor (layout));
+
+  g_object_unref (monitor);
+
+  gdk_toplevel_layout_unref (layout2);
+  gdk_toplevel_layout_unref (layout);
+}
+
+int
+main (int argc, char *argv[])
+{
+  (g_test_init) (&argc, &argv, NULL);
+
+  gtk_init ();
+
+  g_test_add_func ("/toplevellayout/basic", test_toplevel_layout_basic);
+
+  return g_test_run ();
+}