Make sure that all timeouts in HildonBanner are removed
[hildon] / tests / check-hildon-wizard-dialog.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include <stdlib.h>
26 #include <check.h>
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"
33
34 #include <hildon/hildon-wizard-dialog.h>
35
36 #define DEFAULT_NOTEBOOK_PAGES 3
37
38 /* -------------------- Fixtures -------------------- */
39
40 static HildonWizardDialog *wizard_dialog = NULL;
41 static GtkWindow * showed_window = NULL;
42
43 static void 
44 fx_setup_default_wizard_dialog ()
45 {
46   int argc = 0;
47   gint i;
48   GtkNotebook *book;
49   GtkBox *box[DEFAULT_NOTEBOOK_PAGES];
50   GtkLabel *label;
51
52   gtk_init(&argc, NULL);
53
54   showed_window = GTK_WINDOW(create_test_window());
55     
56   /* Create a default notebook for the wizard */
57   book = GTK_NOTEBOOK(gtk_notebook_new());
58
59   /* Check notebook object has been created properly */
60   fail_if(!GTK_IS_NOTEBOOK(book),
61           "hildon-wizard-dialog: Auxiliar notebook creation failed.");  
62
63   for(i=0; i<DEFAULT_NOTEBOOK_PAGES; i++)
64     {
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); 
69     } 
70
71   /* Create the wizard dialog */
72   wizard_dialog = HILDON_WIZARD_DIALOG(hildon_wizard_dialog_new(showed_window, "Wizard test", book));
73
74   show_test_window(GTK_WIDGET(showed_window));
75   
76   show_test_window(GTK_WIDGET(wizard_dialog));
77   
78   /* Check wizard dialog object has been created properly */
79   fail_if(!HILDON_IS_WIZARD_DIALOG(wizard_dialog),
80           "hildon-wizard-dialog: Creation failed.");  
81
82 }
83
84 static void 
85 fx_teardown_default_wizard_dialog ()
86 {
87   gtk_widget_destroy (GTK_WIDGET(wizard_dialog));
88 }
89
90 /* -------------------- Test cases -------------------- */
91
92 /* ----- Test case for set/get property notebook -----*/
93
94 /**
95  * Purpose: Check set and get of property "wizard-notebook"
96  * Cases considered:
97  *    - Set and get of a regular notebook.
98  */
99 START_TEST (test_set_get_property_wizard_notebook_regular)
100 {
101   GtkNotebook *book, *old_book;
102   GValue book_value = {0,};
103   GValue ret_book_value = {0,};
104   gint i;
105   GtkBox *box[2];
106   GtkLabel *label;
107
108   book = GTK_NOTEBOOK(gtk_notebook_new());
109   for(i=0; i<2; i++)
110     {
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); 
115     }
116
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));
122
123   g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
124   g_value_set_object(&book_value, book);
125   g_value_reset (&ret_book_value);
126
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");
135 }
136 END_TEST
137
138 /**
139  * Purpose: Check set and get of property "wizard-notebook" with
140  *          invalid values.
141  * Cases considered:
142  *    - Set property to NULL
143  */
144 START_TEST (test_set_get_property_wizard_notebook_invalid)
145 {
146   GValue book_value = {0,};
147   GValue ret_book_value = {0,};
148
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");
156 }
157 END_TEST
158
159
160 /* ---------- Suite creation ---------- */
161
162 Suite *create_hildon_wizard_dialog_suite()
163 {
164   /* Create the suite */
165   Suite *s = suite_create("HildonWizardDialog");
166
167   /* Create test cases */
168   TCase *tc1 = tcase_create("set_get_property_wizard_notebook");
169
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);
175
176   /* Return created suite */
177   return s;             
178 }
179
180