| 1 | #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP |
| 2 | #define BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP |
| 3 | |
| 4 | // MS compatible compilers support #pragma once |
| 5 | |
| 6 | #if defined(_MSC_VER) |
| 7 | # pragma once |
| 8 | #endif |
| 9 | |
| 10 | // boost/core/lightweight_test_trait.hpp |
| 11 | // |
| 12 | // BOOST_TEST_TRAIT_TRUE, BOOST_TEST_TRAIT_FALSE, BOOST_TEST_TRAIT_SAME |
| 13 | // |
| 14 | // Copyright 2014, 2021 Peter Dimov |
| 15 | // |
| 16 | // Copyright 2019 Glen Joseph Fernandes |
| 17 | // (glenjofe@gmail.com) |
| 18 | // |
| 19 | // Distributed under the Boost Software License, Version 1.0. |
| 20 | // See accompanying file LICENSE_1_0.txt or copy at |
| 21 | // http://www.boost.org/LICENSE_1_0.txt |
| 22 | |
| 23 | #include <boost/core/lightweight_test.hpp> |
| 24 | #include <boost/core/type_name.hpp> |
| 25 | #include <boost/core/detail/is_same.hpp> |
| 26 | #include <boost/config.hpp> |
| 27 | |
| 28 | namespace boost |
| 29 | { |
| 30 | namespace detail |
| 31 | { |
| 32 | |
| 33 | template< class T > inline void test_trait_impl( char const * trait, void (*)( T ), |
| 34 | bool expected, char const * file, int line, char const * function ) |
| 35 | { |
| 36 | if( T::value == expected ) |
| 37 | { |
| 38 | test_results(); |
| 39 | } |
| 40 | else |
| 41 | { |
| 42 | BOOST_LIGHTWEIGHT_TEST_OSTREAM |
| 43 | << file << "(" << line << "): predicate '" << trait << "' [" |
| 44 | << boost::core::type_name<T>() << "]" |
| 45 | << " test failed in function '" << function |
| 46 | << "' (should have been " << ( expected? "true" : "false" ) << ")" |
| 47 | << std::endl; |
| 48 | |
| 49 | ++test_results().errors(); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | template<class T> inline bool test_trait_same_impl_( T ) |
| 54 | { |
| 55 | return T::value; |
| 56 | } |
| 57 | |
| 58 | template<class T1, class T2> inline void test_trait_same_impl( char const * types, |
| 59 | boost::core::detail::is_same<T1, T2> same, char const * file, int line, char const * function ) |
| 60 | { |
| 61 | if( test_trait_same_impl_( same ) ) |
| 62 | { |
| 63 | test_results(); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | BOOST_LIGHTWEIGHT_TEST_OSTREAM |
| 68 | << file << "(" << line << "): test 'is_same<" << types << ">'" |
| 69 | << " failed in function '" << function |
| 70 | << "' ('" << boost::core::type_name<T1>() |
| 71 | << "' != '" << boost::core::type_name<T2>() << "')" |
| 72 | << std::endl; |
| 73 | |
| 74 | ++test_results().errors(); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | } // namespace detail |
| 79 | } // namespace boost |
| 80 | |
| 81 | #define BOOST_TEST_TRAIT_TRUE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, true, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) ) |
| 82 | #define BOOST_TEST_TRAIT_FALSE(type) ( ::boost::detail::test_trait_impl(#type, (void(*)type)0, false, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) ) |
| 83 | |
| 84 | #if defined(__GNUC__) |
| 85 | // ignoring -Wvariadic-macros with #pragma doesn't work under GCC |
| 86 | # pragma GCC system_header |
| 87 | #endif |
| 88 | |
| 89 | #define BOOST_TEST_TRAIT_SAME(...) ( ::boost::detail::test_trait_same_impl(#__VA_ARGS__, ::boost::core::detail::is_same< __VA_ARGS__ >(), __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) ) |
| 90 | |
| 91 | #endif // #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_TRAIT_HPP |
| 92 | |