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 "test_suites.h"
27 #include "check_utils.h"
29 #include "hildon-window.h"
30 #include "hildon-volumebar.h"
31 #include "hildon-hvolumebar.h"
32 #include "hildon-vvolumebar.h"
34 /* -------------------- Fixtures -------------------- */
36 static HildonVolumebar *volumebar = NULL;
37 static HildonWindow *window = NULL;
40 fx_setup_hvolumebar ()
44 gtk_init(&argc, NULL);
46 volumebar = HILDON_VOLUMEBAR(hildon_hvolumebar_new());
48 /* Check volumebar object has been created properly */
49 fail_if(!HILDON_VOLUMEBAR(volumebar),
50 "hildon-volumebar: Creation failed.");
52 /* Add volumebar to a window to avoid gtk warnings when
53 trying to set focus to parent window */
54 window = HILDON_WINDOW(hildon_window_new());
56 /* Check window object has been created properly */
57 fail_if(!HILDON_IS_WINDOW(window),
58 "hildon-window: Creation failed.");
60 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
62 /* Displays the widget and the window */
63 show_all_test_window (GTK_WIDGET (window));
67 fx_setup_vvolumebar ()
71 gtk_init(&argc, NULL);
73 volumebar = HILDON_VOLUMEBAR(hildon_vvolumebar_new());
75 /* Check volumebar object has been created properly */
76 fail_if(!HILDON_VOLUMEBAR(volumebar),
77 "hildon-volumebar: Creation failed.");
79 /* Add volumebar to a window to avoid gtk warnings when
80 trying to set focus to parent window */
81 window = HILDON_WINDOW(hildon_window_new());
83 /* Check window object has been created properly */
84 fail_if(!HILDON_IS_WINDOW(window),
85 "hildon-window: Creation failed.");
87 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
89 /* Displays the widget and the window */
90 show_all_test_window (GTK_WIDGET (window));
94 fx_teardown_volumebar()
96 gtk_widget_destroy (GTK_WIDGET (window));
100 /* -------------------- Test cases -------------------- */
102 /* ----- Test case for set/get_mute -----*/
105 * Purpose: Check mute usage
107 * - Set mute ON when volumebar is focusable
108 * - Set mute OFF when volumebar is focusable
109 * - Set mute ON when volumebar is not focusable
110 * - Set mute OFF when volumebar is not focusable
112 START_TEST (test_set_get_mute_regular)
117 /* Test1: Set mute in focusable state */
118 g_value_init(&value, G_TYPE_BOOLEAN);
119 g_value_set_boolean(&value, TRUE);
120 g_object_set_property(G_OBJECT(volumebar), "can-focus", &value);
121 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE);
122 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
123 fail_if(ret_mute != TRUE,
124 "hildon-volumebar: Set mute to TRUE (volumebar is focusable), but get mute returned FALSE");
126 /* Test2: Unset mute in focusable state */
127 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE);
128 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
129 fail_if(ret_mute != FALSE,
130 "hildon-volumebar: Set mute to FALSE (volumebar is focusable), but get mute returned TRUE");
132 /* Test3: Set mute in not focusable state */
133 g_value_set_boolean(&value, FALSE);
134 g_object_set_property(G_OBJECT(volumebar), "can-focus", &value);
135 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE);
136 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
137 fail_if(ret_mute != TRUE,
138 "hildon-volumebar: Set mute to TRUE (volumebar is not focusable), but get mute returned FALSE");
140 /* Test4: Unset mute in not focusable state */
141 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE);
142 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
143 fail_if(ret_mute != FALSE,
144 "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but get mute returned TRUE");
145 fail_if(gtk_window_get_focus(GTK_WINDOW(window)) != NULL,
146 "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but parent window has focused child");
151 * Purpose: Test handling of invalid values for get/set_mute interface
153 * - Set mute with NULL volumebar object
154 * - Get mute with NULL volumebar object
156 START_TEST (test_set_get_mute_invalid)
158 /* Check volumebar object has been created properly */
159 fail_if(!HILDON_VOLUMEBAR(volumebar),
160 "hildon-volumebar: Creation failed.");
162 /* Test1: Check set mute with NULL volumebar object */
163 hildon_volumebar_set_mute(NULL, FALSE);
165 /* Test2: Check get mute with NULL volumebar object */
166 hildon_volumebar_get_mute(NULL);
170 /* ---------- Suite creation ---------- */
172 Suite *create_hildon_volumebar_suite()
174 /* Create the suite */
175 Suite *s = suite_create("HildonVolumebar");
177 /* Create test cases */
178 TCase *tc1 = tcase_create("set_get_mute_hvolumebar");
179 TCase *tc2 = tcase_create("set_get_mute_vvolumebar");
181 /* Create test case for set/get_mute (hvolumebar) and add it to the suite */
182 tcase_add_checked_fixture(tc1, fx_setup_hvolumebar, fx_teardown_volumebar);
183 tcase_add_test(tc1, test_set_get_mute_regular);
184 tcase_add_test(tc1, test_set_get_mute_invalid);
185 suite_add_tcase (s, tc1);
187 /* Create test case for set/get_mute (vvolumebar) and add it to the suite */
188 tcase_add_checked_fixture(tc2, fx_setup_vvolumebar, fx_teardown_volumebar);
189 tcase_add_test(tc2, test_set_get_mute_regular);
190 tcase_add_test(tc2, test_set_get_mute_invalid);
191 suite_add_tcase (s, tc2);
193 /* Return created suite */