From a51ddbbe1b9710bd75dc96d89f84aed53cedb0a4 Mon Sep 17 00:00:00 2001 From: michael starke Date: Tue, 5 Jan 2016 10:42:20 +0100 Subject: [PATCH] Added KeePassKit dependency to MacPassTest --- MacPass.xcodeproj/project.pbxproj | 4 +++ MacPass/MPAutotypeDelay.h | 2 ++ MacPass/MPAutotypeDelay.m | 10 +++--- MacPass/MPDocument.h | 2 +- MacPassTests/MPDatabaseLoading.m | 2 +- MacPassTests/MPDatabaseSearch.m | 3 +- MacPassTests/MPTestAutotype.m | 2 +- MacPassTests/MPTestAutotypeDelay.m | 57 +++++++++++++++++++++++------- MacPassTests/MPTestDocument.m | 3 +- 9 files changed, 60 insertions(+), 25 deletions(-) diff --git a/MacPass.xcodeproj/project.pbxproj b/MacPass.xcodeproj/project.pbxproj index 56bd25f5..f1af112c 100644 --- a/MacPass.xcodeproj/project.pbxproj +++ b/MacPass.xcodeproj/project.pbxproj @@ -108,6 +108,7 @@ 4C4B7EEE17A467E1000234C7 /* MPGroupInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4B7EEC17A467E1000234C7 /* MPGroupInspectorViewController.m */; }; 4C4B7EF317A467FC000234C7 /* MPEntryInspectorViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4B7EF117A467FC000234C7 /* MPEntryInspectorViewController.m */; }; 4C4B7EF817A4B335000234C7 /* MPUniqueCharactersFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4B7EF717A4B335000234C7 /* MPUniqueCharactersFormatter.m */; }; + 4C4DC0A61C3AD17500DE9DCF /* KeePassKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4C7B63791C0CB55600D7038C /* KeePassKit.framework */; }; 4C4F72D118DF704400E8D378 /* DDHotKeyTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4F72CF18DF704400E8D378 /* DDHotKeyTextField.m */; }; 4C4FCE15177CFE6B00BBF7AE /* MPCustomFieldTableCellView.m in Sources */ = {isa = PBXBuildFile; fileRef = 4C4FCE14177CFE6B00BBF7AE /* MPCustomFieldTableCellView.m */; }; 4C52A88E1788628B00868229 /* 06_BlockDeviceTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 4C52A88B1788628B00868229 /* 06_BlockDeviceTemplate.pdf */; }; @@ -721,6 +722,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 4C4DC0A61C3AD17500DE9DCF /* KeePassKit.framework in Frameworks */, 4C473A8718AFD85B0073FD2E /* XCTest.framework in Frameworks */, 4C45FB1D178E09ED0010007D /* Cocoa.framework in Frameworks */, ); @@ -2010,6 +2012,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MacPassTests/MacPassTests-Prefix.pch"; @@ -2034,6 +2037,7 @@ FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(DEVELOPER_FRAMEWORKS_DIR)", + "$(PROJECT_DIR)/Carthage/Build/Mac", ); GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "MacPassTests/MacPassTests-Prefix.pch"; diff --git a/MacPass/MPAutotypeDelay.h b/MacPass/MPAutotypeDelay.h index 3ebc749e..c086b456 100644 --- a/MacPass/MPAutotypeDelay.h +++ b/MacPass/MPAutotypeDelay.h @@ -9,6 +9,8 @@ #import "MPAutotypeCommand.h" @interface MPAutotypeDelay : MPAutotypeCommand + +@property (readonly) NSUInteger delay; /** * Creates an DelayCommand that delays the execution for n milliseconds * diff --git a/MacPass/MPAutotypeDelay.m b/MacPass/MPAutotypeDelay.m index f25575f3..a267a64b 100644 --- a/MacPass/MPAutotypeDelay.m +++ b/MacPass/MPAutotypeDelay.m @@ -8,10 +8,8 @@ #import "MPAutotypeDelay.h" -@interface MPAutotypeDelay () { -@private - NSUInteger _delay; -} +@interface MPAutotypeDelay () +@property (readwrite) NSUInteger delay; @end @implementation MPAutotypeDelay @@ -22,7 +20,7 @@ } - (NSString *)description { - return [[NSString alloc] initWithFormat:@"%@ delay: %ld ms", self.class, _delay]; + return [[NSString alloc] initWithFormat:@"%@ delay: %ld ms", self.class, self.delay]; } - (instancetype)initWithDelay:(NSUInteger)delay { @@ -36,7 +34,7 @@ - (void)execute { /* milliseconds * 10000 = microseconds */ - usleep((useconds_t)(_delay*1000)); + usleep((useconds_t)(self.delay*1000)); } @end diff --git a/MacPass/MPDocument.h b/MacPass/MPDocument.h index 2a73ffe3..2a0b4b28 100644 --- a/MacPass/MPDocument.h +++ b/MacPass/MPDocument.h @@ -21,7 +21,7 @@ // #import -#import "KeePassKit/KeePassKit.h" +#import #import "MPEntrySearchContext.h" #import "MPTargetNodeResolving.h" diff --git a/MacPassTests/MPDatabaseLoading.m b/MacPassTests/MPDatabaseLoading.m index 0e060040..3eba9cf1 100644 --- a/MacPassTests/MPDatabaseLoading.m +++ b/MacPassTests/MPDatabaseLoading.m @@ -7,9 +7,9 @@ // #import +#import #import "MPDocument.h" -#import "KeePassKit/KeePassKit.h" @interface MPDatabaseLoading : XCTestCase diff --git a/MacPassTests/MPDatabaseSearch.m b/MacPassTests/MPDatabaseSearch.m index d61f50ed..10089123 100644 --- a/MacPassTests/MPDatabaseSearch.m +++ b/MacPassTests/MPDatabaseSearch.m @@ -8,8 +8,7 @@ #import #import - -#import "KeePassKit/KeePassKit.h" +#import @interface MPDatabaseSearch : XCTestCase diff --git a/MacPassTests/MPTestAutotype.m b/MacPassTests/MPTestAutotype.m index e1e621aa..39b680c4 100644 --- a/MacPassTests/MPTestAutotype.m +++ b/MacPassTests/MPTestAutotype.m @@ -9,6 +9,7 @@ #import #import #import +#import #import "MPAutotypeCommand.h" #import "MPAutotypeContext.h" @@ -17,7 +18,6 @@ #import "MPKeyMapper.h" -#import "KeePassKit/KeePassKit.h" @interface MPTestAutotype : XCTestCase @property (strong) KPKEntry *entry; diff --git a/MacPassTests/MPTestAutotypeDelay.m b/MacPassTests/MPTestAutotypeDelay.m index c1afbc85..c02c077f 100644 --- a/MacPassTests/MPTestAutotypeDelay.m +++ b/MacPassTests/MPTestAutotypeDelay.m @@ -7,33 +7,64 @@ // #import +#import + +#import "MPAutotypeContext.h" +#import "MPAutotypeDelay.h" @interface MPTestAutotypeDelay : XCTestCase - +@property (strong) KPKEntry *entry; @end @implementation MPTestAutotypeDelay - (void)setUp { - [super setUp]; - // Put setup code here. This method is called before the invocation of each test method in the class. + [super setUp]; + self.entry = [[KPKEntry alloc] init]; + self.entry.title = @"Title"; + self.entry.url = @"www.myurl.com"; + self.entry.username = @"Username"; + self.entry.password = @"Password"; } - (void)tearDown { - // Put teardown code here. This method is called after the invocation of each test method in the class. - [super tearDown]; + [super tearDown]; } -- (void)testExample { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. +- (void)testValidDelayCommands { + /* Command 1 */ + MPAutotypeContext *context = [[MPAutotypeContext alloc] initWithEntry:self.entry andSequence:@"{DELAY 200}"]; + NSArray *commands = [MPAutotypeCommand commandsForContext:context]; + + XCTAssertTrue(commands.count == 1); + /* {DELAY 200} */ + XCTAssertTrue([commands.firstObject isKindOfClass:[MPAutotypeDelay class]], @"Command is Delay command"); + MPAutotypeDelay *delay = commands.firstObject; + XCTAssertEqual(delay.delay, 200, @"Delay is 200 ms"); } -- (void)testPerformanceExample { - // This is an example of a performance test case. - [self measureBlock:^{ - // Put the code you want to measure the time of here. - }]; +- (void)testDelayExecution { + MPAutotypeDelay *delay = [[MPAutotypeDelay alloc] initWithDelay:200]; + XCTestExpectation *expectation = [self expectationWithDescription:delay.description]; + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [delay execute]; + [expectation fulfill]; + }); + + [self waitForExpectationsWithTimeout:(delay.delay/1000.0) handler:^(NSError *error) { + if (error != nil) { + NSLog(@"Error: %@", error.localizedDescription); + } + }]; +} + + +- (void)testDelayLimit { + XCTFail(@"Missing Test"); +} + +- (void)testMalformedDelay { + XCTFail(@"Missing Test"); } @end diff --git a/MacPassTests/MPTestDocument.m b/MacPassTests/MPTestDocument.m index 3dbaee39..eaf9378b 100644 --- a/MacPassTests/MPTestDocument.m +++ b/MacPassTests/MPTestDocument.m @@ -7,9 +7,10 @@ // #import +#import #import "MPDocument.h" -#import "KeePassKit/KeePassKit.h" + @interface MPTestDocument : XCTestCase @end