Permalink
Browse files

Merge branch 'master' of github.com:mronge/MailCore

  • Loading branch information...
2 parents bc90b09 + 6a7c75b commit d5b029aa806fed4da8bb5b84655312a547396b4f @mronge mronge committed Feb 8, 2013
View
@@ -4,3 +4,4 @@ xcuserdata
.DS_Store
include/
.idea
+TestData/account.plist
@@ -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\"",
@@ -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;
@@ -38,4 +38,5 @@
@interface CTConnectedTest : SenTestCase
@property (nonatomic, strong) CTCoreAccount *account;
@property (nonatomic, strong) CTCoreFolder *folder;
+@property (nonatomic, strong) NSDictionary *credentials;
@end
@@ -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
@@ -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");
@@ -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
Oops, something went wrong.

0 comments on commit d5b029a

Please sign in to comment.