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 <gtk/gtkhbox.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
30 #include "hildon-date-editor.h"
32 /* Taken from the values of the properties of HildonDateEditor */
40 /* -------------------- Fixtures -------------------- */
42 static HildonDateEditor *date_editor = NULL;
43 static GtkWidget *showed_window = NULL;
46 fx_setup_default_date_editor ()
50 gtk_init(&argc, NULL);
52 showed_window = create_test_window ();
54 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
55 /* Check that the date editor object has been created properly */
56 fail_if(!HILDON_IS_DATE_EDITOR(date_editor),
57 "hildon-date-editor: Creation failed.");
59 /* This packs the widget into the window (a gtk container). */
60 gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor));
62 /* Displays the widget and the window */
63 show_all_test_window (showed_window);
67 fx_teardown_default_date_editor ()
70 /* Destroy the widget and the window */
71 gtk_widget_destroy (GTK_WIDGET (showed_window));
75 /* -------------------- Test cases -------------------- */
77 /* ----- Test case for set_date -----*/
80 * Purpose: test setting regular values for hildon_date_editor_set_date
82 * - Set and get the date 30/03/1981
84 START_TEST (test_set_date_regular)
86 guint year, month, day;
87 guint ret_year, ret_month, ret_day;
93 /* Test 1: Try date 30/3/1981 */
94 hildon_date_editor_set_date (date_editor, year, month, day);
95 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
97 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
98 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
99 ret_year, ret_month, ret_day, year, month, day);
104 test_set_date_limits_check (guint year, guint month, guint day)
106 guint ret_year, ret_month, ret_day;
108 hildon_date_editor_set_date (date_editor, year, month, day);
109 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
111 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
112 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
113 ret_year, ret_month, ret_day, year, month, day);
117 * Purpose: test limit date values for hildon_date_editor_set_date
119 * - test a year value equal to the year limits (1970, 2037)
120 * - test a month value equal to the month limits (1, 12)
121 * - test a day value equal to the day limits for March (1, 31)
122 * - test a day value equal to the day limits June (1, 30)
123 * - test a day value equal to the day limit for a common February (28-2-1981)
124 * - test a day value equal to the day limit for a February of a leap year (29-2-1980)
126 START_TEST (test_set_date_limits)
128 guint year, month, day;
134 /* Test 1: Test year limits */
135 test_set_date_limits_check (year, month, day);
138 test_set_date_limits_check (year, month, day);
140 /* Test 2: Test month limits */
144 test_set_date_limits_check (year, month, day);
147 test_set_date_limits_check (year, month, day);
149 /* Test 3: Test day limits */
153 test_set_date_limits_check (year, month, day);
155 /* Test 4: Test day limits */
159 test_set_date_limits_check (year, month, day);
161 /* Test 5: Test february limits */
165 test_set_date_limits_check (year, month, day);
167 /* Test 6: Test february limits for a leap year */
171 test_set_date_limits_check (year, month, day);
176 * Purpose: test invalid parameter values for hildon_date_editor_set_date
179 * - test passing GtkHBox instead a HildonDateEditor
181 * - test negative values
182 * - test invalid month days
183 * - test a year value lower and higher than the year limits (1970, 2037)
184 * - test a month value lower and higher than the year limits (1, 12)
185 * - test a day value lower and higher than the year limits (1, 31)
187 START_TEST (test_set_date_invalid)
189 guint year, month, day;
190 guint ret_year, ret_month, ret_day;
191 GtkWidget *aux_object = NULL;
198 hildon_date_editor_set_date (date_editor, year, month, day);
200 /* Test 1: Test NULL */
201 hildon_date_editor_set_date (NULL, year, month, day);
202 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
204 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
205 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
206 ret_year, ret_month, ret_day, year, month, day);
208 /* Test 2: Test another object */
209 aux_object = gtk_hbox_new (TRUE, 0);
210 hildon_date_editor_set_date ((HildonDateEditor *) (aux_object), year, month, day);
211 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
213 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
214 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
215 ret_year, ret_month, ret_day, year, month, day);
216 gtk_widget_destroy (GTK_WIDGET(aux_object));
218 /* Test 3: Test leap year */
219 hildon_date_editor_set_date (date_editor, year, 2, 29);
220 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
222 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
223 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
224 ret_year, ret_month, ret_day, year, month, day);
226 /* Restore the original value */
227 hildon_date_editor_set_date (date_editor, year, month, day);
229 /* Test 4: Test negative values */
230 hildon_date_editor_set_date (date_editor, -year, -month, -day);
231 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
232 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
233 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
234 ret_year, ret_month, ret_day, year, month, day);
236 /* Test 5: Test invalid month days */
237 hildon_date_editor_set_date (date_editor, year, 11, 31);
238 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
239 fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
240 "hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
241 ret_year, ret_month, ret_day, year, month, day);
243 /* Test 6: Test year invalid values, the year value could be set
244 under/over the value of the property because the date is not
245 validated if the value was not set through the user interface */
246 hildon_date_editor_set_date (date_editor, MIN_YEAR - 1, month, day);
247 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
249 fail_if (ret_year != (MIN_YEAR - 1),
250 "hildon-date-editor: The returned year is %u and should be %u",
251 ret_year, MIN_YEAR - 1);
253 hildon_date_editor_set_date (date_editor, MAX_YEAR + 1, month, day);
254 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
256 fail_if (ret_year != MAX_YEAR + 1,
257 "hildon-date-editor: The returned year is %u and should be %u",
258 ret_year, MAX_YEAR + 1);
260 /* Test 7: Test month invalid values, we do not have the same
261 problem with the years because both month 0 and 13 are not valid
263 hildon_date_editor_set_date (date_editor, year, MIN_MONTH - 1, day);
264 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
266 fail_if (ret_month != month,
267 "hildon-date-editor: The returned month is %u and should be %u",
270 hildon_date_editor_set_date (date_editor, year, MAX_MONTH + 1, day);
271 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
273 fail_if (ret_month != month,
274 "hildon-date-editor: The returned month is %u and should be %u",
277 /* Test 8: Test day invalid values */
278 hildon_date_editor_set_date (date_editor, year, month, MIN_DAY - 1);
279 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
281 fail_if (ret_day != day,
282 "hildon-date-editor: The returned day is %u and should be %u",
285 hildon_date_editor_set_date (date_editor, year, month, MAX_DAY + 1);
286 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
288 fail_if (ret_day != day,
289 "hildon-date-editor: The returned day is %u and should be %u",
294 /* ----- Test case for get_date -----*/
296 /* We do not include tests for limit values because we think they're
297 tested enought with the set_data tests */
300 * Purpose: test getting regular values for hildon_date_editor_get_date
302 * - Set and get date 30/03/1981
304 START_TEST (test_get_date_regular)
306 guint year, month, day;
307 guint ret_year, ret_month, ret_day;
308 GValue value = { 0, };
314 /* Test 1: Test regular values */
315 hildon_date_editor_set_date (NULL, year, month, day);
317 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
319 g_value_init (&value, G_TYPE_UINT);
320 g_object_get_property (G_OBJECT (date_editor), "year", &value);
321 fail_if (g_value_get_uint (&value) != ret_year,
322 "hildon-date-editor: get_date failed. The returned year is %u and should be %u",
323 g_value_get_uint (&value),
326 g_value_unset (&value);
327 g_value_init (&value, G_TYPE_UINT);
328 g_object_get_property (G_OBJECT (date_editor), "month", &value);
329 fail_if (g_value_get_uint (&value) != ret_month,
330 "hildon-date-editor: get_date failed. The returned month is %u and should be %u",
331 g_value_get_uint (&value),
334 g_value_unset (&value);
335 g_value_init (&value, G_TYPE_UINT);
336 g_object_get_property (G_OBJECT (date_editor), "day", &value);
337 fail_if (g_value_get_uint (&value) != ret_day,
338 "hildon-date-editor: get_date failed. The returned day is %u and should be %u",
339 g_value_get_uint (&value),
345 * Purpose: test getting regular values passing invalid arguments for
346 * hildon_date_editor_get_date
348 * - HildonDateEditor NULL
353 START_TEST (test_get_date_invalid)
355 guint year, month, day;
356 guint ret_year, ret_month, ret_day;
362 hildon_date_editor_set_date (date_editor, year, month, day);
364 /* Check that does not fail */
365 hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day);
367 /* Check NULL arguments */
368 hildon_date_editor_get_date (date_editor, NULL, &ret_month, &ret_day);
369 fail_if (hildon_date_editor_get_year (date_editor) != year,
370 "hildon-date-editor: get_date failed. The returned year is %u and should be %u",
373 hildon_date_editor_get_date (date_editor, &ret_year, NULL, &ret_day);
374 fail_if (hildon_date_editor_get_month (date_editor) != month,
375 "hildon-date-editor: get_date failed. The returned month is %u and should be %u",
378 hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, NULL);
379 fail_if (hildon_date_editor_get_day (date_editor) != day,
380 "hildon-date-editor: get_date failed. The returned day is %u and should be %u",
385 /* ----- Test case for get_year -----*/
388 * Purpose: test getting regular values of the year for hildon_date_editor_get_year
390 * - get a year set with set_date 30/03/1981
391 * - get a year set with set_year 1980
392 * - get a year set with set_property 2004
394 START_TEST (test_get_year_regular)
396 guint year, month, day;
397 GValue value = {0, };
403 /* Test 1: Set year with set_date */
404 hildon_date_editor_set_date (date_editor, year, month, day);
406 fail_if (hildon_date_editor_get_year (date_editor) != year,
407 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
408 hildon_date_editor_get_year (date_editor), year);
410 /* Test 2: set year with set_year */
412 hildon_date_editor_set_year (date_editor, year);
414 fail_if (hildon_date_editor_get_year (date_editor) != year,
415 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
416 hildon_date_editor_get_year (date_editor), year);
418 /* Test 3: set year with set_property */
420 g_value_init (&value, G_TYPE_UINT);
421 g_value_set_uint (&value, year);
422 g_object_set_property (G_OBJECT (date_editor), "year", &value);
424 fail_if (hildon_date_editor_get_year (date_editor) != year,
425 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
426 hildon_date_editor_get_year (date_editor), year);
431 * Purpose: test getting year when a value over the limits was set for
432 * hildon_date_editor_get_year
437 START_TEST (test_get_year_limits)
444 hildon_date_editor_set_year (date_editor, year);
446 /* Test 1: upper limit */
447 hildon_date_editor_set_year (date_editor, MAX_YEAR);
449 fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR,
450 "hildon-date-editor: The returned year is %u and should be %u",
451 hildon_date_editor_get_year (date_editor), MAX_YEAR);
453 /* Test 2: lower limit */
454 hildon_date_editor_set_year (date_editor, MIN_YEAR);
456 fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR,
457 "hildon-date-editor: The returned year is %u and should be %u",
458 hildon_date_editor_get_year (date_editor), MIN_YEAR);
463 * Purpose: test getting a year for invalid attributes for
464 * hildon_date_editor_get_year
466 * - HildonDateEditor is NULL
467 * - Pass a GtkHBox instead a HildonDateEditor
471 START_TEST (test_get_year_invalid)
474 GtkWidget *aux_object = NULL;
476 /* Test 1: Test NULL */
477 ret_year = hildon_date_editor_get_year (NULL);
478 fail_if (ret_year != 0,
479 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
482 /* Test 2: another object */
483 aux_object = gtk_hbox_new (TRUE, 0);
484 ret_year = hildon_date_editor_get_year ((HildonDateEditor *) (aux_object));
485 fail_if (ret_year != 0,
486 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
488 gtk_widget_destroy (GTK_WIDGET(aux_object));
490 /* Test 3: upper limit, the test is OK but it shouldn't. The reason
491 is that the value of the date is not validated by Hildon since it
492 was not set using the UI */
493 hildon_date_editor_set_year (date_editor, MAX_YEAR + 1);
495 fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR + 1,
496 "hildon-date-editor: The returned year is %u and should be %u",
497 hildon_date_editor_get_year (date_editor), MAX_YEAR + 1);
499 /* Test 4: lower limit, see the above comment */
500 hildon_date_editor_set_year (date_editor, MIN_YEAR - 1);
502 fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR - 1,
503 "hildon-date-editor: The returned year is %u and should be %u",
504 hildon_date_editor_get_year (date_editor), MIN_YEAR - 1);
508 /* ----- Test case for set_year -----*/
511 * Purpose: test setting a regular value for a year for
512 * hildon_date_editor_set_year
516 START_TEST (test_set_year_regular)
523 /* Test 1: Try year 1981 */
524 hildon_date_editor_set_year (date_editor, year);
525 ret_year = hildon_date_editor_get_year (date_editor);
527 fail_if (ret_year != year,
528 "hildon-date-editor: set_year failed. The returned year is %u and should be %u",
534 * Purpose: test setting values of the year over the limits for
535 * hildon_date_editor_set_year
540 START_TEST (test_set_year_limits)
543 GValue value = { 0, };
548 hildon_date_editor_set_year (date_editor, year);
550 /* Test 1: Test upper limit */
551 g_value_init (&value, G_TYPE_UINT);
552 hildon_date_editor_set_year (date_editor, MAX_YEAR);
553 g_object_get_property (G_OBJECT (date_editor), "year", &value);
554 fail_if (g_value_get_uint (&value) != MAX_YEAR,
555 "hildon-date-editor: The returned year is %u and should be %u",
556 g_value_get_uint (&value), year);
558 /* Test 2: Test lower limit */
559 g_value_unset (&value);
560 g_value_init (&value, G_TYPE_UINT);
561 hildon_date_editor_set_year (date_editor, MIN_YEAR);
562 g_object_get_property (G_OBJECT (date_editor), "year", &value);
563 fail_if (g_value_get_uint (&value) != MIN_YEAR,
564 "hildon-date-editor: The returned year is %u and should be %u",
565 g_value_get_uint (&value), MIN_YEAR);
569 /* ----- Test case for get_month -----*/
572 * Purpose: test getting a year for regular values for
573 * hildon_date_editor_get_month
575 * - set month with set_date 30/03/1981
576 * - set month with set_month 1
577 * - set month with set_property 7
579 START_TEST (test_get_month_regular)
581 guint year, month, day;
582 GValue value = {0, };
588 /* Test 1: Set year with set_date */
589 hildon_date_editor_set_date (date_editor, year, month, day);
591 fail_if (hildon_date_editor_get_month (date_editor) != month,
592 "hildon-date-editor: The returned month is %u and should be %u",
593 hildon_date_editor_get_month (date_editor), month);
595 /* Test 2: set month with set_month */
597 hildon_date_editor_set_month (date_editor, month);
599 fail_if (hildon_date_editor_get_month (date_editor) != month,
600 "hildon-date-editor: The returned month is %u and should be %u",
601 hildon_date_editor_get_month (date_editor), month);
603 /* Test 3: set month with set_property */
605 g_value_init (&value, G_TYPE_UINT);
606 g_value_set_uint (&value, month);
607 g_object_set_property (G_OBJECT (date_editor), "month", &value);
609 fail_if (hildon_date_editor_get_month (date_editor) != month,
610 "hildon-date-editor: The returned month is %u and should be %u",
611 hildon_date_editor_get_month (date_editor), month);
616 * Purpose: test getting values of the month over the limits for
617 * hildon_date_editor_get_month
622 START_TEST (test_get_month_limits)
625 /* Test 1: Upper limit */
626 hildon_date_editor_set_month (date_editor, MAX_MONTH);
628 fail_if (hildon_date_editor_get_month (date_editor) != MAX_MONTH,
629 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
630 hildon_date_editor_get_month (date_editor), MAX_MONTH);
632 /* Test 2: Lower limit */
633 hildon_date_editor_set_month (date_editor, MIN_MONTH);
635 fail_if (hildon_date_editor_get_month (date_editor) != MIN_MONTH,
636 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
637 hildon_date_editor_get_month (date_editor), MIN_MONTH);
642 * Purpose: test getting a month for invalid attributes for
643 * hildon_date_editor_get_month
645 * - HildonDateEditor is NULL
646 * - HildonDateEditor is really a GtkHBox
648 START_TEST (test_get_month_invalid)
651 GtkWidget *aux_object = NULL;
653 /* Test 1: Test NULL */
654 ret_month = hildon_date_editor_get_month (NULL);
655 fail_if (ret_month != 0,
656 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
659 /* Test 2: another object */
660 aux_object = gtk_hbox_new (TRUE, 0);
661 ret_month = hildon_date_editor_get_month ((HildonDateEditor *) (aux_object));
662 fail_if (ret_month != 0,
663 "hildon-date-editor: get_month failed. The returned month is %u and should be %u",
665 gtk_widget_destroy (GTK_WIDGET(aux_object));
669 /* ----- Test case for set_month -----*/
672 * Purpose: test setting regular values for month for
673 * hildon_date_editor_set_month
677 START_TEST (test_set_month_regular)
684 /* Test 1: Try month March (3) */
685 hildon_date_editor_set_month (date_editor, month);
686 ret_month = hildon_date_editor_get_month (date_editor);
688 fail_if (ret_month != month,
689 "hildon-date-editor: set_month failed. The returned month is %u and should be %u",
695 * Purpose: test setting values for month over the limits for
696 * hildon_date_editor_get_month
701 START_TEST (test_set_month_limits)
703 GValue value = { 0, };
705 /* Test 1: Test upper limit */
706 g_value_init (&value, G_TYPE_UINT);
707 hildon_date_editor_set_month (date_editor, MAX_MONTH);
708 g_object_get_property (G_OBJECT (date_editor), "month", &value);
709 fail_if (g_value_get_uint (&value) != MAX_MONTH,
710 "hildon-date-editor: The returned month is %u and should be %u",
711 g_value_get_uint (&value), MAX_MONTH);
713 /* Test 2: Test lower limit */
714 g_value_unset (&value);
715 g_value_init (&value, G_TYPE_UINT);
716 hildon_date_editor_set_month (date_editor, MIN_MONTH);
717 g_object_get_property (G_OBJECT (date_editor), "month", &value);
718 fail_if (g_value_get_uint (&value) != MIN_MONTH,
719 "hildon-date-editor: The returned month is %u and should be %u",
720 g_value_get_uint (&value), MIN_MONTH);
724 /* ----- Test case for get_day -----*/
727 * Purpose: test getting regular values for day for
728 * hildon_date_editor_get_day
730 * - Get a day set with set_date 30/03/1981
731 * - Get a day set with set_day 6
732 * - Get a day set with set_property 10
734 START_TEST (test_get_day_regular)
736 guint year, month, day;
737 GValue value = {0, };
743 /* Test 1: Set day with set_date */
744 hildon_date_editor_set_date (date_editor, year, month, day);
746 fail_if (hildon_date_editor_get_day (date_editor) != day,
747 "hildon-date-editor: The returned day is %u and should be %u",
748 hildon_date_editor_get_day (date_editor), day);
750 /* Test 2: set day with set_day */
752 hildon_date_editor_set_day (date_editor, day);
754 fail_if (hildon_date_editor_get_day (date_editor) != day,
755 "hildon-date-editor: The returned day is %u and should be %u",
756 hildon_date_editor_get_day (date_editor), day);
759 /* Test 3: set day with set_property */
761 g_value_init (&value, G_TYPE_UINT);
762 g_value_set_uint (&value, day);
763 g_object_set_property (G_OBJECT (date_editor), "day", &value);
765 fail_if (hildon_date_editor_get_day (date_editor) != day,
766 "hildon-date-editor: The returned day is %u and should be %u",
767 hildon_date_editor_get_day (date_editor), day);
773 * Purpose: test getting a day set over the limits for
774 * hildon_date_editor_get_day
776 * - Get day 31 for March
777 * - Get day 30 for June
778 * - Get day 29 for February for a leap year
779 * - Get day 28 for February for a common year
782 START_TEST (test_get_day_limits)
784 guint day, month, year;
790 /* Test 1: 31 of February */
791 hildon_date_editor_set_date (date_editor, year, month, day);
792 fail_if (hildon_date_editor_get_day (date_editor) != day,
793 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
794 hildon_date_editor_get_day (date_editor), day);
796 /* Test 2: 30 of February */
799 hildon_date_editor_set_date (date_editor, year, month, day);
800 fail_if (hildon_date_editor_get_day (date_editor) != day,
801 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
802 hildon_date_editor_get_day (date_editor), day);
804 /* Test 3: 29 of February */
808 hildon_date_editor_set_date (date_editor, year, month, day);
809 fail_if (hildon_date_editor_get_day (date_editor) != day,
810 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
811 hildon_date_editor_get_day (date_editor), day);
813 /* Test 3: 28 of February */
817 hildon_date_editor_set_date (date_editor, year, month, day);
818 fail_if (hildon_date_editor_get_day (date_editor) != day,
819 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
820 hildon_date_editor_get_day (date_editor), day);
823 hildon_date_editor_set_day (date_editor, 1);
825 fail_if (hildon_date_editor_get_day (date_editor) != 1,
826 "hildon-date-editor: get_day failed. The returned day is %u and should be %u",
827 hildon_date_editor_get_day (date_editor), 1);
832 * Purpose: test getting a day with invalid attributes for
833 * hildon_date_editor_get_day
835 * - HildonDateEditor is NULL
836 * - HildonDateEditor is really a GtkHBox
838 START_TEST (test_get_day_invalid)
841 GtkWidget *aux_object = NULL;
843 /* Test 1: Test NULL */
844 ret_year = hildon_date_editor_get_year (NULL);
845 fail_if (ret_year != 0,
846 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
849 /* Test 2: another object */
850 aux_object = gtk_hbox_new (TRUE, 0);
851 ret_year = hildon_date_editor_get_year ((HildonDateEditor *) aux_object);
852 fail_if (ret_year != 0,
853 "hildon-date-editor: get_year failed. The returned year is %u and should be %u",
855 gtk_widget_destroy (GTK_WIDGET(aux_object));
859 /* ----- Test case for set_day -----*/
862 * Purpose: test setting a regular value for day for
863 * hildon_date_editor_get_day
867 START_TEST (test_set_day_regular)
874 /* Test 1: Try day 30 */
875 hildon_date_editor_set_day (date_editor, day);
876 ret_day = hildon_date_editor_get_day (date_editor);
878 fail_if (ret_day != day,
879 "hildon-date-editor: set_day failed. The returned day is %u and should be %u",
885 * Purpose: test seeting a day over the limits for
886 * hildon_date_editor_get_day
894 START_TEST (test_set_day_limits)
896 guint day, year, month;
897 GValue value = { 0, };
904 hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);
906 /* Test 1: Test 31/03 */
907 g_value_init (&value, G_TYPE_UINT);
908 hildon_date_editor_set_day (date_editor, day);
909 g_object_get_property (G_OBJECT (date_editor), "day", &value);
910 fail_if (g_value_get_uint (&value) != day,
911 "hildon-date-editor: The returned day is %u and should be %u",
912 g_value_get_uint (&value), day);
914 /* Test 2: Test 30/06 */
917 hildon_date_editor_set_date (date_editor, year, month, 1);
918 g_value_unset (&value);
919 g_value_init (&value, G_TYPE_UINT);
920 hildon_date_editor_set_day (date_editor, day);
921 g_object_get_property (G_OBJECT (date_editor), "day", &value);
922 fail_if (g_value_get_uint (&value) != day,
923 "hildon-date-editor: The returned day is %u and should be %u",
924 g_value_get_uint (&value), day);
926 /* Test 3: Test 29/02/1980 */
930 hildon_date_editor_set_date (date_editor, year, month, 1);
931 g_value_unset (&value);
932 g_value_init (&value, G_TYPE_UINT);
933 hildon_date_editor_set_day (date_editor, day);
934 g_object_get_property (G_OBJECT (date_editor), "day", &value);
935 fail_if (g_value_get_uint (&value) != day,
936 "hildon-date-editor: The returned day is %u and should be %u",
937 g_value_get_uint (&value), day);
939 /* Test 4: Test 28/02/1981 */
943 hildon_date_editor_set_date (date_editor, year, month, 1);
944 g_value_unset (&value);
945 g_value_init (&value, G_TYPE_UINT);
946 hildon_date_editor_set_day (date_editor, day);
947 g_object_get_property (G_OBJECT (date_editor), "day", &value);
948 fail_if (g_value_get_uint (&value) != day,
949 "hildon-date-editor: The returned day is %u and should be %u",
950 g_value_get_uint (&value), day);
952 /* Test 5: Test 1/02/1980 */
956 hildon_date_editor_set_date (date_editor, year, month, 10);
957 g_value_unset (&value);
958 g_value_init (&value, G_TYPE_UINT);
959 hildon_date_editor_set_day (date_editor, day);
960 g_object_get_property (G_OBJECT (date_editor), "day", &value);
961 fail_if (g_value_get_uint (&value) != day,
962 "hildon-date-editor: The returned day is %u and should be %u",
963 g_value_get_uint (&value), day);
967 /* ---------- Suite creation ---------- */
969 Suite *create_hildon_date_editor_suite(void)
971 /* Create the suite */
972 Suite *s = suite_create("HildonDateEditor");
974 /* Create test cases */
975 TCase *tc1 = tcase_create("set_date");
976 TCase *tc2 = tcase_create("get_date");
977 TCase *tc3 = tcase_create("get_year");
978 TCase *tc4 = tcase_create("set_year");
979 TCase *tc5 = tcase_create("get_month");
980 TCase *tc6 = tcase_create("set_month");
981 TCase *tc7 = tcase_create("get_day");
982 TCase *tc8 = tcase_create("set_day");
984 /* Create test case for set_date and add it to the suite */
985 tcase_add_checked_fixture(tc1, fx_setup_default_date_editor, fx_teardown_default_date_editor);
986 tcase_add_test(tc1, test_set_date_regular);
987 tcase_add_test(tc1, test_set_date_limits);
988 tcase_add_test(tc1, test_set_date_invalid);
989 suite_add_tcase (s, tc1);
991 /* Create test case for get_date and add it to the suite */
992 tcase_add_checked_fixture(tc2, fx_setup_default_date_editor, fx_teardown_default_date_editor);
993 tcase_add_test(tc2, test_get_date_regular);
994 tcase_add_test(tc2, test_get_date_invalid);
995 suite_add_tcase (s, tc2);
997 /* Create test case for get_year and add it to the suite */
998 tcase_add_checked_fixture(tc3, fx_setup_default_date_editor, fx_teardown_default_date_editor);
999 tcase_add_test(tc3, test_get_year_regular);
1000 tcase_add_test(tc3, test_get_year_limits);
1001 tcase_add_test(tc3, test_get_year_invalid);
1002 suite_add_tcase (s, tc3);
1004 /* Create test case for set_year and add it to the suite */
1005 tcase_add_checked_fixture(tc4, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1006 tcase_add_test(tc4, test_set_year_regular);
1007 tcase_add_test(tc4, test_set_year_limits);
1008 suite_add_tcase (s, tc4);
1010 /* Create test case for get_month and add it to the suite */
1011 tcase_add_checked_fixture(tc5, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1012 tcase_add_test(tc5, test_get_month_regular);
1013 tcase_add_test(tc5, test_get_month_limits);
1014 tcase_add_test(tc5, test_get_month_invalid);
1015 suite_add_tcase (s, tc5);
1017 /* Create test case for set_month and add it to the suite */
1018 tcase_add_checked_fixture(tc6, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1019 tcase_add_test(tc6, test_set_month_regular);
1020 tcase_add_test(tc6, test_set_month_limits);
1021 suite_add_tcase (s, tc6);
1023 /* Create test case for get_day and add it to the suite */
1024 tcase_add_checked_fixture(tc7, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1025 tcase_add_test(tc7, test_get_day_regular);
1026 tcase_add_test(tc7, test_get_day_limits);
1027 tcase_add_test(tc7, test_get_day_invalid);
1028 suite_add_tcase (s, tc7);
1030 /* Create test case for set_day and add it to the suite */
1031 tcase_add_checked_fixture(tc8, fx_setup_default_date_editor, fx_teardown_default_date_editor);
1032 tcase_add_test(tc8, test_set_day_regular);
1033 tcase_add_test(tc8, test_set_day_limits);
1034 suite_add_tcase (s, tc8);
1036 /* Return created suite */