catch_reporter_registrars.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Created by Phil on 31/12/2010.
  3. * Copyright 2010 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. #ifndef TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  10. #include "catch_interfaces_registry_hub.h"
  11. namespace Catch {
  12. template<typename T>
  13. class ReporterRegistrar {
  14. class ReporterFactory : public IReporterFactory {
  15. IStreamingReporterPtr create( ReporterConfig const& config ) const override {
  16. return std::unique_ptr<T>( new T( config ) );
  17. }
  18. std::string getDescription() const override {
  19. return T::getDescription();
  20. }
  21. };
  22. public:
  23. explicit ReporterRegistrar( std::string const& name ) {
  24. getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
  25. }
  26. };
  27. template<typename T>
  28. class ListenerRegistrar {
  29. class ListenerFactory : public IReporterFactory {
  30. IStreamingReporterPtr create( ReporterConfig const& config ) const override {
  31. return std::unique_ptr<T>( new T( config ) );
  32. }
  33. std::string getDescription() const override {
  34. return std::string();
  35. }
  36. };
  37. public:
  38. ListenerRegistrar() {
  39. getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
  40. }
  41. };
  42. }
  43. #if !defined(CATCH_CONFIG_DISABLE)
  44. #define CATCH_REGISTER_REPORTER( name, reporterType ) \
  45. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  46. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  47. namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
  48. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  49. #define CATCH_REGISTER_LISTENER( listenerType ) \
  50. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  51. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  52. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
  53. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  54. #else // CATCH_CONFIG_DISABLE
  55. #define CATCH_REGISTER_REPORTER(name, reporterType)
  56. #define CATCH_REGISTER_LISTENER(listenerType)
  57. #endif // CATCH_CONFIG_DISABLE
  58. #endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED