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/gtkhbox.h>
29 #include <gtk/gtkentry.h>
30 #include <gtk/gtkviewport.h>
31 #include <gtk/gtkscrolledwindow.h>
32 #include "test_suites.h"
33 #include "check_utils.h"
35 #include "hildon-window.h"
38 /* -------------------- Fixtures -------------------- */
40 static HildonWindow *window = NULL;
43 fx_setup_default_window ()
46 gtk_init(&argc, NULL);
48 window = HILDON_WINDOW(hildon_window_new());
49 /* Check window object has been created properly */
50 fail_if(!HILDON_IS_WINDOW(window),
51 "hildon-window: Creation failed.");
53 show_all_test_window(GTK_WIDGET(window));
57 fx_teardown_default_window ()
59 gtk_widget_destroy(GTK_WIDGET(window));
63 /* -------------------- Test cases -------------------- */
65 /* ----- Test case for add_with_scrollbar -----*/
68 * Purpose: Test regular usage
70 * - Add a non viewport child
71 * - Add a viewport child
73 START_TEST (test_add_with_scrollbar_regular)
76 GtkWidget *scrolled_window;
78 GList *children, *first;
80 /* Test1: Check addition of a non viewport child */
81 box = gtk_hbox_new(FALSE, 0);
82 hildon_window_add_with_scrollbar(window, box);
84 show_all_test_window(GTK_WIDGET(window));
86 children = gtk_container_get_children(GTK_CONTAINER(window));
87 first = g_list_first(children);
88 fail_if(first == NULL,
89 "hildon-window: Added a hbox with scrollbar, but window has not children");
90 fail_if (!GTK_IS_SCROLLED_WINDOW(first->data),
91 "hildon-window: Added a hbox with scrollbar, but retrieved child is not a scrolled window");
92 scrolled_window = GTK_WIDGET(first->data);
93 g_list_free(children);
94 children = gtk_container_get_children(GTK_CONTAINER(scrolled_window));
95 first = g_list_first(children);
96 fail_if(first == NULL,
97 "hildon-window: Added a hbox with scrollbar, but scrolled window has not children");
98 fail_if (!GTK_IS_VIEWPORT(first->data),
99 "hildon-window: Added a hbox with scrollbar, but retrieved child from the scrolled window is not a viewport");
100 viewport = GTK_WIDGET(first->data);
101 g_list_free(children);
102 children = gtk_container_get_children(GTK_CONTAINER(viewport));
103 first = g_list_first(children);
104 fail_if(first == NULL,
105 "hildon-window: Added a hbox with scrollbar, but viewport child of the scrolled window has not children");
106 fail_if (!GTK_IS_HBOX(first->data),
107 "hildon-window: Added a hbox with scrollbar, but retrieved child from the viewport of the scrolled window is not a hbox");
108 g_list_free(children);
109 gtk_container_remove(GTK_CONTAINER(window), scrolled_window);
111 /* Test2: Check addition of a viewport child */
112 box = gtk_hbox_new(FALSE, 0);
113 viewport = gtk_viewport_new(GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 100, 10, 10, 1000)),
114 GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 100, 10, 10, 1000)));
115 gtk_container_add(GTK_CONTAINER(viewport), box);
116 hildon_window_add_with_scrollbar(window, viewport);
118 show_all_test_window(GTK_WIDGET(window));
120 children = gtk_container_get_children(GTK_CONTAINER(window));
121 first = g_list_first(children);
122 fail_if(first == NULL,
123 "hildon-window: Added a hbox inside a viewport with scrollbar, but window has not children");
124 fail_if (!GTK_IS_SCROLLED_WINDOW(first->data),
125 "hildon-window: Added a hbox inside a viewport with scrollbar, but retrieved child is not a scrolled window");
126 scrolled_window = GTK_WIDGET(first->data);
127 g_list_free(children);
128 children = gtk_container_get_children(GTK_CONTAINER(scrolled_window));
129 first = g_list_first(children);
130 fail_if(first == NULL,
131 "hildon-window: Added a hbox inside a viewportwith scrollbar, but scrolled window has not children");
132 fail_if (!GTK_IS_VIEWPORT(first->data),
133 "hildon-window: Added a hbox inside a viewport with scrollbar, but retrieved child from the scrolled window is not a viewport");
134 viewport = GTK_WIDGET(first->data);
135 g_list_free(children);
136 children = gtk_container_get_children(GTK_CONTAINER(viewport));
137 first = g_list_first(children);
138 fail_if(first == NULL,
139 "hildon-window: Added a hbox inside a viewport with scrollbar, but viewport child of the scrolled window has not children");
140 fail_if (!GTK_IS_HBOX(first->data),
141 "hildon-window: Added a hbox inside a viewport with scrollbar, but retrieved child from the viewport of the scrolled window is not a hbox");
142 g_list_free(children);
143 gtk_container_remove(GTK_CONTAINER(window), scrolled_window);
148 * Purpose: Check invalid values
151 * - Add a child to a NULL window
152 * - Add a child with a parent already set
154 START_TEST (test_add_with_scrollbar_invalid)
156 GList *children, *first;
160 /* Test1: Add NULL object */
161 hildon_window_add_with_scrollbar(window, NULL);
162 children = gtk_container_get_children(GTK_CONTAINER(window));
163 first = g_list_first(children);
164 fail_if (first != NULL,
165 "hildon-window: Addition of a NULL child is allowed");
166 g_list_free(children);
168 /* Test2: Add to a NULL window */
169 hildon_window_add_with_scrollbar(NULL, gtk_hbox_new(FALSE, 0));
171 /* Test3: Add a widget with a parent already set */
172 hbox = gtk_hbox_new(FALSE, 0);
173 entry = gtk_entry_new();
174 gtk_container_add(GTK_CONTAINER(hbox), entry);
175 hildon_window_add_with_scrollbar(window, entry);
177 show_all_test_window(GTK_WIDGET(window));
179 children = gtk_container_get_children(GTK_CONTAINER(window));
180 first = g_list_first(children);
181 fail_if (first != NULL,
182 "hildon-window: Addition of a child with parent already set is allowed");
183 g_list_free(children);
187 /* ---------- Suite creation ---------- */
189 Suite *create_hildon_window_suite()
191 /* Create the suite */
192 Suite *s = suite_create("HildonWindow");
194 /* Create test cases */
195 TCase *tc1 = tcase_create("add_with_scrollbar");
197 /* Create test case for add_with_scrollbar and add it to the suite */
198 tcase_add_checked_fixture(tc1, fx_setup_default_window, fx_teardown_default_window);
199 tcase_add_test(tc1, test_add_with_scrollbar_regular);
200 tcase_add_test(tc1, test_add_with_scrollbar_invalid);
201 suite_add_tcase (s, tc1);
203 /* Return created suite */