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