first cut of ObjC bindings

This commit is contained in:
Phil Nash 2010-11-14 22:47:30 +00:00
parent 635216e2c6
commit d52f61cc67
13 changed files with 641 additions and 3 deletions

View File

@ -0,0 +1,24 @@
//
// CatchOCTestCase.h
// OCTest
//
// Created by Phil on 13/11/2010.
// Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
//
#include "../../../catch_objc.hpp"
#import <Cocoa/Cocoa.h>
#import "TestObj.h"
@interface TestFixture : NSObject
{
TestObj* obj;
}
@end
CATCH_REGISTER_CLASS( TestFixture )

View File

@ -0,0 +1,49 @@
//
// CatchOCTestCase.mm
// OCTest
//
// Created by Phil Nash on 13/11/2010.
// Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
//
#import "CatchOCTestCase.h"
@implementation TestFixture
- (id) init
{
self = [super init];
if (self != nil)
{
obj = [[TestObj alloc] init];
}
return self;
}
- (void) dealloc
{
[obj release];
[super dealloc];
}
OC_TEST_CASE( "OCTest/test1", "This is a test case" )
{
EXPECT( obj.int_val == 0 );
obj.int_val = 1;
EXPECT( obj.int_val == 1 );
}
OC_TEST_CASE( "OCTest/test2", "This is another test case" )
{
EXPECT( obj.int_val == 0 );
obj.int_val = 2;
EXPECT( obj.int_val == 2 );
}
@end

14
Test/Xcode/OCTest/Main.mm Normal file
View File

@ -0,0 +1,14 @@
#import <Foundation/Foundation.h>
#import "../../../catch_runner.hpp"
#import "CatchOCTestCase.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
int result = Catch::Main( argc, (char* const*)argv );
[pool drain];
return result;
}

View File

@ -0,0 +1,79 @@
.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
.\"See Also:
.\"man mdoc.samples for a complete listing of options
.\"man mdoc for the short list of editing options
.\"/usr/share/misc/mdoc.template
.Dd 13/11/2010 \" DATE
.Dt OCTest 1 \" Program name and manual section number
.Os Darwin
.Sh NAME \" Section Header - required - don't modify
.Nm OCTest,
.\" The following lines are read in generating the apropos(man -k) database. Use only key
.\" words here as the database is built based on the words here and in the .ND line.
.Nm Other_name_for_same_program(),
.Nm Yet another name for the same program.
.\" Use .Nm macro to designate other names for the documented program.
.Nd This line parsed for whatis database.
.Sh SYNOPSIS \" Section Header - required - don't modify
.Nm
.Op Fl abcd \" [-abcd]
.Op Fl a Ar path \" [-a path]
.Op Ar file \" [file]
.Op Ar \" [file ...]
.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
arg2 ... \" Arguments
.Sh DESCRIPTION \" Section Header - required - don't modify
Use the .Nm macro to refer to your program throughout the man page like such:
.Nm
Underlining is accomplished with the .Ar macro like this:
.Ar underlined text .
.Pp \" Inserts a space
A list of items with descriptions:
.Bl -tag -width -indent \" Begins a tagged list
.It item a \" Each item preceded by .It macro
Description of item a
.It item b
Description of item b
.El \" Ends the list
.Pp
A list of flags and their descriptions:
.Bl -tag -width -indent \" Differs from above in tag removed
.It Fl a \"-a flag as a list item
Description of -a flag
.It Fl b
Description of -b flag
.El \" Ends the list
.Pp
.\" .Sh ENVIRONMENT \" May not be needed
.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
.\" .It Ev ENV_VAR_1
.\" Description of ENV_VAR_1
.\" .It Ev ENV_VAR_2
.\" Description of ENV_VAR_2
.\" .El
.Sh FILES \" File used or created by the topic of the man page
.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
.It Pa /usr/share/file_name
FILE_1 description
.It Pa /Users/joeuser/Library/really_long_file_name
FILE_2 description
.El \" Ends the list
.\" .Sh DIAGNOSTICS \" May not be needed
.\" .Bl -diag
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .It Diagnostic Tag
.\" Diagnostic informtion here.
.\" .El
.Sh SEE ALSO
.\" List links in ascending order by section, alphabetically within a section.
.\" Please do not reference files that do not exist without filing a bug report
.Xr a 1 ,
.Xr b 1 ,
.Xr c 1 ,
.Xr a 2 ,
.Xr b 2 ,
.Xr a 3 ,
.Xr b 3
.\" .Sh BUGS \" Document known, unremedied bugs
.\" .Sh HISTORY \" Document history if command behaves in a unique manner

View File

@ -0,0 +1,25 @@
/*
* OCTest.mm
* OCTest
*
* Created by Phil on 13/11/2010.
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
*
*/
#import "../../../catch.hpp"
#import "TestObj.h"
TEST_CASE( "OCTest/TestObj", "tests TestObj" )
{
TestObj* obj = [[TestObj alloc] init];
EXPECT( obj.int_val == 0 );
obj.int_val = 1;
EXPECT( obj.int_val == 1 );
[obj release];
}

View File

@ -0,0 +1,237 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objects = {
/* Begin PBXBuildFile section */
4A5953B5128E95B8009DC1B9 /* TestObj.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5953B4128E95B8009DC1B9 /* TestObj.m */; };
4A5953B7128E95D6009DC1B9 /* OCTest.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A5953B6128E95D6009DC1B9 /* OCTest.mm */; };
4A5953F1128E9A61009DC1B9 /* CatchOCTestCase.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4A5953F0128E9A61009DC1B9 /* CatchOCTestCase.mm */; };
8DD76F9A0486AA7600D96B5E /* Main.mm in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* Main.mm */; settings = {ATTRIBUTES = (); }; };
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 08FB779EFE84155DC02AAC07 /* Foundation.framework */; };
8DD76F9F0486AA7600D96B5E /* OCTest.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6859EA3029092ED04C91782 /* OCTest.1 */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
8DD76F9E0486AA7600D96B5E /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 8;
dstPath = /usr/share/man/man1/;
dstSubfolderSpec = 0;
files = (
8DD76F9F0486AA7600D96B5E /* OCTest.1 in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 1;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
08FB7796FE84155DC02AAC07 /* Main.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = Main.mm; sourceTree = "<group>"; };
08FB779EFE84155DC02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
32A70AAB03705E1F00C91783 /* OCTest_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCTest_Prefix.pch; sourceTree = "<group>"; };
4A5953B3128E95B8009DC1B9 /* TestObj.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestObj.h; sourceTree = "<group>"; };
4A5953B4128E95B8009DC1B9 /* TestObj.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestObj.m; sourceTree = "<group>"; };
4A5953B6128E95D6009DC1B9 /* OCTest.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OCTest.mm; sourceTree = "<group>"; };
4A5953EF128E9A61009DC1B9 /* CatchOCTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CatchOCTestCase.h; sourceTree = "<group>"; };
4A5953F0128E9A61009DC1B9 /* CatchOCTestCase.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = CatchOCTestCase.mm; sourceTree = "<group>"; };
8DD76FA10486AA7600D96B5E /* OCTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = OCTest; sourceTree = BUILT_PRODUCTS_DIR; };
C6859EA3029092ED04C91782 /* OCTest.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = OCTest.1; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8DD76F9B0486AA7600D96B5E /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8DD76F9C0486AA7600D96B5E /* Foundation.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
08FB7794FE84155DC02AAC07 /* OCTest */ = {
isa = PBXGroup;
children = (
08FB7795FE84155DC02AAC07 /* Source */,
C6859EA2029092E104C91782 /* Documentation */,
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */,
1AB674ADFE9D54B511CA2CBB /* Products */,
);
name = OCTest;
sourceTree = "<group>";
};
08FB7795FE84155DC02AAC07 /* Source */ = {
isa = PBXGroup;
children = (
32A70AAB03705E1F00C91783 /* OCTest_Prefix.pch */,
08FB7796FE84155DC02AAC07 /* Main.mm */,
4A5953B3128E95B8009DC1B9 /* TestObj.h */,
4A5953B4128E95B8009DC1B9 /* TestObj.m */,
4A5953B6128E95D6009DC1B9 /* OCTest.mm */,
4A5953EF128E9A61009DC1B9 /* CatchOCTestCase.h */,
4A5953F0128E9A61009DC1B9 /* CatchOCTestCase.mm */,
);
name = Source;
sourceTree = "<group>";
};
08FB779DFE84155DC02AAC07 /* External Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
08FB779EFE84155DC02AAC07 /* Foundation.framework */,
);
name = "External Frameworks and Libraries";
sourceTree = "<group>";
};
1AB674ADFE9D54B511CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8DD76FA10486AA7600D96B5E /* OCTest */,
);
name = Products;
sourceTree = "<group>";
};
C6859EA2029092E104C91782 /* Documentation */ = {
isa = PBXGroup;
children = (
C6859EA3029092ED04C91782 /* OCTest.1 */,
);
name = Documentation;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
8DD76F960486AA7600D96B5E /* OCTest */ = {
isa = PBXNativeTarget;
buildConfigurationList = 1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "OCTest" */;
buildPhases = (
8DD76F990486AA7600D96B5E /* Sources */,
8DD76F9B0486AA7600D96B5E /* Frameworks */,
8DD76F9E0486AA7600D96B5E /* CopyFiles */,
);
buildRules = (
);
dependencies = (
);
name = OCTest;
productInstallPath = "$(HOME)/bin";
productName = OCTest;
productReference = 8DD76FA10486AA7600D96B5E /* OCTest */;
productType = "com.apple.product-type.tool";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "OCTest" */;
compatibilityVersion = "Xcode 3.1";
hasScannedForEncodings = 1;
mainGroup = 08FB7794FE84155DC02AAC07 /* OCTest */;
projectDirPath = "";
projectRoot = "";
targets = (
8DD76F960486AA7600D96B5E /* OCTest */,
);
};
/* End PBXProject section */
/* Begin PBXSourcesBuildPhase section */
8DD76F990486AA7600D96B5E /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8DD76F9A0486AA7600D96B5E /* Main.mm in Sources */,
4A5953B5128E95B8009DC1B9 /* TestObj.m in Sources */,
4A5953B7128E95D6009DC1B9 /* OCTest.mm in Sources */,
4A5953F1128E9A61009DC1B9 /* CatchOCTestCase.mm in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin XCBuildConfiguration section */
1DEB927508733DD40010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_MODEL_TUNING = G5;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = OCTest_Prefix.pch;
INSTALL_PATH = /usr/local/bin;
PRODUCT_NAME = OCTest;
};
name = Debug;
};
1DEB927608733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
GCC_MODEL_TUNING = G5;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = OCTest_Prefix.pch;
INSTALL_PATH = /usr/local/bin;
PRODUCT_NAME = OCTest;
};
name = Release;
};
1DEB927908733DD40010E9CD /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Debug;
};
1DEB927A08733DD40010E9CD /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
SDKROOT = macosx10.6;
};
name = Release;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
1DEB927408733DD40010E9CD /* Build configuration list for PBXNativeTarget "OCTest" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB927508733DD40010E9CD /* Debug */,
1DEB927608733DD40010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "OCTest" */ = {
isa = XCConfigurationList;
buildConfigurations = (
1DEB927908733DD40010E9CD /* Debug */,
1DEB927A08733DD40010E9CD /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}

View File

@ -0,0 +1,7 @@
//
// Prefix header for all source files of the 'OCTest' target in the 'OCTest' project.
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#endif

View File

@ -0,0 +1,19 @@
//
// TestObj.h
// OCTest
//
// Created by Phil on 13/11/2010.
// Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface TestObj : NSObject {
int int_val;
}
@property (nonatomic, assign ) int int_val;
@end

View File

@ -0,0 +1,16 @@
//
// TestObj.m
// OCTest
//
// Created by Phil on 13/11/2010.
// Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
//
#import "TestObj.h"
@implementation TestObj
@synthesize int_val;
@end

View File

@ -52,6 +52,7 @@
4A59538C128E93E1009DC1B9 /* catch_runnerconfig.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_runnerconfig.hpp; path = ../../internal/catch_runnerconfig.hpp; sourceTree = SOURCE_ROOT; };
4A59538D128E93E1009DC1B9 /* catch_section.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_section.hpp; path = ../../internal/catch_section.hpp; sourceTree = SOURCE_ROOT; };
4A59538E128E93E1009DC1B9 /* catch_testcaseinfo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_testcaseinfo.hpp; path = ../../internal/catch_testcaseinfo.hpp; sourceTree = SOURCE_ROOT; };
4A5955C412909CCC009DC1B9 /* catch_objc.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_objc.hpp; path = ../../catch_objc.hpp; sourceTree = SOURCE_ROOT; };
8DD76F6C0486A84900D96B5E /* Test */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = Test; sourceTree = BUILT_PRODUCTS_DIR; };
C6859E8B029090EE04C91782 /* Test.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = Test.1; sourceTree = "<group>"; };
/* End PBXFileReference section */
@ -110,6 +111,7 @@
4AFC341312809A12003A0C29 /* Catch */ = {
isa = PBXGroup;
children = (
4A5955C412909CCC009DC1B9 /* catch_objc.hpp */,
4A59537F128E93CA009DC1B9 /* catch_default_main.hpp */,
4A595380128E93CA009DC1B9 /* catch_reporter_basic.hpp */,
4A595381128E93CA009DC1B9 /* catch_reporter_xml.hpp */,

117
catch_objc.hpp Normal file
View File

@ -0,0 +1,117 @@
/*
* catch_objc.hpp
* Test
*
* Created by Phil on 14/11/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_OBJC_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
#import <objc/runtime.h>
#include <string>
#include "catch.hpp"
namespace Catch
{
template<typename T>
class OcMethod : public TestCase
{
public:
OcMethod( SEL sel ) : m_sel( sel )
{
}
virtual void invoke() const
{
T* obj = [[T alloc] init];
if( [obj respondsToSelector: m_sel] )
[obj performSelector: m_sel];
[obj release];
}
virtual TestCase* clone() const
{
return new OcMethod<T>( m_sel );
}
virtual bool operator == ( const TestCase& other ) const
{
const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
return ocmOther && ocmOther->m_sel == m_sel;
}
virtual bool operator < ( const TestCase& other ) const
{
const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
return ocmOther && ocmOther->m_sel < m_sel;
}
private:
SEL m_sel;
};
template<typename T>
struct OcAutoReg
{
OcAutoReg()
{
u_int count;
Method* methods = class_copyMethodList([T class], &count);
for( int i = 0; i < count ; i++ )
{
SEL selector = method_getName(methods[i]);
std::string methodName = sel_getName(selector);
if( startsWith( methodName, "Catch_TestCase_" ) )
{
std::string testCaseName = methodName.substr( 15 );
std::string name = getAnnotation( "Name", testCaseName );
std::string desc = getAnnotation( "Description", testCaseName );
TestRegistry::instance().registerTest( TestCaseInfo( new OcMethod<T>( selector ), name, desc ) );
}
}
free(methods);
}
private:
bool startsWith( const std::string& str, const std::string& sub )
{
return str.length() > sub.length() && str.substr( 0, sub.length() ) == sub;
}
const char* getAnnotation( const std::string& annotationName, const std::string& testCaseName )
{
NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
SEL sel = NSSelectorFromString( selStr );
[selStr release];
if( [[T class] respondsToSelector: sel] )
return (const char*)[[T class] performSelector: sel];
return "";
}
};
}
#define CATCH_REGISTER_CLASS( className ) namespace{ Catch::OcAutoReg<className> reg; }
#define OC_TEST_CASE( name, desc )\
+(const char*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
{\
return name; \
}\
+(const char*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
{ \
return desc; \
} \
-(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
#endif // TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED

View File

@ -16,8 +16,11 @@
#include "catch_common.h"
#include <vector>
#include <set>
#include <stdexcept>
#include <iostream>
namespace Catch
{
class TestRegistry
@ -32,17 +35,22 @@ public:
void registerTest( const TestCaseInfo& testInfo )
{
m_functions.push_back( testInfo );
if( m_functions.find( testInfo ) == m_functions.end() )
{
m_functions.insert( testInfo );
m_functionsInOrder.push_back( testInfo );
}
}
std::vector<TestCaseInfo> getAllTests() const
{
return m_functions;
return m_functionsInOrder;
}
private:
std::vector<TestCaseInfo> m_functions;
std::set<TestCaseInfo> m_functions;
std::vector<TestCaseInfo> m_functionsInOrder;
};
typedef void(*TestFunction)();
@ -63,6 +71,18 @@ struct FreeFunctionTestCase : TestCase
return new FreeFunctionTestCase( fun );
}
virtual bool operator == ( const TestCase& other ) const
{
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun == ffOther->fun;
}
virtual bool operator < ( const TestCase& other ) const
{
const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
return ffOther && fun < ffOther->fun;
}
private:
TestFunction fun;
};
@ -84,6 +104,18 @@ struct MethodTestCase : TestCase
{
return new MethodTestCase<C>( method );
}
virtual bool operator == ( const TestCase& other ) const
{
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && method == mtOther->method;
}
virtual bool operator < ( const TestCase& other ) const
{
const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
return mtOther && &method < &mtOther->method;
}
private:
void (C::*method)();

View File

@ -23,6 +23,8 @@ namespace Catch
virtual ~TestCase(){}
virtual void invoke() const = 0;
virtual TestCase* clone() const = 0;
virtual bool operator == ( const TestCase& other ) const = 0;
virtual bool operator < ( const TestCase& other ) const = 0;
};
class TestCaseInfo
@ -79,6 +81,21 @@ namespace Catch
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:
TestCase* test;
std::string name;