Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Allow { NULL <op> T }to work

Commit
7dfd830a3a273a6b2b23ff66eb96f0c72ff6f991
Author
Phil Nash ·
Parents
ef611c65d9d5

Files · Download .tar.gz

Changes

 Test/ConditionTests.cpp     |   9 ++++
 internal/catch_capture.hpp  | 114 ++++++++++++++++++++++----------------------
 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