diff options
-rwxr-xr-x | build-mac/mailcore2.xcodeproj/project.pbxproj | 20 | ||||
-rw-r--r-- | tests/main.mm | 4 | ||||
-rw-r--r-- | tests/test-all-mac.h | 16 | ||||
-rw-r--r-- | tests/test-all-mac.mm | 79 | ||||
-rw-r--r-- | tests/test-all.cpp (renamed from tests/test-all.mm) | 85 |
5 files changed, 147 insertions, 57 deletions
diff --git a/build-mac/mailcore2.xcodeproj/project.pbxproj b/build-mac/mailcore2.xcodeproj/project.pbxproj index 6f507c75..84aeb972 100755 --- a/build-mac/mailcore2.xcodeproj/project.pbxproj +++ b/build-mac/mailcore2.xcodeproj/project.pbxproj @@ -163,6 +163,8 @@ 9EF9AB25175F40C70027FA3B /* MCIMAPFolderStatusOperation.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 9EF9AB0E175F30C20027FA3B /* MCIMAPFolderStatusOperation.h */; }; BD49963719FEC6DD000945BC /* ConvertUTF.c in Sources */ = {isa = PBXBuildFile; fileRef = BD49963519FEC6DD000945BC /* ConvertUTF.c */; }; BD49963819FEC6DD000945BC /* ConvertUTF.c in Sources */ = {isa = PBXBuildFile; fileRef = BD49963519FEC6DD000945BC /* ConvertUTF.c */; }; + BD6272981A13FF2A00129AA8 /* test-all-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BD6272961A13FF2A00129AA8 /* test-all-mac.mm */; }; + BD6272991A13FF2A00129AA8 /* test-all-mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BD6272961A13FF2A00129AA8 /* test-all-mac.mm */; }; BD63713B177DFF080094121B /* MCLibetpan.cc in Sources */ = {isa = PBXBuildFile; fileRef = BD637139177DFF080094121B /* MCLibetpan.cc */; }; C07AD5D7FD82F8ACAB576231 /* NSError+MCO.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = C07AD44B013BB42A240B4F04 /* NSError+MCO.h */; }; C07AD99B2E2054C684DB8FF6 /* NSError+MCO.mm in Sources */ = {isa = PBXBuildFile; fileRef = C07ADFE43E22B38EFF23ADB5 /* NSError+MCO.mm */; }; @@ -400,8 +402,8 @@ C6A81B931706840C00882C15 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A81B921706840C00882C15 /* UIKit.framework */; }; C6A81B941706840C00882C15 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C64EA78F169F259200778456 /* Foundation.framework */; }; C6A81B961706840C00882C15 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A81B951706840C00882C15 /* CoreGraphics.framework */; }; - C6A81BAE1706847900882C15 /* test-all.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6A81BAC1706847900882C15 /* test-all.mm */; }; - C6A81BAF170684D300882C15 /* test-all.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6A81BAC1706847900882C15 /* test-all.mm */; }; + C6A81BAE1706847900882C15 /* test-all.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6A81BAC1706847900882C15 /* test-all.cpp */; }; + C6A81BAF170684D300882C15 /* test-all.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6A81BAC1706847900882C15 /* test-all.cpp */; }; C6A81BB2170685A700882C15 /* libMailCore-ios.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C6BA2C191705F4E6003F0E9E /* libMailCore-ios.a */; }; C6A81BB41706891B00882C15 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C6A81BB31706891B00882C15 /* CFNetwork.framework */; }; C6A81BBA17068C0600882C15 /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = C6A81BB717068C0600882C15 /* AppDelegate.mm */; }; @@ -1455,6 +1457,8 @@ 9EF9AB18175F36600027FA3B /* MCOIMAPFolderStatusOperation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPFolderStatusOperation.mm; sourceTree = "<group>"; }; BD49963519FEC6DD000945BC /* ConvertUTF.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ConvertUTF.c; sourceTree = "<group>"; }; BD49963619FEC6DD000945BC /* ConvertUTF.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConvertUTF.h; sourceTree = "<group>"; }; + BD6272961A13FF2A00129AA8 /* test-all-mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "test-all-mac.mm"; sourceTree = "<group>"; }; + BD6272971A13FF2A00129AA8 /* test-all-mac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "test-all-mac.h"; sourceTree = "<group>"; }; BD637139177DFF080094121B /* MCLibetpan.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MCLibetpan.cc; sourceTree = "<group>"; }; BD63713A177DFF080094121B /* MCLibetpan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCLibetpan.h; sourceTree = "<group>"; }; C07AD057D3C8FBDC7AC95733 /* MCOIMAPSession.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MCOIMAPSession.mm; sourceTree = "<group>"; }; @@ -1713,7 +1717,7 @@ C6A81B911706840C00882C15 /* test-ios.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "test-ios.app"; sourceTree = BUILT_PRODUCTS_DIR; }; C6A81B921706840C00882C15 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = Library/Frameworks/UIKit.framework; sourceTree = DEVELOPER_DIR; }; C6A81B951706840C00882C15 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = Library/Frameworks/CoreGraphics.framework; sourceTree = DEVELOPER_DIR; }; - C6A81BAC1706847900882C15 /* test-all.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = "test-all.mm"; sourceTree = "<group>"; }; + C6A81BAC1706847900882C15 /* test-all.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = "test-all.cpp"; sourceTree = "<group>"; }; C6A81BAD1706847900882C15 /* test-all.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "test-all.h"; sourceTree = "<group>"; }; C6A81BB31706891B00882C15 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks/CFNetwork.framework; sourceTree = DEVELOPER_DIR; }; C6A81BB617068C0600882C15 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; }; @@ -2487,8 +2491,10 @@ isa = PBXGroup; children = ( C64EA7AA16A00AF600778456 /* main.mm */, - C6A81BAC1706847900882C15 /* test-all.mm */, + C6A81BAC1706847900882C15 /* test-all.cpp */, C6A81BAD1706847900882C15 /* test-all.h */, + BD6272961A13FF2A00129AA8 /* test-all-mac.mm */, + BD6272971A13FF2A00129AA8 /* test-all-mac.h */, ); name = tests; path = ../tests; @@ -3268,7 +3274,8 @@ buildActionMask = 2147483647; files = ( C64EA7AB16A00AF600778456 /* main.mm in Sources */, - C6A81BAF170684D300882C15 /* test-all.mm in Sources */, + BD6272981A13FF2A00129AA8 /* test-all-mac.mm in Sources */, + C6A81BAF170684D300882C15 /* test-all.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3276,7 +3283,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - C6A81BAE1706847900882C15 /* test-all.mm in Sources */, + C6A81BAE1706847900882C15 /* test-all.cpp in Sources */, + BD6272991A13FF2A00129AA8 /* test-all-mac.mm in Sources */, C6A81BBA17068C0600882C15 /* AppDelegate.mm in Sources */, C6A81BBB17068C0600882C15 /* main.m in Sources */, ); diff --git a/tests/main.mm b/tests/main.mm index 10be4c02..b17fa0f5 100644 --- a/tests/main.mm +++ b/tests/main.mm @@ -9,6 +9,9 @@ #import <Foundation/Foundation.h> #include "test-all.h" +#if __APPLE__ +#include "test-all-mac.h" +#endif int main(int argc, const char * argv[]) { @@ -16,6 +19,7 @@ int main(int argc, const char * argv[]) @autoreleasepool { testAll(); + testAllMac(); } return 0; diff --git a/tests/test-all-mac.h b/tests/test-all-mac.h new file mode 100644 index 00000000..9cb6b13d --- /dev/null +++ b/tests/test-all-mac.h @@ -0,0 +1,16 @@ +// +// test-all-mac.h +// mailcore2 +// +// Created by Hoa Dinh on 11/12/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#ifndef __mailcore2__test_all_mac__ +#define __mailcore2__test_all_mac__ + +#include <MailCore/MailCore.h> + +extern void testAllMac(); + +#endif /* defined(__mailcore2__test_all_mac__) */ diff --git a/tests/test-all-mac.mm b/tests/test-all-mac.mm new file mode 100644 index 00000000..3f0bf8a6 --- /dev/null +++ b/tests/test-all-mac.mm @@ -0,0 +1,79 @@ +// +// test-all-mac.cpp +// mailcore2 +// +// Created by Hoa Dinh on 11/12/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include "test-all-mac.h" + +#include <MailCore/MailCore.h> + +extern "C" { + extern int mailstream_debug; +} + +static mailcore::String * password = NULL; +static mailcore::String * displayName = NULL; +static mailcore::String * email = NULL; + +static void testProviders() { + NSString *filename = [[NSBundle bundleForClass:[MCOMessageBuilder class]] pathForResource:@"providers" ofType:@"json"]; + mailcore::MailProvidersManager::sharedManager()->registerProvidersWithFilename(filename.mco_mcString); + + NSLog(@"Providers: %s", MCUTF8DESC(mailcore::MailProvidersManager::sharedManager()->providerForEmail(MCSTR("email1@gmail.com")))); +} + +void testObjC() +{ + MCOIMAPSession *session = [[MCOIMAPSession alloc] init]; + session.username = [NSString mco_stringWithMCString:email]; + session.password = [NSString mco_stringWithMCString:password]; + session.hostname = @"imap.gmail.com"; + session.port = 993; + session.connectionType = MCOConnectionTypeTLS; + + NSLog(@"check account"); + MCOIMAPOperation *checkOp = [session checkAccountOperation]; + [checkOp start:^(NSError *err) { + NSLog(@"check account done"); + if (err) { + NSLog(@"Oh crap, an error %@", err); + } else { + NSLog(@"CONNECTED"); + NSLog(@"fetch all folders"); + MCOIMAPFetchFoldersOperation *foldersOp = [session fetchAllFoldersOperation]; + [foldersOp start:^(NSError *err, NSArray *folders) { + NSLog(@"fetch all folders done"); + if (err) { + NSLog(@"Oh crap, an error %@", err); + } else { + NSLog(@"Folder %@", folders); + } + }]; + } + }]; + + + [[NSRunLoop currentRunLoop] run]; + [session autorelease]; +} + +void testAllMac() +{ + mailcore::setICUDataDirectory(MCSTR("/usr/local/share/icu")); + + email = MCSTR("email@gmail.com"); + password = MCSTR("MyP4ssw0rd"); + displayName = MCSTR("My Email"); + + mailcore::AutoreleasePool * pool = new mailcore::AutoreleasePool(); + MCLogEnabled = 1; + mailstream_debug = 1; + + //testProviders(); + //testObjC(); + + pool->release(); +} diff --git a/tests/test-all.mm b/tests/test-all.cpp index af66c6b0..2fc09e17 100644 --- a/tests/test-all.mm +++ b/tests/test-all.cpp @@ -9,6 +9,12 @@ #include "test-all.h" #include <MailCore/MailCore.h> +#if __APPLE__ +#include <CoreFoundation/CoreFoundation.h> +#endif +#if __linux__ +#include <glib.h> +#endif extern "C" { extern int mailstream_debug; @@ -17,6 +23,9 @@ extern "C" { static mailcore::String * password = NULL; static mailcore::String * displayName = NULL; static mailcore::String * email = NULL; +#if __linux +static GMainLoop * s_main_loop = NULL; +#endif class TestOperation : public mailcore::Operation { void main() @@ -179,7 +188,11 @@ static void testOperationQueue() op->release(); } - [[NSRunLoop currentRunLoop] run]; +#if __APPLE__ + CFRunLoopRun(); +#elif __linux__ + g_main_loop_run(s_main_loop); +#endif queue->release(); } @@ -214,7 +227,11 @@ static void testAsyncSMTP(mailcore::Data * data) op->setCallback(callback); op->start(); - [[NSRunLoop currentRunLoop] run]; +#if __APPLE__ + CFRunLoopRun(); +#elif __linux__ + g_main_loop_run(s_main_loop); +#endif //smtp->release(); } @@ -259,7 +276,11 @@ static void testAsyncIMAP() op->setImapCallback(callback); op->start(); //MCLog("%s", MCUTF8DESC(messages)); - [[NSRunLoop currentRunLoop] run]; +#if __APPLE__ + CFRunLoopRun(); +#elif __linux__ + g_main_loop_run(s_main_loop); +#endif //session->release(); } @@ -297,7 +318,11 @@ static void testAsyncPOP() //mailcore::Array * messages = session->fetchMessages(&error); //MCLog("%s", MCUTF8DESC(messages)); - [[NSRunLoop currentRunLoop] run]; +#if __APPLE__ + CFRunLoopRun(); +#elif __linux__ + g_main_loop_run(s_main_loop); +#endif } static void testAddresses() @@ -313,13 +338,6 @@ static void testAddresses() MCLog("%s", MCUTF8DESC(str)); } -static void testProviders() { - NSString *filename = [[NSBundle bundleForClass:[MCOMessageBuilder class]] pathForResource:@"providers" ofType:@"json"]; - mailcore::MailProvidersManager::sharedManager()->registerProvidersWithFilename(filename.mco_mcString); - - NSLog(@"Providers: %s", MCUTF8DESC(mailcore::MailProvidersManager::sharedManager()->providerForEmail(MCSTR("email1@gmail.com")))); -} - static void testAttachments() { mailcore::Attachment *attachment = mailcore::Attachment::attachmentWithText(MCSTR("Hello World")); @@ -328,42 +346,6 @@ static void testAttachments() MCLog("%s", MCUTF8DESC(str)); } -void testObjC() -{ - MCOIMAPSession *session = [[MCOIMAPSession alloc] init]; - session.username = [NSString mco_stringWithMCString:email]; - session.password = [NSString mco_stringWithMCString:password]; - session.hostname = @"imap.gmail.com"; - session.port = 993; - session.connectionType = MCOConnectionTypeTLS; - - NSLog(@"check account"); - MCOIMAPOperation *checkOp = [session checkAccountOperation]; - [checkOp start:^(NSError *err) { - NSLog(@"check account done"); - if (err) { - NSLog(@"Oh crap, an error %@", err); - } else { - NSLog(@"CONNECTED"); - NSLog(@"fetch all folders"); - MCOIMAPFetchFoldersOperation *foldersOp = [session fetchAllFoldersOperation]; - [foldersOp start:^(NSError *err, NSArray *folders) { - NSLog(@"fetch all folders done"); - if (err) { - NSLog(@"Oh crap, an error %@", err); - } else { - NSLog(@"Folder %@", folders); - } - }]; - } - }]; - - - [[NSRunLoop currentRunLoop] run]; - [session autorelease]; -} - - void testAll() { mailcore::setICUDataDirectory(MCSTR("/usr/local/share/icu")); @@ -372,6 +354,10 @@ void testAll() password = MCSTR("MyP4ssw0rd"); displayName = MCSTR("My Email"); +#if __linux__ + s_main_loop = g_main_loop_new (NULL, FALSE); +#endif + mailcore::AutoreleasePool * pool = new mailcore::AutoreleasePool(); MCLogEnabled = 1; mailstream_debug = 1; @@ -387,9 +373,6 @@ void testAll() //testAsyncPOP(); //testAddresses(); //testAttachments(); - //testProviders(); - //testObjC(); - - MCLog("pool release"); + pool->release(); } |