From 3ae86373f2238bcd771392f329b52d7b8923d003 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Thu, 16 Jun 2016 22:17:54 +0200 Subject: Central place for test macros --- tests/mailsynctest.h | 21 +-------------------- tests/mailtest.h | 21 +-------------------- tests/testutils.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 40 deletions(-) create mode 100644 tests/testutils.h (limited to 'tests') 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 @@ #include #include - -#define ASYNCCOMPARE(actual, expected) \ -do {\ - if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ - return KAsync::error(1, "Comparison failed.");\ -} while (0) - -#define ASYNCVERIFY(statement) \ -do {\ - if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ - return KAsync::error(1, "Verify failed.");\ -} while (0) - -#define VERIFYEXEC(statement) \ -do {\ - auto result = statement.exec(); \ - result.waitForFinished(); \ - if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ - return;\ -} while (0) +#include "testutils.h" namespace Sink { 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 @@ #include #include - -#define ASYNCCOMPARE(actual, expected) \ -do {\ - if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ - return KAsync::error(1, "Comparison failed.");\ -} while (0) - -#define ASYNCVERIFY(statement) \ -do {\ - if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ - return KAsync::error(1, "Verify failed.");\ -} while (0) - -#define VERIFYEXEC(statement) \ -do {\ - auto result = statement.exec(); \ - result.waitForFinished(); \ - if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ - return;\ -} while (0) +#include "testutils.h" namespace Sink { 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 @@ +/* + * Copyright (C) 2016 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#pragma once + +#define ASYNCCOMPARE(actual, expected) \ +do {\ + if (!QTest::qCompare(actual, expected, #actual, #expected, __FILE__, __LINE__))\ + return KAsync::error(1, "Comparison failed.");\ +} while (0) + +#define ASYNCVERIFY(statement) \ +do {\ + if (!QTest::qVerify((statement), #statement, "", __FILE__, __LINE__))\ + return KAsync::error(1, "Verify failed.");\ +} while (0) + +#define VERIFYEXEC(statement) \ +do {\ + auto result = statement.exec(); \ + result.waitForFinished(); \ + if (!QTest::qVerify(!result.errorCode(), #statement, "", __FILE__, __LINE__))\ + return;\ +} while (0) + +#define VERIFYEXEC_FAIL(statement) \ +do {\ + auto result = statement.exec(); \ + result.waitForFinished(); \ + if (!QTest::qVerify(result.errorCode(), #statement, "", __FILE__, __LINE__))\ + return;\ +} while (0) -- cgit v1.2.3