]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/test/doc/test_organization/nullary_tests.qbk
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / doc / test_organization / nullary_tests.qbk
CommitLineData
7c673cae
FG
1[/
2 / Copyright (c) 2003 Boost.Test contributors
3 /
4 / Distributed under the Boost Software License, Version 1.0. (See accompanying
5 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 /]
7
8[section:test_organization_nullary Test cases without parameters]
9
10The most common scenario is that you want to write test case without any parameters. The __UTF__ provides you with both
11automatic and manual registration APIs to declare such test case.
12
13[#ref_BOOST_AUTO_TEST_CASE][h4 Automated registration]
14
15To declare a test case without parameters, which is registered in place of implementation, employ the
16macro __BOOST_AUTO_TEST_CASE__.
17
18``
19 __BOOST_AUTO_TEST_CASE__(test_case_name);
20``
21
22This API is designed to closely mimic nullary free function declaration syntax.
23In comparison with free function all you need to do is to skip result type and brackets and wrap test
24case name into BOOST_AUTO_TEST_CASE:
25
26[bt_example example06..Nullary function based test case with automated registration..run]
27
28With this macro you don't need to implement any other registration steps. The macro creates and
29registers the test case with the name `free_test_function` automatically.
30
31[#ref_BOOST_TEST_CASE][h4 Manual registration]
32
33The __UTF__ allows to manually create test case without parameters based on nullary free functions, nullary
34function objects (including those created with `boost::bind` and nullary `boost::function`
35instances). To do this, employ the macro __BOOST_TEST_CASE__:
36
37``
38 BOOST_TEST_CASE(test_function);
39``
40
41__BOOST_TEST_CASE__ creates an instance of the class [classref boost::unit_test::test_case] and returns a pointer to the
42constructed instance. The test case name is deduced from the macro argument test_function. If you prefer to
43assign a different test case name, you have to use the underlying make_test_case interface instead. To
44register a new test case, employ the method [memberref boost::unit_test::test_suite::add `test_suite::add`].
45Both test case creation and registration are performed in the
46[link boost_test.adv_scenarios.test_module_init_overview test module initialization function].
47
48Here is the simplest example of manually registered test case. A single test case is created and registered inside
49the test module initialization routine. Note that the free function name is passed by address to the macro __BOOST_TEST_CASE__`.
50
51[#ref_bt_example01]
52[bt_example example01..Nullary free function manually registered..run]
53
54A test case can be implemented as a method of a class. In this case a pointer to the class instance has to be
55bound to the test method to create a test case. You can use the same instance of the class for multiple test
56cases. The __UTF__ doesn't take an ownership of the class instance and you are required to manage the class
57instance lifetime yourself.
58
59[warning
60 The class instance can't be defined in the initialization function scope, since it becomes invalid as
61 soon as the test execution exits it. It needs to be either defined statically/globally or managed using a
62 shared pointer.
63]
64
65[bt_example example03..Nullary method of a class bound to shared class instance and manually registered..run-fail]
66
67[endsect]
68
69[/EOF]