7a76260848e72ac2bf7052e03bb070b10b932a6d
[hildon] / tests / check-hildon-volumebar.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 "test_suites.h"
27 #include "check_utils.h"
28
29 #include "hildon-window.h"
30 #include "hildon-volumebar.h"
31 #include "hildon-hvolumebar.h"
32 #include "hildon-vvolumebar.h"
33
34 /* -------------------- Fixtures -------------------- */
35
36 static HildonVolumebar *volumebar = NULL;
37 static HildonWindow *window = NULL;
38
39 static void 
40 fx_setup_hvolumebar ()
41 {
42   int argc = 0;
43
44   gtk_init(&argc, NULL);
45
46   volumebar = HILDON_VOLUMEBAR(hildon_hvolumebar_new());
47
48   /* Check volumebar object has been created properly */
49   fail_if(!HILDON_VOLUMEBAR(volumebar),
50           "hildon-volumebar: Creation failed.");
51   
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());
55
56  /* Check window object has been created properly */
57   fail_if(!HILDON_IS_WINDOW(window),
58           "hildon-window: Creation failed.");
59
60   gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
61
62   /* Displays the widget and the window */
63   show_all_test_window (GTK_WIDGET (window));
64 }
65
66 static void
67 fx_setup_vvolumebar ()
68 {
69   int argc = 0;
70
71   gtk_init(&argc, NULL);
72
73   volumebar = HILDON_VOLUMEBAR(hildon_vvolumebar_new());
74
75   /* Check volumebar object has been created properly */
76   fail_if(!HILDON_VOLUMEBAR(volumebar),
77           "hildon-volumebar: Creation failed.");
78
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());
82
83  /* Check window object has been created properly */
84   fail_if(!HILDON_IS_WINDOW(window),
85           "hildon-window: Creation failed.");
86
87   gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
88
89   /* Displays the widget and the window */
90   show_all_test_window (GTK_WIDGET (window));
91 }
92
93 static void
94 fx_teardown_volumebar()
95 {
96    gtk_widget_destroy (GTK_WIDGET (window));
97 }
98
99
100 /* -------------------- Test cases -------------------- */
101
102 /* ----- Test case for set/get_mute -----*/
103
104 /**
105  * Purpose: Check mute usage
106  * Cases considered:
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
111  */
112 START_TEST (test_set_get_mute_regular)
113 {
114   gboolean ret_mute;
115   GValue value = {0,};
116
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");     
125
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");
131
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");    
139   
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");
147 }
148 END_TEST
149
150 /**
151  * Purpose: Test handling of invalid values for get/set_mute interface
152  * Cases considered:
153  *    - Set mute with NULL volumebar object
154  *    - Get mute with NULL volumebar object
155  */
156 START_TEST (test_set_get_mute_invalid)
157 {
158   /* Check volumebar object has been created properly */
159   fail_if(!HILDON_VOLUMEBAR(volumebar),
160           "hildon-volumebar: Creation failed.");
161
162   /* Test1: Check set mute with NULL volumebar object */
163   hildon_volumebar_set_mute(NULL, FALSE);
164
165   /* Test2: Check get mute with NULL volumebar object */
166   hildon_volumebar_get_mute(NULL);
167 }
168 END_TEST
169
170 /* ---------- Suite creation ---------- */
171
172 Suite *create_hildon_volumebar_suite()
173 {
174   /* Create the suite */
175   Suite *s = suite_create("HildonVolumebar");
176
177   /* Create test cases */
178   TCase *tc1 = tcase_create("set_get_mute_hvolumebar");
179   TCase *tc2 = tcase_create("set_get_mute_vvolumebar");
180
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);
186
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);
192
193   /* Return created suite */
194   return s;
195 }
196
197