Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-program.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
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.
10  *
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.
15  *
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
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdlib.h>
24 #include <check.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtklabel.h>
27 #include "test_suites.h"
28
29 #include "hildon-program.h"
30
31
32 /* -------------------- Fixtures -------------------- */
33
34 static HildonProgram *program = NULL;
35
36 static void 
37 fx_setup_default_program ()
38 {
39   int argc = 0;
40   gtk_init(&argc, NULL);
41
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.");
46
47 }
48
49 static void 
50 fx_teardown_default_program ()
51 {
52   g_object_unref(program);
53 }
54
55
56 /* -------------------- Test cases -------------------- */
57
58 /* ----- Test case for hildon_program_add_window -----*/
59
60 /**
61  * Purpose: Test regular usage of the add_window interface
62  * Cases considered:
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
66  */
67 START_TEST (test_add_window_regular)
68 {
69   HildonWindow *window; 
70   HildonWindow *window1; 
71
72   /* Test1: Add a window object to the program */  
73   window = HILDON_WINDOW(hildon_window_new());
74   hildon_program_add_window(program, window);
75
76   /* Test2: Add another window object to the program */  
77   window1 = HILDON_WINDOW(hildon_window_new());
78   hildon_program_add_window(program, window1);
79
80   /* Test3: Add the same window object to the program */  
81   hildon_program_add_window(program, window);
82   hildon_program_remove_window(program, window);
83
84   gtk_widget_destroy (GTK_WIDGET (window));
85   gtk_widget_destroy (GTK_WIDGET (window1));
86 }
87 END_TEST
88
89 /**
90  * Purpose: Check invalid values of the add_window interface
91  * Cases considered:
92  *    - Add to a NULL program
93  *    - Add a NULL window
94  *    - Add a label instead of a window
95  */
96 START_TEST (test_add_window_invalid)
97 {
98   GtkWidget *label;
99
100   /* Test1: Add to a NULL program */  
101   hildon_program_add_window(NULL, NULL);
102
103   /* Test2: Add a NULL window */
104   hildon_program_add_window(program, NULL);
105
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));
109
110   gtk_widget_destroy (GTK_WIDGET (label));
111 }
112 END_TEST
113
114 /* ----- Test case for hildon_program_remove_window -----*/
115
116 /**
117  * Purpose: Test regular usage of the remove_window interface
118  * Cases considered:
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
122  */
123 START_TEST (test_remove_window_regular)
124 {
125   HildonWindow *window; 
126   HildonWindow *window1; 
127
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);
132
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);
138
139   /* Test3: Remove a window two times */  
140   hildon_program_remove_window(program, window1);
141   hildon_program_remove_window(program, window1);
142
143   gtk_widget_destroy (GTK_WIDGET (window));
144   gtk_widget_destroy (GTK_WIDGET (window1));
145 }
146 END_TEST
147
148 /**
149  * Purpose: Check invalid values of the remove_window interface
150  * Cases considered:
151  *    - Remove from a NULL program
152  *    - Remove a NULL window
153  *    - Remove a label instead of a window
154  */
155 START_TEST (test_remove_window_invalid)
156 {
157   GtkWidget *label;
158
159   /* Test1: Remove from a NULL program */
160   hildon_program_remove_window(NULL, NULL);
161
162   /* Test2: Remove a NULL window */  
163   hildon_program_remove_window(program, NULL);
164
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));
168
169   gtk_widget_destroy (GTK_WIDGET (label));
170 }
171 END_TEST
172
173 /* ----- Test case for hildon_program_set_can_hibernate -----*/
174
175 /**
176  * Purpose: Test regular usage of the set_cant_hibernate interface
177  * Cases considered:
178  *    - Test the initial value of the property, it must be FALSE
179  *    - Set a value and test if the value is correct
180  */
181 START_TEST (test_set_can_hibernate_regular)
182 {
183
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");
187
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");
192     
193 }
194 END_TEST
195
196 /**
197  * Purpose: Check invalid values of the set_can_hibernate interface
198  * Cases considered:
199  *    - Set the property to a NULL object
200  */
201 START_TEST (test_set_can_hibernate_invalid)
202 {
203   hildon_program_set_can_hibernate(NULL, TRUE);
204 }
205 END_TEST
206
207 /* ---------- Suite creation ---------- */
208
209 Suite *create_hildon_program_suite()
210 {
211   /* Create the suite */
212   Suite *s = suite_create("HildonProgram");
213
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");
218
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);
224
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);
230
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);
236
237   /* Return created suite */
238   return s;
239 }