| 1 | /* Copyright 2016-2017 Joaquin M Lopez Munoz. |
| 2 | * Distributed under the Boost Software License, Version 1.0. |
| 3 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | * http://www.boost.org/LICENSE_1_0.txt) |
| 5 | * |
| 6 | * See http://www.boost.org/libs/poly_collection for library home page. |
| 7 | */ |
| 8 | |
| 9 | #include "test_registration.hpp" |
| 10 | |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | #include <iterator> |
| 13 | #include "any_types.hpp" |
| 14 | #include "base_types.hpp" |
| 15 | #include "function_types.hpp" |
| 16 | #include "test_utilities.hpp" |
| 17 | |
| 18 | using namespace test_utilities; |
| 19 | |
| 20 | template<typename PolyCollection,typename Type> |
| 21 | void test_registration() |
| 22 | { |
| 23 | using unregistered_type=boost::poly_collection::unregistered_type; |
| 24 | |
| 25 | { |
| 26 | PolyCollection p; |
| 27 | const PolyCollection& cp=p; |
| 28 | |
| 29 | BOOST_TEST(!p.is_registered(typeid(Type))); |
| 30 | BOOST_TEST(!p.template is_registered<Type>()); |
| 31 | check_throw<unregistered_type>( |
| 32 | [&]{(void)p.begin(typeid(Type));}, |
| 33 | [&]{(void)p.end(typeid(Type));}, |
| 34 | [&]{(void)cp.begin(typeid(Type));}, |
| 35 | [&]{(void)cp.end(typeid(Type));}, |
| 36 | [&]{(void)p.cbegin(typeid(Type));}, |
| 37 | [&]{(void)p.cend(typeid(Type));}, |
| 38 | [&]{(void)p.template begin<Type>();}, |
| 39 | [&]{(void)p.template end<Type>();}, |
| 40 | [&]{(void)cp.template begin<Type>();}, |
| 41 | [&]{(void)cp.template end<Type>();}, |
| 42 | [&]{(void)p.template cbegin<Type>();}, |
| 43 | [&]{(void)p.template cend<Type>();}, |
| 44 | [&]{(void)p.segment(typeid(Type));}, |
| 45 | [&]{(void)cp.segment(typeid(Type));}, |
| 46 | [&]{(void)p.template segment<Type>();}, |
| 47 | [&]{(void)cp.template segment<Type>();}, |
| 48 | [&]{(void)cp.empty(typeid(Type));}, |
| 49 | [&]{(void)cp.size(typeid(Type));}, |
| 50 | [&]{(void)cp.max_size(typeid(Type));}, |
| 51 | [&]{(void)p.reserve(typeid(Type),0);}, |
| 52 | [&]{(void)cp.capacity(typeid(Type));}, |
| 53 | [&]{(void)p.shrink_to_fit(typeid(Type));}, |
| 54 | [&]{(void)p.clear(typeid(Type));}, |
| 55 | [&]{(void)cp.template empty<Type>();}, |
| 56 | [&]{(void)cp.template size<Type>();}, |
| 57 | [&]{(void)cp.template max_size<Type>();}, |
| 58 | /* reserve<Type> omitted as it actually registers the type */ |
| 59 | [&]{(void)cp.template capacity<Type>();}, |
| 60 | [&]{(void)p.template shrink_to_fit<Type>();}, |
| 61 | [&]{(void)p.template clear<Type>();}); |
| 62 | |
| 63 | p.register_types(); |
| 64 | p.template register_types<>(); |
| 65 | BOOST_TEST(!p.is_registered(typeid(Type))); |
| 66 | |
| 67 | p.template register_types<Type>(); |
| 68 | |
| 69 | BOOST_TEST(p.is_registered(typeid(Type))); |
| 70 | BOOST_TEST(p.template is_registered<Type>()); |
| 71 | (void)p.end(typeid(Type)); |
| 72 | (void)cp.begin(typeid(Type)); |
| 73 | (void)cp.end(typeid(Type)); |
| 74 | (void)p.cbegin(typeid(Type)); |
| 75 | (void)p.cend(typeid(Type)); |
| 76 | (void)p.template begin<Type>(); |
| 77 | (void)p.template end<Type>(); |
| 78 | (void)cp.template begin<Type>(); |
| 79 | (void)cp.template end<Type>(); |
| 80 | (void)cp.template cbegin<Type>(); |
| 81 | (void)cp.template cend<Type>(); |
| 82 | (void)cp.empty(typeid(Type)); |
| 83 | (void)cp.size(typeid(Type)); |
| 84 | (void)cp.max_size(typeid(Type)); |
| 85 | (void)p.reserve(typeid(Type),0); |
| 86 | (void)cp.capacity(typeid(Type)); |
| 87 | (void)p.shrink_to_fit(typeid(Type)); |
| 88 | (void)p.clear(typeid(Type)); |
| 89 | (void)cp.template empty<Type>(); |
| 90 | (void)cp.template size<Type>(); |
| 91 | (void)cp.template max_size<Type>(); |
| 92 | /* reserve<Type> omitted */ |
| 93 | (void)cp.template capacity<Type>(); |
| 94 | (void)p.template shrink_to_fit<Type>(); |
| 95 | (void)p.template clear<Type>(); |
| 96 | } |
| 97 | |
| 98 | { |
| 99 | PolyCollection p; |
| 100 | p.template reserve<Type>(0); |
| 101 | BOOST_TEST(p.is_registered(typeid(Type))); |
| 102 | } |
| 103 | |
| 104 | { |
| 105 | PolyCollection p; |
| 106 | p.template register_types<Type,Type,Type>(); |
| 107 | BOOST_TEST(p.is_registered(typeid(Type))); |
| 108 | BOOST_TEST( |
| 109 | std::distance( |
| 110 | p.segment_traversal().begin(),p.segment_traversal().end())==1); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void test_registration() |
| 115 | { |
| 116 | test_registration<any_types::collection,any_types::t1>(); |
| 117 | test_registration<base_types::collection,base_types::t1>(); |
| 118 | test_registration<function_types::collection,function_types::t1>(); |
| 119 | } |
| 120 | |