summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp138
1 files changed, 105 insertions, 33 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 619376fd33..990fc5679d 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -289,7 +289,7 @@ namespace QTest
{
class WatchDog;
-static QObject *currentTestObject = 0;
+static QObject *currentTestObject = nullptr;
static QString mainSourcePath;
#if defined(Q_OS_MACOS)
@@ -423,7 +423,7 @@ Q_TESTLIB_EXPORT bool printAvailableFunctions = false;
Q_TESTLIB_EXPORT QStringList testFunctions;
Q_TESTLIB_EXPORT QStringList testTags;
-static void qPrintTestSlots(FILE *stream, const char *filter = 0)
+static void qPrintTestSlots(FILE *stream, const char *filter = nullptr)
{
for (int i = 0; i < QTest::currentTestObject->metaObject()->methodCount(); ++i) {
QMetaMethod sl = QTest::currentTestObject->metaObject()->method(i);
@@ -516,7 +516,7 @@ static int qToInt(const char *str)
Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, const char *const argv[], bool qml)
{
int logFormat = -1; // Not set
- const char *logFilename = 0;
+ const char *logFilename = nullptr;
QTest::testFunctions.clear();
QTest::testTags.clear();
@@ -897,7 +897,7 @@ struct QTestDataSetter
}
~QTestDataSetter()
{
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
}
};
@@ -974,11 +974,11 @@ void TestMethods::invokeTestOnData(int index) const
if (i == -1) {
QTestLog::info(qPrintable(
QString::fromLatin1("warmup stage result : %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
} else {
QTestLog::info(qPrintable(
QString::fromLatin1("accumulation stage result: %1")
- .arg(QBenchmarkTestMethodData::current->result.value)), 0, 0);
+ .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0);
}
}
}
@@ -1040,7 +1040,7 @@ public:
void run() override {
QMutexLocker locker(&mutex);
waitCondition.wakeAll();
- while (1) {
+ while (true) {
int t = timeout.loadRelaxed();
if (!t)
break;
@@ -1115,7 +1115,7 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
if (data && !dataCount) {
// Let empty data tag through.
if (!*data)
- data = 0;
+ data = nullptr;
else {
fprintf(stderr, "Unknown testdata for function %s(): '%s'\n", name.constData(), data);
fprintf(stderr, "Function has no testdata.\n");
@@ -1130,10 +1130,9 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
if (!data || !qstrcmp(data, table.testData(curDataIndex)->dataTag())) {
foundFunction = true;
- QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : 0);
+ QTestPrivate::checkBlackLists(name.constData(), dataCount ? table.testData(curDataIndex)->dataTag() : nullptr);
- QTestDataSetter s(curDataIndex >= dataCount ? static_cast<QTestData *>(0)
- : table.testData(curDataIndex));
+ QTestDataSetter s(curDataIndex >= dataCount ? nullptr : table.testData(curDataIndex));
QTestPrivate::qtestMouseButtons = Qt::NoButton;
if (watchDog)
@@ -1156,14 +1155,14 @@ bool TestMethods::invokeTest(int index, const char *data, WatchDog *watchDog) co
return false;
}
- QTestResult::setCurrentGlobalTestData(0);
+ QTestResult::setCurrentGlobalTestData(nullptr);
++curGlobalDataIndex;
} while (curGlobalDataIndex < globalDataCount);
QTestResult::finishedCurrentTestFunction();
QTestResult::setSkipCurrentTest(false);
QTestResult::setBlacklistCurrentTest(false);
- QTestResult::setCurrentTestData(0);
+ QTestResult::setCurrentTestData(nullptr);
return true;
}
@@ -1241,7 +1240,7 @@ char *toHexRepresentation(const char *ba, int length)
* */
const int maxLen = 50;
const int len = qMin(maxLen, length);
- char *result = 0;
+ char *result = nullptr;
if (length > maxLen) {
const int size = len * 3 + 4;
@@ -1274,10 +1273,8 @@ char *toHexRepresentation(const char *ba, int length)
++o;
if (i == len)
break;
- else {
- result[o] = ' ';
- ++o;
- }
+ result[o] = ' ';
+ ++o;
}
return result;
@@ -1497,7 +1494,7 @@ void TestMethods::invokeTests(QObject *testObject) const
QTestResult::finishedCurrentTestDataCleanup();
}
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
#if defined(Q_OS_UNIX)
@@ -1567,7 +1564,7 @@ FatalSignalHandler::FatalSignalHandler()
stack.ss_flags = 0;
stack.ss_size = sizeof alternate_stack;
stack.ss_sp = alternate_stack;
- sigaltstack(&stack, 0);
+ sigaltstack(&stack, nullptr);
act.sa_flags |= SA_ONSTACK;
#endif
@@ -1586,7 +1583,7 @@ FatalSignalHandler::FatalSignalHandler()
oldact.sa_flags & SA_SIGINFO ||
#endif
oldact.sa_handler != SIG_DFL) {
- sigaction(fatalSignals[i], &oldact, 0);
+ sigaction(fatalSignals[i], &oldact, nullptr);
} else
{
sigaddset(&handledSignals, fatalSignals[i]);
@@ -1611,7 +1608,7 @@ FatalSignalHandler::~FatalSignalHandler()
// If someone overwrote it in the mean time, put it back
if (oldact.sa_handler != FatalSignalHandler::signal)
- sigaction(i, &oldact, 0);
+ sigaction(i, &oldact, nullptr);
}
}
@@ -1927,7 +1924,7 @@ int QTest::qRun()
QTestResult::addFailure("Caught unhandled exception", __FILE__, __LINE__);
if (QTestResult::currentTestFunction()) {
QTestResult::finishedCurrentTestFunction();
- QTestResult::setCurrentTestFunction(0);
+ QTestResult::setCurrentTestFunction(nullptr);
}
QTestLog::stopLogging();
@@ -1936,7 +1933,7 @@ int QTest::qRun()
IOPMAssertionRelease(powerID);
}
#endif
- currentTestObject = 0;
+ currentTestObject = nullptr;
// Rethrow exception to make debugging easier.
throw;
@@ -1957,13 +1954,13 @@ int QTest::qRun()
*/
void QTest::qCleanup()
{
- currentTestObject = 0;
+ currentTestObject = nullptr;
QTestTable::clearGlobalTestTable();
QTestLog::stopLogging();
delete QBenchmarkGlobalData::current;
- QBenchmarkGlobalData::current = 0;
+ QBenchmarkGlobalData::current = nullptr;
QSignalDumper::endDump();
@@ -2550,9 +2547,9 @@ bool QTest::qCompare(qfloat16 const &t1, qfloat16 const &t2, const char *actual,
bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(floatingCompare(t1, t2),
- "Compared floats are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared floats are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
}
/*! \fn bool QTest::qCompare(const double &t1, const double &t2, const char *actual, const char *expected, const char *file, int line)
@@ -2561,11 +2558,86 @@ bool QTest::qCompare(float const &t1, float const &t2, const char *actual, const
bool QTest::qCompare(double const &t1, double const &t2, const char *actual, const char *expected,
const char *file, int line)
{
- return compare_helper(floatingCompare(t1, t2),
- "Compared doubles are not the same (fuzzy compare)",
- toString(t1), toString(t2), actual, expected, file, line);
+ return QTestResult::compare(floatingCompare(t1, t2),
+ "Compared doubles are not the same (fuzzy compare)",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(int t1, int t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(unsigned t1, unsigned t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
}
+/*! \fn bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(QStringView t1, const QLatin1String &t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+bool QTest::qCompare(const QLatin1String &t1, QStringView t2, const char *actual, const char *expected,
+ const char *file, int line)
+{
+ return QTestResult::compare(t1 == t2,
+ "Compared values are not the same",
+ t1, t2, actual, expected, file, line);
+}
+
+/*! \fn bool QTest::qCompare(const QString &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QString &t1, const QLatin1String &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
+/*! \fn bool QTest::qCompare(const QLatin1String &t1, const QString &t2, const char *actual, const char *expected, const char *file, int line)
+ \internal
+ \since 5.14
+ */
+
/*! \fn bool QTest::qCompare(const double &t1, const float &t2, const char *actual, const char *expected, const char *file, int line)
\internal
*/
@@ -2703,7 +2775,7 @@ template <> Q_TESTLIB_EXPORT char *QTest::toString<char>(const char &t)
char *QTest::toString(const char *str)
{
if (!str)
- return 0;
+ return nullptr;
char *msg = new char[strlen(str) + 1];
return qstrcpy(msg, str);
}