mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 21:42:32 +00:00
Using current KeePassKit, extended Tests
Signed-off-by: michael starke <michael.starke@hicknhack-software.com>
This commit is contained in:
@@ -42,7 +42,6 @@
|
||||
NSData *data = [self encode:binary];
|
||||
KPKBinary *decodedBinary = [self decode:data ofClass:[KPKBinary class]];
|
||||
|
||||
|
||||
XCTAssertTrue([decodedBinary.data isEqualToData:binary.data]);
|
||||
XCTAssertTrue([decodedBinary.name isEqualToString:binary.name]);
|
||||
}
|
||||
@@ -105,20 +104,36 @@
|
||||
group.title = @"A Group";
|
||||
group.iconId = 50;
|
||||
group.notes = @"Some notes";
|
||||
group.isAutoTypeEnabled = KPKInheritYES;
|
||||
|
||||
KPKEntry *entry = [[KPKEntry alloc] init];
|
||||
entry.title = @"Entry";
|
||||
entry.url = @"www.url.com";
|
||||
[group addEntry:entry];
|
||||
|
||||
KPKGroup *childGroup = [[KPKGroup alloc] init];
|
||||
childGroup.title = @"Subgroup";
|
||||
childGroup.iconId = 1;
|
||||
childGroup.isAutoTypeEnabled = KPKInheritNO;
|
||||
[group addGroup:childGroup];
|
||||
|
||||
KPKEntry *subEntry = [[KPKEntry alloc] init];
|
||||
subEntry.title = @"Subentry";
|
||||
subEntry.url = @"www.url.com";
|
||||
[childGroup addEntry:subEntry];
|
||||
|
||||
NSData *data = [self encode:group];
|
||||
KPKGroup *decodedGroup = [self decode:data ofClass:[KPKGroup class]];
|
||||
|
||||
XCTAssertTrue([group.uuid isEqual:decodedGroup.uuid]);
|
||||
XCTAssertTrue([group.title isEqualToString:decodedGroup.title]);
|
||||
XCTAssertEqual([group.entries count], [decodedGroup.entries count]);
|
||||
XCTAssertEqual(group.entries.count, decodedGroup.entries.count);
|
||||
XCTAssertEqual(group.iconId, decodedGroup.iconId);
|
||||
XCTAssertTrue([group.notes isEqualToString:decodedGroup.notes]);
|
||||
|
||||
|
||||
XCTAssertEqualObjects(childGroup.parent, group);
|
||||
XCTAssertEqualObjects(subEntry.parent, childGroup);
|
||||
|
||||
KPKEntry *decodedEntry = [decodedGroup entryForUUID:entry.uuid];
|
||||
XCTAssertNotNil(decodedEntry);
|
||||
XCTAssertEqualObjects(decodedEntry.parent, decodedGroup);
|
||||
@@ -137,11 +152,9 @@
|
||||
}
|
||||
|
||||
- (id)decode:(NSData *)data ofClass:(Class)class usingSecureCoding:(BOOL)secureCoding {
|
||||
|
||||
if(secureCoding && ![class instancesRespondToSelector:@selector(supportsSecureCoding)]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
if(![class instancesRespondToSelector:@selector(initWithCoder:)]) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
#import "KPKIconTypes.h"
|
||||
#import "KPKGroup.h"
|
||||
#import "KPKEntry.h"
|
||||
#import "KPKAttribute.h"
|
||||
#import "KPKBinary.h"
|
||||
@@ -54,16 +56,64 @@
|
||||
|
||||
entry.title = @"NewTitle";
|
||||
[entry removeBinary:binary];
|
||||
[[entry.customAttributes lastObject] setKey:@"NewCustomKey"];
|
||||
((KPKAttribute *)entry.customAttributes.lastObject).key = @"NewCustomKey";
|
||||
|
||||
XCTAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
|
||||
XCTAssertTrue([copyEntry.title isEqualToString:@"Title"], @"Titles should match");
|
||||
XCTAssertTrue([copyEntry.url isEqualToString:@"URL"], @"URLS should match");
|
||||
XCTAssertTrue([copyEntry.binaries count] == 1, @"Binaries should be copied");
|
||||
XCTAssertEqualObjects(copyEntry.title, @"Title", @"Titles should match");
|
||||
XCTAssertEqualObjects(copyEntry.url, @"URL", @"URLS should match");
|
||||
XCTAssertEqual(copyEntry.binaries.count, 1, @"Binareis should be copied");
|
||||
|
||||
KPKBinary *copiedBinary = [copyEntry.binaries lastObject];
|
||||
XCTAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
|
||||
XCTAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should match");
|
||||
XCTAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
|
||||
}
|
||||
|
||||
- (void)testGroupCopying {
|
||||
|
||||
/*
|
||||
root
|
||||
+ Group A
|
||||
+ Entry A
|
||||
+ Group A1
|
||||
+ Group A2
|
||||
+ Entry B
|
||||
*/
|
||||
|
||||
KPKGroup *root = [[KPKGroup alloc] init];
|
||||
root.title = @"root";
|
||||
|
||||
KPKGroup *groupA = [[KPKGroup alloc] init];
|
||||
groupA.title = @"Group A";
|
||||
groupA.isAutoTypeEnabled = KPKInheritNO;
|
||||
|
||||
KPKGroup *groupA1 = [[KPKGroup alloc] init];
|
||||
groupA1.title = @"Group A1";
|
||||
groupA1.notes = @"Some notes";
|
||||
groupA1.iconId = KPKIconASCII;
|
||||
|
||||
KPKGroup *groupA2 = [[KPKGroup alloc] init];
|
||||
groupA2.title = @"Group A2";
|
||||
groupA2.notes = @"More notes";
|
||||
groupA2.isSearchEnabled = KPKInheritYES;
|
||||
|
||||
KPKEntry *entryA = [[KPKEntry alloc] init];
|
||||
entryA.title = @"Entry A";
|
||||
entryA.url = @"www.url.com";
|
||||
KPKEntry *entryB = [[KPKEntry alloc] init];
|
||||
entryB.title = @"Entry B";
|
||||
entryB.url = @"www.nope.com";
|
||||
|
||||
|
||||
[groupA addEntry:entryA];
|
||||
[groupA addGroup:groupA1];
|
||||
[groupA addGroup:groupA2];
|
||||
[groupA2 addEntry:entryB];
|
||||
|
||||
[root addGroup:groupA];
|
||||
|
||||
KPKGroup *copy = [root copy];
|
||||
|
||||
XCTAssertEqualObjects(root, copy);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -336,8 +336,27 @@
|
||||
XCTFail(@"Missing test");
|
||||
}
|
||||
|
||||
- (void)testUpdateToInvalidNode {
|
||||
XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty");
|
||||
XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty");
|
||||
|
||||
KPKEntry *invalid = [_tree createEntry:_tree.root];
|
||||
KPKEntry *copy = [_entryA copy];
|
||||
XCTAssertThrows([_entryA updateToNode:invalid], @"Updating to a wrong node is not allowed");
|
||||
XCTAssertEqualObjects(_entryA, copy, @"Entry a has no changes after updateToNode was called with wrong node argument");
|
||||
|
||||
XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty after failed update");
|
||||
XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty after failed update");
|
||||
|
||||
}
|
||||
|
||||
- (void)testUndoRedoEditEntry {
|
||||
XCTFail(@"Missing test");
|
||||
XCTAssertFalse(_undoManager.canUndo, @"Undo stack is empty");
|
||||
XCTAssertFalse(_undoManager.canRedo, @"Redo stack is empty");
|
||||
|
||||
KPKEntry *copy = [_entryA copy];
|
||||
copy.title = @"New Title";
|
||||
copy.url = @"New URL";
|
||||
}
|
||||
|
||||
- (void)testUndoRedoEditGroup {
|
||||
|
||||
Reference in New Issue
Block a user