diff options
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qplaintestlogger.cpp | 27 | ||||
-rw-r--r-- | src/testlib/qplaintestlogger_p.h | 7 | ||||
-rw-r--r-- | src/testlib/qtestdata.h | 8 | ||||
-rw-r--r-- | src/testlib/qtestutil_macos.mm | 7 |
4 files changed, 38 insertions, 11 deletions
diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 5d9283d8e5..851a284678 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -225,7 +225,8 @@ void QPlainTestLogger::outputMessage(const char *str) outputString(str); } -void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line) +void QPlainTestLogger::printMessage(MessageSource source, const char *type, const char *msg, + const char *file, int line) { QTEST_ASSERT(type); QTEST_ASSERT(msg); @@ -233,13 +234,23 @@ void QPlainTestLogger::printMessage(const char *type, const char *msg, const cha QTestCharBuffer messagePrefix; QTestCharBuffer failureLocation; - if (file) { #ifdef Q_OS_WIN -#define FAILURE_LOCATION_STR "\n%s(%d) : failure location" + constexpr const char *INCIDENT_LOCATION_STR = "\n%s(%d) : failure location"; + constexpr const char *OTHER_LOCATION_STR = "\n%s(%d) : message location"; #else -#define FAILURE_LOCATION_STR "\n Loc: [%s(%d)]" + constexpr const char *INCIDENT_LOCATION_STR = "\n Loc: [%s(%d)]"; + constexpr const char *OTHER_LOCATION_STR = INCIDENT_LOCATION_STR; #endif - QTest::qt_asprintf(&failureLocation, FAILURE_LOCATION_STR, file, line); + + if (file) { + switch (source) { + case MessageSource::Incident: + QTest::qt_asprintf(&failureLocation, INCIDENT_LOCATION_STR, file, line); + break; + case MessageSource::Other: + QTest::qt_asprintf(&failureLocation, OTHER_LOCATION_STR, file, line); + break; + } } const char *msgFiller = msg[0] ? " " : ""; @@ -360,7 +371,7 @@ void QPlainTestLogger::stopLogging() void QPlainTestLogger::enterTestFunction(const char * /*function*/) { if (QTestLog::verboseLevel() >= 1) - printMessage(QTest::messageType2String(Info), "entering"); + printMessage(MessageSource::Other, QTest::messageType2String(Info), "entering"); } void QPlainTestLogger::leaveTestFunction() @@ -375,7 +386,7 @@ void QPlainTestLogger::addIncident(IncidentTypes type, const char *description, && QTestLog::verboseLevel() < 0) return; - printMessage(QTest::incidentType2String(type), description, file, line); + printMessage(MessageSource::Incident, QTest::incidentType2String(type), description, file, line); } void QPlainTestLogger::addBenchmarkResult(const QBenchmarkResult &result) @@ -399,7 +410,7 @@ void QPlainTestLogger::addMessage(MessageTypes type, const QString &message, if (type != QAbstractTestLogger::QFatal && QTestLog::verboseLevel() < 0) return; - printMessage(QTest::messageType2String(type), qPrintable(message), file, line); + printMessage(MessageSource::Other, QTest::messageType2String(type), qPrintable(message), file, line); } QT_END_NAMESPACE diff --git a/src/testlib/qplaintestlogger_p.h b/src/testlib/qplaintestlogger_p.h index 80ef4864c1..1a19b99442 100644 --- a/src/testlib/qplaintestlogger_p.h +++ b/src/testlib/qplaintestlogger_p.h @@ -78,7 +78,12 @@ public: const char *file = nullptr, int line = 0) override; private: - void printMessage(const char *type, const char *msg, const char *file = nullptr, int line = 0); + enum class MessageSource { + Incident, + Other, + }; + void printMessage(MessageSource source, const char *type, const char *msg, + const char *file = nullptr, int line = 0); void outputMessage(const char *str); void printBenchmarkResult(const QBenchmarkResult &result); }; diff --git a/src/testlib/qtestdata.h b/src/testlib/qtestdata.h index cf10fed8f3..ed81a9de6e 100644 --- a/src/testlib/qtestdata.h +++ b/src/testlib/qtestdata.h @@ -85,6 +85,14 @@ inline QTestData &operator<<(QTestData &data, const char * value) return data; } +#ifdef __cpp_char8_t +Q_WEAK_OVERLOAD +inline QTestData &operator<<(QTestData &data, const char8_t *value) +{ + return data << reinterpret_cast<const char *>(value); +} +#endif + #ifdef QT_USE_QSTRINGBUILDER template<typename A, typename B> inline QTestData &operator<<(QTestData &data, const QStringBuilder<A, B> &value) diff --git a/src/testlib/qtestutil_macos.mm b/src/testlib/qtestutil_macos.mm index 880cd0f91f..e6638e5cb8 100644 --- a/src/testlib/qtestutil_macos.mm +++ b/src/testlib/qtestutil_macos.mm @@ -53,8 +53,11 @@ namespace QTestPrivate { to start with a clean slate and prevents the "previous restore failed" dialog from showing if there was a test crash. */ - void disableWindowRestore() { - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"ApplePersistenceIgnoreState"]; + void disableWindowRestore() + { + [NSUserDefaults.standardUserDefaults registerDefaults:@{ + @"ApplePersistenceIgnoreState" : @YES + }]; } bool macCrashReporterWillShowDialog() |