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 9 #include "catch_assertionresult.h" 10 11 namespace Catch { AssertionResultData(ResultWas::OfType _resultType,LazyExpression const & _lazyExpression)12 AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): 13 lazyExpression(_lazyExpression), 14 resultType(_resultType) {} 15 reconstructExpression() const16 std::string AssertionResultData::reconstructExpression() const { 17 18 if( reconstructedExpression.empty() ) { 19 if( lazyExpression ) { 20 ReusableStringStream rss; 21 rss << lazyExpression; 22 reconstructedExpression = rss.str(); 23 } 24 } 25 return reconstructedExpression; 26 } 27 AssertionResult(AssertionInfo const & info,AssertionResultData const & data)28 AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) 29 : m_info( info ), 30 m_resultData( data ) 31 {} 32 33 // Result was a success succeeded() const34 bool AssertionResult::succeeded() const { 35 return Catch::isOk( m_resultData.resultType ); 36 } 37 38 // Result was a success, or failure is suppressed isOk() const39 bool AssertionResult::isOk() const { 40 return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); 41 } 42 getResultType() const43 ResultWas::OfType AssertionResult::getResultType() const { 44 return m_resultData.resultType; 45 } 46 hasExpression() const47 bool AssertionResult::hasExpression() const { 48 return m_info.capturedExpression[0] != 0; 49 } 50 hasMessage() const51 bool AssertionResult::hasMessage() const { 52 return !m_resultData.message.empty(); 53 } 54 getExpression() const55 std::string AssertionResult::getExpression() const { 56 if( isFalseTest( m_info.resultDisposition ) ) 57 return "!(" + m_info.capturedExpression + ")"; 58 else 59 return m_info.capturedExpression; 60 } 61 getExpressionInMacro() const62 std::string AssertionResult::getExpressionInMacro() const { 63 std::string expr; 64 if( m_info.macroName[0] == 0 ) 65 expr = m_info.capturedExpression; 66 else { 67 expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); 68 expr += m_info.macroName; 69 expr += "( "; 70 expr += m_info.capturedExpression; 71 expr += " )"; 72 } 73 return expr; 74 } 75 hasExpandedExpression() const76 bool AssertionResult::hasExpandedExpression() const { 77 return hasExpression() && getExpandedExpression() != getExpression(); 78 } 79 getExpandedExpression() const80 std::string AssertionResult::getExpandedExpression() const { 81 std::string expr = m_resultData.reconstructExpression(); 82 return expr.empty() 83 ? getExpression() 84 : expr; 85 } 86 getMessage() const87 std::string AssertionResult::getMessage() const { 88 return m_resultData.message; 89 } getSourceInfo() const90 SourceLineInfo AssertionResult::getSourceInfo() const { 91 return m_info.lineInfo; 92 } 93 getTestMacroName() const94 StringRef AssertionResult::getTestMacroName() const { 95 return m_info.macroName; 96 } 97 98 } // end namespace Catch 99