1 /* 2 * Created by Phil on 5/8/2012. 3 * Copyright 2012 Two Blue Cubes Ltd. All rights reserved. 4 * 5 * Distributed under the Boost Software License, Version 1.0. (See accompanying 6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 */ 8 9 #include "catch_interfaces_registry_hub.h" 10 11 #include "catch_context.h" 12 #include "catch_test_case_registry_impl.h" 13 #include "catch_reporter_registry.h" 14 #include "catch_exception_translator_registry.h" 15 #include "catch_tag_alias_registry.h" 16 #include "catch_startup_exception_registry.h" 17 #include "catch_singletons.hpp" 18 #include "catch_enum_values_registry.h" 19 20 namespace Catch { 21 22 namespace { 23 24 class RegistryHub : public IRegistryHub, public IMutableRegistryHub, 25 private NonCopyable { 26 27 public: // IRegistryHub 28 RegistryHub() = default; getReporterRegistry() const29 IReporterRegistry const& getReporterRegistry() const override { 30 return m_reporterRegistry; 31 } getTestCaseRegistry() const32 ITestCaseRegistry const& getTestCaseRegistry() const override { 33 return m_testCaseRegistry; 34 } getExceptionTranslatorRegistry() const35 IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override { 36 return m_exceptionTranslatorRegistry; 37 } getTagAliasRegistry() const38 ITagAliasRegistry const& getTagAliasRegistry() const override { 39 return m_tagAliasRegistry; 40 } getStartupExceptionRegistry() const41 StartupExceptionRegistry const& getStartupExceptionRegistry() const override { 42 return m_exceptionRegistry; 43 } 44 45 public: // IMutableRegistryHub registerReporter(std::string const & name,IReporterFactoryPtr const & factory)46 void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { 47 m_reporterRegistry.registerReporter( name, factory ); 48 } registerListener(IReporterFactoryPtr const & factory)49 void registerListener( IReporterFactoryPtr const& factory ) override { 50 m_reporterRegistry.registerListener( factory ); 51 } registerTest(TestCase const & testInfo)52 void registerTest( TestCase const& testInfo ) override { 53 m_testCaseRegistry.registerTest( testInfo ); 54 } registerTranslator(const IExceptionTranslator * translator)55 void registerTranslator( const IExceptionTranslator* translator ) override { 56 m_exceptionTranslatorRegistry.registerTranslator( translator ); 57 } registerTagAlias(std::string const & alias,std::string const & tag,SourceLineInfo const & lineInfo)58 void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { 59 m_tagAliasRegistry.add( alias, tag, lineInfo ); 60 } registerStartupException()61 void registerStartupException() noexcept override { 62 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) 63 m_exceptionRegistry.add(std::current_exception()); 64 #else 65 CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!"); 66 #endif 67 } getMutableEnumValuesRegistry()68 IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override { 69 return m_enumValuesRegistry; 70 } 71 72 private: 73 TestRegistry m_testCaseRegistry; 74 ReporterRegistry m_reporterRegistry; 75 ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; 76 TagAliasRegistry m_tagAliasRegistry; 77 StartupExceptionRegistry m_exceptionRegistry; 78 Detail::EnumValuesRegistry m_enumValuesRegistry; 79 }; 80 } 81 82 using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>; 83 getRegistryHub()84 IRegistryHub const& getRegistryHub() { 85 return RegistryHubSingleton::get(); 86 } getMutableRegistryHub()87 IMutableRegistryHub& getMutableRegistryHub() { 88 return RegistryHubSingleton::getMutable(); 89 } cleanUp()90 void cleanUp() { 91 cleanupSingletons(); 92 cleanUpContext(); 93 } translateActiveException()94 std::string translateActiveException() { 95 return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); 96 } 97 98 99 } // end namespace Catch 100