mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Some more refactoring/ cleaning of test case files
This commit is contained in:
		
							
								
								
									
										40
									
								
								internal/catch_interfaces_testcase.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								internal/catch_interfaces_testcase.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| /* | ||||
|  *  catch_interfaces_testcase.h | ||||
|  *  Test | ||||
|  * | ||||
|  *  Created by Phil on 07/01/2011. | ||||
|  *  Copyright 2011 Two Blue Cubes Ltd. All rights reserved. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|     struct ITestCase | ||||
|     { | ||||
|         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; | ||||
|     }; | ||||
|  | ||||
| } | ||||
| #endif // TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED | ||||
							
								
								
									
										142
									
								
								internal/catch_test_case_info.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								internal/catch_test_case_info.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,142 @@ | ||||
| /* | ||||
|  *  catch_test_case_info.hpp | ||||
|  *  Catch | ||||
|  * | ||||
|  *  Created by Phil on 29/10/2010. | ||||
|  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_interfaces_testcase.h" | ||||
| #include <map> | ||||
| #include <string> | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|     class TestCaseInfo | ||||
|     { | ||||
|     public: | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         TestCaseInfo | ||||
|         ( | ||||
|             ITestCase* testCase,  | ||||
|             const char* name,  | ||||
|             const char* description  | ||||
|         ) | ||||
|         :   m_test( testCase ), | ||||
|             m_name( name ), | ||||
|             m_description( description ) | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         TestCaseInfo | ||||
|         () | ||||
|         :   m_test( NULL ) | ||||
|         { | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         TestCaseInfo | ||||
|         ( | ||||
|             const TestCaseInfo& other | ||||
|         ) | ||||
|         :   m_test( other.m_test->clone() ), | ||||
|             m_name( other.m_name ), | ||||
|             m_description( other.m_description ) | ||||
|         { | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         TestCaseInfo& operator =  | ||||
|         ( | ||||
|             const TestCaseInfo& other  | ||||
|         ) | ||||
|         { | ||||
|             TestCaseInfo temp( other ); | ||||
|             swap( temp ); | ||||
|             return *this; | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         ~TestCaseInfo | ||||
|         () | ||||
|         { | ||||
|             delete m_test; | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         void invoke | ||||
|         () | ||||
|         const | ||||
|         { | ||||
|             m_test->invoke(); | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         const std::string& getName | ||||
|         () | ||||
|         const | ||||
|         { | ||||
|             return m_name; | ||||
|         } | ||||
|  | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         const std::string& getDescription | ||||
|         () | ||||
|         const | ||||
|         { | ||||
|             return m_description; | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         void swap | ||||
|         ( | ||||
|             TestCaseInfo& other | ||||
|         ) | ||||
|         { | ||||
|             std::swap( m_test, other.m_test ); | ||||
|             m_name.swap( other.m_name ); | ||||
|             m_description.swap( other.m_description ); | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         bool operator ==  | ||||
|         ( | ||||
|             const TestCaseInfo& other | ||||
|         ) | ||||
|         const | ||||
|         { | ||||
|             return *m_test == *other.m_test && m_name == other.m_name && m_description == other.m_description;             | ||||
|         } | ||||
|          | ||||
|         /////////////////////////////////////////////////////////////////////// | ||||
|         bool operator < | ||||
|         ( | ||||
|             const TestCaseInfo& other | ||||
|         )  | ||||
|         const | ||||
|         { | ||||
|             if( m_name < other.m_name ) | ||||
|                 return true; | ||||
|             if( m_name > other.m_name ) | ||||
|                 return false; | ||||
|  | ||||
|             return *m_test < *other.m_test; | ||||
|         } | ||||
|  | ||||
|     private: | ||||
|         ITestCase* m_test; | ||||
|         std::string m_name; | ||||
|         std::string m_description; | ||||
|     }; | ||||
|      | ||||
| } | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
| @@ -11,6 +11,7 @@ | ||||
|  */ | ||||
|  | ||||
| #include "catch_test_registry.hpp" | ||||
| #include "catch_test_case_info.hpp" | ||||
| #include "catch_hub.h" | ||||
|  | ||||
| #include <vector> | ||||
| @@ -42,8 +43,6 @@ namespace Catch | ||||
|         std::vector<TestCaseInfo> m_functionsInOrder; | ||||
|     }; | ||||
|      | ||||
|     typedef void(*TestFunction)(); | ||||
|      | ||||
|     struct FreeFunctionTestCase : ITestCase | ||||
|     { | ||||
|         FreeFunctionTestCase( TestFunction fun ) | ||||
|   | ||||
| @@ -12,12 +12,11 @@ | ||||
| #ifndef TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED | ||||
|  | ||||
| #include "catch_testcase.hpp" | ||||
| #include "catch_common.h" | ||||
| #include "catch_interfaces_testcase.h" | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
| typedef void(*TestFunction)(); | ||||
|      | ||||
| template<typename C> | ||||
| struct MethodTestCase : ITestCase | ||||
| @@ -52,6 +51,8 @@ struct MethodTestCase : ITestCase | ||||
| private: | ||||
|     void (C::*method)(); | ||||
| }; | ||||
|  | ||||
| typedef void(*TestFunction)(); | ||||
|      | ||||
| struct AutoReg | ||||
| { | ||||
|   | ||||
| @@ -1,107 +0,0 @@ | ||||
| /* | ||||
|  *  catch_testcase.hpp | ||||
|  *  Catch | ||||
|  * | ||||
|  *  Created by Phil on 29/10/2010. | ||||
|  *  Copyright 2010 Two Blue Cubes Ltd. All rights reserved. | ||||
|  * | ||||
|  *  Distributed under the Boost Software License, Version 1.0. (See accompanying | ||||
|  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
| #define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
|  | ||||
| #include <map> | ||||
| #include <string> | ||||
|  | ||||
| namespace Catch | ||||
| { | ||||
|     struct ITestCase | ||||
|     { | ||||
|         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 | ||||
|     { | ||||
|     public: | ||||
|         TestCaseInfo( ITestCase* testCase, const char* name, const char* description ) | ||||
|         :   test( testCase ), | ||||
|             name( name ), | ||||
|             description( description ) | ||||
|         { | ||||
|         } | ||||
|         TestCaseInfo() | ||||
|         :   test( NULL ) | ||||
|         { | ||||
|         } | ||||
|          | ||||
|         TestCaseInfo( const TestCaseInfo& other ) | ||||
|         :   test( other.test->clone() ), | ||||
|             name( other.name ), | ||||
|             description( other.description ) | ||||
|         { | ||||
|         } | ||||
|          | ||||
|         TestCaseInfo& operator = ( const TestCaseInfo& other ) | ||||
|         { | ||||
|             TestCaseInfo temp( other ); | ||||
|             swap( temp ); | ||||
|             return *this; | ||||
|         } | ||||
|          | ||||
|         ~TestCaseInfo() | ||||
|         { | ||||
|             delete test; | ||||
|         } | ||||
|          | ||||
|         void invoke() const | ||||
|         { | ||||
|             test->invoke(); | ||||
|         } | ||||
|          | ||||
|         const std::string& getName() const | ||||
|         { | ||||
|             return name; | ||||
|         } | ||||
|         const std::string& getDescription() const | ||||
|         { | ||||
|             return description; | ||||
|         } | ||||
|          | ||||
|         void swap( TestCaseInfo& other ) | ||||
|         { | ||||
|             std::swap( test, other.test ); | ||||
|             name.swap( other.name ); | ||||
|             description.swap( other.description ); | ||||
|         } | ||||
|          | ||||
|         bool operator == ( const TestCaseInfo& other ) const | ||||
|         { | ||||
|             return *test == *other.test && name == other.name && description == other.description;             | ||||
|         } | ||||
|          | ||||
|         bool operator < ( const TestCaseInfo& other ) const | ||||
|         { | ||||
|             if( name < other.name ) | ||||
|                 return true; | ||||
|             if( name > other.name ) | ||||
|                 return false; | ||||
|  | ||||
|             return *test < *other.test; | ||||
|         } | ||||
|          | ||||
|     private: | ||||
|         ITestCase* test; | ||||
|         std::string name; | ||||
|         std::string description; | ||||
|     }; | ||||
|      | ||||
| } | ||||
|  | ||||
| #endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash