Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-wizard-dialog.c
1 /*
2  * Copyright (C) 2006 Nokia Corporation.
3  *
4  * Contact: Luc Pionchon <luc.pionchon@nokia.com>
5  *
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.
10  *
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.
15  *
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
19  * 02110-1301 USA
20  *
21  */
22
23 #include <stdlib.h>
24 #include <check.h>
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"
31
32 #include "hildon-wizard-dialog.h"
33
34 #define DEFAULT_NOTEBOOK_PAGES 3
35
36 /* -------------------- Fixtures -------------------- */
37
38 static HildonWizardDialog *wizard_dialog = NULL;
39 static GtkWindow * showed_window = NULL;
40
41 static void 
42 fx_setup_default_wizard_dialog ()
43 {
44   int argc = 0;
45   gint i;
46   GtkNotebook *book;
47   GtkBox *box[DEFAULT_NOTEBOOK_PAGES];
48   GtkLabel *label;
49
50   gtk_init(&argc, NULL);
51
52   showed_window = GTK_WINDOW(create_test_window());
53     
54   /* Create a default notebook for the wizard */
55   book = GTK_NOTEBOOK(gtk_notebook_new());
56
57   /* Check notebook object has been created properly */
58   fail_if(!GTK_IS_NOTEBOOK(book),
59           "hildon-wizard-dialog: Auxiliar notebook creation failed.");  
60
61   for(i=0; i<DEFAULT_NOTEBOOK_PAGES; i++)
62     {
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); 
67     } 
68
69   /* Create the wizard dialog */
70   wizard_dialog = HILDON_WIZARD_DIALOG(hildon_wizard_dialog_new(showed_window, "Wizard test", book));
71
72   show_test_window(GTK_WIDGET(showed_window));
73   
74   show_test_window(GTK_WIDGET(wizard_dialog));
75   
76   /* Check wizard dialog object has been created properly */
77   fail_if(!HILDON_IS_WIZARD_DIALOG(wizard_dialog),
78           "hildon-wizard-dialog: Creation failed.");  
79
80 }
81
82 static void 
83 fx_teardown_default_wizard_dialog ()
84 {
85   gtk_widget_destroy (GTK_WIDGET(wizard_dialog));
86 }
87
88 /* -------------------- Test cases -------------------- */
89
90 /* ----- Test case for set/get property notebook -----*/
91
92 /**
93  * Purpose: Check set and get of property "wizard-notebook"
94  * Cases considered:
95  *    - Set and get of a regular notebook.
96  */
97 START_TEST (test_set_get_property_wizard_notebook_regular)
98 {
99   GtkNotebook *book, *old_book;
100   GValue book_value = {0,};
101   GValue ret_book_value = {0,};
102   gint i;
103   GtkBox *box[2];
104   GtkLabel *label;
105
106   book = GTK_NOTEBOOK(gtk_notebook_new());
107   for(i=0; i<2; i++)
108     {
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); 
113     }
114
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));
120
121   g_value_init(&book_value, GTK_TYPE_NOTEBOOK);
122   g_value_set_object(&book_value, book);
123   g_value_reset (&ret_book_value);
124
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");
133 }
134 END_TEST
135
136 /**
137  * Purpose: Check set and get of property "wizard-notebook" with
138  *          invalid values.
139  * Cases considered:
140  *    - Set property to NULL
141  */
142 START_TEST (test_set_get_property_wizard_notebook_invalid)
143 {
144   GValue book_value = {0,};
145   GValue ret_book_value = {0,};
146
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");
154 }
155 END_TEST
156
157
158 /* ---------- Suite creation ---------- */
159
160 Suite *create_hildon_wizard_dialog_suite()
161 {
162   /* Create the suite */
163   Suite *s = suite_create("HildonWizardDialog");
164
165   /* Create test cases */
166   TCase *tc1 = tcase_create("set_get_property_wizard_notebook");
167
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);
173
174   /* Return created suite */
175   return s;             
176 }
177
178