From bef57b317f2efc0e73f2275d594be9d69f5a75d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sat, 31 Jul 2021 18:25:42 +0200 Subject: testlib: Deprecate QWARN() in favor of qWarning() The QtTest best practices documentations recommends using output mechanisms such as qDebug() and qWarning() for diagnostic messages, and this is also what most of our own tests do. The QWARN() macro and corresponding internal QTest::qWarn() function was added when QtTest was first implemented, but was likely meant as an internal implementation detail, like its cousin QTestLog::info(), which does not have any corresponding macro. This theory is backed by our own QtTest self-test (tst_silent) describing the output from QWARN() as "an internal testlib warning". The only difference between QWARN() and qWarning(), besides the much richer feature set of the latter, is that qWarning() will not pass on file and line number information in release mode, but QWARN() will. This is an acceptable loss of functionality, considering that the user can override this behavior by defining QT_MESSAGELOGCONTEXT. [ChangeLog][QtTest] QWARN() has been deprecated in favor of qWarning() Pick-to: 6.2 Change-Id: I5a2431ce48c47392244560dd520953b9fc735c85 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/largefile/tst_largefile.cpp | 11 +++++------ tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 6 +++--- tests/auto/corelib/io/qsettings/tst_qsettings.cpp | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index fcc0a31763..d05c5bca9f 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -299,7 +299,7 @@ void tst_LargeFile::createSparseFile() DWORD bytes; if (!::DeviceIoControl(handle, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &bytes, NULL)) { - QWARN("Unable to set test file as sparse. " + qWarning("Unable to set test file as sparse. " "Limiting test file to 16MiB."); maxSizeBits = 24; } @@ -347,11 +347,10 @@ void tst_LargeFile::fillFileSparsely() { if (failed) { this_->maxSizeBits = lastKnownGoodIndex; - QWARN( qPrintable( - QString("QFile::error %1: '%2'. Maximum size bits reset to %3.") - .arg(this_->largeFile.error()) - .arg(this_->largeFile.errorString()) - .arg(this_->maxSizeBits)) ); + qWarning("QFile::error %d: '%s'. Maximum size bits reset to %d.", + this_->largeFile.error(), + qPrintable(this_->largeFile.errorString()), + this_->maxSizeBits); } else lastKnownGoodIndex = qMax(index_, lastKnownGoodIndex); } diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 4d74fe4d98..461d2c03d4 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1360,7 +1360,7 @@ void tst_QFileInfo::isSymbolicLink_data() #if defined(Q_OS_WIN) const auto creationResult = FileSystem::createSymbolicLink("symlink", m_sourceFile); if (creationResult.dwErr == ERROR_PRIVILEGE_NOT_HELD) { - QWARN(msgInsufficientPrivileges(creationResult.errorMessage)); + qWarning() << qPrintable(msgInsufficientPrivileges(creationResult.errorMessage)); } else { QVERIFY2(creationResult.dwErr == ERROR_SUCCESS, qPrintable(creationResult.errorMessage)); QTest::newRow("NTFS-symlink") @@ -1423,7 +1423,7 @@ void tst_QFileInfo::link_data() #if defined(Q_OS_WIN) auto creationResult = FileSystem::createSymbolicLink("link", m_sourceFile); if (creationResult.dwErr == ERROR_PRIVILEGE_NOT_HELD) { - QWARN(msgInsufficientPrivileges(creationResult.errorMessage)); + qWarning() << qPrintable(msgInsufficientPrivileges(creationResult.errorMessage)); } else { QVERIFY2(creationResult.dwErr == ERROR_SUCCESS, qPrintable(creationResult.errorMessage)); QTest::newRow("link") @@ -1432,7 +1432,7 @@ void tst_QFileInfo::link_data() creationResult = FileSystem::createSymbolicLink("brokenlink", "dummyfile"); if (creationResult.dwErr == ERROR_PRIVILEGE_NOT_HELD) { - QWARN(msgInsufficientPrivileges(creationResult.errorMessage)); + qWarning() << qPrintable(msgInsufficientPrivileges(creationResult.errorMessage)); } else { QVERIFY2(creationResult.dwErr == ERROR_SUCCESS, qPrintable(creationResult.errorMessage)); QTest::newRow("broken link") diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 9ae8fcf61f..065e2b402b 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -2073,7 +2073,7 @@ void SettingsThread::run() settings.setValue(QString::number((param * NumIterations) + i), param); settings.sync(); if (settings.status() != QSettings::NoError) { - QWARN(qPrintable(QString("Unexpected QSettings status %1").arg((int)settings.status()))); + qWarning() << qPrintable(QString("Unexpected QSettings status %1").arg((int)settings.status())); ++numThreadSafetyFailures; } } -- cgit v1.2.3