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
24 #include <gtk/gtkmain.h>
25 #include "test_suites.h"
26 #include "check_utils.h"
28 #include "hildon-range-editor.h"
31 /* -------------------- Fixtures -------------------- */
33 static GtkWidget *showed_window = NULL;
34 static HildonRangeEditor *range_editor = NULL;
37 fx_setup_default_range_editor ()
40 gtk_init(&argc, NULL);
42 range_editor = HILDON_RANGE_EDITOR(hildon_range_editor_new());
44 showed_window = create_test_window ();
46 /* This packs the widget into the window (a gtk container). */
47 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (range_editor));
49 /* Displays the widget and the window */
50 show_all_test_window (showed_window);
52 /* Check range_editor object has been created properly */
53 fail_if(!HILDON_IS_RANGE_EDITOR(range_editor),
54 "hildon-range-editor: Creation failed.");
57 while (gtk_events_pending ())
59 gtk_main_iteration ();
65 fx_teardown_default_range_editor ()
68 /* Destroy the window */
69 gtk_widget_destroy (showed_window);
72 /* -------------------- Test cases -------------------- */
74 /* ----- Test case for set_limit, get_min, get_max -----*/
77 * Purpose: Check that regular range limit values are set and get properly
79 * - Set limits to (-10,10) and get min/max using the range editor object
80 * - Set limits to (0,10) and get min/max using the range editor object
81 * - Set limits to (-10,0) and get min/max using the range editor object
82 * - Set limits to (1,10) and get min/max using the range editor object
83 * - Set limits to (-10,-10) and get min/max using the range editor object
85 START_TEST (test_set_limits_get_min_get_max_regular)
87 gint range_start, range_end;
89 /* Test1: Set limits to (-10,10) */
90 hildon_range_editor_set_limits(range_editor, -10, 10);
91 range_start = hildon_range_editor_get_min(range_editor);
92 fail_if(range_start != -10,
93 "hildon-range-editor: set limits to (-10,10) but get_min didn't return -10");
94 range_end = hildon_range_editor_get_max(range_editor);
95 fail_if(range_end != 10,
96 "hildon-range-editor: set limits to (-10,10) but get_max didn't return 10");
98 /* Test2: Set limits to (0,10) */
99 hildon_range_editor_set_limits(range_editor, 0, 10);
100 range_start = hildon_range_editor_get_min(range_editor);
101 fail_if(range_start != 0,
102 "hildon-range-editor: set limits to (0,10) but get_min didn't return 0");
103 range_end = hildon_range_editor_get_max(range_editor);
104 fail_if(range_end != 10,
105 "hildon-range-editor: set limits to (0,10) but get_max didn't return 10");
107 /* Test3: Set limits to (-10,0) */
108 hildon_range_editor_set_limits(range_editor, -10, 0);
109 range_start = hildon_range_editor_get_min(range_editor);
110 fail_if(range_start != -10,
111 "hildon-range-editor: set limits to (-10,0) but get_min didn't return -10");
112 range_end = hildon_range_editor_get_max(range_editor);
113 fail_if(range_end != 0,
114 "hildon-range-editor: set limits to (-10,0) but get_max didn't return 0");
116 /* Test4: Set limits to (1,10) */
117 hildon_range_editor_set_limits(range_editor, 1, 10);
118 range_start = hildon_range_editor_get_min(range_editor);
119 fail_if(range_start != 1,
120 "hildon-range-editor: set limits to (1,10) but get_min didn't return 1");
121 range_end = hildon_range_editor_get_max(range_editor);
122 fail_if(range_end != 10,
123 "hildon-range-editor: set limits to (1,10) but get_max didn't return 10");
125 /* Test5: Set limits to (-10,-1) */
126 hildon_range_editor_set_limits(range_editor, -10, -1);
127 range_start = hildon_range_editor_get_min(range_editor);
128 fail_if(range_start != -10,
129 "hildon-range-editor: set limits to (-10,-1) but get_min didn't return -10");
130 range_end = hildon_range_editor_get_max(range_editor);
131 fail_if(range_end != -1,
132 "hildon-range-editor: set limits to (-10,-1) but get_max didn't return -1");
137 * Purpose: Check that range limit values are set and get properly
139 * - Set limits to (G_MININT,G_MAXINT) and get min/max using the range editor object
141 START_TEST (test_set_limits_get_min_get_max_limits)
143 gint range_start, range_end;
145 /* Test1: Set limits to (G_MININT,G_MAXINT) */
146 hildon_range_editor_set_limits(range_editor, G_MININT, G_MAXINT);
147 range_start = hildon_range_editor_get_min(range_editor);
148 fail_if(range_start != G_MININT,
149 "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_min didn't return G_MININT");
150 range_end = hildon_range_editor_get_max(range_editor);
151 fail_if(range_end != G_MAXINT,
152 "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_max didn't return G_MAXINT");
157 * Purpose: Check that invalid values are handled properly
159 * - Set inverted limits (10,-10)
160 * - Set range editor object to NULL for set_limits
161 * - Set range editor object to NULL for get_min and get_max
163 START_TEST (test_set_limits_get_min_get_max_invalid)
165 gint range_start, range_end;
167 /* Test1: Set limits to (10,-10) */
168 hildon_range_editor_set_limits(range_editor, 10, -10);
169 range_start = hildon_range_editor_get_min(range_editor);
170 fail_if(range_start != -10,
171 "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_min didn't return -10");
172 range_end = hildon_range_editor_get_max(range_editor);
173 fail_if(range_end != -10,
174 "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_max didn't return -1");
176 /* Test2: set range editor to NULL for set_limits. */
177 hildon_range_editor_set_limits(NULL, 100, -100);
179 /* Test3: set range editor to NULL for get_min and get_max */
180 range_start = hildon_range_editor_get_min(NULL);
181 fail_if(range_start != 0,
182 "hildon-range-editor: setting range editor to NULL produced get_min to return a value != 0");
183 range_end = hildon_range_editor_get_max(NULL);
184 fail_if(range_end != 0,
185 "hildon-range-editor: setting range editor to NULL produced get_max to return a value != 0");
190 /* ----- Test case for set_min -----*/
193 * Purpose: Check regular minimum values for limits are set properly
195 * - Set min limit to -100
196 * - Set min limit to 0
197 * - Set min limit to 100
199 START_TEST (test_set_min_regular)
203 /* Test1: Set min limits -100 */
204 hildon_range_editor_set_min(range_editor, -100);
205 range_start = hildon_range_editor_get_min(range_editor);
206 fail_if(range_start != -100,
207 "hildon-range-editor: set min limit to -100 but get_min didn't return -100");
209 /* Test2: Set min limits 0 */
210 hildon_range_editor_set_min(range_editor, 0);
211 range_start = hildon_range_editor_get_min(range_editor);
212 fail_if(range_start != 0,
213 "hildon-range-editor: set min limit to 0 but get_min didn't return 0");
215 /* Test3: Set min limits 100 */
216 hildon_range_editor_set_min(range_editor, 100);
217 range_start = hildon_range_editor_get_min(range_editor);
218 fail_if(range_start != 100,
219 "hildon-range-editor: set min limit to 100 but get_min didn't return 100");
224 * Purpose: Check limit minimum values for limits are set properly
226 * - Set min limit to G_MININT
228 START_TEST (test_set_min_limits)
232 /* Test1: Set min limit to G_MININT */
233 hildon_range_editor_set_min(range_editor, G_MININT);
234 range_start = hildon_range_editor_get_min(range_editor);
235 fail_if(range_start != G_MININT,
236 "hildon-range-editor: set min limit to G_MININT but get_min didn't return G_MININT");
241 * Purpose: Check that invalid values are handled properly
243 * - Set minimum limit greater than maximum limit
244 * - Set range editor object to NULL for set_min
246 START_TEST (test_set_min_invalid)
248 gint range_start, range_end;
250 /* Test1: Set minimum limit greater than maximum limit */
251 hildon_range_editor_set_limits(range_editor, -10, 10);
252 hildon_range_editor_set_min(range_editor, 15);
253 range_start = hildon_range_editor_get_min(range_editor);
254 fail_if(range_start != 15,
255 "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_min didn't return 15");
256 range_end = hildon_range_editor_get_max(range_editor);
257 fail_if(range_end != 15,
258 "hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_max didn't return 15");
260 /* Test2: set range editor to NULL */
261 hildon_range_editor_set_min(NULL, 15);
266 /* ----- Test case for set_max -----*/
269 * Purpose: Check regular maximum values for limits are set properly
271 * - Set max limit to -100
272 * - Set max limit to 0
273 * - Set max limit to 100
275 START_TEST (test_set_max_regular)
279 /* Test1: Set max limits -100 */
280 hildon_range_editor_set_max(range_editor, -100);
281 range_end = hildon_range_editor_get_max(range_editor);
282 fail_if(range_end != -100,
283 "hildon-range-editor: set max limit to -100 but get_max didn't return -100");
285 /* Test2: Set max limits 0 */
286 hildon_range_editor_set_max(range_editor, 0);
287 range_end = hildon_range_editor_get_max(range_editor);
288 fail_if(range_end != 0,
289 "hildon-range-editor: set max limit to 0 but get_max didn't return 0");
291 /* Test3: Set max limits 100 */
292 hildon_range_editor_set_max(range_editor, 100);
293 range_end = hildon_range_editor_get_max(range_editor);
294 fail_if(range_end != 100,
295 "hildon-range-editor: set max limit to 100 but get_max didn't return 100");
300 * Purpose: Check limit maximum values for limits are set properly
302 * - Set min limit to G_MAXINT
304 START_TEST (test_set_max_limits)
308 /* Test1: Set max limit to G_MAXINT */
309 hildon_range_editor_set_max(range_editor, G_MAXINT);
310 range_end = hildon_range_editor_get_max(range_editor);
311 fail_if(range_end != G_MAXINT,
312 "hildon-range-editor: set min limit to G_MAXINT but get_max didn't return G_MAXINT");
317 * Purpose: Check that invalid values are handled properly
319 * - Set maximum limit lower than minimum limit
320 * - Set range editor object to NULL for set_max
322 START_TEST (test_set_max_invalid)
324 gint range_start, range_end;
326 /* Test1: Set maximum limit lower than minimum limit */
327 hildon_range_editor_set_limits(range_editor, -10, 10);
328 hildon_range_editor_set_max(range_editor, -15);
329 range_start = hildon_range_editor_get_min(range_editor);
330 fail_if(range_start != -15,
331 "hildon-range-editor: set max limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_min didn't return -15");
332 range_end = hildon_range_editor_get_max(range_editor);
333 fail_if(range_end != -15,
334 "hildon-range-editor: set min limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_max didn't return -15");
336 /* Test2: set range editor to NULL */
337 hildon_range_editor_set_max(NULL, 15);
342 /* ---------- Suite creation ---------- */
344 Suite *create_hildon_range_editor_suite()
346 /* Create the suite */
347 Suite *s = suite_create("HildonRangeEditor");
349 /* Create test cases */
350 TCase *tc1 = tcase_create("set_limits_get_min_get_max");
351 TCase *tc2 = tcase_create("set_min");
352 TCase *tc3 = tcase_create("set_max");
354 /* Create test case for set_limits, get_min and get_max and add it to the suite */
355 tcase_add_checked_fixture(tc1, fx_setup_default_range_editor, fx_teardown_default_range_editor);
356 tcase_add_test(tc1, test_set_limits_get_min_get_max_regular);
357 tcase_add_test(tc1, test_set_limits_get_min_get_max_limits);
358 tcase_add_test(tc1, test_set_limits_get_min_get_max_invalid);
359 suite_add_tcase (s, tc1);
361 /* Create test case for set_min */
362 tcase_add_checked_fixture(tc2, fx_setup_default_range_editor, fx_teardown_default_range_editor);
363 tcase_add_test(tc2, test_set_min_regular);
364 tcase_add_test(tc2, test_set_min_limits);
365 tcase_add_test(tc2, test_set_min_invalid);
366 suite_add_tcase (s, tc2);
368 /* Create test case for set_max */
369 tcase_add_checked_fixture(tc3, fx_setup_default_range_editor, fx_teardown_default_range_editor);
370 tcase_add_test(tc3, test_set_max_regular);
371 tcase_add_test(tc3, test_set_max_limits);
372 tcase_add_test(tc3, test_set_max_invalid);
373 suite_add_tcase (s, tc3);
375 /* Return created suite */