1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14
15 #ifndef GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP
16 #define GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP
17
18 #include <boost/config.hpp>
19
20 // Determine debug/release mode
21 // (it would be convenient if Boost.Config or Boost.Test would define this)
22 // Note that they might be combined (e.g. for optimize+no inline)
23 #if defined (BOOST_CLANG) || defined(BOOST_GCC)
24 #if defined(__OPTIMIZE__)
25 #define BOOST_GEOMETRY_COMPILER_MODE_RELEASE
26 #endif
27 #if defined(__NO_INLINE__)
28 #define BOOST_GEOMETRY_COMPILER_MODE_DEBUG
29 #endif
30 #endif
31
32 #if defined(BOOST_MSVC)
33 #if defined(_DEBUG)
34 #define BOOST_GEOMETRY_COMPILER_MODE_DEBUG
35 #else
36 #define BOOST_GEOMETRY_COMPILER_MODE_RELEASE
37 #endif
38 #endif
39
40
41 #if defined(BOOST_MSVC)
42 // We deliberately mix float/double's so turn off warnings
43 #pragma warning( disable : 4244 )
44 // For (new since Boost 1.40) warning in Boost.Test on putenv/posix
45 #pragma warning( disable : 4996 )
46
47 //#pragma warning( disable : 4305 )
48 #endif // defined(BOOST_MSVC)
49
50 #include <boost/config.hpp>
51 #include <boost/concept_check.hpp>
52 #include <boost/core/ignore_unused.hpp>
53 #include <boost/foreach.hpp>
54
55 #include <string_from_type.hpp>
56
57 // Include some always-included-for-testing files
58 #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST)
59
60 // Until Boost.Test fixes it, silence warning issued by clang:
61 #ifdef __clang__
62 # pragma clang diagnostic push
63 // warning: unused variable 'check_is_close' [-Wunused-variable]
64 # pragma clang diagnostic ignored "-Wunused-variable"
65 // warnings when -Wconversion is set
66 # pragma clang diagnostic ignored "-Wsign-conversion"
67 # pragma clang diagnostic ignored "-Wshorten-64-to-32"
68 #endif
69
70 # include <boost/test/tools/floating_point_comparison.hpp>
71 #ifndef BOOST_TEST_MODULE
72 # include <boost/test/included/test_exec_monitor.hpp>
73 //# include <boost/test/included/prg_exec_monitor.hpp>
74 # include <boost/test/impl/execution_monitor.ipp>
75 #endif
76
77 #ifdef __clang__
78 # pragma clang diagnostic pop
79 #endif
80
81 #endif
82
83
84 #if defined(HAVE_TTMATH)
85 # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
86 #endif
87
88 #if defined(HAVE_CLN) || defined(HAVE_GMP)
89 # include <boost/numeric_adaptor/numeric_adaptor.hpp>
90 #endif
91
92
93 #if defined(HAVE_GMP)
94 # include <boost/numeric_adaptor/gmp_value_type.hpp>
95 #endif
96 #if defined(HAVE_CLN)
97 # include <boost/numeric_adaptor/cln_value_type.hpp>
98 #endif
99
100 // For all tests:
101 // - do NOT use "using namespace boost::geometry" to make clear what is Boost.Geometry
102 // - use bg:: as short alias
103 #include <boost/geometry/core/coordinate_type.hpp>
104 #include <boost/geometry/core/config.hpp>
105 #include <boost/geometry/core/closure.hpp>
106 #include <boost/geometry/core/point_order.hpp>
107 #include <boost/geometry/core/tag.hpp>
108 namespace bg = boost::geometry;
109
110
111 template <typename CoordinateType, typename T1, typename T2>
if_typed_tt(T1 value_tt,T2 value)112 inline T1 if_typed_tt(T1 value_tt, T2 value)
113 {
114 #if defined(HAVE_TTMATH)
115 return boost::is_same<CoordinateType, ttmath_big>::type::value ? value_tt : value;
116 #else
117 boost::ignore_unused(value_tt);
118 return value;
119 #endif
120 }
121
122 template <typename CoordinateType, typename Specified, typename T>
if_typed(T value_typed,T value)123 inline T if_typed(T value_typed, T value)
124 {
125 return boost::is_same<CoordinateType, Specified>::value ? value_typed : value;
126 }
127
128 template <typename Geometry1, typename Geometry2>
type_for_assert_message()129 inline std::string type_for_assert_message()
130 {
131 bool const ccw =
132 bg::point_order<Geometry1>::value == bg::counterclockwise
133 || bg::point_order<Geometry2>::value == bg::counterclockwise;
134 bool const open =
135 bg::closure<Geometry1>::value == bg::open
136 || bg::closure<Geometry2>::value == bg::open;
137
138 std::ostringstream out;
139 out << string_from_type<typename bg::coordinate_type<Geometry1>::type>::name()
140 << (ccw ? " ccw" : "")
141 << (open ? " open" : "");
142 return out.str();
143 }
144
145 struct geographic_policy
146 {
147 template <typename CoordinateType>
applygeographic_policy148 static inline CoordinateType apply(CoordinateType const& value)
149 {
150 return value;
151 }
152 };
153
154 struct mathematical_policy
155 {
156 template <typename CoordinateType>
applymathematical_policy157 static inline CoordinateType apply(CoordinateType const& value)
158 {
159 return 90 - value;
160 }
161
162 };
163
164 struct ut_base_settings
165 {
ut_base_settingsut_base_settings166 explicit ut_base_settings(bool val = true)
167 : m_test_validity(true)
168 {
169 set_test_validity(val);
170 }
171
set_test_validityut_base_settings172 inline void set_test_validity(bool val)
173 {
174 #if defined(BOOST_GEOMETRY_TEST_FAILURES)
175 boost::ignore_unused(val);
176 #else
177 m_test_validity = val;
178 #endif
179 }
180
test_validityut_base_settings181 inline bool test_validity() const
182 {
183 return m_test_validity;
184 }
185
186 private :
187 bool m_test_validity;
188 };
189
190
191 typedef double default_test_type;
192
193 #if defined(BOOST_GEOMETRY_USE_RESCALING)
194 #define BG_IF_RESCALED(a, b) a
195 #else
196 #define BG_IF_RESCALED(a, b) b
197 #endif
198
199 #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
200 #define BG_IF_KRAMER(a, b) a
201 #else
202 #define BG_IF_KRAMER(a, b) b
203 #endif
204
BoostGeometryWriteTestConfiguration()205 inline void BoostGeometryWriteTestConfiguration()
206 {
207 std::cout << std::endl << "Test configuration:" << std::endl;
208 #if defined(BOOST_GEOMETRY_USE_RESCALING)
209 std::cout << " - Using rescaling" << std::endl;
210 #endif
211 #if defined(BOOST_GEOMETRY_USE_KRAMER_RULE)
212 std::cout << " - Using Kramer rule" << std::endl;
213 #else
214 std::cout << " - Using general form" << std::endl;
215 #endif
216 #if defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE)
217 std::cout << " - Testing only one type" << std::endl;
218 #endif
219 #if defined(BOOST_GEOMETRY_TEST_ONLY_ONE_ORDER)
220 std::cout << " - Testing only one order" << std::endl;
221 #endif
222 #if defined(BOOST_GEOMETRY_TEST_FAILURES)
223 std::cout << " - Including failing test cases" << std::endl;
224 #endif
225 std::cout << " - Default test type: " << string_from_type<default_test_type>::name() << std::endl;
226 std::cout << std::endl;
227 }
228
229 #ifdef BOOST_GEOMETRY_TEST_FAILURES
230 #define BG_NO_FAILURES 0
BoostGeometryWriteExpectedFailures(std::size_t for_rescaling,std::size_t for_no_rescaling=BG_NO_FAILURES)231 inline void BoostGeometryWriteExpectedFailures(std::size_t for_rescaling,
232 std::size_t for_no_rescaling = BG_NO_FAILURES)
233 {
234 boost::ignore_unused(for_rescaling, for_no_rescaling);
235
236 #if defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE) && defined(BOOST_GEOMETRY_TEST_ONLY_ONE_ORDER)
237 std::cout << std::endl;
238 #if defined(BOOST_GEOMETRY_USE_RESCALING)
239 std::cout << "RESCALED - Expected: " << for_rescaling << " error(s)" << std::endl;
240 #else
241 std::cout << "NOT RESCALED - Expected: " << for_no_rescaling << " error(s)" << std::endl;
242 #endif
243 #endif
244 }
245 #endif
246
247 #endif // GEOMETRY_TEST_GEOMETRY_TEST_COMMON_HPP
248