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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
|
/*
* 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 "test_suites.h"
#include "check_utils.h"
#include "hildon-range-editor.h"
#include <unistd.h>
/* -------------------- Fixtures -------------------- */
static GtkWidget *showed_window = NULL;
static HildonRangeEditor *range_editor = NULL;
static void
fx_setup_default_range_editor ()
{
int argc = 0;
gtk_init(&argc, NULL);
range_editor = HILDON_RANGE_EDITOR(hildon_range_editor_new());
showed_window = create_test_window ();
/* This packs the widget into the window (a gtk container). */
gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (range_editor));
/* Displays the widget and the window */
show_all_test_window (showed_window);
/* Check range_editor object has been created properly */
fail_if(!HILDON_IS_RANGE_EDITOR(range_editor),
"hildon-range-editor: Creation failed.");
while (gtk_events_pending ())
{
gtk_main_iteration ();
}
}
static void
fx_teardown_default_range_editor ()
{
/* Destroy the window */
gtk_widget_destroy (showed_window);
}
/* -------------------- Test cases -------------------- */
/* ----- Test case for set_limit, get_min, get_max -----*/
/**
* Purpose: Check that regular range limit values are set and get properly
* Cases considered:
* - Set limits to (-10,10) and get min/max using the range editor object
* - Set limits to (0,10) and get min/max using the range editor object
* - Set limits to (-10,0) and get min/max using the range editor object
* - Set limits to (1,10) and get min/max using the range editor object
* - Set limits to (-10,-10) and get min/max using the range editor object
*/
START_TEST (test_set_limits_get_min_get_max_regular)
{
gint range_start, range_end;
/* Test1: Set limits to (-10,10) */
hildon_range_editor_set_limits(range_editor, -10, 10);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -10,
"hildon-range-editor: set limits to (-10,10) but get_min didn't return -10");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 10,
"hildon-range-editor: set limits to (-10,10) but get_max didn't return 10");
/* Test2: Set limits to (0,10) */
hildon_range_editor_set_limits(range_editor, 0, 10);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != 0,
"hildon-range-editor: set limits to (0,10) but get_min didn't return 0");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 10,
"hildon-range-editor: set limits to (0,10) but get_max didn't return 10");
/* Test3: Set limits to (-10,0) */
hildon_range_editor_set_limits(range_editor, -10, 0);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -10,
"hildon-range-editor: set limits to (-10,0) but get_min didn't return -10");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 0,
"hildon-range-editor: set limits to (-10,0) but get_max didn't return 0");
/* Test4: Set limits to (1,10) */
hildon_range_editor_set_limits(range_editor, 1, 10);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != 1,
"hildon-range-editor: set limits to (1,10) but get_min didn't return 1");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 10,
"hildon-range-editor: set limits to (1,10) but get_max didn't return 10");
/* Test5: Set limits to (-10,-1) */
hildon_range_editor_set_limits(range_editor, -10, -1);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -10,
"hildon-range-editor: set limits to (-10,-1) but get_min didn't return -10");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != -1,
"hildon-range-editor: set limits to (-10,-1) but get_max didn't return -1");
}
END_TEST
/**
* Purpose: Check that range limit values are set and get properly
* Cases considered:
* - Set limits to (G_MININT,G_MAXINT) and get min/max using the range editor object
*/
START_TEST (test_set_limits_get_min_get_max_limits)
{
gint range_start, range_end;
/* Test1: Set limits to (G_MININT,G_MAXINT) */
hildon_range_editor_set_limits(range_editor, G_MININT, G_MAXINT);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != G_MININT,
"hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_min didn't return G_MININT");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != G_MAXINT,
"hildon-range-editor: set limits to (G_MININT,G_MAXINT) but get_max didn't return G_MAXINT");
}
END_TEST
/**
* Purpose: Check that invalid values are handled properly
* Cases considered:
* - Set inverted limits (10,-10)
* - Set range editor object to NULL for set_limits
* - Set range editor object to NULL for get_min and get_max
*/
START_TEST (test_set_limits_get_min_get_max_invalid)
{
gint range_start, range_end;
/* Test1: Set limits to (10,-10) */
hildon_range_editor_set_limits(range_editor, 10, -10);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -10,
"hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_min didn't return -10");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != -10,
"hildon-range-editor: set inverted limits to (10,-10) expecting to set limits to (-10,-10) but get_max didn't return -1");
/* Test2: set range editor to NULL for set_limits. */
hildon_range_editor_set_limits(NULL, 100, -100);
/* Test3: set range editor to NULL for get_min and get_max */
range_start = hildon_range_editor_get_min(NULL);
fail_if(range_start != 0,
"hildon-range-editor: setting range editor to NULL produced get_min to return a value != 0");
range_end = hildon_range_editor_get_max(NULL);
fail_if(range_end != 0,
"hildon-range-editor: setting range editor to NULL produced get_max to return a value != 0");
}
END_TEST
/* ----- Test case for set_min -----*/
/**
* Purpose: Check regular minimum values for limits are set properly
* Cases considered:
* - Set min limit to -100
* - Set min limit to 0
* - Set min limit to 100
*/
START_TEST (test_set_min_regular)
{
gint range_start;
/* Test1: Set min limits -100 */
hildon_range_editor_set_min(range_editor, -100);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -100,
"hildon-range-editor: set min limit to -100 but get_min didn't return -100");
/* Test2: Set min limits 0 */
hildon_range_editor_set_min(range_editor, 0);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != 0,
"hildon-range-editor: set min limit to 0 but get_min didn't return 0");
/* Test3: Set min limits 100 */
hildon_range_editor_set_min(range_editor, 100);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != 100,
"hildon-range-editor: set min limit to 100 but get_min didn't return 100");
}
END_TEST
/**
* Purpose: Check limit minimum values for limits are set properly
* Cases considered:
* - Set min limit to G_MININT
*/
START_TEST (test_set_min_limits)
{
gint range_start;
/* Test1: Set min limit to G_MININT */
hildon_range_editor_set_min(range_editor, G_MININT);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != G_MININT,
"hildon-range-editor: set min limit to G_MININT but get_min didn't return G_MININT");
}
END_TEST
/**
* Purpose: Check that invalid values are handled properly
* Cases considered:
* - Set minimum limit greater than maximum limit
* - Set range editor object to NULL for set_min
*/
START_TEST (test_set_min_invalid)
{
gint range_start, range_end;
/* Test1: Set minimum limit greater than maximum limit */
hildon_range_editor_set_limits(range_editor, -10, 10);
hildon_range_editor_set_min(range_editor, 15);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != 15,
"hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_min didn't return 15");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 15,
"hildon-range-editor: set min limit to 15 when max limit is 10 expecting to set limits to (15,15) but get_max didn't return 15");
/* Test2: set range editor to NULL */
hildon_range_editor_set_min(NULL, 15);
}
END_TEST
/* ----- Test case for set_max -----*/
/**
* Purpose: Check regular maximum values for limits are set properly
* Cases considered:
* - Set max limit to -100
* - Set max limit to 0
* - Set max limit to 100
*/
START_TEST (test_set_max_regular)
{
gint range_end;
/* Test1: Set max limits -100 */
hildon_range_editor_set_max(range_editor, -100);
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != -100,
"hildon-range-editor: set max limit to -100 but get_max didn't return -100");
/* Test2: Set max limits 0 */
hildon_range_editor_set_max(range_editor, 0);
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 0,
"hildon-range-editor: set max limit to 0 but get_max didn't return 0");
/* Test3: Set max limits 100 */
hildon_range_editor_set_max(range_editor, 100);
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != 100,
"hildon-range-editor: set max limit to 100 but get_max didn't return 100");
}
END_TEST
/**
* Purpose: Check limit maximum values for limits are set properly
* Cases considered:
* - Set min limit to G_MAXINT
*/
START_TEST (test_set_max_limits)
{
gint range_end;
/* Test1: Set max limit to G_MAXINT */
hildon_range_editor_set_max(range_editor, G_MAXINT);
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != G_MAXINT,
"hildon-range-editor: set min limit to G_MAXINT but get_max didn't return G_MAXINT");
}
END_TEST
/**
* Purpose: Check that invalid values are handled properly
* Cases considered:
* - Set maximum limit lower than minimum limit
* - Set range editor object to NULL for set_max
*/
START_TEST (test_set_max_invalid)
{
gint range_start, range_end;
/* Test1: Set maximum limit lower than minimum limit */
hildon_range_editor_set_limits(range_editor, -10, 10);
hildon_range_editor_set_max(range_editor, -15);
range_start = hildon_range_editor_get_min(range_editor);
fail_if(range_start != -15,
"hildon-range-editor: set max limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_min didn't return -15");
range_end = hildon_range_editor_get_max(range_editor);
fail_if(range_end != -15,
"hildon-range-editor: set min limit to -15 when min limit is -10 expecting to set limits to (-15,-15) but get_max didn't return -15");
/* Test2: set range editor to NULL */
hildon_range_editor_set_max(NULL, 15);
}
END_TEST
/* ---------- Suite creation ---------- */
Suite *create_hildon_range_editor_suite()
{
/* Create the suite */
Suite *s = suite_create("HildonRangeEditor");
/* Create test cases */
TCase *tc1 = tcase_create("set_limits_get_min_get_max");
TCase *tc2 = tcase_create("set_min");
TCase *tc3 = tcase_create("set_max");
/* Create test case for set_limits, get_min and get_max and add it to the suite */
tcase_add_checked_fixture(tc1, fx_setup_default_range_editor, fx_teardown_default_range_editor);
tcase_add_test(tc1, test_set_limits_get_min_get_max_regular);
tcase_add_test(tc1, test_set_limits_get_min_get_max_limits);
tcase_add_test(tc1, test_set_limits_get_min_get_max_invalid);
suite_add_tcase (s, tc1);
/* Create test case for set_min */
tcase_add_checked_fixture(tc2, fx_setup_default_range_editor, fx_teardown_default_range_editor);
tcase_add_test(tc2, test_set_min_regular);
tcase_add_test(tc2, test_set_min_limits);
tcase_add_test(tc2, test_set_min_invalid);
suite_add_tcase (s, tc2);
/* Create test case for set_max */
tcase_add_checked_fixture(tc3, fx_setup_default_range_editor, fx_teardown_default_range_editor);
tcase_add_test(tc3, test_set_max_regular);
tcase_add_test(tc3, test_set_max_limits);
tcase_add_test(tc3, test_set_max_invalid);
suite_add_tcase (s, tc3);
/* Return created suite */
return s;
}
|