test_exceptions.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. // Boost.Geometry Index
  2. //
  3. // R-tree nodes based on runtime-polymorphism, storing static-size containers
  4. // test version throwing exceptions on creation
  5. //
  6. // Copyright (c) 2011-2013 Adam Wulkiewicz, Lodz, Poland.
  7. //
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #ifndef BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP
  12. #define BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP
  13. #include <rtree/test_rtree.hpp>
  14. #include <rtree/exceptions/test_throwing.hpp>
  15. #include <rtree/exceptions/test_throwing_node.hpp>
  16. #include <boost/geometry/geometries/point.hpp>
  17. #include <boost/geometry/geometries/box.hpp>
  18. // test value exceptions
  19. template <typename Parameters>
  20. void test_rtree_value_exceptions(Parameters const& parameters = Parameters())
  21. {
  22. typedef std::pair<bg::model::point<float, 2, bg::cs::cartesian>, throwing_value> Value;
  23. typedef bgi::rtree<Value, Parameters> Tree;
  24. typedef typename Tree::bounds_type B;
  25. throwing_value::reset_calls_counter();
  26. throwing_value::set_max_calls((std::numeric_limits<size_t>::max)());
  27. std::vector<Value> input;
  28. B qbox;
  29. generate::input<2>::apply(input, qbox);
  30. for ( size_t i = 0 ; i < 50 ; i += 2 )
  31. {
  32. throwing_value::reset_calls_counter();
  33. throwing_value::set_max_calls(10000);
  34. Tree tree(parameters);
  35. throwing_value::reset_calls_counter();
  36. throwing_value::set_max_calls(i);
  37. BOOST_CHECK_THROW( tree.insert(input.begin(), input.end()), throwing_value_copy_exception );
  38. }
  39. for ( size_t i = 0 ; i < 20 ; i += 1 )
  40. {
  41. throwing_value::reset_calls_counter();
  42. throwing_value::set_max_calls(i);
  43. BOOST_CHECK_THROW( Tree tree(input.begin(), input.end(), parameters), throwing_value_copy_exception );
  44. }
  45. for ( size_t i = 0 ; i < 10 ; i += 1 )
  46. {
  47. throwing_value::reset_calls_counter();
  48. throwing_value::set_max_calls(10000);
  49. Tree tree(parameters);
  50. tree.insert(input.begin(), input.end());
  51. throwing_value::reset_calls_counter();
  52. throwing_value::set_max_calls(i);
  53. BOOST_CHECK_THROW( tree.remove(input.begin(), input.end()), throwing_value_copy_exception );
  54. }
  55. for ( size_t i = 0 ; i < 20 ; i += 2 )
  56. {
  57. throwing_value::reset_calls_counter();
  58. throwing_value::set_max_calls(10000);
  59. Tree tree(parameters);
  60. tree.insert(input.begin(), input.end());
  61. throwing_value::reset_calls_counter();
  62. throwing_value::set_max_calls(i);
  63. BOOST_CHECK_THROW( Tree tree2(tree), throwing_value_copy_exception );
  64. }
  65. for ( size_t i = 0 ; i < 20 ; i += 2 )
  66. {
  67. throwing_value::reset_calls_counter();
  68. throwing_value::set_max_calls(10000);
  69. Tree tree(parameters);
  70. Tree tree2(parameters);
  71. tree.insert(input.begin(), input.end());
  72. throwing_value::reset_calls_counter();
  73. throwing_value::set_max_calls(i);
  74. BOOST_CHECK_THROW(tree2 = tree, throwing_value_copy_exception );
  75. }
  76. }
  77. // test value exceptions
  78. template <typename Parameters>
  79. void test_rtree_elements_exceptions(Parameters const& parameters = Parameters())
  80. {
  81. typedef std::pair<bg::model::point<float, 2, bg::cs::cartesian>, throwing_value> Value;
  82. typedef bgi::rtree<Value, Parameters> Tree;
  83. typedef typename Tree::bounds_type B;
  84. throwing_value::reset_calls_counter();
  85. throwing_value::set_max_calls((std::numeric_limits<size_t>::max)());
  86. std::vector<Value> input;
  87. B qbox;
  88. generate::input<2>::apply(input, qbox, 2);
  89. for ( size_t i = 0 ; i < 100 ; i += 2 )
  90. {
  91. throwing_varray_settings::reset_calls_counter();
  92. throwing_varray_settings::set_max_calls(10000);
  93. Tree tree(parameters);
  94. throwing_varray_settings::reset_calls_counter();
  95. throwing_varray_settings::set_max_calls(i);
  96. BOOST_CHECK_THROW( tree.insert(input.begin(), input.end()), throwing_varray_exception );
  97. }
  98. for ( size_t i = 0 ; i < 100 ; i += 2 )
  99. {
  100. throwing_varray_settings::reset_calls_counter();
  101. throwing_varray_settings::set_max_calls(i);
  102. throwing_nodes_stats::reset_counters();
  103. BOOST_CHECK_THROW( Tree tree(input.begin(), input.end(), parameters), throwing_varray_exception );
  104. BOOST_CHECK_EQUAL(throwing_nodes_stats::internal_nodes_count(), 0u);
  105. BOOST_CHECK_EQUAL(throwing_nodes_stats::leafs_count(), 0u);
  106. }
  107. for ( size_t i = 0 ; i < 50 ; i += 2 )
  108. {
  109. throwing_varray_settings::reset_calls_counter();
  110. throwing_varray_settings::set_max_calls(10000);
  111. Tree tree(parameters);
  112. tree.insert(input.begin(), input.end());
  113. throwing_varray_settings::reset_calls_counter();
  114. throwing_varray_settings::set_max_calls(i);
  115. BOOST_CHECK_THROW( tree.remove(input.begin(), input.end()), throwing_varray_exception );
  116. }
  117. for ( size_t i = 0 ; i < 50 ; i += 2 )
  118. {
  119. throwing_varray_settings::reset_calls_counter();
  120. throwing_varray_settings::set_max_calls(10000);
  121. Tree tree(parameters);
  122. tree.insert(input.begin(), input.end());
  123. throwing_varray_settings::reset_calls_counter();
  124. throwing_varray_settings::set_max_calls(i);
  125. BOOST_CHECK_THROW( Tree tree2(tree), throwing_varray_exception );
  126. }
  127. for ( size_t i = 0 ; i < 50 ; i += 2 )
  128. {
  129. throwing_varray_settings::reset_calls_counter();
  130. throwing_varray_settings::set_max_calls(10000);
  131. Tree tree(parameters);
  132. Tree tree2(parameters);
  133. tree.insert(input.begin(), input.end());
  134. throwing_varray_settings::reset_calls_counter();
  135. throwing_varray_settings::set_max_calls(i);
  136. BOOST_CHECK_THROW(tree2 = tree, throwing_varray_exception );
  137. }
  138. }
  139. #endif // BOOST_GEOMETRY_INDEX_TEST_RTREE_EXCEPTIONS_HPP