]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/test/writing-test-ts/test-fixture-detect-setup-teardown.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / test / test / writing-test-ts / test-fixture-detect-setup-teardown.cpp
1 // (C) Copyright Raffi Enficiaud 2017.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5
6 // See http://www.boost.org/libs/test for the library home page.
7
8 // checks issue https://svn.boost.org/trac/boost/ticket/5563 in particular
9 // the ability of the framework to detect new fixture signatures.
10
11 #define BOOST_TEST_MODULE test_fixture_detect_setup_teardown
12 #include <boost/test/unit_test.hpp>
13 #include <iostream>
14 #include <boost/test/unit_test_suite.hpp>
15 #include <boost/test/framework.hpp>
16
17 using namespace boost::unit_test;
18
19 class fixture_without {
20 public:
21 fixture_without() {}
22 ~fixture_without() {}
23 };
24
25 class fixture_with {
26 public:
27 fixture_with() {}
28 void setup() {}
29 void teardown() {}
30 ~fixture_with() {}
31 };
32
33 class fixture_with_child : public fixture_with {
34 public:
35 fixture_with_child() {}
36 ~fixture_with_child() {}
37 };
38
39 BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect )
40 {
41 BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
42 BOOST_CHECK(!impl_fixture::has_setup<fixture_without>::value);
43
44 fixture_without obj;
45 setup_conditional(obj);
46 teardown_conditional(obj);
47 }
48
49 BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both )
50 {
51 BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
52 BOOST_CHECK(impl_fixture::has_setup<fixture_with>::value);
53
54 fixture_with obj;
55 setup_conditional(obj);
56 teardown_conditional(obj);
57 }
58
59 #if defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_TRAILING_RESULT_TYPES)
60
61 BOOST_AUTO_TEST_CASE( fixture_setup_teardown_detect_both_from_child )
62 {
63 // cannot detect this with the C++03 approach
64 BOOST_CHECK(!impl_fixture::has_setup<fixture_with_child>::value);
65 BOOST_CHECK(!impl_fixture::has_setup<fixture_with_child>::value);
66
67 fixture_with_child obj;
68 setup_conditional(obj);
69 teardown_conditional(obj);
70 }
71
72 #endif
73
74 int check_gf_1 = 0;
75
76 struct global_fixture_1 {
77 global_fixture_1() {
78 check_gf_1 = 2;
79 }
80 void setup() {
81 check_gf_1 += 40;
82 }
83 void teardown() {
84 check_gf_1 -= 40;
85 }
86 ~global_fixture_1() {
87 if(check_gf_1 != 0) {
88 // exits with errors
89 std::exit(1);
90 }
91 }
92 };
93
94 BOOST_TEST_GLOBAL_FIXTURE(global_fixture_1);
95
96 BOOST_AUTO_TEST_CASE( check_global_fixture_entered )
97 {
98 BOOST_CHECK(check_gf_1 == 42);
99 check_gf_1 -= 2;
100 }
101
102 int check_gf_2 = 0;
103
104 namespace random_namespace {
105 struct global_fixture_2 {
106 global_fixture_2() {
107 check_gf_2 = 2;
108 }
109 void setup() {
110 check_gf_2 += 40;
111 }
112 void teardown() {
113 check_gf_2 -= 40;
114 }
115 ~global_fixture_2() {
116 if(check_gf_2 != 0) {
117 // exits with errors
118 std::exit(1);
119 }
120 }
121 };
122 }
123
124 namespace random_namespace {
125 BOOST_TEST_GLOBAL_FIXTURE(global_fixture_2);
126 }
127
128 BOOST_AUTO_TEST_CASE( check_global_fixture_in_namespace_entered )
129 {
130 BOOST_CHECK(check_gf_2 == 42);
131 check_gf_2 -= 2;
132 }