summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-06-16 22:17:54 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-06-16 22:17:54 +0200
commit3ae86373f2238bcd771392f329b52d7b8923d003 (patch)
tree03a9648d64081de0457d9ec94e41774ca662cf00
parent9d727c366ed709fd15d2358800f57e927fd18ed2 (diff)
downloadsink-3ae86373f2238bcd771392f329b52d7b8923d003.tar.gz
sink-3ae86373f2238bcd771392f329b52d7b8923d003.zip
Central place for test macros
-rw-r--r--examples/imapresource/tests/imapserverproxytest.cpp29
-rw-r--r--tests/mailsynctest.h21
-rw-r--r--tests/mailtest.h21
-rw-r--r--tests/testutils.h47
4 files changed, 50 insertions, 68 deletions
diff --git a/examples/imapresource/tests/imapserverproxytest.cpp b/examples/imapresource/tests/imapserverproxytest.cpp
index 3761dac..e32298c 100644
--- a/examples/imapresource/tests/imapserverproxytest.cpp
+++ b/examples/imapresource/tests/imapserverproxytest.cpp
@@ -7,34 +7,7 @@
7 7
8#include "log.h" 8#include "log.h"
9#include "test.h" 9#include "test.h"
10 10#include "tests/testutils.h"
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 11
39using namespace Imap; 12using namespace Imap;
40 13
diff --git a/tests/mailsynctest.h b/tests/mailsynctest.h
index ec40f33..a21335b 100644
--- a/tests/mailsynctest.h
+++ b/tests/mailsynctest.h
@@ -22,26 +22,7 @@
22#include <QByteArray> 22#include <QByteArray>
23 23
24#include <applicationdomaintype.h> 24#include <applicationdomaintype.h>
25 25#include "testutils.h"
26#define ASYNCCOMPARE(actual, expected) \
27do {\
28 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
29 return KAsync::error<void>(1, "Comparison failed.");\
30} while (0)
31
32#define ASYNCVERIFY(statement) \
33do {\
34 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
35 return KAsync::error<void>(1, "Verify failed.");\
36} while (0)
37
38#define VERIFYEXEC(statement) \
39do {\
40 auto result = statement.exec(); \
41 result.waitForFinished(); \
42 if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\
43 return;\
44} while (0)
45 26
46namespace Sink { 27namespace Sink {
47 28
diff --git a/tests/mailtest.h b/tests/mailtest.h
index 16d5d73..362e044 100644
--- a/tests/mailtest.h
+++ b/tests/mailtest.h
@@ -22,26 +22,7 @@
22#include <QByteArray> 22#include <QByteArray>
23 23
24#include <applicationdomaintype.h> 24#include <applicationdomaintype.h>
25 25#include "testutils.h"
26#define ASYNCCOMPARE(actual, expected) \
27do {\
28 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
29 return KAsync::error<void>(1, "Comparison failed.");\
30} while (0)
31
32#define ASYNCVERIFY(statement) \
33do {\
34 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
35 return KAsync::error<void>(1, "Verify failed.");\
36} while (0)
37
38#define VERIFYEXEC(statement) \
39do {\
40 auto result = statement.exec(); \
41 result.waitForFinished(); \
42 if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\
43 return;\
44} while (0)
45 26
46namespace Sink { 27namespace Sink {
47 28
diff --git a/tests/testutils.h b/tests/testutils.h
new file mode 100644
index 0000000..f89da38
--- /dev/null
+++ b/tests/testutils.h
@@ -0,0 +1,47 @@
1/*
2 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19#pragma once
20
21#define ASYNCCOMPARE(actual, expected) \
22do {\
23 if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\
24 return KAsync::error<void>(1, "Comparison failed.");\
25} while (0)
26
27#define ASYNCVERIFY(statement) \
28do {\
29 if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\
30 return KAsync::error<void>(1, "Verify failed.");\
31} while (0)
32
33#define VERIFYEXEC(statement) \
34do {\
35 auto result = statement.exec(); \
36 result.waitForFinished(); \
37 if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\
38 return;\
39} while (0)
40
41#define VERIFYEXEC_FAIL(statement) \
42do {\
43 auto result = statement.exec(); \
44 result.waitForFinished(); \
45 if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\
46 return;\
47} while (0)