1 /* $NetBSD: macros_h_test.c,v 1.3 2014/12/10 04:38:03 christos Exp $ */ 2 3 /* 4 * Automated Testing Framework (atf) 5 * 6 * Copyright (c) 2008 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 34 void atf_require_inside_if(void); 35 void atf_require_equal_inside_if(void); 36 void atf_check_errno_semicolons(void); 37 void atf_require_errno_semicolons(void); 38 39 void 40 atf_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 52 void 53 atf_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 65 void 66 atf_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 74 void 75 atf_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 88 ATF_TC(TEST_MACRO_1); 89 ATF_TC_HEAD(TEST_MACRO_1, tc) { if (tc != NULL) {} } 90 ATF_TC_BODY(TEST_MACRO_1, tc) { if (tc != NULL) {} } 91 atf_tc_t *test_name_1 = &ATF_TC_NAME(TEST_MACRO_1); 92 void (*head_1)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_1); 93 void (*body_1)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_1); 94 ATF_TC_WITH_CLEANUP(TEST_MACRO_2); 95 ATF_TC_HEAD(TEST_MACRO_2, tc) { if (tc != NULL) {} } 96 ATF_TC_BODY(TEST_MACRO_2, tc) { if (tc != NULL) {} } 97 ATF_TC_CLEANUP(TEST_MACRO_2, tc) { if (tc != NULL) {} } 98 atf_tc_t *test_name_2 = &ATF_TC_NAME(TEST_MACRO_2); 99 void (*head_2)(atf_tc_t *) = ATF_TC_HEAD_NAME(TEST_MACRO_2); 100 void (*body_2)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_2); 101 void (*cleanup_2)(const atf_tc_t *) = ATF_TC_CLEANUP_NAME(TEST_MACRO_2); 102 ATF_TC_WITHOUT_HEAD(TEST_MACRO_3); 103 ATF_TC_BODY(TEST_MACRO_3, tc) { if (tc != NULL) {} } 104 atf_tc_t *test_name_3 = &ATF_TC_NAME(TEST_MACRO_3); 105 void (*body_3)(const atf_tc_t *) = ATF_TC_BODY_NAME(TEST_MACRO_3); 106