• 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 
19 namespace Catch {
20 
21     namespace {
22 
23         class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
24                             private NonCopyable {
25 
26         public: // IRegistryHub
27             RegistryHub() = default;
getReporterRegistry() const28             IReporterRegistry const& getReporterRegistry() const override {
29                 return m_reporterRegistry;
30             }
getTestCaseRegistry() const31             ITestCaseRegistry const& getTestCaseRegistry() const override {
32                 return m_testCaseRegistry;
33             }
getExceptionTranslatorRegistry() const34             IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
35                 return m_exceptionTranslatorRegistry;
36             }
getTagAliasRegistry() const37             ITagAliasRegistry const& getTagAliasRegistry() const override {
38                 return m_tagAliasRegistry;
39             }
getStartupExceptionRegistry() const40             StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
41                 return m_exceptionRegistry;
42             }
43 
44         public: // IMutableRegistryHub
registerReporter(std::string const & name,IReporterFactoryPtr const & factory)45             void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
46                 m_reporterRegistry.registerReporter( name, factory );
47             }
registerListener(IReporterFactoryPtr const & factory)48             void registerListener( IReporterFactoryPtr const& factory ) override {
49                 m_reporterRegistry.registerListener( factory );
50             }
registerTest(TestCase const & testInfo)51             void registerTest( TestCase const& testInfo ) override {
52                 m_testCaseRegistry.registerTest( testInfo );
53             }
registerTranslator(const IExceptionTranslator * translator)54             void registerTranslator( const IExceptionTranslator* translator ) override {
55                 m_exceptionTranslatorRegistry.registerTranslator( translator );
56             }
registerTagAlias(std::string const & alias,std::string const & tag,SourceLineInfo const & lineInfo)57             void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
58                 m_tagAliasRegistry.add( alias, tag, lineInfo );
59             }
registerStartupException()60             void registerStartupException() noexcept override {
61                 m_exceptionRegistry.add(std::current_exception());
62             }
63 
64         private:
65             TestRegistry m_testCaseRegistry;
66             ReporterRegistry m_reporterRegistry;
67             ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
68             TagAliasRegistry m_tagAliasRegistry;
69             StartupExceptionRegistry m_exceptionRegistry;
70         };
71     }
72 
73     using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
74 
getRegistryHub()75     IRegistryHub const& getRegistryHub() {
76         return RegistryHubSingleton::get();
77     }
getMutableRegistryHub()78     IMutableRegistryHub& getMutableRegistryHub() {
79         return RegistryHubSingleton::getMutable();
80     }
cleanUp()81     void cleanUp() {
82         cleanupSingletons();
83         cleanUpContext();
84     }
translateActiveException()85     std::string translateActiveException() {
86         return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
87     }
88 
89 
90 } // end namespace Catch
91