mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 15:12:21 +00:00
More experiments with NSProxy
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
@interface MPEntryProxy ()
|
@interface MPEntryProxy ()
|
||||||
|
|
||||||
@property (strong) KPKEntry *entry;
|
@property (strong) KPKEntry *entry;
|
||||||
|
@property (strong) NSMutableDictionary *valueStore;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@@ -22,13 +23,35 @@
|
|||||||
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:nil userInfo:nil];
|
@throw [NSException exceptionWithName:NSInvalidArgumentException reason:nil userInfo:nil];
|
||||||
}
|
}
|
||||||
_entry = entry;
|
_entry = entry;
|
||||||
|
_valueStore = [[NSMutableDictionary alloc] init];
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)forwardInvocation:(NSInvocation *)invocation {
|
- (void)forwardInvocation:(NSInvocation *)invocation {
|
||||||
NSLog(@"forwardInvocation: %@", NSStringFromSelector(invocation.selector));
|
NSLog(@"forwardInvocation: %@", NSStringFromSelector(invocation.selector));
|
||||||
|
NSString *seletor = NSStringFromSelector(invocation.selector);
|
||||||
|
if([seletor hasPrefix:@"set"]) {
|
||||||
|
NSLog(@"forwardInvocation: setter detected");
|
||||||
|
NSString *property = [seletor substringFromIndex:3].lowercaseString; // lowercase fist letter!!!
|
||||||
|
if(invocation.methodSignature.numberOfArguments == 3) {
|
||||||
|
id value;
|
||||||
|
[invocation getArgument:&value atIndex:2];
|
||||||
|
NSLog(@"forwardInvocation: captured value %@", value);
|
||||||
|
if(value) {
|
||||||
|
self.valueStore[property] = value;
|
||||||
|
}
|
||||||
|
return; // captures getter, just return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
id change = self.valueStore[seletor.lowercaseString];
|
||||||
|
if(change) {
|
||||||
|
NSLog(@"forwardInvocation: hit cached value. Returning cache!");
|
||||||
|
[invocation setReturnValue:&change];
|
||||||
|
}
|
||||||
|
else {
|
||||||
[invocation invokeWithTarget:self.entry];
|
[invocation invokeWithTarget:self.entry];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
|
- (NSMethodSignature *)methodSignatureForSelector:(SEL)sel {
|
||||||
NSLog(@"methodSignatureForSelector %@", NSStringFromSelector(sel));
|
NSLog(@"methodSignatureForSelector %@", NSStringFromSelector(sel));
|
||||||
|
|||||||
@@ -41,7 +41,7 @@
|
|||||||
NSString *newPassword = @"new password";
|
NSString *newPassword = @"new password";
|
||||||
NSString *newKeystrokes = @"{ENTER 3}";
|
NSString *newKeystrokes = @"{ENTER 3}";
|
||||||
[((id)self.proxy) setPassword:newPassword];
|
[((id)self.proxy) setPassword:newPassword];
|
||||||
XCTAssertEqualObjects(self.entry.password, newPassword, @"Proxy sets password on entry!");
|
XCTAssertNotEqualObjects(self.entry.password, newPassword, @"Proxy does not set password on entry!");
|
||||||
|
|
||||||
[((id)self.proxy) autotype].defaultKeystrokeSequence= newKeystrokes;
|
[((id)self.proxy) autotype].defaultKeystrokeSequence= newKeystrokes;
|
||||||
XCTAssertEqualObjects(self.entry.autotype.defaultKeystrokeSequence, newKeystrokes, @"Proxy sets default keystroke sequence on entry autotype!");
|
XCTAssertEqualObjects(self.entry.autotype.defaultKeystrokeSequence, newKeystrokes, @"Proxy sets default keystroke sequence on entry autotype!");
|
||||||
|
|||||||
Reference in New Issue
Block a user