diff options
author | Sona Kurazyan <[email protected]> | 2022-04-26 17:07:00 +0200 |
---|---|---|
committer | Marc Mutz <[email protected]> | 2022-05-02 20:06:20 +0000 |
commit | 7baa06fe0c7fa1a1d20ae749915a6483621f204e (patch) | |
tree | 4870b761bd66e7f61d37375f80917c7445692884 | |
parent | 34242f843ec41b63c706e4604ac3a65805d11107 (diff) |
QtTestLib: replace QLatin1String uses with _L1/_s/QStringLiteral
Task-number: QTBUG-98434
Change-Id: Ie327fd4af1880002e5a1e09b43384f2b709625e7
Reviewed-by: Marc Mutz <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
-rw-r--r-- | src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp | 6 | ||||
-rw-r--r-- | src/testlib/qbenchmarkvalgrind.cpp | 16 | ||||
-rw-r--r-- | src/testlib/qplaintestlogger.cpp | 8 | ||||
-rw-r--r-- | src/testlib/qtaptestlogger.cpp | 38 | ||||
-rw-r--r-- | src/testlib/qteamcitylogger.cpp | 46 | ||||
-rw-r--r-- | src/testlib/qtest.h | 2 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 54 |
7 files changed, 88 insertions, 82 deletions
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp index bea1ee6d6ce..766df676010 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp @@ -53,6 +53,8 @@ #include <initializer_list> +using namespace Qt::StringLiterals; + // dummy class TestBenchmark : public QObject { @@ -225,8 +227,8 @@ QTest::qSleep(250); //! [27] void TestBenchmark::simple() { - QString str1 = QLatin1String("This is a test string"); - QString str2 = QLatin1String("This is a test string"); + QString str1 = u"This is a test string"_s; + QString str2 = u"This is a test string"_s; QCOMPARE(str1.localeAwareCompare(str2), 0); QBENCHMARK { str1.localeAwareCompare(str2); diff --git a/src/testlib/qbenchmarkvalgrind.cpp b/src/testlib/qbenchmarkvalgrind.cpp index 29cbcd8e3c6..6068e56b89a 100644 --- a/src/testlib/qbenchmarkvalgrind.cpp +++ b/src/testlib/qbenchmarkvalgrind.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + // Returns \c true if valgrind is available. bool QBenchmarkValgrindUtils::haveValgrind() { @@ -57,7 +59,7 @@ bool QBenchmarkValgrindUtils::haveValgrind() return false; #else QProcess process; - process.start(QLatin1String("valgrind"), QStringList(QLatin1String("--version"))); + process.start(u"valgrind"_s, QStringList(u"--version"_s)); return process.waitForStarted() && process.waitForFinished(-1); #endif } @@ -89,7 +91,7 @@ qint64 QBenchmarkValgrindUtils::extractResult(const QString &fileName) qint64 val = -1; bool valSeen = false; - QRegularExpression rxValue(QLatin1String("^summary: (\\d+)")); + QRegularExpression rxValue(u"^summary: (\\d+)"_s); while (!file.atEnd()) { const QString line(QLatin1String(file.readLine())); QRegularExpressionMatch match = rxValue.match(line); @@ -169,22 +171,20 @@ QString QBenchmarkValgrindUtils::outFileBase(qint64 pid) bool QBenchmarkValgrindUtils::runCallgrindSubProcess(const QStringList &origAppArgs, int &exitCode) { const QString &execFile = origAppArgs.at(0); - QStringList args; - args << QLatin1String("--tool=callgrind") << QLatin1String("--instr-atstart=yes") - << QLatin1String("--quiet") - << execFile << QLatin1String("-callgrindchild"); + QStringList args{ u"--tool=callgrind"_s, u"--instr-atstart=yes"_s, + u"--quiet"_s, execFile, u"-callgrindchild"_s }; // pass on original arguments that make sense (e.g. avoid wasting time producing output // that will be ignored anyway) ... for (int i = 1; i < origAppArgs.size(); ++i) { const QString &arg = origAppArgs.at(i); - if (arg == QLatin1String("-callgrind")) + if (arg == "-callgrind"_L1) continue; args << arg; // ok to pass on } QProcess process; - process.start(QLatin1String("valgrind"), args); + process.start(u"valgrind"_s, args); process.waitForStarted(-1); QBenchmarkGlobalData::current->callgrindOutFileBase = QBenchmarkValgrindUtils::outFileBase(process.processId()); diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index aa041edb663..a2713d0c0e2 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -72,6 +72,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace QTest { static const char *incidentType2String(QAbstractTestLogger::IncidentTypes type) @@ -148,9 +150,9 @@ namespace QTest { template <typename T> QString formatResult(T number, int significantDigits) { if (number < T(0)) - return QLatin1String("NAN"); + return u"NAN"_s; if (number == T(0)) - return QLatin1String("0"); + return u"0"_s; QString beforeDecimalPoint = QString::number(qint64(number), 'f', 0); QString afterDecimalPoint = QString::number(number, 'f', 20); @@ -168,7 +170,7 @@ namespace QTest { int afterUse = significantDigits - beforeUse; // leading zeroes after the decimal point does not count towards the digit use. - if (beforeDecimalPoint == QLatin1String("0") && afterDecimalPoint.isEmpty() == false) { + if (beforeDecimalPoint == u'0' && !afterDecimalPoint.isEmpty()) { ++afterUse; int i = 0; diff --git a/src/testlib/qtaptestlogger.cpp b/src/testlib/qtaptestlogger.cpp index 45b3d2f9a08..ab2de7f53ef 100644 --- a/src/testlib/qtaptestlogger.cpp +++ b/src/testlib/qtaptestlogger.cpp @@ -48,6 +48,9 @@ #endif QT_BEGIN_NAMESPACE + +using namespace Qt::StringLiterals; + /*! \internal \class QTapTestLogger \inmodule QtTest @@ -316,15 +319,14 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description, #if QT_CONFIG(regularexpression) // This is fragile, but unfortunately testlib doesn't plumb // the expected and actual values to the loggers (yet). - static QRegularExpression verifyRegex( - QLatin1String("^'(?<actualexpression>.*)' returned " - "(?<actual>\\w+).+\\((?<message>.*)\\)$")); + static QRegularExpression verifyRegex(u"^'(?<actualexpression>.*)' returned " + "(?<actual>\\w+).+\\((?<message>.*)\\)$"_s); static QRegularExpression compareRegex( - QLatin1String("^(?<message>.*)\n" - "\\s*Actual\\s+\\((?<actualexpression>.*)\\)\\s*: (?<actual>.*)\n" - "\\s*Expected\\s+\\((?<expectedexpresssion>.*)\\)\\s*: " - "(?<expected>.*)$")); + u"^(?<message>.*)\n" + "\\s*Actual\\s+\\((?<actualexpression>.*)\\)\\s*: (?<actual>.*)\n" + "\\s*Expected\\s+\\((?<expectedexpresssion>.*)\\)\\s*: " + "(?<expected>.*)$"_s); QString descriptionString = QString::fromUtf8(description); QRegularExpressionMatch match = verifyRegex.match(descriptionString); @@ -333,26 +335,24 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description, match = compareRegex.match(descriptionString); if (match.hasMatch()) { - QString message = match.captured(QLatin1String("message")); + QString message = match.captured(u"message"); QString expected; QString actual; const auto parenthesize = [&match](QLatin1String key) -> QString { - return QLatin1String(" (") % match.captured(key) % u')'; + return " ("_L1 % match.captured(key) % u')'; }; - const QString actualExpression - = parenthesize(QLatin1String("actualexpression")); + const QString actualExpression = parenthesize("actualexpression"_L1); if (isVerify) { - actual = match.captured(QLatin1String("actual")).toLower() - % actualExpression; - expected = QLatin1String(actual.startsWith(QLatin1String("true ")) - ? "false" : "true") % actualExpression; + actual = match.captured(u"actual").toLower() % actualExpression; + expected = (actual.startsWith("true "_L1) ? "false"_L1 : "true"_L1) + % actualExpression; if (message.isEmpty()) - message = QLatin1String("Verification failed"); + message = u"Verification failed"_s; } else { - expected = match.captured(QLatin1String("expected")) - % parenthesize(QLatin1String("expectedexpresssion")); - actual = match.captured(QLatin1String("actual")) % actualExpression; + expected = match.captured(u"expected") + % parenthesize("expectedexpresssion"_L1); + actual = match.captured(u"actual") % actualExpression; } QTestCharBuffer diagnosticsYamlish; diff --git a/src/testlib/qteamcitylogger.cpp b/src/testlib/qteamcitylogger.cpp index 5bd6b4f4291..9311f24a570 100644 --- a/src/testlib/qteamcitylogger.cpp +++ b/src/testlib/qteamcitylogger.cpp @@ -50,6 +50,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + namespace QTest { static const char *incidentType2String(QAbstractTestLogger::IncidentTypes type) @@ -119,13 +121,13 @@ void QTeamCityLogger::startLogging() flowID = tcEscapedString(QString::fromUtf8(QTestResult::currentTestObjectName())); - QString str = QLatin1String("##teamcity[testSuiteStarted name='%1' flowId='%1']\n").arg(flowID); + QString str = "##teamcity[testSuiteStarted name='%1' flowId='%1']\n"_L1.arg(flowID); outputString(qPrintable(str)); } void QTeamCityLogger::stopLogging() { - QString str = QLatin1String("##teamcity[testSuiteFinished name='%1' flowId='%1']\n").arg(flowID); + QString str = "##teamcity[testSuiteFinished name='%1' flowId='%1']\n"_L1.arg(flowID); outputString(qPrintable(str)); QAbstractTestLogger::stopLogging(); @@ -153,7 +155,7 @@ void QTeamCityLogger::addIncident(IncidentTypes type, const char *description, QString tmpFuncName = escapedTestFuncName(); if (tmpFuncName != currTestFuncName) { - buf = QLatin1String("##teamcity[testStarted name='%1' flowId='%2']\n").arg(tmpFuncName, flowID); + buf = "##teamcity[testStarted name='%1' flowId='%2']\n"_L1.arg(tmpFuncName, flowID); outputString(qPrintable(buf)); } @@ -168,27 +170,27 @@ void QTeamCityLogger::addIncident(IncidentTypes type, const char *description, // Test failed if (type == Fail || type == XPass) { - QString messageText(QLatin1String("Failure!")); + QString messageText(u"Failure!"_s); if (file) - messageText += QLatin1String(" |[Loc: %1(%2)|]").arg(QString::fromUtf8(file)).arg(line); + messageText += " |[Loc: %1(%2)|]"_L1.arg(QString::fromUtf8(file)).arg(line); - buf = QLatin1String("##teamcity[testFailed name='%1' message='%2' details='%3' flowId='%4']\n") + buf = "##teamcity[testFailed name='%1' message='%2' details='%3' flowId='%4']\n"_L1 .arg(tmpFuncName, messageText, detailedText, flowID); outputString(qPrintable(buf)); } else if (type == Skip) { if (file) - detailedText.append(QLatin1String(" |[Loc: %1(%2)|]").arg(QString::fromUtf8(file)).arg(line)); + detailedText.append(" |[Loc: %1(%2)|]"_L1.arg(QString::fromUtf8(file)).arg(line)); - buf = QLatin1String("##teamcity[testIgnored name='%1' message='%2' flowId='%3']\n") + buf = "##teamcity[testIgnored name='%1' message='%2' flowId='%3']\n"_L1 .arg(escapedTestFuncName(), detailedText, flowID); outputString(qPrintable(buf)); } if (!pendingMessages.isEmpty()) { - buf = QLatin1String("##teamcity[testStdOut name='%1' out='%2' flowId='%3']\n") + buf = "##teamcity[testStdOut name='%1' out='%2' flowId='%3']\n"_L1 .arg(tmpFuncName, pendingMessages, flowID); outputString(qPrintable(buf)); @@ -196,7 +198,7 @@ void QTeamCityLogger::addIncident(IncidentTypes type, const char *description, pendingMessages.clear(); } - buf = QLatin1String("##teamcity[testFinished name='%1' flowId='%2']\n").arg(tmpFuncName, flowID); + buf = "##teamcity[testFinished name='%1' flowId='%2']\n"_L1.arg(tmpFuncName, flowID); outputString(qPrintable(buf)); } @@ -223,22 +225,22 @@ QString QTeamCityLogger::tcEscapedString(const QString &str) const for (QChar ch : str) { switch (ch.toLatin1()) { case '\n': - formattedString.append(QLatin1String("|n")); + formattedString.append("|n"_L1); break; case '\r': - formattedString.append(QLatin1String("|r")); + formattedString.append("|r"_L1); break; case '|': - formattedString.append(QLatin1String("||")); + formattedString.append("||"_L1); break; case '[': - formattedString.append(QLatin1String("|[")); + formattedString.append("|["_L1); break; case ']': - formattedString.append(QLatin1String("|]")); + formattedString.append("|]"_L1); break; case '\'': - formattedString.append(QLatin1String("|'")); + formattedString.append("|'"_L1); break; default: formattedString.append(ch); @@ -262,16 +264,16 @@ void QTeamCityLogger::addPendingMessage(const char *type, const QString &msg, co QString pendMessage; if (!pendingMessages.isEmpty()) - pendMessage += QLatin1String("|n"); + pendMessage += "|n"_L1; if (file) { - pendMessage += QLatin1String("%1 |[Loc: %2(%3)|]: %4") - .arg(QString::fromUtf8(type), QString::fromUtf8(file)) - .arg(line) - .arg(msg); + pendMessage += "%1 |[Loc: %2(%3)|]: %4"_L1 + .arg(QString::fromUtf8(type), QString::fromUtf8(file)) + .arg(line) + .arg(msg); } else { - pendMessage += QLatin1String("%1: %2").arg(QString::fromUtf8(type), msg); + pendMessage += "%1: %2"_L1.arg(QString::fromUtf8(type), msg); } pendingMessages.append(pendMessage); diff --git a/src/testlib/qtest.h b/src/testlib/qtest.h index eb7c2c34125..cbd8d54433d 100644 --- a/src/testlib/qtest.h +++ b/src/testlib/qtest.h @@ -404,7 +404,7 @@ inline char *toString(const std::tuple<Types...> &tuple) inline char *toString(std::nullptr_t) { - return toString(QLatin1String("nullptr")); + return toString(QStringLiteral("nullptr")); } template<> diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index b4d1ee402fa..00a9b29f127 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -125,6 +125,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + using QtMiscUtils::toHexUpper; using QtMiscUtils::fromHex; @@ -298,7 +300,8 @@ namespace QTest QString Internal::formatTryTimeoutDebugMessage(q_no_char8_t::QUtf8StringView expr, int timeout, int actual) { - return QLatin1String("QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) was too short, %3 ms would have been sufficient this time.") + return "QTestLib: This test case check (\"%1\") failed because the requested timeout (%2 ms) " + "was too short, %3 ms would have been sufficient this time."_L1 // ### Qt 7: remove the toString() (or earlier, when arg() can handle QUtf8StringView), passing the view directly .arg(expr.toString(), QString::number(timeout), QString::number(actual)); } @@ -1066,7 +1069,7 @@ class WatchDog : public QThread public: WatchDog() { - setObjectName(QLatin1String("QtTest Watchdog")); + setObjectName("QtTest Watchdog"_L1); auto locker = qt_unique_lock(mutex); expecting.store(ThreadStart, std::memory_order_relaxed); start(); @@ -1154,7 +1157,7 @@ bool TestMethods::invokeTest(int index, QLatin1String tag, WatchDog *watchDog) c QBenchmarkTestMethodData::current = &benchmarkData; const QByteArray &name = m_methods[index].name(); - QBenchmarkGlobalData::current->context.slotName = QLatin1String(name) + QLatin1String("()"); + QBenchmarkGlobalData::current->context.slotName = QLatin1String(name) + "()"_L1; char member[512]; QTestTable table; @@ -2300,8 +2303,8 @@ void QTest::failOnWarning(const QRegularExpression &messagePattern) #ifdef Q_OS_WIN static inline bool isWindowsBuildDirectory(const QString &dirName) { - return dirName.compare(QLatin1String("Debug"), Qt::CaseInsensitive) == 0 - || dirName.compare(QLatin1String("Release"), Qt::CaseInsensitive) == 0; + return dirName.compare("Debug"_L1, Qt::CaseInsensitive) == 0 + || dirName.compare("Release"_L1, Qt::CaseInsensitive) == 0; } #endif @@ -2392,10 +2395,9 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co #endif // Q_OS_WIN else if (QTestLog::verboseLevel() >= 2) { const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + u'/' + base); - QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found relative to test binary [%2]; " - "checking next location").arg(base, candidate)), - file, line); + QTestLog::info(qPrintable("testdata %1 not found relative to test binary [%2]; " + "checking next location"_L1.arg(base, candidate)), + file, line); } } @@ -2404,16 +2406,15 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co const char *testObjectName = QTestResult::currentTestObjectName(); if (testObjectName) { const QString testsPath = QLibraryInfo::path(QLibraryInfo::TestsPath); - const QString candidate = QLatin1String("%1/%2/%3") + const QString candidate = "%1/%2/%3"_L1 .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); if (QFileInfo::exists(candidate)) { found = candidate; } else if (QTestLog::verboseLevel() >= 2) { - QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found in tests install path [%2]; " - "checking next location") - .arg(base, QDir::toNativeSeparators(candidate))), - file, line); + QTestLog::info(qPrintable("testdata %1 not found in tests install path [%2]; " + "checking next location"_L1 + .arg(base, QDir::toNativeSeparators(candidate))), + file, line); } } } @@ -2425,17 +2426,16 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co // If the srcdir is relative, that means it is relative to the current working // directory of the compiler at compile time, which should be passed in as `builddir'. - if (!srcdir.isAbsolute() && builddir) { - srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); - } + if (!srcdir.isAbsolute() && builddir) + srcdir.setFile(QFile::decodeName(builddir) + u'/' + srcdir.filePath()); const QString canonicalPath = srcdir.canonicalFilePath(); - const QString candidate = QLatin1String("%1/%2").arg(canonicalPath, base); + const QString candidate = "%1/%2"_L1.arg(canonicalPath, base); if (!canonicalPath.isEmpty() && QFileInfo::exists(candidate)) { found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found relative to source path [%2]") + "testdata %1 not found relative to source path [%2]"_L1 .arg(base, QDir::toNativeSeparators(candidate))), file, line); } @@ -2443,12 +2443,12 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co // 4. Try resources if (found.isEmpty()) { - const QString candidate = QLatin1String(":/%1").arg(base); + const QString candidate = ":/%1"_L1.arg(base); if (QFileInfo::exists(candidate)) { found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found in resources [%2]") + "testdata %1 not found in resources [%2]"_L1 .arg(base, QDir::toNativeSeparators(candidate))), file, line); } @@ -2461,7 +2461,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found in current directory [%2]") + "testdata %1 not found in current directory [%2]"_L1 .arg(base, QDir::toNativeSeparators(candidate))), file, line); } @@ -2474,7 +2474,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found in main source directory [%2]") + "testdata %1 not found in main source directory [%2]"_L1 .arg(base, QDir::toNativeSeparators(candidate))), file, line); } @@ -2487,7 +2487,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 not found in supplied source directory [%2]") + "testdata %1 not found in supplied source directory [%2]"_L1 .arg(base, QDir::toNativeSeparators(candidate))), file, line); } @@ -2496,11 +2496,11 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co if (found.isEmpty()) { QTestLog::warn(qPrintable( - QLatin1String("testdata %1 could not be located!").arg(base)), + "testdata %1 could not be located!"_L1.arg(base)), file, line); } else if (QTestLog::verboseLevel() >= 1) { QTestLog::info(qPrintable( - QLatin1String("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))), + "testdata %1 was located at %2"_L1.arg(base, QDir::toNativeSeparators(found))), file, line); } |