Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-seekbar.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/gtkcontainer.h>
27 #include <glib/gprintf.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30
31 #include "hildon-seekbar.h"
32
33 /* -------------------- Fixtures -------------------- */
34
35 static GtkWidget *showed_window = NULL;
36 static HildonSeekbar *seekbar = NULL;
37
38 static void 
39 fx_setup_default_seekbar ()
40 {
41   int argc = 0;
42   gtk_init(&argc, NULL);
43
44   seekbar = HILDON_SEEKBAR(hildon_seekbar_new());
45
46   showed_window =  create_test_window ();
47
48   /* This packs the widget into the window (a gtk container). */
49   gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (seekbar));
50
51   /* Displays the widget and the window */
52   show_all_test_window (showed_window);
53
54   /* Check that the seekbar object has been created properly */
55   fail_if(!HILDON_SEEKBAR(seekbar),
56           "hildon-seekbar: Creation failed.");
57 }
58
59 static void 
60 fx_teardown_default_seekbar ()
61 {
62
63   /* Destroy the window */
64   gtk_widget_destroy (showed_window);
65 }
66
67 /* -------------------- Test cases -------------------- */
68
69 /* ----- Test case for set_time -----*/
70
71 /**
72  * Purpose: test setting regular time values for hildon_seekbar_set_time
73  * Cases considered:
74  *    - Set and get 1000 seconds without setting new position and fraction.
75  *    - Set and get 500 seconds setting without setting new position but new fraction should be set.
76  *    - Set and get 500 seconds setting without setting new position but new fraction should be set.
77  */
78 START_TEST (test_set_time_regular)
79 {
80   gint ret_seconds;
81   gint seconds;
82   gint position;
83   gint fraction;
84
85   /* Test 1: Set and get 1000 seconds without setting new position and fraction */
86   seconds = 1000;
87   hildon_seekbar_set_total_time(seekbar,seconds);
88   ret_seconds=hildon_seekbar_get_total_time(seekbar);
89
90   fail_if(ret_seconds != seconds, 
91           "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
92           seconds,ret_seconds);
93
94
95   /* Test 2: Set and get 500 seconds with a fraction set to 750 and position set to 750 (in order to test the correct update of 
96      position and fraction.    */
97   seconds = 500;
98   position = 750;
99   fraction = 750;
100
101   hildon_seekbar_set_fraction(seekbar,fraction);
102   fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
103           "hildon-seekbar: set total time to %d but get_fraction returns %d ",
104           fraction,hildon_seekbar_get_fraction(seekbar));
105
106   hildon_seekbar_set_position(seekbar,position);
107   fail_if(position != hildon_seekbar_get_position(seekbar), 
108           "hildon-seekbar: set total time to %d but get_position returns %d",
109           position,hildon_seekbar_get_position(seekbar));
110
111   hildon_seekbar_set_total_time(seekbar,seconds);
112   fail_if(seconds != hildon_seekbar_get_fraction(seekbar), 
113           "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
114           seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
115
116   fail_if(seconds != hildon_seekbar_get_position(seekbar), 
117           "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
118           seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
119
120   ret_seconds=hildon_seekbar_get_total_time(seekbar);
121   fail_if(ret_seconds != seconds, 
122           "hildon-seekbar: set total time to %d but get_total_time returns %d ",
123           seconds,ret_seconds);   
124
125   /* Test 3: Set and get 500 seconds with a fraction set to 750 and position set to 250 (in order to test the correct update of 
126      position and fraction.
127   */
128   seconds = 1000;
129   hildon_seekbar_set_total_time(seekbar,seconds);
130
131   seconds = 500;
132   position = 250;
133   fraction = 750;
134
135   hildon_seekbar_set_fraction(seekbar,fraction);
136   fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
137           "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d ",
138           fraction,hildon_seekbar_get_fraction(seekbar));
139
140   hildon_seekbar_set_position(seekbar,position);
141   fail_if(position != hildon_seekbar_get_position(seekbar), 
142           "hildon-seekbar: set seekbar position to %d but get_position returns %d",
143           position,hildon_seekbar_get_position(seekbar));
144
145   hildon_seekbar_set_total_time(seekbar,seconds);
146   fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
147           "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d being total time %d",
148           seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
149
150   ret_seconds=hildon_seekbar_get_total_time(seekbar);
151   fail_if(ret_seconds != seconds, 
152           "hildon-seekbar: set total time to %d but get_total_time returns %d ",
153           seconds,ret_seconds);
154 }
155 END_TEST
156
157 /**
158  * Purpose: test setting limit time values for hildon_seekbar_set_time
159  * Cases considered:
160  *    - Set and get 0 seconds setting new position and fraction (previously set to 750).
161  *    - Set and get G_MAXINT seconds without setting new position and fraction.
162  */
163 START_TEST (test_set_time_limits)
164 {
165   gint ret_seconds;
166   gint seconds;
167   gint position;
168   gint fraction;
169
170   seconds = 1000;
171   hildon_seekbar_set_total_time(seekbar,seconds);
172     
173   position = 750;
174   fraction = 750;
175
176   hildon_seekbar_set_fraction(seekbar,fraction);
177   hildon_seekbar_set_position(seekbar,position);
178
179   /* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/
180   seconds = 1;
181   hildon_seekbar_set_total_time(seekbar,seconds);
182   ret_seconds=hildon_seekbar_get_total_time(seekbar);
183
184   fail_if(ret_seconds != seconds, 
185           "hildon-seekbar: set seekbar total time to %d should return %d but get_total_time returns %d",
186           seconds,ret_seconds);
187
188   /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
189   fail_if(seconds != hildon_seekbar_get_fraction(seekbar), 
190           "hildon-seekbar: set time to %d but get_fraction returns %d ",
191           seconds,hildon_seekbar_get_fraction(seekbar));
192
193   /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
194   fail_if(seconds != hildon_seekbar_get_position(seekbar), 
195           "hildon-seekbar: set time to %d but get_position returns %d",
196           seconds,hildon_seekbar_get_position(seekbar));
197
198   /* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */
199   seconds = G_MAXINT;
200   hildon_seekbar_set_total_time(seekbar,seconds);
201   ret_seconds=hildon_seekbar_get_total_time(seekbar);
202
203   fail_if(ret_seconds != seconds, 
204           "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
205           seconds,ret_seconds);
206     
207     
208 }
209 END_TEST
210
211
212 /**
213  * Purpose: test setting invalid time values for hildon_seekbar_set_time
214  * Cases considered:
215  *    - Set and get seconds to a NULL object.
216  *    - Set and get 0 seconds without setting new position and fraction.
217  *    - Set and get -1 seconds without setting new position and fraction.
218  */
219 START_TEST (test_set_time_invalid)
220 {
221   gint init_seconds;
222   gint ret_seconds;
223   gint seconds;
224
225   init_seconds = 1000;
226   /* Test 1: Set/get seconds on NULL object */
227   hildon_seekbar_set_total_time(NULL,init_seconds);
228   ret_seconds=hildon_seekbar_get_total_time(NULL);
229
230   /* Init seekbar to 1000 seconds*/
231   hildon_seekbar_set_total_time(seekbar,init_seconds);
232     
233
234   /* Test 2: Set and get 0 seconds */
235   seconds = 0;
236   hildon_seekbar_set_total_time(seekbar,seconds);
237   ret_seconds=hildon_seekbar_get_total_time(seekbar);
238
239   fail_if(ret_seconds != init_seconds, 
240           "hildon-seekbar: set seekbar total time to %d, should set %d but get_total_time returns %d",
241           seconds,init_seconds,ret_seconds);
242
243   /* Test 3: Set and get -1 seconds */
244   seconds = -1;
245   hildon_seekbar_set_total_time(seekbar,seconds);
246   ret_seconds=hildon_seekbar_get_total_time(seekbar);
247
248   fail_if(ret_seconds != init_seconds, 
249           "hildon-seekbar: set seekbar total time to %d, should return %d but get_total_time returns %d",
250           seconds,init_seconds,ret_seconds);
251     
252 }
253 END_TEST
254
255 /* ----- Test case for set_fraction -----*/
256
257 /**
258  * Purpose: test setting regular fraction values for hildon_seekbar_set_fraction
259  * Cases considered:
260  *    - Set and get fraction to 500 with total time set to 1000.
261  *    - Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500.
262  */
263 START_TEST (test_set_fraction_regular)
264 {
265   gint ret_seconds;
266   gint init_seconds;
267   gint seconds;
268
269   /* Init seekbar to 1000 */
270   init_seconds = 1000;
271   hildon_seekbar_set_total_time(seekbar,init_seconds);
272
273   /* Test 1: Set and get fraction to 500 with total time set to 1000 */
274   seconds = 500;
275   hildon_seekbar_set_fraction(seekbar,seconds);
276   ret_seconds=hildon_seekbar_get_fraction(seekbar);
277
278   fail_if(ret_seconds != seconds, 
279           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
280           seconds,ret_seconds);
281
282   /* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */
283   seconds = 500;
284
285   hildon_seekbar_set_fraction(seekbar,seconds);
286   hildon_seekbar_set_position(seekbar,seconds);
287
288   hildon_seekbar_set_fraction(seekbar,seconds-10);
289
290   ret_seconds=hildon_seekbar_get_fraction(seekbar);
291
292   fail_if(ret_seconds != seconds-10, 
293           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
294           seconds,ret_seconds);
295
296   fail_if(hildon_seekbar_get_position(seekbar) != seconds-10, 
297           "hildon-seekbar: set seekbar fraction to %d but get seekbar position returns %d",
298           seconds-10,hildon_seekbar_get_position(seekbar));
299     
300 }
301 END_TEST
302
303 /**
304  * Purpose: test setting limit fraction values for hildon_seekbar_set_fraction
305  * Cases considered:
306  *    - Set and get fraction to 0 with total time set to G_MAXINT.
307  *    - Set and get fraction to 1 with total time set to G_MAXINT.
308  *    - Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT.
309  *    - Set and get fraction to G_MAXINT with total time set to G_MAXINT.
310  */
311 START_TEST (test_set_fraction_limits)
312 {
313   gint ret_seconds;
314   gint seconds;
315   gint init_seconds;
316
317   /* Init seekbar to G_MAXINT total time */
318   init_seconds = G_MAXINT;
319   hildon_seekbar_set_total_time(seekbar,init_seconds);
320
321   /* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */
322   seconds = 0;
323   hildon_seekbar_set_fraction(seekbar,seconds);
324   ret_seconds=hildon_seekbar_get_fraction(seekbar);
325
326   fail_if(ret_seconds != seconds, 
327           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
328           seconds,ret_seconds);
329
330   /* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */
331   seconds = 1;
332   hildon_seekbar_set_fraction(seekbar,seconds);
333   ret_seconds=hildon_seekbar_get_fraction(seekbar);
334
335   fail_if(ret_seconds != seconds, 
336           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
337           seconds,ret_seconds);
338
339   /* Test 3: Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT */
340   seconds = G_MAXINT-1;
341   hildon_seekbar_set_fraction(seekbar,seconds);
342   ret_seconds=hildon_seekbar_get_fraction(seekbar);
343
344   fail_if(ret_seconds != seconds, 
345           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
346           seconds,ret_seconds);
347
348   /* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */
349   seconds = G_MAXINT;
350     
351   hildon_seekbar_set_fraction(seekbar,seconds);
352   ret_seconds=hildon_seekbar_get_fraction(seekbar);
353     
354   fail_if(ret_seconds != seconds, 
355           "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
356           seconds,ret_seconds);
357
358     
359 }
360 END_TEST
361
362 /**
363  * Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction
364  * Cases considered:
365  *    - Set and get fraction to NULL object.
366  *    - Set and get fraction to -1 with total time set to G_MAXINT.
367  *    - Set and get fraction to 2000 with total time set to 1000.
368  */
369 START_TEST (test_set_fraction_invalid)
370 {
371   gint ret_seconds;
372   gint seconds;
373   gint init_seconds;
374
375   /* Init seekbar to G_MAXINT total time */
376   init_seconds = G_MAXINT;
377   hildon_seekbar_set_total_time(seekbar,init_seconds);
378
379   /* Test 1: Set and get fraction to NULL object */
380   seconds = 1000;
381   hildon_seekbar_set_fraction(NULL,seconds);
382   ret_seconds=hildon_seekbar_get_fraction(NULL);
383
384   /* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */
385   seconds = -1;
386   hildon_seekbar_set_fraction(seekbar,seconds);
387   ret_seconds=hildon_seekbar_get_fraction(seekbar);
388
389   fail_if(ret_seconds != 0, 
390           "hildon-seekbar: set seekbar fraction to %d should set 0 but get seekbar fraction returns %d",
391           seconds,ret_seconds);
392
393   /* Init seekbar to 1000 total time */
394   init_seconds = 1000;
395   hildon_seekbar_set_total_time(seekbar,init_seconds);
396   hildon_seekbar_set_fraction(seekbar,init_seconds-500);
397
398   /* Test 3: Set and get fraction to 2000 with total time set to 1000 */
399   seconds = 2000;
400   hildon_seekbar_set_fraction(seekbar,seconds);
401   ret_seconds=hildon_seekbar_get_fraction(seekbar);
402
403   fail_if(ret_seconds != init_seconds-500, 
404           "hildon-seekbar: set seekbar fraction to %d should set %d but get seekbar fraction returns %d",
405           seconds,init_seconds,ret_seconds);
406     
407 }
408 END_TEST
409
410
411
412 /* ---------- Suite creation ---------- */
413
414 Suite *create_hildon_seekbar_suite()
415 {
416   /* Create the suite */
417   Suite *s = suite_create("HildonSeekbar");
418
419   /* Create test cases */
420   TCase *tc1 = tcase_create("set_time");
421   TCase *tc2 = tcase_create("set_fraction");
422
423   /* Create test case for hildon_seekbar_set_time and add it to the suite */
424   tcase_add_checked_fixture(tc1, fx_setup_default_seekbar, fx_teardown_default_seekbar);
425   tcase_add_test(tc1, test_set_time_regular);
426   tcase_add_test(tc1, test_set_time_limits);
427   tcase_add_test(tc1, test_set_time_invalid);
428   suite_add_tcase (s, tc1);
429
430   /* Create test case for hildon_seekbar_set_fraction  and add it to the suite */
431   tcase_add_checked_fixture(tc2, fx_setup_default_seekbar, fx_teardown_default_seekbar);
432   tcase_add_test(tc2, test_set_fraction_regular);
433   tcase_add_test(tc2, test_set_fraction_limits);
434   tcase_add_test(tc2, test_set_fraction_invalid);
435   suite_add_tcase (s, tc2);
436
437   /* Return created suite */
438   return s;             
439 }
440