More improvements on modelchangeobserving

This commit is contained in:
michael starke
2016-08-29 17:44:32 +02:00
parent 0bf439e01d
commit cd47237742
8 changed files with 134 additions and 10 deletions

View File

@@ -16,6 +16,8 @@
#import "MPAutotypePaste.h"
#import "MPAutotypeKeyPress.h"
#import "MPSettingsHelper.h"
#import "MPKeyMapper.h"
@@ -196,7 +198,13 @@
keyPress = commands[0];
/* Lower case is ok, since we only need the key, not the sequence to reproduce the string */
XCTAssertTrue([@"t" isEqualToString:[MPKeyMapper stringForKey:keyPress.keyCode]]);
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand);
BOOL useCommandInsteadOfControl = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeySendCommandForControlKey];
if(useCommandInsteadOfControl) {
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand);
}
else {
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskControl);
}
/* {USERNAME} */
paste = commands[1];
@@ -205,7 +213,12 @@
/* %+^{TAB} */
keyPress = commands[2];
XCTAssertEqual(keyPress.keyCode, kVK_Tab); // Tab is a fixed key, no mapping needed
XCTAssertEqual(keyPress.modifierMask, (kCGEventFlagMaskCommand | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate));
if(useCommandInsteadOfControl) {
XCTAssertEqual(keyPress.modifierMask, (kCGEventFlagMaskCommand | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate));
}
else {
XCTAssertEqual(keyPress.modifierMask, (kCGEventFlagMaskControl | kCGEventFlagMaskShift | kCGEventFlagMaskAlternate));
}
/* Whoo{PASSWORD} */
paste = commands[3];
@@ -228,7 +241,12 @@
keyPress = commands[0];
XCTAssertEqualObjects(@"t", [MPKeyMapper stringForKey:keyPress.keyCode]);
/* TODO - Respect user settings? */
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand);
if(useCommandInsteadOfControl) {
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskCommand);
}
else {
XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskControl);
}
/*XCTAssertEqual(keyPress.modifierMask, kCGEventFlagMaskControl);*/
}

View File

@@ -0,0 +1,43 @@
//
// MPTestModelChangeObservingHelper.m
// MacPass
//
// Created by Michael Starke on 29/08/16.
// Copyright © 2016 HicknHack Software GmbH. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "MPModelChangeObserving.h"
@interface MPTestModelChangeObservingHelper : XCTestCase
@property (strong) MPModelChangeObservingHelper *helper;
@end
@implementation MPTestModelChangeObservingHelper
- (void)setUp {
[super setUp];
self.helper = [[MPModelChangeObservingHelper alloc] init];
}
- (void)tearDown {
self.helper = nil;
[super tearDown];
}
- (void)testAddObserver {
[self.helper beginObservingModelChangesForKeyPath:@"testKey"];
NSMutableSet *set = [self.helper valueForKey:@"observedPaths"];
XCTAssertEqual(set.count, 1, @"Observed paths contains one element");
XCTAssertTrue([set containsObject:@"testKey"], @"Observed set contains testKey");
}
- (void)testRemoveObserver {
NSString *aKeyPath = @"testKeyPath";
[self.helper beginObservingModelChangesForKeyPath:aKeyPath];
[self.helper endObservingModelChangesForKeyPath:aKeyPath];
NSMutableSet *set = [self.helper valueForKey:@"observedPaths"];
XCTAssertFalse([set containsObject:aKeyPath], @"Observed path is removed after end of observation");
}
@end