Browse Source

IOSAD-191 Add isEqual to PEPAttachmentTest. Add PEPMessage tests.

IOSAD-191
David Alarcon 1 year ago
parent
commit
d9530b57b5
3 changed files with 163 additions and 0 deletions
  1. +32
    -0
      PEPObjCAdapterTypesTests_macOS/Mocks/PEPAttachmentTest.m
  2. +127
    -0
      PEPObjCAdapterTypesTests_macOS/PEPMessageTests.m
  3. +4
    -0
      pEpObjCAdapter.xcodeproj/project.pbxproj

+ 32
- 0
PEPObjCAdapterTypesTests_macOS/Mocks/PEPAttachmentTest.m View File

@ -8,6 +8,8 @@
#import "PEPAttachmentTest.h"
#import "NSObject+Extension.h"
@implementation PEPAttachmentTest
- (instancetype)init {
@ -17,9 +19,39 @@
self.mimeType = @"text/plain";
self.filename = @"attachment.txt";
self.contentDisposition = PEPContentDispositionAttachment;
s_keys = @[@"data", @"size", @"mimeType", @"filename", @"contentDisposition"];
}
return self;
}
// MARK: - Equality
/**
The keys that should be used to decide `isEqual` and compute the `hash`.
*/
static NSArray *s_keys;
- (BOOL)isEqualToPEPAttachment:(PEPAttachment * _Nonnull)attachment
{
return [self isEqualToObject:attachment basedOnKeys:s_keys];
}
- (NSUInteger)hash
{
return [self hashBasedOnKeys:s_keys];
}
- (BOOL)isEqual:(id)object
{
if (object == self) {
return YES;
}
if (!object || ![object isKindOfClass:[self class]]) {
return NO;
}
return [self isEqualToPEPAttachment:object];
}
@end

+ 127
- 0
PEPObjCAdapterTypesTests_macOS/PEPMessageTests.m View File

@ -0,0 +1,127 @@
//
// PEPMessageTests.m
// PEPObjCAdapterTypesTests_macOS
//
// Created by David Alarcon on 27/1/21.
// Copyright © 2021 pp. All rights reserved.
//
#import <XCTest/XCTest.h>
#import "PEPMessageTest.h"
#import "PEPAttachmentTest.h"
@interface PEPMessageTests : XCTestCase
@property (nonatomic, strong) PEPMessageTest *message;
@property (nonatomic, strong) PEPMessageTest *unarchivedMessage;
@end
@implementation PEPMessageTests
- (void)setUp {
[super setUp];
self.message = [PEPMessageTest new];
NSError *error;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:self.message
requiringSecureCoding:YES
error:&error];
XCTAssertNil(error, "Error archiving pEp message.");
self.unarchivedMessage = [NSKeyedUnarchiver unarchivedObjectOfClass:[PEPMessageTest class]
fromData:data
error:&error];
XCTAssertNil(error, "Error unarchiving pEp message.");
}
- (void)tearDown {
[super tearDown];
}
- (void)testConformsSecureCodingProtocol {
XCTAssertTrue([self.message conformsToProtocol:@protocol(NSSecureCoding)]);
}
- (void)testSupportsSecureCodingProtocol {
XCTAssertTrue([PEPMessageTest supportsSecureCoding]);
}
- (void)testMessageMessageID {
XCTAssertEqualObjects(self.message.messageID, self.unarchivedMessage.messageID);
}
- (void)testMessageFrom {
XCTAssertEqualObjects(self.message.from, self.unarchivedMessage.from);
}
- (void)testMessageTo {
XCTAssertEqualObjects(self.message.to, self.unarchivedMessage.to);
}
- (void)testMessageCC {
XCTAssertEqualObjects(self.message.cc, self.unarchivedMessage.cc);
}
- (void)testMessageBCC {
XCTAssertEqualObjects(self.message.bcc, self.unarchivedMessage.bcc);
}
- (void)testMessageShortMessage {
XCTAssertEqualObjects(self.message.shortMessage, self.unarchivedMessage.shortMessage);
}
- (void)testMessageLongMessage {
XCTAssertEqualObjects(self.message.longMessage, self.unarchivedMessage.longMessage);
}
- (void)testMessageLongMessageFormatted {
XCTAssertEqualObjects(self.message.longMessageFormatted,
self.unarchivedMessage.longMessageFormatted);
}
- (void)testMessageReplyTo {
XCTAssertEqualObjects(self.message.replyTo, self.unarchivedMessage.replyTo);
}
- (void)testMessageInReplyTo {
XCTAssertEqualObjects(self.message.inReplyTo, self.unarchivedMessage.inReplyTo);
}
- (void)testMessageReferences {
XCTAssertEqualObjects(self.message.references, self.unarchivedMessage.references);
}
- (void)testMessageSentDate {
XCTAssertEqualObjects(self.message.sentDate, self.unarchivedMessage.sentDate);
}
- (void)testMessageReceivedDate {
XCTAssertEqualObjects(self.message.receivedDate, self.unarchivedMessage.receivedDate);
}
- (void)testMessageAttachments {
XCTAssertEqualObjects(self.message.attachments, self.unarchivedMessage.attachments);
}
- (void)testMessageOptionalFields {
XCTAssertEqualObjects(self.message.optionalFields, self.unarchivedMessage.optionalFields);
}
- (void)testMessageKeywords {
XCTAssertEqualObjects(self.message.keywords, self.unarchivedMessage.keywords);
}
- (void)testMessageReceivedBy {
XCTAssertEqualObjects(self.message.receivedBy, self.unarchivedMessage.receivedBy);
}
- (void)testMessageDirection {
XCTAssertEqual(self.message.direction, self.unarchivedMessage.direction);
}
@end

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

@ -185,6 +185,7 @@
4E81CD2525C168DC009F140D /* PEPAttachmentTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD2425C168DC009F140D /* PEPAttachmentTest.m */; };
4E81CD2D25C16AEE009F140D /* PEPAttachmentTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD2C25C16AEE009F140D /* PEPAttachmentTests.m */; };
4E81CD3625C16F6B009F140D /* PEPMessageTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD3525C16F6B009F140D /* PEPMessageTest.m */; };
4E81CD3E25C17CBD009F140D /* PEPMessageTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4E81CD3D25C17CBD009F140D /* PEPMessageTests.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, ); }; };
@ -418,6 +419,7 @@
4E81CD2C25C16AEE009F140D /* PEPAttachmentTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPAttachmentTests.m; sourceTree = "<group>"; };
4E81CD3425C16F6B009F140D /* PEPMessageTest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PEPMessageTest.h; sourceTree = "<group>"; };
4E81CD3525C16F6B009F140D /* PEPMessageTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPMessageTest.m; sourceTree = "<group>"; };
4E81CD3D25C17CBD009F140D /* PEPMessageTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PEPMessageTests.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>"; };
@ -767,6 +769,7 @@
4EDB86FD25C067DC00FA045D /* PEPIdentityTests.m */,
4E81CD1B25C160CE009F140D /* PEPLanguageTests.m */,
4E81CD2C25C16AEE009F140D /* PEPAttachmentTests.m */,
4E81CD3D25C17CBD009F140D /* PEPMessageTests.m */,
);
path = PEPObjCAdapterTypesTests_macOS;
sourceTree = "<group>";
@ -1300,6 +1303,7 @@
buildActionMask = 2147483647;
files = (
4E81CD2525C168DC009F140D /* PEPAttachmentTest.m in Sources */,
4E81CD3E25C17CBD009F140D /* PEPMessageTests.m in Sources */,
4EDB86FE25C067DC00FA045D /* PEPIdentityTests.m in Sources */,
4E81CD1C25C160CE009F140D /* PEPLanguageTests.m in Sources */,
4E81CD3625C16F6B009F140D /* PEPMessageTest.m in Sources */,


Loading…
Cancel
Save