|
|
@ -8,36 +8,17 @@ |
|
|
|
|
|
|
|
#import <XCTest/XCTest.h> |
|
|
|
|
|
|
|
#import "PEPIdentityTest.h" |
|
|
|
#import "PEPIdentity+SecureCoding.h" |
|
|
|
|
|
|
|
@interface PEPIdentityTests : XCTestCase |
|
|
|
@property (nonatomic, strong) PEPIdentityTest *identity; |
|
|
|
@property (nonatomic, strong) PEPIdentityTest *unarchivedIdentity; |
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
@implementation PEPIdentityTests |
|
|
|
|
|
|
|
- (void)setUp { |
|
|
|
[super setUp]; |
|
|
|
|
|
|
|
self.identity = [PEPIdentityTest new]; |
|
|
|
|
|
|
|
NSError *error; |
|
|
|
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.identity |
|
|
|
requiringSecureCoding:YES |
|
|
|
error:&error]; |
|
|
|
|
|
|
|
XCTAssertNil(error, "Error archiving pEp identity."); |
|
|
|
|
|
|
|
self.unarchivedIdentity = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPIdentity class] |
|
|
|
fromData:data |
|
|
|
error:&error]; |
|
|
|
|
|
|
|
XCTAssertNil(error, "Error unarchiving pEp identity."); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testConformsSecureCodingProtocol { |
|
|
|
XCTAssertTrue([self.identity conformsToProtocol:@protocol(NSSecureCoding)]); |
|
|
|
PEPIdentity *testee = [PEPIdentity new]; |
|
|
|
XCTAssertTrue([testee conformsToProtocol:@protocol(NSSecureCoding)]); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testSupportsSecureCodingProtocol { |
|
|
@ -45,31 +26,83 @@ |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityAddress { |
|
|
|
XCTAssertEqualObjects(self.identity.address, self.unarchivedIdentity.address); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqualObjects(testee.address, unarchivedTestee.address); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityUserID { |
|
|
|
XCTAssertEqualObjects(self.identity.userID, self.unarchivedIdentity.userID); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqualObjects(testee.userID, unarchivedTestee.userID); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityFingerprint { |
|
|
|
XCTAssertEqualObjects(self.identity.fingerPrint, self.unarchivedIdentity.fingerPrint); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqualObjects(testee.fingerPrint, unarchivedTestee.fingerPrint); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityLanguage { |
|
|
|
XCTAssertEqualObjects(self.identity.language, self.unarchivedIdentity.language); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqualObjects(testee.language, unarchivedTestee.language); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityCommType { |
|
|
|
XCTAssertEqual(self.identity.commType, self.unarchivedIdentity.commType); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqual(testee.commType, unarchivedTestee.commType); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityIsOwn { |
|
|
|
XCTAssertEqual(self.identity.isOwn, self.unarchivedIdentity.isOwn); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqual(testee.isOwn, unarchivedTestee.isOwn); |
|
|
|
} |
|
|
|
|
|
|
|
- (void)testIdentityFlags { |
|
|
|
XCTAssertEqual(self.identity.flags, self.unarchivedIdentity.flags); |
|
|
|
PEPIdentity *testee = [self identityWithAllFieldsFilled]; |
|
|
|
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee]; |
|
|
|
|
|
|
|
XCTAssertEqual(testee.flags, unarchivedTestee.flags); |
|
|
|
} |
|
|
|
|
|
|
|
// MARK: - Helper |
|
|
|
|
|
|
|
- (PEPIdentity *)archiveAndUnarchiveIdentity:(PEPIdentity *)identity { |
|
|
|
NSError *error; |
|
|
|
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:identity |
|
|
|
requiringSecureCoding:YES |
|
|
|
error:&error]; |
|
|
|
XCTAssertNotNil(data, "Error archiving pEp identity."); |
|
|
|
|
|
|
|
PEPIdentity *unarchivedIdentity = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPIdentity class] |
|
|
|
fromData:data |
|
|
|
error:&error]; |
|
|
|
XCTAssertNotNil(unarchivedIdentity, "Error unarchiving pEp identity."); |
|
|
|
|
|
|
|
return unarchivedIdentity; |
|
|
|
} |
|
|
|
|
|
|
|
- (PEPIdentity *)identityWithAllFieldsFilled { |
|
|
|
PEPIdentity *identity = [PEPIdentity new]; |
|
|
|
|
|
|
|
identity.address = @"test@host.com"; |
|
|
|
identity.userID = @"pEp_own_userId"; |
|
|
|
identity.fingerPrint = @"184C1DE2D4AB98A2A8BB7F23B0EC5F483B62E19D"; |
|
|
|
identity.language = @"cat"; |
|
|
|
identity.commType = PEPCommTypePEP; |
|
|
|
identity.isOwn = YES; |
|
|
|
identity.flags = PEPIdentityFlagsNotForSync; |
|
|
|
|
|
|
|
return identity; |
|
|
|
} |
|
|
|
|
|
|
|
@end |