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