| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  *  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,  | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |             const char* description, | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             const SourceLineInfo& lineInfo | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         ) | 
					
						
							|  |  |  |         :   m_test( testCase ), | 
					
						
							|  |  |  |             m_name( name ), | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |             m_description( description ), | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             m_lineInfo( lineInfo ) | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         TestCaseInfo | 
					
						
							|  |  |  |         () | 
					
						
							| 
									
										
										
										
											2011-09-23 10:03:52 +02:00
										 |  |  |         :   m_test( NULL ), | 
					
						
							|  |  |  |             m_name(), | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             m_description() | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         TestCaseInfo | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const TestCaseInfo& other | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         :   m_test( other.m_test->clone() ), | 
					
						
							|  |  |  |             m_name( other.m_name ), | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |             m_description( other.m_description ), | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             m_lineInfo( other.m_lineInfo ) | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-01-18 20:09:21 +00:00
										 |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         TestCaseInfo | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const TestCaseInfo& other, | 
					
						
							|  |  |  |             const std::string& name | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         :   m_test( other.m_test->clone() ), | 
					
						
							|  |  |  |             m_name( name ), | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |             m_description( other.m_description ), | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             m_lineInfo( other.m_lineInfo ) | 
					
						
							| 
									
										
										
										
											2011-01-18 20:09:21 +00:00
										 |  |  |         { | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         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; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-01-14 08:47:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |         const SourceLineInfo& getLineInfo | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |         () | 
					
						
							|  |  |  |         const | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             return m_lineInfo; | 
					
						
							| 
									
										
										
										
											2011-04-21 08:59:42 +01:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-14 08:47:43 +00:00
										 |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         bool isHidden | 
					
						
							|  |  |  |         () | 
					
						
							|  |  |  |         const | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             return m_name.size() >= 2 && m_name[0] == '.' && m_name[1] == '/'; | 
					
						
							|  |  |  |         }         | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |          | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         void swap | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             TestCaseInfo& other | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             std::swap( m_test, other.m_test ); | 
					
						
							|  |  |  |             m_name.swap( other.m_name ); | 
					
						
							|  |  |  |             m_description.swap( other.m_description ); | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |             m_lineInfo.swap( other.m_lineInfo ); | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         bool operator ==  | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const TestCaseInfo& other | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         const | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2012-02-09 08:34:01 +00:00
										 |  |  |             return *m_test == *other.m_test && m_name == other.m_name; | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |         bool operator < | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const TestCaseInfo& other | 
					
						
							|  |  |  |         )  | 
					
						
							|  |  |  |         const | 
					
						
							|  |  |  |         { | 
					
						
							| 
									
										
										
										
											2012-02-09 08:34:01 +00:00
										 |  |  |             return m_name < other.m_name; | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         ITestCase* m_test; | 
					
						
							|  |  |  |         std::string m_name; | 
					
						
							|  |  |  |         std::string m_description; | 
					
						
							| 
									
										
										
										
											2012-05-08 19:16:18 +01:00
										 |  |  |         SourceLineInfo m_lineInfo;         | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  |     }; | 
					
						
							|  |  |  |      | 
					
						
							| 
									
										
										
										
											2011-03-11 19:44:59 +00:00
										 |  |  |     ///////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  |     ///////////////////////////////////////////////////////////////////////////    
 | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     class TestSpec | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |     public: | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////        
 | 
					
						
							|  |  |  |         TestSpec | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const std::string& rawSpec | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         :   m_rawSpec( rawSpec ), | 
					
						
							|  |  |  |             m_isWildcarded( false ) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if( m_rawSpec[m_rawSpec.size()-1] == '*' ) | 
					
						
							|  |  |  |             { | 
					
						
							|  |  |  |                 m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 ); | 
					
						
							|  |  |  |                 m_isWildcarded = true; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |         ///////////////////////////////////////////////////////////////////////        
 | 
					
						
							|  |  |  |         bool matches | 
					
						
							|  |  |  |         ( | 
					
						
							|  |  |  |             const std::string& testName | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         const | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             if( !m_isWildcarded ) | 
					
						
							|  |  |  |                 return m_rawSpec == testName; | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |                 return testName.size() >= m_rawSpec.size() && testName.substr( 0, m_rawSpec.size() ) == m_rawSpec;             | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |          | 
					
						
							|  |  |  |     private: | 
					
						
							|  |  |  |         std::string m_rawSpec; | 
					
						
							|  |  |  |         bool m_isWildcarded; | 
					
						
							|  |  |  |     }; | 
					
						
							| 
									
										
										
										
											2011-01-07 19:57:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-16 19:02:09 +00:00
										 |  |  | #endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
 |