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