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 "test_suites.h"
29 #include "check_utils.h"
31 #include "hildon-window.h"
32 #include "hildon-volumebar.h"
33 #include "hildon-hvolumebar.h"
34 #include "hildon-vvolumebar.h"
36 /* -------------------- Fixtures -------------------- */
38 static HildonVolumebar *volumebar = NULL;
39 static HildonWindow *window = NULL;
42 fx_setup_hvolumebar ()
46 gtk_init(&argc, NULL);
48 volumebar = HILDON_VOLUMEBAR(hildon_hvolumebar_new());
50 /* Check volumebar object has been created properly */
51 fail_if(!HILDON_VOLUMEBAR(volumebar),
52 "hildon-volumebar: Creation failed.");
54 /* Add volumebar to a window to avoid gtk warnings when
55 trying to set focus to parent window */
56 window = HILDON_WINDOW(hildon_window_new());
58 /* Check window object has been created properly */
59 fail_if(!HILDON_IS_WINDOW(window),
60 "hildon-window: Creation failed.");
62 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
64 /* Displays the widget and the window */
65 show_all_test_window (GTK_WIDGET (window));
69 fx_setup_vvolumebar ()
73 gtk_init(&argc, NULL);
75 volumebar = HILDON_VOLUMEBAR(hildon_vvolumebar_new());
77 /* Check volumebar object has been created properly */
78 fail_if(!HILDON_VOLUMEBAR(volumebar),
79 "hildon-volumebar: Creation failed.");
81 /* Add volumebar to a window to avoid gtk warnings when
82 trying to set focus to parent window */
83 window = HILDON_WINDOW(hildon_window_new());
85 /* Check window object has been created properly */
86 fail_if(!HILDON_IS_WINDOW(window),
87 "hildon-window: Creation failed.");
89 gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
91 /* Displays the widget and the window */
92 show_all_test_window (GTK_WIDGET (window));
96 fx_teardown_volumebar()
98 gtk_widget_destroy (GTK_WIDGET (window));
102 /* -------------------- Test cases -------------------- */
104 /* ----- Test case for set/get_mute -----*/
107 * Purpose: Check mute usage
109 * - Set mute ON when volumebar is focusable
110 * - Set mute OFF when volumebar is focusable
111 * - Set mute ON when volumebar is not focusable
112 * - Set mute OFF when volumebar is not focusable
114 START_TEST (test_set_get_mute_regular)
119 /* Test1: Set mute in focusable state */
120 g_value_init(&value, G_TYPE_BOOLEAN);
121 g_value_set_boolean(&value, TRUE);
122 g_object_set_property(G_OBJECT(volumebar), "can-focus", &value);
123 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE);
124 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
125 fail_if(ret_mute != TRUE,
126 "hildon-volumebar: Set mute to TRUE (volumebar is focusable), but get mute returned FALSE");
128 /* Test2: Unset mute in focusable state */
129 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE);
130 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
131 fail_if(ret_mute != FALSE,
132 "hildon-volumebar: Set mute to FALSE (volumebar is focusable), but get mute returned TRUE");
134 /* Test3: Set mute in not focusable state */
135 g_value_set_boolean(&value, FALSE);
136 g_object_set_property(G_OBJECT(volumebar), "can-focus", &value);
137 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), TRUE);
138 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
139 fail_if(ret_mute != TRUE,
140 "hildon-volumebar: Set mute to TRUE (volumebar is not focusable), but get mute returned FALSE");
142 /* Test4: Unset mute in not focusable state */
143 hildon_volumebar_set_mute(HILDON_VOLUMEBAR(volumebar), FALSE);
144 ret_mute = hildon_volumebar_get_mute(HILDON_VOLUMEBAR(volumebar));
145 fail_if(ret_mute != FALSE,
146 "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but get mute returned TRUE");
147 fail_if(gtk_window_get_focus(GTK_WINDOW(window)) != NULL,
148 "hildon-volumebar: Set mute to FALSE (volumebar is not focusable), but parent window has focused child");
153 * Purpose: Test handling of invalid values for get/set_mute interface
155 * - Set mute with NULL volumebar object
156 * - Get mute with NULL volumebar object
158 START_TEST (test_set_get_mute_invalid)
160 /* Check volumebar object has been created properly */
161 fail_if(!HILDON_VOLUMEBAR(volumebar),
162 "hildon-volumebar: Creation failed.");
164 /* Test1: Check set mute with NULL volumebar object */
165 hildon_volumebar_set_mute(NULL, FALSE);
167 /* Test2: Check get mute with NULL volumebar object */
168 hildon_volumebar_get_mute(NULL);
172 /* ---------- Suite creation ---------- */
174 Suite *create_hildon_volumebar_suite()
176 /* Create the suite */
177 Suite *s = suite_create("HildonVolumebar");
179 /* Create test cases */
180 TCase *tc1 = tcase_create("set_get_mute_hvolumebar");
181 TCase *tc2 = tcase_create("set_get_mute_vvolumebar");
183 /* Create test case for set/get_mute (hvolumebar) and add it to the suite */
184 tcase_add_checked_fixture(tc1, fx_setup_hvolumebar, fx_teardown_volumebar);
185 tcase_add_test(tc1, test_set_get_mute_regular);
186 tcase_add_test(tc1, test_set_get_mute_invalid);
187 suite_add_tcase (s, tc1);
189 /* Create test case for set/get_mute (vvolumebar) and add it to the suite */
190 tcase_add_checked_fixture(tc2, fx_setup_vvolumebar, fx_teardown_volumebar);
191 tcase_add_test(tc2, test_set_get_mute_regular);
192 tcase_add_test(tc2, test_set_get_mute_invalid);
193 suite_add_tcase (s, tc2);
195 /* Return created suite */