Remove building with NOCRYPTO option
[minix3.git] / external / bsd / atf / dist / atf-c++ / macros_hpp_test.cpp
blob2cb75360a4d7cde7b19891d958acc6c2ab0d3ebd
1 //
2 // Automated Testing Framework (atf)
3 //
4 // Copyright (c) 2008 The NetBSD Foundation, Inc.
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 // 1. Redistributions of source code must retain the above copyright
11 // notice, this list of conditions and the following disclaimer.
12 // 2. Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
16 // THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 // CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 // IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 // GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 // IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 // IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <stdexcept>
32 #include <atf-c++/macros.hpp>
34 void
35 atf_check_errno_semicolons(void)
37 // Check that ATF_CHECK_ERRNO does not contain a semicolon that would
38 // cause an empty-statement that confuses some compilers.
39 ATF_CHECK_ERRNO(1, 1 == 1);
40 ATF_CHECK_ERRNO(2, 2 == 2);
43 void
44 atf_require_inside_if(void)
46 // Make sure that ATF_REQUIRE can be used inside an if statement that
47 // does not have braces. Earlier versions of it generated an error
48 // if there was an else clause because they confused the compiler
49 // by defining an unprotected nested if.
50 if (true)
51 ATF_REQUIRE(true);
52 else
53 ATF_REQUIRE(true);
56 void
57 atf_require_eq_inside_if(void)
59 // Make sure that ATF_REQUIRE_EQ can be used inside an if statement
60 // that does not have braces. Earlier versions of it generated an
61 // error if there was an else clause because they confused the
62 // compiler by defining an unprotected nested if.
63 if (true)
64 ATF_REQUIRE_EQ(true, true);
65 else
66 ATF_REQUIRE_EQ(true, true);
69 void
70 atf_require_throw_runtime_error(void)
72 // Check that we can pass std::runtime_error to ATF_REQUIRE_THROW.
73 // Earlier versions generated a warning because the macro's code also
74 // attempted to capture this exception, and thus we had a duplicate
75 // catch clause.
76 ATF_REQUIRE_THROW(std::runtime_error, (void)0);
79 void
80 atf_require_throw_inside_if(void)
82 // Make sure that ATF_REQUIRE_THROW can be used inside an if statement
83 // that does not have braces. Earlier versions of it generated an
84 // error because a trailing ; after a catch block was not allowed.
85 if (true)
86 ATF_REQUIRE_THROW(std::runtime_error, (void)0);
87 else
88 ATF_REQUIRE_THROW(std::runtime_error, (void)1);
91 void
92 atf_require_errno_semicolons(void)
94 // Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would
95 // cause an empty-statement that confuses some compilers.
96 ATF_REQUIRE_ERRNO(1, 1 == 1);
97 ATF_REQUIRE_ERRNO(2, 2 == 2);
100 // Test case names should not be expanded during instatiation so that they
101 // can have the exact same name as macros.
102 #define TEST_MACRO_1 invalid + name
103 #define TEST_MACRO_2 invalid + name
104 #define TEST_MACRO_3 invalid + name
105 ATF_TEST_CASE(TEST_MACRO_1);
106 ATF_TEST_CASE_HEAD(TEST_MACRO_1) { }
107 ATF_TEST_CASE_BODY(TEST_MACRO_1) { }
108 void instantiate_1(void) {
109 ATF_TEST_CASE_USE(TEST_MACRO_1);
110 atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_1)();
111 delete the_test;
113 ATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_2);
114 ATF_TEST_CASE_HEAD(TEST_MACRO_2) { }
115 ATF_TEST_CASE_BODY(TEST_MACRO_2) { }
116 ATF_TEST_CASE_CLEANUP(TEST_MACRO_2) { }
117 void instatiate_2(void) {
118 ATF_TEST_CASE_USE(TEST_MACRO_2);
119 atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_2)();
120 delete the_test;
122 ATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_3);
123 ATF_TEST_CASE_HEAD(TEST_MACRO_3) { }
124 ATF_TEST_CASE_BODY(TEST_MACRO_3) { }
125 ATF_TEST_CASE_CLEANUP(TEST_MACRO_3) { }
126 void instatiate_3(void) {
127 ATF_TEST_CASE_USE(TEST_MACRO_3);
128 atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_3)();
129 delete the_test;