| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QTESTRESULT_P_H |
| 5 | #define QTESTRESULT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtTest/qttestglobal.h> |
| 19 | #include <QtCore/qstringfwd.h> |
| 20 | #include <QtCore/private/qglobal_p.h> |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | class QTestResultPrivate; |
| 25 | class QTestData; |
| 26 | |
| 27 | class Q_TESTLIB_EXPORT QTestResult |
| 28 | { |
| 29 | public: |
| 30 | static const char *currentTestObjectName(); |
| 31 | static bool currentTestFailed(); |
| 32 | static QTestData *currentTestData(); |
| 33 | static QTestData *currentGlobalTestData(); |
| 34 | static const char *currentTestFunction(); |
| 35 | static const char *currentDataTag(); |
| 36 | static const char *currentGlobalDataTag(); |
| 37 | static void finishedCurrentTestData(); |
| 38 | static void finishedCurrentTestDataCleanup(); |
| 39 | static void finishedCurrentTestFunction(); |
| 40 | static void reset(); |
| 41 | static void setBlacklistCurrentTest(bool b); |
| 42 | |
| 43 | static void addFailure(const char *message, const char *file = nullptr, int line = 0); |
| 44 | // ### TODO: Remove this overload when deprecated QTest::compare_overload |
| 45 | // is removed. Can't declare it deprecated, because it will unconditionally |
| 46 | // provide warnings. |
| 47 | static bool compare(bool success, const char *failureMsg, |
| 48 | char *val1, char *val2, |
| 49 | const char *actual, const char *expected, |
| 50 | const char *file, int line); |
| 51 | static bool compare(bool success, const char *failureMsg, |
| 52 | double val1, double val2, |
| 53 | const char *actual, const char *expected, |
| 54 | const char *file, int line); |
| 55 | static bool compare(bool success, const char *failureMsg, |
| 56 | float val1, float val2, |
| 57 | const char *actual, const char *expected, |
| 58 | const char *file, int line); |
| 59 | static bool compare(bool success, const char *failureMsg, |
| 60 | int val1, int val2, |
| 61 | const char *actual, const char *expected, |
| 62 | const char *file, int line); |
| 63 | #if QT_POINTER_SIZE == 8 |
| 64 | static bool compare(bool success, const char *failureMsg, |
| 65 | qsizetype val1, qsizetype val2, |
| 66 | const char *actual, const char *expected, |
| 67 | const char *file, int line); |
| 68 | #endif |
| 69 | static bool compare(bool success, const char *failureMsg, |
| 70 | unsigned val1, unsigned val2, |
| 71 | const char *actual, const char *expected, |
| 72 | const char *file, int line); |
| 73 | static bool compare(bool success, const char *failureMsg, |
| 74 | QStringView val1, QStringView val2, |
| 75 | const char *actual, const char *expected, |
| 76 | const char *file, int line); |
| 77 | static bool compare(bool success, const char *failureMsg, |
| 78 | const QLatin1StringView &val1, QStringView val2, |
| 79 | const char *actual, const char *expected, |
| 80 | const char *file, int line); |
| 81 | static bool compare(bool success, const char *failureMsg, |
| 82 | QStringView val1, const QLatin1StringView &val2, |
| 83 | const char *actual, const char *expected, |
| 84 | const char *file, int line); |
| 85 | static bool compare(bool success, const char *failureMsg, |
| 86 | const char *actual, const char *expeceted, |
| 87 | const char *file, int line); |
| 88 | static void setCurrentGlobalTestData(QTestData *data); |
| 89 | static void setCurrentTestData(QTestData *data); |
| 90 | static void setCurrentTestFunction(const char *func); |
| 91 | static void setCurrentTestObject(const char *name); |
| 92 | static void addSkip(const char *message, const char *file, int line); |
| 93 | static bool expectFail(const char *dataIndex, const char *, |
| 94 | QTest::TestFailMode mode, const char *file, int line); |
| 95 | static void fail(const char *message, const char *file, int line); |
| 96 | static bool verify(bool statement, const char *statementStr, const char *, |
| 97 | const char *file, int line); |
| 98 | static void setSkipCurrentTest(bool value); |
| 99 | static bool skipCurrentTest(); |
| 100 | |
| 101 | static void setCurrentAppName(const char *appName); |
| 102 | static const char *currentAppName(); |
| 103 | |
| 104 | static bool reportResult(bool success, const void *lhs, const void *rhs, |
| 105 | const char *(*lhsFormatter)(const void *), |
| 106 | const char *(*rhsFormatter)(const void *), |
| 107 | const char *lhsExpr, const char *rhsExpr, |
| 108 | QTest::ComparisonOperation op, const char *file, int line, |
| 109 | const char *failureMessage = nullptr); |
| 110 | |
| 111 | private: |
| 112 | Q_DISABLE_COPY(QTestResult) |
| 113 | }; |
| 114 | |
| 115 | QT_END_NAMESPACE |
| 116 | |
| 117 | #endif |
| 118 | |