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
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
26 #include <gtk/gtkmain.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
30 #include "hildon-window.h"
31 #include "hildon-time-picker.h"
33 /* -------------------- Fixtures -------------------- */
35 static HildonTimePicker *time_picker = NULL;
36 static HildonWindow *tp_window = NULL;
39 fx_setup_default_time_picker ()
42 gtk_init(&argc, NULL);
44 tp_window = HILDON_WINDOW(hildon_window_new());
45 /* Check window object has been created properly */
46 fail_if(!HILDON_IS_WINDOW(tp_window),
47 "hildon-time-picker: Window creation failed.");
49 time_picker = HILDON_TIME_PICKER(hildon_time_picker_new(GTK_WINDOW(tp_window)));
51 /* Check time_picker object has been created properly */
52 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
53 "hildon-time-picker: Creation failed.");
55 /* Displays the widget and the window */
56 show_all_test_window (GTK_WIDGET (tp_window));
57 show_all_test_window (GTK_WIDGET (time_picker));
62 fx_teardown_default_time_picker ()
64 gtk_widget_destroy (GTK_WIDGET (time_picker));
65 gtk_widget_destroy (GTK_WIDGET (tp_window));
68 /* -------------------- Test cases -------------------- */
70 /* ----- Test case for set_time -----*/
73 * Purpose: Check that regular time values are set and get properly
75 * - Set and get time to 5h 30m using time picker object.
76 * - Set and get time to 18h 2m using time picker object.
78 START_TEST (test_set_time_regular)
85 /* Check time_picker object has been created properly */
86 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
87 "hildon-time-picker: Creation failed.");
89 /* Test 1: Set and get time to 5h 30m using time picker object. */
93 hildon_time_picker_set_time(time_picker,hours,minutes);
94 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
96 fail_if (hours != ret_hours || minutes != ret_minutes,
97 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
98 hours, minutes, ret_hours, ret_minutes);
100 /* Test 2: Set and get time to 18h 2m using time picker object. */
104 hildon_time_picker_set_time(time_picker,hours,minutes);
105 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
107 fail_if (hours != ret_hours || minutes != ret_minutes,
108 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
109 hours, minutes, ret_hours, ret_minutes);
114 * Purpose: Check that limit time values are set and get properly
116 * - Set and get time to 0h 0m using time picker object.
117 * - Set and get time to 0h 59m using time picker object.
118 * - Set and get time to 12h 59m using time picker object.
119 * - Set and get time to 23h 59m using time picker object.
121 START_TEST (test_set_time_limits)
128 /* Check time_picker object has been created properly */
129 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
130 "hildon-time-picker: Creation failed.");
132 /* Test 1: Set and get time to 0h 0m using time picker object. */
136 hildon_time_picker_set_time(time_picker,hours,minutes);
137 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
139 fail_if (hours != ret_hours || minutes != ret_minutes,
140 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
141 hours, minutes, ret_hours, ret_minutes);
143 /* Test 2: Set and get time to 0h 59m using time picker object. */
147 hildon_time_picker_set_time(time_picker,hours,minutes);
148 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
150 fail_if (hours != ret_hours || minutes != ret_minutes,
151 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
152 hours, minutes, ret_hours, ret_minutes);
154 /* Test 3: Set and get time to 12h 59m using time picker object. */
158 hildon_time_picker_set_time(time_picker,hours,minutes);
159 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
161 fail_if (hours != ret_hours || minutes != ret_minutes,
162 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
163 hours, minutes, ret_hours, ret_minutes);
165 /* Test 4: Set and get time to 23h 59m using time picker object. */
169 hildon_time_picker_set_time(time_picker,hours,minutes);
170 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
172 fail_if (hours != ret_hours || minutes != ret_minutes,
173 "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
174 hours, minutes, ret_hours, ret_minutes);
179 * Purpose: Check that limit time values are set and get properly
181 * - Set and get time using NULL time picker.
182 * - Set and get time to 0h 60m using time picker object.
183 * - Set and get time to 24h 0m using time picker object.
184 * - Set and get time to 24h 60m using time picker object.
185 * - Set and get time to 16000h 15533m using time picker object.
187 START_TEST (test_set_time_invalid)
193 guint expected_hours;
194 guint expected_minutes;
196 /* Check time_picker object has been created properly */
197 fail_if(!HILDON_IS_TIME_PICKER(time_picker),
198 "hildon-time-picker: Creation failed.");
205 /* Test 1: Set and get time using NULL time picker */
206 hildon_time_picker_set_time(NULL,hours,minutes);
207 hildon_time_picker_get_time(NULL,&ret_hours,&ret_minutes);
209 /* Test 2: Set and get time to 0h 60m using time picker object. */
210 hildon_time_picker_set_time(time_picker,hours,minutes);
211 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
213 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
214 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
215 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
217 /* Test 3: Set and get time to 24h 0m using time picker object. */
223 hildon_time_picker_set_time(time_picker,hours,minutes);
224 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
226 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
227 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
228 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
230 /* Test 4: Set and get time to 24h 60m using time picker object. */
236 hildon_time_picker_set_time(time_picker,hours,minutes);
237 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
239 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
240 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
241 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
243 /* Test 5: Set and get time to 16000h 15533m using time picker object.*/
249 hildon_time_picker_set_time(time_picker,hours,minutes);
250 hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
252 fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
253 "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
254 hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);
258 /* ---------- Suite creation ---------- */
260 Suite *create_hildon_time_picker_suite()
262 /* Create the suite */
263 Suite *s = suite_create("HildonTimePicker");
265 /* Create test cases */
266 TCase *tc1 = tcase_create("set_time");
268 /* Create test case for hildon_time_picker_set_time and add it to the suite */
269 tcase_add_checked_fixture(tc1, fx_setup_default_time_picker, fx_teardown_default_time_picker);
270 tcase_add_test(tc1, test_set_time_regular);
271 tcase_add_test(tc1, test_set_time_limits);
272 tcase_add_test(tc1, test_set_time_invalid);
273 suite_add_tcase(s, tc1);
275 /* Return created suite */