8#ifndef TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
9#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
13#import <objc/runtime.h>
41 OcMethod( Class cls,
SEL sel ) : m_cls( cls ), m_sel( sel ) {}
44 id obj = [[m_cls alloc] init];
63 std::string
const& annotationName,
64 std::string
const& testCaseName ) {
65 NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
66 SEL sel = NSSelectorFromString( selStr );
70 return [(NSString*)value UTF8String];
76 std::size_t noTestMethods = 0;
77 int noClasses = objc_getClassList(
nullptr, 0 );
80 objc_getClassList( classes, noClasses );
82 for(
int c = 0; c < noClasses; c++ ) {
83 Class cls = classes[c];
86 Method* methods = class_copyMethodList( cls, &
count );
87 for( u_int m = 0; m <
count ; m++ ) {
88 SEL selector = method_getName(methods[m]);
89 std::string methodName = sel_getName(selector);
90 if(
startsWith( methodName,
"Catch_TestCase_" ) ) {
91 std::string testCaseName = methodName.substr( 15 );
94 const char* className = class_getName( cls );
103 return noTestMethods;
106#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
110 namespace NSStringMatchers {
113 StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
114 StringHolder( StringHolder
const& other ) : m_substr( [other.m_substr copy] ){}
119 bool match( NSString*
const& str )
const override {
126 struct Equals : StringHolder {
127 Equals( NSString* substr ) : StringHolder( substr ){}
129 bool match( NSString*
const& str )
const override {
130 return (str != nil || m_substr == nil ) &&
131 [str isEqualToString:m_substr];
134 std::string describe()
const override {
139 struct Contains : StringHolder {
140 Contains( NSString* substr ) : StringHolder( substr ){}
142 bool match( NSString*
const& str )
const override {
143 return (str != nil || m_substr == nil ) &&
144 [str rangeOfString:m_substr].location != NSNotFound;
147 std::string describe()
const override {
152 struct StartsWith : StringHolder {
153 StartsWith( NSString* substr ) : StringHolder( substr ){}
155 bool match( NSString*
const& str )
const override {
156 return (str != nil || m_substr == nil ) &&
157 [str rangeOfString:m_substr].location == 0;
160 std::string describe()
const override {
164 struct EndsWith : StringHolder {
165 EndsWith( NSString* substr ) : StringHolder( substr ){}
167 bool match( NSString*
const& str )
const override {
168 return (str != nil || m_substr == nil ) &&
169 [str rangeOfString:m_substr].location == [str length] - [m_substr length];
172 std::string describe()
const override {
180 inline Impl::NSStringMatchers::Equals
181 Equals( NSString* substr ){
return Impl::NSStringMatchers::Equals( substr ); }
183 inline Impl::NSStringMatchers::Contains
184 Contains( NSString* substr ){
return Impl::NSStringMatchers::Contains( substr ); }
186 inline Impl::NSStringMatchers::StartsWith
187 StartsWith( NSString* substr ){
return Impl::NSStringMatchers::StartsWith( substr ); }
189 inline Impl::NSStringMatchers::EndsWith
190 EndsWith( NSString* substr ){
return Impl::NSStringMatchers::EndsWith( substr ); }
194 using namespace Matchers;
201#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
202#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
203+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
207+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
211-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
213#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
void arcSafeRelease(NSObject *obj)
id performOptionalSelector(id obj, SEL sel)
#define CATCH_UNSAFE_UNRETAINED
OcMethod(Class cls, SEL sel)
virtual void invoke() const
std::string getAnnotation(Class cls, std::string const &annotationName, std::string const &testCaseName)
std::string stringify(const T &e)
StdString::StartsWithMatcher StartsWith(std::string const &str, CaseSensitive::Choice caseSensitivity)
StdString::EqualsMatcher Equals(std::string const &str, CaseSensitive::Choice caseSensitivity)
StdString::EndsWithMatcher EndsWith(std::string const &str, CaseSensitive::Choice caseSensitivity)
StdString::ContainsMatcher Contains(std::string const &str, CaseSensitive::Choice caseSensitivity)
TestCase makeTestCase(ITestInvoker *_testCase, std::string const &_className, NameAndTags const &nameAndTags, SourceLineInfo const &_lineInfo)
IMutableRegistryHub & getMutableRegistryHub()
bool startsWith(std::string const &s, std::string const &prefix)
std::size_t registerTestMethods()
virtual void registerTest(TestCase const &testInfo)=0