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"
|
2017-07-12 23:39:31 +02:00
|
|
|
#include "catch_stringref.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>
|
2017-07-12 19:01:54 +02:00
|
|
|
class TestInvokerAsMethod : public ITestInvoker {
|
|
|
|
void (C::*m_testAsMethod)();
|
2012-05-10 22:46:46 +02:00
|
|
|
public:
|
2017-07-13 09:25:47 +02:00
|
|
|
TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-07-12 19:01:54 +02:00
|
|
|
void invoke() const override {
|
2010-11-10 00:24:00 +01:00
|
|
|
C obj;
|
2017-07-12 19:01:54 +02:00
|
|
|
(obj.*m_testAsMethod)();
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
};
|
2011-01-07 20:57:32 +01:00
|
|
|
|
2017-07-13 09:25:47 +02:00
|
|
|
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
|
2013-03-16 21:18:52 +01:00
|
|
|
|
2017-07-12 23:39:31 +02:00
|
|
|
template<typename C>
|
2017-07-13 09:25:47 +02:00
|
|
|
auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
|
|
|
|
return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
|
2017-07-12 23:39:31 +02:00
|
|
|
}
|
2013-03-16 21:18:52 +01:00
|
|
|
|
2017-07-12 23:39:31 +02:00
|
|
|
struct NameAndTags {
|
2017-07-25 22:41:35 +02:00
|
|
|
NameAndTags( StringRef name_ = "", StringRef tags_ = "" ) noexcept;
|
2017-07-12 23:39:31 +02:00
|
|
|
StringRef name;
|
|
|
|
StringRef tags;
|
2010-11-10 00:24:00 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-07-12 23:39:31 +02:00
|
|
|
struct AutoReg : NonCopyable {
|
2017-07-13 09:25:47 +02:00
|
|
|
AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
|
2017-09-07 16:51:33 +02:00
|
|
|
~AutoReg();
|
2017-07-12 23:39:31 +02:00
|
|
|
};
|
2015-11-20 17:54:07 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
} // end namespace Catch
|
|
|
|
|
2017-08-27 17:03:32 +02:00
|
|
|
#if defined(CATCH_CONFIG_DISABLE)
|
|
|
|
#define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
|
|
|
|
static void TestName()
|
|
|
|
#define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
|
|
|
|
namespace{ \
|
|
|
|
struct TestName : ClassName { \
|
|
|
|
void test(); \
|
|
|
|
}; \
|
|
|
|
} \
|
|
|
|
void TestName::test()
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2013-03-16 21:18:52 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
|
|
|
|
static void TestName(); \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
|
2017-08-10 11:34:26 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
|
2015-12-15 08:50:51 +01:00
|
|
|
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, ... ) \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
|
2017-08-10 11:34:26 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
|
2013-03-16 21:18:52 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-12-15 08:50:51 +01:00
|
|
|
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
|
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(); \
|
|
|
|
}; \
|
2017-08-10 11:34:26 +02:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
|
2013-03-16 21:18:52 +01:00
|
|
|
} \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
|
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, ... ) \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
|
2017-08-29 09:52:58 +02:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
|
2017-09-07 16:51:33 +02:00
|
|
|
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
|
2015-11-20 17:54:07 +01:00
|
|
|
|
2010-12-27 21:51:06 +01:00
|
|
|
|
2012-09-17 07:42:29 +02:00
|
|
|
#endif // TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
|