Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixes to MailCore tests; no hard-coding of mail account data, proper test data file access #67

Merged
merged 8 commits into from

2 participants

@scottnonnenberg

Hey guys. I'm back with an updated and cleaner Pull Request.

Now all TestData is compiled into the Test bundle and pulled out of it when needed by the tests. The same account.plist is still recommended (and excluded by .gitignore) to specify your own mail account information for the live test.

There was one key change to the source to make the tests pass, in commit 'Fix to Core Folder tests; senderDate returns nil.' Not sure why [NSDate distantPast] was used instead of nil, but I changed it to what the test expected, nil. We can easily change that back and in the test if needed. [NSDate distantPast] just seems very weird to me.

Three tests still failing, but they seem like they might be a regression in the core functionality more than anything specific to my changes. Thoughts?

file://localhost/Users/scottnonnenberg/Development/MailCore/Tests/CTCoreAttachmentTests.m: error: testJPEG (CTCoreAttachmentTests) failed: 'image/jpeg' should be equal to 'application/octet-stream' The content-type should have been image/jpeg
file://localhost/Users/scottnonnenberg/Development/MailCore/Tests/CTCoreAttachmentTests.m: error: testPNG (CTCoreAttachmentTests) failed: 'image/png' should be equal to 'application/octet-stream' The content-type should have been image/png
file://localhost/Users/scottnonnenberg/Development/MailCore/Tests/CTCoreAttachmentTests.m: error: testTIFF (CTCoreAttachmentTests) failed: 'image/tiff' should be equal to 'application/octet-stream' The content-type should have been image/TIFF

scottnonnenberg added some commits
@scottnonnenberg scottnonnenberg account.plist used to specify mail account data
Instead of hardcoding it. Excluded from the repository via .gitignore. Also adding TestData to the project, compiled into the Test bundle.

Pushing the iOS deployment target down to 4.3, and ensuring that all projects have the same value there.
d3bf550
@scottnonnenberg scottnonnenberg Fixing Core Folder tests
sentDateGMT has been removed, changing to senderDate. Also, changing from bodyPreferringPlainText to just body - the former required an out parameter that was not being provided.
d28da84
@scottnonnenberg scottnonnenberg MIME/CoreAttachment tests get files from bundle
Because in the newest simulators, your current working directory is more like it is in when you're on the phone itself.

Also no need for the filePrefix var any longer.
7565fd2
@scottnonnenberg scottnonnenberg Core Message tests: files in bundle, testSentDate
testSentDate wasn't quite passing: sentDateGMT has been removed and the number of seconds representing the date the email was sent is not what was there before. Fixed.

Also, we needed to pull the message files out of the test bundle.
c98f744
@scottnonnenberg scottnonnenberg Core Message tests whitespace b5fee7f
@scottnonnenberg scottnonnenberg Fix to Core Folder tests; senderDate returns nil
Noticed that this change was necessary to get all Core Folder tests passing. Those tests expected senderDate to return nil if there was no message loaded.
dcd20b4
@scottnonnenberg scottnonnenberg Properly pulling MIMETests/testBruteForce files fc5c8a3
@scottnonnenberg scottnonnenberg CTCoreMessage.htmlBody now behaves like .body
It calls fetchBodyStructure if myFields or myParsedMIME is null, just like .body does. Two new tests added; the change to htmlBody is required to get them both to pass.
1934f9c
@mronge mronge merged commit 6a7c75b into MailCore:master
@mronge
Owner

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2012
  1. @scottnonnenberg

    account.plist used to specify mail account data

    scottnonnenberg authored
    Instead of hardcoding it. Excluded from the repository via .gitignore. Also adding TestData to the project, compiled into the Test bundle.
    
    Pushing the iOS deployment target down to 4.3, and ensuring that all projects have the same value there.
  2. @scottnonnenberg

    Fixing Core Folder tests

    scottnonnenberg authored
    sentDateGMT has been removed, changing to senderDate. Also, changing from bodyPreferringPlainText to just body - the former required an out parameter that was not being provided.
  3. @scottnonnenberg

    MIME/CoreAttachment tests get files from bundle

    scottnonnenberg authored
    Because in the newest simulators, your current working directory is more like it is in when you're on the phone itself.
    
    Also no need for the filePrefix var any longer.
  4. @scottnonnenberg

    Core Message tests: files in bundle, testSentDate

    scottnonnenberg authored
    testSentDate wasn't quite passing: sentDateGMT has been removed and the number of seconds representing the date the email was sent is not what was there before. Fixed.
    
    Also, we needed to pull the message files out of the test bundle.
  5. @scottnonnenberg
  6. @scottnonnenberg

    Fix to Core Folder tests; senderDate returns nil

    scottnonnenberg authored
    Noticed that this change was necessary to get all Core Folder tests passing. Those tests expected senderDate to return nil if there was no message loaded.
  7. @scottnonnenberg
  8. @scottnonnenberg

    CTCoreMessage.htmlBody now behaves like .body

    scottnonnenberg authored
    It calls fetchBodyStructure if myFields or myParsedMIME is null, just like .body does. Two new tests added; the change to htmlBody is required to get them both to pass.
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -4,3 +4,4 @@ xcuserdata
.DS_Store
include/
.idea
+TestData/account.plist
View
10 MailCore.xcodeproj/project.pbxproj
@@ -117,6 +117,7 @@
F8EC5B0514C37F60006AF4D3 /* CTMIME_HtmlPart.m in Sources */ = {isa = PBXBuildFile; fileRef = F8EC5B0214C37F60006AF4D3 /* CTMIME_HtmlPart.m */; };
F8EC5B0514C37F60006AF4D5 /* CTConnectedTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8EC5B0514C37F60006AF4D4 /* CTConnectedTest.m */; };
F8EC5B0514C37F60006AF4D8 /* CTCoreFolderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = F8EC5B0514C37F60006AF4D7 /* CTCoreFolderTests.m */; };
+ F9FC3A731683FC07004B2D1E /* TestData in Resources */ = {isa = PBXBuildFile; fileRef = F9FC3A721683FC07004B2D1E /* TestData */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -298,6 +299,7 @@
F8EC5B0514C37F60006AF4D6 /* CTConnectedTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTConnectedTest.h; path = Tests/CTConnectedTest.h; sourceTree = "<group>"; };
F8EC5B0514C37F60006AF4D7 /* CTCoreFolderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CTCoreFolderTests.m; path = Tests/CTCoreFolderTests.m; sourceTree = "<group>"; };
F8EC5B0514C37F60006AF4D9 /* CTCoreFolderTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CTCoreFolderTests.h; path = Tests/CTCoreFolderTests.h; sourceTree = "<group>"; };
+ F9FC3A721683FC07004B2D1E /* TestData */ = {isa = PBXFileReference; lastKnownFileType = folder; path = TestData; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -359,6 +361,7 @@
F888632D158102F50088CF38 /* Cyrus SASL.xcodeproj */,
F890D38D10CEECD50039817C /* libetpan.xcodeproj */,
F85A18AF09C7D8F200305C06 /* Tests */,
+ F9FC3A721683FC07004B2D1E /* TestData */,
08FB77AEFE84172EC02AAC07 /* Classes */,
32C88DFF0371C24200C91783 /* Other Sources */,
089C1665FE841158C02AAC07 /* Resources */,
@@ -784,6 +787,7 @@
buildActionMask = 2147483647;
files = (
F8DFCF5615801A5000C01975 /* InfoPlist.strings in Resources */,
+ F9FC3A731683FC07004B2D1E /* TestData in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -1033,6 +1037,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "libetpan/build-mac/include/**";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = "";
SDKROOT = macosx;
};
@@ -1049,6 +1054,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
HEADER_SEARCH_PATHS = "libetpan/build-mac/include/**";
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = "";
SDKROOT = macosx;
};
@@ -1111,7 +1117,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
INFOPLIST_FILE = "Tests/Tests-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/iOSPorts/ports/security/cyrus-sasl/build/Debug-iphoneos\"",
@@ -1138,7 +1144,7 @@
GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
INFOPLIST_FILE = "Tests/Tests-Info.plist";
- IPHONEOS_DEPLOYMENT_TARGET = 5.1;
+ IPHONEOS_DEPLOYMENT_TARGET = 4.3;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"\"$(SRCROOT)/iOSPorts/ports/security/cyrus-sasl/build/Debug-iphoneos\"",
View
5 Source/CTCoreMessage.m
@@ -177,6 +177,9 @@ - (BOOL)hasHtmlBody {
}
- (NSString *)htmlBody {
+ if (myFields == NULL || myParsedMIME == nil) {
+ [self fetchBodyStructure];
+ }
NSMutableString *result = [NSMutableString string];
[self _buildUpHtmlBodyText:myParsedMIME result:result];
return result;
@@ -354,7 +357,7 @@ - (NSTimeZone*)senderTimeZone {
- (NSDate *)senderDate {
if ( myFields->fld_orig_date == NULL) {
- return [NSDate distantPast];
+ return nil;
} else {
struct mailimf_date_time *d;
View
1  Tests/CTConnectedTest.h
@@ -38,4 +38,5 @@
@interface CTConnectedTest : SenTestCase
@property (nonatomic, strong) CTCoreAccount *account;
@property (nonatomic, strong) CTCoreFolder *folder;
+@property (nonatomic, strong) NSDictionary *credentials;
@end
View
57 Tests/CTConnectedTest.m
@@ -35,15 +35,41 @@
@implementation CTConnectedTest {
}
-@synthesize account, folder;
-NSString *SERVER = @"imap.gmail.com";
-NSString *USERNAME = @"mailcoretests@gmail.com";
-NSString *PASSWORD = @"MailCoreRockz";
+@synthesize account, folder, credentials;
+
+/* Create a TestData/account.plist file to make these tests work. Start with this:
+
+ <?xml version="1.0" encoding="UTF-8"?>
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+ <plist version="1.0">
+ <dict>
+ <key>username</key>
+ <string>username</string>
+ <key>password</key>
+ <string>password</string>
+ <key>server</key>
+ <string>server</string>
+ <key>port</key>
+ <integer>993</integer>
+ <key>path</key>
+ <string>MailCoreTests</string>
+ </dict>
+ </plist>
+
+ Because account.plist is included in the .gitignore file, your credentials won't be added
+ to source control.
+
+ */
- (void)setUp {
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/account" ofType:@"plist"];
+ self.credentials = [NSDictionary dictionaryWithContentsOfFile:filePath];
+
+ STAssertNotNil(self.credentials, @"These tests will fail anyway if they can't connect");
+
self.account = [[CTCoreAccount alloc] init];
[self connect];
- self.folder = [self.account folderWithPath:@"Test"];
+ self.folder = [self.account folderWithPath:[self.credentials valueForKey:@"path"]];
[self.folder connect];
}
@@ -60,12 +86,27 @@ - (void)dealloc {
}
- (void)connect {
- [self.account connectToServer:SERVER port:993 connectionType:CTConnectionTypeTLS authType:CTImapAuthTypePlain
- login:USERNAME password:PASSWORD];
+ NSString *server = [self.credentials valueForKey:@"server"];
+ int port = [[self.credentials objectForKey:@"port"] intValue];
+ NSString *username = [self.credentials valueForKey:@"username"];
+ NSString *password = [self.credentials valueForKey:@"password"];
+
+ STAssertFalse([server isEqualToString:@"server"], @"You need to provide your own account info");
+ STAssertFalse([username isEqualToString:@"username"], @"You need to provide your own account info");
+ STAssertFalse([password isEqualToString:@"password"], @"You need to provide your own account info");
+ /* Once you've provided your own account info, create a folder with six messages in it.
+ The path key in the account.plist should point to this directory, and you're ready! */
+
+ BOOL success = [self.account connectToServer:server port:port connectionType:CTConnectionTypeTLS authType:CTImapAuthTypePlain login:username password:password];
+
+ STAssertTrue(success, @"should successfully connect to email account");
+ if (!success) {
+ NSLog(@"!!!!!!! Can't connect to account !!!!!!! Error: %@", [[self.account lastError] localizedDescription]);
+ }
}
- (void)disconnect {
[self.folder disconnect];
[self.account disconnect];
}
-@end
+@end
View
16 Tests/CTCoreAttachmentTests.m
@@ -34,32 +34,32 @@
@implementation CTCoreAttachmentTests
- (void)testJPEG {
- NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6201.jpg"];
- CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/DSC_6201" ofType:@"jpg"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:filePath];
STAssertEqualObjects(@"image/jpeg", [attach contentType], @"The content-type should have been image/jpeg");
STAssertTrue([attach data] != nil, @"Data should not have been nil");
[attach release];
}
- (void)testPNG {
- NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6202.png"];
- CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/DSC_6202" ofType:@"png"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:filePath];
STAssertEqualObjects(@"image/png", [attach contentType], @"The content-type should have been image/png");
STAssertTrue([attach data] != nil, @"Data should not have been nil");
[attach release];
}
- (void)testTIFF {
- NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6193.tif"];
- CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/DSC_6193" ofType:@"tif"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:filePath];
STAssertEqualObjects(@"image/tiff", [attach contentType], @"The content-type should have been image/TIFF");
STAssertTrue([attach data] != nil, @"Data should not have been nil");
[attach release];
}
- (void)testNEF {
- NSString *path = [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/DSC_6204.NEF"];
- CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:path];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/DSC_6204" ofType:@"NEF"];
+ CTCoreAttachment *attach = [[CTCoreAttachment alloc] initWithContentsOfFile:filePath];
STAssertEqualObjects(@"application/octet-stream", [attach contentType],
@"The content-type should have been application/octet-stream");
STAssertTrue([attach data] != nil, @"Data should not have been nil");
View
22 Tests/CTCoreFolderTests.m
@@ -43,7 +43,7 @@ - (void)testFetchOnlyDefaults {
STAssertTrue([msg uid] > 0, @"We should have the UID");
STAssertTrue([msg messageSize] > 0, @"We always download message size");
- STAssertNil([msg sentDateGMT], @"We have no envelope so should be nil");
+ STAssertNil([msg senderDate], @"We have no envelope so should be nil");
STAssertNil([msg subject], @"We have no envelope so should be nil");
STAssertNil([msg to], @"We have no envelope so should be nil");
STAssertNil([msg cc], @"We have no envelope so should be nil");
@@ -52,7 +52,7 @@ - (void)testFetchOnlyDefaults {
STAssertNil([msg bcc], @"We have no envelope so should be nil");
// This will force another download of message body data, checking to make sure it works
- NSString *body = [msg bodyPreferringPlainText];
+ NSString *body = [msg body];
STAssertTrue(body.length > 0, @"");
}
@@ -63,14 +63,14 @@ - (void)testFetchEnvelope {
STAssertTrue([msg uid] > 0, @"We should have the UID");
STAssertTrue([msg messageSize] > 0, @"We always download message size");
- STAssertNotNil([msg sentDateGMT], @"We DO HAVE AN envelope so shouldn't be nil");
+ STAssertNotNil([msg senderDate], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg subject], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg to], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg sender], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg from], @"We DO HAVE AN envelope so shouldn't be nil");
// This will force another download of message body data, checking to make sure it works
- NSString *body = [msg bodyPreferringPlainText];
+ NSString *body = [msg body];
STAssertTrue(body.length > 0, @"");
}
@@ -81,14 +81,14 @@ - (void)testFetchEnvelopeUsingUIDFetch {
STAssertTrue([msg uid] > 0, @"We should have the UID");
STAssertTrue([msg messageSize] > 0, @"We always download message size");
- STAssertNotNil([msg sentDateGMT], @"We DO HAVE AN envelope so shouldn't be nil");
+ STAssertNotNil([msg senderDate], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg subject], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg to], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg sender], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg from], @"We DO HAVE AN envelope so shouldn't be nil");
// This will force another download of message body data, checking to make sure it works
- NSString *body = [msg bodyPreferringPlainText];
+ NSString *body = [msg body];
STAssertTrue(body.length > 0, @"");
}
@@ -99,7 +99,7 @@ - (void)testFetchBodyStructure {
STAssertTrue([msg uid] > 0, @"We should have the UID");
STAssertTrue([msg messageSize] > 0, @"We always download message size");
- STAssertNil([msg sentDateGMT], @"We have no envelope so should be nil");
+ STAssertNil([msg senderDate], @"We have no envelope so should be nil");
STAssertNil([msg subject], @"We have no envelope so should be nil");
STAssertNil([msg to], @"We have no envelope so should be nil");
STAssertNil([msg cc], @"We have no envelope so should be nil");
@@ -108,7 +108,7 @@ - (void)testFetchBodyStructure {
STAssertNil([msg bcc], @"We have no envelope so should be nil");
// A second call to fetch the body structure shouldn't be needed, we only need to fetch body
- NSString *body = [msg bodyPreferringPlainText];
+ NSString *body = [msg body];
STAssertTrue(body.length > 0, @"");
}
@@ -119,14 +119,14 @@ - (void)testFetchEverything {
STAssertTrue([msg uid] > 0, @"We should have the UID");
STAssertTrue([msg messageSize] > 0, @"We always download message size");
- STAssertNotNil([msg sentDateGMT], @"We DO HAVE AN envelope so shouldn't be nil");
+ STAssertNotNil([msg senderDate], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg subject], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg to], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg sender], @"We DO HAVE AN envelope so shouldn't be nil");
STAssertNotNil([msg from], @"We DO HAVE AN envelope so shouldn't be nil");
// A second call to fetch the body structure shouldn't be needed, we only need to fetch body
- NSString *body = [msg bodyPreferringPlainText];
+ NSString *body = [msg body];
STAssertTrue(body.length > 0, @"");
}
-@end
+@end
View
55 Tests/CTCoreMessageTests.m
@@ -38,7 +38,8 @@
@implementation CTCoreMessageTests
- (void)setUp {
myMsg = [[CTCoreMessage alloc] init];
- myRealMsg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab" ofType:@""];
+ myRealMsg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
}
- (void)tearDown {
@@ -46,6 +47,16 @@ - (void)tearDown {
[myRealMsg release];
}
+- (void)testBody {
+ STAssertTrue([[myRealMsg body] rangeOfString:@"Kiwi-dev mailing list"].location != NSNotFound, @"Expect to pull out the right text");
+ NSLog(@"Body is %@", [myRealMsg body]);
+}
+
+- (void)testHtmlBody {
+ STAssertTrue([[myRealMsg htmlBody] rangeOfString:@"CTCoreMessage no longer depends"].location != NSNotFound, @"Expect to pull out the right text");
+ NSLog(@"Html body is %@", [myRealMsg htmlBody]);
+}
+
- (void)testBasicSubject {
[myMsg setSubject:@"Test value1!"];
STAssertEqualObjects(@"Test value1!", [myMsg subject], @"Basic set and get of subject failed.");
@@ -78,7 +89,8 @@ - (void)testBasicBody {
}
- (void)testSubjectOnData {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
[msg fetchBodyStructure];
STAssertEqualObjects(@"[Kiwi-dev] Revision 16", [msg subject], @"");
NSRange notFound = NSMakeRange(NSNotFound, 0);
@@ -93,11 +105,11 @@ - (void)testRender {
/* Do a few sanity checks on the str */
NSRange notFound = NSMakeRange(NSNotFound, 0);
STAssertTrue(!NSEqualRanges([str rangeOfString:@"Date:"],notFound), @"Render sanity check failed!");
- STAssertTrue(!NSEqualRanges([str rangeOfString:@"Message-ID:"],notFound), @"Render sanity check failed!");
- STAssertTrue(!NSEqualRanges([str rangeOfString:@"MIME-Version: 1.0"],notFound), @"Render sanity check failed!");
+ STAssertTrue(!NSEqualRanges([str rangeOfString:@"Message-ID:"],notFound), @"Render sanity check failed!");
+ STAssertTrue(!NSEqualRanges([str rangeOfString:@"MIME-Version: 1.0"],notFound), @"Render sanity check failed!");
STAssertTrue(!NSEqualRanges([str rangeOfString:@"test"],notFound), @"Render sanity check failed!");
- STAssertTrue(!NSEqualRanges([str rangeOfString:@"Content-Transfer-Encoding:"],notFound), @"Render sanity check failed!");
- STAssertTrue(NSEqualRanges([str rangeOfString:@"not there"],notFound), @"Render sanity check failed!");
+ STAssertTrue(!NSEqualRanges([str rangeOfString:@"Content-Transfer-Encoding:"],notFound), @"Render sanity check failed!");
+ STAssertTrue(NSEqualRanges([str rangeOfString:@"not there"],notFound), @"Render sanity check failed!");
}
- (void)testRenderWithToField {
@@ -108,7 +120,7 @@ - (void)testRenderWithToField {
/* Do a few sanity checks on the str */
NSRange notFound = NSMakeRange(NSNotFound, 0);
STAssertTrue(!NSEqualRanges([str rangeOfString:@"message"],notFound), @"Render sanity check failed!");
- STAssertTrue(!NSEqualRanges([str rangeOfString:@"To: Matt <test@test.com>"],notFound), @"Render sanity check failed!");
+ STAssertTrue(!NSEqualRanges([str rangeOfString:@"To: Matt <test@test.com>"],notFound), @"Render sanity check failed!");
}
- (void)testTo {
@@ -126,7 +138,8 @@ - (void)testFrom {
}
- (void)testFromSpecialChar {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/kiwi-dev/1162094633.15211_0.randymail-mx2:2,RSab"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/kiwi-dev/1162094633.15211_0.randymail-mx2:2,RSab" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
CTCoreAddress *addr = [[msg from] anyObject];
STAssertEqualObjects(@"Joachim Mårtensson", [addr name], @"");
[msg release];
@@ -152,10 +165,19 @@ - (void)testReplyTo {
}
- (void)testSentDate {
- // Is this right?? I'm super confused by this time zone stuff
- NSDate *sentDate = [myRealMsg sentDateGMT];
- NSDate *actualDate = [NSDate dateWithTimeIntervalSince1970:1167217609];
- STAssertEqualObjects(sentDate, actualDate, @"Date's should be equal!");
+ NSTimeInterval sentSince1970 = [[myRealMsg senderDate] timeIntervalSince1970];
+
+ NSTimeInterval actualSince1970 = 1167196009;
+ /*
+ you can get this value by typing this into your browser console
+
+ > date = new Date('Tue, 26 Dec 2006 21:06:49 -0800 (PST)')
+ Tue Dec 26 2006 21:06:49 GMT-0800 (PST)
+ > date.getTime() / 1000
+ 1167196009
+ */
+
+ STAssertEquals(sentSince1970, actualSince1970, @"Dates should be equal!");
}
- (void)testSettingFromTwice {
@@ -166,16 +188,17 @@ - (void)testSettingFromTwice {
}
- (void)testAttachments {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:
- [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/mime-tests/png_attachment"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/mime-tests/png_attachment" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
[msg fetchBodyStructure];
NSArray *attachments = [msg attachments];
STAssertTrue([attachments count] == 1, @"Count should have been 1");
STAssertEqualObjects([[attachments objectAtIndex:0] filename], @"Picture 1.png", @"Incorrect filename");
CTBareAttachment *bareAttach = [attachments objectAtIndex:0];
CTCoreAttachment *attach = [bareAttach fetchFullAttachment];
- NSData *origData = [NSData dataWithContentsOfFile:
- [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/Picture 1.png"]];
+
+ filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/Picture 1" ofType:@"png"];
+ NSData *origData = [NSData dataWithContentsOfFile:filePath];
STAssertEqualObjects(origData, attach.data, @"Original data and attach data should be the same");
[msg release];
}
View
2  Tests/CTMIMETests.h
@@ -31,8 +31,6 @@
#import <SenTestingKit/SenTestingKit.h>
-const NSString *filePrefix;
-
@interface CTMIMETests : SenTestCase {
}
View
33 Tests/CTMIMETests.m
@@ -41,11 +41,10 @@
#import "CTMIME_TextPart.h"
#import "CTMIME_Enumerator.h"
-const NSString *filePrefix = @"/Users/mronge/Projects/MailCore/";
-
@implementation CTMIMETests
- (void)testMIMETextPart {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/kiwi-dev/1167196014.6158_0.theronge.com:2,Sab" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
CTMIME *mime = [CTMIMEFactory createMIMEWithMIMEStruct:[msg messageStruct]->msg_mime forMessage:[msg messageStruct]];
STAssertTrue([mime isKindOfClass:[CTMIME_MessagePart class]],@"Outmost MIME type should be Message but it's not!");
STAssertTrue([[mime content] isKindOfClass:[CTMIME_MultiPart class]],@"Incorrect MIME structure found!");
@@ -79,13 +78,19 @@ - (void)testSmallMIME {
- (void)testBruteForce {
// run it on a bunch of the files in the test data directory and see if we can get it to crash
- NSDirectoryEnumerator *dirEnumerator = [[NSFileManager defaultManager] enumeratorAtPath:[filePrefix stringByAppendingString:@"TestData/kiwi-dev/"]];
- NSString *file;
+ NSString *directory = [[NSBundle bundleForClass:[self class]] resourcePath];
+ NSString *filesDirectory = [directory stringByAppendingPathComponent:@"TestData/kiwi-dev/"];
+
+ NSError *error;
+ NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:filesDirectory error:&error];
+
NSRange notFound = NSMakeRange(NSNotFound, 0);
- while ((file = [dirEnumerator nextObject])) {
+ for (NSString *file in directoryContents) {
if (!NSEqualRanges([file rangeOfString:@".svn"],notFound))
continue;
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@TestData/kiwi-dev/%@",filePrefix,file]];
+
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:[NSString stringWithFormat:@"TestData/kiwi-dev/%@",file] ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
NSLog(@"%@", [msg subject]);
[msg fetchBodyStructure];
NSString *stuff = [msg body];
@@ -95,7 +100,9 @@ - (void)testBruteForce {
}
- (void)testImageJPEGAttachment {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:[NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/mime-tests/imagetest"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/mime-tests/imagetest" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
+
CTMIME *mime = [CTMIMEFactory createMIMEWithMIMEStruct:[msg messageStruct]->msg_mime forMessage:[msg messageStruct]];
STAssertTrue([mime isKindOfClass:[CTMIME_MessagePart class]],@"Outmost MIME type should be Message but it's not!");
STAssertTrue([[mime content] isKindOfClass:[CTMIME_MultiPart class]],@"Incorrect MIME structure found!");
@@ -111,8 +118,9 @@ - (void)testImageJPEGAttachment {
}
- (void)testImagePNGAttachment {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:
- [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/mime-tests/png_attachment"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/mime-tests/png_attachment" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
+
CTMIME *mime = [CTMIMEFactory createMIMEWithMIMEStruct:
[msg messageStruct]->msg_mime forMessage:[msg messageStruct]];
STAssertTrue([mime isKindOfClass:[CTMIME_MessagePart class]],
@@ -133,8 +141,9 @@ - (void)testImagePNGAttachment {
}
- (void)testEnumerator {
- CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:
- [NSString stringWithFormat:@"%@%@",filePrefix,@"TestData/mime-tests/png_attachment"]];
+ NSString *filePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestData/mime-tests/png_attachment" ofType:@""];
+ CTCoreMessage *msg = [[CTCoreMessage alloc] initWithFileAtPath:filePath];
+
CTMIME *mime = [CTMIMEFactory createMIMEWithMIMEStruct:
[msg messageStruct]->msg_mime forMessage:[msg messageStruct]];
CTMIME_Enumerator *enumerator = [mime mimeEnumerator];
Something went wrong with that request. Please try again.