diff options
| author | Phil Nash | 2011-03-18 19:08:33 +0000 |
|---|---|---|
| committer | Phil Nash | 2011-03-18 19:08:33 +0000 |
| commit | 7dfd830a3a273a6b2b23ff66eb96f0c72ff6f991 (patch) | |
| tree | 0527c5de35615409d7db472801318e97e7ce2109 | |
| parent | ef611c65d9d5e9144e2b4d09e40ff9f2edd656d0 (diff) | |
| download | catch3-7dfd830a3a273a6b2b23ff66eb96f0c72ff6f991.tar.gz | |
Allow { NULL <op> T }to work
| -rw-r--r-- | Test/ConditionTests.cpp | 9 | ||||
| -rw-r--r-- | internal/catch_capture.hpp | 114 | ||||
| -rw-r--r-- | internal/catch_evaluate.hpp | 14 |
3 files changed, 80 insertions, 57 deletions
diff --git a/Test/ConditionTests.cpp b/Test/ConditionTests.cpp index 5a2c5751..96fcb1a7 100644 --- a/Test/ConditionTests.cpp +++ b/Test/ConditionTests.cpp @@ -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 diff --git a/internal/catch_capture.hpp b/internal/catch_capture.hpp index 69753f7a..abefecc7 100644 --- a/internal/catch_capture.hpp +++ b/internal/catch_capture.hpp @@ -395,65 +395,65 @@ private: const T& m_lhs; }; - template<typename LhsT> - class PtrExpression - { - public: +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 - ) - { - 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 { diff --git a/internal/catch_evaluate.hpp b/internal/catch_evaluate.hpp index 2d020ca5..0bfe373f 100644 --- a/internal/catch_evaluate.hpp +++ b/internal/catch_evaluate.hpp @@ -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 |