diff options
Diffstat (limited to 'src/boost/libs/core/test')
135 files changed, 7261 insertions, 0 deletions
diff --git a/src/boost/libs/core/test/Jamfile.v2 b/src/boost/libs/core/test/Jamfile.v2 new file mode 100644 index 00000000..dfe0b6ab --- /dev/null +++ b/src/boost/libs/core/test/Jamfile.v2 @@ -0,0 +1,171 @@ +# Boost.Core Library test Jamfile +# +# Copyright (c) 2014, 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 + +import modules ; +import testing ; + +# quick test (for CI) +run quick.cpp ; + +# full test suite +run addressof_test.cpp ; +run addressof_test2.cpp ; +run addressof_np_test.cpp ; +run addressof_fn_test.cpp ; +compile addressof_constexpr_test.cpp ; +compile-fail addressof_fail_rvalue.cpp ; + +run checked_delete_test.cpp ; +compile-fail checked_delete_fail.cpp ; +compile-fail checked_delete_fail2.cpp ; + +compile ref_ct_test.cpp ; +run ref_test.cpp ; +run ref_ref_test.cpp ; +run ref_fn_test.cpp ; +compile-fail ref_rv_fail1.cpp ; +compile-fail ref_rv_fail2.cpp ; +compile-fail ref_rv_fail3.cpp ; +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 ; +run eif_lazy.cpp ; +run eif_lazy_test.cpp ; +run eif_member_templates.cpp ; +run eif_namespace_disambiguation.cpp ; +run eif_no_disambiguation.cpp ; +run eif_partial_specializations.cpp ; + +compile-fail noncopyable_compile_fail.cpp ; + +run explicit_operator_bool.cpp ; +run explicit_operator_bool_noexcept.cpp ; +compile-fail explicit_operator_bool_compile_fail_conv_int.cpp ; +compile-fail explicit_operator_bool_compile_fail_conv_pvoid.cpp ; +compile-fail explicit_operator_bool_compile_fail_delete.cpp ; +compile-fail explicit_operator_bool_compile_fail_shift.cpp ; + +compile ignore_unused_test.cpp : <toolset>gcc-4.8:<cxxflags>"-Wunused-variable -Wunused-local-typedefs -Werror" + <toolset>gcc:<cxxflags>"-Wunused-variable -Werror" + <toolset>clang:<cxxflags>"-Wunused-variable -Werror" + <toolset>msvc:<cxxflags>"/we4100 /we4101" ; +run sp_typeinfo_test.cpp ; +run sp_typeinfo_test.cpp : : : <rtti>off : sp_typeinfo_test_no_rtti ; + +run visit_each_test.cpp ; + +run get_pointer_test.cpp ; + +run lightweight_test_test.cpp ; +run lightweight_test_test.cpp : : : <exception-handling>off : lightweight_test_test_no_except ; +run lightweight_test_test2.cpp ; +run lightweight_test_all_with_test.cpp ; +run lightweight_test_lt_le_test.cpp ; +run lightweight_test_gt_ge_test.cpp ; +run lightweight_test_eq_nullptr.cpp ; +run lightweight_test_test3.cpp ; +run lightweight_test_test4.cpp ; +run lightweight_test_test5.cpp : : : + <warnings>extra + <toolset>msvc:<warnings-as-errors>on + <toolset>gcc:<warnings-as-errors>on + <toolset>clang:<warnings-as-errors>on + <toolset>gcc-4.4.7:<cxxflags>-Wno-sign-compare ; + +run-fail lightweight_test_all_eq_test.cpp ; +run-fail lightweight_test_all_with_fail.cpp ; + +run-fail lightweight_test_fail.cpp ; +run-fail lightweight_test_fail2.cpp ; +run-fail lightweight_test_fail3.cpp ; +run-fail lightweight_test_fail4.cpp ; +run-fail lightweight_test_fail5.cpp ; +run-fail lightweight_test_fail6.cpp ; +run-fail lightweight_test_fail7.cpp ; +run-fail lightweight_test_fail7.cpp : : : <rtti>off : lightweight_test_fail7_no_rtti ; +run-fail lightweight_test_fail8.cpp ; +run-fail lightweight_test_fail8.cpp : : : <rtti>off : lightweight_test_fail8_no_rtti ; +run-fail lightweight_test_fail9.cpp ; +run-fail lightweight_test_fail10.cpp ; +run-fail lightweight_test_fail11.cpp ; +run-fail lightweight_test_fail12.cpp ; +run-fail lightweight_test_lt_fail.cpp ; +run-fail lightweight_test_le_fail.cpp ; +run-fail lightweight_test_gt_fail.cpp ; +run-fail lightweight_test_ge_fail.cpp ; + +run is_same_test.cpp ; + +run typeinfo_test.cpp ; +run typeinfo_test.cpp : : : <rtti>off : typeinfo_test_no_rtti ; + +run iterator_test.cpp ; +run detail_iterator_test.cpp ; + +run demangle_test.cpp : : : <test-info>always_show_run_output ; + +run demangled_name_test.cpp : : : <test-info>always_show_run_output ; +run demangled_name_test.cpp : : : <rtti>off <test-info>always_show_run_output : demangled_name_test_no_rtti ; + +run scoped_enum.cpp ; +compile-fail scoped_enum_compile_fail_conv_from_int.cpp ; +compile-fail scoped_enum_compile_fail_conv_to_int.cpp ; + +run underlying_type.cpp ; + +run pointer_traits_pointer_test.cpp ; +run pointer_traits_element_type_test.cpp ; +run pointer_traits_difference_type_test.cpp ; +run pointer_traits_rebind_test.cpp ; +run pointer_traits_pointer_to_test.cpp ; +run to_address_test.cpp ; + +run exchange_test.cpp ; +run exchange_move_test.cpp ; + +run first_scalar_test.cpp ; +compile first_scalar_constexpr_test.cpp ; + +run empty_value_test.cpp ; +run empty_value_size_test.cpp ; +run empty_value_final_test.cpp ; + +run quick_exit_test.cpp ; +run-fail quick_exit_fail.cpp ; + +compile use_default_test.cpp ; + +run default_allocator_test.cpp ; +run noinit_adaptor_test.cpp ; +run alloc_construct_test.cpp ; +run alloc_construct_throws_test.cpp ; +run alloc_construct_cxx11_test.cpp ; + +run nvp_test.cpp ; + +lib lib_typeid : lib_typeid.cpp : <link>shared:<define>LIB_TYPEID_DYN_LINK=1 ; + +run test_lib_typeid.cpp lib_typeid : : : <link>shared : test_lib_typeid_shared ; +run test_lib_typeid.cpp lib_typeid : : : <link>static : test_lib_typeid_static ; + +run test_lib_typeid.cpp lib_typeid : : : <link>shared <rtti>off : test_lib_typeid_shared_no_rtti ; +run test_lib_typeid.cpp lib_typeid : : : <link>static <rtti>off : test_lib_typeid_static_no_rtti ; + +run uncaught_exceptions.cpp : : : <exception-handling>on ; +run uncaught_exceptions_np.cpp : : : <exception-handling>on ; + +run no_exceptions_support_test.cpp ; +run no_exceptions_support_test.cpp : : : <exception-handling>off : no_exceptions_support_test_nx ; + +use-project /boost/core/swap : ./swap ; +build-project ./swap ; diff --git a/src/boost/libs/core/test/addressof_constexpr_test.cpp b/src/boost/libs/core/test/addressof_constexpr_test.cpp new file mode 100644 index 00000000..d7255a93 --- /dev/null +++ b/src/boost/libs/core/test/addressof_constexpr_test.cpp @@ -0,0 +1,20 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include <boost/core/addressof.hpp> +#include <boost/static_assert.hpp> + +#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/src/boost/libs/core/test/addressof_fail_rvalue.cpp b/src/boost/libs/core/test/addressof_fail_rvalue.cpp new file mode 100644 index 00000000..258eaaaa --- /dev/null +++ b/src/boost/libs/core/test/addressof_fail_rvalue.cpp @@ -0,0 +1,26 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include <boost/core/addressof.hpp> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) +struct type { }; + +inline const type function() +{ + return type(); +} + +int main() +{ + (void)boost::addressof(function()); +} +#else +#error Requires rvalue references and deleted functions +#endif diff --git a/src/boost/libs/core/test/addressof_fn_test.cpp b/src/boost/libs/core/test/addressof_fn_test.cpp new file mode 100644 index 00000000..0d043bf4 --- /dev/null +++ b/src/boost/libs/core/test/addressof_fn_test.cpp @@ -0,0 +1,76 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// addressof_fn_test.cpp: addressof( f ) +// +// Copyright (c) 2008, 2009 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 <boost/utility/addressof.hpp> +#include <boost/detail/lightweight_test.hpp> + + +void f0() +{ +} + +void f1(int) +{ +} + +void f2(int, int) +{ +} + +void f3(int, int, int) +{ +} + +void f4(int, int, int, int) +{ +} + +void f5(int, int, int, int, int) +{ +} + +void f6(int, int, int, int, int, int) +{ +} + +void f7(int, int, int, int, int, int, int) +{ +} + +void f8(int, int, int, int, int, int, int, int) +{ +} + +void f9(int, int, int, int, int, int, int, int, int) +{ +} + +int main() +{ + BOOST_TEST( boost::addressof( f0 ) == &f0 ); + BOOST_TEST( boost::addressof( f1 ) == &f1 ); + BOOST_TEST( boost::addressof( f2 ) == &f2 ); + BOOST_TEST( boost::addressof( f3 ) == &f3 ); + BOOST_TEST( boost::addressof( f4 ) == &f4 ); + BOOST_TEST( boost::addressof( f5 ) == &f5 ); + BOOST_TEST( boost::addressof( f6 ) == &f6 ); + BOOST_TEST( boost::addressof( f7 ) == &f7 ); + BOOST_TEST( boost::addressof( f8 ) == &f8 ); + BOOST_TEST( boost::addressof( f9 ) == &f9 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/addressof_np_test.cpp b/src/boost/libs/core/test/addressof_np_test.cpp new file mode 100644 index 00000000..9e155d42 --- /dev/null +++ b/src/boost/libs/core/test/addressof_np_test.cpp @@ -0,0 +1,50 @@ +// +// Copyright 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 +// + +#include <boost/utility/addressof.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <cstddef> + +#if defined( BOOST_NO_CXX11_NULLPTR ) + +void nullptr_test() +{ +} + +#else + +void nullptr_test() +{ + { + auto x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } + + { + auto const volatile x = nullptr; + BOOST_TEST( boost::addressof(x) == &x ); + } +} + +#endif + +int main() +{ + nullptr_test(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/addressof_test.cpp b/src/boost/libs/core/test/addressof_test.cpp new file mode 100644 index 00000000..9619cc3a --- /dev/null +++ b/src/boost/libs/core/test/addressof_test.cpp @@ -0,0 +1,94 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Douglas Gregor (gregod@cs.rpi.edu) +// +// 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) + +// For more information, see http://www.boost.org + + +#include <boost/utility/addressof.hpp> + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include <iostream> + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#include <boost/detail/lightweight_test.hpp> + +template<class T> void scalar_test( T * = 0 ) +{ + T* px = new T(); + + T& x = *px; + BOOST_TEST( boost::addressof(x) == px ); + + const T& cx = *px; + const T* pcx = boost::addressof(cx); + BOOST_TEST( pcx == px ); + + volatile T& vx = *px; + volatile T* pvx = boost::addressof(vx); + BOOST_TEST( pvx == px ); + + const volatile T& cvx = *px; + const volatile T* pcvx = boost::addressof(cvx); + BOOST_TEST( pcvx == px ); + + delete px; +} + +template<class T> void array_test( T * = 0 ) +{ + T nrg[3] = {1,2,3}; + T (*pnrg)[3] = &nrg; + BOOST_TEST( boost::addressof(nrg) == pnrg ); + + T const cnrg[3] = {1,2,3}; + T const (*pcnrg)[3] = &cnrg; + BOOST_TEST( boost::addressof(cnrg) == pcnrg ); +} + +struct addressable +{ + addressable( int = 0 ) + { + } +}; + +struct useless_type {}; + +class nonaddressable { +public: + + nonaddressable( int = 0 ) + { + } + + void dummy(); // Silence GCC warning: all member of class are private + +private: + + useless_type operator&() const; +}; + +int main() +{ + scalar_test<char>(); + scalar_test<int>(); + scalar_test<addressable>(); + scalar_test<nonaddressable>(); + + array_test<char>(); + array_test<int>(); + array_test<addressable>(); + array_test<nonaddressable>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/addressof_test2.cpp b/src/boost/libs/core/test/addressof_test2.cpp new file mode 100644 index 00000000..b1c36f82 --- /dev/null +++ b/src/boost/libs/core/test/addressof_test2.cpp @@ -0,0 +1,95 @@ +// Copyright (C) 2002 Brad King (brad.king@kitware.com) +// Douglas Gregor (gregod@cs.rpi.edu) +// +// Copyright 2009 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) + +// For more information, see http://www.boost.org + + +#include <boost/utility/addressof.hpp> + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(push, 3) +#endif + +#include <iostream> + +#if defined(BOOST_MSVC) && (BOOST_MSVC < 1300) +#pragma warning(pop) +#endif + +#include <boost/detail/lightweight_test.hpp> + +template<class T> void scalar_test( T * = 0 ) +{ + T* px = new T(); + + T& x = *px; + BOOST_TEST( boost::addressof(x) == px ); + + const T& cx = *px; + const T* pcx = boost::addressof(cx); + BOOST_TEST( pcx == px ); + + volatile T& vx = *px; + volatile T* pvx = boost::addressof(vx); + BOOST_TEST( pvx == px ); + + const volatile T& cvx = *px; + const volatile T* pcvx = boost::addressof(cvx); + BOOST_TEST( pcvx == px ); + + delete px; +} + +template<class T> void array_test( T * = 0 ) +{ + T nrg[3] = {1,2,3}; + T (*pnrg)[3] = &nrg; + BOOST_TEST( boost::addressof(nrg) == pnrg ); + + T const cnrg[3] = {1,2,3}; + T const (*pcnrg)[3] = &cnrg; + BOOST_TEST( boost::addressof(cnrg) == pcnrg ); +} + +class convertible { +public: + + convertible( int = 0 ) + { + } + + template<class U> operator U () const + { + return U(); + } +}; + +class convertible2 { +public: + + convertible2( int = 0 ) + { + } + + operator convertible2* () const + { + return 0; + } +}; + +int main() +{ + scalar_test<convertible>(); + scalar_test<convertible2>(); + + array_test<convertible>(); + array_test<convertible2>(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/alloc_construct_cxx11_test.cpp b/src/boost/libs/core/test/alloc_construct_cxx11_test.cpp new file mode 100644 index 00000000..2075d7a2 --- /dev/null +++ b/src/boost/libs/core/test/alloc_construct_cxx11_test.cpp @@ -0,0 +1,78 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <boost/core/alloc_construct.hpp> +#include <boost/core/lightweight_test.hpp> + +class type { +public: + explicit type(int x) + : value_(x) { } + + int value() const { + return value_; + } + + static int count; + +private: + type(const type&); + type& operator=(const type&); + + int value_; +}; + +int type::count = 0; + +template<class T> +struct creator { + typedef T value_type; + + creator() { } + + template<class U> + creator(const creator<U>&) { } + + T* allocate(std::size_t size) { + return static_cast<T*>(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } + + template<class V> + void construct(type* ptr, const V& value) { + ::new(static_cast<void*>(ptr)) type(value + 1); + ++type::count; + } + + void destroy(type* ptr) { + ptr->~type(); + --type::count; + } +}; + +int main() +{ + creator<type> a; + type* p = a.allocate(1); + boost::alloc_construct(a, p, 1); + BOOST_TEST_EQ(type::count, 1); + BOOST_TEST_EQ(p->value(), 2); + boost::alloc_destroy(a, p); + BOOST_TEST_EQ(type::count, 0); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/core/test/alloc_construct_test.cpp b/src/boost/libs/core/test/alloc_construct_test.cpp new file mode 100644 index 00000000..511afc61 --- /dev/null +++ b/src/boost/libs/core/test/alloc_construct_test.cpp @@ -0,0 +1,135 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/alloc_construct.hpp> +#include <boost/core/default_allocator.hpp> +#include <boost/core/lightweight_test.hpp> + +class type { +public: + explicit type(int x = 0, int y = 0) + : value_(x + y) { + ++count; + } + + type(const type& other) + : value_(other.value_) { + ++count; + } + + ~type() { + --count; + } + + int value() const { + return value_; + } + + static int count; + +private: + int value_; +}; + +int type::count = 0; + +void test_construct() +{ + boost::default_allocator<type> a; + type* p = a.allocate(1); + boost::alloc_construct(a, p); + BOOST_TEST_EQ(type::count, 1); + BOOST_TEST_EQ(p->value(), 0); + boost::alloc_destroy(a, p); + BOOST_TEST_EQ(type::count, 0); + a.deallocate(p, 1); +} + +void test_construct_value() +{ + boost::default_allocator<type> a; + type* p = a.allocate(1); + boost::alloc_construct(a, p, 1); + BOOST_TEST_EQ(type::count, 1); + BOOST_TEST_EQ(p->value(), 1); + boost::alloc_destroy(a, p); + BOOST_TEST_EQ(type::count, 0); + a.deallocate(p, 1); +} + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +void test_construct_args() +{ + boost::default_allocator<type> a; + type* p = a.allocate(1); + boost::alloc_construct(a, p, 1, 2); + BOOST_TEST_EQ(type::count, 1); + BOOST_TEST_EQ(p->value(), 3); + boost::alloc_destroy(a, p); + BOOST_TEST_EQ(type::count, 0); + a.deallocate(p, 1); +} +#endif + +void test_construct_n() +{ + boost::default_allocator<type> a; + type* p = a.allocate(3); + boost::alloc_construct_n(a, p, 3); + BOOST_TEST_EQ(type::count, 3); + BOOST_TEST_EQ(p[0].value(), 0); + BOOST_TEST_EQ(p[1].value(), 0); + BOOST_TEST_EQ(p[2].value(), 0); + boost::alloc_destroy_n(a, p, 3); + BOOST_TEST_EQ(type::count, 0); + a.deallocate(p, 3); +} + +void test_construct_n_list() +{ + boost::default_allocator<type> a; + type* p = a.allocate(3); + type q(1); + boost::alloc_construct_n(a, p, 3, &q, 1); + BOOST_TEST_EQ(type::count, 4); + BOOST_TEST_EQ(p[0].value(), 1); + BOOST_TEST_EQ(p[1].value(), 1); + BOOST_TEST_EQ(p[2].value(), 1); + boost::alloc_destroy_n(a, p, 3); + BOOST_TEST_EQ(type::count, 1); + a.deallocate(p, 3); +} + +void test_construct_n_iterator() +{ + boost::default_allocator<type> a; + type* p = a.allocate(3); + type l[] = { type(1), type(2), type(3) }; + boost::alloc_construct_n(a, p, 3, &l[0]); + BOOST_TEST_EQ(type::count, 6); + BOOST_TEST_EQ(p[0].value(), 1); + BOOST_TEST_EQ(p[1].value(), 2); + BOOST_TEST_EQ(p[2].value(), 3); + boost::alloc_destroy_n(a, p, 3); + BOOST_TEST_EQ(type::count, 3); + a.deallocate(p, 3); +} + +int main() +{ + test_construct(); + test_construct_value(); +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \ + !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + test_construct_args(); +#endif + test_construct_n(); + test_construct_n_list(); + test_construct_n_iterator(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/alloc_construct_throws_test.cpp b/src/boost/libs/core/test/alloc_construct_throws_test.cpp new file mode 100644 index 00000000..0a86fc8f --- /dev/null +++ b/src/boost/libs/core/test/alloc_construct_throws_test.cpp @@ -0,0 +1,46 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/alloc_construct.hpp> +#include <boost/core/default_allocator.hpp> +#include <boost/core/lightweight_test.hpp> + +class type { +public: + type() { + if (count == 4) { + throw true; + } + ++count; + } + + ~type() { + --count; + } + + static int count; + +private: + type(const type&); + type& operator=(const type&); +}; + +int type::count = 0; + +int main() +{ + boost::default_allocator<type> a; + type* p = a.allocate(5); + try { + boost::alloc_construct_n(a, p, 5); + BOOST_ERROR("construct_n did not throw"); + } catch (...) { + BOOST_TEST_EQ(type::count, 0); + } + a.deallocate(p, 5); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/checked_delete_fail.cpp b/src/boost/libs/core/test/checked_delete_fail.cpp new file mode 100644 index 00000000..76418db5 --- /dev/null +++ b/src/boost/libs/core/test/checked_delete_fail.cpp @@ -0,0 +1,27 @@ +// Boost checked_delete test program ---------------------------------------// + +// Copyright Beman Dawes 2001. 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) + +// See http://www.boost.org/libs/utility for documentation. + +// Revision History +// 21 May 01 Initial version (Beman Dawes) + +#include <boost/checked_delete.hpp> // for checked_delete + +// This program demonstrates compiler errors when trying to delete an +// incomplete type. + +namespace +{ + class Incomplete; +} + +int main() +{ + Incomplete * p = 0; + boost::checked_delete(p); // should cause compile time error + return 0; +} // main diff --git a/src/boost/libs/core/test/checked_delete_fail2.cpp b/src/boost/libs/core/test/checked_delete_fail2.cpp new file mode 100644 index 00000000..f7362a93 --- /dev/null +++ b/src/boost/libs/core/test/checked_delete_fail2.cpp @@ -0,0 +1,27 @@ +// Boost checked_delete test program ---------------------------------------// + +// Copyright Beman Dawes 2001. 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) + +// See http://www.boost.org/libs/utility for documentation. + +// Revision History +// 21 May 01 Initial version (Beman Dawes) + +#include <boost/checked_delete.hpp> // for checked_delete + +// This program demonstrates compiler errors when trying to delete an +// incomplete type. + +namespace +{ + class Incomplete; +} + +int main() +{ + Incomplete * p = 0; + boost::checked_array_delete(p); // should cause compile time error + return 0; +} // main diff --git a/src/boost/libs/core/test/checked_delete_test.cpp b/src/boost/libs/core/test/checked_delete_test.cpp new file mode 100644 index 00000000..46c2aedc --- /dev/null +++ b/src/boost/libs/core/test/checked_delete_test.cpp @@ -0,0 +1,58 @@ +// Boost checked_delete test program + +// Copyright Beman Dawes 2001. Copyright 2014 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 <boost/core/checked_delete.hpp> +#include <boost/core/lightweight_test.hpp> + +struct X +{ + static int instances; + + X() + { + ++instances; + } + + ~X() + { + --instances; + } + +private: + + X( X const & ); + X & operator=( X const & ); +}; + +int X::instances = 0; + +int main() +{ + BOOST_TEST( X::instances == 0 ); + + { + X * p = new X; + + BOOST_TEST( X::instances == 1 ); + + boost::checked_delete( p ); + + BOOST_TEST( X::instances == 0 ); + } + + { + X * p = new X[ 3 ]; + + BOOST_TEST( X::instances == 3 ); + + boost::checked_array_delete( p ); + + BOOST_TEST( X::instances == 0 ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/cmake_subdir_test/CMakeLists.txt b/src/boost/libs/core/test/cmake_subdir_test/CMakeLists.txt new file mode 100644 index 00000000..ae24a60f --- /dev/null +++ b/src/boost/libs/core/test/cmake_subdir_test/CMakeLists.txt @@ -0,0 +1,19 @@ +# Copyright 2018, 2019 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 + +cmake_minimum_required(VERSION 3.5) + +project(cmake_subdir_test LANGUAGES CXX) + +add_subdirectory(../.. boostorg/core) +add_subdirectory(../../../assert boostorg/assert) +add_subdirectory(../../../config boostorg/config) + +add_executable(quick ../quick.cpp) +target_link_libraries(quick Boost::core) + +enable_testing() +add_test(quick quick) + +add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>) diff --git a/src/boost/libs/core/test/default_allocator_test.cpp b/src/boost/libs/core/test/default_allocator_test.cpp new file mode 100644 index 00000000..e9217470 --- /dev/null +++ b/src/boost/libs/core/test/default_allocator_test.cpp @@ -0,0 +1,277 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/default_allocator.hpp> +#include <boost/core/lightweight_test_trait.hpp> +#include <vector> +#include <list> + +class type { +public: + explicit type(double value) + : value_(value) { } + +private: + type(const type&); + type& operator=(const type&); + + double value_; +}; + +void test_value_type() +{ + BOOST_TEST_TRAIT_SAME(int, + boost::default_allocator<int>::value_type); + BOOST_TEST_TRAIT_SAME(type, + boost::default_allocator<type>::value_type); + BOOST_TEST_TRAIT_SAME(int[5], + boost::default_allocator<int[5]>::value_type); + BOOST_TEST_TRAIT_SAME(void, + boost::default_allocator<void>::value_type); +} + +void test_pointer() +{ + BOOST_TEST_TRAIT_SAME(int*, + boost::default_allocator<int>::pointer); + BOOST_TEST_TRAIT_SAME(type*, + boost::default_allocator<type>::pointer); + BOOST_TEST_TRAIT_SAME(int(*)[5], + boost::default_allocator<int[5]>::pointer); + BOOST_TEST_TRAIT_SAME(void*, + boost::default_allocator<void>::pointer); +} + +void test_const_pointer() +{ + BOOST_TEST_TRAIT_SAME(const int*, + boost::default_allocator<int>::const_pointer); + BOOST_TEST_TRAIT_SAME(const type*, + boost::default_allocator<type>::const_pointer); + BOOST_TEST_TRAIT_SAME(const int(*)[5], + boost::default_allocator<int[5]>::const_pointer); + BOOST_TEST_TRAIT_SAME(const void*, + boost::default_allocator<void>::const_pointer); +} + +void test_reference() +{ + BOOST_TEST_TRAIT_SAME(int&, + boost::default_allocator<int>::reference); + BOOST_TEST_TRAIT_SAME(type&, + boost::default_allocator<type>::reference); + BOOST_TEST_TRAIT_SAME(int(&)[5], + boost::default_allocator<int[5]>::reference); + BOOST_TEST_TRAIT_SAME(void, + boost::default_allocator<void>::reference); +} + +void test_const_reference() +{ + BOOST_TEST_TRAIT_SAME(const int&, + boost::default_allocator<int>::const_reference); + BOOST_TEST_TRAIT_SAME(const type&, + boost::default_allocator<type>::const_reference); + BOOST_TEST_TRAIT_SAME(const int(&)[5], + boost::default_allocator<int[5]>::const_reference); + BOOST_TEST_TRAIT_SAME(const void, + boost::default_allocator<void>::const_reference); +} + +void test_size_type() +{ + BOOST_TEST_TRAIT_SAME(std::size_t, + boost::default_allocator<int>::size_type); + BOOST_TEST_TRAIT_SAME(std::size_t, + boost::default_allocator<type>::size_type); + BOOST_TEST_TRAIT_SAME(std::size_t, + boost::default_allocator<int[5]>::size_type); + BOOST_TEST_TRAIT_SAME(std::size_t, + boost::default_allocator<void>::size_type); +} + +void test_difference_type() +{ + BOOST_TEST_TRAIT_SAME(std::ptrdiff_t, + boost::default_allocator<int>::difference_type); + BOOST_TEST_TRAIT_SAME(std::ptrdiff_t, + boost::default_allocator<type>::difference_type); + BOOST_TEST_TRAIT_SAME(std::ptrdiff_t, + boost::default_allocator<int[5]>::difference_type); + BOOST_TEST_TRAIT_SAME(std::ptrdiff_t, + boost::default_allocator<void>::difference_type); +} + +void test_propagate_on_container_move_assignment() +{ + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<int>:: + propagate_on_container_move_assignment)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<type>:: + propagate_on_container_move_assignment)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<int[5]>:: + propagate_on_container_move_assignment)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<void>:: + propagate_on_container_move_assignment)); +} + +void test_is_always_equal() +{ + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<int>::is_always_equal)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<type>::is_always_equal)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<int[5]>::is_always_equal)); + BOOST_TEST_TRAIT_TRUE((boost::default_allocator<void>::is_always_equal)); +} + +void test_rebind() +{ + BOOST_TEST_TRAIT_SAME(boost::default_allocator<type>, + boost::default_allocator<int>::rebind<type>::other); + BOOST_TEST_TRAIT_SAME(boost::default_allocator<int[5]>, + boost::default_allocator<type>::rebind<int[5]>::other); + BOOST_TEST_TRAIT_SAME(boost::default_allocator<void>, + boost::default_allocator<int[5]>::rebind<void>::other); + BOOST_TEST_TRAIT_SAME(boost::default_allocator<int>, + boost::default_allocator<void>::rebind<int>::other); +} + +void test_default_construct() +{ + boost::default_allocator<int> a1; + (void)a1; + boost::default_allocator<type> a2; + (void)a2; + boost::default_allocator<int[5]> a3; + (void)a3; + boost::default_allocator<void> a4; + (void)a4; +} + +void test_copy() +{ + boost::default_allocator<int> a1; + boost::default_allocator<int> a2(a1); + (void)a2; + boost::default_allocator<int[5]> a3; + boost::default_allocator<int[5]> a4(a3); + (void)a4; + boost::default_allocator<void> a5; + boost::default_allocator<void> a6(a5); + (void)a6; +} + +void test_construct_other() +{ + boost::default_allocator<int> a1; + boost::default_allocator<type> a2(a1); + boost::default_allocator<int[5]> a3(a2); + boost::default_allocator<void> a4(a3); + boost::default_allocator<int> a5(a4); + (void)a5; +} + +#if defined(PTRDIFF_MAX) && defined(SIZE_MAX) +template<class T> +std::size_t max_size() +{ + return PTRDIFF_MAX < SIZE_MAX / sizeof(T) + ? PTRDIFF_MAX : SIZE_MAX / sizeof(T); +} +#else +template<class T> +std::size_t max_size() +{ + return ~static_cast<std::size_t>(0) / sizeof(T); +} +#endif + +void test_max_size() +{ + BOOST_TEST_EQ(max_size<int>(), + boost::default_allocator<int>().max_size()); + BOOST_TEST_EQ(max_size<type>(), + boost::default_allocator<type>().max_size()); + BOOST_TEST_EQ(max_size<int[5]>(), + boost::default_allocator<int[5]>().max_size()); +} + +template<class T> +void test_allocate() +{ + boost::default_allocator<T> a; + T* p = a.allocate(1); + BOOST_TEST(p != 0); + a.deallocate(p, 1); + p = a.allocate(0); + a.deallocate(p, 0); + BOOST_TEST_THROWS(a.allocate(a.max_size() + 1), std::bad_alloc); +} + +void test_allocate_deallocate() +{ + test_allocate<int>(); + test_allocate<type>(); + test_allocate<int[5]>(); +} + +void test_equals() +{ + BOOST_TEST(boost::default_allocator<int>() == + boost::default_allocator<type>()); + BOOST_TEST(boost::default_allocator<type>() == + boost::default_allocator<int[5]>()); + BOOST_TEST(boost::default_allocator<int[5]>() == + boost::default_allocator<void>()); + BOOST_TEST(boost::default_allocator<void>() == + boost::default_allocator<int>()); +} + +void test_not_equals() +{ + BOOST_TEST(!(boost::default_allocator<int>() != + boost::default_allocator<type>())); + BOOST_TEST(!(boost::default_allocator<type>() != + boost::default_allocator<int[5]>())); + BOOST_TEST(!(boost::default_allocator<int[5]>() != + boost::default_allocator<void>())); + BOOST_TEST(!(boost::default_allocator<void>() != + boost::default_allocator<int>())); +} + +void test_container() +{ + std::vector<int, boost::default_allocator<int> > v; + v.push_back(1); + BOOST_TEST(v.size() == 1); + BOOST_TEST(v.front() == 1); + std::list<int, boost::default_allocator<int> > l; + l.push_back(1); + BOOST_TEST(l.size() == 1); + BOOST_TEST(l.front() == 1); +} + +int main() +{ + test_value_type(); + test_pointer(); + test_const_pointer(); + test_reference(); + test_const_reference(); + test_size_type(); + test_difference_type(); + test_propagate_on_container_move_assignment(); + test_is_always_equal(); + test_rebind(); + test_default_construct(); + test_copy(); + test_construct_other(); + test_max_size(); + test_allocate_deallocate(); + test_equals(); + test_not_equals(); + test_container(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/demangle_test.cpp b/src/boost/libs/core/test/demangle_test.cpp new file mode 100644 index 00000000..0656ed55 --- /dev/null +++ b/src/boost/libs/core/test/demangle_test.cpp @@ -0,0 +1,62 @@ +// +// Trivial test for core::demangle +// +// Copyright (c) 2014 Peter Dimov +// Copyright (c) 2014 Andrey Semashev +// +// 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 <boost/core/demangle.hpp> +#include <typeinfo> +#include <iostream> + +template<class T1, class T2> struct Y1 +{ +}; + +void test_demangle() +{ + typedef Y1<int, long> T; + std::cout << boost::core::demangle( typeid( T ).name() ) << std::endl; +} + +void test_demangle_alloc() +{ + typedef Y1<int, long> T; + const char* p = boost::core::demangle_alloc( typeid( T ).name() ); + if (p) + { + std::cout << p << std::endl; + boost::core::demangle_free(p); + } + else + { + std::cout << "[demangling failed]" << std::endl; + } +} + +void test_scoped_demangled_name() +{ + typedef Y1<int, long> T; + boost::core::scoped_demangled_name demangled_name( typeid( T ).name() ); + const char* p = demangled_name.get(); + if (p) + { + std::cout << p << std::endl; + } + else + { + std::cout << "[demangling failed]" << std::endl; + } +} + +int main() +{ + test_demangle(); + test_demangle_alloc(); + test_scoped_demangled_name(); + return 0; +} diff --git a/src/boost/libs/core/test/demangled_name_test.cpp b/src/boost/libs/core/test/demangled_name_test.cpp new file mode 100644 index 00000000..fce32834 --- /dev/null +++ b/src/boost/libs/core/test/demangled_name_test.cpp @@ -0,0 +1,23 @@ +// +// Trivial test for core::demangled_name +// +// Copyright (c) 2014 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 <boost/core/typeinfo.hpp> +#include <iostream> + +template<class T1, class T2> struct Y1 +{ +}; + +int main() +{ + typedef Y1<int, long> T; + std::cout << boost::core::demangled_name( BOOST_CORE_TYPEID( T ) ); + return 0; +} diff --git a/src/boost/libs/core/test/detail_iterator_test.cpp b/src/boost/libs/core/test/detail_iterator_test.cpp new file mode 100644 index 00000000..a6ca7d73 --- /dev/null +++ b/src/boost/libs/core/test/detail_iterator_test.cpp @@ -0,0 +1,148 @@ +// +// Test for boost/detail/iterator.hpp +// +// Copyright 2014 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 <boost/detail/iterator.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> +#include <cstddef> +#include <list> + +/* + +namespace boost { +namespace detail { + +template <class Iterator> struct iterator_traits: std::iterator_traits<Iterator> +{ +}; + +using std::distance; + +} // namespace detail +} // namespace boost + +*/ + +// struct C {} doesn't wotk with libc++. +typedef std::forward_iterator_tag C; + +struct T +{ +}; + +struct D +{ +}; + +struct P +{ +}; + +struct R +{ +}; + +template< class Category, class T, class Distance = std::ptrdiff_t, class Pointer = T*, class Reference = T& > +struct iterator +{ + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; +}; + +int main() +{ + using boost::core::is_same; + +/* + template<class Iterator> struct iterator_traits { + typedef typename Iterator::difference_type difference_type; + typedef typename Iterator::value_type value_type; + typedef typename Iterator::pointer pointer; + typedef typename Iterator::reference reference; + typedef typename Iterator::iterator_category iterator_category; + }; +*/ + { + typedef ::iterator<C,T,D,P,R> It; + + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,C>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,D>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,P>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,R>)); + } +/* + template<class T> struct iterator_traits<T*> { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef T* pointer; + typedef T& reference; + typedef random_access_iterator_tag iterator_category; + }; +*/ + { + typedef T* It; + + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,std::random_access_iterator_tag>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,std::ptrdiff_t>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,T*>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,T&>)); + } + +/* + template<class T> struct iterator_traits<const T*> { + typedef ptrdiff_t difference_type; + typedef T value_type; + typedef const T* pointer; + typedef const T& reference; + typedef random_access_iterator_tag iterator_category; + }; +*/ + { + typedef T const* It; + + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::iterator_category,std::random_access_iterator_tag>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::value_type,T>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::difference_type,std::ptrdiff_t>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::pointer,T const*>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::detail::iterator_traits<It>::reference,T const&>)); + } +/* + template<class InputIterator> + typename iterator_traits<InputIterator>::difference_type + distance( InputIterator first, InputIterator last ); +*/ + { + int const N = 5; + T x[ N ] = {}; + + BOOST_TEST_EQ( boost::detail::distance( x, x + N ), N ); + } + + { + int const N = 5; + T const x[ N ] = {}; + + BOOST_TEST_EQ( boost::detail::distance( x, x + N ), N ); + } + + { + int const N = 5; + std::list<T> x( N ); + + BOOST_TEST_EQ( boost::detail::distance( x.begin(), x.end() ), x.size() ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/eif_constructors.cpp b/src/boost/libs/core/test/eif_constructors.cpp new file mode 100644 index 00000000..ea82b407 --- /dev/null +++ b/src/boost/libs/core/test/eif_constructors.cpp @@ -0,0 +1,61 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + bool my_value; + + template <class T> + container(const T&, const typename enable_if<is_arithmetic<T>, T>::type * = 0): + my_value(true) {} + + template <class T> + container(const T&, const typename disable_if<is_arithmetic<T>, T>::type * = 0): + my_value(false) {} +}; + +// example from Howard Hinnant (tests enable_if template members of a templated class) +template <class charT> +struct xstring +{ + template <class It> + xstring(It begin, It end, typename + disable_if<is_arithmetic<It> >::type* = 0) + : data(end-begin) {} + + int data; +}; + + +int main() +{ + + BOOST_TEST(container(1).my_value); + BOOST_TEST(container(1.0).my_value); + + BOOST_TEST(!container("1").my_value); + BOOST_TEST(!container(static_cast<void*>(0)).my_value); + + char sa[] = "123456"; + BOOST_TEST(xstring<char>(sa, sa+6).data == 6); + + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_dummy_arg_disambiguation.cpp b/src/boost/libs/core/test/eif_dummy_arg_disambiguation.cpp new file mode 100644 index 00000000..e72b1584 --- /dev/null +++ b/src/boost/libs/core/test/eif_dummy_arg_disambiguation.cpp @@ -0,0 +1,45 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template <int N> struct dummy { + dummy(int) {}; +}; + +template<class T> +typename enable_if<is_arithmetic<T>, bool>::type +arithmetic_object(T t, dummy<0> = 0) { return true; } + +template<class T> +typename disable_if<is_arithmetic<T>, bool>::type +arithmetic_object(T t, dummy<1> = 0) { return false; } + + +int main() +{ + + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast<void*>(0))); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_lazy.cpp b/src/boost/libs/core/test/eif_lazy.cpp new file mode 100644 index 00000000..029eca54 --- /dev/null +++ b/src/boost/libs/core/test/eif_lazy.cpp @@ -0,0 +1,81 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if_c; +using boost::lazy_enable_if_c; + +// This class provides a reduced example of a traits class for +// computing the result of multiplying two types. The member typedef +// 'type' in this traits class defines the return type of this +// operator. The return type member is invalid unless both arguments +// for mult_traits are values that mult_traits expects (ints in this +// case). This kind of situation may arise if a traits class only +// makes sense for some set of types, not all C++ types. + +template <class T> struct is_int { + BOOST_STATIC_CONSTANT(bool, value = (boost::is_same<T, int>::value)); +}; + +template <class T, class U> +struct mult_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct mult_traits<int, int> { + typedef int type; +}; + + +// Next, a forwarding function mult() is defined. It is enabled only +// when both arguments are of type int. The first version, using +// non-lazy enable_if_c does not work. + +#if 0 +template <class T, class U> +typename enable_if_c< + is_int<T>::value && is_int<U>::value, + typename mult_traits<T, U>::type +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +// A correct version uses lazy_enable_if_c. +// This template removes compiler errors from invalid code used as an +// argument to enable_if_c. + +#if 1 +template <class T, class U> +typename lazy_enable_if_c< + is_int<T>::value & is_int<U>::value, + mult_traits<T, U> +>::type +mult(const T& x, const U& y) {return x * y;} +#endif + +double mult(int i, double d) { return (double)i * d; } + +int main() +{ + + + BOOST_TEST(mult(1, 2) == 2); + + BOOST_TEST(mult(1, 3.0) == 3.0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_lazy_test.cpp b/src/boost/libs/core/test/eif_lazy_test.cpp new file mode 100644 index 00000000..6077759a --- /dev/null +++ b/src/boost/libs/core/test/eif_lazy_test.cpp @@ -0,0 +1,98 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +// Testing all variations of lazy_enable_if. + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::lazy_enable_if; +using boost::lazy_disable_if; + +using boost::lazy_enable_if_c; +using boost::lazy_disable_if_c; + + +template <class T> +struct is_int_or_double { + BOOST_STATIC_CONSTANT(bool, + value = (boost::is_same<T, int>::value || + boost::is_same<T, double>::value)); +}; + +template <class T> +struct some_traits { + typedef typename T::does_not_exist type; +}; + +template <> +struct some_traits<int> { + typedef bool type; +}; + +template <> +struct some_traits<double> { + typedef bool type; +}; + +template <class T> +struct make_bool { + typedef bool type; +}; + +template <> +struct make_bool<int> {}; + +template <> +struct make_bool<double> {}; + +namespace A { + + template<class T> + typename lazy_enable_if<is_int_or_double<T>, some_traits<T> >::type + foo(T t) { return true; } + + template<class T> + typename lazy_enable_if_c<is_int_or_double<T>::value, some_traits<T> >::type + foo2(T t) { return true; } +} + +namespace B { + template<class T> + typename lazy_disable_if<is_int_or_double<T>, make_bool<T> >::type + foo(T t) { return false; } + + template<class T> + typename lazy_disable_if_c<is_int_or_double<T>::value, make_bool<T> >::type + foo2(T t) { return false; } +} + +int main() +{ + using namespace A; + using namespace B; + BOOST_TEST(foo(1)); + BOOST_TEST(foo(1.0)); + + BOOST_TEST(!foo("1")); + BOOST_TEST(!foo(static_cast<void*>(0))); + + BOOST_TEST(foo2(1)); + BOOST_TEST(foo2(1.0)); + + BOOST_TEST(!foo2("1")); + BOOST_TEST(!foo2(static_cast<void*>(0))); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_member_templates.cpp b/src/boost/libs/core/test/eif_member_templates.cpp new file mode 100644 index 00000000..2f1eeb21 --- /dev/null +++ b/src/boost/libs/core/test/eif_member_templates.cpp @@ -0,0 +1,42 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +struct container { + template <class T> + typename enable_if<is_arithmetic<T>, bool>::type + arithmetic_object(const T&, const int* /* disambiguate */ = 0) {return true;} + + template <class T> + typename disable_if<is_arithmetic<T>, bool>::type + arithmetic_object(const T&) {return false;} +}; + +int main() +{ + + BOOST_TEST(container().arithmetic_object(1)); + BOOST_TEST(container().arithmetic_object(1.0)); + + BOOST_TEST(!container().arithmetic_object("1")); + BOOST_TEST(!container().arithmetic_object(static_cast<void*>(0))); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_namespace_disambiguation.cpp b/src/boost/libs/core/test/eif_namespace_disambiguation.cpp new file mode 100644 index 00000000..d190ee2f --- /dev/null +++ b/src/boost/libs/core/test/eif_namespace_disambiguation.cpp @@ -0,0 +1,50 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/config.hpp> +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if; +using boost::is_arithmetic; + +template<class T> struct not_ +{ + BOOST_STATIC_CONSTANT( bool, value = !T::value ); +}; + +namespace A { + template<class T> + typename enable_if<is_arithmetic<T>, bool>::type + arithmetic_object(T t) { return true; } +} + +namespace B { + template<class T> + typename enable_if<not_<is_arithmetic<T> >, bool>::type + arithmetic_object(T t) { return false; } +} + +int main() +{ + using namespace A; + using namespace B; + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast<void*>(0))); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_no_disambiguation.cpp b/src/boost/libs/core/test/eif_no_disambiguation.cpp new file mode 100644 index 00000000..385451b4 --- /dev/null +++ b/src/boost/libs/core/test/eif_no_disambiguation.cpp @@ -0,0 +1,46 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/config.hpp> +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if; +using boost::is_arithmetic; + +template<class T> struct not_ +{ + BOOST_STATIC_CONSTANT( bool, value = !T::value ); +}; + +template<class T> +typename enable_if<is_arithmetic<T>, bool>::type +arithmetic_object(T t) { return true; } + +template<class T> +typename enable_if<not_<is_arithmetic<T> >, bool>::type +arithmetic_object(T t) { return false; } + + +int main() +{ + + BOOST_TEST(arithmetic_object(1)); + BOOST_TEST(arithmetic_object(1.0)); + + BOOST_TEST(!arithmetic_object("1")); + BOOST_TEST(!arithmetic_object(static_cast<void*>(0))); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/eif_partial_specializations.cpp b/src/boost/libs/core/test/eif_partial_specializations.cpp new file mode 100644 index 00000000..c3234943 --- /dev/null +++ b/src/boost/libs/core/test/eif_partial_specializations.cpp @@ -0,0 +1,89 @@ +// Boost enable_if library + +// Copyright 2003 (c) The Trustees of Indiana University. + +// Use, modification, and distribution is subject to 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) + +// Authors: Jaakko Jarvi (jajarvi at osl.iu.edu) +// Jeremiah Willcock (jewillco at osl.iu.edu) +// Andrew Lumsdaine (lums at osl.iu.edu) + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_arithmetic.hpp> +#include <boost/detail/lightweight_test.hpp> + +using boost::enable_if_has_type; +using boost::enable_if_c; +using boost::disable_if_c; +using boost::enable_if; +using boost::disable_if; +using boost::is_arithmetic; + +template <class T, class Enable = void> +struct tester; + +template <class T> +struct tester<T, typename enable_if_c<is_arithmetic<T>::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template <class T> +struct tester<T, typename disable_if_c<is_arithmetic<T>::value>::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template <class T, class Enable = void> +struct tester2; + +template <class T> +struct tester2<T, typename enable_if<is_arithmetic<T> >::type> { + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +template <class T> +struct tester2<T, typename disable_if<is_arithmetic<T> >::type> { + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template <class T, class Enable = void> +struct tester3 +{ + typedef T type; + BOOST_STATIC_CONSTANT(bool, value = false); +}; + +template <class T> +struct tester3<T, typename enable_if_has_type<typename T::value_type>::type> +{ + typedef typename T::value_type type; + BOOST_STATIC_CONSTANT(bool, value = true); +}; + +struct sample_value_type +{ + typedef float***& value_type; +}; + +int main() +{ + + BOOST_TEST(tester<int>::value); + BOOST_TEST(tester<double>::value); + + BOOST_TEST(!tester<char*>::value); + BOOST_TEST(!tester<void*>::value); + + BOOST_TEST(tester2<int>::value); + BOOST_TEST(tester2<double>::value); + + BOOST_TEST(!tester2<char*>::value); + BOOST_TEST(!tester2<void*>::value); + + BOOST_TEST(!tester3<char*>::value); + BOOST_TEST(tester3<sample_value_type>::value); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/empty_value_final_test.cpp b/src/boost/libs/core/test/empty_value_final_test.cpp new file mode 100644 index 00000000..7ad649a3 --- /dev/null +++ b/src/boost/libs/core/test/empty_value_final_test.cpp @@ -0,0 +1,62 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/empty_value.hpp> +#include <boost/core/lightweight_test.hpp> + +#if !defined(BOOST_NO_CXX11_FINAL) +class type final { +public: + explicit type(int count) + : value_(count) { } + int value() const { + return value_ + 1; + } + int value() { + return value_ + 2; + } +private: + int value_; +}; + +struct empty final { + int value() const { + return 1; + } + int value() { + return 2; + } +}; + +void test_type() +{ + const boost::empty_value<type> v1(boost::empty_init_t(), 3); + BOOST_TEST(v1.get().value() == 4); + boost::empty_value<type> v2(boost::empty_init_t(), 3); + BOOST_TEST(v2.get().value() == 5); +} + +void test_empty() +{ + const boost::empty_value<empty> v1 = boost::empty_init_t(); + BOOST_TEST(v1.get().value() == 1); + boost::empty_value<empty> v2; + BOOST_TEST(v2.get().value() == 2); +} + +int main() +{ + test_type(); + test_empty(); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/core/test/empty_value_size_test.cpp b/src/boost/libs/core/test/empty_value_size_test.cpp new file mode 100644 index 00000000..f0ed675e --- /dev/null +++ b/src/boost/libs/core/test/empty_value_size_test.cpp @@ -0,0 +1,60 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) +#include <boost/core/empty_value.hpp> +#include <boost/core/lightweight_test.hpp> + +struct T1 { }; + +struct S1 + : boost::empty_value<T1, 0, true> { }; + +struct T2 { + int value; +}; + +struct S2 + : boost::empty_value<T1, 0, true> + , boost::empty_value<T2, 1, true> { }; + +struct S3 + : boost::empty_value<T1, 0, false> + , boost::empty_value<T2, 1, true> { }; + +struct T3 { }; + +struct S4 + : boost::empty_value<T1, 0, true> + , boost::empty_value<T3, 1, true> { }; + +struct S5 + : boost::empty_value<T1, 0, false> + , boost::empty_value<T3, 1, false> { }; + +struct S6 + : boost::empty_value<T1, 0, true> + , boost::empty_value<T2, 1, true> + , boost::empty_value<T3, 2, true> { }; + +int main() +{ + BOOST_TEST(sizeof(S1) == sizeof(T1)); + BOOST_TEST(sizeof(S2) == sizeof(T2)); + BOOST_TEST(sizeof(S3) > sizeof(T2)); + BOOST_TEST(sizeof(S4) == sizeof(T1)); + BOOST_TEST(sizeof(S5) > sizeof(T1)); + BOOST_TEST(sizeof(S6) == sizeof(T2)); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/core/test/empty_value_test.cpp b/src/boost/libs/core/test/empty_value_test.cpp new file mode 100644 index 00000000..b7cf7961 --- /dev/null +++ b/src/boost/libs/core/test/empty_value_test.cpp @@ -0,0 +1,72 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/empty_value.hpp> +#include <boost/core/lightweight_test.hpp> + +struct empty { + int value() const { + return 1; + } + int value() { + return 2; + } +}; + +class type { +public: + explicit type(int count) + : value_(count) { } + int value() const { + return value_ + 1; + } + int value() { + return value_ + 2; + } +private: + int value_; +}; + +void test_int() +{ + const boost::empty_value<int> v1(boost::empty_init_t(), 7); + BOOST_TEST(v1.get() == 7); + boost::empty_value<int> v2 = boost::empty_init_t(); + BOOST_TEST(v2.get() == 0); + v2 = v1; + BOOST_TEST(v2.get() == 7); + v2.get() = 8; + BOOST_TEST(v2.get() == 8); +} + +void test_empty() +{ + const boost::empty_value<empty> v1 = boost::empty_init_t(); + BOOST_TEST(v1.get().value() == 1); + boost::empty_value<empty> v2; + BOOST_TEST(v2.get().value() == 2); +} + +void test_type() +{ + const boost::empty_value<type> v1(boost::empty_init_t(), 2); + BOOST_TEST(v1.get().value() == 3); + boost::empty_value<type> v2(boost::empty_init_t(), 3); + BOOST_TEST(v2.get().value() == 5); + v2 = v1; + BOOST_TEST(v2.get().value() == 4); + v2.get() = type(4); + BOOST_TEST(v2.get().value() == 6); +} + +int main() +{ + test_int(); + test_empty(); + test_type(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/exchange_move_test.cpp b/src/boost/libs/core/test/exchange_move_test.cpp new file mode 100644 index 00000000..0ce20af1 --- /dev/null +++ b/src/boost/libs/core/test/exchange_move_test.cpp @@ -0,0 +1,100 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#include <boost/core/exchange.hpp> +#include <boost/core/lightweight_test.hpp> + +class C1 { +public: + explicit C1(int i) + : i_(i) { } + C1(C1&& c) + : i_(c.i_) { } + C1& operator=(C1&& c) { + i_ = c.i_; + return *this; + } + int i() const { + return i_; + } +private: + C1(const C1&); + C1& operator=(const C1&); + int i_; +}; + +void test1() +{ + C1 x(1); + BOOST_TEST(boost::exchange(x, C1(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +class C2 { +public: + explicit C2(int i) + : i_(i) { } + operator C1() const { + return C1(i_); + } + int i() const { + return i_; + } +private: + C2(const C2&); + C2& operator=(const C2&); + int i_; +}; + +void test2() +{ + C1 x(1); + BOOST_TEST(boost::exchange(x, C2(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +class C3 { +public: + explicit C3(int i) + : i_(i) { } + C3(C3&& c) + : i_(c.i_) { } + C3& operator=(C1&& c) { + i_ = c.i(); + return *this; + } + int i() const { + return i_; + } +private: + C3(const C3&); + C3& operator=(const C3&); + int i_; +}; + +void test3() +{ + C3 x(1); + BOOST_TEST(boost::exchange(x, C1(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +int main() +{ + test1(); + test2(); + test3(); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/src/boost/libs/core/test/exchange_test.cpp b/src/boost/libs/core/test/exchange_test.cpp new file mode 100644 index 00000000..524d5b72 --- /dev/null +++ b/src/boost/libs/core/test/exchange_test.cpp @@ -0,0 +1,89 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/exchange.hpp> +#include <boost/core/lightweight_test.hpp> + +void test1() +{ + int i = 1; + BOOST_TEST(boost::exchange(i, 2) == 1); + BOOST_TEST(i == 2); +} + +class C1 { +public: + explicit C1(int i) + : i_(i) { } + int i() const { + return i_; + } +private: + int i_; +}; + +void test2() +{ + C1 x(1); + BOOST_TEST(boost::exchange(x, C1(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +class C2 { +public: + explicit C2(int i) + : i_(i) { } + operator C1() const { + return C1(i_); + } + int i() const { + return i_; + } +private: + int i_; +}; + +void test3() +{ + C1 x(1); + BOOST_TEST(boost::exchange(x, C2(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +class C3 { +public: + explicit C3(int i) + : i_(i) { } + C3(const C3& c) + : i_(c.i_) { } + C3& operator=(const C1& c) { + i_ = c.i(); + return *this; + } + int i() const { + return i_; + } +private: + C3& operator=(const C3&); + int i_; +}; + +void test4() +{ + C3 x(1); + BOOST_TEST(boost::exchange(x, C1(2)).i() == 1); + BOOST_TEST(x.i() == 2); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/explicit_operator_bool.cpp b/src/boost/libs/core/test/explicit_operator_bool.cpp new file mode 100644 index 00000000..5e852599 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool.cpp @@ -0,0 +1,54 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool.cpp + * \author Andrey Semashev + * \date 17.07.2010 + * + * \brief This test checks that explicit operator bool can be used in + * the valid contexts. + */ + +#define BOOST_TEST_MODULE explicit_operator_bool + +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + // A test object that has the operator of explicit conversion to bool + struct checkable1 + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + + struct checkable2 + { + BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() + BOOST_CONSTEXPR bool operator! () const + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable1 val1; + if (val1) + { + checkable2 val2; + if (val2) + return 0; + } + + return 1; +} diff --git a/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_int.cpp b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_int.cpp new file mode 100644 index 00000000..2664d5e6 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_int.cpp @@ -0,0 +1,41 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool_compile_fail_conv_int.cpp + * \author Andrey Semashev + * \date 17.07.2010 + * + * \brief This test checks that explicit operator bool cannot be used in + * an unintended context. + */ + +#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_conv_int + +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + // A test object that has the operator of explicit conversion to bool + struct checkable + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable val; + int n = val; + (void)n; + + return 0; +} diff --git a/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp new file mode 100644 index 00000000..b7e7e031 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_conv_pvoid.cpp @@ -0,0 +1,41 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool_compile_fail_conv_pvoid.cpp + * \author Andrey Semashev + * \date 17.07.2010 + * + * \brief This test checks that explicit operator bool cannot be used in + * an unintended context. + */ + +#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_conv_pvoid + +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + // A test object that has the operator of explicit conversion to bool + struct checkable + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable val; + void* p = val; + (void)p; + + return 0; +} diff --git a/src/boost/libs/core/test/explicit_operator_bool_compile_fail_delete.cpp b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_delete.cpp new file mode 100644 index 00000000..d780f941 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_delete.cpp @@ -0,0 +1,40 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool_compile_fail_delete.cpp + * \author Andrey Semashev + * \date 17.07.2010 + * + * \brief This test checks that explicit operator bool cannot be used in + * an unintended context. + */ + +#define BOOST_TEST_MODULE util_explicit_operator_bool_delete + +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + // A test object that has the operator of explicit conversion to bool + struct checkable + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable val; + delete val; + + return 0; +} diff --git a/src/boost/libs/core/test/explicit_operator_bool_compile_fail_shift.cpp b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_shift.cpp new file mode 100644 index 00000000..ce563a68 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool_compile_fail_shift.cpp @@ -0,0 +1,40 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool_compile_fail_shift.cpp + * \author Andrey Semashev + * \date 17.07.2010 + * + * \brief This test checks that explicit operator bool cannot be used in + * an unintended context. + */ + +#define BOOST_TEST_MODULE explicit_operator_bool_compile_fail_shift + +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + // A test object that has the operator of explicit conversion to bool + struct checkable + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable val; + val << 2; + + return 0; +} diff --git a/src/boost/libs/core/test/explicit_operator_bool_noexcept.cpp b/src/boost/libs/core/test/explicit_operator_bool_noexcept.cpp new file mode 100644 index 00000000..c645cca6 --- /dev/null +++ b/src/boost/libs/core/test/explicit_operator_bool_noexcept.cpp @@ -0,0 +1,89 @@ +/* + * Copyright Andrey Semashev 2007 - 2013. + * 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) + */ +/*! + * \file explicit_operator_bool_noexcept.cpp + * \author Andrey Semashev + * \date 26.04.2014 + * + * \brief This test checks that explicit operator bool is noexcept when possible. + */ + +#define BOOST_TEST_MODULE explicit_operator_bool_noexcept + +#include <boost/config.hpp> + +#if !defined(BOOST_NO_CXX11_NOEXCEPT) + +#include <boost/detail/lightweight_test.hpp> +#include <boost/utility/explicit_operator_bool.hpp> + +namespace { + + struct checkable1 + { + BOOST_EXPLICIT_OPERATOR_BOOL() + bool operator! () const + { + return false; + } + }; + + struct checkable2 + { + BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() + BOOST_CONSTEXPR bool operator! () const + { + return false; + } + }; + + struct noexcept_checkable1 + { + BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() + bool operator! () const noexcept + { + return false; + } + }; + + struct noexcept_checkable2 + { + BOOST_CONSTEXPR_EXPLICIT_OPERATOR_BOOL() + BOOST_CONSTEXPR bool operator! () const noexcept + { + return false; + } + }; + +} // namespace + +int main(int, char*[]) +{ + checkable1 val1; + checkable2 val2; + + noexcept_checkable1 noexcept_val1; + noexcept_checkable2 noexcept_val2; + + BOOST_TEST(!noexcept(static_cast< bool >(val1))); + // constexpr functions are implicitly noexcept + BOOST_TEST(noexcept(static_cast< bool >(val2))); + + BOOST_TEST(noexcept(static_cast< bool >(noexcept_val1))); + BOOST_TEST(noexcept(static_cast< bool >(noexcept_val2))); + + return boost::report_errors(); +} + +#else + +int main(int, char*[]) +{ + return 0; +} + +#endif diff --git a/src/boost/libs/core/test/first_scalar_constexpr_test.cpp b/src/boost/libs/core/test/first_scalar_constexpr_test.cpp new file mode 100644 index 00000000..e9d2500c --- /dev/null +++ b/src/boost/libs/core/test/first_scalar_constexpr_test.cpp @@ -0,0 +1,19 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/config.hpp> +#if !defined(BOOST_NO_CXX14_CONSTEXPR) +#include <boost/core/first_scalar.hpp> +#include <boost/static_assert.hpp> + +static int i1 = 0; +BOOST_STATIC_ASSERT(boost::first_scalar(&i1) == &i1); +static int i2[4] = { }; +BOOST_STATIC_ASSERT(boost::first_scalar(i2) == &i2[0]); +static int i3[2][4][6] = { }; +BOOST_STATIC_ASSERT(boost::first_scalar(i3) == &i3[0][0][0]); +#endif diff --git a/src/boost/libs/core/test/first_scalar_test.cpp b/src/boost/libs/core/test/first_scalar_test.cpp new file mode 100644 index 00000000..3963fc87 --- /dev/null +++ b/src/boost/libs/core/test/first_scalar_test.cpp @@ -0,0 +1,20 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/first_scalar.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() +{ + int i1 = 0; + BOOST_TEST_EQ(boost::first_scalar(&i1), &i1); + int i2[4] = { }; + BOOST_TEST_EQ(boost::first_scalar(i2), &i2[0]); + int i3[2][4][6] = { }; + BOOST_TEST_EQ(boost::first_scalar(i3), &i3[0][0][0]); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/get_pointer_test.cpp b/src/boost/libs/core/test/get_pointer_test.cpp new file mode 100644 index 00000000..1ddf3be8 --- /dev/null +++ b/src/boost/libs/core/test/get_pointer_test.cpp @@ -0,0 +1,74 @@ +// +// get_pointer_test.cpp +// +// Copyright 2014, 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 <boost/get_pointer.hpp> +#include <boost/core/lightweight_test.hpp> +#include <memory> + +struct X +{ +}; + +int main() +{ + using boost::get_pointer; + + { + X * p = new X; + BOOST_TEST( get_pointer( p ) == p ); + + delete p; + } + + { + X * p = 0; + BOOST_TEST( get_pointer( p ) == 0 ); + } + +#if !defined( BOOST_NO_AUTO_PTR ) + + { + std::auto_ptr< X > p( new X ); + BOOST_TEST( get_pointer( p ) == p.get() ); + } + + { + std::auto_ptr< X > p; + BOOST_TEST( get_pointer( p ) == 0 ); + } + +#endif + +#if !defined( BOOST_NO_CXX11_SMART_PTR ) + + { + std::unique_ptr< X > p( new X ); + BOOST_TEST( get_pointer( p ) == p.get() ); + } + + { + std::unique_ptr< X > p; + BOOST_TEST( get_pointer( p ) == 0 ); + } + + { + std::shared_ptr< X > p( new X ); + BOOST_TEST( get_pointer( p ) == p.get() ); + } + + { + std::shared_ptr< X > p; + BOOST_TEST( get_pointer( p ) == 0 ); + } + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/ignore_unused_test.cpp b/src/boost/libs/core/test/ignore_unused_test.cpp new file mode 100644 index 00000000..67bdd800 --- /dev/null +++ b/src/boost/libs/core/test/ignore_unused_test.cpp @@ -0,0 +1,75 @@ +// Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland. +// +// Use, modification and distribution is subject to 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 <boost/core/ignore_unused.hpp> + +BOOST_CXX14_CONSTEXPR int test_fun(int a) +{ + boost::ignore_unused(a); + return 0; +} + +int main() +{ + { + int a; + boost::ignore_unused(a); + } + { + int a, b; + boost::ignore_unused(a, b); + } + { + int a, b, c; + boost::ignore_unused(a, b, c); + } + { + int a, b, c, d; + boost::ignore_unused(a, b, c, d); + } + { + int a, b, c, d, e; + boost::ignore_unused(a, b, c, d, e); + } + + { + typedef int a; + boost::ignore_unused<a>(); + } + { + typedef int a; + typedef int b; + boost::ignore_unused<a, b>(); + } + { + typedef int a; + typedef int b; + typedef int c; + boost::ignore_unused<a, b, c>(); + } + { + typedef int a; + typedef int b; + typedef int c; + typedef int d; + boost::ignore_unused<a, b, c, d>(); + } + { + typedef int a; + typedef int b; + typedef int c; + typedef int d; + typedef int e; + boost::ignore_unused<a, b, c, d, e>(); + } + + { + BOOST_CXX14_CONSTEXPR const int a = test_fun(0); + boost::ignore_unused(a); + } + + return 0; +} diff --git a/src/boost/libs/core/test/is_same_test.cpp b/src/boost/libs/core/test/is_same_test.cpp new file mode 100644 index 00000000..838db225 --- /dev/null +++ b/src/boost/libs/core/test/is_same_test.cpp @@ -0,0 +1,38 @@ +// +// Test for core::is_same<T1,T2> +// +// Copyright 2014 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 <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +struct X +{ +}; + +struct Y +{ +}; + +int main() +{ + BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<X, X> )); + BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<Y, Y> )); + BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<void, void> )); + BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<int, int> )); + BOOST_TEST_TRAIT_TRUE(( boost::core::is_same<void const volatile, void const volatile> )); + + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, Y> )); + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, X const> )); + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, void> )); + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<X, int> )); + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<int, void> )); + BOOST_TEST_TRAIT_FALSE(( boost::core::is_same<void, void const volatile> )); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/iterator_test.cpp b/src/boost/libs/core/test/iterator_test.cpp new file mode 100644 index 00000000..3eb2902d --- /dev/null +++ b/src/boost/libs/core/test/iterator_test.cpp @@ -0,0 +1,69 @@ +// +// Test for boost/iterator.hpp +// +// Copyright 2014 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 <boost/iterator.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +/* + +template< class Category, class T, + class Distance = ptrdiff_t, + class Pointer = T*, + class Reference = T&> +struct iterator +{ + typedef T value_type; + typedef Distance difference_type; + typedef Pointer pointer; + typedef Reference reference; + typedef Category iterator_category; +}; + +*/ + +struct C +{ +}; + +struct T +{ +}; + +struct D +{ +}; + +struct P +{ +}; + +struct R +{ +}; + +int main() +{ + using boost::core::is_same; + + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::iterator_category,C>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::value_type,T>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::difference_type,D>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::pointer,P>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T,D,P,R>::reference,R>)); + + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::iterator_category,C>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::value_type,T>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::difference_type,std::ptrdiff_t>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::pointer,T*>)); + BOOST_TEST_TRAIT_TRUE((is_same<boost::iterator<C,T>::reference,T&>)); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lib_typeid.cpp b/src/boost/libs/core/test/lib_typeid.cpp new file mode 100644 index 00000000..b07a393c --- /dev/null +++ b/src/boost/libs/core/test/lib_typeid.cpp @@ -0,0 +1,17 @@ + +// Copyright 2018 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. + +#include <boost/core/typeinfo.hpp> +#include <boost/config.hpp> + +#if defined(LIB_TYPEID_DYN_LINK) +# define EXPORT BOOST_SYMBOL_EXPORT +#else +# define EXPORT +#endif + +EXPORT boost::core::typeinfo const & get_typeid_int() +{ + return BOOST_CORE_TYPEID( int ); +} diff --git a/src/boost/libs/core/test/lightweight_test_all_eq_test.cpp b/src/boost/libs/core/test/lightweight_test_all_eq_test.cpp new file mode 100644 index 00000000..46254e75 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_all_eq_test.cpp @@ -0,0 +1,124 @@ +// +// 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 <vector> +#include <set> +#include <boost/core/lightweight_test.hpp> + +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<int> x, y; + x.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector<int> x, y; + y.push_back( 1 ); + BOOST_TEST_ALL_EQ( x.begin(), x.end(), y.begin(), y.end() ); + ++test_cases; + } + + { + std::vector<int> 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<float> 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<int> 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<int> 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<int> 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<int> 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<int> 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; + } + + return boost::report_errors() == test_cases; +} diff --git a/src/boost/libs/core/test/lightweight_test_all_with_fail.cpp b/src/boost/libs/core/test/lightweight_test_all_with_fail.cpp new file mode 100644 index 00000000..9a4a4293 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_all_with_fail.cpp @@ -0,0 +1,105 @@ +// +// Negative est for BOOST_TEST_ALL_WITH +// +// 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 <cmath> +#include <functional> +#include <vector> +#include <boost/core/lightweight_test.hpp> + +int fail_vector() +{ + int test_cases = 0; + + { + std::vector<int> x, y; + x.push_back( 1 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + ++test_cases; + } + + { + std::vector<int> x, y; + y.push_back( 1 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + ++test_cases; + } + + { + std::vector<int> 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( 2 ); y.push_back( 3 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + ++test_cases; + } + + { + std::vector<int> x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); + y.push_back( 1 ); y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + ++test_cases; + } + + { + std::vector<int> 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_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + ++test_cases; + } + + { + std::vector<int> 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_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() ); + ++test_cases; + } + + return test_cases; +} + +template <typename T> +struct with_tolerance +{ + with_tolerance(T tolerance) : tolerance(tolerance) {} + bool operator()(T lhs, T rhs) + { + return (std::abs(lhs - rhs) <= tolerance); + } + +private: + T tolerance; +}; + +int fail_tolerance_predicate() +{ + int test_cases = 0; + + { + std::vector<double> x, y; + x.push_back( 1.0 ); x.push_back( 1.0 ); + y.push_back( 1.0 - 1e-4 ); y.push_back( 1.0 + 1e-4 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) ); + ++test_cases; + } + + return test_cases; +} + +int main() +{ + int test_cases = 0; + + test_cases += fail_vector(); + test_cases += fail_tolerance_predicate(); + + return boost::report_errors() == test_cases; +} diff --git a/src/boost/libs/core/test/lightweight_test_all_with_test.cpp b/src/boost/libs/core/test/lightweight_test_all_with_test.cpp new file mode 100644 index 00000000..bc078a41 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_all_with_test.cpp @@ -0,0 +1,76 @@ +// +// Test for BOOST_TEST_ALL_WITH +// +// 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 <cmath> +#include <functional> +#include <vector> +#include <boost/core/lightweight_test.hpp> + +void test_vector() +{ + { + std::vector<int> 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( 2 ); y.push_back( 3 ); y.push_back( 4 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::equal_to<int>() ); + } + + { + std::vector<int> x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 ); y.push_back( 5 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::not_equal_to<int>() ); + } + + { + std::vector<int> x, y; + x.push_back( 1 ); x.push_back( 2 ); x.push_back( 3 ); x.push_back( 4 ); + y.push_back( 2 ); y.push_back( 3 ); y.push_back( 4 ); y.push_back( 5 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), std::less<int>() ); + } +} + +template <typename T> +struct with_tolerance +{ + with_tolerance(T tolerance) : tolerance(tolerance) {} + bool operator()(T lhs, T rhs) + { + return (std::abs(lhs - rhs) <= tolerance); + } + +private: + T tolerance; +}; + +void test_tolerance_predicate() +{ + { + std::vector<double> x, y; + x.push_back( 1.0 ); x.push_back( 2.0 ); x.push_back( 3.0 ); x.push_back( 4.0 ); + y.push_back( 1.0 ); y.push_back( 2.0 ); y.push_back( 3.0 ); y.push_back( 4.0 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) ); + } + + { + std::vector<double> x, y; + x.push_back( 1.0 ); x.push_back( 1.0 ); + y.push_back( 1.0 - 1e-6 ); y.push_back( 1.0 + 1e-6 ); + BOOST_TEST_ALL_WITH( x.begin(), x.end(), y.begin(), y.end(), with_tolerance<double>(1e-5) ); + } +} + +int main() +{ + test_vector(); + test_tolerance_predicate(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_eq_nullptr.cpp b/src/boost/libs/core/test/lightweight_test_eq_nullptr.cpp new file mode 100644 index 00000000..fb24a5e7 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_eq_nullptr.cpp @@ -0,0 +1,31 @@ +// +// Test BOOST_TEST_EQ( p, nullptr ) +// +// Copyright 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 <boost/config.hpp> +#include <boost/core/lightweight_test.hpp> + +int main() +{ +#if !defined( BOOST_NO_CXX11_NULLPTR ) + + int x = 0; + int* p1 = 0; + int* p2 = &x; + + BOOST_TEST_EQ( p1, nullptr ); + BOOST_TEST_NE( p2, nullptr ); + + BOOST_TEST_EQ( nullptr, p1 ); + BOOST_TEST_NE( nullptr, p2 ); + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail.cpp b/src/boost/libs/core/test/lightweight_test_fail.cpp new file mode 100644 index 00000000..ec329b32 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST( x == 1 ); // will fail + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail10.cpp b/src/boost/libs/core/test/lightweight_test_fail10.cpp new file mode 100644 index 00000000..388c47e7 --- /dev/null +++ b/src/boost/libs/core/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 <boost/core/lightweight_test.hpp> + +int main() +{ + BOOST_TEST_EQ("xab"+1 , "yab"+1); // compares addresses, not cstrings + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail11.cpp b/src/boost/libs/core/test/lightweight_test_fail11.cpp new file mode 100644 index 00000000..591813a3 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail11.cpp @@ -0,0 +1,14 @@ +/* +Copyright 2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/lightweight_test.hpp> + +int main() +{ + BOOST_TEST(true); + return 0; +} diff --git a/src/boost/libs/core/test/lightweight_test_fail12.cpp b/src/boost/libs/core/test/lightweight_test_fail12.cpp new file mode 100644 index 00000000..fb3e0ac7 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail12.cpp @@ -0,0 +1,68 @@ +// +// Negative test for BOOST_TEST_TRAIT_SAME +// +// Copyright 2014, 2019 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 <boost/core/lightweight_test_trait.hpp> +#include <boost/config.hpp> + +struct X +{ + typedef int type; +}; + +template<class T1, class T2> struct Y +{ + typedef T1 type; +}; + +typedef int I1; +typedef const int I2; +typedef volatile int I3; +typedef const volatile int I4; +typedef int& I5; +typedef const int& I6; +typedef volatile int& I7; +typedef const volatile int& I8; +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +typedef int&& I9; +typedef const int&& I10; +typedef volatile int&& I11; +typedef const volatile int&& I12; +#endif + +int main() +{ + BOOST_TEST_TRAIT_SAME(char[1], char[2]); + BOOST_TEST_TRAIT_SAME(char[1], char[]); + BOOST_TEST_TRAIT_SAME(char[1], char*); + BOOST_TEST_TRAIT_SAME(void(), void(int)); + BOOST_TEST_TRAIT_SAME(void(), void(*)()); + BOOST_TEST_TRAIT_SAME(X, void); + BOOST_TEST_TRAIT_SAME(X::type, void); + BOOST_TEST_TRAIT_SAME(X, Y<void, void>); + BOOST_TEST_TRAIT_SAME(X::type, Y<float, int>::type); + BOOST_TEST_TRAIT_SAME(Y<int, float>, Y<int, double>); + BOOST_TEST_TRAIT_SAME(I1, I2); + BOOST_TEST_TRAIT_SAME(I3, I4); + BOOST_TEST_TRAIT_SAME(I5, I6); + BOOST_TEST_TRAIT_SAME(I7, I8); + + int expected = 14; + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + + BOOST_TEST_TRAIT_SAME(I9, I10); + BOOST_TEST_TRAIT_SAME(I11, I12); + + expected += 2; + +#endif + + return boost::report_errors() == expected; +} diff --git a/src/boost/libs/core/test/lightweight_test_fail2.cpp b/src/boost/libs/core/test/lightweight_test_fail2.cpp new file mode 100644 index 00000000..dcab7244 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail2.cpp @@ -0,0 +1,18 @@ +// +// Test for BOOST_ERROR +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +int main() +{ + BOOST_ERROR( "expected failure" ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail3.cpp b/src/boost/libs/core/test/lightweight_test_fail3.cpp new file mode 100644 index 00000000..1e208420 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail3.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_EQ +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_EQ( x, 1 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail4.cpp b/src/boost/libs/core/test/lightweight_test_fail4.cpp new file mode 100644 index 00000000..492699ab --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail4.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_NE +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_NE( x, 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail5.cpp b/src/boost/libs/core/test/lightweight_test_fail5.cpp new file mode 100644 index 00000000..5cc46598 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail5.cpp @@ -0,0 +1,26 @@ +// +// Negative test for BOOST_TEST_THROWS +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +struct X +{ +}; + +void f() +{ +} + +int main() +{ + BOOST_TEST_THROWS( f(), X ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail6.cpp b/src/boost/libs/core/test/lightweight_test_fail6.cpp new file mode 100644 index 00000000..10544ab8 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail6.cpp @@ -0,0 +1,27 @@ +// +// Negative test for BOOST_TEST_THROWS +// +// Copyright (c) 2014 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 <boost/detail/lightweight_test.hpp> + +struct X +{ +}; + +void f() +{ + throw 5; +} + +int main() +{ + BOOST_TEST_THROWS( f(), X ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail7.cpp b/src/boost/libs/core/test/lightweight_test_fail7.cpp new file mode 100644 index 00000000..ed393e69 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail7.cpp @@ -0,0 +1,38 @@ +// +// Negative test for BOOST_TEST_TRAIT_TRUE +// +// Copyright (c) 2014 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 <boost/core/lightweight_test_trait.hpp> + +template<class T1, class T2> struct Y1 +{ + enum { value = 1 }; +}; + +template<class T1, class T2> struct Y2 +{ + enum { value = 0 }; +}; + +struct X1 +{ + typedef int type; +}; + +struct X2 +{ + typedef int type; +}; + +int main() +{ + BOOST_TEST_TRAIT_TRUE(( Y2<X1::type, X2::type> )); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail8.cpp b/src/boost/libs/core/test/lightweight_test_fail8.cpp new file mode 100644 index 00000000..7b6d4869 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_fail8.cpp @@ -0,0 +1,38 @@ +// +// Negative test for BOOST_TEST_TRAIT_FALSE +// +// Copyright (c) 2014 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 <boost/core/lightweight_test_trait.hpp> + +template<class T1, class T2> struct Y1 +{ + enum { value = 1 }; +}; + +template<class T1, class T2> struct Y2 +{ + enum { value = 0 }; +}; + +struct X1 +{ + typedef int type; +}; + +struct X2 +{ + typedef int type; +}; + +int main() +{ + BOOST_TEST_TRAIT_FALSE(( Y1<X1::type, X2::type> )); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_fail9.cpp b/src/boost/libs/core/test/lightweight_test_fail9.cpp new file mode 100644 index 00000000..a87a4f14 --- /dev/null +++ b/src/boost/libs/core/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 <boost/core/lightweight_test.hpp> + +int main() +{ + BOOST_TEST_CSTR_EQ("x" , "y"); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_ge_fail.cpp b/src/boost/libs/core/test/lightweight_test_ge_fail.cpp new file mode 100644 index 00000000..66712157 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_ge_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_GE +// +// Copyright 2017 Kohei Takahashi +// +// 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_GE( x, 1 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_gt_fail.cpp b/src/boost/libs/core/test/lightweight_test_gt_fail.cpp new file mode 100644 index 00000000..3a0bd3c6 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_gt_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_GT +// +// Copyright 2017 Kohei Takahashi +// +// 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_GT( x, 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_gt_ge_test.cpp b/src/boost/libs/core/test/lightweight_test_gt_ge_test.cpp new file mode 100644 index 00000000..d935a0ab --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_gt_ge_test.cpp @@ -0,0 +1,34 @@ +// +// Test for BOOST_TEST_GT, BOOST_TEST_GE +// +// Copyright 2017 Kohei Takahashi +// +// 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_GT( x, -1 ); + BOOST_TEST_GT( ++x, 0 ); + BOOST_TEST_GT( x++, 0 ); + + BOOST_TEST_GE( x, 2 ); + BOOST_TEST_GE( ++x, 3 ); + BOOST_TEST_GE( x++, 3 ); + + int y = 5; + + BOOST_TEST_GT( ++y, ++x ); + BOOST_TEST_GT( y++, x++ ); + + BOOST_TEST_GE( ++y, x ); + BOOST_TEST_GE( y++, x++ ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_le_fail.cpp b/src/boost/libs/core/test/lightweight_test_le_fail.cpp new file mode 100644 index 00000000..9706be42 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_le_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_LE +// +// Copyright 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 1; + + BOOST_TEST_LE( x, 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_lt_fail.cpp b/src/boost/libs/core/test/lightweight_test_lt_fail.cpp new file mode 100644 index 00000000..ba6d2432 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_lt_fail.cpp @@ -0,0 +1,20 @@ +// +// Negative test for BOOST_TEST_LT +// +// Copyright 2014, 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_LT( x, 0 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_lt_le_test.cpp b/src/boost/libs/core/test/lightweight_test_lt_le_test.cpp new file mode 100644 index 00000000..7f087832 --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_lt_le_test.cpp @@ -0,0 +1,34 @@ +// +// Test for BOOST_TEST_LT, BOOST_TEST_LE +// +// Copyright 2014, 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 <boost/core/lightweight_test.hpp> + +int main() +{ + int x = 0; + + BOOST_TEST_LT( x, 1 ); + BOOST_TEST_LT( ++x, 2 ); + BOOST_TEST_LT( x++, 3 ); + + BOOST_TEST_LE( x, 2 ); + BOOST_TEST_LE( ++x, 3 ); + BOOST_TEST_LE( x++, 4 ); + + int y = 3; + + BOOST_TEST_LT( ++y, ++x ); + BOOST_TEST_LT( y++, x++ ); + + BOOST_TEST_LE( ++y, x ); + BOOST_TEST_LE( y++, x++ ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_test.cpp b/src/boost/libs/core/test/lightweight_test_test.cpp new file mode 100644 index 00000000..bfef152b --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_test.cpp @@ -0,0 +1,96 @@ +// +// Test for lightweight_test.hpp +// +// Copyright (c) 2014 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 <vector> +#include <boost/detail/lightweight_test.hpp> + +struct X +{ +}; + +#if !defined( BOOST_NO_EXCEPTIONS ) +# define LWT_THROW( x ) throw x +#else +# define LWT_THROW( x ) ((void)(x)) +#endif + +void f( bool x ) +{ + if( x ) + { + LWT_THROW( X() ); + } + else + { + LWT_THROW( 5 ); + } +} + +int main() +{ + int x = 0; + + // BOOST_TEST + + BOOST_TEST( x == 0 ); + BOOST_TEST( ++x == 1 ); + BOOST_TEST( x++ == 1 ); + BOOST_TEST( x == 2? true: false ); + BOOST_TEST( x == 2? &x: 0 ); + + // BOOST_TEST_NOT + + BOOST_TEST_NOT( x == 1 ); + BOOST_TEST_NOT( ++x == 2 ); + BOOST_TEST_NOT( x++ == 2 ); + BOOST_TEST_NOT( --x == 2 ); + BOOST_TEST_NOT( x-- == 2 ); + BOOST_TEST_NOT( x == 2? false: true ); + BOOST_TEST_NOT( x == 2? 0: &x ); + + // BOOST_TEST_EQ + + BOOST_TEST_EQ( x, 2 ); + BOOST_TEST_EQ( ++x, 3 ); + BOOST_TEST_EQ( x++, 3 ); + + int y = 4; + + 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<int> xarray; + xarray.push_back(1); + xarray.push_back(2); + std::vector<int> yarray(xarray); + BOOST_TEST_ALL_EQ(xarray.begin(), xarray.end(), yarray.begin(), yarray.end()); + } + + // BOOST_TEST_THROWS + + BOOST_TEST_THROWS( throw X(), X ); + BOOST_TEST_THROWS( throw 1, int ); + + BOOST_TEST_THROWS( f(true), X ); + BOOST_TEST_THROWS( f(false), int ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_test2.cpp b/src/boost/libs/core/test/lightweight_test_test2.cpp new file mode 100644 index 00000000..c60feccf --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_test2.cpp @@ -0,0 +1,44 @@ +// +// Test for lightweight_test_trait.hpp +// +// Copyright (c) 2014 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 <boost/core/lightweight_test_trait.hpp> + +template<class T1, class T2> struct Y1 +{ + enum { value = 1 }; +}; + +template<class T1, class T2> struct Y2 +{ + enum { value = 0 }; +}; + +struct X1 +{ + typedef int type; +}; + +struct X2 +{ + typedef int type; +}; + +int main() +{ + // BOOST_TEST_TRAIT_TRUE + + BOOST_TEST_TRAIT_TRUE(( Y1<X1::type, X2::type> )); + + // BOOST_TEST_TRAIT_FALSE + + BOOST_TEST_TRAIT_FALSE(( Y2<X1::type, X2::type> )); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_test3.cpp b/src/boost/libs/core/test/lightweight_test_test3.cpp new file mode 100644 index 00000000..cda641aa --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_test3.cpp @@ -0,0 +1,147 @@ +// +// Test for lightweight_test.hpp +// +// Copyright (c) 2014, 2018 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 <boost/core/lightweight_test.hpp> +#include <boost/core/noncopyable.hpp> +#include <ostream> + +// EQ + +struct eq1: private boost::noncopyable {}; +struct eq2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, eq1 const& ) +{ + return os << "eq1()"; +} + +std::ostream& operator<<( std::ostream& os, eq2 const& ) +{ + return os << "eq2()"; +} + +bool operator==( eq1 const&, eq2 const& ) +{ + return true; +} + +// NE + +struct ne1: private boost::noncopyable {}; +struct ne2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, ne1 const& ) +{ + return os << "ne1()"; +} + +std::ostream& operator<<( std::ostream& os, ne2 const& ) +{ + return os << "ne2()"; +} + +bool operator!=( ne1 const&, ne2 const& ) +{ + return true; +} + +// LT + +struct lt1: private boost::noncopyable {}; +struct lt2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, lt1 const& ) +{ + return os << "lt1()"; +} + +std::ostream& operator<<( std::ostream& os, lt2 const& ) +{ + return os << "lt2()"; +} + +bool operator<( lt1 const&, lt2 const& ) +{ + return true; +} + +// LE + +struct le1: private boost::noncopyable {}; +struct le2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, le1 const& ) +{ + return os << "le1()"; +} + +std::ostream& operator<<( std::ostream& os, le2 const& ) +{ + return os << "le2()"; +} + +bool operator<=( le1 const&, le2 const& ) +{ + return true; +} + +// GT + +struct gt1: private boost::noncopyable {}; +struct gt2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, gt1 const& ) +{ + return os << "gt1()"; +} + +std::ostream& operator<<( std::ostream& os, gt2 const& ) +{ + return os << "gt2()"; +} + +bool operator>( gt1 const&, gt2 const& ) +{ + return true; +} + +// GE + +struct ge1: private boost::noncopyable {}; +struct ge2: private boost::noncopyable {}; + +std::ostream& operator<<( std::ostream& os, ge1 const& ) +{ + return os << "ge1()"; +} + +std::ostream& operator<<( std::ostream& os, ge2 const& ) +{ + return os << "ge2()"; +} + +bool operator>=( ge1 const&, ge2 const& ) +{ + return true; +} + +// + +int main() +{ + BOOST_TEST_EQ( eq1(), eq2() ); + BOOST_TEST_NE( ne1(), ne2() ); + BOOST_TEST_LT( lt1(), lt2() ); + BOOST_TEST_LE( le1(), le2() ); + BOOST_TEST_GT( gt1(), gt2() ); + BOOST_TEST_GE( ge1(), ge2() ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_test4.cpp b/src/boost/libs/core/test/lightweight_test_test4.cpp new file mode 100644 index 00000000..a3e8b04e --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_test4.cpp @@ -0,0 +1,36 @@ +// +// Test for BOOST_TEST_TRAIT_SAME +// +// Copyright 2014, 2019 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 <boost/core/lightweight_test_trait.hpp> + +struct X +{ + typedef int type; +}; + +template<class T1, class T2> struct Y +{ + typedef T1 type; +}; + +int main() +{ + BOOST_TEST_TRAIT_SAME(X, X); + BOOST_TEST_TRAIT_SAME(void, void); + BOOST_TEST_TRAIT_SAME(char[1], char[1]); + BOOST_TEST_TRAIT_SAME(char[], char[]); + BOOST_TEST_TRAIT_SAME(void(), void()); + BOOST_TEST_TRAIT_SAME(X::type, X::type); + BOOST_TEST_TRAIT_SAME(X::type, Y<int, float>::type); + BOOST_TEST_TRAIT_SAME(Y<int, float>, Y<int, float>); + BOOST_TEST_TRAIT_SAME(Y<void, float>::type, void); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/lightweight_test_test5.cpp b/src/boost/libs/core/test/lightweight_test_test5.cpp new file mode 100644 index 00000000..78870d1c --- /dev/null +++ b/src/boost/libs/core/test/lightweight_test_test5.cpp @@ -0,0 +1,19 @@ +// +// Test that BOOST_TEST_EQ doesn't emit sign compare warnings +// +// Copyright 2019 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 <boost/core/lightweight_test.hpp> + +int main() +{ + BOOST_TEST_EQ(1, 1u); + BOOST_TEST_EQ(~0u, -1); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/no_exceptions_support_test.cpp b/src/boost/libs/core/test/no_exceptions_support_test.cpp new file mode 100644 index 00000000..64533faf --- /dev/null +++ b/src/boost/libs/core/test/no_exceptions_support_test.cpp @@ -0,0 +1,52 @@ +// +// Test for no_exceptions_support.hpp +// +// Copyright 2019 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 <boost/core/no_exceptions_support.hpp> +#include <boost/core/quick_exit.hpp> +#include <boost/throw_exception.hpp> +#include <exception> + +void f() +{ + boost::throw_exception( std::exception() ); +} + +int main() +{ + BOOST_TRY + { + f(); + } + BOOST_CATCH( std::exception const& ) + { + return 0; + } + BOOST_CATCH( ... ) + { + return 1; + } + BOOST_CATCH_END + + return 1; +} + +#if defined(BOOST_NO_EXCEPTIONS) + +namespace boost +{ + +void throw_exception( std::exception const& ) +{ + boost::quick_exit( 0 ); +} + +} + +#endif diff --git a/src/boost/libs/core/test/noinit_adaptor_test.cpp b/src/boost/libs/core/test/noinit_adaptor_test.cpp new file mode 100644 index 00000000..605941f0 --- /dev/null +++ b/src/boost/libs/core/test/noinit_adaptor_test.cpp @@ -0,0 +1,100 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/noinit_adaptor.hpp> +#include <boost/core/default_allocator.hpp> +#include <boost/core/lightweight_test.hpp> +#include <vector> + +template<class T> +class creator + : public boost::default_allocator<T> { +public: + template<class U> + struct rebind { + typedef creator<U> other; + }; + + creator(int state) + : state_(state) { } + + template<class U> + creator(const creator<U>& other) + : state_(other.state()) { } + + template<class U, class V> + void construct(U*, const V&) { + BOOST_ERROR("construct"); + } + + template<class U> + void destroy(U*) { + BOOST_ERROR("destroy"); + } + + int state() const { + return state_; + } + +private: + int state_; +}; + +template<class T, class U> +inline bool +operator==(const creator<T>& lhs, const creator<U>& rhs) +{ + return lhs.state() == rhs.state(); +} + +template<class T, class U> +inline bool +operator!=(const creator<T>& lhs, const creator<U>& rhs) +{ + return !(lhs == rhs); +} + +class type { +public: + type() { } + + type(int value) + : value_(value) { } + + int value() const { + return value_; + } + +private: + int value_; +}; + +inline bool +operator==(const type& lhs, const type& rhs) +{ + return lhs.value() == rhs.value(); +} + +template<class A> +void test(const A& allocator) +{ + std::vector<typename A::value_type, A> v(allocator); + v.push_back(1); + BOOST_TEST(v.front() == 1); + v.clear(); + v.resize(5); + v.front() = 1; +} + +int main() +{ + test(boost::noinit_adaptor<creator<int> >(1)); + test(boost::noinit_adaptor<creator<type> >(2)); + test(boost::noinit_adapt(creator<int>(3))); + test(boost::noinit_adapt(creator<type>(4))); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/noncopyable_compile_fail.cpp b/src/boost/libs/core/test/noncopyable_compile_fail.cpp new file mode 100644 index 00000000..f1f02938 --- /dev/null +++ b/src/boost/libs/core/test/noncopyable_compile_fail.cpp @@ -0,0 +1,36 @@ +// boost class noncopyable test program ------------------------------------// + +// (C) Copyright Beman Dawes 1999. 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) + +// See http://www.boost.org for most recent version including documentation. + +// Revision History +// 9 Jun 99 Add unnamed namespace +// 2 Jun 99 Initial Version + +#include <boost/noncopyable.hpp> +#include <iostream> + +// This program demonstrates compiler errors resulting from trying to copy +// construct or copy assign a class object derived from class noncopyable. + +namespace +{ + class DontTreadOnMe : private boost::noncopyable + { + public: + DontTreadOnMe() { std::cout << "defanged!" << std::endl; } + }; // DontTreadOnMe + +} // unnamed namespace + +int main() +{ + DontTreadOnMe object1; + DontTreadOnMe object2(object1); + object1 = object2; + return 0; +} // main + diff --git a/src/boost/libs/core/test/nvp_test.cpp b/src/boost/libs/core/test/nvp_test.cpp new file mode 100644 index 00000000..c292659d --- /dev/null +++ b/src/boost/libs/core/test/nvp_test.cpp @@ -0,0 +1,46 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/nvp.hpp> +#include <boost/core/lightweight_test.hpp> + +void test() +{ + const char* n = "name"; + int v = 1; + boost::nvp<int> p(n, v); + BOOST_TEST_EQ(p.name(), n); + BOOST_TEST_EQ(p.value(), 1); + BOOST_TEST_EQ(&p.value(), &v); +} + +void test_factory() +{ + const char* n = "name"; + int v = 1; + boost::nvp<int> p = boost::make_nvp(n, v); + BOOST_TEST_EQ(p.name(), n); + BOOST_TEST_EQ(p.value(), 1); + BOOST_TEST_EQ(&p.value(), &v); +} + +void test_macro() +{ + int v = 1; + boost::nvp<int> p = BOOST_NVP(v); + BOOST_TEST_CSTR_EQ(p.name(), "v"); + BOOST_TEST_EQ(p.value(), 1); + BOOST_TEST_EQ(&p.value(), &v); +} + +int main() +{ + test(); + test_factory(); + test_macro(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/pointer_traits_difference_type_test.cpp b/src/boost/libs/core/test/pointer_traits_difference_type_test.cpp new file mode 100644 index 00000000..e9d0b094 --- /dev/null +++ b/src/boost/libs/core/test/pointer_traits_difference_type_test.cpp @@ -0,0 +1,41 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +template<class T> +struct P { }; + +template<class T> +struct E { + typedef long difference_type; +}; + +int main() +{ + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<int*>::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<P<int> >::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<long, + boost::pointer_traits<E<int> >::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<void*>::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<P<void> >::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<long, + boost::pointer_traits<E<void> >::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<const int*>::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<std::ptrdiff_t, + boost::pointer_traits<P<const int> >::difference_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<long, + boost::pointer_traits<E<const int> >::difference_type>)); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/pointer_traits_element_type_test.cpp b/src/boost/libs/core/test/pointer_traits_element_type_test.cpp new file mode 100644 index 00000000..a20733e5 --- /dev/null +++ b/src/boost/libs/core/test/pointer_traits_element_type_test.cpp @@ -0,0 +1,83 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +template<class T> +struct P1 { }; + +template<class T1, class T2> +struct P2 { }; + +template<class T1, class T2, class T3> +struct P3 { }; + +template<class T> +struct E1 { + typedef bool element_type; +}; + +template<class T1, class T2> +struct E2 { + typedef bool element_type; +}; + +template<class T1, class T2, class T3> +struct E3 { + typedef bool element_type; +}; + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +template<class T, class... U> +struct P { }; + +template<class T, class... U> +struct E { + typedef bool element_type; +}; +#endif + +int main() +{ + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int, + boost::pointer_traits<int*>::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int, + boost::pointer_traits<P1<int> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int, + boost::pointer_traits<P2<int, char> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int, + boost::pointer_traits<P3<int, char, char> >::element_type>)); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int, + boost::pointer_traits<P<int, char, char, char> >::element_type>)); +#endif + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E1<int> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E2<int, int> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E3<int, int, int> >::element_type>)); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E<int, int, int, int> >::element_type>)); +#endif + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void, + boost::pointer_traits<void*>::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void, + boost::pointer_traits<P1<void> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E1<void> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int, + boost::pointer_traits<const int*>::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int, + boost::pointer_traits<P1<const int> >::element_type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<bool, + boost::pointer_traits<E1<const int> >::element_type>)); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/pointer_traits_pointer_test.cpp b/src/boost/libs/core/test/pointer_traits_pointer_test.cpp new file mode 100644 index 00000000..a98eb4d5 --- /dev/null +++ b/src/boost/libs/core/test/pointer_traits_pointer_test.cpp @@ -0,0 +1,30 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +template<class T> +struct P { }; + +int main() +{ + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int*, + boost::pointer_traits<int*>::pointer>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P<int>, + boost::pointer_traits<P<int> >::pointer>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void*, + boost::pointer_traits<void*>::pointer>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P<void>, + boost::pointer_traits<P<void> >::pointer>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int*, + boost::pointer_traits<const int*>::pointer>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P<const int>, + boost::pointer_traits<P<const int> >::pointer>)); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/pointer_traits_pointer_to_test.cpp b/src/boost/libs/core/test/pointer_traits_pointer_to_test.cpp new file mode 100644 index 00000000..33e21add --- /dev/null +++ b/src/boost/libs/core/test/pointer_traits_pointer_to_test.cpp @@ -0,0 +1,63 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T> +class pointer { +public: + typedef typename boost::pointer_traits<T>::element_type element_type; + pointer(T value) + : value_(value) { } + T get() const BOOST_NOEXCEPT { + return value_; + } + static pointer<T> pointer_to(element_type& value) { + return pointer<T>(&value); + } +private: + T value_; +}; + +template<class T> +inline bool +operator==(const pointer<T>& lhs, const pointer<T>& rhs) BOOST_NOEXCEPT +{ + return lhs.get() == rhs.get(); +} + +int main() +{ + int i = 0; + { + typedef int* type; + type p = &i; + BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p); + } + { + typedef pointer<int*> type; + type p(&i); + BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p); + } + { + typedef pointer<pointer<int*> > type; + type p(&i); + BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p); + } + { + typedef const int* type; + type p = &i; + BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p); + } + { + typedef pointer<const int*> type; + type p(&i); + BOOST_TEST(boost::pointer_traits<type>::pointer_to(i) == p); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/pointer_traits_rebind_test.cpp b/src/boost/libs/core/test/pointer_traits_rebind_test.cpp new file mode 100644 index 00000000..999d1954 --- /dev/null +++ b/src/boost/libs/core/test/pointer_traits_rebind_test.cpp @@ -0,0 +1,107 @@ +/* +Copyright 2017 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test_trait.hpp> + +template<class T> +struct P1 { }; + +template<class T1, class T2> +struct P2 { }; + +template<class T1, class T2, class T3> +struct P3 { }; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template<class T> +struct E1 { + template<class U> + using rebind = E1<bool>; +}; + +template<class T1, class T2> +struct E2 { + template<class U> + using rebind = E2<bool, T2>; +}; + +template<class T1, class T2, class T3> +struct E3 { + template<class U> + using rebind = E3<bool, T2, T3>; +}; +#endif + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +template<class T, class... U> +struct P { }; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template<class T, class... U> +struct E { + template<class V> + using rebind = E<bool, U...>; +}; +#endif +#endif + +struct R { }; + +int main() +{ + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<char*, + boost::pointer_traits<R*>::rebind_to<char>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<char>, + boost::pointer_traits<P1<R> >::rebind_to<char>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P2<char, R>, + boost::pointer_traits<P2<R, R> >::rebind_to<char>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P3<char, R, R>, + boost::pointer_traits<P3<R, R, R> >::rebind_to<char>::type>)); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P<char, R, R, R>, + boost::pointer_traits<P<R, R, R, R> >::rebind_to<char>::type>)); +#endif + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<void*, + boost::pointer_traits<R*>::rebind_to<void>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<void>, + boost::pointer_traits<P1<R> >::rebind_to<void>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<R*, + boost::pointer_traits<void*>::rebind_to<R>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<R>, + boost::pointer_traits<P1<void> >::rebind_to<R>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<const int*, + boost::pointer_traits<R*>::rebind_to<const int>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<const int>, + boost::pointer_traits<P1<R> >::rebind_to<const int>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<int*, + boost::pointer_traits<const R*>::rebind_to<int>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<P1<int>, + boost::pointer_traits<P1<const R> >::rebind_to<int>::type>)); +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>, + boost::pointer_traits<E1<R> >::rebind_to<char>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E2<bool, R>, + boost::pointer_traits<E2<R, R> >::rebind_to<char>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E3<bool, R, R>, + boost::pointer_traits<E3<R, R, R> >::rebind_to<char>::type>)); +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E<bool, R, R, R>, + boost::pointer_traits<E<R, R, R, R> >::rebind_to<char>::type>)); +#endif + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>, + boost::pointer_traits<E1<R> >::rebind_to<void>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>, + boost::pointer_traits<E1<void> >::rebind_to<R>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>, + boost::pointer_traits<E1<R> >::rebind_to<const int>::type>)); + BOOST_TEST_TRAIT_TRUE((boost::core::is_same<E1<bool>, + boost::pointer_traits<E1<const R> >::rebind_to<int>::type>)); +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/quick.cpp b/src/boost/libs/core/test/quick.cpp new file mode 100644 index 00000000..7f266c3a --- /dev/null +++ b/src/boost/libs/core/test/quick.cpp @@ -0,0 +1,33 @@ +// +// quick.cpp - a quick (CI) test for Boost.Core +// +// Copyright 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 <boost/core/addressof.hpp> +#include <boost/core/checked_delete.hpp> +#include <boost/core/demangle.hpp> +#include <boost/detail/iterator.hpp> +#include <boost/core/enable_if.hpp> +#include <boost/core/explicit_operator_bool.hpp> +#include <boost/get_pointer.hpp> +#include <boost/core/ignore_unused.hpp> +#include <boost/core/is_same.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/noncopyable.hpp> +#include <boost/core/null_deleter.hpp> +#include <boost/core/pointer_traits.hpp> +#include <boost/ref.hpp> +#include <boost/core/scoped_enum.hpp> +#include <boost/core/typeinfo.hpp> +#include <boost/core/underlying_type.hpp> +#include <boost/visit_each.hpp> + +int main() +{ +} diff --git a/src/boost/libs/core/test/quick_exit_fail.cpp b/src/boost/libs/core/test/quick_exit_fail.cpp new file mode 100644 index 00000000..b1d394ee --- /dev/null +++ b/src/boost/libs/core/test/quick_exit_fail.cpp @@ -0,0 +1,17 @@ + +// Test for quick_exit.hpp +// +// Copyright 2018 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 <boost/core/quick_exit.hpp> + +int main() +{ + boost::quick_exit( 1 ); + return 0; +} diff --git a/src/boost/libs/core/test/quick_exit_test.cpp b/src/boost/libs/core/test/quick_exit_test.cpp new file mode 100644 index 00000000..e5f7795f --- /dev/null +++ b/src/boost/libs/core/test/quick_exit_test.cpp @@ -0,0 +1,17 @@ + +// Test for quick_exit.hpp +// +// Copyright 2018 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 <boost/core/quick_exit.hpp> + +int main() +{ + boost::quick_exit( 0 ); + return 1; +} diff --git a/src/boost/libs/core/test/ref_ct_test.cpp b/src/boost/libs/core/test/ref_ct_test.cpp new file mode 100644 index 00000000..731d62d8 --- /dev/null +++ b/src/boost/libs/core/test/ref_ct_test.cpp @@ -0,0 +1,121 @@ +// Copyright David Abrahams and Aleksey Gurtovoy +// 2002-2004. 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) + +// compile-time test for "boost/ref.hpp" header content +// see 'ref_test.cpp' for run-time part + +#include <boost/ref.hpp> +#include <boost/core/is_same.hpp> +#include <boost/static_assert.hpp> +#include <boost/detail/workaround.hpp> + +namespace { + +template< typename T, typename U > +void ref_test(boost::reference_wrapper<U>) +{ + typedef typename boost::reference_wrapper<U>::type type; + BOOST_STATIC_ASSERT((boost::core::is_same<U,type>::value)); + BOOST_STATIC_ASSERT((boost::core::is_same<T,type>::value)); +} + +template< typename T > +void assignable_test(T x) +{ + x = x; +} + +template< bool R, typename T > +void is_reference_wrapper_test(T) +{ + BOOST_STATIC_ASSERT(boost::is_reference_wrapper<T>::value == R); +} + +template< typename R, typename Ref > +void cxx_reference_test(Ref) +{ + BOOST_STATIC_ASSERT((boost::core::is_same<R,Ref>::value)); +} + +template< typename R, typename Ref > +void unwrap_reference_test(Ref) +{ + typedef typename boost::unwrap_reference<Ref>::type type; + BOOST_STATIC_ASSERT((boost::core::is_same<R,type>::value)); +} + +} // namespace + +int main() +{ + int i = 0; + int& ri = i; + + int const ci = 0; + int const& rci = ci; + + // 'ref/cref' functions test + ref_test<int>(boost::ref(i)); + ref_test<int>(boost::ref(ri)); + ref_test<int const>(boost::ref(ci)); + ref_test<int const>(boost::ref(rci)); + + ref_test<int const>(boost::cref(i)); + ref_test<int const>(boost::cref(ri)); + ref_test<int const>(boost::cref(ci)); + ref_test<int const>(boost::cref(rci)); + + // test 'assignable' requirement + assignable_test(boost::ref(i)); + assignable_test(boost::ref(ri)); + assignable_test(boost::cref(i)); + assignable_test(boost::cref(ci)); + assignable_test(boost::cref(rci)); + + // 'is_reference_wrapper' test + is_reference_wrapper_test<true>(boost::ref(i)); + is_reference_wrapper_test<true>(boost::ref(ri)); + is_reference_wrapper_test<true>(boost::cref(i)); + is_reference_wrapper_test<true>(boost::cref(ci)); + is_reference_wrapper_test<true>(boost::cref(rci)); + + is_reference_wrapper_test<false>(i); + is_reference_wrapper_test<false, int&>(ri); + is_reference_wrapper_test<false>(ci); + is_reference_wrapper_test<false, int const&>(rci); + + // ordinary references/function template arguments deduction test + cxx_reference_test<int>(i); + cxx_reference_test<int>(ri); + cxx_reference_test<int>(ci); + cxx_reference_test<int>(rci); + + cxx_reference_test<int&, int&>(i); + cxx_reference_test<int&, int&>(ri); + cxx_reference_test<int const&, int const&>(i); + cxx_reference_test<int const&, int const&>(ri); + cxx_reference_test<int const&, int const&>(ci); + cxx_reference_test<int const&, int const&>(rci); + + // 'unwrap_reference' test + unwrap_reference_test<int>(boost::ref(i)); + unwrap_reference_test<int>(boost::ref(ri)); + unwrap_reference_test<int const>(boost::cref(i)); + unwrap_reference_test<int const>(boost::cref(ci)); + unwrap_reference_test<int const>(boost::cref(rci)); + + unwrap_reference_test<int>(i); + unwrap_reference_test<int>(ri); + unwrap_reference_test<int>(ci); + unwrap_reference_test<int>(rci); + unwrap_reference_test<int&, int&>(i); + unwrap_reference_test<int&, int&>(ri); + unwrap_reference_test<int const&, int const&>(i); + unwrap_reference_test<int const&, int const&>(ri); + unwrap_reference_test<int const&, int const&>(ci); + unwrap_reference_test<int const&, int const&>(rci); + + return 0; +} diff --git a/src/boost/libs/core/test/ref_cv_test.cpp b/src/boost/libs/core/test/ref_cv_test.cpp new file mode 100644 index 00000000..734d9b38 --- /dev/null +++ b/src/boost/libs/core/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 <boost/ref.hpp> +#include <boost/core/lightweight_test.hpp> + +#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(); +} diff --git a/src/boost/libs/core/test/ref_fn_test.cpp b/src/boost/libs/core/test/ref_fn_test.cpp new file mode 100644 index 00000000..aec54e82 --- /dev/null +++ b/src/boost/libs/core/test/ref_fn_test.cpp @@ -0,0 +1,81 @@ +#include <boost/config.hpp> + +#if defined(BOOST_MSVC) +#pragma warning(disable: 4786) // identifier truncated in debug info +#pragma warning(disable: 4710) // function not inlined +#pragma warning(disable: 4711) // function selected for automatic inline expansion +#pragma warning(disable: 4514) // unreferenced inline removed +#endif + +// ref_fn_test.cpp: ref( f ) +// +// Copyright (c) 2008 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 <boost/ref.hpp> +#include <boost/detail/lightweight_test.hpp> + + +void f0() +{ +} + +void f1(int) +{ +} + +void f2(int, int) +{ +} + +void f3(int, int, int) +{ +} + +void f4(int, int, int, int) +{ +} + +void f5(int, int, int, int, int) +{ +} + +void f6(int, int, int, int, int, int) +{ +} + +void f7(int, int, int, int, int, int, int) +{ +} + +void f8(int, int, int, int, int, int, int, int) +{ +} + +void f9(int, int, int, int, int, int, int, int, int) +{ +} + +#define BOOST_TEST_REF( f ) BOOST_TEST( &boost::ref( f ).get() == &f ) + +int main() +{ + int v = 0; + BOOST_TEST_REF( v ); + + BOOST_TEST_REF( f0 ); + BOOST_TEST_REF( f1 ); + BOOST_TEST_REF( f2 ); + BOOST_TEST_REF( f3 ); + BOOST_TEST_REF( f4 ); + BOOST_TEST_REF( f5 ); + BOOST_TEST_REF( f6 ); + BOOST_TEST_REF( f7 ); + BOOST_TEST_REF( f8 ); + BOOST_TEST_REF( f9 ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/ref_implicit_fail.cpp b/src/boost/libs/core/test/ref_implicit_fail.cpp new file mode 100644 index 00000000..a012f526 --- /dev/null +++ b/src/boost/libs/core/test/ref_implicit_fail.cpp @@ -0,0 +1,20 @@ +// +// Rvalues should not implicitly convert to a reference_wrapper +// +// Copyright 2014 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 <boost/ref.hpp> + +void f( boost::reference_wrapper< int > ) +{ +} + +int main() +{ + f( 1 ); // should fail +} diff --git a/src/boost/libs/core/test/ref_implicit_fail2.cpp b/src/boost/libs/core/test/ref_implicit_fail2.cpp new file mode 100644 index 00000000..ff67630a --- /dev/null +++ b/src/boost/libs/core/test/ref_implicit_fail2.cpp @@ -0,0 +1,20 @@ +// +// Rvalues should not implicitly convert to a reference_wrapper +// +// Copyright 2014 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 <boost/ref.hpp> + +void f( boost::reference_wrapper< int const > ) +{ +} + +int main() +{ + f( 1 ); // should fail +} diff --git a/src/boost/libs/core/test/ref_ref_test.cpp b/src/boost/libs/core/test/ref_ref_test.cpp new file mode 100644 index 00000000..46be561c --- /dev/null +++ b/src/boost/libs/core/test/ref_ref_test.cpp @@ -0,0 +1,64 @@ +// +// Test that ref(ref(x)) does NOT collapse to ref(x) +// +// This irregularity of std::ref is questionable and breaks +// existing Boost code such as proto::make_expr +// +// Copyright 2014 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 <boost/ref.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T> void test( T const & t ) +{ + { + boost::reference_wrapper< T const > r = boost::ref( t ); + BOOST_TEST_EQ( &r.get(), &t ); + } + + { + boost::reference_wrapper< T const > r = boost::cref( t ); + BOOST_TEST_EQ( &r.get(), &t ); + } +} + +template<class T> void test_nonconst( T & t ) +{ + { + boost::reference_wrapper< T > r = boost::ref( t ); + BOOST_TEST_EQ( &r.get(), &t ); + } + + { + boost::reference_wrapper< T const > r = boost::cref( t ); + BOOST_TEST_EQ( &r.get(), &t ); + } +} + +int main() +{ + int x = 0; + + test( x ); + test( boost::ref( x ) ); + test( boost::cref( x ) ); + + test_nonconst( x ); + + { + boost::reference_wrapper< int > r = boost::ref( x ); + test_nonconst( r ); + } + + { + boost::reference_wrapper< int const > r = boost::cref( x ); + test_nonconst( r ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/ref_rv_fail1.cpp b/src/boost/libs/core/test/ref_rv_fail1.cpp new file mode 100644 index 00000000..1c0a2e68 --- /dev/null +++ b/src/boost/libs/core/test/ref_rv_fail1.cpp @@ -0,0 +1,23 @@ +// +// Test that a reference_wrapper can't be constructed from an rvalue +// +// Copyright 2014 Agustin Berge +// +// 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 <boost/ref.hpp> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +int main() +{ + boost::reference_wrapper<int const> r( 1 ); // this should produce an ERROR + (void)r; +} + +#else +# error To fail, this test requires rvalue references +#endif diff --git a/src/boost/libs/core/test/ref_rv_fail2.cpp b/src/boost/libs/core/test/ref_rv_fail2.cpp new file mode 100644 index 00000000..8ce26807 --- /dev/null +++ b/src/boost/libs/core/test/ref_rv_fail2.cpp @@ -0,0 +1,17 @@ +// +// Test that an rvalue can't be passed to ref() +// +// Copyright 2014 Agustin Berge +// +// 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 <boost/ref.hpp> + +int main() +{ + boost::reference_wrapper<int> r = boost::ref( 2 ); // this should produce an ERROR + (void)r; +} diff --git a/src/boost/libs/core/test/ref_rv_fail3.cpp b/src/boost/libs/core/test/ref_rv_fail3.cpp new file mode 100644 index 00000000..14b39b85 --- /dev/null +++ b/src/boost/libs/core/test/ref_rv_fail3.cpp @@ -0,0 +1,27 @@ +// +// Test that a const rvalue can't be passed to ref() +// +// Copyright 2014 Agustin Berge +// +// 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 <boost/ref.hpp> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +struct X {}; + +X const crv() { return X(); } + +int main() +{ + boost::reference_wrapper<X const> r = boost::ref( crv() ); // this should produce an ERROR + (void)r; +} + +#else +# error To fail, this test requires rvalue references +#endif diff --git a/src/boost/libs/core/test/ref_rv_fail4.cpp b/src/boost/libs/core/test/ref_rv_fail4.cpp new file mode 100644 index 00000000..899de7bc --- /dev/null +++ b/src/boost/libs/core/test/ref_rv_fail4.cpp @@ -0,0 +1,24 @@ +// +// Test that an rvalue can't be passed to cref() +// +// Copyright 2014 Agustin Berge +// Copyright 2014 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 <boost/ref.hpp> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +int main() +{ + boost::reference_wrapper<int const> r = boost::cref( 2 ); // should fail + (void)r; +} + +#else +# error To fail, this test requires rvalue references. +#endif diff --git a/src/boost/libs/core/test/ref_rv_fail5.cpp b/src/boost/libs/core/test/ref_rv_fail5.cpp new file mode 100644 index 00000000..ed18edf9 --- /dev/null +++ b/src/boost/libs/core/test/ref_rv_fail5.cpp @@ -0,0 +1,28 @@ +// +// Test that a const rvalue can't be passed to cref() +// +// Copyright 2014 Agustin Berge +// Copyright 2014 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 <boost/ref.hpp> + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + +struct X {}; + +X const crv() { return X(); } + +int main() +{ + boost::reference_wrapper<X const> r = boost::cref( crv() ); // must fail + (void)r; +} + +#else +# error To fail, this test requires rvalue references. +#endif diff --git a/src/boost/libs/core/test/ref_test.cpp b/src/boost/libs/core/test/ref_test.cpp new file mode 100644 index 00000000..a8f5bd73 --- /dev/null +++ b/src/boost/libs/core/test/ref_test.cpp @@ -0,0 +1,101 @@ +// Copyright David Abrahams and Aleksey Gurtovoy +// 2002-2004. 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) + +// run-time test for "boost/ref.hpp" header content +// see 'ref_ct_test.cpp' for compile-time part + +#include <boost/ref.hpp> +#include <boost/detail/lightweight_test.hpp> + +namespace { +using namespace boost; + +template <class T> +struct ref_wrapper +{ + // Used to verify implicit conversion + static T* get_pointer(T& x) + { + return &x; + } + + static T const* get_const_pointer(T const& x) + { + return &x; + } + + template <class Arg> + static T* passthru(Arg x) + { + return get_pointer(x); + } + + template <class Arg> + static T const* cref_passthru(Arg x) + { + return get_const_pointer(x); + } + + static void test(T x) + { + BOOST_TEST(passthru(ref(x)) == &x); + BOOST_TEST(&ref(x).get() == &x); + + BOOST_TEST(cref_passthru(cref(x)) == &x); + BOOST_TEST(&cref(x).get() == &x); + } +}; + +struct copy_counter { + static int count_; + copy_counter(copy_counter const& /*other*/) { + ++count_; + } + copy_counter() {} + static void reset() { count_ = 0; } + static int count() { return copy_counter::count_; } +}; + +int copy_counter::count_ = 0; + +} // namespace unnamed + +template <class T> +void do_unwrap(T t) { + + /* typename unwrap_reference<T>::type& lt = */ + unwrap_ref(t); + +} + +void unwrap_test() { + + int i = 3; + const int ci = 2; + + do_unwrap(i); + do_unwrap(ci); + do_unwrap(ref(i)); + do_unwrap(cref(ci)); + do_unwrap(ref(ci)); + + copy_counter cc; + BOOST_TEST(cc.count() == 0); + + do_unwrap(cc); + do_unwrap(ref(cc)); + do_unwrap(cref(cc)); + + BOOST_TEST(cc.count() == 1); + BOOST_TEST(unwrap_ref(ref(cc)).count() == 1); +} + +int main() +{ + ref_wrapper<int>::test(1); + ref_wrapper<int const>::test(1); + unwrap_test(); + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/scoped_enum.cpp b/src/boost/libs/core/test/scoped_enum.cpp new file mode 100644 index 00000000..2a83749b --- /dev/null +++ b/src/boost/libs/core/test/scoped_enum.cpp @@ -0,0 +1,157 @@ +/* + * Copyright Andrey Semashev 2014. + * 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) + */ +/*! + * \file scoped_enum.cpp + * \author Andrey Semashev + * \date 06.06.2014 + * + * \brief This test checks that scoped enum emulation works similar to C++11 scoped enums. + */ + +#include <boost/core/scoped_enum.hpp> +#include <boost/core/lightweight_test.hpp> + +BOOST_SCOPED_ENUM_DECLARE_BEGIN(namespace_enum1) +{ + value0, + value1, + value2 +} +BOOST_SCOPED_ENUM_DECLARE_END(namespace_enum1) + +BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(namespace_enum2, unsigned char) +{ + // Checks that enum value names do not clash + value0 = 10, + value1 = 20, + value2 = 30 +} +BOOST_SCOPED_ENUM_DECLARE_END(namespace_enum2) + +struct my_struct +{ + // Checks that declarations are valid in class scope + BOOST_SCOPED_ENUM_DECLARE_BEGIN(color) + { + red, + green, + blue + } + BOOST_SCOPED_ENUM_DECLARE_END(color) + + color m_color; + + explicit my_struct(color col) : m_color(col) + { + } + + color get_color() const + { + return m_color; + } +}; + +void check_operators() +{ + namespace_enum1 enum1 = namespace_enum1::value0; + BOOST_TEST(enum1 == namespace_enum1::value0); + BOOST_TEST(enum1 != namespace_enum1::value1); + BOOST_TEST(enum1 != namespace_enum1::value2); + + enum1 = namespace_enum1::value1; + BOOST_TEST(enum1 != namespace_enum1::value0); + BOOST_TEST(enum1 == namespace_enum1::value1); + BOOST_TEST(enum1 != namespace_enum1::value2); + + BOOST_TEST(!(enum1 < namespace_enum1::value0)); + BOOST_TEST(!(enum1 <= namespace_enum1::value0)); + BOOST_TEST(enum1 >= namespace_enum1::value0); + BOOST_TEST(enum1 > namespace_enum1::value0); + + BOOST_TEST(!(enum1 < namespace_enum1::value1)); + BOOST_TEST(enum1 <= namespace_enum1::value1); + BOOST_TEST(enum1 >= namespace_enum1::value1); + BOOST_TEST(!(enum1 > namespace_enum1::value1)); + + namespace_enum1 enum2 = namespace_enum1::value0; + BOOST_TEST(enum1 != enum2); + + enum2 = enum1; + BOOST_TEST(enum1 == enum2); +} + +void check_argument_passing() +{ + my_struct str(my_struct::color::green); + BOOST_TEST(str.get_color() == my_struct::color::green); +} + +void check_switch_case() +{ + my_struct str(my_struct::color::blue); + + switch (boost::native_value(str.get_color())) + { + case my_struct::color::blue: + break; + default: + BOOST_ERROR("Unexpected color value in switch/case"); + } +} + +template< typename T > +struct my_trait +{ + enum _ { value = 0 }; +}; + +template< > +struct my_trait< BOOST_SCOPED_ENUM_NATIVE(namespace_enum2) > +{ + enum _ { value = 1 }; +}; + +template< typename T > +void native_type_helper(T) +{ + BOOST_TEST(my_trait< T >::value != 0); +} + +void check_native_type() +{ + BOOST_TEST(my_trait< int >::value == 0); + BOOST_TEST(my_trait< BOOST_SCOPED_ENUM_NATIVE(namespace_enum2) >::value != 0); + BOOST_TEST(my_trait< boost::native_type< namespace_enum2 >::type >::value != 0); + + namespace_enum2 enum1 = namespace_enum2::value0; + native_type_helper(boost::native_value(enum1)); +} + +void check_underlying_cast() +{ + namespace_enum2 enum1 = namespace_enum2::value1; + BOOST_TEST(boost::underlying_cast< unsigned char >(enum1) == 20); +} + +void check_underlying_type() +{ + // The real check for the type is in the underlying_type trait test. + namespace_enum2 enum1 = namespace_enum2::value1; + BOOST_TEST(sizeof(enum1) == sizeof(unsigned char)); +} + +int main(int, char*[]) +{ + check_operators(); + check_argument_passing(); + check_switch_case(); + check_native_type(); + check_underlying_cast(); + check_underlying_type(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/scoped_enum_compile_fail_conv_from_int.cpp b/src/boost/libs/core/test/scoped_enum_compile_fail_conv_from_int.cpp new file mode 100644 index 00000000..2ff144fb --- /dev/null +++ b/src/boost/libs/core/test/scoped_enum_compile_fail_conv_from_int.cpp @@ -0,0 +1,30 @@ +/* + * Copyright Andrey Semashev 2014. + * 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) + */ +/*! + * \file scoped_enum_compile_fail_conv_from_int.cpp + * \author Andrey Semashev + * \date 06.06.2014 + * + * \brief This test checks that scoped enum emulation prohibits implicit conversions from int + */ + +#include <boost/core/scoped_enum.hpp> + +BOOST_SCOPED_ENUM_DECLARE_BEGIN(color) +{ + red, + green, + blue +} +BOOST_SCOPED_ENUM_DECLARE_END(color) + +int main(int, char*[]) +{ + color col = 2; + + return boost::native_value(col); +} diff --git a/src/boost/libs/core/test/scoped_enum_compile_fail_conv_to_int.cpp b/src/boost/libs/core/test/scoped_enum_compile_fail_conv_to_int.cpp new file mode 100644 index 00000000..699e0bb8 --- /dev/null +++ b/src/boost/libs/core/test/scoped_enum_compile_fail_conv_to_int.cpp @@ -0,0 +1,31 @@ +/* + * Copyright Andrey Semashev 2014. + * 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) + */ +/*! + * \file scoped_enum_compile_fail_conv_to_int.cpp + * \author Andrey Semashev + * \date 06.06.2014 + * + * \brief This test checks that scoped enum emulation prohibits implicit conversions to int + */ + +#include <boost/core/scoped_enum.hpp> + +BOOST_SCOPED_ENUM_DECLARE_BEGIN(color) +{ + red, + green, + blue +} +BOOST_SCOPED_ENUM_DECLARE_END(color) + +int main(int, char*[]) +{ + color col = color::red; + int n = col; + + return n; +} diff --git a/src/boost/libs/core/test/sp_typeinfo_test.cpp b/src/boost/libs/core/test/sp_typeinfo_test.cpp new file mode 100644 index 00000000..ae98c2c8 --- /dev/null +++ b/src/boost/libs/core/test/sp_typeinfo_test.cpp @@ -0,0 +1,53 @@ +// +// sp_typeinfo_test.cpp +// +// Copyright (c) 2009 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 +// + +#define BOOST_ALLOW_DEPRECATED_HEADERS + +#include <boost/detail/sp_typeinfo.hpp> +#include <boost/detail/lightweight_test.hpp> +#include <iostream> + +int main() +{ + BOOST_TEST( BOOST_SP_TYPEID( int ) == BOOST_SP_TYPEID( int ) ); + BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( long ) ); + BOOST_TEST( BOOST_SP_TYPEID( int ) != BOOST_SP_TYPEID( void ) ); + + boost::detail::sp_typeinfo const & ti = BOOST_SP_TYPEID( int ); + + boost::detail::sp_typeinfo const * pti = &BOOST_SP_TYPEID( int ); + BOOST_TEST( *pti == ti ); + + BOOST_TEST( ti == ti ); + BOOST_TEST( !( ti != ti ) ); + BOOST_TEST( !ti.before( ti ) ); + + char const * nti = ti.name(); + std::cout << nti << std::endl; + + boost::detail::sp_typeinfo const & tv = BOOST_SP_TYPEID( void ); + + boost::detail::sp_typeinfo const * ptv = &BOOST_SP_TYPEID( void ); + BOOST_TEST( *ptv == tv ); + + BOOST_TEST( tv == tv ); + BOOST_TEST( !( tv != tv ) ); + BOOST_TEST( !tv.before( tv ) ); + + char const * ntv = tv.name(); + std::cout << ntv << std::endl; + + BOOST_TEST( ti != tv ); + BOOST_TEST( !( ti == tv ) ); + + BOOST_TEST( ti.before( tv ) != tv.before( ti ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/Jamfile.v2 b/src/boost/libs/core/test/swap/Jamfile.v2 new file mode 100644 index 00000000..091f4038 --- /dev/null +++ b/src/boost/libs/core/test/swap/Jamfile.v2 @@ -0,0 +1,71 @@ +# Copyright (c) 2007, 2008 Joseph Gauterin +# +# 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) + +# bring in rules for testing +import testing ; + +local compile_tests = + root_header_1.cpp + root_header_2.cpp + lib_header_1.cpp + lib_header_2.cpp + mixed_headers_1.cpp + mixed_headers_2.cpp + ; + +local compile_fail_tests = + const_wrapper_fail.cpp ; + +local run_tests = + primitive.cpp + specialized_in_boost.cpp + specialized_in_global.cpp + specialized_in_other.cpp + specialized_in_std.cpp + specialized_in_boost_and_other.cpp + std_bitset.cpp + std_dateorder.cpp + std_string.cpp + std_typeinfo_ptr.cpp + std_vector_of_boost.cpp + std_vector_of_global.cpp + std_vector_of_other.cpp + no_ambiguity_in_boost.cpp + array_of_array_of_class.cpp + array_of_array_of_int.cpp + array_of_class.cpp + array_of_int.cpp + array_of_template.cpp + ; + +rule test_all +{ + local all_rules ; + local file ; + + for file in $(compile_tests) + { + local test_name = [ MATCH "([^.]*).cpp$" : $(file) ] ; + all_rules += [ compile $(file) : : "swap-$(test_name)" ] ; + } + + for file in $(compile_fail_tests) + { + local test_name = [ MATCH "([^.]*).cpp$" : $(file) ] ; + all_rules += [ compile-fail $(file) : : "swap-$(test_name)" ] ; + } + + for file in $(run_tests) + { + local test_name = [ MATCH "([^.]*).cpp$" : $(file) ] ; + all_rules += [ run $(file) : : : : "swap-$(test_name)" ] ; + } + + #ECHO All rules: $(all_rules) ; + return $(all_rules) ; +} + +test-suite core/swap : [ test_all r ] ; diff --git a/src/boost/libs/core/test/swap/array_of_array_of_class.cpp b/src/boost/libs/core/test/swap/array_of_array_of_class.cpp new file mode 100644 index 00000000..67541d31 --- /dev/null +++ b/src/boost/libs/core/test/swap/array_of_array_of_class.cpp @@ -0,0 +1,70 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +#include <algorithm> //for std::copy and std::equal +#include <cstddef> //for std::size_t + +//Provide swap function in both the namespace of swap_test_class +//(which is the global namespace), and the std namespace. +//It's common to provide a swap function for a class in both +//namespaces. Scott Meyers recommends doing so: Effective C++, +//Third Edition, item 25, "Consider support for a non-throwing swap". +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + + +int main() +{ + const std::size_t first_dimension = 3; + const std::size_t second_dimension = 4; + const std::size_t number_of_elements = first_dimension * second_dimension; + + swap_test_class array1[first_dimension][second_dimension]; + swap_test_class array2[first_dimension][second_dimension]; + + swap_test_class* const ptr1 = array1[0]; + swap_test_class* const ptr2 = array2[0]; + + for (std::size_t i = 0; i < number_of_elements; ++i) + { + ptr1[i].set_data( static_cast<int>(i) ); + ptr2[i].set_data( static_cast<int>(i + number_of_elements) ); + } + + boost::swap(array1, array2); + + for (std::size_t i = 0; i < number_of_elements; ++i) + { + BOOST_CHECK_EQUAL(ptr1[i].get_data(), static_cast<int>(i + number_of_elements) ); + BOOST_CHECK_EQUAL(ptr2[i].get_data(), static_cast<int>(i) ); + } + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), number_of_elements); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/array_of_array_of_int.cpp b/src/boost/libs/core/test/swap/array_of_array_of_int.cpp new file mode 100644 index 00000000..3f9b2399 --- /dev/null +++ b/src/boost/libs/core/test/swap/array_of_array_of_int.cpp @@ -0,0 +1,44 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping an array of arrays of integers by means of boost::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <algorithm> //for std::copy and std::equal +#include <cstddef> //for std::size_t + +int main() +{ + const std::size_t first_dimension = 3; + const std::size_t second_dimension = 4; + const std::size_t number_of_elements = first_dimension * second_dimension; + + int array1[first_dimension][second_dimension]; + int array2[first_dimension][second_dimension]; + + int* const ptr1 = array1[0]; + int* const ptr2 = array2[0]; + + for (std::size_t i = 0; i < number_of_elements; ++i) + { + ptr1[i] = static_cast<int>(i); + ptr2[i] = static_cast<int>(i + number_of_elements); + } + + boost::swap(array1, array2); + + for (std::size_t i = 0; i < number_of_elements; ++i) + { + BOOST_CHECK_EQUAL(ptr1[i], static_cast<int>(i + number_of_elements) ); + BOOST_CHECK_EQUAL(ptr2[i], static_cast<int>(i) ); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/array_of_class.cpp b/src/boost/libs/core/test/swap/array_of_class.cpp new file mode 100644 index 00000000..ef7327ec --- /dev/null +++ b/src/boost/libs/core/test/swap/array_of_class.cpp @@ -0,0 +1,62 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping an array of arrays of swap_test_class objects by means of boost::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +#include <algorithm> //for std::copy and std::equal +#include <cstddef> //for std::size_t + +//Provide swap function in both the namespace of swap_test_class +//(which is the global namespace), and the std namespace. +//It's common to provide a swap function for a class in both +//namespaces. Scott Meyers recommends doing so: Effective C++, +//Third Edition, item 25, "Consider support for a non-throwing swap". +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + + +int main() +{ + const std::size_t array_size = 2; + const swap_test_class initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) }; + const swap_test_class initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) }; + + swap_test_class array1[array_size]; + swap_test_class array2[array_size]; + + std::copy(initial_array1, initial_array1 + array_size, array1); + std::copy(initial_array2, initial_array2 + array_size, array2); + + swap_test_class::reset(); + boost::swap(array1, array2); + + BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); + BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/array_of_int.cpp b/src/boost/libs/core/test/swap/array_of_int.cpp new file mode 100644 index 00000000..e8285e0b --- /dev/null +++ b/src/boost/libs/core/test/swap/array_of_int.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping an array of integers by means of boost::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <algorithm> //for std::copy and std::equal +#include <cstddef> //for std::size_t + + +int main() +{ + const std::size_t array_size = 3; + const int initial_array1[array_size] = { 1, 2, 3 }; + const int initial_array2[array_size] = { 4, 5, 6 }; + + int array1[array_size]; + int array2[array_size]; + + std::copy(initial_array1, initial_array1 + array_size, array1); + std::copy(initial_array2, initial_array2 + array_size, array2); + + boost::swap(array1, array2); + + BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); + BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/array_of_template.cpp b/src/boost/libs/core/test/swap/array_of_template.cpp new file mode 100644 index 00000000..c0e76e3c --- /dev/null +++ b/src/boost/libs/core/test/swap/array_of_template.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping an array of swap_test_template<int> objects by means of boost::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +#include <algorithm> //for std::copy and std::equal +#include <cstddef> //for std::size_t + +template <class T> +class swap_test_template +{ +public: + typedef T template_argument; + swap_test_class swap_test_object; +}; + +template <class T> +inline bool operator==(const swap_test_template<T> & lhs, const swap_test_template<T> & rhs) +{ + return lhs.swap_test_object == rhs.swap_test_object; +} + +template <class T> +inline bool operator!=(const swap_test_template<T> & lhs, const swap_test_template<T> & rhs) +{ + return !(lhs == rhs); +} + +//Provide swap function in the namespace of swap_test_template +//(which is the global namespace). Note that it isn't allowed to put +//an overload of this function within the std namespace. +template <class T> +void swap(swap_test_template<T>& left, swap_test_template<T>& right) +{ + left.swap_test_object.swap(right.swap_test_object); +} + + +int main() +{ + const std::size_t array_size = 2; + const swap_test_template<int> initial_array1[array_size] = { swap_test_class(1), swap_test_class(2) }; + const swap_test_template<int> initial_array2[array_size] = { swap_test_class(3), swap_test_class(4) }; + + swap_test_template<int> array1[array_size]; + swap_test_template<int> array2[array_size]; + + std::copy(initial_array1, initial_array1 + array_size, array1); + std::copy(initial_array2, initial_array2 + array_size, array2); + + swap_test_class::reset(); + boost::swap(array1, array2); + + BOOST_CHECK(std::equal(array1, array1 + array_size, initial_array2)); + BOOST_CHECK(std::equal(array2, array2 + array_size, initial_array1)); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(), array_size); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(), 0); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/swap/const_wrapper_fail.cpp b/src/boost/libs/core/test/swap/const_wrapper_fail.cpp new file mode 100644 index 00000000..da2e4c6a --- /dev/null +++ b/src/boost/libs/core/test/swap/const_wrapper_fail.cpp @@ -0,0 +1,28 @@ +// Copyright 2018 Andrzej Krzemieński +// Copyright 2018 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. + +#include <boost/core/swap.hpp> + +namespace boost +{ + +template<class T> struct Wrapper +{ + T value; +}; + +template<class T> inline void swap( Wrapper<T> & w, Wrapper<T> & v ) +{ + boost::swap( w, v ); +} + +} // namespace boost + +int main() +{ + boost::Wrapper<int> const w = { 2 }; + boost::Wrapper<int> const v = { 3 }; + + swap( w, v ); +} diff --git a/src/boost/libs/core/test/swap/lib_header_1.cpp b/src/boost/libs/core/test/swap/lib_header_1.cpp new file mode 100644 index 00000000..923dea60 --- /dev/null +++ b/src/boost/libs/core/test/swap/lib_header_1.cpp @@ -0,0 +1,10 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap header compiles as a standalone translation unit + +#include <boost/utility/swap.hpp> + diff --git a/src/boost/libs/core/test/swap/lib_header_2.cpp b/src/boost/libs/core/test/swap/lib_header_2.cpp new file mode 100644 index 00000000..e88909db --- /dev/null +++ b/src/boost/libs/core/test/swap/lib_header_2.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap header include guards work correctly + +#include <boost/utility/swap.hpp> +#include <boost/utility/swap.hpp> + diff --git a/src/boost/libs/core/test/swap/mixed_headers_1.cpp b/src/boost/libs/core/test/swap/mixed_headers_1.cpp new file mode 100644 index 00000000..cdb9fe52 --- /dev/null +++ b/src/boost/libs/core/test/swap/mixed_headers_1.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap headers work when both are included + +#include <boost/swap.hpp> +#include <boost/utility/swap.hpp> + diff --git a/src/boost/libs/core/test/swap/mixed_headers_2.cpp b/src/boost/libs/core/test/swap/mixed_headers_2.cpp new file mode 100644 index 00000000..94e9d870 --- /dev/null +++ b/src/boost/libs/core/test/swap/mixed_headers_2.cpp @@ -0,0 +1,12 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap headers work when both are included + +#include <boost/utility/swap.hpp> +#include <boost/swap.hpp> + + diff --git a/src/boost/libs/core/test/swap/no_ambiguity_in_boost.cpp b/src/boost/libs/core/test/swap/no_ambiguity_in_boost.cpp new file mode 100644 index 00000000..795ffe30 --- /dev/null +++ b/src/boost/libs/core/test/swap/no_ambiguity_in_boost.cpp @@ -0,0 +1,45 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// boost::swap internally does an unqualified function call to swap. +// This could have led to ambiguity or infinite recursion, when the +// objects to be swapped would themselves be from the boost namespace. +// If so, boost::swap itself might be found by argument dependent lookup. +// The implementation of boost::swap resolves this issue by giving +// boost::swap two template argumetns, thereby making it less specialized +// than std::swap. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + + +int main() +{ + const boost::swap_test_class initial_value1(1); + const boost::swap_test_class initial_value2(2); + + boost::swap_test_class object1 = initial_value1; + boost::swap_test_class object2 = initial_value2; + + boost::swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),0); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),3); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/primitive.cpp b/src/boost/libs/core/test/swap/primitive.cpp new file mode 100644 index 00000000..a996f011 --- /dev/null +++ b/src/boost/libs/core/test/swap/primitive.cpp @@ -0,0 +1,24 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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 <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +int main() +{ + int object1 = 1; + int object2 = 2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,2); + BOOST_CHECK_EQUAL(object2,1); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/root_header_1.cpp b/src/boost/libs/core/test/swap/root_header_1.cpp new file mode 100644 index 00000000..575d2cba --- /dev/null +++ b/src/boost/libs/core/test/swap/root_header_1.cpp @@ -0,0 +1,10 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap header compiles as a standalone translation unit + +#include <boost/swap.hpp> + diff --git a/src/boost/libs/core/test/swap/root_header_2.cpp b/src/boost/libs/core/test/swap/root_header_2.cpp new file mode 100644 index 00000000..d26b3a62 --- /dev/null +++ b/src/boost/libs/core/test/swap/root_header_2.cpp @@ -0,0 +1,11 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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) + +// Tests that the swap header include guards work correctly + +#include <boost/swap.hpp> +#include <boost/swap.hpp> + diff --git a/src/boost/libs/core/test/swap/specialized_in_boost.cpp b/src/boost/libs/core/test/swap/specialized_in_boost.cpp new file mode 100644 index 00000000..dcb015da --- /dev/null +++ b/src/boost/libs/core/test/swap/specialized_in_boost.cpp @@ -0,0 +1,46 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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 <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + const boost::swap_test_class initial_value1(1); + const boost::swap_test_class initial_value2(2); + + boost::swap_test_class object1 = initial_value1; + boost::swap_test_class object2 = initial_value2; + + boost::swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(boost::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(boost::swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/specialized_in_boost_and_other.cpp b/src/boost/libs/core/test/swap/specialized_in_boost_and_other.cpp new file mode 100644 index 00000000..d5967759 --- /dev/null +++ b/src/boost/libs/core/test/swap/specialized_in_boost_and_other.cpp @@ -0,0 +1,65 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests whether instances of a class from a namespace other than boost are +// properly swapped, when both boost and the other namespace have a custom +// swap function for that class. Note that it shouldn't be necessary for a class +// in an other namespace to have a custom swap function in boost, because the +// boost::swap utility should find the swap function in the other namespace, by +// argument dependent lookup (ADL). Unfortunately ADL isn't fully implemented +// by some specific compiler versions, including Intel C++ 8.1, MSVC 7.1, and +// Borland 5.9.3. Users of those compilers might consider adding a swap overload +// to the boost namespace. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(::other::swap_test_class& left, ::other::swap_test_class& right) + { + left.swap(right); + } +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + const other::swap_test_class initial_value1(1); + const other::swap_test_class initial_value2(2); + + other::swap_test_class object1 = initial_value1; + other::swap_test_class object2 = initial_value2; + + other::swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/specialized_in_global.cpp b/src/boost/libs/core/test/swap/specialized_in_global.cpp new file mode 100644 index 00000000..8b0f10ac --- /dev/null +++ b/src/boost/libs/core/test/swap/specialized_in_global.cpp @@ -0,0 +1,40 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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 <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +//Provide swap function in gloabl namespace +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +int main() +{ + const swap_test_class initial_value1(1); + const swap_test_class initial_value2(2); + + swap_test_class object1 = initial_value1; + swap_test_class object2 = initial_value2; + + swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/specialized_in_other.cpp b/src/boost/libs/core/test/swap/specialized_in_other.cpp new file mode 100644 index 00000000..016cc8ac --- /dev/null +++ b/src/boost/libs/core/test/swap/specialized_in_other.cpp @@ -0,0 +1,46 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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 <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + const other::swap_test_class initial_value1(1); + const other::swap_test_class initial_value2(2); + + other::swap_test_class object1 = initial_value1; + other::swap_test_class object2 = initial_value2; + + other::swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(other::swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(other::swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/specialized_in_std.cpp b/src/boost/libs/core/test/swap/specialized_in_std.cpp new file mode 100644 index 00000000..62d4ee4a --- /dev/null +++ b/src/boost/libs/core/test/swap/specialized_in_std.cpp @@ -0,0 +1,45 @@ +// Copyright (c) 2007 Joseph Gauterin +// +// 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 <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + + +//Provide swap function in namespace std +namespace std +{ + template <> + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + const swap_test_class initial_value1(1); + const swap_test_class initial_value2(2); + + swap_test_class object1 = initial_value1; + swap_test_class object2 = initial_value2; + + swap_test_class::reset(); + boost::swap(object1,object2); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),1); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_bitset.cpp b/src/boost/libs/core/test/swap/std_bitset.cpp new file mode 100644 index 00000000..6fc3ecb3 --- /dev/null +++ b/src/boost/libs/core/test/swap/std_bitset.cpp @@ -0,0 +1,34 @@ +// Copyright (c) 2008 - 2010 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::bitset<T> objects by means of boost::swap. +// Unlike most other Standard C++ Library template classes, +// std::bitset<T> does not have its own std::swap overload. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <bitset> + +int main() +{ + typedef std::bitset<8> bitset_type; + const bitset_type initial_value1 = 1; + const bitset_type initial_value2 = 2; + + bitset_type object1 = initial_value1; + bitset_type object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_dateorder.cpp b/src/boost/libs/core/test/swap/std_dateorder.cpp new file mode 100644 index 00000000..7f6df733 --- /dev/null +++ b/src/boost/libs/core/test/swap/std_dateorder.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::time_base::dateorder objects by means of boost::swap. +// std::time_base::dateorder is an enumerated type. It does not have an +// std::swap overload or template specialization. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <locale> + +int main() +{ + const std::time_base::dateorder initial_value1 = std::time_base::dmy; + const std::time_base::dateorder initial_value2 = std::time_base::mdy; + + std::time_base::dateorder object1 = initial_value1; + std::time_base::dateorder object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_string.cpp b/src/boost/libs/core/test/swap/std_string.cpp new file mode 100644 index 00000000..128f3b52 --- /dev/null +++ b/src/boost/libs/core/test/swap/std_string.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::string objects by means of boost::swap. +// std::string has its own std::swap overload. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <string> + +int main() +{ + const std::string initial_value1 = "one"; + const std::string initial_value2 = "two"; + + std::string object1 = initial_value1; + std::string object2 = initial_value2; + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1,initial_value2); + BOOST_CHECK_EQUAL(object2,initial_value1); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_typeinfo_ptr.cpp b/src/boost/libs/core/test/swap/std_typeinfo_ptr.cpp new file mode 100644 index 00000000..10fd6e53 --- /dev/null +++ b/src/boost/libs/core/test/swap/std_typeinfo_ptr.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::type_info pointers by means of boost::swap. +// There is no std::swap overload or template specialization +// for std::type_info pointers. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <typeinfo> + +int main() +{ + const std::type_info * const initial_value1 = 0; + const std::type_info * const initial_value2 = &typeid(double); + + const std::type_info * ptr1 = initial_value1; + const std::type_info * ptr2 = initial_value2; + + boost::swap(ptr1,ptr2); + + BOOST_CHECK_EQUAL(ptr1,initial_value2); + BOOST_CHECK_EQUAL(ptr2,initial_value1); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_vector_of_boost.cpp b/src/boost/libs/core/test/swap/std_vector_of_boost.cpp new file mode 100644 index 00000000..93d5d61a --- /dev/null +++ b/src/boost/libs/core/test/swap/std_vector_of_boost.cpp @@ -0,0 +1,61 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::vector objects by means of boost::swap, +// having boost::swap_test_class as vector element type. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <vector> + +//Put test class in namespace boost +namespace boost +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace boost +namespace boost +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + typedef boost::swap_test_class swap_test_class_type; + typedef std::vector<swap_test_class_type> vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + const vector_type initial_value1(initial_size1, swap_test_class_type(1)); + const vector_type initial_value2(initial_size2, swap_test_class_type(2)); + + vector_type object1 = initial_value1; + vector_type object2 = initial_value2; + + swap_test_class_type::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_vector_of_global.cpp b/src/boost/libs/core/test/swap/std_vector_of_global.cpp new file mode 100644 index 00000000..08d6974c --- /dev/null +++ b/src/boost/libs/core/test/swap/std_vector_of_global.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::vector objects by means of boost::swap, +// having ::swap_test_class as vector element type. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <vector> + +//Put test class in the global namespace +#include "./swap_test_class.hpp" + +//Provide swap function in the global namespace +void swap(swap_test_class& left, swap_test_class& right) +{ + left.swap(right); +} + +int main() +{ + typedef std::vector<swap_test_class> vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + const vector_type initial_value1(initial_size1, swap_test_class(1)); + const vector_type initial_value2(initial_size2, swap_test_class(2)); + + vector_type object1 = initial_value1; + vector_type object2 = initial_value2; + + swap_test_class::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(swap_test_class::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/std_vector_of_other.cpp b/src/boost/libs/core/test/swap/std_vector_of_other.cpp new file mode 100644 index 00000000..77a3525a --- /dev/null +++ b/src/boost/libs/core/test/swap/std_vector_of_other.cpp @@ -0,0 +1,61 @@ +// Copyright (c) 2008 Joseph Gauterin, Niels Dekker +// +// 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) + +// Tests swapping std::vector objects by means of boost::swap, +// having other::swap_test_class as vector element type. + +#include <boost/utility/swap.hpp> +#include <boost/core/lightweight_test.hpp> +#define BOOST_CHECK BOOST_TEST +#define BOOST_CHECK_EQUAL BOOST_TEST_EQ + +#include <vector> + +//Put test class in namespace other +namespace other +{ + #include "./swap_test_class.hpp" +} + +//Provide swap function in namespace other +namespace other +{ + void swap(swap_test_class& left, swap_test_class& right) + { + left.swap(right); + } +} + +int main() +{ + typedef other::swap_test_class swap_test_class_type; + typedef std::vector<swap_test_class_type> vector_type; + + const vector_type::size_type initial_size1 = 1; + const vector_type::size_type initial_size2 = 2; + + const vector_type initial_value1(initial_size1, swap_test_class_type(1)); + const vector_type initial_value2(initial_size2, swap_test_class_type(2)); + + vector_type object1 = initial_value1; + vector_type object2 = initial_value2; + + swap_test_class_type::reset(); + + boost::swap(object1,object2); + + BOOST_CHECK_EQUAL(object1.size(),initial_size2); + BOOST_CHECK_EQUAL(object2.size(),initial_size1); + + BOOST_CHECK(object1 == initial_value2); + BOOST_CHECK(object2 == initial_value1); + + BOOST_CHECK_EQUAL(swap_test_class_type::swap_count(),0); + BOOST_CHECK_EQUAL(swap_test_class_type::copy_count(),0); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/core/test/swap/swap_test_class.hpp b/src/boost/libs/core/test/swap/swap_test_class.hpp new file mode 100644 index 00000000..a25dbbd8 --- /dev/null +++ b/src/boost/libs/core/test/swap/swap_test_class.hpp @@ -0,0 +1,114 @@ +// Copyright (c) 2007-2008 Joseph Gauterin +// +// 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) + +// Tests class used by the Boost.Swap tests + +#ifndef BOOST_UTILITY_SWAP_TEST_CLASS_HPP +#define BOOST_UTILITY_SWAP_TEST_CLASS_HPP + + +class swap_test_class +{ + int m_data; +public: + explicit swap_test_class(int arg = 0) + : + m_data(arg) + { + ++constructCount(); + } + + ~swap_test_class() + { + ++destructCount(); + } + + swap_test_class(const swap_test_class& arg) + : + m_data(arg.m_data) + { + ++copyCount(); + ++destructCount(); + } + + swap_test_class& operator=(const swap_test_class& arg) + { + m_data = arg.m_data; + ++copyCount(); + return *this; + } + + void swap(swap_test_class& other) + { + const int temp = m_data; + m_data = other.m_data; + other.m_data = temp; + + ++swapCount(); + } + + int get_data() const + { + return m_data; + } + + void set_data(int arg) + { + m_data = arg; + } + + static unsigned int swap_count(){ return swapCount(); } + static unsigned int copy_count(){ return copyCount(); } + static unsigned int construct_count(){ return constructCount(); } + static unsigned int destruct_count(){ return destructCount(); } + + static void reset() + { + swapCount() = 0; + copyCount() = 0; + constructCount() = 0; + destructCount() = 0; + } + +private: + static unsigned int& swapCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& copyCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& constructCount() + { + static unsigned int value = 0; + return value; + } + + static unsigned int& destructCount() + { + static unsigned int value = 0; + return value; + } + +}; + + +inline bool operator==(const swap_test_class & lhs, const swap_test_class & rhs) +{ + return lhs.get_data() == rhs.get_data(); +} + +inline bool operator!=(const swap_test_class & lhs, const swap_test_class & rhs) +{ + return !(lhs == rhs); +} + +#endif diff --git a/src/boost/libs/core/test/test_lib_typeid.cpp b/src/boost/libs/core/test/test_lib_typeid.cpp new file mode 100644 index 00000000..4e1fd753 --- /dev/null +++ b/src/boost/libs/core/test/test_lib_typeid.cpp @@ -0,0 +1,26 @@ + +// Copyright 2018 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. + +#include <boost/core/typeinfo.hpp> +#include <boost/core/lightweight_test.hpp> + +boost::core::typeinfo const & get_typeid_int(); + +int main() +{ + boost::core::typeinfo const & ti = BOOST_CORE_TYPEID( int ); + boost::core::typeinfo const & tf = BOOST_CORE_TYPEID( float ); + + boost::core::typeinfo const & ti2 = get_typeid_int(); + + BOOST_TEST( ti2 == ti ); + BOOST_TEST( ti2 != tf ); + + BOOST_TEST( !ti2.before( ti ) ); + BOOST_TEST( !ti.before( ti2 ) ); + + BOOST_TEST( ti2.before( tf ) != tf.before( ti2 ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/to_address_test.cpp b/src/boost/libs/core/test/to_address_test.cpp new file mode 100644 index 00000000..e1b55c4c --- /dev/null +++ b/src/boost/libs/core/test/to_address_test.cpp @@ -0,0 +1,158 @@ +/* +Copyright 2017-2018 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include <boost/core/pointer_traits.hpp> +#include <boost/core/lightweight_test.hpp> + +template<class T> +class P1 { +public: + explicit P1(T* p) + : p_(p) { } + T* operator->() const BOOST_NOEXCEPT { + return p_; + } +private: + T* p_; +}; + +template<class T> +class P2 { +public: + explicit P2(T* p) + : p_(p) { } + P1<T> operator->() const BOOST_NOEXCEPT { + return p_; + } +private: + P1<T> p_; +}; + +#if !defined(BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION) +template<class T> +class P3 { +public: + explicit P3(T* p) + : p_(p) { } + T* get() const BOOST_NOEXCEPT { + return p_; + } +private: + T* p_; +}; + +namespace boost { +template<class T> +struct pointer_traits<P3<T> > { + static T* to_address(const P3<T>& p) BOOST_NOEXCEPT { + return p.get(); + } +}; +} /* boost */ + +template<class T> +class P4 { +public: + explicit P4(T* p) + : p_(p) { } + T* operator->() const BOOST_NOEXCEPT { + return 0; + } + T* get() const BOOST_NOEXCEPT { + return p_; + } +private: + int* p_; +}; + +namespace boost { +template<class T> +struct pointer_traits<P4<T> > { + static T* to_address(const P4<T>& p) BOOST_NOEXCEPT { + return p.get(); + } +}; +} /* boost */ + +#if !defined(BOOST_NO_CXX11_POINTER_TRAITS) +template<class T> +class P5 { +public: + explicit P5(T* p) + : p_(p) { } + T* get() const BOOST_NOEXCEPT { + return p_; + } +private: + T* p_; +}; + +namespace std { +template<class T> +struct pointer_traits<P5<T> > { + static T* to_address(const P5<T>& p) BOOST_NOEXCEPT { + return p.get(); + } +}; +} /* std */ + +template<class T> +class P6 { +public: + explicit P6(T* p) + : p_(p) { } + T* get() const BOOST_NOEXCEPT { + return p_; + } +private: + T* p_; +}; + +namespace boost { +template<class T> +struct pointer_traits<P6<T> > { + static T* to_address(const P6<T>& p) BOOST_NOEXCEPT { + return p.get(); + } +}; +} /* boost */ + +namespace std { +template<class T> +struct pointer_traits<P6<T> > { + static T* to_address(const P6<T>& p) BOOST_NOEXCEPT { + return 0; + } +}; +} /* std */ +#endif +#endif + +int main() +{ + int i = 0; + BOOST_TEST(boost::to_address(&i) == &i); + int* p = &i; + BOOST_TEST(boost::to_address(p) == &i); + P1<int> p1(&i); + BOOST_TEST(boost::to_address(p1) == &i); + P2<int> p2(&i); + BOOST_TEST(boost::to_address(p2) == &i); +#if !defined(BOOST_NO_CXX14_RETURN_TYPE_DEDUCTION) + P3<int> p3(&i); + BOOST_TEST(boost::to_address(p3) == &i); + P4<int> p4(&i); + BOOST_TEST(boost::to_address(p4) == &i); +#if !defined(BOOST_NO_CXX11_POINTER_TRAITS) + P5<int> p5(&i); + BOOST_TEST(boost::to_address(p5) == &i); + P6<int> p6(&i); + BOOST_TEST(boost::to_address(p6) == &i); +#endif +#endif + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/typeinfo_test.cpp b/src/boost/libs/core/test/typeinfo_test.cpp new file mode 100644 index 00000000..3e122bb1 --- /dev/null +++ b/src/boost/libs/core/test/typeinfo_test.cpp @@ -0,0 +1,51 @@ +// +// typeinfo_test.cpp +// +// Copyright (c) 2009 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 <boost/core/typeinfo.hpp> +#include <boost/core/lightweight_test.hpp> +#include <iostream> + +int main() +{ + BOOST_TEST( BOOST_CORE_TYPEID( int ) == BOOST_CORE_TYPEID( int ) ); + BOOST_TEST( BOOST_CORE_TYPEID( int ) != BOOST_CORE_TYPEID( long ) ); + BOOST_TEST( BOOST_CORE_TYPEID( int ) != BOOST_CORE_TYPEID( void ) ); + + boost::core::typeinfo const & ti = BOOST_CORE_TYPEID( int ); + + boost::core::typeinfo const * pti = &BOOST_CORE_TYPEID( int ); + BOOST_TEST( *pti == ti ); + + BOOST_TEST( ti == ti ); + BOOST_TEST( !( ti != ti ) ); + BOOST_TEST( !ti.before( ti ) ); + + char const * nti = ti.name(); + std::cout << nti << std::endl; + + boost::core::typeinfo const & tv = BOOST_CORE_TYPEID( void ); + + boost::core::typeinfo const * ptv = &BOOST_CORE_TYPEID( void ); + BOOST_TEST( *ptv == tv ); + + BOOST_TEST( tv == tv ); + BOOST_TEST( !( tv != tv ) ); + BOOST_TEST( !tv.before( tv ) ); + + char const * ntv = tv.name(); + std::cout << ntv << std::endl; + + BOOST_TEST( ti != tv ); + BOOST_TEST( !( ti == tv ) ); + + BOOST_TEST( ti.before( tv ) != tv.before( ti ) ); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/uncaught_exceptions.cpp b/src/boost/libs/core/test/uncaught_exceptions.cpp new file mode 100644 index 00000000..d8b1fc61 --- /dev/null +++ b/src/boost/libs/core/test/uncaught_exceptions.cpp @@ -0,0 +1,55 @@ +/* + * Copyright Andrey Semashev 2018. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * https://www.boost.org/LICENSE_1_0.txt) + */ +/*! + * \file uncaught_exceptions.cpp + * \author Andrey Semashev + * \date 2018-11-10 + * + * \brief This file contains tests for the uncaught_exceptions function. + * + * This file only contains the very basic checks of functionality that can be portably achieved + * through C++03 std::uncaught_exception. + */ + +#include <boost/core/uncaught_exceptions.hpp> +#include <boost/core/lightweight_test.hpp> + +struct my_exception {}; + +class exception_watcher +{ + unsigned int& m_count; + +public: + explicit exception_watcher(unsigned int& count) : m_count(count) {} + ~exception_watcher() { m_count = boost::core::uncaught_exceptions(); } +}; + +// Tests for uncaught_exceptions when used in a destructor while an exception propagates +void test_in_destructor() +{ + const unsigned int root_count = boost::core::uncaught_exceptions(); + + unsigned int level1_count = root_count; + try + { + exception_watcher watcher(level1_count); + throw my_exception(); + } + catch (...) + { + } + + BOOST_TEST_NE(root_count, level1_count); +} + +int main() +{ + test_in_destructor(); + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/uncaught_exceptions_np.cpp b/src/boost/libs/core/test/uncaught_exceptions_np.cpp new file mode 100644 index 00000000..7498ccff --- /dev/null +++ b/src/boost/libs/core/test/uncaught_exceptions_np.cpp @@ -0,0 +1,90 @@ +/* + * Copyright Andrey Semashev 2018. + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE_1_0.txt or copy at + * https://www.boost.org/LICENSE_1_0.txt) + */ +/*! + * \file uncaught_exceptions_np.cpp + * \author Andrey Semashev + * \date 2018-11-10 + * + * \brief This file contains tests for the uncaught_exceptions function. + * + * This file contains checks that are compiler specific and not quite portable or require C++17. + */ + +#include <boost/core/uncaught_exceptions.hpp> + +#if !defined(BOOST_CORE_UNCAUGHT_EXCEPTIONS_EMULATED) + +#include <boost/core/lightweight_test.hpp> + +struct my_exception1 {}; +struct my_exception2 {}; + +class exception_watcher2 +{ + unsigned int& m_count; + +public: + explicit exception_watcher2(unsigned int& count) : m_count(count) {} + ~exception_watcher2() { m_count = boost::core::uncaught_exceptions(); } +}; + +class exception_watcher1 +{ + unsigned int& m_count1; + unsigned int& m_count2; + +public: + exception_watcher1(unsigned int& count1, unsigned int& count2) : m_count1(count1), m_count2(count2) {} + ~exception_watcher1() + { + m_count1 = boost::core::uncaught_exceptions(); + try + { + exception_watcher2 watcher2(m_count2); + throw my_exception2(); + } + catch (...) + { + } + } +}; + +// Tests for uncaught_exceptions when used in nested destructors while an exception propagates +void test_in_nested_destructors() +{ + const unsigned int root_count = boost::core::uncaught_exceptions(); + + unsigned int level1_count = root_count, level2_count = root_count; + try + { + exception_watcher1 watcher1(level1_count, level2_count); + throw my_exception1(); + } + catch (...) + { + } + + BOOST_TEST_NE(root_count, level1_count); + BOOST_TEST_NE(root_count, level2_count); + BOOST_TEST_NE(level1_count, level2_count); +} + +int main() +{ + test_in_nested_destructors(); + + return boost::report_errors(); +} + +#else + +int main() +{ + return 0; +} + +#endif diff --git a/src/boost/libs/core/test/underlying_type.cpp b/src/boost/libs/core/test/underlying_type.cpp new file mode 100644 index 00000000..0823f584 --- /dev/null +++ b/src/boost/libs/core/test/underlying_type.cpp @@ -0,0 +1,68 @@ +/* + * Copyright Andrey Semashev 2014. + * 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) + */ +/*! + * \file underlying_type.cpp + * \author Andrey Semashev + * \date 06.06.2014 + * + * \brief This test checks that underlying_type trait works. + */ + +#include <boost/core/underlying_type.hpp> +#include <boost/core/scoped_enum.hpp> +#include <boost/core/lightweight_test_trait.hpp> +#include <boost/core/is_same.hpp> +#include <boost/config.hpp> + +BOOST_SCOPED_ENUM_UT_DECLARE_BEGIN(emulated_enum, unsigned char) +{ + value0, + value1, + value2 +} +BOOST_SCOPED_ENUM_DECLARE_END(emulated_enum) + +#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) + +enum class native_enum : unsigned short +{ + value0, + value1, + value2 +}; + +#endif + +#if defined(BOOST_NO_UNDERLYING_TYPE) +namespace boost { + +template< > +struct underlying_type< emulated_enum > +{ + typedef unsigned char type; +}; + +#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) +template< > +struct underlying_type< native_enum > +{ + typedef unsigned short type; +}; +#endif + +} // namespace boost +#endif + +int main(int, char*[]) +{ + BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< emulated_enum >::type, unsigned char >)); +#if !defined(BOOST_NO_CXX11_SCOPED_ENUMS) + BOOST_TEST_TRAIT_TRUE((boost::core::is_same< boost::underlying_type< native_enum >::type, unsigned short >)); +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/core/test/use_default_test.cpp b/src/boost/libs/core/test/use_default_test.cpp new file mode 100644 index 00000000..adf1da6a --- /dev/null +++ b/src/boost/libs/core/test/use_default_test.cpp @@ -0,0 +1,15 @@ +/* +Copyright 2019 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ + +#include <boost/core/use_default.hpp> + +template<class, class = boost::use_default> +struct type { }; + +template class type<int>; +template class type<void, boost::use_default>; diff --git a/src/boost/libs/core/test/visit_each_test.cpp b/src/boost/libs/core/test/visit_each_test.cpp new file mode 100644 index 00000000..726188ef --- /dev/null +++ b/src/boost/libs/core/test/visit_each_test.cpp @@ -0,0 +1,65 @@ +// +// visit_each_test.cpp +// +// Copyright 2014 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 <boost/visit_each.hpp> +#include <boost/core/lightweight_test.hpp> +#include <string> + +struct X +{ + int v; + std::string w; +}; + +template<class Visitor> inline void visit_each( Visitor & visitor, X const & x ) +{ + using boost::visit_each; + + visit_each( visitor, x.v ); + visit_each( visitor, x.w ); +} + +struct V +{ + int s_; + + V(): s_( 0 ) + { + } + + template< class T > void operator()( T const & t ) + { + } + + void operator()( int const & v ) + { + s_ = s_ * 10 + v; + } + + void operator()( std::string const & w ) + { + s_ = s_ * 10 + w.size(); + } +}; + +int main() +{ + X x = { 5, "test" }; + V v; + + { + using boost::visit_each; + visit_each( v, x ); + } + + BOOST_TEST( v.s_ == 54 ); + + return boost::report_errors(); +} |