Fix warnings in benchmarks from QFile::open being [[nodiscard]]

Change-Id: I8a80af3614a92645be2d64d02ce81e9d263468c8
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Volker Hilsheimer 2025-01-30 09:48:42 +01:00
parent 823c2bfc13
commit 1c3ee86f18
7 changed files with 21 additions and 20 deletions

View File

@ -27,7 +27,7 @@ public slots:
for (uint i=0; i<10000; ++i) {
QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i));
file.open(QIODevice::WriteOnly);
QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(file.fileName()));
}
}
void cleanupTestCase()

View File

@ -226,7 +226,7 @@ void tst_qfile::readBigFile()
switch (testType) {
case QFileBenchmark: {
QFile file(tempDir.filename);
file.open(QIODevice::ReadOnly|textMode|bufferedMode);
Q_UNUSED(file.open(QIODevice::ReadOnly|textMode|bufferedMode));
QBENCHMARK {
while(!file.atEnd())
file.read(blockSize);
@ -238,7 +238,7 @@ void tst_qfile::readBigFile()
#ifdef QT_BUILD_INTERNAL
case QFSFileEngineBenchmark: {
QFSFileEngine fse(tempDir.filename);
fse.open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt);
Q_UNUSED(fse.open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt));
QBENCHMARK {
//qWarning() << fse.supportsExtension(QAbstractFileEngine::AtEndExtension);
while (fse.read(buffer, blockSize)) {}
@ -313,7 +313,7 @@ void tst_qfile::seek()
switch (testType) {
case QFileBenchmark: {
QFile file(tempDir.filename);
file.open(QIODevice::ReadOnly);
Q_UNUSED(file.open(QIODevice::ReadOnly));
QBENCHMARK {
i=(i+1)%sp_size;
file.seek(seekpos[i]);
@ -324,7 +324,7 @@ void tst_qfile::seek()
#ifdef QT_BUILD_INTERNAL
case QFSFileEngineBenchmark: {
QFSFileEngine fse(tempDir.filename);
fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt);
Q_UNUSED(fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt));
QBENCHMARK {
i=(i+1)%sp_size;
fse.seek(seekpos[i]);
@ -392,7 +392,7 @@ void tst_qfile::open()
case QFileBenchmark: {
QBENCHMARK {
QFile file(tempDir.filename);
file.open(QIODevice::ReadOnly);
Q_UNUSED(file.open(QIODevice::ReadOnly));
file.close();
}
}
@ -401,7 +401,7 @@ void tst_qfile::open()
case QFSFileEngineBenchmark: {
QBENCHMARK {
QFSFileEngine fse(tempDir.filename);
fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt);
Q_UNUSED(fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt));
fse.close();
}
}
@ -503,7 +503,7 @@ void tst_qfile::readSmallFiles()
QList<QFile*> fileList;
for (const QString &file : files) {
QFile *f = new QFile(tempDir.filePath(file));
f->open(QIODevice::ReadOnly|textMode|bufferedMode);
Q_UNUSED(f->open(QIODevice::ReadOnly|textMode|bufferedMode));
fileList.append(f);
}
@ -525,7 +525,7 @@ void tst_qfile::readSmallFiles()
QList<QFSFileEngine*> fileList;
for (const QString &file : files) {
QFSFileEngine *fse = new QFSFileEngine(tempDir.filePath(file));
fse->open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt);
Q_UNUSED(fse->open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt));
fileList.append(fse);
}

View File

@ -41,7 +41,7 @@ void tst_QIODevice::read_old()
{
QFile file(name);
file.open(QIODevice::WriteOnly);
Q_UNUSED(file.open(QIODevice::WriteOnly));
file.seek(size);
file.write("x", 1);
file.close();
@ -49,7 +49,7 @@ void tst_QIODevice::read_old()
QBENCHMARK {
QFile file(name);
file.open(QIODevice::ReadOnly);
Q_UNUSED(file.open(QIODevice::ReadOnly));
QByteArray ba;
qint64 s = size - 1024;
file.seek(512);
@ -70,7 +70,7 @@ void tst_QIODevice::peekAndRead()
{
QFile file(name);
file.open(QIODevice::WriteOnly);
Q_UNUSED(file.open(QIODevice::WriteOnly));
file.seek(size);
file.write("x", 1);
file.close();
@ -78,7 +78,7 @@ void tst_QIODevice::peekAndRead()
QBENCHMARK {
QFile file(name);
file.open(QIODevice::ReadOnly);
Q_UNUSED(file.open(QIODevice::ReadOnly));
QByteArray ba(size / 1024, Qt::Uninitialized);
while (!file.atEnd()) {

View File

@ -34,7 +34,7 @@ void tst_QTemporaryFile::openclose()
QBENCHMARK {
for (qint64 i = 0; i < amount; ++i) {
QTemporaryFile file;
file.open();
Q_UNUSED(file.open());
file.close();
}
}
@ -50,7 +50,7 @@ void tst_QTemporaryFile::readwrite()
QBENCHMARK {
for (qint64 i = 0; i < amount; ++i) {
QTemporaryFile file;
file.open();
Q_UNUSED(file.open());
file.write(data);
file.seek(0);
file.read(dataSize);

View File

@ -56,7 +56,7 @@ void BenchmarkQtJson::parseNumbers()
QString testFile = QFINDTESTDATA("numbers.json");
QVERIFY2(!testFile.isEmpty(), "cannot find test file numbers.json!");
QFile file(testFile);
file.open(QFile::ReadOnly);
QVERIFY2(file.open(QFile::ReadOnly), "cannot open test file number.json!");
QByteArray testJson = file.readAll();
QBENCHMARK {
@ -70,7 +70,7 @@ void BenchmarkQtJson::parseJson()
QString testFile = QFINDTESTDATA("test.json");
QVERIFY2(!testFile.isEmpty(), "cannot find test file test.json!");
QFile file(testFile);
file.open(QFile::ReadOnly);
QVERIFY2(file.open(QFile::ReadOnly), "cannot open test file test.json!");
QByteArray testJson = file.readAll();
QBENCHMARK {
@ -84,7 +84,7 @@ void BenchmarkQtJson::parseJsonToVariant()
QString testFile = QFINDTESTDATA("test.json");
QVERIFY2(!testFile.isEmpty(), "cannot find test file test.json!");
QFile file(testFile);
file.open(QFile::ReadOnly);
QVERIFY2(file.open(QFile::ReadOnly), "cannot open test file test.json!");
QByteArray testJson = file.readAll();
QBENCHMARK {

View File

@ -83,7 +83,8 @@ void tst_LanceBench::initTestCase()
std::sort(qpsFiles.begin(), qpsFiles.end());
for (const QString& fileName : std::as_const(qpsFiles)) {
QFile file(scriptsDir + fileName);
file.open(QFile::ReadOnly);
QVERIFY2(file.open(QFile::ReadOnly),
qPrintable(QString::fromLatin1("Failed to open %1").arg(fileName)));
QByteArray cont = file.readAll();
scripts.insert(fileName, QString::fromUtf8(cont).split(QLatin1Char('\n'), Qt::SkipEmptyParts));
}

View File

@ -37,7 +37,7 @@ public:
void qfile_vs_qnetworkaccessmanager::initTestCase()
{
testFile.open();
QVERIFY2(testFile.open(), "Cannot open temporary file");
QByteArray qba(1*1024*1024, 'x'); // 1 MB
for (int i = 0; i < 100; i++) {
testFile.write(qba);