Commit f6afa111 authored by Andrei Lișiță's avatar Andrei Lișiță 🎮
Browse files

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

parent 385be40e
Pipeline #241705 passed with stages
in 12 minutes and 4 seconds
......@@ -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();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment