aboutsummaryrefslogtreecommitdiff
path: root/test/test-objc-hook.m
diff options
context:
space:
mode:
authorcomex2015-01-17 14:18:39 -0500
committercomex2015-01-17 14:18:39 -0500
commitd283f92c82d871bc26db88161cf6deca4ddf424d (patch)
treec5b1ea5ea9c5759c2d17451b5ce81c48915d4242 /test/test-objc-hook.m
parentimp forwarding works (diff)
downloadsubstitute-d283f92c82d871bc26db88161cf6deca4ddf424d.tar.gz
fixes and test - both tests work on all archs
Diffstat (limited to 'test/test-objc-hook.m')
-rw-r--r--test/test-objc-hook.m46
1 files changed, 46 insertions, 0 deletions
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 <Foundation/Foundation.h>
+
+@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!"];
+}