Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qtestcase.cpp File Reference
#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/qdiriterator.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 <algorithm>
#include <array>
#include <charconv>
#include <chrono>
#include <cmath>
#include <limits>
#include <memory>
#include <mutex>
#include <numeric>
#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 alreadyDebugging ()
 
static bool hasSystemCrashReporter ()
 
static void maybeDisableCoreDump ()
 
static void prepareStackTrace ()
 
static void printTestRunTime ()
 
static void generateStackTrace ()
 
static bool installCoverageTool (const char *appname, const char *testname)
 
static bool isValidSlot (const QMetaMethod &sl)
 
static void QTest::invokeMethod (QObject *obj, const char *methodName)
 
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)
 
char * QTest::toPrettyUnicode (QStringView string)
 
bool QTest::reportResult (bool success, qxp::function_ref< const char *()> lhs, qxp::function_ref< const char *()> rhs, 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

static DebuggerProgram debugger = None
 
Q_TESTLIB_EXPORT Qt::MouseButtons QTestPrivate::qtestMouseButtons = Qt::NoButton
 
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 bool QTest::noCrashHandler = false
 
Q_TESTLIB_EXPORT bool QTest::printAvailableFunctions = false
 
Q_TESTLIB_EXPORT QStringList QTest::testFunctions
 
Q_TESTLIB_EXPORT QStringList QTest::testTags
 

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:240
GLdouble GLdouble t
Definition qopenglext.h:243
static constexpr QSSGRenderTextureFormat FORMAT(QSSGRenderTextureFormat::RGBA16F)
const char * TYPE

Definition at line 3374 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 3320 of file qtestcase.cpp.

Function Documentation

◆ alreadyDebugging()

static bool alreadyDebugging ( )
static

Definition at line 220 of file qtestcase.cpp.

References open(), and read().

Referenced by generateStackTrace(), and QTest::TestMethods::invokeTests().

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

◆ floatingCompare()

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

Definition at line 3170 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:

◆ generateStackTrace()

static void generateStackTrace ( )
static

Definition at line 371 of file qtestcase.cpp.

References alreadyDebugging(), debugger, EINTR_LOOP, None, ret, and void.

+ Here is the call graph for this function:

◆ hasSystemCrashReporter()

static bool hasSystemCrashReporter ( )
static

Definition at line 269 of file qtestcase.cpp.

References QTestPrivate::macCrashReporterWillShowDialog().

Referenced by prepareStackTrace().

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

◆ initEnvironment()

static void initEnvironment ( )
static

Definition at line 2201 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 417 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 438 of file qtestcase.cpp.

References QMetaMethod::access(), QMetaMethod::methodType(), QMetaMethod::name(), QMetaMethod::parameterCount(), QMetaMethod::Private, QMetaMethod::returnType(), and QMetaMethod::Slot.

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

+ Here is the call graph for this function:
+ 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 3355 of file qtestcase.cpp.

References text.

◆ maybeDisableCoreDump()

static void maybeDisableCoreDump ( )
static

Definition at line 278 of file qtestcase.cpp.

References ok, qEnvironmentVariableIntValue(), and qWarning.

Referenced by QTest::qInit().

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

◆ prepareStackTrace()

static void prepareStackTrace ( )
static

Definition at line 294 of file qtestcase.cpp.

References debugger, hasSystemCrashReporter(), None, ok, and qEnvironmentVariableIntValue().

Referenced by QTest::qRun().

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

◆ printTestRunTime()

static void printTestRunTime ( )
static

Definition at line 361 of file qtestcase.cpp.

References QTest::currentTestFunction(), QTestLog::msecsFunctionTime(), QTestLog::msecsTotalTime(), and qRound().

+ Here is the call graph for this function:

Variable Documentation

◆ debugger