2 * This file is a part of hildon tests
4 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
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.
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.
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
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkcontainer.h>
29 #include <glib/gprintf.h>
30 #include "test_suites.h"
31 #include "check_utils.h"
33 #include "hildon-seekbar.h"
35 /* -------------------- Fixtures -------------------- */
37 static GtkWidget *showed_window = NULL;
38 static HildonSeekbar *seekbar = NULL;
41 fx_setup_default_seekbar ()
44 gtk_init(&argc, NULL);
46 seekbar = HILDON_SEEKBAR(hildon_seekbar_new());
48 showed_window = create_test_window ();
50 /* This packs the widget into the window (a gtk container). */
51 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (seekbar));
53 /* Displays the widget and the window */
54 show_all_test_window (showed_window);
56 /* Check that the seekbar object has been created properly */
57 fail_if(!HILDON_SEEKBAR(seekbar),
58 "hildon-seekbar: Creation failed.");
62 fx_teardown_default_seekbar ()
65 /* Destroy the window */
66 gtk_widget_destroy (showed_window);
69 /* -------------------- Test cases -------------------- */
71 /* ----- Test case for set_time -----*/
74 * Purpose: test setting regular time values for hildon_seekbar_set_time
76 * - Set and get 1000 seconds without setting new position and fraction.
77 * - Set and get 500 seconds setting without setting new position but new fraction should be set.
78 * - Set and get 500 seconds setting without setting new position but new fraction should be set.
80 START_TEST (test_set_time_regular)
87 /* Test 1: Set and get 1000 seconds without setting new position and fraction */
89 hildon_seekbar_set_total_time(seekbar,seconds);
90 ret_seconds=hildon_seekbar_get_total_time(seekbar);
92 fail_if(ret_seconds != seconds,
93 "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
97 /* 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
98 position and fraction. */
103 hildon_seekbar_set_fraction(seekbar,fraction);
104 fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
105 "hildon-seekbar: set total time to %d but get_fraction returns %d ",
106 fraction,hildon_seekbar_get_fraction(seekbar));
108 hildon_seekbar_set_position(seekbar,position);
109 fail_if(position != hildon_seekbar_get_position(seekbar),
110 "hildon-seekbar: set total time to %d but get_position returns %d",
111 position,hildon_seekbar_get_position(seekbar));
113 hildon_seekbar_set_total_time(seekbar,seconds);
114 fail_if(seconds != hildon_seekbar_get_fraction(seekbar),
115 "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
116 seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
118 fail_if(seconds != hildon_seekbar_get_position(seekbar),
119 "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
120 seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
122 ret_seconds=hildon_seekbar_get_total_time(seekbar);
123 fail_if(ret_seconds != seconds,
124 "hildon-seekbar: set total time to %d but get_total_time returns %d ",
125 seconds,ret_seconds);
127 /* 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
128 position and fraction.
131 hildon_seekbar_set_total_time(seekbar,seconds);
137 hildon_seekbar_set_fraction(seekbar,fraction);
138 fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
139 "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d ",
140 fraction,hildon_seekbar_get_fraction(seekbar));
142 hildon_seekbar_set_position(seekbar,position);
143 fail_if(position != hildon_seekbar_get_position(seekbar),
144 "hildon-seekbar: set seekbar position to %d but get_position returns %d",
145 position,hildon_seekbar_get_position(seekbar));
147 hildon_seekbar_set_total_time(seekbar,seconds);
148 fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
149 "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d being total time %d",
150 seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
152 ret_seconds=hildon_seekbar_get_total_time(seekbar);
153 fail_if(ret_seconds != seconds,
154 "hildon-seekbar: set total time to %d but get_total_time returns %d ",
155 seconds,ret_seconds);
160 * Purpose: test setting limit time values for hildon_seekbar_set_time
162 * - Set and get 0 seconds setting new position and fraction (previously set to 750).
163 * - Set and get G_MAXINT seconds without setting new position and fraction.
165 START_TEST (test_set_time_limits)
173 hildon_seekbar_set_total_time(seekbar,seconds);
178 hildon_seekbar_set_fraction(seekbar,fraction);
179 hildon_seekbar_set_position(seekbar,position);
181 /* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/
183 hildon_seekbar_set_total_time(seekbar,seconds);
184 ret_seconds=hildon_seekbar_get_total_time(seekbar);
186 fail_if(ret_seconds != seconds,
187 "hildon-seekbar: set seekbar total time to %d should return %d but get_total_time returns %d",
188 seconds,ret_seconds);
190 /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
191 fail_if(seconds != hildon_seekbar_get_fraction(seekbar),
192 "hildon-seekbar: set time to %d but get_fraction returns %d ",
193 seconds,hildon_seekbar_get_fraction(seekbar));
195 /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
196 fail_if(seconds != hildon_seekbar_get_position(seekbar),
197 "hildon-seekbar: set time to %d but get_position returns %d",
198 seconds,hildon_seekbar_get_position(seekbar));
200 /* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */
202 hildon_seekbar_set_total_time(seekbar,seconds);
203 ret_seconds=hildon_seekbar_get_total_time(seekbar);
205 fail_if(ret_seconds != seconds,
206 "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
207 seconds,ret_seconds);
215 * Purpose: test setting invalid time values for hildon_seekbar_set_time
217 * - Set and get seconds to a NULL object.
218 * - Set and get 0 seconds without setting new position and fraction.
219 * - Set and get -1 seconds without setting new position and fraction.
221 START_TEST (test_set_time_invalid)
228 /* Test 1: Set/get seconds on NULL object */
229 hildon_seekbar_set_total_time(NULL,init_seconds);
230 ret_seconds=hildon_seekbar_get_total_time(NULL);
232 /* Init seekbar to 1000 seconds*/
233 hildon_seekbar_set_total_time(seekbar,init_seconds);
236 /* Test 2: Set and get 0 seconds */
238 hildon_seekbar_set_total_time(seekbar,seconds);
239 ret_seconds=hildon_seekbar_get_total_time(seekbar);
241 fail_if(ret_seconds != init_seconds,
242 "hildon-seekbar: set seekbar total time to %d, should set %d but get_total_time returns %d",
243 seconds,init_seconds,ret_seconds);
245 /* Test 3: Set and get -1 seconds */
247 hildon_seekbar_set_total_time(seekbar,seconds);
248 ret_seconds=hildon_seekbar_get_total_time(seekbar);
250 fail_if(ret_seconds != init_seconds,
251 "hildon-seekbar: set seekbar total time to %d, should return %d but get_total_time returns %d",
252 seconds,init_seconds,ret_seconds);
257 /* ----- Test case for set_fraction -----*/
260 * Purpose: test setting regular fraction values for hildon_seekbar_set_fraction
262 * - Set and get fraction to 500 with total time set to 1000.
263 * - Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500.
265 START_TEST (test_set_fraction_regular)
271 /* Init seekbar to 1000 */
273 hildon_seekbar_set_total_time(seekbar,init_seconds);
275 /* Test 1: Set and get fraction to 500 with total time set to 1000 */
277 hildon_seekbar_set_fraction(seekbar,seconds);
278 ret_seconds=hildon_seekbar_get_fraction(seekbar);
280 fail_if(ret_seconds != seconds,
281 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
282 seconds,ret_seconds);
284 /* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */
287 hildon_seekbar_set_fraction(seekbar,seconds);
288 hildon_seekbar_set_position(seekbar,seconds);
290 hildon_seekbar_set_fraction(seekbar,seconds-10);
292 ret_seconds=hildon_seekbar_get_fraction(seekbar);
294 fail_if(ret_seconds != seconds-10,
295 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
296 seconds,ret_seconds);
298 fail_if(hildon_seekbar_get_position(seekbar) != seconds-10,
299 "hildon-seekbar: set seekbar fraction to %d but get seekbar position returns %d",
300 seconds-10,hildon_seekbar_get_position(seekbar));
306 * Purpose: test setting limit fraction values for hildon_seekbar_set_fraction
308 * - Set and get fraction to 0 with total time set to G_MAXINT.
309 * - Set and get fraction to 1 with total time set to G_MAXINT.
310 * - Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT.
311 * - Set and get fraction to G_MAXINT with total time set to G_MAXINT.
313 START_TEST (test_set_fraction_limits)
319 /* Init seekbar to G_MAXINT total time */
320 init_seconds = G_MAXINT;
321 hildon_seekbar_set_total_time(seekbar,init_seconds);
323 /* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */
325 hildon_seekbar_set_fraction(seekbar,seconds);
326 ret_seconds=hildon_seekbar_get_fraction(seekbar);
328 fail_if(ret_seconds != seconds,
329 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
330 seconds,ret_seconds);
332 /* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */
334 hildon_seekbar_set_fraction(seekbar,seconds);
335 ret_seconds=hildon_seekbar_get_fraction(seekbar);
337 fail_if(ret_seconds != seconds,
338 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
339 seconds,ret_seconds);
341 /* Test 3: Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT */
342 seconds = G_MAXINT-1;
343 hildon_seekbar_set_fraction(seekbar,seconds);
344 ret_seconds=hildon_seekbar_get_fraction(seekbar);
346 fail_if(ret_seconds != seconds,
347 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
348 seconds,ret_seconds);
350 /* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */
353 hildon_seekbar_set_fraction(seekbar,seconds);
354 ret_seconds=hildon_seekbar_get_fraction(seekbar);
356 fail_if(ret_seconds != seconds,
357 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
358 seconds,ret_seconds);
365 * Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction
367 * - Set and get fraction to NULL object.
368 * - Set and get fraction to -1 with total time set to G_MAXINT.
369 * - Set and get fraction to 2000 with total time set to 1000.
371 START_TEST (test_set_fraction_invalid)
377 /* Init seekbar to G_MAXINT total time */
378 init_seconds = G_MAXINT;
379 hildon_seekbar_set_total_time(seekbar,init_seconds);
381 /* Test 1: Set and get fraction to NULL object */
383 hildon_seekbar_set_fraction(NULL,seconds);
384 ret_seconds=hildon_seekbar_get_fraction(NULL);
386 /* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */
388 hildon_seekbar_set_fraction(seekbar,seconds);
389 ret_seconds=hildon_seekbar_get_fraction(seekbar);
391 fail_if(ret_seconds != 0,
392 "hildon-seekbar: set seekbar fraction to %d should set 0 but get seekbar fraction returns %d",
393 seconds,ret_seconds);
395 /* Init seekbar to 1000 total time */
397 hildon_seekbar_set_total_time(seekbar,init_seconds);
398 hildon_seekbar_set_fraction(seekbar,init_seconds-500);
400 /* Test 3: Set and get fraction to 2000 with total time set to 1000 */
402 hildon_seekbar_set_fraction(seekbar,seconds);
403 ret_seconds=hildon_seekbar_get_fraction(seekbar);
405 fail_if(ret_seconds != init_seconds-500,
406 "hildon-seekbar: set seekbar fraction to %d should set %d but get seekbar fraction returns %d",
407 seconds,init_seconds,ret_seconds);
414 /* ---------- Suite creation ---------- */
416 Suite *create_hildon_seekbar_suite()
418 /* Create the suite */
419 Suite *s = suite_create("HildonSeekbar");
421 /* Create test cases */
422 TCase *tc1 = tcase_create("set_time");
423 TCase *tc2 = tcase_create("set_fraction");
425 /* Create test case for hildon_seekbar_set_time and add it to the suite */
426 tcase_add_checked_fixture(tc1, fx_setup_default_seekbar, fx_teardown_default_seekbar);
427 tcase_add_test(tc1, test_set_time_regular);
428 tcase_add_test(tc1, test_set_time_limits);
429 tcase_add_test(tc1, test_set_time_invalid);
430 suite_add_tcase (s, tc1);
432 /* Create test case for hildon_seekbar_set_fraction and add it to the suite */
433 tcase_add_checked_fixture(tc2, fx_setup_default_seekbar, fx_teardown_default_seekbar);
434 tcase_add_test(tc2, test_set_fraction_regular);
435 tcase_add_test(tc2, test_set_fraction_limits);
436 tcase_add_test(tc2, test_set_fraction_invalid);
437 suite_add_tcase (s, tc2);
439 /* Return created suite */