Release 2.2.0 RC2
[hildon] / tests / check-hildon-program.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 <gtk/gtklabel.h>
29 #include "test_suites.h"
30
31 #include <hildon/hildon-program.h>
32
33
34 /* -------------------- Fixtures -------------------- */
35
36 static HildonProgram *program = NULL;
37
38 static void 
39 fx_setup_default_program ()
40 {
41   int argc = 0;
42   gtk_init(&argc, NULL);
43
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.");
48
49 }
50
51 static void 
52 fx_teardown_default_program ()
53 {
54   g_object_unref(program);
55 }
56
57
58 /* -------------------- Test cases -------------------- */
59
60 /* ----- Test case for hildon_program_add_window -----*/
61
62 /**
63  * Purpose: Test regular usage of the add_window interface
64  * Cases considered:
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
68  */
69 START_TEST (test_add_window_regular)
70 {
71   HildonWindow *window; 
72   HildonWindow *window1; 
73
74   /* Test1: Add a window object to the program */  
75   window = HILDON_WINDOW(hildon_window_new());
76   hildon_program_add_window(program, window);
77
78   /* Test2: Add another window object to the program */  
79   window1 = HILDON_WINDOW(hildon_window_new());
80   hildon_program_add_window(program, window1);
81
82   /* Test3: Add the same window object to the program */  
83   hildon_program_add_window(program, window);
84   hildon_program_remove_window(program, window);
85
86   gtk_widget_destroy (GTK_WIDGET (window));
87   gtk_widget_destroy (GTK_WIDGET (window1));
88 }
89 END_TEST
90
91 /**
92  * Purpose: Check invalid values of the add_window interface
93  * Cases considered:
94  *    - Add to a NULL program
95  *    - Add a NULL window
96  *    - Add a label instead of a window
97  */
98 START_TEST (test_add_window_invalid)
99 {
100   GtkWidget *label;
101
102   /* Test1: Add to a NULL program */  
103   hildon_program_add_window(NULL, NULL);
104
105   /* Test2: Add a NULL window */
106   hildon_program_add_window(program, NULL);
107
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));
111
112   gtk_widget_destroy (GTK_WIDGET (label));
113 }
114 END_TEST
115
116 /* ----- Test case for hildon_program_remove_window -----*/
117
118 /**
119  * Purpose: Test regular usage of the remove_window interface
120  * Cases considered:
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
124  */
125 START_TEST (test_remove_window_regular)
126 {
127   HildonWindow *window; 
128   HildonWindow *window1; 
129
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);
134
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);
140
141   /* Test3: Remove a window two times */  
142   hildon_program_remove_window(program, window1);
143   hildon_program_remove_window(program, window1);
144
145   gtk_widget_destroy (GTK_WIDGET (window));
146   gtk_widget_destroy (GTK_WIDGET (window1));
147 }
148 END_TEST
149
150 /**
151  * Purpose: Check invalid values of the remove_window interface
152  * Cases considered:
153  *    - Remove from a NULL program
154  *    - Remove a NULL window
155  *    - Remove a label instead of a window
156  */
157 START_TEST (test_remove_window_invalid)
158 {
159   GtkWidget *label;
160
161   /* Test1: Remove from a NULL program */
162   hildon_program_remove_window(NULL, NULL);
163
164   /* Test2: Remove a NULL window */  
165   hildon_program_remove_window(program, NULL);
166
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));
170
171   gtk_widget_destroy (GTK_WIDGET (label));
172 }
173 END_TEST
174
175 /* ----- Test case for hildon_program_set_can_hibernate -----*/
176
177 /**
178  * Purpose: Test regular usage of the set_cant_hibernate interface
179  * Cases considered:
180  *    - Test the initial value of the property, it must be FALSE
181  *    - Set a value and test if the value is correct
182  */
183 START_TEST (test_set_can_hibernate_regular)
184 {
185
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");
189
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");
194     
195 }
196 END_TEST
197
198 /**
199  * Purpose: Check invalid values of the set_can_hibernate interface
200  * Cases considered:
201  *    - Set the property to a NULL object
202  */
203 START_TEST (test_set_can_hibernate_invalid)
204 {
205   hildon_program_set_can_hibernate(NULL, TRUE);
206 }
207 END_TEST
208
209 /* ---------- Suite creation ---------- */
210
211 Suite *create_hildon_program_suite()
212 {
213   /* Create the suite */
214   Suite *s = suite_create("HildonProgram");
215
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");
220
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);
226
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);
232
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);
238
239   /* Return created suite */
240   return s;
241 }