diff --git a/.travis.yml b/.travis.yml index a74c257..f7a3095 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,24 +19,6 @@ env: matrix: - BOGUS_JOB=true -addons: - apt: - packages: - - g++-4.7 - - g++-4.8 - - g++-4.9 - - g++-5 - - g++-6 - - clang-3.6 - - clang-3.7 - - clang-3.8 - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise - - llvm-toolchain-precise-3.6 - - llvm-toolchain-precise-3.7 - - llvm-toolchain-precise-3.8 - matrix: exclude: @@ -48,60 +30,206 @@ matrix: - os: linux env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.7 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.7 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-4.8 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.8 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++03 + addons: + apt: + packages: + - g++-4.9 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-4.9 CXXSTD=c++11 + addons: + apt: + packages: + - g++-4.9 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++03 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++11 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-5 CXXSTD=c++14 + addons: + apt: + packages: + - g++-5 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++03 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++11 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++14 + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=gcc COMPILER=g++-6 CXXSTD=c++1z + addons: + apt: + packages: + - g++-6 + sources: + - ubuntu-toolchain-r-test - os: linux env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 + - os: linux + env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++11 + - os: linux env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.6 - os: linux env: TOOLSET=clang COMPILER=clang++-3.6 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.6 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.6 - os: linux env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.7 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 - os: linux env: TOOLSET=clang COMPILER=clang++-3.7 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.7 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.7 - os: linux env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++03 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 - os: linux env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++11 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 - os: linux env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++14 + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 - os: linux env: TOOLSET=clang COMPILER=clang++-3.8 CXXSTD=c++1z + addons: + apt: + packages: + - clang-3.8 + sources: + - ubuntu-toolchain-r-test + - llvm-toolchain-precise-3.8 - os: osx env: TOOLSET=clang COMPILER=clang++ CXXSTD=c++03 diff --git a/doc/lightweight_test.qbk b/doc/lightweight_test.qbk index 4b9abd1..77a3e49 100644 --- a/doc/lightweight_test.qbk +++ b/doc/lightweight_test.qbk @@ -36,6 +36,9 @@ When using `lightweight_test.hpp`, *do not forget* to #define BOOST_ERROR(message) /*unspecified*/ #define BOOST_TEST_EQ(expr1, expr2) /*unspecified*/ #define BOOST_TEST_NE(expr1, expr2) /*unspecified*/ +#define BOOST_TEST_CSTR_EQ(expr1, expr2) /*unspecified*/ +#define BOOST_TEST_CSTR_NE(expr1, expr2) /*unspecified*/ +#define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) /* unspecified */ #define BOOST_TEST_THROWS(expr, excep) /*unspecified*/ namespace boost @@ -101,6 +104,34 @@ message containing both expressions. [endsect] +[section BOOST_TEST_CSTR_EQ] + +`` +BOOST_TEST_CSTR_EQ(expr1, expr2) +`` + +Specialization of BOOST_TEST_EQ which interprets expr1 and expr2 as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) != 0`, increase the error count and output a message containing both expressions. + +[endsect] + +[section BOOST_TEST_CSTR_NE] + +`` +BOOST_TEST_CSTR_NE(expr1, expr2) +`` + +Specialization of BOOST_TEST_NE which interprets expr1 and expr2 as pointers to null-terminated byte strings (C strings). If `std::strcmp(expr1, expr2) == 0`, increase the error count and output a message containing both expressions. + +[section BOOST_TEST_ALL_EQ] + +`` +BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) +`` + +Compares the content of two sequences. If they have different sizes, or if any pairwise element differs, increases the error count and outputs a message containing at most 8 differing elements. + +[endsect] + [section BOOST_TEST_THROWS] `` diff --git a/include/boost/core/addressof.hpp b/include/boost/core/addressof.hpp index 889b582..0a2b46b 100644 --- a/include/boost/core/addressof.hpp +++ b/include/boost/core/addressof.hpp @@ -1,162 +1,265 @@ -// Copyright (C) 2002 Brad King (brad.king@kitware.com) -// Douglas Gregor (gregod@cs.rpi.edu) -// -// Copyright (C) 2002, 2008, 2013 Peter Dimov -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt) +/* +Copyright (C) 2002 Brad King (brad.king@kitware.com) + Douglas Gregor (gregod@cs.rpi.edu) -// For more information, see http://www.boost.org +Copyright (C) 2002, 2008, 2013 Peter Dimov + +Copyright (C) 2017 Glen Joseph Fernandes (glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(See accompanying file LICENSE_1_0.txt or copy at +http://www.boost.org/LICENSE_1_0.txt) +*/ #ifndef BOOST_CORE_ADDRESSOF_HPP #define BOOST_CORE_ADDRESSOF_HPP -# include -# include -# include +#include -namespace boost +#if defined(BOOST_MSVC_FULL_VER) && BOOST_MSVC_FULL_VER >= 190024215 +#define BOOST_CORE_HAS_BUILTIN_ADDRESSOF +#elif defined(BOOST_GCC) && BOOST_GCC >= 70000 +#define BOOST_CORE_HAS_BUILTIN_ADDRESSOF +#elif defined(__has_builtin) +#if __has_builtin(__builtin_addressof) +#define BOOST_CORE_HAS_BUILTIN_ADDRESSOF +#endif +#endif + +#if defined(BOOST_CORE_HAS_BUILTIN_ADDRESSOF) +#if defined(BOOST_NO_CXX11_CONSTEXPR) +#define BOOST_CORE_NO_CONSTEXPR_ADDRESSOF +#endif + +namespace boost { + +template +BOOST_CONSTEXPR inline T* +addressof(T& o) BOOST_NOEXCEPT { + return __builtin_addressof(o); +} -namespace detail -{ - -template struct addr_impl_ref -{ - T & v_; - - BOOST_FORCEINLINE addr_impl_ref( T & v ): v_( v ) {} - BOOST_FORCEINLINE operator T& () const { return v_; } - -private: - addr_impl_ref & operator=(const addr_impl_ref &); -}; - -template struct addressof_impl -{ - static BOOST_FORCEINLINE T * f( T & v, long ) - { - return reinterpret_cast( - &const_cast(reinterpret_cast(v))); - } - - static BOOST_FORCEINLINE T * f( T * v, int ) - { - return v; - } -}; - -#if !defined( BOOST_NO_CXX11_NULLPTR ) - -#if !defined( BOOST_NO_CXX11_DECLTYPE ) && ( ( defined( __clang__ ) && !defined( _LIBCPP_VERSION ) ) || defined( __INTEL_COMPILER ) ) - - typedef decltype(nullptr) addr_nullptr_t; - +} /* boost */ #else +#include +#include - typedef std::nullptr_t addr_nullptr_t; +namespace boost { +namespace detail { +template +class addressof_ref { +public: + BOOST_FORCEINLINE addressof_ref(T& o) BOOST_NOEXCEPT + : o_(o) { } + BOOST_FORCEINLINE operator T&() const BOOST_NOEXCEPT { + return o_; + } +private: + addressof_ref& operator=(const addressof_ref&); + T& o_; +}; + +template +struct address_of { + static BOOST_FORCEINLINE T* get(T& o, long) BOOST_NOEXCEPT { + return reinterpret_cast(& + const_cast(reinterpret_cast(o))); + } + static BOOST_FORCEINLINE T* get(T* p, int) BOOST_NOEXCEPT { + return p; + } +}; + +#if !defined(BOOST_NO_CXX11_NULLPTR) +#if !defined(BOOST_NO_CXX11_DECLTYPE) && \ + (defined(__INTEL_COMPILER) || \ + (defined(__clang__) && !defined(_LIBCPP_VERSION))) +typedef decltype(nullptr) addressof_null_t; +#else +typedef std::nullptr_t addressof_null_t; #endif -template<> struct addressof_impl< addr_nullptr_t > -{ - typedef addr_nullptr_t T; - - static BOOST_FORCEINLINE T * f( T & v, int ) - { - return &v; +template<> +struct address_of { + typedef addressof_null_t type; + static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT { + return &o; } }; -template<> struct addressof_impl< addr_nullptr_t const > -{ - typedef addr_nullptr_t const T; - - static BOOST_FORCEINLINE T * f( T & v, int ) - { - return &v; +template<> +struct address_of { + typedef const addressof_null_t type; + static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT { + return &o; } }; -template<> struct addressof_impl< addr_nullptr_t volatile > -{ - typedef addr_nullptr_t volatile T; - - static BOOST_FORCEINLINE T * f( T & v, int ) - { - return &v; +template<> +struct address_of { + typedef volatile addressof_null_t type; + static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT { + return &o; } }; -template<> struct addressof_impl< addr_nullptr_t const volatile > -{ - typedef addr_nullptr_t const volatile T; - - static BOOST_FORCEINLINE T * f( T & v, int ) - { - return &v; +template<> +struct address_of { + typedef const volatile addressof_null_t type; + static BOOST_FORCEINLINE type* get(type& o, int) BOOST_NOEXCEPT { + return &o; } }; - #endif -} // namespace detail +} /* detail */ + +#if defined(BOOST_NO_CXX11_SFINAE_EXPR) || \ + defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || \ + defined(BOOST_NO_CXX11_CONSTEXPR) || \ + defined(BOOST_NO_CXX11_DECLTYPE) +#define BOOST_CORE_NO_CONSTEXPR_ADDRESSOF + +template +BOOST_FORCEINLINE T* +addressof(T& o) BOOST_NOEXCEPT +{ +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x610)) || \ + BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5120) + return detail::address_of::get(o, 0); +#else + return detail::address_of::get(detail::addressof_ref(o), 0); +#endif +} + +#if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) +namespace detail { + +template +struct addressof_result { + typedef T* type; +}; + +} /* detail */ + +template +BOOST_FORCEINLINE typename detail::addressof_result::type +addressof(T (&o)[N]) BOOST_NOEXCEPT +{ + return &o; +} +#endif + +#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) +template +BOOST_FORCEINLINE +T (*addressof(T (&o)[N]) BOOST_NOEXCEPT)[N] +{ + return reinterpret_cast(&o); +} + +template +BOOST_FORCEINLINE +const T (*addressof(const T (&o)[N]) BOOST_NOEXCEPT)[N] +{ + return reinterpret_cast(&o); +} +#endif +#else +namespace detail { + +template +T&& addressof_declval() BOOST_NOEXCEPT; + +template +struct addressof_void { + typedef void type; +}; + +template +struct addressof_member_operator { + static constexpr bool value = false; +}; + +template +struct addressof_member_operator().operator&())>::type> { + static constexpr bool value = true; +}; + +#if BOOST_WORKAROUND(BOOST_INTEL, < 1600) +struct addressof_addressable { }; + +addressof_addressable* +operator&(addressof_addressable&) BOOST_NOEXCEPT; +#endif + +template +struct addressof_non_member_operator { + static constexpr bool value = false; +}; + +template +struct addressof_non_member_operator()))>::type> { + static constexpr bool value = true; +}; + +template +struct addressof_expression { + static constexpr bool value = false; +}; + +template +struct addressof_expression())>::type> { + static constexpr bool value = true; +}; + +template +struct addressof_is_constexpr { + static constexpr bool value = addressof_expression::value && + !addressof_member_operator::value && + !addressof_non_member_operator::value; +}; + +template +struct addressof_if { }; + +template +struct addressof_if { + typedef T* type; +}; template BOOST_FORCEINLINE -T * addressof( T & v ) +typename addressof_if::value, T>::type +addressof(T& o) BOOST_NOEXCEPT { -#if (defined( __BORLANDC__ ) && BOOST_WORKAROUND( __BORLANDC__, BOOST_TESTED_AT( 0x610 ) ) ) || (defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5120)) - - return boost::detail::addressof_impl::f( v, 0 ); - -#else - - return boost::detail::addressof_impl::f( boost::detail::addr_impl_ref( v ), 0 ); - -#endif + return address_of::get(addressof_ref(o), 0); } -#if defined( __SUNPRO_CC ) && BOOST_WORKAROUND( __SUNPRO_CC, BOOST_TESTED_AT( 0x590 ) ) - -namespace detail +template +constexpr BOOST_FORCEINLINE +typename addressof_if::value, T>::type +addressof(T& o) BOOST_NOEXCEPT { - -template struct addressof_addp -{ - typedef T * type; -}; - -} // namespace detail - -template< class T, std::size_t N > -BOOST_FORCEINLINE -typename detail::addressof_addp< T[N] >::type addressof( T (&t)[N] ) -{ - return &t; + return &o; } -#endif +} /* detail */ -// Borland doesn't like casting an array reference to a char reference -// but these overloads work around the problem. -#if defined( __BORLANDC__ ) && BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) -template -BOOST_FORCEINLINE -T (*addressof(T (&t)[N]))[N] +template +constexpr BOOST_FORCEINLINE T* +addressof(T& o) BOOST_NOEXCEPT { - return reinterpret_cast(&t); -} - -template -BOOST_FORCEINLINE -const T (*addressof(const T (&t)[N]))[N] -{ - return reinterpret_cast(&t); + return detail::addressof(o); } #endif -} // namespace boost +} /* boost */ +#endif -#endif // BOOST_CORE_ADDRESSOF_HPP +#endif diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index d6db024..b4b59c7 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -19,10 +19,12 @@ // http://www.boost.org/LICENSE_1_0.txt // +#include #include #include #include #include +#include // IDE's like Visual Studio perform better if output goes to std::cout or // some other stream, so allow user to configure output stream: @@ -101,6 +103,16 @@ inline void throw_failed_impl(char const * excep, char const * file, int line, c # pragma GCC diagnostic ignored "-Wsign-compare" #endif +// specialize test output for char pointers to avoid printing as cstring +template inline const T& test_output_impl(const T& v) { return v; } +inline const void* test_output_impl(const char* v) { return v; } +inline const void* test_output_impl(const unsigned char* v) { return v; } +inline const void* test_output_impl(const signed char* v) { return v; } +inline const void* test_output_impl(char* v) { return v; } +inline const void* test_output_impl(unsigned char* v) { return v; } +inline const void* test_output_impl(signed char* v) { return v; } +template inline const void* test_output_impl(T volatile* v) { return const_cast(v); } + template inline void test_eq_impl( char const * expr1, char const * expr2, char const * file, int line, char const * function, T const & t, U const & u ) { @@ -113,7 +125,7 @@ template inline void test_eq_impl( char const * expr1, char co BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << "(" << line << "): test '" << expr1 << " == " << expr2 << "' failed in function '" << function << "': " - << "'" << t << "' != '" << u << "'" << std::endl; + << "'" << test_output_impl(t) << "' != '" << test_output_impl(u) << "'" << std::endl; ++test_errors(); } } @@ -130,11 +142,113 @@ template inline void test_ne_impl( char const * expr1, char co BOOST_LIGHTWEIGHT_TEST_OSTREAM << file << "(" << line << "): test '" << expr1 << " != " << expr2 << "' failed in function '" << function << "': " + << "'" << test_output_impl(t) << "' == '" << test_output_impl(u) << "'" << std::endl; + ++test_errors(); + } +} + +inline void test_cstr_eq_impl( char const * expr1, char const * expr2, + char const * file, int line, char const * function, char const * const t, char const * const u ) +{ + if( std::strcmp(t, u) == 0 ) + { + report_errors_remind(); + } + else + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " == " << expr2 + << "' failed in function '" << function << "': " + << "'" << t << "' != '" << u << "'" << std::endl; + ++test_errors(); + } +} + +inline void test_cstr_ne_impl( char const * expr1, char const * expr2, + char const * file, int line, char const * function, char const * const t, char const * const u ) +{ + if( std::strcmp(t, u) != 0 ) + { + report_errors_remind(); + } + else + { + BOOST_LIGHTWEIGHT_TEST_OSTREAM + << file << "(" << line << "): test '" << expr1 << " == " << expr2 + << "' failed in function '" << function << "': " << "'" << t << "' == '" << u << "'" << std::endl; ++test_errors(); } } +template +void test_all_eq_impl(FormattedOutputFunction& output, + char const * file, int line, char const * function, + InputIterator1 first_begin, InputIterator1 first_end, + InputIterator2 second_begin, InputIterator2 second_end) +{ + InputIterator1 first_it = first_begin; + InputIterator2 second_it = second_begin; + typename std::iterator_traits::difference_type first_index = 0; + typename std::iterator_traits::difference_type second_index = 0; + std::size_t error_count = 0; + const std::size_t max_count = 8; + do + { + while ((first_it != first_end) && (second_it != second_end) && (*first_it == *second_it)) + { + ++first_it; + ++second_it; + ++first_index; + ++second_index; + } + if ((first_it == first_end) || (second_it == second_end)) + { + break; // do-while + } + if (error_count == 0) + { + output << file << "(" << line << "): Container contents differ in function '" << function << "':"; + } + else if (error_count >= max_count) + { + output << " ..."; + break; + } + output << " [" << first_index << "] '" << test_output_impl(*first_it) << "' != '" << test_output_impl(*second_it) << "'"; + ++first_it; + ++second_it; + ++first_index; + ++second_index; + ++error_count; + } while (first_it != first_end); + + first_index += std::distance(first_it, first_end); + second_index += std::distance(second_it, second_end); + if (first_index != second_index) + { + if (error_count == 0) + { + output << file << "(" << line << "): Container sizes differ in function '" << function << "': size(" << first_index << ") != size(" << second_index << ")"; + } + else + { + output << " [*] size(" << first_index << ") != size(" << second_index << ")"; + } + ++error_count; + } + + if (error_count == 0) + { + boost::detail::report_errors_remind(); + } + else + { + output << std::endl; + ++boost::detail::test_errors(); + } +} + #if defined(_MSC_VER) # pragma warning(pop) #elif defined(__clang__) && defined(__has_warning) @@ -177,6 +291,11 @@ inline int report_errors() #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) #define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) +#define BOOST_TEST_CSTR_EQ(expr1,expr2) ( ::boost::detail::test_cstr_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) +#define BOOST_TEST_CSTR_NE(expr1,expr2) ( ::boost::detail::test_cstr_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) ) + +#define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) ( ::boost::detail::test_all_eq_impl(BOOST_LIGHTWEIGHT_TEST_OSTREAM, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, begin1, end1, begin2, end2) ) + #ifndef BOOST_NO_EXCEPTIONS #define BOOST_TEST_THROWS( EXPR, EXCEP ) \ try { \ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f40577d..712de26 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -13,6 +13,7 @@ run addressof_test.cpp ; run addressof_test2.cpp ; run addressof_np_test.cpp ; run addressof_fn_test.cpp ; +compile addressof_constexpr_test.cpp ; run checked_delete_test.cpp ; compile-fail checked_delete_fail.cpp ; @@ -29,6 +30,7 @@ compile-fail ref_rv_fail4.cpp ; compile-fail ref_rv_fail5.cpp ; compile-fail ref_implicit_fail.cpp ; compile-fail ref_implicit_fail2.cpp ; +run ref_cv_test.cpp ; run eif_constructors.cpp ; run eif_dummy_arg_disambiguation.cpp ; @@ -63,6 +65,7 @@ run lightweight_test_test.cpp ; run lightweight_test_test.cpp : : : off : lightweight_test_test_no_except ; run lightweight_test_test2.cpp ; +run lightweight_test_all_eq_test.cpp ; run-fail lightweight_test_fail.cpp ; run-fail lightweight_test_fail2.cpp ; @@ -74,6 +77,8 @@ run-fail lightweight_test_fail7.cpp ; run-fail lightweight_test_fail7.cpp : : : off : lightweight_test_fail7_no_rtti ; run-fail lightweight_test_fail8.cpp ; run-fail lightweight_test_fail8.cpp : : : off : lightweight_test_fail8_no_rtti ; +run-fail lightweight_test_fail9.cpp ; +run-fail lightweight_test_fail10.cpp ; run is_same_test.cpp ; diff --git a/test/addressof_constexpr_test.cpp b/test/addressof_constexpr_test.cpp new file mode 100644 index 0000000..9d93565 --- /dev/null +++ b/test/addressof_constexpr_test.cpp @@ -0,0 +1,21 @@ +/* +Copyright 2017 Glen Joseph Fernandes + + +Distributed under the Boost Software +License, Version 1.0. +http://boost.org/LICENSE_1_0.txt +*/ + +#include +#include + +#if !defined(BOOST_CORE_NO_CONSTEXPR_ADDRESSOF) +struct Type { }; + +static int v1 = 0; +static Type v2 = { }; + +BOOST_STATIC_ASSERT(boost::addressof(v1) == &v1); +BOOST_STATIC_ASSERT(boost::addressof(v2) == &v2); +#endif diff --git a/test/lightweight_test_all_eq_test.cpp b/test/lightweight_test_all_eq_test.cpp new file mode 100644 index 0000000..0fb0fb9 --- /dev/null +++ b/test/lightweight_test_all_eq_test.cpp @@ -0,0 +1,126 @@ +// +// Negative test for BOOST_TEST_ALL_EQ +// +// Copyright (c) 2017 Bjorn Reese +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include +#include +#include + +int main() +{ + int test_cases = 0; + + // Array + + { + int x[] = { 1 }; + int y[] = { 1, 2 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 1, 2 }; + int y[] = { 1 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 2 }; + int y[] = { 1, 2 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + { + int x[] = { 1, 2, 3, 4 }; + int y[] = { 1, 3, 2, 4 }; + BOOST_TEST_ALL_EQ( x, x + sizeof(x)/sizeof(x[0]), y, y + sizeof(y)/sizeof(y[0]) ); + ++test_cases; + } + + // Vector + + { + std::vector x, y; + x.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + y.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1.0f ); x.push_back( 2.0f ); x.push_back( 3.0f ); x.push_back( 4.0f ); + y.push_back( 4.0f ); y.push_back( 2.0f ); y.push_back( 3.0f ); y.push_back( 1.0f ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 ); y.push_back( 4 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 1 ); y.push_back( 3 ); y.push_back( 2 );; + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + // Set + + { + std::set x, y; + x.insert(1); + y.insert(1); y.insert(3); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::set x, y; + x.insert(1); x.insert(2); + y.insert(1); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::set x, y; + x.insert(1); x.insert(2); + y.insert(1); y.insert(3); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + boost::report_errors(); + + return boost::detail::test_errors() != test_cases; +} diff --git a/test/lightweight_test_fail10.cpp b/test/lightweight_test_fail10.cpp new file mode 100644 index 0000000..388c47e --- /dev/null +++ b/test/lightweight_test_fail10.cpp @@ -0,0 +1,18 @@ +// +// Negative test for BOOST_TEST_EQ on const char* +// +// Copyright (c) 2017 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include + +int main() +{ + BOOST_TEST_EQ("xab"+1 , "yab"+1); // compares addresses, not cstrings + + return boost::report_errors(); +} diff --git a/test/lightweight_test_fail9.cpp b/test/lightweight_test_fail9.cpp new file mode 100644 index 0000000..a87a4f1 --- /dev/null +++ b/test/lightweight_test_fail9.cpp @@ -0,0 +1,18 @@ +// +// Negative test for BOOST_TEST_CSTR_EQ +// +// Copyright (c) 2017 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// + +#include + +int main() +{ + BOOST_TEST_CSTR_EQ("x" , "y"); + + return boost::report_errors(); +} diff --git a/test/lightweight_test_test.cpp b/test/lightweight_test_test.cpp index d4808a1..bfef152 100644 --- a/test/lightweight_test_test.cpp +++ b/test/lightweight_test_test.cpp @@ -8,6 +8,7 @@ // http://www.boost.org/LICENSE_1_0.txt // +#include #include struct X @@ -64,11 +65,24 @@ int main() BOOST_TEST_EQ( ++x, ++y ); BOOST_TEST_EQ( x++, y++ ); + BOOST_TEST_CSTR_EQ("xabc"+1, "yabc"+1); // equal cstrings, different addresses + BOOST_TEST_EQ( &y, &y ); // BOOST_TEST_NE BOOST_TEST_NE( ++x, y ); BOOST_TEST_NE( &x, &y ); + BOOST_TEST_NE("xabc"+1, "yabc"+1); // equal cstrings, different addresses + BOOST_TEST_CSTR_NE("x", "y"); + + // BOOST_TEST_ALL_EQ + { + std::vector xarray; + xarray.push_back(1); + xarray.push_back(2); + std::vector yarray(xarray); + BOOST_TEST_ALL_EQ(xarray.begin(), xarray.end(), yarray.begin(), yarray.end()); + } // BOOST_TEST_THROWS diff --git a/test/ref_cv_test.cpp b/test/ref_cv_test.cpp new file mode 100644 index 0000000..734d9b3 --- /dev/null +++ b/test/ref_cv_test.cpp @@ -0,0 +1,35 @@ +// ref_cv_test.cpp: ref( x ) where x is of a cv-qualified type +// +// Copyright (c) 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#define BOOST_TEST_REF( x ) BOOST_TEST( &boost::ref( x ).get() == &x ) +#define BOOST_TEST_CREF( x ) BOOST_TEST( &boost::cref( x ).get() == &x ) + +int main() +{ + int x1 = 1; + int const x2 = 2; + int volatile x3 = 3; + int const volatile x4 = 4; + + BOOST_TEST_REF( x1 ); + BOOST_TEST_CREF( x1 ); + + BOOST_TEST_REF( x2 ); + BOOST_TEST_CREF( x2 ); + + BOOST_TEST_REF( x3 ); + BOOST_TEST_CREF( x3 ); + + BOOST_TEST_REF( x4 ); + BOOST_TEST_CREF( x4 ); + + return boost::report_errors(); +}