4#include <QtTest/private/qtestresult_p.h>
5#include <QtTest/qtestassert.h>
6#include <QtTest/private/qtestlog_p.h>
7#include <QtTest/private/qplaintestlogger_p.h>
8#include <QtTest/private/qbenchmark_p.h>
9#include <QtTest/private/qbenchmarkmetric_p.h>
11#include <QtCore/private/qlogging_p.h>
19#include <QtCore/QByteArray>
20#include <QtCore/qmath.h>
21#include <QtCore/QLibraryInfo>
24# include <android/log.h>
36static const char multiplePrefixes[] =
"\0kMGTPE";
37static const char submultiplePrefixes[] =
"afpnum";
39template <
int N>
struct FixedBufString
41 static constexpr size_t MaxSize =
N;
43 std::array<char, N + 2>
buf;
54 operator const char *()
const
67 template <
typename... Args>
void appendf(
const char *
format, Args &&...
args)
71 std::forward<Args>(
args)...);
74 template <
int Power = 1000>
void appendScaled(
qreal value,
const char *unit)
79 if (
v < 1 && Power == 1000) {
80 const char *prefixes = submultiplePrefixes;
81 ratio =
qreal(std::atto::num) / std::atto::den;
82 while (
value * ratio > 1000 && *prefixes) {
86 prefix[0] = *prefixes;
88 const char *prefixes = multiplePrefixes;
90 while (
value > 1000 * ratio) {
94 prefix[0] = *prefixes;
99 appendf(
", %.3g %s%s",
value, prefix, unit);
128 Q_UNREACHABLE_RETURN(
nullptr);
154 Q_UNREACHABLE_RETURN(
nullptr);
157 template <
typename T>
184 afterDecimalPoint.
remove(0, beforeDecimalPoint.
size() + 1);
186 int beforeUse =
qMin(beforeDecimalPoint.
size(), significantDigits);
187 int beforeRemove = beforeDecimalPoint.
size() - beforeUse;
190 beforeDecimalPoint.
chop(beforeRemove);
191 for (
int i = 0;
i < beforeRemove; ++
i) {
192 beforeDecimalPoint.
append(u
'0');
195 int afterUse = significantDigits - beforeUse;
198 if (beforeDecimalPoint ==
"0" && !afterDecimalPoint.
isEmpty()) {
202 while (
i < afterDecimalPoint.
size() && afterDecimalPoint.
at(
i) ==
'0')
208 int afterRemove = afterDecimalPoint.
size() - afterUse;
209 afterDecimalPoint.
chop(afterRemove);
211 char separator =
',';
212 char decimalPoint =
'.';
216 for (
int i = beforeDecimalPoint.
size() -1;
i >= 1; --
i) {
218 beforeDecimalPoint.
insert(
i, separator);
222 print = beforeDecimalPoint;
224 print.
append(decimalPoint);
226 print += afterDecimalPoint;
242void QPlainTestLogger::outputMessage(
const char *
str)
247 OutputDebugStringA(
str);
250#elif defined(Q_OS_ANDROID)
251 __android_log_write(ANDROID_LOG_INFO,
"QTestLib",
str);
256void QPlainTestLogger::printMessage(MessageSource
source,
const char *
type,
const char *msg,
266 constexpr const char *INCIDENT_LOCATION_STR =
"\n%s(%d) : failure location";
267 constexpr const char *OTHER_LOCATION_STR =
"\n%s(%d) : message location";
269 constexpr const char *INCIDENT_LOCATION_STR =
"\n Loc: [%s(%d)]";
270 constexpr const char *OTHER_LOCATION_STR = INCIDENT_LOCATION_STR;
275 case MessageSource::Incident:
278 case MessageSource::Other:
284 const char *msgFiller = msg[0] ?
" " :
"";
288 type, testIdentifier.
data(), msgFiller, msg, messageLocation.
data());
294 outputMessage(messagePrefix.
data());
299 FixedBufString<1022>
buf;
304 buf.appendf(
":\"%s\":\n",
tag.data());
312 using namespace std::chrono;
313 FixedBufString<1022>
buf;
316 if (
result.measurement.metric == metric)
317 return result.measurement.value;
323 qreal executionTime = 0;
325 executionTime = *
ns / (1000 * 1000 * 1000);
327 executionTime = *ms / 1000;
336 unitText,
result.setByMacro ?
" per iteration" :
"");
338 switch (
result.measurement.metric) {
341 buf.appendScaled<1000>(
result.measurement.value,
"bit/s");
345 buf.appendScaled<1024>(
result.measurement.value,
"B/s");
351 buf.appendScaled(
result.measurement.value / executionTime,
"Hz");
356 buf.appendf(
", %.3f instr/cycle",
result.measurement.value / *cycles);
384 buf.appendScaled(
result.measurement.value / executionTime,
"/sec");
395 buf.appendf(
" (total: %s, iterations: %d)\n",
419 "********* Start testing of %s *********\n"
432 qsnprintf(
buf,
sizeof(
buf),
"Totals: %d passed, %d failed, %d skipped, %d blacklisted, %dms\n",
437 "Totals: %d passed, %d failed, %d skipped, %d blacklisted, %dms\n"
438 "********* Finished testing of %s *********\n",
477 printBenchmarkResults(
results);
Base class for test loggers.
void outputString(const char *msg)
Convenience method to write msg to the output stream.
IncidentTypes
\value Pass The test ran to completion successfully.
virtual void startLogging()
Called before the start of a test run.
virtual void addMessage(QtMsgType, const QMessageLogContext &, const QString &)
This is an overloaded member function, provided for convenience. It differs from the above function o...
MessageTypes
The members whose names begin with Q describe messages that originate in calls, by the test or code u...
virtual void stopLogging()
Called after the end of a test run.
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
void chop(qsizetype n)
Removes n bytes from the end of the byte array.
char at(qsizetype i) const
Returns the byte at index position i in the byte array.
QByteArray & insert(qsizetype i, QByteArrayView data)
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
static QByteArray number(int, int base=10)
Returns a byte-array representing the whole number n as text.
QByteArray & remove(qsizetype index, qsizetype len)
Removes len bytes from the array, starting at index position pos, and returns a reference to the arra...
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static const char * build() noexcept
Returns a string describing how this version of Qt was built.
bool isEmpty() const noexcept
void stopLogging() override
Called after the end of a test run.
void leaveTestFunction() override
This virtual method is called after a test function has completed, to match \l enterTestFunction().
void addMessage(QtMsgType, const QMessageLogContext &, const QString &) override
This is an overloaded member function, provided for convenience. It differs from the above function o...
void addIncident(IncidentTypes type, const char *description, const char *file=nullptr, int line=0) override
This virtual method is called when an event occurs that relates to the resolution of the test.
void startLogging() override
Called before the start of a test run.
void enterTestFunction(const char *function) override
This virtual method is called before each test function is invoked.
void addBenchmarkResults(const QList< QBenchmarkResult > &results) override
QPlainTestLogger(const char *filename)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString productType()
static QString productVersion()
static int verboseLevel()
static int blacklistCount()
static qreal msecsTotalTime()
static const char * currentTestObjectName()
list append(new Employee("Blackpool", "Stephen"))
Combined button and popup list for selecting options.
void generateTestIdentifier(QTestCharBuffer *identifier, int parts)
int qt_asprintf(QTestCharBuffer *str, const char *format,...)
static const char * ptMessageType2String(QAbstractTestLogger::MessageTypes type)
static const char * ptIncidentType2String(QAbstractTestLogger::IncidentTypes type)
static int countSignificantDigits(T num)
const char * benchmarkMetricUnit(QBenchmarkMetric metric)
static const char * benchmarkResult2String()
QByteArray formatResult(T number, int significantDigits)
bool shouldLogToStderr()
Returns true if logging stderr should be ensured.
Q_CORE_EXPORT int qsnprintf(char *str, size_t n, const char *fmt,...)
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qIsNull(qfloat16 f) noexcept
int qRound(qfloat16 d) noexcept
constexpr const T & qMin(const T &a, const T &b)
constexpr T qAbs(const T &t)
GLsizei const GLfloat * v
[13]
GLenum GLuint GLenum GLsizei length
GLenum GLuint GLenum GLsizei const GLchar * buf
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum format
GLsizei GLsizei GLchar * source
#define qPrintable(string)
#define QTEST_ASSERT(cond)
#define QTEST_VERSION_STR