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 "hildon-window.h"
31 #include "hildon-note.h"
33 /* -------------------- Fixtures -------------------- */
35 static HildonNote *note = NULL;
36 static GtkWindow * n_window = NULL;
39 fx_setup_default_note ()
43 gtk_init(&argc, NULL);
45 n_window = GTK_WINDOW(hildon_window_new());
46 /* Check window object has been created properly */
47 fail_if(!HILDON_IS_WINDOW(n_window),
48 "hildon-note: Window creation failed.");
52 fx_teardown_default_note ()
54 gtk_widget_destroy (GTK_WIDGET (n_window));
57 /* -------------------- Test cases -------------------- */
59 /* ----- Test case for new_confirmation -----*/
61 * Purpose: Check that note dialog is properly created with description regular values.
63 * - Create new confirmation note with description set to TEST_STRING
64 * - Create new confirmation note with description set to "".
67 START_TEST (test_new_confirmation_regular)
69 const gchar * description = NULL;
70 const gchar * ret_description = NULL;
72 GValue enum_value={0, };
73 HildonNoteType note_type;
75 g_value_init (&value, G_TYPE_STRING);
76 g_value_init (&enum_value, G_TYPE_INT);
78 /* Test 1: create new confirmation note with description set to TEST_STRING */
79 description = TEST_STRING;
80 note = HILDON_NOTE(hildon_note_new_confirmation(n_window,description));
81 fail_if(!HILDON_IS_NOTE(note),
82 "hildon-note: Creation failed with hildon_note_new_confirmation");
84 g_object_get_property(G_OBJECT (note),"description",&value);
85 ret_description = g_value_get_string (&value);
86 fail_if( strcmp (description,ret_description) != 0,
87 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
88 description,ret_description);
90 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
91 note_type = g_value_get_int(&enum_value);
92 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
93 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
95 gtk_widget_destroy (GTK_WIDGET (note));
98 /* Test 2: create new confirmation note with description set to "" */
100 note = HILDON_NOTE(hildon_note_new_confirmation(n_window,description));
101 fail_if(!HILDON_IS_NOTE(note),
102 "hildon-note: Creation failed with hildon_note_new_confirmation");
104 g_object_get_property(G_OBJECT (note),"description",&value);
105 ret_description = g_value_get_string (&value);
106 fail_if( strcmp (description,ret_description) != 0,
107 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
108 description,ret_description);
110 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
111 note_type = g_value_get_int(&enum_value);
112 fail_unless( note_type == HILDON_NOTE_TYPE_CONFIRMATION,
113 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
115 gtk_widget_destroy (GTK_WIDGET (note));
119 g_value_unset(&value);
120 g_value_unset(&enum_value);
125 * Purpose: Check that note dialog is properly created with description invalid values.
127 * - Create new confirmation note with window set to NULL.
128 * - Create new confirmation note with description set to "NULL".
131 START_TEST (test_new_confirmation_invalid)
133 const gchar * ret_description = NULL;
135 GValue enum_value={0, };
136 HildonNoteType note_type;
137 HildonNote * invalid_note;
139 g_value_init (&value, G_TYPE_STRING);
140 g_value_init (&enum_value, G_TYPE_INT);
142 /* Test 1: create new confirmation note with window set to "NULL" */
143 invalid_note = HILDON_NOTE(hildon_note_new_confirmation(NULL,""));
144 fail_if(!HILDON_IS_NOTE(invalid_note),
145 "hildon-note: Creation failed with hildon_note_new_confirmation");
147 g_object_get_property(G_OBJECT (invalid_note),"description",&value);
148 ret_description = g_value_get_string (&value);
149 fail_if( strcmp ("",ret_description) != 0,
150 "hildon-note: Empty description was not set properly on creation. Returned description: %s",
153 g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value);
154 note_type = g_value_get_int(&enum_value);
155 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
156 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
158 gtk_widget_destroy (GTK_WIDGET (invalid_note));
161 /* Test 2: create new confirmation note with description set to "NULL" */
162 invalid_note = HILDON_NOTE(hildon_note_new_confirmation(n_window,NULL));
163 fail_if(HILDON_IS_NOTE(invalid_note),
164 "hildon-note: Creation succeeded with hildon_note_new_confirmation with NULL description");
166 g_value_unset(&value);
167 g_value_unset(&enum_value);
171 /* ----- Test case for new_information -----*/
173 * Purpose: Check that note dialog is properly created with description regular values.
175 * - Create new information note with description set to TEST_STRING.
176 * - Create new information note with description set to "".
179 START_TEST (test_new_information_regular)
181 const gchar * description = NULL;
182 const gchar * ret_description = NULL;
184 GValue enum_value={0, };
185 HildonNoteType note_type;
187 g_value_init (&value, G_TYPE_STRING);
188 g_value_init (&enum_value, G_TYPE_INT);
190 /* Test 1: create new information note with description set to "Standard question?" */
191 description = TEST_STRING;
192 note = HILDON_NOTE(hildon_note_new_information(n_window,description));
193 fail_if(!HILDON_IS_NOTE(note),
194 "hildon-note: Creation failed with hildon_note_new_information");
196 g_object_get_property(G_OBJECT (note),"description",&value);
197 ret_description = g_value_get_string (&value);
198 fail_if( strcmp (description,ret_description) != 0,
199 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
200 description,ret_description);
202 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
203 note_type = g_value_get_int(&enum_value);
204 fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME,
205 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type);
207 gtk_widget_destroy (GTK_WIDGET (note));
210 /* Test 2: create new information note with description set to "" */
212 note = HILDON_NOTE(hildon_note_new_information(n_window,description));
213 fail_if(!HILDON_IS_NOTE(note),
214 "hildon-note: Creation failed with hildon_note_new_information");
216 g_object_get_property(G_OBJECT (note),"description",&value);
217 ret_description = g_value_get_string (&value);
218 fail_if( strcmp (description,ret_description) != 0,
219 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
220 description,ret_description);
222 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
223 note_type = g_value_get_int(&enum_value);
224 fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME,
225 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type);
227 gtk_widget_destroy (GTK_WIDGET (note));
230 g_value_unset(&value);
231 g_value_unset(&enum_value);
237 * Purpose: Check that note dialog is properly created with description invalid values.
239 * - Create new information note with window set to NULL.
240 * - Create new information note with description set to "NULL".
243 START_TEST (test_new_information_invalid)
245 const gchar * ret_description = NULL;
247 GValue enum_value={0, };
248 HildonNoteType note_type;
249 HildonNote * invalid_note;
251 g_value_init (&value, G_TYPE_STRING);
252 g_value_init (&enum_value, G_TYPE_INT);
254 /* Test 1: create new information note with window set to "NULL" */
255 invalid_note = HILDON_NOTE(hildon_note_new_information(NULL,""));
256 fail_if(!HILDON_IS_NOTE(invalid_note),
257 "hildon-note: Creation failed with hildon_note_new_information");
259 g_object_get_property(G_OBJECT (invalid_note),"description",&value);
260 ret_description = g_value_get_string (&value);
261 fail_if( strcmp ("",ret_description) != 0,
262 "hildon-note: Empty description was not set properly on creation. Returned description: %s",
265 g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value);
266 note_type = g_value_get_int(&enum_value);
267 fail_if( note_type != HILDON_NOTE_TYPE_INFORMATION_THEME,
268 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_INFORMATION_THEME)",note_type);
270 gtk_widget_destroy (GTK_WIDGET (invalid_note));
273 /* Test 2: create new information note with description set to "NULL" */
274 invalid_note = HILDON_NOTE(hildon_note_new_information(n_window,NULL));
275 fail_if(HILDON_IS_NOTE(invalid_note),
276 "hildon-note: Creation succeeded with hildon_note_new_information where msg == NULL");
278 g_value_unset(&value);
279 g_value_unset(&enum_value);
283 /* ----- Test case for new_confirmation_with_icon_name -----*/
285 * Purpose: Check that note dialog is properly created with description regular values.
287 * - Create new confirmation note with description set to TEST_STRING and icon name "qgn_list_cp_calibration".
288 * - Create new confirmation note with description set to "" and icon name NULL.
291 START_TEST (test_new_confirmation_with_icon_name_regular)
293 const gchar * description = NULL;
294 const gchar * ret_description = NULL;
295 const gchar *icon_name = NULL;
296 const gchar * ret_icon_name = NULL;
298 GValue icon_name_value={0, };
299 GValue enum_value={0, };
300 HildonNoteType note_type;
302 g_value_init (&value, G_TYPE_STRING);
303 g_value_init (&icon_name_value, G_TYPE_STRING);
304 g_value_init (&enum_value, G_TYPE_INT);
306 /* Test 1: create new confirmation note with description set to TEST_STRING */
307 description = TEST_STRING;
308 icon_name="qgn_list_cp_calibration";
309 note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name));
310 fail_if(!HILDON_IS_NOTE(note),
311 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
313 g_object_get_property(G_OBJECT (note),"description",&value);
314 ret_description = g_value_get_string (&value);
315 fail_if( strcmp (description,ret_description) != 0,
316 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
317 description,ret_description);
319 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
320 note_type = g_value_get_int(&enum_value);
321 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
322 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
324 g_object_get_property(G_OBJECT (note),"icon",&icon_name_value);
325 ret_icon_name = g_value_get_string (&icon_name_value);
326 fail_if( strcmp (icon_name,ret_icon_name) != 0,
327 "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s",
328 icon_name,ret_icon_name);
330 gtk_widget_destroy (GTK_WIDGET (note));
333 /* Test 2: create new confirmation note with description set to "" and icon name set to NULL */
336 note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name));
337 fail_if(!HILDON_IS_NOTE(note),
338 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
340 g_object_get_property(G_OBJECT (note),"description",&value);
341 ret_description = g_value_get_string (&value);
342 fail_if( strcmp (description,ret_description) != 0,
343 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
344 description,ret_description);
346 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
347 note_type = g_value_get_int(&enum_value);
348 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
349 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
351 g_object_get_property(G_OBJECT (note),"icon",&icon_name_value);
352 ret_icon_name = g_value_get_string (&icon_name_value);
353 fail_if( ret_icon_name != NULL,
354 "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s",
355 icon_name,ret_icon_name);
357 gtk_widget_destroy (GTK_WIDGET (note));
360 g_value_unset(&value);
361 g_value_unset(&icon_name_value);
362 g_value_unset(&enum_value);
368 * Purpose: Check that note dialog is properly created with description invalid values.
370 * - Create new confirmation note with window set to NULL.
371 * - Create new confirmation note with description set to "NULL".
374 START_TEST (test_new_confirmation_with_icon_name_invalid)
376 const gchar * ret_description = NULL;
377 const gchar * ret_icon_name = NULL;
379 GValue enum_value={0, };
380 GValue icon_name_value={0, };
381 HildonNoteType note_type;
382 HildonNote * invalid_note;
384 g_value_init (&value, G_TYPE_STRING);
385 g_value_init (&icon_name_value, G_TYPE_STRING);
386 g_value_init (&enum_value, G_TYPE_INT);
388 /* Test 1: create new confirmation note with window set to "NULL" */
389 invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(NULL,"",""));
390 fail_if(!HILDON_IS_NOTE(invalid_note),
391 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
393 g_object_get_property(G_OBJECT (invalid_note),"description",&value);
394 ret_description = g_value_get_string (&value);
395 fail_if( strcmp ("",ret_description) != 0,
396 "hildon-note: Description "" was not set properly on creation. Returned description: %s",
399 g_object_get_property(G_OBJECT (invalid_note),"icon",&icon_name_value);
400 ret_icon_name = g_value_get_string (&icon_name_value);
401 fail_if( strcmp ("",ret_icon_name) != 0,
402 "hildon-note: Description "" was not set properly on creation. Returned description: %s",
405 g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value);
406 note_type = g_value_get_int(&enum_value);
407 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
408 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
410 gtk_widget_destroy (GTK_WIDGET (invalid_note));
413 /* Test 2: create new confirmation note with description set to "NULL" */
414 invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,NULL,"qgn_list_cp_calibration"));
415 fail_if(HILDON_IS_NOTE(invalid_note),
416 "hildon-note: Creation succeeded with hildon_note_new_confirmation_with_icon_name with message == NULL");
418 g_value_unset(&icon_name_value);
419 g_value_unset(&value);
420 g_value_unset(&enum_value);
424 /* ----- Test case for new_cancel_with_progress_bar -----*/
427 * Purpose: Check that note dialog is properly created with description regular values.
429 * - Create new confirmation note with description set to TEST_STRING and NULL GtkProgressBar.
430 * - Create new confirmation note with description set to "" and correct GtkProgressBar.
433 START_TEST (test_new_cancel_with_progress_bar_regular)
435 const gchar * description = NULL;
436 const gchar * ret_description = NULL;
438 GValue enum_value={0, };
439 GtkProgressBar * progress_bar=NULL;
441 HildonNoteType note_type;
443 g_value_init (&value, G_TYPE_STRING);
444 g_value_init (&enum_value, G_TYPE_INT);
446 /* Test 1: create new confirmation note with description set to TEST_STRING and NULL GtkProgressBar */
447 description = TEST_STRING;
448 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,progress_bar));
449 fail_if(!HILDON_IS_NOTE(note),
450 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
452 g_object_get_property(G_OBJECT (note),"description",&value);
453 ret_description = g_value_get_string (&value);
454 fail_if( strcmp (description,ret_description) != 0,
455 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
456 description,ret_description);
458 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
459 note_type = g_value_get_int(&enum_value);
460 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
461 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
463 gtk_widget_destroy (GTK_WIDGET (note));
466 /* Test 2: create new confirmation note with description set to "" */
468 progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
469 fail_if(!GTK_IS_PROGRESS_BAR(progress_bar),
470 "hildon-note: Progress bar creation failed in hildon_note_new_cancel_with_progress_bar");
472 gtk_progress_bar_set_fraction(progress_bar,0.5);
474 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,progress_bar));
475 fail_if(!HILDON_IS_NOTE(note),
476 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
478 g_object_get_property(G_OBJECT (note),"description",&value);
479 ret_description = g_value_get_string (&value);
480 fail_if( strcmp (description,ret_description) != 0,
481 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
482 description,ret_description);
484 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
485 note_type = g_value_get_int(&enum_value);
486 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
487 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
489 gtk_widget_destroy (GTK_WIDGET (progress_bar));
490 gtk_widget_destroy (GTK_WIDGET (note));
493 g_value_unset(&value);
494 g_value_unset(&enum_value);
499 * Purpose: Check that note dialog is properly created with description invalid values.
501 * - Create new confirmation note with description set to NULL.
502 * - Create new confirmation note with window set to NULL.
505 START_TEST (test_new_cancel_with_progress_bar_invalid)
507 const gchar * description = NULL;
508 const gchar * ret_description = NULL;
510 GValue enum_value={0, };
512 HildonNoteType note_type;
514 g_value_init (&value, G_TYPE_STRING);
515 g_value_init (&enum_value, G_TYPE_INT);
517 /* Test 1: create new confirmation note with description set to NULL */
519 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,NULL));
520 fail_if(HILDON_IS_NOTE(note),
521 "hildon-note: Creation succeeded with hildon_note_new_cancel_with_progress_bar where msg == NULL");
523 /* Test 2: create new confirmation note with window set to NULL */
525 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(NULL,description,NULL));
526 fail_if(!HILDON_IS_NOTE(note),
527 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
529 g_object_get_property(G_OBJECT (note),"description",&value);
530 ret_description = g_value_get_string (&value);
531 fail_if( strcmp(description,ret_description) != 0,
532 "hildon-note: Empty description was not set properly on creation",
533 description,ret_description);
535 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
536 note_type = g_value_get_int(&enum_value);
537 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
538 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
540 gtk_widget_destroy (GTK_WIDGET (note));
543 g_value_unset(&value);
544 g_value_unset(&enum_value);
550 /* ---------- Suite creation ---------- */
551 Suite *create_hildon_note_suite()
553 /* Create the suite */
554 Suite *s = suite_create("HildonNote");
556 /* Create test cases */
557 TCase *tc1 = tcase_create("new_confirmation");
558 TCase *tc2 = tcase_create("new_confirmation_with_icon_name");
559 TCase *tc3 = tcase_create("new_information");
560 TCase *tc4 = tcase_create("new_cancel_with_progress_bar");
562 /* Create test case for hildon_note_new_confirmation and add it to the suite */
563 tcase_add_checked_fixture(tc1, fx_setup_default_note, fx_teardown_default_note);
564 tcase_add_test(tc1, test_new_confirmation_regular);
565 tcase_add_test(tc1, test_new_confirmation_invalid);
566 suite_add_tcase (s, tc1);
568 /* Create test case for hildon_note_new_confirmation_with_icon_name and add it to the suite */
569 tcase_add_checked_fixture(tc2, fx_setup_default_note, fx_teardown_default_note);
570 tcase_add_test(tc2, test_new_confirmation_with_icon_name_regular);
571 tcase_add_test(tc2, test_new_confirmation_with_icon_name_invalid);
572 suite_add_tcase (s, tc2);
574 /* Create test case for hildon_note_new_with_information and add it to the suite */
575 tcase_add_checked_fixture(tc3, fx_setup_default_note, fx_teardown_default_note);
576 tcase_add_test(tc3, test_new_information_regular);
577 tcase_add_test(tc3, test_new_information_invalid);
578 suite_add_tcase (s, tc3);
580 /* Create test case for hildon_note_new_with_progress_bar and add it to the suite */
581 tcase_add_checked_fixture(tc4, fx_setup_default_note, fx_teardown_default_note);
582 tcase_add_test(tc4, test_new_cancel_with_progress_bar_regular);
583 tcase_add_test(tc4, test_new_cancel_with_progress_bar_invalid);
584 suite_add_tcase (s, tc4);
586 /* Return created suite */