QtTestLib: stop using QLatin1Char constructor for creating char literals

Required for porting away from QLatin1Char/QLatin1String in scope of
QTBUG-98434.

Change-Id: I3debae5f481037958bfb65caabca97a0d4681eb9
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
Sona Kurazyan 2022-04-26 16:33:09 +02:00
parent c038fa9e77
commit 79cf895c70
6 changed files with 17 additions and 18 deletions

View File

@ -140,7 +140,7 @@ void QAppleTestLogger::addIncident(IncidentTypes type, const char *description,
QString message = testIdentifier(); QString message = testIdentifier();
if (qstrlen(description)) if (qstrlen(description))
message += QLatin1Char('\n') % QString::fromLatin1(description); message += u'\n' % QString::fromLatin1(description);
AppleUnifiedLogger::messageHandler(messageData.messageType, context, message, subsystem()); AppleUnifiedLogger::messageHandler(messageData.messageType, context, message, subsystem());
} }

View File

@ -272,8 +272,8 @@ void QJUnitTestLogger::addFailure(QTest::LogElementType elementType,
failureElement->addAttribute(QTest::AI_Type, failureType); failureElement->addAttribute(QTest::AI_Type, failureType);
// Assume the first line is the message, and the remainder are details // Assume the first line is the message, and the remainder are details
QString message = failureDescription.section(QLatin1Char('\n'), 0, 0); QString message = failureDescription.section(u'\n', 0, 0);
QString details = failureDescription.section(QLatin1Char('\n'), 1); QString details = failureDescription.section(u'\n', 1);
failureElement->addAttribute(QTest::AI_Message, message.toUtf8().constData()); failureElement->addAttribute(QTest::AI_Message, message.toUtf8().constData());

View File

@ -162,7 +162,7 @@ namespace QTest {
// Replace insignificant digits before the decimal point with zeros. // Replace insignificant digits before the decimal point with zeros.
beforeDecimalPoint.chop(beforeRemove); beforeDecimalPoint.chop(beforeRemove);
for (int i = 0; i < beforeRemove; ++i) { for (int i = 0; i < beforeRemove; ++i) {
beforeDecimalPoint.append(QLatin1Char('0')); beforeDecimalPoint.append(u'0');
} }
int afterUse = significantDigits - beforeUse; int afterUse = significantDigits - beforeUse;
@ -172,9 +172,8 @@ namespace QTest {
++afterUse; ++afterUse;
int i = 0; int i = 0;
while (i < afterDecimalPoint.length() && afterDecimalPoint.at(i) == QLatin1Char('0')) { while (i < afterDecimalPoint.length() && afterDecimalPoint.at(i) == u'0')
++i; ++i;
}
afterUse += i; afterUse += i;
} }
@ -182,8 +181,8 @@ namespace QTest {
int afterRemove = afterDecimalPoint.length() - afterUse; int afterRemove = afterDecimalPoint.length() - afterUse;
afterDecimalPoint.chop(afterRemove); afterDecimalPoint.chop(afterRemove);
QChar separator = QLatin1Char(','); QChar separator = u',';
QChar decimalPoint = QLatin1Char('.'); QChar decimalPoint = u'.';
// insert thousands separators // insert thousands separators
int length = beforeDecimalPoint.length(); int length = beforeDecimalPoint.length();

View File

@ -337,7 +337,7 @@ void QTapTestLogger::addIncident(IncidentTypes type, const char *description,
QString expected; QString expected;
QString actual; QString actual;
const auto parenthesize = [&match](QLatin1String key) -> QString { const auto parenthesize = [&match](QLatin1String key) -> QString {
return QLatin1String(" (") % match.captured(key) % QLatin1Char(')'); return QLatin1String(" (") % match.captured(key) % u')';
}; };
const QString actualExpression const QString actualExpression
= parenthesize(QLatin1String("actualexpression")); = parenthesize(QLatin1String("actualexpression"));

View File

@ -2328,7 +2328,7 @@ QSharedPointer<QTemporaryDir> QTest::qExtractTestData(const QString &dirName)
return result; return result;
const QString dataPath = tempDir->path(); const QString dataPath = tempDir->path();
const QString resourcePath = QLatin1Char(':') + dirName; const QString resourcePath = u':' + dirName;
const QFileInfo fileInfo(resourcePath); const QFileInfo fileInfo(resourcePath);
if (!fileInfo.isDir()) { if (!fileInfo.isDir()) {
@ -2346,7 +2346,7 @@ QSharedPointer<QTemporaryDir> QTest::qExtractTestData(const QString &dirName)
QFileInfo fileInfo = it.nextFileInfo(); QFileInfo fileInfo = it.nextFileInfo();
if (!fileInfo.isDir()) { if (!fileInfo.isDir()) {
const QString destination = dataPath + QLatin1Char('/') + QStringView{fileInfo.filePath()}.mid(resourcePath.length()); const QString destination = dataPath + u'/' + QStringView{fileInfo.filePath()}.mid(resourcePath.length());
QFileInfo destinationFileInfo(destination); QFileInfo destinationFileInfo(destination);
QDir().mkpath(destinationFileInfo.path()); QDir().mkpath(destinationFileInfo.path());
if (!QFile::copy(fileInfo.filePath(), destination)) { if (!QFile::copy(fileInfo.filePath(), destination)) {
@ -2391,7 +2391,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co
} }
#endif // Q_OS_WIN #endif // Q_OS_WIN
else if (QTestLog::verboseLevel() >= 2) { else if (QTestLog::verboseLevel() >= 2) {
const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + u'/' + base);
QTestLog::info(qPrintable( QTestLog::info(qPrintable(
QLatin1String("testdata %1 not found relative to test binary [%2]; " QLatin1String("testdata %1 not found relative to test binary [%2]; "
"checking next location").arg(base, candidate)), "checking next location").arg(base, candidate)),
@ -2456,7 +2456,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co
// 5. Try current directory // 5. Try current directory
if (found.isEmpty()) { if (found.isEmpty()) {
const QString candidate = QDir::currentPath() + QLatin1Char('/') + base; const QString candidate = QDir::currentPath() + u'/' + base;
if (QFileInfo::exists(candidate)) { if (QFileInfo::exists(candidate)) {
found = candidate; found = candidate;
} else if (QTestLog::verboseLevel() >= 2) { } else if (QTestLog::verboseLevel() >= 2) {
@ -2469,7 +2469,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co
// 6. Try main source directory // 6. Try main source directory
if (found.isEmpty()) { if (found.isEmpty()) {
const QString candidate = QTest::mainSourcePath % QLatin1Char('/') % base; const QString candidate = QTest::mainSourcePath % u'/' % base;
if (QFileInfo::exists(candidate)) { if (QFileInfo::exists(candidate)) {
found = candidate; found = candidate;
} else if (QTestLog::verboseLevel() >= 2) { } else if (QTestLog::verboseLevel() >= 2) {
@ -2482,7 +2482,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co
// 7. Try the supplied source directory // 7. Try the supplied source directory
if (found.isEmpty() && sourcedir) { if (found.isEmpty() && sourcedir) {
const QString candidate = QFile::decodeName(sourcedir) % QLatin1Char('/') % base; const QString candidate = QFile::decodeName(sourcedir) % u'/' % base;
if (QFileInfo::exists(candidate)) { if (QFileInfo::exists(candidate)) {
found = candidate; found = candidate;
} else if (QTestLog::verboseLevel() >= 2) { } else if (QTestLog::verboseLevel() >= 2) {

View File

@ -148,7 +148,7 @@ namespace QTest {
// ignore an optional whitespace at the end of str // ignore an optional whitespace at the end of str
// (the space was added automatically by ~QDebug() until Qt 5.3, // (the space was added automatically by ~QDebug() until Qt 5.3,
// so autotests still might expect it) // so autotests still might expect it)
if (expected.endsWith(QLatin1Char(' '))) if (expected.endsWith(u' '))
return actual == QStringView{expected}.left(expected.length() - 1); return actual == QStringView{expected}.left(expected.length() - 1);
return false; return false;
@ -328,10 +328,10 @@ void QTestLog::printUnhandledIgnoreMessages()
QTest::IgnoreResultList *list = QTest::ignoreResultList; QTest::IgnoreResultList *list = QTest::ignoreResultList;
while (list) { while (list) {
if (list->pattern.userType() == QMetaType::QString) { if (list->pattern.userType() == QMetaType::QString) {
message = QStringLiteral("Did not receive message: \"") + list->pattern.toString() + QLatin1Char('"'); message = QStringLiteral("Did not receive message: \"") + list->pattern.toString() + u'"';
} else { } else {
#if QT_CONFIG(regularexpression) #if QT_CONFIG(regularexpression)
message = QStringLiteral("Did not receive any message matching: \"") + list->pattern.toRegularExpression().pattern() + QLatin1Char('"'); message = QStringLiteral("Did not receive any message matching: \"") + list->pattern.toRegularExpression().pattern() + u'"';
#endif #endif
} }
FOREACH_TEST_LOGGER FOREACH_TEST_LOGGER