Release 2.2.0 RC2
[hildon] / tests / check-hildon-find-toolbar.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include <stdlib.h>
26 #include <check.h>
27 #include <gtk/gtkmain.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30 #include <string.h>
31
32 #include <hildon/hildon-find-toolbar.h>
33 #include <hildon/hildon-window.h>
34
35 /* -------------------- Fixtures -------------------- */
36
37 static HildonFindToolbar *find_toolbar = NULL;
38 static GtkWidget *showed_window = NULL;
39
40 static void 
41 fx_setup_default_find_toolbar ()
42 {
43   int argc = 0;
44   gtk_init(&argc, NULL);
45
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.");
51
52   showed_window =  create_test_window ();
53   
54   hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));
55
56   /* Displays the widget and the window */
57   show_all_test_window (showed_window);
58
59 }
60
61 static void 
62 fx_setup_model_find_toolbar ()
63 {
64   int argc = 0;
65   GtkListStore *model;
66   GtkTreeIter iter;
67   GValue value = {0,};
68
69   gtk_init(&argc, NULL);
70
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.");
81
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);
85
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");
88
89   showed_window =  create_test_window ();
90   
91   hildon_window_add_toolbar(HILDON_WINDOW(showed_window), GTK_TOOLBAR(find_toolbar));
92
93   /* Displays the widget and the window */
94   show_all_test_window (showed_window);
95 }
96
97 static void 
98 fx_teardown_find_toolbar()
99 {
100
101   gtk_widget_destroy(GTK_WIDGET(showed_window)); 
102   
103 }
104
105 /* -------------------- Test cases -------------------- */
106
107 /* ----- Test case for set/get_property "label"  -----*/
108
109 /**
110  * Purpose: Check that property "label" is set and get properly.
111  * Cases considered:
112  *    - Set and get with a regular string
113  *    - Set and get with value ""
114  */
115 START_TEST (test_set_get_property_label_regular)
116 {
117   GValue value_set = {0,};
118   GValue value_get = {0,};
119
120   g_value_init(&value_set,G_TYPE_STRING);
121   g_value_init(&value_get,G_TYPE_STRING);
122
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));
130
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));
138 }
139 END_TEST
140
141 /**
142  * Purpose: Check handling of invalid values for property "label"
143  * Cases considered:
144  *    - Set and get with NULL value
145  */
146 START_TEST (test_set_get_property_label_invalid)
147 {
148   GValue value_set = {0,};
149   GValue value_get = {0,};
150
151   g_value_init(&value_set,G_TYPE_STRING);
152
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));
160 }
161 END_TEST
162
163 /* ---------- Suite creation ---------- */
164
165 Suite *create_hildon_find_toolbar_suite()
166 {
167   /* Create the suite */
168   Suite *s = suite_create("HildonFindToolbar");
169
170   /* Create test cases */
171   TCase *tc1 = tcase_create("set_get_property_label");
172   TCase *tc2 = tcase_create("model_set_get_property_label");
173
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);
179
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);
185
186   /* Return created suite */
187   return s;
188 }