2012-08-06 21:16:53 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 5/8/2012.
|
|
|
|
* Copyright 2012 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_REGISTRY_HUB_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
|
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
#include "catch_interfaces_registry_hub.h"
|
2012-08-06 09:33:15 +02:00
|
|
|
|
2012-08-06 21:16:53 +02:00
|
|
|
#include "catch_test_case_registry_impl.hpp"
|
|
|
|
#include "catch_reporter_registry.hpp"
|
|
|
|
#include "catch_exception_translator_registry.hpp"
|
2012-08-06 09:33:15 +02:00
|
|
|
|
2012-08-06 21:16:53 +02:00
|
|
|
namespace Catch {
|
2012-08-06 09:33:15 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
RegistryHub( RegistryHub const& );
|
|
|
|
void operator=( RegistryHub const& );
|
2012-08-06 09:33:15 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
public: // IRegistryHub
|
|
|
|
RegistryHub() {
|
|
|
|
}
|
|
|
|
virtual IReporterRegistry const& getReporterRegistry() const {
|
|
|
|
return m_reporterRegistry;
|
|
|
|
}
|
|
|
|
virtual ITestCaseRegistry const& getTestCaseRegistry() const {
|
|
|
|
return m_testCaseRegistry;
|
|
|
|
}
|
|
|
|
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() {
|
|
|
|
return m_exceptionTranslatorRegistry;
|
|
|
|
}
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
public: // IMutableRegistryHub
|
|
|
|
virtual void registerReporter( std::string const& name, IReporterFactory* factory ) {
|
|
|
|
m_reporterRegistry.registerReporter( name, factory );
|
|
|
|
}
|
|
|
|
virtual void registerTest( TestCase const& testInfo ) {
|
|
|
|
m_testCaseRegistry.registerTest( testInfo );
|
|
|
|
}
|
|
|
|
virtual void registerTranslator( const IExceptionTranslator* translator ) {
|
|
|
|
m_exceptionTranslatorRegistry.registerTranslator( translator );
|
|
|
|
}
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
private:
|
|
|
|
TestRegistry m_testCaseRegistry;
|
|
|
|
ReporterRegistry m_reporterRegistry;
|
|
|
|
ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
|
|
|
|
};
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
// Single, global, instance
|
|
|
|
template <typename T>
|
|
|
|
struct GlobalRegistryHub
|
|
|
|
{
|
|
|
|
static T*& instance()
|
|
|
|
{
|
2012-08-07 08:58:34 +02:00
|
|
|
if( !theRegistryHub )
|
2013-11-22 12:47:21 +01:00
|
|
|
theRegistryHub = new T();
|
2012-08-07 08:58:34 +02:00
|
|
|
return theRegistryHub;
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2013-11-22 12:47:21 +01:00
|
|
|
static T* theRegistryHub;
|
|
|
|
};
|
|
|
|
template <typename T>
|
|
|
|
T* GlobalRegistryHub<T>::theRegistryHub = NULL;
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2013-11-22 12:47:21 +01:00
|
|
|
INTERNAL_CATCH_INLINE IRegistryHub& getRegistryHub() {
|
|
|
|
return *GlobalRegistryHub<RegistryHub>::instance();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2013-11-22 12:47:21 +01:00
|
|
|
INTERNAL_CATCH_INLINE IMutableRegistryHub& getMutableRegistryHub() {
|
|
|
|
return *GlobalRegistryHub<RegistryHub>::instance();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2013-11-22 12:47:21 +01:00
|
|
|
INTERNAL_CATCH_INLINE void cleanUp() {
|
|
|
|
delete GlobalRegistryHub<RegistryHub>::instance();
|
|
|
|
GlobalRegistryHub<RegistryHub>::instance() = NULL;
|
2012-08-08 09:33:54 +02:00
|
|
|
cleanUpContext();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2013-11-22 12:47:21 +01:00
|
|
|
INTERNAL_CATCH_INLINE std::string translateActiveException() {
|
2012-10-17 09:14:22 +02:00
|
|
|
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
|
|
|
}
|
|
|
|
|
2012-08-06 21:16:53 +02:00
|
|
|
|
|
|
|
} // end namespace Catch
|
2012-09-17 07:42:29 +02:00
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
|