/* * catch_testcase.hpp * 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 #include namespace Catch { struct ITestCase { virtual ~ITestCase(){} virtual void invoke() const = 0; virtual ITestCase* clone() const = 0; virtual bool operator == ( const ITestCase& other ) const = 0; virtual bool operator < ( const ITestCase& other ) const = 0; }; class TestCaseInfo { public: TestCaseInfo( ITestCase* testCase, const char* name, const char* 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 ) { TestCaseInfo temp( other ); swap( temp ); return *this; } ~TestCaseInfo() { delete test; } void invoke() const { test->invoke(); } const std::string& getName() const { return name; } const std::string& getDescription() const { return description; } void swap( TestCaseInfo& other ) { std::swap( test, other.test ); name.swap( other.name ); description.swap( other.description ); } 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; } private: ITestCase* test; std::string name; std::string description; }; } #endif // TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED