mirror of
https://github.com/boostorg/detail.git
synced 2025-07-29 20:07:15 +02:00
Add some tests
Test classes which I'm going to remove the MPL dependency from: blank, allocator_utilities, is_xxx and reference_content. I'm also going to change indirect_traits, but that's tested in the python module.
This commit is contained in:
@ -7,7 +7,7 @@
|
||||
|
||||
build-project container_fwd ;
|
||||
|
||||
project detail/test
|
||||
project detail/test
|
||||
: requirements
|
||||
<toolset>clang:<cxxflags>-Wno-unused
|
||||
<toolset>clang:<cxxflags>-Wno-tautological-compare
|
||||
@ -22,7 +22,11 @@ project detail/test
|
||||
import ../../config/checks/config : requires ;
|
||||
|
||||
run binary_search_test.cpp ;
|
||||
run blank_test.cpp ;
|
||||
run is_sorted_test.cpp ;
|
||||
run numeric_traits_test.cpp ;
|
||||
run is_xxx_test.cpp ;
|
||||
# run test_utf8_codecvt.cpp : : : [ requires std_wstreambuf ] ;
|
||||
run test_utf8_codecvt.cpp ;
|
||||
run test_utf8_codecvt.cpp ;
|
||||
run allocator_utilities_test.cpp ;
|
||||
run reference_content_test.cpp ;
|
||||
|
40
test/allocator_utilities_test.cpp
Normal file
40
test/allocator_utilities_test.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
// Copyright 2018 Daniel James.
|
||||
// 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/allocator_utilities.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <cassert>
|
||||
|
||||
typedef std::allocator<int> std_int_allocator;
|
||||
typedef typename boost::detail::allocator::rebind_to<std_int_allocator, char>::type char_allocator;
|
||||
typedef typename boost::detail::allocator::rebind_to<char_allocator, int>::type int_allocator;
|
||||
typedef typename boost::detail::allocator::rebind_to<int_allocator, char>::type char_allocator2;
|
||||
|
||||
int main() {
|
||||
BOOST_STATIC_ASSERT((!boost::is_same<char_allocator, int_allocator>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<char_allocator, char_allocator2>::value));
|
||||
|
||||
// Check the constructors works okay
|
||||
std_int_allocator a1;
|
||||
char_allocator a2(a1);
|
||||
char_allocator a2a(a2);
|
||||
int_allocator a3(a2);
|
||||
|
||||
// Check allocate works okay
|
||||
{
|
||||
typename char_allocator::pointer p = a2.allocate(10);
|
||||
assert(p);
|
||||
a2.deallocate(p, 10);
|
||||
}
|
||||
|
||||
// Try using the standalone construct/destroy
|
||||
{
|
||||
typename int_allocator::pointer p2 = a3.allocate(1);
|
||||
boost::detail::allocator::construct(p2, 25);
|
||||
assert(*p2 == 25);
|
||||
boost::detail::allocator::destroy(p2);
|
||||
a3.deallocate(p2, 1);
|
||||
}
|
||||
}
|
32
test/blank_test.cpp
Normal file
32
test/blank_test.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
// Copyright 2018 Daniel James.
|
||||
// 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/blank.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <cassert>
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
BOOST_STATIC_ASSERT((boost::is_pod<boost::blank>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_empty<boost::blank>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_stateless<boost::blank>::value));
|
||||
|
||||
boost::blank b1,b2;
|
||||
assert(b1 == b2);
|
||||
assert(b1 <= b2);
|
||||
assert(b1 >= b2);
|
||||
assert(!(b1 != b2));
|
||||
assert(!(b1 < b2));
|
||||
assert(!(b1 > b2));
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
std::stringstream s;
|
||||
s << "(" << b1 << ")";
|
||||
assert(s.str() == "()");
|
||||
#endif
|
||||
}
|
23
test/is_xxx_test.cpp
Normal file
23
test/is_xxx_test.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
// Copyright 2018 Daniel James.
|
||||
// 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/is_xxx.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
|
||||
namespace is_xxx_test {
|
||||
template <typename T> struct thing1 {};
|
||||
template <typename T1, typename T2 = int> struct thing2 {};
|
||||
}
|
||||
|
||||
BOOST_DETAIL_IS_XXX_DEF(thing1, is_xxx_test::thing1, 1);
|
||||
BOOST_DETAIL_IS_XXX_DEF(thing2, is_xxx_test::thing2, 2);
|
||||
|
||||
BOOST_STATIC_ASSERT((is_thing1<is_xxx_test::thing1<int> >::value));
|
||||
BOOST_STATIC_ASSERT((!is_thing1<is_xxx_test::thing2<int> >::value));
|
||||
BOOST_STATIC_ASSERT((!is_thing2<is_xxx_test::thing1<int> >::value));
|
||||
BOOST_STATIC_ASSERT((is_thing2<is_xxx_test::thing2<int> >::value));
|
||||
BOOST_STATIC_ASSERT((is_thing2<is_xxx_test::thing2<int, float> >::value));
|
||||
|
||||
int main() {}
|
16
test/reference_content_test.cpp
Normal file
16
test/reference_content_test.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
// Copyright 2018 Daniel James.
|
||||
// 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/reference_content.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<int, boost::detail::make_reference_content<int>::type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<boost::detail::reference_content<int&>, boost::detail::make_reference_content<int&>::type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<int, boost::detail::make_reference_content<>::template apply<int>::type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<boost::detail::reference_content<int&>, boost::detail::make_reference_content<>::template apply<int&>::type>::value));
|
||||
BOOST_STATIC_ASSERT((boost::has_nothrow_copy<boost::detail::make_reference_content<int&>::type>::value));
|
||||
|
||||
int main() {}
|
Reference in New Issue
Block a user