Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 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 | |
Phil Nash | 42d1b45 | 2012-11-13 21:59:50 +0000 | [diff] [blame^] | 15 | |
| 16 | AssertionInfo::AssertionInfo( const std::string& _macroName, |
| 17 | const SourceLineInfo& _lineInfo, |
| 18 | const std::string& _capturedExpression, |
| 19 | ResultDisposition::Flags _resultDisposition ) |
| 20 | : macroName( _macroName ), |
| 21 | lineInfo( _lineInfo ), |
| 22 | capturedExpression( _capturedExpression ), |
| 23 | resultDisposition( _resultDisposition ) |
| 24 | { |
| 25 | if( shouldNegate( resultDisposition ) ) |
| 26 | capturedExpression = "!" + _capturedExpression; |
| 27 | } |
| 28 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 29 | AssertionResult::AssertionResult() {} |
| 30 | |
| 31 | AssertionResult::AssertionResult( const AssertionInfo& info, const AssertionResultData& data ) |
| 32 | : m_info( info ), |
| 33 | m_resultData( data ) |
| 34 | {} |
| 35 | |
| 36 | AssertionResult::~AssertionResult() {} |
| 37 | |
Phil Nash | 42d1b45 | 2012-11-13 21:59:50 +0000 | [diff] [blame^] | 38 | // Result was a success |
| 39 | bool AssertionResult::succeeded() const { |
| 40 | return Catch::isOk( m_resultData.resultType ); |
| 41 | } |
| 42 | |
| 43 | // Result was a success, or failure is suppressed |
| 44 | bool AssertionResult::isOk() const { |
| 45 | return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | ResultWas::OfType AssertionResult::getResultType() const { |
| 49 | return m_resultData.resultType; |
| 50 | } |
| 51 | |
| 52 | bool AssertionResult::hasExpression() const { |
| 53 | return !m_info.capturedExpression.empty(); |
| 54 | } |
| 55 | |
| 56 | bool AssertionResult::hasMessage() const { |
| 57 | return !m_resultData.message.empty(); |
| 58 | } |
| 59 | |
| 60 | std::string AssertionResult::getExpression() const { |
| 61 | return m_info.capturedExpression; |
| 62 | } |
| 63 | |
| 64 | bool AssertionResult::hasExpandedExpression() const { |
| 65 | return hasExpression() && getExpandedExpression() != getExpression(); |
| 66 | } |
| 67 | |
| 68 | std::string AssertionResult::getExpandedExpression() const { |
| 69 | return m_resultData.reconstructedExpression; |
| 70 | } |
| 71 | |
| 72 | std::string AssertionResult::getMessage() const { |
| 73 | return m_resultData.message; |
| 74 | } |
| 75 | SourceLineInfo AssertionResult::getSourceInfo() const { |
| 76 | return m_info.lineInfo; |
| 77 | } |
| 78 | |
| 79 | std::string AssertionResult::getTestMacroName() const { |
| 80 | return m_info.macroName; |
| 81 | } |
| 82 | |
| 83 | } // end namespace Catch |
| 84 | |
| 85 | #endif // TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED |