Make sure that all timeouts in HildonBanner are removed
[hildon] / tests / check-hildon-banner.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 #ifndef HILDON_DISABLE_DEPRECATED
25
26 #include <stdlib.h>
27 #include <check.h>
28 #include <gtk/gtkmain.h>
29 #include "test_suites.h"
30 #include "check_utils.h"
31 #include <hildon/hildon-banner.h>
32 #include <hildon/hildon-window.h>
33
34 /* -------------------- Fixtures -------------------- */
35
36 static GtkWidget * b_window = NULL;
37
38 static void 
39 fx_setup_default_banner ()
40 {
41   int argc = 0;
42   gtk_init(&argc, NULL);
43   
44   b_window = create_test_window();
45
46  /* Check window object has been created properly */
47   fail_if(!HILDON_IS_WINDOW(b_window),
48           "hildon-banner: Window creation failed.");
49
50   
51 }
52
53 static void 
54 fx_teardown_default_banner ()
55 {
56
57   gtk_widget_destroy(b_window);
58
59 }
60
61 /* -------------------- Test cases -------------------- */
62
63 /* ----- Test case for show_animation -----*/
64
65 /**
66  * Purpose: Check creation of new animation banner with regular values
67  * Cases considered:
68  *    - Create an animation banner with NULL animation name and TEST_STRING text. 
69  *    - Create an animation banner with dummy animation name and "" text.
70  */
71 START_TEST (test_show_animation_regular)
72 {
73   gchar * animation_name=NULL;
74   gchar * text=NULL;
75     
76   HildonBanner * hildon_banner = NULL;
77
78
79   /*Test 1: Create an animation banner with NULL animation name. */
80   text = TEST_STRING;
81   hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,NULL,text));
82
83   fail_if(!HILDON_IS_BANNER(hildon_banner),
84           "hildon-banner: hildon_banner_show_animation failed creating banner.");
85     
86   hildon_banner_set_text(hildon_banner,text);
87   
88   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
89
90   /*Test 2: Create an animation banner with animation name set to "dummy" and text set to "". */
91   text="";
92   animation_name = "dummy";
93   hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,animation_name,text));
94     
95   fail_if(!HILDON_IS_BANNER(hildon_banner),
96           "hildon-banner: hildon_banner_show_animation failed creating banner.");
97     
98   hildon_banner_set_text(hildon_banner,text);
99   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
100     
101 }
102 END_TEST
103
104 /**
105  * Purpose: Check creation of new animation banner with invalid values
106  * Cases considered:
107  *    - Create an animation banner with NULL text. 
108  *    - Create an animation banner with NULL window.
109  */
110 START_TEST (test_show_animation_invalid)
111 {
112   gchar * animation_name=NULL;
113   gchar * text=NULL;
114     
115   HildonBanner * hildon_banner = NULL;
116
117   /*Test 1: Create an animation banner with NULL text. */
118     
119   hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,NULL,NULL));
120     
121   fail_if(HILDON_IS_BANNER(hildon_banner),
122           "hildon-banner: hildon_banner_show_animation failed creating banner.");
123     
124   hildon_banner = NULL;
125     
126   /*Test 2: Create an animation banner with NULL window. */
127   text="";
128   animation_name = "dummy";
129   hildon_banner = HILDON_BANNER(hildon_banner_show_animation(NULL,animation_name,text));
130     
131   fail_if(!HILDON_IS_BANNER(hildon_banner),
132           "hildon-banner: hildon_banner_show_animation failed creating banner.");
133     
134   hildon_banner_set_text(hildon_banner,text);
135   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
136     
137 }
138 END_TEST
139
140 /* ----- Test case for show_progress -----*/
141 /**
142  * Purpose: Check creation of new banner with progress bar with regular values.
143  * Cases considered:
144  *    - Create new progress banner with standard progress bar and "" as text.
145  *    - Create new progress banner with NULL progress bar and TEST_STRING as text.
146  */
147 START_TEST (test_show_progress_regular)
148 {
149   gchar * text=NULL;
150     
151   GtkProgressBar * progress_bar = NULL;
152   HildonBanner * hildon_banner = NULL;
153
154   progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
155
156   /*Test 1: Create progress banner with TEST_STRING as text and basic progress_bar. */
157   text = TEST_STRING;
158   hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,progress_bar,text));
159
160   fail_if(!HILDON_IS_BANNER(hildon_banner),
161           "hildon-banner: hildon_banner_show_progress failed creating banner.");
162     
163   hildon_banner_set_text(hildon_banner,text);
164   hildon_banner_set_fraction(hildon_banner,0.5);
165   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
166
167   hildon_banner = NULL;
168
169   /*Test 2: Create progress banner with "" as text and NULL progress_bar. */
170   text = "";
171   hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,NULL,text));
172     
173   fail_if(!HILDON_IS_BANNER(hildon_banner),
174           "hildon-banner: hildon_banner_show_progress failed creating banner.");
175     
176   hildon_banner_set_text(hildon_banner,text);
177   hildon_banner_set_fraction(hildon_banner,0.2);
178   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
179     
180 }
181 END_TEST
182
183 /**
184  * Purpose: Check creation of new banner with progress bar with invalid values
185  * Cases considered:
186  *    - Create new progress banner with NULL text.
187  *    - Create new progress banner with NULL window.
188  */
189 START_TEST (test_show_progress_invalid)
190 {
191   gchar * text=NULL;
192     
193   GtkProgressBar * progress_bar = NULL;
194   HildonBanner * hildon_banner = NULL;
195
196   progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
197   /*Test 1: Create progress banner with TEST_STRING as text and basic progress_bar. */
198   text = TEST_STRING;
199   hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,progress_bar,NULL));
200
201   /* NULL text avoid create correct banner. */
202   fail_if(HILDON_IS_BANNER(hildon_banner),
203           "hildon-banner: hildon_banner_show_progress failed creating banner.");
204     
205   /*Test 2: Create progress banner with TEST_STRING as text, NULL progress_bar and NULL window */
206   text = TEST_STRING;
207   hildon_banner = HILDON_BANNER(hildon_banner_show_progress(NULL,NULL,text));
208     
209   fail_if(!HILDON_IS_BANNER(hildon_banner),
210           "hildon-banner: hildon_banner_show_progress failed creating banner.");
211     
212   hildon_banner_set_text(hildon_banner,text);
213   hildon_banner_set_fraction(hildon_banner,0.2);
214
215   gtk_widget_destroy(GTK_WIDGET(hildon_banner));
216 }
217 END_TEST
218
219 /* ---------- Suite creation ---------- */
220 Suite *create_hildon_banner_suite()
221 {
222   /* Create the suite */
223   Suite *s = suite_create("HildonBanner");
224
225   /* Create test cases */
226   TCase *tc1 = tcase_create("show_animation");
227   TCase *tc2 = tcase_create("show_progress");
228
229   /* Create unit tests for hildon_banner_show_animation and add it to the suite */
230   tcase_add_checked_fixture(tc1, fx_setup_default_banner, fx_teardown_default_banner);
231   tcase_add_test(tc1, test_show_animation_regular);
232   tcase_add_test(tc1, test_show_animation_invalid);
233   suite_add_tcase (s, tc1);
234
235   /* Create unit tests for hildon_banner_show_animation and add it to the suite */
236   tcase_add_checked_fixture(tc2, fx_setup_default_banner, fx_teardown_default_banner);
237   tcase_add_test(tc2, test_show_progress_regular);
238   tcase_add_test(tc2, test_show_progress_invalid);
239   suite_add_tcase (s, tc2);
240
241
242
243   /* Return created suite */
244   return s;             
245 }
246
247 #endif