1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#import <Foundation/Foundation.h>
#import "Testing.h"
static NSString *desc = @"[MyObject]";
static NSString *
myObjectDescription(id self, SEL _cmd)
{
return desc;
}
int
main(void)
{
id obj;
Class cls;
NSAutoreleasePool *pool;
pool = [NSAutoreleasePool new];
cls = (Class)objc_allocateClassPair([NSObject class], "MyObject", 0);
if (cls != Nil)
{
objc_registerClassPair(cls);
class_addMethod(cls, @selector(description),
(IMP)myObjectDescription, "@@:");
obj = [cls new];
pass([obj description] == desc, "New class's description method is called correctly");
[obj release];
}
return 0;
}
|