Use NSProxy as base class for FBApplicationProcessProxy #979
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,18 @@ @implementation FBApplicationProcessProxy | |
+ (instancetype)proxyWithApplicationProcess:(XCUIApplicationProcess *)applicationProcess | ||
{ | ||
NSParameterAssert(applicationProcess); | ||
FBApplicationProcessProxy *proxy = [self.class new]; | ||
NSParameterAssert([[applicationProcess class] isEqual:XCUIApplicationProcess.class]); | ||
FBApplicationProcessProxy *proxy = [[self.class alloc] init]; | ||
proxy.applicationProcess = applicationProcess; | ||
return proxy; | ||
} | ||
|
||
- (instancetype)init { | ||
return self; | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
} | ||
|
||
#pragma mark - Override XCUIApplicationProcess methods | ||
|
||
- (void)waitForQuiescence | ||
{ | ||
if (!self.shouldWaitForQuiescence) { | ||
|
@@ -45,9 +52,16 @@ - (void)waitForQuiescenceIncludingAnimationsIdle:(BOOL)includeAnimations | |
[self.applicationProcess waitForQuiescenceIncludingAnimationsIdle:includeAnimations]; | ||
} | ||
|
||
- (id)forwardingTargetForSelector:(SEL)aSelector | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why kill There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't done any benchmarking, and implemented the only two required methods. if this is faster, then let's use it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://developer.apple.com/documentation/objectivec/nsobject/1418855-forwardingtargetforselector
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Simple benchmark with 10 million invocations answers the question "How |
||
#pragma mark - Forward not implemented methods to applicationProcess | ||
|
||
- (void)forwardInvocation:(NSInvocation *)invocation | ||
{ | ||
[invocation invokeWithTarget:self.applicationProcess]; | ||
} | ||
|
||
- (nullable NSMethodSignature *)methodSignatureForSelector:(SEL)sel | ||
{ | ||
return self.applicationProcess; | ||
return [self.applicationProcess methodSignatureForSelector:sel]; | ||
} | ||
|
||
@end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "FBApplicationProcessProxy.h" | ||
#import "XCUIApplicationProcess.h" | ||
|
||
@interface FBApplicationProcessProxy (NonProxiedMethod) | ||
- (void)objectsMethod; | ||
@end | ||
|
||
@implementation FBApplicationProcessProxy (NonProxiedMethod) | ||
|
||
- (void)objectsMethod | ||
{ | ||
// intentionally empty | ||
} | ||
|
||
@end | ||
|
||
@interface FBApplicationProcessProxy (ProxiedMethod) | ||
- (NSInteger)proxiedMethod; | ||
@end | ||
|
||
@interface XCUIApplicationProcess (TestableMethods) | ||
- (void)objectsMethod; | ||
- (int)proxiedMethod; | ||
@end | ||
|
||
@implementation XCUIApplicationProcess (TestableMethods) | ||
|
||
- (int)proxiedMethod; | ||
{ | ||
return 1; | ||
} | ||
|
||
- (void)objectsMethod | ||
{ | ||
NSString *errorMessage = [NSString stringWithFormat:@"Method %@ must NOT be proxied", NSStringFromSelector(_cmd)]; | ||
NSException * exception = [[NSException alloc] initWithName:@"Test failed" reason:errorMessage userInfo:nil]; | ||
[exception raise]; | ||
} | ||
|
||
@end | ||
|
||
@interface FBApplicationProcessProxyTest : XCTestCase | ||
|
||
@end | ||
|
||
@implementation FBApplicationProcessProxyTest | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
|
||
- (void)testMethodCallIsProxied { | ||
XCUIApplicationProcess *applicationProcess = [[XCUIApplicationProcess alloc] init]; | ||
FBApplicationProcessProxy *proxy = [FBApplicationProcessProxy proxyWithApplicationProcess:applicationProcess]; | ||
XCTAssertEqual([proxy proxiedMethod], 1); | ||
} | ||
|
||
- (void)testMethodCallIsNotProxied { | ||
XCUIApplicationProcess *applicationProcess = [[XCUIApplicationProcess alloc] init]; | ||
FBApplicationProcessProxy *proxy = [FBApplicationProcessProxy proxyWithApplicationProcess:applicationProcess]; | ||
XCTAssertNoThrow([proxy objectsMethod]); | ||
} | ||
|
||
- (void)testProxyIsProxy { | ||
XCUIApplicationProcess *applicationProcess = [[XCUIApplicationProcess alloc] init]; | ||
FBApplicationProcessProxy *proxy = [FBApplicationProcessProxy proxyWithApplicationProcess:applicationProcess]; | ||
XCTAssertTrue([proxy isProxy]); | ||
} | ||
|
||
- (void)testAssertProxyObjectParameter { | ||
XCUIApplicationProcess *applicationProcess = [[XCUIApplicationProcess alloc] init]; | ||
id proxy = (id)[FBApplicationProcessProxy proxyWithApplicationProcess:applicationProcess]; | ||
XCTAssertThrows([FBApplicationProcessProxy proxyWithApplicationProcess:proxy]); | ||
} | ||
|
||
@end |
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.