Make sure that all timeouts in HildonBanner are removed
[hildon] / tests / check-hildon-set-password-dialog.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
25 #include <stdlib.h>
26 #include <string.h>
27 #include <check.h>
28 #include <gtk/gtkmain.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
31
32 #include <hildon/hildon-set-password-dialog.h>
33 #include <hildon/hildon-window.h>
34
35 /* -------------------- Fixtures -------------------- */
36
37 static HildonSetPasswordDialog *set_password_dialog = NULL;
38 static GtkWindow *spd_window=NULL;
39
40 static void 
41 fx_setup_default_set_password_dialog ()
42 {
43   int argc = 0;
44     
45   gtk_init(&argc, NULL);
46   spd_window = GTK_WINDOW(create_test_window());
47
48   /* Check window object has been created properly */
49   fail_if(!HILDON_IS_WINDOW(spd_window),
50           "hildon-set_password_dialog: Window creation failed.");
51
52   set_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, TRUE));    
53
54   /* Check that the set password dialog object has been created properly */
55   fail_if(!HILDON_SET_PASSWORD_DIALOG(set_password_dialog),
56           "hildon-set_password_dialog: Creation failed.");
57
58   show_test_window(GTK_WIDGET(spd_window));
59
60   show_test_window(GTK_WIDGET(set_password_dialog));
61
62 }
63
64 static void 
65 fx_teardown_default_set_password_dialog ()
66 {
67
68   gtk_widget_destroy (GTK_WIDGET (set_password_dialog));
69
70   gtk_widget_destroy (GTK_WIDGET (spd_window));
71
72 }
73
74 /* -------------------- Test cases -------------------- */
75
76 /* ----- Test case for get_protected -----*/
77
78 /**
79  * Purpose: Check that regular values are get properly.
80  * Cases considered:
81  *    - Get TRUE from modify_protection property.
82  *    - Get FALSE from modify_protection property.
83  *
84  */
85 START_TEST (test_get_protected_regular)
86 {
87   gboolean ret_protected;
88   HildonSetPasswordDialog *protected_test_password_dialog = NULL;
89
90   /* I must create one dialog for each value of protected boolean because is a G_PARAM_CONSTRUCT_ONLY property */
91   protected_test_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, TRUE));
92     
93   /* Test 1: Get TRUE from modify_protection property. */
94   ret_protected = hildon_set_password_dialog_get_protected(set_password_dialog);
95   fail_if(ret_protected!=TRUE,
96           "hildon-set_password_dialog: modify_protection must be TRUE, but hildon_set_password_dialog_get_protected returns FALSE");
97
98   gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog));
99
100   /* Test 2: Get FALSE from modify_protection property */
101   /* I must create one dialog for each value of protected boolean because is a G_PARAM_CONSTRUCT_ONLY property */
102   protected_test_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, FALSE));
103
104   ret_protected = hildon_set_password_dialog_get_protected(protected_test_password_dialog);
105   fail_if(ret_protected!=FALSE,
106           "hildon-set_password_dialog: modify_protection must be FALSE, but hildon_set_password_dialog_get_protected returns TRUE");
107     
108   gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog));
109 }
110 END_TEST
111
112 /**
113  * Purpose: Check that invalid values are get properly.
114  * Cases considered:
115  *    - Get modify_protection from NULL object.
116  *
117  */
118 START_TEST (test_get_protected_invalid)
119 {
120   gboolean ret_protected;
121
122   ret_protected = hildon_set_password_dialog_get_protected (NULL);
123   fail_if (ret_protected != FALSE,
124            "hildon-set_password_dialog: modify_protection must be FALSE, but hildon_set_password_dialog_get_protected return TRUE");
125 }
126 END_TEST
127
128 /* ----- Test case for get_password -----*/
129
130 /**
131  * Purpose: Check that regular values are get properly.
132  * Cases considered:
133  *    - Get password "test_password" from HildonSetPasswordDialog created with "test_password" by default.
134  *    - Get password "" from HildonSetPasswordDialog created with "" by default.
135  *    - Get password TEST_STRING from HildonSetPasswordDialog created with TEST_STRING by default.
136  */
137 START_TEST (test_get_password_regular)
138 {
139   const gchar * default_password=NULL;
140   const gchar * ret_password;
141   HildonSetPasswordDialog * default_set_password_dialog;
142     
143
144   /* Test 1: Get password "test_password" from HildonSetPasswordDialog created with "test_password" by default. */
145   default_password = "test_password";
146   default_set_password_dialog = 
147     HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE));
148   fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog),
149           "hildon-set_password_dialog: hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default");
150
151   ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog);   
152   fail_if(strcmp (default_password,ret_password)!=0,
153           "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password);
154
155   gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));    
156
157   /* Test 2: Create new dialog with password "" by default */
158   default_password = "";
159   default_set_password_dialog = 
160     HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE));
161   fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog),
162           "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default");
163
164   ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog);   
165   fail_if(strcmp (default_password,ret_password)!=0,
166           "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password);
167
168   gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));        
169
170   /* Test 3: Create new dialog with password TEST_STRING by default */
171   default_password = TEST_STRING;
172   default_set_password_dialog = 
173     HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,default_password,FALSE));
174   fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog),
175           "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default");
176
177   ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog);
178   fail_if(strcmp (default_password,ret_password)!=0,
179           "hildon-set_password_dialog: default password and returned password are diferent (%s,%s)",default_password,ret_password);
180     
181   gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
182     
183 }
184 END_TEST
185
186 /**
187  * Purpose: Check that regular values are get properly.
188  * Cases considered:
189  *    - Get empty password from HildonSetPasswordDialog created with NULL password by default.
190  *    - Get password from NULL object.
191  */
192 START_TEST (test_get_password_invalid)
193 {
194   const gchar * ret_password;
195   HildonSetPasswordDialog * default_set_password_dialog;
196     
197
198   /* Test 1: Get empty password from HildonSetPasswordDialog created with NULL password by default */
199   default_set_password_dialog = 
200     HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new_with_default(spd_window,NULL,FALSE));
201   fail_if(!HILDON_IS_SET_PASSWORD_DIALOG(default_set_password_dialog),
202           "hildon-set-password-dialog: Creation failed with hildon_set_password_dialog_new_with_default");
203
204   ret_password = hildon_set_password_dialog_get_password(default_set_password_dialog);
205   fail_if(strcmp(ret_password,"")!=0,
206           "hildon-set_password_dialog: returned password is not empty");
207     
208   gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
209
210   /* Test 2: Get password from NULL object */
211   ret_password = hildon_set_password_dialog_get_password(NULL);
212
213   fail_if(ret_password!=NULL,
214           "hildon-set_password_dialog: returned password is not null");
215     
216 }
217 END_TEST
218
219 /* ---------- Suite creation ---------- */
220
221 Suite *create_hildon_set_password_dialog_suite()
222 {
223   /* Create the suite */
224   Suite *s = suite_create("HildonSetPasswordDialog");
225
226   /* Create test cases */
227   TCase *tc1 = tcase_create("get_protected");
228   TCase *tc2 = tcase_create("get_password");
229
230   /* Create test case for hildon_set_password_dialog_get_protected and add it to the suite */
231   tcase_add_checked_fixture(tc1, fx_setup_default_set_password_dialog, fx_teardown_default_set_password_dialog);
232   tcase_add_test(tc1, test_get_protected_regular);
233   tcase_add_test(tc1, test_get_protected_invalid);
234   suite_add_tcase (s, tc1);
235
236   /* Create test case for hildon_set_password_dialog_get_password and add it to the suite */
237   tcase_add_checked_fixture(tc2, fx_setup_default_set_password_dialog, fx_teardown_default_set_password_dialog);
238   tcase_add_test(tc2, test_get_password_regular);
239   tcase_add_test(tc2, test_get_password_invalid);
240   suite_add_tcase (s, tc2);
241
242   /* Return created suite */
243   return s;             
244 }