From 3bdd59920fab954fd94a7b643042e1aaf7801674 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Thu, 29 Jun 2017 08:38:51 +0200 Subject: Refactor tst_qdir::entryList() Split the test in two: one test that requires the symlinks and test files and one that does not need them. In the test with test files, verify each step and the deletion of the files. Task-number: QTBUG-58654 Task-number: QTBUG-50835 Change-Id: I14de57ce7a1df2d834d5a7565c804dead1d89088 Reviewed-by: Oliver Wolff Reviewed-by: Thiago Macieira --- tests/auto/corelib/io/qdir/tst_qdir.cpp | 99 +++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 30 deletions(-) (limited to 'tests/auto/corelib/io/qdir') diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index da948849f6..e6bad9a8ef 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -93,6 +93,9 @@ private slots: void entryList_data(); void entryList(); + void entryListWithTestFiles_data(); + void entryListWithTestFiles(); + void entryListTimedSort(); void entryListSimple_data(); @@ -717,6 +720,32 @@ void tst_QDir::entryList_data() QTest::newRow("resources2") << QString(":/tst_qdir/resources/entryList") << QStringList("*.data") << (int)(QDir::Files) << (int)(QDir::NoSort) << QString("file1.data,file2.data,file3.data").split(','); +} + +void tst_QDir::entryList() +{ + QFETCH(QString, dirName); + QFETCH(QStringList, nameFilters); + QFETCH(int, filterspec); + QFETCH(int, sortspec); + QFETCH(QStringList, expected); + + QDir dir(dirName); + QVERIFY2(dir.exists(), msgDoesNotExist(dirName).constData()); + + QStringList actual = dir.entryList(nameFilters, (QDir::Filters)filterspec, + (QDir::SortFlags)sortspec); + + QCOMPARE(actual, expected); +} + +void tst_QDir::entryListWithTestFiles_data() +{ + QTest::addColumn("dirName"); // relative from current path or abs + QTest::addColumn("nameFilters"); + QTest::addColumn("filterspec"); + QTest::addColumn("sortspec"); + QTest::addColumn("expected"); QTest::newRow("nofilter") << (m_dataPath + "/entrylist/") << QStringList("*") << int(QDir::NoFilter) << int(QDir::Name) @@ -823,7 +852,7 @@ void tst_QDir::entryList_data() << QString("c,b,a,a.a,a.b,a.c,b.b,b.c,b.a,c.c,c.b,c.a,f.c,f.b,f.a,f,e.c,e.b,e.a,e,d.c,d.b,d.a,d").split(','); } -void tst_QDir::entryList() +void tst_QDir::entryListWithTestFiles() { QFETCH(QString, dirName); QFETCH(QStringList, nameFilters); @@ -831,28 +860,49 @@ void tst_QDir::entryList() QFETCH(int, sortspec); QFETCH(QStringList, expected); + QStringList testFiles; + QString entrylistPath = (m_dataPath + "/entrylist/"); - QFile(entrylistPath + "writable").open(QIODevice::ReadWrite); - QFile(entrylistPath + "file").setPermissions(QFile::ReadOwner | QFile::ReadUser); - QFile::remove(entrylistPath + "linktofile"); - QFile::remove(entrylistPath + "linktodirectory"); - QFile::remove(entrylistPath + "linktofile.lnk"); - QFile::remove(entrylistPath + "linktodirectory.lnk"); - QFile::remove(entrylistPath + "brokenlink.lnk"); - QFile::remove(entrylistPath + "brokenlink"); + + { + const QString writableFileName = entrylistPath + "writable"; + QFile writableFile(writableFileName); + testFiles.append(writableFileName); + + QVERIFY2(writableFile.open(QIODevice::ReadWrite), + qPrintable(writableFile.errorString())); + } + + { + QFile readOnlyFile(entrylistPath + "file"); + QVERIFY2(readOnlyFile.setPermissions(QFile::ReadOwner | QFile::ReadUser), + qPrintable(readOnlyFile.errorString())); + } + #ifndef Q_NO_SYMLINKS #if defined(Q_OS_WIN) // ### Sadly, this is a platform difference right now. // Note we are using capital L in entryList on one side here, to test case-insensitivity - QFile::link((m_dataPath + "/entryList/") + "file", entrylistPath + "linktofile.lnk"); - QFile::link((m_dataPath + "/entryList/") + "directory", entrylistPath + "linktodirectory.lnk"); - QFile::link((m_dataPath + "/entryList/") + "nothing", entrylistPath + "brokenlink.lnk"); + const QVector > symLinks = + { + {m_dataPath + "/entryList/file", entrylistPath + "linktofile.lnk"}, + {m_dataPath + "/entryList/directory", entrylistPath + "linktodirectory.lnk"}, + {m_dataPath + "/entryList/nothing", entrylistPath + "brokenlink.lnk"} + }; #else - QFile::link("file", entrylistPath + "linktofile.lnk"); - QFile::link("directory", entrylistPath + "linktodirectory.lnk"); - QFile::link("nothing", entrylistPath + "brokenlink.lnk"); + const QVector > symLinks = + { + {"file", entrylistPath + "linktofile.lnk"}, + {"directory", entrylistPath + "linktodirectory.lnk"}, + {"nothing", entrylistPath + "brokenlink.lnk"} + }; #endif + for (const auto &symLink : symLinks) { + QVERIFY2(QFile::link(symLink.first, symLink.second), + qPrintable(symLink.first + "->" + symLink.second)); + testFiles.append(symLink.second); + } #endif //Q_NO_SYMLINKS QDir dir(dirName); @@ -861,8 +911,6 @@ void tst_QDir::entryList() QStringList actual = dir.entryList(nameFilters, (QDir::Filters)filterspec, (QDir::SortFlags)sortspec); - int max = qMin(actual.count(), expected.count()); - bool doContentCheck = true; #if defined(Q_OS_UNIX) if (qstrcmp(QTest::currentDataTag(), "QDir::AllEntries | QDir::Writable") == 0) { @@ -872,20 +920,11 @@ void tst_QDir::entryList() } #endif - if (doContentCheck) { - for (int i=0; i= 0; --i) + QVERIFY2(QFile::remove(testFiles.at(i)), qPrintable(testFiles.at(i))); - QFile::remove(entrylistPath + "writable"); - QFile::remove(entrylistPath + "linktofile"); - QFile::remove(entrylistPath + "linktodirectory"); - QFile::remove(entrylistPath + "linktofile.lnk"); - QFile::remove(entrylistPath + "linktodirectory.lnk"); - QFile::remove(entrylistPath + "brokenlink.lnk"); - QFile::remove(entrylistPath + "brokenlink"); + if (doContentCheck) + QCOMPARE(actual, expected); } void tst_QDir::entryListTimedSort() -- cgit v1.2.3