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/gtkliststore.h>
29 #include <gtk/gtkcellrenderer.h>
30 #include <gtk/gtktreeviewcolumn.h>
31 #include <gtk/gtktreemodel.h>
32 #include <gtk/gtkscrolledwindow.h>
33 #include <gtk/gtktreeview.h>
34 #include <gtk/gtkbox.h>
35 #include <gtk/gtkcellrenderertext.h>
36 #include <gtk/gtkbutton.h>
37 #include <gtk/gtkvbox.h>
38 #include <gtk/gtkfixed.h>
39 #include <gtk/gtklabel.h>
40 #include <glib/gprintf.h>
41 #include "test_suites.h"
43 #include <hildon/hildon-scroll-area.h>
52 /* -------------------- Fixtures -------------------- */
55 fx_setup_default_scroll_area ()
59 gtk_init(&argc, NULL);
62 /* -------------------- Test cases -------------------- */
64 /* ------------ Test case for scroll-area --------------*/
68 * Helper function used to create the tests, it creates a treemodel
69 * and inserts test data to it. This function it is used in the
70 * create_view_and_model function.
74 create_and_fill_model (void)
79 store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);
83 /* Append a row and fill in some data */
84 gtk_list_store_append (store, &iter);
85 gtk_list_store_set (store, &iter,
86 COL_NAME, "Heinz El-Mann",
90 /* append another row and fill in some data */
91 gtk_list_store_append (store, &iter);
92 gtk_list_store_set (store, &iter,
97 /* ... and a third row */
98 gtk_list_store_append (store, &iter);
99 gtk_list_store_set (store, &iter,
100 COL_NAME, "Joe Bungop",
104 return GTK_TREE_MODEL (store);
109 * Helper function used to create the tests, it creates a treeview and
110 * a treemodel, it returns the treeview with the treemodel associated.
114 create_view_and_model (void)
116 GtkTreeViewColumn *col;
117 GtkCellRenderer *renderer;
121 view = gtk_tree_view_new ();
123 /* --- Column #1 --- */
125 renderer = gtk_cell_renderer_text_new ();
126 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
133 /* --- Column #2 --- */
135 col = gtk_tree_view_column_new();
137 renderer = gtk_cell_renderer_text_new ();
138 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (view),
145 model = create_and_fill_model ();
147 gtk_tree_view_set_model (GTK_TREE_VIEW (view), model);
149 g_object_unref (model); /* destroy model automatically with view */
155 * Purpose: Check the construction of the scroll-area
157 * - Create a regular case of construction
158 * - Create a scroll area with a label, it is not a proper case but it is
159 * returning a proper value
161 START_TEST (test_create_scroll_area_regular)
163 GtkWidget *button[2];
165 GtkWidget *scroll_window;
171 /* Test1: Create a regular case of construction*/
172 box = gtk_vbox_new(FALSE,0);
173 scroll_window = gtk_scrolled_window_new(NULL, NULL);
175 treew = create_view_and_model();
177 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_window),
178 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
181 button[i] = gtk_button_new_with_label("Junk button");
183 gtk_box_pack_start_defaults(GTK_BOX(box), button[0]);
185 fixed = hildon_scroll_area_new(scroll_window, treew);
187 /* Check the return value is a proper gtk_fixed object */
188 if (!GTK_FIXED(fixed))
190 gtk_widget_destroy (GTK_WIDGET (scroll_window));
191 gtk_widget_destroy (GTK_WIDGET (box));
192 gtk_widget_destroy (GTK_WIDGET (treew));
193 fail("hildon-scroll-area: Creation failed.");
196 gtk_box_pack_start_defaults(GTK_BOX(box), fixed);
197 gtk_box_pack_start_defaults(GTK_BOX(box), button[1]);
199 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll_window), box);
201 gtk_widget_destroy (GTK_WIDGET (scroll_window));
203 /* Test2: Create a scroll area with a label, it is not a proper case but it is
204 returning a proper value */
205 scroll_window = gtk_scrolled_window_new(NULL, NULL);
207 label = gtk_label_new("This is a label widget example");
208 fixed = hildon_scroll_area_new(scroll_window, label);
210 /* Check the return value is a fixed value when we try to create the scroll area with a label */
211 if (!GTK_FIXED(fixed))
213 gtk_widget_destroy (GTK_WIDGET (label));
214 gtk_widget_destroy (GTK_WIDGET (scroll_window));
215 fail("hildon-scroll-area: Creation with a label did not return a proper fixed object");
217 gtk_widget_destroy (GTK_WIDGET (label));
218 gtk_widget_destroy (GTK_WIDGET (scroll_window));
223 * Purpose: Check the construction of the scroll-area
226 * - Create with NULL widgets
227 * - Create with actual invalid widget instead of the scrolled-window
228 * - Create with actual invalid widget instead of the treeview
230 START_TEST (test_create_scroll_area_invalid)
235 GtkWidget *scroll_window;
237 fixed = hildon_scroll_area_new(NULL, NULL);
239 /* Test1: Create with NULL widgets */
240 fail_if(fixed != NULL,
241 "hildon-scroll-area: Invalid creation did not return a NULL value.");
243 treew = create_view_and_model();
244 label = gtk_label_new("This is an invalid example widget");
245 fixed = hildon_scroll_area_new(label, treew);
247 /* Test2: Create with actual invalid widget instead of the scrolled-window */
248 if (GTK_FIXED(fixed))
250 gtk_widget_destroy (GTK_WIDGET (label));
251 gtk_widget_destroy (GTK_WIDGET (treew));
252 fail ("hildon-scroll-area: Invalid creation did not return a NULL value when we set an invalid value in the first parameter.");
255 gtk_widget_destroy (GTK_WIDGET (label));
256 gtk_widget_destroy (GTK_WIDGET (treew));
258 scroll_window = gtk_scrolled_window_new(NULL, NULL);
259 fixed = hildon_scroll_area_new(scroll_window, label);
261 /* Test3: Create with actual invalid widget instead of the treeview */
262 if (!GTK_FIXED(fixed))
264 gtk_widget_destroy (GTK_WIDGET (scroll_window));
265 fail ("hildon-scroll-area: Invalid creation returned a NULL value when we set an invalid value in the second parameter.");
268 gtk_widget_destroy (GTK_WIDGET (scroll_window));
274 /* ---------- Suite creation ---------- */
276 Suite *create_hildon_scroll_area_suite()
278 /* Create the suite */
279 Suite *s = suite_create("HildonScrollArea");
281 /* Create test cases */
282 TCase *tc1 = tcase_create("create_scroll_area");
284 /* Create test case for scroll-area and add it to the suite */
285 tcase_add_checked_fixture(tc1, fx_setup_default_scroll_area, NULL);
286 tcase_add_test(tc1, test_create_scroll_area_regular);
287 tcase_add_test(tc1, test_create_scroll_area_invalid);
288 suite_add_tcase(s, tc1);
290 /* Return created suite */