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