Adding missing debian changelog. Modyfying hildon-banner to allow creation with null...
[hildon] / tests / check-hildon-composite-widget.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/gtkwindow.h>
27 #include <gtk/gtkentry.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30 #include <unistd.h>
31
32 #include "hildon-composite-widget.h"
33 #include "hildon-time-editor.h"
34
35 /* -------------------- Fixtures ---------------------- */
36
37 static void 
38 fx_setup_gtk ()
39 {
40   int argc = 0;
41   gtk_init(&argc, NULL);
42 }
43
44 static void 
45 fx_teardown_gtk ()
46 {
47 }
48
49 /* -------------------- Test cases -------------------- */
50
51 /* ----- Test case for focus -----*/
52
53 /**
54  * Purpose: Test regular usage
55  * Cases considered:
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
59  */
60 START_TEST (test_focus_regular)
61 {
62   GtkWidget *time_editor;
63   GtkWindow *window;
64
65   /* Test1: check with a composite widget */
66   time_editor = hildon_time_editor_new();
67
68   hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT);
69
70   gtk_widget_destroy(GTK_WIDGET(time_editor));
71
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);
76
77   /* show widget */
78   show_all_test_window(GTK_WIDGET(window));
79
80   hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT);
81
82   gtk_widget_destroy(GTK_WIDGET(window));
83
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);
88
89   /* show widget */
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);
93
94   gtk_widget_destroy(GTK_WIDGET(window));  
95 }
96 END_TEST
97
98 /**
99  * Purpose: Test invalid usage
100  * Cases considered:
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)
106  */
107 START_TEST (test_focus_invalid)
108 {
109   GtkWidget *time_editor, *entry;
110   GtkWindow *window;
111   
112   /* Test1: check with a composite widget */
113   entry = gtk_entry_new();
114   hildon_composite_widget_focus(entry, GTK_DIR_RIGHT);
115   
116   gtk_widget_destroy(GTK_WIDGET(entry));
117   
118   /* Test2: with NULL widget */
119   hildon_composite_widget_focus(NULL, GTK_DIR_RIGHT);
120   
121   /* Test3: with invalid direction */
122   time_editor = hildon_time_editor_new();
123   hildon_composite_widget_focus(time_editor,GTK_DIR_RIGHT+1);
124
125   gtk_widget_destroy(GTK_WIDGET(time_editor));
126   
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);
131
132   show_all_test_window(GTK_WIDGET(window));
133   hildon_composite_widget_focus(entry, GTK_DIR_RIGHT);
134
135   gtk_widget_destroy(GTK_WIDGET(window));
136   
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);
141
142   show_all_test_window(GTK_WIDGET(window));
143   hildon_composite_widget_focus(time_editor, GTK_DIR_RIGHT+1);
144
145   gtk_widget_destroy(GTK_WIDGET(window));
146 }
147 END_TEST
148
149 /* ---------- Suite creation ---------- */
150
151 Suite *create_hildon_composite_widget_suite()
152 {
153   /* Create the suite */
154   Suite *s = suite_create("HildonCompositeWidget");
155
156   /* Create test cases */
157   TCase *tc1 = tcase_create("focus");
158
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);
164
165   /* Return created suite */
166   return s;             
167 }
168
169