Skip to content

Commit 70091f1

Browse files
committed
test: avoid hard UIKit links in fixtures
1 parent b139d41 commit 70091f1

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

test/runtime/fixtures/Marshalling/TNSObjCTypes.m

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#import "TNSObjCTypes.h"
22

3-
#if TARGET_OS_IPHONE
4-
#import <UIKit/UIKit.h>
5-
#endif
3+
#import <objc/message.h>
64

75
void TNSFunctionWithCFTypeRefArgument(CFTypeRef x) {
86
NSString* str = (__bridge NSString*)x;
@@ -21,14 +19,25 @@ CFTypeRef TNSFunctionWithCreateCFTypeRefReturn() {
2119
return 0;
2220
}
2321

22+
Class controllerClass = NSClassFromString(@"UITabBarController");
23+
if (controllerClass == nil) {
24+
return 0;
25+
}
26+
27+
SEL newSelector = sel_registerName("new");
28+
SEL viewSelector = sel_registerName("view");
2429
uintptr_t sink = 0;
2530
CFAbsoluteTime startedAt = CFAbsoluteTimeGetCurrent();
2631
for (int i = 0; i < iterations; i++) {
2732
@autoreleasepool {
28-
UITabBarController* controller = [UITabBarController new];
29-
sink ^= touchView ? (uintptr_t)controller.view : (uintptr_t)controller;
33+
id controller = ((id (*)(Class, SEL))objc_msgSend)(controllerClass, newSelector);
34+
if (touchView) {
35+
sink ^= (uintptr_t)((id (*)(id, SEL))objc_msgSend)(controller, viewSelector);
36+
} else {
37+
sink ^= (uintptr_t)controller;
38+
}
3039
#if !__has_feature(objc_arc)
31-
[controller release];
40+
((void (*)(id, SEL))objc_msgSend)(controller, sel_registerName("release"));
3241
#endif
3342
}
3443
}
@@ -43,11 +52,18 @@ CFTypeRef TNSFunctionWithCreateCFTypeRefReturn() {
4352
return 0;
4453
}
4554

55+
Class colorClass = NSClassFromString(@"UIColor");
56+
if (colorClass == nil) {
57+
return 0;
58+
}
59+
60+
SEL colorSelector = sel_registerName("colorWithRed:green:blue:alpha:");
4661
uintptr_t sink = 0;
4762
CFAbsoluteTime startedAt = CFAbsoluteTimeGetCurrent();
4863
for (int i = 0; i < iterations; i++) {
4964
@autoreleasepool {
50-
UIColor* color = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:1];
65+
id color = ((id (*)(Class, SEL, double, double, double, double))objc_msgSend)(
66+
colorClass, colorSelector, 0.1, 0.2, 0.3, 1.0);
5167
sink ^= (uintptr_t)color;
5268
}
5369
}

0 commit comments

Comments
 (0)