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 <gtk/gtklabel.h>
29 #include "test_suites.h"
31 #include "hildon-program.h"
34 /* -------------------- Fixtures -------------------- */
36 static HildonProgram *program = NULL;
39 fx_setup_default_program ()
42 gtk_init(&argc, NULL);
44 program = hildon_program_get_instance();
45 /* Check program object has been created properly */
46 fail_if(!HILDON_IS_PROGRAM(program),
47 "hildon-program: Creation failed.");
52 fx_teardown_default_program ()
54 g_object_unref(program);
58 /* -------------------- Test cases -------------------- */
60 /* ----- Test case for hildon_program_add_window -----*/
63 * Purpose: Test regular usage of the add_window interface
65 * - Add a window object to the program
66 * - Add another window object to the program
67 * - Add the same window object to the program
69 START_TEST (test_add_window_regular)
72 HildonWindow *window1;
74 /* Test1: Add a window object to the program */
75 window = HILDON_WINDOW(hildon_window_new());
76 hildon_program_add_window(program, window);
78 /* Test2: Add another window object to the program */
79 window1 = HILDON_WINDOW(hildon_window_new());
80 hildon_program_add_window(program, window1);
82 /* Test3: Add the same window object to the program */
83 hildon_program_add_window(program, window);
84 hildon_program_remove_window(program, window);
86 gtk_widget_destroy (GTK_WIDGET (window));
87 gtk_widget_destroy (GTK_WIDGET (window1));
92 * Purpose: Check invalid values of the add_window interface
94 * - Add to a NULL program
96 * - Add a label instead of a window
98 START_TEST (test_add_window_invalid)
102 /* Test1: Add to a NULL program */
103 hildon_program_add_window(NULL, NULL);
105 /* Test2: Add a NULL window */
106 hildon_program_add_window(program, NULL);
108 /* Test3: Add a label instead of a window */
109 label = gtk_label_new("This is an invalid example widget");
110 hildon_program_add_window(program, HILDON_WINDOW(label));
112 gtk_widget_destroy (GTK_WIDGET (label));
116 /* ----- Test case for hildon_program_remove_window -----*/
119 * Purpose: Test regular usage of the remove_window interface
121 * - Add a window object to the program and remove it
122 * - Add another window object to the program and remove the first one
123 * - Remove a window two times
125 START_TEST (test_remove_window_regular)
127 HildonWindow *window;
128 HildonWindow *window1;
130 /* Test1: Add a window object to the program and remove it */
131 window = HILDON_WINDOW(hildon_window_new());
132 hildon_program_add_window(program, window);
133 hildon_program_remove_window(program, window);
135 /* Test2: Add another window object to the program and remove the first one */
136 window1 = HILDON_WINDOW(hildon_window_new());
137 hildon_program_add_window(program, window);
138 hildon_program_add_window(program, window1);
139 hildon_program_remove_window(program, window);
141 /* Test3: Remove a window two times */
142 hildon_program_remove_window(program, window1);
143 hildon_program_remove_window(program, window1);
145 gtk_widget_destroy (GTK_WIDGET (window));
146 gtk_widget_destroy (GTK_WIDGET (window1));
151 * Purpose: Check invalid values of the remove_window interface
153 * - Remove from a NULL program
154 * - Remove a NULL window
155 * - Remove a label instead of a window
157 START_TEST (test_remove_window_invalid)
161 /* Test1: Remove from a NULL program */
162 hildon_program_remove_window(NULL, NULL);
164 /* Test2: Remove a NULL window */
165 hildon_program_remove_window(program, NULL);
167 /* Test3: Remove a label instead of a window */
168 label = gtk_label_new("This is an invalid example widget");
169 hildon_program_remove_window(program, HILDON_WINDOW(label));
171 gtk_widget_destroy (GTK_WIDGET (label));
175 /* ----- Test case for hildon_program_set_can_hibernate -----*/
178 * Purpose: Test regular usage of the set_cant_hibernate interface
180 * - Test the initial value of the property, it must be FALSE
181 * - Set a value and test if the value is correct
183 START_TEST (test_set_can_hibernate_regular)
186 /* Test1: Test the initial value of the property, it must be FALSE */
187 fail_if(hildon_program_get_can_hibernate(program),
188 "hildon-program: The initial value of the hibernate property must be FALSE and it is not");
190 /* Test2: Set a value and test if the value is correct */
191 hildon_program_set_can_hibernate(program, TRUE);
192 fail_if(!hildon_program_get_can_hibernate(program),
193 "hildon-program: We set the hibernate property to TRUE and it is FALSE");
199 * Purpose: Check invalid values of the set_can_hibernate interface
201 * - Set the property to a NULL object
203 START_TEST (test_set_can_hibernate_invalid)
205 hildon_program_set_can_hibernate(NULL, TRUE);
209 /* ---------- Suite creation ---------- */
211 Suite *create_hildon_program_suite()
213 /* Create the suite */
214 Suite *s = suite_create("HildonProgram");
216 /* Create test cases */
217 TCase *tc1 = tcase_create("add_window");
218 TCase *tc2 = tcase_create("remove_window");
219 TCase *tc3 = tcase_create("set_can_hibernate");
221 /* Create test case for add_window and add it to the suite */
222 tcase_add_checked_fixture(tc1, fx_setup_default_program, fx_teardown_default_program);
223 tcase_add_test(tc1, test_add_window_regular);
224 tcase_add_test(tc1, test_add_window_invalid);
225 suite_add_tcase (s, tc1);
227 /* Create test case for remove_window and add it to the suite */
228 tcase_add_checked_fixture(tc2, fx_setup_default_program, fx_teardown_default_program);
229 tcase_add_test(tc2, test_remove_window_regular);
230 tcase_add_test(tc2, test_remove_window_invalid);
231 suite_add_tcase (s, tc2);
233 /* Create test case for set_can_hibernate and add it to the suite */
234 tcase_add_checked_fixture(tc3, fx_setup_default_program, fx_teardown_default_program);
235 tcase_add_test(tc3, test_set_can_hibernate_regular);
236 tcase_add_test(tc3, test_set_can_hibernate_invalid);
237 suite_add_tcase (s, tc3);
239 /* Return created suite */