2 * This file is a part of hildon tests
4 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
6 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
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.
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.
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
28 #include <gtk/gtkmain.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
31 #include "hildon-get-password-dialog.h"
33 /* -------------------- Fixtures -------------------- */
35 static HildonGetPasswordDialog *get_password_dialog = NULL;
36 static GtkWindow * gpd_window = NULL;
39 fx_setup_default_get_password_dialog ()
43 gtk_init(&argc, NULL);
45 gpd_window = GTK_WINDOW(create_test_window());
47 /* Check the auxiliary window is being created properly */
48 fail_if (!GTK_IS_WINDOW (gpd_window),
49 "hildon-get-password-dialog: Window creation failed.");
51 get_password_dialog = HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new(gpd_window, TRUE));
52 /* Check get password dialog object has been created properly */
53 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
54 "hildon-get-password-dialog: Creation failed.");
56 show_test_window(GTK_WIDGET(gpd_window));
58 show_test_window(GTK_WIDGET(get_password_dialog));
63 fx_teardown_default_get_password_dialog ()
65 gtk_widget_destroy(GTK_WIDGET(get_password_dialog));
67 gtk_widget_destroy(GTK_WIDGET(gpd_window));
70 /* -------------------- Test cases -------------------- */
72 /* ----- Test case for hildon_get_password_dialog_new_with_default -----*/
75 * Purpose: Check that regular password values are set and get properly.
77 * - Create new get password dialog with "test_password" password by default.
78 * - Create new get password dialog with "" password by default.
79 * - Create new get password dialog with "1234567890" password by default.
80 * - Create new get password dialog with TEST_STRING password by default
82 START_TEST (test_new_with_default_regular)
84 const gchar * default_password=NULL;
85 const gchar * ret_password;
86 HildonGetPasswordDialog * default_get_password_dialog;
88 /* Test 1: Create new dialog with password "test_password" by default */
89 default_password="test_password";
90 default_get_password_dialog =
91 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
92 fail_if (!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
93 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
95 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
96 fail_if (strcmp (default_password,ret_password) != 0,
97 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
98 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
100 /* Test 2: Create new dialog with password "" by default */
102 default_get_password_dialog =
103 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
104 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
105 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
107 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
108 fail_if (strcmp (default_password,ret_password) != 0,
109 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
111 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
113 /* Test 3: Create new dialog with password "1234567890" by default */
114 default_password="1234567890";
116 default_get_password_dialog =
117 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
118 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
119 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
121 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
122 fail_if(strcmp (default_password,ret_password)!=0,
123 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
125 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
127 /* Test 4: Create new dialog with password TEST_STRING by default */
128 default_password=TEST_STRING;
130 default_get_password_dialog =
131 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
132 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
133 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
135 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
136 fail_if (strcmp (default_password,ret_password) != 0,
137 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
139 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
144 * Purpose: Check that invalid password values are set and get properly.
146 * - Create new NULL get password dialog.
147 * - Create new dialog with NULL window by default
149 START_TEST (test_new_with_default_invalid)
151 const gchar * default_password="";
152 const gchar * ret_password;
153 HildonGetPasswordDialog * default_get_password_dialog;
155 /* Check get password dialog object has been created properly */
156 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
157 "hildon-get-password-dialog: Creation failed.");
158 fail_if (!GTK_IS_WINDOW (gpd_window),
159 "hildon-get-password-dialog: Window creation failed.");
161 /* Test 1: Create new dialog with NULL password by default */
162 default_password=NULL;
163 default_get_password_dialog =
164 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(gpd_window,default_password,FALSE));
165 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
166 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
168 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
169 fail_if(strcmp ("",ret_password) != 0,
170 "hildon-get-password-dialog: Error setting null password. Returned password is \"%s\"",ret_password);
172 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
174 /* Test 2: Create new dialog with NULL window by default */
175 default_get_password_dialog =
176 HILDON_GET_PASSWORD_DIALOG(hildon_get_password_dialog_new_with_default(NULL,default_password,FALSE));
177 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG(default_get_password_dialog),
178 "hildon-get-password-dialog: Creation failed with hildon_get_password_dialog_new_with_default");
180 ret_password = hildon_get_password_dialog_get_password(default_get_password_dialog);
181 fail_if (ret_password == NULL,
182 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
184 gtk_widget_destroy(GTK_WIDGET(default_get_password_dialog));
189 * Purpose: Check that regular "max characters" values are set and get properly.
191 * - Set max characters to 10.
192 * - Set max characters to G_MAXUINT16+1.
195 START_TEST (test_set_max_characters_regular)
201 /* Check get password dialog object has been created properly */
202 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
203 "hildon-get-password-dialog: Creation failed.");
204 fail_if (!GTK_IS_WINDOW (gpd_window),
205 "hildon-get-password-dialog: Window creation failed.");
207 g_value_init (&value, G_TYPE_INT);
209 /* Test 1: Set max characters to 10 */
211 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
212 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
213 ret_max_chars = g_value_get_int (&value);
215 fail_if(ret_max_chars!=max_chars,
216 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
218 g_value_unset (&value);
220 /* Test 2: Set max characters to G_MAXUINT16+1 */
221 g_value_init (&value, G_TYPE_INT);
222 max_chars = G_MAXUINT16+1;
223 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
224 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
225 ret_max_chars = g_value_get_int (&value);
227 fail_if(ret_max_chars!=G_MAXUINT16,
228 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
230 g_value_unset (&value);
235 * Purpose: Check that limits "max characters" values are set and get properly.
237 * - Set max characters to 1.
238 * - Set max characters to G_MAXINT.
240 START_TEST (test_set_max_characters_limits)
246 /* Check get password dialog object has been created properly */
247 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
248 "hildon-get-password-dialog: Creation failed.");
249 fail_if (!GTK_IS_WINDOW (gpd_window),
250 "hildon-get-password-dialog: Window creation failed.");
252 g_value_init (&value, G_TYPE_INT);
254 /* Test 1: Set max characters to 1 */
256 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
257 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
258 ret_max_chars = g_value_get_int (&value);
260 fail_if(ret_max_chars!=max_chars,
261 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
263 g_value_unset (&value);
265 /* Test 2: Set max characters to G_MAXINT */
266 g_value_init (&value, G_TYPE_INT);
267 max_chars = G_MAXINT;
268 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
269 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
270 ret_max_chars = g_value_get_int (&value);
272 fail_if(ret_max_chars!=G_MAXUINT16,
273 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %u",max_chars,ret_max_chars);
275 g_value_unset (&value);
280 * Purpose: Check that limits "max characters" values are set and get properly.
282 * - Set max characters to 0.
283 * - Set max characters to -1.
284 * - Set max characters on NULL object.
286 START_TEST (test_set_max_characters_invalid)
292 /* Check get password dialog object has been created properly */
293 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
294 "hildon-get-password-dialog: Creation failed.");
295 fail_if (!GTK_IS_WINDOW (gpd_window),
296 "hildon-get-password-dialog: Window creation failed.");
298 g_value_init (&value, G_TYPE_INT);
300 /* Test 1: Set max characters to 0 */
302 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
303 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
304 ret_max_chars = g_value_get_int (&value);
306 fail_if(ret_max_chars!=max_chars,
307 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i",max_chars,ret_max_chars);
309 g_value_unset (&value);
311 /* Test 2: Set max characters to -1 */
312 g_value_init (&value, G_TYPE_INT);
314 hildon_get_password_dialog_set_max_characters(get_password_dialog,max_chars);
315 g_object_get_property(G_OBJECT (get_password_dialog),"max-characters",&value);
316 ret_max_chars = g_value_get_int (&value);
318 fail_if(ret_max_chars!=0,
319 "hildon-get-password-dialog: Set %i max chars incorrect. Return value is %i and expected is 0",max_chars,ret_max_chars);
320 g_value_unset (&value);
322 /* Test 2: Set max characters on NULL object */
324 hildon_get_password_dialog_set_max_characters(NULL,max_chars);
329 * Purpose: Check that regular password values are get properly.
331 * - Get password "test_password" set by g_object_set_property.
332 * - Get password "01234567890" set by g_object_set_property.
333 * - Get password TEST_STRING set by g_object_set_property.
334 * - Get password "" set by set by g_object_set_property.
336 START_TEST (test_get_password_regular)
338 const gchar * default_password="test_password";
339 const gchar * ret_password;
342 /* Check get password dialog object has been created properly */
343 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
344 "hildon-get-password-dialog: Creation failed.");
345 fail_if (!GTK_IS_WINDOW (gpd_window),
346 "hildon-get-password-dialog: Window creation failed.");
348 /* Test 1: Get password "test_password" set by g_object_set_property. */
349 g_value_init (&value, G_TYPE_STRING);
350 g_value_set_string(&value,default_password);
351 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
352 g_value_unset (&value);
354 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
355 fail_if(strcmp (default_password,ret_password)!=0,
356 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
358 /* Test 2: Get password "01234567890" set by g_object_set_property. */
359 default_password = "01234567890";
361 g_value_init (&value, G_TYPE_STRING);
362 g_value_set_string(&value,default_password);
363 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
364 g_value_unset (&value);
366 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
367 fail_if(strcmp (default_password,ret_password)!=0,
368 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
370 /* Test 3: Get password TEST_STRING set by g_object_set_property. */
371 default_password = TEST_STRING;
373 g_value_init (&value, G_TYPE_STRING);
374 g_value_set_string(&value,default_password);
375 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
376 g_value_unset (&value);
378 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
379 fail_if(strcmp (default_password,ret_password)!=0,
380 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
382 /* Test 4: Get password "" set by g_object_set_property. */
383 default_password = "";
385 g_value_init (&value, G_TYPE_STRING);
386 g_value_set_string(&value,default_password);
387 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
388 g_value_unset (&value);
390 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
391 fail_if(strcmp (default_password,ret_password)!=0,
392 "hildon-get-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);
397 * Purpose: Check that limit password values are get properly.
399 * - Get empty password set by g_object_set_property with NULL value.
400 * - Get password from NULL object.
403 START_TEST (test_get_password_invalid)
405 const gchar * default_password=NULL;
406 const gchar * ret_password;
409 /* Check get password dialog object has been created properly */
410 fail_if(!HILDON_IS_GET_PASSWORD_DIALOG (get_password_dialog),
411 "hildon-get-password-dialog: Creation failed.");
412 fail_if (!GTK_IS_WINDOW (gpd_window),
413 "hildon-get-password-dialog: Window creation failed.");
415 /* Test 1: Get password NULL set by g_object_set_property. */
416 default_password = NULL;
417 g_value_init (&value, G_TYPE_STRING);
418 g_value_set_string(&value,default_password);
419 g_object_set_property(G_OBJECT (get_password_dialog),"password",&value);
420 g_value_unset (&value);
422 ret_password = hildon_get_password_dialog_get_password(get_password_dialog);
423 fail_if(strcmp(ret_password,"")!=0,
424 "hildon-get-password-dialog: Returned password is not empty (%s)",ret_password);
426 /* Test 2: Get password from NULL object. */
427 ret_password = hildon_get_password_dialog_get_password(NULL);
432 /* ---------- Suite creation ---------- */
433 Suite *create_hildon_get_password_dialog_suite()
435 /* Create the suite */
436 Suite *s = suite_create("HildonGetPasswordDialog");
438 /* Create test cases */
439 TCase *tc1 = tcase_create("new_with_default");
440 TCase *tc2 = tcase_create("set_max_characters");
441 TCase *tc3 = tcase_create("get_password");
443 /* Create test case for hildon_get_password_dialog_new_with_default and add it to the suite */
444 tcase_add_checked_fixture(tc1, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
445 tcase_add_test(tc1, test_new_with_default_regular);
446 tcase_add_test(tc1, test_new_with_default_invalid);
447 suite_add_tcase (s, tc1);
449 /* Create test case for hildon_get_password_dialog_set_max_characters and add it to the suite */
450 tcase_add_checked_fixture(tc2, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
451 tcase_add_test(tc2, test_set_max_characters_regular);
452 tcase_add_test(tc2, test_set_max_characters_limits);
453 tcase_add_test(tc2, test_set_max_characters_invalid);
454 suite_add_tcase (s, tc2);
456 /* Create test case for hildon_get_password_dialog_get_password and add it to the suite */
457 tcase_add_checked_fixture(tc3, fx_setup_default_get_password_dialog, fx_teardown_default_get_password_dialog);
458 tcase_add_test(tc3, test_get_password_regular);
459 tcase_add_test(tc3, test_get_password_invalid);
460 suite_add_tcase (s, tc3);
463 /* Return created suite */