Browse Source

IOSAD-191 Create PEPTypesTestUtil. Add PEPIdentity+SecureCodingTest tests.

IOSAD-191
David Alarcon 1 year ago
parent
commit
5547809a4d
5 changed files with 224 additions and 30 deletions
  1. +63
    -30
      PEPObjCAdapterTypesTests/PEPIdentityTests.m
  2. +94
    -0
      PEPObjCAdapterTypesTests_iOS/PEPIdentity+SecureCodingTest.m
  3. +20
    -0
      PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.h
  4. +29
    -0
      PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.m
  5. +18
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj

+ 63
- 30
PEPObjCAdapterTypesTests/PEPIdentityTests.m View File

@ -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

+ 94
- 0
PEPObjCAdapterTypesTests_iOS/PEPIdentity+SecureCodingTest.m View File

@ -0,0 +1,94 @@
//
// PEPIdentity+SecureCodingTest.m
// pEpObjCAdapter
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 pp. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PEPTypesTestUtil.h"
#import "PEPIdentity+SecureCoding.h"
@interface PEPIdentity_SecureCodingTest : XCTestCase
@end
@implementation PEPIdentity_SecureCodingTest
- (void)testConformsSecureCodingProtocol {
PEPIdentity *testee = [PEPIdentity new];
XCTAssertTrue([testee conformsToProtocol:@protocol(NSSecureCoding)]);
}
- (void)testSupportsSecureCodingProtocol {
XCTAssertTrue([PEPIdentity supportsSecureCoding]);
}
- (void)testIdentityAddress {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqualObjects(testee.address, unarchivedTestee.address);
}
- (void)testIdentityUserID {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqualObjects(testee.userID, unarchivedTestee.userID);
}
- (void)testIdentityFingerprint {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqualObjects(testee.fingerPrint, unarchivedTestee.fingerPrint);
}
- (void)testIdentityLanguage {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqualObjects(testee.language, unarchivedTestee.language);
}
- (void)testIdentityCommType {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqual(testee.commType, unarchivedTestee.commType);
}
- (void)testIdentityIsOwn {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
PEPIdentity *unarchivedTestee = [self archiveAndUnarchiveIdentity:testee];
XCTAssertEqual(testee.isOwn, unarchivedTestee.isOwn);
}
- (void)testIdentityFlags {
PEPIdentity *testee = [PEPTypesTestUtil pEpIdentityWithAllFieldsFilled];
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;
}
@end

+ 20
- 0
PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.h View File

@ -0,0 +1,20 @@
//
// PEPTypesTestUtil.h
// PEPObjCAdapterTypesTests_iOS
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 pp. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@class PEPIdentity;
@interface PEPTypesTestUtil : NSObject
+ (PEPIdentity *)pEpIdentityWithAllFieldsFilled;
@end
NS_ASSUME_NONNULL_END

+ 29
- 0
PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.m View File

@ -0,0 +1,29 @@
//
// PEPTypesTestUtil.m
// PEPObjCAdapterTypesTests_iOS
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 pp. All rights reserved.
//
#import "PEPTypesTestUtil.h"
#import "PEPIdentity.h"
@implementation PEPTypesTestUtil
+ (PEPIdentity *)pEpIdentityWithAllFieldsFilled {
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

+ 18
- 0
pEpObjCAdapter.xcodeproj/project.pbxproj View File

@ -196,6 +196,8 @@
4E81CE5C25C1B166009F140D /* PEPAttachmentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD2C25C16AEE009F140D /* PEPAttachmentTests.m */; };
4E81CE6B25C1B16B009F140D /* PEPMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD3D25C17CBD009F140D /* PEPMessageTests.m */; };
4E81CE6C25C1B16B009F140D /* PEPMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD3D25C17CBD009F140D /* PEPMessageTests.m */; };
4E81CE8825C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CE8625C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m */; };
4E81CE9625C1CE21009F140D /* PEPTypesTestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CE9525C1CE21009F140D /* PEPTypesTestUtil.m */; };
4EA9B51F25BF20EA0048427E /* PEPIdentity+SecureCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EA9B43D25BEE0990048427E /* PEPIdentity+SecureCoding.h */; settings = {ATTRIBUTES = (Public, ); }; };
4EA9B54D25BF20FD0048427E /* PEPIdentity+SecureCoding.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EA9B43E25BEE0990048427E /* PEPIdentity+SecureCoding.m */; };
4EA9B58425BF278B0048427E /* PEPLanguage+SecureCoding.h in Headers */ = {isa = PBXBuildFile; fileRef = 4EA9B56425BF277F0048427E /* PEPLanguage+SecureCoding.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -438,6 +440,9 @@
4E81CD3D25C17CBD009F140D /* PEPMessageTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPMessageTests.m; sourceTree = "<group>"; };
4E81CD4925C19DD4009F140D /* PEPObjCAdapterTypesTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PEPObjCAdapterTypesTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4E81CD4D25C19DD4009F140D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4E81CE8625C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPIdentity+SecureCodingTest.m"; sourceTree = "<group>"; };
4E81CE9425C1CE21009F140D /* PEPTypesTestUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPTypesTestUtil.h; sourceTree = "<group>"; };
4E81CE9525C1CE21009F140D /* PEPTypesTestUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPTypesTestUtil.m; sourceTree = "<group>"; };
4EA9B43D25BEE0990048427E /* PEPIdentity+SecureCoding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPIdentity+SecureCoding.h"; sourceTree = "<group>"; };
4EA9B43E25BEE0990048427E /* PEPIdentity+SecureCoding.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPIdentity+SecureCoding.m"; sourceTree = "<group>"; };
4EA9B56425BF277F0048427E /* PEPLanguage+SecureCoding.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPLanguage+SecureCoding.h"; sourceTree = "<group>"; };
@ -793,6 +798,8 @@
4E81CD4A25C19DD4009F140D /* PEPObjCAdapterTypesTests_iOS */ = {
isa = PBXGroup;
children = (
4E81CE9325C1CDF9009F140D /* TestUtils */,
4E81CE8625C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m */,
4E81CD4D25C19DD4009F140D /* Info.plist */,
);
path = PEPObjCAdapterTypesTests_iOS;
@ -810,6 +817,15 @@
path = PEPObjCAdapterTypesTests;
sourceTree = "<group>";
};
4E81CE9325C1CDF9009F140D /* TestUtils */ = {
isa = PBXGroup;
children = (
4E81CE9425C1CE21009F140D /* PEPTypesTestUtil.h */,
4E81CE9525C1CE21009F140D /* PEPTypesTestUtil.m */,
);
path = TestUtils;
sourceTree = "<group>";
};
4EDB86EB25C0674900FA045D /* PEPObjCAdapterTypesTests_macOS */ = {
isa = PBXGroup;
children = (
@ -1376,6 +1392,7 @@
buildActionMask = 2147483647;
files = (
4E81CE5C25C1B166009F140D /* PEPAttachmentTests.m in Sources */,
4E81CE9625C1CE21009F140D /* PEPTypesTestUtil.m in Sources */,
4E81CE6C25C1B16B009F140D /* PEPMessageTests.m in Sources */,
4E81CDEC25C1AAAE009F140D /* PEPAttachmentTest.m in Sources */,
4E81CE4C25C1B163009F140D /* PEPLanguageTests.m in Sources */,
@ -1383,6 +1400,7 @@
4E81CE0325C1ABA7009F140D /* PEPMessageTest.m in Sources */,
4E81CDB725C1A6A9009F140D /* PEPIdentityTest.m in Sources */,
4E81CE3C25C1B15E009F140D /* PEPIdentityTests.m in Sources */,
4E81CE8825C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};


Loading…
Cancel
Save