From af8fa2794b4d1580ad69ac7de40761634cb0fa39 Mon Sep 17 00:00:00 2001 From: Rohan McGovern Date: Thu, 31 May 2012 11:16:10 +1000 Subject: [PATCH] Make tst_qtextstream parallel-safe. Write to a QTemporaryDir instead of the test's build directory. Change-Id: Ib65a0d58fbdf8caf8f2cb7002aeed1ce34742183 Reviewed-by: Toby Tomkins Reviewed-by: Kalle Lehtonen --- tests/auto/corelib/io/qtextstream/test/test.pro | 1 + .../corelib/io/qtextstream/tst_qtextstream.cpp | 28 +++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tests/auto/corelib/io/qtextstream/test/test.pro b/tests/auto/corelib/io/qtextstream/test/test.pro index 93fb6d2..df0bb13 100644 --- a/tests/auto/corelib/io/qtextstream/test/test.pro +++ b/tests/auto/corelib/io/qtextstream/test/test.pro @@ -1,4 +1,5 @@ CONFIG += testcase +CONFIG += parallel_test TARGET = ../tst_qtextstream QT = core network testlib SOURCES = ../tst_qtextstream.cpp diff --git a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp index 6e330fa..b22723a 100644 --- a/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp +++ b/tests/auto/corelib/io/qtextstream/tst_qtextstream.cpp @@ -50,14 +50,13 @@ #include #include #include +#include #include #include #include #include "../../../network-settings.h" -static const char *TestFileName = "testfile"; - Q_DECLARE_METATYPE(qlonglong) Q_DECLARE_METATYPE(qulonglong) Q_DECLARE_METATYPE(QList) @@ -71,6 +70,9 @@ class tst_QTextStream : public QObject { Q_OBJECT +public: + tst_QTextStream(); + public slots: void initTestCase(); void cleanup(); @@ -239,12 +241,22 @@ private: void generateRealNumbersData(bool for_QString); void generateStringData(bool for_QString); void generateRealNumbersDataWrite(); + + QTemporaryDir tempDir; + QString testFileName; }; +tst_QTextStream::tst_QTextStream() + : tempDir(QDir::tempPath() + "/tst_qtextstream.XXXXXX") +{ +} + void tst_QTextStream::initTestCase() { QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); + testFileName = tempDir.path() + "/testfile"; + // chdir into the testdata dir and refer to our helper apps with relative paths QString testdata_dir = QFileInfo(QFINDTESTDATA("stdinProcess")).absolutePath(); QVERIFY2(QDir::setCurrent(testdata_dir), qPrintable("Could not chdir to " + testdata_dir)); @@ -488,8 +500,8 @@ void tst_QTextStream::readLineFromDevice() QFETCH(QByteArray, data); QFETCH(QStringList, lines); - QFile::remove(TestFileName); - QFile file(TestFileName); + QFile::remove(testFileName); + QFile file(testFileName); QVERIFY(file.open(QFile::ReadWrite)); QCOMPARE(file.write(data), qlonglong(data.size())); QVERIFY(file.flush()); @@ -1340,7 +1352,7 @@ void tst_QTextStream::pos2() void tst_QTextStream::pos3LargeFile() { { - QFile file(TestFileName); + QFile file(testFileName); file.open(QIODevice::WriteOnly | QIODevice::Text); QTextStream out( &file ); // NOTE: The unusual spacing is to ensure non-1-character whitespace. @@ -1351,7 +1363,7 @@ void tst_QTextStream::pos3LargeFile() out << lineString; // File is automatically flushed and closed on destruction. } - QFile file(TestFileName); + QFile file(testFileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QTextStream in( &file ); const int testValues[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -1677,8 +1689,8 @@ void tst_QTextStream::utf8IncompleteAtBufferBoundary_data() void tst_QTextStream::utf8IncompleteAtBufferBoundary() { - QFile::remove(TestFileName); - QFile data(TestFileName); + QFile::remove(testFileName); + QFile data(testFileName); QTextCodec *utf8Codec = QTextCodec::codecForMib(106); QString lineContents = QString::fromUtf8("\342\200\223" // U+2013 EN DASH -- 2.7.4