diff options
| author | Phil Nash | 2015-07-23 19:03:33 +0100 |
|---|---|---|
| committer | Phil Nash | 2015-07-23 23:05:05 +0100 |
| commit | 733ebb6024d6b6ff60ef96b9f761828e6eff6ae7 (patch) | |
| tree | 15f230026099d84782a4449942ff2ce0bcc42c4b /include | |
| parent | d6e59cd56f196eb40cbec3223531ee8d98e8ac8f (diff) | |
| download | catch3-733ebb6024d6b6ff60ef96b9f761828e6eff6ae7.tar.gz | |
Added CATCH_CONFIG_CPP11_LONG_LONG support
Diffstat (limited to 'include')
| -rw-r--r-- | include/internal/catch_compiler_capabilities.h | 10 | ||||
| -rw-r--r-- | include/internal/catch_evaluate.hpp | 42 | ||||
| -rw-r--r-- | include/internal/catch_tostring.h | 7 | ||||
| -rw-r--r-- | include/internal/catch_tostring.hpp | 27 | ||||
| -rw-r--r-- | include/internal/catch_xmlwriter.hpp | 3 |
5 files changed, 81 insertions, 8 deletions
diff --git a/include/internal/catch_compiler_capabilities.h b/include/internal/catch_compiler_capabilities.h index db8100f0..a5847545 100644 --- a/include/internal/catch_compiler_capabilities.h +++ b/include/internal/catch_compiler_capabilities.h @@ -16,6 +16,7 @@ // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported +// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? @@ -130,6 +131,10 @@ # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS # endif +# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) +# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG +# endif + #endif // __cplusplus >= 201103L // Now set the actual defines based on the above + anything the user has configured @@ -149,7 +154,10 @@ # define CATCH_CONFIG_CPP11_TUPLE #endif #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) -#define CATCH_CONFIG_VARIADIC_MACROS +# define CATCH_CONFIG_VARIADIC_MACROS +#endif +#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) +# define CATCH_CONFIG_CPP11_LONG_LONG #endif diff --git a/include/internal/catch_evaluate.hpp b/include/internal/catch_evaluate.hpp index ab9db784..76f19e2a 100644 --- a/include/internal/catch_evaluate.hpp +++ b/include/internal/catch_evaluate.hpp @@ -160,13 +160,51 @@ namespace Internal { return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); } +#ifdef CATCH_CONFIG_CPP11_LONG_LONG + // long long to unsigned X + template<Operator Op> bool compare( long long lhs, unsigned int rhs ) { + return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); + } + template<Operator Op> bool compare( long long lhs, unsigned long rhs ) { + return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); + } + template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) { + return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); + } + template<Operator Op> bool compare( long long lhs, unsigned char rhs ) { + return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); + } + + // unsigned long long to X + template<Operator Op> bool compare( unsigned long long lhs, int rhs ) { + return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); + } + template<Operator Op> bool compare( unsigned long long lhs, long rhs ) { + return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); + } + template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) { + return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); + } + template<Operator Op> bool compare( unsigned long long lhs, char rhs ) { + return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); + } + + // pointer to long long (when comparing against NULL) + template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) { + return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); + } + template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) { + return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); + } +#endif // CATCH_CONFIG_CPP11_LONG_LONG + #ifdef CATCH_CONFIG_CPP11_NULLPTR // pointer to nullptr_t (when comparing against nullptr) template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { - return Evaluator<T*, T*, Op>::evaluate( CATCH_NULL, rhs ); + return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs ); } template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) { - return Evaluator<T*, T*, Op>::evaluate( lhs, CATCH_NULL ); + return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr ); } #endif // CATCH_CONFIG_CPP11_NULLPTR diff --git a/include/internal/catch_tostring.h b/include/internal/catch_tostring.h index 8efb9be3..91bc106a 100644 --- a/include/internal/catch_tostring.h +++ b/include/internal/catch_tostring.h @@ -52,6 +52,11 @@ std::string toString( char value ); std::string toString( signed char value ); std::string toString( unsigned char value ); +#ifdef CATCH_CONFIG_CPP11_LONG_LONG +std::string toString( long long value ); +std::string toString( unsigned long long value ); +#endif + #ifdef CATCH_CONFIG_CPP11_NULLPTR std::string toString( std::nullptr_t ); #endif @@ -65,7 +70,7 @@ std::string toString( std::nullptr_t ); namespace Detail { - extern std::string unprintableString; + extern const std::string unprintableString; struct BorgType { template<typename T> BorgType( T const& ); diff --git a/include/internal/catch_tostring.hpp b/include/internal/catch_tostring.hpp index 60f8f823..50b587d1 100644 --- a/include/internal/catch_tostring.hpp +++ b/include/internal/catch_tostring.hpp @@ -15,9 +15,11 @@ namespace Catch { namespace Detail { - std::string unprintableString = "{?}"; - + const std::string unprintableString = "{?}"; + namespace { + const int hexThreshold = 255; + struct Endianness { enum Arch { Big, Little }; @@ -99,7 +101,7 @@ std::string toString( wchar_t* const value ) std::string toString( int value ) { std::ostringstream oss; oss << value; - if( value >= 255 ) + if( value > Detail::hexThreshold ) oss << " (0x" << std::hex << value << ")"; return oss.str(); } @@ -107,7 +109,7 @@ std::string toString( int value ) { std::string toString( unsigned long value ) { std::ostringstream oss; oss << value; - if( value >= 255 ) + if( value > Detail::hexThreshold ) oss << " (0x" << std::hex << value << ")"; return oss.str(); } @@ -157,6 +159,23 @@ std::string toString( unsigned char value ) { return toString( static_cast<char>( value ) ); } +#ifdef CATCH_CONFIG_CPP11_LONG_LONG +std::string toString( long long value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ")"; + return oss.str(); +} +std::string toString( unsigned long long value ) { + std::ostringstream oss; + oss << value; + if( value > Detail::hexThreshold ) + oss << " (0x" << std::hex << value << ")"; + return oss.str(); +} +#endif + #ifdef CATCH_CONFIG_CPP11_NULLPTR std::string toString( std::nullptr_t ) { return "nullptr"; diff --git a/include/internal/catch_xmlwriter.hpp b/include/internal/catch_xmlwriter.hpp index 5f2e87e5..738415c3 100644 --- a/include/internal/catch_xmlwriter.hpp +++ b/include/internal/catch_xmlwriter.hpp @@ -10,6 +10,7 @@ #include "catch_stream.h" #include "catch_compiler_capabilities.h" +#include "catch_suppress_warnings.h" #include <sstream> #include <string> @@ -231,4 +232,6 @@ namespace Catch { }; } +#include "catch_reenable_warnings.h" + #endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED |