summaryrefslogtreecommitdiffstats
path: root/examples/imapresource/tests/imapserverproxytest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-22 14:39:47 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-05-22 14:39:47 +0200
commit893c601d325c3f02ba29869baeb90c3f0a890005 (patch)
treec8819f911faedc59f4718e5b58bb586f9ada93e8 /examples/imapresource/tests/imapserverproxytest.cpp
parentacd2902aaecaba864c5673adead98e59222e0fc9 (diff)
downloadsink-893c601d325c3f02ba29869baeb90c3f0a890005.tar.gz
sink-893c601d325c3f02ba29869baeb90c3f0a890005.zip
ImapServerProxyTest
Diffstat (limited to 'examples/imapresource/tests/imapserverproxytest.cpp')
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
new file mode 100644
index 0000000..d13a937
--- /dev/null
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -0,0 +1,97 @@
1#include <QtTest>
2
3#include <QString>
4#include <KMime/Message>
5
6#include "../imapserverproxy.h"
7
8#include "log.h"
9#include "test.h"
10
11#define ASYNCCOMPARE(actual, expected) \
12do {\
13 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
14 return KAsync::error<void>(1, "Comparison failed.");\
15} while (0)
16
17#define ASYNCVERIFY(statement) \
18do {\
19 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
20 return KAsync::error<void>(1, "Verify failed.");\
21} while (0)
22
23#define VERIFYEXEC(statement) \
24do {\
25 auto result = statement.exec(); \
26 result.waitForFinished(); \
27 if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\
28 return;\
29} while (0)
30
31#define VERIFYEXEC_FAIL(statement) \
32do {\
33 auto result = statement.exec(); \
34 result.waitForFinished(); \
35 if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\
36 return;\
37} while (0)
38
39/**
40 */
41class ImapServerProxyTest : public QObject
42{
43 Q_OBJECT
44
45 QTemporaryDir tempDir;
46 QString targetPath;
47private slots:
48 void initTestCase()
49 {
50 Sink::Log::setDebugOutputLevel(Sink::Log::Trace);
51 system("resetmailbox.sh");
52 }
53
54 void cleanup()
55 {
56 }
57
58 void init()
59 {
60 qDebug();
61 qDebug() << "-----------------------------------------";
62 qDebug();
63 }
64
65 void testLogin()
66 {
67 ImapServerProxy imap("localhost", 993);
68 VERIFYEXEC(imap.login("doe", "doe"));
69 }
70
71 void testLoginFailure()
72 {
73 ImapServerProxy imap("foobar", 993);
74 VERIFYEXEC_FAIL(imap.login("doe", "doe"));
75 }
76
77 void testFetchFolders()
78 {
79 ImapServerProxy imap("localhost", 993);
80 auto future = imap.fetchFolders([](const QStringList &){});
81 future.waitForFinished();
82 QVERIFY(!future.errorCode());
83 }
84
85 void testFetchFoldersFailure()
86 {
87 ImapServerProxy imap("foobar", 993);
88 auto future = imap.fetchFolders([](const QStringList &){});
89 auto future2 = future;
90 future2.waitForFinished();
91 QVERIFY(future2.errorCode());
92 }
93
94};
95
96QTEST_MAIN(ImapServerProxyTest)
97#include "imapserverproxytest.moc"