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
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkvbox.h>
29 #include <gtk/gtklabel.h>
30 #include <glib/gprintf.h>
31 #include "test_suites.h"
32 #include "check_utils.h"
34 #include "hildon-wizard-dialog.h"
36 #define DEFAULT_NOTEBOOK_PAGES 3
38 /* -------------------- Fixtures -------------------- */
40 static HildonWizardDialog *wizard_dialog = NULL;
41 static GtkWindow * showed_window = NULL;
44 fx_setup_default_wizard_dialog ()
49 GtkBox *box[DEFAULT_NOTEBOOK_PAGES];
52 gtk_init(&argc, NULL);
54 showed_window = GTK_WINDOW(create_test_window());
56 /* Create a default notebook for the wizard */
57 book = GTK_NOTEBOOK(gtk_notebook_new());
59 /* Check notebook object has been created properly */
60 fail_if(!GTK_IS_NOTEBOOK(book),
61 "hildon-wizard-dialog: Auxiliar notebook creation failed.");
63 for(i=0; i<DEFAULT_NOTEBOOK_PAGES; i++)
65 box[i] = GTK_BOX(gtk_vbox_new(FALSE, 0));
66 label = GTK_LABEL(gtk_label_new(g_strdup_printf("Label for page %d", i)));
67 gtk_box_pack_start_defaults(box[i], GTK_WIDGET(label));
68 gtk_notebook_append_page(book, GTK_WIDGET(box[i]), NULL);
71 /* Create the wizard dialog */
72 wizard_dialog = HILDON_WIZARD_DIALOG(hildon_wizard_dialog_new(showed_window, "Wizard test", book));
74 show_test_window(GTK_WIDGET(showed_window));
76 show_test_window(GTK_WIDGET(wizard_dialog));
78 /* Check wizard dialog object has been created properly */
79 fail_if(!HILDON_IS_WIZARD_DIALOG(wizard_dialog),
80 "hildon-wizard-dialog: Creation failed.");
85 fx_teardown_default_wizard_dialog ()
87 gtk_widget_destroy (GTK_WIDGET(wizard_dialog));
90 /* -------------------- Test cases -------------------- */
92 /* ----- Test case for set/get property notebook -----*/
95 * Purpose: Check set and get of property "wizard-notebook"
97 * - Set and get of a regular notebook.
99 START_TEST (test_set_get_property_wizard_notebook_regular)
101 GtkNotebook *book, *old_book;
102 GValue book_value = {0,};
103 GValue ret_book_value = {0,};
108 book = GTK_NOTEBOOK(gtk_notebook_new());
111 box[i] = GTK_BOX(gtk_vbox_new(FALSE, 0));
112 label = GTK_LABEL(gtk_label_new(g_strdup_printf("Label for page %d", i)));
113 gtk_box_pack_start_defaults(box[i], GTK_WIDGET(label));
114 gtk_notebook_append_page(book, GTK_WIDGET(box[i]), NULL);
117 /* Free the old notebook */
118 g_value_init(&ret_book_value, GTK_TYPE_NOTEBOOK);
119 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
120 old_book = g_value_get_object (&ret_book_value);
121 gtk_widget_destroy (GTK_WIDGET(old_book));
123 g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
124 g_value_set_object(&book_value, book);
125 g_value_reset (&ret_book_value);
127 /* Test1: Set and get a regular notebook */
128 /* We don't test dialog title, set during setting of property "wizard-notebook"
129 because it is a visual issue and not a functional one, so it can be changed
130 at any time without breaking any test */
131 g_object_set_property(G_OBJECT(wizard_dialog), "wizard-notebook", &book_value);
132 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
133 fail_if(g_value_get_object(&ret_book_value) != g_value_get_object(&book_value),
134 "hildon-wizard-dialog: set property \"wizard-notebook\" but get_property returned a different notebook object");
139 * Purpose: Check set and get of property "wizard-notebook" with
142 * - Set property to NULL
144 START_TEST (test_set_get_property_wizard_notebook_invalid)
146 GValue book_value = {0,};
147 GValue ret_book_value = {0,};
149 /* Test1: set property to NULL */
150 g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
151 g_value_set_object(&book_value, NULL);
152 g_object_set_property(G_OBJECT(wizard_dialog), "wizard-notebook", &book_value);
153 g_object_get_property(G_OBJECT(wizard_dialog), "wizard-notebook", &ret_book_value);
154 fail_if((g_value_get_object(&ret_book_value) != NULL),
155 "hildon-wizard-dialog: Set \"wizard-notebook\" property to NULL is not forbidden");
160 /* ---------- Suite creation ---------- */
162 Suite *create_hildon_wizard_dialog_suite()
164 /* Create the suite */
165 Suite *s = suite_create("HildonWizardDialog");
167 /* Create test cases */
168 TCase *tc1 = tcase_create("set_get_property_wizard_notebook");
170 /* Create test case for property "wizard-notebook" and add it to the suite */
171 tcase_add_checked_fixture(tc1, fx_setup_default_wizard_dialog, fx_teardown_default_wizard_dialog);
172 tcase_add_test(tc1, test_set_get_property_wizard_notebook_regular);
173 tcase_add_test(tc1, test_set_get_property_wizard_notebook_invalid);
174 suite_add_tcase(s, tc1);
176 /* Return created suite */