Increase default value of HildonPannableArea:velocity_max to 2000
[hildon] / tests / check-hildon-time-picker.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 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, or (at your option) any later version.
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 #include <stdlib.h>
25 #include <check.h>
26 #include <gtk/gtkmain.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
29
30 #include <hildon/hildon-window.h>
31 #include <hildon/hildon-time-picker.h>
32
33 /* -------------------- Fixtures -------------------- */
34
35 static HildonTimePicker *time_picker = NULL;
36 static HildonWindow *tp_window = NULL;
37
38 static void
39 fx_setup_default_time_picker ()
40 {
41   int argc = 0;
42   gtk_init(&argc, NULL);
43
44   tp_window = HILDON_WINDOW(hildon_window_new());
45  /* Check window object has been created properly */
46   fail_if(!HILDON_IS_WINDOW(tp_window),
47           "hildon-time-picker: Window creation failed.");
48
49   time_picker = HILDON_TIME_PICKER(hildon_time_picker_new(GTK_WINDOW(tp_window)));
50
51   /* Check time_picker object has been created properly */
52   fail_if(!HILDON_IS_TIME_PICKER(time_picker),
53           "hildon-time-picker: Creation failed.");
54
55   /* Displays the widget and the window */
56   show_all_test_window (GTK_WIDGET (tp_window));
57   show_all_test_window (GTK_WIDGET (time_picker));
58
59 }
60
61 static void
62 fx_teardown_default_time_picker ()
63 {
64   gtk_widget_destroy (GTK_WIDGET (time_picker));
65   gtk_widget_destroy (GTK_WIDGET (tp_window));
66 }
67
68 /* -------------------- Test cases -------------------- */
69
70 /* ----- Test case for set_time -----*/
71
72 /**
73  * Purpose: Check that regular time values are set and get properly
74  * Cases considered:
75  *    - Set and get time to 5h 30m using time picker object.
76  *    - Set and get time to 18h 2m using time picker object.
77  */
78 START_TEST (test_set_time_regular)
79 {
80   guint hours;
81   guint minutes;
82   guint ret_hours;
83   guint ret_minutes;
84     
85   /* Check time_picker object has been created properly */
86   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
87           "hildon-time-picker: Creation failed.");
88
89   /* Test 1: Set and get time to 5h 30m using time picker object. */
90   hours = 5;
91   minutes = 30;
92     
93   hildon_time_picker_set_time(time_picker,hours,minutes);
94   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
95     
96   fail_if (hours != ret_hours || minutes != ret_minutes,
97            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
98            hours, minutes, ret_hours, ret_minutes);
99
100   /* Test 2: Set and get time to 18h 2m using time picker object. */
101   hours = 18;
102   minutes = 2;
103     
104   hildon_time_picker_set_time(time_picker,hours,minutes);
105   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
106
107   fail_if (hours != ret_hours || minutes != ret_minutes,
108            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
109            hours, minutes, ret_hours, ret_minutes);
110 }
111 END_TEST
112
113 /**
114  * Purpose: Check that limit time values are set and get properly       
115  * Cases considered:
116  *    - Set and get time to 0h 0m using time picker object.
117  *    - Set and get time to 0h 59m using time picker object.
118  *    - Set and get time to 12h 59m using time picker object.
119  *    - Set and get time to 23h 59m using time picker object.
120  */
121 START_TEST (test_set_time_limits)
122 {
123   guint hours;
124   guint minutes;
125   guint ret_hours;
126   guint ret_minutes;
127     
128   /* Check time_picker object has been created properly */
129   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
130           "hildon-time-picker: Creation failed.");
131     
132   /* Test 1: Set and get time to 0h 0m using time picker object. */
133   hours = 0;
134   minutes = 0;
135     
136   hildon_time_picker_set_time(time_picker,hours,minutes);
137   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
138
139   fail_if (hours != ret_hours || minutes != ret_minutes,
140            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
141            hours, minutes, ret_hours, ret_minutes);    
142
143   /* Test 2: Set and get time to 0h 59m using time picker object. */
144   hours = 0;
145   minutes = 59;
146     
147   hildon_time_picker_set_time(time_picker,hours,minutes);
148   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
149
150   fail_if (hours != ret_hours || minutes != ret_minutes,
151            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
152            hours, minutes, ret_hours, ret_minutes);
153
154   /* Test 3: Set and get time to 12h 59m using time picker object. */
155   hours = 12;
156   minutes = 59;
157     
158   hildon_time_picker_set_time(time_picker,hours,minutes);
159   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
160
161   fail_if (hours != ret_hours || minutes != ret_minutes,
162            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
163            hours, minutes, ret_hours, ret_minutes);
164
165   /* Test 4: Set and get time to 23h 59m using time picker object. */
166   hours = 23;
167   minutes = 59;
168     
169   hildon_time_picker_set_time(time_picker,hours,minutes);
170   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
171
172   fail_if (hours != ret_hours || minutes != ret_minutes,
173            "hildon-time-picker: Set time (%uh:%um) but returned time is (%uh:%um)",
174            hours, minutes, ret_hours, ret_minutes);   
175 }
176 END_TEST
177
178 /**
179  * Purpose: Check that limit time values are set and get properly       
180  * Cases considered:
181  *    - Set and get time using NULL time picker.
182  *    - Set and get time to 0h 60m using time picker object.
183  *    - Set and get time to 24h 0m using time picker object.
184  *    - Set and get time to 24h 60m using time picker object.
185  *    - Set and get time to 16000h 15533m using time picker object.
186  */
187 START_TEST (test_set_time_invalid)
188 {
189   guint hours;
190   guint minutes;
191   guint ret_hours;
192   guint ret_minutes;
193   guint expected_hours;
194   guint expected_minutes;
195     
196   /* Check time_picker object has been created properly */
197   fail_if(!HILDON_IS_TIME_PICKER(time_picker), 
198           "hildon-time-picker: Creation failed.");
199
200   hours = 0;
201   minutes = 60;
202   expected_hours=1;
203   expected_minutes=0;
204
205   /* Test 1: Set and get time using NULL time picker */
206   hildon_time_picker_set_time(NULL,hours,minutes);
207   hildon_time_picker_get_time(NULL,&ret_hours,&ret_minutes);
208
209   /* Test 2: Set and get time to 0h 60m using time picker object. */   
210   hildon_time_picker_set_time(time_picker,hours,minutes);
211   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
212
213   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
214            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
215            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
216
217   /* Test 3: Set and get time to 24h 0m using time picker object. */   
218   hours = 24;
219   minutes = 0;
220   expected_hours=0;
221   expected_minutes=0;
222     
223   hildon_time_picker_set_time(time_picker,hours,minutes);
224   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
225
226   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
227            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
228            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
229
230   /* Test 4: Set and get time to 24h 60m using time picker object. */
231   hours = 24;
232   minutes = 60;
233   expected_hours=1;
234   expected_minutes=0;
235     
236   hildon_time_picker_set_time(time_picker,hours,minutes);
237   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
238
239   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
240            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
241            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);   
242
243   /* Test 5: Set and get time to 16000h 15533m using time picker object.*/
244   hours = 16000;
245   minutes = 15533;
246   expected_hours=10;
247   expected_minutes=53;
248     
249   hildon_time_picker_set_time(time_picker,hours,minutes);
250   hildon_time_picker_get_time(time_picker,&ret_hours,&ret_minutes);
251
252   fail_if (expected_hours != ret_hours || expected_minutes != ret_minutes,
253            "hildon-time-picker: Set time (%uh:%um), expected time is (%uh:%um) but returned time is (%uh:%um)",
254            hours, minutes, expected_hours, expected_minutes, ret_hours, ret_minutes);    
255 }
256 END_TEST
257
258 /* ---------- Suite creation ---------- */
259
260 Suite *create_hildon_time_picker_suite()
261 {
262   /* Create the suite */
263   Suite *s = suite_create("HildonTimePicker");
264
265   /* Create test cases */
266   TCase *tc1 = tcase_create("set_time");
267
268   /* Create test case for hildon_time_picker_set_time and add it to the suite */
269   tcase_add_checked_fixture(tc1, fx_setup_default_time_picker, fx_teardown_default_time_picker);
270   tcase_add_test(tc1, test_set_time_regular);
271   tcase_add_test(tc1, test_set_time_limits);
272   tcase_add_test(tc1, test_set_time_invalid);
273   suite_add_tcase(s, tc1);
274
275   /* Return created suite */
276   return s;             
277 }