~ubuntu-branches/debian/squeeze/glib2.0/squeeze

« back to all changes in this revision

Viewing changes to docs/reference/glib/tmpl/testing.sgml

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-02-15 13:00:43 UTC
  • mfrom: (1.3.1 upstream) (69.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20090215130043-q47fbt3owmt42m2f
Tags: 2.18.4-2
* Release to unstable
* debian/rules:
- bump SHVER, since we are already forcing a 2.18.0 dependecy on the
  symbols introduced in the development versions
* debian/control.in:
- added Homepage and Vcs-* control fields

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Testing
3
3
 
4
4
<!-- ##### SECTION Short_Description ##### -->
5
 
 
 
5
a test framework
6
6
 
7
7
<!-- ##### SECTION Long_Description ##### -->
8
8
<para>
9
 
 
10
 
</para>
11
 
 
 
9
GLib provides a framework for writing and maintaining unit tests
 
10
in parallel to the code they are testing. The API is designed according 
 
11
to established concepts found in the other test frameworks (JUnit, NUnit, 
 
12
RUnit), which in turn is based on smalltalk unit testing concepts.
 
13
<variablelist>
 
14
  <varlistentry>
 
15
    <term>Test case</term>
 
16
    <listitem><para>
 
17
      Tests (test methods) are grouped together with their 
 
18
      fixture into test cases.
 
19
    </para></listitem>
 
20
  </varlistentry>
 
21
  <varlistentry>
 
22
    <term>Fixture</term>
 
23
    <listitem><para>
 
24
      A test fixture consists of fixture data and setup and teardown methods 
 
25
      to establish the environment for the test functions. We use fresh 
 
26
      fixtures, i.e. fixtures are newly set up and torn down around each test 
 
27
      invokation to avoid dependencies between tests.
 
28
    </para></listitem>
 
29
  </varlistentry>
 
30
  <varlistentry>
 
31
    <term>Test suite</term>
 
32
    <listitem><para>
 
33
      Test cases can be grouped into test suites, to allow subsets of the 
 
34
      available tests to be run. Test suites can be grouped into other test 
 
35
      suites as well.
 
36
    </para></listitem>
 
37
  </varlistentry>
 
38
</variablelist>
 
39
The API is designed to handle creation and registration of test suites and
 
40
test cases implicitly. A simple call like
 
41
<informalexample><programlisting>
 
42
  g_test_add_func ("/misc/assertions", test_assertions);
 
43
</programlisting></informalexample>
 
44
creates a test suite called "misc" with a single test case named "assertions",
 
45
which consists of running the test_assertions function.
 
46
</para>
 
47
<para>
 
48
In addition to the traditional g_assert(), the test framework provides
 
49
an extended set of assertions for string and numerical comparisons:
 
50
g_assert_cmpfloat(), g_assert_cmpint(), g_assert_cmpuint(), g_assert_cmphex(),
 
51
g_assert_cmpstr(). The advantage of these variants over plain g_assert()
 
52
is that the assertion messages can be more elaborate, and include the
 
53
values of the compared entities.
 
54
</para>
 
55
<para>
 
56
GLib ships with two utilites called gtester and gtester-report to 
 
57
facilitate running tests and producing nicely formatted test reports. 
 
58
</para>
12
59
 
13
60
<!-- ##### SECTION See_Also ##### -->
14
61
<para>
15
 
 
 
62
<link linkend="gtester">gtester</link>,
 
63
<link linkend="gtester-report">gtester-report</link>
16
64
</para>
17
65
 
18
 
 
19
66
<!-- ##### SECTION Stability_Level ##### -->
20
67
 
21
68
 
22
 
<!-- ##### TYPEDEF GTestCase ##### -->
23
 
<para>
24
 
 
25
 
</para>
26
 
 
27
 
 
28
 
<!-- ##### TYPEDEF GTestSuite ##### -->
29
 
<para>
30
 
 
31
 
</para>
32
 
 
33
 
 
34
69
<!-- ##### FUNCTION g_test_minimized_result ##### -->
35
70
<para>
36
71
 
63
98
 
64
99
<!-- ##### MACRO g_test_quick ##### -->
65
100
<para>
66
 
 
 
101
Returns %TRUE if tests are run in quick mode.
67
102
</para>
68
103
 
69
104
 
70
105
 
71
106
<!-- ##### MACRO g_test_slow ##### -->
72
107
<para>
73
 
 
 
108
Returns %TRUE if tests are run in slow mode.
74
109
</para>
75
110
 
76
111
 
77
112
 
78
113
<!-- ##### MACRO g_test_thorough ##### -->
79
114
<para>
80
 
 
 
115
Returns %TRUE if tests are run in thorough mode.
81
116
</para>
82
117
 
83
118
 
84
119
 
85
120
<!-- ##### MACRO g_test_perf ##### -->
86
121
<para>
87
 
 
 
122
Returns %TRUE if tests are run in performance mode.
88
123
</para>
89
124
 
90
125
 
91
126
 
92
127
<!-- ##### MACRO g_test_verbose ##### -->
93
128
<para>
94
 
 
 
129
Returns %TRUE if tests are run in verbose mode.
95
130
</para>
96
131
 
97
132
 
98
133
 
99
134
<!-- ##### MACRO g_test_quiet ##### -->
100
135
<para>
101
 
 
 
136
Returns %TRUE if tests are run in quiet mode.
102
137
</para>
103
138
 
104
139
 
210
245
 
211
246
<!-- ##### MACRO g_test_queue_unref ##### -->
212
247
<para>
213
 
 
 
248
Enqueue an object to be released with g_object_unref() during
 
249
the next teardown phase. This is equivalent to calling g_test_queue_destroy()
 
250
with a destroy callback of g_object_unref().
214
251
</para>
215
252
 
216
 
@gobject: 
 
253
@gobject: the object to unref
 
254
@Since: 2.16
217
255
 
218
256
 
219
257
<!-- ##### ENUM GTestTrapFlags ##### -->
220
258
<para>
221
 
 
 
259
Test traps are guards around forked tests. These flags
 
260
determine what traps to set.
222
261
</para>
223
262
 
224
 
@G_TEST_TRAP_SILENCE_STDOUT: 
225
 
@G_TEST_TRAP_SILENCE_STDERR: 
226
 
@G_TEST_TRAP_INHERIT_STDIN: 
 
263
@G_TEST_TRAP_SILENCE_STDOUT: Redirect stdout of the test child to 
 
264
    <filename>/dev/null</filename> so it cannot be observed on the 
 
265
    console during test runs. The actual output is still captured 
 
266
    though to allow later tests with g_test_trap_assert_stdout().
 
267
@G_TEST_TRAP_SILENCE_STDERR: Redirect stderr of the test child to 
 
268
    <filename>/dev/null</filename> so it cannot be observed on the 
 
269
    console during test runs. The actual output is still captured 
 
270
    though to allow later tests with g_test_trap_assert_stderr().
 
271
@G_TEST_TRAP_INHERIT_STDIN: If this flag is given, stdin of the forked 
 
272
    child process is shared with stdin of its parent process. It is 
 
273
    redirected to <filename>/dev/null</filename> otherwise.
227
274
 
228
275
<!-- ##### FUNCTION g_test_trap_fork ##### -->
229
276
<para>
253
300
 
254
301
<!-- ##### MACRO g_test_trap_assert_passed ##### -->
255
302
<para>
256
 
 
 
303
Assert that the last forked test passed. See g_test_trap_fork().
257
304
</para>
258
305
 
 
306
@Since: 2.16
259
307
 
260
308
 
261
309
<!-- ##### MACRO g_test_trap_assert_failed ##### -->
262
310
<para>
263
 
 
 
311
Assert that the last forked test failed. See g_test_trap_fork().
264
312
</para>
265
313
 
 
314
@Since: 2.16
266
315
 
267
316
 
268
317
<!-- ##### MACRO g_test_trap_assert_stdout ##### -->
269
318
<para>
270
 
 
 
319
Assert that the stdout output of the last forked test matches @soutpattern. 
 
320
See g_test_trap_fork().
271
321
</para>
272
322
 
273
 
@soutpattern: 
 
323
@soutpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>
 
324
@Since: 2.16
274
325
 
275
326
 
276
327
<!-- ##### MACRO g_test_trap_assert_stdout_unmatched ##### -->
277
328
<para>
278
 
 
 
329
Assert that the stdout output of the last forked test does not match 
 
330
@soutpattern.  See g_test_trap_fork().
279
331
</para>
280
332
 
281
 
@soutpattern: 
 
333
@soutpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>
 
334
@Since: 2.16
282
335
 
283
336
 
284
337
<!-- ##### MACRO g_test_trap_assert_stderr ##### -->
285
338
<para>
286
 
 
 
339
Assert that the stderr output of the last forked test matches @serrpattern. 
 
340
See g_test_trap_fork().
287
341
</para>
288
342
 
289
 
@serrpattern: 
 
343
@serrpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>
 
344
@Since: 2.16
290
345
 
291
346
 
292
347
<!-- ##### MACRO g_test_trap_assert_stderr_unmatched ##### -->
293
348
<para>
294
 
 
 
349
Assert that the stderr output of the last forked test does not match 
 
350
@serrpattern.  See g_test_trap_fork().
295
351
</para>
296
352
 
297
 
@serrpattern: 
 
353
@serrpattern: a glob-style <link linkend="glib-Glob-style-pattern-matching">pattern</link>
 
354
@Since: 2.16
298
355
 
299
356
 
300
357
<!-- ##### MACRO g_test_rand_bit ##### -->
301
358
<para>
302
 
 
 
359
Get a reproducible random bit (0 or 1),
 
360
see g_test_rand_int() for details on test case random numbers.
303
361
</para>
304
362
 
 
363
@Since: 2.16
305
364
 
306
365
 
307
366
<!-- ##### FUNCTION g_test_rand_int ##### -->
342
401
 
343
402
<!-- ##### MACRO g_assert ##### -->
344
403
<para>
345
 
 
346
 
</para>
347
 
 
348
 
@expr: 
 
404
Debugging macro to terminate the application if the assertion fails.
 
405
If the assertion fails (i.e. the expression is not true), an error message
 
406
is logged and the application is terminated.
 
407
</para>
 
408
<para>
 
409
The macro can be turned off in final releases of code by defining
 
410
#G_DISABLE_ASSERT when compiling the application.
 
411
</para>
 
412
 
 
413
@expr: the expression to check.
349
414
 
350
415
 
351
416
<!-- ##### MACRO g_assert_not_reached ##### -->
352
417
<para>
353
 
 
 
418
Debugging macro to terminate the application if it is ever reached.
 
419
If it is reached, an error message is logged and the application is terminated.
 
420
</para>
 
421
<para>
 
422
The macro can be turned off in final releases of code by defining
 
423
#G_DISABLE_ASSERT when compiling the application.
354
424
</para>
355
425
 
356
426
 
357
427
 
358
428
<!-- ##### MACRO g_assert_cmpstr ##### -->
359
429
<para>
360
 
 
361
 
</para>
362
 
 
363
 
@s1: 
364
 
@cmp: 
365
 
@s2: 
 
430
Debugging macro to terminate the application with a warning message 
 
431
if a string comparison fails.
 
432
The strings are compared using g_strcmp0().
 
433
</para>
 
434
<para>
 
435
The effect of <literal>g_assert_cmpstr (s1, op, s2)</literal> is the same
 
436
as <literal>g_assert (s1 op s2)</literal>. The advantage of this macro
 
437
is that it can produce a message that includes the actual values of @s1
 
438
and @s2.
 
439
</para>
 
440
<informalexample><programlisting>
 
441
  g_assert_cmpstr (mystring, ==, "fubar");
 
442
</programlisting></informalexample>
 
443
 
 
444
@s1: a string (may be %NULL)
 
445
@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
 
446
@s2: another string (may be %NULL)
 
447
@Since: 2.16
366
448
 
367
449
 
368
450
<!-- ##### MACRO g_assert_cmpint ##### -->
369
451
<para>
370
 
 
371
 
</para>
372
 
 
373
 
@n1: 
374
 
@cmp: 
375
 
@n2: 
 
452
Debugging macro to terminate the application with a warning message 
 
453
if an integer comparison fails.
 
454
</para>
 
455
<para>
 
456
The effect of <literal>g_assert_cmpint (n1, op, n2)</literal> is the same
 
457
as <literal>g_assert (n1 op n2)</literal>. The advantage of this macro
 
458
is that it can produce a message that includes the actual values of @n1
 
459
and @n2.
 
460
</para>
 
461
 
 
462
@n1: an integer
 
463
@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
 
464
@n2: another integer
 
465
@Since: 2.16
376
466
 
377
467
 
378
468
<!-- ##### MACRO g_assert_cmpuint ##### -->
379
469
<para>
380
 
 
381
 
</para>
382
 
 
383
 
@n1: 
384
 
@cmp: 
385
 
@n2: 
 
470
Debugging macro to terminate the application with a warning message 
 
471
if an unsigned integer comparison fails.
 
472
</para>
 
473
<para>
 
474
The effect of <literal>g_assert_cmpuint (n1, op, n2)</literal> is the same
 
475
as <literal>g_assert (n1 op n2)</literal>. The advantage of this macro
 
476
is that it can produce a message that includes the actual values of @n1
 
477
and @n2.
 
478
</para>
 
479
 
 
480
@n1: an unsigned integer
 
481
@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
 
482
@n2: another unsigned integer
 
483
@Since: 2.16
386
484
 
387
485
 
388
486
<!-- ##### MACRO g_assert_cmphex ##### -->
389
487
<para>
390
 
 
 
488
Debugging macro to terminate the application with a warning message 
 
489
if an unsigned integer comparison fails. This is a variant of
 
490
g_assert_cmpuint() that displays the numbers in hexadecimal notation
 
491
in the message.
391
492
</para>
392
493
 
393
 
@n1: 
394
 
@cmp: 
395
 
@n2: 
 
494
@n1: an unsigned integer
 
495
@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
 
496
@n2: another unsigned integer
 
497
@Since: 2.16
396
498
 
397
499
 
398
500
<!-- ##### MACRO g_assert_cmpfloat ##### -->
399
501
<para>
400
 
 
401
 
</para>
402
 
 
403
 
@n1: 
404
 
@cmp: 
405
 
@n2: 
406
 
 
407
 
 
408
 
<!-- ##### FUNCTION g_strcmp0 ##### -->
409
 
<para>
410
 
 
411
 
</para>
412
 
 
413
 
@str1: 
414
 
@str2: 
 
502
Debugging macro to terminate the application with a warning message 
 
503
if a floating point number comparison fails.
 
504
</para>
 
505
<para>
 
506
The effect of <literal>g_assert_cmpflott (n1, op, n2)</literal> is the same
 
507
as <literal>g_assert (n1 op n2)</literal>. The advantage of this function
 
508
is that it can produce a message that includes the actual values of @n1
 
509
and @n2.
 
510
</para>
 
511
 
 
512
@n1: an floating point number
 
513
@cmp: The comparsion operator to use. One of ==, !=, &lt;, &gt;, &lt;=, &gt;=.
 
514
@n2: another floating point number
 
515
@Since: 2.16
 
516
 
 
517
 
 
518
<!-- ##### TYPEDEF GTestCase ##### -->
 
519
<para>
 
520
An opaque structure representing a test case.
 
521
</para>
 
522
 
 
523
 
 
524
<!-- ##### TYPEDEF GTestSuite ##### -->
 
525
<para>
 
526
An opaque structure representing a test suite.
 
527
</para>
 
528
 
 
529
 
 
530
<!-- ##### FUNCTION g_test_create_case ##### -->
 
531
<para>
 
532
 
 
533
</para>
 
534
 
 
535
@test_name: 
 
536
@data_size: 
 
537
@test_data: 
 
538
@data_setup: 
 
539
@data_test: 
 
540
@data_teardown: 
 
541
@Returns: 
 
542
 
 
543
 
 
544
<!-- ##### FUNCTION g_test_create_suite ##### -->
 
545
<para>
 
546
 
 
547
</para>
 
548
 
 
549
@suite_name: 
 
550
@Returns: 
 
551
 
 
552
 
 
553
<!-- ##### FUNCTION g_test_get_root ##### -->
 
554
<para>
 
555
 
 
556
</para>
 
557
 
 
558
@Returns: 
 
559
 
 
560
 
 
561
<!-- ##### FUNCTION g_test_suite_add ##### -->
 
562
<para>
 
563
 
 
564
</para>
 
565
 
 
566
@suite: 
 
567
@test_case: 
 
568
 
 
569
 
 
570
<!-- ##### FUNCTION g_test_suite_add_suite ##### -->
 
571
<para>
 
572
 
 
573
</para>
 
574
 
 
575
@suite: 
 
576
@nestedsuite: 
 
577
 
 
578
 
 
579
<!-- ##### FUNCTION g_test_run_suite ##### -->
 
580
<para>
 
581
 
 
582
</para>
 
583
 
 
584
@suite: 
415
585
@Returns: 
416
586
 
417
587