Adding the test suite.
[hildon] / tests / check-hildon-date-editor.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
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.
10  *
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.
15  *
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
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdlib.h>
24 #include <check.h>
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkhbox.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
29
30 #include "hildon-date-editor.h"
31
32 /* Taken from the values of the properties of HildonDateEditor */
33 #define MAX_YEAR 2037
34 #define MAX_MONTH 12
35 #define MAX_DAY 31
36 #define MIN_YEAR 1970
37 #define MIN_MONTH 1
38 #define MIN_DAY 1
39
40 /* -------------------- Fixtures -------------------- */
41
42 static HildonDateEditor *date_editor = NULL;
43 static GtkWidget *showed_window = NULL;
44
45 static void 
46 fx_setup_default_date_editor ()
47 {
48   int argc = 0;
49
50   gtk_init(&argc, NULL);
51   
52   showed_window =  create_test_window ();
53
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.");
58   
59   /* This packs the widget into the window (a gtk container). */
60   gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor));
61   
62   /* Displays the widget and the window */
63   show_all_test_window (showed_window);
64 }
65
66 static void 
67 fx_teardown_default_date_editor ()
68 {
69
70   /* Destroy the widget and the window */
71   gtk_widget_destroy (GTK_WIDGET (showed_window));
72
73 }
74
75 /* -------------------- Test cases -------------------- */
76
77 /* ----- Test case for set_date -----*/
78
79 /**
80  * Purpose: test setting regular values for hildon_date_editor_set_date
81  * Cases considered:
82  *    - Set and get the date 30/03/1981
83  */
84 START_TEST (test_set_date_regular)
85 {
86   guint year, month, day;
87   guint ret_year, ret_month, ret_day;
88
89   year = 1981;
90   month = 3;
91   day = 30;
92
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);
96
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);
100 }
101 END_TEST
102
103 static void
104 test_set_date_limits_check (guint year, guint month, guint day)
105 {
106   guint ret_year, ret_month, ret_day;
107
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);
110
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);
114 }
115
116 /**
117  * Purpose: test limit date values for hildon_date_editor_set_date
118  * Cases considered:
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)
125  */
126 START_TEST (test_set_date_limits)
127 {
128   guint year, month, day;
129
130   year = MIN_YEAR;
131   month = 3;
132   day = 30;
133
134   /* Test 1: Test year limits */
135   test_set_date_limits_check (year, month, day);
136
137   year = MAX_YEAR;
138   test_set_date_limits_check (year, month, day);
139
140   /* Test 2: Test month limits */
141   year = 1981;
142   month = MIN_MONTH;
143   day = 30;
144   test_set_date_limits_check (year, month, day);
145
146   month = MAX_MONTH;
147   test_set_date_limits_check (year, month, day);
148
149   /* Test 3: Test day limits */
150   year = 1981;
151   month = 3;
152   day = 31;
153   test_set_date_limits_check (year, month, day);
154
155   /* Test 4: Test day limits */
156   year = 1981;
157   month = 6;
158   day = 30;
159   test_set_date_limits_check (year, month, day);
160
161   /* Test 5: Test february limits */
162   year = 1981;
163   month = 2;
164   day = 28;
165   test_set_date_limits_check (year, month, day);
166
167   /* Test 6: Test february limits for a leap year */
168   year = 1980;
169   month = 2;
170   day = 29;
171   test_set_date_limits_check (year, month, day);
172 }
173 END_TEST
174
175 /**
176  * Purpose: test invalid parameter values for hildon_date_editor_set_date
177  * Cases considered:
178  *    - test NULL widget
179  *    - test passing GtkHBox instead a HildonDateEditor
180  *    - test leap year
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)
186  */
187 START_TEST (test_set_date_invalid)
188 {
189   guint year, month, day;
190   guint ret_year, ret_month, ret_day;
191   GtkWidget *aux_object = NULL;
192
193   year = 1981;
194   month = 3;
195   day = 30;
196
197   /* Set init date */
198   hildon_date_editor_set_date (date_editor, year, month, day);
199
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);
203
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);
207
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);
212
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));
217
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);
221
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);
225
226   /* Restore the original value */
227   hildon_date_editor_set_date (date_editor, year, month, day);
228
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);
235
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);
242
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);
248
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);
252
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);
255
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);
259
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
262      for g_date */
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);
265
266   fail_if (ret_month != month,
267            "hildon-date-editor: The returned month is %u and should be %u",
268            ret_month, month);
269
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);
272
273   fail_if (ret_month != month,
274            "hildon-date-editor: The returned month is %u and should be %u",
275            ret_month, month);
276
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);
280
281   fail_if (ret_day != day,
282            "hildon-date-editor: The returned day is %u and should be %u",
283            ret_day, day);
284
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);
287
288   fail_if (ret_day != day,
289            "hildon-date-editor: The returned day is %u and should be %u",
290            ret_day, day);
291 }
292 END_TEST
293
294 /* ----- Test case for get_date -----*/
295
296 /* We do not include tests for limit values because we think they're
297    tested enought with the set_data tests */
298
299 /**
300  * Purpose: test getting regular values for hildon_date_editor_get_date
301  * Cases considered:
302  *    - Set and get date 30/03/1981
303  */
304 START_TEST (test_get_date_regular)
305 {
306   guint year, month, day;
307   guint ret_year, ret_month, ret_day;
308   GValue value = { 0, };
309
310   year = 1981;
311   month = 3;
312   day = 30;
313
314   /* Test 1: Test regular values */
315   hildon_date_editor_set_date (NULL, year, month, day);
316
317   hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
318
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),
324            ret_year);
325
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),
332            ret_month);
333
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),
340            ret_day);
341 }
342 END_TEST
343
344 /**
345  * Purpose: test getting regular values passing invalid arguments for
346  * hildon_date_editor_get_date 
347  * Cases considered: 
348  *    - HildonDateEditor NULL
349  *    - year is NULL
350  *    - month is NULL
351  *    - day is NULL
352  */
353 START_TEST (test_get_date_invalid)
354 {
355   guint year, month, day;
356   guint ret_year, ret_month, ret_day;
357
358   year = 1981;
359   month = 3;
360   day = 30;
361
362   hildon_date_editor_set_date (date_editor, year, month, day);
363
364   /* Check that does not fail */
365   hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day);
366
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", 
371            ret_year, year);
372
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", 
376            ret_month, month);
377
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", 
381            ret_day, day);
382 }
383 END_TEST
384
385 /* ----- Test case for get_year -----*/
386
387 /**
388  * Purpose: test getting regular values of the year for hildon_date_editor_get_year
389  * Cases considered:
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
393  */
394 START_TEST (test_get_year_regular)
395 {
396   guint year, month, day;
397   GValue value = {0, };
398
399   year = 1981;
400   month = 3;
401   day = 30;
402
403   /* Test 1: Set year with set_date */
404   hildon_date_editor_set_date (date_editor, year, month, day);
405
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);
409
410   /* Test 2: set year with set_year */
411   year = 1980;
412   hildon_date_editor_set_year (date_editor, year);
413
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);
417
418   /* Test 3: set year with set_property */
419   year = 2004;
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);
423
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);
427 }
428 END_TEST
429
430 /**
431  * Purpose: test getting year when a value over the limits was set for
432  * hildon_date_editor_get_year
433  * Cases considered:
434  *    - test year 2037
435  *    - test year 1970
436  */
437 START_TEST (test_get_year_limits)
438 {
439   guint year;
440
441   year = 1981;
442
443   /* Set init year */
444   hildon_date_editor_set_year (date_editor, year);
445
446   /* Test 1: upper limit */
447   hildon_date_editor_set_year (date_editor, MAX_YEAR);
448
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);
452
453   /* Test 2: lower limit */
454   hildon_date_editor_set_year (date_editor, MIN_YEAR);
455
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);
459 }
460 END_TEST
461
462 /**
463  * Purpose: test getting a year for invalid attributes for
464  * hildon_date_editor_get_year
465  * Cases considered: 
466  *    - HildonDateEditor is NULL
467  *    - Pass a GtkHBox instead a HildonDateEditor
468  *    - test year 2038
469  *    - test year 1969
470  */
471 START_TEST (test_get_year_invalid)
472 {
473   guint ret_year;
474   GtkWidget *aux_object = NULL;
475
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", 
480            ret_year, 0);
481
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", 
487            ret_year, 0);
488   gtk_widget_destroy (GTK_WIDGET(aux_object));
489
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);
494
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);
498
499   /* Test 4: lower limit, see the above comment */
500   hildon_date_editor_set_year (date_editor, MIN_YEAR - 1);
501
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);
505 }
506 END_TEST
507
508 /* ----- Test case for set_year -----*/
509
510 /**
511  * Purpose: test setting a regular value for a year for
512  * hildon_date_editor_set_year
513  * Cases considered:
514  *    - Set year 1981
515  */
516 START_TEST (test_set_year_regular)
517 {
518   guint year;
519   guint ret_year;
520
521   year = 1981;
522
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);
526
527   fail_if (ret_year != year,
528            "hildon-date-editor: set_year failed. The returned year is %u and should be %u", 
529            ret_year, year);
530 }
531 END_TEST
532
533 /**
534  * Purpose: test setting values of the year over the limits for
535  * hildon_date_editor_set_year
536  * Cases considered:
537  *    - Set year 2037
538  *    - Set year 1970
539  */
540 START_TEST (test_set_year_limits)
541 {
542   guint year;
543   GValue value = { 0, };
544
545   year = 1981;
546
547   /* Set init date */
548   hildon_date_editor_set_year (date_editor, year);
549
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);
557
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);
566 }
567 END_TEST
568
569 /* ----- Test case for get_month -----*/
570
571 /**
572  * Purpose: test getting a year for regular values for
573  * hildon_date_editor_get_month
574  * Cases considered:
575  *    - set month with set_date 30/03/1981
576  *    - set month with set_month 1
577  *    - set month with set_property 7
578  */
579 START_TEST (test_get_month_regular)
580 {
581   guint year, month, day;
582   GValue value = {0, };
583
584   year = 1981;
585   month = 3;
586   day = 30;
587
588   /* Test 1: Set year with set_date */
589   hildon_date_editor_set_date (date_editor, year, month, day);
590
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);
594
595   /* Test 2: set month with set_month */
596   month = 1;
597   hildon_date_editor_set_month (date_editor, month);
598
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);
602
603   /* Test 3: set month with set_property */
604   month = 7;
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);
608
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);
612 }
613 END_TEST
614
615 /**
616  * Purpose: test getting values of the month over the limits for
617  * hildon_date_editor_get_month
618  * Cases considered:
619  *    - Get month 12
620  *    - Get month 1
621  */
622 START_TEST (test_get_month_limits)
623 {
624
625   /* Test 1: Upper limit */
626   hildon_date_editor_set_month (date_editor, MAX_MONTH);
627
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);
631
632   /* Test 2: Lower limit */
633   hildon_date_editor_set_month (date_editor, MIN_MONTH);
634
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);
638 }
639 END_TEST
640
641 /**
642  * Purpose:  test getting a month for invalid attributes for
643  * hildon_date_editor_get_month
644  * Cases considered:
645  *    - HildonDateEditor is NULL
646  *    - HildonDateEditor is really a GtkHBox
647  */
648 START_TEST (test_get_month_invalid)
649 {
650   guint ret_month;
651   GtkWidget *aux_object = NULL;
652
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", 
657            ret_month, 0);
658
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", 
664            ret_month, 0);
665   gtk_widget_destroy (GTK_WIDGET(aux_object));
666 }
667 END_TEST
668
669 /* ----- Test case for set_month -----*/
670
671 /**
672  * Purpose: test setting regular values for month for
673  * hildon_date_editor_set_month
674  * Cases considered:
675  *    - Set month 3
676  */
677 START_TEST (test_set_month_regular)
678 {
679   guint month;
680   guint ret_month;
681
682   month = 3;
683
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);
687
688   fail_if (ret_month != month,
689            "hildon-date-editor: set_month failed. The returned month is %u and should be %u", 
690            ret_month, month);
691 }
692 END_TEST
693
694 /**
695  * Purpose: test setting values for month over the limits for
696  * hildon_date_editor_get_month
697  * Cases considered:
698  *    - Set month 12
699  *    - Set month 1
700  */
701 START_TEST (test_set_month_limits)
702 {
703   GValue value = { 0, };
704
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);
712
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);
721 }
722 END_TEST
723
724 /* ----- Test case for get_day -----*/
725
726 /**
727  * Purpose: test getting regular values for day for
728  * hildon_date_editor_get_day
729  * Cases considered:
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
733  */
734 START_TEST (test_get_day_regular)
735 {
736   guint year, month, day;
737   GValue value = {0, };
738
739   year = 1981;
740   month = 3;
741   day = 30;
742
743   /* Test 1: Set day with set_date */
744   hildon_date_editor_set_date (date_editor, year, month, day);
745
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);
749
750   /* Test 2: set day with set_day */
751   day = 6;
752   hildon_date_editor_set_day (date_editor, day);
753
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);
757
758
759   /* Test 3: set day with set_property */
760   day = 10;
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);
764
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);
768
769 }
770 END_TEST
771
772 /**
773  * Purpose: test getting a day set over the limits for
774  * hildon_date_editor_get_day
775  * Cases considered:
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
780  *    - Get day 1
781  */
782 START_TEST (test_get_day_limits)
783 {
784   guint day, month, year;
785
786   year = 1981;
787   month = 3;
788   day = 31;
789
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);
795
796   /* Test 2: 30 of February */
797   month = 6;
798   day = 30;
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);
803
804   /* Test 3: 29 of February */
805   year = 1980;
806   month = 2;
807   day = 29;
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);
812
813   /* Test 3: 28 of February */
814   year = 1981;
815   month = 2;
816   day = 28;
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);
821
822   /* Test 5: day 1 */
823   hildon_date_editor_set_day (date_editor, 1);
824
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);
828 }
829 END_TEST
830
831 /**
832  * Purpose: test getting a day with invalid attributes for
833  * hildon_date_editor_get_day
834  * Cases considered:
835  *    - HildonDateEditor is NULL
836  *    - HildonDateEditor is really a GtkHBox
837  */
838 START_TEST (test_get_day_invalid)
839 {
840   guint ret_year;
841   GtkWidget *aux_object = NULL;
842
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", 
847            ret_year, 0);
848
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", 
854            ret_year, 0);
855   gtk_widget_destroy (GTK_WIDGET(aux_object));
856 }
857 END_TEST
858
859 /* ----- Test case for set_day -----*/
860
861 /**
862  * Purpose: test setting a regular value for day for
863  * hildon_date_editor_get_day
864  * Cases considered:
865  *    - Set day 30
866  */
867 START_TEST (test_set_day_regular)
868 {
869   guint day;
870   guint ret_day;
871
872   day = 30;
873
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);
877
878   fail_if (ret_day != day,
879            "hildon-date-editor: set_day failed. The returned day is %u and should be %u", 
880            ret_day, day);
881 }
882 END_TEST
883
884 /**
885  * Purpose: test seeting a day over the limits for
886  * hildon_date_editor_get_day
887  * Cases considered:
888  *    - Set day 31
889  *    - Set day 30
890  *    - Set day 29
891  *    - Set day 28
892  *    - Set day 1
893  */
894 START_TEST (test_set_day_limits)
895 {
896   guint day, year, month;
897   GValue value = { 0, };
898
899   year = 1981;
900   month = 3;
901   day = 31;
902
903   /* Set init date */
904   hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);
905
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);
913
914   /* Test 2: Test 30/06 */
915   month = 6;
916   day = 30;
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);
925
926   /* Test 3: Test 29/02/1980 */
927   year = 1980;
928   month = 2;
929   day = 29;
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);
938
939   /* Test 4: Test 28/02/1981 */
940   year = 1981;
941   month = 2;
942   day = 28;
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);
951
952   /* Test 5: Test 1/02/1980 */
953   year = 1980;
954   month = 2;
955   day = 1;
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);
964 }
965 END_TEST
966
967 /* ---------- Suite creation ---------- */
968
969 Suite *create_hildon_date_editor_suite(void)
970 {
971   /* Create the suite */
972   Suite *s = suite_create("HildonDateEditor");
973
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");
983
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);
990
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);
996
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);
1003
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);
1009
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);
1016
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);
1022
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);
1029
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);
1035
1036   /* Return created suite */
1037   return s;
1038 }