diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-09 14:25:26 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-07-10 07:07:30 +0200 |
commit | 72024fd50cdead8d890886dba32fd81ac54ff3ae (patch) | |
tree | 15a8e2183babb6ba22938622fa1c4300ee054599 /tests/auto/corelib/io | |
parent | 745448d3eaa178ff1b7b75bdd577ad31e9177cd6 (diff) |
Reduce repetitive invocations of QFINDTESTDATA.
Store the file names in variables instead.
Task-number: QTBUG-38890
Change-Id: I65f28bb62674f14aa099e935a9d7a4e9e6e90ba9
Reviewed-by: Joerg Bornemann <joerg.bornemann@digia.com>
Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
Diffstat (limited to 'tests/auto/corelib/io')
3 files changed, 35 insertions, 17 deletions
diff --git a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp index 515a10426c..230030d5cd 100644 --- a/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp +++ b/tests/auto/corelib/io/qresourceengine/tst_qresourceengine.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -47,6 +47,9 @@ class tst_QResourceEngine: public QObject { Q_OBJECT +public: + tst_QResourceEngine() : m_runtimeResourceRcc(QFINDTESTDATA("runtime_resource.rcc")) {} + private slots: void initTestCase(); void cleanupTestCase(); @@ -59,20 +62,24 @@ private slots: void searchPath(); void doubleSlashInRoot(); void setLocale(); + +private: + const QString m_runtimeResourceRcc; }; void tst_QResourceEngine::initTestCase() { - QVERIFY(QResource::registerResource(QFINDTESTDATA("runtime_resource.rcc"))); - QVERIFY(QResource::registerResource(QFINDTESTDATA("runtime_resource.rcc"), "/secondary_root/")); + QVERIFY(!m_runtimeResourceRcc.isEmpty()); + QVERIFY(QResource::registerResource(m_runtimeResourceRcc)); + QVERIFY(QResource::registerResource(m_runtimeResourceRcc, "/secondary_root/")); } void tst_QResourceEngine::cleanupTestCase() { // make sure we don't leak memory - QVERIFY(QResource::unregisterResource(QFINDTESTDATA("runtime_resource.rcc"))); - QVERIFY(QResource::unregisterResource(QFINDTESTDATA("runtime_resource.rcc"), "/secondary_root/")); + QVERIFY(QResource::unregisterResource(m_runtimeResourceRcc)); + QVERIFY(QResource::unregisterResource(m_runtimeResourceRcc, "/secondary_root/")); } void tst_QResourceEngine::checkStructure_data() diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index edf4dd2f00..74220d7f97 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -446,13 +446,15 @@ void tst_QTemporaryFile::rename() void tst_QTemporaryFile::renameFdLeak() { #ifdef Q_OS_UNIX + const QByteArray sourceFile = QFile::encodeName(QFINDTESTDATA(__FILE__)); + QVERIFY(!sourceFile.isEmpty()); // Test this on Unix only // Open a bunch of files to force the fd count to go up static const int count = 10; int bunch_of_files[count]; for (int i = 0; i < count; ++i) { - bunch_of_files[i] = ::open(qPrintable(QFINDTESTDATA("tst_qtemporaryfile.cpp")), O_RDONLY); + bunch_of_files[i] = ::open(sourceFile.constData(), O_RDONLY); QVERIFY(bunch_of_files[i] != -1); } @@ -647,8 +649,10 @@ void tst_QTemporaryFile::createNativeFile_data() QTest::addColumn<bool>("valid"); QTest::addColumn<QByteArray>("content"); - QTest::newRow("nativeFile") << QFINDTESTDATA("resources/test.txt") << (qint64)-1 << false << QByteArray(); - QTest::newRow("nativeFileWithPos") << QFINDTESTDATA("resources/test.txt") << (qint64)5 << false << QByteArray(); + const QString nativeFilePath = QFINDTESTDATA("resources/test.txt"); + + QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); + QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test"); QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test"); } diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 64d35ef154..15fd235048 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -245,6 +245,8 @@ private: QTemporaryDir tempDir; QString testFileName; + const QString m_rfc3261FilePath; + const QString m_shiftJisFilePath; }; void runOnExit() @@ -256,11 +258,16 @@ Q_DESTRUCTOR_FUNCTION(runOnExit) tst_QTextStream::tst_QTextStream() : tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX") + , m_rfc3261FilePath(QFINDTESTDATA("rfc3261.txt")) + , m_shiftJisFilePath(QFINDTESTDATA("shift-jis.txt")) { } void tst_QTextStream::initTestCase() { + QVERIFY(!m_rfc3261FilePath.isEmpty()); + QVERIFY(!m_shiftJisFilePath.isEmpty()); + testFileName = tempDir.path() + "/testfile"; // chdir into the testdata dir and refer to our helper apps with relative paths @@ -768,7 +775,7 @@ void tst_QTextStream::generateAllData(bool for_QString) // ------------------------------------------------------------------------------ void tst_QTextStream::readLineUntilNull() { - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); QTextStream stream(&file); @@ -887,7 +894,7 @@ void tst_QTextStream::lineCount_data() QTest::newRow("buffersize+1 line") << QByteArray(16384, '\n') << 16384; QTest::newRow("buffersize+2 line") << QByteArray(16385, '\n') << 16385; - QFile file(QFINDTESTDATA("rfc3261.txt")); file.open(QFile::ReadOnly); + QFile file(m_rfc3261FilePath); file.open(QFile::ReadOnly); QTest::newRow("rfc3261") << file.readAll() << 15067; } @@ -923,7 +930,7 @@ void tst_QTextStream::performance() stopWatch.restart(); int nlines1 = 0; - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); while (!file.atEnd()) { @@ -935,7 +942,7 @@ void tst_QTextStream::performance() stopWatch.restart(); int nlines2 = 0; - QFile file2(QFINDTESTDATA("rfc3261.txt")); + QFile file2(m_rfc3261FilePath); QVERIFY(file2.open(QFile::ReadOnly)); QTextStream stream(&file2); @@ -1155,7 +1162,7 @@ void tst_QTextStream::readNewlines() // ------------------------------------------------------------------------------ void tst_QTextStream::seek() { - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QFile::ReadOnly)); QTextStream stream(&file); @@ -1248,7 +1255,7 @@ void tst_QTextStream::pos() } { // Latin1 device - QFile file(QFINDTESTDATA("rfc3261.txt")); + QFile file(m_rfc3261FilePath); QVERIFY(file.open(QIODevice::ReadOnly)); QTextStream stream(&file); @@ -1280,7 +1287,7 @@ void tst_QTextStream::pos() { // Shift-JIS device for (int i = 0; i < 2; ++i) { - QFile file(QFINDTESTDATA("shift-jis.txt")); + QFile file(m_shiftJisFilePath); if (i == 0) QVERIFY(file.open(QIODevice::ReadOnly)); else |