Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qabstracttestlogger_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 QABSTRACTTESTLOGGER_P_H
5#define QABSTRACTTESTLOGGER_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/private/qglobal_p.h>
20#include <QtCore/qbytearrayalgorithms.h>
21
22#include <stdio.h>
23#include <stdlib.h>
24
26
28class QTestData;
29
30class Q_TESTLIB_EXPORT QAbstractTestLogger
31{
32 Q_DISABLE_COPY_MOVE(QAbstractTestLogger)
33public:
45
52 // testlib's internal messages:
54 Warn
55 };
56
57 QAbstractTestLogger(const char *filename);
58 virtual ~QAbstractTestLogger();
59
60 virtual void startLogging();
61 virtual void stopLogging();
62
63 virtual void enterTestFunction(const char *function) = 0;
64 virtual void leaveTestFunction() = 0;
65
66 virtual void enterTestData(QTestData *) {}
67
68 virtual void addIncident(IncidentTypes type, const char *description,
69 const char *file = nullptr, int line = 0) = 0;
70 virtual void addBenchmarkResult(const QBenchmarkResult &result) = 0;
71 virtual void addBenchmarkResults(const QList<QBenchmarkResult> &result);
72
73 virtual void addMessage(QtMsgType, const QMessageLogContext &,
74 const QString &);
75
77 const char *file = nullptr, int line = 0) = 0;
78
79 virtual bool isRepeatSupported() const;
80
81 bool isLoggingToStdout() const;
82
83 void outputString(const char *msg);
84
85protected:
86 void filterUnprintable(char *str) const;
87 FILE *stream;
88};
89
91{
92 enum { InitialSize = 512 };
93
94 inline QTestCharBuffer() : buf(staticBuf)
95 {
96 staticBuf[0] = '\0';
97 }
98
99 Q_DISABLE_COPY_MOVE(QTestCharBuffer)
100
102 {
103 if (buf != staticBuf)
104 free(buf);
105 }
106
107 inline char *data()
108 {
109 return buf;
110 }
111
112 inline char **buffer()
113 {
114 return &buf;
115 }
116
117 inline const char* constData() const
118 {
119 return buf;
120 }
121
122 inline int size() const
123 {
124 return _size;
125 }
126
127 bool reset(int newSize, bool copy = false)
128 {
129 char *newBuf = nullptr;
130 if (buf == staticBuf) {
131 // if we point to our internal buffer, we need to malloc first
132 newBuf = reinterpret_cast<char *>(malloc(newSize));
133 if (copy && newBuf)
134 qstrncpy(newBuf, buf, _size);
135 } else {
136 // if we already malloc'ed, just realloc
137 newBuf = reinterpret_cast<char *>(realloc(buf, newSize));
138 }
139
140 // if the allocation went wrong (newBuf == 0), we leave the object as is
141 if (!newBuf)
142 return false;
143
144 _size = newSize;
145 buf = newBuf;
146 return true;
147 }
148
149 bool resize(int newSize) {
150 return newSize <= _size || reset(newSize, true);
151 }
152
153 void clear() { buf[0] = '\0'; }
154 bool isEmpty() { return buf[0] == '\0'; }
155
156private:
157 int _size = InitialSize;
158 char* buf;
159 char staticBuf[InitialSize];
160};
161
162namespace QTest
163{
164 int qt_asprintf(QTestCharBuffer *buf, const char *format, ...);
165}
166
167namespace QTestPrivate
168{
169 enum IdentifierPart { TestObject = 0x1, TestFunction = 0x2, TestDataTag = 0x4, AllParts = 0xFFFF };
170 void Q_TESTLIB_EXPORT generateTestIdentifier(QTestCharBuffer *identifier, int parts = AllParts);
171 bool appendCharBuffer(QTestCharBuffer *accumulator, const QTestCharBuffer &more);
172}
173
175
176#endif
Base class for test loggers.
virtual void addBenchmarkResult(const QBenchmarkResult &result)=0
This virtual method is called after a benchmark has been run enough times to produce usable data.
virtual void leaveTestFunction()=0
This virtual method is called after a test function has completed, to match \l enterTestFunction().
IncidentTypes
\value Pass The test ran to completion successfully.
virtual void enterTestData(QTestData *)
This virtual method is called before and after each call to a test function.
MessageTypes
The members whose names begin with Q describe messages that originate in calls, by the test or code u...
virtual void enterTestFunction(const char *function)=0
This virtual method is called before each test function is invoked.
virtual void addMessage(MessageTypes type, const QString &message, const char *file=nullptr, int line=0)=0
This is an overloaded member function, provided for convenience. It differs from the above function o...
virtual void addIncident(IncidentTypes type, const char *description, const char *file=nullptr, int line=0)=0
This virtual method is called when an event occurs that relates to the resolution of the test.
\inmodule QtCore
Definition qlogging.h:42
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QString str
[2]
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,...)
static jboolean copy(JNIEnv *, jobject)
Q_CORE_EXPORT char * qstrncpy(char *dst, const char *src, size_t len)
QtMsgType
Definition qlogging.h:29
GLenum type
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum format
GLboolean reset
GLuint64EXT * result
[6]
QFile file
[0]
bool reset(int newSize, bool copy=false)
const char * constData() const
bool resize(int newSize)