Release 2.1.94
[hildon] / tests / check-hildon-volumebar.c
1 /*
2  * This file is a part of hildon tests
3  *
4  * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
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.
12  *
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.
17  *
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
21  * 02110-1301 USA
22  *
23  */
24
25 #include <stdlib.h>
26 #include <check.h>
27 #include <gtk/gtkmain.h>
28 #include "test_suites.h"
29 #include "check_utils.h"
30
31 #include <hildon/hildon-window.h>
32 #include <hildon/hildon-volumebar.h>
33 #include <hildon/hildon-hvolumebar.h>
34 #include <hildon/hildon-vvolumebar.h>
35
36 /* -------------------- Fixtures -------------------- */
37
38 static HildonVolumebar *volumebar = NULL;
39 static HildonWindow *window = NULL;
40
41 static void 
42 fx_setup_hvolumebar ()
43 {
44   int argc = 0;
45
46   gtk_init(&argc, NULL);
47
48   volumebar = HILDON_VOLUMEBAR(hildon_hvolumebar_new());
49
50   /* Check volumebar object has been created properly */
51   fail_if(!HILDON_VOLUMEBAR(volumebar),
52           "hildon-volumebar: Creation failed.");
53   
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());
57
58  /* Check window object has been created properly */
59   fail_if(!HILDON_IS_WINDOW(window),
60           "hildon-window: Creation failed.");
61
62   gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
63
64   /* Displays the widget and the window */
65   show_all_test_window (GTK_WIDGET (window));
66 }
67
68 static void
69 fx_setup_vvolumebar ()
70 {
71   int argc = 0;
72
73   gtk_init(&argc, NULL);
74
75   volumebar = HILDON_VOLUMEBAR(hildon_vvolumebar_new());
76
77   /* Check volumebar object has been created properly */
78   fail_if(!HILDON_VOLUMEBAR(volumebar),
79           "hildon-volumebar: Creation failed.");
80
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());
84
85  /* Check window object has been created properly */
86   fail_if(!HILDON_IS_WINDOW(window),
87           "hildon-window: Creation failed.");
88
89   gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(volumebar));
90
91   /* Displays the widget and the window */
92   show_all_test_window (GTK_WIDGET (window));
93 }
94
95 static void
96 fx_teardown_volumebar()
97 {
98    gtk_widget_destroy (GTK_WIDGET (window));
99 }
100
101
102 /* -------------------- Test cases -------------------- */
103
104 /* ----- Test case for set/get_mute -----*/
105
106 /**
107  * Purpose: Check mute usage
108  * Cases considered:
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
113  */
114 START_TEST (test_set_get_mute_regular)
115 {
116   gboolean ret_mute;
117   GValue value = {0,};
118
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");     
127
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");
133
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");    
141   
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");
149 }
150 END_TEST
151
152 /**
153  * Purpose: Test handling of invalid values for get/set_mute interface
154  * Cases considered:
155  *    - Set mute with NULL volumebar object
156  *    - Get mute with NULL volumebar object
157  */
158 START_TEST (test_set_get_mute_invalid)
159 {
160   /* Check volumebar object has been created properly */
161   fail_if(!HILDON_VOLUMEBAR(volumebar),
162           "hildon-volumebar: Creation failed.");
163
164   /* Test1: Check set mute with NULL volumebar object */
165   hildon_volumebar_set_mute(NULL, FALSE);
166
167   /* Test2: Check get mute with NULL volumebar object */
168   hildon_volumebar_get_mute(NULL);
169 }
170 END_TEST
171
172 /* ---------- Suite creation ---------- */
173
174 Suite *create_hildon_volumebar_suite()
175 {
176   /* Create the suite */
177   Suite *s = suite_create("HildonVolumebar");
178
179   /* Create test cases */
180   TCase *tc1 = tcase_create("set_get_mute_hvolumebar");
181   TCase *tc2 = tcase_create("set_get_mute_vvolumebar");
182
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);
188
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);
194
195   /* Return created suite */
196   return s;
197 }
198
199