~carsten-munk/m-r/libhildon-2.1.24

« back to all changes in this revision

Viewing changes to tests/check-hildon-seekbar.c

  • Committer: Carsten V. Munk
  • Date: 2008-12-08 15:00:57 UTC
  • Revision ID: cvm@cs.au.dk-20081208150057-7e0a50c8zdupbzar
initial commit of 2.1.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <gtk/gtkcontainer.h>
 
29
#include <glib/gprintf.h>
 
30
#include "test_suites.h"
 
31
#include "check_utils.h"
 
32
 
 
33
#include "hildon-seekbar.h"
 
34
 
 
35
/* -------------------- Fixtures -------------------- */
 
36
 
 
37
static GtkWidget *showed_window = NULL;
 
38
static HildonSeekbar *seekbar = NULL;
 
39
 
 
40
static void 
 
41
fx_setup_default_seekbar ()
 
42
{
 
43
  int argc = 0;
 
44
  gtk_init(&argc, NULL);
 
45
 
 
46
  seekbar = HILDON_SEEKBAR(hildon_seekbar_new());
 
47
 
 
48
  showed_window =  create_test_window ();
 
49
 
 
50
  /* This packs the widget into the window (a gtk container). */
 
51
  gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (seekbar));
 
52
 
 
53
  /* Displays the widget and the window */
 
54
  show_all_test_window (showed_window);
 
55
 
 
56
  /* Check that the seekbar object has been created properly */
 
57
  fail_if(!HILDON_SEEKBAR(seekbar),
 
58
          "hildon-seekbar: Creation failed.");
 
59
}
 
60
 
 
61
static void 
 
62
fx_teardown_default_seekbar ()
 
63
{
 
64
 
 
65
  /* Destroy the window */
 
66
  gtk_widget_destroy (showed_window);
 
67
}
 
68
 
 
69
/* -------------------- Test cases -------------------- */
 
70
 
 
71
/* ----- Test case for set_time -----*/
 
72
 
 
73
/**
 
74
 * Purpose: test setting regular time values for hildon_seekbar_set_time
 
75
 * Cases considered:
 
76
 *    - Set and get 1000 seconds without setting new position and fraction.
 
77
 *    - Set and get 500 seconds setting without setting new position but new fraction should be set.
 
78
 *    - Set and get 500 seconds setting without setting new position but new fraction should be set.
 
79
 */
 
80
START_TEST (test_set_time_regular)
 
81
{
 
82
  gint ret_seconds;
 
83
  gint seconds;
 
84
  gint position;
 
85
  gint fraction;
 
86
 
 
87
  /* Test 1: Set and get 1000 seconds without setting new position and fraction */
 
88
  seconds = 1000;
 
89
  hildon_seekbar_set_total_time(seekbar,seconds);
 
90
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
91
 
 
92
  fail_if(ret_seconds != seconds, 
 
93
          "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
 
94
          seconds,ret_seconds);
 
95
 
 
96
 
 
97
  /* 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 
 
98
     position and fraction.    */
 
99
  seconds = 500;
 
100
  position = 750;
 
101
  fraction = 750;
 
102
 
 
103
  hildon_seekbar_set_fraction(seekbar,fraction);
 
104
  fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
 
105
          "hildon-seekbar: set total time to %d but get_fraction returns %d ",
 
106
          fraction,hildon_seekbar_get_fraction(seekbar));
 
107
 
 
108
  hildon_seekbar_set_position(seekbar,position);
 
109
  fail_if(position != hildon_seekbar_get_position(seekbar), 
 
110
          "hildon-seekbar: set total time to %d but get_position returns %d",
 
111
          position,hildon_seekbar_get_position(seekbar));
 
112
 
 
113
  hildon_seekbar_set_total_time(seekbar,seconds);
 
114
  fail_if(seconds != hildon_seekbar_get_fraction(seekbar), 
 
115
          "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
 
116
          seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
 
117
 
 
118
  fail_if(seconds != hildon_seekbar_get_position(seekbar), 
 
119
          "hildon-seekbar: set total time to %d but get_fraction returns %d being total time %d",
 
120
          seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
 
121
 
 
122
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
123
  fail_if(ret_seconds != seconds, 
 
124
          "hildon-seekbar: set total time to %d but get_total_time returns %d ",
 
125
          seconds,ret_seconds);   
 
126
 
 
127
  /* 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 
 
128
     position and fraction.
 
129
  */
 
130
  seconds = 1000;
 
131
  hildon_seekbar_set_total_time(seekbar,seconds);
 
132
 
 
133
  seconds = 500;
 
134
  position = 250;
 
135
  fraction = 750;
 
136
 
 
137
  hildon_seekbar_set_fraction(seekbar,fraction);
 
138
  fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
 
139
          "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d ",
 
140
          fraction,hildon_seekbar_get_fraction(seekbar));
 
141
 
 
142
  hildon_seekbar_set_position(seekbar,position);
 
143
  fail_if(position != hildon_seekbar_get_position(seekbar), 
 
144
          "hildon-seekbar: set seekbar position to %d but get_position returns %d",
 
145
          position,hildon_seekbar_get_position(seekbar));
 
146
 
 
147
  hildon_seekbar_set_total_time(seekbar,seconds);
 
148
  fail_if(fraction != hildon_seekbar_get_fraction(seekbar), 
 
149
          "hildon-seekbar: set seekbar fraction to %d but get_fraction returns %d being total time %d",
 
150
          seconds,hildon_seekbar_get_fraction(seekbar),hildon_seekbar_get_total_time(seekbar));
 
151
 
 
152
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
153
  fail_if(ret_seconds != seconds, 
 
154
          "hildon-seekbar: set total time to %d but get_total_time returns %d ",
 
155
          seconds,ret_seconds);
 
156
}
 
157
END_TEST
 
158
 
 
159
/**
 
160
 * Purpose: test setting limit time values for hildon_seekbar_set_time
 
161
 * Cases considered:
 
162
 *    - Set and get 0 seconds setting new position and fraction (previously set to 750).
 
163
 *    - Set and get G_MAXINT seconds without setting new position and fraction.
 
164
 */
 
165
START_TEST (test_set_time_limits)
 
166
{
 
167
  gint ret_seconds;
 
168
  gint seconds;
 
169
  gint position;
 
170
  gint fraction;
 
171
 
 
172
  seconds = 1000;
 
173
  hildon_seekbar_set_total_time(seekbar,seconds);
 
174
    
 
175
  position = 750;
 
176
  fraction = 750;
 
177
 
 
178
  hildon_seekbar_set_fraction(seekbar,fraction);
 
179
  hildon_seekbar_set_position(seekbar,position);
 
180
 
 
181
  /* Test 1: Set and get 1 seconds without setting new position and fraction (time was previously set to 1000)*/
 
182
  seconds = 1;
 
183
  hildon_seekbar_set_total_time(seekbar,seconds);
 
184
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
185
 
 
186
  fail_if(ret_seconds != seconds, 
 
187
          "hildon-seekbar: set seekbar total time to %d should return %d but get_total_time returns %d",
 
188
          seconds,ret_seconds);
 
189
 
 
190
  /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
 
191
  fail_if(seconds != hildon_seekbar_get_fraction(seekbar), 
 
192
          "hildon-seekbar: set time to %d but get_fraction returns %d ",
 
193
          seconds,hildon_seekbar_get_fraction(seekbar));
 
194
 
 
195
  /* Check with seconds because hildon_seekbar_set_total_time must update fraction and position to total time set*/
 
196
  fail_if(seconds != hildon_seekbar_get_position(seekbar), 
 
197
          "hildon-seekbar: set time to %d but get_position returns %d",
 
198
          seconds,hildon_seekbar_get_position(seekbar));
 
199
 
 
200
  /* Test 2: Set and get G_MAXINT seconds without setting new position and fraction */
 
201
  seconds = G_MAXINT;
 
202
  hildon_seekbar_set_total_time(seekbar,seconds);
 
203
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
204
 
 
205
  fail_if(ret_seconds != seconds, 
 
206
          "hildon-seekbar: set seekbar total time to %d but get_total_time returns %d",
 
207
          seconds,ret_seconds);
 
208
    
 
209
    
 
210
}
 
211
END_TEST
 
212
 
 
213
 
 
214
/**
 
215
 * Purpose: test setting invalid time values for hildon_seekbar_set_time
 
216
 * Cases considered:
 
217
 *    - Set and get seconds to a NULL object.
 
218
 *    - Set and get 0 seconds without setting new position and fraction.
 
219
 *    - Set and get -1 seconds without setting new position and fraction.
 
220
 */
 
221
START_TEST (test_set_time_invalid)
 
222
{
 
223
  gint init_seconds;
 
224
  gint ret_seconds;
 
225
  gint seconds;
 
226
 
 
227
  init_seconds = 1000;
 
228
  /* Test 1: Set/get seconds on NULL object */
 
229
  hildon_seekbar_set_total_time(NULL,init_seconds);
 
230
  ret_seconds=hildon_seekbar_get_total_time(NULL);
 
231
 
 
232
  /* Init seekbar to 1000 seconds*/
 
233
  hildon_seekbar_set_total_time(seekbar,init_seconds);
 
234
    
 
235
 
 
236
  /* Test 2: Set and get 0 seconds */
 
237
  seconds = 0;
 
238
  hildon_seekbar_set_total_time(seekbar,seconds);
 
239
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
240
 
 
241
  fail_if(ret_seconds != init_seconds, 
 
242
          "hildon-seekbar: set seekbar total time to %d, should set %d but get_total_time returns %d",
 
243
          seconds,init_seconds,ret_seconds);
 
244
 
 
245
  /* Test 3: Set and get -1 seconds */
 
246
  seconds = -1;
 
247
  hildon_seekbar_set_total_time(seekbar,seconds);
 
248
  ret_seconds=hildon_seekbar_get_total_time(seekbar);
 
249
 
 
250
  fail_if(ret_seconds != init_seconds, 
 
251
          "hildon-seekbar: set seekbar total time to %d, should return %d but get_total_time returns %d",
 
252
          seconds,init_seconds,ret_seconds);
 
253
    
 
254
}
 
255
END_TEST
 
256
 
 
257
/* ----- Test case for set_fraction -----*/
 
258
 
 
259
/**
 
260
 * Purpose: test setting regular fraction values for hildon_seekbar_set_fraction
 
261
 * Cases considered:
 
262
 *    - Set and get fraction to 500 with total time set to 1000.
 
263
 *    - Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500.
 
264
 */
 
265
START_TEST (test_set_fraction_regular)
 
266
{
 
267
  gint ret_seconds;
 
268
  gint init_seconds;
 
269
  gint seconds;
 
270
 
 
271
  /* Init seekbar to 1000 */
 
272
  init_seconds = 1000;
 
273
  hildon_seekbar_set_total_time(seekbar,init_seconds);
 
274
 
 
275
  /* Test 1: Set and get fraction to 500 with total time set to 1000 */
 
276
  seconds = 500;
 
277
  hildon_seekbar_set_fraction(seekbar,seconds);
 
278
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
279
 
 
280
  fail_if(ret_seconds != seconds, 
 
281
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
282
          seconds,ret_seconds);
 
283
 
 
284
  /* Test 2: Set and get fraction to 490 with total time set to 1000, fraction and position previously set to 500 */
 
285
  seconds = 500;
 
286
 
 
287
  hildon_seekbar_set_fraction(seekbar,seconds);
 
288
  hildon_seekbar_set_position(seekbar,seconds);
 
289
 
 
290
  hildon_seekbar_set_fraction(seekbar,seconds-10);
 
291
 
 
292
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
293
 
 
294
  fail_if(ret_seconds != seconds-10, 
 
295
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
296
          seconds,ret_seconds);
 
297
 
 
298
  fail_if(hildon_seekbar_get_position(seekbar) != seconds-10, 
 
299
          "hildon-seekbar: set seekbar fraction to %d but get seekbar position returns %d",
 
300
          seconds-10,hildon_seekbar_get_position(seekbar));
 
301
    
 
302
}
 
303
END_TEST
 
304
 
 
305
/**
 
306
 * Purpose: test setting limit fraction values for hildon_seekbar_set_fraction
 
307
 * Cases considered:
 
308
 *    - Set and get fraction to 0 with total time set to G_MAXINT.
 
309
 *    - Set and get fraction to 1 with total time set to G_MAXINT.
 
310
 *    - Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT.
 
311
 *    - Set and get fraction to G_MAXINT with total time set to G_MAXINT.
 
312
 */
 
313
START_TEST (test_set_fraction_limits)
 
314
{
 
315
  gint ret_seconds;
 
316
  gint seconds;
 
317
  gint init_seconds;
 
318
 
 
319
  /* Init seekbar to G_MAXINT total time */
 
320
  init_seconds = G_MAXINT;
 
321
  hildon_seekbar_set_total_time(seekbar,init_seconds);
 
322
 
 
323
  /* Test 1: Set and get fraction to 0 with total time set to G_MAXINT */
 
324
  seconds = 0;
 
325
  hildon_seekbar_set_fraction(seekbar,seconds);
 
326
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
327
 
 
328
  fail_if(ret_seconds != seconds, 
 
329
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
330
          seconds,ret_seconds);
 
331
 
 
332
  /* Test 2: Set and get fraction to 1 with total time set to G_MAXINT */
 
333
  seconds = 1;
 
334
  hildon_seekbar_set_fraction(seekbar,seconds);
 
335
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
336
 
 
337
  fail_if(ret_seconds != seconds, 
 
338
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
339
          seconds,ret_seconds);
 
340
 
 
341
  /* Test 3: Set and get fraction to G_MAXINT-1 with total time set to G_MAXINT */
 
342
  seconds = G_MAXINT-1;
 
343
  hildon_seekbar_set_fraction(seekbar,seconds);
 
344
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
345
 
 
346
  fail_if(ret_seconds != seconds, 
 
347
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
348
          seconds,ret_seconds);
 
349
 
 
350
  /* Test 4: Set and get fraction to G_MAXINT with total time set to G_MAXINT */
 
351
  seconds = G_MAXINT;
 
352
    
 
353
  hildon_seekbar_set_fraction(seekbar,seconds);
 
354
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
355
    
 
356
  fail_if(ret_seconds != seconds, 
 
357
          "hildon-seekbar: set seekbar fraction to %d but get seekbar fraction returns %d",
 
358
          seconds,ret_seconds);
 
359
 
 
360
    
 
361
}
 
362
END_TEST
 
363
 
 
364
/**
 
365
 * Purpose: test setting invalid fraction values for hildon_seekbar_set_fraction
 
366
 * Cases considered:
 
367
 *    - Set and get fraction to NULL object.
 
368
 *    - Set and get fraction to -1 with total time set to G_MAXINT.
 
369
 *    - Set and get fraction to 2000 with total time set to 1000.
 
370
 */
 
371
START_TEST (test_set_fraction_invalid)
 
372
{
 
373
  gint ret_seconds;
 
374
  gint seconds;
 
375
  gint init_seconds;
 
376
 
 
377
  /* Init seekbar to G_MAXINT total time */
 
378
  init_seconds = G_MAXINT;
 
379
  hildon_seekbar_set_total_time(seekbar,init_seconds);
 
380
 
 
381
  /* Test 1: Set and get fraction to NULL object */
 
382
  seconds = 1000;
 
383
  hildon_seekbar_set_fraction(NULL,seconds);
 
384
  ret_seconds=hildon_seekbar_get_fraction(NULL);
 
385
 
 
386
  /* Test 2: Set and get fraction to -1 with total time set to G_MAXINT */
 
387
  seconds = -1;
 
388
  hildon_seekbar_set_fraction(seekbar,seconds);
 
389
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
390
 
 
391
  fail_if(ret_seconds != 0, 
 
392
          "hildon-seekbar: set seekbar fraction to %d should set 0 but get seekbar fraction returns %d",
 
393
          seconds,ret_seconds);
 
394
 
 
395
  /* Init seekbar to 1000 total time */
 
396
  init_seconds = 1000;
 
397
  hildon_seekbar_set_total_time(seekbar,init_seconds);
 
398
  hildon_seekbar_set_fraction(seekbar,init_seconds-500);
 
399
 
 
400
  /* Test 3: Set and get fraction to 2000 with total time set to 1000 */
 
401
  seconds = 2000;
 
402
  hildon_seekbar_set_fraction(seekbar,seconds);
 
403
  ret_seconds=hildon_seekbar_get_fraction(seekbar);
 
404
 
 
405
  fail_if(ret_seconds != init_seconds-500, 
 
406
          "hildon-seekbar: set seekbar fraction to %d should set %d but get seekbar fraction returns %d",
 
407
          seconds,init_seconds,ret_seconds);
 
408
    
 
409
}
 
410
END_TEST
 
411
 
 
412
 
 
413
 
 
414
/* ---------- Suite creation ---------- */
 
415
 
 
416
Suite *create_hildon_seekbar_suite()
 
417
{
 
418
  /* Create the suite */
 
419
  Suite *s = suite_create("HildonSeekbar");
 
420
 
 
421
  /* Create test cases */
 
422
  TCase *tc1 = tcase_create("set_time");
 
423
  TCase *tc2 = tcase_create("set_fraction");
 
424
 
 
425
  /* Create test case for hildon_seekbar_set_time and add it to the suite */
 
426
  tcase_add_checked_fixture(tc1, fx_setup_default_seekbar, fx_teardown_default_seekbar);
 
427
  tcase_add_test(tc1, test_set_time_regular);
 
428
  tcase_add_test(tc1, test_set_time_limits);
 
429
  tcase_add_test(tc1, test_set_time_invalid);
 
430
  suite_add_tcase (s, tc1);
 
431
 
 
432
  /* Create test case for hildon_seekbar_set_fraction  and add it to the suite */
 
433
  tcase_add_checked_fixture(tc2, fx_setup_default_seekbar, fx_teardown_default_seekbar);
 
434
  tcase_add_test(tc2, test_set_fraction_regular);
 
435
  tcase_add_test(tc2, test_set_fraction_limits);
 
436
  tcase_add_test(tc2, test_set_fraction_invalid);
 
437
  suite_add_tcase (s, tc2);
 
438
 
 
439
  /* Return created suite */
 
440
  return s;             
 
441
}
 
442