From d283f92c82d871bc26db88161cf6deca4ddf424d Mon Sep 17 00:00:00 2001 From: comex Date: Sat, 17 Jan 2015 14:18:39 -0500 Subject: fixes and test - both tests work on all archs --- test/test-objc-hook.m | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/test-objc-hook.m (limited to 'test') diff --git a/test/test-objc-hook.m b/test/test-objc-hook.m new file mode 100644 index 0000000..ae7d3ff --- /dev/null +++ b/test/test-objc-hook.m @@ -0,0 +1,46 @@ +#include "substitute.h" +#import + +@interface Base : NSObject { +} +- (void)foo:(NSString *)str; +- (void)bar:(NSString *)str; +@end + +@implementation Base +- (void)foo:(NSString *)str { + NSLog(@"base foo: %@", str); +} +- (void)bar:(NSString *)str { + NSLog(@"base bar: %@", str); +} +@end + +@interface Derived : Base { +} +@end + +@implementation Derived +- (void)foo:(NSString *)str { + NSLog(@"derived foo: %@", str); +} +@end + +static void (*old_foo)(id, SEL, NSString *); +static void new_foo(id self, SEL sel, NSString *str) { + NSLog(@"new foo: %@; calling orig", str); + return old_foo(self, sel, str); +} +static void (*old_bar)(id, SEL, NSString *); +static void new_bar(id self, SEL sel, NSString *str) { + NSLog(@"new bar: %@; calling orig", str); + return old_bar(self, sel, str); +} + +int main() { + assert(!substitute_hook_objc_message([Derived class], @selector(foo:), new_foo, &old_foo, NULL)); + assert(!substitute_hook_objc_message([Derived class], @selector(bar:), new_bar, &old_bar, NULL)); + Derived *d = [[Derived alloc] init]; + [d foo:@"hi!"]; + [d bar:@"hello!"]; +} -- cgit v1.2.3