2010-11-10 00:24:00 +01:00
|
|
|
/*
|
2011-01-05 22:16:54 +01:00
|
|
|
* catch_test_registry.hpp
|
2010-11-10 00:24:00 +01:00
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
|
|
|
|
|
|
|
template<typename C>
|
2011-01-07 10:38:32 +01:00
|
|
|
struct MethodTestCase : ITestCase
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
MethodTestCase
|
|
|
|
(
|
|
|
|
void (C::*method)()
|
|
|
|
)
|
2011-01-31 11:10:20 +01:00
|
|
|
: m_method( method )
|
2010-11-10 00:24:00 +01:00
|
|
|
{}
|
|
|
|
|
2011-02-03 21:00:46 +01: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
|
|
|
}
|
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual ITestCase* clone
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-01-31 11:10:20 +01:00
|
|
|
return new MethodTestCase<C>( m_method );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2010-11-14 23:47:30 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual bool operator ==
|
|
|
|
(
|
|
|
|
const ITestCase& other
|
|
|
|
)
|
|
|
|
const
|
2010-11-14 23:47:30 +01:00
|
|
|
{
|
|
|
|
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
|
2011-01-31 11:10:20 +01:00
|
|
|
return mtOther && m_method == mtOther->m_method;
|
2010-11-14 23:47:30 +01:00
|
|
|
}
|
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
virtual bool operator <
|
|
|
|
(
|
|
|
|
const ITestCase& other
|
|
|
|
)
|
|
|
|
const
|
2010-11-14 23:47:30 +01:00
|
|
|
{
|
|
|
|
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
|
2011-01-31 11:10:20 +01:00
|
|
|
return mtOther && &m_method < &mtOther->m_method;
|
2010-11-14 23:47:30 +01:00
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
private:
|
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
|
|
|
|
|
|
|
struct AutoReg
|
|
|
|
{
|
2011-02-03 21:00:46 +01:00
|
|
|
AutoReg
|
|
|
|
( TestFunction function,
|
|
|
|
const char* name,
|
2011-04-21 09:59:42 +02:00
|
|
|
const char* description,
|
2012-05-08 20:16:18 +02:00
|
|
|
const SourceLineInfo& lineInfo
|
2011-02-03 21:00:46 +01:00
|
|
|
);
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2010-11-10 00:24:00 +01:00
|
|
|
template<typename C>
|
2011-02-03 21:00:46 +01:00
|
|
|
AutoReg
|
|
|
|
(
|
|
|
|
void (C::*method)(),
|
|
|
|
const char* name,
|
2011-04-21 09:59:42 +02:00
|
|
|
const char* description,
|
2012-05-08 20:16:18 +02:00
|
|
|
const SourceLineInfo& lineInfo
|
2011-02-03 21:00:46 +01:00
|
|
|
)
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2012-05-08 20:16:18 +02:00
|
|
|
registerTestCase( new MethodTestCase<C>( method ), name, description, lineInfo );
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
2011-01-07 11:01:40 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
void registerTestCase
|
|
|
|
(
|
|
|
|
ITestCase* testCase,
|
|
|
|
const char* name,
|
2011-04-21 09:59:42 +02:00
|
|
|
const char* description,
|
2012-05-08 20:16:18 +02:00
|
|
|
const SourceLineInfo& lineInfo
|
2011-02-03 21:00:46 +01:00
|
|
|
);
|
2011-01-07 11:22:24 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
~AutoReg
|
|
|
|
();
|
2011-01-07 11:01:40 +01:00
|
|
|
|
|
|
|
private:
|
2011-02-03 21:00:46 +01: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 ) \
|
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )(); \
|
2012-05-08 20:16:18 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
|
2010-11-10 08:42:15 +01:00
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )()
|
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 ) \
|
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )() ATTRIBUTE_NORETURN; \
|
2012-05-08 20:16:18 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
|
2011-01-31 21:15:40 +01:00
|
|
|
static void INTERNAL_CATCH_UNIQUE_NAME( catch_internal_TestFunction )()
|
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2010-11-10 00:24:00 +01:00
|
|
|
#define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
|
2012-05-08 20:16:18 +02:00
|
|
|
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &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{ \
|
|
|
|
struct INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper ) : ClassName{ \
|
|
|
|
void test(); \
|
|
|
|
}; \
|
2012-05-08 20:16:18 +02:00
|
|
|
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper )::test, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
|
2011-12-28 20:55:11 +01:00
|
|
|
} \
|
2011-04-12 19:44:58 +02:00
|
|
|
void INTERNAL_CATCH_UNIQUE_NAME( Catch_FixtureWrapper )::test()
|
2010-12-27 21:51:06 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED
|