Make sure that all timeouts in HildonBanner are removed
[hildon] / tests / check-hildon-range-editor.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
31 #include <hildon/hildon-range-editor.h>
32 #include <unistd.h>
33
34 /* -------------------- Fixtures -------------------- */
35
36 static GtkWidget *showed_window = NULL;
37 static HildonRangeEditor *range_editor = NULL;
38
39 static void
40 fx_setup_default_range_editor ()
41 {
42   int argc = 0;
43   gtk_init(&argc, NULL);
44
45   range_editor = HILDON_RANGE_EDITOR(hildon_range_editor_new());
46
47   showed_window =  create_test_window ();
48
49   /* This packs the widget into the window (a gtk container). */
50   gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (range_editor));
51
52   /* Displays the widget and the window */
53   show_all_test_window (showed_window);
54
55   /* Check range_editor object has been created properly */
56   fail_if(!HILDON_IS_RANGE_EDITOR(range_editor),
57           "hildon-range-editor: Creation failed.");
58
59
60   while (gtk_events_pending ())
61     {
62       gtk_main_iteration ();
63     }
64
65 }
66
67 static void 
68 fx_teardown_default_range_editor ()
69 {
70
71   /* Destroy the window */
72   gtk_widget_destroy (showed_window);
73 }
74
75 /* -------------------- Test cases -------------------- */
76
77 /* ----- Test case for set_limit, get_min, get_max -----*/
78
79 /**
80  * Purpose: Check that regular range limit values are set and get properly
81  * Cases considered:
82  *    - Set limits to (-10,10) and get min/max using the range editor object
83  *    - Set limits to (0,10) and get min/max using the range editor object
84  *    - Set limits to (-10,0) and get min/max using the range editor object
85  *    - Set limits to (1,10) and get min/max using the range editor object
86  *    - Set limits to (-10,-10) and get min/max using the range editor object
87  */
88 START_TEST (test_set_limits_get_min_get_max_regular)
89 {
90   gint range_start, range_end;
91
92   /* Test1: Set limits to (-10,10) */
93   hildon_range_editor_set_limits(range_editor, -10, 10);
94   range_start = hildon_range_editor_get_min(range_editor);
95   fail_if(range_start != -10, 
96           "hildon-range-editor: set limits to (-10,10) but get_min didn't return -10");
97   range_end = hildon_range_editor_get_max(range_editor);
98   fail_if(range_end != 10, 
99           "hildon-range-editor: set limits to (-10,10) but get_max didn't return 10");
100
101   /* Test2: Set limits to (0,10) */
102   hildon_range_editor_set_limits(range_editor, 0, 10);
103   range_start = hildon_range_editor_get_min(range_editor);
104   fail_if(range_start != 0, 
105           "hildon-range-editor: set limits to (0,10) but get_min didn't return 0");
106   range_end = hildon_range_editor_get_max(range_editor);
107   fail_if(range_end != 10, 
108           "hildon-range-editor: set limits to (0,10) but get_max didn't return 10");
109
110   /* Test3: Set limits to (-10,0) */
111   hildon_range_editor_set_limits(range_editor, -10, 0);
112   range_start = hildon_range_editor_get_min(range_editor);
113   fail_if(range_start != -10, 
114           "hildon-range-editor: set limits to (-10,0) but get_min didn't return -10");
115   range_end = hildon_range_editor_get_max(range_editor);
116   fail_if(range_end != 0, 
117           "hildon-range-editor: set limits to (-10,0) but get_max didn't return 0");
118
119   /* Test4: Set limits to (1,10) */
120   hildon_range_editor_set_limits(range_editor, 1, 10);
121   range_start = hildon_range_editor_get_min(range_editor);
122   fail_if(range_start != 1, 
123           "hildon-range-editor: set limits to (1,10) but get_min didn't return 1");
124   range_end = hildon_range_editor_get_max(range_editor);
125   fail_if(range_end != 10, 
126           "hildon-range-editor: set limits to (1,10) but get_max didn't return 10");
127
128   /* Test5: Set limits to (-10,-1) */
129   hildon_range_editor_set_limits(range_editor, -10, -1);
130   range_start = hildon_range_editor_get_min(range_editor);
131   fail_if(range_start != -10, 
132           "hildon-range-editor: set limits to (-10,-1) but get_min didn't return -10");
133   range_end = hildon_range_editor_get_max(range_editor);
134   fail_if(range_end != -1, 
135           "hildon-range-editor: set limits to (-10,-1) but get_max didn't return -1");
136 }
137 END_TEST
138
139 /**
140  * Purpose: Check that range limit values are set and get properly
141  * Cases considered:
142  *    - Set limits to (G_MININT,G_MAXINT) and get min/max using the range editor object
143  */
144 START_TEST (test_set_limits_get_min_get_max_limits)
145 {
146   gint range_start, range_end;
147
148   /* Test1: Set limits to (G_MININT,G_MAXINT) */
149   hildon_range_editor_set_limits(range_editor, G_MININT, G_MAXINT);
150   range_start = hildon_range_editor_get_min(range_editor);
151   fail_if(range_start != G_MININT, 
152           "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_min didn't return G_MININT");
153   range_end = hildon_range_editor_get_max(range_editor);
154   fail_if(range_end != G_MAXINT, 
155           "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_max didn't return G_MAXINT");
156 }
157 END_TEST
158
159 /**
160  * Purpose: Check that invalid values are handled properly
161  * Cases considered:
162  *    - Set inverted limits (10,-10)
163  *    - Set range editor object to NULL for set_limits
164  *    - Set range editor object to NULL for get_min and get_max
165  */
166 START_TEST (test_set_limits_get_min_get_max_invalid)
167 {
168   gint range_start, range_end;
169
170   /* Test1: Set limits to (10,-10) */
171   hildon_range_editor_set_limits(range_editor, 10, -10);
172   range_start = hildon_range_editor_get_min(range_editor);
173   fail_if(range_start != -10, 
174           "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_min didn't return -10");
175   range_end = hildon_range_editor_get_max(range_editor);
176   fail_if(range_end != -10, 
177           "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_max didn't return -1");
178
179   /* Test2: set range editor to NULL for set_limits. */
180   hildon_range_editor_set_limits(NULL, 100, -100);
181
182   /* Test3: set range editor to NULL for get_min and get_max */
183   range_start = hildon_range_editor_get_min(NULL);
184   fail_if(range_start != 0, 
185           "hildon-range-editor: setting range editor to NULL produced get_min to return a value != 0");
186   range_end = hildon_range_editor_get_max(NULL);
187   fail_if(range_end != 0, 
188           "hildon-range-editor: setting range editor to NULL produced get_max to return a value != 0");
189 }
190 END_TEST
191
192
193 /* ----- Test case for set_min -----*/
194
195 /**
196  * Purpose: Check regular minimum values for limits are set properly
197  * Cases considered:
198  *    - Set min limit to -100
199  *    - Set min limit to 0
200  *    - Set min limit to 100
201  */
202 START_TEST (test_set_min_regular)
203 {
204   gint range_start;
205
206   /* Test1: Set min limits -100 */
207   hildon_range_editor_set_min(range_editor, -100);
208   range_start = hildon_range_editor_get_min(range_editor);
209   fail_if(range_start != -100, 
210           "hildon-range-editor: set min limit to -100 but get_min didn't return -100");
211
212   /* Test2: Set min limits 0 */
213   hildon_range_editor_set_min(range_editor, 0);
214   range_start = hildon_range_editor_get_min(range_editor);
215   fail_if(range_start != 0, 
216           "hildon-range-editor: set min limit to 0 but get_min didn't return 0");
217
218   /* Test3: Set min limits 100 */
219   hildon_range_editor_set_min(range_editor, 100);
220   range_start = hildon_range_editor_get_min(range_editor);
221   fail_if(range_start != 100, 
222           "hildon-range-editor: set min limit to 100 but get_min didn't return 100");
223 }
224 END_TEST
225
226 /**
227  * Purpose: Check limit minimum values for limits are set properly
228  * Cases considered:
229  *    - Set min limit to G_MININT
230  */
231 START_TEST (test_set_min_limits)
232 {
233   gint range_start;
234
235   /* Test1: Set min limit to G_MININT */
236   hildon_range_editor_set_min(range_editor, G_MININT);
237   range_start = hildon_range_editor_get_min(range_editor);
238   fail_if(range_start != G_MININT, 
239           "hildon-range-editor: set min limit to G_MININT but get_min didn't return G_MININT");
240 }
241 END_TEST
242
243 /**
244  * Purpose: Check that invalid values are handled properly
245  * Cases considered:
246  *    - Set minimum limit greater than maximum limit
247  *    - Set range editor object to NULL for set_min
248  */
249 START_TEST (test_set_min_invalid)
250 {
251   gint range_start, range_end;
252
253   /* Test1: Set minimum limit greater than maximum limit */
254   hildon_range_editor_set_limits(range_editor, -10, 10);
255   hildon_range_editor_set_min(range_editor, 15);
256   range_start = hildon_range_editor_get_min(range_editor);
257   fail_if(range_start != 15, 
258           "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_min didn't return 15");
259   range_end = hildon_range_editor_get_max(range_editor);
260   fail_if(range_end != 15, 
261           "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_max didn't return 15");
262
263   /* Test2: set range editor to NULL */
264   hildon_range_editor_set_min(NULL, 15);
265 }
266 END_TEST
267
268
269 /* ----- Test case for set_max -----*/
270
271 /**
272  * Purpose: Check regular maximum values for limits are set properly
273  * Cases considered:
274  *    - Set max limit to -100
275  *    - Set max limit to 0
276  *    - Set max limit to 100
277  */
278 START_TEST (test_set_max_regular)
279 {
280   gint range_end;
281
282   /* Test1: Set max limits -100 */
283   hildon_range_editor_set_max(range_editor, -100);
284   range_end = hildon_range_editor_get_max(range_editor);
285   fail_if(range_end != -100, 
286           "hildon-range-editor: set max limit to -100 but get_max didn't return -100");
287
288   /* Test2: Set max limits 0 */
289   hildon_range_editor_set_max(range_editor, 0);
290   range_end = hildon_range_editor_get_max(range_editor);
291   fail_if(range_end != 0, 
292           "hildon-range-editor: set max limit to 0 but get_max didn't return 0");
293
294   /* Test3: Set max limits 100 */
295   hildon_range_editor_set_max(range_editor, 100);
296   range_end = hildon_range_editor_get_max(range_editor);
297   fail_if(range_end != 100, 
298           "hildon-range-editor: set max limit to 100 but get_max didn't return 100");
299 }
300 END_TEST
301
302 /**
303  * Purpose: Check limit maximum values for limits are set properly
304  * Cases considered:
305  *    - Set min limit to G_MAXINT
306  */
307 START_TEST (test_set_max_limits)
308 {
309   gint range_end;
310
311   /* Test1: Set max limit to G_MAXINT */
312   hildon_range_editor_set_max(range_editor, G_MAXINT);
313   range_end = hildon_range_editor_get_max(range_editor);
314   fail_if(range_end != G_MAXINT, 
315           "hildon-range-editor: set min limit to G_MAXINT but get_max didn't return G_MAXINT");
316 }
317 END_TEST
318
319 /**
320  * Purpose: Check that invalid values are handled properly
321  * Cases considered:
322  *    - Set maximum limit lower than minimum limit
323  *    - Set range editor object to NULL for set_max
324  */
325 START_TEST (test_set_max_invalid)
326 {
327   gint range_start, range_end;
328
329   /* Test1: Set maximum limit lower than minimum limit */
330   hildon_range_editor_set_limits(range_editor, -10, 10);
331   hildon_range_editor_set_max(range_editor, -15);
332   range_start = hildon_range_editor_get_min(range_editor);
333   fail_if(range_start != -15, 
334           "hildon-range-editor: set max limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_min didn't return -15");
335   range_end = hildon_range_editor_get_max(range_editor);
336   fail_if(range_end != -15, 
337           "hildon-range-editor: set min limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_max didn't return -15");
338
339   /* Test2: set range editor to NULL */
340   hildon_range_editor_set_max(NULL, 15);
341 }
342 END_TEST
343
344
345 /* ---------- Suite creation ---------- */
346
347 Suite *create_hildon_range_editor_suite()
348 {
349   /* Create the suite */
350   Suite *s = suite_create("HildonRangeEditor");
351
352   /* Create test cases */
353   TCase *tc1 = tcase_create("set_limits_get_min_get_max");
354   TCase *tc2 = tcase_create("set_min");
355   TCase *tc3 = tcase_create("set_max");
356
357   /* Create test case for set_limits, get_min and get_max and add it to the suite */
358   tcase_add_checked_fixture(tc1, fx_setup_default_range_editor, fx_teardown_default_range_editor);
359   tcase_add_test(tc1, test_set_limits_get_min_get_max_regular);
360   tcase_add_test(tc1, test_set_limits_get_min_get_max_limits);
361   tcase_add_test(tc1, test_set_limits_get_min_get_max_invalid);
362   suite_add_tcase (s, tc1);
363
364   /* Create test case for set_min */
365   tcase_add_checked_fixture(tc2, fx_setup_default_range_editor, fx_teardown_default_range_editor);
366   tcase_add_test(tc2, test_set_min_regular);
367   tcase_add_test(tc2, test_set_min_limits);
368   tcase_add_test(tc2, test_set_min_invalid);
369   suite_add_tcase (s, tc2);
370
371   /* Create test case for set_max */
372   tcase_add_checked_fixture(tc3, fx_setup_default_range_editor, fx_teardown_default_range_editor);
373   tcase_add_test(tc3, test_set_max_regular);
374   tcase_add_test(tc3, test_set_max_limits);
375   tcase_add_test(tc3, test_set_max_invalid);
376   suite_add_tcase (s, tc3);
377
378   /* Return created suite */
379   return s;
380 }
381
382