summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2017-02-21 15:05:29 +0100
committerDavid Faure <david.faure@kdab.com>2017-02-23 18:12:13 +0000
commit8cb9314971cdc61137855a6b374b4a4468dff7e7 (patch)
treed770cd46ab3b99021c653385f3bf6299472ddd6d /tests/auto/corelib
parent11790f41a70a8184a470f77e857f85b47481d7cb (diff)
tst_qurl: use temp dir and create our own files for testing
This allows to test specific filenames without polluting the current dir. Change-Id: Ieb99019a2e37e30f294d85c5d80af1de1b919019 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp47
1 files changed, 32 insertions, 15 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 01573e046e..e0e6c6f281 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -46,6 +46,7 @@ class tst_QUrl : public QObject
Q_OBJECT
private slots:
+ void initTestCase();
void effectiveTLDs_data();
void effectiveTLDs();
void getSetCheck();
@@ -182,8 +183,15 @@ private slots:
private:
void testThreadingHelper();
+
+ QTemporaryDir m_tempDir;
};
+void tst_QUrl::initTestCase()
+{
+ QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString()));
+}
+
// Testing get/set functions
void tst_QUrl::getSetCheck()
{
@@ -3062,26 +3070,35 @@ void tst_QUrl::fromUserInputWithCwd_data()
// Null
QTest::newRow("null") << QString() << QString() << QUrl() << QUrl();
- // Existing files
- const QString base = QDir::currentPath();
- QDirIterator it(base, QDir::NoDotDot | QDir::AllEntries);
- int c = 0;
- while (it.hasNext()) {
- it.next();
- QUrl url = QUrl::fromLocalFile(it.filePath());
- if (it.fileName() == QLatin1String(".")) {
- url = QUrl::fromLocalFile(base
+ // Use a tempdir with files, for testing specific file names
+ // We use canonicalPath() on the dir path because ::getcwd() canonicalizes,
+ // so we get a canonical base path for URLs with "." as working directory.
+ const QString base = QDir(m_tempDir.path()).canonicalPath();
+ QDir::setCurrent(base); // for the tests that use "." as working dir
+
+ // "."
+ {
+ const QUrl url = QUrl::fromLocalFile(base
#ifdef Q_OS_WINRT
+ QLatin1Char('/')
#endif
); // fromUserInput cleans the path
- }
- QTest::newRow(("file-" + QByteArray::number(c)).constData())
- << it.fileName() << base << url << url;
- QTest::newRow(("file-" + QByteArray::number(c) + "-dot").constData())
- << it.fileName() << QStringLiteral(".") << url << url;
- ++c;
+ QTest::newRow("dot-in-path") << "." << base << url << url;
+ QTest::newRow("dot-in-dot") << "." << QStringLiteral(".") << url << url;
}
+
+ // Existing files
+ for (const char *fileName : {"file.txt", "file#a.txt", "file .txt"}) {
+ const QString filePath = base + '/' + fileName;
+ QFile file(filePath);
+ QVERIFY2(file.open(QIODevice::WriteOnly), qPrintable(filePath));
+ file.write("Hello world\n");
+
+ const QUrl url = QUrl::fromLocalFile(filePath);
+ QTest::newRow(fileName) << fileName << base << url << url;
+ QTest::newRow(QByteArray(fileName) + "-in-dot") << fileName << QStringLiteral(".") << url << url;
+ }
+
#ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox
QDir parent(base);
QVERIFY(parent.cdUp());