[libhandy] tests: Test hdy_deck_get_adjacent_child() and navigate()
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy] tests: Test hdy_deck_get_adjacent_child() and navigate()
- Date: Tue, 2 Jun 2020 07:17:13 +0000 (UTC)
commit ef9d244dc2ce1fe40f84051b3cb3a7194d5f5614
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Jun 2 00:21:11 2020 +0500
tests: Test hdy_deck_get_adjacent_child() and navigate()
Signed-off-by: Alexander Mikhaylenko <alexm gnome org>
tests/meson.build | 1 +
tests/test-deck.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 1de3b7be..305c806c 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -24,6 +24,7 @@ test_names = [
'test-avatar',
'test-carousel',
'test-combo-row',
+ 'test-deck',
'test-expander-row',
'test-header-bar',
'test-header-group',
diff --git a/tests/test-deck.c b/tests/test-deck.c
new file mode 100644
index 00000000..935268ce
--- /dev/null
+++ b/tests/test-deck.c
@@ -0,0 +1,93 @@
+/*
+ * 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_deck_adjacent_child (void)
+{
+ g_autoptr (HdyDeck) deck = NULL;
+ GtkWidget *children[2];
+ gint i;
+ GtkWidget *result;
+
+ deck = HDY_DECK (hdy_deck_new ());
+ g_assert_nonnull (deck);
+
+ for (i = 0; i < 2; i++) {
+ children[i] = gtk_label_new ("");
+ g_assert_nonnull (children[i]);
+
+ gtk_container_add (GTK_CONTAINER (deck), children[i]);
+ }
+
+ hdy_deck_set_visible_child (deck, children[0]);
+
+ result = hdy_deck_get_adjacent_child (deck, HDY_NAVIGATION_DIRECTION_BACK);
+ g_assert_null (result);
+
+ result = hdy_deck_get_adjacent_child (deck, HDY_NAVIGATION_DIRECTION_FORWARD);
+ g_assert_true (result == children[1]);
+
+ hdy_deck_set_visible_child (deck, children[1]);
+
+ result = hdy_deck_get_adjacent_child (deck, HDY_NAVIGATION_DIRECTION_BACK);
+ g_assert_true (result == children[0]);
+
+ result = hdy_deck_get_adjacent_child (deck, HDY_NAVIGATION_DIRECTION_FORWARD);
+ g_assert_null (result);
+}
+
+
+static void
+test_hdy_deck_navigate (void)
+{
+ g_autoptr (HdyDeck) deck = NULL;
+ GtkWidget *children[2];
+ gint i;
+ gboolean result;
+
+ deck = HDY_DECK (hdy_deck_new ());
+ g_assert_nonnull (deck);
+
+ for (i = 0; i < 2; i++) {
+ children[i] = gtk_label_new ("");
+ g_assert_nonnull (children[i]);
+
+ gtk_container_add (GTK_CONTAINER (deck), children[i]);
+ }
+
+ hdy_deck_set_visible_child (deck, children[0]);
+
+ result = hdy_deck_navigate (deck, HDY_NAVIGATION_DIRECTION_BACK);
+ g_assert_false (result);
+
+ result = hdy_deck_navigate (deck, HDY_NAVIGATION_DIRECTION_FORWARD);
+ g_assert_true (result);
+ g_assert_true (hdy_deck_get_visible_child (deck) == children[1]);
+
+ result = hdy_deck_navigate (deck, HDY_NAVIGATION_DIRECTION_FORWARD);
+ g_assert_false (result);
+
+ result = hdy_deck_navigate (deck, HDY_NAVIGATION_DIRECTION_BACK);
+ g_assert_true (result);
+ g_assert_true (hdy_deck_get_visible_child (deck) == children[0]);
+}
+
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ gtk_test_init (&argc, &argv, NULL);
+
+ g_test_add_func ("/Handy/Deck/adjacent_child", test_hdy_deck_adjacent_child);
+ g_test_add_func ("/Handy/Deck/navigate", test_hdy_deck_navigate);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]