mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-22 19:33:29 +01:00
Allow { NULL <op> T }to work
This commit is contained in:
parent
ef611c65d9
commit
7dfd830a3a
@ -224,7 +224,16 @@ TEST_CASE( "./succeeding/conditions/ptr", "Pointers can be compared to null" )
|
||||
|
||||
TestData data;
|
||||
p = &data;
|
||||
|
||||
REQUIRE( p != NULL );
|
||||
|
||||
const TestData* cp = p;
|
||||
REQUIRE( cp != NULL );
|
||||
|
||||
const TestData* const cpc = p;
|
||||
REQUIRE( cpc != NULL );
|
||||
|
||||
// REQUIRE( NULL != p ); // gives warning, but should compile and run ok
|
||||
}
|
||||
|
||||
// Not (!) tests
|
||||
|
@ -395,65 +395,65 @@ private:
|
||||
const T& m_lhs;
|
||||
};
|
||||
|
||||
template<typename LhsT>
|
||||
class PtrExpression
|
||||
template<typename LhsT>
|
||||
class PtrExpression
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
PtrExpression
|
||||
(
|
||||
MutableResultInfo& result,
|
||||
const LhsT* lhs
|
||||
)
|
||||
: m_result( result ),
|
||||
m_lhs( lhs )
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
MutableResultInfo& operator ==
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
public:
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
PtrExpression
|
||||
(
|
||||
MutableResultInfo& result,
|
||||
const LhsT* lhs
|
||||
)
|
||||
: m_result( result ),
|
||||
m_lhs( lhs )
|
||||
{}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
MutableResultInfo& operator ==
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
MutableResultInfo& operator ==
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
MutableResultInfo& operator !=
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
MutableResultInfo& operator !=
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
private:
|
||||
MutableResultInfo& m_result;
|
||||
const LhsT* m_lhs;
|
||||
};
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
MutableResultInfo& operator ==
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename RhsT>
|
||||
MutableResultInfo& operator !=
|
||||
(
|
||||
const RhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// This catches NULL
|
||||
MutableResultInfo& operator !=
|
||||
(
|
||||
LhsT* rhs
|
||||
)
|
||||
{
|
||||
return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
|
||||
}
|
||||
|
||||
private:
|
||||
MutableResultInfo& m_result;
|
||||
const LhsT* m_lhs;
|
||||
};
|
||||
|
||||
class ResultBuilder
|
||||
{
|
||||
|
@ -216,6 +216,20 @@ namespace Internal
|
||||
{
|
||||
return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs, testLhsSign( lhs ) );
|
||||
}
|
||||
|
||||
template<Operator Op, typename T>
|
||||
bool compare( long lhs, const T* rhs )
|
||||
{
|
||||
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( NULL ), rhs );
|
||||
|
||||
}
|
||||
|
||||
template<Operator Op, typename T>
|
||||
bool compare( long lhs, T* rhs )
|
||||
{
|
||||
return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
|
||||
|
||||
}
|
||||
|
||||
} // end of namespace Internal
|
||||
} // end of namespace Catch
|
||||
|
Loading…
Reference in New Issue
Block a user