[libadwaita/wip/cdavis/spin-row] tests: Add AdwSpinRow test




commit aeab6c5cc5a0d12d6d99286f5bc62ebdf97a3c04
Author: Christopher Davis <christopherdavis gnome org>
Date:   Tue Aug 23 15:51:30 2022 -0400

    tests: Add AdwSpinRow test

 tests/meson.build     |   1 +
 tests/test-spin-row.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
---
diff --git a/tests/meson.build b/tests/meson.build
index 2f17a06c..b61b0180 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -48,6 +48,7 @@ test_names = [
   'test-preferences-page',
   'test-preferences-row',
   'test-preferences-window',
+  'test-spin-row',
   'test-split-button',
   'test-squeezer',
   'test-status-page',
diff --git a/tests/test-spin-row.c b/tests/test-spin-row.c
new file mode 100644
index 00000000..7584cf06
--- /dev/null
+++ b/tests/test-spin-row.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2022 Christopher Davis <christopherdavis gnome org>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include <adwaita.h>
+
+static void
+test_adw_spin_row_new_with_range (void)
+{
+  AdwSpinRow *row = g_object_ref_sink (ADW_SPIN_ROW (adw_spin_row_new_with_range (1998.0, 2022.0, 1.0)));
+  GtkAdjustment *adjustment = adw_spin_row_get_adjustment (row);
+
+  g_assert_nonnull (row);
+  g_assert_nonnull (adjustment);
+
+  g_assert_cmpfloat (gtk_adjustment_get_lower (adjustment), ==, 1998.0);
+  g_assert_cmpfloat (gtk_adjustment_get_upper (adjustment), ==, 2022.0);
+  g_assert_cmpfloat (gtk_adjustment_get_step_increment (adjustment), ==, 1.0);
+  g_assert_cmpfloat (gtk_adjustment_get_page_increment (adjustment), ==, 10.0);
+
+  g_assert_finalize_object (row);
+}
+
+static void
+test_adw_spin_row_configure (void)
+{
+
+  AdwSpinRow *row = g_object_ref_sink (ADW_SPIN_ROW (adw_spin_row_new_with_range (0.0, 1.0, 1.0)));
+  GtkAdjustment *adjustment = gtk_adjustment_new (2000.0, 1998.0, 2022.0, 1.0, 10.0, 0);
+
+  g_assert_nonnull (row);
+  g_assert_nonnull (adjustment);
+
+  adw_spin_row_configure (row, adjustment, 2.0, 2);
+
+  g_assert_cmpfloat (adw_spin_row_get_value (row), ==, 2000.0);
+  g_assert_cmpfloat (adw_spin_row_get_climb_rate (row), ==, 2.0);
+  g_assert_cmpfloat (adw_spin_row_get_digits (row), ==, 2);
+  g_assert (adw_spin_row_get_adjustment (row) == adjustment);
+
+  g_assert_finalize_object (row);
+}
+
+static void
+test_adw_spin_row_add_remove (void)
+{
+  AdwSpinRow *row = g_object_ref_sink (ADW_SPIN_ROW (adw_spin_row_new_with_range (0.0, 1.0, 1.0)));
+  GtkWidget *prefix, *suffix;
+
+  g_assert_nonnull (row);
+
+  prefix = gtk_check_button_new ();
+  g_assert_nonnull (prefix);
+
+  suffix = gtk_check_button_new ();
+  g_assert_nonnull (suffix);
+
+  adw_spin_row_add_prefix (row, prefix);
+  adw_spin_row_add_suffix (row, suffix);
+
+  adw_spin_row_remove (row, prefix);
+  adw_spin_row_remove (row, suffix);
+
+  g_assert_finalize_object (row);
+}
+
+static void
+test_adw_spin_row_subtitle (void)
+{
+  AdwSpinRow *row = g_object_ref_sink (ADW_SPIN_ROW (adw_spin_row_new_with_range (0.0, 1.0, 1.0)));
+
+  g_assert_nonnull (row);
+
+  g_assert_cmpstr (adw_spin_row_get_subtitle (row), ==, "");
+
+  adw_spin_row_set_subtitle (row, "Dummy subtitle");
+  g_assert_cmpstr (adw_spin_row_get_subtitle (row), ==, "Dummy subtitle");
+
+  adw_preferences_row_set_use_markup (ADW_PREFERENCES_ROW (row), FALSE);
+  adw_spin_row_set_subtitle (row, "Invalid <b>markup");
+  g_assert_cmpstr (adw_spin_row_get_subtitle (row), ==, "Invalid <b>markup");
+
+  g_assert_finalize_object (row);
+}
+
+int
+main (int   argc,
+      char *argv[])
+{
+  gtk_test_init (&argc, &argv, NULL);
+  adw_init ();
+
+  g_test_add_func("/Adwaita/SpinRow/new_with_range", test_adw_spin_row_new_with_range);
+  g_test_add_func("/Adwaita/SpinRow/configure", test_adw_spin_row_configure);
+  g_test_add_func("/Adwaita/SpinRow/add_remove", test_adw_spin_row_add_remove);
+  g_test_add_func("/Adwaita/SpinRow/subtitle", test_adw_spin_row_subtitle);
+
+  return g_test_run();
+}


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