2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
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.
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.
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
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"
31 #include "hildon-seekbar.h"
33 /* -------------------- Fixtures -------------------- */
35 static GtkWidget *showed_window = NULL;
36 static HildonSeekbar *seekbar = NULL;
39 fx_setup_default_seekbar ()
42 gtk_init(&argc, NULL);
44 seekbar = HILDON_SEEKBAR(hildon_seekbar_new());
46 showed_window = create_test_window ();
48 /* This packs the widget into the window (a gtk container). */
49 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (seekbar));
51 /* Displays the widget and the window */
52 show_all_test_window (showed_window);
54 /* Check that the seekbar object has been created properly */
55 fail_if(!HILDON_SEEKBAR(seekbar),
56 "hildon-seekbar: Creation failed.");
60 fx_teardown_default_seekbar ()
63 /* Destroy the window */
64 gtk_widget_destroy (showed_window);
67 /* -------------------- Test cases -------------------- */
69 /* ----- Test case for set_time -----*/
72 * Purpose: test setting regular time values for hildon_seekbar_set_time
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.
78 START_TEST (test_set_time_regular)
85 /* Test 1: Set and get 1000 seconds without setting new position and fraction */
87 hildon_seekbar_set_total_time(seekbar,seconds);
88 ret_seconds=hildon_seekbar_get_total_time(seekbar);
90 fail_if(ret_seconds != seconds,
91 "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
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. */
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));
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));
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));
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));
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);
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.
129 hildon_seekbar_set_total_time(seekbar,seconds);
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));
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));
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));
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);
158 * Purpose: test setting limit time values for hildon_seekbar_set_time
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.
163 START_TEST (test_set_time_limits)
171 hildon_seekbar_set_total_time(seekbar,seconds);
176 hildon_seekbar_set_fraction(seekbar,fraction);
177 hildon_seekbar_set_position(seekbar,position);
179 /* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/
181 hildon_seekbar_set_total_time(seekbar,seconds);
182 ret_seconds=hildon_seekbar_get_total_time(seekbar);
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);
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));
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));
198 /* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */
200 hildon_seekbar_set_total_time(seekbar,seconds);
201 ret_seconds=hildon_seekbar_get_total_time(seekbar);
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);
213 * Purpose: test setting invalid time values for hildon_seekbar_set_time
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.
219 START_TEST (test_set_time_invalid)
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);
230 /* Init seekbar to 1000 seconds*/
231 hildon_seekbar_set_total_time(seekbar,init_seconds);
234 /* Test 2: Set and get 0 seconds */
236 hildon_seekbar_set_total_time(seekbar,seconds);
237 ret_seconds=hildon_seekbar_get_total_time(seekbar);
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);
243 /* Test 3: Set and get -1 seconds */
245 hildon_seekbar_set_total_time(seekbar,seconds);
246 ret_seconds=hildon_seekbar_get_total_time(seekbar);
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);
255 /* ----- Test case for set_fraction -----*/
258 * Purpose: test setting regular fraction values for hildon_seekbar_set_fraction
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.
263 START_TEST (test_set_fraction_regular)
269 /* Init seekbar to 1000 */
271 hildon_seekbar_set_total_time(seekbar,init_seconds);
273 /* Test 1: Set and get fraction to 500 with total time set to 1000 */
275 hildon_seekbar_set_fraction(seekbar,seconds);
276 ret_seconds=hildon_seekbar_get_fraction(seekbar);
278 fail_if(ret_seconds != seconds,
279 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
280 seconds,ret_seconds);
282 /* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */
285 hildon_seekbar_set_fraction(seekbar,seconds);
286 hildon_seekbar_set_position(seekbar,seconds);
288 hildon_seekbar_set_fraction(seekbar,seconds-10);
290 ret_seconds=hildon_seekbar_get_fraction(seekbar);
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);
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));
304 * Purpose: test setting limit fraction values for hildon_seekbar_set_fraction
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.
311 START_TEST (test_set_fraction_limits)
317 /* Init seekbar to G_MAXINT total time */
318 init_seconds = G_MAXINT;
319 hildon_seekbar_set_total_time(seekbar,init_seconds);
321 /* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */
323 hildon_seekbar_set_fraction(seekbar,seconds);
324 ret_seconds=hildon_seekbar_get_fraction(seekbar);
326 fail_if(ret_seconds != seconds,
327 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
328 seconds,ret_seconds);
330 /* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */
332 hildon_seekbar_set_fraction(seekbar,seconds);
333 ret_seconds=hildon_seekbar_get_fraction(seekbar);
335 fail_if(ret_seconds != seconds,
336 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
337 seconds,ret_seconds);
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);
344 fail_if(ret_seconds != seconds,
345 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
346 seconds,ret_seconds);
348 /* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */
351 hildon_seekbar_set_fraction(seekbar,seconds);
352 ret_seconds=hildon_seekbar_get_fraction(seekbar);
354 fail_if(ret_seconds != seconds,
355 "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
356 seconds,ret_seconds);
363 * Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction
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.
369 START_TEST (test_set_fraction_invalid)
375 /* Init seekbar to G_MAXINT total time */
376 init_seconds = G_MAXINT;
377 hildon_seekbar_set_total_time(seekbar,init_seconds);
379 /* Test 1: Set and get fraction to NULL object */
381 hildon_seekbar_set_fraction(NULL,seconds);
382 ret_seconds=hildon_seekbar_get_fraction(NULL);
384 /* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */
386 hildon_seekbar_set_fraction(seekbar,seconds);
387 ret_seconds=hildon_seekbar_get_fraction(seekbar);
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);
393 /* Init seekbar to 1000 total time */
395 hildon_seekbar_set_total_time(seekbar,init_seconds);
396 hildon_seekbar_set_fraction(seekbar,init_seconds-500);
398 /* Test 3: Set and get fraction to 2000 with total time set to 1000 */
400 hildon_seekbar_set_fraction(seekbar,seconds);
401 ret_seconds=hildon_seekbar_get_fraction(seekbar);
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);
412 /* ---------- Suite creation ---------- */
414 Suite *create_hildon_seekbar_suite()
416 /* Create the suite */
417 Suite *s = suite_create("HildonSeekbar");
419 /* Create test cases */
420 TCase *tc1 = tcase_create("set_time");
421 TCase *tc2 = tcase_create("set_fraction");
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);
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);
437 /* Return created suite */