Browse Source

Tests up and running

master
Andreas Buff 5 months ago
parent
commit
54918835ef
6 changed files with 254 additions and 47 deletions
  1. +4
    -0
      Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.mm
  2. +10
    -0
      pEpMimeObjCAdapter.xcodeproj/project.pbxproj
  3. +144
    -45
      pEpMimeObjCAdapterTests_macOS/Interface/PEPMessage+PEPMessage_MIMETest.m
  4. +16
    -0
      pEpMimeObjCAdapterTests_macOS/TestUtils/PEPAttachment+PEPTestTypes.m
  5. +19
    -0
      pEpMimeObjCAdapterTests_macOS/TestUtils/PEPIdentity+PEPTestTypes.m
  6. +61
    -2
      pEpMimeObjCAdapterTests_macOS/TestUtils/PEPMessage+PEPTestTypes.m

+ 4
- 0
Interface/PEPMessage+PEPMessage_MIME/PEPMessage+PEPMessage_MIME.mm View File

@ -17,6 +17,10 @@
+ (nullable instancetype)pEpMessageWithMimeData:(NSData *)mimeData error:(NSError **)error {
NSString *mimeString = [[NSString alloc] initWithData:mimeData encoding:NSUTF8StringEncoding];
if (!mimeString) {
// Try again with ascii. Rare mails require that.
mimeString = [[NSString alloc] initWithData:mimeData encoding:NSASCIIStringEncoding];
}
if (!mimeString) {
*error = [NSError errorWithDomain:PEPMimeObjCAdapterErrorDomain
code:PEPMimeObjCAdapterErrorMIMEParsing


+ 10
- 0
pEpMimeObjCAdapter.xcodeproj/project.pbxproj View File

@ -27,6 +27,8 @@
1585EA052696E5F100B822E1 /* PEPMessage+PEPTestTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 1585EA042696E5F100B822E1 /* PEPMessage+PEPTestTypes.m */; };
1585EA082696E60D00B822E1 /* PEPIdentity+PEPTestTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 1585EA072696E60D00B822E1 /* PEPIdentity+PEPTestTypes.m */; };
1585EA0B2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 1585EA0A2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m */; };
1585EA0D2696F69200B822E1 /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 1585EA0C2696F69200B822E1 /* libc++.tbd */; };
1585EA442696FB1D00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml in Resources */ = {isa = PBXBuildFile; fileRef = 1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -107,6 +109,8 @@
1585EA072696E60D00B822E1 /* PEPIdentity+PEPTestTypes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPIdentity+PEPTestTypes.m"; sourceTree = "<group>"; };
1585EA092696E62600B822E1 /* PEPAttachment+PEPTestTypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PEPAttachment+PEPTestTypes.h"; sourceTree = "<group>"; };
1585EA0A2696E62600B822E1 /* PEPAttachment+PEPTestTypes.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PEPAttachment+PEPTestTypes.m"; sourceTree = "<group>"; };
1585EA0C2696F69200B822E1 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Ihre Sendung 254539842170 wird verpackt - \"bienenweber@t-online.de\" <bienenweber@t-online.de> - 2020-04-22 1101.eml"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -124,6 +128,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1585EA0D2696F69200B822E1 /* libc++.tbd in Frameworks */,
1585E9EA2695BDEC00B822E1 /* libpEpMimeObjCAdapter_macOS.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
@ -175,6 +180,7 @@
1585E8F8268E112A00B822E1 /* Frameworks */ = {
isa = PBXGroup;
children = (
1585EA0C2696F69200B822E1 /* libc++.tbd */,
1585E936269454A100B822E1 /* libpEpEngine_macOS.a */,
);
name = Frameworks;
@ -234,6 +240,7 @@
1585E9F32695BE0300B822E1 /* test_mails */ = {
isa = PBXGroup;
children = (
1585EA182696FB1C00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml */,
);
path = test_mails;
sourceTree = "<group>";
@ -406,6 +413,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1585EA442696FB1D00B822E1 /* Ihre Sendung 254539842170 wird verpackt - "bienenweber@t-online.de" <bienenweber@t-online.de> - 2020-04-22 1101.eml in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -638,6 +646,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "security.pep.pEpMimeObjCAdapterTests-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@ -656,6 +665,7 @@
"@loader_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.3;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_BUNDLE_IDENTIFIER = "security.pep.pEpMimeObjCAdapterTests-macOS";
PRODUCT_NAME = "$(TARGET_NAME)";
};


+ 144
- 45
pEpMimeObjCAdapterTests_macOS/Interface/PEPMessage+PEPMessage_MIMETest.m View File

@ -7,7 +7,9 @@
#import <XCTest/XCTest.h>
#import "PEPMessage+PEPMessage_MIME.h"
#import <PEPObjCAdapterTypes_macOS/PEPObjCAdapterTypes_macOS.h>
#import "PEPMessage+PEPTestTypes.h"
@interface PEPMessage_MIMETest : XCTestCase
@ -20,74 +22,171 @@
}
- (void)testPEPMessage2MIMEString_onlyRequiredFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
PEPMessage *testee = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
[self assertPEPMessageToMimeString:testee];
}
- (void)testPEPMessage2MIMEString_allFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
PEPMessage *testee = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
[self assertPEPMessageToMimeString:testee];
}
- (void)testPEPMessage2MIMEData_onlyRequiredFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
PEPMessage *testee = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
[self assertPEPMessageToMimeData:testee];
}
- (void)testPEPMessage2MIMEData_allFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testMIME2PEPMessage_onlyRequiredFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testMIME2PEPMessage_allFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testRoundtripMIMEString2PEPMessageAndBack_allFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testRoundtripMIMEString2PEPMessageAndBack_onlyRequiredFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testRoundtripMIMEData2PEPMessageAndBack_allFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
- (void)testRoundtripMIMEData2PEPMessageAndBack_onlyRequiredFieldsSet {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
PEPMessage *testee = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
[self assertPEPMessageToMimeData:testee];
}
- (void)testMIMEData2PEPMessage_onlyRequiredFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
NSError *error = nil;
NSData *mimeData = [pEpMessage mimeDataWithError:&error];
XCTAssertNotNil(mimeData);
[self assertMimedata2PEPMessage:mimeData];
}
- (void)testMIMEData2PEPMessage_allFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
NSError *error = nil;
NSData *mimeData = [pEpMessage mimeDataWithError:&error];
XCTAssertNotNil(mimeData);
[self assertMimedata2PEPMessage:mimeData];
}
- (void)testMIMEString2PEPMessage_onlyRequiredFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
NSError *error = nil;
NSString *mimestring = [pEpMessage mimeStringWithError:&error];
XCTAssertNotNil(mimestring);
[self assertMimeString2PEPMessage:mimestring];
}
- (void)testMIMEString2PEPMessage_allFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
NSError *error = nil;
NSString *mimestring = [pEpMessage mimeStringWithError:&error];
XCTAssertNotNil(mimestring);
[self assertMimeString2PEPMessage:mimestring];
}
- (void)testRoundtripPEPMessage2MIMEStringAndBack_allFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
NSError *error = nil;
NSString *mimestring = [pEpMessage mimeStringWithError:&error];
XCTAssertNotNil(mimestring);
[self assertMimeString2PEPMessage:mimestring];
PEPMessage *backConvertedPEPMessage = [PEPMessage pEpMessageWithMimeString:mimestring
error:&error];
XCTAssertNotNil(backConvertedPEPMessage);
[pEpMessage isEqual:backConvertedPEPMessage];
}
- (void)testRoundtripPEPMessage2MIMEStringAndBack_onlyRequiredFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
NSError *error = nil;
NSString *mimestring = [pEpMessage mimeStringWithError:&error];
XCTAssertNotNil(mimestring);
[self assertMimeString2PEPMessage:mimestring];
PEPMessage *backConvertedPEPMessage = [PEPMessage pEpMessageWithMimeString:mimestring
error:&error];
XCTAssertNotNil(backConvertedPEPMessage);
[pEpMessage isEqual:backConvertedPEPMessage];
}
- (void)testRoundtripPEPMessage2MIMEDataAndBack_allFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:NO];
NSError *error = nil;
NSData *mimeData = [pEpMessage mimeDataWithError:&error];
XCTAssertNotNil(mimeData);
[self assertMimedata2PEPMessage:mimeData];
PEPMessage *backConvertedPEPMessage = [PEPMessage pEpMessageWithMimeData:mimeData error:&error];
XCTAssertNotNil(backConvertedPEPMessage);
[pEpMessage isEqual:backConvertedPEPMessage];
}
- (void)testRoundtripPEPMessage2MIMEDataAndBack_onlyRequiredFieldsSet {
PEPMessage *pEpMessage = [PEPMessage testMessageWithOnlyRequiredFieldsSet:YES];
NSError *error = nil;
NSData *mimeData = [pEpMessage mimeDataWithError:&error];
XCTAssertNotNil(mimeData);
[self assertMimedata2PEPMessage:mimeData];
PEPMessage *backConvertedPEPMessage = [PEPMessage pEpMessageWithMimeData:mimeData error:&error];
XCTAssertNotNil(backConvertedPEPMessage);
[pEpMessage isEqual:backConvertedPEPMessage];
}
/// If you have mails causing issue which you want to test, add them to Resoureces/test_mails group.
/// If OK for privacy reasons, feel free to check them in.
/// The must have ".eml" extension.
- (void)testRoundtripForAllMailsInTestmails {
NSBundle *bundle = [NSBundle bundleForClass:self.class];
NSArray<NSURL*> *urls = [bundle URLsForResourcesWithExtension:@"eml" subdirectory:nil];
XCTAssertTrue(urls.count > 0, @"This test does nothing if there are zero mails in test_mails directory");
for (NSURL *url in urls) {
NSError *error = nil;
NSString *mailString = [NSString stringWithContentsOfURL:url
encoding:NSUTF8StringEncoding
error:&error];
if (!mailString) {
mailString = [NSString stringWithContentsOfURL:url
encoding:NSASCIIStringEncoding
error:&error];
}
if (!mailString) {
XCTFail(@"Error lodaing url: %@", url);
continue;
}
[self assertRoundtripMIMEString2PEPMEssageAndBack:mailString];
}
}
// MARK: - HELPER
- (void)assertPEPMessageToMimeString:(PEPMessage *)pEpMEssage {
NSError *error = nil;
NSString *testee = [pEpMEssage mimeStringWithError:&error];
XCTAssertNotNil(testee);
}
- (void)assertPEPMessageToMimeData:(PEPMessage *)pEpMEssage {
NSError *error = nil;
NSData *testee = [pEpMEssage mimeDataWithError:&error];
XCTAssertNotNil(testee);
NSString *convertedTestee = [[NSString alloc] initWithData:testee encoding:NSUTF8StringEncoding];
XCTAssertNotNil(convertedTestee, @"Somthins is wrong with data.");
}
- (void)assertMimeString2PEPMessage:(NSString *)mimeString {
NSError *error = nil;
PEPMessage *testee = [PEPMessage pEpMessageWithMimeString:mimeString error:&error];
XCTAssertNotNil(testee);
}
- (void)assertMimedata2PEPMessage:(NSData *)mimeData {
NSError *error = nil;
PEPMessage *testee = [PEPMessage pEpMessageWithMimeData:mimeData error:&error];
XCTAssertNotNil(testee);
}
- (void)assertRoundtripMIMEString2PEPMEssageAndBack:(NSString *)mimeString {
NSError *error = nil;
PEPMessage *pEpMEssage = [PEPMessage pEpMessageWithMimeString:mimeString error:&error];
XCTAssertNotNil(pEpMEssage);
NSData *mimeData = [pEpMEssage mimeDataWithError:&error];
XCTAssertNotNil(mimeData);
NSString *mimeStringFromData = [[NSString alloc] initWithData:mimeData
encoding:NSUTF8StringEncoding];
XCTAssertNotNil(mimeStringFromData);
NSString *mimeStringBackConverted = [pEpMEssage mimeStringWithError:&error];
XCTAssertNotNil(mimeStringBackConverted);
PEPMessage *onceMoreMessage = [PEPMessage pEpMessageWithMimeString:mimeStringBackConverted
error:&error];
XCTAssertTrue([pEpMEssage isEqual:onceMoreMessage]);
}
@end

+ 16
- 0
pEpMimeObjCAdapterTests_macOS/TestUtils/PEPAttachment+PEPTestTypes.m View File

@ -18,4 +18,20 @@
return result;
}
- (BOOL)isEqual:(PEPAttachment *)other
{
if (other == self) {
return YES;
} else if (![self.data isEqual:other.data]) {
return NO;
} else if (![self.filename isEqual:other.filename]) {
return NO;
} else if (self.size != other.size) {
return NO;
} else if (self.contentDisposition != other.contentDisposition) {
return NO;
}
return YES;
}
@end

+ 19
- 0
pEpMimeObjCAdapterTests_macOS/TestUtils/PEPIdentity+PEPTestTypes.m View File

@ -19,6 +19,25 @@
result.userID = !userID ? @"someUserID" : userID;
result.userName = onlyRequiredFileds ? nil : (!username ? @"someUsername" : username);
result.isOwn = isOwn;
return result;
}
- (BOOL)isEqual:(PEPIdentity *)other
{
if (other == self) {
return YES;
} else if (![self.userID isEqual:other.userID]) {
return NO;
} else if (![self.address isEqual:other.address]) {
return NO;
} else if (![self.userName isEqual:other.userName]) {
return NO;
} else if (![self.fingerPrint isEqual:other.fingerPrint]) {
return NO;
} else if (self.isOwn != other.isOwn) {
return NO;
}
return YES;
}
@end

+ 61
- 2
pEpMimeObjCAdapterTests_macOS/TestUtils/PEPMessage+PEPTestTypes.m View File

@ -49,8 +49,8 @@
username:@"bccUserName"
isOwn:NO];
PEPAttachment attachment1 = [PEPAttachment testAttachmentWithOnlyRequiredFieldsSet:onlyRequiredFileds];
PEPAttachment attachment2 = [PEPAttachment testAttachmentWithOnlyRequiredFieldsSet:onlyRequiredFileds];
PEPAttachment *attachment1 = [PEPAttachment testAttachmentWithOnlyRequiredFieldsSet:onlyRequiredFileds];
PEPAttachment *attachment2 = [PEPAttachment testAttachmentWithOnlyRequiredFieldsSet:onlyRequiredFileds];
PEPMessage *result = [PEPMessage new];
result.from = from;
@ -63,4 +63,63 @@
return result;
}
- (BOOL)isEqual:(PEPMessage *)other
{
if (other == self) {
return YES;
} else if (![self.shortMessage isEqual:other.shortMessage]
&& !(self.shortMessage == nil && other.shortMessage == nil)) {
return NO;
} else if (![self.longMessage isEqual:other.longMessage]
&& !(self.longMessage == nil && other.longMessage == nil)) {
return NO;
} else if (![self.longMessageFormatted isEqual:other.longMessageFormatted]
&& !(self.longMessageFormatted == nil && other.longMessageFormatted == nil)) {
return NO;
} else if (![self.messageID isEqual:other.messageID] && !(self.messageID == nil && other.messageID == nil)) {
return NO;
} else if (![self.optionalFields isEqual:other.optionalFields] && !(self.optionalFields == nil && other.optionalFields == nil)) {
return NO;
} else if (![self.from isEqual:other.from]) {
return NO;
} else if (self.to.count > 0) {
if (self.to.count != other.to.count) {
return NO;
}
for (int i = 0; i < self.to.count; i++) {
PEPIdentity *my = self.to[i];
PEPIdentity *oth = other.to[i];
if (![my isEqual:oth]) {
return NO;
}
}
} else if (self.cc.count > 0) {
if (self.cc.count != other.cc.count) {
return NO;
}
for (int i = 0; i < self.cc.count; i++) {
PEPIdentity *my = self.cc[i];
PEPIdentity *oth = other.cc[i];
if (![my isEqual:oth]) {
return NO;
}
}
} else if (![self.bcc isEqual:other.bcc]) {
return NO;
} else if (self.attachments.count > 0) {
if (self.attachments.count != other.attachments.count) {
return NO;
}
for (int i = 0; i < self.attachments.count; i++) {
PEPAttachment *my = self.attachments[i];
PEPAttachment *oth = other.attachments[i];
if (![my isEqual:oth]) {
return NO;
}
}
}
return YES;
}
@end

Loading…
Cancel
Save