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

Made ITestCase a shared object

Commit
9c6ce97f01745d23bc48ca497698f4a30e8feba2
Author
Phil Nash ·
Parents
a67d833091a0

Files · Download .tar.gz

Changes

 include/internal/catch_interfaces_registry_hub.h   |  3 ---
 include/internal/catch_interfaces_testcase.h       |  8 +++----
 include/internal/catch_objc.hpp                    | 19 +++------------
 include/internal/catch_test_case_info.hpp          | 27 ++++------------------
 include/internal/catch_test_case_registry_impl.hpp | 23 ++++--------------
 include/internal/catch_test_registry.hpp           | 18 +++------------
 6 files changed, 19 insertions(+), 79 deletions(-)

diff --git a/include/internal/catch_interfaces_registry_hub.h b/include/internal/catch_interfaces_registry_hub.h
index 0da503bd..28aae7a0 100644
--- a/include/internal/catch_interfaces_registry_hub.h
+++ b/include/internal/catch_interfaces_registry_hub.h
@@ -11,14 +11,11 @@
 #include "catch_interfaces_reporter.h"
 #include "catch_interfaces_config.h"
 
-#include <memory>
 #include <vector>
-#include <stdlib.h>
 
 namespace Catch {
 
     class TestCaseInfo;
-    struct IResultCapture;
     struct ITestCaseRegistry;
     struct IExceptionTranslatorRegistry;
     struct IExceptionTranslator;
diff --git a/include/internal/catch_interfaces_testcase.h b/include/internal/catch_interfaces_testcase.h
index f3ccb58d..0781e646 100644
--- a/include/internal/catch_interfaces_testcase.h
+++ b/include/internal/catch_interfaces_testcase.h
@@ -11,12 +11,10 @@
 #include <vector>
 
 namespace Catch {
-    struct ITestCase {
+    struct ITestCase : IShared {
+        virtual void invoke () const = 0;
+    protected:
         virtual ~ITestCase();
-        virtual void invoke () const = 0;        
-        virtual ITestCase* clone() const = 0;        
-        virtual bool operator == ( const ITestCase& other ) const = 0;        
-        virtual bool operator < ( const ITestCase& other ) const = 0;
     };
     
     class TestCaseInfo;
diff --git a/include/internal/catch_objc.hpp b/include/internal/catch_objc.hpp
index a461e08b..ad13e295 100644
--- a/include/internal/catch_objc.hpp
+++ b/include/internal/catch_objc.hpp
@@ -33,7 +33,7 @@
 
 namespace Catch {
 
-    class OcMethod : public ITestCase {
+    class OcMethod : public SharedImpl<ITestCase> {
     
     public:
         OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
@@ -47,22 +47,9 @@ namespace Catch {
             
             arcSafeRelease( obj );
         }
-        
-        virtual ITestCase* clone() const {
-            return new OcMethod( m_cls, m_sel );
-        }
-        
-        virtual bool operator == ( const ITestCase& other ) const {
-            const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
-            return ocmOther && ocmOther->m_sel == m_sel;
-        }
-        
-        virtual bool operator < ( const ITestCase& other ) const {
-            const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
-            return ocmOther && ocmOther->m_sel < m_sel;
-        }
-        
     private:
+        virtual ~OcMethod() {}
+        
         Class m_cls;
         SEL m_sel;
     };
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index bc0b8827..c54ae02e 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -33,30 +33,13 @@ namespace Catch {
             m_description()
         {}
         
-        TestCaseInfo( const TestCaseInfo& other )
-        :   m_test( other.m_test->clone() ),
-            m_name( other.m_name ),
-            m_description( other.m_description ),
-            m_lineInfo( other.m_lineInfo )
-        {}
-        
         TestCaseInfo( const TestCaseInfo& other, const std::string& name )
-        :   m_test( other.m_test->clone() ),
+        :   m_test( other.m_test ),
             m_name( name ),
             m_description( other.m_description ),
             m_lineInfo( other.m_lineInfo )
         {}
-        
-        TestCaseInfo& operator = ( const TestCaseInfo& other ) {
-            TestCaseInfo temp( other );
-            swap( temp );
-            return *this;
-        }
-        
-        ~TestCaseInfo() {
-            delete m_test;
-        }
-        
+
         void invoke() const {
             m_test->invoke();
         }
@@ -78,14 +61,14 @@ namespace Catch {
         }        
         
         void swap( TestCaseInfo& other ) {
-            std::swap( m_test, other.m_test );
+            m_test.swap( other.m_test );
             m_name.swap( other.m_name );
             m_description.swap( other.m_description );
             m_lineInfo.swap( other.m_lineInfo );
         }
         
         bool operator == ( const TestCaseInfo& other ) const {
-            return *m_test == *other.m_test && m_name == other.m_name;
+            return m_test.get() == other.m_test.get() && m_name == other.m_name;
         }
         
         bool operator < ( const TestCaseInfo& other ) const {
@@ -93,7 +76,7 @@ namespace Catch {
         }
 
     private:
-        ITestCase* m_test;
+        Ptr<ITestCase> m_test;
         std::string m_name;
         std::string m_description;
         SourceLineInfo m_lineInfo;        
diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp
index 5e23fed9..62398dce 100644
--- a/include/internal/catch_test_case_registry_impl.hpp
+++ b/include/internal/catch_test_case_registry_impl.hpp
@@ -68,31 +68,18 @@ namespace Catch {
 
     ///////////////////////////////////////////////////////////////////////////
         
-    class FreeFunctionTestCase : public ITestCase {
+    class FreeFunctionTestCase : public SharedImpl<ITestCase> {
     public:
 
         FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
-        virtual ~FreeFunctionTestCase();
-        
+
         virtual void invoke() const {
             m_fun();
         }
-        
-        virtual ITestCase* clone() const {
-            return new FreeFunctionTestCase( m_fun );
-        }
-        
-        virtual bool operator == ( const ITestCase& other ) const {
-            const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
-            return ffOther && m_fun == ffOther->m_fun;
-        }
-        
-        virtual bool operator < ( const ITestCase& other ) const {
-            const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
-            return ffOther && m_fun < ffOther->m_fun;
-        }
-        
+
     private:
+        virtual ~FreeFunctionTestCase();
+
         TestFunction m_fun;
     };
         
diff --git a/include/internal/catch_test_registry.hpp b/include/internal/catch_test_registry.hpp
index 5a0ef0d9..b41c85e3 100644
--- a/include/internal/catch_test_registry.hpp
+++ b/include/internal/catch_test_registry.hpp
@@ -14,7 +14,7 @@
 namespace Catch {
     
 template<typename C>
-class MethodTestCase : public ITestCase {
+class MethodTestCase : public SharedImpl<ITestCase> {
 
 public:
     MethodTestCase( void (C::*method)() ) : m_method( method ) {}
@@ -24,21 +24,9 @@ public:
         (obj.*m_method)();
     }
     
-    virtual ITestCase* clone() const {
-        return new MethodTestCase<C>( m_method );
-    }
-
-    virtual bool operator == ( const ITestCase& other ) const {
-        const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
-        return mtOther && m_method == mtOther->m_method;
-    }
-    
-    virtual bool operator < ( const ITestCase& other ) const {
-        const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
-        return mtOther && &m_method < &mtOther->m_method;
-    }
-    
 private:
+    virtual ~MethodTestCase() {}
+
     void (C::*m_method)();
 };