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

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