| 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 QTESTLOG_P_H |
| 5 | #define QTESTLOG_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 | |
| 20 | #if defined(Q_OS_DARWIN) |
| 21 | #include <QtCore/private/qcore_mac_p.h> |
| 22 | #endif |
| 23 | |
| 24 | #include <QtCore/qobjectdefs.h> |
| 25 | |
| 26 | QT_BEGIN_NAMESPACE |
| 27 | |
| 28 | class QBenchmarkResult; |
| 29 | class QRegularExpression; |
| 30 | class QTestData; |
| 31 | class QAbstractTestLogger; |
| 32 | |
| 33 | class Q_TESTLIB_EXPORT QTestLog |
| 34 | { |
| 35 | Q_GADGET |
| 36 | public: |
| 37 | QTestLog() = delete; |
| 38 | ~QTestLog() = delete; |
| 39 | Q_DISABLE_COPY_MOVE(QTestLog) |
| 40 | |
| 41 | enum LogMode { |
| 42 | Plain = 0, XML, LightXML, JUnitXML, CSV, TeamCity, TAP |
| 43 | #if defined(QT_USE_APPLE_UNIFIED_LOGGING) |
| 44 | , Apple |
| 45 | #endif |
| 46 | #if defined(HAVE_XCTEST) |
| 47 | , XCTest |
| 48 | #endif |
| 49 | }; |
| 50 | Q_ENUM(LogMode) |
| 51 | |
| 52 | static void enterTestFunction(const char* function); |
| 53 | static void leaveTestFunction(); |
| 54 | |
| 55 | static void enterTestData(QTestData *data); |
| 56 | |
| 57 | static void addPass(const char *msg); |
| 58 | static void addFail(const char *msg, const char *file, int line); |
| 59 | static void addXFail(const char *msg, const char *file, int line); |
| 60 | static void addXPass(const char *msg, const char *file, int line); |
| 61 | static void addBPass(const char *msg); |
| 62 | static void addBFail(const char *msg, const char *file, int line); |
| 63 | static void addBXPass(const char *msg, const char *file, int line); |
| 64 | static void addBXFail(const char *msg, const char *file, int line); |
| 65 | static void addSkip(const char *msg, const char *file, int line); |
| 66 | static void addBenchmarkResult(const QList<QBenchmarkResult> &result) |
| 67 | { return addBenchmarkResults(result: { result }); } |
| 68 | static void addBenchmarkResults(const QList<QBenchmarkResult> &result); |
| 69 | |
| 70 | static void ignoreMessage(QtMsgType type, const char *msg); |
| 71 | #ifndef QT_NO_REGULAREXPRESSION |
| 72 | static void ignoreMessage(QtMsgType type, const QRegularExpression &expression); |
| 73 | #endif |
| 74 | static void failOnWarning(); |
| 75 | static void failOnWarning(const char *msg); |
| 76 | #ifndef QT_NO_REGULAREXPRESSION |
| 77 | static void failOnWarning(const QRegularExpression &expression); |
| 78 | #endif |
| 79 | static int unhandledIgnoreMessages(); |
| 80 | static void printUnhandledIgnoreMessages(); |
| 81 | static void clearIgnoreMessages(); |
| 82 | static void clearFailOnWarnings(); |
| 83 | static void clearCurrentTestState(); |
| 84 | |
| 85 | static void warn(const char *msg, const char *file, int line); |
| 86 | static void info(const char *msg, const char *file, int line); |
| 87 | |
| 88 | static void startLogging(); |
| 89 | static void stopLogging(); |
| 90 | |
| 91 | static void addLogger(LogMode mode, const char *filename); |
| 92 | static void addLogger(std::unique_ptr<QAbstractTestLogger> logger); |
| 93 | |
| 94 | static bool hasLoggers(); |
| 95 | static bool isRepeatSupported(); |
| 96 | static bool loggerUsingStdout(); |
| 97 | |
| 98 | static void setVerboseLevel(int level); |
| 99 | static int verboseLevel(); |
| 100 | |
| 101 | static void setMaxWarnings(int max); |
| 102 | |
| 103 | static void setPrintAvailableTagsMode(); |
| 104 | |
| 105 | static int passCount(); |
| 106 | static int failCount(); |
| 107 | static int skipCount(); |
| 108 | static int blacklistCount(); |
| 109 | static int totalCount(); |
| 110 | |
| 111 | static void resetCounters(); |
| 112 | |
| 113 | static void setInstalledTestCoverage(bool installed); |
| 114 | static bool installedTestCoverage(); |
| 115 | |
| 116 | static qint64 nsecsTotalTime(); |
| 117 | static qreal msecsTotalTime() { return QTestLog::nsecsTotalTime() / 1000000.; } |
| 118 | static qint64 nsecsFunctionTime(); |
| 119 | static qreal msecsFunctionTime() { return QTestLog::nsecsFunctionTime() / 1000000.; } |
| 120 | |
| 121 | private: |
| 122 | static bool printAvailableTags; |
| 123 | }; |
| 124 | |
| 125 | QT_END_NAMESPACE |
| 126 | |
| 127 | #endif |
| 128 | |