diff options
author | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2016-01-08 12:30:57 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@theqtcompany.com> | 2016-01-08 12:35:24 +0100 |
commit | ad16478a76815f8f61d454bf7760aaf9ffbb4b51 (patch) | |
tree | eefdd9219cc9d59b62e042f49fc7555b980cb7a4 /tests/auto/corelib/io | |
parent | 80a741f3616290897ba0d9f1cbd3c9c5ee62da37 (diff) | |
parent | 09c92863001790a0304a5ef389901ee2b5b6cdc2 (diff) |
Merge remote-tracking branch 'origin/5.6' into dev
Based on merge done by Liang Qi
Change-Id: Id566e5b9f284d29bff2199f13f9417c660f5b26f
Diffstat (limited to 'tests/auto/corelib/io')
-rw-r--r-- | tests/auto/corelib/io/qfile/BLACKLIST | 4 | ||||
-rw-r--r-- | tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp | 23 | ||||
-rw-r--r-- | tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 19 | ||||
-rw-r--r-- | tests/auto/corelib/io/qurl/tst_qurl.cpp | 54 |
4 files changed, 83 insertions, 17 deletions
diff --git a/tests/auto/corelib/io/qfile/BLACKLIST b/tests/auto/corelib/io/qfile/BLACKLIST index 7aac313b12..e3bc093c83 100644 --- a/tests/auto/corelib/io/qfile/BLACKLIST +++ b/tests/auto/corelib/io/qfile/BLACKLIST @@ -3,3 +3,7 @@ msvc-2015 [readLineStdin_lineByLine] msvc-2015 +[openStandardStreamsFileDescriptors] +osx +[openStandardStreamsBufferedStreams] +osx diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 8a7ca8429f..3425c14cd4 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -464,6 +464,15 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() #endif #ifdef Q_XDG_PLATFORM + struct EnvVarRestorer + { + EnvVarRestorer() : origRuntimeDir(qgetenv("XDG_RUNTIME_DIR")) {} + ~EnvVarRestorer() { qputenv("XDG_RUNTIME_DIR", origRuntimeDir.constData()); } + const QByteArray origRuntimeDir; + }; + EnvVarRestorer restorer; + + // When $XDG_RUNTIME_DIR points to a directory with wrong ownership, QStandardPaths should warn qputenv("XDG_RUNTIME_DIR", QFile::encodeName("/tmp")); // It's very unlikely that /tmp is 0600 or that we can chmod it // The call below outputs @@ -474,6 +483,20 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() qPrintable(QString::fromLatin1("QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of %1").arg(uid))); const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir)); + + // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should warn (QTBUG-48771) + qputenv("XDG_RUNTIME_DIR", "does_not_exist"); + QTest::ignoreMessage(QtWarningMsg, "QStandardPaths: XDG_RUNTIME_DIR points to non-existing path 'does_not_exist', please create it with 0700 permissions."); + const QString nonExistingRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + QVERIFY2(nonExistingRuntimeDir.isEmpty(), qPrintable(nonExistingRuntimeDir)); + + // When $XDG_RUNTIME_DIR points to a file, QStandardPaths should warn + const QString file = QFINDTESTDATA("tst_qstandardpaths.cpp"); + QVERIFY(!file.isEmpty()); + qputenv("XDG_RUNTIME_DIR", QFile::encodeName(file)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QStandardPaths: XDG_RUNTIME_DIR points to '%1' which is not a directory").arg(file))); + const QString noRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + QVERIFY2(noRuntimeDir.isEmpty(), qPrintable(file)); #endif } diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 58a3db9615..621e215d60 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -229,6 +229,13 @@ void tst_QTemporaryDir::autoRemove() void tst_QTemporaryDir::nonWritableCurrentDir() { #ifdef Q_OS_UNIX + +# if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) + const char nonWritableDir[] = "/data"; +# else + const char nonWritableDir[] = "/home"; +# endif + if (::geteuid() == 0) QSKIP("not valid running this test as root"); @@ -240,13 +247,13 @@ void tst_QTemporaryDir::nonWritableCurrentDir() } QString dir; }; - ChdirOnReturn cor(QDir::currentPath()); -#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) - QDir::setCurrent("/data"); -#else - QDir::setCurrent("/home"); -#endif + const QFileInfo nonWritableDirFi = QFileInfo(QLatin1String(nonWritableDir)); + QVERIFY(nonWritableDirFi.isDir()); + QVERIFY(!nonWritableDirFi.isWritable()); + + ChdirOnReturn cor(QDir::currentPath()); + QVERIFY(QDir::setCurrent(nonWritableDirFi.absoluteFilePath())); // QTemporaryDir("tempXXXXXX") is probably a bad idea in any app // where the current dir could anything... QTemporaryDir dir("tempXXXXXX"); diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 97dfac3062..07257297e0 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -79,6 +79,8 @@ private slots: void toLocalFile(); void fromLocalFile_data(); void fromLocalFile(); + void fromLocalFileNormalize_data(); + void fromLocalFileNormalize(); void macTypes(); void relative(); void compat_legacy(); @@ -1242,16 +1244,6 @@ void tst_QUrl::fromLocalFile_data() << QString::fromLatin1("/"); QTest::newRow("data7") << QString::fromLatin1("/Mambo <#5>.mp3") << QString::fromLatin1("file:///Mambo <%235>.mp3") << QString::fromLatin1("/Mambo <#5>.mp3"); - QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt") - << QString::fromLatin1("/a%.txt"); - QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt") - << QString::fromLatin1("/a%25.txt"); - QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt") - << QString::fromLatin1("/%80.txt"); - QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("a.txt"); - QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("/a.txt"); } void tst_QUrl::fromLocalFile() @@ -1266,6 +1258,41 @@ void tst_QUrl::fromLocalFile() QCOMPARE(url.path(), thePath); } +void tst_QUrl::fromLocalFileNormalize_data() +{ + QTest::addColumn<QString>("theFile"); // should support the fromLocalFile/toLocalFile roundtrip (so no //host or windows path) + QTest::addColumn<QString>("theUrl"); + QTest::addColumn<QString>("urlWithNormalizedPath"); + + QTest::newRow("data0") << QString::fromLatin1("/a.txt") << QString::fromLatin1("file:///a.txt") << QString::fromLatin1("file:///a.txt"); + QTest::newRow("data1") << QString::fromLatin1("a.txt") << QString::fromLatin1("file:a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data8") << QString::fromLatin1("/a%.txt") << QString::fromLatin1("file:///a%25.txt") + << QString::fromLatin1("file:///a%25.txt"); + QTest::newRow("data9") << QString::fromLatin1("/a%25.txt") << QString::fromLatin1("file:///a%2525.txt") + << QString::fromLatin1("file:///a%2525.txt"); + QTest::newRow("data10") << QString::fromLatin1("/%80.txt") << QString::fromLatin1("file:///%2580.txt") + << QString::fromLatin1("file:///%2580.txt"); + QTest::newRow("data11") << QString::fromLatin1("./a.txt") << QString::fromLatin1("file:./a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data12") << QString::fromLatin1("././a.txt") << QString::fromLatin1("file:././a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data13") << QString::fromLatin1("b/../a.txt") << QString::fromLatin1("file:b/../a.txt") << QString::fromLatin1("file:a.txt"); + QTest::newRow("data14") << QString::fromLatin1("/b/../a.txt") << QString::fromLatin1("file:///b/../a.txt") << QString::fromLatin1("file:///a.txt"); + QTest::newRow("data15") << QString::fromLatin1("/b/.") << QString::fromLatin1("file:///b/.") << QString::fromLatin1("file:///b"); +} + +void tst_QUrl::fromLocalFileNormalize() +{ + QFETCH(QString, theFile); + QFETCH(QString, theUrl); + QFETCH(QString, urlWithNormalizedPath); + + QUrl url = QUrl::fromLocalFile(theFile); + + QCOMPARE(url.toString(QUrl::DecodeReserved), theUrl); + QCOMPARE(url.toLocalFile(), theFile); // roundtrip + QCOMPARE(url.path(), theFile); // works as well as long as we don't test windows paths + QCOMPARE(url.toString(QUrl::NormalizePathSegments), urlWithNormalizedPath); +} + void tst_QUrl::macTypes() { #ifndef Q_OS_MAC @@ -2961,6 +2988,9 @@ void tst_QUrl::fromUserInputWithCwd_data() while (it.hasNext()) { it.next(); QUrl url = QUrl::fromLocalFile(it.filePath()); + if (it.fileName() == QLatin1String(".")) { + url = QUrl::fromLocalFile(QDir::currentPath()); // fromUserInput cleans the path + } QTest::newRow(("file-" + QByteArray::number(c++)).constData()) << it.fileName() << QDir::currentPath() << url << url; } @@ -3023,6 +3053,8 @@ void tst_QUrl::fileName_data() << QString() << "tmp.txt" << "tmp.txt"; QTest::newRow("encoded") << "print:/specials/Print%20To%20File%20(PDF%252FAcrobat)" << "/specials/" << "Print To File (PDF%252FAcrobat)" << "Print To File (PDF%2FAcrobat)"; + QTest::newRow("endsWithDot") << "file:///temp/." + << "/temp/" << "." << "."; } void tst_QUrl::fileName() @@ -3515,7 +3547,7 @@ void tst_QUrl::setComponents_data() << PrettyDecoded << "/path" << "trash:/path"; QTest::newRow("path-withdotdot") << QUrl("file:///tmp") << int(Path) << "//tmp/..///root/." << Tolerant << true - << PrettyDecoded << "/root" << "file:///root"; + << PrettyDecoded << "/tmp/..///root/." << "file:///tmp/..///root/."; // the other fields can be present and be empty // that is, their delimiters would be present, but there would be nothing to one side |