Created
March 29, 2015 13:16
-
-
Save 3ign0n/fdb60f836da3aeff447f to your computer and use it in GitHub Desktop.
just a test with MOAspects
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
// | |
// MOAspectsClassHierarchyTestCase.m | |
// MOAspectsDemo | |
#import <UIKit/UIKit.h> | |
#import <XCTest/XCTest.h> | |
#import "MOAspects.h" | |
@interface BAZBase: NSObject | |
@end | |
@implementation BAZBase | |
-(BOOL)foobar:(long long)arg1 | |
{ | |
if (arg1 > 100) | |
{ | |
return YES; | |
} | |
return NO; | |
} | |
@end | |
@interface BAZA: BAZBase | |
@end | |
@implementation BAZA | |
-(BOOL)foobar:(long long)arg1 | |
{ | |
if (arg1 > 1) | |
{ | |
return YES; | |
} | |
return NO; | |
} | |
-(BOOL)superFoobar:(long long)arg1 | |
{ | |
return [super foobar:arg1]; | |
} | |
@end | |
@interface BAZB: BAZBase | |
@end | |
@implementation BAZB | |
-(BOOL)foobar:(long long)arg1 | |
{ | |
if (arg1 > 0) | |
{ | |
return YES; | |
} | |
return NO; | |
} | |
@end | |
@interface BAZC: BAZA | |
@end | |
@implementation BAZC | |
-(BOOL)foobar:(long long)arg1 | |
{ | |
if (arg1 > 2) | |
{ | |
return YES; | |
} | |
return NO; | |
} | |
@end | |
@interface MOAspectsClassHierarchyTestCase : XCTestCase | |
@end | |
@implementation MOAspectsClassHierarchyTestCase | |
- (void)setUp { | |
[super setUp]; | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
} | |
- (void)tearDown { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
[super tearDown]; | |
} | |
- (void)testExample { | |
__block BOOL isCalled1 = NO; | |
[MOAspects hookInstanceMethodForClass:[BAZBase class] selector:@selector(foobar:) aspectsPosition:MOAspectsPositionAfter usingBlock:^(id obj, long long arg1){ | |
NSLog(@"===========hooked BAZBase %lld", arg1); | |
isCalled1 = YES; | |
}]; | |
__block BOOL isCalled2 = NO; | |
[MOAspects hookInstanceMethodForClass:[BAZA class] selector:@selector(foobar:) aspectsPosition:MOAspectsPositionAfter usingBlock:^(id obj, long long arg1){ | |
NSLog(@"===========hooked BAZA %lld", arg1); | |
isCalled2 = YES; | |
}]; | |
__block BOOL isCalled3 = NO; | |
[MOAspects hookInstanceMethodForClass:[BAZB class] selector:@selector(foobar:) aspectsPosition:MOAspectsPositionAfter usingBlock:^(id obj, long long arg1){ | |
NSLog(@"===========hooked BAZB %lld", arg1); | |
isCalled3 = YES; | |
}]; | |
__block BOOL isCalled4 = NO; | |
[MOAspects hookInstanceMethodForClass:[BAZC class] selector:@selector(foobar:) aspectsPosition:MOAspectsPositionAfter usingBlock:^(id obj, long long arg1){ | |
NSLog(@"===========hooked BAZC %lld", arg1); | |
isCalled4 = YES; | |
}]; | |
BAZA* BAZa = [[BAZA alloc] init]; | |
long long ll = 5; | |
[BAZa foobar:ll]; | |
XCTAssertFalse(isCalled1); | |
XCTAssertTrue(isCalled2); | |
XCTAssertFalse(isCalled3); | |
XCTAssertFalse(isCalled4); | |
/* | |
[BAZa superFoobar:ll]; | |
XCTAssertFalse(isCalled1); | |
XCTAssertTrue(isCalled2); | |
XCTAssertFalse(isCalled3); | |
XCTAssertFalse(isCalled4); | |
*/ | |
BAZB* BAZb = [[BAZB alloc] init]; | |
[BAZb foobar:ll]; | |
XCTAssertFalse(isCalled1); | |
XCTAssertTrue(isCalled2); | |
XCTAssertTrue(isCalled3); | |
XCTAssertFalse(isCalled4); | |
BAZC* BAZc = [[BAZC alloc] init]; | |
[BAZc foobar:ll]; | |
XCTAssertFalse(isCalled1); | |
XCTAssertTrue(isCalled2); | |
XCTAssertTrue(isCalled3); | |
XCTAssertTrue(isCalled4); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment