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
qtestcase.cpp File Reference

(a2566e139f8b2eed2b8cf7d90bc0a2ae6b289be8)

#include <QtTest/qtestcase.h>
#include <QtTest/private/qtestcase_p.h>
#include <QtTest/qtestassert.h>
#include <QtCore/qbytearray.h>
#include <QtCore/qcoreapplication.h>
#include <QtCore/qdebug.h>
#include <QtCore/qdir.h>
#include <QtCore/qdirlisting.h>
#include <QtCore/qfile.h>
#include <QtCore/qfileinfo.h>
#include <QtCore/qfloat16.h>
#include <QtCore/qlibraryinfo.h>
#include <QtCore/qlist.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qobject.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qtemporarydir.h>
#include <QtCore/qthread.h>
#include <QtCore/qvarlengtharray.h>
#include <QtCore/private/qlocking_p.h>
#include <QtCore/private/qtools_p.h>
#include <QtCore/private/qwaitcondition_p.h>
#include <QtCore/qtestsupport_core.h>
#include <QtTest/private/qtestlog_p.h>
#include <QtTest/private/qtesttable_p.h>
#include <QtTest/qtestdata.h>
#include <QtTest/private/qtestresult_p.h>
#include <QtTest/private/qsignaldumper_p.h>
#include <QtTest/private/qbenchmark_p.h>
#include <QtTest/private/cycle_p.h>
#include <QtTest/private/qtestblacklist_p.h>
#include <QtTest/private/qtestcrashhandler_p.h>
#include <algorithm>
#include <array>
#include <charconv>
#include <chrono>
#include <cmath>
#include <limits>
#include <memory>
#include <mutex>
#include <numeric>
#include <optional>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
+ Include dependency graph for qtestcase.cpp:

Go to the source code of this file.

Classes

class  QTest::TestMethods
 
struct  QTest::QTestDataSetter
 
class  QTest::WatchDog
 

Namespaces

namespace  QTestPrivate
 
namespace  QTest
 [15]
 
namespace  QTest::Internal
 

Macros

#define TO_STRING_IMPL(TYPE, FORMAT)
 
#define TO_STRING_FLOAT(TYPE, FORMAT)
 

Functions

static bool installCoverageTool (const char *appname, const char *testname)
 
static bool isValidSlot (const QMetaMethod &sl)
 
void QTest::setThrowOnFail (bool enable) noexcept
 
void QTest::setThrowOnSkip (bool enable) noexcept
 
static bool QTest::invokeTestMethodIfValid (QMetaMethod m, QObject *obj=QTest::currentTestObject)
 
static void QTest::invokeTestMethodIfExists (const char *methodName, QObject *obj=QTest::currentTestObject)
 
int QTest::defaultEventDelay ()
 
int Q_TESTLIB_EXPORT QTest::defaultMouseDelay ()
 
int Q_TESTLIB_EXPORT QTest::defaultKeyDelay ()
 
static bool QTest::qPrintTestSlots (FILE *stream, const char *filter=nullptr, const char *preamble="")
 
static void QTest::qPrintDataTags (FILE *stream)
 
static int QTest::qToInt (const char *str)
 
Q_TESTLIB_EXPORT void QTest::qtest_qParseArgs (int argc, const char *const argv[], bool qml)
 
Q_TESTLIB_EXPORT void QTest::qtest_qParseArgs (int argc, char *argv[], bool qml)
 
static QList< QBenchmarkResultQTest::qMedian (const QList< QList< QBenchmarkResult > > &container)
 
static void QTest::printUnknownDataTagError (QLatin1StringView name, QLatin1StringView tag, const QTestTable &lTable, const QTestTable &gTable)
 
voidQTest::fetchData (QTestData *data, const char *tagName, int typeId)
 
char * QTest::formatString (const char *prefix, const char *suffix, size_t numArguments,...)
 
char * QTest::toHexRepresentation (const char *ba, qsizetype length)
 Returns a pointer to a string that is the string ba represented as a space-separated sequence of hex characters.
 
char * QTest::toPrettyCString (const char *p, qsizetype length)
 
 QTest::switch (ch)
 
return QTest::first (2)
 
char * toPrettyUnicode (QStringView string)
 
bool reportResult (bool success, const void *lhs, const void *rhs, const char *(*lhsFormatter)(const void *), const char *(*rhsFormatter)(const void *), const char *lhsExpr, const char *rhsExpr, ComparisonOperation op, const char *file, int line)
 
static void initEnvironment ()
 
template<typename T >
static bool floatingCompare (const T &actual, const T &expected)
 
static void massageExponent (char *text)
 

Variables

Q_TESTLIB_EXPORT Qt::MouseButtons QTestPrivate::qtestMouseButtons = Qt::NoButton
 
static Q_CONSTINIT QBasicAtomicInt QTest::g_throwOnFail = Q_BASIC_ATOMIC_INITIALIZER(0)
 
static Q_CONSTINIT QBasicAtomicInt QTest::g_throwOnSkip = Q_BASIC_ATOMIC_INITIALIZER(0)
 
Q_TESTLIB_EXPORT int QTest::lastMouseTimestamp = 0
 
static QObjectQTest::currentTestObject = nullptr
 
static QString QTest::mainSourcePath
 
static bool QTest::inTestFunction = false
 
static int QTest::keyDelay = -1
 
static int QTest::mouseDelay = -1
 
static int QTest::eventDelay = -1
 
static int QTest::repetitions = 1
 
static bool QTest::repeatForever = false
 
static bool QTest::skipBlacklisted = false
 
bool QTest::Internal::noCrashHandler = false
 
Q_TESTLIB_EXPORT bool QTest::printAvailableFunctions = false
 
Q_TESTLIB_EXPORT QStringList QTest::testFunctions
 
Q_TESTLIB_EXPORT QStringList QTest::testTags
 
constexpr qsizetype QTest::PrettyUnicodeMaxOutputSize = 256
 
constexpr qsizetype QTest::PrettyUnicodeMaxIncrement
 

Macro Definition Documentation

◆ TO_STRING_FLOAT

#define TO_STRING_FLOAT ( TYPE,
FORMAT )
Value:
template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \
{ \
char *msg = new char[128]; \
switch (qFpClassify(t)) { \
case FP_INFINITE: \
qstrncpy(msg, (t < 0 ? "-inf" : "inf"), 128); \
break; \
case FP_NAN: \
qstrncpy(msg, "nan", 128); \
break; \
default: \
qsnprintf(msg, 128, #FORMAT, double(t)); \
massageExponent(msg); \
break; \
} \
return msg; \
}
int qFpClassify(qfloat16 f) noexcept
Definition qfloat16.h:286
GLdouble GLdouble t
Definition qopenglext.h:243
static constexpr QSSGRenderTextureFormat FORMAT(QSSGRenderTextureFormat::RGBA16F)
const char * TYPE

Definition at line 3048 of file qtestcase.cpp.

◆ TO_STRING_IMPL

#define TO_STRING_IMPL ( TYPE,
FORMAT )
Value:
template <> Q_TESTLIB_EXPORT char *QTest::toString<TYPE>(const TYPE &t) \
{ \
char *msg = new char[128]; \
qsnprintf(msg, 128, #FORMAT, t); \
return msg; \
}

Definition at line 2994 of file qtestcase.cpp.

Function Documentation

◆ floatingCompare()

template<typename T >
static bool floatingCompare ( const T & actual,
const T & expected )
static

Definition at line 2843 of file qtestcase.cpp.

References expected, Q_FALLTHROUGH, qFpClassify(), qFuzzyCompare(), and qFuzzyIsNull().

Referenced by QTest::qCompare(), QTest::qCompare(), and QTest::qCompare().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initEnvironment()

static void initEnvironment ( )
static

Definition at line 1777 of file qtestcase.cpp.

References qputenv().

Referenced by QTest::qInit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ installCoverageTool()

static bool installCoverageTool ( const char * appname,
const char * testname )
static

Definition at line 133 of file qtestcase.cpp.

References Q_UNUSED, qEnvironmentVariableIsEmpty(), and qputenv().

+ Here is the call graph for this function:

◆ isValidSlot()

static bool isValidSlot ( const QMetaMethod & sl)
static

Definition at line 154 of file qtestcase.cpp.

References QMetaMethod::Private, and QMetaMethod::Slot.

Referenced by QTest::TestMethods::TestMethods(), QTest::qPrintDataTags(), QTest::qPrintTestSlots(), and QTest::qRun().

+ Here is the caller graph for this function:

◆ massageExponent()

static void massageExponent ( char * text)
static

Be consistent about leading 0 in exponent.

POSIX specifies that e (hence g when using it) uses at least two digits in the exponent, requiring a leading 0 on single-digit exponents; (at least) MinGW includes a leading zero also on an already-two-digit exponent, e.g. 9e-040, which differs from more usual platforms. So massage that away.

Definition at line 3029 of file qtestcase.cpp.

References text.

◆ reportResult()

bool reportResult ( bool success,
const void * lhs,
const void * rhs,
const char *(*)(const void *) lhsFormatter,
const char *(*)(const void *) rhsFormatter,
const char * lhsExpr,
const char * rhsExpr,
ComparisonOperation op,
const char * file,
int line )

Definition at line 1766 of file qtestcase.cpp.

References file, line, and QTestResult::reportResult().

Referenced by QFutureInterface< T >::reportFinished(), and QFutureInterface< T >::reportResult().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toPrettyUnicode()

char * toPrettyUnicode ( QStringView string)