catch2/internal/catch_testcase.hpp

107 lines
2.6 KiB
C++
Raw Normal View History

2010-11-10 00:24:00 +01:00
/*
2011-01-05 22:14:29 +01:00
* catch_testcase.hpp
2010-11-10 00:24:00 +01:00
* Catch
*
* Created by Phil on 29/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_TESTCASEINFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED
#include <map>
#include <string>
namespace Catch
{
struct TestCase
{
virtual ~TestCase(){}
virtual void invoke() const = 0;
virtual TestCase* clone() const = 0;
2010-11-14 23:47:30 +01:00
virtual bool operator == ( const TestCase& other ) const = 0;
virtual bool operator < ( const TestCase& other ) const = 0;
2010-11-10 00:24:00 +01:00
};
class TestCaseInfo
{
public:
TestCaseInfo( TestCase* testCase, const std::string& name, const std::string& description )
: test( testCase ),
name( name ),
description( description )
{
}
TestCaseInfo()
: test( NULL )
{
}
TestCaseInfo( const TestCaseInfo& other )
: test( other.test->clone() ),
name( other.name ),
description( other.description )
{
}
TestCaseInfo& operator = ( const TestCaseInfo& other )
{
2010-11-11 21:37:46 +01:00
TestCaseInfo temp( other );
swap( temp );
2010-11-10 00:24:00 +01:00
return *this;
}
~TestCaseInfo()
{
delete test;
}
void invoke() const
{
test->invoke();
}
const std::string& getName() const
{
return name;
}
const std::string& getDescription() const
{
return description;
}
2010-11-11 21:37:46 +01:00
void swap( TestCaseInfo& other )
{
std::swap( test, other.test );
name.swap( other.name );
description.swap( other.description );
}
2010-11-14 23:47:30 +01:00
bool operator == ( const TestCaseInfo& other ) const
{
return *test == *other.test && name == other.name && description == other.description;
}
bool operator < ( const TestCaseInfo& other ) const
{
if( name < other.name )
return true;
if( name > other.name )
return false;
return *test < *other.test;
}
2010-11-10 00:24:00 +01:00
private:
TestCase* test;
std::string name;
std::string description;
};
}
#endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED