2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 18/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)
|
|
|
|
*/
|
2012-09-17 07:42:29 +02:00
|
|
|
#ifndef TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
#include "catch_common.h"
|
2011-01-07 20:57:32 +01:00
|
|
|
#include "catch_interfaces_testcase.h"
|
2015-03-04 08:08:53 +01:00
|
|
|
#include "catch_compiler_capabilities.h"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
namespace Catch {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
template<typename C>
|
2012-08-14 09:38:22 +02:00
|
|
|
class MethodTestCase : public SharedImpl<ITestCase> {
|
2012-05-16 09:02:20 +02:00
|
|
|
|
2012-05-10 22:46:46 +02:00
|
|
|
public:
|
|
|
|
MethodTestCase( void (C::*method)() ) : m_method( method ) {}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-05-10 22:46:46 +02:00
|
|
|
virtual void invoke() const {
|
2010-11-10 00:24:00 +01:00
|
|
|
C obj;
|
2011-01-31 11:10:20 +01:00
|
|
|
(obj.*m_method)();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
private:
|
2012-08-14 09:38:22 +02:00
|
|
|
virtual ~MethodTestCase() {}
|
|
|
|
|
2011-01-31 11:10:20 +01:00
|
|
|
void (C::*m_method)();
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
2011-01-07 20:57:32 +01:00
|
|
|
|
|
|
|
typedef void(*TestFunction)();
|
2013-03-16 21:18:52 +01:00
|
|
|
|
|
|
|
struct NameAndDesc {
|
|
|
|
NameAndDesc( const char* _name = "", const char* _description= "" )
|
|
|
|
: name( _name ), description( _description )
|
|
|
|
{}
|
|
|
|
|
|
|
|
const char* name;
|
|
|
|
const char* description;
|
|
|
|
};
|
|
|
|
|
2015-11-20 17:54:07 +01:00
|
|
|
void registerTestCase
|
|
|
|
( ITestCase* testCase,
|
|
|
|
char const* className,
|
|
|
|
NameAndDesc const& nameAndDesc,
|
|
|
|
SourceLineInfo const& lineInfo );
|
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
struct AutoReg {
|
|
|
|
|
2015-11-20 17:54:07 +01:00
|
|
|
AutoReg
|
|
|
|
( TestFunction function,
|
|
|
|
SourceLineInfo const& lineInfo,
|
|
|
|
NameAndDesc const& nameAndDesc );
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
template<typename C>
|
2015-11-20 17:54:07 +01:00
|
|
|
AutoReg
|
|
|
|
( void (C::*method)(),
|
|
|
|
char const* className,
|
|
|
|
NameAndDesc const& nameAndDesc,
|
|
|
|
SourceLineInfo const& lineInfo ) {
|
|
|
|
|
|
|
|
registerTestCase
|
|
|
|
( new MethodTestCase<C>( method ),
|
|
|
|
className,
|
|
|
|
nameAndDesc,
|
|
|
|
lineInfo );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-05-10 22:46:46 +02:00
|
|
|
~AutoReg();
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2011-01-07 11:01:40 +01:00
|
|
|
private:
|
2013-07-03 20:14:59 +02:00
|
|
|
AutoReg( AutoReg const& );
|
2013-04-23 19:58:56 +02:00
|
|
|
void operator= ( AutoReg const& );
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2015-11-20 17:54:07 +01:00
|
|
|
void registerTestCaseFunction
|
|
|
|
( TestFunction function,
|
|
|
|
SourceLineInfo const& lineInfo,
|
|
|
|
NameAndDesc const& nameAndDesc );
|
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2013-03-16 21:18:52 +01:00
|
|
|
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
|
|
|
|
static void TestName(); \
|
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
|
|
|
|
static void TestName()
|
2013-03-16 21:18:52 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE( ... ) \
|
2015-12-15 08:50:51 +01:00
|
|
|
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
|
2013-03-16 21:18:52 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
|
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
|
2013-03-16 21:18:52 +01:00
|
|
|
namespace{ \
|
2015-12-15 08:50:51 +01:00
|
|
|
struct TestName : ClassName{ \
|
2013-03-16 21:18:52 +01:00
|
|
|
void test(); \
|
|
|
|
}; \
|
2015-12-15 08:50:51 +01:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \
|
2013-03-16 21:18:52 +01:00
|
|
|
} \
|
2015-12-15 08:50:51 +01:00
|
|
|
void TestName::test()
|
|
|
|
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
|
|
|
|
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
|
2013-03-16 21:18:52 +01:00
|
|
|
|
2015-11-20 17:54:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
|
|
|
|
Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) );
|
|
|
|
|
2013-03-16 21:18:52 +01:00
|
|
|
#else
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
|
|
|
|
static void TestName(); \
|
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\
|
|
|
|
static void TestName()
|
2013-03-16 21:18:52 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
|
2015-12-15 08:50:51 +01:00
|
|
|
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
|
2013-03-16 21:18:52 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
|
2013-03-16 21:18:52 +01:00
|
|
|
namespace{ \
|
2015-12-15 08:50:51 +01:00
|
|
|
struct TestCaseName : ClassName{ \
|
2013-03-16 21:18:52 +01:00
|
|
|
void test(); \
|
|
|
|
}; \
|
2015-12-15 08:50:51 +01:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \
|
2013-03-16 21:18:52 +01:00
|
|
|
} \
|
2015-12-15 08:50:51 +01:00
|
|
|
void TestCaseName::test()
|
|
|
|
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
|
|
|
|
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
|
2013-03-16 21:18:52 +01:00
|
|
|
|
2015-11-20 17:54:07 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
|
|
|
|
Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) );
|
2013-03-16 21:18:52 +01:00
|
|
|
#endif
|
2010-12-27 21:51:06 +01:00
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
|