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 "test_suites.h"
27 #include "check_utils.h"
29 #include "hildon-window.h"
30 #include "hildon-time-picker.h"
32 /* -------------------- Fixtures -------------------- */
34 static HildonTimePicker *time_picker = NULL;
35 static HildonWindow *tp_window = NULL;
38 fx_setup_default_time_picker ()
41 gtk_init(&argc, NULL);
43 tp_window = HILDON_WINDOW(hildon_window_new());
44 /* Check window object has been created properly */
45 fail_if(!HILDON_IS_WINDOW(tp_window),
46 "hildon-time-picker: Window creation failed.");
48 time_picker = HILDON_TIME_PICKER(hildon_time_picker_new(GTK_WINDOW(tp_window)));
50 /* Check time_picker object has been created properly */
51 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
52 "hildon-time-picker: Creation failed.");
54 /* Displays the widget and the window */
55 show_all_test_window (GTK_WIDGET (tp_window));
56 show_all_test_window (GTK_WIDGET (time_picker));
61 fx_teardown_default_time_picker ()
63 gtk_widget_destroy (GTK_WIDGET (time_picker));
64 gtk_widget_destroy (GTK_WIDGET (tp_window));
67 /* -------------------- Test cases -------------------- */
69 /* ----- Test case for set_time -----*/
72 * Purpose: Check that regular time values are set and get properly
74 * - Set and get time to 5h 30m using time picker object.
75 * - Set and get time to 18h 2m using time picker object.
77 START_TEST (test_set_time_regular)
84 /* Check time_picker object has been created properly */
85 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
86 "hildon-time-picker: Creation failed.");
88 /* Test 1: Set and get time to 5h 30m using time picker object. */
92 hildon_time_picker_set_time(time_picker,hours,minutes);
93 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
95 fail_if (hours != ret_hours || minutes != ret_minutes,
96 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
97 hours, minutes, ret_hours, ret_minutes);
99 /* Test 2: Set and get time to 18h 2m using time picker object. */
103 hildon_time_picker_set_time(time_picker,hours,minutes);
104 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
106 fail_if (hours != ret_hours || minutes != ret_minutes,
107 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
108 hours, minutes, ret_hours, ret_minutes);
113 * Purpose: Check that limit time values are set and get properly
115 * - Set and get time to 0h 0m using time picker object.
116 * - Set and get time to 0h 59m using time picker object.
117 * - Set and get time to 12h 59m using time picker object.
118 * - Set and get time to 23h 59m using time picker object.
120 START_TEST (test_set_time_limits)
127 /* Check time_picker object has been created properly */
128 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
129 "hildon-time-picker: Creation failed.");
131 /* Test 1: Set and get time to 0h 0m using time picker object. */
135 hildon_time_picker_set_time(time_picker,hours,minutes);
136 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
138 fail_if (hours != ret_hours || minutes != ret_minutes,
139 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
140 hours, minutes, ret_hours, ret_minutes);
142 /* Test 2: Set and get time to 0h 59m using time picker object. */
146 hildon_time_picker_set_time(time_picker,hours,minutes);
147 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
149 fail_if (hours != ret_hours || minutes != ret_minutes,
150 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
151 hours, minutes, ret_hours, ret_minutes);
153 /* Test 3: Set and get time to 12h 59m using time picker object. */
157 hildon_time_picker_set_time(time_picker,hours,minutes);
158 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
160 fail_if (hours != ret_hours || minutes != ret_minutes,
161 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
162 hours, minutes, ret_hours, ret_minutes);
164 /* Test 4: Set and get time to 23h 59m using time picker object. */
168 hildon_time_picker_set_time(time_picker,hours,minutes);
169 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
171 fail_if (hours != ret_hours || minutes != ret_minutes,
172 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
173 hours, minutes, ret_hours, ret_minutes);
178 * Purpose: Check that limit time values are set and get properly
180 * - Set and get time using NULL time picker.
181 * - Set and get time to 0h 60m using time picker object.
182 * - Set and get time to 24h 0m using time picker object.
183 * - Set and get time to 24h 60m using time picker object.
184 * - Set and get time to 16000h 15533m using time picker object.
186 START_TEST (test_set_time_invalid)
192 guint expected_hours;
193 guint expected_minutes;
195 /* Check time_picker object has been created properly */
196 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
197 "hildon-time-picker: Creation failed.");
204 /* Test 1: Set and get time using NULL time picker */
205 hildon_time_picker_set_time(NULL,hours,minutes);
206 hildon_time_picker_get_time(NULL,&ret_hours,&ret_minutes);
208 /* Test 2: Set and get time to 0h 60m using time picker object. */
209 hildon_time_picker_set_time(time_picker,hours,minutes);
210 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
212 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
213 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
214 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
216 /* Test 3: Set and get time to 24h 0m using time picker object. */
222 hildon_time_picker_set_time(time_picker,hours,minutes);
223 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
225 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
226 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
227 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
229 /* Test 4: Set and get time to 24h 60m using time picker object. */
235 hildon_time_picker_set_time(time_picker,hours,minutes);
236 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
238 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
239 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
240 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
242 /* Test 5: Set and get time to 16000h 15533m using time picker object.*/
248 hildon_time_picker_set_time(time_picker,hours,minutes);
249 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
251 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
252 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
253 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
257 /* ---------- Suite creation ---------- */
259 Suite *create_hildon_time_picker_suite()
261 /* Create the suite */
262 Suite *s = suite_create("HildonTimePicker");
264 /* Create test cases */
265 TCase *tc1 = tcase_create("set_time");
267 /* Create test case for hildon_time_picker_set_time and add it to the suite */
268 tcase_add_checked_fixture(tc1, fx_setup_default_time_picker, fx_teardown_default_time_picker);
269 tcase_add_test(tc1, test_set_time_regular);
270 tcase_add_test(tc1, test_set_time_limits);
271 tcase_add_test(tc1, test_set_time_invalid);
272 suite_add_tcase(s, tc1);
274 /* Return created suite */