Fix a typo in the signal declaration
[hildon] / tests / check-hildon-date-editor.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include <stdlib.h>
26 #include <check.h>
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkhbox.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
31
32 #include <hildon/hildon-date-editor.h>
33
34 /* Taken from the values of the properties of HildonDateEditor */
35 #define MAX_YEAR 2037
36 #define MAX_MONTH 12
37 #define MAX_DAY 31
38 #define MIN_YEAR 1970
39 #define MIN_MONTH 1
40 #define MIN_DAY 1
41
42 /* -------------------- Fixtures -------------------- */
43
44 static HildonDateEditor *date_editor = NULL;
45 static GtkWidget *showed_window = NULL;
46
47 static void 
48 fx_setup_default_date_editor ()
49 {
50   int argc = 0;
51
52   gtk_init(&argc, NULL);
53   
54   showed_window =  create_test_window ();
55
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.");
60   
61   /* This packs the widget into the window (a gtk container). */
62   gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor));
63   
64   /* Displays the widget and the window */
65   show_all_test_window (showed_window);
66 }
67
68 static void 
69 fx_teardown_default_date_editor ()
70 {
71
72   /* Destroy the widget and the window */
73   gtk_widget_destroy (GTK_WIDGET (showed_window));
74
75 }
76
77 /* -------------------- Test cases -------------------- */
78
79 /* ----- Test case for set_date -----*/
80
81 /**
82  * Purpose: test setting regular values for hildon_date_editor_set_date
83  * Cases considered:
84  *    - Set and get the date 30/03/1981
85  */
86 START_TEST (test_set_date_regular)
87 {
88   guint year, month, day;
89   guint ret_year, ret_month, ret_day;
90
91   year = 1981;
92   month = 3;
93   day = 30;
94
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);
98
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);
102 }
103 END_TEST
104
105 static void
106 test_set_date_limits_check (guint year, guint month, guint day)
107 {
108   guint ret_year, ret_month, ret_day;
109
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);
112
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);
116 }
117
118 /**
119  * Purpose: test limit date values for hildon_date_editor_set_date
120  * Cases considered:
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)
127  */
128 START_TEST (test_set_date_limits)
129 {
130   guint year, month, day;
131
132   year = MIN_YEAR;
133   month = 3;
134   day = 30;
135
136   /* Test 1: Test year limits */
137   test_set_date_limits_check (year, month, day);
138
139   year = MAX_YEAR;
140   test_set_date_limits_check (year, month, day);
141
142   /* Test 2: Test month limits */
143   year = 1981;
144   month = MIN_MONTH;
145   day = 30;
146   test_set_date_limits_check (year, month, day);
147
148   month = MAX_MONTH;
149   test_set_date_limits_check (year, month, day);
150
151   /* Test 3: Test day limits */
152   year = 1981;
153   month = 3;
154   day = 31;
155   test_set_date_limits_check (year, month, day);
156
157   /* Test 4: Test day limits */
158   year = 1981;
159   month = 6;
160   day = 30;
161   test_set_date_limits_check (year, month, day);
162
163   /* Test 5: Test february limits */
164   year = 1981;
165   month = 2;
166   day = 28;
167   test_set_date_limits_check (year, month, day);
168
169   /* Test 6: Test february limits for a leap year */
170   year = 1980;
171   month = 2;
172   day = 29;
173   test_set_date_limits_check (year, month, day);
174 }
175 END_TEST
176
177 /**
178  * Purpose: test invalid parameter values for hildon_date_editor_set_date
179  * Cases considered:
180  *    - test NULL widget
181  *    - test passing GtkHBox instead a HildonDateEditor
182  *    - test leap year
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)
188  */
189 START_TEST (test_set_date_invalid)
190 {
191   guint year, month, day;
192   guint ret_year, ret_month, ret_day;
193   GtkWidget *aux_object = NULL;
194
195   year = 1981;
196   month = 3;
197   day = 30;
198
199   /* Set init date */
200   hildon_date_editor_set_date (date_editor, year, month, day);
201
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);
205
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);
209
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);
214
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));
219
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);
223
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);
227
228   /* Restore the original value */
229   hildon_date_editor_set_date (date_editor, year, month, day);
230
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);
237
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);
244
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);
250
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);
254
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);
257
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);
261
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
264      for g_date */
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);
267
268   fail_if (ret_month != month,
269            "hildon-date-editor: The returned month is %u and should be %u",
270            ret_month, month);
271
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);
274
275   fail_if (ret_month != month,
276            "hildon-date-editor: The returned month is %u and should be %u",
277            ret_month, month);
278
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);
282
283   fail_if (ret_day != day,
284            "hildon-date-editor: The returned day is %u and should be %u",
285            ret_day, day);
286
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);
289
290   fail_if (ret_day != day,
291            "hildon-date-editor: The returned day is %u and should be %u",
292            ret_day, day);
293 }
294 END_TEST
295
296 /* ----- Test case for get_date -----*/
297
298 /* We do not include tests for limit values because we think they're
299    tested enought with the set_data tests */
300
301 /**
302  * Purpose: test getting regular values for hildon_date_editor_get_date
303  * Cases considered:
304  *    - Set and get date 30/03/1981
305  */
306 START_TEST (test_get_date_regular)
307 {
308   guint year, month, day;
309   guint ret_year, ret_month, ret_day;
310   GValue value = { 0, };
311
312   year = 1981;
313   month = 3;
314   day = 30;
315
316   /* Test 1: Test regular values */
317   hildon_date_editor_set_date (NULL, year, month, day);
318
319   hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
320
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),
326            ret_year);
327
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),
334            ret_month);
335
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),
342            ret_day);
343 }
344 END_TEST
345
346 /**
347  * Purpose: test getting regular values passing invalid arguments for
348  * hildon_date_editor_get_date 
349  * Cases considered: 
350  *    - HildonDateEditor NULL
351  *    - year is NULL
352  *    - month is NULL
353  *    - day is NULL
354  */
355 START_TEST (test_get_date_invalid)
356 {
357   guint year, month, day;
358   guint ret_year, ret_month, ret_day;
359
360   year = 1981;
361   month = 3;
362   day = 30;
363
364   hildon_date_editor_set_date (date_editor, year, month, day);
365
366   /* Check that does not fail */
367   hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day);
368
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", 
373            ret_year, year);
374
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", 
378            ret_month, month);
379
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", 
383            ret_day, day);
384 }
385 END_TEST
386
387 /* ----- Test case for get_year -----*/
388
389 /**
390  * Purpose: test getting regular values of the year for hildon_date_editor_get_year
391  * Cases considered:
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
395  */
396 START_TEST (test_get_year_regular)
397 {
398   guint year, month, day;
399   GValue value = {0, };
400
401   year = 1981;
402   month = 3;
403   day = 30;
404
405   /* Test 1: Set year with set_date */
406   hildon_date_editor_set_date (date_editor, year, month, day);
407
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);
411
412   /* Test 2: set year with set_year */
413   year = 1980;
414   hildon_date_editor_set_year (date_editor, year);
415
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);
419
420   /* Test 3: set year with set_property */
421   year = 2004;
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);
425
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);
429 }
430 END_TEST
431
432 /**
433  * Purpose: test getting year when a value over the limits was set for
434  * hildon_date_editor_get_year
435  * Cases considered:
436  *    - test year 2037
437  *    - test year 1970
438  */
439 START_TEST (test_get_year_limits)
440 {
441   guint year;
442
443   year = 1981;
444
445   /* Set init year */
446   hildon_date_editor_set_year (date_editor, year);
447
448   /* Test 1: upper limit */
449   hildon_date_editor_set_year (date_editor, MAX_YEAR);
450
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);
454
455   /* Test 2: lower limit */
456   hildon_date_editor_set_year (date_editor, MIN_YEAR);
457
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);
461 }
462 END_TEST
463
464 /**
465  * Purpose: test getting a year for invalid attributes for
466  * hildon_date_editor_get_year
467  * Cases considered: 
468  *    - HildonDateEditor is NULL
469  *    - Pass a GtkHBox instead a HildonDateEditor
470  *    - test year 2038
471  *    - test year 1969
472  */
473 START_TEST (test_get_year_invalid)
474 {
475   guint ret_year;
476   GtkWidget *aux_object = NULL;
477
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", 
482            ret_year, 0);
483
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", 
489            ret_year, 0);
490   gtk_widget_destroy (GTK_WIDGET(aux_object));
491
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);
496
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);
500
501   /* Test 4: lower limit, see the above comment */
502   hildon_date_editor_set_year (date_editor, MIN_YEAR - 1);
503
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);
507 }
508 END_TEST
509
510 /* ----- Test case for set_year -----*/
511
512 /**
513  * Purpose: test setting a regular value for a year for
514  * hildon_date_editor_set_year
515  * Cases considered:
516  *    - Set year 1981
517  */
518 START_TEST (test_set_year_regular)
519 {
520   guint year;
521   guint ret_year;
522
523   year = 1981;
524
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);
528
529   fail_if (ret_year != year,
530            "hildon-date-editor: set_year failed. The returned year is %u and should be %u", 
531            ret_year, year);
532 }
533 END_TEST
534
535 /**
536  * Purpose: test setting values of the year over the limits for
537  * hildon_date_editor_set_year
538  * Cases considered:
539  *    - Set year 2037
540  *    - Set year 1970
541  */
542 START_TEST (test_set_year_limits)
543 {
544   guint year;
545   GValue value = { 0, };
546
547   year = 1981;
548
549   /* Set init date */
550   hildon_date_editor_set_year (date_editor, year);
551
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);
559
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);
568 }
569 END_TEST
570
571 /* ----- Test case for get_month -----*/
572
573 /**
574  * Purpose: test getting a year for regular values for
575  * hildon_date_editor_get_month
576  * Cases considered:
577  *    - set month with set_date 30/03/1981
578  *    - set month with set_month 1
579  *    - set month with set_property 7
580  */
581 START_TEST (test_get_month_regular)
582 {
583   guint year, month, day;
584   GValue value = {0, };
585
586   year = 1981;
587   month = 3;
588   day = 30;
589
590   /* Test 1: Set year with set_date */
591   hildon_date_editor_set_date (date_editor, year, month, day);
592
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);
596
597   /* Test 2: set month with set_month */
598   month = 1;
599   hildon_date_editor_set_month (date_editor, month);
600
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);
604
605   /* Test 3: set month with set_property */
606   month = 7;
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);
610
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);
614 }
615 END_TEST
616
617 /**
618  * Purpose: test getting values of the month over the limits for
619  * hildon_date_editor_get_month
620  * Cases considered:
621  *    - Get month 12
622  *    - Get month 1
623  */
624 START_TEST (test_get_month_limits)
625 {
626
627   /* Test 1: Upper limit */
628   hildon_date_editor_set_month (date_editor, MAX_MONTH);
629
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);
633
634   /* Test 2: Lower limit */
635   hildon_date_editor_set_month (date_editor, MIN_MONTH);
636
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);
640 }
641 END_TEST
642
643 /**
644  * Purpose:  test getting a month for invalid attributes for
645  * hildon_date_editor_get_month
646  * Cases considered:
647  *    - HildonDateEditor is NULL
648  *    - HildonDateEditor is really a GtkHBox
649  */
650 START_TEST (test_get_month_invalid)
651 {
652   guint ret_month;
653   GtkWidget *aux_object = NULL;
654
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", 
659            ret_month, 0);
660
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", 
666            ret_month, 0);
667   gtk_widget_destroy (GTK_WIDGET(aux_object));
668 }
669 END_TEST
670
671 /* ----- Test case for set_month -----*/
672
673 /**
674  * Purpose: test setting regular values for month for
675  * hildon_date_editor_set_month
676  * Cases considered:
677  *    - Set month 3
678  */
679 START_TEST (test_set_month_regular)
680 {
681   guint month;
682   guint ret_month;
683
684   month = 3;
685
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);
689
690   fail_if (ret_month != month,
691            "hildon-date-editor: set_month failed. The returned month is %u and should be %u", 
692            ret_month, month);
693 }
694 END_TEST
695
696 /**
697  * Purpose: test setting values for month over the limits for
698  * hildon_date_editor_get_month
699  * Cases considered:
700  *    - Set month 12
701  *    - Set month 1
702  */
703 START_TEST (test_set_month_limits)
704 {
705   GValue value = { 0, };
706
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);
714
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);
723 }
724 END_TEST
725
726 /* ----- Test case for get_day -----*/
727
728 /**
729  * Purpose: test getting regular values for day for
730  * hildon_date_editor_get_day
731  * Cases considered:
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
735  */
736 START_TEST (test_get_day_regular)
737 {
738   guint year, month, day;
739   GValue value = {0, };
740
741   year = 1981;
742   month = 3;
743   day = 30;
744
745   /* Test 1: Set day with set_date */
746   hildon_date_editor_set_date (date_editor, year, month, day);
747
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);
751
752   /* Test 2: set day with set_day */
753   day = 6;
754   hildon_date_editor_set_day (date_editor, day);
755
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);
759
760
761   /* Test 3: set day with set_property */
762   day = 10;
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);
766
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);
770
771 }
772 END_TEST
773
774 /**
775  * Purpose: test getting a day set over the limits for
776  * hildon_date_editor_get_day
777  * Cases considered:
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
782  *    - Get day 1
783  */
784 START_TEST (test_get_day_limits)
785 {
786   guint day, month, year;
787
788   year = 1981;
789   month = 3;
790   day = 31;
791
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);
797
798   /* Test 2: 30 of February */
799   month = 6;
800   day = 30;
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);
805
806   /* Test 3: 29 of February */
807   year = 1980;
808   month = 2;
809   day = 29;
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);
814
815   /* Test 3: 28 of February */
816   year = 1981;
817   month = 2;
818   day = 28;
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);
823
824   /* Test 5: day 1 */
825   hildon_date_editor_set_day (date_editor, 1);
826
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);
830 }
831 END_TEST
832
833 /**
834  * Purpose: test getting a day with invalid attributes for
835  * hildon_date_editor_get_day
836  * Cases considered:
837  *    - HildonDateEditor is NULL
838  *    - HildonDateEditor is really a GtkHBox
839  */
840 START_TEST (test_get_day_invalid)
841 {
842   guint ret_year;
843   GtkWidget *aux_object = NULL;
844
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", 
849            ret_year, 0);
850
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", 
856            ret_year, 0);
857   gtk_widget_destroy (GTK_WIDGET(aux_object));
858 }
859 END_TEST
860
861 /* ----- Test case for set_day -----*/
862
863 /**
864  * Purpose: test setting a regular value for day for
865  * hildon_date_editor_get_day
866  * Cases considered:
867  *    - Set day 30
868  */
869 START_TEST (test_set_day_regular)
870 {
871   guint day;
872   guint ret_day;
873
874   day = 25;
875
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);
879
880   fail_if (ret_day != day,
881            "hildon-date-editor: set_day failed. The returned day is %u and should be %u", 
882            ret_day, day);
883 }
884 END_TEST
885
886 /**
887  * Purpose: test seeting a day over the limits for
888  * hildon_date_editor_get_day
889  * Cases considered:
890  *    - Set day 31
891  *    - Set day 30
892  *    - Set day 29
893  *    - Set day 28
894  *    - Set day 1
895  */
896 START_TEST (test_set_day_limits)
897 {
898   guint day, year, month;
899   GValue value = { 0, };
900
901   year = 1981;
902   month = 3;
903   day = 31;
904
905   /* Set init date */
906   hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);
907
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);
915
916   /* Test 2: Test 30/06 */
917   month = 6;
918   day = 30;
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);
927
928   /* Test 3: Test 29/02/1980 */
929   year = 1980;
930   month = 2;
931   day = 29;
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);
940
941   /* Test 4: Test 28/02/1981 */
942   year = 1981;
943   month = 2;
944   day = 28;
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);
953
954   /* Test 5: Test 1/02/1980 */
955   year = 1980;
956   month = 2;
957   day = 1;
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);
966 }
967 END_TEST
968
969 /* ---------- Suite creation ---------- */
970
971 Suite *create_hildon_date_editor_suite(void)
972 {
973   /* Create the suite */
974   Suite *s = suite_create("HildonDateEditor");
975
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");
985
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);
992
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);
998
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);
1005
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);
1011
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);
1018
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);
1024
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);
1031
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);
1037
1038   /* Return created suite */
1039   return s;
1040 }