[libhandy] test-combo-row: Check if property notify events are emitted correctly



commit 6986f2d249f6b1791300d3bede1716098d5301c4
Author: Yetizone <andreii lisita gmail com>
Date:   Sun Dec 27 14:40:03 2020 +0200

    test-combo-row: Check if property notify events are emitted correctly

 tests/test-combo-row.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)
---
diff --git a/tests/test-combo-row.c b/tests/test-combo-row.c
index 12feea61..d8691777 100644
--- a/tests/test-combo-row.c
+++ b/tests/test-combo-row.c
@@ -6,6 +6,13 @@
 
 #include <handy.h>
 
+gint notified;
+
+static void
+notify_cb (GtkWidget *widget, gpointer data)
+{
+  notified++;
+}
 
 static void
 test_hdy_combo_row_set_for_enum (void)
@@ -34,22 +41,62 @@ test_hdy_combo_row_set_for_enum (void)
   g_assert_cmpstr (hdy_enum_value_object_get_nick (value), ==, "vertical");
 }
 
+static void
+test_hdy_combo_row_selected_index (void)
+{
+  g_autoptr (HdyComboRow) row = NULL;
+  gint selected_index = 0;
+
+  row = HDY_COMBO_ROW (g_object_ref_sink (hdy_combo_row_new ()));
+  g_assert_nonnull (row);
+
+  notified = 0;
+  g_signal_connect (row, "notify::selected-index", G_CALLBACK (notify_cb), NULL);
+
+  g_object_get (row, "selected-index", &selected_index, NULL);
+  g_assert_cmpint (selected_index, ==, -1);
+
+  hdy_combo_row_set_selected_index (row, -1);
+  g_assert_cmpint (notified, ==, 0);
+
+  hdy_combo_row_set_for_enum (row, GTK_TYPE_SELECTION_MODE, hdy_enum_value_row_name, NULL, NULL);
+  g_assert_cmpint (hdy_combo_row_get_selected_index (row), ==, 0);
+  g_assert_cmpint (notified, ==, 1);
+
+  hdy_combo_row_set_selected_index (row, 3);
+  g_assert_cmpint (hdy_combo_row_get_selected_index (row), ==, 3);
+  g_assert_cmpint (notified, ==, 2);
+
+  g_object_set (row, "selected-index", 1, NULL);
+  g_assert_cmpint (hdy_combo_row_get_selected_index (row), ==, 1);
+  g_assert_cmpint (notified, ==, 3);
+}
 
 static void
 test_hdy_combo_row_use_subtitle (void)
 {
   g_autoptr (HdyComboRow) row = NULL;
+  gboolean use_subtitle = FALSE;
 
   row = g_object_ref_sink (HDY_COMBO_ROW (hdy_combo_row_new ()));
   g_assert_nonnull (row);
 
+  notified = 0;
+  g_signal_connect (row, "notify::use-subtitle", G_CALLBACK (notify_cb), NULL);
+
   g_assert_false (hdy_combo_row_get_use_subtitle (row));
 
+  hdy_combo_row_set_use_subtitle (row, FALSE);
+  g_assert_cmpint (notified, ==, 0);
+
   hdy_combo_row_set_use_subtitle (row, TRUE);
   g_assert_true (hdy_combo_row_get_use_subtitle (row));
+  g_assert_cmpint (notified, ==, 1);
 
-  hdy_combo_row_set_use_subtitle (row, FALSE);
-  g_assert_false (hdy_combo_row_get_use_subtitle (row));
+  g_object_set (row, "use-subtitle", FALSE, NULL);
+  g_object_get (row, "use-subtitle", &use_subtitle, NULL);
+  g_assert_false (use_subtitle);
+  g_assert_cmpint (notified, ==, 2);
 }
 
 
@@ -61,6 +108,7 @@ main (gint argc,
   hdy_init ();
 
   g_test_add_func("/Handy/ComboRow/set_for_enum", test_hdy_combo_row_set_for_enum);
+  g_test_add_func("/Handy/ComboRow/selected_index", test_hdy_combo_row_selected_index);
   g_test_add_func("/Handy/ComboRow/use_subtitle", test_hdy_combo_row_use_subtitle);
 
   return g_test_run();


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