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 "test_suites.h"
30 #include "check_utils.h"
31 #include "hildon-controlbar.h"
33 /* -------------------- Fixtures -------------------- */
34 static HildonControlbar *controlbar = NULL;
35 static GtkWidget *showed_window = NULL;
38 fx_setup_default_controlbar ()
41 gtk_init(&argc, NULL);
43 controlbar = HILDON_CONTROLBAR(hildon_controlbar_new());
44 /* Check controlbar object has been created properly */
45 fail_if(!HILDON_IS_CONTROLBAR(controlbar),
46 "hildon-controlbar: Creation failed.");
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 (controlbar));
53 /* Displays the widget and the window */
54 show_all_test_window (showed_window);
59 fx_teardown_default_controlbar ()
62 /* Destroy the widget and the window */
63 gtk_widget_destroy (GTK_WIDGET(showed_window));
67 /* -------------------- Test cases -------------------- */
69 /* ----- Test case for set_range -----*/
71 * Purpose: Check that regular range values are set and get properly
73 * - Set a range of [20,1000].
74 * - Set a range of [20,20].
76 START_TEST (test_set_range_regular)
83 /* Test 1: Set a range of [20,1000] */
86 hildon_controlbar_set_range(controlbar,init_min,init_max);
88 min = hildon_controlbar_get_min(controlbar);
90 fail_if (min != init_min,
91 "hildon-controlbar: The returned min is %d and should be %d",
94 max = hildon_controlbar_get_max(controlbar);
96 fail_if (max != init_max,
97 "hildon-controlbar: The returned max is %d and should be %d",
100 /* Test 2: Set a range of [20, 20] */
103 hildon_controlbar_set_range(controlbar,init_min,init_max);
105 min = hildon_controlbar_get_min(controlbar);
107 fail_if (min != init_min,
108 "hildon-controlbar: The returned min is %d and should be %d",
111 max = hildon_controlbar_get_max(controlbar);
113 fail_if (max != init_max,
114 "hildon-controlbar: The returned max is %d and should be %d",
121 * Purpose: Check that limits range values are set and get properly
123 * - Set a range of [0,G_MAXINT-1].
125 START_TEST (test_set_range_limits)
132 /* Test 1: Set a range of [0,G_MAXINT-1] */
134 init_max = G_MAXINT-1;
135 hildon_controlbar_set_range(controlbar,init_min,init_max);
137 min=hildon_controlbar_get_min(controlbar);
139 fail_if (min != init_min,
140 "hildon-controlbar: The returned min is %d and should be %d",
143 max=hildon_controlbar_get_max(controlbar);
145 fail_if (max != init_max,
146 "hildon-controlbar: The returned max is %d and should be %d",
152 * Purpose: Check that invalid range values are set and get properly
154 * - Set a range of [10,100] on NULL object.
155 * - Set a range of [-1,G_MAXINT].
156 * - Set a range of [G_MININT,-1].
157 * - Set a range of [G_MAXINT,-1].
158 * - Set a range of [1,G_MININT].
160 START_TEST (test_set_range_invalid)
169 /* Test 1: Set range on a NULL object */
170 hildon_controlbar_set_range(NULL,init_min,init_max);
174 /* Test 2: Set a range of [-1,G_MAXINT] */
175 hildon_controlbar_set_range(controlbar,init_min,init_max);
177 min=hildon_controlbar_get_min(controlbar);
179 fail_if (min != init_min,
180 "hildon-controlbar: The returned min is %d and should be %d",
183 max=hildon_controlbar_get_max(controlbar);
185 fail_if (max != init_max,
186 "hildon-controlbar: The returned max is %d and should be %d",
189 /* Test 3: Set a range of [G_MININT,-1] */
192 hildon_controlbar_set_range(controlbar,init_min,init_max);
194 min=hildon_controlbar_get_min(controlbar);
196 fail_if (min != init_min,
197 "hildon-controlbar: The returned min is %d and should be %d",
199 max=hildon_controlbar_get_max(controlbar);
201 fail_if (max != init_max,
202 "hildon-controlbar: The returned max is %d and should be %d",
205 /* Test 4: Set a range of [G_MAXINT,-1] */
208 hildon_controlbar_set_range(controlbar,init_min,init_max);
210 max=hildon_controlbar_get_max(controlbar);
212 fail_if (max != init_max,
213 "hildon-controlbar: The returned max is %d and should be %d",
216 min=hildon_controlbar_get_min(controlbar);
218 fail_if (min != init_max,
219 "hildon-controlbar: The returned min is %d and should be %d",
222 /* Test 5: Set a range of [1,G_MININT] */
225 hildon_controlbar_set_range(controlbar,init_min,init_max);
227 max=hildon_controlbar_get_max(controlbar);
229 fail_if (max != init_min,
230 "hildon-controlbar: The returned max is %d and should be %d",
233 min=hildon_controlbar_get_min(controlbar);
235 fail_if (min != init_min,
236 "hildon-controlbar: The returned min is %d and should be %d",
241 /* ----- Test case for set_value -----*/
243 * Purpose: Check that regular values are set and get properly
245 * - Set a value of 500 in the range [0,1000].
247 START_TEST (test_set_value_regular)
253 /* Must set a range different than [0,0], if not set you can not set a value*/
254 hildon_controlbar_set_range(controlbar,0,1000);
256 /* Test 1: Set a value of 500 in the range [0,1000].*/
257 hildon_controlbar_set_value(controlbar,init_value);
258 value=hildon_controlbar_get_value(controlbar);
259 fail_if (value != init_value,
260 "hildon-controlbar: The returned value is %d and should be %d",
267 * Purpose: Check that limit values are set and get properly
269 * - Set a value of 0 in the range [0,1000].
270 * - Set a value of 1000 in the range [0,1000].
272 START_TEST (test_set_value_limits)
277 /* Must set a range diferent than [0,0], if not set you can not set a value*/
278 hildon_controlbar_set_range(controlbar,0,1000);
280 /* Test 1: Set a value of 0 in the range [0,1000] */
283 hildon_controlbar_set_value(controlbar,init_value);
284 value=hildon_controlbar_get_value(controlbar);
285 fail_if (value != init_value,
286 "hildon-controlbar: The returned value is %d and should be %d",
289 /* Test 2: Set a value of 1000 in the range [0,1000] */
292 hildon_controlbar_set_value(controlbar,init_value);
293 value=hildon_controlbar_get_value(controlbar);
294 fail_if (value != init_value,
295 "hildon-controlbar: The returned value is %d and should be %d",
302 * Purpose: Check that invalid values are set and get properly
304 * - Set a value of 1 in a NULL controlbar.
305 * - Set a value of -1 in the range [2,1000].
306 * - Set a value of 1 in the range [2,1000].
307 * - Set a value of G_MININT in the range [2,1000].
308 * - Set a value of 1001 in the range [2,1000].
309 * - Set a value of G_MAXINT in the range [2,1000].
310 * - Set a value of G_MAXINT in the range [2,G_MAXINT].
312 START_TEST (test_set_value_invalid)
315 gint initial_value=4;
323 /* Must set a range diferent than [0,0], if not set you can not set a value*/
324 hildon_controlbar_set_range(controlbar,min_value,max_value);
325 hildon_controlbar_set_value(controlbar,initial_value);
327 /* Test 1: Set a value of 1 in a NULL controlbar. */
329 hildon_controlbar_set_value(NULL,init_value);
332 /* Test 2: Set a value of -1 in the range [2,1000] */
334 hildon_controlbar_set_value(controlbar,init_value);
335 value=hildon_controlbar_get_value(controlbar);
336 fail_if (value != initial_value,
337 "hildon-controlbar: The returned value is %d and should be %d",
338 value, initial_value);
340 /* Test 3: Set a value of 1 in the range [2,1000] */
342 hildon_controlbar_set_value(controlbar,min_value);
344 hildon_controlbar_set_value(controlbar,init_value);
345 value=hildon_controlbar_get_value(controlbar);
346 fail_if (value != min_value,
347 "hildon-controlbar: The returned value is %d and should be %d",
351 /* Test 4: Set a value of G_MININT in the range [2,1000] */
353 hildon_controlbar_set_value(controlbar,min_value+2);
354 current_value = hildon_controlbar_get_value(controlbar);
356 hildon_controlbar_set_value(controlbar,init_value);
357 value=hildon_controlbar_get_value(controlbar);
358 fail_if (value != current_value,
359 "hildon-controlbar: The returned value is %d and should be %d",
360 value, current_value);
362 /* Test 5: Set a value of 1001 in the range [2,1000] */
365 hildon_controlbar_set_value(controlbar,init_value);
366 value=hildon_controlbar_get_value(controlbar);
367 fail_if (value != max_value,
368 "hildon-controlbar: The returned value is %d and should be %d",
372 /* Test 6: Set a value of G_MAXINT in the range [2,1000] */
375 hildon_controlbar_set_value(controlbar,init_value);
376 value=hildon_controlbar_get_value(controlbar);
377 fail_if (value != max_value,
378 "hildon-controlbar: The returned value is %d and should be %d",
381 /* Test 7: Set a value of G_MAXINT in the range [2,G_MAXINT] */
383 hildon_controlbar_set_range(controlbar,2,G_MAXINT);
384 hildon_controlbar_set_value(controlbar,init_value);
385 value=hildon_controlbar_get_value(controlbar);
386 fail_if (value != G_MAXINT-1,
387 "hildon-controlbar: The returned value is %d and should be %d",
392 /* ---------- Suite creation ---------- */
394 Suite *create_hildon_controlbar_suite()
396 /* Create the suite */
397 Suite *s = suite_create("HildonControlbar");
399 /* Create test cases */
400 TCase *tc1 = tcase_create("set_range");
401 TCase *tc2 = tcase_create("set_value");
403 /* Create test case for hildon_controlbar_set_range and add it to the suite */
404 tcase_add_checked_fixture(tc1, fx_setup_default_controlbar, fx_teardown_default_controlbar);
405 tcase_add_test(tc1, test_set_range_regular);
406 tcase_add_test(tc1, test_set_range_limits);
407 tcase_add_test(tc1, test_set_range_invalid);
408 suite_add_tcase (s, tc1);
410 /* Create test case for hildon_controlbar_set_value and add it to the suite */
411 tcase_add_checked_fixture(tc2, fx_setup_default_controlbar, fx_teardown_default_controlbar);
412 tcase_add_test(tc2, test_set_value_regular);
413 tcase_add_test(tc2, test_set_value_limits);
414 tcase_add_test(tc2, test_set_value_invalid);
415 suite_add_tcase (s, tc2);