2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkvbox.h>
27 #include <gtk/gtklabel.h>
28 #include <glib/gprintf.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
32 #include "hildon-wizard-dialog.h"
34 #define DEFAULT_NOTEBOOK_PAGES 3
36 /* -------------------- Fixtures -------------------- */
38 static HildonWizardDialog *wizard_dialog = NULL;
39 static GtkWindow * showed_window = NULL;
42 fx_setup_default_wizard_dialog ()
47 GtkBox *box[DEFAULT_NOTEBOOK_PAGES];
50 gtk_init(&argc, NULL);
52 showed_window = GTK_WINDOW(create_test_window());
54 /* Create a default notebook for the wizard */
55 book = GTK_NOTEBOOK(gtk_notebook_new());
57 /* Check notebook object has been created properly */
58 fail_if(!GTK_IS_NOTEBOOK(book),
59 "hildon-wizard-dialog: Auxiliar notebook creation failed.");
61 for(i=0; i<DEFAULT_NOTEBOOK_PAGES; i++)
63 box[i] = GTK_BOX(gtk_vbox_new(FALSE, 0));
64 label = GTK_LABEL(gtk_label_new(g_strdup_printf("Label for page %d", i)));
65 gtk_box_pack_start_defaults(box[i], GTK_WIDGET(label));
66 gtk_notebook_append_page(book, GTK_WIDGET(box[i]), NULL);
69 /* Create the wizard dialog */
70 wizard_dialog = HILDON_WIZARD_DIALOG(hildon_wizard_dialog_new(showed_window, "Wizard test", book));
72 show_test_window(GTK_WIDGET(showed_window));
74 show_test_window(GTK_WIDGET(wizard_dialog));
76 /* Check wizard dialog object has been created properly */
77 fail_if(!HILDON_IS_WIZARD_DIALOG(wizard_dialog),
78 "hildon-wizard-dialog: Creation failed.");
83 fx_teardown_default_wizard_dialog ()
85 gtk_widget_destroy (GTK_WIDGET(wizard_dialog));
88 /* -------------------- Test cases -------------------- */
90 /* ----- Test case for set/get property notebook -----*/
93 * Purpose: Check set and get of property "wizard-notebook"
95 * - Set and get of a regular notebook.
97 START_TEST (test_set_get_property_wizard_notebook_regular)
99 GtkNotebook *book, *old_book;
100 GValue book_value = {0,};
101 GValue ret_book_value = {0,};
106 book = GTK_NOTEBOOK(gtk_notebook_new());
109 box[i] = GTK_BOX(gtk_vbox_new(FALSE, 0));
110 label = GTK_LABEL(gtk_label_new(g_strdup_printf("Label for page %d", i)));
111 gtk_box_pack_start_defaults(box[i], GTK_WIDGET(label));
112 gtk_notebook_append_page(book, GTK_WIDGET(box[i]), NULL);
115 /* Free the old notebook */
116 g_value_init(&ret_book_value, GTK_TYPE_NOTEBOOK);
117 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
118 old_book = g_value_get_object (&ret_book_value);
119 gtk_widget_destroy (GTK_WIDGET(old_book));
121 g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
122 g_value_set_object(&book_value, book);
123 g_value_reset (&ret_book_value);
125 /* Test1: Set and get a regular notebook */
126 /* We don't test dialog title, set during setting of property "wizard-notebook"
127 because it is a visual issue and not a functional one, so it can be changed
128 at any time without breaking any test */
129 g_object_set_property(G_OBJECT(wizard_dialog), "wizard-notebook", &book_value);
130 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
131 fail_if(g_value_get_object(&ret_book_value) != g_value_get_object(&book_value),
132 "hildon-wizard-dialog: set property \"wizard-notebook\" but get_property returned a different notebook object");
137 * Purpose: Check set and get of property "wizard-notebook" with
140 * - Set property to NULL
142 START_TEST (test_set_get_property_wizard_notebook_invalid)
144 GValue book_value = {0,};
145 GValue ret_book_value = {0,};
147 /* Test1: set property to NULL */
148 g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
149 g_value_set_object(&book_value, NULL);
150 g_object_set_property(G_OBJECT(wizard_dialog), "wizard-notebook", &book_value);
151 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
152 fail_if((g_value_get_object(&ret_book_value) != NULL),
153 "hildon-wizard-dialog: Set \"wizard-notebook\" property to NULL is not forbidden");
158 /* ---------- Suite creation ---------- */
160 Suite *create_hildon_wizard_dialog_suite()
162 /* Create the suite */
163 Suite *s = suite_create("HildonWizardDialog");
165 /* Create test cases */
166 TCase *tc1 = tcase_create("set_get_property_wizard_notebook");
168 /* Create test case for property "wizard-notebook" and add it to the suite */
169 tcase_add_checked_fixture(tc1, fx_setup_default_wizard_dialog, fx_teardown_default_wizard_dialog);
170 tcase_add_test(tc1, test_set_get_property_wizard_notebook_regular);
171 tcase_add_test(tc1, test_set_get_property_wizard_notebook_invalid);
172 suite_add_tcase(s, tc1);
174 /* Return created suite */