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 "test_suites.h"
29 #include "check_utils.h"
31 #include "hildon-range-editor.h"
34 /* -------------------- Fixtures -------------------- */
36 static GtkWidget *showed_window = NULL;
37 static HildonRangeEditor *range_editor = NULL;
40 fx_setup_default_range_editor ()
43 gtk_init(&argc, NULL);
45 range_editor = HILDON_RANGE_EDITOR(hildon_range_editor_new());
47 showed_window = create_test_window ();
49 /* This packs the widget into the window (a gtk container). */
50 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (range_editor));
52 /* Displays the widget and the window */
53 show_all_test_window (showed_window);
55 /* Check range_editor object has been created properly */
56 fail_if(!HILDON_IS_RANGE_EDITOR(range_editor),
57 "hildon-range-editor: Creation failed.");
60 while (gtk_events_pending ())
62 gtk_main_iteration ();
68 fx_teardown_default_range_editor ()
71 /* Destroy the window */
72 gtk_widget_destroy (showed_window);
75 /* -------------------- Test cases -------------------- */
77 /* ----- Test case for set_limit, get_min, get_max -----*/
80 * Purpose: Check that regular range limit values are set and get properly
82 * - Set limits to (-10,10) and get min/max using the range editor object
83 * - Set limits to (0,10) and get min/max using the range editor object
84 * - Set limits to (-10,0) and get min/max using the range editor object
85 * - Set limits to (1,10) and get min/max using the range editor object
86 * - Set limits to (-10,-10) and get min/max using the range editor object
88 START_TEST (test_set_limits_get_min_get_max_regular)
90 gint range_start, range_end;
92 /* Test1: Set limits to (-10,10) */
93 hildon_range_editor_set_limits(range_editor, -10, 10);
94 range_start = hildon_range_editor_get_min(range_editor);
95 fail_if(range_start != -10,
96 "hildon-range-editor: set limits to (-10,10) but get_min didn't return -10");
97 range_end = hildon_range_editor_get_max(range_editor);
98 fail_if(range_end != 10,
99 "hildon-range-editor: set limits to (-10,10) but get_max didn't return 10");
101 /* Test2: Set limits to (0,10) */
102 hildon_range_editor_set_limits(range_editor, 0, 10);
103 range_start = hildon_range_editor_get_min(range_editor);
104 fail_if(range_start != 0,
105 "hildon-range-editor: set limits to (0,10) but get_min didn't return 0");
106 range_end = hildon_range_editor_get_max(range_editor);
107 fail_if(range_end != 10,
108 "hildon-range-editor: set limits to (0,10) but get_max didn't return 10");
110 /* Test3: Set limits to (-10,0) */
111 hildon_range_editor_set_limits(range_editor, -10, 0);
112 range_start = hildon_range_editor_get_min(range_editor);
113 fail_if(range_start != -10,
114 "hildon-range-editor: set limits to (-10,0) but get_min didn't return -10");
115 range_end = hildon_range_editor_get_max(range_editor);
116 fail_if(range_end != 0,
117 "hildon-range-editor: set limits to (-10,0) but get_max didn't return 0");
119 /* Test4: Set limits to (1,10) */
120 hildon_range_editor_set_limits(range_editor, 1, 10);
121 range_start = hildon_range_editor_get_min(range_editor);
122 fail_if(range_start != 1,
123 "hildon-range-editor: set limits to (1,10) but get_min didn't return 1");
124 range_end = hildon_range_editor_get_max(range_editor);
125 fail_if(range_end != 10,
126 "hildon-range-editor: set limits to (1,10) but get_max didn't return 10");
128 /* Test5: Set limits to (-10,-1) */
129 hildon_range_editor_set_limits(range_editor, -10, -1);
130 range_start = hildon_range_editor_get_min(range_editor);
131 fail_if(range_start != -10,
132 "hildon-range-editor: set limits to (-10,-1) but get_min didn't return -10");
133 range_end = hildon_range_editor_get_max(range_editor);
134 fail_if(range_end != -1,
135 "hildon-range-editor: set limits to (-10,-1) but get_max didn't return -1");
140 * Purpose: Check that range limit values are set and get properly
142 * - Set limits to (G_MININT,G_MAXINT) and get min/max using the range editor object
144 START_TEST (test_set_limits_get_min_get_max_limits)
146 gint range_start, range_end;
148 /* Test1: Set limits to (G_MININT,G_MAXINT) */
149 hildon_range_editor_set_limits(range_editor, G_MININT, G_MAXINT);
150 range_start = hildon_range_editor_get_min(range_editor);
151 fail_if(range_start != G_MININT,
152 "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_min didn't return G_MININT");
153 range_end = hildon_range_editor_get_max(range_editor);
154 fail_if(range_end != G_MAXINT,
155 "hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_max didn't return G_MAXINT");
160 * Purpose: Check that invalid values are handled properly
162 * - Set inverted limits (10,-10)
163 * - Set range editor object to NULL for set_limits
164 * - Set range editor object to NULL for get_min and get_max
166 START_TEST (test_set_limits_get_min_get_max_invalid)
168 gint range_start, range_end;
170 /* Test1: Set limits to (10,-10) */
171 hildon_range_editor_set_limits(range_editor, 10, -10);
172 range_start = hildon_range_editor_get_min(range_editor);
173 fail_if(range_start != -10,
174 "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_min didn't return -10");
175 range_end = hildon_range_editor_get_max(range_editor);
176 fail_if(range_end != -10,
177 "hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_max didn't return -1");
179 /* Test2: set range editor to NULL for set_limits. */
180 hildon_range_editor_set_limits(NULL, 100, -100);
182 /* Test3: set range editor to NULL for get_min and get_max */
183 range_start = hildon_range_editor_get_min(NULL);
184 fail_if(range_start != 0,
185 "hildon-range-editor: setting range editor to NULL produced get_min to return a value != 0");
186 range_end = hildon_range_editor_get_max(NULL);
187 fail_if(range_end != 0,
188 "hildon-range-editor: setting range editor to NULL produced get_max to return a value != 0");
193 /* ----- Test case for set_min -----*/
196 * Purpose: Check regular minimum values for limits are set properly
198 * - Set min limit to -100
199 * - Set min limit to 0
200 * - Set min limit to 100
202 START_TEST (test_set_min_regular)
206 /* Test1: Set min limits -100 */
207 hildon_range_editor_set_min(range_editor, -100);
208 range_start = hildon_range_editor_get_min(range_editor);
209 fail_if(range_start != -100,
210 "hildon-range-editor: set min limit to -100 but get_min didn't return -100");
212 /* Test2: Set min limits 0 */
213 hildon_range_editor_set_min(range_editor, 0);
214 range_start = hildon_range_editor_get_min(range_editor);
215 fail_if(range_start != 0,
216 "hildon-range-editor: set min limit to 0 but get_min didn't return 0");
218 /* Test3: Set min limits 100 */
219 hildon_range_editor_set_min(range_editor, 100);
220 range_start = hildon_range_editor_get_min(range_editor);
221 fail_if(range_start != 100,
222 "hildon-range-editor: set min limit to 100 but get_min didn't return 100");
227 * Purpose: Check limit minimum values for limits are set properly
229 * - Set min limit to G_MININT
231 START_TEST (test_set_min_limits)
235 /* Test1: Set min limit to G_MININT */
236 hildon_range_editor_set_min(range_editor, G_MININT);
237 range_start = hildon_range_editor_get_min(range_editor);
238 fail_if(range_start != G_MININT,
239 "hildon-range-editor: set min limit to G_MININT but get_min didn't return G_MININT");
244 * Purpose: Check that invalid values are handled properly
246 * - Set minimum limit greater than maximum limit
247 * - Set range editor object to NULL for set_min
249 START_TEST (test_set_min_invalid)
251 gint range_start, range_end;
253 /* Test1: Set minimum limit greater than maximum limit */
254 hildon_range_editor_set_limits(range_editor, -10, 10);
255 hildon_range_editor_set_min(range_editor, 15);
256 range_start = hildon_range_editor_get_min(range_editor);
257 fail_if(range_start != 15,
258 "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");
259 range_end = hildon_range_editor_get_max(range_editor);
260 fail_if(range_end != 15,
261 "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");
263 /* Test2: set range editor to NULL */
264 hildon_range_editor_set_min(NULL, 15);
269 /* ----- Test case for set_max -----*/
272 * Purpose: Check regular maximum values for limits are set properly
274 * - Set max limit to -100
275 * - Set max limit to 0
276 * - Set max limit to 100
278 START_TEST (test_set_max_regular)
282 /* Test1: Set max limits -100 */
283 hildon_range_editor_set_max(range_editor, -100);
284 range_end = hildon_range_editor_get_max(range_editor);
285 fail_if(range_end != -100,
286 "hildon-range-editor: set max limit to -100 but get_max didn't return -100");
288 /* Test2: Set max limits 0 */
289 hildon_range_editor_set_max(range_editor, 0);
290 range_end = hildon_range_editor_get_max(range_editor);
291 fail_if(range_end != 0,
292 "hildon-range-editor: set max limit to 0 but get_max didn't return 0");
294 /* Test3: Set max limits 100 */
295 hildon_range_editor_set_max(range_editor, 100);
296 range_end = hildon_range_editor_get_max(range_editor);
297 fail_if(range_end != 100,
298 "hildon-range-editor: set max limit to 100 but get_max didn't return 100");
303 * Purpose: Check limit maximum values for limits are set properly
305 * - Set min limit to G_MAXINT
307 START_TEST (test_set_max_limits)
311 /* Test1: Set max limit to G_MAXINT */
312 hildon_range_editor_set_max(range_editor, G_MAXINT);
313 range_end = hildon_range_editor_get_max(range_editor);
314 fail_if(range_end != G_MAXINT,
315 "hildon-range-editor: set min limit to G_MAXINT but get_max didn't return G_MAXINT");
320 * Purpose: Check that invalid values are handled properly
322 * - Set maximum limit lower than minimum limit
323 * - Set range editor object to NULL for set_max
325 START_TEST (test_set_max_invalid)
327 gint range_start, range_end;
329 /* Test1: Set maximum limit lower than minimum limit */
330 hildon_range_editor_set_limits(range_editor, -10, 10);
331 hildon_range_editor_set_max(range_editor, -15);
332 range_start = hildon_range_editor_get_min(range_editor);
333 fail_if(range_start != -15,
334 "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");
335 range_end = hildon_range_editor_get_max(range_editor);
336 fail_if(range_end != -15,
337 "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");
339 /* Test2: set range editor to NULL */
340 hildon_range_editor_set_max(NULL, 15);
345 /* ---------- Suite creation ---------- */
347 Suite *create_hildon_range_editor_suite()
349 /* Create the suite */
350 Suite *s = suite_create("HildonRangeEditor");
352 /* Create test cases */
353 TCase *tc1 = tcase_create("set_limits_get_min_get_max");
354 TCase *tc2 = tcase_create("set_min");
355 TCase *tc3 = tcase_create("set_max");
357 /* Create test case for set_limits, get_min and get_max and add it to the suite */
358 tcase_add_checked_fixture(tc1, fx_setup_default_range_editor, fx_teardown_default_range_editor);
359 tcase_add_test(tc1, test_set_limits_get_min_get_max_regular);
360 tcase_add_test(tc1, test_set_limits_get_min_get_max_limits);
361 tcase_add_test(tc1, test_set_limits_get_min_get_max_invalid);
362 suite_add_tcase (s, tc1);
364 /* Create test case for set_min */
365 tcase_add_checked_fixture(tc2, fx_setup_default_range_editor, fx_teardown_default_range_editor);
366 tcase_add_test(tc2, test_set_min_regular);
367 tcase_add_test(tc2, test_set_min_limits);
368 tcase_add_test(tc2, test_set_min_invalid);
369 suite_add_tcase (s, tc2);
371 /* Create test case for set_max */
372 tcase_add_checked_fixture(tc3, fx_setup_default_range_editor, fx_teardown_default_range_editor);
373 tcase_add_test(tc3, test_set_max_regular);
374 tcase_add_test(tc3, test_set_max_limits);
375 tcase_add_test(tc3, test_set_max_invalid);
376 suite_add_tcase (s, tc3);
378 /* Return created suite */