GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/* |
||
2 |
* Catch v1.5.1 |
||
3 |
* Generated: 2016-04-28 08:12:37.387488 |
||
4 |
* ---------------------------------------------------------- |
||
5 |
* This file has been merged from multiple headers. Please don't edit it directly |
||
6 |
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. |
||
7 |
* |
||
8 |
* Distributed under the Boost Software License, Version 1.0. (See accompanying |
||
9 |
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
||
10 |
*/ |
||
11 |
#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED |
||
12 |
#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED |
||
13 |
|||
14 |
#define TWOBLUECUBES_CATCH_HPP_INCLUDED |
||
15 |
|||
16 |
#ifdef __clang__ |
||
17 |
# pragma clang system_header |
||
18 |
#elif defined __GNUC__ |
||
19 |
# pragma GCC system_header |
||
20 |
#endif |
||
21 |
|||
22 |
// #included from: internal/catch_suppress_warnings.h |
||
23 |
|||
24 |
#ifdef __clang__ |
||
25 |
# ifdef __ICC // icpc defines the __clang__ macro |
||
26 |
# pragma warning(push) |
||
27 |
# pragma warning(disable: 161 1682) |
||
28 |
# else // __ICC |
||
29 |
# pragma clang diagnostic ignored "-Wglobal-constructors" |
||
30 |
# pragma clang diagnostic ignored "-Wvariadic-macros" |
||
31 |
# pragma clang diagnostic ignored "-Wc99-extensions" |
||
32 |
# pragma clang diagnostic ignored "-Wunused-variable" |
||
33 |
# pragma clang diagnostic push |
||
34 |
# pragma clang diagnostic ignored "-Wpadded" |
||
35 |
# pragma clang diagnostic ignored "-Wc++98-compat" |
||
36 |
# pragma clang diagnostic ignored "-Wc++98-compat-pedantic" |
||
37 |
# pragma clang diagnostic ignored "-Wswitch-enum" |
||
38 |
# pragma clang diagnostic ignored "-Wcovered-switch-default" |
||
39 |
# endif |
||
40 |
#elif defined __GNUC__ |
||
41 |
# pragma GCC diagnostic ignored "-Wvariadic-macros" |
||
42 |
# pragma GCC diagnostic ignored "-Wunused-variable" |
||
43 |
# pragma GCC diagnostic push |
||
44 |
# pragma GCC diagnostic ignored "-Wpadded" |
||
45 |
#endif |
||
46 |
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) |
||
47 |
# define CATCH_IMPL |
||
48 |
#endif |
||
49 |
|||
50 |
#ifdef CATCH_IMPL |
||
51 |
# ifndef CLARA_CONFIG_MAIN |
||
52 |
# define CLARA_CONFIG_MAIN_NOT_DEFINED |
||
53 |
# define CLARA_CONFIG_MAIN |
||
54 |
# endif |
||
55 |
#endif |
||
56 |
|||
57 |
// #included from: internal/catch_notimplemented_exception.h |
||
58 |
#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED |
||
59 |
|||
60 |
// #included from: catch_common.h |
||
61 |
#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED |
||
62 |
|||
63 |
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line |
||
64 |
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) |
||
65 |
#ifdef CATCH_CONFIG_COUNTER |
||
66 |
# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) |
||
67 |
#else |
||
68 |
# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) |
||
69 |
#endif |
||
70 |
|||
71 |
#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr |
||
72 |
#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) |
||
73 |
|||
74 |
#include <sstream> |
||
75 |
#include <stdexcept> |
||
76 |
#include <algorithm> |
||
77 |
|||
78 |
// stack |
||
79 |
#ifdef HAVE_EXECINFO |
||
80 |
#include <execinfo.h> |
||
81 |
#endif // HAVE_EXECINFO |
||
82 |
// stack |
||
83 |
|||
84 |
// #included from: catch_compiler_capabilities.h |
||
85 |
#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED |
||
86 |
|||
87 |
// Detect a number of compiler features - mostly C++11/14 conformance - by compiler |
||
88 |
// The following features are defined: |
||
89 |
// |
||
90 |
// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? |
||
91 |
// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? |
||
92 |
// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods |
||
93 |
// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? |
||
94 |
// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported |
||
95 |
// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? |
||
96 |
// CATCH_CONFIG_CPP11_OVERRIDE : is override supported? |
||
97 |
// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) |
||
98 |
|||
99 |
// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? |
||
100 |
|||
101 |
// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? |
||
102 |
// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? |
||
103 |
// **************** |
||
104 |
// Note to maintainers: if new toggles are added please document them |
||
105 |
// in configuration.md, too |
||
106 |
// **************** |
||
107 |
|||
108 |
// In general each macro has a _NO_<feature name> form |
||
109 |
// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. |
||
110 |
// Many features, at point of detection, define an _INTERNAL_ macro, so they |
||
111 |
// can be combined, en-mass, with the _NO_ forms later. |
||
112 |
|||
113 |
// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 |
||
114 |
|||
115 |
#if defined(__cplusplus) && __cplusplus >= 201103L |
||
116 |
# define CATCH_CPP11_OR_GREATER |
||
117 |
#endif |
||
118 |
|||
119 |
#ifdef __clang__ |
||
120 |
|||
121 |
# if __has_feature(cxx_nullptr) |
||
122 |
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
||
123 |
# endif |
||
124 |
|||
125 |
# if __has_feature(cxx_noexcept) |
||
126 |
# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
||
127 |
# endif |
||
128 |
|||
129 |
# if defined(CATCH_CPP11_OR_GREATER) |
||
130 |
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) |
||
131 |
# endif |
||
132 |
|||
133 |
#endif // __clang__ |
||
134 |
|||
135 |
//////////////////////////////////////////////////////////////////////////////// |
||
136 |
// Borland |
||
137 |
#ifdef __BORLANDC__ |
||
138 |
|||
139 |
#endif // __BORLANDC__ |
||
140 |
|||
141 |
//////////////////////////////////////////////////////////////////////////////// |
||
142 |
// EDG |
||
143 |
#ifdef __EDG_VERSION__ |
||
144 |
|||
145 |
#endif // __EDG_VERSION__ |
||
146 |
|||
147 |
//////////////////////////////////////////////////////////////////////////////// |
||
148 |
// Digital Mars |
||
149 |
#ifdef __DMC__ |
||
150 |
|||
151 |
#endif // __DMC__ |
||
152 |
|||
153 |
//////////////////////////////////////////////////////////////////////////////// |
||
154 |
// GCC |
||
155 |
#ifdef __GNUC__ |
||
156 |
|||
157 |
# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) |
||
158 |
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
||
159 |
# endif |
||
160 |
|||
161 |
# if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) && defined(CATCH_CPP11_OR_GREATER) |
||
162 |
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" ) |
||
163 |
# endif |
||
164 |
|||
165 |
// - otherwise more recent versions define __cplusplus >= 201103L |
||
166 |
// and will get picked up below |
||
167 |
|||
168 |
#endif // __GNUC__ |
||
169 |
|||
170 |
//////////////////////////////////////////////////////////////////////////////// |
||
171 |
// Visual C++ |
||
172 |
#ifdef _MSC_VER |
||
173 |
|||
174 |
#if (_MSC_VER >= 1600) |
||
175 |
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
||
176 |
# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
||
177 |
#endif |
||
178 |
|||
179 |
#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) |
||
180 |
#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
||
181 |
#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
||
182 |
#endif |
||
183 |
|||
184 |
#endif // _MSC_VER |
||
185 |
|||
186 |
//////////////////////////////////////////////////////////////////////////////// |
||
187 |
|||
188 |
// Use variadic macros if the compiler supports them |
||
189 |
#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ |
||
190 |
( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ |
||
191 |
( defined __GNUC__ && __GNUC__ >= 3 ) || \ |
||
192 |
( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) |
||
193 |
|||
194 |
#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
||
195 |
|||
196 |
#endif |
||
197 |
|||
198 |
// Use __COUNTER__ if the compiler supports it |
||
199 |
#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \ |
||
200 |
( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \ |
||
201 |
( defined __clang__ && __clang_major__ >= 3 ) |
||
202 |
|||
203 |
#define CATCH_INTERNAL_CONFIG_COUNTER |
||
204 |
|||
205 |
#endif |
||
206 |
|||
207 |
//////////////////////////////////////////////////////////////////////////////// |
||
208 |
// C++ language feature support |
||
209 |
|||
210 |
// catch all support for C++11 |
||
211 |
#if defined(CATCH_CPP11_OR_GREATER) |
||
212 |
|||
213 |
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) |
||
214 |
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
||
215 |
# endif |
||
216 |
|||
217 |
# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
||
218 |
# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
||
219 |
# endif |
||
220 |
|||
221 |
# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
||
222 |
# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
||
223 |
# endif |
||
224 |
|||
225 |
# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM |
||
226 |
# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM |
||
227 |
# endif |
||
228 |
|||
229 |
# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE |
||
230 |
# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE |
||
231 |
# endif |
||
232 |
|||
233 |
# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
||
234 |
# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
||
235 |
# endif |
||
236 |
|||
237 |
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) |
||
238 |
# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG |
||
239 |
# endif |
||
240 |
|||
241 |
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) |
||
242 |
# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE |
||
243 |
# endif |
||
244 |
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) |
||
245 |
# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
||
246 |
# endif |
||
247 |
|||
248 |
#endif // __cplusplus >= 201103L |
||
249 |
|||
250 |
// Now set the actual defines based on the above + anything the user has configured |
||
251 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) |
||
252 |
# define CATCH_CONFIG_CPP11_NULLPTR |
||
253 |
#endif |
||
254 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) |
||
255 |
# define CATCH_CONFIG_CPP11_NOEXCEPT |
||
256 |
#endif |
||
257 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) |
||
258 |
# define CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
259 |
#endif |
||
260 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) |
||
261 |
# define CATCH_CONFIG_CPP11_IS_ENUM |
||
262 |
#endif |
||
263 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) |
||
264 |
# define CATCH_CONFIG_CPP11_TUPLE |
||
265 |
#endif |
||
266 |
#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) |
||
267 |
# define CATCH_CONFIG_VARIADIC_MACROS |
||
268 |
#endif |
||
269 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) |
||
270 |
# define CATCH_CONFIG_CPP11_LONG_LONG |
||
271 |
#endif |
||
272 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) |
||
273 |
# define CATCH_CONFIG_CPP11_OVERRIDE |
||
274 |
#endif |
||
275 |
#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) |
||
276 |
# define CATCH_CONFIG_CPP11_UNIQUE_PTR |
||
277 |
#endif |
||
278 |
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) |
||
279 |
# define CATCH_CONFIG_COUNTER |
||
280 |
#endif |
||
281 |
|||
282 |
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) |
||
283 |
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS |
||
284 |
#endif |
||
285 |
|||
286 |
// noexcept support: |
||
287 |
#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) |
||
288 |
# define CATCH_NOEXCEPT noexcept |
||
289 |
# define CATCH_NOEXCEPT_IS(x) noexcept(x) |
||
290 |
#else |
||
291 |
# define CATCH_NOEXCEPT throw() |
||
292 |
# define CATCH_NOEXCEPT_IS(x) |
||
293 |
#endif |
||
294 |
|||
295 |
// nullptr support |
||
296 |
#ifdef CATCH_CONFIG_CPP11_NULLPTR |
||
297 |
# define CATCH_NULL nullptr |
||
298 |
#else |
||
299 |
# define CATCH_NULL NULL |
||
300 |
#endif |
||
301 |
|||
302 |
// override support |
||
303 |
#ifdef CATCH_CONFIG_CPP11_OVERRIDE |
||
304 |
# define CATCH_OVERRIDE override |
||
305 |
#else |
||
306 |
# define CATCH_OVERRIDE |
||
307 |
#endif |
||
308 |
|||
309 |
// unique_ptr support |
||
310 |
#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR |
||
311 |
# define CATCH_AUTO_PTR( T ) std::unique_ptr<T> |
||
312 |
#else |
||
313 |
# define CATCH_AUTO_PTR( T ) std::auto_ptr<T> |
||
314 |
#endif |
||
315 |
|||
316 |
namespace Catch { |
||
317 |
|||
318 |
struct IConfig; |
||
319 |
|||
320 |
struct CaseSensitive { enum Choice { |
||
321 |
Yes, |
||
322 |
No |
||
323 |
}; }; |
||
324 |
|||
325 |
class NonCopyable { |
||
326 |
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
327 |
NonCopyable( NonCopyable const& ) = delete; |
||
328 |
NonCopyable( NonCopyable && ) = delete; |
||
329 |
NonCopyable& operator = ( NonCopyable const& ) = delete; |
||
330 |
NonCopyable& operator = ( NonCopyable && ) = delete; |
||
331 |
#else |
||
332 |
NonCopyable( NonCopyable const& info ); |
||
333 |
NonCopyable& operator = ( NonCopyable const& ); |
||
334 |
#endif |
||
335 |
|||
336 |
protected: |
||
337 |
9892 |
NonCopyable() {} |
|
338 |
virtual ~NonCopyable(); |
||
339 |
}; |
||
340 |
|||
341 |
class SafeBool { |
||
342 |
public: |
||
343 |
typedef void (SafeBool::*type)() const; |
||
344 |
|||
345 |
static type makeSafe( bool value ) { |
||
346 |
✗✗✓✗ ✗✗✗✓ ✓✗ |
3 |
return value ? &SafeBool::trueValue : 0; |
347 |
} |
||
348 |
private: |
||
349 |
void trueValue() const {} |
||
350 |
}; |
||
351 |
|||
352 |
template<typename ContainerT> |
||
353 |
inline void deleteAll( ContainerT& container ) { |
||
354 |
2 |
typename ContainerT::const_iterator it = container.begin(); |
|
355 |
2 |
typename ContainerT::const_iterator itEnd = container.end(); |
|
356 |
✗✗✗✓ |
1 |
for(; it != itEnd; ++it ) |
357 |
delete *it; |
||
358 |
} |
||
359 |
template<typename AssociativeContainerT> |
||
360 |
inline void deleteAllValues( AssociativeContainerT& container ) { |
||
361 |
typename AssociativeContainerT::const_iterator it = container.begin(); |
||
362 |
typename AssociativeContainerT::const_iterator itEnd = container.end(); |
||
363 |
for(; it != itEnd; ++it ) |
||
364 |
delete it->second; |
||
365 |
} |
||
366 |
|||
367 |
bool startsWith( std::string const& s, std::string const& prefix ); |
||
368 |
bool endsWith( std::string const& s, std::string const& suffix ); |
||
369 |
bool contains( std::string const& s, std::string const& infix ); |
||
370 |
void toLowerInPlace( std::string& s ); |
||
371 |
std::string toLower( std::string const& s ); |
||
372 |
std::string trim( std::string const& str ); |
||
373 |
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); |
||
374 |
|||
375 |
4 |
struct pluralise { |
|
376 |
pluralise( std::size_t count, std::string const& label ); |
||
377 |
|||
378 |
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); |
||
379 |
|||
380 |
std::size_t m_count; |
||
381 |
std::string m_label; |
||
382 |
}; |
||
383 |
|||
384 |
✗✗✗✗ |
18695644 |
struct SourceLineInfo { |
385 |
|||
386 |
SourceLineInfo(); |
||
387 |
SourceLineInfo( char const* _file, std::size_t _line ); |
||
388 |
SourceLineInfo( SourceLineInfo const& other ); |
||
389 |
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
390 |
2 |
SourceLineInfo( SourceLineInfo && ) = default; |
|
391 |
SourceLineInfo& operator = ( SourceLineInfo const& ) = default; |
||
392 |
SourceLineInfo& operator = ( SourceLineInfo && ) = default; |
||
393 |
# endif |
||
394 |
bool empty() const; |
||
395 |
bool operator == ( SourceLineInfo const& other ) const; |
||
396 |
bool operator < ( SourceLineInfo const& other ) const; |
||
397 |
|||
398 |
std::string file; |
||
399 |
std::size_t line; |
||
400 |
}; |
||
401 |
|||
402 |
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); |
||
403 |
|||
404 |
// This is just here to avoid compiler warnings with macro constants and boolean literals |
||
405 |
inline bool isTrue( bool value ){ return value; } |
||
406 |
inline bool alwaysTrue() { return true; } |
||
407 |
inline bool alwaysFalse() { return false; } |
||
408 |
|||
409 |
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); |
||
410 |
|||
411 |
void seedRng( IConfig const& config ); |
||
412 |
unsigned int rngSeed(); |
||
413 |
|||
414 |
// Use this in variadic streaming macros to allow |
||
415 |
// >> +StreamEndStop |
||
416 |
// as well as |
||
417 |
// >> stuff +StreamEndStop |
||
418 |
struct StreamEndStop { |
||
419 |
std::string operator+() { |
||
420 |
return std::string(); |
||
421 |
} |
||
422 |
}; |
||
423 |
template<typename T> |
||
424 |
T const& operator + ( T const& value, StreamEndStop ) { |
||
425 |
return value; |
||
426 |
} |
||
427 |
} |
||
428 |
|||
429 |
#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) |
||
430 |
#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); |
||
431 |
|||
432 |
#include <ostream> |
||
433 |
|||
434 |
namespace Catch { |
||
435 |
|||
436 |
class NotImplementedException : public std::exception |
||
437 |
{ |
||
438 |
public: |
||
439 |
NotImplementedException( SourceLineInfo const& lineInfo ); |
||
440 |
NotImplementedException( NotImplementedException const& ) {} |
||
441 |
|||
442 |
virtual ~NotImplementedException() CATCH_NOEXCEPT {} |
||
443 |
|||
444 |
virtual const char* what() const CATCH_NOEXCEPT; |
||
445 |
|||
446 |
private: |
||
447 |
std::string m_what; |
||
448 |
SourceLineInfo m_lineInfo; |
||
449 |
}; |
||
450 |
|||
451 |
} // end namespace Catch |
||
452 |
|||
453 |
/////////////////////////////////////////////////////////////////////////////// |
||
454 |
#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) |
||
455 |
|||
456 |
// #included from: internal/catch_context.h |
||
457 |
#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED |
||
458 |
|||
459 |
// #included from: catch_interfaces_generators.h |
||
460 |
#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED |
||
461 |
|||
462 |
#include <string> |
||
463 |
|||
464 |
namespace Catch { |
||
465 |
|||
466 |
struct IGeneratorInfo { |
||
467 |
virtual ~IGeneratorInfo(); |
||
468 |
virtual bool moveNext() = 0; |
||
469 |
virtual std::size_t getCurrentIndex() const = 0; |
||
470 |
}; |
||
471 |
|||
472 |
struct IGeneratorsForTest { |
||
473 |
virtual ~IGeneratorsForTest(); |
||
474 |
|||
475 |
virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; |
||
476 |
virtual bool moveNext() = 0; |
||
477 |
}; |
||
478 |
|||
479 |
IGeneratorsForTest* createGeneratorsForTest(); |
||
480 |
|||
481 |
} // end namespace Catch |
||
482 |
|||
483 |
// #included from: catch_ptr.hpp |
||
484 |
#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED |
||
485 |
|||
486 |
#ifdef __clang__ |
||
487 |
#pragma clang diagnostic push |
||
488 |
#pragma clang diagnostic ignored "-Wpadded" |
||
489 |
#endif |
||
490 |
|||
491 |
namespace Catch { |
||
492 |
|||
493 |
// An intrusive reference counting smart pointer. |
||
494 |
// T must implement addRef() and release() methods |
||
495 |
// typically implementing the IShared interface |
||
496 |
template<typename T> |
||
497 |
class Ptr { |
||
498 |
public: |
||
499 |
4 |
Ptr() : m_p( CATCH_NULL ){} |
|
500 |
1593 |
Ptr( T* p ) : m_p( p ){ |
|
501 |
✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗✓✗ ✗✗✓✗ ✓✗✓✗ ✓✗ |
1592 |
if( m_p ) |
502 |
✓✗✓✗ ✗✗✓✗ ✗✗ |
1592 |
m_p->addRef(); |
503 |
} |
||
504 |
167128 |
Ptr( Ptr const& other ) : m_p( other.m_p ){ |
|
505 |
✗✗✓✗ ✗✗✓✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✓✗✗✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✗✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✓✗✓✗ ✓✗ |
167128 |
if( m_p ) |
506 |
✗✗✓✗ ✗✗✓✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✓✗✗✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗✗✗ ✓✗✓✗ ✓✗✗✗ ✓✗✓✗ ✓✗ |
167128 |
m_p->addRef(); |
507 |
} |
||
508 |
~Ptr(){ |
||
509 |
✗✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✗✗✗✗ ✓✗✗✗ ✓✗✗✗ ✓✗✗✗ ✓✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✓✗✗ ✓✓✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✗✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✗✗✗✗ ✗✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✗✗✓✗ ✓✗✗✗ ✓✗✗✓ ✓✗✗✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✗✗✗✗ ✗✗✓✗ ✗✗✗✗ ✓✗✓✗ ✓✗✗✗ ✗✗✗✗ ✓✓✓✗ ✗✗ |
168725 |
if( m_p ) |
510 |
168720 |
m_p->release(); |
|
511 |
3834 |
} |
|
512 |
void reset() { |
||
513 |
✗✗✗✓ |
1 |
if( m_p ) |
514 |
m_p->release(); |
||
515 |
1 |
m_p = CATCH_NULL; |
|
516 |
} |
||
517 |
Ptr& operator = ( T* p ){ |
||
518 |
790 |
Ptr temp( p ); |
|
519 |
396 |
swap( temp ); |
|
520 |
396 |
return *this; |
|
521 |
} |
||
522 |
4 |
Ptr& operator = ( Ptr const& other ){ |
|
523 |
8 |
Ptr temp( other ); |
|
524 |
4 |
swap( temp ); |
|
525 |
8 |
return *this; |
|
526 |
} |
||
527 |
800 |
void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } |
|
528 |
8968 |
T* get() const{ return m_p; } |
|
529 |
1537 |
T& operator*() const { return *m_p; } |
|
530 |
3230883 |
T* operator->() const { return m_p; } |
|
531 |
3 |
bool operator !() const { return m_p == CATCH_NULL; } |
|
532 |
4 |
operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); } |
|
533 |
|||
534 |
private: |
||
535 |
T* m_p; |
||
536 |
}; |
||
537 |
|||
538 |
3242 |
struct IShared : NonCopyable { |
|
539 |
virtual ~IShared(); |
||
540 |
virtual void addRef() const = 0; |
||
541 |
virtual void release() const = 0; |
||
542 |
}; |
||
543 |
|||
544 |
template<typename T = IShared> |
||
545 |
3242 |
struct SharedImpl : T { |
|
546 |
|||
547 |
3242 |
SharedImpl() : m_rc( 0 ){} |
|
548 |
|||
549 |
168720 |
virtual void addRef() const { |
|
550 |
168720 |
++m_rc; |
|
551 |
168720 |
} |
|
552 |
168720 |
virtual void release() const { |
|
553 |
✓✓✓✓ ✓✓✓✓ ✓✓ |
168720 |
if( --m_rc == 0 ) |
554 |
1590 |
delete this; |
|
555 |
168720 |
} |
|
556 |
|||
557 |
mutable unsigned int m_rc; |
||
558 |
}; |
||
559 |
|||
560 |
} // end namespace Catch |
||
561 |
|||
562 |
#ifdef __clang__ |
||
563 |
#pragma clang diagnostic pop |
||
564 |
#endif |
||
565 |
|||
566 |
#include <memory> |
||
567 |
#include <vector> |
||
568 |
#include <stdlib.h> |
||
569 |
|||
570 |
namespace Catch { |
||
571 |
|||
572 |
class TestCase; |
||
573 |
class Stream; |
||
574 |
struct IResultCapture; |
||
575 |
struct IRunner; |
||
576 |
struct IGeneratorsForTest; |
||
577 |
struct IConfig; |
||
578 |
|||
579 |
struct IContext |
||
580 |
{ |
||
581 |
virtual ~IContext(); |
||
582 |
|||
583 |
virtual IResultCapture* getResultCapture() = 0; |
||
584 |
virtual IRunner* getRunner() = 0; |
||
585 |
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; |
||
586 |
virtual bool advanceGeneratorsForCurrentTest() = 0; |
||
587 |
virtual Ptr<IConfig const> getConfig() const = 0; |
||
588 |
}; |
||
589 |
|||
590 |
1 |
struct IMutableContext : IContext |
|
591 |
{ |
||
592 |
virtual ~IMutableContext(); |
||
593 |
virtual void setResultCapture( IResultCapture* resultCapture ) = 0; |
||
594 |
virtual void setRunner( IRunner* runner ) = 0; |
||
595 |
virtual void setConfig( Ptr<IConfig const> const& config ) = 0; |
||
596 |
}; |
||
597 |
|||
598 |
IContext& getCurrentContext(); |
||
599 |
IMutableContext& getCurrentMutableContext(); |
||
600 |
void cleanUpContext(); |
||
601 |
Stream createStream( std::string const& streamName ); |
||
602 |
|||
603 |
} |
||
604 |
|||
605 |
// #included from: internal/catch_test_registry.hpp |
||
606 |
#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED |
||
607 |
|||
608 |
// #included from: catch_interfaces_testcase.h |
||
609 |
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED |
||
610 |
|||
611 |
#include <vector> |
||
612 |
|||
613 |
namespace Catch { |
||
614 |
|||
615 |
class TestSpec; |
||
616 |
|||
617 |
788 |
struct ITestCase : IShared { |
|
618 |
virtual void invoke () const = 0; |
||
619 |
protected: |
||
620 |
virtual ~ITestCase(); |
||
621 |
}; |
||
622 |
|||
623 |
class TestCase; |
||
624 |
struct IConfig; |
||
625 |
|||
626 |
struct ITestCaseRegistry { |
||
627 |
virtual ~ITestCaseRegistry(); |
||
628 |
virtual std::vector<TestCase> const& getAllTests() const = 0; |
||
629 |
virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0; |
||
630 |
}; |
||
631 |
|||
632 |
bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); |
||
633 |
std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ); |
||
634 |
std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ); |
||
635 |
|||
636 |
} |
||
637 |
|||
638 |
namespace Catch { |
||
639 |
|||
640 |
template<typename C> |
||
641 |
class MethodTestCase : public SharedImpl<ITestCase> { |
||
642 |
|||
643 |
public: |
||
644 |
MethodTestCase( void (C::*method)() ) : m_method( method ) {} |
||
645 |
|||
646 |
virtual void invoke() const { |
||
647 |
C obj; |
||
648 |
(obj.*m_method)(); |
||
649 |
} |
||
650 |
|||
651 |
private: |
||
652 |
virtual ~MethodTestCase() {} |
||
653 |
|||
654 |
void (C::*m_method)(); |
||
655 |
}; |
||
656 |
|||
657 |
typedef void(*TestFunction)(); |
||
658 |
|||
659 |
struct NameAndDesc { |
||
660 |
NameAndDesc( const char* _name = "", const char* _description= "" ) |
||
661 |
394 |
: name( _name ), description( _description ) |
|
662 |
{} |
||
663 |
|||
664 |
const char* name; |
||
665 |
const char* description; |
||
666 |
}; |
||
667 |
|||
668 |
void registerTestCase |
||
669 |
( ITestCase* testCase, |
||
670 |
char const* className, |
||
671 |
NameAndDesc const& nameAndDesc, |
||
672 |
SourceLineInfo const& lineInfo ); |
||
673 |
|||
674 |
struct AutoReg { |
||
675 |
|||
676 |
AutoReg |
||
677 |
( TestFunction function, |
||
678 |
SourceLineInfo const& lineInfo, |
||
679 |
NameAndDesc const& nameAndDesc ); |
||
680 |
|||
681 |
template<typename C> |
||
682 |
AutoReg |
||
683 |
( void (C::*method)(), |
||
684 |
char const* className, |
||
685 |
NameAndDesc const& nameAndDesc, |
||
686 |
SourceLineInfo const& lineInfo ) { |
||
687 |
|||
688 |
registerTestCase |
||
689 |
( new MethodTestCase<C>( method ), |
||
690 |
className, |
||
691 |
nameAndDesc, |
||
692 |
lineInfo ); |
||
693 |
} |
||
694 |
|||
695 |
~AutoReg(); |
||
696 |
|||
697 |
private: |
||
698 |
AutoReg( AutoReg const& ); |
||
699 |
void operator= ( AutoReg const& ); |
||
700 |
}; |
||
701 |
|||
702 |
void registerTestCaseFunction |
||
703 |
( TestFunction function, |
||
704 |
SourceLineInfo const& lineInfo, |
||
705 |
NameAndDesc const& nameAndDesc ); |
||
706 |
|||
707 |
} // end namespace Catch |
||
708 |
|||
709 |
#ifdef CATCH_CONFIG_VARIADIC_MACROS |
||
710 |
/////////////////////////////////////////////////////////////////////////////// |
||
711 |
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ |
||
712 |
static void TestName(); \ |
||
713 |
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\ |
||
714 |
static void TestName() |
||
715 |
#define INTERNAL_CATCH_TESTCASE( ... ) \ |
||
716 |
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) |
||
717 |
|||
718 |
/////////////////////////////////////////////////////////////////////////////// |
||
719 |
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ |
||
720 |
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } |
||
721 |
|||
722 |
/////////////////////////////////////////////////////////////////////////////// |
||
723 |
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ |
||
724 |
namespace{ \ |
||
725 |
struct TestName : ClassName{ \ |
||
726 |
void test(); \ |
||
727 |
}; \ |
||
728 |
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \ |
||
729 |
} \ |
||
730 |
void TestName::test() |
||
731 |
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ |
||
732 |
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) |
||
733 |
|||
734 |
/////////////////////////////////////////////////////////////////////////////// |
||
735 |
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ |
||
736 |
Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); |
||
737 |
|||
738 |
#else |
||
739 |
/////////////////////////////////////////////////////////////////////////////// |
||
740 |
#define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \ |
||
741 |
static void TestName(); \ |
||
742 |
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\ |
||
743 |
static void TestName() |
||
744 |
#define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ |
||
745 |
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc ) |
||
746 |
|||
747 |
/////////////////////////////////////////////////////////////////////////////// |
||
748 |
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ |
||
749 |
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } |
||
750 |
|||
751 |
/////////////////////////////////////////////////////////////////////////////// |
||
752 |
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\ |
||
753 |
namespace{ \ |
||
754 |
struct TestCaseName : ClassName{ \ |
||
755 |
void test(); \ |
||
756 |
}; \ |
||
757 |
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \ |
||
758 |
} \ |
||
759 |
void TestCaseName::test() |
||
760 |
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ |
||
761 |
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc ) |
||
762 |
|||
763 |
/////////////////////////////////////////////////////////////////////////////// |
||
764 |
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \ |
||
765 |
Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); |
||
766 |
#endif |
||
767 |
|||
768 |
// #included from: internal/catch_capture.hpp |
||
769 |
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED |
||
770 |
|||
771 |
// #included from: catch_result_builder.h |
||
772 |
#define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED |
||
773 |
|||
774 |
// #included from: catch_result_type.h |
||
775 |
#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED |
||
776 |
|||
777 |
namespace Catch { |
||
778 |
|||
779 |
// ResultWas::OfType enum |
||
780 |
struct ResultWas { enum OfType { |
||
781 |
Unknown = -1, |
||
782 |
Ok = 0, |
||
783 |
Info = 1, |
||
784 |
Warning = 2, |
||
785 |
|||
786 |
FailureBit = 0x10, |
||
787 |
|||
788 |
ExpressionFailed = FailureBit | 1, |
||
789 |
ExplicitFailure = FailureBit | 2, |
||
790 |
|||
791 |
Exception = 0x100 | FailureBit, |
||
792 |
|||
793 |
ThrewException = Exception | 1, |
||
794 |
DidntThrowException = Exception | 2, |
||
795 |
|||
796 |
FatalErrorCondition = 0x200 | FailureBit |
||
797 |
|||
798 |
}; }; |
||
799 |
|||
800 |
inline bool isOk( ResultWas::OfType resultType ) { |
||
801 |
2865846 |
return ( resultType & ResultWas::FailureBit ) == 0; |
|
802 |
} |
||
803 |
inline bool isJustInfo( int flags ) { |
||
804 |
return flags == ResultWas::Info; |
||
805 |
} |
||
806 |
|||
807 |
// ResultDisposition::Flags enum |
||
808 |
struct ResultDisposition { enum Flags { |
||
809 |
Normal = 0x01, |
||
810 |
|||
811 |
ContinueOnFailure = 0x02, // Failures fail test, but execution continues |
||
812 |
FalseTest = 0x04, // Prefix expression with ! |
||
813 |
SuppressFail = 0x08 // Failures are reported but do not fail the test |
||
814 |
}; }; |
||
815 |
|||
816 |
inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { |
||
817 |
return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) ); |
||
818 |
} |
||
819 |
|||
820 |
inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } |
||
821 |
1432892 |
inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } |
|
822 |
inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } |
||
823 |
|||
824 |
} // end namespace Catch |
||
825 |
|||
826 |
// #included from: catch_assertionresult.h |
||
827 |
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED |
||
828 |
|||
829 |
#include <string> |
||
830 |
|||
831 |
namespace Catch { |
||
832 |
|||
833 |
42992168 |
struct AssertionInfo |
|
834 |
{ |
||
835 |
8 |
AssertionInfo() {} |
|
836 |
AssertionInfo( std::string const& _macroName, |
||
837 |
SourceLineInfo const& _lineInfo, |
||
838 |
std::string const& _capturedExpression, |
||
839 |
ResultDisposition::Flags _resultDisposition ); |
||
840 |
|||
841 |
std::string macroName; |
||
842 |
SourceLineInfo lineInfo; |
||
843 |
std::string capturedExpression; |
||
844 |
ResultDisposition::Flags resultDisposition; |
||
845 |
}; |
||
846 |
|||
847 |
34390155 |
struct AssertionResultData |
|
848 |
{ |
||
849 |
4298772 |
AssertionResultData() : resultType( ResultWas::Unknown ) {} |
|
850 |
|||
851 |
std::string reconstructedExpression; |
||
852 |
std::string message; |
||
853 |
ResultWas::OfType resultType; |
||
854 |
}; |
||
855 |
|||
856 |
2865846 |
class AssertionResult { |
|
857 |
public: |
||
858 |
AssertionResult(); |
||
859 |
AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); |
||
860 |
~AssertionResult(); |
||
861 |
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
862 |
✓✗ | 1432923 |
AssertionResult( AssertionResult const& ) = default; |
863 |
AssertionResult( AssertionResult && ) = default; |
||
864 |
AssertionResult& operator = ( AssertionResult const& ) = default; |
||
865 |
AssertionResult& operator = ( AssertionResult && ) = default; |
||
866 |
# endif |
||
867 |
|||
868 |
bool isOk() const; |
||
869 |
bool succeeded() const; |
||
870 |
ResultWas::OfType getResultType() const; |
||
871 |
bool hasExpression() const; |
||
872 |
bool hasMessage() const; |
||
873 |
std::string getExpression() const; |
||
874 |
std::string getExpressionInMacro() const; |
||
875 |
bool hasExpandedExpression() const; |
||
876 |
std::string getExpandedExpression() const; |
||
877 |
std::string getMessage() const; |
||
878 |
SourceLineInfo getSourceInfo() const; |
||
879 |
std::string getTestMacroName() const; |
||
880 |
|||
881 |
protected: |
||
882 |
AssertionInfo m_info; |
||
883 |
AssertionResultData m_resultData; |
||
884 |
}; |
||
885 |
|||
886 |
} // end namespace Catch |
||
887 |
|||
888 |
// #included from: catch_matchers.hpp |
||
889 |
#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED |
||
890 |
|||
891 |
namespace Catch { |
||
892 |
namespace Matchers { |
||
893 |
namespace Impl { |
||
894 |
|||
895 |
namespace Generic { |
||
896 |
template<typename ExpressionT> class AllOf; |
||
897 |
template<typename ExpressionT> class AnyOf; |
||
898 |
template<typename ExpressionT> class Not; |
||
899 |
} |
||
900 |
|||
901 |
template<typename ExpressionT> |
||
902 |
62 |
struct Matcher : SharedImpl<IShared> |
|
903 |
{ |
||
904 |
typedef ExpressionT ExpressionType; |
||
905 |
|||
906 |
62 |
virtual ~Matcher() {} |
|
907 |
virtual Ptr<Matcher> clone() const = 0; |
||
908 |
virtual bool match( ExpressionT const& expr ) const = 0; |
||
909 |
virtual std::string toString() const = 0; |
||
910 |
|||
911 |
Generic::AllOf<ExpressionT> operator && ( Matcher<ExpressionT> const& other ) const; |
||
912 |
Generic::AnyOf<ExpressionT> operator || ( Matcher<ExpressionT> const& other ) const; |
||
913 |
Generic::Not<ExpressionT> operator ! () const; |
||
914 |
}; |
||
915 |
|||
916 |
template<typename DerivedT, typename ExpressionT> |
||
917 |
124 |
struct MatcherImpl : Matcher<ExpressionT> { |
|
918 |
|||
919 |
virtual Ptr<Matcher<ExpressionT> > clone() const { |
||
920 |
return Ptr<Matcher<ExpressionT> >( new DerivedT( static_cast<DerivedT const&>( *this ) ) ); |
||
921 |
} |
||
922 |
}; |
||
923 |
|||
924 |
namespace Generic { |
||
925 |
template<typename ExpressionT> |
||
926 |
class Not : public MatcherImpl<Not<ExpressionT>, ExpressionT> { |
||
927 |
public: |
||
928 |
explicit Not( Matcher<ExpressionT> const& matcher ) : m_matcher(matcher.clone()) {} |
||
929 |
Not( Not const& other ) : m_matcher( other.m_matcher ) {} |
||
930 |
|||
931 |
virtual bool match( ExpressionT const& expr ) const CATCH_OVERRIDE { |
||
932 |
return !m_matcher->match( expr ); |
||
933 |
} |
||
934 |
|||
935 |
virtual std::string toString() const CATCH_OVERRIDE { |
||
936 |
return "not " + m_matcher->toString(); |
||
937 |
} |
||
938 |
private: |
||
939 |
Ptr< Matcher<ExpressionT> > m_matcher; |
||
940 |
}; |
||
941 |
|||
942 |
template<typename ExpressionT> |
||
943 |
62 |
class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> { |
|
944 |
public: |
||
945 |
|||
946 |
93 |
AllOf() {} |
|
947 |
AllOf( AllOf const& other ) : m_matchers( other.m_matchers ) {} |
||
948 |
|||
949 |
AllOf& add( Matcher<ExpressionT> const& matcher ) { |
||
950 |
m_matchers.push_back( matcher.clone() ); |
||
951 |
return *this; |
||
952 |
} |
||
953 |
31 |
virtual bool match( ExpressionT const& expr ) const |
|
954 |
{ |
||
955 |
✗✓ | 62 |
for( std::size_t i = 0; i < m_matchers.size(); ++i ) |
956 |
if( !m_matchers[i]->match( expr ) ) |
||
957 |
return false; |
||
958 |
return true; |
||
959 |
} |
||
960 |
virtual std::string toString() const { |
||
961 |
std::ostringstream oss; |
||
962 |
oss << "( "; |
||
963 |
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { |
||
964 |
if( i != 0 ) |
||
965 |
oss << " and "; |
||
966 |
oss << m_matchers[i]->toString(); |
||
967 |
} |
||
968 |
oss << " )"; |
||
969 |
return oss.str(); |
||
970 |
} |
||
971 |
|||
972 |
AllOf operator && ( Matcher<ExpressionT> const& other ) const { |
||
973 |
AllOf allOfExpr( *this ); |
||
974 |
allOfExpr.add( other ); |
||
975 |
return allOfExpr; |
||
976 |
} |
||
977 |
|||
978 |
private: |
||
979 |
std::vector<Ptr<Matcher<ExpressionT> > > m_matchers; |
||
980 |
}; |
||
981 |
|||
982 |
template<typename ExpressionT> |
||
983 |
class AnyOf : public MatcherImpl<AnyOf<ExpressionT>, ExpressionT> { |
||
984 |
public: |
||
985 |
|||
986 |
AnyOf() {} |
||
987 |
AnyOf( AnyOf const& other ) : m_matchers( other.m_matchers ) {} |
||
988 |
|||
989 |
AnyOf& add( Matcher<ExpressionT> const& matcher ) { |
||
990 |
m_matchers.push_back( matcher.clone() ); |
||
991 |
return *this; |
||
992 |
} |
||
993 |
virtual bool match( ExpressionT const& expr ) const |
||
994 |
{ |
||
995 |
for( std::size_t i = 0; i < m_matchers.size(); ++i ) |
||
996 |
if( m_matchers[i]->match( expr ) ) |
||
997 |
return true; |
||
998 |
return false; |
||
999 |
} |
||
1000 |
virtual std::string toString() const { |
||
1001 |
std::ostringstream oss; |
||
1002 |
oss << "( "; |
||
1003 |
for( std::size_t i = 0; i < m_matchers.size(); ++i ) { |
||
1004 |
if( i != 0 ) |
||
1005 |
oss << " or "; |
||
1006 |
oss << m_matchers[i]->toString(); |
||
1007 |
} |
||
1008 |
oss << " )"; |
||
1009 |
return oss.str(); |
||
1010 |
} |
||
1011 |
|||
1012 |
AnyOf operator || ( Matcher<ExpressionT> const& other ) const { |
||
1013 |
AnyOf anyOfExpr( *this ); |
||
1014 |
anyOfExpr.add( other ); |
||
1015 |
return anyOfExpr; |
||
1016 |
} |
||
1017 |
|||
1018 |
private: |
||
1019 |
std::vector<Ptr<Matcher<ExpressionT> > > m_matchers; |
||
1020 |
}; |
||
1021 |
|||
1022 |
} // namespace Generic |
||
1023 |
|||
1024 |
template<typename ExpressionT> |
||
1025 |
Generic::AllOf<ExpressionT> Matcher<ExpressionT>::operator && ( Matcher<ExpressionT> const& other ) const { |
||
1026 |
Generic::AllOf<ExpressionT> allOfExpr; |
||
1027 |
allOfExpr.add( *this ); |
||
1028 |
allOfExpr.add( other ); |
||
1029 |
return allOfExpr; |
||
1030 |
} |
||
1031 |
|||
1032 |
template<typename ExpressionT> |
||
1033 |
Generic::AnyOf<ExpressionT> Matcher<ExpressionT>::operator || ( Matcher<ExpressionT> const& other ) const { |
||
1034 |
Generic::AnyOf<ExpressionT> anyOfExpr; |
||
1035 |
anyOfExpr.add( *this ); |
||
1036 |
anyOfExpr.add( other ); |
||
1037 |
return anyOfExpr; |
||
1038 |
} |
||
1039 |
|||
1040 |
template<typename ExpressionT> |
||
1041 |
Generic::Not<ExpressionT> Matcher<ExpressionT>::operator ! () const { |
||
1042 |
return Generic::Not<ExpressionT>( *this ); |
||
1043 |
} |
||
1044 |
|||
1045 |
namespace StdString { |
||
1046 |
|||
1047 |
inline std::string makeString( std::string const& str ) { return str; } |
||
1048 |
inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); } |
||
1049 |
|||
1050 |
struct CasedString |
||
1051 |
{ |
||
1052 |
CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) |
||
1053 |
: m_caseSensitivity( caseSensitivity ), |
||
1054 |
m_str( adjustString( str ) ) |
||
1055 |
{} |
||
1056 |
std::string adjustString( std::string const& str ) const { |
||
1057 |
return m_caseSensitivity == CaseSensitive::No |
||
1058 |
? toLower( str ) |
||
1059 |
: str; |
||
1060 |
|||
1061 |
} |
||
1062 |
std::string toStringSuffix() const |
||
1063 |
{ |
||
1064 |
return m_caseSensitivity == CaseSensitive::No |
||
1065 |
? " (case insensitive)" |
||
1066 |
: ""; |
||
1067 |
} |
||
1068 |
CaseSensitive::Choice m_caseSensitivity; |
||
1069 |
std::string m_str; |
||
1070 |
}; |
||
1071 |
|||
1072 |
struct Equals : MatcherImpl<Equals, std::string> { |
||
1073 |
Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
||
1074 |
: m_data( str, caseSensitivity ) |
||
1075 |
{} |
||
1076 |
Equals( Equals const& other ) : m_data( other.m_data ){} |
||
1077 |
|||
1078 |
virtual ~Equals(); |
||
1079 |
|||
1080 |
virtual bool match( std::string const& expr ) const { |
||
1081 |
return m_data.m_str == m_data.adjustString( expr );; |
||
1082 |
} |
||
1083 |
virtual std::string toString() const { |
||
1084 |
return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
||
1085 |
} |
||
1086 |
|||
1087 |
CasedString m_data; |
||
1088 |
}; |
||
1089 |
|||
1090 |
struct Contains : MatcherImpl<Contains, std::string> { |
||
1091 |
Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
||
1092 |
: m_data( substr, caseSensitivity ){} |
||
1093 |
Contains( Contains const& other ) : m_data( other.m_data ){} |
||
1094 |
|||
1095 |
virtual ~Contains(); |
||
1096 |
|||
1097 |
virtual bool match( std::string const& expr ) const { |
||
1098 |
return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos; |
||
1099 |
} |
||
1100 |
virtual std::string toString() const { |
||
1101 |
return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
||
1102 |
} |
||
1103 |
|||
1104 |
CasedString m_data; |
||
1105 |
}; |
||
1106 |
|||
1107 |
struct StartsWith : MatcherImpl<StartsWith, std::string> { |
||
1108 |
StartsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
||
1109 |
: m_data( substr, caseSensitivity ){} |
||
1110 |
|||
1111 |
StartsWith( StartsWith const& other ) : m_data( other.m_data ){} |
||
1112 |
|||
1113 |
virtual ~StartsWith(); |
||
1114 |
|||
1115 |
virtual bool match( std::string const& expr ) const { |
||
1116 |
return startsWith( m_data.adjustString( expr ), m_data.m_str ); |
||
1117 |
} |
||
1118 |
virtual std::string toString() const { |
||
1119 |
return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
||
1120 |
} |
||
1121 |
|||
1122 |
CasedString m_data; |
||
1123 |
}; |
||
1124 |
|||
1125 |
struct EndsWith : MatcherImpl<EndsWith, std::string> { |
||
1126 |
EndsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
||
1127 |
: m_data( substr, caseSensitivity ){} |
||
1128 |
EndsWith( EndsWith const& other ) : m_data( other.m_data ){} |
||
1129 |
|||
1130 |
virtual ~EndsWith(); |
||
1131 |
|||
1132 |
virtual bool match( std::string const& expr ) const { |
||
1133 |
return endsWith( m_data.adjustString( expr ), m_data.m_str ); |
||
1134 |
} |
||
1135 |
virtual std::string toString() const { |
||
1136 |
return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
||
1137 |
} |
||
1138 |
|||
1139 |
CasedString m_data; |
||
1140 |
}; |
||
1141 |
} // namespace StdString |
||
1142 |
} // namespace Impl |
||
1143 |
|||
1144 |
// The following functions create the actual matcher objects. |
||
1145 |
// This allows the types to be inferred |
||
1146 |
template<typename ExpressionT> |
||
1147 |
inline Impl::Generic::Not<ExpressionT> Not( Impl::Matcher<ExpressionT> const& m ) { |
||
1148 |
return Impl::Generic::Not<ExpressionT>( m ); |
||
1149 |
} |
||
1150 |
|||
1151 |
template<typename ExpressionT> |
||
1152 |
inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1, |
||
1153 |
Impl::Matcher<ExpressionT> const& m2 ) { |
||
1154 |
return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ); |
||
1155 |
} |
||
1156 |
template<typename ExpressionT> |
||
1157 |
inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1, |
||
1158 |
Impl::Matcher<ExpressionT> const& m2, |
||
1159 |
Impl::Matcher<ExpressionT> const& m3 ) { |
||
1160 |
return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 ); |
||
1161 |
} |
||
1162 |
template<typename ExpressionT> |
||
1163 |
inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1, |
||
1164 |
Impl::Matcher<ExpressionT> const& m2 ) { |
||
1165 |
return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ); |
||
1166 |
} |
||
1167 |
template<typename ExpressionT> |
||
1168 |
inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1, |
||
1169 |
Impl::Matcher<ExpressionT> const& m2, |
||
1170 |
Impl::Matcher<ExpressionT> const& m3 ) { |
||
1171 |
return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 ); |
||
1172 |
} |
||
1173 |
|||
1174 |
inline Impl::StdString::Equals Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
||
1175 |
return Impl::StdString::Equals( str, caseSensitivity ); |
||
1176 |
} |
||
1177 |
inline Impl::StdString::Equals Equals( const char* str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
||
1178 |
return Impl::StdString::Equals( Impl::StdString::makeString( str ), caseSensitivity ); |
||
1179 |
} |
||
1180 |
inline Impl::StdString::Contains Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
||
1181 |
return Impl::StdString::Contains( substr, caseSensitivity ); |
||
1182 |
} |
||
1183 |
inline Impl::StdString::Contains Contains( const char* substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
||
1184 |
return Impl::StdString::Contains( Impl::StdString::makeString( substr ), caseSensitivity ); |
||
1185 |
} |
||
1186 |
inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) { |
||
1187 |
return Impl::StdString::StartsWith( substr ); |
||
1188 |
} |
||
1189 |
inline Impl::StdString::StartsWith StartsWith( const char* substr ) { |
||
1190 |
return Impl::StdString::StartsWith( Impl::StdString::makeString( substr ) ); |
||
1191 |
} |
||
1192 |
inline Impl::StdString::EndsWith EndsWith( std::string const& substr ) { |
||
1193 |
return Impl::StdString::EndsWith( substr ); |
||
1194 |
} |
||
1195 |
inline Impl::StdString::EndsWith EndsWith( const char* substr ) { |
||
1196 |
return Impl::StdString::EndsWith( Impl::StdString::makeString( substr ) ); |
||
1197 |
} |
||
1198 |
|||
1199 |
} // namespace Matchers |
||
1200 |
|||
1201 |
using namespace Matchers; |
||
1202 |
|||
1203 |
} // namespace Catch |
||
1204 |
|||
1205 |
namespace Catch { |
||
1206 |
|||
1207 |
struct TestFailureException{}; |
||
1208 |
|||
1209 |
template<typename T> class ExpressionLhs; |
||
1210 |
|||
1211 |
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; |
||
1212 |
|||
1213 |
1432923 |
struct CopyableStream { |
|
1214 |
✓✗ | 1432923 |
CopyableStream() {} |
1215 |
CopyableStream( CopyableStream const& other ) { |
||
1216 |
oss << other.oss.str(); |
||
1217 |
} |
||
1218 |
CopyableStream& operator=( CopyableStream const& other ) { |
||
1219 |
oss.str(""); |
||
1220 |
oss << other.oss.str(); |
||
1221 |
return *this; |
||
1222 |
} |
||
1223 |
std::ostringstream oss; |
||
1224 |
}; |
||
1225 |
|||
1226 |
2865846 |
class ResultBuilder { |
|
1227 |
public: |
||
1228 |
ResultBuilder( char const* macroName, |
||
1229 |
SourceLineInfo const& lineInfo, |
||
1230 |
char const* capturedExpression, |
||
1231 |
ResultDisposition::Flags resultDisposition, |
||
1232 |
char const* secondArg = "" ); |
||
1233 |
|||
1234 |
template<typename T> |
||
1235 |
ExpressionLhs<T const&> operator <= ( T const& operand ); |
||
1236 |
ExpressionLhs<bool> operator <= ( bool value ); |
||
1237 |
|||
1238 |
template<typename T> |
||
1239 |
ResultBuilder& operator << ( T const& value ) { |
||
1240 |
m_stream.oss << value; |
||
1241 |
return *this; |
||
1242 |
} |
||
1243 |
|||
1244 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); |
||
1245 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); |
||
1246 |
|||
1247 |
ResultBuilder& setResultType( ResultWas::OfType result ); |
||
1248 |
ResultBuilder& setResultType( bool result ); |
||
1249 |
ResultBuilder& setLhs( std::string const& lhs ); |
||
1250 |
ResultBuilder& setRhs( std::string const& rhs ); |
||
1251 |
ResultBuilder& setOp( std::string const& op ); |
||
1252 |
|||
1253 |
void endExpression(); |
||
1254 |
|||
1255 |
std::string reconstructExpression() const; |
||
1256 |
AssertionResult build() const; |
||
1257 |
|||
1258 |
void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); |
||
1259 |
void captureResult( ResultWas::OfType resultType ); |
||
1260 |
void captureExpression(); |
||
1261 |
void captureExpectedException( std::string const& expectedMessage ); |
||
1262 |
void captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ); |
||
1263 |
void handleResult( AssertionResult const& result ); |
||
1264 |
void react(); |
||
1265 |
bool shouldDebugBreak() const; |
||
1266 |
bool allowThrows() const; |
||
1267 |
|||
1268 |
private: |
||
1269 |
AssertionInfo m_assertionInfo; |
||
1270 |
AssertionResultData m_data; |
||
1271 |
5731692 |
struct ExprComponents { |
|
1272 |
5731692 |
ExprComponents() : testFalse( false ) {} |
|
1273 |
bool testFalse; |
||
1274 |
std::string lhs, rhs, op; |
||
1275 |
} m_exprComponents; |
||
1276 |
CopyableStream m_stream; |
||
1277 |
|||
1278 |
bool m_shouldDebugBreak; |
||
1279 |
bool m_shouldThrow; |
||
1280 |
}; |
||
1281 |
|||
1282 |
} // namespace Catch |
||
1283 |
|||
1284 |
// Include after due to circular dependency: |
||
1285 |
// #included from: catch_expression_lhs.hpp |
||
1286 |
#define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED |
||
1287 |
|||
1288 |
// #included from: catch_evaluate.hpp |
||
1289 |
#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED |
||
1290 |
|||
1291 |
#ifdef _MSC_VER |
||
1292 |
#pragma warning(push) |
||
1293 |
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch |
||
1294 |
#endif |
||
1295 |
|||
1296 |
#include <cstddef> |
||
1297 |
|||
1298 |
namespace Catch { |
||
1299 |
namespace Internal { |
||
1300 |
|||
1301 |
enum Operator { |
||
1302 |
IsEqualTo, |
||
1303 |
IsNotEqualTo, |
||
1304 |
IsLessThan, |
||
1305 |
IsGreaterThan, |
||
1306 |
IsLessThanOrEqualTo, |
||
1307 |
IsGreaterThanOrEqualTo |
||
1308 |
}; |
||
1309 |
|||
1310 |
template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } }; |
||
1311 |
template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } }; |
||
1312 |
template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } }; |
||
1313 |
template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } }; |
||
1314 |
template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } }; |
||
1315 |
template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } }; |
||
1316 |
template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } }; |
||
1317 |
|||
1318 |
template<typename T> |
||
1319 |
inline T& opCast(T const& t) { return const_cast<T&>(t); } |
||
1320 |
|||
1321 |
// nullptr_t support based on pull request #154 from Konstantin Baumann |
||
1322 |
#ifdef CATCH_CONFIG_CPP11_NULLPTR |
||
1323 |
inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } |
||
1324 |
#endif // CATCH_CONFIG_CPP11_NULLPTR |
||
1325 |
|||
1326 |
// So the compare overloads can be operator agnostic we convey the operator as a template |
||
1327 |
// enum, which is used to specialise an Evaluator for doing the comparison. |
||
1328 |
template<typename T1, typename T2, Operator Op> |
||
1329 |
class Evaluator{}; |
||
1330 |
|||
1331 |
template<typename T1, typename T2> |
||
1332 |
struct Evaluator<T1, T2, IsEqualTo> { |
||
1333 |
static bool evaluate( T1 const& lhs, T2 const& rhs) { |
||
1334 |
1415803 |
return bool( opCast( lhs ) == opCast( rhs ) ); |
|
1335 |
} |
||
1336 |
}; |
||
1337 |
template<typename T1, typename T2> |
||
1338 |
struct Evaluator<T1, T2, IsNotEqualTo> { |
||
1339 |
static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
||
1340 |
10356 |
return bool( opCast( lhs ) != opCast( rhs ) ); |
|
1341 |
} |
||
1342 |
}; |
||
1343 |
template<typename T1, typename T2> |
||
1344 |
struct Evaluator<T1, T2, IsLessThan> { |
||
1345 |
static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
||
1346 |
✓✗ | 4031 |
return bool( opCast( lhs ) < opCast( rhs ) ); |
1347 |
} |
||
1348 |
}; |
||
1349 |
template<typename T1, typename T2> |
||
1350 |
struct Evaluator<T1, T2, IsGreaterThan> { |
||
1351 |
static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
||
1352 |
2685 |
return bool( opCast( lhs ) > opCast( rhs ) ); |
|
1353 |
} |
||
1354 |
}; |
||
1355 |
template<typename T1, typename T2> |
||
1356 |
struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> { |
||
1357 |
static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
||
1358 |
22 |
return bool( opCast( lhs ) >= opCast( rhs ) ); |
|
1359 |
} |
||
1360 |
}; |
||
1361 |
template<typename T1, typename T2> |
||
1362 |
struct Evaluator<T1, T2, IsLessThanOrEqualTo> { |
||
1363 |
static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
||
1364 |
4 |
return bool( opCast( lhs ) <= opCast( rhs ) ); |
|
1365 |
} |
||
1366 |
}; |
||
1367 |
|||
1368 |
template<Operator Op, typename T1, typename T2> |
||
1369 |
bool applyEvaluator( T1 const& lhs, T2 const& rhs ) { |
||
1370 |
771 |
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); |
|
1371 |
} |
||
1372 |
|||
1373 |
// This level of indirection allows us to specialise for integer types |
||
1374 |
// to avoid signed/ unsigned warnings |
||
1375 |
|||
1376 |
// "base" overload |
||
1377 |
template<Operator Op, typename T1, typename T2> |
||
1378 |
bool compare( T1 const& lhs, T2 const& rhs ) { |
||
1379 |
1421270 |
return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); |
|
1380 |
} |
||
1381 |
|||
1382 |
// unsigned X to int |
||
1383 |
template<Operator Op> bool compare( unsigned int lhs, int rhs ) { |
||
1384 |
114 |
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
|
1385 |
} |
||
1386 |
template<Operator Op> bool compare( unsigned long lhs, int rhs ) { |
||
1387 |
426 |
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
|
1388 |
} |
||
1389 |
template<Operator Op> bool compare( unsigned char lhs, int rhs ) { |
||
1390 |
144 |
return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
|
1391 |
} |
||
1392 |
|||
1393 |
// unsigned X to long |
||
1394 |
template<Operator Op> bool compare( unsigned int lhs, long rhs ) { |
||
1395 |
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
||
1396 |
} |
||
1397 |
template<Operator Op> bool compare( unsigned long lhs, long rhs ) { |
||
1398 |
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
||
1399 |
} |
||
1400 |
template<Operator Op> bool compare( unsigned char lhs, long rhs ) { |
||
1401 |
return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
||
1402 |
} |
||
1403 |
|||
1404 |
// int to unsigned X |
||
1405 |
template<Operator Op> bool compare( int lhs, unsigned int rhs ) { |
||
1406 |
60 |
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
|
1407 |
} |
||
1408 |
template<Operator Op> bool compare( int lhs, unsigned long rhs ) { |
||
1409 |
27 |
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
|
1410 |
} |
||
1411 |
template<Operator Op> bool compare( int lhs, unsigned char rhs ) { |
||
1412 |
return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
||
1413 |
} |
||
1414 |
|||
1415 |
// long to unsigned X |
||
1416 |
template<Operator Op> bool compare( long lhs, unsigned int rhs ) { |
||
1417 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1418 |
} |
||
1419 |
template<Operator Op> bool compare( long lhs, unsigned long rhs ) { |
||
1420 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1421 |
} |
||
1422 |
template<Operator Op> bool compare( long lhs, unsigned char rhs ) { |
||
1423 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1424 |
} |
||
1425 |
|||
1426 |
// pointer to long (when comparing against NULL) |
||
1427 |
template<Operator Op, typename T> bool compare( long lhs, T* rhs ) { |
||
1428 |
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
||
1429 |
} |
||
1430 |
template<Operator Op, typename T> bool compare( T* lhs, long rhs ) { |
||
1431 |
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
||
1432 |
} |
||
1433 |
|||
1434 |
// pointer to int (when comparing against NULL) |
||
1435 |
template<Operator Op, typename T> bool compare( int lhs, T* rhs ) { |
||
1436 |
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
||
1437 |
} |
||
1438 |
template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { |
||
1439 |
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
||
1440 |
} |
||
1441 |
|||
1442 |
#ifdef CATCH_CONFIG_CPP11_LONG_LONG |
||
1443 |
// long long to unsigned X |
||
1444 |
template<Operator Op> bool compare( long long lhs, unsigned int rhs ) { |
||
1445 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1446 |
} |
||
1447 |
template<Operator Op> bool compare( long long lhs, unsigned long rhs ) { |
||
1448 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1449 |
} |
||
1450 |
template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) { |
||
1451 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1452 |
} |
||
1453 |
template<Operator Op> bool compare( long long lhs, unsigned char rhs ) { |
||
1454 |
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
||
1455 |
} |
||
1456 |
|||
1457 |
// unsigned long long to X |
||
1458 |
template<Operator Op> bool compare( unsigned long long lhs, int rhs ) { |
||
1459 |
return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
||
1460 |
} |
||
1461 |
template<Operator Op> bool compare( unsigned long long lhs, long rhs ) { |
||
1462 |
return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
||
1463 |
} |
||
1464 |
template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) { |
||
1465 |
return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
||
1466 |
} |
||
1467 |
template<Operator Op> bool compare( unsigned long long lhs, char rhs ) { |
||
1468 |
return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
||
1469 |
} |
||
1470 |
|||
1471 |
// pointer to long long (when comparing against NULL) |
||
1472 |
template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) { |
||
1473 |
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
||
1474 |
} |
||
1475 |
template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) { |
||
1476 |
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
||
1477 |
} |
||
1478 |
#endif // CATCH_CONFIG_CPP11_LONG_LONG |
||
1479 |
|||
1480 |
#ifdef CATCH_CONFIG_CPP11_NULLPTR |
||
1481 |
// pointer to nullptr_t (when comparing against nullptr) |
||
1482 |
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { |
||
1483 |
30 |
return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs ); |
|
1484 |
} |
||
1485 |
template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) { |
||
1486 |
10365 |
return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr ); |
|
1487 |
} |
||
1488 |
#endif // CATCH_CONFIG_CPP11_NULLPTR |
||
1489 |
|||
1490 |
} // end of namespace Internal |
||
1491 |
} // end of namespace Catch |
||
1492 |
|||
1493 |
#ifdef _MSC_VER |
||
1494 |
#pragma warning(pop) |
||
1495 |
#endif |
||
1496 |
|||
1497 |
// #included from: catch_tostring.h |
||
1498 |
#define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED |
||
1499 |
|||
1500 |
#include <sstream> |
||
1501 |
#include <iomanip> |
||
1502 |
#include <limits> |
||
1503 |
#include <vector> |
||
1504 |
#include <cstddef> |
||
1505 |
|||
1506 |
#ifdef __OBJC__ |
||
1507 |
// #included from: catch_objc_arc.hpp |
||
1508 |
#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED |
||
1509 |
|||
1510 |
#import <Foundation/Foundation.h> |
||
1511 |
|||
1512 |
#ifdef __has_feature |
||
1513 |
#define CATCH_ARC_ENABLED __has_feature(objc_arc) |
||
1514 |
#else |
||
1515 |
#define CATCH_ARC_ENABLED 0 |
||
1516 |
#endif |
||
1517 |
|||
1518 |
void arcSafeRelease( NSObject* obj ); |
||
1519 |
id performOptionalSelector( id obj, SEL sel ); |
||
1520 |
|||
1521 |
#if !CATCH_ARC_ENABLED |
||
1522 |
inline void arcSafeRelease( NSObject* obj ) { |
||
1523 |
[obj release]; |
||
1524 |
} |
||
1525 |
inline id performOptionalSelector( id obj, SEL sel ) { |
||
1526 |
if( [obj respondsToSelector: sel] ) |
||
1527 |
return [obj performSelector: sel]; |
||
1528 |
return nil; |
||
1529 |
} |
||
1530 |
#define CATCH_UNSAFE_UNRETAINED |
||
1531 |
#define CATCH_ARC_STRONG |
||
1532 |
#else |
||
1533 |
inline void arcSafeRelease( NSObject* ){} |
||
1534 |
inline id performOptionalSelector( id obj, SEL sel ) { |
||
1535 |
#ifdef __clang__ |
||
1536 |
#pragma clang diagnostic push |
||
1537 |
#pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
||
1538 |
#endif |
||
1539 |
if( [obj respondsToSelector: sel] ) |
||
1540 |
return [obj performSelector: sel]; |
||
1541 |
#ifdef __clang__ |
||
1542 |
#pragma clang diagnostic pop |
||
1543 |
#endif |
||
1544 |
return nil; |
||
1545 |
} |
||
1546 |
#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained |
||
1547 |
#define CATCH_ARC_STRONG __strong |
||
1548 |
#endif |
||
1549 |
|||
1550 |
#endif |
||
1551 |
|||
1552 |
#ifdef CATCH_CONFIG_CPP11_TUPLE |
||
1553 |
#include <tuple> |
||
1554 |
#endif |
||
1555 |
|||
1556 |
#ifdef CATCH_CONFIG_CPP11_IS_ENUM |
||
1557 |
#include <type_traits> |
||
1558 |
#endif |
||
1559 |
|||
1560 |
namespace Catch { |
||
1561 |
|||
1562 |
// Why we're here. |
||
1563 |
template<typename T> |
||
1564 |
std::string toString( T const& value ); |
||
1565 |
|||
1566 |
// Built in overloads |
||
1567 |
|||
1568 |
std::string toString( std::string const& value ); |
||
1569 |
std::string toString( std::wstring const& value ); |
||
1570 |
std::string toString( const char* const value ); |
||
1571 |
std::string toString( char* const value ); |
||
1572 |
std::string toString( const wchar_t* const value ); |
||
1573 |
std::string toString( wchar_t* const value ); |
||
1574 |
std::string toString( int value ); |
||
1575 |
std::string toString( unsigned long value ); |
||
1576 |
std::string toString( unsigned int value ); |
||
1577 |
std::string toString( const double value ); |
||
1578 |
std::string toString( const float value ); |
||
1579 |
std::string toString( bool value ); |
||
1580 |
std::string toString( char value ); |
||
1581 |
std::string toString( signed char value ); |
||
1582 |
std::string toString( unsigned char value ); |
||
1583 |
|||
1584 |
#ifdef CATCH_CONFIG_CPP11_LONG_LONG |
||
1585 |
std::string toString( long long value ); |
||
1586 |
std::string toString( unsigned long long value ); |
||
1587 |
#endif |
||
1588 |
|||
1589 |
#ifdef CATCH_CONFIG_CPP11_NULLPTR |
||
1590 |
std::string toString( std::nullptr_t ); |
||
1591 |
#endif |
||
1592 |
|||
1593 |
#ifdef __OBJC__ |
||
1594 |
std::string toString( NSString const * const& nsstring ); |
||
1595 |
std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); |
||
1596 |
std::string toString( NSObject* const& nsObject ); |
||
1597 |
#endif |
||
1598 |
|||
1599 |
namespace Detail { |
||
1600 |
|||
1601 |
extern const std::string unprintableString; |
||
1602 |
|||
1603 |
struct BorgType { |
||
1604 |
template<typename T> BorgType( T const& ); |
||
1605 |
}; |
||
1606 |
|||
1607 |
struct TrueType { char sizer[1]; }; |
||
1608 |
struct FalseType { char sizer[2]; }; |
||
1609 |
|||
1610 |
TrueType& testStreamable( std::ostream& ); |
||
1611 |
FalseType testStreamable( FalseType ); |
||
1612 |
|||
1613 |
FalseType operator<<( std::ostream const&, BorgType const& ); |
||
1614 |
|||
1615 |
template<typename T> |
||
1616 |
struct IsStreamInsertable { |
||
1617 |
static std::ostream &s; |
||
1618 |
static T const&t; |
||
1619 |
enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) }; |
||
1620 |
}; |
||
1621 |
|||
1622 |
#if defined(CATCH_CONFIG_CPP11_IS_ENUM) |
||
1623 |
template<typename T, |
||
1624 |
bool IsEnum = std::is_enum<T>::value |
||
1625 |
> |
||
1626 |
struct EnumStringMaker |
||
1627 |
{ |
||
1628 |
74 |
static std::string convert( T const& ) { return unprintableString; } |
|
1629 |
}; |
||
1630 |
|||
1631 |
template<typename T> |
||
1632 |
struct EnumStringMaker<T,true> |
||
1633 |
{ |
||
1634 |
static std::string convert( T const& v ) |
||
1635 |
{ |
||
1636 |
return ::Catch::toString( |
||
1637 |
static_cast<typename std::underlying_type<T>::type>(v) |
||
1638 |
✓✗✓✗ ✓✗✓✗ |
4486 |
); |
1639 |
} |
||
1640 |
}; |
||
1641 |
#endif |
||
1642 |
template<bool C> |
||
1643 |
struct StringMakerBase { |
||
1644 |
#if defined(CATCH_CONFIG_CPP11_IS_ENUM) |
||
1645 |
template<typename T> |
||
1646 |
static std::string convert( T const& v ) |
||
1647 |
{ |
||
1648 |
4560 |
return EnumStringMaker<T>::convert( v ); |
|
1649 |
} |
||
1650 |
#else |
||
1651 |
template<typename T> |
||
1652 |
static std::string convert( T const& ) { return unprintableString; } |
||
1653 |
#endif |
||
1654 |
}; |
||
1655 |
|||
1656 |
template<> |
||
1657 |
struct StringMakerBase<true> { |
||
1658 |
template<typename T> |
||
1659 |
927222 |
static std::string convert( T const& _value ) { |
|
1660 |
1854444 |
std::ostringstream oss; |
|
1661 |
1854444 |
oss << _value; |
|
1662 |
1854444 |
return oss.str(); |
|
1663 |
} |
||
1664 |
}; |
||
1665 |
|||
1666 |
std::string rawMemoryToString( const void *object, std::size_t size ); |
||
1667 |
|||
1668 |
template<typename T> |
||
1669 |
inline std::string rawMemoryToString( const T& object ) { |
||
1670 |
10579 |
return rawMemoryToString( &object, sizeof(object) ); |
|
1671 |
} |
||
1672 |
|||
1673 |
} // end namespace Detail |
||
1674 |
|||
1675 |
template<typename T> |
||
1676 |
struct StringMaker : |
||
1677 |
Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {}; |
||
1678 |
|||
1679 |
template<typename T> |
||
1680 |
struct StringMaker<T*> { |
||
1681 |
template<typename U> |
||
1682 |
10686 |
static std::string convert( U* p ) { |
|
1683 |
✓✓✓✓ ✓✓✗✓ ✗✓ |
10686 |
if( !p ) |
1684 |
287 |
return "NULL"; |
|
1685 |
else |
||
1686 |
return Detail::rawMemoryToString( p ); |
||
1687 |
} |
||
1688 |
}; |
||
1689 |
|||
1690 |
template<typename R, typename C> |
||
1691 |
struct StringMaker<R C::*> { |
||
1692 |
static std::string convert( R C::* p ) { |
||
1693 |
if( !p ) |
||
1694 |
return "NULL"; |
||
1695 |
else |
||
1696 |
return Detail::rawMemoryToString( p ); |
||
1697 |
} |
||
1698 |
}; |
||
1699 |
|||
1700 |
namespace Detail { |
||
1701 |
template<typename InputIterator> |
||
1702 |
std::string rangeToString( InputIterator first, InputIterator last ); |
||
1703 |
} |
||
1704 |
|||
1705 |
//template<typename T, typename Allocator> |
||
1706 |
//struct StringMaker<std::vector<T, Allocator> > { |
||
1707 |
// static std::string convert( std::vector<T,Allocator> const& v ) { |
||
1708 |
// return Detail::rangeToString( v.begin(), v.end() ); |
||
1709 |
// } |
||
1710 |
//}; |
||
1711 |
|||
1712 |
template<typename T, typename Allocator> |
||
1713 |
std::string toString( std::vector<T,Allocator> const& v ) { |
||
1714 |
return Detail::rangeToString( v.begin(), v.end() ); |
||
1715 |
} |
||
1716 |
|||
1717 |
#ifdef CATCH_CONFIG_CPP11_TUPLE |
||
1718 |
|||
1719 |
// toString for tuples |
||
1720 |
namespace TupleDetail { |
||
1721 |
template< |
||
1722 |
typename Tuple, |
||
1723 |
std::size_t N = 0, |
||
1724 |
bool = (N < std::tuple_size<Tuple>::value) |
||
1725 |
> |
||
1726 |
struct ElementPrinter { |
||
1727 |
static void print( const Tuple& tuple, std::ostream& os ) |
||
1728 |
{ |
||
1729 |
os << ( N ? ", " : " " ) |
||
1730 |
<< Catch::toString(std::get<N>(tuple)); |
||
1731 |
ElementPrinter<Tuple,N+1>::print(tuple,os); |
||
1732 |
} |
||
1733 |
}; |
||
1734 |
|||
1735 |
template< |
||
1736 |
typename Tuple, |
||
1737 |
std::size_t N |
||
1738 |
> |
||
1739 |
struct ElementPrinter<Tuple,N,false> { |
||
1740 |
static void print( const Tuple&, std::ostream& ) {} |
||
1741 |
}; |
||
1742 |
|||
1743 |
} |
||
1744 |
|||
1745 |
template<typename ...Types> |
||
1746 |
struct StringMaker<std::tuple<Types...>> { |
||
1747 |
|||
1748 |
static std::string convert( const std::tuple<Types...>& tuple ) |
||
1749 |
{ |
||
1750 |
std::ostringstream os; |
||
1751 |
os << '{'; |
||
1752 |
TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os ); |
||
1753 |
os << " }"; |
||
1754 |
return os.str(); |
||
1755 |
} |
||
1756 |
}; |
||
1757 |
#endif // CATCH_CONFIG_CPP11_TUPLE |
||
1758 |
|||
1759 |
namespace Detail { |
||
1760 |
template<typename T> |
||
1761 |
std::string makeString( T const& value ) { |
||
1762 |
926654 |
return StringMaker<T>::convert( value ); |
|
1763 |
} |
||
1764 |
} // end namespace Detail |
||
1765 |
|||
1766 |
/// \brief converts any type to a string |
||
1767 |
/// |
||
1768 |
/// The default template forwards on to ostringstream - except when an |
||
1769 |
/// ostringstream overload does not exist - in which case it attempts to detect |
||
1770 |
/// that and writes {?}. |
||
1771 |
/// Overload (not specialise) this template for custom typs that you don't want |
||
1772 |
/// to provide an ostream overload for. |
||
1773 |
template<typename T> |
||
1774 |
std::string toString( T const& value ) { |
||
1775 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
15814 |
return StringMaker<T>::convert( value ); |
1776 |
} |
||
1777 |
|||
1778 |
namespace Detail { |
||
1779 |
template<typename InputIterator> |
||
1780 |
std::string rangeToString( InputIterator first, InputIterator last ) { |
||
1781 |
std::ostringstream oss; |
||
1782 |
oss << "{ "; |
||
1783 |
if( first != last ) { |
||
1784 |
oss << Catch::toString( *first ); |
||
1785 |
for( ++first ; first != last ; ++first ) |
||
1786 |
oss << ", " << Catch::toString( *first ); |
||
1787 |
} |
||
1788 |
oss << " }"; |
||
1789 |
return oss.str(); |
||
1790 |
} |
||
1791 |
} |
||
1792 |
|||
1793 |
} // end namespace Catch |
||
1794 |
|||
1795 |
namespace Catch { |
||
1796 |
|||
1797 |
// Wraps the LHS of an expression and captures the operator and RHS (if any) - |
||
1798 |
// wrapping them all in a ResultBuilder object |
||
1799 |
template<typename T> |
||
1800 |
class ExpressionLhs { |
||
1801 |
ExpressionLhs& operator = ( ExpressionLhs const& ); |
||
1802 |
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
1803 |
ExpressionLhs& operator = ( ExpressionLhs && ) = delete; |
||
1804 |
# endif |
||
1805 |
|||
1806 |
public: |
||
1807 |
81028 |
ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} |
|
1808 |
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
||
1809 |
ExpressionLhs( ExpressionLhs const& ) = default; |
||
1810 |
ExpressionLhs( ExpressionLhs && ) = default; |
||
1811 |
# endif |
||
1812 |
|||
1813 |
template<typename RhsT> |
||
1814 |
ResultBuilder& operator == ( RhsT const& rhs ) { |
||
1815 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
1334717 |
return captureExpression<Internal::IsEqualTo>( rhs ); |
1816 |
} |
||
1817 |
|||
1818 |
template<typename RhsT> |
||
1819 |
ResultBuilder& operator != ( RhsT const& rhs ) { |
||
1820 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
10326 |
return captureExpression<Internal::IsNotEqualTo>( rhs ); |
1821 |
} |
||
1822 |
|||
1823 |
template<typename RhsT> |
||
1824 |
ResultBuilder& operator < ( RhsT const& rhs ) { |
||
1825 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✗✗✗✗ |
4031 |
return captureExpression<Internal::IsLessThan>( rhs ); |
1826 |
} |
||
1827 |
|||
1828 |
template<typename RhsT> |
||
1829 |
ResultBuilder& operator > ( RhsT const& rhs ) { |
||
1830 |
✓✗✓✗ ✓✗✓✗ |
2685 |
return captureExpression<Internal::IsGreaterThan>( rhs ); |
1831 |
} |
||
1832 |
|||
1833 |
template<typename RhsT> |
||
1834 |
ResultBuilder& operator <= ( RhsT const& rhs ) { |
||
1835 |
✓✗✓✗ ✓✗✓✗ |
4 |
return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); |
1836 |
} |
||
1837 |
|||
1838 |
template<typename RhsT> |
||
1839 |
ResultBuilder& operator >= ( RhsT const& rhs ) { |
||
1840 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
22 |
return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); |
1841 |
} |
||
1842 |
|||
1843 |
ResultBuilder& operator == ( bool rhs ) { |
||
1844 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
80637 |
return captureExpression<Internal::IsEqualTo>( rhs ); |
1845 |
} |
||
1846 |
|||
1847 |
ResultBuilder& operator != ( bool rhs ) { |
||
1848 |
return captureExpression<Internal::IsNotEqualTo>( rhs ); |
||
1849 |
} |
||
1850 |
|||
1851 |
469 |
void endExpression() { |
|
1852 |
469 |
bool value = m_lhs ? true : false; |
|
1853 |
✓✗✓✗ |
938 |
m_rb |
1854 |
✓✗✓✗ |
1407 |
.setLhs( Catch::toString( value ) ) |
1855 |
✓✗✓✗ |
938 |
.setResultType( value ) |
1856 |
.endExpression(); |
||
1857 |
469 |
} |
|
1858 |
|||
1859 |
// Only simple binary expressions are allowed on the LHS. |
||
1860 |
// If more complex compositions are required then place the sub expression in parentheses |
||
1861 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); |
||
1862 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); |
||
1863 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); |
||
1864 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); |
||
1865 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); |
||
1866 |
template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); |
||
1867 |
|||
1868 |
private: |
||
1869 |
template<Internal::Operator Op, typename RhsT> |
||
1870 |
1432423 |
ResultBuilder& captureExpression( RhsT const& rhs ) { |
|
1871 |
1432423 |
return m_rb |
|
1872 |
1525643 |
.setResultType( Internal::compare<Op>( m_lhs, rhs ) ) |
|
1873 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✗✗ ✓✗✗✗ ✓✗✓✗ ✗✗✓✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗ |
4283927 |
.setLhs( Catch::toString( m_lhs ) ) |
1874 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✓✗✓✗ ✗✗✗✗ ✓✗✓✗ ✗✗✗✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
4297767 |
.setRhs( Catch::toString( rhs ) ) |
1875 |
✓✗✓✗ ✓✓✗✓ ✗✓✗✓ ✓✗✓✗ ✓✓✗✓ ✓✗✓✗ ✓✗✗✓ ✓✗✓✗ ✓✓✗✓ ✓✗✓✓ ✗✓✓✗ ✓✓✗✗ ✓✗✗✓ ✗✗✓✓ ✗✓✗✓ ✗✓✓✗ ✓✗✓✗ ✓✗✗✓ ✗✓✗✓ ✓✗✓✗ ✓✗✓✓ ✗✓✗✓ ✗✓✓✗ ✓✗✓✗ ✓✓✗✓ ✗✓✓✗ ✓✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✗✗✗ ✗✗✗✓ ✗✓✗✓ ✗✗✗✗ ✗✗✗✓ ✗✓✗✓ ✗✓✗✗ ✗✗✗✗ ✗✓✗✓ ✗✓✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✗✗✗ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✗ |
8594608 |
.setOp( Internal::OperatorTraits<Op>::getName() ); |
1876 |
} |
||
1877 |
|||
1878 |
private: |
||
1879 |
ResultBuilder& m_rb; |
||
1880 |
T m_lhs; |
||
1881 |
}; |
||
1882 |
|||
1883 |
} // end namespace Catch |
||
1884 |
|||
1885 |
|||
1886 |
namespace Catch { |
||
1887 |
|||
1888 |
template<typename T> |
||
1889 |
inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) { |
||
1890 |
1351823 |
return ExpressionLhs<T const&>( *this, operand ); |
|
1891 |
} |
||
1892 |
|||
1893 |
inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) { |
||
1894 |
162096 |
return ExpressionLhs<bool>( *this, value ); |
|
1895 |
} |
||
1896 |
|||
1897 |
} // namespace Catch |
||
1898 |
|||
1899 |
// #included from: catch_message.h |
||
1900 |
#define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED |
||
1901 |
|||
1902 |
#include <string> |
||
1903 |
|||
1904 |
namespace Catch { |
||
1905 |
|||
1906 |
struct MessageInfo { |
||
1907 |
MessageInfo( std::string const& _macroName, |
||
1908 |
SourceLineInfo const& _lineInfo, |
||
1909 |
ResultWas::OfType _type ); |
||
1910 |
|||
1911 |
std::string macroName; |
||
1912 |
SourceLineInfo lineInfo; |
||
1913 |
ResultWas::OfType type; |
||
1914 |
std::string message; |
||
1915 |
unsigned int sequence; |
||
1916 |
|||
1917 |
bool operator == ( MessageInfo const& other ) const { |
||
1918 |
return sequence == other.sequence; |
||
1919 |
} |
||
1920 |
bool operator < ( MessageInfo const& other ) const { |
||
1921 |
return sequence < other.sequence; |
||
1922 |
} |
||
1923 |
private: |
||
1924 |
static unsigned int globalCount; |
||
1925 |
}; |
||
1926 |
|||
1927 |
struct MessageBuilder { |
||
1928 |
MessageBuilder( std::string const& macroName, |
||
1929 |
SourceLineInfo const& lineInfo, |
||
1930 |
ResultWas::OfType type ) |
||
1931 |
: m_info( macroName, lineInfo, type ) |
||
1932 |
{} |
||
1933 |
|||
1934 |
template<typename T> |
||
1935 |
MessageBuilder& operator << ( T const& value ) { |
||
1936 |
m_stream << value; |
||
1937 |
return *this; |
||
1938 |
} |
||
1939 |
|||
1940 |
MessageInfo m_info; |
||
1941 |
std::ostringstream m_stream; |
||
1942 |
}; |
||
1943 |
|||
1944 |
class ScopedMessage { |
||
1945 |
public: |
||
1946 |
ScopedMessage( MessageBuilder const& builder ); |
||
1947 |
ScopedMessage( ScopedMessage const& other ); |
||
1948 |
~ScopedMessage(); |
||
1949 |
|||
1950 |
MessageInfo m_info; |
||
1951 |
}; |
||
1952 |
|||
1953 |
} // end namespace Catch |
||
1954 |
|||
1955 |
// #included from: catch_interfaces_capture.h |
||
1956 |
#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED |
||
1957 |
|||
1958 |
#include <string> |
||
1959 |
|||
1960 |
namespace Catch { |
||
1961 |
|||
1962 |
class TestCase; |
||
1963 |
class AssertionResult; |
||
1964 |
struct AssertionInfo; |
||
1965 |
struct SectionInfo; |
||
1966 |
struct SectionEndInfo; |
||
1967 |
struct MessageInfo; |
||
1968 |
class ScopedMessageBuilder; |
||
1969 |
struct Counts; |
||
1970 |
|||
1971 |
struct IResultCapture { |
||
1972 |
|||
1973 |
virtual ~IResultCapture(); |
||
1974 |
|||
1975 |
virtual void assertionEnded( AssertionResult const& result ) = 0; |
||
1976 |
virtual bool sectionStarted( SectionInfo const& sectionInfo, |
||
1977 |
Counts& assertions ) = 0; |
||
1978 |
virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; |
||
1979 |
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; |
||
1980 |
virtual void pushScopedMessage( MessageInfo const& message ) = 0; |
||
1981 |
virtual void popScopedMessage( MessageInfo const& message ) = 0; |
||
1982 |
|||
1983 |
virtual std::string getCurrentTestName() const = 0; |
||
1984 |
virtual const AssertionResult* getLastResult() const = 0; |
||
1985 |
|||
1986 |
virtual void handleFatalErrorCondition( std::string const& message ) = 0; |
||
1987 |
}; |
||
1988 |
|||
1989 |
IResultCapture& getResultCapture(); |
||
1990 |
} |
||
1991 |
|||
1992 |
// #included from: catch_debugger.h |
||
1993 |
#define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED |
||
1994 |
|||
1995 |
// #included from: catch_platform.h |
||
1996 |
#define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED |
||
1997 |
|||
1998 |
#if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) |
||
1999 |
#define CATCH_PLATFORM_MAC |
||
2000 |
#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) |
||
2001 |
#define CATCH_PLATFORM_IPHONE |
||
2002 |
#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) |
||
2003 |
#define CATCH_PLATFORM_WINDOWS |
||
2004 |
#endif |
||
2005 |
|||
2006 |
#include <string> |
||
2007 |
|||
2008 |
namespace Catch{ |
||
2009 |
|||
2010 |
bool isDebuggerActive(); |
||
2011 |
void writeToDebugConsole( std::string const& text ); |
||
2012 |
} |
||
2013 |
|||
2014 |
#ifdef CATCH_PLATFORM_MAC |
||
2015 |
|||
2016 |
// The following code snippet based on: |
||
2017 |
// http://cocoawithlove.com/2008/03/break-into-debugger.html |
||
2018 |
#ifdef DEBUG |
||
2019 |
#if defined(__ppc64__) || defined(__ppc__) |
||
2020 |
#define CATCH_BREAK_INTO_DEBUGGER() \ |
||
2021 |
if( Catch::isDebuggerActive() ) { \ |
||
2022 |
__asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ |
||
2023 |
: : : "memory","r0","r3","r4" ); \ |
||
2024 |
} |
||
2025 |
#else |
||
2026 |
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );} |
||
2027 |
#endif |
||
2028 |
#endif |
||
2029 |
|||
2030 |
#elif defined(_MSC_VER) |
||
2031 |
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); } |
||
2032 |
#elif defined(__MINGW32__) |
||
2033 |
extern "C" __declspec(dllimport) void __stdcall DebugBreak(); |
||
2034 |
#define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); } |
||
2035 |
#endif |
||
2036 |
|||
2037 |
#ifndef CATCH_BREAK_INTO_DEBUGGER |
||
2038 |
#define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); |
||
2039 |
#endif |
||
2040 |
|||
2041 |
// #included from: catch_interfaces_runner.h |
||
2042 |
#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED |
||
2043 |
|||
2044 |
namespace Catch { |
||
2045 |
class TestCase; |
||
2046 |
|||
2047 |
struct IRunner { |
||
2048 |
virtual ~IRunner(); |
||
2049 |
virtual bool aborting() const = 0; |
||
2050 |
}; |
||
2051 |
} |
||
2052 |
|||
2053 |
/////////////////////////////////////////////////////////////////////////////// |
||
2054 |
// In the event of a failure works out if the debugger needs to be invoked |
||
2055 |
// and/or an exception thrown and takes appropriate action. |
||
2056 |
// This needs to be done as a macro so the debugger will stop in the user |
||
2057 |
// source code rather than in Catch library code |
||
2058 |
#define INTERNAL_CATCH_REACT( resultBuilder ) \ |
||
2059 |
if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ |
||
2060 |
resultBuilder.react(); |
||
2061 |
|||
2062 |
/////////////////////////////////////////////////////////////////////////////// |
||
2063 |
#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \ |
||
2064 |
do { \ |
||
2065 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
||
2066 |
try { \ |
||
2067 |
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ |
||
2068 |
( __catchResult <= expr ).endExpression(); \ |
||
2069 |
} \ |
||
2070 |
catch( ... ) { \ |
||
2071 |
__catchResult.useActiveException( Catch::ResultDisposition::Normal ); \ |
||
2072 |
} \ |
||
2073 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2074 |
} while( Catch::isTrue( false && static_cast<bool>(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look |
||
2075 |
|||
2076 |
/////////////////////////////////////////////////////////////////////////////// |
||
2077 |
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ |
||
2078 |
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ |
||
2079 |
if( Catch::getResultCapture().getLastResult()->succeeded() ) |
||
2080 |
|||
2081 |
/////////////////////////////////////////////////////////////////////////////// |
||
2082 |
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \ |
||
2083 |
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ |
||
2084 |
if( !Catch::getResultCapture().getLastResult()->succeeded() ) |
||
2085 |
|||
2086 |
/////////////////////////////////////////////////////////////////////////////// |
||
2087 |
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \ |
||
2088 |
do { \ |
||
2089 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
||
2090 |
try { \ |
||
2091 |
expr; \ |
||
2092 |
__catchResult.captureResult( Catch::ResultWas::Ok ); \ |
||
2093 |
} \ |
||
2094 |
catch( ... ) { \ |
||
2095 |
__catchResult.useActiveException( resultDisposition ); \ |
||
2096 |
} \ |
||
2097 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2098 |
} while( Catch::alwaysFalse() ) |
||
2099 |
|||
2100 |
/////////////////////////////////////////////////////////////////////////////// |
||
2101 |
#define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \ |
||
2102 |
do { \ |
||
2103 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \ |
||
2104 |
if( __catchResult.allowThrows() ) \ |
||
2105 |
try { \ |
||
2106 |
expr; \ |
||
2107 |
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ |
||
2108 |
} \ |
||
2109 |
catch( ... ) { \ |
||
2110 |
__catchResult.captureExpectedException( matcher ); \ |
||
2111 |
} \ |
||
2112 |
else \ |
||
2113 |
__catchResult.captureResult( Catch::ResultWas::Ok ); \ |
||
2114 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2115 |
} while( Catch::alwaysFalse() ) |
||
2116 |
|||
2117 |
/////////////////////////////////////////////////////////////////////////////// |
||
2118 |
#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \ |
||
2119 |
do { \ |
||
2120 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
||
2121 |
if( __catchResult.allowThrows() ) \ |
||
2122 |
try { \ |
||
2123 |
expr; \ |
||
2124 |
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ |
||
2125 |
} \ |
||
2126 |
catch( exceptionType ) { \ |
||
2127 |
__catchResult.captureResult( Catch::ResultWas::Ok ); \ |
||
2128 |
} \ |
||
2129 |
catch( ... ) { \ |
||
2130 |
__catchResult.useActiveException( resultDisposition ); \ |
||
2131 |
} \ |
||
2132 |
else \ |
||
2133 |
__catchResult.captureResult( Catch::ResultWas::Ok ); \ |
||
2134 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2135 |
} while( Catch::alwaysFalse() ) |
||
2136 |
|||
2137 |
/////////////////////////////////////////////////////////////////////////////// |
||
2138 |
#ifdef CATCH_CONFIG_VARIADIC_MACROS |
||
2139 |
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \ |
||
2140 |
do { \ |
||
2141 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ |
||
2142 |
__catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ |
||
2143 |
__catchResult.captureResult( messageType ); \ |
||
2144 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2145 |
} while( Catch::alwaysFalse() ) |
||
2146 |
#else |
||
2147 |
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \ |
||
2148 |
do { \ |
||
2149 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ |
||
2150 |
__catchResult << log + ::Catch::StreamEndStop(); \ |
||
2151 |
__catchResult.captureResult( messageType ); \ |
||
2152 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2153 |
} while( Catch::alwaysFalse() ) |
||
2154 |
#endif |
||
2155 |
|||
2156 |
/////////////////////////////////////////////////////////////////////////////// |
||
2157 |
#define INTERNAL_CATCH_INFO( log, macroName ) \ |
||
2158 |
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; |
||
2159 |
|||
2160 |
/////////////////////////////////////////////////////////////////////////////// |
||
2161 |
#define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \ |
||
2162 |
do { \ |
||
2163 |
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ |
||
2164 |
try { \ |
||
2165 |
std::string matcherAsString = (matcher).toString(); \ |
||
2166 |
__catchResult \ |
||
2167 |
.setLhs( Catch::toString( arg ) ) \ |
||
2168 |
.setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \ |
||
2169 |
.setOp( "matches" ) \ |
||
2170 |
.setResultType( (matcher).match( arg ) ); \ |
||
2171 |
__catchResult.captureExpression(); \ |
||
2172 |
} catch( ... ) { \ |
||
2173 |
__catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ |
||
2174 |
} \ |
||
2175 |
INTERNAL_CATCH_REACT( __catchResult ) \ |
||
2176 |
} while( Catch::alwaysFalse() ) |
||
2177 |
|||
2178 |
// #included from: internal/catch_section.h |
||
2179 |
#define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED |
||
2180 |
|||
2181 |
// #included from: catch_section_info.h |
||
2182 |
#define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED |
||
2183 |
|||
2184 |
// #included from: catch_totals.hpp |
||
2185 |
#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED |
||
2186 |
|||
2187 |
#include <cstddef> |
||
2188 |
|||
2189 |
namespace Catch { |
||
2190 |
|||
2191 |
struct Counts { |
||
2192 |
10207 |
Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {} |
|
2193 |
|||
2194 |
Counts operator - ( Counts const& other ) const { |
||
2195 |
1933 |
Counts diff; |
|
2196 |
1933 |
diff.passed = passed - other.passed; |
|
2197 |
1933 |
diff.failed = failed - other.failed; |
|
2198 |
1933 |
diff.failedButOk = failedButOk - other.failedButOk; |
|
2199 |
return diff; |
||
2200 |
} |
||
2201 |
Counts& operator += ( Counts const& other ) { |
||
2202 |
1182 |
passed += other.passed; |
|
2203 |
1182 |
failed += other.failed; |
|
2204 |
1182 |
failedButOk += other.failedButOk; |
|
2205 |
return *this; |
||
2206 |
} |
||
2207 |
|||
2208 |
std::size_t total() const { |
||
2209 |
1148 |
return passed + failed + failedButOk; |
|
2210 |
} |
||
2211 |
bool allPassed() const { |
||
2212 |
✓✗✗✓ ✓✗✗✓ |
2 |
return failed == 0 && failedButOk == 0; |
2213 |
} |
||
2214 |
bool allOk() const { |
||
2215 |
return failed == 0; |
||
2216 |
} |
||
2217 |
|||
2218 |
std::size_t passed; |
||
2219 |
std::size_t failed; |
||
2220 |
std::size_t failedButOk; |
||
2221 |
}; |
||
2222 |
|||
2223 |
1188 |
struct Totals { |
|
2224 |
|||
2225 |
Totals operator - ( Totals const& other ) const { |
||
2226 |
394 |
Totals diff; |
|
2227 |
788 |
diff.assertions = assertions - other.assertions; |
|
2228 |
788 |
diff.testCases = testCases - other.testCases; |
|
2229 |
return diff; |
||
2230 |
} |
||
2231 |
|||
2232 |
394 |
Totals delta( Totals const& prevTotals ) const { |
|
2233 |
394 |
Totals diff = *this - prevTotals; |
|
2234 |
✗✓ | 394 |
if( diff.assertions.failed > 0 ) |
2235 |
++diff.testCases.failed; |
||
2236 |
✗✓ | 394 |
else if( diff.assertions.failedButOk > 0 ) |
2237 |
++diff.testCases.failedButOk; |
||
2238 |
else |
||
2239 |
394 |
++diff.testCases.passed; |
|
2240 |
394 |
return diff; |
|
2241 |
} |
||
2242 |
|||
2243 |
Totals& operator += ( Totals const& other ) { |
||
2244 |
788 |
assertions += other.assertions; |
|
2245 |
788 |
testCases += other.testCases; |
|
2246 |
return *this; |
||
2247 |
} |
||
2248 |
|||
2249 |
Counts assertions; |
||
2250 |
Counts testCases; |
||
2251 |
}; |
||
2252 |
} |
||
2253 |
|||
2254 |
namespace Catch { |
||
2255 |
|||
2256 |
123748 |
struct SectionInfo { |
|
2257 |
SectionInfo |
||
2258 |
( SourceLineInfo const& _lineInfo, |
||
2259 |
std::string const& _name, |
||
2260 |
std::string const& _description = std::string() ); |
||
2261 |
|||
2262 |
std::string name; |
||
2263 |
std::string description; |
||
2264 |
SourceLineInfo lineInfo; |
||
2265 |
}; |
||
2266 |
|||
2267 |
✗✗ | 400 |
struct SectionEndInfo { |
2268 |
SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) |
||
2269 |
400 |
: sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) |
|
2270 |
{} |
||
2271 |
|||
2272 |
SectionInfo sectionInfo; |
||
2273 |
Counts prevAssertions; |
||
2274 |
double durationInSeconds; |
||
2275 |
}; |
||
2276 |
|||
2277 |
} // end namespace Catch |
||
2278 |
|||
2279 |
// #included from: catch_timer.h |
||
2280 |
#define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED |
||
2281 |
|||
2282 |
#ifdef CATCH_PLATFORM_WINDOWS |
||
2283 |
typedef unsigned long long uint64_t; |
||
2284 |
#else |
||
2285 |
#include <stdint.h> |
||
2286 |
#endif |
||
2287 |
|||
2288 |
namespace Catch { |
||
2289 |
|||
2290 |
class Timer { |
||
2291 |
public: |
||
2292 |
9015 |
Timer() : m_ticks( 0 ) {} |
|
2293 |
void start(); |
||
2294 |
unsigned int getElapsedMicroseconds() const; |
||
2295 |
unsigned int getElapsedMilliseconds() const; |
||
2296 |
double getElapsedSeconds() const; |
||
2297 |
|||
2298 |
private: |
||
2299 |
uint64_t m_ticks; |
||
2300 |
}; |
||
2301 |
|||
2302 |
} // namespace Catch |
||
2303 |
|||
2304 |
#include <string> |
||
2305 |
|||
2306 |
namespace Catch { |
||
2307 |
|||
2308 |
class Section : NonCopyable { |
||
2309 |
public: |
||
2310 |
Section( SectionInfo const& info ); |
||
2311 |
~Section(); |
||
2312 |
|||
2313 |
// This indicates whether the section should be executed or not |
||
2314 |
operator bool() const; |
||
2315 |
|||
2316 |
private: |
||
2317 |
SectionInfo m_info; |
||
2318 |
|||
2319 |
std::string m_name; |
||
2320 |
Counts m_assertions; |
||
2321 |
bool m_sectionIncluded; |
||
2322 |
Timer m_timer; |
||
2323 |
}; |
||
2324 |
|||
2325 |
} // end namespace Catch |
||
2326 |
|||
2327 |
#ifdef CATCH_CONFIG_VARIADIC_MACROS |
||
2328 |
#define INTERNAL_CATCH_SECTION( ... ) \ |
||
2329 |
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) |
||
2330 |
#else |
||
2331 |
#define INTERNAL_CATCH_SECTION( name, desc ) \ |
||
2332 |
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) |
||
2333 |
#endif |
||
2334 |
|||
2335 |
// #included from: internal/catch_generators.hpp |
||
2336 |
#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED |
||
2337 |
|||
2338 |
#include <iterator> |
||
2339 |
#include <vector> |
||
2340 |
#include <string> |
||
2341 |
#include <stdlib.h> |
||
2342 |
|||
2343 |
namespace Catch { |
||
2344 |
|||
2345 |
template<typename T> |
||
2346 |
struct IGenerator { |
||
2347 |
virtual ~IGenerator() {} |
||
2348 |
virtual T getValue( std::size_t index ) const = 0; |
||
2349 |
virtual std::size_t size () const = 0; |
||
2350 |
}; |
||
2351 |
|||
2352 |
template<typename T> |
||
2353 |
class BetweenGenerator : public IGenerator<T> { |
||
2354 |
public: |
||
2355 |
BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} |
||
2356 |
|||
2357 |
virtual T getValue( std::size_t index ) const { |
||
2358 |
return m_from+static_cast<int>( index ); |
||
2359 |
} |
||
2360 |
|||
2361 |
virtual std::size_t size() const { |
||
2362 |
return static_cast<std::size_t>( 1+m_to-m_from ); |
||
2363 |
} |
||
2364 |
|||
2365 |
private: |
||
2366 |
|||
2367 |
T m_from; |
||
2368 |
T m_to; |
||
2369 |
}; |
||
2370 |
|||
2371 |
template<typename T> |
||
2372 |
class ValuesGenerator : public IGenerator<T> { |
||
2373 |
public: |
||
2374 |
ValuesGenerator(){} |
||
2375 |
|||
2376 |
void add( T value ) { |
||
2377 |
m_values.push_back( value ); |
||
2378 |
} |
||
2379 |
|||
2380 |
virtual T getValue( std::size_t index ) const { |
||
2381 |
return m_values[index]; |
||
2382 |
} |
||
2383 |
|||
2384 |
virtual std::size_t size() const { |
||
2385 |
return m_values.size(); |
||
2386 |
} |
||
2387 |
|||
2388 |
private: |
||
2389 |
std::vector<T> m_values; |
||
2390 |
}; |
||
2391 |
|||
2392 |
template<typename T> |
||
2393 |
class CompositeGenerator { |
||
2394 |
public: |
||
2395 |
CompositeGenerator() : m_totalSize( 0 ) {} |
||
2396 |
|||
2397 |
// *** Move semantics, similar to auto_ptr *** |
||
2398 |
CompositeGenerator( CompositeGenerator& other ) |
||
2399 |
: m_fileInfo( other.m_fileInfo ), |
||
2400 |
m_totalSize( 0 ) |
||
2401 |
{ |
||
2402 |
move( other ); |
||
2403 |
} |
||
2404 |
|||
2405 |
CompositeGenerator& setFileInfo( const char* fileInfo ) { |
||
2406 |
m_fileInfo = fileInfo; |
||
2407 |
return *this; |
||
2408 |
} |
||
2409 |
|||
2410 |
~CompositeGenerator() { |
||
2411 |
deleteAll( m_composed ); |
||
2412 |
} |
||
2413 |
|||
2414 |
operator T () const { |
||
2415 |
size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); |
||
2416 |
|||
2417 |
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin(); |
||
2418 |
typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end(); |
||
2419 |
for( size_t index = 0; it != itEnd; ++it ) |
||
2420 |
{ |
||
2421 |
const IGenerator<T>* generator = *it; |
||
2422 |
if( overallIndex >= index && overallIndex < index + generator->size() ) |
||
2423 |
{ |
||
2424 |
return generator->getValue( overallIndex-index ); |
||
2425 |
} |
||
2426 |
index += generator->size(); |
||
2427 |
} |
||
2428 |
CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); |
||
2429 |
return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so |
||
2430 |
} |
||
2431 |
|||
2432 |
void add( const IGenerator<T>* generator ) { |
||
2433 |
m_totalSize += generator->size(); |
||
2434 |
m_composed.push_back( generator ); |
||
2435 |
} |
||
2436 |
|||
2437 |
CompositeGenerator& then( CompositeGenerator& other ) { |
||
2438 |
move( other ); |
||
2439 |
return *this; |
||
2440 |
} |
||
2441 |
|||
2442 |
CompositeGenerator& then( T value ) { |
||
2443 |
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
||
2444 |
valuesGen->add( value ); |
||
2445 |
add( valuesGen ); |
||
2446 |
return *this; |
||
2447 |
} |
||
2448 |
|||
2449 |
private: |
||
2450 |
|||
2451 |
void move( CompositeGenerator& other ) { |
||
2452 |
std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); |
||
2453 |
m_totalSize += other.m_totalSize; |
||
2454 |
other.m_composed.clear(); |
||
2455 |
} |
||
2456 |
|||
2457 |
std::vector<const IGenerator<T>*> m_composed; |
||
2458 |
std::string m_fileInfo; |
||
2459 |
size_t m_totalSize; |
||
2460 |
}; |
||
2461 |
|||
2462 |
namespace Generators |
||
2463 |
{ |
||
2464 |
template<typename T> |
||
2465 |
CompositeGenerator<T> between( T from, T to ) { |
||
2466 |
CompositeGenerator<T> generators; |
||
2467 |
generators.add( new BetweenGenerator<T>( from, to ) ); |
||
2468 |
return generators; |
||
2469 |
} |
||
2470 |
|||
2471 |
template<typename T> |
||
2472 |
CompositeGenerator<T> values( T val1, T val2 ) { |
||
2473 |
CompositeGenerator<T> generators; |
||
2474 |
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
||
2475 |
valuesGen->add( val1 ); |
||
2476 |
valuesGen->add( val2 ); |
||
2477 |
generators.add( valuesGen ); |
||
2478 |
return generators; |
||
2479 |
} |
||
2480 |
|||
2481 |
template<typename T> |
||
2482 |
CompositeGenerator<T> values( T val1, T val2, T val3 ){ |
||
2483 |
CompositeGenerator<T> generators; |
||
2484 |
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
||
2485 |
valuesGen->add( val1 ); |
||
2486 |
valuesGen->add( val2 ); |
||
2487 |
valuesGen->add( val3 ); |
||
2488 |
generators.add( valuesGen ); |
||
2489 |
return generators; |
||
2490 |
} |
||
2491 |
|||
2492 |
template<typename T> |
||
2493 |
CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) { |
||
2494 |
CompositeGenerator<T> generators; |
||
2495 |
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
||
2496 |
valuesGen->add( val1 ); |
||
2497 |
valuesGen->add( val2 ); |
||
2498 |
valuesGen->add( val3 ); |
||
2499 |
valuesGen->add( val4 ); |
||
2500 |
generators.add( valuesGen ); |
||
2501 |
return generators; |
||
2502 |
} |
||
2503 |
|||
2504 |
} // end namespace Generators |
||
2505 |
|||
2506 |
using namespace Generators; |
||
2507 |
|||
2508 |
} // end namespace Catch |
||
2509 |
|||
2510 |
#define INTERNAL_CATCH_LINESTR2( line ) #line |
||
2511 |
#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) |
||
2512 |
|||
2513 |
#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) |
||
2514 |
|||
2515 |
// #included from: internal/catch_interfaces_exception.h |
||
2516 |
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED |
||
2517 |
|||
2518 |
#include <string> |
||
2519 |
#include <vector> |
||
2520 |
|||
2521 |
// #included from: catch_interfaces_registry_hub.h |
||
2522 |
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED |
||
2523 |
|||
2524 |
#include <string> |
||
2525 |
|||
2526 |
namespace Catch { |
||
2527 |
|||
2528 |
class TestCase; |
||
2529 |
struct ITestCaseRegistry; |
||
2530 |
struct IExceptionTranslatorRegistry; |
||
2531 |
struct IExceptionTranslator; |
||
2532 |
struct IReporterRegistry; |
||
2533 |
struct IReporterFactory; |
||
2534 |
|||
2535 |
struct IRegistryHub { |
||
2536 |
virtual ~IRegistryHub(); |
||
2537 |
|||
2538 |
virtual IReporterRegistry const& getReporterRegistry() const = 0; |
||
2539 |
virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; |
||
2540 |
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; |
||
2541 |
}; |
||
2542 |
|||
2543 |
struct IMutableRegistryHub { |
||
2544 |
virtual ~IMutableRegistryHub(); |
||
2545 |
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0; |
||
2546 |
virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0; |
||
2547 |
virtual void registerTest( TestCase const& testInfo ) = 0; |
||
2548 |
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; |
||
2549 |
}; |
||
2550 |
|||
2551 |
IRegistryHub& getRegistryHub(); |
||
2552 |
IMutableRegistryHub& getMutableRegistryHub(); |
||
2553 |
void cleanUp(); |
||
2554 |
std::string translateActiveException(); |
||
2555 |
|||
2556 |
} |
||
2557 |
|||
2558 |
namespace Catch { |
||
2559 |
|||
2560 |
typedef std::string(*exceptionTranslateFunction)(); |
||
2561 |
|||
2562 |
struct IExceptionTranslator; |
||
2563 |
typedef std::vector<const IExceptionTranslator*> ExceptionTranslators; |
||
2564 |
|||
2565 |
struct IExceptionTranslator { |
||
2566 |
virtual ~IExceptionTranslator(); |
||
2567 |
virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; |
||
2568 |
}; |
||
2569 |
|||
2570 |
struct IExceptionTranslatorRegistry { |
||
2571 |
virtual ~IExceptionTranslatorRegistry(); |
||
2572 |
|||
2573 |
virtual std::string translateActiveException() const = 0; |
||
2574 |
}; |
||
2575 |
|||
2576 |
class ExceptionTranslatorRegistrar { |
||
2577 |
template<typename T> |
||
2578 |
class ExceptionTranslator : public IExceptionTranslator { |
||
2579 |
public: |
||
2580 |
|||
2581 |
ExceptionTranslator( std::string(*translateFunction)( T& ) ) |
||
2582 |
: m_translateFunction( translateFunction ) |
||
2583 |
{} |
||
2584 |
|||
2585 |
virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE { |
||
2586 |
try { |
||
2587 |
if( it == itEnd ) |
||
2588 |
throw; |
||
2589 |
else |
||
2590 |
return (*it)->translate( it+1, itEnd ); |
||
2591 |
} |
||
2592 |
catch( T& ex ) { |
||
2593 |
return m_translateFunction( ex ); |
||
2594 |
} |
||
2595 |
} |
||
2596 |
|||
2597 |
protected: |
||
2598 |
std::string(*m_translateFunction)( T& ); |
||
2599 |
}; |
||
2600 |
|||
2601 |
public: |
||
2602 |
template<typename T> |
||
2603 |
ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { |
||
2604 |
getMutableRegistryHub().registerTranslator |
||
2605 |
( new ExceptionTranslator<T>( translateFunction ) ); |
||
2606 |
} |
||
2607 |
}; |
||
2608 |
} |
||
2609 |
|||
2610 |
/////////////////////////////////////////////////////////////////////////////// |
||
2611 |
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ |
||
2612 |
static std::string translatorName( signature ); \ |
||
2613 |
namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\ |
||
2614 |
static std::string translatorName( signature ) |
||
2615 |
|||
2616 |
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) |
||
2617 |
|||
2618 |
// #included from: internal/catch_approx.hpp |
||
2619 |
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED |
||
2620 |
|||
2621 |
#include <cmath> |
||
2622 |
#include <limits> |
||
2623 |
|||
2624 |
namespace Catch { |
||
2625 |
namespace Detail { |
||
2626 |
|||
2627 |
class Approx { |
||
2628 |
public: |
||
2629 |
explicit Approx ( double value ) |
||
2630 |
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ), |
||
2631 |
m_scale( 1.0 ), |
||
2632 |
m_value( value ) |
||
2633 |
{} |
||
2634 |
|||
2635 |
Approx( Approx const& other ) |
||
2636 |
: m_epsilon( other.m_epsilon ), |
||
2637 |
m_scale( other.m_scale ), |
||
2638 |
m_value( other.m_value ) |
||
2639 |
{} |
||
2640 |
|||
2641 |
static Approx custom() { |
||
2642 |
return Approx( 0 ); |
||
2643 |
} |
||
2644 |
|||
2645 |
Approx operator()( double value ) { |
||
2646 |
Approx approx( value ); |
||
2647 |
approx.epsilon( m_epsilon ); |
||
2648 |
approx.scale( m_scale ); |
||
2649 |
return approx; |
||
2650 |
} |
||
2651 |
|||
2652 |
friend bool operator == ( double lhs, Approx const& rhs ) { |
||
2653 |
// Thanks to Richard Harris for his help refining this formula |
||
2654 |
return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) ); |
||
2655 |
} |
||
2656 |
|||
2657 |
friend bool operator == ( Approx const& lhs, double rhs ) { |
||
2658 |
return operator==( rhs, lhs ); |
||
2659 |
} |
||
2660 |
|||
2661 |
friend bool operator != ( double lhs, Approx const& rhs ) { |
||
2662 |
return !operator==( lhs, rhs ); |
||
2663 |
} |
||
2664 |
|||
2665 |
friend bool operator != ( Approx const& lhs, double rhs ) { |
||
2666 |
return !operator==( rhs, lhs ); |
||
2667 |
} |
||
2668 |
|||
2669 |
Approx& epsilon( double newEpsilon ) { |
||
2670 |
m_epsilon = newEpsilon; |
||
2671 |
return *this; |
||
2672 |
} |
||
2673 |
|||
2674 |
Approx& scale( double newScale ) { |
||
2675 |
m_scale = newScale; |
||
2676 |
return *this; |
||
2677 |
} |
||
2678 |
|||
2679 |
std::string toString() const { |
||
2680 |
std::ostringstream oss; |
||
2681 |
oss << "Approx( " << Catch::toString( m_value ) << " )"; |
||
2682 |
return oss.str(); |
||
2683 |
} |
||
2684 |
|||
2685 |
private: |
||
2686 |
double m_epsilon; |
||
2687 |
double m_scale; |
||
2688 |
double m_value; |
||
2689 |
}; |
||
2690 |
} |
||
2691 |
|||
2692 |
template<> |
||
2693 |
inline std::string toString<Detail::Approx>( Detail::Approx const& value ) { |
||
2694 |
return value.toString(); |
||
2695 |
} |
||
2696 |
|||
2697 |
} // end namespace Catch |
||
2698 |
|||
2699 |
// #included from: internal/catch_interfaces_tag_alias_registry.h |
||
2700 |
#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED |
||
2701 |
|||
2702 |
// #included from: catch_tag_alias.h |
||
2703 |
#define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED |
||
2704 |
|||
2705 |
#include <string> |
||
2706 |
|||
2707 |
namespace Catch { |
||
2708 |
|||
2709 |
struct TagAlias { |
||
2710 |
TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} |
||
2711 |
|||
2712 |
std::string tag; |
||
2713 |
SourceLineInfo lineInfo; |
||
2714 |
}; |
||
2715 |
|||
2716 |
struct RegistrarForTagAliases { |
||
2717 |
RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); |
||
2718 |
}; |
||
2719 |
|||
2720 |
} // end namespace Catch |
||
2721 |
|||
2722 |
#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } |
||
2723 |
// #included from: catch_option.hpp |
||
2724 |
#define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED |
||
2725 |
|||
2726 |
namespace Catch { |
||
2727 |
|||
2728 |
// An optional type |
||
2729 |
template<typename T> |
||
2730 |
class Option { |
||
2731 |
public: |
||
2732 |
4 |
Option() : nullableValue( CATCH_NULL ) {} |
|
2733 |
Option( T const& _value ) |
||
2734 |
: nullableValue( new( storage ) T( _value ) ) |
||
2735 |
{} |
||
2736 |
Option( Option const& _other ) |
||
2737 |
: nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL ) |
||
2738 |
{} |
||
2739 |
|||
2740 |
~Option() { |
||
2741 |
4 |
reset(); |
|
2742 |
} |
||
2743 |
|||
2744 |
Option& operator= ( Option const& _other ) { |
||
2745 |
if( &_other != this ) { |
||
2746 |
reset(); |
||
2747 |
if( _other ) |
||
2748 |
nullableValue = new( storage ) T( *_other ); |
||
2749 |
} |
||
2750 |
return *this; |
||
2751 |
} |
||
2752 |
396 |
Option& operator = ( T const& _value ) { |
|
2753 |
396 |
reset(); |
|
2754 |
✓✗✓✗ ✓✗✗✗ ✗✗✗✗ ✗✗ |
398 |
nullableValue = new( storage ) T( _value ); |
2755 |
396 |
return *this; |
|
2756 |
} |
||
2757 |
|||
2758 |
void reset() { |
||
2759 |
✗✓✗✓ ✗✓✗✓ ✗✓✗✓ ✓✗✓✗ ✗✗✗✗ ✗✓✗✓ ✓✗✗✗ ✗✗✗✗ ✗✗ |
797 |
if( nullableValue ) |
2760 |
396 |
nullableValue->~T(); |
|
2761 |
794 |
nullableValue = CATCH_NULL; |
|
2762 |
} |
||
2763 |
|||
2764 |
T& operator*() { return *nullableValue; } |
||
2765 |
T const& operator*() const { return *nullableValue; } |
||
2766 |
T* operator->() { return nullableValue; } |
||
2767 |
const T* operator->() const { return nullableValue; } |
||
2768 |
|||
2769 |
T valueOr( T const& defaultValue ) const { |
||
2770 |
return nullableValue ? *nullableValue : defaultValue; |
||
2771 |
} |
||
2772 |
|||
2773 |
bool some() const { return nullableValue != CATCH_NULL; } |
||
2774 |
bool none() const { return nullableValue == CATCH_NULL; } |
||
2775 |
|||
2776 |
bool operator !() const { return nullableValue == CATCH_NULL; } |
||
2777 |
operator SafeBool::type() const { |
||
2778 |
2 |
return SafeBool::makeSafe( some() ); |
|
2779 |
} |
||
2780 |
|||
2781 |
private: |
||
2782 |
T* nullableValue; |
||
2783 |
char storage[sizeof(T)]; |
||
2784 |
}; |
||
2785 |
|||
2786 |
} // end namespace Catch |
||
2787 |
|||
2788 |
namespace Catch { |
||
2789 |
|||
2790 |
struct ITagAliasRegistry { |
||
2791 |
virtual ~ITagAliasRegistry(); |
||
2792 |
virtual Option<TagAlias> find( std::string const& alias ) const = 0; |
||
2793 |
virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; |
||
2794 |
|||
2795 |
static ITagAliasRegistry const& get(); |
||
2796 |
}; |
||
2797 |
|||
2798 |
} // end namespace Catch |
||
2799 |
|||
2800 |
// These files are included here so the single_include script doesn't put them |
||
2801 |
// in the conditionally compiled sections |
||
2802 |
// #included from: internal/catch_test_case_info.h |
||
2803 |
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED |
||
2804 |
|||
2805 |
#include <string> |
||
2806 |
#include <set> |
||
2807 |
|||
2808 |
#ifdef __clang__ |
||
2809 |
#pragma clang diagnostic push |
||
2810 |
#pragma clang diagnostic ignored "-Wpadded" |
||
2811 |
#endif |
||
2812 |
|||
2813 |
namespace Catch { |
||
2814 |
|||
2815 |
struct ITestCase; |
||
2816 |
|||
2817 |
29304 |
struct TestCaseInfo { |
|
2818 |
enum SpecialProperties{ |
||
2819 |
None = 0, |
||
2820 |
IsHidden = 1 << 1, |
||
2821 |
ShouldFail = 1 << 2, |
||
2822 |
MayFail = 1 << 3, |
||
2823 |
Throws = 1 << 4 |
||
2824 |
}; |
||
2825 |
|||
2826 |
TestCaseInfo( std::string const& _name, |
||
2827 |
std::string const& _className, |
||
2828 |
std::string const& _description, |
||
2829 |
std::set<std::string> const& _tags, |
||
2830 |
SourceLineInfo const& _lineInfo ); |
||
2831 |
|||
2832 |
TestCaseInfo( TestCaseInfo const& other ); |
||
2833 |
|||
2834 |
friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags ); |
||
2835 |
|||
2836 |
bool isHidden() const; |
||
2837 |
bool throws() const; |
||
2838 |
bool okToFail() const; |
||
2839 |
bool expectedToFail() const; |
||
2840 |
|||
2841 |
std::string name; |
||
2842 |
std::string className; |
||
2843 |
std::string description; |
||
2844 |
std::set<std::string> tags; |
||
2845 |
std::set<std::string> lcaseTags; |
||
2846 |
std::string tagsAsString; |
||
2847 |
SourceLineInfo lineInfo; |
||
2848 |
SpecialProperties properties; |
||
2849 |
}; |
||
2850 |
|||
2851 |
4174 |
class TestCase : public TestCaseInfo { |
|
2852 |
public: |
||
2853 |
|||
2854 |
TestCase( ITestCase* testCase, TestCaseInfo const& info ); |
||
2855 |
TestCase( TestCase const& other ); |
||
2856 |
|||
2857 |
TestCase withName( std::string const& _newName ) const; |
||
2858 |
|||
2859 |
void invoke() const; |
||
2860 |
|||
2861 |
TestCaseInfo const& getTestCaseInfo() const; |
||
2862 |
|||
2863 |
void swap( TestCase& other ); |
||
2864 |
bool operator == ( TestCase const& other ) const; |
||
2865 |
bool operator < ( TestCase const& other ) const; |
||
2866 |
TestCase& operator = ( TestCase const& other ); |
||
2867 |
|||
2868 |
private: |
||
2869 |
Ptr<ITestCase> test; |
||
2870 |
}; |
||
2871 |
|||
2872 |
TestCase makeTestCase( ITestCase* testCase, |
||
2873 |
std::string const& className, |
||
2874 |
std::string const& name, |
||
2875 |
std::string const& description, |
||
2876 |
SourceLineInfo const& lineInfo ); |
||
2877 |
} |
||
2878 |
|||
2879 |
#ifdef __clang__ |
||
2880 |
#pragma clang diagnostic pop |
||
2881 |
#endif |
||
2882 |
|||
2883 |
|||
2884 |
#ifdef __OBJC__ |
||
2885 |
// #included from: internal/catch_objc.hpp |
||
2886 |
#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED |
||
2887 |
|||
2888 |
#import <objc/runtime.h> |
||
2889 |
|||
2890 |
#include <string> |
||
2891 |
|||
2892 |
// NB. Any general catch headers included here must be included |
||
2893 |
// in catch.hpp first to make sure they are included by the single |
||
2894 |
// header for non obj-usage |
||
2895 |
|||
2896 |
/////////////////////////////////////////////////////////////////////////////// |
||
2897 |
// This protocol is really only here for (self) documenting purposes, since |
||
2898 |
// all its methods are optional. |
||
2899 |
@protocol OcFixture |
||
2900 |
|||
2901 |
@optional |
||
2902 |
|||
2903 |
-(void) setUp; |
||
2904 |
-(void) tearDown; |
||
2905 |
|||
2906 |
@end |
||
2907 |
|||
2908 |
namespace Catch { |
||
2909 |
|||
2910 |
class OcMethod : public SharedImpl<ITestCase> { |
||
2911 |
|||
2912 |
public: |
||
2913 |
OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} |
||
2914 |
|||
2915 |
virtual void invoke() const { |
||
2916 |
id obj = [[m_cls alloc] init]; |
||
2917 |
|||
2918 |
performOptionalSelector( obj, @selector(setUp) ); |
||
2919 |
performOptionalSelector( obj, m_sel ); |
||
2920 |
performOptionalSelector( obj, @selector(tearDown) ); |
||
2921 |
|||
2922 |
arcSafeRelease( obj ); |
||
2923 |
} |
||
2924 |
private: |
||
2925 |
virtual ~OcMethod() {} |
||
2926 |
|||
2927 |
Class m_cls; |
||
2928 |
SEL m_sel; |
||
2929 |
}; |
||
2930 |
|||
2931 |
namespace Detail{ |
||
2932 |
|||
2933 |
inline std::string getAnnotation( Class cls, |
||
2934 |
std::string const& annotationName, |
||
2935 |
std::string const& testCaseName ) { |
||
2936 |
NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; |
||
2937 |
SEL sel = NSSelectorFromString( selStr ); |
||
2938 |
arcSafeRelease( selStr ); |
||
2939 |
id value = performOptionalSelector( cls, sel ); |
||
2940 |
if( value ) |
||
2941 |
return [(NSString*)value UTF8String]; |
||
2942 |
return ""; |
||
2943 |
} |
||
2944 |
} |
||
2945 |
|||
2946 |
inline size_t registerTestMethods() { |
||
2947 |
size_t noTestMethods = 0; |
||
2948 |
int noClasses = objc_getClassList( CATCH_NULL, 0 ); |
||
2949 |
|||
2950 |
Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); |
||
2951 |
objc_getClassList( classes, noClasses ); |
||
2952 |
|||
2953 |
for( int c = 0; c < noClasses; c++ ) { |
||
2954 |
Class cls = classes[c]; |
||
2955 |
{ |
||
2956 |
u_int count; |
||
2957 |
Method* methods = class_copyMethodList( cls, &count ); |
||
2958 |
for( u_int m = 0; m < count ; m++ ) { |
||
2959 |
SEL selector = method_getName(methods[m]); |
||
2960 |
std::string methodName = sel_getName(selector); |
||
2961 |
if( startsWith( methodName, "Catch_TestCase_" ) ) { |
||
2962 |
std::string testCaseName = methodName.substr( 15 ); |
||
2963 |
std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); |
||
2964 |
std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); |
||
2965 |
const char* className = class_getName( cls ); |
||
2966 |
|||
2967 |
getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); |
||
2968 |
noTestMethods++; |
||
2969 |
} |
||
2970 |
} |
||
2971 |
free(methods); |
||
2972 |
} |
||
2973 |
} |
||
2974 |
return noTestMethods; |
||
2975 |
} |
||
2976 |
|||
2977 |
namespace Matchers { |
||
2978 |
namespace Impl { |
||
2979 |
namespace NSStringMatchers { |
||
2980 |
|||
2981 |
template<typename MatcherT> |
||
2982 |
struct StringHolder : MatcherImpl<MatcherT, NSString*>{ |
||
2983 |
StringHolder( NSString* substr ) : m_substr( [substr copy] ){} |
||
2984 |
StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} |
||
2985 |
StringHolder() { |
||
2986 |
arcSafeRelease( m_substr ); |
||
2987 |
} |
||
2988 |
|||
2989 |
NSString* m_substr; |
||
2990 |
}; |
||
2991 |
|||
2992 |
struct Equals : StringHolder<Equals> { |
||
2993 |
Equals( NSString* substr ) : StringHolder( substr ){} |
||
2994 |
|||
2995 |
virtual bool match( ExpressionType const& str ) const { |
||
2996 |
return (str != nil || m_substr == nil ) && |
||
2997 |
[str isEqualToString:m_substr]; |
||
2998 |
} |
||
2999 |
|||
3000 |
virtual std::string toString() const { |
||
3001 |
return "equals string: " + Catch::toString( m_substr ); |
||
3002 |
} |
||
3003 |
}; |
||
3004 |
|||
3005 |
struct Contains : StringHolder<Contains> { |
||
3006 |
Contains( NSString* substr ) : StringHolder( substr ){} |
||
3007 |
|||
3008 |
virtual bool match( ExpressionType const& str ) const { |
||
3009 |
return (str != nil || m_substr == nil ) && |
||
3010 |
[str rangeOfString:m_substr].location != NSNotFound; |
||
3011 |
} |
||
3012 |
|||
3013 |
virtual std::string toString() const { |
||
3014 |
return "contains string: " + Catch::toString( m_substr ); |
||
3015 |
} |
||
3016 |
}; |
||
3017 |
|||
3018 |
struct StartsWith : StringHolder<StartsWith> { |
||
3019 |
StartsWith( NSString* substr ) : StringHolder( substr ){} |
||
3020 |
|||
3021 |
virtual bool match( ExpressionType const& str ) const { |
||
3022 |
return (str != nil || m_substr == nil ) && |
||
3023 |
[str rangeOfString:m_substr].location == 0; |
||
3024 |
} |
||
3025 |
|||
3026 |
virtual std::string toString() const { |
||
3027 |
return "starts with: " + Catch::toString( m_substr ); |
||
3028 |
} |
||
3029 |
}; |
||
3030 |
struct EndsWith : StringHolder<EndsWith> { |
||
3031 |
EndsWith( NSString* substr ) : StringHolder( substr ){} |
||
3032 |
|||
3033 |
virtual bool match( ExpressionType const& str ) const { |
||
3034 |
return (str != nil || m_substr == nil ) && |
||
3035 |
[str rangeOfString:m_substr].location == [str length] - [m_substr length]; |
||
3036 |
} |
||
3037 |
|||
3038 |
virtual std::string toString() const { |
||
3039 |
return "ends with: " + Catch::toString( m_substr ); |
||
3040 |
} |
||
3041 |
}; |
||
3042 |
|||
3043 |
} // namespace NSStringMatchers |
||
3044 |
} // namespace Impl |
||
3045 |
|||
3046 |
inline Impl::NSStringMatchers::Equals |
||
3047 |
Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } |
||
3048 |
|||
3049 |
inline Impl::NSStringMatchers::Contains |
||
3050 |
Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } |
||
3051 |
|||
3052 |
inline Impl::NSStringMatchers::StartsWith |
||
3053 |
StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } |
||
3054 |
|||
3055 |
inline Impl::NSStringMatchers::EndsWith |
||
3056 |
EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } |
||
3057 |
|||
3058 |
} // namespace Matchers |
||
3059 |
|||
3060 |
using namespace Matchers; |
||
3061 |
|||
3062 |
} // namespace Catch |
||
3063 |
|||
3064 |
/////////////////////////////////////////////////////////////////////////////// |
||
3065 |
#define OC_TEST_CASE( name, desc )\ |
||
3066 |
+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ |
||
3067 |
{\ |
||
3068 |
return @ name; \ |
||
3069 |
}\ |
||
3070 |
+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ |
||
3071 |
{ \ |
||
3072 |
return @ desc; \ |
||
3073 |
} \ |
||
3074 |
-(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) |
||
3075 |
|||
3076 |
#endif |
||
3077 |
|||
3078 |
#ifdef CATCH_IMPL |
||
3079 |
// #included from: internal/catch_impl.hpp |
||
3080 |
#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED |
||
3081 |
|||
3082 |
// Collect all the implementation files together here |
||
3083 |
// These are the equivalent of what would usually be cpp files |
||
3084 |
|||
3085 |
#ifdef __clang__ |
||
3086 |
#pragma clang diagnostic push |
||
3087 |
#pragma clang diagnostic ignored "-Wweak-vtables" |
||
3088 |
#endif |
||
3089 |
|||
3090 |
// #included from: ../catch_session.hpp |
||
3091 |
#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED |
||
3092 |
|||
3093 |
// #included from: internal/catch_commandline.hpp |
||
3094 |
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED |
||
3095 |
|||
3096 |
// #included from: catch_config.hpp |
||
3097 |
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED |
||
3098 |
|||
3099 |
// #included from: catch_test_spec_parser.hpp |
||
3100 |
#define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED |
||
3101 |
|||
3102 |
#ifdef __clang__ |
||
3103 |
#pragma clang diagnostic push |
||
3104 |
#pragma clang diagnostic ignored "-Wpadded" |
||
3105 |
#endif |
||
3106 |
|||
3107 |
// #included from: catch_test_spec.hpp |
||
3108 |
#define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED |
||
3109 |
|||
3110 |
#ifdef __clang__ |
||
3111 |
#pragma clang diagnostic push |
||
3112 |
#pragma clang diagnostic ignored "-Wpadded" |
||
3113 |
#endif |
||
3114 |
|||
3115 |
// #included from: catch_wildcard_pattern.hpp |
||
3116 |
#define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED |
||
3117 |
|||
3118 |
namespace Catch |
||
3119 |
{ |
||
3120 |
class WildcardPattern { |
||
3121 |
enum WildcardPosition { |
||
3122 |
NoWildcard = 0, |
||
3123 |
WildcardAtStart = 1, |
||
3124 |
WildcardAtEnd = 2, |
||
3125 |
WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd |
||
3126 |
}; |
||
3127 |
|||
3128 |
public: |
||
3129 |
|||
3130 |
WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ) |
||
3131 |
: m_caseSensitivity( caseSensitivity ), |
||
3132 |
m_wildcard( NoWildcard ), |
||
3133 |
m_pattern( adjustCase( pattern ) ) |
||
3134 |
{ |
||
3135 |
if( startsWith( m_pattern, "*" ) ) { |
||
3136 |
m_pattern = m_pattern.substr( 1 ); |
||
3137 |
m_wildcard = WildcardAtStart; |
||
3138 |
} |
||
3139 |
if( endsWith( m_pattern, "*" ) ) { |
||
3140 |
m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); |
||
3141 |
m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd ); |
||
3142 |
} |
||
3143 |
} |
||
3144 |
virtual ~WildcardPattern(); |
||
3145 |
virtual bool matches( std::string const& str ) const { |
||
3146 |
switch( m_wildcard ) { |
||
3147 |
case NoWildcard: |
||
3148 |
return m_pattern == adjustCase( str ); |
||
3149 |
case WildcardAtStart: |
||
3150 |
return endsWith( adjustCase( str ), m_pattern ); |
||
3151 |
case WildcardAtEnd: |
||
3152 |
return startsWith( adjustCase( str ), m_pattern ); |
||
3153 |
case WildcardAtBothEnds: |
||
3154 |
return contains( adjustCase( str ), m_pattern ); |
||
3155 |
} |
||
3156 |
|||
3157 |
#ifdef __clang__ |
||
3158 |
#pragma clang diagnostic push |
||
3159 |
#pragma clang diagnostic ignored "-Wunreachable-code" |
||
3160 |
#endif |
||
3161 |
throw std::logic_error( "Unknown enum" ); |
||
3162 |
#ifdef __clang__ |
||
3163 |
#pragma clang diagnostic pop |
||
3164 |
#endif |
||
3165 |
} |
||
3166 |
private: |
||
3167 |
std::string adjustCase( std::string const& str ) const { |
||
3168 |
return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; |
||
3169 |
} |
||
3170 |
CaseSensitive::Choice m_caseSensitivity; |
||
3171 |
WildcardPosition m_wildcard; |
||
3172 |
std::string m_pattern; |
||
3173 |
}; |
||
3174 |
} |
||
3175 |
|||
3176 |
#include <string> |
||
3177 |
#include <vector> |
||
3178 |
|||
3179 |
namespace Catch { |
||
3180 |
|||
3181 |
✗✓✗✓ ✗✗✗✗ ✗✗✗✗ |
12 |
class TestSpec { |
3182 |
4 |
struct Pattern : SharedImpl<> { |
|
3183 |
virtual ~Pattern(); |
||
3184 |
virtual bool matches( TestCaseInfo const& testCase ) const = 0; |
||
3185 |
}; |
||
3186 |
class NamePattern : public Pattern { |
||
3187 |
public: |
||
3188 |
NamePattern( std::string const& name ) |
||
3189 |
: m_wildcardPattern( toLower( name ), CaseSensitive::No ) |
||
3190 |
{} |
||
3191 |
virtual ~NamePattern(); |
||
3192 |
virtual bool matches( TestCaseInfo const& testCase ) const { |
||
3193 |
return m_wildcardPattern.matches( toLower( testCase.name ) ); |
||
3194 |
} |
||
3195 |
private: |
||
3196 |
WildcardPattern m_wildcardPattern; |
||
3197 |
}; |
||
3198 |
|||
3199 |
class TagPattern : public Pattern { |
||
3200 |
public: |
||
3201 |
3 |
TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} |
|
3202 |
virtual ~TagPattern(); |
||
3203 |
394 |
virtual bool matches( TestCaseInfo const& testCase ) const { |
|
3204 |
1576 |
return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); |
|
3205 |
} |
||
3206 |
private: |
||
3207 |
std::string m_tag; |
||
3208 |
}; |
||
3209 |
|||
3210 |
class ExcludedPattern : public Pattern { |
||
3211 |
public: |
||
3212 |
3 |
ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} |
|
3213 |
virtual ~ExcludedPattern(); |
||
3214 |
788 |
virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } |
|
3215 |
private: |
||
3216 |
Ptr<Pattern> m_underlyingPattern; |
||
3217 |
}; |
||
3218 |
|||
3219 |
✓✗✓✗ |
12 |
struct Filter { |
3220 |
std::vector<Ptr<Pattern> > m_patterns; |
||
3221 |
|||
3222 |
bool matches( TestCaseInfo const& testCase ) const { |
||
3223 |
// All patterns in a filter must match for the filter to be a match |
||
3224 |
✓✓ | 1970 |
for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) |
3225 |
✓✗ | 788 |
if( !(*it)->matches( testCase ) ) |
3226 |
return false; |
||
3227 |
return true; |
||
3228 |
} |
||
3229 |
}; |
||
3230 |
|||
3231 |
public: |
||
3232 |
bool hasFilters() const { |
||
3233 |
2 |
return !m_filters.empty(); |
|
3234 |
} |
||
3235 |
394 |
bool matches( TestCaseInfo const& testCase ) const { |
|
3236 |
// A TestSpec matches if any filter matches |
||
3237 |
✓✗ | 1576 |
for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) |
3238 |
✗✓ | 788 |
if( it->matches( testCase ) ) |
3239 |
return true; |
||
3240 |
return false; |
||
3241 |
} |
||
3242 |
|||
3243 |
private: |
||
3244 |
std::vector<Filter> m_filters; |
||
3245 |
|||
3246 |
friend class TestSpecParser; |
||
3247 |
}; |
||
3248 |
} |
||
3249 |
|||
3250 |
#ifdef __clang__ |
||
3251 |
#pragma clang diagnostic pop |
||
3252 |
#endif |
||
3253 |
|||
3254 |
namespace Catch { |
||
3255 |
|||
3256 |
4 |
class TestSpecParser { |
|
3257 |
enum Mode{ None, Name, QuotedName, Tag }; |
||
3258 |
Mode m_mode; |
||
3259 |
bool m_exclusion; |
||
3260 |
std::size_t m_start, m_pos; |
||
3261 |
std::string m_arg; |
||
3262 |
TestSpec::Filter m_currentFilter; |
||
3263 |
TestSpec m_testSpec; |
||
3264 |
ITagAliasRegistry const* m_tagAliases; |
||
3265 |
|||
3266 |
public: |
||
3267 |
4 |
TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} |
|
3268 |
|||
3269 |
1 |
TestSpecParser& parse( std::string const& arg ) { |
|
3270 |
1 |
m_mode = None; |
|
3271 |
1 |
m_exclusion = false; |
|
3272 |
1 |
m_start = std::string::npos; |
|
3273 |
2 |
m_arg = m_tagAliases->expandAliases( arg ); |
|
3274 |
✓✓ | 4 |
for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) |
3275 |
6 |
visitChar( m_arg[m_pos] ); |
|
3276 |
✗✓ | 1 |
if( m_mode == Name ) |
3277 |
addPattern<TestSpec::NamePattern>(); |
||
3278 |
1 |
return *this; |
|
3279 |
} |
||
3280 |
TestSpec testSpec() { |
||
3281 |
✓✗✗✗ ✗✗✗✗ ✗✗ |
1 |
addFilter(); |
3282 |
2 |
return m_testSpec; |
|
3283 |
} |
||
3284 |
private: |
||
3285 |
3 |
void visitChar( char c ) { |
|
3286 |
✓✓ | 3 |
if( m_mode == None ) { |
3287 |
✓✓✗✗ ✗ |
2 |
switch( c ) { |
3288 |
case ' ': return; |
||
3289 |
1 |
case '~': m_exclusion = true; return; |
|
3290 |
1 |
case '[': return startNewMode( Tag, ++m_pos ); |
|
3291 |
case '"': return startNewMode( QuotedName, ++m_pos ); |
||
3292 |
default: startNewMode( Name, m_pos ); break; |
||
3293 |
} |
||
3294 |
} |
||
3295 |
✗✓ | 1 |
if( m_mode == Name ) { |
3296 |
if( c == ',' ) { |
||
3297 |
addPattern<TestSpec::NamePattern>(); |
||
3298 |
addFilter(); |
||
3299 |
} |
||
3300 |
else if( c == '[' ) { |
||
3301 |
if( subString() == "exclude:" ) |
||
3302 |
m_exclusion = true; |
||
3303 |
else |
||
3304 |
addPattern<TestSpec::NamePattern>(); |
||
3305 |
startNewMode( Tag, ++m_pos ); |
||
3306 |
} |
||
3307 |
} |
||
3308 |
✗✓✗✗ |
1 |
else if( m_mode == QuotedName && c == '"' ) |
3309 |
addPattern<TestSpec::NamePattern>(); |
||
3310 |
✓✗✓✗ |
1 |
else if( m_mode == Tag && c == ']' ) |
3311 |
1 |
addPattern<TestSpec::TagPattern>(); |
|
3312 |
} |
||
3313 |
void startNewMode( Mode mode, std::size_t start ) { |
||
3314 |
1 |
m_mode = mode; |
|
3315 |
1 |
m_start = start; |
|
3316 |
} |
||
3317 |
1 |
std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } |
|
3318 |
template<typename T> |
||
3319 |
1 |
void addPattern() { |
|
3320 |
2 |
std::string token = subString(); |
|
3321 |
✓✗✓✗ ✗✓✗✗ ✗✗✗✗ |
4 |
if( startsWith( token, "exclude:" ) ) { |
3322 |
m_exclusion = true; |
||
3323 |
token = token.substr( 8 ); |
||
3324 |
} |
||
3325 |
✓✗✗✗ |
1 |
if( !token.empty() ) { |
3326 |
✓✗✓✗ ✗✗✗✗ |
3 |
Ptr<TestSpec::Pattern> pattern = new T( token ); |
3327 |
✓✗✗✗ |
1 |
if( m_exclusion ) |
3328 |
✓✗✗✗ |
2 |
pattern = new TestSpec::ExcludedPattern( pattern ); |
3329 |
✓✗✗✗ |
1 |
m_currentFilter.m_patterns.push_back( pattern ); |
3330 |
} |
||
3331 |
1 |
m_exclusion = false; |
|
3332 |
1 |
m_mode = None; |
|
3333 |
1 |
} |
|
3334 |
1 |
void addFilter() { |
|
3335 |
✓✗ | 2 |
if( !m_currentFilter.m_patterns.empty() ) { |
3336 |
1 |
m_testSpec.m_filters.push_back( m_currentFilter ); |
|
3337 |
4 |
m_currentFilter = TestSpec::Filter(); |
|
333 |