1240116Smarcel// Copyright (c) 2008 The NetBSD Foundation, Inc.
2240116Smarcel// All rights reserved.
3240116Smarcel//
4240116Smarcel// Redistribution and use in source and binary forms, with or without
5240116Smarcel// modification, are permitted provided that the following conditions
6240116Smarcel// are met:
7240116Smarcel// 1. Redistributions of source code must retain the above copyright
8240116Smarcel//    notice, this list of conditions and the following disclaimer.
9240116Smarcel// 2. Redistributions in binary form must reproduce the above copyright
10240116Smarcel//    notice, this list of conditions and the following disclaimer in the
11240116Smarcel//    documentation and/or other materials provided with the distribution.
12240116Smarcel//
13240116Smarcel// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
14240116Smarcel// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
15240116Smarcel// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
16240116Smarcel// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17240116Smarcel// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
18240116Smarcel// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19240116Smarcel// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
20240116Smarcel// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21240116Smarcel// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
22240116Smarcel// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23240116Smarcel// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
24240116Smarcel// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25240116Smarcel
26275988Sngie#include <atf-c++/macros.hpp>
27275988Sngie
28240116Smarcel#include <stdexcept>
29240116Smarcel
30240116Smarcelvoid
31240116Smarcelatf_check_errno_semicolons(void)
32240116Smarcel{
33240116Smarcel    // Check that ATF_CHECK_ERRNO does not contain a semicolon that would
34240116Smarcel    // cause an empty-statement that confuses some compilers.
35240116Smarcel    ATF_CHECK_ERRNO(1, 1 == 1);
36240116Smarcel    ATF_CHECK_ERRNO(2, 2 == 2);
37240116Smarcel}
38240116Smarcel
39240116Smarcelvoid
40240116Smarcelatf_require_inside_if(void)
41240116Smarcel{
42240116Smarcel    // Make sure that ATF_REQUIRE can be used inside an if statement that
43240116Smarcel    // does not have braces.  Earlier versions of it generated an error
44240116Smarcel    // if there was an else clause because they confused the compiler
45240116Smarcel    // by defining an unprotected nested if.
46240116Smarcel    if (true)
47240116Smarcel        ATF_REQUIRE(true);
48240116Smarcel    else
49240116Smarcel        ATF_REQUIRE(true);
50240116Smarcel}
51240116Smarcel
52240116Smarcelvoid
53240116Smarcelatf_require_eq_inside_if(void)
54240116Smarcel{
55240116Smarcel    // Make sure that ATF_REQUIRE_EQ can be used inside an if statement
56240116Smarcel    // that does not have braces.  Earlier versions of it generated an
57240116Smarcel    // error if there was an else clause because they confused the
58240116Smarcel    // compiler by defining an unprotected nested if.
59240116Smarcel    if (true)
60240116Smarcel        ATF_REQUIRE_EQ(true, true);
61240116Smarcel    else
62240116Smarcel        ATF_REQUIRE_EQ(true, true);
63240116Smarcel}
64240116Smarcel
65240116Smarcelvoid
66240116Smarcelatf_require_throw_runtime_error(void)
67240116Smarcel{
68240116Smarcel    // Check that we can pass std::runtime_error to ATF_REQUIRE_THROW.
69240116Smarcel    // Earlier versions generated a warning because the macro's code also
70240116Smarcel    // attempted to capture this exception, and thus we had a duplicate
71240116Smarcel    // catch clause.
72240116Smarcel    ATF_REQUIRE_THROW(std::runtime_error, (void)0);
73240116Smarcel}
74240116Smarcel
75240116Smarcelvoid
76240116Smarcelatf_require_throw_inside_if(void)
77240116Smarcel{
78240116Smarcel    // Make sure that ATF_REQUIRE_THROW can be used inside an if statement
79240116Smarcel    // that does not have braces.  Earlier versions of it generated an
80240116Smarcel    // error because a trailing ; after a catch block was not allowed.
81240116Smarcel    if (true)
82240116Smarcel        ATF_REQUIRE_THROW(std::runtime_error, (void)0);
83240116Smarcel    else
84240116Smarcel        ATF_REQUIRE_THROW(std::runtime_error, (void)1);
85240116Smarcel}
86240116Smarcel
87240116Smarcelvoid
88240116Smarcelatf_require_errno_semicolons(void)
89240116Smarcel{
90240116Smarcel    // Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would
91240116Smarcel    // cause an empty-statement that confuses some compilers.
92240116Smarcel    ATF_REQUIRE_ERRNO(1, 1 == 1);
93240116Smarcel    ATF_REQUIRE_ERRNO(2, 2 == 2);
94240116Smarcel}
95240116Smarcel
96240116Smarcel// Test case names should not be expanded during instatiation so that they
97240116Smarcel// can have the exact same name as macros.
98240116Smarcel#define TEST_MACRO_1 invalid + name
99240116Smarcel#define TEST_MACRO_2 invalid + name
100240116Smarcel#define TEST_MACRO_3 invalid + name
101240116SmarcelATF_TEST_CASE(TEST_MACRO_1);
102240116SmarcelATF_TEST_CASE_HEAD(TEST_MACRO_1) { }
103240116SmarcelATF_TEST_CASE_BODY(TEST_MACRO_1) { }
104240116Smarcelvoid instantiate_1(void) {
105240116Smarcel    ATF_TEST_CASE_USE(TEST_MACRO_1);
106240116Smarcel    atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_1)();
107240116Smarcel    delete the_test;
108240116Smarcel}
109240116SmarcelATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_2);
110240116SmarcelATF_TEST_CASE_HEAD(TEST_MACRO_2) { }
111240116SmarcelATF_TEST_CASE_BODY(TEST_MACRO_2) { }
112240116SmarcelATF_TEST_CASE_CLEANUP(TEST_MACRO_2) { }
113240116Smarcelvoid instatiate_2(void) {
114240116Smarcel    ATF_TEST_CASE_USE(TEST_MACRO_2);
115240116Smarcel    atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_2)();
116240116Smarcel    delete the_test;
117240116Smarcel}
118240116SmarcelATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_3);
119240116SmarcelATF_TEST_CASE_HEAD(TEST_MACRO_3) { }
120240116SmarcelATF_TEST_CASE_BODY(TEST_MACRO_3) { }
121240116SmarcelATF_TEST_CASE_CLEANUP(TEST_MACRO_3) { }
122240116Smarcelvoid instatiate_3(void) {
123240116Smarcel    ATF_TEST_CASE_USE(TEST_MACRO_3);
124240116Smarcel    atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_3)();
125240116Smarcel    delete the_test;
126240116Smarcel}
127