forked from FLEXTool/FLEX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FLEXTestsMethodsList.m
101 lines (83 loc) · 2.93 KB
/
FLEXTestsMethodsList.m
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// FLEXTestMethodList.m
// FLEXTestMethodList
//
// Created by Tigran Yesayan on 7/6/17.
// Copyright © 2017 Flipboard. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "FLEXRuntimeUtility.h"
#import "FLEXManager.h"
#import "FLEXWindow.h"
#import "FLEXMultiColumnTableView.h"
@interface FLEXRuntimeUtility (Testing)
+ (NSString *)readableTypeForEncoding:(NSString *)encodingString;
@end
@interface FLEXTestMethodList : XCTestCase
@end
@implementation FLEXTestMethodList
- (void)testExample {
NSArray<Class> *classesToTest = @[
[NSObject class],
[NSArray class],
[UIApplication class],
[UIView class],
[NSThread class],
[CALayer class],
[NSDictionary class],
[NSProxy class],
[NSData class],
[FLEXManager class],
[FLEXWindow class],
[FLEXMultiColumnTableView class],
[NSString class],
[NSSet class],
[NSUndoManager class],
[NSMutableArray class],
[NSMutableDictionary class],
[NSException class],
[UIImage class],
[UIViewController class],
[UIScreen class],
[UIResponder class],
[NSNumber class],
[NSValue class],
[NSError class],
[NSNotificationCenter class],
[NSUserActivity class],
[NSUserDefaults class],
[NSExpression class],
[NSBundle class]
];
for (Class cls in classesToTest) {
[self testMethodListForClass:cls];
}
}
- (void)testMethodListForClass:(Class)class {
NSLog(@"class: %@", NSStringFromClass(class));
unsigned int methodCount = 0;
Method *methods = class_copyMethodList(class, &methodCount);
for (unsigned int i = 0; i < methodCount; ++i) {
Method method = methods[i];
NSArray *prevWay = [self prettyArgumentComponentsForMethod:method];
NSArray *newWay = [FLEXRuntimeUtility prettyArgumentComponentsForMethod:method];
XCTAssertEqualObjects(prevWay, newWay);
}
free(methods);
}
#pragma mark - Method to test with
- (NSArray *)prettyArgumentComponentsForMethod:(Method)method {
NSMutableArray *components = [NSMutableArray new];
NSString *selectorName = NSStringFromSelector(method_getName(method));
NSArray *selectorComponents = [selectorName componentsSeparatedByString:@":"];
unsigned int numberOfArguments = method_getNumberOfArguments(method);
for (unsigned int argIndex = kFLEXNumberOfImplicitArgs; argIndex < numberOfArguments; argIndex++) {
char *argType = method_copyArgumentType(method, argIndex);
NSString *readableArgType = [FLEXRuntimeUtility readableTypeForEncoding:@(argType)];
free(argType);
NSString *prettyComponent = [NSString stringWithFormat:@"%@:(%@) ", [selectorComponents objectAtIndex:argIndex - kFLEXNumberOfImplicitArgs], readableArgType];
[components addObject:prettyComponent];
}
return components;
}
@end