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 18 namespace Catch { 19 20 namespace { 21 22 class RegistryHub : public IRegistryHub, public IMutableRegistryHub, 23 private NonCopyable { 24 25 public: // IRegistryHub 26 RegistryHub() = default; getReporterRegistry() const27 IReporterRegistry const& getReporterRegistry() const override { 28 return m_reporterRegistry; 29 } getTestCaseRegistry() const30 ITestCaseRegistry const& getTestCaseRegistry() const override { 31 return m_testCaseRegistry; 32 } getExceptionTranslatorRegistry()33 IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() override { 34 return m_exceptionTranslatorRegistry; 35 } getTagAliasRegistry() const36 ITagAliasRegistry const& getTagAliasRegistry() const override { 37 return m_tagAliasRegistry; 38 } getStartupExceptionRegistry() const39 StartupExceptionRegistry const& getStartupExceptionRegistry() const override { 40 return m_exceptionRegistry; 41 } 42 43 public: // IMutableRegistryHub registerReporter(std::string const & name,IReporterFactoryPtr const & factory)44 void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { 45 m_reporterRegistry.registerReporter( name, factory ); 46 } registerListener(IReporterFactoryPtr const & factory)47 void registerListener( IReporterFactoryPtr const& factory ) override { 48 m_reporterRegistry.registerListener( factory ); 49 } registerTest(TestCase const & testInfo)50 void registerTest( TestCase const& testInfo ) override { 51 m_testCaseRegistry.registerTest( testInfo ); 52 } registerTranslator(const IExceptionTranslator * translator)53 void registerTranslator( const IExceptionTranslator* translator ) override { 54 m_exceptionTranslatorRegistry.registerTranslator( translator ); 55 } registerTagAlias(std::string const & alias,std::string const & tag,SourceLineInfo const & lineInfo)56 void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { 57 m_tagAliasRegistry.add( alias, tag, lineInfo ); 58 } registerStartupException()59 void registerStartupException() noexcept override { 60 m_exceptionRegistry.add(std::current_exception()); 61 } 62 63 private: 64 TestRegistry m_testCaseRegistry; 65 ReporterRegistry m_reporterRegistry; 66 ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; 67 TagAliasRegistry m_tagAliasRegistry; 68 StartupExceptionRegistry m_exceptionRegistry; 69 }; 70 71 // Single, global, instance getTheRegistryHub()72 RegistryHub*& getTheRegistryHub() { 73 static RegistryHub* theRegistryHub = nullptr; 74 if( !theRegistryHub ) 75 theRegistryHub = new RegistryHub(); 76 return theRegistryHub; 77 } 78 } 79 getRegistryHub()80 IRegistryHub& getRegistryHub() { 81 return *getTheRegistryHub(); 82 } getMutableRegistryHub()83 IMutableRegistryHub& getMutableRegistryHub() { 84 return *getTheRegistryHub(); 85 } cleanUp()86 void cleanUp() { 87 delete getTheRegistryHub(); 88 getTheRegistryHub() = nullptr; 89 cleanUpContext(); 90 ReusableStringStream::cleanup(); 91 } translateActiveException()92 std::string translateActiveException() { 93 return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); 94 } 95 96 97 } // end namespace Catch 98