2006-10-16 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
[hildon] / ut / hildon-clock-widgets_tests.c
1 /*
2  * This file is part of hildon-libs
3  *
4  * Copyright (C) 2005, 2006 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.
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 <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29 #include <assert.h>
30
31 #include <gtk/gtk.h>
32
33 #include <hildon-widgets/hildon-date-editor.h>
34 #include <hildon-widgets/hildon-time-editor.h>
35 #include <hildon-widgets/hildon-calendar-popup.h>
36
37 #include <outo.h>
38
39 /* Prototypes */
40 void init_test (void);
41 testcase* get_tests (void);
42
43 void init_test (void)
44 {
45     int plop = 0;
46     gtk_init (&plop, NULL);
47 }
48
49 /* time editor: new time: ok parameters */
50 static int test01a()
51 {
52   HildonTimeEditor *time_editor;
53
54   
55   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
56   assert(time_editor);
57   return 1;
58 }
59
60 /* time editor: get time: ok parameters */
61 static int test02a()
62 {
63   HildonTimeEditor *time_editor;
64   guint hours = 99, minutes = 99, seconds = 99;
65
66   
67
68   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
69   hildon_time_editor_get_time( time_editor, &hours, &minutes, &seconds );
70
71   assert (hours   >= 0 && hours   < 24);
72   assert (minutes >= 0 && minutes < 60);
73   assert (seconds >= 0 && seconds < 60);
74
75   return 1;
76 }
77
78 /* time editor: get time: null time editor */
79 static int test02b()
80 {
81   HildonTimeEditor *time_editor = NULL;
82   guint hours = 99, minutes = 99, seconds = 99;
83
84   
85
86   hildon_time_editor_get_time( time_editor, &hours, &minutes, &seconds );
87
88   assert (hours   >= 0 && hours   < 24);
89   assert (minutes >= 0 && minutes < 60);
90   assert (seconds >= 0 && seconds < 60);
91
92   return 1;
93 }
94
95 /* time editor: get time: null minutes */
96 static int test02c()
97 {
98   HildonTimeEditor *time_editor = NULL;
99   guint hours = 99, seconds = 99;
100
101   
102
103   hildon_time_editor_get_time (time_editor, &hours, NULL, &seconds);
104
105   return 1;
106 }
107
108 /* time editor: get time: null hours */
109 static int test02d()
110 {
111   HildonTimeEditor *time_editor = NULL;
112   guint minutes = 99, seconds = 99;
113
114   
115
116   hildon_time_editor_get_time (time_editor, NULL, &minutes, &seconds);
117
118   return 1;
119 }
120
121 /* time editor: get time: null hours, null minutes, null seconds */
122 static int test02e()
123 {
124   HildonTimeEditor *time_editor = NULL;
125
126   
127
128   hildon_time_editor_get_time (time_editor, NULL, NULL, NULL);
129
130   return 1;
131 }
132
133 /* time editor: get time: null seconds */
134 static int test02f()
135 {
136   HildonTimeEditor *time_editor = NULL;
137   guint hours = 99, minutes = 99;;
138
139   init_test();
140
141   hildon_time_editor_get_time (time_editor, &hours, &minutes, NULL);
142
143   return 1;
144 }
145
146 /* time editor: set time: hours, minutes, seconds are the minimum */
147 static int test03a()
148 {
149   HildonTimeEditor *time_editor;
150   guint hours = 0, minutes = 0, seconds = 0;
151
152   
153
154   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
155
156   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
157   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
158
159   assert (hours   == 0);
160   assert (minutes == 0);
161   assert (seconds == 0);
162
163   return 1;
164 }
165
166 /* time editor: set time: ok parameters */
167 static int test03b()
168 {
169   HildonTimeEditor *time_editor;
170   guint hours = 12, minutes = 30, seconds = 30;
171
172   
173
174   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
175
176   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
177   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
178
179   assert (hours   == 12);
180   assert (minutes == 30);
181   assert (seconds == 30);
182
183   return 1;
184 }
185
186 /* time editor: set time: hours on limit */
187 static int test03c()
188 {
189   HildonTimeEditor *time_editor;
190   guint hours = 24, minutes = 30, seconds = 0;
191
192   
193
194   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
195
196   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
197   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
198
199   assert (hours   == 24);
200   assert (minutes == 30);
201   assert (seconds == 0);
202
203
204   return 1;
205 }
206
207 /* time editor: set time: minutes on limit */
208 static int test03d()
209 {
210   HildonTimeEditor *time_editor;
211   guint hours = 12, minutes = 60, seconds = 0;
212
213   
214
215   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
216
217   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
218   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
219
220   assert (hours   == 12);
221   assert (minutes == 60);
222   assert (seconds == 0);
223
224
225   return 1;
226 }
227
228 /* time editor: set time: seconds on limit */
229 static int test03da()
230 {
231   HildonTimeEditor *time_editor;
232   guint hours = 12, minutes = 30, seconds = 60;
233
234   init_test();
235
236   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
237
238   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
239   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
240
241   assert (hours   == 12);
242   assert (minutes == 30);
243   assert (seconds == 60);
244
245   return 1;
246 }
247
248
249 /* time editor: set time: hours, minutes on limit */
250 static int test03e()
251 {
252   HildonTimeEditor *time_editor;
253   guint hours = 24, minutes = 60, seconds = 0;
254
255   
256
257   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
258
259   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
260   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
261
262   assert (hours   == 24);
263   assert (minutes == 60);
264   assert (seconds == 0);
265
266   return 1;
267 }
268
269 /* time editor: set time: hours, minutes, second on limit */
270 static int test03ea()
271 {
272   HildonTimeEditor *time_editor;
273   guint hours = 24, minutes = 60, seconds = 60;
274
275   init_test();
276
277   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
278
279   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
280   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
281
282   assert( hours   == 24 );
283   assert( minutes == 60 );
284   assert( seconds == 60 );
285
286   return 1;
287 }
288
289 /* time editor: set time: hours, minutes over max */
290 static int test03f()
291 {
292   HildonTimeEditor *time_editor;
293   guint hours = 25, minutes = 61, seconds = 0;
294
295   
296
297   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
298
299   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
300   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
301
302   assert (hours   == 25);
303   assert (minutes == 61);
304   assert (seconds == 0);
305
306   return 1;
307 }
308
309 /* time editor: set time: hours, minutes, seconds over max */
310 static int test03fa()
311 {
312   HildonTimeEditor *time_editor;
313   guint hours = 25, minutes = 61, seconds = 61;
314
315   init_test();
316
317   time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
318
319   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
320   hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
321
322   assert (hours   == 25);
323   assert (minutes == 61);
324   assert (seconds == 61);
325
326   return 1;
327 }
328
329 /* time editor: set time: null time editor*/
330 static int test03g()
331 {
332   HildonTimeEditor *time_editor = NULL;
333   guint hours = 23, minutes = 59, seconds = 0;
334
335   init_test();
336
337   hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
338
339   return 1;
340 }
341
342 /* time editor: show seconds: ok parameters */
343 static int test03h()
344 {
345   HildonTimeEditor *time_editor = NULL;
346
347   init_test();
348
349   time_editor = HILDON_TIME_EDITOR( hildon_time_editor_new () );
350 #ifndef HILDON_DISABLE_DEPRECATED
351   hildon_time_editor_show_seconds( time_editor, TRUE );
352 #else
353   hildon_time_editor_set_show_seconds (time_editor, TRUE);
354 #endif
355
356   return 1;
357 }
358
359 /* time editor: show seconds: null time editor*/
360 static int test03i()
361 {
362   HildonTimeEditor *time_editor = NULL;
363
364 #ifndef HILDON_DISABLE_DEPRECATED
365   hildon_time_editor_show_seconds( time_editor, TRUE );
366 #else
367   hildon_time_editor_set_show_seconds (time_editor, TRUE);
368 #endif
369
370   return 1;
371 }
372
373 /* time editor: get type: */
374 static int test04a()
375 {
376   GType t;
377
378   
379   
380   t = hildon_time_editor_get_type();
381
382   assert (t);
383
384   return 1;
385 }
386
387 /* date editor: new: ok parameters */
388 static int test05a()
389 {
390   HildonDateEditor *date_editor;
391
392   
393   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
394   assert (date_editor);
395   return 1;
396 }
397
398 /* date editor: get date: ok parameters */
399 static int test06a()
400 {
401   HildonDateEditor *date_editor;
402   guint year = 99999, month = 99, day = 999;
403
404   
405
406   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
407
408   hildon_date_editor_get_date (date_editor, &year, &month, &day);
409
410   assert (year  > 0);
411   assert (month > 0 && month < 13);
412   assert (day   > 0 && day   < 32);
413
414   return 1;
415 }
416
417 /* date editor: get date: null date editor */
418 static int test06b()
419 {
420   HildonDateEditor *date_editor = NULL;
421   guint year = 99999, month = 99, day = 999;
422
423   
424
425   hildon_date_editor_get_date (date_editor, &year, &month, &day);
426
427   assert (year  > 0);
428   assert (month > 0 && month < 13);
429   assert (day   > 0 && day   < 32);
430
431   return 1;
432 }
433
434 /* date editor: get date: null year */
435 static int test06c()
436 {
437   HildonDateEditor *date_editor;
438   guint month = 99, day = 999;
439
440   
441
442   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
443
444   hildon_date_editor_get_date (date_editor, NULL, &month, &day);
445
446   return 1;
447 }
448
449 /* date editor: get date: null month */
450 static int test06d()
451 {
452   HildonDateEditor *date_editor;
453   guint  month = 99, day = 999;
454
455   
456
457   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
458
459   hildon_date_editor_get_date (date_editor, &month, NULL, &day);
460
461   return 1;
462 }
463
464 /* date editor: get date: null day */
465 static int test06e()
466 {
467   HildonDateEditor *date_editor;
468   guint year = 99999, month = 99;
469
470   
471
472   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
473
474   hildon_date_editor_get_date (date_editor, &year, &month, NULL);
475
476   return 1;
477 }
478
479 /* date editor: get date: null year, month, day */
480 static int test06f()
481 {
482   HildonDateEditor *date_editor;
483
484   
485
486   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
487
488   hildon_date_editor_get_date (date_editor, NULL, NULL, NULL);
489
490   return 1;
491 }
492
493 /* date editor: set date: year, month, day are zero */
494 static int test07a()
495 {
496   HildonDateEditor *date_editor;
497   guint year = 0, month = 0, day = 0;
498
499   
500
501   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
502
503   hildon_date_editor_set_date (date_editor, year, month, day);
504   hildon_date_editor_get_date (date_editor, &year, &month, &day);
505
506   assert (year  == 0);
507   assert (month == 0);
508   assert (day   == 0);
509
510   return 1;
511 }
512
513 /* date editor: set date: year, month, day are the minumum */
514 static int test07ai()
515 {
516   HildonDateEditor *date_editor;
517   guint year = 1, month = 1, day = 1;
518
519   
520
521   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
522
523   hildon_date_editor_set_date (date_editor, year, month, day);
524   hildon_date_editor_get_date (date_editor, &year, &month, &day);
525
526   assert (year  == 1);
527   assert (month == 1);
528   assert (day   == 1);
529
530   return 1;
531 }
532
533 /* date editor: set date: month less than minimum */
534 static int test07b()
535 {
536   HildonDateEditor *date_editor;
537   guint year = 2003, month = 0, day = 2;
538
539   
540
541   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
542
543   hildon_date_editor_set_date (date_editor, year, month, day);
544   hildon_date_editor_get_date (date_editor, &year, &month, &day);
545
546   assert (year  == 2003);
547   assert (month == 0);
548   assert (day   == 2);
549
550   return 1;
551 }
552
553 /* date editor: set date: day less than minimum */
554 static int test07c()
555 {
556   HildonDateEditor *date_editor;
557   guint year = 2003, month = 12, day = 0;
558
559   
560
561   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
562
563   hildon_date_editor_set_date (date_editor, year, month, day);
564   hildon_date_editor_get_date (date_editor, &year, &month, &day);
565
566   assert (year  == 2003);
567   assert (month == 12);
568   assert (day   == 0);
569
570   return 1;
571 }
572
573 /* date editor: set date: ok parameters */
574 static int test07d()
575 {
576   HildonDateEditor *date_editor;
577   guint year = 2003, month = 12, day = 2;
578
579   
580
581   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
582
583   hildon_date_editor_set_date (date_editor, year, month, day);
584   hildon_date_editor_get_date (date_editor, &year, &month, &day);
585
586   assert (year  == 2003);
587   assert (month == 12);
588   assert (day   == 2);
589
590   return 1;
591 }
592
593 /* date editor: set date: big year, should be ok */
594 static int test07e()
595 {
596   HildonDateEditor *date_editor;
597   /* hmm.. year seems to fail between 2020 and 2030 */
598   guint year = 2500, month = 12, day = 2;
599
600   
601
602   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
603
604   hildon_date_editor_set_date (date_editor, year, month, day);
605   hildon_date_editor_get_date (date_editor, &year, &month, &day);
606
607   assert (year  == 2500);
608   assert (month == 12);
609   assert (day   == 2);
610
611   return 1;
612 }
613
614 /* date editor: set date: month over max */
615 static int test07f()
616 {
617   HildonDateEditor *date_editor;
618   guint year = 2003, month = 13, day = 2;
619
620   
621
622   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
623
624   hildon_date_editor_set_date (date_editor, year, month, day);
625   hildon_date_editor_get_date (date_editor, &year, &month, &day);
626
627   assert (year  == 2003);
628   assert (month == 13);
629   assert (day   == 2);
630
631   return 1;
632 }
633
634 /* date editor: set date: day over max */
635 static int test07g()
636 {
637   HildonDateEditor *date_editor;
638   guint year = 2003, month = 11, day = 31;
639
640   
641
642   date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
643
644   hildon_date_editor_set_date (date_editor, year, month, day);
645   hildon_date_editor_get_date (date_editor, &year, &month, &day);
646
647   assert (year  == 2003);
648   assert (month == 11);
649   assert (day   == 31);
650
651   return 1;
652 }
653
654 /* date editor: set date: null date editor */
655 static int test07h()
656 {
657   
658
659   hildon_date_editor_set_date (NULL, 0, 0, 0);
660
661   return 1;
662 }
663
664
665 testcase tcases[] =
666 {
667     {*test01a, " 01a_time_editor_new",                EXPECT_OK},
668     {*test02a, " 02a_time_editor_get_time",           EXPECT_OK},
669     {*test02b, " 02b_time_editor_get_time_null",      EXPECT_ASSERT},
670     {*test02c, " 02c_time_editor_get_time_null2",     EXPECT_ASSERT},
671     {*test02d, " 02d_time_editor_get_time_null3",     EXPECT_ASSERT},
672     {*test02e, " 02e_time_editor_get_time_null4",     EXPECT_ASSERT},
673     {*test02f, " 02e_time_editor_get_time_null5",     EXPECT_ASSERT},
674     {*test03a, " 03a_time_editor_set_time_both_0",    EXPECT_OK},
675     {*test03b, " 03b_..._both_between",               EXPECT_OK},
676     {*test03c, " 03c_..._hours_limit",                EXPECT_ASSERT},
677     {*test03d, " 03d_..._minutes_limit",              EXPECT_ASSERT},
678     {*test03da," 03d_..._seconds_limit",              EXPECT_ASSERT},
679     {*test03e, " 03e_..._both_limit",                 EXPECT_ASSERT},
680     {*test03ea," 03e_..._all_limit",                  EXPECT_ASSERT},
681     {*test03f, " 03f_..._both_over",                  EXPECT_ASSERT},
682     {*test03fa," 03f_..._all_over",                   EXPECT_ASSERT},
683     {*test03g, " 03g_..._null",                       EXPECT_ASSERT},
684     {*test03h, " 03h_show_seconds_ok",                EXPECT_OK},
685     {*test03i, " 03i_show_seconds_null",              EXPECT_ASSERT},
686     {*test04a, " 04a_time_editor_get_type",           EXPECT_OK},
687     {*test05a, " 05a_date_editor_new",                EXPECT_OK},
688     {*test06a, " 06a_date_editor_get_date",           EXPECT_OK},
689     {*test06b, " 06b_date_editor_get_date_null",      EXPECT_ASSERT},
690     {*test06c, " 06c_date_editor_get_date_null2",     EXPECT_ASSERT},
691     {*test06d, " 06d_date_editor_get_date_null3",     EXPECT_ASSERT},
692     {*test06e, " 06e_date_editor_get_date_null4",     EXPECT_ASSERT},
693     {*test06f, " 06f_date_editor_get_date_null5",     EXPECT_ASSERT},
694     {*test07a, " 07a_date_editor_set_date_valid1",    EXPECT_ASSERT},
695     {*test07ai," 07ai_date_editor_set_date_valid1a",  EXPECT_OK},
696     {*test07b, " 07b_date_editor_set_date_valid2",    EXPECT_ASSERT},
697     {*test07c, " 07c_date_editor_set_date_valid3",    EXPECT_ASSERT},
698     {*test07d, " 07d_date_editor_set_date_valid4",    EXPECT_OK},
699     {*test07e, " 07e_date_editor_set_date_valid5",    EXPECT_OK},
700     {*test07f, " 07f_date_editor_set_date_valid6",    EXPECT_ASSERT},
701     {*test07g, " 07g_date_editor_set_date_valid7",    EXPECT_ASSERT},
702     {*test07h, " 07h_date_editor_set_date_null",      EXPECT_ASSERT},
703     
704     {0} /*REMEMBER THE TERMINATING NULL*/
705 };
706
707 /*use EXPECT_ASSERT for the tests that are _ment_ to throw assert so they are 
708   consider passed when they throw assert and failed when tehy do not*/
709
710 testcase* get_tests (void)
711 {
712     g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
713     return tcases;
714 }