Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / common / boost / 1.64.0 / include / boost-1_64 / boost / core / lightweight_test.hpp
1 #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_HPP
2 #define BOOST_CORE_LIGHTWEIGHT_TEST_HPP
3
4 // MS compatible compilers support #pragma once
5
6 #if defined(_MSC_VER)
7 # pragma once
8 #endif
9
10 //
11 //  boost/core/lightweight_test.hpp - lightweight test library
12 //
13 //  Copyright (c) 2002, 2009, 2014 Peter Dimov
14 //  Copyright (2) Beman Dawes 2010, 2011
15 //  Copyright (3) Ion Gaztanaga 2013
16 //
17 //  Distributed under the Boost Software License, Version 1.0.
18 //  See accompanying file LICENSE_1_0.txt or copy at
19 //  http://www.boost.org/LICENSE_1_0.txt
20 //
21
22 #include <iterator>
23 #include <boost/assert.hpp>
24 #include <boost/current_function.hpp>
25 #include <boost/core/no_exceptions_support.hpp>
26 #include <iostream>
27 #include <cstring>
28
29 //  IDE's like Visual Studio perform better if output goes to std::cout or
30 //  some other stream, so allow user to configure output stream:
31 #ifndef BOOST_LIGHTWEIGHT_TEST_OSTREAM
32 # define BOOST_LIGHTWEIGHT_TEST_OSTREAM std::cerr
33 #endif
34
35 namespace boost
36 {
37
38 namespace detail
39 {
40
41 struct report_errors_reminder
42 {
43     bool called_report_errors_function;
44
45     report_errors_reminder() : called_report_errors_function(false) {}
46
47     ~report_errors_reminder()
48     {
49         BOOST_ASSERT(called_report_errors_function);  // verify report_errors() was called  
50     }
51 };
52
53 inline report_errors_reminder& report_errors_remind()
54 {
55     static report_errors_reminder r;
56     return r;
57 }
58
59 inline int & test_errors()
60 {
61     static int x = 0;
62     report_errors_remind();
63     return x;
64 }
65
66 inline void test_failed_impl(char const * expr, char const * file, int line, char const * function)
67 {
68     BOOST_LIGHTWEIGHT_TEST_OSTREAM
69       << file << "(" << line << "): test '" << expr << "' failed in function '"
70       << function << "'" << std::endl;
71     ++test_errors();
72 }
73
74 inline void error_impl(char const * msg, char const * file, int line, char const * function)
75 {
76     BOOST_LIGHTWEIGHT_TEST_OSTREAM
77       << file << "(" << line << "): " << msg << " in function '"
78       << function << "'" << std::endl;
79     ++test_errors();
80 }
81
82 inline void throw_failed_impl(char const * excep, char const * file, int line, char const * function)
83 {
84    BOOST_LIGHTWEIGHT_TEST_OSTREAM
85     << file << "(" << line << "): Exception '" << excep << "' not thrown in function '"
86     << function << "'" << std::endl;
87    ++test_errors();
88 }
89
90 // In the comparisons below, it is possible that T and U are signed and unsigned integer types, which generates warnings in some compilers.
91 // A cleaner fix would require common_type trait or some meta-programming, which would introduce a dependency on Boost.TypeTraits. To avoid
92 // the dependency we just disable the warnings.
93 #if defined(_MSC_VER)
94 # pragma warning(push)
95 # pragma warning(disable: 4389)
96 #elif defined(__clang__) && defined(__has_warning)
97 # if __has_warning("-Wsign-compare")
98 #  pragma clang diagnostic push
99 #  pragma clang diagnostic ignored "-Wsign-compare"
100 # endif
101 #elif defined(__GNUC__) && !(defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
102 # pragma GCC diagnostic push
103 # pragma GCC diagnostic ignored "-Wsign-compare"
104 #endif
105
106 // specialize test output for char pointers to avoid printing as cstring
107 template <class T> inline const T& test_output_impl(const T& v) { return v; }
108 inline const void* test_output_impl(const char* v) { return v; }
109 inline const void* test_output_impl(const unsigned char* v) { return v; }
110 inline const void* test_output_impl(const signed char* v) { return v; }
111 inline const void* test_output_impl(char* v) { return v; }
112 inline const void* test_output_impl(unsigned char* v) { return v; }
113 inline const void* test_output_impl(signed char* v) { return v; }
114 template<class T> inline const void* test_output_impl(T volatile* v) { return const_cast<T*>(v); }
115
116 template<class T, class U> inline void test_eq_impl( char const * expr1, char const * expr2,
117   char const * file, int line, char const * function, T const & t, U const & u )
118 {
119     if( t == u )
120     {
121         report_errors_remind();
122     }
123     else
124     {
125         BOOST_LIGHTWEIGHT_TEST_OSTREAM
126             << file << "(" << line << "): test '" << expr1 << " == " << expr2
127             << "' failed in function '" << function << "': "
128             << "'" << test_output_impl(t) << "' != '" << test_output_impl(u) << "'" << std::endl;
129         ++test_errors();
130     }
131 }
132
133 template<class T, class U> inline void test_ne_impl( char const * expr1, char const * expr2,
134   char const * file, int line, char const * function, T const & t, U const & u )
135 {
136     if( t != u )
137     {
138         report_errors_remind();
139     }
140     else
141     {
142         BOOST_LIGHTWEIGHT_TEST_OSTREAM
143             << file << "(" << line << "): test '" << expr1 << " != " << expr2
144             << "' failed in function '" << function << "': "
145             << "'" << test_output_impl(t) << "' == '" << test_output_impl(u) << "'" << std::endl;
146         ++test_errors();
147     }
148 }
149
150 inline void test_cstr_eq_impl( char const * expr1, char const * expr2,
151   char const * file, int line, char const * function, char const * const t, char const * const u )
152 {
153     if( std::strcmp(t, u) == 0 )
154     {
155         report_errors_remind();
156     }
157     else
158     {
159         BOOST_LIGHTWEIGHT_TEST_OSTREAM
160             << file << "(" << line << "): test '" << expr1 << " == " << expr2
161             << "' failed in function '" << function << "': "
162             << "'" << t << "' != '" << u << "'" << std::endl;
163         ++test_errors();
164     }
165 }
166
167 inline void test_cstr_ne_impl( char const * expr1, char const * expr2,
168   char const * file, int line, char const * function, char const * const t, char const * const u )
169 {
170     if( std::strcmp(t, u) != 0 )
171     {
172         report_errors_remind();
173     }
174     else
175     {
176         BOOST_LIGHTWEIGHT_TEST_OSTREAM
177             << file << "(" << line << "): test '" << expr1 << " == " << expr2
178             << "' failed in function '" << function << "': "
179             << "'" << t << "' == '" << u << "'" << std::endl;
180         ++test_errors();
181     }
182 }
183
184 template<class FormattedOutputFunction, class InputIterator1, class InputIterator2>
185 void test_all_eq_impl(FormattedOutputFunction& output,
186                       char const * file, int line, char const * function,
187                       InputIterator1 first_begin, InputIterator1 first_end,
188                       InputIterator2 second_begin, InputIterator2 second_end)
189 {
190     InputIterator1 first_it = first_begin;
191     InputIterator2 second_it = second_begin;
192     typename std::iterator_traits<InputIterator1>::difference_type first_index = 0;
193     typename std::iterator_traits<InputIterator2>::difference_type second_index = 0;
194     std::size_t error_count = 0;
195     const std::size_t max_count = 8;
196     do
197     {
198         while ((first_it != first_end) && (second_it != second_end) && (*first_it == *second_it))
199         {
200             ++first_it;
201             ++second_it;
202             ++first_index;
203             ++second_index;
204         }
205         if ((first_it == first_end) || (second_it == second_end))
206         {
207             break; // do-while
208         }
209         if (error_count == 0)
210         {
211             output << file << "(" << line << "): Container contents differ in function '" << function << "':";
212         }
213         else if (error_count >= max_count)
214         {
215             output << " ...";
216             break;
217         }
218         output << " [" << first_index << "] '" << test_output_impl(*first_it) << "' != '" << test_output_impl(*second_it) << "'";
219         ++first_it;
220         ++second_it;
221         ++first_index;
222         ++second_index;
223         ++error_count;
224     } while (first_it != first_end);
225
226     first_index += std::distance(first_it, first_end);
227     second_index += std::distance(second_it, second_end);
228     if (first_index != second_index)
229     {
230         if (error_count == 0)
231         {
232             output << file << "(" << line << "): Container sizes differ in function '" << function << "': size(" << first_index << ") != size(" << second_index << ")";
233         }
234         else
235         {
236             output << " [*] size(" << first_index << ") != size(" << second_index << ")";
237         }
238         ++error_count;
239     }
240
241     if (error_count == 0)
242     {
243         boost::detail::report_errors_remind();
244     }
245     else
246     {
247         output << std::endl;
248         ++boost::detail::test_errors();
249     }
250 }
251
252 template<class FormattedOutputFunction, class InputIterator1, class InputIterator2, typename BinaryPredicate>
253 void test_all_with_impl(FormattedOutputFunction& output,
254                         char const * file, int line, char const * function,
255                         InputIterator1 first_begin, InputIterator1 first_end,
256                         InputIterator2 second_begin, InputIterator2 second_end,
257                         BinaryPredicate predicate)
258 {
259     InputIterator1 first_it = first_begin;
260     InputIterator2 second_it = second_begin;
261     typename std::iterator_traits<InputIterator1>::difference_type first_index = 0;
262     typename std::iterator_traits<InputIterator2>::difference_type second_index = 0;
263     std::size_t error_count = 0;
264     const std::size_t max_count = 8;
265     do
266     {
267         while ((first_it != first_end) && (second_it != second_end) && predicate(*first_it, *second_it))
268         {
269             ++first_it;
270             ++second_it;
271             ++first_index;
272             ++second_index;
273         }
274         if ((first_it == first_end) || (second_it == second_end))
275         {
276             break; // do-while
277         }
278         if (error_count == 0)
279         {
280             output << file << "(" << line << "): Container contents differ in function '" << function << "':";
281         }
282         else if (error_count >= max_count)
283         {
284             output << " ...";
285             break;
286         }
287         output << " [" << first_index << "]";
288         ++first_it;
289         ++second_it;
290         ++first_index;
291         ++second_index;
292         ++error_count;
293     } while (first_it != first_end);
294
295     first_index += std::distance(first_it, first_end);
296     second_index += std::distance(second_it, second_end);
297     if (first_index != second_index)
298     {
299         if (error_count == 0)
300         {
301             output << file << "(" << line << "): Container sizes differ in function '" << function << "': size(" << first_index << ") != size(" << second_index << ")";
302         }
303         else
304         {
305             output << " [*] size(" << first_index << ") != size(" << second_index << ")";
306         }
307         ++error_count;
308     }
309
310     if (error_count == 0)
311     {
312         report_errors_remind();
313     }
314     else
315     {
316         output << std::endl;
317         ++test_errors();
318     }
319 }
320
321 #if defined(_MSC_VER)
322 # pragma warning(pop)
323 #elif defined(__clang__) && defined(__has_warning)
324 # if __has_warning("-Wsign-compare")
325 #  pragma clang diagnostic pop
326 # endif
327 #elif defined(__GNUC__) && !(defined(__INTEL_COMPILER) || defined(__ICL) || defined(__ICC) || defined(__ECC)) && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406
328 # pragma GCC diagnostic pop
329 #endif
330
331 } // namespace detail
332
333 inline int report_errors()
334 {
335     boost::detail::report_errors_remind().called_report_errors_function = true;
336
337     int errors = boost::detail::test_errors();
338
339     if( errors == 0 )
340     {
341         BOOST_LIGHTWEIGHT_TEST_OSTREAM
342           << "No errors detected." << std::endl;
343         return 0;
344     }
345     else
346     {
347         BOOST_LIGHTWEIGHT_TEST_OSTREAM
348           << errors << " error" << (errors == 1? "": "s") << " detected." << std::endl;
349         return 1;
350     }
351 }
352
353 } // namespace boost
354
355 #define BOOST_TEST(expr) ((expr)? (void)0: ::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION))
356 #define BOOST_TEST_NOT(expr) BOOST_TEST(!(expr))
357
358 #define BOOST_ERROR(msg) ( ::boost::detail::error_impl(msg, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION) )
359
360 #define BOOST_TEST_EQ(expr1,expr2) ( ::boost::detail::test_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
361 #define BOOST_TEST_NE(expr1,expr2) ( ::boost::detail::test_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
362
363 #define BOOST_TEST_CSTR_EQ(expr1,expr2) ( ::boost::detail::test_cstr_eq_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
364 #define BOOST_TEST_CSTR_NE(expr1,expr2) ( ::boost::detail::test_cstr_ne_impl(#expr1, #expr2, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, expr1, expr2) )
365
366 #define BOOST_TEST_ALL_EQ(begin1, end1, begin2, end2) ( ::boost::detail::test_all_eq_impl(BOOST_LIGHTWEIGHT_TEST_OSTREAM, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, begin1, end1, begin2, end2) )
367 #define BOOST_TEST_ALL_WITH(begin1, end1, begin2, end2, predicate) ( ::boost::detail::test_all_with_impl(BOOST_LIGHTWEIGHT_TEST_OSTREAM, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION, begin1, end1, begin2, end2, predicate) )
368
369 #ifndef BOOST_NO_EXCEPTIONS
370    #define BOOST_TEST_THROWS( EXPR, EXCEP )                    \
371       try {                                                    \
372          EXPR;                                                 \
373          ::boost::detail::throw_failed_impl                    \
374          (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \
375       }                                                        \
376       catch(EXCEP const&) {                                    \
377       }                                                        \
378       catch(...) {                                             \
379          ::boost::detail::throw_failed_impl                    \
380          (#EXCEP, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); \
381       }                                                        \
382    //
383 #else
384    #define BOOST_TEST_THROWS( EXPR, EXCEP )
385 #endif
386
387 #endif // #ifndef BOOST_CORE_LIGHTWEIGHT_TEST_HPP