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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*
* 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/gtkcontainer.h>
#include <glib/gprintf.h>
#include "test_suites.h"
#include "check_utils.h"
#include <hildon/hildon-seekbar.h>
/* -------------------- Fixtures -------------------- */
static GtkWidget *showed_window = NULL;
static HildonSeekbar *seekbar = NULL;
static void
fx_setup_default_seekbar ()
{
int argc = 0;
gtk_init(&argc, NULL);
seekbar = HILDON_SEEKBAR(hildon_seekbar_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 (seekbar));
/* Displays the widget and the window */
show_all_test_window (showed_window);
/* Check that the seekbar object has been created properly */
fail_if(!HILDON_SEEKBAR(seekbar),
"hildon-seekbar: Creation failed.");
}
static void
fx_teardown_default_seekbar ()
{
/* Destroy the window */
gtk_widget_destroy (showed_window);
}
/* -------------------- Test cases -------------------- */
/* ----- Test case for set_time -----*/
/**
* Purpose: test setting regular time values for hildon_seekbar_set_time
* Cases considered:
* - Set and get 1000 seconds without setting new position and fraction.
* - Set and get 500 seconds setting without setting new position but new fraction should be set.
* - Set and get 500 seconds setting without setting new position but new fraction should be set.
*/
START_TEST (test_set_time_regular)
{
gint ret_seconds;
gint seconds;
gint position;
gint fraction;
/* Test 1: Set and get 1000 seconds without setting new position and fraction */
seconds = 1000;
hildon_seekbar_set_total_time(seekbar,seconds);
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
seconds,ret_seconds);
/* Test 2: Set and get 500 seconds with a fraction set to 750 and position set to 750 (in order to test the correct update of
position and fraction. */
seconds = 500;
position = 750;
fraction = 750;
hildon_seekbar_set_fraction(seekbar,fraction);
fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
"hildon-seekbar: set total time to %d but get_fraction returns %d ",
fraction,hildon_seekbar_get_fraction(seekbar));
hildon_seekbar_set_position(seekbar,position);
fail_if(position != hildon_seekbar_get_position(seekbar),
"hildon-seekbar: set total time to %d but get_position returns %d",
position,hildon_seekbar_get_position(seekbar));
hildon_seekbar_set_total_time(seekbar,seconds);
fail_if(seconds != hildon_seekbar_get_fraction(seekbar),
"hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
fail_if(seconds != hildon_seekbar_get_position(seekbar),
"hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set total time to %d but get_total_time returns %d ",
seconds,ret_seconds);
/* Test 3: Set and get 500 seconds with a fraction set to 750 and position set to 250 (in order to test the correct update of
position and fraction.
*/
seconds = 1000;
hildon_seekbar_set_total_time(seekbar,seconds);
seconds = 500;
position = 250;
fraction = 750;
hildon_seekbar_set_fraction(seekbar,fraction);
fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
"hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d ",
fraction,hildon_seekbar_get_fraction(seekbar));
hildon_seekbar_set_position(seekbar,position);
fail_if(position != hildon_seekbar_get_position(seekbar),
"hildon-seekbar: set seekbar position to %d but get_position returns %d",
position,hildon_seekbar_get_position(seekbar));
hildon_seekbar_set_total_time(seekbar,seconds);
fail_if(fraction != hildon_seekbar_get_fraction(seekbar),
"hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d being total time %d",
seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set total time to %d but get_total_time returns %d ",
seconds,ret_seconds);
}
END_TEST
/**
* Purpose: test setting limit time values for hildon_seekbar_set_time
* Cases considered:
* - Set and get 0 seconds setting new position and fraction (previously set to 750).
* - Set and get G_MAXINT seconds without setting new position and fraction.
*/
START_TEST (test_set_time_limits)
{
gint ret_seconds;
gint seconds;
gint position;
gint fraction;
seconds = 1000;
hildon_seekbar_set_total_time(seekbar,seconds);
position = 750;
fraction = 750;
hildon_seekbar_set_fraction(seekbar,fraction);
hildon_seekbar_set_position(seekbar,position);
/* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/
seconds = 1;
hildon_seekbar_set_total_time(seekbar,seconds);
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar total time to %d should return %d but get_total_time returns %d",
seconds,ret_seconds);
/* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
fail_if(seconds != hildon_seekbar_get_fraction(seekbar),
"hildon-seekbar: set time to %d but get_fraction returns %d ",
seconds,hildon_seekbar_get_fraction(seekbar));
/* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
fail_if(seconds != hildon_seekbar_get_position(seekbar),
"hildon-seekbar: set time to %d but get_position returns %d",
seconds,hildon_seekbar_get_position(seekbar));
/* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */
seconds = G_MAXINT;
hildon_seekbar_set_total_time(seekbar,seconds);
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
seconds,ret_seconds);
}
END_TEST
/**
* Purpose: test setting invalid time values for hildon_seekbar_set_time
* Cases considered:
* - Set and get seconds to a NULL object.
* - Set and get 0 seconds without setting new position and fraction.
* - Set and get -1 seconds without setting new position and fraction.
*/
START_TEST (test_set_time_invalid)
{
gint init_seconds;
gint ret_seconds;
gint seconds;
init_seconds = 1000;
/* Test 1: Set/get seconds on NULL object */
hildon_seekbar_set_total_time(NULL,init_seconds);
ret_seconds=hildon_seekbar_get_total_time(NULL);
/* Init seekbar to 1000 seconds*/
hildon_seekbar_set_total_time(seekbar,init_seconds);
/* Test 2: Set and get 0 seconds */
seconds = 0;
hildon_seekbar_set_total_time(seekbar,seconds);
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != init_seconds,
"hildon-seekbar: set seekbar total time to %d, should set %d but get_total_time returns %d",
seconds,init_seconds,ret_seconds);
/* Test 3: Set and get -1 seconds */
seconds = -1;
hildon_seekbar_set_total_time(seekbar,seconds);
ret_seconds=hildon_seekbar_get_total_time(seekbar);
fail_if(ret_seconds != init_seconds,
"hildon-seekbar: set seekbar total time to %d, should return %d but get_total_time returns %d",
seconds,init_seconds,ret_seconds);
}
END_TEST
/* ----- Test case for set_fraction -----*/
/**
* Purpose: test setting regular fraction values for hildon_seekbar_set_fraction
* Cases considered:
* - Set and get fraction to 500 with total time set to 1000.
* - Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500.
*/
START_TEST (test_set_fraction_regular)
{
gint ret_seconds;
gint init_seconds;
gint seconds;
/* Init seekbar to 1000 */
init_seconds = 1000;
hildon_seekbar_set_total_time(seekbar,init_seconds);
/* Test 1: Set and get fraction to 500 with total time set to 1000 */
seconds = 500;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
/* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */
seconds = 500;
hildon_seekbar_set_fraction(seekbar,seconds);
hildon_seekbar_set_position(seekbar,seconds);
hildon_seekbar_set_fraction(seekbar,seconds-10);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds-10,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
fail_if(hildon_seekbar_get_position(seekbar) != seconds-10,
"hildon-seekbar: set seekbar fraction to %d but get seekbar position returns %d",
seconds-10,hildon_seekbar_get_position(seekbar));
}
END_TEST
/**
* Purpose: test setting limit fraction values for hildon_seekbar_set_fraction
* Cases considered:
* - Set and get fraction to 0 with total time set to G_MAXINT.
* - Set and get fraction to 1 with total time set to G_MAXINT.
* - Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT.
* - Set and get fraction to G_MAXINT with total time set to G_MAXINT.
*/
START_TEST (test_set_fraction_limits)
{
gint ret_seconds;
gint seconds;
gint init_seconds;
/* Init seekbar to G_MAXINT total time */
init_seconds = G_MAXINT;
hildon_seekbar_set_total_time(seekbar,init_seconds);
/* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */
seconds = 0;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
/* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */
seconds = 1;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
/* Test 3: Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT */
seconds = G_MAXINT-1;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
/* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */
seconds = G_MAXINT;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != seconds,
"hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
seconds,ret_seconds);
}
END_TEST
/**
* Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction
* Cases considered:
* - Set and get fraction to NULL object.
* - Set and get fraction to -1 with total time set to G_MAXINT.
* - Set and get fraction to 2000 with total time set to 1000.
*/
START_TEST (test_set_fraction_invalid)
{
gint ret_seconds;
gint seconds;
gint init_seconds;
/* Init seekbar to G_MAXINT total time */
init_seconds = G_MAXINT;
hildon_seekbar_set_total_time(seekbar,init_seconds);
/* Test 1: Set and get fraction to NULL object */
seconds = 1000;
hildon_seekbar_set_fraction(NULL,seconds);
ret_seconds=hildon_seekbar_get_fraction(NULL);
/* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */
seconds = -1;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != 0,
"hildon-seekbar: set seekbar fraction to %d should set 0 but get seekbar fraction returns %d",
seconds,ret_seconds);
/* Init seekbar to 1000 total time */
init_seconds = 1000;
hildon_seekbar_set_total_time(seekbar,init_seconds);
hildon_seekbar_set_fraction(seekbar,init_seconds-500);
/* Test 3: Set and get fraction to 2000 with total time set to 1000 */
seconds = 2000;
hildon_seekbar_set_fraction(seekbar,seconds);
ret_seconds=hildon_seekbar_get_fraction(seekbar);
fail_if(ret_seconds != init_seconds-500,
"hildon-seekbar: set seekbar fraction to %d should set %d but get seekbar fraction returns %d",
seconds,init_seconds,ret_seconds);
}
END_TEST
/* ---------- Suite creation ---------- */
Suite *create_hildon_seekbar_suite()
{
/* Create the suite */
Suite *s = suite_create("HildonSeekbar");
/* Create test cases */
TCase *tc1 = tcase_create("set_time");
TCase *tc2 = tcase_create("set_fraction");
/* Create test case for hildon_seekbar_set_time and add it to the suite */
tcase_add_checked_fixture(tc1, fx_setup_default_seekbar, fx_teardown_default_seekbar);
tcase_add_test(tc1, test_set_time_regular);
tcase_add_test(tc1, test_set_time_limits);
tcase_add_test(tc1, test_set_time_invalid);
suite_add_tcase (s, tc1);
/* Create test case for hildon_seekbar_set_fraction and add it to the suite */
tcase_add_checked_fixture(tc2, fx_setup_default_seekbar, fx_teardown_default_seekbar);
tcase_add_test(tc2, test_set_fraction_regular);
tcase_add_test(tc2, test_set_fraction_limits);
tcase_add_test(tc2, test_set_fraction_invalid);
suite_add_tcase (s, tc2);
/* Return created suite */
return s;
}
|