From a76a0afc1a23a54334070b08f8a4af5d1cc6676d Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 24 Jul 2018 16:59:11 +0200 Subject: Reduce redundancy and duplication in tst_QFile::appendAndRead Use one QStringLiteral instead of repeating a QLatin1String(), that was passed to a function that has to convert it to unicode; do the conversion at compile-time. Reducing i % 256 is fatuous when i ranges from 1 to 100. A QFile will close() itself on destruction, no need to do it explicitly. Especially when *not* close()ing the *other* QFile that was left open. Change-Id: Idb39312d9c9beaf082b7cead574bc6bb9bb3a775 Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qfile/tst_qfile.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tests/auto/corelib/io/qfile/tst_qfile.cpp') diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 2d01dbb90a..678a80c3f7 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -2759,19 +2759,20 @@ void tst_QFile::renameMultiple() void tst_QFile::appendAndRead() { - QFile writeFile(QLatin1String("appendfile.txt")); + const QString fileName(QStringLiteral("appendfile.txt")); + QFile writeFile(fileName); QVERIFY2(writeFile.open(QIODevice::Append | QIODevice::Truncate), msgOpenFailed(writeFile).constData()); - QFile readFile(QLatin1String("appendfile.txt")); + QFile readFile(fileName); QVERIFY2(readFile.open(QIODevice::ReadOnly), msgOpenFailed(readFile).constData()); // Write to the end of the file, then read that character back, and so on. for (int i = 0; i < 100; ++i) { char c = '\0'; - writeFile.putChar(char(i % 256)); + writeFile.putChar(char(i)); writeFile.flush(); QVERIFY(readFile.getChar(&c)); - QCOMPARE(c, char(i % 256)); + QCOMPARE(c, char(i)); QCOMPARE(readFile.pos(), writeFile.pos()); } @@ -2782,8 +2783,6 @@ void tst_QFile::appendAndRead() writeFile.flush(); QCOMPARE(readFile.read(size).size(), size); } - - readFile.close(); } void tst_QFile::miscWithUncPathAsCurrentDir() -- cgit v1.2.3