• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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                 m_exceptionRegistry.add(std::current_exception());
63             }
getMutableEnumValuesRegistry()64             IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override {
65                 return m_enumValuesRegistry;
66             }
67 
68         private:
69             TestRegistry m_testCaseRegistry;
70             ReporterRegistry m_reporterRegistry;
71             ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
72             TagAliasRegistry m_tagAliasRegistry;
73             StartupExceptionRegistry m_exceptionRegistry;
74             Detail::EnumValuesRegistry m_enumValuesRegistry;
75         };
76     }
77 
78     using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
79 
getRegistryHub()80     IRegistryHub const& getRegistryHub() {
81         return RegistryHubSingleton::get();
82     }
getMutableRegistryHub()83     IMutableRegistryHub& getMutableRegistryHub() {
84         return RegistryHubSingleton::getMutable();
85     }
cleanUp()86     void cleanUp() {
87         cleanupSingletons();
88         cleanUpContext();
89     }
translateActiveException()90     std::string translateActiveException() {
91         return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
92     }
93 
94 
95 } // end namespace Catch
96