Skip to content

Commit

Permalink
add test case for commit 20d59c
Browse files Browse the repository at this point in the history
  • Loading branch information
rob2468 committed Oct 11, 2016
1 parent 15415f2 commit f6a5471
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Demo/iOSDemo/JSPatchTests/JPTestObject.h
Expand Up @@ -138,3 +138,17 @@
@interface JPTestProtocolObject : NSObject <JPTestProtocol, JPTestProtocol2>
- (BOOL)testProtocolMethods;
@end

@interface JPTestSwizzledForwardInvocationSuperObject : NSObject

@property (nonatomic, assign) BOOL callSwizzledSuperForwardInvocationPassed;

- (void)swizzleSuperForwoardInvocation;

@end

@interface JPTestSwizzledForwardInvocationSubObject : JPTestSwizzledForwardInvocationSuperObject

- (void)callTestSwizzledSuperForwardInvocation;

@end
44 changes: 44 additions & 0 deletions Demo/iOSDemo/JSPatchTests/JPTestObject.m
Expand Up @@ -7,6 +7,7 @@
//

#import "JPTestObject.h"
#import <objc/runtime.h>

@implementation JPTestObject
- (void)funcReturnVoid
Expand Down Expand Up @@ -576,3 +577,46 @@ - (BOOL)testProtocolMethods
}
#pragma clang diagnostic pop
@end

@implementation JPTestSwizzledForwardInvocationSuperObject

- (void)swizzleSuperForwoardInvocation
{
class_replaceMethod([JPTestSwizzledForwardInvocationSuperObject class], @selector(forwardInvocation:), (IMP)SwizzledSuperForwardInvocation, "v@:@");
}

static void SwizzledSuperForwardInvocation(__unsafe_unretained id assignSlf, SEL selector, NSInvocation *invocation)
{
if ([NSStringFromSelector(invocation.selector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) {
((JPTestSwizzledForwardInvocationSuperObject *)assignSlf).callSwizzledSuperForwardInvocationPassed = YES;
}
}

- (void)forwardInvocation:(NSInvocation *)anInvocation
{
if ([NSStringFromSelector(anInvocation.selector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) {
self.callSwizzledSuperForwardInvocationPassed = NO;
}
}

@end

@implementation JPTestSwizzledForwardInvocationSubObject

- (void)callTestSwizzledSuperForwardInvocation
{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wundeclared-selector"
[self performSelector:@selector(testSwizzledSuperForwardInvocation) withObject:nil];
#pragma clang diagnostic pop
}

- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector
{
if ([NSStringFromSelector(aSelector) isEqualToString:@"testSwizzledSuperForwardInvocation"]) {
return [self methodSignatureForSelector:@selector(callTestSwizzledSuperForwardInvocation)];
}
return [super methodSignatureForSelector:aSelector];
}

@end
7 changes: 7 additions & 0 deletions Demo/iOSDemo/JSPatchTests/JSPatchTests.m
Expand Up @@ -152,6 +152,13 @@ - (void)testEngine {
XCTAssert(subObj.funcCallSuperPassed, @"funcCallSuperPassed");
XCTAssert(obj.callForwardInvocationPassed, @"callForwardInvocationPassed");

JPTestSwizzledForwardInvocationSubObject *tmp = [[JPTestSwizzledForwardInvocationSubObject alloc] init];
[tmp callTestSwizzledSuperForwardInvocation];
XCTAssert(!tmp.callSwizzledSuperForwardInvocationPassed);
[tmp swizzleSuperForwoardInvocation];
[tmp callTestSwizzledSuperForwardInvocation];
XCTAssert(tmp.callSwizzledSuperForwardInvocationPassed);

XCTAssert(obj.propertySetFramePassed, @"propertySetFramePassed");
XCTAssert(obj.propertySetViewPassed, @"propertySetViewPassed");

Expand Down
3 changes: 3 additions & 0 deletions Demo/iOSDemo/JSPatchTests/test.js
Expand Up @@ -107,6 +107,9 @@ require('JPEngine').defineStruct({
return d
}
})
defineClass("JPTestSwizzledForwardInvocationSubObject",{
stubMethod: function() {}
})

var JPTestObject = require("JPTestObject")
var UIView = require("UIView")
Expand Down

0 comments on commit f6a5471

Please sign in to comment.