/* * Created by Phil on 28/5/2014. * Copyright 2014 Two Blue Cubes Ltd. All rights reserved. * * 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_RESULT_BUILDER_H_INCLUDED #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED #include "catch_assertionresult.h" #include "catch_decomposer.h" #include "catch_result_type.h" #include "catch_common.h" #include "catch_matchers.hpp" #include namespace Catch { template class ExpressionLhs; struct CopyableStream { CopyableStream() = default; CopyableStream( CopyableStream const& other ); CopyableStream& operator=( CopyableStream const& other ); std::ostringstream oss; }; class ResultBuilder : public DecomposedExpression { public: ResultBuilder( StringRef macroName, SourceLineInfo const& lineInfo, StringRef capturedExpression, ResultDisposition::Flags resultDisposition); ~ResultBuilder(); template ExpressionLhs operator <= ( T const& operand ); ExpressionLhs operator <= ( bool value ); template ResultBuilder& operator << ( T const& value ) { stream().oss << value; return *this; } ResultBuilder& setResultType( ResultWas::OfType result ); ResultBuilder& setResultType( bool result ); void endExpression( DecomposedExpression const& expr ); void reconstructExpression( std::string& dest ) const override; AssertionResult build() const; AssertionResult build( DecomposedExpression const& expr ) const; void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); void captureResult( ResultWas::OfType resultType ); void captureExpression(); #if !defined(CATCH_CONFIG_DISABLE_MATCHERS) void captureExpectedException( std::string const& expectedMessage ); void captureExpectedException( Matchers::Impl::MatcherBase const& matcher ); #endif // CATCH_CONFIG_DISABLE_MATCHERS void handleResult( AssertionResult const& result ); void react(); bool shouldDebugBreak() const; bool allowThrows() const; template void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString ); void setExceptionGuard(); void unsetExceptionGuard(); private: AssertionInfo m_assertionInfo; AssertionResultData m_data; CopyableStream& stream(); static CopyableStream& s_stream(); bool m_shouldDebugBreak = false; bool m_shouldThrow = false; bool m_guardException = false; bool m_usedStream = false; }; } // namespace Catch // Include after due to circular dependency: #include "catch_expression_lhs.hpp" namespace Catch { template ExpressionLhs ResultBuilder::operator <= ( T const& operand ) { return ExpressionLhs( *this, operand ); } inline ExpressionLhs ResultBuilder::operator <= ( bool value ) { return ExpressionLhs( *this, value ); } template void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString ) { MatchExpression expr( arg, matcher, matcherString ); setResultType( matcher.match( arg ) ); endExpression( expr ); } } // namespace Catch #endif // TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED