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"
32 #include "hildon-set-password-dialog.h"
33 #include "hildon-window.h"
35 /* -------------------- Fixtures -------------------- */
37 static HildonSetPasswordDialog *set_password_dialog = NULL;
38 static GtkWindow *spd_window=NULL;
41 fx_setup_default_set_password_dialog ()
45 gtk_init(&argc, NULL);
46 spd_window = GTK_WINDOW(create_test_window());
48 /* Check window object has been created properly */
49 fail_if(!HILDON_IS_WINDOW(spd_window),
50 "hildon-set_password_dialog: Window creation failed.");
52 set_password_dialog = HILDON_SET_PASSWORD_DIALOG(hildon_set_password_dialog_new(spd_window, TRUE));
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.");
58 show_test_window(GTK_WIDGET(spd_window));
60 show_test_window(GTK_WIDGET(set_password_dialog));
65 fx_teardown_default_set_password_dialog ()
68 gtk_widget_destroy (GTK_WIDGET (set_password_dialog));
70 gtk_widget_destroy (GTK_WIDGET (spd_window));
74 /* -------------------- Test cases -------------------- */
76 /* ----- Test case for get_protected -----*/
79 * Purpose: Check that regular values are get properly.
81 * - Get TRUE from modify_protection property.
82 * - Get FALSE from modify_protection property.
85 START_TEST (test_get_protected_regular)
87 gboolean ret_protected;
88 HildonSetPasswordDialog *protected_test_password_dialog = NULL;
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));
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");
98 gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog));
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));
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");
108 gtk_widget_destroy (GTK_WIDGET (protected_test_password_dialog));
113 * Purpose: Check that invalid values are get properly.
115 * - Get modify_protection from NULL object.
118 START_TEST (test_get_protected_invalid)
120 gboolean ret_protected;
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");
128 /* ----- Test case for get_password -----*/
131 * Purpose: Check that regular values are get properly.
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.
137 START_TEST (test_get_password_regular)
139 const gchar * default_password=NULL;
140 const gchar * ret_password;
141 HildonSetPasswordDialog * default_set_password_dialog;
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");
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);
155 gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
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");
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);
168 gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
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");
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);
181 gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
187 * Purpose: Check that regular values are get properly.
189 * - Get empty password from HildonSetPasswordDialog created with NULL password by default.
190 * - Get password from NULL object.
192 START_TEST (test_get_password_invalid)
194 const gchar * ret_password;
195 HildonSetPasswordDialog * default_set_password_dialog;
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");
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");
208 gtk_widget_destroy (GTK_WIDGET (default_set_password_dialog));
210 /* Test 2: Get password from NULL object */
211 ret_password = hildon_set_password_dialog_get_password(NULL);
213 fail_if(ret_password!=NULL,
214 "hildon-set_password_dialog: returned password is not null");
219 /* ---------- Suite creation ---------- */
221 Suite *create_hildon_set_password_dialog_suite()
223 /* Create the suite */
224 Suite *s = suite_create("HildonSetPasswordDialog");
226 /* Create test cases */
227 TCase *tc1 = tcase_create("get_protected");
228 TCase *tc2 = tcase_create("get_password");
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);
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);
242 /* Return created suite */