2 * This file is a part of hildon tests
4 * Copyright (C) 2009 Nokia Corporation, all rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <gtk/gtkmain.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
29 #include <hildon/hildon.h>
31 static HildonButton *button = NULL;
32 static HildonTouchSelector *selector = NULL;
33 static GtkWindow *window = NULL;
40 gtk_init (&argc, NULL);
42 window = GTK_WINDOW (hildon_window_new());
44 fail_if (!HILDON_IS_WINDOW(window),
45 "hildon-picker-button: Window creation failed.");
47 button = HILDON_BUTTON (hildon_picker_button_new (HILDON_SIZE_AUTO,
48 HILDON_BUTTON_ARRANGEMENT_VERTICAL));
49 selector = HILDON_TOUCH_SELECTOR (hildon_touch_selector_new_text ());
51 hildon_touch_selector_append_text (selector, "Row one");
52 hildon_touch_selector_append_text (selector, "Row two");
53 hildon_touch_selector_append_text (selector, "Row three");
54 hildon_touch_selector_append_text (selector, "Row four");
56 hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (button), selector);
58 gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (button));
59 gtk_widget_show (GTK_WIDGET (button));
61 show_test_window (GTK_WIDGET (window));
67 gtk_widget_destroy (GTK_WIDGET (window));
71 Purpose: test that programmatic changes in the selector update the
72 value displayed in the button.
76 - Initial value must be empty.
77 - Programmatically selecting an item in the selector should show it in the button.
78 - Updating the contents of a selected row should update the displayed value accordingly.
81 START_TEST (test_hildon_picker_button_value)
86 const gchar *new_value = "Something different";
88 /* Test 1: getting initial value. */
89 value = hildon_button_get_value (button);
90 fail_if (strcmp (value, "") != 0,
91 "hildon-picker-button: default value wrong: `%s'",
94 /* Test 2: Selecting a particular row. */
95 hildon_touch_selector_set_active (selector, 0, 1);
96 value = hildon_button_get_value (button);
97 fail_if (strcmp (value, "Row two") != 0,
98 "hildon-picker-button: switched to second row in the selector, "
99 "but button displays `%s'.", value);
101 /* Test 3: Modifying a selected row. */
102 model = hildon_touch_selector_get_model (selector, 0);
103 hildon_touch_selector_get_selected (selector, 0, &iter);
104 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
106 value = hildon_button_get_value (button);
107 fail_if (strcmp (value, new_value) != 0,
108 "hildon-picker-button: set the currently selected row to `%s' "
109 "but button displays `%s'.", new_value, value);
114 Suite *create_hildon_picker_button_suite (void)
116 Suite *s = suite_create ("HildonPickerButton");
118 TCase *tc1 = tcase_create ("hildon_picker_button");
119 tcase_add_checked_fixture (tc1, fx_setup, fx_teardown);
120 tcase_add_test (tc1, test_hildon_picker_button_value);
121 suite_add_tcase (s, tc1);