aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-banner.c
blob: ed3ee428cd6bbec1daa033cbb3e430ca3a07e74d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/*
 * This file is a part of hildon tests
 *
 * Copyright (C) 2006, 2007 Nokia Corporation, all rights reserved.
 *
 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 */
#ifndef HILDON_DISABLE_DEPRECATED

#include <stdlib.h>
#include <check.h>
#include <gtk/gtkmain.h>
#include "test_suites.h"
#include "check_utils.h"
#include <hildon/hildon-banner.h>
#include <hildon/hildon-window.h>

/* -------------------- Fixtures -------------------- */

static GtkWidget * b_window = NULL;

static void 
fx_setup_default_banner ()
{
  int argc = 0;
  gtk_init(&argc, NULL);
  
  b_window = create_test_window();

 /* Check window object has been created properly */
  fail_if(!HILDON_IS_WINDOW(b_window),
          "hildon-banner: Window creation failed.");

  
}

static void 
fx_teardown_default_banner ()
{

  gtk_widget_destroy(b_window);

}

/* -------------------- Test cases -------------------- */

/* ----- Test case for show_animation -----*/

/**
 * Purpose: Check creation of new animation banner with regular values
 * Cases considered:
 *    - Create an animation banner with NULL animation name and TEST_STRING text. 
 *    - Create an animation banner with dummy animation name and "" text.
 */
START_TEST (test_show_animation_regular)
{
  gchar * animation_name=NULL;
  gchar * text=NULL;
    
  HildonBanner * hildon_banner = NULL;


  /*Test 1: Create an animation banner with NULL animation name. */
  text = TEST_STRING;
  hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,NULL,text));

  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_animation failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  
  gtk_widget_destroy(GTK_WIDGET(hildon_banner));

  /*Test 2: Create an animation banner with animation name set to "dummy" and text set to "". */
  text="";
  animation_name = "dummy";
  hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,animation_name,text));
    
  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_animation failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  gtk_widget_destroy(GTK_WIDGET(hildon_banner));
    
}
END_TEST

/**
 * Purpose: Check creation of new animation banner with invalid values
 * Cases considered:
 *    - Create an animation banner with NULL text. 
 *    - Create an animation banner with NULL window.
 */
START_TEST (test_show_animation_invalid)
{
  gchar * animation_name=NULL;
  gchar * text=NULL;
    
  HildonBanner * hildon_banner = NULL;

  /*Test 1: Create an animation banner with NULL text. */
    
  hildon_banner = HILDON_BANNER(hildon_banner_show_animation(b_window,NULL,NULL));
    
  fail_if(HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_animation failed creating banner.");
    
  hildon_banner = NULL;
    
  /*Test 2: Create an animation banner with NULL window. */
  text="";
  animation_name = "dummy";
  hildon_banner = HILDON_BANNER(hildon_banner_show_animation(NULL,animation_name,text));
    
  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_animation failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  gtk_widget_destroy(GTK_WIDGET(hildon_banner));
    
}
END_TEST

/* ----- Test case for show_progress -----*/
/**
 * Purpose: Check creation of new banner with progress bar with regular values.
 * Cases considered:
 *    - Create new progress banner with standard progress bar and "" as text.
 *    - Create new progress banner with NULL progress bar and TEST_STRING as text.
 */
START_TEST (test_show_progress_regular)
{
  gchar * text=NULL;
    
  GtkProgressBar * progress_bar = NULL;
  HildonBanner * hildon_banner = NULL;

  progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());

  /*Test 1: Create progress banner with TEST_STRING as text and basic progress_bar. */
  text = TEST_STRING;
  hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,progress_bar,text));

  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_progress failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  hildon_banner_set_fraction(hildon_banner,0.5);
  gtk_widget_destroy(GTK_WIDGET(hildon_banner));

  hildon_banner = NULL;

  /*Test 2: Create progress banner with "" as text and NULL progress_bar. */
  text = "";
  hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,NULL,text));
    
  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_progress failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  hildon_banner_set_fraction(hildon_banner,0.2);
  gtk_widget_destroy(GTK_WIDGET(hildon_banner));
    
}
END_TEST

/**
 * Purpose: Check creation of new banner with progress bar with invalid values
 * Cases considered:
 *    - Create new progress banner with NULL text.
 *    - Create new progress banner with NULL window.
 */
START_TEST (test_show_progress_invalid)
{
  gchar * text=NULL;
    
  GtkProgressBar * progress_bar = NULL;
  HildonBanner * hildon_banner = NULL;

  progress_bar = GTK_PROGRESS_BAR(gtk_progress_bar_new());
  /*Test 1: Create progress banner with TEST_STRING as text and basic progress_bar. */
  text = TEST_STRING;
  hildon_banner = HILDON_BANNER(hildon_banner_show_progress(b_window,progress_bar,NULL));

  /* NULL text avoid create correct banner. */
  fail_if(HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_progress failed creating banner.");
    
  /*Test 2: Create progress banner with TEST_STRING as text, NULL progress_bar and NULL window */
  text = TEST_STRING;
  hildon_banner = HILDON_BANNER(hildon_banner_show_progress(NULL,NULL,text));
    
  fail_if(!HILDON_IS_BANNER(hildon_banner),
          "hildon-banner: hildon_banner_show_progress failed creating banner.");
    
  hildon_banner_set_text(hildon_banner,text);
  hildon_banner_set_fraction(hildon_banner,0.2);

  gtk_widget_destroy(GTK_WIDGET(hildon_banner));
}
END_TEST

/* ---------- Suite creation ---------- */
Suite *create_hildon_banner_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonBanner");

  /* Create test cases */
  TCase *tc1 = tcase_create("show_animation");
  TCase *tc2 = tcase_create("show_progress");

  /* Create unit tests for hildon_banner_show_animation and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_banner, fx_teardown_default_banner);
  tcase_add_test(tc1, test_show_animation_regular);
  tcase_add_test(tc1, test_show_animation_invalid);
  suite_add_tcase (s, tc1);

  /* Create unit tests for hildon_banner_show_animation and add it to the suite */
  tcase_add_checked_fixture(tc2, fx_setup_default_banner, fx_teardown_default_banner);
  tcase_add_test(tc2, test_show_progress_regular);
  tcase_add_test(tc2, test_show_progress_invalid);
  suite_add_tcase (s, tc2);



  /* Return created suite */
  return s;             
}

#endif