diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2018-07-24 16:59:11 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2018-07-30 15:04:40 +0000 |
commit | a76a0afc1a23a54334070b08f8a4af5d1cc6676d (patch) | |
tree | 49db8c4ed65deed0ebaf8c0f1ada60f0b06d6460 /tests | |
parent | cb505bedde4940d927b593ecc3668789e9f1c0a0 (diff) |
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 <thiago.macieira@intel.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qfile/tst_qfile.cpp | 11 |
1 files changed, 5 insertions, 6 deletions
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() |