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 <gtk/gtkhbox.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
32 #include "hildon-date-editor.h"
34 /* Taken from the values of the properties of HildonDateEditor */
42 /* -------------------- Fixtures -------------------- */
44 static HildonDateEditor *date_editor = NULL;
45 static GtkWidget *showed_window = NULL;
48 fx_setup_default_date_editor ()
52 gtk_init(&argc, NULL);
54 showed_window = create_test_window ();
56 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
57 /* Check that the date editor object has been created properly */
58 fail_if(!HILDON_IS_DATE_EDITOR(date_editor),
59 "hildon-date-editor: Creation failed.");
61 /* This packs the widget into the window (a gtk container). */
62 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor));
64 /* Displays the widget and the window */
65 show_all_test_window (showed_window);
69 fx_teardown_default_date_editor ()
72 /* Destroy the widget and the window */
73 gtk_widget_destroy (GTK_WIDGET (showed_window));
77 /* -------------------- Test cases -------------------- */
79 /* ----- Test case for set_date -----*/
82 * Purpose: test setting regular values for hildon_date_editor_set_date
84 * - Set and get the date 30/03/1981
86 START_TEST (test_set_date_regular)
88 guint year, month, day;
89 guint ret_year, ret_month, ret_day;
95 /* Test 1: Try date 30/3/1981 */
96 hildon_date_editor_set_date (date_editor, year, month, day);
97 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
99 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
100 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
101 ret_year, ret_month, ret_day, year, month, day);
106 test_set_date_limits_check (guint year, guint month, guint day)
108 guint ret_year, ret_month, ret_day;
110 hildon_date_editor_set_date (date_editor, year, month, day);
111 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
113 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
114 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
115 ret_year, ret_month, ret_day, year, month, day);
119 * Purpose: test limit date values for hildon_date_editor_set_date
121 * - test a year value equal to the year limits (1970, 2037)
122 * - test a month value equal to the month limits (1, 12)
123 * - test a day value equal to the day limits for March (1, 31)
124 * - test a day value equal to the day limits June (1, 30)
125 * - test a day value equal to the day limit for a common February (28-2-1981)
126 * - test a day value equal to the day limit for a February of a leap year (29-2-1980)
128 START_TEST (test_set_date_limits)
130 guint year, month, day;
136 /* Test 1: Test year limits */
137 test_set_date_limits_check (year, month, day);
140 test_set_date_limits_check (year, month, day);
142 /* Test 2: Test month limits */
146 test_set_date_limits_check (year, month, day);
149 test_set_date_limits_check (year, month, day);
151 /* Test 3: Test day limits */
155 test_set_date_limits_check (year, month, day);
157 /* Test 4: Test day limits */
161 test_set_date_limits_check (year, month, day);
163 /* Test 5: Test february limits */
167 test_set_date_limits_check (year, month, day);
169 /* Test 6: Test february limits for a leap year */
173 test_set_date_limits_check (year, month, day);
178 * Purpose: test invalid parameter values for hildon_date_editor_set_date
181 * - test passing GtkHBox instead a HildonDateEditor
183 * - test negative values
184 * - test invalid month days
185 * - test a year value lower and higher than the year limits (1970, 2037)
186 * - test a month value lower and higher than the year limits (1, 12)
187 * - test a day value lower and higher than the year limits (1, 31)
189 START_TEST (test_set_date_invalid)
191 guint year, month, day;
192 guint ret_year, ret_month, ret_day;
193 GtkWidget *aux_object = NULL;
200 hildon_date_editor_set_date (date_editor, year, month, day);
202 /* Test 1: Test NULL */
203 hildon_date_editor_set_date (NULL, year, month, day);
204 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
206 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
207 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
208 ret_year, ret_month, ret_day, year, month, day);
210 /* Test 2: Test another object */
211 aux_object = gtk_hbox_new (TRUE, 0);
212 hildon_date_editor_set_date ((HildonDateEditor *) (aux_object), year, month, day);
213 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
215 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
216 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
217 ret_year, ret_month, ret_day, year, month, day);
218 gtk_widget_destroy (GTK_WIDGET(aux_object));
220 /* Test 3: Test leap year */
221 hildon_date_editor_set_date (date_editor, year, 2, 29);
222 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
224 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
225 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
226 ret_year, ret_month, ret_day, year, month, day);
228 /* Restore the original value */
229 hildon_date_editor_set_date (date_editor, year, month, day);
231 /* Test 4: Test negative values */
232 hildon_date_editor_set_date (date_editor, -year, -month, -day);
233 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
234 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
235 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
236 ret_year, ret_month, ret_day, year, month, day);
238 /* Test 5: Test invalid month days */
239 hildon_date_editor_set_date (date_editor, year, 11, 31);
240 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
241 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
242 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
243 ret_year, ret_month, ret_day, year, month, day);
245 /* Test 6: Test year invalid values, the year value could be set
246 under/over the value of the property because the date is not
247 validated if the value was not set through the user interface */
248 hildon_date_editor_set_date (date_editor, MIN_YEAR - 1, month, day);
249 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
251 fail_if (ret_year != (MIN_YEAR - 1),
252 "hildon-date-editor: The returned year is %u and should be %u",
253 ret_year, MIN_YEAR - 1);
255 hildon_date_editor_set_date (date_editor, MAX_YEAR + 1, month, day);
256 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
258 fail_if (ret_year != MAX_YEAR + 1,
259 "hildon-date-editor: The returned year is %u and should be %u",
260 ret_year, MAX_YEAR + 1);
262 /* Test 7: Test month invalid values, we do not have the same
263 problem with the years because both month 0 and 13 are not valid
265 hildon_date_editor_set_date (date_editor, year, MIN_MONTH - 1, day);
266 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
268 fail_if (ret_month != month,
269 "hildon-date-editor: The returned month is %u and should be %u",
272 hildon_date_editor_set_date (date_editor, year, MAX_MONTH + 1, day);
273 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
275 fail_if (ret_month != month,
276 "hildon-date-editor: The returned month is %u and should be %u",
279 /* Test 8: Test day invalid values */
280 hildon_date_editor_set_date (date_editor, year, month, MIN_DAY - 1);
281 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
283 fail_if (ret_day != day,
284 "hildon-date-editor: The returned day is %u and should be %u",
287 hildon_date_editor_set_date (date_editor, year, month, MAX_DAY + 1);
288 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
290 fail_if (ret_day != day,
291 "hildon-date-editor: The returned day is %u and should be %u",
296 /* ----- Test case for get_date -----*/
298 /* We do not include tests for limit values because we think they're
299 tested enought with the set_data tests */
302 * Purpose: test getting regular values for hildon_date_editor_get_date
304 * - Set and get date 30/03/1981
306 START_TEST (test_get_date_regular)
308 guint year, month, day;
309 guint ret_year, ret_month, ret_day;
310 GValue value = { 0, };
316 /* Test 1: Test regular values */
317 hildon_date_editor_set_date (NULL, year, month, day);
319 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
321 g_value_init (&value, G_TYPE_UINT);
322 g_object_get_property (G_OBJECT (date_editor), "year", &value);
323 fail_if (g_value_get_uint (&value) != ret_year,
324 "hildon-date-editor: get_date failed. The returned year is %u and should be %u",
325 g_value_get_uint (&value),
328 g_value_unset (&value);
329 g_value_init (&value, G_TYPE_UINT);
330 g_object_get_property (G_OBJECT (date_editor), "month", &value);
331 fail_if (g_value_get_uint (&value) != ret_month,
332 "hildon-date-editor: get_date failed. The returned month is %u and should be %u",
333 g_value_get_uint (&value),
336 g_value_unset (&value);
337 g_value_init (&value, G_TYPE_UINT);
338 g_object_get_property (G_OBJECT (date_editor), "day", &value);
339 fail_if (g_value_get_uint (&value) != ret_day,
340 "hildon-date-editor: get_date failed. The returned day is %u and should be %u",
341 g_value_get_uint (&value),
347 * Purpose: test getting regular values passing invalid arguments for
348 * hildon_date_editor_get_date
350 * - HildonDateEditor NULL
355 START_TEST (test_get_date_invalid)
357 guint year, month, day;
358 guint ret_year, ret_month, ret_day;
364 hildon_date_editor_set_date (date_editor, year, month, day);
366 /* Check that does not fail */
367 hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day);
369 /* Check NULL arguments */
370 hildon_date_editor_get_date (date_editor, NULL, &ret_month, &ret_day);
371 fail_if (hildon_date_editor_get_year (date_editor) != year,
372 "hildon-date-editor: get_date failed. The returned year is %u and should be %u",
375 hildon_date_editor_get_date (date_editor, &ret_year, NULL, &ret_day);
376 fail_if (hildon_date_editor_get_month (date_editor) != month,
377 "hildon-date-editor: get_date failed. The returned month is %u and should be %u",
380 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, NULL);
381 fail_if (hildon_date_editor_get_day (date_editor) != day,
382 "hildon-date-editor: get_date failed. The returned day is %u and should be %u",
387 /* ----- Test case for get_year -----*/
390 * Purpose: test getting regular values of the year for hildon_date_editor_get_year
392 * - get a year set with set_date 30/03/1981
393 * - get a year set with set_year 1980
394 * - get a year set with set_property 2004
396 START_TEST (test_get_year_regular)
398 guint year, month, day;
399 GValue value = {0, };
405 /* Test 1: Set year with set_date */
406 hildon_date_editor_set_date (date_editor, year, month, day);
408 fail_if (hildon_date_editor_get_year (date_editor) != year,
409 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
410 hildon_date_editor_get_year (date_editor), year);
412 /* Test 2: set year with set_year */
414 hildon_date_editor_set_year (date_editor, year);
416 fail_if (hildon_date_editor_get_year (date_editor) != year,
417 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
418 hildon_date_editor_get_year (date_editor), year);
420 /* Test 3: set year with set_property */
422 g_value_init (&value, G_TYPE_UINT);
423 g_value_set_uint (&value, year);
424 g_object_set_property (G_OBJECT (date_editor), "year", &value);
426 fail_if (hildon_date_editor_get_year (date_editor) != year,
427 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
428 hildon_date_editor_get_year (date_editor), year);
433 * Purpose: test getting year when a value over the limits was set for
434 * hildon_date_editor_get_year
439 START_TEST (test_get_year_limits)
446 hildon_date_editor_set_year (date_editor, year);
448 /* Test 1: upper limit */
449 hildon_date_editor_set_year (date_editor, MAX_YEAR);
451 fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR,
452 "hildon-date-editor: The returned year is %u and should be %u",
453 hildon_date_editor_get_year (date_editor), MAX_YEAR);
455 /* Test 2: lower limit */
456 hildon_date_editor_set_year (date_editor, MIN_YEAR);
458 fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR,
459 "hildon-date-editor: The returned year is %u and should be %u",
460 hildon_date_editor_get_year (date_editor), MIN_YEAR);
465 * Purpose: test getting a year for invalid attributes for
466 * hildon_date_editor_get_year
468 * - HildonDateEditor is NULL
469 * - Pass a GtkHBox instead a HildonDateEditor
473 START_TEST (test_get_year_invalid)
476 GtkWidget *aux_object = NULL;
478 /* Test 1: Test NULL */
479 ret_year = hildon_date_editor_get_year (NULL);
480 fail_if (ret_year != 0,
481 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
484 /* Test 2: another object */
485 aux_object = gtk_hbox_new (TRUE, 0);
486 ret_year = hildon_date_editor_get_year ((HildonDateEditor *) (aux_object));
487 fail_if (ret_year != 0,
488 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
490 gtk_widget_destroy (GTK_WIDGET(aux_object));
492 /* Test 3: upper limit, the test is OK but it shouldn't. The reason
493 is that the value of the date is not validated by Hildon since it
494 was not set using the UI */
495 hildon_date_editor_set_year (date_editor, MAX_YEAR + 1);
497 fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR + 1,
498 "hildon-date-editor: The returned year is %u and should be %u",
499 hildon_date_editor_get_year (date_editor), MAX_YEAR + 1);
501 /* Test 4: lower limit, see the above comment */
502 hildon_date_editor_set_year (date_editor, MIN_YEAR - 1);
504 fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR - 1,
505 "hildon-date-editor: The returned year is %u and should be %u",
506 hildon_date_editor_get_year (date_editor), MIN_YEAR - 1);
510 /* ----- Test case for set_year -----*/
513 * Purpose: test setting a regular value for a year for
514 * hildon_date_editor_set_year
518 START_TEST (test_set_year_regular)
525 /* Test 1: Try year 1981 */
526 hildon_date_editor_set_year (date_editor, year);
527 ret_year = hildon_date_editor_get_year (date_editor);
529 fail_if (ret_year != year,
530 "hildon-date-editor: set_year failed. The returned year is %u and should be %u",
536 * Purpose: test setting values of the year over the limits for
537 * hildon_date_editor_set_year
542 START_TEST (test_set_year_limits)
545 GValue value = { 0, };
550 hildon_date_editor_set_year (date_editor, year);
552 /* Test 1: Test upper limit */
553 g_value_init (&value, G_TYPE_UINT);
554 hildon_date_editor_set_year (date_editor, MAX_YEAR);
555 g_object_get_property (G_OBJECT (date_editor), "year", &value);
556 fail_if (g_value_get_uint (&value) != MAX_YEAR,
557 "hildon-date-editor: The returned year is %u and should be %u",
558 g_value_get_uint (&value), year);
560 /* Test 2: Test lower limit */
561 g_value_unset (&value);
562 g_value_init (&value, G_TYPE_UINT);
563 hildon_date_editor_set_year (date_editor, MIN_YEAR);
564 g_object_get_property (G_OBJECT (date_editor), "year", &value);
565 fail_if (g_value_get_uint (&value) != MIN_YEAR,
566 "hildon-date-editor: The returned year is %u and should be %u",
567 g_value_get_uint (&value), MIN_YEAR);
571 /* ----- Test case for get_month -----*/
574 * Purpose: test getting a year for regular values for
575 * hildon_date_editor_get_month
577 * - set month with set_date 30/03/1981
578 * - set month with set_month 1
579 * - set month with set_property 7
581 START_TEST (test_get_month_regular)
583 guint year, month, day;
584 GValue value = {0, };
590 /* Test 1: Set year with set_date */
591 hildon_date_editor_set_date (date_editor, year, month, day);
593 fail_if (hildon_date_editor_get_month (date_editor) != month,
594 "hildon-date-editor: The returned month is %u and should be %u",
595 hildon_date_editor_get_month (date_editor), month);
597 /* Test 2: set month with set_month */
599 hildon_date_editor_set_month (date_editor, month);
601 fail_if (hildon_date_editor_get_month (date_editor) != month,
602 "hildon-date-editor: The returned month is %u and should be %u",
603 hildon_date_editor_get_month (date_editor), month);
605 /* Test 3: set month with set_property */
607 g_value_init (&value, G_TYPE_UINT);
608 g_value_set_uint (&value, month);
609 g_object_set_property (G_OBJECT (date_editor), "month", &value);
611 fail_if (hildon_date_editor_get_month (date_editor) != month,
612 "hildon-date-editor: The returned month is %u and should be %u",
613 hildon_date_editor_get_month (date_editor), month);
618 * Purpose: test getting values of the month over the limits for
619 * hildon_date_editor_get_month
624 START_TEST (test_get_month_limits)
627 /* Test 1: Upper limit */
628 hildon_date_editor_set_month (date_editor, MAX_MONTH);
630 fail_if (hildon_date_editor_get_month (date_editor) != MAX_MONTH,
631 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
632 hildon_date_editor_get_month (date_editor), MAX_MONTH);
634 /* Test 2: Lower limit */
635 hildon_date_editor_set_month (date_editor, MIN_MONTH);
637 fail_if (hildon_date_editor_get_month (date_editor) != MIN_MONTH,
638 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
639 hildon_date_editor_get_month (date_editor), MIN_MONTH);
644 * Purpose: test getting a month for invalid attributes for
645 * hildon_date_editor_get_month
647 * - HildonDateEditor is NULL
648 * - HildonDateEditor is really a GtkHBox
650 START_TEST (test_get_month_invalid)
653 GtkWidget *aux_object = NULL;
655 /* Test 1: Test NULL */
656 ret_month = hildon_date_editor_get_month (NULL);
657 fail_if (ret_month != 0,
658 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
661 /* Test 2: another object */
662 aux_object = gtk_hbox_new (TRUE, 0);
663 ret_month = hildon_date_editor_get_month ((HildonDateEditor *) (aux_object));
664 fail_if (ret_month != 0,
665 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
667 gtk_widget_destroy (GTK_WIDGET(aux_object));
671 /* ----- Test case for set_month -----*/
674 * Purpose: test setting regular values for month for
675 * hildon_date_editor_set_month
679 START_TEST (test_set_month_regular)
686 /* Test 1: Try month March (3) */
687 hildon_date_editor_set_month (date_editor, month);
688 ret_month = hildon_date_editor_get_month (date_editor);
690 fail_if (ret_month != month,
691 "hildon-date-editor: set_month failed. The returned month is %u and should be %u",
697 * Purpose: test setting values for month over the limits for
698 * hildon_date_editor_get_month
703 START_TEST (test_set_month_limits)
705 GValue value = { 0, };
707 /* Test 1: Test upper limit */
708 g_value_init (&value, G_TYPE_UINT);
709 hildon_date_editor_set_month (date_editor, MAX_MONTH);
710 g_object_get_property (G_OBJECT (date_editor), "month", &value);
711 fail_if (g_value_get_uint (&value) != MAX_MONTH,
712 "hildon-date-editor: The returned month is %u and should be %u",
713 g_value_get_uint (&value), MAX_MONTH);
715 /* Test 2: Test lower limit */
716 g_value_unset (&value);
717 g_value_init (&value, G_TYPE_UINT);
718 hildon_date_editor_set_month (date_editor, MIN_MONTH);
719 g_object_get_property (G_OBJECT (date_editor), "month", &value);
720 fail_if (g_value_get_uint (&value) != MIN_MONTH,
721 "hildon-date-editor: The returned month is %u and should be %u",
722 g_value_get_uint (&value), MIN_MONTH);
726 /* ----- Test case for get_day -----*/
729 * Purpose: test getting regular values for day for
730 * hildon_date_editor_get_day
732 * - Get a day set with set_date 30/03/1981
733 * - Get a day set with set_day 6
734 * - Get a day set with set_property 10
736 START_TEST (test_get_day_regular)
738 guint year, month, day;
739 GValue value = {0, };
745 /* Test 1: Set day with set_date */
746 hildon_date_editor_set_date (date_editor, year, month, day);
748 fail_if (hildon_date_editor_get_day (date_editor) != day,
749 "hildon-date-editor: The returned day is %u and should be %u",
750 hildon_date_editor_get_day (date_editor), day);
752 /* Test 2: set day with set_day */
754 hildon_date_editor_set_day (date_editor, day);
756 fail_if (hildon_date_editor_get_day (date_editor) != day,
757 "hildon-date-editor: The returned day is %u and should be %u",
758 hildon_date_editor_get_day (date_editor), day);
761 /* Test 3: set day with set_property */
763 g_value_init (&value, G_TYPE_UINT);
764 g_value_set_uint (&value, day);
765 g_object_set_property (G_OBJECT (date_editor), "day", &value);
767 fail_if (hildon_date_editor_get_day (date_editor) != day,
768 "hildon-date-editor: The returned day is %u and should be %u",
769 hildon_date_editor_get_day (date_editor), day);
775 * Purpose: test getting a day set over the limits for
776 * hildon_date_editor_get_day
778 * - Get day 31 for March
779 * - Get day 30 for June
780 * - Get day 29 for February for a leap year
781 * - Get day 28 for February for a common year
784 START_TEST (test_get_day_limits)
786 guint day, month, year;
792 /* Test 1: 31 of February */
793 hildon_date_editor_set_date (date_editor, year, month, day);
794 fail_if (hildon_date_editor_get_day (date_editor) != day,
795 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
796 hildon_date_editor_get_day (date_editor), day);
798 /* Test 2: 30 of February */
801 hildon_date_editor_set_date (date_editor, year, month, day);
802 fail_if (hildon_date_editor_get_day (date_editor) != day,
803 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
804 hildon_date_editor_get_day (date_editor), day);
806 /* Test 3: 29 of February */
810 hildon_date_editor_set_date (date_editor, year, month, day);
811 fail_if (hildon_date_editor_get_day (date_editor) != day,
812 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
813 hildon_date_editor_get_day (date_editor), day);
815 /* Test 3: 28 of February */
819 hildon_date_editor_set_date (date_editor, year, month, day);
820 fail_if (hildon_date_editor_get_day (date_editor) != day,
821 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
822 hildon_date_editor_get_day (date_editor), day);
825 hildon_date_editor_set_day (date_editor, 1);
827 fail_if (hildon_date_editor_get_day (date_editor) != 1,
828 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
829 hildon_date_editor_get_day (date_editor), 1);
834 * Purpose: test getting a day with invalid attributes for
835 * hildon_date_editor_get_day
837 * - HildonDateEditor is NULL
838 * - HildonDateEditor is really a GtkHBox
840 START_TEST (test_get_day_invalid)
843 GtkWidget *aux_object = NULL;
845 /* Test 1: Test NULL */
846 ret_year = hildon_date_editor_get_year (NULL);
847 fail_if (ret_year != 0,
848 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
851 /* Test 2: another object */
852 aux_object = gtk_hbox_new (TRUE, 0);
853 ret_year = hildon_date_editor_get_year ((HildonDateEditor *) aux_object);
854 fail_if (ret_year != 0,
855 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
857 gtk_widget_destroy (GTK_WIDGET(aux_object));
861 /* ----- Test case for set_day -----*/
864 * Purpose: test setting a regular value for day for
865 * hildon_date_editor_get_day
869 START_TEST (test_set_day_regular)
876 /* Test 1: Try day 30 */
877 hildon_date_editor_set_day (date_editor, day);
878 ret_day = hildon_date_editor_get_day (date_editor);
880 fail_if (ret_day != day,
881 "hildon-date-editor: set_day failed. The returned day is %u and should be %u",
887 * Purpose: test seeting a day over the limits for
888 * hildon_date_editor_get_day
896 START_TEST (test_set_day_limits)
898 guint day, year, month;
899 GValue value = { 0, };
906 hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);
908 /* Test 1: Test 31/03 */
909 g_value_init (&value, G_TYPE_UINT);
910 hildon_date_editor_set_day (date_editor, day);
911 g_object_get_property (G_OBJECT (date_editor), "day", &value);
912 fail_if (g_value_get_uint (&value) != day,
913 "hildon-date-editor: The returned day is %u and should be %u",
914 g_value_get_uint (&value), day);
916 /* Test 2: Test 30/06 */
919 hildon_date_editor_set_date (date_editor, year, month, 1);
920 g_value_unset (&value);
921 g_value_init (&value, G_TYPE_UINT);
922 hildon_date_editor_set_day (date_editor, day);
923 g_object_get_property (G_OBJECT (date_editor), "day", &value);
924 fail_if (g_value_get_uint (&value) != day,
925 "hildon-date-editor: The returned day is %u and should be %u",
926 g_value_get_uint (&value), day);
928 /* Test 3: Test 29/02/1980 */
932 hildon_date_editor_set_date (date_editor, year, month, 1);
933 g_value_unset (&value);
934 g_value_init (&value, G_TYPE_UINT);
935 hildon_date_editor_set_day (date_editor, day);
936 g_object_get_property (G_OBJECT (date_editor), "day", &value);
937 fail_if (g_value_get_uint (&value) != day,
938 "hildon-date-editor: The returned day is %u and should be %u",
939 g_value_get_uint (&value), day);
941 /* Test 4: Test 28/02/1981 */
945 hildon_date_editor_set_date (date_editor, year, month, 1);
946 g_value_unset (&value);
947 g_value_init (&value, G_TYPE_UINT);
948 hildon_date_editor_set_day (date_editor, day);
949 g_object_get_property (G_OBJECT (date_editor), "day", &value);
950 fail_if (g_value_get_uint (&value) != day,
951 "hildon-date-editor: The returned day is %u and should be %u",
952 g_value_get_uint (&value), day);
954 /* Test 5: Test 1/02/1980 */
958 hildon_date_editor_set_date (date_editor, year, month, 10);
959 g_value_unset (&value);
960 g_value_init (&value, G_TYPE_UINT);
961 hildon_date_editor_set_day (date_editor, day);
962 g_object_get_property (G_OBJECT (date_editor), "day", &value);
963 fail_if (g_value_get_uint (&value) != day,
964 "hildon-date-editor: The returned day is %u and should be %u",
965 g_value_get_uint (&value), day);
969 /* ---------- Suite creation ---------- */
971 Suite *create_hildon_date_editor_suite(void)
973 /* Create the suite */
974 Suite *s = suite_create("HildonDateEditor");
976 /* Create test cases */
977 TCase *tc1 = tcase_create("set_date");
978 TCase *tc2 = tcase_create("get_date");
979 TCase *tc3 = tcase_create("get_year");
980 TCase *tc4 = tcase_create("set_year");
981 TCase *tc5 = tcase_create("get_month");
982 TCase *tc6 = tcase_create("set_month");
983 TCase *tc7 = tcase_create("get_day");
984 TCase *tc8 = tcase_create("set_day");
986 /* Create test case for set_date and add it to the suite */
987 tcase_add_checked_fixture(tc1, fx_setup_default_date_editor, fx_teardown_default_date_editor);
988 tcase_add_test(tc1, test_set_date_regular);
989 tcase_add_test(tc1, test_set_date_limits);
990 tcase_add_test(tc1, test_set_date_invalid);
991 suite_add_tcase (s, tc1);
993 /* Create test case for get_date and add it to the suite */
994 tcase_add_checked_fixture(tc2, fx_setup_default_date_editor, fx_teardown_default_date_editor);
995 tcase_add_test(tc2, test_get_date_regular);
996 tcase_add_test(tc2, test_get_date_invalid);
997 suite_add_tcase (s, tc2);
999 /* Create test case for get_year and add it to the suite */
1000 tcase_add_checked_fixture(tc3, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1001 tcase_add_test(tc3, test_get_year_regular);
1002 tcase_add_test(tc3, test_get_year_limits);
1003 tcase_add_test(tc3, test_get_year_invalid);
1004 suite_add_tcase (s, tc3);
1006 /* Create test case for set_year and add it to the suite */
1007 tcase_add_checked_fixture(tc4, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1008 tcase_add_test(tc4, test_set_year_regular);
1009 tcase_add_test(tc4, test_set_year_limits);
1010 suite_add_tcase (s, tc4);
1012 /* Create test case for get_month and add it to the suite */
1013 tcase_add_checked_fixture(tc5, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1014 tcase_add_test(tc5, test_get_month_regular);
1015 tcase_add_test(tc5, test_get_month_limits);
1016 tcase_add_test(tc5, test_get_month_invalid);
1017 suite_add_tcase (s, tc5);
1019 /* Create test case for set_month and add it to the suite */
1020 tcase_add_checked_fixture(tc6, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1021 tcase_add_test(tc6, test_set_month_regular);
1022 tcase_add_test(tc6, test_set_month_limits);
1023 suite_add_tcase (s, tc6);
1025 /* Create test case for get_day and add it to the suite */
1026 tcase_add_checked_fixture(tc7, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1027 tcase_add_test(tc7, test_get_day_regular);
1028 tcase_add_test(tc7, test_get_day_limits);
1029 tcase_add_test(tc7, test_get_day_invalid);
1030 suite_add_tcase (s, tc7);
1032 /* Create test case for set_day and add it to the suite */
1033 tcase_add_checked_fixture(tc8, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1034 tcase_add_test(tc8, test_set_day_regular);
1035 tcase_add_test(tc8, test_set_day_limits);
1036 suite_add_tcase (s, tc8);
1038 /* Return created suite */