From f05c597ae506ea6163394dbb6b70ecc77fae3b3c Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Fri, 11 Dec 2015 13:42:28 +0100 Subject: winrt: msvc2015: refactor file handling msvc2015 reintroduced a couple of functions from the win32 API towards WinRT. Enable usage of those and simplify the file system engine. Furthermore update the autotests. Change-Id: I9eafffba0ddfd05917c184c4a6b9e166f86d71d9 Reviewed-by: Oliver Wolff --- tests/auto/corelib/io/io.pro | 1 + tests/auto/corelib/io/largefile/tst_largefile.cpp | 12 ++++- .../tst_qabstractfileengine.cpp | 13 +++++ .../corelib/io/qdatastream/tst_qdatastream.cpp | 15 ++++++ tests/auto/corelib/io/qdir/qdir.pro | 3 ++ tests/auto/corelib/io/qdir/tst_qdir.cpp | 57 +++++++++++++++++----- .../auto/corelib/io/qdiriterator/qdiriterator.pro | 1 + .../corelib/io/qdiriterator/tst_qdiriterator.cpp | 15 +++++- tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 29 +++++++---- .../qfileselector/platforms/+windows/+winrt/test | 0 .../corelib/io/qfileselector/platforms/+winrt/test | 0 .../io/qfileselector/platforms/+winrt/test2 | 0 .../corelib/io/qfileselector/qfileselector.qrc | 3 ++ .../corelib/io/qfileselector/tst_qfileselector.cpp | 2 +- tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp | 14 ++++++ .../io/qloggingregistry/qloggingregistry.pro | 1 + .../io/qstandardpaths/tst_qstandardpaths.cpp | 5 +- .../corelib/io/qtemporarydir/tst_qtemporarydir.cpp | 7 ++- .../io/qtemporaryfile/tst_qtemporaryfile.cpp | 14 +++++- tests/auto/corelib/io/qurl/tst_qurl.cpp | 8 ++- 20 files changed, 171 insertions(+), 29 deletions(-) create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+windows/+winrt/test create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+winrt/test create mode 100644 tests/auto/corelib/io/qfileselector/platforms/+winrt/test2 (limited to 'tests/auto/corelib') diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 24592238bd..29717b3a1c 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -63,4 +63,5 @@ winrt: SUBDIRS -= \ qprocess \ qprocess-noapplication \ qprocessenvironment \ + qstorageinfo \ qwinoverlappedionotifier diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp index 0a28ee7b9c..afbb307f03 100644 --- a/tests/auto/corelib/io/largefile/tst_largefile.cpp +++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp @@ -70,7 +70,7 @@ public: , fd_(-1) , stream_(0) { - #if defined(QT_LARGEFILE_SUPPORT) && !defined(Q_OS_MAC) + #if defined(QT_LARGEFILE_SUPPORT) && !defined(Q_OS_MAC) && !defined(Q_OS_WINRT) maxSizeBits = 36; // 64 GiB #elif defined(Q_OS_MAC) // HFS+ does not support sparse files, so we limit file size for the test @@ -135,6 +135,9 @@ private: int fd_; FILE *stream_; + + QSharedPointer m_tempDir; + QString m_previousCurrent; }; /* @@ -229,6 +232,11 @@ QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position) void tst_LargeFile::initTestCase() { + m_previousCurrent = QDir::currentPath(); + m_tempDir = QSharedPointer(new QTemporaryDir); + QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory.")); + QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory")); + QFile file("qt_largefile.tmp"); QVERIFY( !file.exists() || file.remove() ); } @@ -240,6 +248,8 @@ void tst_LargeFile::cleanupTestCase() QFile file("qt_largefile.tmp"); QVERIFY( !file.exists() || file.remove() ); + + QDir::setCurrent(m_previousCurrent); } void tst_LargeFile::init() diff --git a/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp b/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp index 977c396e21..8c4c8b48d7 100644 --- a/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp +++ b/tests/auto/corelib/io/qabstractfileengine/tst_qabstractfileengine.cpp @@ -52,6 +52,7 @@ class tst_QAbstractFileEngine { Q_OBJECT public slots: + void initTestCase(); void cleanupTestCase(); private slots: @@ -64,6 +65,8 @@ private slots: void mounting(); private: QStringList filesForRemoval; + QSharedPointer m_currentDir; + QString m_previousCurrent; }; class ReferenceFileEngine @@ -563,6 +566,14 @@ class FileEngineHandler } }; +void tst_QAbstractFileEngine::initTestCase() +{ + m_previousCurrent = QDir::currentPath(); + m_currentDir = QSharedPointer(new QTemporaryDir()); + QVERIFY2(!m_currentDir.isNull(), qPrintable("Could not create current directory.")); + QDir::setCurrent(m_currentDir->path()); +} + void tst_QAbstractFileEngine::cleanupTestCase() { bool failed = false; @@ -576,6 +587,8 @@ void tst_QAbstractFileEngine::cleanupTestCase() } QVERIFY(!failed); + + QDir::setCurrent(m_previousCurrent); } void tst_QAbstractFileEngine::customHandler() diff --git a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp index d9d3f55d4a..86fd142036 100644 --- a/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp +++ b/tests/auto/corelib/io/qdatastream/tst_qdatastream.cpp @@ -50,6 +50,7 @@ public: void stream_data(int noOfElements); public slots: + void initTestCase(); void cleanupTestCase(); private slots: @@ -243,6 +244,10 @@ private: void readqint64(QDataStream *s); void readQIcon(QDataStream *s); void readQEasingCurve(QDataStream *s); + +private: + QSharedPointer m_tempDir; + QString m_previousCurrent; }; static int NColorRoles[] = { @@ -293,10 +298,20 @@ void tst_QDataStream::getSetCheck() QCOMPARE(QDataStream::ReadCorruptData, obj1.status()); } +void tst_QDataStream::initTestCase() +{ + m_previousCurrent = QDir::currentPath(); + m_tempDir = QSharedPointer(new QTemporaryDir); + QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory.")); + QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory")); +} + void tst_QDataStream::cleanupTestCase() { QFile::remove(QLatin1String("qdatastream.out")); QFile::remove(QLatin1String("datastream.tmp")); + + QDir::setCurrent(m_previousCurrent); } static int dataIndex(const QString &tag) diff --git a/tests/auto/corelib/io/qdir/qdir.pro b/tests/auto/corelib/io/qdir/qdir.pro index 0adc7e0450..65cfd3faa9 100644 --- a/tests/auto/corelib/io/qdir/qdir.pro +++ b/tests/auto/corelib/io/qdir/qdir.pro @@ -5,6 +5,9 @@ SOURCES = tst_qdir.cpp RESOURCES += qdir.qrc TESTDATA += testdir testData searchdir resources entrylist types tst_qdir.cpp + +contains(CONFIG, builtin_testdata): DEFINES += BUILTIN_TESTDATA + DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 android:!android-no-sdk { diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp index ae6fe7eaef..ad49678245 100644 --- a/tests/auto/corelib/io/qdir/tst_qdir.cpp +++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp @@ -56,7 +56,7 @@ # include #endif -#if defined(Q_OS_VXWORKS) +#if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT) #define Q_NO_SYMLINKS #endif @@ -216,7 +216,12 @@ private slots: void cdBelowRoot(); private: +#ifdef BUILTIN_TESTDATA + QString m_dataPath; + QSharedPointer m_dataDir; +#else const QString m_dataPath; +#endif }; Q_DECLARE_METATYPE(tst_QDir::UncHandling) @@ -224,7 +229,7 @@ Q_DECLARE_METATYPE(tst_QDir::UncHandling) tst_QDir::tst_QDir() #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) : m_dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) -#else +#elif !defined(BUILTIN_TESTDATA) : m_dataPath(QFileInfo(QFINDTESTDATA("testData")).absolutePath()) #endif { @@ -261,12 +266,23 @@ void tst_QDir::init() void tst_QDir::initTestCase() { +#ifdef BUILTIN_TESTDATA + m_dataDir = QEXTRACTTESTDATA("/"); + QVERIFY2(!m_dataDir.isNull(), qPrintable("Did not find testdata. Is this builtin?")); + m_dataPath = m_dataDir->path(); +#endif + QVERIFY2(!m_dataPath.isEmpty(), "test data not found"); } void tst_QDir::cleanupTestCase() { +#ifdef BUILTIN_TESTDATA + // We need to reset the current directory outside of QTemporaryDir for successful deletion + QDir::setCurrent(QCoreApplication::applicationDirPath()); +#else QDir(QDir::currentPath() + "/tmpdir").removeRecursively(); +#endif } // Testing get/set functions @@ -532,7 +548,7 @@ void tst_QDir::exists_data() QTest::newRow("simple dir") << (m_dataPath + "/resources") << true; QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << true; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -544,7 +560,7 @@ void tst_QDir::exists_data() QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; #endif -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) QTest::newRow("This drive should exist") << "C:/" << true; // find a non-existing drive and check if it does not exist #ifdef QT_BUILD_INTERNAL @@ -897,7 +913,7 @@ void tst_QDir::entryListSimple_data() QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 2; #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << 2; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2; @@ -980,7 +996,6 @@ void tst_QDir::canonicalPath_data() QTest::newRow("relative") << "." << m_dataPath; QTest::newRow("relativeSubDir") << "./testData/../testData" << m_dataPath + "/testData"; - #ifndef Q_OS_WIN QTest::newRow("absPath") << m_dataPath + "/testData/../testData" << m_dataPath + "/testData"; #else @@ -1179,7 +1194,7 @@ tst_QDir::cleanPath_data() QTest::newRow("data10") << "/:/" << "/:"; #endif #endif -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QTest::newRow("data11") << "//foo//bar" << "//foo/bar"; #endif QTest::newRow("data12") << "ab/a/" << "ab/a"; // Path item with length of 2 @@ -1191,11 +1206,13 @@ tst_QDir::cleanPath_data() QTest::newRow("data14") << "c://foo" << "c:/foo"; // Drive letters and unc path in one string +#ifndef Q_OS_WINRT #ifdef Q_OS_WIN QTest::newRow("data15") << "//c:/foo" << "//c:/foo"; #else QTest::newRow("data15") << "//c:/foo" << "/c:/foo"; #endif +#endif // !Q_OS_WINRT QTest::newRow("QTBUG-23892_0") << "foo/.." << "."; QTest::newRow("QTBUG-23892_1") << "foo/../" << "."; @@ -1314,7 +1331,7 @@ void tst_QDir::absoluteFilePath_data() QTest::newRow("2") << "/" << "passwd" << "/passwd"; QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path"; QTest::newRow("4") << "" << "" << QDir::currentPath(); -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QTest::newRow("5") << "//machine" << "share" << "//machine/share"; #endif @@ -1338,7 +1355,7 @@ void tst_QDir::absolutePath_data() QTest::addColumn("expectedPath"); QTest::newRow("0") << "/machine/share/dir1" << "/machine/share/dir1"; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) QTest::newRow("1") << "\\machine\\share\\dir1" << "/machine/share/dir1"; QTest::newRow("2") << "//machine/share/dir1" << "//machine/share/dir1"; QTest::newRow("3") << "\\\\machine\\share\\dir1" << "//machine/share/dir1"; @@ -1406,10 +1423,12 @@ void tst_QDir::relativeFilePath_data() QTest::newRow("27") << "C:" << "D:/" << "D:/"; QTest::newRow("28") << "C:/" << "D:" << "D:"; QTest::newRow("29") << "C:/" << "D:/" << "D:/"; +#ifndef Q_OS_WINRT QTest::newRow("30") << "C:/foo/bar" << "//anotherHost/foo/bar" << "//anotherHost/foo/bar"; QTest::newRow("31") << "//anotherHost/foo" << "//anotherHost/foo/bar" << "bar"; QTest::newRow("32") << "//anotherHost/foo" << "bar" << "bar"; QTest::newRow("33") << "//anotherHost/foo" << "C:/foo/bar" << "C:/foo/bar"; +#endif // !Q_OS_WINRT #endif QTest::newRow("resource0") << ":/prefix" << "foo.bar" << "foo.bar"; @@ -1594,7 +1613,11 @@ void tst_QDir::homePath() qputenv("HOME", envHome); #elif defined(Q_OS_WIN) - if (strHome.length() > 3) // root dir = "c:/"; "//" is not really valid... + if (strHome.length() > 3 // root dir = "c:/"; "//" is not really valid... +#if defined(Q_OS_WINRT) + && strHome.length() > QDir::rootPath().length() +#endif + ) QVERIFY(!strHome.endsWith('/')); #endif @@ -2059,6 +2082,9 @@ void tst_QDir::drives() QVERIFY(list.count() >= 1); //system QLatin1Char systemdrive('c'); #endif +#if defined(Q_OS_WINRT) + QSKIP("WinRT has no concept of drives"); +#endif #if defined(Q_OS_WIN) QVERIFY(list.count() <= 26); bool foundsystem = false; @@ -2115,7 +2141,9 @@ void tst_QDir::equalityOperator_data() << true; //need a path in the root directory that is unlikely to be a symbolic link. -#if defined (Q_OS_WIN) +#if defined (Q_OS_WINRT) + QString pathinroot(QDir::rootPath() + QLatin1String("assets/..")); +#elif defined (Q_OS_WIN) QString pathinroot("c:/windows/.."); #elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) QString pathinroot("/system/.."); @@ -2246,6 +2274,10 @@ void tst_QDir::cdBelowRoot() #define ROOT QString("/") #define DIR QString("/tmp") #define CD_INTO "tmp" +#elif defined (Q_OS_WINRT) +#define ROOT QDir::rootPath() +#define DIR QDir::rootPath() +#define CD_INTO QDir::rootPath() #else #define ROOT QString::fromLocal8Bit(qgetenv("SystemDrive"))+"/" #define DIR QString::fromLocal8Bit(qgetenv("SystemRoot")).replace('\\', '/') @@ -2260,6 +2292,9 @@ void tst_QDir::cdBelowRoot() #ifdef Q_OS_UNIX if (::getuid() == 0) QSKIP("Running this test as root doesn't make sense"); +#endif +#ifdef Q_OS_WINRT + QSKIP("WinRT has no concept of system root"); #endif QDir dir(DIR); QVERIFY(!dir.cd("../..")); diff --git a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro index a2429bf2f0..51bfcb36a5 100644 --- a/tests/auto/corelib/io/qdiriterator/qdiriterator.pro +++ b/tests/auto/corelib/io/qdiriterator/qdiriterator.pro @@ -5,6 +5,7 @@ SOURCES = tst_qdiriterator.cpp RESOURCES += qdiriterator.qrc TESTDATA += entrylist +contains(CONFIG, builtin_testdata): DEFINES += BUILTIN_TESTDATA wince*mips*|wincewm50smart-msvc200*: DEFINES += WINCE_BROKEN_ITERATE=1 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp index 6b1719ad53..554771f4d2 100644 --- a/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp +++ b/tests/auto/corelib/io/qdiriterator/tst_qdiriterator.cpp @@ -42,7 +42,7 @@ #include -#if defined(Q_OS_VXWORKS) +#if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT) #define Q_NO_SYMLINKS #endif @@ -115,6 +115,10 @@ private slots: #ifndef Q_OS_WIN void hiddenDirs_hiddenFiles(); #endif +#ifdef BUILTIN_TESTDATA +private: + QSharedPointer m_dataDir; +#endif }; void tst_QDirIterator::initTestCase() @@ -141,6 +145,10 @@ void tst_QDirIterator::initTestCase() } testdata_dir += QStringLiteral("/entrylist"); +#elif defined(BUILTIN_TESTDATA) + m_dataDir = QEXTRACTTESTDATA("/"); + QVERIFY2(!m_dataDir.isNull(), qPrintable("Could not extract test data")); + QString testdata_dir = m_dataDir->path(); #else // chdir into testdata directory, then find testdata by relative paths. @@ -217,6 +225,11 @@ void tst_QDirIterator::cleanupTestCase() Q_FOREACH(QString dirName, createdDirectories) currentDir.rmdir(dirName); + +#ifdef Q_OS_WINRT + QDir::setCurrent(QCoreApplication::applicationDirPath()); +#endif // Q_OS_WINRT + } void tst_QDirIterator::iterateRelativeDirectory_data() diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 210fdb5a12..d2c43f79d6 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -66,7 +66,7 @@ #include #include "../../../../shared/filesystem.h" -#if defined(Q_OS_VXWORKS) +#if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT) #define Q_NO_SYMLINKS #endif @@ -427,12 +427,12 @@ void tst_QFileInfo::isDir_data() QTest::newRow("broken link") << "brokenlink.lnk" << false; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) QTest::newRow("drive 1") << "c:" << true; QTest::newRow("drive 2") << "c:/" << true; //QTest::newRow("drive 2") << "t:s" << false; #endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName(); QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true; @@ -469,7 +469,7 @@ void tst_QFileInfo::isRoot_data() QTest::newRow("simple dir") << m_resourcesDir << false; QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << false; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) QTest::newRow("drive 1") << "c:" << false; QTest::newRow("drive 2") << "c:/" << true; QTest::newRow("drive 3") << "p:/" << false; @@ -513,7 +513,12 @@ void tst_QFileInfo::exists_data() QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false; QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false; QTest::newRow("data10") << "." << true; + + // Skip for the WinRT case, as GetFileAttributesEx removes _any_ + // trailing whitespace and "." is a valid entry as seen in data10 +#ifndef Q_OS_WINRT QTest::newRow("data11") << ". " << false; +#endif QTest::newRow("empty") << "" << false; QTest::newRow("simple dir") << m_resourcesDir << true; @@ -554,7 +559,7 @@ void tst_QFileInfo::absolutePath_data() QTest::addColumn("filename"); QString drivePrefix; -#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) +#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)) drivePrefix = QDir::currentPath().left(2); QString nonCurrentDrivePrefix = drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:"); @@ -564,6 +569,8 @@ void tst_QFileInfo::absolutePath_data() QTest::newRow(":my.dll") << nonCurrentDrivePrefix + "my.dll" << nonCurrentDrivePrefix + "/" << "my.dll"; +#elif defined(Q_OS_WINRT) + drivePrefix = QDir::currentPath().left(2); #endif QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << ""; QTest::newRow("1") << "/machine/share/dir1" << drivePrefix + "/machine/share" << "dir1"; @@ -571,7 +578,7 @@ void tst_QFileInfo::absolutePath_data() QTest::newRow("3") << "/usr/local/bin/" << drivePrefix + "/usr/local/bin" << ""; QTest::newRow("/test") << "/test" << drivePrefix + "/" << "test"; -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) +#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/" << "autoexec.bat"; QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath() @@ -735,7 +742,7 @@ void tst_QFileInfo::canonicalFilePath() } #endif -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) typedef BOOL (WINAPI *PtrCreateSymbolicLink)(LPTSTR, LPTSTR, DWORD); PtrCreateSymbolicLink ptrCreateSymbolicLink = (PtrCreateSymbolicLink)QLibrary::resolve(QLatin1String("kernel32"), "CreateSymbolicLinkW"); @@ -831,7 +838,7 @@ void tst_QFileInfo::dir_data() QTest::newRow("absFilePath") << QDir::currentPath() + "/tmp.txt" << false << QDir::currentPath(); QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath(); QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << true << ":/tst_qfileinfo/resources"; -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QTest::newRow("driveWithSlash") << "C:/file1.ext1.ext2" << true << "C:/"; QTest::newRow("driveWithoutSlash") << QDir::currentPath().left(2) + "file1.ext1.ext2" << false << QDir::currentPath().left(2); #endif @@ -1022,7 +1029,7 @@ void tst_QFileInfo::size() void tst_QFileInfo::systemFiles() { -#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) +#if !defined(Q_OS_WIN) || defined(Q_OS_WINCE) || defined(Q_OS_WINRT) QSKIP("This is a Windows only test"); #endif QFileInfo fi("c:\\pagefile.sys"); @@ -1193,6 +1200,8 @@ void tst_QFileInfo::fileTimes() #endif #if defined(Q_OS_WINCE) QEXPECT_FAIL("simple", "WinCE only stores date of access data, not the time", Continue); +#elif defined(Q_OS_WINRT) + QEXPECT_FAIL("", "WinRT does not allow timestamp handling change in the filesystem due to sandboxing", Continue); #elif defined(Q_OS_QNX) QEXPECT_FAIL("", "QNX uses the noatime filesystem option", Continue); #elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) @@ -1628,7 +1637,7 @@ void tst_QFileInfo::isWritable() QVERIFY(QFileInfo("tempfile.txt").isWritable()); tempfile.remove(); -#ifdef Q_OS_WIN +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) #ifdef Q_OS_WINCE QFileInfo fi("\\Windows\\wince.nls"); #else diff --git a/tests/auto/corelib/io/qfileselector/platforms/+windows/+winrt/test b/tests/auto/corelib/io/qfileselector/platforms/+windows/+winrt/test new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+winrt/test b/tests/auto/corelib/io/qfileselector/platforms/+winrt/test new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/platforms/+winrt/test2 b/tests/auto/corelib/io/qfileselector/platforms/+winrt/test2 new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc index 6e2699774d..37bd397c9d 100644 --- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc +++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc @@ -24,6 +24,7 @@ platforms/+unix/test platforms/+windows/+wince/test platforms/+windows/+winnt/test + platforms/+windows/+winrt/test platforms/+windows/test platforms/+android/test platforms/+blackberry/test @@ -34,6 +35,7 @@ platforms/+haiku/test platforms/+linux/test platforms/+wince/test + platforms/+winrt/test platforms/test2 @@ -45,6 +47,7 @@ platforms/+linux/test2 platforms/+wince/test2 platforms/+winnt/test2 + platforms/+winrt/test2 platforms/test3 diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp index 87381f4c4e..112aca224c 100644 --- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp +++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp @@ -99,7 +99,7 @@ void tst_QFileSelector::basicTest_data() expectedPlatform2File = QString(":/platforms/test2"); #else QString distributionName; -# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD) +# if (defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)) || defined(Q_OS_FREEBSD) || defined(Q_OS_WINRT) distributionName = QSysInfo::productType(); # endif foreach (const QString &selector, QFileSelectorPrivate::platformSelectors()) { diff --git a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp index f637ffcfc5..0fdddd1180 100644 --- a/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp +++ b/tests/auto/corelib/io/qiodevice/tst_qiodevice.cpp @@ -43,6 +43,7 @@ class tst_QIODevice : public QObject private slots: void initTestCase(); + void cleanupTestCase(); void getSetCheck(); void constructing_QTcpSocket(); void constructing_QFile(); @@ -60,6 +61,10 @@ private slots: void peekBug(); void readAllKeepPosition(); void writeInTextMode(); + +private: + QSharedPointer m_tempDir; + QString m_previousCurrent; }; void tst_QIODevice::initTestCase() @@ -68,6 +73,15 @@ void tst_QIODevice::initTestCase() QVERIFY(QFileInfo(QStringLiteral("./tst_qiodevice.cpp")).exists() || QFile::copy(QStringLiteral(":/tst_qiodevice.cpp"), QStringLiteral("./tst_qiodevice.cpp"))); #endif + m_previousCurrent = QDir::currentPath(); + m_tempDir = QSharedPointer(new QTemporaryDir); + QVERIFY2(!m_tempDir.isNull(), qPrintable("Could not create temporary directory.")); + QVERIFY2(QDir::setCurrent(m_tempDir->path()), qPrintable("Could not switch current directory")); +} + +void tst_QIODevice::cleanupTestCase() +{ + QDir::setCurrent(m_previousCurrent); } // Testing get/set functions diff --git a/tests/auto/corelib/io/qloggingregistry/qloggingregistry.pro b/tests/auto/corelib/io/qloggingregistry/qloggingregistry.pro index 6be5fb1067..a311173c0e 100644 --- a/tests/auto/corelib/io/qloggingregistry/qloggingregistry.pro +++ b/tests/auto/corelib/io/qloggingregistry/qloggingregistry.pro @@ -6,6 +6,7 @@ QT = core core-private testlib SOURCES += tst_qloggingregistry.cpp OTHER_FILES += qtlogging.ini +TESTDATA += qtlogging.ini android:!android-no-sdk: { RESOURCES += \ diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 50c5b938e9..e1c277717d 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -429,6 +429,8 @@ void tst_qstandardpaths::testFindExecutable() void tst_qstandardpaths::testFindExecutableLinkToDirectory() { + // WinRT has no link support +#ifndef Q_OS_WINRT // link to directory const QString target = QDir::tempPath() + QDir::separator() + QLatin1String("link.lnk"); QFile::remove(target); @@ -436,15 +438,16 @@ void tst_qstandardpaths::testFindExecutableLinkToDirectory() QVERIFY(appFile.link(target)); QVERIFY(QStandardPaths::findExecutable(target).isEmpty()); QFile::remove(target); +#endif } void tst_qstandardpaths::testRuntimeDirectory() { +#ifdef Q_XDG_PLATFORM const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY(!runtimeDir.isEmpty()); // Check that it can automatically fix permissions -#ifdef Q_XDG_PLATFORM QFile file(runtimeDir); const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser; const QFile::Permissions additionalPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp index 621e215d60..6e03d8360e 100644 --- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp +++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp @@ -72,11 +72,14 @@ private slots: void QTBUG43352_failedSetPermissions(); -public: +private: + QString m_previousCurrent; }; void tst_QTemporaryDir::initTestCase() { + m_previousCurrent = QDir::currentPath(); + QDir::setCurrent(QDir::tempPath()); QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); QCoreApplication::setApplicationName("tst_qtemporarydir"); } @@ -84,6 +87,8 @@ void tst_QTemporaryDir::initTestCase() void tst_QTemporaryDir::cleanupTestCase() { QVERIFY(QDir().rmdir("test-XXXXXX")); + + QDir::setCurrent(m_previousCurrent); } void tst_QTemporaryDir::construction() diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp index 94e6bbaade..6e461cae17 100644 --- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp +++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp @@ -85,10 +85,15 @@ private slots: void QTBUG_4796_data(); void QTBUG_4796(); void guaranteeUnique(); +private: + QString m_previousCurrent; }; void tst_QTemporaryFile::initTestCase() { + m_previousCurrent = QDir::currentPath(); + QDir::setCurrent(QDir::tempPath()); + // For QTBUG_4796 QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); QCoreApplication::setApplicationName("tst_qtemporaryfile"); @@ -116,6 +121,8 @@ void tst_QTemporaryFile::cleanupTestCase() { // From QTBUG_4796 QVERIFY(QDir().rmdir("test-XXXXXX")); + + QDir::setCurrent(m_previousCurrent); } void tst_QTemporaryFile::construction() @@ -678,8 +685,11 @@ void tst_QTemporaryFile::createNativeFile_data() const QString nativeFilePath = QFINDTESTDATA("resources/test.txt"); #endif - QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); - QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); + // File might not exist locally in case of sandboxing or remote testing + if (!nativeFilePath.startsWith(QLatin1String(":/"))) { + QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); + QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); + } QTest::newRow("resourceFile") << ":/resources/test.txt" << (qint64)-1 << true << QByteArray("This is a test"); QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test"); } diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 519b05f492..b284e5fc9c 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -3013,14 +3013,20 @@ void tst_QUrl::fromUserInputWithCwd_data() it.next(); QUrl url = QUrl::fromLocalFile(it.filePath()); if (it.fileName() == QLatin1String(".")) { - url = QUrl::fromLocalFile(QDir::currentPath()); // fromUserInput cleans the path + url = QUrl::fromLocalFile(QDir::currentPath() +#ifdef Q_OS_WINRT + + QLatin1Char('/') +#endif + ); // fromUserInput cleans the path } QTest::newRow(QString("file-%1").arg(c++).toLatin1()) << it.fileName() << QDir::currentPath() << url << url; } +#ifndef Q_OS_WINRT // WinRT cannot cd outside current / sandbox QDir parent = QDir::current(); QVERIFY(parent.cdUp()); QUrl parentUrl = QUrl::fromLocalFile(parent.path()); QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl; +#endif QTest::newRow("nonexisting") << "nonexisting" << QDir::currentPath() << QUrl("http://nonexisting") << QUrl::fromLocalFile(QDir::currentPath() + "/nonexisting"); QTest::newRow("short-url") << "example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl::fromLocalFile(QDir::currentPath() + "/example.org"); -- cgit v1.2.3