test_registration.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. #include "test_registration.hpp"
  9. #include <boost/core/lightweight_test.hpp>
  10. #include <iterator>
  11. #include "any_types.hpp"
  12. #include "base_types.hpp"
  13. #include "function_types.hpp"
  14. #include "test_utilities.hpp"
  15. using namespace test_utilities;
  16. template<typename PolyCollection,typename Type>
  17. void test_registration()
  18. {
  19. using unregistered_type=boost::poly_collection::unregistered_type;
  20. {
  21. PolyCollection p;
  22. const PolyCollection& cp=p;
  23. BOOST_TEST(!p.is_registered(typeid(Type)));
  24. BOOST_TEST(!p.template is_registered<Type>());
  25. check_throw<unregistered_type>(
  26. [&]{(void)p.begin(typeid(Type));},
  27. [&]{(void)p.end(typeid(Type));},
  28. [&]{(void)cp.begin(typeid(Type));},
  29. [&]{(void)cp.end(typeid(Type));},
  30. [&]{(void)p.cbegin(typeid(Type));},
  31. [&]{(void)p.cend(typeid(Type));},
  32. [&]{(void)p.template begin<Type>();},
  33. [&]{(void)p.template end<Type>();},
  34. [&]{(void)cp.template begin<Type>();},
  35. [&]{(void)cp.template end<Type>();},
  36. [&]{(void)p.template cbegin<Type>();},
  37. [&]{(void)p.template cend<Type>();},
  38. [&]{(void)p.segment(typeid(Type));},
  39. [&]{(void)cp.segment(typeid(Type));},
  40. [&]{(void)p.template segment<Type>();},
  41. [&]{(void)cp.template segment<Type>();},
  42. [&]{(void)cp.empty(typeid(Type));},
  43. [&]{(void)cp.size(typeid(Type));},
  44. [&]{(void)cp.max_size(typeid(Type));},
  45. [&]{(void)p.reserve(typeid(Type),0);},
  46. [&]{(void)cp.capacity(typeid(Type));},
  47. [&]{(void)p.shrink_to_fit(typeid(Type));},
  48. [&]{(void)p.clear(typeid(Type));},
  49. [&]{(void)cp.template empty<Type>();},
  50. [&]{(void)cp.template size<Type>();},
  51. [&]{(void)cp.template max_size<Type>();},
  52. /* reserve<Type> omitted as it actually registers the type */
  53. [&]{(void)cp.template capacity<Type>();},
  54. [&]{(void)p.template shrink_to_fit<Type>();},
  55. [&]{(void)p.template clear<Type>();});
  56. p.register_types();
  57. p.template register_types<>();
  58. BOOST_TEST(!p.is_registered(typeid(Type)));
  59. p.template register_types<Type>();
  60. BOOST_TEST(p.is_registered(typeid(Type)));
  61. BOOST_TEST(p.template is_registered<Type>());
  62. (void)p.end(typeid(Type));
  63. (void)cp.begin(typeid(Type));
  64. (void)cp.end(typeid(Type));
  65. (void)p.cbegin(typeid(Type));
  66. (void)p.cend(typeid(Type));
  67. (void)p.template begin<Type>();
  68. (void)p.template end<Type>();
  69. (void)cp.template begin<Type>();
  70. (void)cp.template end<Type>();
  71. (void)cp.template cbegin<Type>();
  72. (void)cp.template cend<Type>();
  73. (void)cp.empty(typeid(Type));
  74. (void)cp.size(typeid(Type));
  75. (void)cp.max_size(typeid(Type));
  76. (void)p.reserve(typeid(Type),0);
  77. (void)cp.capacity(typeid(Type));
  78. (void)p.shrink_to_fit(typeid(Type));
  79. (void)p.clear(typeid(Type));
  80. (void)cp.template empty<Type>();
  81. (void)cp.template size<Type>();
  82. (void)cp.template max_size<Type>();
  83. /* reserve<Type> omitted */
  84. (void)cp.template capacity<Type>();
  85. (void)p.template shrink_to_fit<Type>();
  86. (void)p.template clear<Type>();
  87. }
  88. {
  89. PolyCollection p;
  90. p.template reserve<Type>(0);
  91. BOOST_TEST(p.is_registered(typeid(Type)));
  92. }
  93. {
  94. PolyCollection p;
  95. p.template register_types<Type,Type,Type>();
  96. BOOST_TEST(p.is_registered(typeid(Type)));
  97. BOOST_TEST(
  98. std::distance(
  99. p.segment_traversal().begin(),p.segment_traversal().end())==1);
  100. }
  101. }
  102. void test_registration()
  103. {
  104. test_registration<any_types::collection,any_types::t1>();
  105. test_registration<base_types::collection,base_types::t1>();
  106. test_registration<function_types::collection,function_types::t1>();
  107. }