mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-01 12:55:40 +02:00
first cut of ObjC bindings
This commit is contained in:
@@ -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)();
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user