Code cleanup

This commit is contained in:
michael starke
2014-02-23 20:22:59 +01:00
parent 4db333fbc5
commit 1122cfbbde
7 changed files with 140 additions and 69 deletions

View File

@@ -824,6 +824,7 @@
4CEE46DC181C301D006BF1E5 /* MPAutotypeDaemon.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MPAutotypeDaemon.m; sourceTree = "<group>"; };
4CEED1C417D7BD0E007180F1 /* NSError+Messages.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSError+Messages.h"; sourceTree = "<group>"; };
4CEED1C517D7BD0E007180F1 /* NSError+Messages.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSError+Messages.m"; sourceTree = "<group>"; };
4CEFC2F118BA7644007D2565 /* KeePassKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeePassKit.h; sourceTree = "<group>"; };
4CF29BF317879D0000851B60 /* 26_FileSaveTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = 26_FileSaveTemplate.pdf; sourceTree = "<group>"; };
4CF5CF7218B7C81600B0C026 /* NSWindow+Shake.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "NSWindow+Shake.h"; path = "Categories/NSWindow+Shake.h"; sourceTree = "<group>"; };
4CF5CF7318B7C81600B0C026 /* NSWindow+Shake.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "NSWindow+Shake.m"; path = "Categories/NSWindow+Shake.m"; sourceTree = "<group>"; };
@@ -1600,6 +1601,7 @@
4CD3ABAD178F71B50073F5C5 /* KeePassKit */ = {
isa = PBXGroup;
children = (
4CEFC2F118BA7644007D2565 /* KeePassKit.h */,
4C0104B817C37BFC00173EF3 /* Utilites */,
4C1842D6179C716100E2F5BC /* Format */,
4CD3ABAF178F71B50073F5C5 /* Categories */,

View File

@@ -9,10 +9,7 @@
<connections>
<outlet property="emptyTrashButton" destination="szx-Hx-OrV" id="i1Y-qB-TW3"/>
<outlet property="exitHistoryButton" destination="pqx-su-vAh" id="JmV-vC-F48"/>
<outlet property="filterDoneButton" destination="61" id="o8k-20-QUA"/>
<outlet property="filterLabelTextField" destination="6" id="60"/>
<outlet property="filterSearchField" destination="80" id="95"/>
<outlet property="filterTypePopupButton" destination="9ZN-yB-Aiq" id="7Af-Dn-e05"/>
<outlet property="historyBar" destination="S8L-rB-h0h" id="6yZ-El-fVs"/>
<outlet property="historyLabel" destination="gGR-f0-dcr" id="slx-9D-8k8"/>
<outlet property="trashBar" destination="DXf-SC-gVG" id="3aZ-Xc-VDk"/>
@@ -24,6 +21,10 @@
<tabView type="noTabsNoBorder" translatesAutoresizingMaskIntoConstraints="NO" id="8MB-fC-M2Q">
<rect key="frame" x="0.0" y="0.0" width="576" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="trailing" secondItem="Bn2-iY-mQ3" secondAttribute="leading" constant="302" id="CN2-8I-gC2"/>
<constraint firstAttribute="trailing" secondItem="0R1-PX-dgn" secondAttribute="leading" constant="469" id="Fzh-fb-BD7"/>
</constraints>
<font key="font" metaFont="system"/>
<tabViewItems>
<tabViewItem label="Filter" identifier="1" id="Ud6-Nz-6PS">
@@ -35,7 +36,7 @@
<rect key="frame" x="0.0" y="0.0" width="576" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<textField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<textField verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6">
<rect key="frame" x="6" y="8" width="45" height="14"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Search:" id="7">
@@ -44,65 +45,71 @@
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="61">
<rect key="frame" x="526" y="6" width="42" height="17"/>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="O7W-cn-eUP">
<rect key="frame" x="57" y="6" width="42" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="roundRect" title="Done" bezelStyle="roundedRect" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="62">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<buttonCell key="cell" type="recessed" title="Title" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="53D-ne-nv6">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
<connections>
<action selector="exitFilter:" target="-2" id="cip-Yr-YZx"/>
</connections>
</button>
<searchField verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="80">
<rect key="frame" x="418" y="5" width="100" height="19"/>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="0R1-PX-dgn">
<rect key="frame" x="107" y="6" width="77" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<constraints>
<constraint firstAttribute="width" constant="100" id="93"/>
</constraints>
<searchFieldCell key="cell" controlSize="small" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" borderStyle="bezel" usesSingleLineMode="YES" bezelStyle="round" id="81">
<font key="font" metaFont="smallSystem"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</searchFieldCell>
<connections>
<outlet property="delegate" destination="-2" id="Y78-7K-e9c"/>
</connections>
</searchField>
<popUpButton verticalHuggingPriority="750" horizontalCompressionResistancePriority="751" translatesAutoresizingMaskIntoConstraints="NO" id="9ZN-yB-Aiq">
<rect key="frame" x="57" y="6" width="24" height="17"/>
<buttonCell key="cell" type="recessed" title="Username" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="jfQ-Jh-2gl">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Uhl-ck-vVQ">
<rect key="frame" x="192" y="6" width="74" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<popUpButtonCell key="cell" type="roundRect" bezelStyle="roundedRect" alignment="center" controlSize="small" lineBreakMode="truncatingTail" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="oir-UN-bNS">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
<menu key="menu" title="OtherViews" id="el3-on-vmi"/>
</popUpButtonCell>
</popUpButton>
<buttonCell key="cell" type="recessed" title="Password" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="rvQ-4V-SsS">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Bn2-iY-mQ3">
<rect key="frame" x="274" y="6" width="38" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="recessed" title="URL" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="92o-gN-Psj">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="SaV-5p-jIX">
<rect key="frame" x="320" y="6" width="50" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="recessed" title="Notes" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="iDN-2E-hwt">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
</button>
<button verticalHuggingPriority="750" ambiguous="YES" misplaced="YES" translatesAutoresizingMaskIntoConstraints="NO" id="hMB-2T-pBD">
<rect key="frame" x="378" y="6" width="87" height="17"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<buttonCell key="cell" type="recessed" title="Everywhere" bezelStyle="recessed" alignment="center" controlSize="small" state="on" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="G1B-En-dc2">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES" changeBackground="YES" changeGray="YES"/>
<font key="font" metaFont="systemBold" size="12"/>
</buttonCell>
</button>
</subviews>
<constraints>
<constraint firstItem="6" firstAttribute="leading" secondItem="1" secondAttribute="leading" constant="8" id="30"/>
<constraint firstAttribute="trailing" secondItem="61" secondAttribute="trailing" constant="8" id="63"/>
<constraint firstAttribute="centerY" secondItem="61" secondAttribute="centerY" id="69"/>
<constraint firstItem="61" firstAttribute="leading" secondItem="80" secondAttribute="trailing" constant="8" symbolic="YES" id="83"/>
<constraint firstAttribute="centerY" secondItem="80" secondAttribute="centerY" id="86"/>
<constraint firstAttribute="centerY" secondItem="9ZN-yB-Aiq" secondAttribute="centerY" id="4wF-MI-Az7"/>
<constraint firstItem="80" firstAttribute="leading" relation="greaterThanOrEqual" secondItem="9ZN-yB-Aiq" secondAttribute="trailing" constant="8" symbolic="YES" id="O7v-9o-6vB"/>
<constraint firstAttribute="centerY" secondItem="6" secondAttribute="centerY" id="OTP-Xc-T5f"/>
<constraint firstItem="9ZN-yB-Aiq" firstAttribute="leading" secondItem="6" secondAttribute="trailing" constant="8" symbolic="YES" id="xah-WD-k5q"/>
<constraint firstItem="O7W-cn-eUP" firstAttribute="leading" secondItem="6" secondAttribute="trailing" constant="8" symbolic="YES" id="5hN-x3-XlX"/>
<constraint firstItem="0R1-PX-dgn" firstAttribute="leading" secondItem="O7W-cn-eUP" secondAttribute="trailing" constant="8" symbolic="YES" id="67f-i6-eOb"/>
<constraint firstItem="Bn2-iY-mQ3" firstAttribute="leading" secondItem="Uhl-ck-vVQ" secondAttribute="trailing" constant="8" id="TCJ-vg-IIt"/>
<constraint firstItem="SaV-5p-jIX" firstAttribute="leading" secondItem="Bn2-iY-mQ3" secondAttribute="trailing" constant="8" symbolic="YES" id="pAA-uU-moF"/>
<constraint firstItem="hMB-2T-pBD" firstAttribute="leading" secondItem="SaV-5p-jIX" secondAttribute="trailing" constant="8" symbolic="YES" id="zRT-y1-oMu"/>
</constraints>
</customView>
</subviews>
<constraints>
<constraint firstItem="1" firstAttribute="leading" secondItem="caQ-XO-RkM" secondAttribute="leading" id="APY-Gx-UHv"/>
<constraint firstAttribute="bottom" secondItem="1" secondAttribute="bottom" id="SAy-YO-CJX"/>
<constraint firstAttribute="trailing" secondItem="1" secondAttribute="trailing" id="l0b-wL-Hgo"/>
<constraint firstItem="1" firstAttribute="top" secondItem="caQ-XO-RkM" secondAttribute="top" id="oAv-6v-o9d"/>
<constraint firstItem="1" firstAttribute="leading" secondItem="caQ-XO-RkM" secondAttribute="leading" id="3yS-J0-xZL"/>
<constraint firstAttribute="bottom" secondItem="1" secondAttribute="bottom" id="Z4A-sK-v8K"/>
<constraint firstItem="1" firstAttribute="top" secondItem="caQ-XO-RkM" secondAttribute="top" id="a5u-p3-ay5"/>
<constraint firstAttribute="trailing" secondItem="1" secondAttribute="trailing" id="hTR-dg-7Ql"/>
</constraints>
</view>
<connections>
<outlet property="initialFirstResponder" destination="80" id="tDw-Su-DU1"/>
</connections>
</tabViewItem>
<tabViewItem label="Trash" identifier="2" id="na6-h9-r9q">
<view key="view" id="F6S-GS-AwI">

View File

@@ -48,11 +48,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="StringCell" id="269">
<rect key="frame" x="1" y="1" width="104.5" height="17"/>
<rect key="frame" x="1" y="1" width="105" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="270">
<rect key="frame" x="1" y="0.0" width="102.5" height="17"/>
<rect key="frame" x="1" y="0.0" width="103" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="271">
<font key="font" metaFont="system"/>
@@ -86,7 +86,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="ImageCell" id="297">
<rect key="frame" x="108.5" y="1" width="144" height="17"/>
<rect key="frame" x="109" y="1" width="144" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<imageView translatesAutoresizingMaskIntoConstraints="NO" id="298">
@@ -136,11 +136,11 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView identifier="PasswordCell" id="428">
<rect key="frame" x="255.5" y="1" width="118.5" height="17"/>
<rect key="frame" x="256" y="1" width="119" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="429" customClass="NSSecureTextField">
<rect key="frame" x="1" y="0.0" width="116.5" height="17"/>
<rect key="frame" x="1" y="0.0" width="117" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="430">
<font key="font" metaFont="system"/>
@@ -174,7 +174,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="421">
<rect key="frame" x="377" y="1" width="113" height="17"/>
<rect key="frame" x="378" y="1" width="113" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="422">
@@ -212,7 +212,7 @@
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
<prototypeCellViews>
<tableCellView id="616">
<rect key="frame" x="493" y="1" width="198" height="17"/>
<rect key="frame" x="494" y="1" width="198" height="17"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="617">

View File

@@ -104,7 +104,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
[[self view] layoutSubtreeIfNeeded];
[self _updateItemBindings:nil];
[self _updateBindings:nil];
}
- (void)setupNotifications:(NSWindowController *)windowController {
@@ -220,7 +220,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
#pragma mark -
#pragma mark Bindings
- (void)_updateItemBindings:(id)item {
- (void)_updateBindings:(id)item {
if(!item) {
[self.itemNameTextField unbind:NSValueBinding];
[self.itemNameTextField setHidden:YES];
@@ -240,6 +240,10 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
}
[self.itemImageView setHidden:NO];
[self.itemNameTextField setHidden:NO];
if([item respondsToSelector:@selector(notes)]) {
}
}
#pragma mark -
@@ -261,7 +265,7 @@ typedef NS_ENUM(NSUInteger, MPContentTab) {
self.activeTab = MPEntryTab;
}
}
[self _updateItemBindings:document.selectedItem];
[self _updateBindings:document.selectedItem];
/* disable the entry text fields whenever the entry selection changes */
//[_entryViewController endEditing];

View File

@@ -44,7 +44,6 @@
NSBitmapImageRep *bitmapRep = (NSBitmapImageRep *)imageRep;
NSData *pngData = [bitmapRep representationUsingType:NSPNGFileType properties:nil];
XCTAssertTrue([pngData isEqualToData:_imageData], @"Image and PNG data shoudl be identical");
}
@end

View File

@@ -9,9 +9,13 @@
#import <XCTest/XCTest.h>
#import "KPKEntry.h"
#import "KPKGroup.h"
#import "KPKBinary.h"
#import "KPKAttribute.h"
#import "KPKXmlElements.h"
#import "KPKIcon.h"
#import "NSData+Random.h"
@interface KPKTestNSCoding : XCTestCase
@@ -30,7 +34,16 @@
}
- (void)testBinaryCoding {
XCTFail(@"Not Tested");
KPKBinary *binary = [[KPKBinary alloc] init];
binary.name = @"Binary";
binary.data = [NSData dataWithRandomBytes:1*1024*1024];
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]);
}
- (void)testEntryCoding {
@@ -50,7 +63,7 @@
[entry addBinary:binary];
[entry addCustomAttribute:[[KPKAttribute alloc] initWithKey:@"Custom" value:kKPKXmlValue isProtected:NO]];
NSData *encodedData = [self encode:entry];
KPKEntry *copyEntry = [self decode:encodedData ofClass:[KPKEntry class]];
@@ -58,17 +71,58 @@
XCTAssertTrue([copyEntry.title isEqualToString:entry.title], @"Titles should match");
XCTAssertTrue([copyEntry.url isEqualToString:entry.url], @"URLS should match");
XCTAssertTrue([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 macht");
}
- (void)testGroupCoding {
XCTFail(@"Not Implemented");
- (void)testIconCoding {
NSBundle *myBundle = [NSBundle bundleForClass:[self class]];
NSURL *imageURL = [myBundle URLForImageResource:@"image.png"];
KPKIcon *icon = [[KPKIcon alloc] initWithImageAtURL:imageURL];
NSData *data = [self encode:icon];
KPKIcon *decodedIcon = [self decode:data ofClass:[KPKIcon class]];
NSBitmapImageRep *originalRep = [[icon.image representations] lastObject];
NSBitmapImageRep *decodedRep = [[decodedIcon.image representations] lastObject];
XCTAssertTrue([originalRep isKindOfClass:[NSBitmapImageRep class]]);
XCTAssertTrue([decodedRep isKindOfClass:[NSBitmapImageRep class]]);
/*
We cannot assert bit depth since TIFF conversion might just strip a full white alpha channel
XCTAssertEqual([originalRep bitsPerPixel], [decodedRep bitsPerPixel]);
*/
XCTAssertEqual([originalRep pixelsHigh], [decodedRep pixelsHigh]);
XCTAssertEqual([originalRep pixelsWide], [decodedRep pixelsWide]);
NSData *originalData = [icon.image TIFFRepresentation];
NSData *decodedData = [decodedIcon.image TIFFRepresentation];
XCTAssertTrue([originalData isEqualToData:decodedData]);
}
- (void)testGroupCoding {
KPKGroup *group = [[KPKGroup alloc] init];
group.name = @"A Group";
group.iconId = 50;
group.notes = @"Some notes";
KPKEntry *entry = [[KPKEntry alloc] init];
entry.title = @"Entry";
entry.url = @"www.url.com";
[group addEntry:entry];
NSData *data = [self encode:group];
KPKGroup *decodedGroup = [self decode:data ofClass:[KPKGroup class]];
XCTAssertTrue([group.uuid isEqual:decodedGroup.uuid]);
XCTAssertTrue([group.name isEqualToString:decodedGroup.name]);
XCTAssertEqual([group.entries count], [decodedGroup.entries count]);
XCTAssertEqual(group.iconId, decodedGroup.iconId);
XCTAssertTrue([group.notes isEqualToString:decodedGroup.notes]);
KPKEntry *decodedEntry = [decodedGroup entryForUUID:entry.uuid];
XCTAssertNotNil(decodedEntry);
XCTAssertEqualObjects(decodedEntry.parent, decodedGroup);
XCTAssertTrue([decodedEntry isEqualToEntry:entry]);
}
- (NSData *)encode:(id)object {
NSMutableData *data = [[NSMutableData alloc] initWithCapacity:500];
@@ -78,11 +132,16 @@
return data;
}
- (id)decode:(NSData *)data ofClass:(Class)class {
- (id)decode:(NSData *)data ofClass:(Class)class usingSecureCoding:(BOOL)secureCoding {
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
id object = [[class alloc] initWithCoder:unarchiver];
[unarchiver finishDecoding];
return object;
}
- (id)decode:(NSData *)data ofClass:(Class)class {
return [self decode:data ofClass:class usingSecureCoding:NO];
}
@end