Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-time-picker.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdlib.h>
24 #include <check.h>
25 #include <gtk/gtkmain.h>
26 #include "test_suites.h"
27 #include "check_utils.h"
28
29 #include "hildon-window.h"
30 #include "hildon-time-picker.h"
31
32 /* -------------------- Fixtures -------------------- */
33
34 static HildonTimePicker *time_picker = NULL;
35 static HildonWindow *tp_window = NULL;
36
37 static void
38 fx_setup_default_time_picker ()
39 {
40   int argc = 0;
41   gtk_init(&argc, NULL);
42
43   tp_window = HILDON_WINDOW(hildon_window_new());
44  /* Check window object has been created properly */
45   fail_if(!HILDON_IS_WINDOW(tp_window),
46           "hildon-time-picker: Window creation failed.");
47
48   time_picker = HILDON_TIME_PICKER(hildon_time_picker_new(GTK_WINDOW(tp_window)));
49
50   /* Check time_picker object has been created properly */
51   fail_if(!HILDON_IS_TIME_PICKER(time_picker),
52           "hildon-time-picker: Creation failed.");
53
54   /* Displays the widget and the window */
55   show_all_test_window (GTK_WIDGET (tp_window));
56   show_all_test_window (GTK_WIDGET (time_picker));
57
58 }
59
60 static void
61 fx_teardown_default_time_picker ()
62 {
63   gtk_widget_destroy (GTK_WIDGET (time_picker));
64   gtk_widget_destroy (GTK_WIDGET (tp_window));
65 }
66
67 /* -------------------- Test cases -------------------- */
68
69 /* ----- Test case for set_time -----*/
70
71 /**
72  * Purpose: Check that regular time values are set and get properly
73  * Cases considered:
74  *    - Set and get time to 5h 30m using time picker object.
75  *    - Set and get time to 18h 2m using time picker object.
76  */
77 START_TEST (test_set_time_regular)
78 {
79   guint hours;
80   guint minutes;
81   guint ret_hours;
82   guint ret_minutes;
83     
84   /* Check time_picker object has been created properly */
85   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
86           "hildon-time-picker: Creation failed.");
87
88   /* Test 1: Set and get time to 5h 30m using time picker object. */
89   hours = 5;
90   minutes = 30;
91     
92   hildon_time_picker_set_time(time_picker,hours,minutes);
93   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
94     
95   fail_if (hours != ret_hours || minutes != ret_minutes,
96            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
97            hours, minutes, ret_hours, ret_minutes);
98
99   /* Test 2: Set and get time to 18h 2m using time picker object. */
100   hours = 18;
101   minutes = 2;
102     
103   hildon_time_picker_set_time(time_picker,hours,minutes);
104   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
105
106   fail_if (hours != ret_hours || minutes != ret_minutes,
107            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
108            hours, minutes, ret_hours, ret_minutes);
109 }
110 END_TEST
111
112 /**
113  * Purpose: Check that limit time values are set and get properly       
114  * Cases considered:
115  *    - Set and get time to 0h 0m using time picker object.
116  *    - Set and get time to 0h 59m using time picker object.
117  *    - Set and get time to 12h 59m using time picker object.
118  *    - Set and get time to 23h 59m using time picker object.
119  */
120 START_TEST (test_set_time_limits)
121 {
122   guint hours;
123   guint minutes;
124   guint ret_hours;
125   guint ret_minutes;
126     
127   /* Check time_picker object has been created properly */
128   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
129           "hildon-time-picker: Creation failed.");
130     
131   /* Test 1: Set and get time to 0h 0m using time picker object. */
132   hours = 0;
133   minutes = 0;
134     
135   hildon_time_picker_set_time(time_picker,hours,minutes);
136   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
137
138   fail_if (hours != ret_hours || minutes != ret_minutes,
139            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
140            hours, minutes, ret_hours, ret_minutes);    
141
142   /* Test 2: Set and get time to 0h 59m using time picker object. */
143   hours = 0;
144   minutes = 59;
145     
146   hildon_time_picker_set_time(time_picker,hours,minutes);
147   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
148
149   fail_if (hours != ret_hours || minutes != ret_minutes,
150            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
151            hours, minutes, ret_hours, ret_minutes);
152
153   /* Test 3: Set and get time to 12h 59m using time picker object. */
154   hours = 12;
155   minutes = 59;
156     
157   hildon_time_picker_set_time(time_picker,hours,minutes);
158   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
159
160   fail_if (hours != ret_hours || minutes != ret_minutes,
161            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
162            hours, minutes, ret_hours, ret_minutes);
163
164   /* Test 4: Set and get time to 23h 59m using time picker object. */
165   hours = 23;
166   minutes = 59;
167     
168   hildon_time_picker_set_time(time_picker,hours,minutes);
169   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
170
171   fail_if (hours != ret_hours || minutes != ret_minutes,
172            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
173            hours, minutes, ret_hours, ret_minutes);   
174 }
175 END_TEST
176
177 /**
178  * Purpose: Check that limit time values are set and get properly       
179  * Cases considered:
180  *    - Set and get time using NULL time picker.
181  *    - Set and get time to 0h 60m using time picker object.
182  *    - Set and get time to 24h 0m using time picker object.
183  *    - Set and get time to 24h 60m using time picker object.
184  *    - Set and get time to 16000h 15533m using time picker object.
185  */
186 START_TEST (test_set_time_invalid)
187 {
188   guint hours;
189   guint minutes;
190   guint ret_hours;
191   guint ret_minutes;
192   guint expected_hours;
193   guint expected_minutes;
194     
195   /* Check time_picker object has been created properly */
196   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
197           "hildon-time-picker: Creation failed.");
198
199   hours = 0;
200   minutes = 60;
201   expected_hours=1;
202   expected_minutes=0;
203
204   /* Test 1: Set and get time using NULL time picker */
205   hildon_time_picker_set_time(NULL,hours,minutes);
206   hildon_time_picker_get_time(NULL,&ret_hours,&ret_minutes);
207
208   /* Test 2: Set and get time to 0h 60m using time picker object. */   
209   hildon_time_picker_set_time(time_picker,hours,minutes);
210   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
211
212   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
213            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
214            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
215
216   /* Test 3: Set and get time to 24h 0m using time picker object. */   
217   hours = 24;
218   minutes = 0;
219   expected_hours=0;
220   expected_minutes=0;
221     
222   hildon_time_picker_set_time(time_picker,hours,minutes);
223   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
224
225   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
226            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
227            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
228
229   /* Test 4: Set and get time to 24h 60m using time picker object. */
230   hours = 24;
231   minutes = 60;
232   expected_hours=1;
233   expected_minutes=0;
234     
235   hildon_time_picker_set_time(time_picker,hours,minutes);
236   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
237
238   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
239            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
240            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
241
242   /* Test 5: Set and get time to 16000h 15533m using time picker object.*/
243   hours = 16000;
244   minutes = 15533;
245   expected_hours=10;
246   expected_minutes=53;
247     
248   hildon_time_picker_set_time(time_picker,hours,minutes);
249   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
250
251   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
252            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
253            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);    
254 }
255 END_TEST
256
257 /* ---------- Suite creation ---------- */
258
259 Suite *create_hildon_time_picker_suite()
260 {
261   /* Create the suite */
262   Suite *s = suite_create("HildonTimePicker");
263
264   /* Create test cases */
265   TCase *tc1 = tcase_create("set_time");
266
267   /* Create test case for hildon_time_picker_set_time and add it to the suite */
268   tcase_add_checked_fixture(tc1, fx_setup_default_time_picker, fx_teardown_default_time_picker);
269   tcase_add_test(tc1, test_set_time_regular);
270   tcase_add_test(tc1, test_set_time_limits);
271   tcase_add_test(tc1, test_set_time_invalid);
272   suite_add_tcase(s, tc1);
273
274   /* Return created suite */
275   return s;             
276 }