Add three simple tests for HildonPickerButton
authorClaudio Saavedra <csaavedra@igalia.com>
Tue, 5 May 2009 12:13:17 +0000 (15:13 +0300)
committerClaudio Saavedra <csaavedra@igalia.com>
Tue, 5 May 2009 12:14:58 +0000 (15:14 +0300)
* tests/Makefile.am: Add check for HildonPickerButton.
* tests/check-hildon-picker-button.c (fx_setup), (fx_teardown),
(START_TEST), (create_hildon_picker_button_suite): Add three simple
checks for the HildonPickerButton.
* tests/check_test.c (configure_tests): Add the test suite.
* tests/test_suites.h: likewise.

ChangeLog
tests/Makefile.am
tests/check-hildon-picker-button.c [new file with mode: 0644]
tests/check_test.c
tests/test_suites.h

index b989f6b..126bb05 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 2009-05-05  Claudio Saavedra  <csaavedra@igalia.com>
 
+       * tests/Makefile.am: Add check for HildonPickerButton.
+       * tests/check-hildon-picker-button.c (fx_setup), (fx_teardown),
+       (START_TEST), (create_hildon_picker_button_suite): Add three simple
+       checks for the HildonPickerButton.
+       * tests/check_test.c (configure_tests): Add the test suite.
+       * tests/test_suites.h: likewise.
+
+2009-05-05  Claudio Saavedra  <csaavedra@igalia.com>
+
        * hildon/hildon-touch-selector.c
        (+on_row_changed): Emit HildonTouchSelector:changed when the
        contents of a selected row change.
index b40d8a2..12d7db7 100644 (file)
@@ -14,7 +14,8 @@ tests                                 = check_test.c                          \
                                          check-hildon-wizard-dialog.c          \
                                          check-hildon-find-toolbar.c           \
                                          check-hildon-window.c                 \
-                                         check-hildon-program.c
+                                         check-hildon-program.c                \
+                                         check-hildon-picker-button.c
 
 
 DEPRECATED_TESTS                       = check-hildon-range-editor.c           \
diff --git a/tests/check-hildon-picker-button.c b/tests/check-hildon-picker-button.c
new file mode 100644 (file)
index 0000000..b6d89bd
--- /dev/null
@@ -0,0 +1,124 @@
+/*
+ * This file is a part of hildon tests
+ *
+ * Copyright (C) 2009 Nokia Corporation, all rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <check.h>
+#include <gtk/gtkmain.h>
+#include "test_suites.h"
+#include "check_utils.h"
+#include "hildon.h"
+
+static HildonButton *button = NULL;
+static HildonTouchSelector *selector = NULL;
+static GtkWindow *window = NULL;
+
+static void
+fx_setup ()
+{
+    int argc = 0;
+
+    gtk_init (&argc, NULL);
+
+    window = GTK_WINDOW (hildon_window_new());
+
+    fail_if (!HILDON_IS_WINDOW(window),
+            "hildon-picker-button: Window creation failed.");
+
+    button = HILDON_BUTTON (hildon_picker_button_new (HILDON_SIZE_AUTO,
+                              HILDON_BUTTON_ARRANGEMENT_VERTICAL));
+    selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ());
+
+    hildon_touch_selector_append_text (selector, "Row one");
+    hildon_touch_selector_append_text (selector, "Row two");
+    hildon_touch_selector_append_text (selector, "Row three");
+    hildon_touch_selector_append_text (selector, "Row four");
+
+    hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button), selector);
+
+    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));
+    gtk_widget_show (GTK_WIDGET (button));
+
+    show_test_window (GTK_WIDGET (window));
+}
+
+static void
+fx_teardown ()
+{
+    gtk_widget_destroy (GTK_WIDGET (window));
+}
+
+/**
+   Purpose: test that programmatic changes in the selector update the
+   value displayed in the button.
+
+   Checks for:
+
+   - Initial value must be empty.
+   - Programmatically selecting an item in the selector should show it in the button.
+   - Updating the contents of a selected row should update the displayed value accordingly.
+
+*/
+START_TEST (test_hildon_picker_button_value)
+{
+    const gchar *value;
+    GtkTreeIter iter;
+    GtkTreeModel *model;
+    const gchar *new_value = "Something different";
+
+    /* Test 1: getting initial value. */
+    value = hildon_button_get_value (button);
+    fail_if (strcmp (value, "") != 0,
+             "hildon-picker-button: default value wrong: `%s'",
+             value);
+
+    /* Test 2: Selecting a particular row. */
+    hildon_touch_selector_set_active (selector, 0, 1);
+    value = hildon_button_get_value (button);
+    fail_if (strcmp (value, "Row two") != 0,
+             "hildon-picker-button: switched to second row in the selector, "
+             "but button displays `%s'.", value);
+
+    /* Test 3: Modifying a selected row. */
+    model = hildon_touch_selector_get_model (selector, 0);
+    hildon_touch_selector_get_selected (selector, 0, &iter);
+    gtk_list_store_set (GTK_LIST_STORE (model), &iter,
+                        0, new_value, -1);
+    value = hildon_button_get_value (button);
+    fail_if (strcmp (value, new_value) != 0,
+             "hildon-picker-button: set the currently selected row to `%s' "
+             "but button displays `%s'.", new_value, value);
+
+}
+END_TEST
+
+Suite *create_hildon_picker_button_suite (void)
+{
+    Suite *s = suite_create ("HildonPickerButton");
+
+    TCase *tc1 = tcase_create ("hildon_picker_button");
+    tcase_add_checked_fixture (tc1, fx_setup, fx_teardown);
+    tcase_add_test (tc1, test_hildon_picker_button_value);
+    suite_add_tcase (s, tc1);
+
+    return s;
+}
index e54de92..afc2075 100644 (file)
@@ -82,6 +82,7 @@ configure_tests(gint environment)
   srunner_add_suite(sr, create_hildon_banner_suite());
   srunner_add_suite(sr, create_hildon_window_suite());
   srunner_add_suite(sr, create_hildon_helper_suite());
+  srunner_add_suite(sr, create_hildon_picker_button_suite());
 
   /* Disable tests that need maemo environment to be up if it is not running */
   if (environment != ENVIRONMENT_MAEMO_ERROR)
index e93c077..d0d5afa 100644 (file)
@@ -58,6 +58,6 @@ Suite *create_hildon_scroll_area_suite(void);
 Suite *create_hildon_window_suite(void);
 Suite *create_hildon_program_suite(void);
 Suite *create_hildon_composite_widget_suite(void);
-
+Suite *create_hildon_picker_button_suite (void);
 
 #endif