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
28 #include <gtk/gtkmain.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
32 #include <hildon/hildon-calendar-popup.h>
34 /* -------------------- Fixtures -------------------- */
36 static HildonCalendarPopup *calendar = NULL;
39 fx_setup_default_calendar()
43 gtk_init(&argc, NULL);
45 calendar = HILDON_CALENDAR_POPUP(hildon_calendar_popup_new(NULL, 2006, 4, 10));
47 show_test_window(GTK_WIDGET(calendar));
49 /* Check calendar object has been created properly */
50 fail_if(!HILDON_IS_CALENDAR_POPUP(calendar),
51 "hildon-calendar-popup: Creation failed.");
55 fx_teardown_default_calendar()
58 gtk_widget_destroy(GTK_WIDGET(calendar));
62 /* -------------------- Test cases -------------------- */
64 /* ------ Test case for get/set_date ----- */
67 * Purpose: Check regular values for dates
69 * - Set and get date 30/03/1981
71 START_TEST (test_set_get_date_regular)
73 guint year, month, day;
74 guint ret_year, ret_month, ret_day;
76 /* Test1: set a valid date like 30/03/1981 */
80 hildon_calendar_popup_set_date(calendar, year, month, day);
81 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
82 fail_if(year != ret_year || month != ret_month || day != ret_day,
83 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned date %u/%u/%u",
84 year, month, day, ret_year, ret_month, ret_day);
90 * Purpose: Check limit values for dates
92 * - Set and get year to max-year property
93 * - Set and get year to min-year property
94 * - Set and get month to 12
95 * - Set and get month to 1
96 * - Set and get day to 31 (March)
97 * - Set and get day to 30 (April)
98 * - Set and get day to 29 (February 2004)
99 * - Set and get day to 28 (February 2006)
100 * - Set and get day to 1
101 * - Set and get maximum allowed date (according to max-year property).
102 * - Set and get minimum allowed date (according to min-year property).
104 START_TEST (test_set_get_date_limits)
106 GValue value = {0, };
107 guint year, month, day;
108 guint ret_year, ret_month, ret_day;
109 guint max_year, min_year;
111 g_value_init(&value, G_TYPE_UINT);
113 /* Test1: Test year maximum limit */
115 g_value_set_uint (&value, max_year);
116 g_object_set_property (G_OBJECT (calendar), "max-year", &value);
120 hildon_calendar_popup_set_date(calendar, year, month, day);
121 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
122 fail_if(year != ret_year,
123 "hildon-calendar-popup: Set date to %u/%u/%u, with maximum year set to %u, but get date returned year %u",
124 year, month, day, max_year, ret_year);
126 /* Test2: Test year minimum limit */
128 g_value_set_uint (&value, min_year);
129 g_object_set_property (G_OBJECT (calendar), "min-year", &value);
133 hildon_calendar_popup_set_date(calendar, year, month, day);
134 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
135 fail_if(year != ret_year,
136 "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned year %u",
137 year, month, day, min_year, ret_year);
139 /* Test3: Test month minimum limit */
143 hildon_calendar_popup_set_date(calendar, year, month, day);
144 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
145 fail_if(month != ret_month,
146 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned month %u",
147 year, month, day, ret_month);
149 /* Test4: Test month maximum limit */
153 hildon_calendar_popup_set_date(calendar, year, month, day);
154 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
155 fail_if(month != ret_month,
156 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned month %u",
157 year, month, day, ret_month);
159 /* Test5: Test day maximum limit */
165 hildon_calendar_popup_set_date(calendar, year, month, day);
166 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
167 fail_if(day != ret_day,
168 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u",
169 year, month, day, ret_day);
175 hildon_calendar_popup_set_date(calendar, year, month, day);
176 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
177 fail_if(day != ret_day,
178 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u",
179 year, month, day, ret_day);
185 hildon_calendar_popup_set_date(calendar, year, month, day);
186 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
187 fail_if(day != ret_day,
188 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u",
189 year, month, day, ret_day);
195 hildon_calendar_popup_set_date(calendar, year, month, day);
196 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
197 fail_if(day != ret_day,
198 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u",
199 year, month, day, ret_day);
201 /* Test6: Test day minimum limit */
205 hildon_calendar_popup_set_date(calendar, year, month, day);
206 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
207 fail_if(day != ret_day,
208 "hildon-calendar-popup: Set date to %u/%u/%u, but get date returned day %u",
209 year, month, day, ret_day);
211 /* Test7: Test maximum allowed date */
213 g_value_set_uint (&value, max_year);
214 g_object_set_property (G_OBJECT (calendar), "max-year", &value);
218 hildon_calendar_popup_set_date(calendar, year, month, day);
219 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
220 fail_if(year != ret_year,
221 "hildon-calendar-popup: Set date to %u/%u/%u, with maximum year set to %u, but get date returned date %u/%u/%u",
222 year, month, day, max_year, ret_year, ret_month, ret_day);
224 /* Test8: Test minimum allowed date */
226 g_value_set_uint (&value, min_year);
227 g_object_set_property (G_OBJECT (calendar), "min-year", &value);
231 hildon_calendar_popup_set_date(calendar, year, month, day);
232 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
233 fail_if(year != ret_year,
234 "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned date %u/%u/%u",
235 year, month, day, min_year, ret_year, ret_month, ret_day);
240 * Purpose: Check invalid values for dates
242 * - Set and get year above max-year property
243 * - Set and get year under min-year property
244 * - Set and get month to 13
245 * - Set and get month to 0
246 * - Set and get day to 32 (March)
247 * - Set and get day to 31 (April)
248 * - Set and get day to 30 (February 2004)
249 * - Set and get day to 29 (February 2006)
250 * - Set and get day to 0
251 * - Set and get above maximum allowed date (according to max-year property).
252 * - Set and get under minimum allowed date (according to min-year property).
253 * - Set and get date using NULL calendar object
255 START_TEST (test_set_get_date_invalid)
257 GValue value = {0, };
258 guint year, month, day;
259 guint valid_year, valid_month, valid_day;
260 guint current_year, current_month, current_day;
261 guint ret_year, ret_month, ret_day;
262 guint max_year, min_year;
265 g_value_init(&value, G_TYPE_UINT);
267 /* Test 1: Test under minimum year limit */
269 g_value_set_uint (&value, min_year);
270 g_object_set_property (G_OBJECT (calendar), "min-year", &value);
274 hildon_calendar_popup_set_date(calendar, year, month, day);
275 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
276 fail_if(min_year != ret_year,
277 "hildon-calendar-popup: Set date to %u/%u/%u, with minimum year set to %u, but get date returned year = %u != %u",
278 year, month, day, min_year, ret_year, min_year);
280 /* Test 2: Test above maximum month limit */
284 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
288 hildon_calendar_popup_set_date(calendar, year, month, day);
289 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
291 /* Gets the curret date */
292 g_date_clear(&date, 1);
293 g_date_set_time(&date, time(NULL));
295 current_day = g_date_get_day(&date);
296 current_month = g_date_get_month(&date);
297 current_year = g_date_get_year(&date);
299 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
300 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
301 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
304 /* Test 3: Test under minimum month limit */
308 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
312 hildon_calendar_popup_set_date(calendar, year, month, day);
313 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
315 /* Gets the curret date */
316 g_date_clear(&date, 1);
317 g_date_set_time(&date, time(NULL));
319 current_day = g_date_get_day(&date);
320 current_month = g_date_get_month(&date);
321 current_year = g_date_get_year(&date);
323 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
324 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
325 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
328 /* Test 4: Test above maximum day limit */
334 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
338 hildon_calendar_popup_set_date(calendar, year, month, day);
339 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
341 /* Gets the curret date */
342 g_date_clear(&date, 1);
343 g_date_set_time(&date, time(NULL));
345 current_day = g_date_get_day(&date);
346 current_month = g_date_get_month(&date);
347 current_year = g_date_get_year(&date);
349 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
350 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
351 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
358 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
362 hildon_calendar_popup_set_date(calendar, year, month, day);
363 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
365 /* Gets the curret date */
366 g_date_clear(&date, 1);
367 g_date_set_time(&date, time(NULL));
369 current_day = g_date_get_day(&date);
370 current_month = g_date_get_month(&date);
371 current_year = g_date_get_year(&date);
373 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
374 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
375 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
381 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
385 hildon_calendar_popup_set_date(calendar, year, month, day);
386 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
388 /* Gets the curret date */
389 g_date_clear(&date, 1);
390 g_date_set_time(&date, time(NULL));
392 current_day = g_date_get_day(&date);
393 current_month = g_date_get_month(&date);
394 current_year = g_date_get_year(&date);
396 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
397 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
398 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
405 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
409 hildon_calendar_popup_set_date(calendar, year, month, day);
410 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
412 /* Gets the curret date */
413 g_date_clear(&date, 1);
414 g_date_set_time(&date, time(NULL));
416 current_day = g_date_get_day(&date);
417 current_month = g_date_get_month(&date);
418 current_year = g_date_get_year(&date);
420 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
421 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
422 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
424 /* Test5: Test day minimum limit */
428 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
432 hildon_calendar_popup_set_date(calendar, year, month, day);
433 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
435 /* Gets the curret date */
436 g_date_clear(&date, 1);
437 g_date_set_time(&date, time(NULL));
439 current_day = g_date_get_day(&date);
440 current_month = g_date_get_month(&date);
441 current_year = g_date_get_year(&date);
443 fail_if((current_year != ret_year) || (current_month != ret_month) || (current_day != ret_day),
444 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, but get date returned %u/%u/%u instead of %u/%u/%u",
445 valid_year, valid_month, valid_day, year, month, day, ret_year, ret_month, ret_day, current_year, current_month, current_day);
447 /* Test6: Test above maximum allowed date */
449 g_value_set_uint (&value, max_year);
450 g_object_set_property (G_OBJECT (calendar), "max-year", &value);
454 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
458 hildon_calendar_popup_set_date(calendar, year, month, day);
459 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
460 fail_if((max_year != ret_year) || (month != ret_month) || (day != ret_day),
461 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, with maximum year set to %u, but get date returned %u/%u/%u instead of %u/%u/%u",
462 valid_year, valid_month, valid_day, year, month, day, max_year, ret_year, ret_month, ret_day, max_year, month, day);
464 /* Test7: Test minimum allowed date */
466 g_value_set_uint (&value, min_year);
467 g_object_set_property (G_OBJECT (calendar), "min-year", &value);
471 hildon_calendar_popup_set_date(calendar, valid_year, valid_month, valid_day);
475 hildon_calendar_popup_set_date(calendar, year, month, day);
476 hildon_calendar_popup_get_date(calendar, &ret_year, &ret_month, &ret_day);
477 fail_if((min_year != ret_year) || (month != ret_month) || (day != ret_day),
478 "hildon-calendar-popup: Set valid date to %u/%u/%u, then set an invalid date %u/%u/%u, with minimum year set to %u, but get date returned %u/%u/%u instead of %u/%u/%u",
479 valid_year, valid_month, valid_day, year, month, day, min_year, ret_year, ret_month, ret_day, min_year, month, day);
481 /* Test8: Set and get date with NULL calendar objects */
482 hildon_calendar_popup_set_date(NULL, 2006, 10, 15);
483 hildon_calendar_popup_get_date(NULL, &year, &month, &day);
487 /* ---------- Suite creation ---------- */
489 Suite *create_hildon_calendar_popup_suite()
491 /* Create the suite */
492 Suite *s = suite_create("HildonCalendarPopup");
494 /* Create test cases */
495 TCase *tc1 = tcase_create("set_get_date");
497 /* Create test case for set_date and get_date and add it to the suite */
498 tcase_add_checked_fixture(tc1, fx_setup_default_calendar, fx_teardown_default_calendar);
499 tcase_add_test(tc1, test_set_get_date_regular);
500 tcase_add_test(tc1, test_set_get_date_limits);
501 tcase_add_test(tc1, test_set_get_date_invalid);
502 suite_add_tcase (s, tc1);
504 /* Return created suite */