[libhandy] tests: Test hdy_leaflet_get_adjacent_child() and navigate()



commit 95ad02059a6b5be2875168d06482e88f9af904f1
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Jun 2 00:17:48 2020 +0500

    tests: Test hdy_leaflet_get_adjacent_child() and navigate()
    
    Signed-off-by: Alexander Mikhaylenko <alexm gnome org>

 tests/meson.build    |   1 +
 tests/test-leaflet.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 6f854489..1de3b7be 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -28,6 +28,7 @@ test_names = [
   'test-header-bar',
   'test-header-group',
   'test-keypad',
+  'test-leaflet',
   'test-preferences-group',
   'test-preferences-page',
   'test-preferences-row',
diff --git a/tests/test-leaflet.c b/tests/test-leaflet.c
new file mode 100644
index 00000000..ac7faf5a
--- /dev/null
+++ b/tests/test-leaflet.c
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2020 Alexander Mikhaylenko <alexm gnome org>
+ *
+ * SPDX-License-Identifier: LGPL-2.1+
+ */
+
+#define HANDY_USE_UNSTABLE_API
+#include <handy.h>
+
+
+static void
+test_hdy_leaflet_adjacent_child (void)
+{
+  g_autoptr (HdyLeaflet) leaflet = NULL;
+  GtkWidget *children[3];
+  gint i;
+  GtkWidget *result;
+
+  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  g_assert_nonnull (leaflet);
+
+  for (i = 0; i < 3; i++) {
+    children[i] = gtk_label_new ("");
+    g_assert_nonnull (children[i]);
+
+    gtk_container_add (GTK_CONTAINER (leaflet), children[i]);
+  }
+
+  gtk_container_child_set (GTK_CONTAINER (leaflet), children[1],
+                           "allow-visible", FALSE,
+                           NULL);
+
+  hdy_leaflet_set_visible_child (leaflet, children[0]);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
+  g_assert_null (result);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_true (result == children[2]);
+
+  hdy_leaflet_set_visible_child (leaflet, children[1]);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
+  g_assert_true (result == children[0]);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_true (result == children[2]);
+
+  hdy_leaflet_set_visible_child (leaflet, children[2]);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
+  g_assert_true (result == children[0]);
+
+  result = hdy_leaflet_get_adjacent_child (leaflet, HDY_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_null (result);
+}
+
+
+static void
+test_hdy_leaflet_navigate (void)
+{
+  g_autoptr (HdyLeaflet) leaflet = NULL;
+  GtkWidget *children[3];
+  gint i;
+  gboolean result;
+
+  leaflet = HDY_LEAFLET (hdy_leaflet_new ());
+  g_assert_nonnull (leaflet);
+
+  for (i = 0; i < 3; i++) {
+    children[i] = gtk_label_new ("");
+    g_assert_nonnull (children[i]);
+
+    gtk_container_add (GTK_CONTAINER (leaflet), children[i]);
+  }
+
+  gtk_container_child_set (GTK_CONTAINER (leaflet), children[1],
+                           "allow-visible", FALSE,
+                           NULL);
+
+  hdy_leaflet_set_visible_child (leaflet, children[0]);
+
+  result = hdy_leaflet_navigate (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
+  g_assert_false (result);
+
+  result = hdy_leaflet_navigate (leaflet, HDY_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_true (result);
+  g_assert_true (hdy_leaflet_get_visible_child (leaflet) == children[2]);
+
+  result = hdy_leaflet_navigate (leaflet, HDY_NAVIGATION_DIRECTION_FORWARD);
+  g_assert_false (result);
+
+  result = hdy_leaflet_navigate (leaflet, HDY_NAVIGATION_DIRECTION_BACK);
+  g_assert_true (result);
+  g_assert_true (hdy_leaflet_get_visible_child (leaflet) == children[0]);
+}
+
+
+gint
+main (gint argc,
+      gchar *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+
+  g_test_add_func ("/Handy/Leaflet/adjacent_child", test_hdy_leaflet_adjacent_child);
+  g_test_add_func ("/Handy/Leaflet/navigate", test_hdy_leaflet_navigate);
+
+  return g_test_run ();
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]