catch2/include/internal/catch_test_case_info.hpp

122 lines
3.6 KiB
C++
Raw Normal View History

/*
2012-08-14 20:30:30 +02:00
* Created by Phil on 14/08/2012.
* Copyright 2012 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_TEST_CASE_INFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
#include "catch_tags.hpp"
2012-08-14 20:30:30 +02:00
#include "catch_test_case_info.h"
#include "catch_interfaces_testcase.h"
2012-05-16 00:58:23 +02:00
namespace Catch {
2012-11-22 20:17:20 +01:00
TestCase::TestCase( ITestCase* testCase,
const std::string& className,
const std::string& name,
const std::string& description,
2012-08-14 20:30:30 +02:00
const SourceLineInfo& lineInfo )
: m_test( testCase ),
m_className( className ),
2012-08-14 20:30:30 +02:00
m_name( name ),
m_description( description ),
m_lineInfo( lineInfo ),
m_isHidden( startsWith( name, "./" ) )
2012-09-15 18:53:27 +02:00
{
TagExtracter( m_tags ).parse( m_description );
2012-09-15 18:53:27 +02:00
if( hasTag( "hide" ) )
m_isHidden = true;
}
2012-11-22 20:17:20 +01:00
TestCase::TestCase()
2012-08-14 20:30:30 +02:00
: m_test( NULL ),
m_className(),
2012-08-14 20:30:30 +02:00
m_name(),
m_description(),
m_isHidden( false )
2012-08-14 20:30:30 +02:00
{}
2012-08-14 09:38:22 +02:00
2012-11-22 20:17:20 +01:00
TestCase::TestCase( const TestCase& other, const std::string& name )
2012-08-14 20:30:30 +02:00
: m_test( other.m_test ),
m_className( other.m_className ),
2012-08-14 20:30:30 +02:00
m_name( name ),
m_description( other.m_description ),
2012-09-15 18:53:27 +02:00
m_tags( other.m_tags ),
m_lineInfo( other.m_lineInfo ),
m_isHidden( other.m_isHidden )
2012-08-14 20:30:30 +02:00
{}
2012-11-22 20:17:20 +01:00
TestCase::TestCase( const TestCase& other )
: m_test( other.m_test ),
m_className( other.m_className ),
m_name( other.m_name ),
m_description( other.m_description ),
2012-09-15 18:53:27 +02:00
m_tags( other.m_tags ),
m_lineInfo( other.m_lineInfo ),
m_isHidden( other.m_isHidden )
{}
2012-11-22 20:17:20 +01:00
void TestCase::invoke() const {
2012-08-14 20:30:30 +02:00
m_test->invoke();
}
2012-11-22 20:17:20 +01:00
const std::string& TestCase::getClassName() const {
return m_className;
}
2012-11-22 20:17:20 +01:00
const std::string& TestCase::getName() const {
2012-08-14 20:30:30 +02:00
return m_name;
}
2012-11-22 20:17:20 +01:00
const std::string& TestCase::getDescription() const {
2012-08-14 20:30:30 +02:00
return m_description;
}
2012-11-22 20:17:20 +01:00
const SourceLineInfo& TestCase::getLineInfo() const {
2012-08-14 20:30:30 +02:00
return m_lineInfo;
}
2012-11-22 20:17:20 +01:00
bool TestCase::isHidden() const {
return m_isHidden;
2012-08-14 20:30:30 +02:00
}
2012-11-22 20:17:20 +01:00
bool TestCase::hasTag( const std::string& tag ) const {
2012-09-15 18:53:27 +02:00
return m_tags.find( tag ) != m_tags.end();
}
2012-11-22 20:17:20 +01:00
bool TestCase::matchesTags( const std::string& tagPattern ) const {
TagExpression exp;
TagExpressionParser( exp ).parse( tagPattern );
return exp.matches( m_tags );
}
2012-11-22 20:17:20 +01:00
const std::set<std::string>& TestCase::getTags() const {
2012-09-15 18:53:27 +02:00
return m_tags;
}
2012-11-22 20:17:20 +01:00
void TestCase::swap( TestCase& other ) {
2012-08-14 20:30:30 +02:00
m_test.swap( other.m_test );
m_className.swap( other.m_className );
2012-08-14 20:30:30 +02:00
m_name.swap( other.m_name );
m_description.swap( other.m_description );
std::swap( m_lineInfo, other.m_lineInfo );
2012-08-14 20:30:30 +02:00
}
2012-11-22 20:17:20 +01:00
bool TestCase::operator == ( const TestCase& other ) const {
return m_test.get() == other.m_test.get() &&
m_name == other.m_name &&
m_className == other.m_className;
2012-08-14 20:30:30 +02:00
}
2012-11-22 20:17:20 +01:00
bool TestCase::operator < ( const TestCase& other ) const {
2012-08-14 20:30:30 +02:00
return m_name < other.m_name;
}
2012-11-22 20:17:20 +01:00
TestCase& TestCase::operator = ( const TestCase& other ) {
TestCase temp( other );
swap( temp );
return *this;
}
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED