2 * Copyright (C) 2006 Nokia Corporation.
4 * Contact: Luc Pionchon <luc.pionchon@nokia.com>
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.
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.
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
25 #include <gtk/gtkmain.h>
26 #include <gtk/gtkwindow.h>
27 #include <gtk/gtkentry.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
32 #include "hildon-composite-widget.h"
33 #include "hildon-time-editor.h"
35 /* -------------------- Fixtures ---------------------- */
41 gtk_init(&argc, NULL);
49 /* -------------------- Test cases -------------------- */
51 /* ----- Test case for focus -----*/
54 * Purpose: Test regular usage
56 * - Check with a composite widget (hildon_time_editor)
57 * - Check with a composite widget (hildon_time_editor) inside a window
58 * - check with a composite widget (hildon_time_editor) inside a window and a focus already given to the window
60 START_TEST (test_focus_regular)
62 GtkWidget *time_editor;
65 /* Test1: check with a composite widget */
66 time_editor = hildon_time_editor_new();
68 hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT);
70 gtk_widget_destroy(GTK_WIDGET(time_editor));
72 /* Test2: check with a composite widget (inside a window) */
73 window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
74 time_editor = hildon_time_editor_new();
75 gtk_container_add(GTK_CONTAINER(window), time_editor);
78 show_all_test_window(GTK_WIDGET(window));
80 hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT);
82 gtk_widget_destroy(GTK_WIDGET(window));
84 /* Test3: check with a composite widget (hildon_time_editor) inside a window and a focus already given to the window */
85 window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
86 time_editor = hildon_time_editor_new();
87 gtk_container_add(GTK_CONTAINER(window), time_editor);
90 show_all_test_window(GTK_WIDGET(window));
91 gtk_widget_grab_focus(GTK_WIDGET(window));
92 hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT);
94 gtk_widget_destroy(GTK_WIDGET(window));
99 * Purpose: Test invalid usage
101 * - Check with non composite widget (gtkentry)
102 * - Check with NULL object
103 * - Check with invalid direction
104 * - Check with non composite widget (gtkentry) (inside a window)
105 * - Check with invalid direction (inside a window)
107 START_TEST (test_focus_invalid)
109 GtkWidget *time_editor, *entry;
112 /* Test1: check with a composite widget */
113 entry = gtk_entry_new();
114 hildon_composite_widget_focus(entry, GTK_DIR_RIGHT);
116 gtk_widget_destroy(GTK_WIDGET(entry));
118 /* Test2: with NULL widget */
119 hildon_composite_widget_focus(NULL, GTK_DIR_RIGHT);
121 /* Test3: with invalid direction */
122 time_editor = hildon_time_editor_new();
123 hildon_composite_widget_focus(time_editor,GTK_DIR_RIGHT+1);
125 gtk_widget_destroy(GTK_WIDGET(time_editor));
127 /* Test4: Check with non composite widget (gtkentry) (inside a window) */
128 window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
129 entry = gtk_entry_new();
130 gtk_container_add(GTK_CONTAINER(window), entry);
132 show_all_test_window(GTK_WIDGET(window));
133 hildon_composite_widget_focus(entry, GTK_DIR_RIGHT);
135 gtk_widget_destroy(GTK_WIDGET(window));
137 /* Test5: Check with invalid direction (inside a window) */
138 window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
139 time_editor = hildon_time_editor_new();
140 gtk_container_add(GTK_CONTAINER(window), time_editor);
142 show_all_test_window(GTK_WIDGET(window));
143 hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT+1);
145 gtk_widget_destroy(GTK_WIDGET(window));
149 /* ---------- Suite creation ---------- */
151 Suite *create_hildon_composite_widget_suite()
153 /* Create the suite */
154 Suite *s = suite_create("HildonCompositeWidget");
156 /* Create test cases */
157 TCase *tc1 = tcase_create("focus");
159 /* Create test case for focus and add it to the suite */
160 tcase_add_checked_fixture(tc1, fx_setup_gtk, fx_teardown_gtk);
161 tcase_add_test(tc1, test_focus_regular);
162 tcase_add_test(tc1, test_focus_invalid);
163 suite_add_tcase (s, tc1);
165 /* Return created suite */