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 | |
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')
5 files changed, 61 insertions, 36 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 diff --git a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp index ce5e83288f..82f0a846bc 100644 --- a/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.cpp +++ b/tests/auto/corelib/kernel/qsharedmemory/test/tst_qsharedmemory.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. @@ -114,7 +114,7 @@ private slots: void uniqueKey(); protected: - QString helperBinary(); + static QString helperBinary(); int remove(const QString &key); QString rememberKey(const QString &key) @@ -131,10 +131,14 @@ protected: QStringList keys; QList<QSharedMemory*> jail; QSharedMemory *existingSharedMemory; + +private: + const QString m_helperBinary; }; -tst_QSharedMemory::tst_QSharedMemory() : - existingSharedMemory(0) +tst_QSharedMemory::tst_QSharedMemory() + : existingSharedMemory(0) + , m_helperBinary(tst_QSharedMemory::helperBinary()) { } @@ -144,7 +148,7 @@ tst_QSharedMemory::~tst_QSharedMemory() void tst_QSharedMemory::initTestCase() { - QVERIFY2(!helperBinary().isEmpty(), "Could not find helper binary"); + QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary"); } void tst_QSharedMemory::init() @@ -455,7 +459,7 @@ void tst_QSharedMemory::readOnly() rememberKey("readonly_segfault"); // ### on windows disable the popup somehow QProcess p; - p.start(helperBinary(), QStringList("readonly_segfault")); + p.start(m_helperBinary, QStringList("readonly_segfault")); p.setProcessChannelMode(QProcess::ForwardedChannels); p.waitForFinished(); QCOMPARE(p.error(), QProcess::Crashed); @@ -753,7 +757,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer() rememberKey("market"); QProcess producer; - producer.start(helperBinary(), QStringList("producer")); + producer.start(m_helperBinary, QStringList("producer")); QVERIFY2(producer.waitForStarted(), "Could not start helper binary"); QVERIFY2(producer.waitForReadyRead(), "Helper process failed to create shared memory segment: " + producer.readAllStandardError()); @@ -764,7 +768,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer() for (int i = 0; i < processes; ++i) { QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); - p->start(helperBinary(), consumerArguments); + p->start(m_helperBinary, consumerArguments); if (p->waitForStarted(2000)) consumers.append(p); else diff --git a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp index 9e33f56a34..42f2709384 100644 --- a/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.cpp +++ b/tests/auto/corelib/kernel/qsystemsemaphore/test/tst_qsystemsemaphore.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. @@ -80,17 +80,20 @@ private slots: #endif // QT_NO_PROCESS private: - QString helperBinary(); + static QString helperBinary(); QSystemSemaphore *existingLock; + + const QString m_helperBinary; }; tst_QSystemSemaphore::tst_QSystemSemaphore() + : m_helperBinary(helperBinary()) { } void tst_QSystemSemaphore::initTestCase() { - QVERIFY2(!helperBinary().isEmpty(), "Could not find helper binary"); + QVERIFY2(!m_helperBinary.isEmpty(), "Could not find helper binary"); } void tst_QSystemSemaphore::init() @@ -193,12 +196,12 @@ void tst_QSystemSemaphore::basicProcesses() QProcess release; release.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(helperBinary(), QStringList("acquire")); + acquire.start(m_helperBinary, QStringList("acquire")); QVERIFY2(acquire.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); QVERIFY(acquire.state() == QProcess::Running); acquire.kill(); - release.start(helperBinary(), QStringList("release")); + release.start(m_helperBinary, QStringList("release")); QVERIFY2(release.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); release.waitForFinished(HELPERWAITTIME); @@ -227,7 +230,7 @@ void tst_QSystemSemaphore::processes() QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); consumers.append(p); - p->start(helperBinary(), QStringList(scripts.at(i))); + p->start(m_helperBinary, QStringList(scripts.at(i))); } while (!consumers.isEmpty()) { @@ -247,14 +250,14 @@ void tst_QSystemSemaphore::undo() QStringList acquireArguments = QStringList("acquire"); QProcess acquire; acquire.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(helperBinary(), acquireArguments); + acquire.start(m_helperBinary, acquireArguments); QVERIFY2(acquire.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); // At process exit the kernel should auto undo - acquire.start(helperBinary(), acquireArguments); + acquire.start(m_helperBinary, acquireArguments); QVERIFY2(acquire.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); @@ -273,18 +276,18 @@ void tst_QSystemSemaphore::initialValue() QProcess release; release.setProcessChannelMode(QProcess::ForwardedChannels); - acquire.start(helperBinary(), acquireArguments); + acquire.start(m_helperBinary, acquireArguments); QVERIFY2(acquire.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); QVERIFY(acquire.state()== QProcess::NotRunning); - acquire.start(helperBinary(), acquireArguments << QLatin1String("2")); + acquire.start(m_helperBinary, acquireArguments << QLatin1String("2")); QVERIFY2(acquire.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); QVERIFY(acquire.state()== QProcess::Running); acquire.kill(); - release.start(helperBinary(), releaseArguments); + release.start(m_helperBinary, releaseArguments); QVERIFY2(release.waitForStarted(), "Could not start helper binary"); acquire.waitForFinished(HELPERWAITTIME); release.waitForFinished(HELPERWAITTIME); |