From c6de55a0bb7cc6bebb5dd896ee8edf806c571b96 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 13 Feb 2018 12:19:01 +0100 Subject: Fix typos Change-Id: Id625efea998f2b4dce9970b903830dc3b3efcd3d Reviewed-by: Leena Miettinen --- src/testlib/qtestcase.qdoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/testlib') diff --git a/src/testlib/qtestcase.qdoc b/src/testlib/qtestcase.qdoc index 0fb1cc6a8a..9a3c770e31 100644 --- a/src/testlib/qtestcase.qdoc +++ b/src/testlib/qtestcase.qdoc @@ -103,7 +103,7 @@ to catch an exception thrown from the \a expression. If the \a expression throws an exception and its type is the same as \a exceptiontype or \a exceptiontype is substitutable with the type of thrown exception - (i.e. usually the type of thrown exception is publically derived + (i.e. usually the type of thrown exception is publicly derived from \a exceptiontype) then execution will be continued. If not-substitutable type of exception is thrown or the \a expression doesn't throw an exception at all, then a failure will be recorded in the test log and -- cgit v1.2.3 From cf4a6111150d866424ee07bda80a1d38f24ea02d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 9 Feb 2018 15:09:25 +0100 Subject: testlib: Split out test identifier buildup into standalone function Change-Id: I99aa106d5aab8f299e61835680709e4fd856defe Reviewed-by: Simon Hausmann --- src/testlib/qplaintestlogger.cpp | 47 ++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) (limited to 'src/testlib') diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index 77959341cf..25c9655691 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -223,38 +223,47 @@ void QPlainTestLogger::outputMessage(const char *str) outputString(str); } +static QTestCharBuffer testIdentifier() +{ + QTestCharBuffer identifier; + + const char *testObject = QTestResult::currentTestObjectName(); + const char *testFunction = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() : "UnknownTestFunc"; + + const char *dataTag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; + const char *globalDataTag = QTestResult::currentGlobalDataTag() ? QTestResult::currentGlobalDataTag() : ""; + const char *tagFiller = (dataTag[0] && globalDataTag[0]) ? ":" : ""; + + QTest::qt_asprintf(&identifier, "%s::%s(%s%s%s)", testObject, testFunction, globalDataTag, tagFiller, dataTag); + return identifier; +} + void QPlainTestLogger::printMessage(const char *type, const char *msg, const char *file, int line) { QTEST_ASSERT(type); QTEST_ASSERT(msg); - QTestCharBuffer buf; + QTestCharBuffer messagePrefix; - const char *fn = QTestResult::currentTestFunction() ? QTestResult::currentTestFunction() - : "UnknownTestFunc"; - const char *tag = QTestResult::currentDataTag() ? QTestResult::currentDataTag() : ""; - const char *gtag = QTestResult::currentGlobalDataTag() - ? QTestResult::currentGlobalDataTag() - : ""; - const char *filler = (tag[0] && gtag[0]) ? ":" : ""; + QTestCharBuffer failureLocation; if (file) { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n" #ifdef Q_OS_WIN - "%s(%d) : failure location\n" +#define FAILURE_LOCATION_STR "\n%s(%d) : failure location" #else - " Loc: [%s(%d)]\n" +#define FAILURE_LOCATION_STR "\n Loc: [%s(%d)]" #endif - , type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg, file, line); - } else { - QTest::qt_asprintf(&buf, "%s: %s::%s(%s%s%s)%s%s\n", - type, QTestResult::currentTestObjectName(), fn, gtag, filler, tag, - msg[0] ? " " : "", msg); + QTest::qt_asprintf(&failureLocation, FAILURE_LOCATION_STR, file, line); } + + const char *msgFiller = msg[0] ? " " : ""; + QTest::qt_asprintf(&messagePrefix, "%s: %s%s%s%s\n", + type, testIdentifier().data(), msgFiller, msg, failureLocation.data()); + // In colored mode, printf above stripped our nonprintable control characters. // Put them back. - memcpy(buf.data(), type, strlen(type)); - outputMessage(buf.data()); + memcpy(messagePrefix.data(), type, strlen(type)); + + outputMessage(messagePrefix.data()); } void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) -- cgit v1.2.3