2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
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; either 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
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtklabel.h>
27 #include "test_suites.h"
29 #include "hildon-program.h"
32 /* -------------------- Fixtures -------------------- */
34 static HildonProgram *program = NULL;
37 fx_setup_default_program ()
40 gtk_init(&argc, NULL);
42 program = hildon_program_get_instance();
43 /* Check program object has been created properly */
44 fail_if(!HILDON_IS_PROGRAM(program),
45 "hildon-program: Creation failed.");
50 fx_teardown_default_program ()
52 g_object_unref(program);
56 /* -------------------- Test cases -------------------- */
58 /* ----- Test case for hildon_program_add_window -----*/
61 * Purpose: Test regular usage of the add_window interface
63 * - Add a window object to the program
64 * - Add another window object to the program
65 * - Add the same window object to the program
67 START_TEST (test_add_window_regular)
70 HildonWindow *window1;
72 /* Test1: Add a window object to the program */
73 window = HILDON_WINDOW(hildon_window_new());
74 hildon_program_add_window(program, window);
76 /* Test2: Add another window object to the program */
77 window1 = HILDON_WINDOW(hildon_window_new());
78 hildon_program_add_window(program, window1);
80 /* Test3: Add the same window object to the program */
81 hildon_program_add_window(program, window);
82 hildon_program_remove_window(program, window);
84 gtk_widget_destroy (GTK_WIDGET (window));
85 gtk_widget_destroy (GTK_WIDGET (window1));
90 * Purpose: Check invalid values of the add_window interface
92 * - Add to a NULL program
94 * - Add a label instead of a window
96 START_TEST (test_add_window_invalid)
100 /* Test1: Add to a NULL program */
101 hildon_program_add_window(NULL, NULL);
103 /* Test2: Add a NULL window */
104 hildon_program_add_window(program, NULL);
106 /* Test3: Add a label instead of a window */
107 label = gtk_label_new("This is an invalid example widget");
108 hildon_program_add_window(program, HILDON_WINDOW(label));
110 gtk_widget_destroy (GTK_WIDGET (label));
114 /* ----- Test case for hildon_program_remove_window -----*/
117 * Purpose: Test regular usage of the remove_window interface
119 * - Add a window object to the program and remove it
120 * - Add another window object to the program and remove the first one
121 * - Remove a window two times
123 START_TEST (test_remove_window_regular)
125 HildonWindow *window;
126 HildonWindow *window1;
128 /* Test1: Add a window object to the program and remove it */
129 window = HILDON_WINDOW(hildon_window_new());
130 hildon_program_add_window(program, window);
131 hildon_program_remove_window(program, window);
133 /* Test2: Add another window object to the program and remove the first one */
134 window1 = HILDON_WINDOW(hildon_window_new());
135 hildon_program_add_window(program, window);
136 hildon_program_add_window(program, window1);
137 hildon_program_remove_window(program, window);
139 /* Test3: Remove a window two times */
140 hildon_program_remove_window(program, window1);
141 hildon_program_remove_window(program, window1);
143 gtk_widget_destroy (GTK_WIDGET (window));
144 gtk_widget_destroy (GTK_WIDGET (window1));
149 * Purpose: Check invalid values of the remove_window interface
151 * - Remove from a NULL program
152 * - Remove a NULL window
153 * - Remove a label instead of a window
155 START_TEST (test_remove_window_invalid)
159 /* Test1: Remove from a NULL program */
160 hildon_program_remove_window(NULL, NULL);
162 /* Test2: Remove a NULL window */
163 hildon_program_remove_window(program, NULL);
165 /* Test3: Remove a label instead of a window */
166 label = gtk_label_new("This is an invalid example widget");
167 hildon_program_remove_window(program, HILDON_WINDOW(label));
169 gtk_widget_destroy (GTK_WIDGET (label));
173 /* ----- Test case for hildon_program_set_can_hibernate -----*/
176 * Purpose: Test regular usage of the set_cant_hibernate interface
178 * - Test the initial value of the property, it must be FALSE
179 * - Set a value and test if the value is correct
181 START_TEST (test_set_can_hibernate_regular)
184 /* Test1: Test the initial value of the property, it must be FALSE */
185 fail_if(hildon_program_get_can_hibernate(program),
186 "hildon-program: The initial value of the hibernate property must be FALSE and it is not");
188 /* Test2: Set a value and test if the value is correct */
189 hildon_program_set_can_hibernate(program, TRUE);
190 fail_if(!hildon_program_get_can_hibernate(program),
191 "hildon-program: We set the hibernate property to TRUE and it is FALSE");
197 * Purpose: Check invalid values of the set_can_hibernate interface
199 * - Set the property to a NULL object
201 START_TEST (test_set_can_hibernate_invalid)
203 hildon_program_set_can_hibernate(NULL, TRUE);
207 /* ---------- Suite creation ---------- */
209 Suite *create_hildon_program_suite()
211 /* Create the suite */
212 Suite *s = suite_create("HildonProgram");
214 /* Create test cases */
215 TCase *tc1 = tcase_create("add_window");
216 TCase *tc2 = tcase_create("remove_window");
217 TCase *tc3 = tcase_create("set_can_hibernate");
219 /* Create test case for add_window and add it to the suite */
220 tcase_add_checked_fixture(tc1, fx_setup_default_program, fx_teardown_default_program);
221 tcase_add_test(tc1, test_add_window_regular);
222 tcase_add_test(tc1, test_add_window_invalid);
223 suite_add_tcase (s, tc1);
225 /* Create test case for remove_window and add it to the suite */
226 tcase_add_checked_fixture(tc2, fx_setup_default_program, fx_teardown_default_program);
227 tcase_add_test(tc2, test_remove_window_regular);
228 tcase_add_test(tc2, test_remove_window_invalid);
229 suite_add_tcase (s, tc2);
231 /* Create test case for set_can_hibernate and add it to the suite */
232 tcase_add_checked_fixture(tc3, fx_setup_default_program, fx_teardown_default_program);
233 tcase_add_test(tc3, test_set_can_hibernate_regular);
234 tcase_add_test(tc3, test_set_can_hibernate_invalid);
235 suite_add_tcase (s, tc3);
237 /* Return created suite */