1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
|
/*
* This file is a part of hildon tests
*
* Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
*
* Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <stdlib.h>
#include <check.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkhbox.h>
#include "test_suites.h"
#include "check_utils.h"
#include "hildon-date-editor.h"
/* Taken from the values of the properties of HildonDateEditor */
#define MAX_YEAR 2037
#define MAX_MONTH 12
#define MAX_DAY 31
#define MIN_YEAR 1970
#define MIN_MONTH 1
#define MIN_DAY 1
/* -------------------- Fixtures -------------------- */
static HildonDateEditor *date_editor = NULL;
static GtkWidget *showed_window = NULL;
static void
fx_setup_default_date_editor ()
{
int argc = 0;
gtk_init(&argc, NULL);
showed_window = create_test_window ();
date_editor = HILDON_DATE_EDITOR(hildon_date_editor_new());
/* Check that the date editor object has been created properly */
fail_if(!HILDON_IS_DATE_EDITOR(date_editor),
"hildon-date-editor: Creation failed.");
/* This packs the widget into the window (a gtk container). */
gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (date_editor));
/* Displays the widget and the window */
show_all_test_window (showed_window);
}
static void
fx_teardown_default_date_editor ()
{
/* Destroy the widget and the window */
gtk_widget_destroy (GTK_WIDGET (showed_window));
}
/* -------------------- Test cases -------------------- */
/* ----- Test case for set_date -----*/
/**
* Purpose: test setting regular values for hildon_date_editor_set_date
* Cases considered:
* - Set and get the date 30/03/1981
*/
START_TEST (test_set_date_regular)
{
guint year, month, day;
guint ret_year, ret_month, ret_day;
year = 1981;
month = 3;
day = 30;
/* Test 1: Try date 30/3/1981 */
hildon_date_editor_set_date (date_editor, year, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
}
END_TEST
static void
test_set_date_limits_check (guint year, guint month, guint day)
{
guint ret_year, ret_month, ret_day;
hildon_date_editor_set_date (date_editor, year, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
}
/**
* Purpose: test limit date values for hildon_date_editor_set_date
* Cases considered:
* - test a year value equal to the year limits (1970, 2037)
* - test a month value equal to the month limits (1, 12)
* - test a day value equal to the day limits for March (1, 31)
* - test a day value equal to the day limits June (1, 30)
* - test a day value equal to the day limit for a common February (28-2-1981)
* - test a day value equal to the day limit for a February of a leap year (29-2-1980)
*/
START_TEST (test_set_date_limits)
{
guint year, month, day;
year = MIN_YEAR;
month = 3;
day = 30;
/* Test 1: Test year limits */
test_set_date_limits_check (year, month, day);
year = MAX_YEAR;
test_set_date_limits_check (year, month, day);
/* Test 2: Test month limits */
year = 1981;
month = MIN_MONTH;
day = 30;
test_set_date_limits_check (year, month, day);
month = MAX_MONTH;
test_set_date_limits_check (year, month, day);
/* Test 3: Test day limits */
year = 1981;
month = 3;
day = 31;
test_set_date_limits_check (year, month, day);
/* Test 4: Test day limits */
year = 1981;
month = 6;
day = 30;
test_set_date_limits_check (year, month, day);
/* Test 5: Test february limits */
year = 1981;
month = 2;
day = 28;
test_set_date_limits_check (year, month, day);
/* Test 6: Test february limits for a leap year */
year = 1980;
month = 2;
day = 29;
test_set_date_limits_check (year, month, day);
}
END_TEST
/**
* Purpose: test invalid parameter values for hildon_date_editor_set_date
* Cases considered:
* - test NULL widget
* - test passing GtkHBox instead a HildonDateEditor
* - test leap year
* - test negative values
* - test invalid month days
* - test a year value lower and higher than the year limits (1970, 2037)
* - test a month value lower and higher than the year limits (1, 12)
* - test a day value lower and higher than the year limits (1, 31)
*/
START_TEST (test_set_date_invalid)
{
guint year, month, day;
guint ret_year, ret_month, ret_day;
GtkWidget *aux_object = NULL;
year = 1981;
month = 3;
day = 30;
/* Set init date */
hildon_date_editor_set_date (date_editor, year, month, day);
/* Test 1: Test NULL */
hildon_date_editor_set_date (NULL, year, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
/* Test 2: Test another object */
aux_object = gtk_hbox_new (TRUE, 0);
hildon_date_editor_set_date ((HildonDateEditor *) (aux_object), year, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
gtk_widget_destroy (GTK_WIDGET(aux_object));
/* Test 3: Test leap year */
hildon_date_editor_set_date (date_editor, year, 2, 29);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
/* Restore the original value */
hildon_date_editor_set_date (date_editor, year, month, day);
/* Test 4: Test negative values */
hildon_date_editor_set_date (date_editor, -year, -month, -day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
/* Test 5: Test invalid month days */
hildon_date_editor_set_date (date_editor, year, 11, 31);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if ((ret_year != year) || (ret_month != month) || (ret_day != day),
"hildon-date-editor: The returned date is %u/%u/%u and should be %u/%u/%u",
ret_year, ret_month, ret_day, year, month, day);
/* Test 6: Test year invalid values, the year value could be set
under/over the value of the property because the date is not
validated if the value was not set through the user interface */
hildon_date_editor_set_date (date_editor, MIN_YEAR - 1, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_year != (MIN_YEAR - 1),
"hildon-date-editor: The returned year is %u and should be %u",
ret_year, MIN_YEAR - 1);
hildon_date_editor_set_date (date_editor, MAX_YEAR + 1, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_year != MAX_YEAR + 1,
"hildon-date-editor: The returned year is %u and should be %u",
ret_year, MAX_YEAR + 1);
/* Test 7: Test month invalid values, we do not have the same
problem with the years because both month 0 and 13 are not valid
for g_date */
hildon_date_editor_set_date (date_editor, year, MIN_MONTH - 1, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_month != month,
"hildon-date-editor: The returned month is %u and should be %u",
ret_month, month);
hildon_date_editor_set_date (date_editor, year, MAX_MONTH + 1, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_month != month,
"hildon-date-editor: The returned month is %u and should be %u",
ret_month, month);
/* Test 8: Test day invalid values */
hildon_date_editor_set_date (date_editor, year, month, MIN_DAY - 1);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_day != day,
"hildon-date-editor: The returned day is %u and should be %u",
ret_day, day);
hildon_date_editor_set_date (date_editor, year, month, MAX_DAY + 1);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
fail_if (ret_day != day,
"hildon-date-editor: The returned day is %u and should be %u",
ret_day, day);
}
END_TEST
/* ----- Test case for get_date -----*/
/* We do not include tests for limit values because we think they're
tested enought with the set_data tests */
/**
* Purpose: test getting regular values for hildon_date_editor_get_date
* Cases considered:
* - Set and get date 30/03/1981
*/
START_TEST (test_get_date_regular)
{
guint year, month, day;
guint ret_year, ret_month, ret_day;
GValue value = { 0, };
year = 1981;
month = 3;
day = 30;
/* Test 1: Test regular values */
hildon_date_editor_set_date (NULL, year, month, day);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, &ret_day);
g_value_init (&value, G_TYPE_UINT);
g_object_get_property (G_OBJECT (date_editor), "year", &value);
fail_if (g_value_get_uint (&value) != ret_year,
"hildon-date-editor: get_date failed. The returned year is %u and should be %u",
g_value_get_uint (&value),
ret_year);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
g_object_get_property (G_OBJECT (date_editor), "month", &value);
fail_if (g_value_get_uint (&value) != ret_month,
"hildon-date-editor: get_date failed. The returned month is %u and should be %u",
g_value_get_uint (&value),
ret_month);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != ret_day,
"hildon-date-editor: get_date failed. The returned day is %u and should be %u",
g_value_get_uint (&value),
ret_day);
}
END_TEST
/**
* Purpose: test getting regular values passing invalid arguments for
* hildon_date_editor_get_date
* Cases considered:
* - HildonDateEditor NULL
* - year is NULL
* - month is NULL
* - day is NULL
*/
START_TEST (test_get_date_invalid)
{
guint year, month, day;
guint ret_year, ret_month, ret_day;
year = 1981;
month = 3;
day = 30;
hildon_date_editor_set_date (date_editor, year, month, day);
/* Check that does not fail */
hildon_date_editor_get_date (NULL, &ret_year, &ret_month, &ret_day);
/* Check NULL arguments */
hildon_date_editor_get_date (date_editor, NULL, &ret_month, &ret_day);
fail_if (hildon_date_editor_get_year (date_editor) != year,
"hildon-date-editor: get_date failed. The returned year is %u and should be %u",
ret_year, year);
hildon_date_editor_get_date (date_editor, &ret_year, NULL, &ret_day);
fail_if (hildon_date_editor_get_month (date_editor) != month,
"hildon-date-editor: get_date failed. The returned month is %u and should be %u",
ret_month, month);
hildon_date_editor_get_date (date_editor, &ret_year, &ret_month, NULL);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: get_date failed. The returned day is %u and should be %u",
ret_day, day);
}
END_TEST
/* ----- Test case for get_year -----*/
/**
* Purpose: test getting regular values of the year for hildon_date_editor_get_year
* Cases considered:
* - get a year set with set_date 30/03/1981
* - get a year set with set_year 1980
* - get a year set with set_property 2004
*/
START_TEST (test_get_year_regular)
{
guint year, month, day;
GValue value = {0, };
year = 1981;
month = 3;
day = 30;
/* Test 1: Set year with set_date */
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_year (date_editor) != year,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), year);
/* Test 2: set year with set_year */
year = 1980;
hildon_date_editor_set_year (date_editor, year);
fail_if (hildon_date_editor_get_year (date_editor) != year,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), year);
/* Test 3: set year with set_property */
year = 2004;
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, year);
g_object_set_property (G_OBJECT (date_editor), "year", &value);
fail_if (hildon_date_editor_get_year (date_editor) != year,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), year);
}
END_TEST
/**
* Purpose: test getting year when a value over the limits was set for
* hildon_date_editor_get_year
* Cases considered:
* - test year 2037
* - test year 1970
*/
START_TEST (test_get_year_limits)
{
guint year;
year = 1981;
/* Set init year */
hildon_date_editor_set_year (date_editor, year);
/* Test 1: upper limit */
hildon_date_editor_set_year (date_editor, MAX_YEAR);
fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR,
"hildon-date-editor: The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), MAX_YEAR);
/* Test 2: lower limit */
hildon_date_editor_set_year (date_editor, MIN_YEAR);
fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR,
"hildon-date-editor: The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), MIN_YEAR);
}
END_TEST
/**
* Purpose: test getting a year for invalid attributes for
* hildon_date_editor_get_year
* Cases considered:
* - HildonDateEditor is NULL
* - Pass a GtkHBox instead a HildonDateEditor
* - test year 2038
* - test year 1969
*/
START_TEST (test_get_year_invalid)
{
guint ret_year;
GtkWidget *aux_object = NULL;
/* Test 1: Test NULL */
ret_year = hildon_date_editor_get_year (NULL);
fail_if (ret_year != 0,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
ret_year, 0);
/* Test 2: another object */
aux_object = gtk_hbox_new (TRUE, 0);
ret_year = hildon_date_editor_get_year ((HildonDateEditor *) (aux_object));
fail_if (ret_year != 0,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
ret_year, 0);
gtk_widget_destroy (GTK_WIDGET(aux_object));
/* Test 3: upper limit, the test is OK but it shouldn't. The reason
is that the value of the date is not validated by Hildon since it
was not set using the UI */
hildon_date_editor_set_year (date_editor, MAX_YEAR + 1);
fail_if (hildon_date_editor_get_year (date_editor) != MAX_YEAR + 1,
"hildon-date-editor: The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), MAX_YEAR + 1);
/* Test 4: lower limit, see the above comment */
hildon_date_editor_set_year (date_editor, MIN_YEAR - 1);
fail_if (hildon_date_editor_get_year (date_editor) != MIN_YEAR - 1,
"hildon-date-editor: The returned year is %u and should be %u",
hildon_date_editor_get_year (date_editor), MIN_YEAR - 1);
}
END_TEST
/* ----- Test case for set_year -----*/
/**
* Purpose: test setting a regular value for a year for
* hildon_date_editor_set_year
* Cases considered:
* - Set year 1981
*/
START_TEST (test_set_year_regular)
{
guint year;
guint ret_year;
year = 1981;
/* Test 1: Try year 1981 */
hildon_date_editor_set_year (date_editor, year);
ret_year = hildon_date_editor_get_year (date_editor);
fail_if (ret_year != year,
"hildon-date-editor: set_year failed. The returned year is %u and should be %u",
ret_year, year);
}
END_TEST
/**
* Purpose: test setting values of the year over the limits for
* hildon_date_editor_set_year
* Cases considered:
* - Set year 2037
* - Set year 1970
*/
START_TEST (test_set_year_limits)
{
guint year;
GValue value = { 0, };
year = 1981;
/* Set init date */
hildon_date_editor_set_year (date_editor, year);
/* Test 1: Test upper limit */
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_year (date_editor, MAX_YEAR);
g_object_get_property (G_OBJECT (date_editor), "year", &value);
fail_if (g_value_get_uint (&value) != MAX_YEAR,
"hildon-date-editor: The returned year is %u and should be %u",
g_value_get_uint (&value), year);
/* Test 2: Test lower limit */
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_year (date_editor, MIN_YEAR);
g_object_get_property (G_OBJECT (date_editor), "year", &value);
fail_if (g_value_get_uint (&value) != MIN_YEAR,
"hildon-date-editor: The returned year is %u and should be %u",
g_value_get_uint (&value), MIN_YEAR);
}
END_TEST
/* ----- Test case for get_month -----*/
/**
* Purpose: test getting a year for regular values for
* hildon_date_editor_get_month
* Cases considered:
* - set month with set_date 30/03/1981
* - set month with set_month 1
* - set month with set_property 7
*/
START_TEST (test_get_month_regular)
{
guint year, month, day;
GValue value = {0, };
year = 1981;
month = 3;
day = 30;
/* Test 1: Set year with set_date */
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_month (date_editor) != month,
"hildon-date-editor: The returned month is %u and should be %u",
hildon_date_editor_get_month (date_editor), month);
/* Test 2: set month with set_month */
month = 1;
hildon_date_editor_set_month (date_editor, month);
fail_if (hildon_date_editor_get_month (date_editor) != month,
"hildon-date-editor: The returned month is %u and should be %u",
hildon_date_editor_get_month (date_editor), month);
/* Test 3: set month with set_property */
month = 7;
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, month);
g_object_set_property (G_OBJECT (date_editor), "month", &value);
fail_if (hildon_date_editor_get_month (date_editor) != month,
"hildon-date-editor: The returned month is %u and should be %u",
hildon_date_editor_get_month (date_editor), month);
}
END_TEST
/**
* Purpose: test getting values of the month over the limits for
* hildon_date_editor_get_month
* Cases considered:
* - Get month 12
* - Get month 1
*/
START_TEST (test_get_month_limits)
{
/* Test 1: Upper limit */
hildon_date_editor_set_month (date_editor, MAX_MONTH);
fail_if (hildon_date_editor_get_month (date_editor) != MAX_MONTH,
"hildon-date-editor: get_month failed. The returned month is %u and should be %u",
hildon_date_editor_get_month (date_editor), MAX_MONTH);
/* Test 2: Lower limit */
hildon_date_editor_set_month (date_editor, MIN_MONTH);
fail_if (hildon_date_editor_get_month (date_editor) != MIN_MONTH,
"hildon-date-editor: get_month failed. The returned month is %u and should be %u",
hildon_date_editor_get_month (date_editor), MIN_MONTH);
}
END_TEST
/**
* Purpose: test getting a month for invalid attributes for
* hildon_date_editor_get_month
* Cases considered:
* - HildonDateEditor is NULL
* - HildonDateEditor is really a GtkHBox
*/
START_TEST (test_get_month_invalid)
{
guint ret_month;
GtkWidget *aux_object = NULL;
/* Test 1: Test NULL */
ret_month = hildon_date_editor_get_month (NULL);
fail_if (ret_month != 0,
"hildon-date-editor: get_month failed. The returned month is %u and should be %u",
ret_month, 0);
/* Test 2: another object */
aux_object = gtk_hbox_new (TRUE, 0);
ret_month = hildon_date_editor_get_month ((HildonDateEditor *) (aux_object));
fail_if (ret_month != 0,
"hildon-date-editor: get_month failed. The returned month is %u and should be %u",
ret_month, 0);
gtk_widget_destroy (GTK_WIDGET(aux_object));
}
END_TEST
/* ----- Test case for set_month -----*/
/**
* Purpose: test setting regular values for month for
* hildon_date_editor_set_month
* Cases considered:
* - Set month 3
*/
START_TEST (test_set_month_regular)
{
guint month;
guint ret_month;
month = 3;
/* Test 1: Try month March (3) */
hildon_date_editor_set_month (date_editor, month);
ret_month = hildon_date_editor_get_month (date_editor);
fail_if (ret_month != month,
"hildon-date-editor: set_month failed. The returned month is %u and should be %u",
ret_month, month);
}
END_TEST
/**
* Purpose: test setting values for month over the limits for
* hildon_date_editor_get_month
* Cases considered:
* - Set month 12
* - Set month 1
*/
START_TEST (test_set_month_limits)
{
GValue value = { 0, };
/* Test 1: Test upper limit */
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_month (date_editor, MAX_MONTH);
g_object_get_property (G_OBJECT (date_editor), "month", &value);
fail_if (g_value_get_uint (&value) != MAX_MONTH,
"hildon-date-editor: The returned month is %u and should be %u",
g_value_get_uint (&value), MAX_MONTH);
/* Test 2: Test lower limit */
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_month (date_editor, MIN_MONTH);
g_object_get_property (G_OBJECT (date_editor), "month", &value);
fail_if (g_value_get_uint (&value) != MIN_MONTH,
"hildon-date-editor: The returned month is %u and should be %u",
g_value_get_uint (&value), MIN_MONTH);
}
END_TEST
/* ----- Test case for get_day -----*/
/**
* Purpose: test getting regular values for day for
* hildon_date_editor_get_day
* Cases considered:
* - Get a day set with set_date 30/03/1981
* - Get a day set with set_day 6
* - Get a day set with set_property 10
*/
START_TEST (test_get_day_regular)
{
guint year, month, day;
GValue value = {0, };
year = 1981;
month = 3;
day = 30;
/* Test 1: Set day with set_date */
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 2: set day with set_day */
day = 6;
hildon_date_editor_set_day (date_editor, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 3: set day with set_property */
day = 10;
g_value_init (&value, G_TYPE_UINT);
g_value_set_uint (&value, day);
g_object_set_property (G_OBJECT (date_editor), "day", &value);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
}
END_TEST
/**
* Purpose: test getting a day set over the limits for
* hildon_date_editor_get_day
* Cases considered:
* - Get day 31 for March
* - Get day 30 for June
* - Get day 29 for February for a leap year
* - Get day 28 for February for a common year
* - Get day 1
*/
START_TEST (test_get_day_limits)
{
guint day, month, year;
year = 1981;
month = 3;
day = 31;
/* Test 1: 31 of February */
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: get_day failed. The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 2: 30 of February */
month = 6;
day = 30;
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: get_day failed. The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 3: 29 of February */
year = 1980;
month = 2;
day = 29;
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: get_day failed. The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 3: 28 of February */
year = 1981;
month = 2;
day = 28;
hildon_date_editor_set_date (date_editor, year, month, day);
fail_if (hildon_date_editor_get_day (date_editor) != day,
"hildon-date-editor: get_day failed. The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), day);
/* Test 5: day 1 */
hildon_date_editor_set_day (date_editor, 1);
fail_if (hildon_date_editor_get_day (date_editor) != 1,
"hildon-date-editor: get_day failed. The returned day is %u and should be %u",
hildon_date_editor_get_day (date_editor), 1);
}
END_TEST
/**
* Purpose: test getting a day with invalid attributes for
* hildon_date_editor_get_day
* Cases considered:
* - HildonDateEditor is NULL
* - HildonDateEditor is really a GtkHBox
*/
START_TEST (test_get_day_invalid)
{
guint ret_year;
GtkWidget *aux_object = NULL;
/* Test 1: Test NULL */
ret_year = hildon_date_editor_get_year (NULL);
fail_if (ret_year != 0,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
ret_year, 0);
/* Test 2: another object */
aux_object = gtk_hbox_new (TRUE, 0);
ret_year = hildon_date_editor_get_year ((HildonDateEditor *) aux_object);
fail_if (ret_year != 0,
"hildon-date-editor: get_year failed. The returned year is %u and should be %u",
ret_year, 0);
gtk_widget_destroy (GTK_WIDGET(aux_object));
}
END_TEST
/* ----- Test case for set_day -----*/
/**
* Purpose: test setting a regular value for day for
* hildon_date_editor_get_day
* Cases considered:
* - Set day 30
*/
START_TEST (test_set_day_regular)
{
guint day;
guint ret_day;
day = 25;
/* Test 1: Try day 30 */
hildon_date_editor_set_day (date_editor, day);
ret_day = hildon_date_editor_get_day (date_editor);
fail_if (ret_day != day,
"hildon-date-editor: set_day failed. The returned day is %u and should be %u",
ret_day, day);
}
END_TEST
/**
* Purpose: test seeting a day over the limits for
* hildon_date_editor_get_day
* Cases considered:
* - Set day 31
* - Set day 30
* - Set day 29
* - Set day 28
* - Set day 1
*/
START_TEST (test_set_day_limits)
{
guint day, year, month;
GValue value = { 0, };
year = 1981;
month = 3;
day = 31;
/* Set init date */
hildon_date_editor_set_date (date_editor, year, month, MIN_DAY);
/* Test 1: Test 31/03 */
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_day (date_editor, day);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != day,
"hildon-date-editor: The returned day is %u and should be %u",
g_value_get_uint (&value), day);
/* Test 2: Test 30/06 */
month = 6;
day = 30;
hildon_date_editor_set_date (date_editor, year, month, 1);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_day (date_editor, day);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != day,
"hildon-date-editor: The returned day is %u and should be %u",
g_value_get_uint (&value), day);
/* Test 3: Test 29/02/1980 */
year = 1980;
month = 2;
day = 29;
hildon_date_editor_set_date (date_editor, year, month, 1);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_day (date_editor, day);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != day,
"hildon-date-editor: The returned day is %u and should be %u",
g_value_get_uint (&value), day);
/* Test 4: Test 28/02/1981 */
year = 1981;
month = 2;
day = 28;
hildon_date_editor_set_date (date_editor, year, month, 1);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_day (date_editor, day);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != day,
"hildon-date-editor: The returned day is %u and should be %u",
g_value_get_uint (&value), day);
/* Test 5: Test 1/02/1980 */
year = 1980;
month = 2;
day = 1;
hildon_date_editor_set_date (date_editor, year, month, 10);
g_value_unset (&value);
g_value_init (&value, G_TYPE_UINT);
hildon_date_editor_set_day (date_editor, day);
g_object_get_property (G_OBJECT (date_editor), "day", &value);
fail_if (g_value_get_uint (&value) != day,
"hildon-date-editor: The returned day is %u and should be %u",
g_value_get_uint (&value), day);
}
END_TEST
/* ---------- Suite creation ---------- */
Suite *create_hildon_date_editor_suite(void)
{
/* Create the suite */
Suite *s = suite_create("HildonDateEditor");
/* Create test cases */
TCase *tc1 = tcase_create("set_date");
TCase *tc2 = tcase_create("get_date");
TCase *tc3 = tcase_create("get_year");
TCase *tc4 = tcase_create("set_year");
TCase *tc5 = tcase_create("get_month");
TCase *tc6 = tcase_create("set_month");
TCase *tc7 = tcase_create("get_day");
TCase *tc8 = tcase_create("set_day");
/* Create test case for set_date and add it to the suite */
tcase_add_checked_fixture(tc1, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc1, test_set_date_regular);
tcase_add_test(tc1, test_set_date_limits);
tcase_add_test(tc1, test_set_date_invalid);
suite_add_tcase (s, tc1);
/* Create test case for get_date and add it to the suite */
tcase_add_checked_fixture(tc2, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc2, test_get_date_regular);
tcase_add_test(tc2, test_get_date_invalid);
suite_add_tcase (s, tc2);
/* Create test case for get_year and add it to the suite */
tcase_add_checked_fixture(tc3, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc3, test_get_year_regular);
tcase_add_test(tc3, test_get_year_limits);
tcase_add_test(tc3, test_get_year_invalid);
suite_add_tcase (s, tc3);
/* Create test case for set_year and add it to the suite */
tcase_add_checked_fixture(tc4, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc4, test_set_year_regular);
tcase_add_test(tc4, test_set_year_limits);
suite_add_tcase (s, tc4);
/* Create test case for get_month and add it to the suite */
tcase_add_checked_fixture(tc5, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc5, test_get_month_regular);
tcase_add_test(tc5, test_get_month_limits);
tcase_add_test(tc5, test_get_month_invalid);
suite_add_tcase (s, tc5);
/* Create test case for set_month and add it to the suite */
tcase_add_checked_fixture(tc6, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc6, test_set_month_regular);
tcase_add_test(tc6, test_set_month_limits);
suite_add_tcase (s, tc6);
/* Create test case for get_day and add it to the suite */
tcase_add_checked_fixture(tc7, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc7, test_get_day_regular);
tcase_add_test(tc7, test_get_day_limits);
tcase_add_test(tc7, test_get_day_invalid);
suite_add_tcase (s, tc7);
/* Create test case for set_day and add it to the suite */
tcase_add_checked_fixture(tc8, fx_setup_default_date_editor, fx_teardown_default_date_editor);
tcase_add_test(tc8, test_set_day_regular);
tcase_add_test(tc8, test_set_day_limits);
suite_add_tcase (s, tc8);
/* Return created suite */
return s;
}
|