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"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
namespace Catch {
|
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 ) {}
|
2010-11-10 00:24:00 +01: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
|
|
|
}
|
|
|
|
|
|
|
|
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)();
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-05-16 09:02:20 +02:00
|
|
|
struct AutoReg {
|
|
|
|
|
2012-11-13 22:59:50 +01:00
|
|
|
AutoReg( TestFunction function,
|
2012-05-10 22:46:46 +02:00
|
|
|
const char* name,
|
|
|
|
const char* description,
|
|
|
|
const SourceLineInfo& lineInfo );
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
template<typename C>
|
2012-11-13 22:59:50 +01:00
|
|
|
AutoReg( void (C::*method)(),
|
|
|
|
const char* className,
|
2012-05-10 22:46:46 +02:00
|
|
|
const char* name,
|
|
|
|
const char* description,
|
|
|
|
const SourceLineInfo& lineInfo ) {
|
2012-11-13 22:59:50 +01:00
|
|
|
registerTestCase( new MethodTestCase<C>( method ), className, name, description, lineInfo );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2011-01-07 11:01:40 +01:00
|
|
|
|
2012-05-10 22:46:46 +02:00
|
|
|
void registerTestCase( ITestCase* testCase,
|
2012-11-13 22:59:50 +01:00
|
|
|
const char* className,
|
|
|
|
const char* name,
|
2012-05-10 22:46:46 +02:00
|
|
|
const char* description,
|
|
|
|
const SourceLineInfo& lineInfo );
|
2011-01-07 11:22:24 +01:00
|
|
|
|
2012-05-10 22:46:46 +02:00
|
|
|
~AutoReg();
|
2011-01-07 11:01:40 +01:00
|
|
|
|
|
|
|
private:
|
2012-05-10 22:46:46 +02:00
|
|
|
AutoReg( const AutoReg& );
|
|
|
|
void operator= ( const AutoReg& );
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-11-10 08:42:15 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
|
2012-05-09 19:59:26 +02:00
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )(); \
|
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
|
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2011-01-31 21:15:40 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \
|
2012-08-13 08:46:10 +02:00
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )() CATCH_ATTRIBUTE_NORETURN; \
|
2012-05-09 19:59:26 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
|
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
|
2011-01-31 21:15:40 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-07-20 19:43:48 +02:00
|
|
|
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
2012-11-13 22:59:50 +01:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Name, Desc, CATCH_INTERNAL_LINEINFO ); }
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-12-27 21:51:06 +01:00
|
|
|
#define TEST_CASE_METHOD( ClassName, TestName, Desc )\
|
2011-12-28 20:55:11 +01:00
|
|
|
namespace{ \
|
2012-05-09 19:59:26 +02:00
|
|
|
struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
|
2011-12-28 20:55:11 +01:00
|
|
|
void test(); \
|
|
|
|
}; \
|
2012-11-13 22:59:50 +01:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test, #ClassName, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
|
2011-12-28 20:55:11 +01:00
|
|
|
} \
|
2012-05-09 19:59:26 +02:00
|
|
|
void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test()
|
2010-12-27 21:51:06 +01:00
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
|