Path: blob/main/contrib/atf/atf-c++/macros_hpp_test.cpp
39507 views
// Copyright (c) 2008 The NetBSD Foundation, Inc.1// All rights reserved.2//3// Redistribution and use in source and binary forms, with or without4// modification, are permitted provided that the following conditions5// are met:6// 1. Redistributions of source code must retain the above copyright7// notice, this list of conditions and the following disclaimer.8// 2. Redistributions in binary form must reproduce the above copyright9// notice, this list of conditions and the following disclaimer in the10// documentation and/or other materials provided with the distribution.11//12// THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND13// CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,14// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF15// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.16// IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY17// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE19// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS20// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER21// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR22// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN23// IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.2425#include <atf-c++/macros.hpp>2627#include <stdexcept>2829void30atf_check_errno_semicolons(void)31{32// Check that ATF_CHECK_ERRNO does not contain a semicolon that would33// cause an empty-statement that confuses some compilers.34ATF_CHECK_ERRNO(1, 1 == 1);35ATF_CHECK_ERRNO(2, 2 == 2);36}3738void39atf_require_inside_if(void)40{41// Make sure that ATF_REQUIRE can be used inside an if statement that42// does not have braces. Earlier versions of it generated an error43// if there was an else clause because they confused the compiler44// by defining an unprotected nested if.45if (true)46ATF_REQUIRE(true);47else48ATF_REQUIRE(true);49}5051void52atf_require_eq_inside_if(void)53{54// Make sure that ATF_REQUIRE_EQ can be used inside an if statement55// that does not have braces. Earlier versions of it generated an56// error if there was an else clause because they confused the57// compiler by defining an unprotected nested if.58if (true)59ATF_REQUIRE_EQ(true, true);60else61ATF_REQUIRE_EQ(true, true);62}6364void65atf_require_throw_runtime_error(void)66{67// Check that we can pass std::runtime_error to ATF_REQUIRE_THROW.68// Earlier versions generated a warning because the macro's code also69// attempted to capture this exception, and thus we had a duplicate70// catch clause.71ATF_REQUIRE_THROW(std::runtime_error, (void)0);72}7374void75atf_require_throw_inside_if(void)76{77// Make sure that ATF_REQUIRE_THROW can be used inside an if statement78// that does not have braces. Earlier versions of it generated an79// error because a trailing ; after a catch block was not allowed.80if (true)81ATF_REQUIRE_THROW(std::runtime_error, (void)0);82else83ATF_REQUIRE_THROW(std::runtime_error, (void)1);84}8586void87atf_require_errno_semicolons(void)88{89// Check that ATF_REQUIRE_ERRNO does not contain a semicolon that would90// cause an empty-statement that confuses some compilers.91ATF_REQUIRE_ERRNO(1, 1 == 1);92ATF_REQUIRE_ERRNO(2, 2 == 2);93}9495// Test case names should not be expanded during instatiation so that they96// can have the exact same name as macros.97#define TEST_MACRO_1 invalid + name98#define TEST_MACRO_2 invalid + name99#define TEST_MACRO_3 invalid + name100ATF_TEST_CASE(TEST_MACRO_1);101ATF_TEST_CASE_HEAD(TEST_MACRO_1) { }102ATF_TEST_CASE_BODY(TEST_MACRO_1) { }103void instantiate_1(void) {104ATF_TEST_CASE_USE(TEST_MACRO_1);105atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_1)();106delete the_test;107}108ATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_2);109ATF_TEST_CASE_HEAD(TEST_MACRO_2) { }110ATF_TEST_CASE_BODY(TEST_MACRO_2) { }111ATF_TEST_CASE_CLEANUP(TEST_MACRO_2) { }112void instatiate_2(void) {113ATF_TEST_CASE_USE(TEST_MACRO_2);114atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_2)();115delete the_test;116}117ATF_TEST_CASE_WITH_CLEANUP(TEST_MACRO_3);118ATF_TEST_CASE_HEAD(TEST_MACRO_3) { }119ATF_TEST_CASE_BODY(TEST_MACRO_3) { }120ATF_TEST_CASE_CLEANUP(TEST_MACRO_3) { }121void instatiate_3(void) {122ATF_TEST_CASE_USE(TEST_MACRO_3);123atf::tests::tc* the_test = new ATF_TEST_CASE_NAME(TEST_MACRO_3)();124delete the_test;125}126127128