aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-name-password-dialog.c
blob: eb70d1dd1d3b99a157fcfcf8fae2517307bef5a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/*
 * This file is a part of hildon tests
 *
 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
 *
 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */
#include <stdlib.h>
#include <string.h>
#include <check.h>
#include <gtk/gtkmain.h>
#include "test_suites.h"
#include "check_utils.h"
#include "hildon-name-password-dialog.h"
#include "hildon-window.h"

/* -------------------- Fixtures -------------------- */

static HildonNamePasswordDialog *name_password_dialog = NULL;
static GtkWindow * npd_window = NULL; 

static void 
fx_setup_default_name_password_dialog ()
{
  int argc = 0;
    
  gtk_init(&argc, NULL);
    
  npd_window = GTK_WINDOW(create_test_window());   

  /* Check window object has been created properly */
  fail_if(!HILDON_IS_WINDOW(npd_window),
          "hildon-name-password-dialog: Window creation failed.");

  name_password_dialog = HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new(npd_window));
  /* Check that the name password dialog object has been created properly */
  fail_if (!HILDON_IS_NAME_PASSWORD_DIALOG (name_password_dialog),
           "hildon-name-password-dialog: Creation failed.");
  
  show_test_window(GTK_WIDGET(npd_window));

  show_test_window(GTK_WIDGET(name_password_dialog));

}

static void 
fx_teardown_default_name_password_dialog ()
{
  gtk_widget_destroy (GTK_WIDGET(name_password_dialog));

  gtk_widget_destroy (GTK_WIDGET(npd_window));
}

/* -------------------- Test cases -------------------- */

/* ----- Test case for new_with_default -----*/

/**
 * Purpose: Check that regular name and password values are correctly added by default on creation.
 * Cases considered: 
 *    - Create new name and password dialog with "test_name" and "test_password" by default.
 *    - Create new name and password dialog with "0123456789" and "123412341234" by default.
 *    - Create new name and password dialog with TEST_STRING and TEST_STRING by default.
 *    - Create new name and password dialog with "" and "" by default.
 */
START_TEST (test_new_with_default_regular)
{
  const gchar * default_name="test_name";
  const gchar * default_password="test_password";
  const gchar * ret_name;
  const gchar * ret_password;
  HildonNamePasswordDialog * default_name_password_dialog=NULL;

  /* Check that the name password dialog object has been created properly */
  fail_if (!HILDON_IS_NAME_PASSWORD_DIALOG (name_password_dialog),
           "hildon-name-password-dialog: Creation failed.");
  fail_if (!GTK_IS_WINDOW (npd_window),
	   "hildon-name-password-dialog: Window creation failed.");

  /* Test 1: Create new dialog with username and password by default */
  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window, default_name, default_password));       
  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)",default_name,ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);
  fail_if (strcmp (default_password,ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);

  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog));
  default_name_password_dialog=NULL;

  /* Test 2: Create new dialog with username and password by default */
  default_name = "0123456789";
  default_password = "123412341234";

  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window, default_name, default_password));       
  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)", default_name, ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);
  fail_if (strcmp (default_password,ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (%s,%s)", default_password, ret_password);

  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog));

  /* Test 3: Create new dialog with invalid username and password by default. */
  default_name = TEST_STRING;
  default_password = TEST_STRING;

  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window,default_name,default_password));

  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)",default_name,ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);       
  fail_if (strcmp (default_password,ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);

  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog)); 

  /* Test 4: Create new dialog with empty username and password by default. */
  default_name = "";
  default_password = "";

  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window,default_name,default_password));

  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)",default_name,ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);  
  fail_if (strcmp (default_password,ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);


  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog)); 
}
END_TEST


/**
 * Purpose: Check that regular name and password values are correctly added by default on creation.
 * Cases considered: 
 *    - Create a name and password dialog with NULL name.
 *    - Create a name and password dialog with NULL password.
 */
START_TEST (test_new_with_default_invalid)
{
  const gchar * default_name="test_name";
  const gchar * default_password="test_password";
  const gchar * ret_name;
  const gchar * ret_password;
  HildonNamePasswordDialog * default_name_password_dialog;

  /* Check that the name password dialog object has been created properly */
  fail_if (!HILDON_IS_NAME_PASSWORD_DIALOG (name_password_dialog),
           "hildon-name-password-dialog: Creation failed.");
  fail_if (!GTK_IS_WINDOW (npd_window),
	   "hildon-name-password-dialog: Window creation failed.");
    
  /* Test 1: Create a name and password dialog with NULL name. */
  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window,NULL,default_password));
   
  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp ("",ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (,%s)",ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);
  fail_if (strcmp (default_password,ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (%s,%s)",default_password,ret_password);

  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog)); 

  /* Test 2: Create a name and password dialog with NULL name. */
  default_name_password_dialog = 
    HILDON_NAME_PASSWORD_DIALOG(hildon_name_password_dialog_new_with_default(npd_window,default_name,NULL));

  fail_if(!HILDON_IS_NAME_PASSWORD_DIALOG(default_name_password_dialog),
	  "hildon-name-password-dialog: Creation failed with hildon_name_password_dialog_new_with_default");

  ret_name = hildon_name_password_dialog_get_name(default_name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)",default_name,ret_name);

  ret_password = hildon_name_password_dialog_get_password(default_name_password_dialog);   
  fail_if (strcmp ("",ret_password) != 0,
	   "hildon-name-password-dialog: Default password and returned password are diferent (,%s)",ret_password);
        
  gtk_widget_destroy (GTK_WIDGET(default_name_password_dialog)); 

}
END_TEST

/* ----- Test case for get_name -----*/

/**
 * Purpose: Check that regular name and password values are correctly added by default on creation.
 * Cases considered: 
 *    - Get name "test_name" set by g_object_set_property.
 *    - Get name "0123456789" set by g_object_set_property.
 *    - Get name TEST_STRING set by g_object_set_property.
 */
START_TEST (test_get_name_regular)
{
  const gchar * default_name="test_name";  
  const gchar * ret_name;
  GValue value={0, };

  /* Check that the name password dialog object has been created properly */
  fail_if (!HILDON_IS_NAME_PASSWORD_DIALOG (name_password_dialog),
           "hildon-name-password-dialog: Creation failed.");
  fail_if (!GTK_IS_WINDOW (npd_window),
	   "hildon-name-password-dialog: Window creation failed.");

  g_value_init (&value, G_TYPE_STRING);
  g_value_set_string(&value, default_name);
  g_object_set_property(G_OBJECT(name_password_dialog), "name", &value);
  g_value_unset (&value);
    
  /* Test 1: Get name "test_name" set by g_object_set_property. */
  ret_name = hildon_name_password_dialog_get_name(name_password_dialog);
    
  fail_if (strcmp(default_name, ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)", default_name, ret_name);
                
  /* Test 2: Get name "0123456789" set by g_object_set_property. */
  default_name = "0123456789";

  g_value_init (&value, G_TYPE_STRING);
  g_value_set_string(&value,default_name);
  g_object_set_property(G_OBJECT(name_password_dialog), "name", &value);
  g_value_unset (&value);

  ret_name = hildon_name_password_dialog_get_name(name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)", default_name, ret_name);

  /* Test 3: Get name TEST_STRING set by g_object_set_property. */
  default_name=TEST_STRING;

  g_value_init (&value, G_TYPE_STRING);
  g_value_set_string(&value,default_name);
  g_object_set_property(G_OBJECT (name_password_dialog),"name",&value);
  g_value_unset (&value);

  ret_name = hildon_name_password_dialog_get_name(name_password_dialog);
  fail_if (strcmp (default_name,ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (%s,%s)",default_name,ret_name);
}
END_TEST


/**
 * Purpose: Check that regular name and password values are correctly added by default on creation.
 * Cases considered: 
 *    - Get name on NULL object.
 *    - Get empty password set by g_object_set_property with NULL value.
 */

START_TEST (test_get_name_invalid)
{
  const gchar * default_name;
  const gchar * ret_name;
  GValue value={0, };

  /* Check that the name password dialog object has been created properly */
  fail_if (!HILDON_IS_NAME_PASSWORD_DIALOG (name_password_dialog),
           "hildon-name-password-dialog: Creation failed.");
  fail_if (!GTK_IS_WINDOW (npd_window),
	   "hildon-name-password-dialog: Window creation failed.");

  /* Test 1: Get name on NULL object. */
  ret_name = hildon_name_password_dialog_get_name(NULL);


  /* Test 2: Get name NULL set by g_object_set_property. */
  default_name = NULL;
  g_value_init (&value, G_TYPE_STRING);
  g_value_set_string(&value,default_name);
  g_object_set_property(G_OBJECT (name_password_dialog),"name",&value);
  g_value_unset (&value);

  ret_name = hildon_name_password_dialog_get_name(name_password_dialog);
    
  fail_if (strcmp ("",ret_name) != 0,
	   "hildon-name-password-dialog: Default name and returned name are diferent (,%s)",ret_name);          
}
END_TEST


/* ---------- Suite creation ---------- */

Suite *create_hildon_name_password_dialog_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonNamePasswordDialog");

  /* Create test cases */
  TCase *tc1 = tcase_create("new_with_default");
  TCase *tc2 = tcase_create("get_name");

  /* Create unit tests for hildon_name_password_dialog_new_with_default and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_name_password_dialog, fx_teardown_default_name_password_dialog);
  tcase_add_test(tc1, test_new_with_default_regular);
  tcase_add_test(tc1, test_new_with_default_invalid);
  suite_add_tcase (s, tc1);

  /* Create unit tests for hildon_name_password_dialog_get_name and add it to the suite */
  tcase_add_checked_fixture(tc2, fx_setup_default_name_password_dialog, fx_teardown_default_name_password_dialog);
  tcase_add_test(tc2, test_get_name_regular);
  tcase_add_test(tc2, test_get_name_invalid);
  suite_add_tcase (s, tc2);

  /* Return created suite */
  return s;             
}