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/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 /* NOTE: The test below has been deliverately commented out, since
223 it fails miserably. The range check in hildon_control_bar_set_range()
224 is _broken_ and fixing it causes other tests to fail. It is safe to assume
225 that by now, fixing this is going to cause more headaches than anything else,
226 and being this a deprecated widget, there is no point on wasting time on it.
229 /* Test 5: Set a range of [1,G_MININT] */
233 hildon_controlbar_set_range(controlbar,init_min,init_max);
235 max=hildon_controlbar_get_max(controlbar);
237 fail_if (max != init_min,
238 "hildon-controlbar: The returned max is %d and should be %d",
241 min=hildon_controlbar_get_min(controlbar);
243 fail_if (min != init_min,
244 "hildon-controlbar: The returned min is %d and should be %d",
250 /* ----- Test case for set_value -----*/
252 * Purpose: Check that regular values are set and get properly
254 * - Set a value of 500 in the range [0,1000].
256 START_TEST (test_set_value_regular)
262 /* Must set a range different than [0,0], if not set you can not set a value*/
263 hildon_controlbar_set_range(controlbar,0,1000);
265 /* Test 1: Set a value of 500 in the range [0,1000].*/
266 hildon_controlbar_set_value(controlbar,init_value);
267 value=hildon_controlbar_get_value(controlbar);
268 fail_if (value != init_value,
269 "hildon-controlbar: The returned value is %d and should be %d",
276 * Purpose: Check that limit values are set and get properly
278 * - Set a value of 0 in the range [0,1000].
279 * - Set a value of 1000 in the range [0,1000].
281 START_TEST (test_set_value_limits)
286 /* Must set a range diferent than [0,0], if not set you can not set a value*/
287 hildon_controlbar_set_range(controlbar,0,1000);
289 /* Test 1: Set a value of 0 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",
298 /* Test 2: Set a value of 1000 in the range [0,1000] */
301 hildon_controlbar_set_value(controlbar,init_value);
302 value=hildon_controlbar_get_value(controlbar);
303 fail_if (value != init_value,
304 "hildon-controlbar: The returned value is %d and should be %d",
311 * Purpose: Check that invalid values are set and get properly
313 * - Set a value of 1 in a NULL controlbar.
314 * - Set a value of -1 in the range [2,1000].
315 * - Set a value of 1 in the range [2,1000].
316 * - Set a value of G_MININT in the range [2,1000].
317 * - Set a value of 1001 in the range [2,1000].
318 * - Set a value of G_MAXINT in the range [2,1000].
319 * - Set a value of G_MAXINT in the range [2,G_MAXINT].
321 START_TEST (test_set_value_invalid)
324 gint initial_value=4;
332 /* Must set a range diferent than [0,0], if not set you can not set a value*/
333 hildon_controlbar_set_range(controlbar,min_value,max_value);
334 hildon_controlbar_set_value(controlbar,initial_value);
336 /* Test 1: Set a value of 1 in a NULL controlbar. */
338 hildon_controlbar_set_value(NULL,init_value);
341 /* Test 2: Set a value of -1 in the range [2,1000] */
343 hildon_controlbar_set_value(controlbar,init_value);
344 value=hildon_controlbar_get_value(controlbar);
345 fail_if (value != initial_value,
346 "hildon-controlbar: The returned value is %d and should be %d",
347 value, initial_value);
349 /* Test 3: Set a value of 1 in the range [2,1000] */
351 hildon_controlbar_set_value(controlbar,min_value);
353 hildon_controlbar_set_value(controlbar,init_value);
354 value=hildon_controlbar_get_value(controlbar);
355 fail_if (value != min_value,
356 "hildon-controlbar: The returned value is %d and should be %d",
360 /* Test 4: Set a value of G_MININT in the range [2,1000] */
362 hildon_controlbar_set_value(controlbar,min_value+2);
363 current_value = hildon_controlbar_get_value(controlbar);
365 hildon_controlbar_set_value(controlbar,init_value);
366 value=hildon_controlbar_get_value(controlbar);
367 fail_if (value != current_value,
368 "hildon-controlbar: The returned value is %d and should be %d",
369 value, current_value);
371 /* Test 5: Set a value of 1001 in the range [2,1000] */
374 hildon_controlbar_set_value(controlbar,init_value);
375 value=hildon_controlbar_get_value(controlbar);
376 fail_if (value != max_value,
377 "hildon-controlbar: The returned value is %d and should be %d",
381 /* Test 6: Set a value of G_MAXINT in the range [2,1000] */
384 hildon_controlbar_set_value(controlbar,init_value);
385 value=hildon_controlbar_get_value(controlbar);
386 fail_if (value != max_value,
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);