aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-program.c
blob: db554fd561b7bee5080455e4e75821cfbcb2d991 (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
/*
 * 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
 *
 */

#include <stdlib.h>
#include <check.h>
#include <gtk/gtkmain.h>
#include <gtk/gtklabel.h>
#include "test_suites.h"

#include "hildon-program.h"


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

static HildonProgram *program = NULL;

static void 
fx_setup_default_program ()
{
  int argc = 0;
  gtk_init(&argc, NULL);

  program = hildon_program_get_instance();
  /* Check program object has been created properly */
  fail_if(!HILDON_IS_PROGRAM(program),
          "hildon-program: Creation failed.");

}

static void 
fx_teardown_default_program ()
{
  g_object_unref(program);
}


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

/* ----- Test case for hildon_program_add_window -----*/

/**
 * Purpose: Test regular usage of the add_window interface
 * Cases considered:
 *    - Add a window object to the program
 *    - Add another window object to the program
 *    - Add the same window object to the program
 */
START_TEST (test_add_window_regular)
{
  HildonWindow *window; 
  HildonWindow *window1; 

  /* Test1: Add a window object to the program */  
  window = HILDON_WINDOW(hildon_window_new());
  hildon_program_add_window(program, window);

  /* Test2: Add another window object to the program */  
  window1 = HILDON_WINDOW(hildon_window_new());
  hildon_program_add_window(program, window1);

  /* Test3: Add the same window object to the program */  
  hildon_program_add_window(program, window);
  hildon_program_remove_window(program, window);

  gtk_widget_destroy (GTK_WIDGET (window));
  gtk_widget_destroy (GTK_WIDGET (window1));
}
END_TEST

/**
 * Purpose: Check invalid values of the add_window interface
 * Cases considered:
 *    - Add to a NULL program
 *    - Add a NULL window
 *    - Add a label instead of a window
 */
START_TEST (test_add_window_invalid)
{
  GtkWidget *label;

  /* Test1: Add to a NULL program */  
  hildon_program_add_window(NULL, NULL);

  /* Test2: Add a NULL window */
  hildon_program_add_window(program, NULL);

  /* Test3: Add a label instead of a window */
  label = gtk_label_new("This is an invalid example widget");
  hildon_program_add_window(program, HILDON_WINDOW(label));

  gtk_widget_destroy (GTK_WIDGET (label));
}
END_TEST

/* ----- Test case for hildon_program_remove_window -----*/

/**
 * Purpose: Test regular usage of the remove_window interface
 * Cases considered:
 *    - Add a window object to the program and remove it
 *    - Add another window object to the program and remove the first one
 *    - Remove a window two times
 */
START_TEST (test_remove_window_regular)
{
  HildonWindow *window; 
  HildonWindow *window1; 

  /* Test1: Add a window object to the program and remove it */  
  window = HILDON_WINDOW(hildon_window_new());
  hildon_program_add_window(program, window);
  hildon_program_remove_window(program, window);

  /* Test2: Add another window object to the program and remove the first one */  
  window1 = HILDON_WINDOW(hildon_window_new());
  hildon_program_add_window(program, window);
  hildon_program_add_window(program, window1);
  hildon_program_remove_window(program, window);

  /* Test3: Remove a window two times */  
  hildon_program_remove_window(program, window1);
  hildon_program_remove_window(program, window1);

  gtk_widget_destroy (GTK_WIDGET (window));
  gtk_widget_destroy (GTK_WIDGET (window1));
}
END_TEST

/**
 * Purpose: Check invalid values of the remove_window interface
 * Cases considered:
 *    - Remove from a NULL program
 *    - Remove a NULL window
 *    - Remove a label instead of a window
 */
START_TEST (test_remove_window_invalid)
{
  GtkWidget *label;

  /* Test1: Remove from a NULL program */
  hildon_program_remove_window(NULL, NULL);

  /* Test2: Remove a NULL window */  
  hildon_program_remove_window(program, NULL);

  /* Test3: Remove a label instead of a window */  
  label = gtk_label_new("This is an invalid example widget");
  hildon_program_remove_window(program, HILDON_WINDOW(label));

  gtk_widget_destroy (GTK_WIDGET (label));
}
END_TEST

/* ----- Test case for hildon_program_set_can_hibernate -----*/

/**
 * Purpose: Test regular usage of the set_cant_hibernate interface
 * Cases considered:
 *    - Test the initial value of the property, it must be FALSE
 *    - Set a value and test if the value is correct
 */
START_TEST (test_set_can_hibernate_regular)
{

  /* Test1: Test the initial value of the property, it must be FALSE */  
  fail_if(hildon_program_get_can_hibernate(program), 
          "hildon-program: The initial value of the hibernate property must be FALSE and it is not");

  /* Test2: Set a value and test if the value is correct */  
  hildon_program_set_can_hibernate(program, TRUE);
  fail_if(!hildon_program_get_can_hibernate(program), 
          "hildon-program: We set the hibernate property to TRUE and it is FALSE");
    
}
END_TEST

/**
 * Purpose: Check invalid values of the set_can_hibernate interface
 * Cases considered:
 *    - Set the property to a NULL object
 */
START_TEST (test_set_can_hibernate_invalid)
{
  hildon_program_set_can_hibernate(NULL, TRUE);
}
END_TEST

/* ---------- Suite creation ---------- */

Suite *create_hildon_program_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonProgram");

  /* Create test cases */
  TCase *tc1 = tcase_create("add_window");
  TCase *tc2 = tcase_create("remove_window");
  TCase *tc3 = tcase_create("set_can_hibernate");

  /* Create test case for add_window and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_program, fx_teardown_default_program);
  tcase_add_test(tc1, test_add_window_regular);
  tcase_add_test(tc1, test_add_window_invalid);
  suite_add_tcase (s, tc1);

  /* Create test case for remove_window and add it to the suite */
  tcase_add_checked_fixture(tc2, fx_setup_default_program, fx_teardown_default_program);
  tcase_add_test(tc2, test_remove_window_regular);
  tcase_add_test(tc2, test_remove_window_invalid);
  suite_add_tcase (s, tc2);

  /* Create test case for set_can_hibernate and add it to the suite */
  tcase_add_checked_fixture(tc3, fx_setup_default_program, fx_teardown_default_program);
  tcase_add_test(tc3, test_set_can_hibernate_regular);
  tcase_add_test(tc3, test_set_can_hibernate_invalid);
  suite_add_tcase (s, tc3);

  /* Return created suite */
  return s;
}