diff options
-rw-r--r-- | src/testlib/qtestcase.cpp | 6 | ||||
-rw-r--r-- | src/testlib/qtestcase.h | 4 | ||||
-rw-r--r-- | src/testlib/qtestresult.cpp | 17 | ||||
-rw-r--r-- | src/testlib/qtestresult_p.h | 3 | ||||
-rw-r--r-- | tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp | 3 | ||||
-rw-r--r-- | tests/auto/testlib/selftests/xunit/tst_xunit.cpp | 4 |
6 files changed, 21 insertions, 16 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index c08ad58d75..eca5bbb033 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2020 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2016 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -2019,9 +2019,9 @@ int QTest::qExec(QObject *testObject, const QStringList &arguments) /*! \internal */ -void QTest::qFail(const char *statementStr, const char *file, int line) +void QTest::qFail(const char *message, const char *file, int line) { - QTestResult::addFailure(statementStr, file, line); + QTestResult::fail(message, file, line); } /*! \internal diff --git a/src/testlib/qtestcase.h b/src/testlib/qtestcase.h index 25385b327a..158fce4e3d 100644 --- a/src/testlib/qtestcase.h +++ b/src/testlib/qtestcase.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtTest module of the Qt Toolkit. @@ -310,7 +310,7 @@ namespace QTest Q_TESTLIB_EXPORT bool qVerify(bool statement, const char *statementStr, const char *description, const char *file, int line); - Q_TESTLIB_EXPORT void qFail(const char *statementStr, const char *file, int line); + Q_TESTLIB_EXPORT void qFail(const char *message, const char *file, int line); Q_TESTLIB_EXPORT void qSkip(const char *message, const char *file, int line); Q_TESTLIB_EXPORT bool qExpectFail(const char *dataIndex, const char *comment, TestFailMode mode, const char *file, int line); diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index ee038d3704..96c7af29d5 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtTest module of the Qt Toolkit. @@ -237,7 +237,6 @@ bool QTestResult::expectFail(const char *dataIndex, const char *comment, if (QTest::expectFailMode) { delete[] comment; - clearExpectFail(); addFailure("Already expecting a fail", file, line); return false; } @@ -278,6 +277,11 @@ static bool checkStatement(bool statement, const char *msg, const char *file, in return false; } +void QTestResult::fail(const char *msg, const char *file, int line) +{ + checkStatement(false, msg, file, line); +} + bool QTestResult::verify(bool statement, const char *statementStr, const char *description, const char *file, int line) { @@ -290,10 +294,11 @@ bool QTestResult::verify(bool statement, const char *statementStr, QTestLog::info(msg, file, line); } - if (!statement && !QTest::expectFailMode) - qsnprintf(msg, 1024, "'%s' returned FALSE. (%s)", statementStr, description ? description : ""); - else if (statement && QTest::expectFailMode) - qsnprintf(msg, 1024, "'%s' returned TRUE unexpectedly. (%s)", statementStr, description ? description : ""); + if (statement == !!QTest::expectFailMode) { + qsnprintf(msg, 1024, + statement ? "'%s' returned TRUE unexpectedly. (%s)" : "'%s' returned FALSE. (%s)", + statementStr, description ? description : ""); + } return checkStatement(statement, msg, file, line); } diff --git a/src/testlib/qtestresult_p.h b/src/testlib/qtestresult_p.h index 4da66885df..05ae764722 100644 --- a/src/testlib/qtestresult_p.h +++ b/src/testlib/qtestresult_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtTest module of the Qt Toolkit. @@ -123,6 +123,7 @@ public: static void addSkip(const char *message, const char *file, int line); static bool expectFail(const char *dataIndex, const char *comment, QTest::TestFailMode mode, const char *file, int line); + static void fail(const char *message, const char *file, int line); static bool verify(bool statement, const char *statementStr, const char *extraInfo, const char *file, int line); static void setSkipCurrentTest(bool value); diff --git a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp index 22f5f3f4c7..1239e70ee3 100644 --- a/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp +++ b/tests/auto/network/socket/qudpsocket/tst_qudpsocket.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Copyright (C) 2017 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** @@ -442,7 +442,6 @@ void tst_QUdpSocket::broadcasting() QEXPECT_FAIL("", "Broadcasting to 255.255.255.255 does not work on FreeBSD", Abort); - QVERIFY(false); // seems that QFAIL() doesn't respect the QEXPECT_FAIL() :/ #endif QFAIL("Network operation timed out"); } diff --git a/tests/auto/testlib/selftests/xunit/tst_xunit.cpp b/tests/auto/testlib/selftests/xunit/tst_xunit.cpp index 508f8cd024..d620784e41 100644 --- a/tests/auto/testlib/selftests/xunit/tst_xunit.cpp +++ b/tests/auto/testlib/selftests/xunit/tst_xunit.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2021 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. @@ -88,7 +88,7 @@ void tst_Xunit::testFunc5() void tst_Xunit::testFunc6() { QEXPECT_FAIL("", "this failure is also expected", Abort); - QVERIFY(false); + QFAIL("This is a deliberate failure"); } void tst_Xunit::testFunc7() |