1275988Sngie/* 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
24275988Sngie * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */
25240116Smarcel
26240116Smarcel#include <atf-c/macros.h>
27240116Smarcel
28240116Smarcelvoid atf_require_inside_if(void);
29240116Smarcelvoid atf_require_equal_inside_if(void);
30240116Smarcelvoid atf_check_errno_semicolons(void);
31240116Smarcelvoid atf_require_errno_semicolons(void);
32240116Smarcel
33240116Smarcelvoid
34240116Smarcelatf_require_inside_if(void)
35240116Smarcel{
36240116Smarcel    /* Make sure that ATF_REQUIRE can be used inside an if statement that
37240116Smarcel     * does not have braces.  Earlier versions of it generated an error
38240116Smarcel     * if there was an else clause because they confused the compiler
39240116Smarcel     * by defining an unprotected nested if. */
40240116Smarcel    if (true)
41240116Smarcel        ATF_REQUIRE(true);
42240116Smarcel    else
43240116Smarcel        ATF_REQUIRE(true);
44240116Smarcel}
45240116Smarcel
46240116Smarcelvoid
47240116Smarcelatf_require_equal_inside_if(void)
48240116Smarcel{
49240116Smarcel    /* Make sure that ATF_REQUIRE_EQUAL can be used inside an if statement
50240116Smarcel     * that does not have braces.  Earlier versions of it generated an
51240116Smarcel     * error if there was an else clause because they confused the
52240116Smarcel     * compiler by defining an unprotected nested if. */
53240116Smarcel    if (true)
54240116Smarcel        ATF_REQUIRE_EQ(true, true);
55240116Smarcel    else
56240116Smarcel        ATF_REQUIRE_EQ(true, true);
57240116Smarcel}
58240116Smarcel
59240116Smarcelvoid
60240116Smarcelatf_check_errno_semicolons(void)
61240116Smarcel{
62240116Smarcel    /* Check that ATF_CHECK_ERRNO does not contain a semicolon that would
63240116Smarcel     * cause an empty-statement that confuses some compilers. */
64240116Smarcel    ATF_CHECK_ERRNO(1, 1 == 1);
65240116Smarcel    ATF_CHECK_ERRNO(2, 2 == 2);
66240116Smarcel}
67240116Smarcel
68240116Smarcelvoid
69240116Smarcelatf_require_errno_semicolons(void)
70240116Smarcel{
71240116Smarcel    /* Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would
72240116Smarcel     * cause an empty-statement that confuses some compilers. */
73240116Smarcel    ATF_REQUIRE_ERRNO(1, 1 == 1);
74240116Smarcel    ATF_REQUIRE_ERRNO(2, 2 == 2);
75240116Smarcel}
76240116Smarcel
77240116Smarcel/* Test case names should not be expanded during instatiation so that they
78240116Smarcel * can have the exact same name as macros. */
79240116Smarcel#define TEST_MACRO_1 invalid + name
80240116Smarcel#define TEST_MACRO_2 invalid + name
81240116Smarcel#define TEST_MACRO_3 invalid + name
82240116SmarcelATF_TC(TEST_MACRO_1);
83240116SmarcelATF_TC_HEAD(TEST_MACRO_1, tc) { if (tc != NULL) {} }
84240116SmarcelATF_TC_BODY(TEST_MACRO_1, tc) { if (tc != NULL) {} }
85240116Smarcelatf_tc_t *test_name_1 = &ATF_TC_NAME(TEST_MACRO_1);
86272307Srodrigcatf_tc_pack_t *test_pack_1 = &ATF_TC_PACK_NAME(TEST_MACRO_1);
87240116Smarcelvoid (*head_1)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_1);
88240116Smarcelvoid (*body_1)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_1);
89240116SmarcelATF_TC_WITH_CLEANUP(TEST_MACRO_2);
90240116SmarcelATF_TC_HEAD(TEST_MACRO_2, tc) { if (tc != NULL) {} }
91240116SmarcelATF_TC_BODY(TEST_MACRO_2, tc) { if (tc != NULL) {} }
92240116SmarcelATF_TC_CLEANUP(TEST_MACRO_2, tc) { if (tc != NULL) {} }
93240116Smarcelatf_tc_t *test_name_2 = &ATF_TC_NAME(TEST_MACRO_2);
94272307Srodrigcatf_tc_pack_t *test_pack_2 = &ATF_TC_PACK_NAME(TEST_MACRO_2);
95240116Smarcelvoid (*head_2)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_2);
96240116Smarcelvoid (*body_2)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_2);
97240116Smarcelvoid (*cleanup_2)(const atf_tc_t *) = ATF_TC_CLEANUP_NAME(TEST_MACRO_2);
98240116SmarcelATF_TC_WITHOUT_HEAD(TEST_MACRO_3);
99240116SmarcelATF_TC_BODY(TEST_MACRO_3, tc) { if (tc != NULL) {} }
100240116Smarcelatf_tc_t *test_name_3 = &ATF_TC_NAME(TEST_MACRO_3);
101272307Srodrigcatf_tc_pack_t *test_pack_3 = &ATF_TC_PACK_NAME(TEST_MACRO_3);
102240116Smarcelvoid (*body_3)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_3);
103