aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2014-11-12 13:02:49 -0800
committerGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2014-11-12 13:02:49 -0800
commit48a2b0fc621d7bf04232da3fb0f3af608bfb54b1 (patch)
tree8cfad62972bbd4633cf80315f9fe08dbe451c043 /tests
parente7e05250566e51ebda6c5ae7b42177765948e85f (diff)
separate test for objc and test for c++
Diffstat (limited to 'tests')
-rw-r--r--tests/main.mm4
-rw-r--r--tests/test-all-mac.h16
-rw-r--r--tests/test-all-mac.mm79
-rw-r--r--tests/test-all.cpp (renamed from tests/test-all.mm)85
4 files changed, 133 insertions, 51 deletions
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();
}