catch2/include/internal/catch_vs_managed_impl.hpp

95 lines
3.0 KiB
C++

/*
* Created by Malcolm on 10/11/2013.
* Copyright 2013 Malcolm Noyes
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_VS_MANAGED_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_VS_MANAGED_HPP_INCLUDED
#ifdef INTERNAL_CATCH_VS_MANAGED
#include <windows.h>
using namespace System;
using namespace System::Text;
using namespace System::Collections::Generic;
using namespace Microsoft::VisualStudio::TestTools::UnitTesting;
namespace Catch {
inline String^ convert_string_to_managed(const std::string& s)
{
String^ result = gcnew String(s.c_str());
return result;
}
}
#include "internal/catch_timer.hpp"
#include "internal/catch_vs_test_registry.hpp"
#include "reporters/catch_vs_reporter.hpp"
#include "internal/catch_exception_translator_registry.hpp"
namespace Catch {
class ExceptionRegistryHub : public IRegistryHub, public IMutableRegistryHub {
ExceptionRegistryHub( ExceptionRegistryHub const& );
void operator=( ExceptionRegistryHub const& );
public: // IRegistryHub
ExceptionRegistryHub() {
}
virtual IReporterRegistry const& getReporterRegistry() const {
throw std::runtime_error("can't do this for Visual Studio tests!");
}
virtual ITestCaseRegistry const& getTestCaseRegistry() const {
throw std::runtime_error("can't do this for Visual Studio tests!");
}
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() {
return m_exceptionTranslatorRegistry;
}
public: // IMutableRegistryHub
virtual void registerReporter( std::string const&, IReporterFactory* ) {
throw std::runtime_error("can't do this for Visual Studio tests!");
}
virtual void registerTest( TestCase const& ) {
throw std::runtime_error("can't do this for Visual Studio tests!");
}
virtual void registerTranslator( const IExceptionTranslator* translator ) {
m_exceptionTranslatorRegistry.registerTranslator( translator );
}
private:
ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
};
template <typename T>
struct GlobalRegistryHub
{
static T& instance()
{
if( !theRegistryHub )
theRegistryHub = new T();
return *theRegistryHub;
}
static T* theRegistryHub;
};
template <typename T>
T* GlobalRegistryHub<T>::theRegistryHub = NULL;
INTERNAL_CATCH_INLINE IMutableRegistryHub& getMutableRegistryHub() {
return GlobalRegistryHub<ExceptionRegistryHub>::instance();
}
INTERNAL_CATCH_INLINE std::string translateActiveException() {
return GlobalRegistryHub<ExceptionRegistryHub>::instance().getExceptionTranslatorRegistry().translateActiveException();
}
}
#endif
#endif // TWOBLUECUBES_CATCH_VS_MANAGED_HPP_INCLUDED