1 /* -*- mode: C; c-file-style: "stroustrup"; indent-tabs-mode: nil; -*- */
2 /* Copyright (c) 2003 Nokia Oyj*/
11 #include <hildon-widgets/hildon-date-editor.h>
12 #include <hildon-widgets/hildon-time-editor.h>
13 #include <hildon-widgets/hildon-calendar-popup.h>
18 void init_test (void);
19 testcase* get_tests (void);
24 gtk_init (&plop, NULL);
27 /* time editor: new time: ok parameters */
30 HildonTimeEditor *time_editor;
33 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
38 /* time editor: get time: ok parameters */
41 HildonTimeEditor *time_editor;
42 guint hours = 99, minutes = 99, seconds = 99;
46 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
47 hildon_time_editor_get_time( time_editor, &hours, &minutes, &seconds );
49 assert (hours >= 0 && hours < 24);
50 assert (minutes >= 0 && minutes < 60);
51 assert (seconds >= 0 && seconds < 60);
56 /* time editor: get time: null time editor */
59 HildonTimeEditor *time_editor = NULL;
60 guint hours = 99, minutes = 99, seconds = 99;
64 hildon_time_editor_get_time( time_editor, &hours, &minutes, &seconds );
66 assert (hours >= 0 && hours < 24);
67 assert (minutes >= 0 && minutes < 60);
68 assert (seconds >= 0 && seconds < 60);
73 /* time editor: get time: null minutes */
76 HildonTimeEditor *time_editor = NULL;
77 guint hours = 99, seconds = 99;
81 hildon_time_editor_get_time (time_editor, &hours, NULL, &seconds);
86 /* time editor: get time: null hours */
89 HildonTimeEditor *time_editor = NULL;
90 guint minutes = 99, seconds = 99;
94 hildon_time_editor_get_time (time_editor, NULL, &minutes, &seconds);
99 /* time editor: get time: null hours, null minutes, null seconds */
102 HildonTimeEditor *time_editor = NULL;
106 hildon_time_editor_get_time (time_editor, NULL, NULL, NULL);
111 /* time editor: get time: null seconds */
114 HildonTimeEditor *time_editor = NULL;
115 guint hours = 99, minutes = 99;;
119 hildon_time_editor_get_time (time_editor, &hours, &minutes, NULL);
124 /* time editor: set time: hours, minutes, seconds are the minimum */
127 HildonTimeEditor *time_editor;
128 guint hours = 0, minutes = 0, seconds = 0;
132 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
134 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
135 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
138 assert (minutes == 0);
139 assert (seconds == 0);
144 /* time editor: set time: ok parameters */
147 HildonTimeEditor *time_editor;
148 guint hours = 12, minutes = 30, seconds = 30;
152 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
154 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
155 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
157 assert (hours == 12);
158 assert (minutes == 30);
159 assert (seconds == 30);
164 /* time editor: set time: hours on limit */
167 HildonTimeEditor *time_editor;
168 guint hours = 24, minutes = 30, seconds = 0;
172 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
174 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
175 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
177 assert (hours == 24);
178 assert (minutes == 30);
179 assert (seconds == 0);
185 /* time editor: set time: minutes on limit */
188 HildonTimeEditor *time_editor;
189 guint hours = 12, minutes = 60, seconds = 0;
193 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
195 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
196 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
198 assert (hours == 12);
199 assert (minutes == 60);
200 assert (seconds == 0);
206 /* time editor: set time: seconds on limit */
207 static int test03da()
209 HildonTimeEditor *time_editor;
210 guint hours = 12, minutes = 30, seconds = 60;
214 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
216 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
217 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
219 assert (hours == 12);
220 assert (minutes == 30);
221 assert (seconds == 60);
227 /* time editor: set time: hours, minutes on limit */
230 HildonTimeEditor *time_editor;
231 guint hours = 24, minutes = 60, seconds = 0;
235 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
237 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
238 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
240 assert (hours == 24);
241 assert (minutes == 60);
242 assert (seconds == 0);
247 /* time editor: set time: hours, minutes, second on limit */
248 static int test03ea()
250 HildonTimeEditor *time_editor;
251 guint hours = 24, minutes = 60, seconds = 60;
255 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
257 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
258 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
260 assert( hours == 24 );
261 assert( minutes == 60 );
262 assert( seconds == 60 );
267 /* time editor: set time: hours, minutes over max */
270 HildonTimeEditor *time_editor;
271 guint hours = 25, minutes = 61, seconds = 0;
275 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
277 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
278 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
280 assert (hours == 25);
281 assert (minutes == 61);
282 assert (seconds == 0);
287 /* time editor: set time: hours, minutes, seconds over max */
288 static int test03fa()
290 HildonTimeEditor *time_editor;
291 guint hours = 25, minutes = 61, seconds = 61;
295 time_editor = HILDON_TIME_EDITOR(hildon_time_editor_new());
297 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
298 hildon_time_editor_get_time (time_editor, &hours, &minutes, &seconds);
300 assert (hours == 25);
301 assert (minutes == 61);
302 assert (seconds == 61);
307 /* time editor: set time: null time editor*/
310 HildonTimeEditor *time_editor = NULL;
311 guint hours = 23, minutes = 59, seconds = 0;
315 hildon_time_editor_set_time (time_editor, hours, minutes, seconds);
320 /* time editor: show seconds: ok parameters */
323 HildonTimeEditor *time_editor = NULL;
327 time_editor = HILDON_TIME_EDITOR( hildon_time_editor_new () );
328 hildon_time_editor_show_seconds( time_editor, TRUE );
333 /* time editor: show seconds: null time editor*/
336 HildonTimeEditor *time_editor = NULL;
340 hildon_time_editor_show_seconds( time_editor, TRUE );
345 /* time editor: get type: */
352 t = hildon_time_editor_get_type();
359 /* date editor: new: ok parameters */
362 HildonDateEditor *date_editor;
365 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
366 assert (date_editor);
370 /* date editor: get date: ok parameters */
373 HildonDateEditor *date_editor;
374 guint year = 99999, month = 99, day = 999;
378 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
380 hildon_date_editor_get_date (date_editor, &year, &month, &day);
383 assert (month > 0 && month < 13);
384 assert (day > 0 && day < 32);
389 /* date editor: get date: null date editor */
392 HildonDateEditor *date_editor = NULL;
393 guint year = 99999, month = 99, day = 999;
397 hildon_date_editor_get_date (date_editor, &year, &month, &day);
400 assert (month > 0 && month < 13);
401 assert (day > 0 && day < 32);
406 /* date editor: get date: null year */
409 HildonDateEditor *date_editor;
410 guint month = 99, day = 999;
414 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
416 hildon_date_editor_get_date (date_editor, NULL, &month, &day);
421 /* date editor: get date: null month */
424 HildonDateEditor *date_editor;
425 guint month = 99, day = 999;
429 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
431 hildon_date_editor_get_date (date_editor, &month, NULL, &day);
436 /* date editor: get date: null day */
439 HildonDateEditor *date_editor;
440 guint year = 99999, month = 99;
444 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
446 hildon_date_editor_get_date (date_editor, &year, &month, NULL);
451 /* date editor: get date: null year, month, day */
454 HildonDateEditor *date_editor;
458 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
460 hildon_date_editor_get_date (date_editor, NULL, NULL, NULL);
465 /* date editor: set date: year, month, day are zero */
468 HildonDateEditor *date_editor;
469 guint year = 0, month = 0, day = 0;
473 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
475 hildon_date_editor_set_date (date_editor, year, month, day);
476 hildon_date_editor_get_date (date_editor, &year, &month, &day);
485 /* date editor: set date: year, month, day are the minumum */
486 static int test07ai()
488 HildonDateEditor *date_editor;
489 guint year = 1, month = 1, day = 1;
493 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
495 hildon_date_editor_set_date (date_editor, year, month, day);
496 hildon_date_editor_get_date (date_editor, &year, &month, &day);
505 /* date editor: set date: month less than minimum */
508 HildonDateEditor *date_editor;
509 guint year = 2003, month = 0, day = 2;
513 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
515 hildon_date_editor_set_date (date_editor, year, month, day);
516 hildon_date_editor_get_date (date_editor, &year, &month, &day);
518 assert (year == 2003);
525 /* date editor: set date: day less than minimum */
528 HildonDateEditor *date_editor;
529 guint year = 2003, month = 12, day = 0;
533 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
535 hildon_date_editor_set_date (date_editor, year, month, day);
536 hildon_date_editor_get_date (date_editor, &year, &month, &day);
538 assert (year == 2003);
539 assert (month == 12);
545 /* date editor: set date: ok parameters */
548 HildonDateEditor *date_editor;
549 guint year = 2003, month = 12, day = 2;
553 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
555 hildon_date_editor_set_date (date_editor, year, month, day);
556 hildon_date_editor_get_date (date_editor, &year, &month, &day);
558 assert (year == 2003);
559 assert (month == 12);
565 /* date editor: set date: big year, should be ok */
568 HildonDateEditor *date_editor;
569 /* hmm.. year seems to fail between 2020 and 2030 */
570 guint year = 2500, month = 12, day = 2;
574 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
576 hildon_date_editor_set_date (date_editor, year, month, day);
577 hildon_date_editor_get_date (date_editor, &year, &month, &day);
579 assert (year == 2500);
580 assert (month == 12);
586 /* date editor: set date: month over max */
589 HildonDateEditor *date_editor;
590 guint year = 2003, month = 13, day = 2;
594 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
596 hildon_date_editor_set_date (date_editor, year, month, day);
597 hildon_date_editor_get_date (date_editor, &year, &month, &day);
599 assert (year == 2003);
600 assert (month == 13);
606 /* date editor: set date: day over max */
609 HildonDateEditor *date_editor;
610 guint year = 2003, month = 11, day = 31;
614 date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
616 hildon_date_editor_set_date (date_editor, year, month, day);
617 hildon_date_editor_get_date (date_editor, &year, &month, &day);
619 assert (year == 2003);
620 assert (month == 11);
626 /* date editor: set date: null date editor */
631 hildon_date_editor_set_date (NULL, 0, 0, 0);
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},
676 {0} /*REMEMBER THE TERMINATING NULL*/
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*/
682 testcase* get_tests (void)
684 g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);