mirror of https://github.com/catchorg/Catch2.git
Fix for comparing (const) char* to NULL
This commit is contained in:
parent
a201f715a8
commit
e1cb8f25f2
|
@ -174,16 +174,26 @@ namespace Internal
|
||||||
template<Operator Op, typename T>
|
template<Operator Op, typename T>
|
||||||
bool compare( long lhs, const T* rhs )
|
bool compare( long lhs, const T* rhs )
|
||||||
{
|
{
|
||||||
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( NULL ), rhs );
|
return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<Operator Op, typename T>
|
template<Operator Op, typename T>
|
||||||
bool compare( long lhs, T* rhs )
|
bool compare( long lhs, T* rhs )
|
||||||
{
|
{
|
||||||
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
|
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<Operator Op, typename T>
|
||||||
|
bool compare( const T* lhs, long rhs )
|
||||||
|
{
|
||||||
|
return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<Operator Op, typename T>
|
||||||
|
bool compare( T* lhs, long rhs )
|
||||||
|
{
|
||||||
|
return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace Internal
|
} // end of namespace Internal
|
||||||
} // end of namespace Catch
|
} // end of namespace Catch
|
||||||
|
|
|
@ -221,6 +221,9 @@ TEST_CASE( "succeeding/conditions/negative ints",
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
inline const char* returnsConstNull(){ return NULL; }
|
||||||
|
inline char* returnsNull(){ return NULL; }
|
||||||
|
|
||||||
TEST_CASE( "./succeeding/conditions/ptr",
|
TEST_CASE( "./succeeding/conditions/ptr",
|
||||||
"Pointers can be compared to null" )
|
"Pointers can be compared to null" )
|
||||||
{
|
{
|
||||||
|
@ -241,6 +244,9 @@ TEST_CASE( "./succeeding/conditions/ptr",
|
||||||
const TestData* const cpc = p;
|
const TestData* const cpc = p;
|
||||||
REQUIRE( cpc != NULL );
|
REQUIRE( cpc != NULL );
|
||||||
|
|
||||||
|
REQUIRE( returnsNull() == NULL );
|
||||||
|
REQUIRE( returnsConstNull() == NULL );
|
||||||
|
|
||||||
// REQUIRE( NULL != p ); // gives warning, but should compile and run ok
|
// REQUIRE( NULL != p ); // gives warning, but should compile and run ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ TEST_CASE( "selftest/main", "Runs all Catch self tests and checks their results"
|
||||||
"Number of 'succeeding' tests is fixed" )
|
"Number of 'succeeding' tests is fixed" )
|
||||||
{
|
{
|
||||||
runner.runMatching( "./succeeding/*" );
|
runner.runMatching( "./succeeding/*" );
|
||||||
CHECK( runner.getTotals().assertions.passed == 273 );
|
CHECK( runner.getTotals().assertions.passed == 275 );
|
||||||
CHECK( runner.getTotals().assertions.failed == 0 );
|
CHECK( runner.getTotals().assertions.failed == 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue