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
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
#include "catch_interfaces_registry_hub.h"
|
2012-08-06 09:33:15 +02:00
|
|
|
|
2017-08-29 16:44:02 +02:00
|
|
|
#include "catch_context.h"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_test_case_registry_impl.h"
|
2017-09-07 16:51:33 +02:00
|
|
|
#include "catch_reporter_registry.h"
|
2017-07-10 14:25:38 +02:00
|
|
|
#include "catch_exception_translator_registry.h"
|
2017-03-15 10:45:37 +01:00
|
|
|
#include "catch_tag_alias_registry.h"
|
2017-06-04 21:39:27 +02:00
|
|
|
#include "catch_startup_exception_registry.h"
|
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
|
|
|
|
2012-08-06 21:16:53 +02:00
|
|
|
namespace {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-06-04 22:56:57 +02:00
|
|
|
class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
|
|
|
|
private NonCopyable {
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
public: // IRegistryHub
|
2017-09-07 16:51:33 +02:00
|
|
|
RegistryHub() = default;
|
2017-07-20 16:57:17 +02:00
|
|
|
IReporterRegistry const& getReporterRegistry() const override {
|
2012-08-06 21:16:53 +02:00
|
|
|
return m_reporterRegistry;
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
ITestCaseRegistry const& getTestCaseRegistry() const override {
|
2012-08-06 21:16:53 +02:00
|
|
|
return m_testCaseRegistry;
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override {
|
2012-08-06 21:16:53 +02:00
|
|
|
return m_exceptionTranslatorRegistry;
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
ITagAliasRegistry const& getTagAliasRegistry() const override {
|
2017-03-15 10:45:37 +01:00
|
|
|
return m_tagAliasRegistry;
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
|
2017-06-04 21:39:27 +02:00
|
|
|
return m_exceptionRegistry;
|
|
|
|
}
|
2012-08-06 21:16:53 +02:00
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
public: // IMutableRegistryHub
|
2017-07-20 16:57:17 +02:00
|
|
|
void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
|
2012-08-06 21:16:53 +02:00
|
|
|
m_reporterRegistry.registerReporter( name, factory );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void registerListener( IReporterFactoryPtr const& factory ) override {
|
2015-08-07 09:20:56 +02:00
|
|
|
m_reporterRegistry.registerListener( factory );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void registerTest( TestCase const& testInfo ) override {
|
2012-08-06 21:16:53 +02:00
|
|
|
m_testCaseRegistry.registerTest( testInfo );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void registerTranslator( const IExceptionTranslator* translator ) override {
|
2012-08-06 21:16:53 +02:00
|
|
|
m_exceptionTranslatorRegistry.registerTranslator( translator );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
|
2017-03-15 10:45:37 +01:00
|
|
|
m_tagAliasRegistry.add( alias, tag, lineInfo );
|
|
|
|
}
|
2017-07-27 12:24:52 +02:00
|
|
|
void registerStartupException() noexcept override {
|
|
|
|
m_exceptionRegistry.add(std::current_exception());
|
2017-06-04 21:39:27 +02:00
|
|
|
}
|
2012-08-06 21:16:53 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
TestRegistry m_testCaseRegistry;
|
|
|
|
ReporterRegistry m_reporterRegistry;
|
|
|
|
ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
|
2017-03-15 10:45:37 +01:00
|
|
|
TagAliasRegistry m_tagAliasRegistry;
|
2017-06-04 21:39:27 +02:00
|
|
|
StartupExceptionRegistry m_exceptionRegistry;
|
2012-08-06 21:16:53 +02:00
|
|
|
};
|
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
// Single, global, instance
|
2017-07-12 16:16:55 +02:00
|
|
|
RegistryHub*& getTheRegistryHub() {
|
2017-04-25 12:41:30 +02:00
|
|
|
static RegistryHub* theRegistryHub = nullptr;
|
2012-08-07 08:58:34 +02:00
|
|
|
if( !theRegistryHub )
|
|
|
|
theRegistryHub = new RegistryHub();
|
|
|
|
return theRegistryHub;
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-07 08:58:34 +02:00
|
|
|
IRegistryHub& getRegistryHub() {
|
|
|
|
return *getTheRegistryHub();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2012-08-07 08:58:34 +02:00
|
|
|
IMutableRegistryHub& getMutableRegistryHub() {
|
|
|
|
return *getTheRegistryHub();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
|
|
|
void cleanUp() {
|
2012-08-07 08:58:34 +02:00
|
|
|
delete getTheRegistryHub();
|
2017-04-25 12:41:30 +02:00
|
|
|
getTheRegistryHub() = nullptr;
|
2012-08-08 09:33:54 +02:00
|
|
|
cleanUpContext();
|
2012-08-06 21:16:53 +02:00
|
|
|
}
|
2012-10-17 09:14:22 +02:00
|
|
|
std::string translateActiveException() {
|
|
|
|
return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
|
|
|
|
}
|
|
|
|
|
2012-08-06 21:16:53 +02:00
|
|
|
|
|
|
|
} // end namespace Catch
|