catch_registry_hub.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include "catch_interfaces_registry_hub.h"
  9. #include "catch_context.h"
  10. #include "catch_test_case_registry_impl.h"
  11. #include "catch_reporter_registry.h"
  12. #include "catch_exception_translator_registry.h"
  13. #include "catch_tag_alias_registry.h"
  14. #include "catch_startup_exception_registry.h"
  15. #include "catch_singletons.hpp"
  16. #include "catch_enum_values_registry.h"
  17. namespace Catch {
  18. namespace {
  19. class RegistryHub : public IRegistryHub, public IMutableRegistryHub,
  20. private NonCopyable {
  21. public: // IRegistryHub
  22. RegistryHub() = default;
  23. IReporterRegistry const& getReporterRegistry() const override {
  24. return m_reporterRegistry;
  25. }
  26. ITestCaseRegistry const& getTestCaseRegistry() const override {
  27. return m_testCaseRegistry;
  28. }
  29. IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const override {
  30. return m_exceptionTranslatorRegistry;
  31. }
  32. ITagAliasRegistry const& getTagAliasRegistry() const override {
  33. return m_tagAliasRegistry;
  34. }
  35. StartupExceptionRegistry const& getStartupExceptionRegistry() const override {
  36. return m_exceptionRegistry;
  37. }
  38. public: // IMutableRegistryHub
  39. void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override {
  40. m_reporterRegistry.registerReporter( name, factory );
  41. }
  42. void registerListener( IReporterFactoryPtr const& factory ) override {
  43. m_reporterRegistry.registerListener( factory );
  44. }
  45. void registerTest( TestCase const& testInfo ) override {
  46. m_testCaseRegistry.registerTest( testInfo );
  47. }
  48. void registerTranslator( const IExceptionTranslator* translator ) override {
  49. m_exceptionTranslatorRegistry.registerTranslator( translator );
  50. }
  51. void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override {
  52. m_tagAliasRegistry.add( alias, tag, lineInfo );
  53. }
  54. void registerStartupException() noexcept override {
  55. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  56. m_exceptionRegistry.add(std::current_exception());
  57. #else
  58. CATCH_INTERNAL_ERROR("Attempted to register active exception under CATCH_CONFIG_DISABLE_EXCEPTIONS!");
  59. #endif
  60. }
  61. IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() override {
  62. return m_enumValuesRegistry;
  63. }
  64. private:
  65. TestRegistry m_testCaseRegistry;
  66. ReporterRegistry m_reporterRegistry;
  67. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  68. TagAliasRegistry m_tagAliasRegistry;
  69. StartupExceptionRegistry m_exceptionRegistry;
  70. Detail::EnumValuesRegistry m_enumValuesRegistry;
  71. };
  72. }
  73. using RegistryHubSingleton = Singleton<RegistryHub, IRegistryHub, IMutableRegistryHub>;
  74. IRegistryHub const& getRegistryHub() {
  75. return RegistryHubSingleton::get();
  76. }
  77. IMutableRegistryHub& getMutableRegistryHub() {
  78. return RegistryHubSingleton::getMutable();
  79. }
  80. void cleanUp() {
  81. cleanupSingletons();
  82. cleanUpContext();
  83. }
  84. std::string translateActiveException() {
  85. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  86. }
  87. } // end namespace Catch