Created
March 29, 2015 13:46
-
-
Save 3ign0n/58c9c34ac2c1c5f9a1ff to your computer and use it in GitHub Desktop.
A MOAspects test case for instance object with class hierarchy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)testChildInstance | |
{ | |
NSString *string; | |
MOAspectsTestChildObject* testChildObj = [[MOAspectsTestChildObject alloc] init]; | |
string = [testChildObj stringWithBOOL:YES]; | |
XCTAssertTrue([string isEqualToString:@"真"]); | |
string = [testChildObj stringWithBOOL:NO]; | |
XCTAssertTrue([string isEqualToString:@"偽"]); | |
__block NSString *hookedString; | |
[MOAspects hookClassMethodForClass:[testChildObj class] | |
selector:@selector(stringWithBOOL:) | |
aspectsPosition:MOAspectsPositionBefore | |
usingBlock:^(id target, BOOL BOOLVar){ | |
hookedString = BOOLVar ? @"真" : @"偽"; | |
}]; | |
hookedString = nil; | |
string = [testChildObj stringWithBOOL:YES]; | |
XCTAssertTrue([string isEqualToString:@"真"]); | |
XCTAssertNotNil(hookedString); | |
XCTAssertTrue([string isEqualToString:hookedString]); | |
hookedString = nil; | |
string = [testChildObj stringWithBOOL:NO]; | |
XCTAssertTrue([string isEqualToString:@"偽"]); | |
XCTAssertNotNil(hookedString); | |
XCTAssertTrue([string isEqualToString:hookedString]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment