aboutsummaryrefslogtreecommitdiff
path: root/tests/check-hildon-controlbar.c
blob: efab1beac148e10d2b34bd3940532a87498850e0 (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
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
/*
 * 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 "test_suites.h"
#include "check_utils.h"
#include <hildon/hildon-controlbar.h>

/* -------------------- Fixtures -------------------- */
static HildonControlbar *controlbar = NULL;
static GtkWidget *showed_window = NULL;

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

  controlbar = HILDON_CONTROLBAR(hildon_controlbar_new());
  /* Check controlbar object has been created properly */
  fail_if(!HILDON_IS_CONTROLBAR(controlbar), 
          "hildon-controlbar: Creation failed.");

  showed_window =  create_test_window ();
  
  /* This packs the widget into the window (a gtk container). */
  gtk_container_add (GTK_CONTAINER (showed_window), GTK_WIDGET (controlbar));
  
  /* Displays the widget and the window */
  show_all_test_window (showed_window);
  
}

static void 
fx_teardown_default_controlbar ()
{

  /* Destroy the widget and the window */
  gtk_widget_destroy (GTK_WIDGET(showed_window));

}

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

/* ----- Test case for set_range -----*/
/**
 * Purpose: Check that regular range values are set and get properly
 * Cases considered:
 *    - Set a range of [20,1000].
 *    - Set a range of [20,20].
 */
START_TEST (test_set_range_regular)
{
  gint init_min;
  gint init_max;
  gint min;
  gint max;
    
  /* Test 1: Set a range of [20,1000] */
  init_min = 20;
  init_max = 1000;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  min = hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d", 
           min, init_min);

  max = hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d", 
           max, init_max);

  /* Test 2: Set a range of [20, 20] */
  init_min = 20;
  init_max = 20;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  min = hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d", 
           min, init_min);

  max = hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d", 
           max, init_max);
    
}
END_TEST

/**
 * Purpose: Check that limits range values are set and get properly
 * Cases considered:
 *    - Set a range of [0,G_MAXINT-1].
 */
START_TEST (test_set_range_limits)
{
  gint init_min;
  gint init_max;
  gint min;
  gint max;
    
  /* Test 1: Set a range of [0,G_MAXINT-1] */
  init_min = 0;
  init_max = G_MAXINT-1;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  min=hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d", 
           min, init_min);

  max=hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d", 
           max, init_max);
}
END_TEST

/**
 * Purpose: Check that invalid range values are set and get properly
 * Cases considered:
 *    - Set a range of [10,100] on NULL object.
 *    - Set a range of [-1,G_MAXINT].
 *    - Set a range of [G_MININT,-1].
 *    - Set a range of [G_MAXINT,-1].
 *    - Set a range of [1,G_MININT].
 */
START_TEST (test_set_range_invalid)
{
  gint init_min;
  gint init_max;
  gint min;
  gint max;

  init_min = 10;
  init_max = 100;
  /* Test 1: Set range on a NULL object */
  hildon_controlbar_set_range(NULL,init_min,init_max);

  init_min = -1;
  init_max = G_MAXINT;
  /* Test 2: Set a range of [-1,G_MAXINT] */
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  min=hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d",
           min, init_min);

  max=hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d",
           max, init_max);

  /* Test 3: Set a range of [G_MININT,-1] */
  init_min = G_MININT;
  init_max = -1;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  min=hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d",
           min, init_min);
  max=hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d",
           max, init_max);

  /* Test 4: Set a range of [G_MAXINT,-1] */
  init_min = G_MAXINT;
  init_max = -1;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  max=hildon_controlbar_get_max(controlbar);

  fail_if (max != init_max,
           "hildon-controlbar: The returned max is %d and should be %d",
           max, init_max);

  min=hildon_controlbar_get_min(controlbar);

  fail_if (min != init_max,
           "hildon-controlbar: The returned min is %d and should be %d",
           min, init_max);

  /* NOTE: The test below has been deliverately commented out, since
     it fails miserably. The range check in hildon_control_bar_set_range()
     is _broken_ and fixing it causes other tests to fail. It is safe to assume
     that by now, fixing this is going to cause more headaches than anything else,
     and being this a deprecated widget, there is no point on wasting time on it.
  */

  /* Test 5: Set a range of [1,G_MININT] */
#if 0
  init_min = 1;
  init_max = G_MININT;
  hildon_controlbar_set_range(controlbar,init_min,init_max);

  max=hildon_controlbar_get_max(controlbar);

  fail_if (max != init_min,
           "hildon-controlbar: The returned max is %d and should be %d",
           max, init_min);

  min=hildon_controlbar_get_min(controlbar);

  fail_if (min != init_min,
           "hildon-controlbar: The returned min is %d and should be %d",
           min, init_min);
#endif
}
END_TEST

/* ----- Test case for set_value -----*/
/**
 * Purpose: Check that regular values are set and get properly
 * Cases considered:
 *    - Set a value of 500 in the range [0,1000].
 */
START_TEST (test_set_value_regular)
{
  gint init_value;
  gint value;

  init_value=500;
  /* Must set a range different than [0,0], if not set you can not set a value*/
  hildon_controlbar_set_range(controlbar,0,1000);

  /* Test 1: Set a value of 500 in the range [0,1000].*/
  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != init_value,
           "hildon-controlbar: The returned value is %d and should be %d", 
           value, init_value);
    
}
END_TEST

/**
 * Purpose: Check that limit values are set and get properly
 * Cases considered:
 *    - Set a value of 0 in the range [0,1000].
 *    - Set a value of 1000 in the range [0,1000].
 */
START_TEST (test_set_value_limits)
{
  gint init_value;
  gint value;

  /* Must set a range diferent than [0,0], if not set you can not set a value*/
  hildon_controlbar_set_range(controlbar,0,1000);

  /*  Test 1: Set a value of 0 in the range [0,1000] */
  init_value=0;

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != init_value,
           "hildon-controlbar: The returned value is %d and should be %d", 
           value, init_value);

  /* Test 2: Set a value of 1000 in the range [0,1000] */
  init_value=1000;

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != init_value,
           "hildon-controlbar: The returned value is %d and should be %d", 
           value, init_value);    
}
END_TEST


/**
 * Purpose: Check that invalid values are set and get properly
 * Cases considered:
 *    - Set a value of 1 in a NULL controlbar.
 *    - Set a value of -1 in the range [2,1000].
 *    - Set a value of 1 in the range [2,1000].
 *    - Set a value of G_MININT in the range [2,1000].
 *    - Set a value of 1001 in the range [2,1000].
 *    - Set a value of G_MAXINT in the range [2,1000].
 *    - Set a value of G_MAXINT in the range [2,G_MAXINT].
 */
START_TEST (test_set_value_invalid)
{
  gint init_value;
  gint initial_value=4;
  gint value;
  gint current_value;
  gint min_value;
  gint max_value;

  min_value = 2;
  max_value = 1000;
  /* Must set a range diferent than [0,0], if not set you can not set a value*/
  hildon_controlbar_set_range(controlbar,min_value,max_value);
  hildon_controlbar_set_value(controlbar,initial_value);

  /* Test 1: Set a value of 1 in a NULL controlbar. */
  init_value=10;
  hildon_controlbar_set_value(NULL,init_value);


  /* Test 2: Set a value of -1 in the range [2,1000] */
  init_value=-1;
  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != initial_value,
           "hildon-controlbar: The returned value is %d and should be %d",
           value, initial_value);

  /* Test 3: Set a value of 1 in the range [2,1000] */
  init_value=1;
  hildon_controlbar_set_value(controlbar,min_value);

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != min_value,
           "hildon-controlbar: The returned value is %d and should be %d",
           value, min_value);


  /* Test 4: Set a value of G_MININT in the range [2,1000] */
  init_value=G_MININT;
  hildon_controlbar_set_value(controlbar,min_value+2);
  current_value = hildon_controlbar_get_value(controlbar);

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != current_value,
           "hildon-controlbar: The returned value is %d and should be %d",
           value, current_value);

  /* Test 5: Set a value of 1001 in the range [2,1000] */
  init_value=1001;

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != max_value,
           "hildon-controlbar: The returned value is %d and should be %d",
           value, max_value);


  /* Test 6: Set a value of G_MAXINT in the range [2,1000] */
  init_value=G_MAXINT;

  hildon_controlbar_set_value(controlbar,init_value);
  value=hildon_controlbar_get_value(controlbar);
  fail_if (value != max_value,
           "hildon-controlbar: The returned value is %d and should be %d",
           value, max_value);
}
END_TEST

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

Suite *create_hildon_controlbar_suite()
{
  /* Create the suite */
  Suite *s = suite_create("HildonControlbar");

  /* Create test cases */
  TCase *tc1 = tcase_create("set_range");
  TCase *tc2 = tcase_create("set_value");

  /* Create test case for hildon_controlbar_set_range and add it to the suite */
  tcase_add_checked_fixture(tc1, fx_setup_default_controlbar, fx_teardown_default_controlbar);
  tcase_add_test(tc1, test_set_range_regular);
  tcase_add_test(tc1, test_set_range_limits);
  tcase_add_test(tc1, test_set_range_invalid);
  suite_add_tcase (s, tc1);

  /* Create test case for hildon_controlbar_set_value and add it to the suite */
  tcase_add_checked_fixture(tc2, fx_setup_default_controlbar, fx_teardown_default_controlbar);
  tcase_add_test(tc2, test_set_value_regular);
  tcase_add_test(tc2, test_set_value_limits);
  tcase_add_test(tc2, test_set_value_invalid);
  suite_add_tcase (s, tc2);

  return s;
}