1/*	$NetBSD: macros_h_test.c,v 1.1.1.1 2011/09/11 17:20:27 christos Exp $	*/
2
3/*
4 * Automated Testing Framework (atf)
5 *
6 * Copyright (c) 2008, 2009, 2010 The NetBSD Foundation, Inc.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
19 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
27 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
29 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#include <atf-c/macros.h>
33
34void atf_require_inside_if(void);
35void atf_require_equal_inside_if(void);
36void atf_check_errno_semicolons(void);
37void atf_require_errno_semicolons(void);
38
39void
40atf_require_inside_if(void)
41{
42    /* Make sure that ATF_REQUIRE can be used inside an if statement that
43     * does not have braces.  Earlier versions of it generated an error
44     * if there was an else clause because they confused the compiler
45     * by defining an unprotected nested if. */
46    if (true)
47        ATF_REQUIRE(true);
48    else
49        ATF_REQUIRE(true);
50}
51
52void
53atf_require_equal_inside_if(void)
54{
55    /* Make sure that ATF_REQUIRE_EQUAL can be used inside an if statement
56     * that does not have braces.  Earlier versions of it generated an
57     * error if there was an else clause because they confused the
58     * compiler by defining an unprotected nested if. */
59    if (true)
60        ATF_REQUIRE_EQ(true, true);
61    else
62        ATF_REQUIRE_EQ(true, true);
63}
64
65void
66atf_check_errno_semicolons(void)
67{
68    /* Check that ATF_CHECK_ERRNO does not contain a semicolon that would
69     * cause an empty-statement that confuses some compilers. */
70    ATF_CHECK_ERRNO(1, 1 == 1);
71    ATF_CHECK_ERRNO(2, 2 == 2);
72}
73
74void
75atf_require_errno_semicolons(void)
76{
77    /* Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would
78     * cause an empty-statement that confuses some compilers. */
79    ATF_REQUIRE_ERRNO(1, 1 == 1);
80    ATF_REQUIRE_ERRNO(2, 2 == 2);
81}
82
83/* Test case names should not be expanded during instatiation so that they
84 * can have the exact same name as macros. */
85#define TEST_MACRO_1 invalid + name
86#define TEST_MACRO_2 invalid + name
87#define TEST_MACRO_3 invalid + name
88ATF_TC(TEST_MACRO_1);
89ATF_TC_HEAD(TEST_MACRO_1, tc) { }
90ATF_TC_BODY(TEST_MACRO_1, tc) { }
91atf_tc_t *test_name_1 = &ATF_TC_NAME(TEST_MACRO_1);
92void (*head_1)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_1);
93void (*body_1)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_1);
94ATF_TC_WITH_CLEANUP(TEST_MACRO_2);
95ATF_TC_HEAD(TEST_MACRO_2, tc) { }
96ATF_TC_BODY(TEST_MACRO_2, tc) { }
97ATF_TC_CLEANUP(TEST_MACRO_2, tc) { }
98atf_tc_t *test_name_2 = &ATF_TC_NAME(TEST_MACRO_2);
99void (*head_2)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_2);
100void (*body_2)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_2);
101void (*cleanup_2)(const atf_tc_t *) = ATF_TC_CLEANUP_NAME(TEST_MACRO_2);
102ATF_TC_WITHOUT_HEAD(TEST_MACRO_3);
103ATF_TC_BODY(TEST_MACRO_3, tc) { }
104atf_tc_t *test_name_3 = &ATF_TC_NAME(TEST_MACRO_3);
105void (*body_3)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_3);
106