Copy on disabled TextFields now possible. This behavior will be used when edit mode is added.

Fixed include issue
Added Tests for NSCoding compliance of KPKAttribute, KPKEntry and KPKBinary
This commit is contained in:
michael starke
2013-08-01 01:33:27 +02:00
parent 83eb0edad2
commit 115537c95b
14 changed files with 284 additions and 48 deletions

View File

@@ -0,0 +1,13 @@
//
// KPKTestNSCopying.h
// MacPass
//
// Created by Michael Starke on 31.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
@interface KPKTestNSCoding : SenTestCase
@end

View File

@@ -0,0 +1,86 @@
//
// KPKTestNSCopying.m
// MacPass
//
// Created by Michael Starke on 31.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKTestNSCoding.h"
#import "KPKEntry.h"
#import "KPKBinary.h"
#import "KPKAttribute.h"
@implementation KPKTestNSCoding
- (void)testAttributeCoding {
KPKAttribute *attribute = [[KPKAttribute alloc] initWithKey:@"Key" value:@"Value" isProtected:YES];
NSData *data = [self encode:attribute];
KPKAttribute *copy = [self decode:data ofClass:[KPKAttribute class]];
STAssertTrue([copy.value isEqualToString:attribute.value], @"Values should be preseved");
STAssertTrue([copy.key isEqualToString:attribute.key], @"Keys should be preserved");
STAssertTrue(copy.isProtected == attribute.isProtected, @"Protected status should be the same");
}
- (void)testBinaryCoding {
}
- (void)testEntryCoding {
/*
1. Deep Copy
2. Copy without History
*/
KPKEntry *entry = [[KPKEntry alloc] init];
entry.title = @"Title";
entry.url = @"URL";
entry.username = @"Username";
entry.password = @"Password";
uint8 bytes[] = { 0xFF, 0x00, 0xFF, 0x00, 0xFF };
NSData *data = [[NSData alloc] initWithBytes:bytes length:5];
KPKBinary *binary = [[KPKBinary alloc] init];
binary.data = data;
binary.name = @"Binary";
[entry addBinary:binary];
[entry addCustomAttribute:[[KPKAttribute alloc] initWithKey:@"Custom" value:@"Value" isProtected:NO]];
NSData *encodedData = [self encode:entry];
KPKEntry *copyEntry = [self decode:encodedData ofClass:[KPKEntry class]];
STAssertNotNil(copyEntry, @"Copied Entry cannot be nil");
STAssertTrue([copyEntry.title isEqualToString:entry.title], @"Titles should match");
STAssertTrue([copyEntry.url isEqualToString:entry.url], @"URLS should match");
STAssertTrue([copyEntry.binaries count] == 1, @"Binareis should be copied");
KPKBinary *copiedBinary = [copyEntry.binaries lastObject];
STAssertTrue([copiedBinary.data isEqualToData:binary.data], @"Binary data should match");
STAssertTrue([copiedBinary.name isEqualToString:binary.name], @"Binary names should macht");
}
- (void)testGroupCoding {
}
- (NSData *)encode:(id)object {
NSMutableData *data = [[NSMutableData alloc] initWithCapacity:500];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[object encodeWithCoder:archiver];
[archiver finishEncoding];
return data;
}
- (id)decode:(NSData *)data ofClass:(Class)class {
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
id object = [[class alloc] initWithCoder:unarchiver];
[unarchiver finishDecoding];
return object;
}
@end

View File

@@ -0,0 +1,13 @@
//
// KPKTestNSCopying.h
// MacPass
//
// Created by Michael Starke on 31.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import <SenTestingKit/SenTestingKit.h>
@interface KPKTestNSCopying : SenTestCase
@end

View File

@@ -0,0 +1,13 @@
//
// KPKTestNSCopying.m
// MacPass
//
// Created by Michael Starke on 31.07.13.
// Copyright (c) 2013 HicknHack Software GmbH. All rights reserved.
//
#import "KPKTestNSCopying.h"
@implementation KPKTestNSCopying
@end