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
26QT_BEGIN_NAMESPACE
27
28class QBenchmarkResult;
29class QRegularExpression;
30class QTestData;
31class QAbstractTestLogger;
32
33class Q_TESTLIB_EXPORT QTestLog
34{
35 Q_GADGET
36public:
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(const char *msg);
75#ifndef QT_NO_REGULAREXPRESSION
76 static void failOnWarning(const QRegularExpression &expression);
77#endif
78 static int unhandledIgnoreMessages();
79 static void printUnhandledIgnoreMessages();
80 static void clearIgnoreMessages();
81 static void clearFailOnWarnings();
82 static void clearCurrentTestState();
83
84 static void warn(const char *msg, const char *file, int line);
85 static void info(const char *msg, const char *file, int line);
86
87 static void startLogging();
88 static void stopLogging();
89
90 static void addLogger(LogMode mode, const char *filename);
91 static void addLogger(QAbstractTestLogger *logger);
92
93 static bool hasLoggers();
94 static bool loggerUsingStdout();
95
96 static void setVerboseLevel(int level);
97 static int verboseLevel();
98
99 static void setMaxWarnings(int max);
100
101 static void setPrintAvailableTagsMode();
102
103 static int passCount();
104 static int failCount();
105 static int skipCount();
106 static int blacklistCount();
107 static int totalCount();
108
109 static void resetCounters();
110
111 static void setInstalledTestCoverage(bool installed);
112 static bool installedTestCoverage();
113
114 static qint64 nsecsTotalTime();
115 static qreal msecsTotalTime() { return QTestLog::nsecsTotalTime() / 1000000.; }
116 static qint64 nsecsFunctionTime();
117 static qreal msecsFunctionTime() { return QTestLog::nsecsFunctionTime() / 1000000.; }
118
119private:
120 static bool printAvailableTags;
121};
122
123QT_END_NAMESPACE
124
125#endif
126

source code of qtbase/src/testlib/qtestlog_p.h