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