Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtestresult_p.h
Go to the documentation of this file.
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
23
24class QTestData;
25
26class Q_TESTLIB_EXPORT QTestResult
27{
28public:
29 // Locks the parts of the current test's identifier for reading, from any thread. The
30 // strings below are only valid while the locker lives, so keep the scope short. Never
31 // log while holding one: the loggers take this lock too.
32 class IdentifierLocker
33 {
34 public:
35 Q_NODISCARD_CTOR IdentifierLocker();
36 ~IdentifierLocker();
37
38 const char *objectName() const;
39 const char *testFunction() const;
40 const char *dataTag() const;
41 const char *globalDataTag() const;
42
43 private:
44 Q_DISABLE_COPY_MOVE(IdentifierLocker)
45 };
46
47 static const char *currentTestObjectName();
48 static bool currentTestFailed();
49 static QTestData *currentTestData();
50 static QTestData *currentGlobalTestData();
51 static const char *currentTestFunction();
52 static const char *currentDataTag();
53 static const char *currentGlobalDataTag();
54 static void finishedCurrentTestData();
55 static void finishedCurrentTestDataCleanup();
56 static void finishedCurrentTestFunction();
57 static void reset();
58 static void setBlacklistCurrentTest(bool b);
59
60 static void addFailure(const char *message, const char *file = nullptr, int line = 0);
61 // ### TODO: Remove this overload when deprecated QTest::compare_overload
62 // is removed. Can't declare it deprecated, because it will unconditionally
63 // provide warnings.
64 static bool compare(bool success, const char *failureMsg,
65 char *val1, char *val2,
66 const char *actual, const char *expected,
67 const char *file, int line);
68 static bool compare(bool success, const char *failureMsg,
69 double val1, double val2,
70 const char *actual, const char *expected,
71 const char *file, int line);
72 static bool compare(bool success, const char *failureMsg,
73 float val1, float val2,
74 const char *actual, const char *expected,
75 const char *file, int line);
76 static bool compare(bool success, const char *failureMsg,
77 int val1, int val2,
78 const char *actual, const char *expected,
79 const char *file, int line);
80#if QT_POINTER_SIZE == 8
81 static bool compare(bool success, const char *failureMsg,
82 qsizetype val1, qsizetype val2,
83 const char *actual, const char *expected,
84 const char *file, int line);
85#endif
86 static bool compare(bool success, const char *failureMsg,
87 unsigned val1, unsigned val2,
88 const char *actual, const char *expected,
89 const char *file, int line);
90 static bool compare(bool success, const char *failureMsg,
91 QStringView val1, QStringView val2,
92 const char *actual, const char *expected,
93 const char *file, int line);
94 static bool compare(bool success, const char *failureMsg,
95 const QLatin1StringView &val1, QStringView val2,
96 const char *actual, const char *expected,
97 const char *file, int line);
98 static bool compare(bool success, const char *failureMsg,
99 QStringView val1, const QLatin1StringView &val2,
100 const char *actual, const char *expected,
101 const char *file, int line);
102 static bool compare(bool success, const char *failureMsg,
103 const char *actual, const char *expeceted,
104 const char *file, int line);
105 static void setCurrentGlobalTestData(QTestData *data);
106 static void setCurrentTestData(QTestData *data);
107 static void setCurrentTestFunction(const char *func);
108 static void setCurrentTestObject(const char *name);
109 static void addSkip(const char *message, const char *file, int line);
110 static bool expectFail(const char *dataIndex, const char *comment,
111 QTest::TestFailMode mode, const char *file, int line);
112 static void fail(const char *message, const char *file, int line);
113 static bool verify(bool statement, const char *statementStr, const char *extraInfo,
114 const char *file, int line);
115 static void setSkipCurrentTest(bool value);
116 static bool skipCurrentTest();
117
118 static void setCurrentAppName(const char *appName);
119 static const char *currentAppName();
120
121 static bool reportResult(bool success, const void *lhs, const void *rhs,
122 const char *(*lhsFormatter)(const void *),
123 const char *(*rhsFormatter)(const void *),
124 const char *lhsExpr, const char *rhsExpr,
125 QTest::ComparisonOperation op, const char *file, int line,
126 const char *failureMessage = nullptr);
127
128 static bool report3WayResult(bool success,
129 const char *failureMessage,
130 const void *lhs, const void *rhs,
131 const char *(*lhsFormatter)(const void *),
132 const char *(*rhsFormatter)(const void *),
133 const char *lhsExpression, const char *rhsExpression,
134 const char *(*actualOrderFormatter)(const void *),
135 const char *(*expectedOrderFormatter)(const void *),
136 const void *actualOrder, const void *expectedOrder,
137 const char *expectedExpression,
138 const char *file, int line);
139
140private:
141 Q_DISABLE_COPY(QTestResult)
142};
143
144QT_END_NAMESPACE
145
146#endif
QBenchmarkResult(const QBenchmarkContext &context, QBenchmarkMeasurerBase::Measurement m, const int iterations, bool setByMacro)
QBenchmarkContext context
bool operator<(const QBenchmarkResult &other) const
QBenchmarkMeasurerBase::Measurement measurement
QBenchmarkResult()=default
\inmodule QtTest
Combined button and popup list for selecting options.
void generateTestIdentifier(QTestCharBuffer *identifier, int parts)
bool appendCharBuffer(QTestCharBuffer *accumulator, const QTestCharBuffer &more)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
QList< QBenchmarkMeasurerBase::Measurement > endBenchmarkMeasurement()
void setIterationCountHint(int count)
void setIterationCount(int count)
void beginBenchmarkMeasurement()
int iterationCount() noexcept
Q_DECLARE_TYPEINFO(QBenchmarkContext, Q_RELOCATABLE_TYPE)
Q_DECLARE_TYPEINFO(QBenchmarkResult, Q_RELOCATABLE_TYPE)