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