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 #ifndef HILDON_DISABLE_DEPRECATED
284 /* ----- Test case for new_confirmation_with_icon_name -----*/
286 * Purpose: Check that note dialog is properly created with description regular values.
288 * - Create new confirmation note with description set to TEST_STRING and icon name "control_calibration_target".
289 * - Create new confirmation note with description set to "" and icon name NULL.
292 START_TEST (test_new_confirmation_with_icon_name_regular)
294 const gchar * description = NULL;
295 const gchar * ret_description = NULL;
296 const gchar *icon_name = NULL;
297 const gchar * ret_icon_name = NULL;
299 GValue icon_name_value={0, };
300 GValue enum_value={0, };
301 HildonNoteType note_type;
303 g_value_init (&value, G_TYPE_STRING);
304 g_value_init (&icon_name_value, G_TYPE_STRING);
305 g_value_init (&enum_value, G_TYPE_INT);
307 /* Test 1: create new confirmation note with description set to TEST_STRING */
308 description = TEST_STRING;
309 icon_name="control_calibration_target";
310 note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name));
311 fail_if(!HILDON_IS_NOTE(note),
312 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
314 g_object_get_property(G_OBJECT (note),"description",&value);
315 ret_description = g_value_get_string (&value);
316 fail_if( strcmp (description,ret_description) != 0,
317 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
318 description,ret_description);
320 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
321 note_type = g_value_get_int(&enum_value);
322 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
323 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
325 g_object_get_property(G_OBJECT (note),"icon",&icon_name_value);
326 ret_icon_name = g_value_get_string (&icon_name_value);
327 fail_if( strcmp (icon_name,ret_icon_name) != 0,
328 "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s",
329 icon_name,ret_icon_name);
331 gtk_widget_destroy (GTK_WIDGET (note));
334 /* Test 2: create new confirmation note with description set to "" and icon name set to NULL */
337 note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,description,icon_name));
338 fail_if(!HILDON_IS_NOTE(note),
339 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
341 g_object_get_property(G_OBJECT (note),"description",&value);
342 ret_description = g_value_get_string (&value);
343 fail_if( strcmp (description,ret_description) != 0,
344 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
345 description,ret_description);
347 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
348 note_type = g_value_get_int(&enum_value);
349 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
350 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
352 g_object_get_property(G_OBJECT (note),"icon",&icon_name_value);
353 ret_icon_name = g_value_get_string (&icon_name_value);
354 fail_if( ret_icon_name != NULL,
355 "hildon-note: icon_name (%s) was not set properly on creation. Returned icon_name: %s",
356 icon_name,ret_icon_name);
358 gtk_widget_destroy (GTK_WIDGET (note));
361 g_value_unset(&value);
362 g_value_unset(&icon_name_value);
363 g_value_unset(&enum_value);
369 * Purpose: Check that note dialog is properly created with description invalid values.
371 * - Create new confirmation note with window set to NULL.
372 * - Create new confirmation note with description set to "NULL".
375 START_TEST (test_new_confirmation_with_icon_name_invalid)
377 const gchar * ret_description = NULL;
378 const gchar * ret_icon_name = NULL;
380 GValue enum_value={0, };
381 GValue icon_name_value={0, };
382 HildonNoteType note_type;
383 HildonNote * invalid_note;
385 g_value_init (&value, G_TYPE_STRING);
386 g_value_init (&icon_name_value, G_TYPE_STRING);
387 g_value_init (&enum_value, G_TYPE_INT);
389 /* Test 1: create new confirmation note with window set to "NULL" */
390 invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(NULL,"",""));
391 fail_if(!HILDON_IS_NOTE(invalid_note),
392 "hildon-note: Creation failed with hildon_note_new_confirmation_with_icon_name");
394 g_object_get_property(G_OBJECT (invalid_note),"description",&value);
395 ret_description = g_value_get_string (&value);
396 fail_if( strcmp ("",ret_description) != 0,
397 "hildon-note: Description "" was not set properly on creation. Returned description: %s",
400 g_object_get_property(G_OBJECT (invalid_note),"icon",&icon_name_value);
401 ret_icon_name = g_value_get_string (&icon_name_value);
402 fail_if( strcmp ("",ret_icon_name) != 0,
403 "hildon-note: Description "" was not set properly on creation. Returned description: %s",
406 g_object_get_property(G_OBJECT (invalid_note),"note_type",&enum_value);
407 note_type = g_value_get_int(&enum_value);
408 fail_if( note_type != HILDON_NOTE_TYPE_CONFIRMATION,
409 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_CONFIRMATION)",note_type);
411 gtk_widget_destroy (GTK_WIDGET (invalid_note));
414 /* Test 2: create new confirmation note with description set to "NULL" */
415 invalid_note = HILDON_NOTE(hildon_note_new_confirmation_with_icon_name(n_window,NULL,"control_calibration_target"));
416 fail_if(HILDON_IS_NOTE(invalid_note),
417 "hildon-note: Creation succeeded with hildon_note_new_confirmation_with_icon_name with message == NULL");
419 g_value_unset(&icon_name_value);
420 g_value_unset(&value);
421 g_value_unset(&enum_value);
426 /* ----- Test case for new_cancel_with_progress_bar -----*/
429 * Purpose: Check that note dialog is properly created with description regular values.
431 * - Create new confirmation note with description set to TEST_STRING and NULL GtkProgressBar.
432 * - Create new confirmation note with description set to "" and correct GtkProgressBar.
435 START_TEST (test_new_cancel_with_progress_bar_regular)
437 const gchar * description = NULL;
438 const gchar * ret_description = NULL;
440 GValue enum_value={0, };
441 GtkProgressBar * progress_bar=NULL;
443 HildonNoteType note_type;
445 g_value_init (&value, G_TYPE_STRING);
446 g_value_init (&enum_value, G_TYPE_INT);
448 /* Test 1: create new confirmation note with description set to TEST_STRING and NULL GtkProgressBar */
449 description = TEST_STRING;
450 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,progress_bar));
451 fail_if(!HILDON_IS_NOTE(note),
452 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
454 g_object_get_property(G_OBJECT (note),"description",&value);
455 ret_description = g_value_get_string (&value);
456 fail_if( strcmp (description,ret_description) != 0,
457 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
458 description,ret_description);
460 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
461 note_type = g_value_get_int(&enum_value);
462 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
463 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
465 gtk_widget_destroy (GTK_WIDGET (note));
468 /* Test 2: create new confirmation note with description set to "" */
470 progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
471 fail_if(!GTK_IS_PROGRESS_BAR(progress_bar),
472 "hildon-note: Progress bar creation failed in hildon_note_new_cancel_with_progress_bar");
474 gtk_progress_bar_set_fraction(progress_bar,0.5);
476 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,progress_bar));
477 fail_if(!HILDON_IS_NOTE(note),
478 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
480 g_object_get_property(G_OBJECT (note),"description",&value);
481 ret_description = g_value_get_string (&value);
482 fail_if( strcmp (description,ret_description) != 0,
483 "hildon-note: Description (%s) was not set properly on creation. Returned description: %s",
484 description,ret_description);
486 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
487 note_type = g_value_get_int(&enum_value);
488 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
489 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
491 gtk_widget_destroy (GTK_WIDGET (progress_bar));
492 gtk_widget_destroy (GTK_WIDGET (note));
495 g_value_unset(&value);
496 g_value_unset(&enum_value);
501 * Purpose: Check that note dialog is properly created with description invalid values.
503 * - Create new confirmation note with description set to NULL.
504 * - Create new confirmation note with window set to NULL.
507 START_TEST (test_new_cancel_with_progress_bar_invalid)
509 const gchar * description = NULL;
510 const gchar * ret_description = NULL;
512 GValue enum_value={0, };
514 HildonNoteType note_type;
516 g_value_init (&value, G_TYPE_STRING);
517 g_value_init (&enum_value, G_TYPE_INT);
519 /* Test 1: create new confirmation note with description set to NULL */
521 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(n_window,description,NULL));
522 fail_if(HILDON_IS_NOTE(note),
523 "hildon-note: Creation succeeded with hildon_note_new_cancel_with_progress_bar where msg == NULL");
525 /* Test 2: create new confirmation note with window set to NULL */
527 note = HILDON_NOTE(hildon_note_new_cancel_with_progress_bar(NULL,description,NULL));
528 fail_if(!HILDON_IS_NOTE(note),
529 "hildon-note: Creation failed with hildon_note_new_cancel_with_progress_bar");
531 g_object_get_property(G_OBJECT (note),"description",&value);
532 ret_description = g_value_get_string (&value);
533 fail_if( strcmp(description,ret_description) != 0,
534 "hildon-note: Empty description was not set properly on creation",
535 description,ret_description);
537 g_object_get_property(G_OBJECT (note),"note_type",&enum_value);
538 note_type = g_value_get_int(&enum_value);
539 fail_if( note_type != HILDON_NOTE_TYPE_PROGRESSBAR,
540 "hildon-note: Type was not set property on creation (HILDON_NOTE_TYPE_PROGRESSBAR)",note_type);
542 gtk_widget_destroy (GTK_WIDGET (note));
545 g_value_unset(&value);
546 g_value_unset(&enum_value);
552 /* ---------- Suite creation ---------- */
553 Suite *create_hildon_note_suite()
555 /* Create the suite */
556 Suite *s = suite_create("HildonNote");
558 /* Create test cases */
559 TCase *tc1 = tcase_create("new_confirmation");
560 #ifndef HILDON_DISABLE_DEPRECATED
561 TCase *tc2 = tcase_create("new_confirmation_with_icon_name");
563 TCase *tc3 = tcase_create("new_information");
564 TCase *tc4 = tcase_create("new_cancel_with_progress_bar");
566 /* Create test case for hildon_note_new_confirmation and add it to the suite */
567 tcase_add_checked_fixture(tc1, fx_setup_default_note, fx_teardown_default_note);
568 tcase_add_test(tc1, test_new_confirmation_regular);
569 tcase_add_test(tc1, test_new_confirmation_invalid);
570 suite_add_tcase (s, tc1);
572 #ifndef HILDON_DISABLE_DEPRECATED
573 /* Create test case for hildon_note_new_confirmation_with_icon_name and add it to the suite */
574 tcase_add_checked_fixture(tc2, fx_setup_default_note, fx_teardown_default_note);
575 tcase_add_test(tc2, test_new_confirmation_with_icon_name_regular);
576 tcase_add_test(tc2, test_new_confirmation_with_icon_name_invalid);
577 suite_add_tcase (s, tc2);
580 /* Create test case for hildon_note_new_with_information and add it to the suite */
581 tcase_add_checked_fixture(tc3, fx_setup_default_note, fx_teardown_default_note);
582 tcase_add_test(tc3, test_new_information_regular);
583 tcase_add_test(tc3, test_new_information_invalid);
584 suite_add_tcase (s, tc3);
586 /* Create test case for hildon_note_new_with_progress_bar and add it to the suite */
587 tcase_add_checked_fixture(tc4, fx_setup_default_note, fx_teardown_default_note);
588 tcase_add_test(tc4, test_new_cancel_with_progress_bar_regular);
589 tcase_add_test(tc4, test_new_cancel_with_progress_bar_invalid);
590 suite_add_tcase (s, tc4);
592 /* Return created suite */