Skip to content

Instantly share code, notes, and snippets.

@3ign0n
Created March 29, 2015 13:46
Show Gist options
  • Save 3ign0n/58c9c34ac2c1c5f9a1ff to your computer and use it in GitHub Desktop.
Save 3ign0n/58c9c34ac2c1c5f9a1ff to your computer and use it in GitHub Desktop.
A MOAspects test case for instance object with class hierarchy
- (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