2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
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.
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.
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
26 #include <gtk/gtkmain.h>
27 #include "test_suites.h"
28 #include "check_utils.h"
29 #include "hildon-get-password-dialog.h"
31 /* -------------------- Fixtures -------------------- */
33 static HildonGetPasswordDialog *get_password_dialog = NULL;
34 static GtkWindow * gpd_window = NULL;
37 fx_setup_default_get_password_dialog ()
41 gtk_init(&argc, NULL);
43 gpd_window = GTK_WINDOW(create_test_window());
45 /* Check the auxiliary window is being created properly */
46 fail_if (!GTK_IS_WINDOW (gpd_window),
47 "hildon-get-password-dialog: Window creation failed.");
49 get_password_dialog = HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new(gpd_window, TRUE));
50 /* Check get password dialog object has been created properly */
51 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
52 "hildon-get-password-dialog: Creation failed.");
54 show_test_window(GTK_WIDGET(gpd_window));
56 show_test_window(GTK_WIDGET(get_password_dialog));
61 fx_teardown_default_get_password_dialog ()
63 gtk_widget_destroy(GTK_WIDGET(get_password_dialog));
65 gtk_widget_destroy(GTK_WIDGET(gpd_window));
68 /* -------------------- Test cases -------------------- */
70 /* ----- Test case for hildon_get_password_dialog_new_with_default -----*/
73 * Purpose: Check that regular password values are set and get properly.
75 * - Create new get password dialog with "test_password" password by default.
76 * - Create new get password dialog with "" password by default.
77 * - Create new get password dialog with "1234567890" password by default.
78 * - Create new get password dialog with TEST_STRING password by default
80 START_TEST (test_new_with_default_regular)
82 const gchar * default_password=NULL;
83 const gchar * ret_password;
84 HildonGetPasswordDialog * default_get_password_dialog;
86 /* Test 1: Create new dialog with password "test_password" by default */
87 default_password="test_password";
88 default_get_password_dialog =
89 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
90 fail_if (!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
91 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
93 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
94 fail_if (strcmp (default_password,ret_password) != 0,
95 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
96 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
98 /* Test 2: Create new dialog with password "" by default */
100 default_get_password_dialog =
101 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
102 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
103 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
105 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
106 fail_if (strcmp (default_password,ret_password) != 0,
107 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
109 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
111 /* Test 3: Create new dialog with password "1234567890" by default */
112 default_password="1234567890";
114 default_get_password_dialog =
115 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
116 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
117 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
119 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
120 fail_if(strcmp (default_password,ret_password)!=0,
121 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
123 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
125 /* Test 4: Create new dialog with password TEST_STRING by default */
126 default_password=TEST_STRING;
128 default_get_password_dialog =
129 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
130 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
131 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
133 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
134 fail_if (strcmp (default_password,ret_password) != 0,
135 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
137 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
142 * Purpose: Check that invalid password values are set and get properly.
144 * - Create new NULL get password dialog.
145 * - Create new dialog with NULL window by default
147 START_TEST (test_new_with_default_invalid)
149 const gchar * default_password="";
150 const gchar * ret_password;
151 HildonGetPasswordDialog * default_get_password_dialog;
153 /* Check get password dialog object has been created properly */
154 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
155 "hildon-get-password-dialog: Creation failed.");
156 fail_if (!GTK_IS_WINDOW (gpd_window),
157 "hildon-get-password-dialog: Window creation failed.");
159 /* Test 1: Create new dialog with NULL password by default */
160 default_password=NULL;
161 default_get_password_dialog =
162 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
163 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
164 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
166 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
167 fail_if(strcmp ("",ret_password) != 0,
168 "hildon-get-password-dialog: Error setting null password. Returned password is \"%s\"",ret_password);
170 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
172 /* Test 2: Create new dialog with NULL window by default */
173 default_get_password_dialog =
174 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(NULL,default_password,FALSE));
175 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
176 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
178 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
179 fail_if (ret_password == NULL,
180 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
182 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
187 * Purpose: Check that regular "max characters" values are set and get properly.
189 * - Set max characters to 10.
190 * - Set max characters to G_MAXUINT16+1.
193 START_TEST (test_set_max_characters_regular)
199 /* Check get password dialog object has been created properly */
200 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
201 "hildon-get-password-dialog: Creation failed.");
202 fail_if (!GTK_IS_WINDOW (gpd_window),
203 "hildon-get-password-dialog: Window creation failed.");
205 g_value_init (&value, G_TYPE_INT);
207 /* Test 1: Set max characters to 10 */
209 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
210 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
211 ret_max_chars = g_value_get_int (&value);
213 fail_if(ret_max_chars!=max_chars,
214 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
216 g_value_unset (&value);
218 /* Test 2: Set max characters to G_MAXUINT16+1 */
219 g_value_init (&value, G_TYPE_INT);
220 max_chars = G_MAXUINT16+1;
221 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
222 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
223 ret_max_chars = g_value_get_int (&value);
225 fail_if(ret_max_chars!=G_MAXUINT16,
226 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
228 g_value_unset (&value);
233 * Purpose: Check that limits "max characters" values are set and get properly.
235 * - Set max characters to 1.
236 * - Set max characters to G_MAXINT.
238 START_TEST (test_set_max_characters_limits)
244 /* Check get password dialog object has been created properly */
245 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
246 "hildon-get-password-dialog: Creation failed.");
247 fail_if (!GTK_IS_WINDOW (gpd_window),
248 "hildon-get-password-dialog: Window creation failed.");
250 g_value_init (&value, G_TYPE_INT);
252 /* Test 1: Set max characters to 1 */
254 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
255 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
256 ret_max_chars = g_value_get_int (&value);
258 fail_if(ret_max_chars!=max_chars,
259 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
261 g_value_unset (&value);
263 /* Test 2: Set max characters to G_MAXINT */
264 g_value_init (&value, G_TYPE_INT);
265 max_chars = G_MAXINT;
266 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
267 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
268 ret_max_chars = g_value_get_int (&value);
270 fail_if(ret_max_chars!=G_MAXUINT16,
271 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %u",max_chars,ret_max_chars);
273 g_value_unset (&value);
278 * Purpose: Check that limits "max characters" values are set and get properly.
280 * - Set max characters to 0.
281 * - Set max characters to -1.
282 * - Set max characters on NULL object.
284 START_TEST (test_set_max_characters_invalid)
290 /* Check get password dialog object has been created properly */
291 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
292 "hildon-get-password-dialog: Creation failed.");
293 fail_if (!GTK_IS_WINDOW (gpd_window),
294 "hildon-get-password-dialog: Window creation failed.");
296 g_value_init (&value, G_TYPE_INT);
298 /* Test 1: Set max characters to 0 */
300 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
301 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
302 ret_max_chars = g_value_get_int (&value);
304 fail_if(ret_max_chars!=max_chars,
305 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
307 g_value_unset (&value);
309 /* Test 2: Set max characters to -1 */
310 g_value_init (&value, G_TYPE_INT);
312 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
313 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
314 ret_max_chars = g_value_get_int (&value);
316 fail_if(ret_max_chars!=0,
317 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i and expected is 0",max_chars,ret_max_chars);
318 g_value_unset (&value);
320 /* Test 2: Set max characters on NULL object */
322 hildon_get_password_dialog_set_max_characters(NULL,max_chars);
327 * Purpose: Check that regular password values are get properly.
329 * - Get password "test_password" set by g_object_set_property.
330 * - Get password "01234567890" set by g_object_set_property.
331 * - Get password TEST_STRING set by g_object_set_property.
332 * - Get password "" set by set by g_object_set_property.
334 START_TEST (test_get_password_regular)
336 const gchar * default_password="test_password";
337 const gchar * ret_password;
340 /* Check get password dialog object has been created properly */
341 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
342 "hildon-get-password-dialog: Creation failed.");
343 fail_if (!GTK_IS_WINDOW (gpd_window),
344 "hildon-get-password-dialog: Window creation failed.");
346 /* Test 1: Get password "test_password" set by g_object_set_property. */
347 g_value_init (&value, G_TYPE_STRING);
348 g_value_set_string(&value,default_password);
349 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
350 g_value_unset (&value);
352 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
353 fail_if(strcmp (default_password,ret_password)!=0,
354 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
356 /* Test 2: Get password "01234567890" set by g_object_set_property. */
357 default_password = "01234567890";
359 g_value_init (&value, G_TYPE_STRING);
360 g_value_set_string(&value,default_password);
361 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
362 g_value_unset (&value);
364 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
365 fail_if(strcmp (default_password,ret_password)!=0,
366 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
368 /* Test 3: Get password TEST_STRING set by g_object_set_property. */
369 default_password = TEST_STRING;
371 g_value_init (&value, G_TYPE_STRING);
372 g_value_set_string(&value,default_password);
373 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
374 g_value_unset (&value);
376 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
377 fail_if(strcmp (default_password,ret_password)!=0,
378 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
380 /* Test 4: Get password "" set by g_object_set_property. */
381 default_password = "";
383 g_value_init (&value, G_TYPE_STRING);
384 g_value_set_string(&value,default_password);
385 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
386 g_value_unset (&value);
388 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
389 fail_if(strcmp (default_password,ret_password)!=0,
390 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
395 * Purpose: Check that limit password values are get properly.
397 * - Get empty password set by g_object_set_property with NULL value.
398 * - Get password from NULL object.
401 START_TEST (test_get_password_invalid)
403 const gchar * default_password=NULL;
404 const gchar * ret_password;
407 /* Check get password dialog object has been created properly */
408 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
409 "hildon-get-password-dialog: Creation failed.");
410 fail_if (!GTK_IS_WINDOW (gpd_window),
411 "hildon-get-password-dialog: Window creation failed.");
413 /* Test 1: Get password NULL set by g_object_set_property. */
414 default_password = NULL;
415 g_value_init (&value, G_TYPE_STRING);
416 g_value_set_string(&value,default_password);
417 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
418 g_value_unset (&value);
420 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
421 fail_if(strcmp(ret_password,"")!=0,
422 "hildon-get-password-dialog: Returned password is not empty (%s)",ret_password);
424 /* Test 2: Get password from NULL object. */
425 ret_password = hildon_get_password_dialog_get_password(NULL);
430 /* ---------- Suite creation ---------- */
431 Suite *create_hildon_get_password_dialog_suite()
433 /* Create the suite */
434 Suite *s = suite_create("HildonGetPasswordDialog");
436 /* Create test cases */
437 TCase *tc1 = tcase_create("new_with_default");
438 TCase *tc2 = tcase_create("set_max_characters");
439 TCase *tc3 = tcase_create("get_password");
441 /* Create test case for hildon_get_password_dialog_new_with_default and add it to the suite */
442 tcase_add_checked_fixture(tc1, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
443 tcase_add_test(tc1, test_new_with_default_regular);
444 tcase_add_test(tc1, test_new_with_default_invalid);
445 suite_add_tcase (s, tc1);
447 /* Create test case for hildon_get_password_dialog_set_max_characters and add it to the suite */
448 tcase_add_checked_fixture(tc2, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
449 tcase_add_test(tc2, test_set_max_characters_regular);
450 tcase_add_test(tc2, test_set_max_characters_limits);
451 tcase_add_test(tc2, test_set_max_characters_invalid);
452 suite_add_tcase (s, tc2);
454 /* Create test case for hildon_get_password_dialog_get_password and add it to the suite */
455 tcase_add_checked_fixture(tc3, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
456 tcase_add_test(tc3, test_get_password_regular);
457 tcase_add_test(tc3, test_get_password_invalid);
458 suite_add_tcase (s, tc3);
461 /* Return created suite */