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/qdir/qdir.pro | 3 ++ tests/auto/corelib/io/qdir/tst_qdir.cpp | 57 ++++++++++++++++++++++++++------- 2 files changed, 49 insertions(+), 11 deletions(-) (limited to 'tests/auto/corelib/io/qdir') 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("../..")); -- cgit v1.2.3