| 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 QTestData; |
| 25 | |
| 26 | class Q_TESTLIB_EXPORT QTestResult |
| 27 | { |
| 28 | public: |
| 29 | static const char *currentTestObjectName(); |
| 30 | static bool currentTestFailed(); |
| 31 | static QTestData *currentTestData(); |
| 32 | static QTestData *currentGlobalTestData(); |
| 33 | static const char *currentTestFunction(); |
| 34 | static const char *currentDataTag(); |
| 35 | static const char *currentGlobalDataTag(); |
| 36 | static void finishedCurrentTestData(); |
| 37 | static void finishedCurrentTestDataCleanup(); |
| 38 | static void finishedCurrentTestFunction(); |
| 39 | static void reset(); |
| 40 | static void setBlacklistCurrentTest(bool b); |
| 41 | |
| 42 | static void addFailure(const char *message, const char *file = nullptr, int line = 0); |
| 43 | // ### TODO: Remove this overload when deprecated QTest::compare_overload |
| 44 | // is removed. Can't declare it deprecated, because it will unconditionally |
| 45 | // provide warnings. |
| 46 | static bool compare(bool success, const char *failureMsg, |
| 47 | char *val1, char *val2, |
| 48 | const char *actual, const char *expected, |
| 49 | const char *file, int line); |
| 50 | static bool compare(bool success, const char *failureMsg, |
| 51 | double val1, double val2, |
| 52 | const char *actual, const char *expected, |
| 53 | const char *file, int line); |
| 54 | static bool compare(bool success, const char *failureMsg, |
| 55 | float val1, float val2, |
| 56 | const char *actual, const char *expected, |
| 57 | const char *file, int line); |
| 58 | static bool compare(bool success, const char *failureMsg, |
| 59 | int val1, int val2, |
| 60 | const char *actual, const char *expected, |
| 61 | const char *file, int line); |
| 62 | #if QT_POINTER_SIZE == 8 |
| 63 | static bool compare(bool success, const char *failureMsg, |
| 64 | qsizetype val1, qsizetype val2, |
| 65 | const char *actual, const char *expected, |
| 66 | const char *file, int line); |
| 67 | #endif |
| 68 | static bool compare(bool success, const char *failureMsg, |
| 69 | unsigned val1, unsigned val2, |
| 70 | const char *actual, const char *expected, |
| 71 | const char *file, int line); |
| 72 | static bool compare(bool success, const char *failureMsg, |
| 73 | QStringView val1, QStringView val2, |
| 74 | const char *actual, const char *expected, |
| 75 | const char *file, int line); |
| 76 | static bool compare(bool success, const char *failureMsg, |
| 77 | const QLatin1StringView &val1, QStringView val2, |
| 78 | const char *actual, const char *expected, |
| 79 | const char *file, int line); |
| 80 | static bool compare(bool success, const char *failureMsg, |
| 81 | QStringView val1, const QLatin1StringView &val2, |
| 82 | const char *actual, const char *expected, |
| 83 | const char *file, int line); |
| 84 | static bool compare(bool success, const char *failureMsg, |
| 85 | const char *actual, const char *expeceted, |
| 86 | const char *file, int line); |
| 87 | static void setCurrentGlobalTestData(QTestData *data); |
| 88 | static void setCurrentTestData(QTestData *data); |
| 89 | static void setCurrentTestFunction(const char *func); |
| 90 | static void setCurrentTestObject(const char *name); |
| 91 | static void addSkip(const char *message, const char *file, int line); |
| 92 | static bool expectFail(const char *dataIndex, const char *, |
| 93 | QTest::TestFailMode mode, const char *file, int line); |
| 94 | static void fail(const char *message, const char *file, int line); |
| 95 | static bool verify(bool statement, const char *statementStr, const char *, |
| 96 | const char *file, int line); |
| 97 | static void setSkipCurrentTest(bool value); |
| 98 | static bool skipCurrentTest(); |
| 99 | |
| 100 | static void setCurrentAppName(const char *appName); |
| 101 | static const char *currentAppName(); |
| 102 | |
| 103 | static bool reportResult(bool success, const void *lhs, const void *rhs, |
| 104 | const char *(*lhsFormatter)(const void *), |
| 105 | const char *(*rhsFormatter)(const void *), |
| 106 | const char *lhsExpr, const char *rhsExpr, |
| 107 | QTest::ComparisonOperation op, const char *file, int line, |
| 108 | const char *failureMessage = nullptr); |
| 109 | |
| 110 | static bool report3WayResult(bool success, |
| 111 | const char *failureMessage, |
| 112 | const void *lhs, const void *rhs, |
| 113 | const char *(*lhsFormatter)(const void *), |
| 114 | const char *(*rhsFormatter)(const void *), |
| 115 | const char *lhsExpression, const char *rhsExpression, |
| 116 | const char *(*actualOrderFormatter)(const void *), |
| 117 | const char *(*expectedOrderFormatter)(const void *), |
| 118 | const void *actualOrder, const void *expectedOrder, |
| 119 | const char *expectedExpression, |
| 120 | const char *file, int line); |
| 121 | |
| 122 | private: |
| 123 | Q_DISABLE_COPY(QTestResult) |
| 124 | }; |
| 125 | |
| 126 | QT_END_NAMESPACE |
| 127 | |
| 128 | #endif |
| 129 | |