2 * This file is a part of hildon tests
4 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 #include <gtk/gtkmain.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
32 #include "hildon-find-toolbar.h"
33 #include "hildon-window.h"
35 /* -------------------- Fixtures -------------------- */
37 static HildonFindToolbar *find_toolbar = NULL;
38 static GtkWidget *showed_window = NULL;
41 fx_setup_default_find_toolbar ()
44 gtk_init(&argc, NULL);
46 /* Creates a find toolbar */
47 find_toolbar = HILDON_FIND_TOOLBAR(hildon_find_toolbar_new(TEST_STRING));
48 /* Check find toolbar object has been created properly */
49 fail_if(!HILDON_IS_FIND_TOOLBAR(find_toolbar),
50 "hildon-find-toolbar: Creation failed.");
52 showed_window = create_test_window ();
54 hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));
56 /* Displays the widget and the window */
57 show_all_test_window (showed_window);
62 fx_setup_model_find_toolbar ()
69 gtk_init(&argc, NULL);
71 /* Creates a find toolbar with a model */
72 model = gtk_list_store_new(1, G_TYPE_STRING);
73 gtk_list_store_append(model, &iter);
74 gtk_list_store_set (model, &iter, 0, "hildon", -1);
75 gtk_list_store_append(model, &iter);
76 gtk_list_store_set (model, &iter, 0, "nokia", -1);
77 find_toolbar = HILDON_FIND_TOOLBAR(hildon_find_toolbar_new_with_model(NULL, model, 0));
78 /* Check find toolbar object has been created properly */
79 fail_if(!HILDON_IS_FIND_TOOLBAR(find_toolbar),
80 "hildon-find-toolbar: Creation failed.");
82 /* Check model is set */
83 g_value_init (&value, GTK_TYPE_LIST_STORE);
84 g_object_get_property(G_OBJECT(find_toolbar), "list", &value);
86 fail_if (model != g_value_get_object(&value),
87 "hildon-find-toolbar: Creation with model failed, model retrieved is different from model set in new_with_model");
89 showed_window = create_test_window ();
91 hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));
93 /* Displays the widget and the window */
94 show_all_test_window (showed_window);
98 fx_teardown_find_toolbar()
101 gtk_widget_destroy(GTK_WIDGET(showed_window));
105 /* -------------------- Test cases -------------------- */
107 /* ----- Test case for set/get_property "label" -----*/
110 * Purpose: Check that property "label" is set and get properly.
112 * - Set and get with a regular string
113 * - Set and get with value ""
115 START_TEST (test_set_get_property_label_regular)
117 GValue value_set = {0,};
118 GValue value_get = {0,};
120 g_value_init(&value_set,G_TYPE_STRING);
121 g_value_init(&value_get,G_TYPE_STRING);
123 /* Test1: set/get of a regular string */
124 g_value_set_string(&value_set, TEST_STRING);
125 g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
126 g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
127 fail_if (strcmp(g_value_get_string(&value_get), g_value_get_string(&value_set)) != 0,
128 "hildon-find-toolbar: Property \"label\" was set to value \"%s\", but get_property retrieved value \"%s\"",
129 g_value_get_string(&value_set), g_value_get_string(&value_get));
131 /* Test2: set/get of label "" */
132 g_value_set_string(&value_set, "");
133 g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
134 g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
135 fail_if (strcmp(g_value_get_string(&value_get), g_value_get_string(&value_set)) != 0,
136 "hildon-find-toolbar: Property \"label\" was set to value \"%s\", but get_property retrieved value \"%s\"",
137 g_value_get_string(&value_set), g_value_get_string(&value_get));
142 * Purpose: Check handling of invalid values for property "label"
144 * - Set and get with NULL value
146 START_TEST (test_set_get_property_label_invalid)
148 GValue value_set = {0,};
149 GValue value_get = {0,};
151 g_value_init(&value_set,G_TYPE_STRING);
153 /* Test1: set/get of NULL label */
154 g_value_set_string(&value_set, NULL);
155 g_object_set_property(G_OBJECT(find_toolbar), "label", &value_set);
156 g_object_get_property(G_OBJECT(find_toolbar), "label", &value_get);
157 fail_if (g_value_get_string(&value_get) != NULL,
158 "hildon-find-toolbar: Property \"label\" was set to value NULL, but get_property retrieved value \"%s\"",
159 g_value_get_string(&value_get));
163 /* ---------- Suite creation ---------- */
165 Suite *create_hildon_find_toolbar_suite()
167 /* Create the suite */
168 Suite *s = suite_create("HildonFindToolbar");
170 /* Create test cases */
171 TCase *tc1 = tcase_create("set_get_property_label");
172 TCase *tc2 = tcase_create("model_set_get_property_label");
174 /* Create unit tests for set/get of property "label" and add it to the suite */
175 tcase_add_checked_fixture(tc1, fx_setup_default_find_toolbar, fx_teardown_find_toolbar);
176 tcase_add_test(tc1, test_set_get_property_label_regular);
177 tcase_add_test(tc1, test_set_get_property_label_invalid);
178 suite_add_tcase (s, tc1);
180 /* Create unit tests for set/get of property "label" and add it to the suite */
181 tcase_add_checked_fixture(tc2, fx_setup_model_find_toolbar, fx_teardown_find_toolbar);
182 tcase_add_test(tc2, test_set_get_property_label_regular);
183 tcase_add_test(tc2, test_set_get_property_label_invalid);
184 suite_add_tcase (s, tc2);
186 /* Return created suite */