mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 15:26:11 +01:00
Added CATCH_CONFIG_CPP11_LONG_LONG support
This commit is contained in:
parent
d6e59cd56f
commit
733ebb6024
@ -16,6 +16,7 @@
|
|||||||
// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
|
// 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_IS_ENUM : std::is_enum is supported?
|
||||||
// CATCH_CONFIG_CPP11_TUPLE : std::tuple 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?
|
// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
|
||||||
|
|
||||||
@ -130,6 +131,10 @@
|
|||||||
# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
|
# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
|
||||||
|
# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
|
||||||
|
# endif
|
||||||
|
|
||||||
#endif // __cplusplus >= 201103L
|
#endif // __cplusplus >= 201103L
|
||||||
|
|
||||||
// Now set the actual defines based on the above + anything the user has configured
|
// Now set the actual defines based on the above + anything the user has configured
|
||||||
@ -149,7 +154,10 @@
|
|||||||
# define CATCH_CONFIG_CPP11_TUPLE
|
# define CATCH_CONFIG_CPP11_TUPLE
|
||||||
#endif
|
#endif
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,13 +160,51 @@ namespace Internal {
|
|||||||
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
|
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
|
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
||||||
// pointer to nullptr_t (when comparing against nullptr)
|
// pointer to nullptr_t (when comparing against nullptr)
|
||||||
template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
|
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 ) {
|
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
|
#endif // CATCH_CONFIG_CPP11_NULLPTR
|
||||||
|
|
||||||
|
@ -52,6 +52,11 @@ std::string toString( char value );
|
|||||||
std::string toString( signed char value );
|
std::string toString( signed char value );
|
||||||
std::string toString( unsigned 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
|
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
||||||
std::string toString( std::nullptr_t );
|
std::string toString( std::nullptr_t );
|
||||||
#endif
|
#endif
|
||||||
@ -65,7 +70,7 @@ std::string toString( std::nullptr_t );
|
|||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
|
|
||||||
extern std::string unprintableString;
|
extern const std::string unprintableString;
|
||||||
|
|
||||||
struct BorgType {
|
struct BorgType {
|
||||||
template<typename T> BorgType( T const& );
|
template<typename T> BorgType( T const& );
|
||||||
|
@ -15,9 +15,11 @@ namespace Catch {
|
|||||||
|
|
||||||
namespace Detail {
|
namespace Detail {
|
||||||
|
|
||||||
std::string unprintableString = "{?}";
|
const std::string unprintableString = "{?}";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
const int hexThreshold = 255;
|
||||||
|
|
||||||
struct Endianness {
|
struct Endianness {
|
||||||
enum Arch { Big, Little };
|
enum Arch { Big, Little };
|
||||||
|
|
||||||
@ -99,7 +101,7 @@ std::string toString( wchar_t* const value )
|
|||||||
std::string toString( int value ) {
|
std::string toString( int value ) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << value;
|
oss << value;
|
||||||
if( value >= 255 )
|
if( value > Detail::hexThreshold )
|
||||||
oss << " (0x" << std::hex << value << ")";
|
oss << " (0x" << std::hex << value << ")";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
@ -107,7 +109,7 @@ std::string toString( int value ) {
|
|||||||
std::string toString( unsigned long value ) {
|
std::string toString( unsigned long value ) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << value;
|
oss << value;
|
||||||
if( value >= 255 )
|
if( value > Detail::hexThreshold )
|
||||||
oss << " (0x" << std::hex << value << ")";
|
oss << " (0x" << std::hex << value << ")";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
@ -157,6 +159,23 @@ std::string toString( unsigned char value ) {
|
|||||||
return toString( static_cast<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
|
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
||||||
std::string toString( std::nullptr_t ) {
|
std::string toString( std::nullptr_t ) {
|
||||||
return "nullptr";
|
return "nullptr";
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "catch_stream.h"
|
#include "catch_stream.h"
|
||||||
#include "catch_compiler_capabilities.h"
|
#include "catch_compiler_capabilities.h"
|
||||||
|
#include "catch_suppress_warnings.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -231,4 +232,6 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
#include "catch_reenable_warnings.h"
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
|
||||||
|
@ -418,6 +418,14 @@ TEST_CASE( "XmlEncode" ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CATCH_CONFIG_CPP11_LONG_LONG
|
||||||
|
TEST_CASE( "long long" ) {
|
||||||
|
long long l = std::numeric_limits<long long>::max();
|
||||||
|
|
||||||
|
REQUIRE( l == std::numeric_limits<long long>::max() );
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
//TEST_CASE( "Divide by Zero signal handler", "[.][sig]" ) {
|
//TEST_CASE( "Divide by Zero signal handler", "[.][sig]" ) {
|
||||||
// int i = 0;
|
// int i = 0;
|
||||||
// int x = 10/i; // This should cause the signal to fire
|
// int x = 10/i; // This should cause the signal to fire
|
||||||
|
Loading…
Reference in New Issue
Block a user