diff options
Diffstat (limited to 'tests/auto/corelib/io')
13 files changed, 231 insertions, 11 deletions
diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 0542833456..470a1dde26 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -11,6 +11,7 @@ SUBDIRS=\ largefile \ qfileinfo \ qfileselector \ + qfilesystemmetadata \ qfilesystementry \ qfilesystemwatcher \ qiodevice \ @@ -59,9 +60,13 @@ SUBDIRS=\ win32:!qtConfig(private_tests): SUBDIRS -= \ qfilesystementry -winrt: SUBDIRS -= \ +!qtConfig(processenvironment): SUBDIRS -= \ + qprocessenvironment + +!qtConfig(process): SUBDIRS -= \ qprocess \ - qprocess-noapplication \ - qprocessenvironment \ + qprocess-noapplication + +winrt: SUBDIRS -= \ qstorageinfo \ qwinoverlappedionotifier diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index c3774997e9..b64de488ed 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -211,6 +211,9 @@ private slots: void cdBelowRoot_data(); void cdBelowRoot(); + void emptyDir(); + void nonEmptyDir(); + private: #ifdef BUILTIN_TESTDATA QString m_dataPath; @@ -2281,6 +2284,26 @@ void tst_QDir::cdBelowRoot() QCOMPARE(dir.path(), rootPath); } +void tst_QDir::emptyDir() +{ + const QString tempDir = QDir::currentPath() + "/tmpdir/"; + QVERIFY(QDir().mkdir(tempDir)); + QVERIFY(QDir(tempDir).mkdir("emptyDirectory")); + + QDir testDir(tempDir + "emptyDirectory"); + QVERIFY(testDir.isEmpty()); + QVERIFY(!testDir.isEmpty(QDir::AllEntries)); + QVERIFY(!testDir.isEmpty(QDir::AllEntries | QDir::NoDot)); + QVERIFY(!testDir.isEmpty(QDir::AllEntries | QDir::NoDotDot)); + QVERIFY(QDir(tempDir).removeRecursively()); +} + +void tst_QDir::nonEmptyDir() +{ + const QDir dir(m_dataPath); + QVERIFY(!dir.isEmpty()); +} + QTEST_MAIN(tst_QDir) #include "tst_qdir.moc" diff --git a/tests/auto/corelib/io/qfile/test/test.pro b/tests/auto/corelib/io/qfile/test/test.pro index c0c4b9d5d2..5f1963cf5f 100644 --- a/tests/auto/corelib/io/qfile/test/test.pro +++ b/tests/auto/corelib/io/qfile/test/test.pro @@ -1,5 +1,5 @@ CONFIG += testcase -CONFIG -= app_bundle debug_and_release_target +CONFIG -= debug_and_release_target QT = core-private core testlib qtHaveModule(network): QT += network else: DEFINES += QT_NO_NETWORK diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp index 34ad2813b0..57e197aa83 100644 --- a/tests/auto/corelib/io/qfile/tst_qfile.cpp +++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp @@ -1373,10 +1373,8 @@ void tst_QFile::copyFallback() #ifdef Q_OS_WIN #include <objbase.h> -#ifndef Q_OS_WINPHONE #include <shlobj.h> #endif -#endif #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) static QString getWorkingDirectoryForLink(const QString &linkFileName) diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index e5ede1ad06..8c2886f337 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -138,7 +138,7 @@ void tst_QFileSelector::basicTest_data() << QString(":/extras/test2"); QTest::newRow("custom1-withselector-nobasefile") << QString(":/extras/test3") << (QStringList() << custom1) - << QString(":/extras/test3"); + << QString(":/extras/+custom1/test3"); QString custom2("custom2"); QString custom3("custom3"); diff --git a/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro b/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro new file mode 100644 index 0000000000..a7d50ece43 --- /dev/null +++ b/tests/auto/corelib/io/qfilesystemmetadata/qfilesystemmetadata.pro @@ -0,0 +1,4 @@ +CONFIG += testcase parallel_test +TARGET = tst_qfilesystemmetadata +QT = core-private testlib +SOURCES = tst_qfilesystemmetadata.cpp diff --git a/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp new file mode 100644 index 0000000000..d17dffe830 --- /dev/null +++ b/tests/auto/corelib/io/qfilesystemmetadata/tst_qfilesystemmetadata.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtCore/private/qfilesystemmetadata_p.h> + +class tst_QFileSystemMetaData : public QObject +{ + Q_OBJECT + +private slots: + void timeSinceEpoch(); +}; + +#if defined(QT_BUILD_INTERNAL) && defined(QT_SHARED) +#ifdef Q_OS_WIN +static FILETIME epochToFileTime(long seconds) +{ + const qint64 sec = 10000000; + // FILETIME is time in 1e-7s units since 1601's start: epoch is 1970's + // start, 369 years (of which 3*24 +69/4 = 89 were leap) later. + const qint64 offset = qint64(365 * 369 + 89) * 24 * 3600; + const qint64 convert = (offset + seconds) * sec; + FILETIME parts; + parts.dwHighDateTime = convert >> 32; + parts.dwLowDateTime = convert & 0xffffffff; + return parts; +} +#endif + +void tst_QFileSystemMetaData::timeSinceEpoch() +{ + // Regression test for QTBUG-48306, used to fail for TZ=Russia/Moscow + // Oct 22 2014 6:00 UTC; TZ=Russia/Moscow changed from +4 to +3 on Oct 26. + const long afterEpochUtc = 1413957600L; + QFileSystemMetaData meta; +#ifdef Q_OS_WIN + WIN32_FIND_DATA data; + memset(&data, 0, sizeof(data)); + data.dwFileAttributes = FILE_ATTRIBUTE_NORMAL; + /* data.ftLastAccessTime = data.ftLastWriteTime = */ + data.ftCreationTime = epochToFileTime(afterEpochUtc); + meta.fillFromFindData(data); +#else + QT_STATBUF data; + memset(&data, 0, sizeof(data)); + data.st_ctime = afterEpochUtc; + meta.fillFromStatBuf(data); +#endif + QCOMPARE(meta.creationTime().toUTC(), + QDateTime::fromMSecsSinceEpoch(afterEpochUtc * qint64(1000), Qt::UTC)); +} +#else // i.e. no Q_AUTOTEST_EXPORT +void tst_QFileSystemMetaData::timeSinceEpoch() +{ + QSKIP("QFileSystemMetaData methods aren't available to test"); +} +#endif +QTEST_MAIN(tst_QFileSystemMetaData) +#include <tst_qfilesystemmetadata.moc> diff --git a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro index 7b83d5dbe8..7a304fe779 100644 --- a/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro +++ b/tests/auto/corelib/io/qlockfile/tst_qlockfile.pro @@ -1,5 +1,4 @@ CONFIG += testcase -CONFIG -= app_bundle TARGET = tst_qlockfile SOURCES += tst_qlockfile.cpp diff --git a/tests/auto/corelib/io/qprocess-noapplication/qprocess-noapplication.pro b/tests/auto/corelib/io/qprocess-noapplication/qprocess-noapplication.pro index e46e7e1100..8e46320e0c 100644 --- a/tests/auto/corelib/io/qprocess-noapplication/qprocess-noapplication.pro +++ b/tests/auto/corelib/io/qprocess-noapplication/qprocess-noapplication.pro @@ -1,4 +1,4 @@ CONFIG += testcase -CONFIG -= app_bundle debug_and_release_target +CONFIG -= debug_and_release_target QT = core testlib SOURCES = tst_qprocessnoapplication.cpp diff --git a/tests/auto/corelib/io/qprocess/test/test.pro b/tests/auto/corelib/io/qprocess/test/test.pro index 96d105a4b4..7d6a7973dc 100644 --- a/tests/auto/corelib/io/qprocess/test/test.pro +++ b/tests/auto/corelib/io/qprocess/test/test.pro @@ -1,5 +1,5 @@ CONFIG += testcase -CONFIG -= app_bundle debug_and_release_target +CONFIG -= debug_and_release_target QT = core-private testlib network SOURCES = ../tst_qprocess.cpp diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 199ab442c4..332c2dcc01 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -184,6 +184,7 @@ private slots: void embeddedZeroByte_data(); void embeddedZeroByte(); + void testXdg(); private: void cleanupTestFiles(); @@ -3565,5 +3566,77 @@ void tst_QSettings::consistentRegistryStorage() } #endif +#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN) && !defined(Q_OS_ANDROID) && !defined(QT_NO_STANDARDPATHS) +QT_BEGIN_NAMESPACE +extern void clearDefaultPaths(); +QT_END_NAMESPACE +#endif +void tst_QSettings::testXdg() +{ +#if defined(QT_BUILD_INTERNAL) && defined(Q_OS_UNIX) && !defined(Q_OS_DARWIN) && !defined(Q_OS_ANDROID) && !defined(QT_NO_STANDARDPATHS) + // Note: The XDG_CONFIG_DIRS test must be done before overriding the system path + // by QSettings::setPath/setSystemIniPath (used in cleanupTestFiles()). + clearDefaultPaths(); + + // Initialize the env. variable & populate testing files. + const QStringList config_dirs = { settingsPath("xdg_1st"), settingsPath("xdg_2nd"), settingsPath("xdg_3rd") }; + qputenv("XDG_CONFIG_DIRS", config_dirs.join(':').toUtf8()); + QList<QSettings *> xdg_orgs, xdg_apps; + for (const auto & dir : config_dirs) { + xdg_orgs << new QSettings{dir + "/software.org.conf", QSettings::NativeFormat}; + xdg_apps << new QSettings{dir + "/software.org/KillerAPP.conf", QSettings::NativeFormat}; + } + Q_ASSERT(config_dirs.size() == 3 && xdg_orgs.size() == 3 && xdg_apps.size() == 3); + for (int i = 0; i < 3; ++i) { + xdg_orgs[i]->setValue("all", QString{"all_org%1"}.arg(i)); + xdg_apps[i]->setValue("all", QString{"all_app%1"}.arg(i)); + xdg_orgs[i]->setValue("all_only_org", QString{"all_only_org%1"}.arg(i)); + xdg_apps[i]->setValue("all_only_app", QString{"all_only_app%1"}.arg(i)); + + if (i > 0) { + xdg_orgs[i]->setValue("from2nd", QString{"from2nd_org%1"}.arg(i)); + xdg_apps[i]->setValue("from2nd", QString{"from2nd_app%1"}.arg(i)); + xdg_orgs[i]->setValue("from2nd_only_org", QString{"from2nd_only_org%1"}.arg(i)); + xdg_apps[i]->setValue("from2nd_only_app", QString{"from2nd_only_app%1"}.arg(i)); + } + + if (i > 1) { + xdg_orgs[i]->setValue("from3rd", QString{"from3rd_org%1"}.arg(i)); + xdg_apps[i]->setValue("from3rd", QString{"from3rd_app%1"}.arg(i)); + xdg_orgs[i]->setValue("from3rd_only_org", QString{"from3rd_only_org%1"}.arg(i)); + xdg_apps[i]->setValue("from3rd_only_app", QString{"from3rd_only_app%1"}.arg(i)); + } + } + qDeleteAll(xdg_apps); + qDeleteAll(xdg_orgs); + + // Do the test. + QSettings app{QSettings::SystemScope, "software.org", "KillerAPP"}, org{QSettings::SystemScope, "software.org"}; + + QVERIFY(app.value("all").toString() == "all_app0"); + QVERIFY(org.value("all").toString() == "all_org0"); + QVERIFY(app.value("all_only_org").toString() == "all_only_org0"); + QVERIFY(org.value("all_only_org").toString() == "all_only_org0"); + QVERIFY(app.value("all_only_app").toString() == "all_only_app0"); + QVERIFY(org.value("all_only_app").toString() == QString{}); + + QVERIFY(app.value("from2nd").toString() == "from2nd_app1"); + QVERIFY(org.value("from2nd").toString() == "from2nd_org1"); + QVERIFY(app.value("from2nd_only_org").toString() == "from2nd_only_org1"); + QVERIFY(org.value("from2nd_only_org").toString() == "from2nd_only_org1"); + QVERIFY(app.value("from2nd_only_app").toString() == "from2nd_only_app1"); + QVERIFY(org.value("from2nd_only_app").toString() == QString{}); + + QVERIFY(app.value("from3rd").toString() == "from3rd_app2"); + QVERIFY(org.value("from3rd").toString() == "from3rd_org2"); + QVERIFY(app.value("from3rd_only_org").toString() == "from3rd_only_org2"); + QVERIFY(org.value("from3rd_only_org").toString() == "from3rd_only_org2"); + QVERIFY(app.value("from3rd_only_app").toString() == "from3rd_only_app2"); + QVERIFY(org.value("from3rd_only_app").toString() == QString{}); +#else + QSKIP("This test is performed in QT_BUILD_INTERNAL on Q_XDG_PLATFORM with use of standard paths only."); +#endif +} + QTEST_MAIN(tst_QSettings) #include "tst_qsettings.moc" diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index a7a761a2da..0a00e00d83 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -385,7 +385,7 @@ void tst_qstandardpaths::testFindExecutable_data() QTest::newRow("win-cmd-nosuffix") << QString() << QString::fromLatin1("cmd") << cmdPath; - if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS8) { + if (QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows8) { // The logo executable on Windows 8 is perfectly suited for testing that the // suffix mechanism is not thrown off by dots in the name. // Note: Requires disabling WOW64 redirection, see initTestCase() diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 487c13be94..758bbead84 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -57,6 +57,8 @@ private slots: void fileTemplate_data(); void getSetCheck(); void fileName(); + void filePath_data(); + void filePath(); void autoRemove(); void nonWritableCurrentDir(); void openOnRootDrives(); @@ -204,6 +206,29 @@ void tst_QTemporaryDir::fileName() QCOMPARE(absoluteFilePath, absoluteTempPath); } +void tst_QTemporaryDir::filePath_data() +{ + QTest::addColumn<QString>("templatePath"); + QTest::addColumn<QString>("fileName"); + + QTest::newRow("0") << QString() << "/tmpfile"; + QTest::newRow("1") << QString() << "tmpfile"; + QTest::newRow("2") << "XXXXX" << "tmpfile"; + QTest::newRow("3") << "YYYYY" << "subdir/file"; +} + +void tst_QTemporaryDir::filePath() +{ + QFETCH(QString, templatePath); + QFETCH(QString, fileName); + + QTemporaryDir dir(templatePath); + const QString filePath = dir.filePath(fileName); + const QString expectedFilePath = QDir::isAbsolutePath(fileName) ? + QString() : dir.path() + QLatin1Char('/') + fileName; + QCOMPARE(filePath, expectedFilePath); +} + void tst_QTemporaryDir::autoRemove() { // Test auto remove |