1 /* 2 * Created by Phil on 8/8/12 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 #ifndef TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED 9 #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED 10 11 #include "catch_assertionresult.h" 12 13 namespace Catch { 14 15 AssertionInfo()16 AssertionInfo::AssertionInfo():macroName(""), capturedExpression(""), resultDisposition(ResultDisposition::Normal), secondArg(""){} 17 AssertionInfo(char const * _macroName,SourceLineInfo const & _lineInfo,char const * _capturedExpression,ResultDisposition::Flags _resultDisposition,char const * _secondArg)18 AssertionInfo::AssertionInfo( char const * _macroName, 19 SourceLineInfo const& _lineInfo, 20 char const * _capturedExpression, 21 ResultDisposition::Flags _resultDisposition, 22 char const * _secondArg) 23 : macroName( _macroName ), 24 lineInfo( _lineInfo ), 25 capturedExpression( _capturedExpression ), 26 resultDisposition( _resultDisposition ), 27 secondArg( _secondArg ) 28 {} 29 AssertionResult()30 AssertionResult::AssertionResult() {} 31 AssertionResult(AssertionInfo const & info,AssertionResultData const & data)32 AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) 33 : m_info( info ), 34 m_resultData( data ) 35 {} 36 ~AssertionResult()37 AssertionResult::~AssertionResult() {} 38 39 // Result was a success succeeded() const40 bool AssertionResult::succeeded() const { 41 return Catch::isOk( m_resultData.resultType ); 42 } 43 44 // Result was a success, or failure is suppressed isOk() const45 bool AssertionResult::isOk() const { 46 return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); 47 } 48 getResultType() const49 ResultWas::OfType AssertionResult::getResultType() const { 50 return m_resultData.resultType; 51 } 52 hasExpression() const53 bool AssertionResult::hasExpression() const { 54 return m_info.capturedExpression[0] != 0; 55 } 56 hasMessage() const57 bool AssertionResult::hasMessage() const { 58 return !m_resultData.message.empty(); 59 } 60 capturedExpressionWithSecondArgument(char const * capturedExpression,char const * secondArg)61 std::string capturedExpressionWithSecondArgument( char const * capturedExpression, char const * secondArg ) { 62 return (secondArg[0] == 0 || secondArg[0] == '"' && secondArg[1] == '"') 63 ? capturedExpression 64 : std::string(capturedExpression) + ", " + secondArg; 65 } 66 getExpression() const67 std::string AssertionResult::getExpression() const { 68 if( isFalseTest( m_info.resultDisposition ) ) 69 return '!' + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg); 70 else 71 return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg); 72 } getExpressionInMacro() const73 std::string AssertionResult::getExpressionInMacro() const { 74 if( m_info.macroName[0] == 0 ) 75 return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg); 76 else 77 return std::string(m_info.macroName) + "( " + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + " )"; 78 } 79 hasExpandedExpression() const80 bool AssertionResult::hasExpandedExpression() const { 81 return hasExpression() && getExpandedExpression() != getExpression(); 82 } 83 getExpandedExpression() const84 std::string AssertionResult::getExpandedExpression() const { 85 return m_resultData.reconstructExpression(); 86 } 87 getMessage() const88 std::string AssertionResult::getMessage() const { 89 return m_resultData.message; 90 } getSourceInfo() const91 SourceLineInfo AssertionResult::getSourceInfo() const { 92 return m_info.lineInfo; 93 } 94 getTestMacroName() const95 std::string AssertionResult::getTestMacroName() const { 96 return m_info.macroName; 97 } 98 discardDecomposedExpression() const99 void AssertionResult::discardDecomposedExpression() const { 100 m_resultData.decomposedExpression = CATCH_NULL; 101 } 102 expandDecomposedExpression() const103 void AssertionResult::expandDecomposedExpression() const { 104 m_resultData.reconstructExpression(); 105 } 106 107 } // end namespace Catch 108 109 #endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED 110