Browse Source

IOSAD-191 Add PEPAttachment_SecureCodingTest tests.

IOSAD-191
David Alarcon 1 year ago
parent
commit
ecb30736de
5 changed files with 101 additions and 4 deletions
  1. +80
    -0
      PEPObjCAdapterTypesTests_iOS/PEPAttachment_SecureCodingTest.m
  2. +2
    -3
      PEPObjCAdapterTypesTests_iOS/PEPLanguage+SecureCodingTest.m
  3. +2
    -1
      PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.h
  4. +13
    -0
      PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.m
  5. +4
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj

+ 80
- 0
PEPObjCAdapterTypesTests_iOS/PEPAttachment_SecureCodingTest.m View File

@ -0,0 +1,80 @@
//
// PEPAttachment_SecureCodingTest.m
// PEPObjCAdapterTypesTests_iOS
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 pp. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PEPTypesTestUtil.h"
#import "PEPAttachment+SecureCoding.h"
@interface PEPAttachment_SecureCodingTest : XCTestCase
@end
@implementation PEPAttachment_SecureCodingTest
- (void)testConformsSecureCodingProtocol {
PEPAttachment *testee = [PEPAttachment new];
XCTAssertTrue([testee conformsToProtocol:@protocol(NSSecureCoding)]);
}
- (void)testSupportsSecureCodingProtocol {
XCTAssertTrue([PEPAttachment supportsSecureCoding]);
}
- (void)testAttachmentData {
PEPAttachment *testee = [PEPTypesTestUtil pEpAttachmentWithAllFieldsFilled];
PEPAttachment *unarchivedTestee = [self archiveAndUnarchiveAttachment:testee];
XCTAssertEqualObjects(testee.data, unarchivedTestee.data);
}
- (void)testAttachmentSize {
PEPAttachment *testee = [PEPTypesTestUtil pEpAttachmentWithAllFieldsFilled];
PEPAttachment *unarchivedTestee = [self archiveAndUnarchiveAttachment:testee];
XCTAssertEqual(testee.size, unarchivedTestee.size);
}
- (void)testAttachmentMimeType {
PEPAttachment *testee = [PEPTypesTestUtil pEpAttachmentWithAllFieldsFilled];
PEPAttachment *unarchivedTestee = [self archiveAndUnarchiveAttachment:testee];
XCTAssertEqualObjects(testee.mimeType, unarchivedTestee.mimeType);
}
- (void)testAttachmentFilename {
PEPAttachment *testee = [PEPTypesTestUtil pEpAttachmentWithAllFieldsFilled];
PEPAttachment *unarchivedTestee = [self archiveAndUnarchiveAttachment:testee];
XCTAssertEqualObjects(testee.filename, unarchivedTestee.filename);
}
- (void)testAttachmentContentDisposition {
PEPAttachment *testee = [PEPTypesTestUtil pEpAttachmentWithAllFieldsFilled];
PEPAttachment *unarchivedTestee = [self archiveAndUnarchiveAttachment:testee];
XCTAssertEqual(testee.contentDisposition, unarchivedTestee.contentDisposition);
}
// MARK: - Helper
- (PEPAttachment *)archiveAndUnarchiveAttachment:(PEPAttachment *)attachment {
NSError *error;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:attachment
requiringSecureCoding:YES
error:&error];
XCTAssertNotNil(data, "Error archiving pEp attachment.");
PEPAttachment *unarchivedAttachment = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPAttachment class]
fromData:data
error:&error];
XCTAssertNotNil(unarchivedAttachment, "Error unarchiving pEp attachment.");
return unarchivedAttachment;
}
@end

+ 2
- 3
PEPObjCAdapterTypesTests_iOS/PEPLanguage+SecureCodingTest.m View File

@ -12,7 +12,6 @@
#import "PEPLanguage+SecureCoding.h"
@interface PEPLanguage_SecureCodingTest : XCTestCase
@end
@implementation PEPLanguage_SecureCodingTest
@ -54,12 +53,12 @@
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:language
requiringSecureCoding:YES
error:&error];
XCTAssertNotNil(data, "Error archiving pEp identity.");
XCTAssertNotNil(data, "Error archiving pEp language.");
PEPLanguage *unarchivedLanguage = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPLanguage class]
fromData:data
error:&error];
XCTAssertNotNil(unarchivedLanguage, "Error unarchiving pEp identity.");
XCTAssertNotNil(unarchivedLanguage, "Error unarchiving pEp language.");
return unarchivedLanguage;
}


+ 2
- 1
PEPObjCAdapterTypesTests_iOS/TestUtils/PEPTypesTestUtil.h View File

@ -10,10 +10,11 @@
NS_ASSUME_NONNULL_BEGIN
@class PEPIdentity;
@class PEPIdentity, PEPAttachment;
@interface PEPTypesTestUtil : NSObject
+ (PEPIdentity *)pEpIdentityWithAllFieldsFilled;
+ (PEPAttachment *)pEpAttachmentWithAllFieldsFilled;
@end


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

@ -9,6 +9,7 @@
#import "PEPTypesTestUtil.h"
#import "PEPIdentity.h"
#import "PEPAttachment.h"
@implementation PEPTypesTestUtil
@ -26,4 +27,16 @@
return identity;
}
+ (PEPAttachment *)pEpAttachmentWithAllFieldsFilled {
PEPAttachment *attachment = [PEPAttachment new];
attachment.data = [@"attachment" dataUsingEncoding:NSUTF8StringEncoding];
attachment.size = attachment.data.length;
attachment.mimeType = @"text/plain";
attachment.filename = @"attachment.txt";
attachment.contentDisposition = PEPContentDispositionAttachment;
return attachment;
}
@end

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

@ -184,6 +184,7 @@
4E81CE8825C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CE8625C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m */; };
4E81CE9625C1CE21009F140D /* PEPTypesTestUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CE9525C1CE21009F140D /* PEPTypesTestUtil.m */; };
4E81CEC225C1D751009F140D /* PEPLanguage+SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CEC125C1D751009F140D /* PEPLanguage+SecureCodingTest.m */; };
4E81CF1825C1E710009F140D /* PEPAttachment_SecureCodingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CF1725C1E710009F140D /* PEPAttachment_SecureCodingTest.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, ); }; };
@ -426,6 +427,7 @@
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>"; };
4E81CEC125C1D751009F140D /* PEPLanguage+SecureCodingTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPLanguage+SecureCodingTest.m"; sourceTree = "<group>"; };
4E81CF1725C1E710009F140D /* PEPAttachment_SecureCodingTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPAttachment_SecureCodingTest.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>"; };
@ -781,6 +783,7 @@
4E81CE9325C1CDF9009F140D /* TestUtils */,
4E81CE8625C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m */,
4E81CEC125C1D751009F140D /* PEPLanguage+SecureCodingTest.m */,
4E81CF1725C1E710009F140D /* PEPAttachment_SecureCodingTest.m */,
4E81CD4D25C19DD4009F140D /* Info.plist */,
);
path = PEPObjCAdapterTypesTests_iOS;
@ -1368,6 +1371,7 @@
files = (
4E81CE9625C1CE21009F140D /* PEPTypesTestUtil.m in Sources */,
4E81CEC225C1D751009F140D /* PEPLanguage+SecureCodingTest.m in Sources */,
4E81CF1825C1E710009F140D /* PEPAttachment_SecureCodingTest.m in Sources */,
4E81CE8825C1CCCB009F140D /* PEPIdentity+SecureCodingTest.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;


Loading…
Cancel
Save