2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* catch_resultinfo.hpp
|
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* Created by Phil on 28/10/2010.
|
|
|
|
* Copyright 2010 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_INFO_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include <string>
|
2011-01-11 10:13:31 +01:00
|
|
|
#include "catch_result_type.h"
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
|
|
|
class ResultInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
ResultInfo
|
|
|
|
()
|
2011-09-23 10:03:52 +02:00
|
|
|
: m_macroName(),
|
|
|
|
m_expr(),
|
|
|
|
m_lhs(),
|
|
|
|
m_rhs(),
|
|
|
|
m_op(),
|
|
|
|
m_message(),
|
2010-12-28 15:17:27 +01:00
|
|
|
m_result( ResultWas::Unknown ),
|
2011-03-10 20:18:14 +01:00
|
|
|
m_isNot( false )
|
2010-11-10 00:24:00 +01:00
|
|
|
{}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
ResultInfo
|
|
|
|
(
|
|
|
|
const char* expr,
|
|
|
|
ResultWas::OfType result,
|
2012-05-08 20:16:18 +02:00
|
|
|
bool isNot,
|
|
|
|
const SourceLineInfo& lineInfo,
|
2011-03-10 15:09:32 +01:00
|
|
|
const char* macroName,
|
|
|
|
const char* message
|
2011-01-11 20:48:48 +01:00
|
|
|
)
|
2010-12-28 15:17:27 +01:00
|
|
|
: m_macroName( macroName ),
|
2012-05-08 20:16:18 +02:00
|
|
|
m_lineInfo( lineInfo ),
|
2010-12-28 15:17:27 +01:00
|
|
|
m_expr( expr ),
|
2012-03-04 12:14:21 +01:00
|
|
|
m_lhs(),
|
|
|
|
m_rhs(),
|
2011-03-01 10:55:17 +01:00
|
|
|
m_op( isNotExpression( expr ) ? "!" : "" ),
|
2011-03-10 15:09:32 +01:00
|
|
|
m_message( message ),
|
2010-11-10 00:24:00 +01:00
|
|
|
m_result( result ),
|
2011-03-10 20:18:14 +01:00
|
|
|
m_isNot( isNot )
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-01-07 10:38:32 +01:00
|
|
|
if( isNot )
|
|
|
|
m_expr = "!" + m_expr;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-09-23 10:03:52 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2012-02-10 09:30:13 +01:00
|
|
|
virtual ~ResultInfo
|
2011-09-23 10:03:52 +02:00
|
|
|
()
|
2012-02-10 09:30:13 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
bool ok
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2010-11-29 20:40:44 +01:00
|
|
|
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
ResultWas::OfType getResultType
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return m_result;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
bool hasExpression
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return !m_expr.empty();
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
bool hasMessage
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return !m_message.empty();
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getExpression
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return m_expr;
|
|
|
|
}
|
2011-01-11 20:48:48 +01:00
|
|
|
|
2012-05-04 08:55:11 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
bool hasExpandedExpression
|
|
|
|
()
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getExpandedExpression
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2011-03-11 20:45:36 +01:00
|
|
|
return hasExpression() ? getExpandedExpressionInternal() : "";
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getMessage
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return m_message;
|
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getFilename
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2012-05-08 20:16:18 +02:00
|
|
|
return m_lineInfo.file;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::size_t getLine
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
2012-05-08 20:16:18 +02:00
|
|
|
return m_lineInfo.line;
|
2010-11-10 00:24:00 +01:00
|
|
|
}
|
|
|
|
|
2011-01-11 20:48:48 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getTestMacroName
|
|
|
|
()
|
|
|
|
const
|
2010-11-10 00:24:00 +01:00
|
|
|
{
|
|
|
|
return m_macroName;
|
|
|
|
}
|
2010-11-11 08:21:57 +01:00
|
|
|
|
|
|
|
protected:
|
2011-01-11 20:48:48 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
2011-01-28 19:56:26 +01:00
|
|
|
std::string getExpandedExpressionInternal
|
|
|
|
()
|
|
|
|
const
|
2010-11-11 08:21:57 +01:00
|
|
|
{
|
|
|
|
if( m_op == "" || m_isNot )
|
|
|
|
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
2012-03-04 12:14:21 +01:00
|
|
|
else if( m_op == "matches" )
|
|
|
|
return m_lhs + " " + m_rhs;
|
2010-11-11 08:21:57 +01:00
|
|
|
else if( m_op != "!" )
|
2012-05-07 20:12:43 +02:00
|
|
|
{
|
|
|
|
if( m_lhs.size() + m_rhs.size() < 30 )
|
|
|
|
return m_lhs + " " + m_op + " " + m_rhs;
|
|
|
|
else if( m_lhs.size() < 70 && m_rhs.size() < 70 )
|
|
|
|
return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs;
|
|
|
|
else
|
|
|
|
return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n";
|
|
|
|
}
|
2010-11-11 08:21:57 +01:00
|
|
|
else
|
2012-05-04 08:55:11 +02:00
|
|
|
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
2010-11-11 08:21:57 +01:00
|
|
|
}
|
2011-03-01 10:55:17 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
bool isNotExpression
|
|
|
|
(
|
|
|
|
const char* expr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return expr && expr[0] == '!';
|
|
|
|
}
|
2010-11-10 00:24:00 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string m_macroName;
|
2012-05-08 20:16:18 +02:00
|
|
|
SourceLineInfo m_lineInfo;
|
2010-11-10 00:24:00 +01:00
|
|
|
std::string m_expr, m_lhs, m_rhs, m_op;
|
|
|
|
std::string m_message;
|
|
|
|
ResultWas::OfType m_result;
|
|
|
|
bool m_isNot;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|