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 <oliver.wolff@theqtcompany.com>
This commit is contained in:
Maurice Kalinowski 2015-12-11 13:42:28 +01:00
parent f4502fbaf0
commit f05c597ae5
26 changed files with 220 additions and 41 deletions

View File

@ -152,7 +152,11 @@ inline void QDirPrivate::setPath(const QString &path)
if (p.endsWith(QLatin1Char('/')) if (p.endsWith(QLatin1Char('/'))
&& p.length() > 1 && p.length() > 1
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
# if defined (Q_OS_WINRT)
&& (!(p.toLower() == QDir::rootPath().toLower()))
# else
&& (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter())) && (!(p.length() == 3 && p.at(1).unicode() == ':' && p.at(0).isLetter()))
# endif
#endif #endif
) { ) {
p.truncate(p.length() - 1); p.truncate(p.length() - 1);
@ -885,6 +889,9 @@ bool QDir::cd(const QString &dirName)
#if defined (Q_OS_UNIX) #if defined (Q_OS_UNIX)
//After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root. //After cleanPath() if path is "/.." or starts with "/../" it means trying to cd above root.
if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/..")) if (newPath.startsWith(QLatin1String("/../")) || newPath == QLatin1String("/.."))
#elif defined (Q_OS_WINRT)
const QString rootPath = QDir::rootPath();
if (newPath.size() < rootPath.size() && rootPath.startsWith(newPath))
#else #else
/* /*
cleanPath() already took care of replacing '\' with '/'. cleanPath() already took care of replacing '\' with '/'.
@ -2187,7 +2194,11 @@ QString QDir::cleanPath(const QString &path)
// Strip away last slash except for root directories // Strip away last slash except for root directories
if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) { if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
#if defined (Q_OS_WIN) #if defined (Q_OS_WIN)
# if defined(Q_OS_WINRT)
if (!((ret.length() == 3 || ret.length() == QDir::rootPath().length()) && ret.at(1) == QLatin1Char(':')))
# else
if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':'))) if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':')))
# endif
#endif #endif
ret.chop(1); ret.chop(1);
} }

View File

@ -1095,7 +1095,7 @@ bool QFileInfo::isRoot() const
return true; return true;
if (d->fileEngine == 0) { if (d->fileEngine == 0) {
if (d->fileEntry.isRoot()) { if (d->fileEntry.isRoot()) {
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
//the path is a drive root, but the drive may not exist //the path is a drive root, but the drive may not exist
//for backward compatibility, return true only if the drive exists //for backward compatibility, return true only if the drive exists
if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ExistsAttribute)) if (!d->cache_enabled || !d->metaData.hasFlags(QFileSystemMetaData::ExistsAttribute))

View File

@ -78,6 +78,11 @@ using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Foundation; using namespace ABI::Windows::Foundation;
using namespace ABI::Windows::Storage; using namespace ABI::Windows::Storage;
using namespace ABI::Windows::ApplicationModel; using namespace ABI::Windows::ApplicationModel;
#if _MSC_VER < 1900
#define Q_OS_WINRT_WIN81
#endif
#endif // Q_OS_WINRT #endif // Q_OS_WINRT
#ifndef SPI_GETPLATFORMTYPE #ifndef SPI_GETPLATFORMTYPE
@ -522,7 +527,7 @@ QString QFileSystemEngine::nativeAbsoluteFilePath(const QString &path)
{ {
// can be //server or //server/share // can be //server or //server/share
QString absPath; QString absPath;
#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) #if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT_WIN81)
QVarLengthArray<wchar_t, MAX_PATH> buf(qMax(MAX_PATH, path.size() + 1)); QVarLengthArray<wchar_t, MAX_PATH> buf(qMax(MAX_PATH, path.size() + 1));
wchar_t *fileName = 0; wchar_t *fileName = 0;
DWORD retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName); DWORD retLen = GetFullPathName((wchar_t*)path.utf16(), buf.size(), buf.data(), &fileName);
@ -532,6 +537,16 @@ QString QFileSystemEngine::nativeAbsoluteFilePath(const QString &path)
} }
if (retLen != 0) if (retLen != 0)
absPath = QString::fromWCharArray(buf.data(), retLen); absPath = QString::fromWCharArray(buf.data(), retLen);
# if defined(Q_OS_WINRT)
// Win32 returns eg C:/ as root directory with a trailing /.
// WinRT returns the sandbox root without /.
// Also C:/../.. returns C:/ on Win32, while for WinRT it steps outside the package
// and goes beyond package root. Hence force the engine to stay inside
// the package.
const QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
if (absPath.size() < rootPath.size() && rootPath.startsWith(absPath))
absPath = rootPath;
# endif // Q_OS_WINRT
#elif !defined(Q_OS_WINCE) #elif !defined(Q_OS_WINCE)
if (QDir::isRelativePath(path)) if (QDir::isRelativePath(path))
absPath = QDir::toNativeSeparators(QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + path)); absPath = QDir::toNativeSeparators(QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + path));
@ -569,7 +584,7 @@ QFileSystemEntry QFileSystemEngine::absoluteName(const QFileSystemEntry &entry)
ret = entry.filePath(); ret = entry.filePath();
#endif #endif
} else { } else {
#ifndef Q_OS_WINRT #ifndef Q_OS_WINRT_WIN81
ret = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + entry.filePath()); ret = QDir::cleanPath(QDir::currentPath() + QLatin1Char('/') + entry.filePath());
#else #else
// Some WinRT APIs do not support absolute paths (due to sandboxing). // Some WinRT APIs do not support absolute paths (due to sandboxing).
@ -1218,8 +1233,8 @@ QString QFileSystemEngine::rootPath()
if (FAILED(item->get_Path(finalWinPath.GetAddressOf()))) if (FAILED(item->get_Path(finalWinPath.GetAddressOf())))
return ret; return ret;
ret = QDir::fromNativeSeparators(QString::fromWCharArray(finalWinPath.GetRawBuffer(nullptr))); const QString qtWinPath = QDir::fromNativeSeparators(QString::fromWCharArray(finalWinPath.GetRawBuffer(nullptr)));
ret = qtWinPath.endsWith(QLatin1Char('/')) ? qtWinPath : qtWinPath + QLatin1Char('/');
#else #else
QString ret = QString::fromLatin1(qgetenv("SystemDrive")); QString ret = QString::fromLatin1(qgetenv("SystemDrive"));
if (ret.isEmpty()) if (ret.isEmpty())
@ -1337,7 +1352,7 @@ bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &entry)
if(!(meta.exists() && meta.isDirectory())) if(!(meta.exists() && meta.isDirectory()))
return false; return false;
#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) #if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT_WIN81)
//TODO: this should really be using nativeFilePath(), but that returns a path in long format \\?\c:\foo //TODO: this should really be using nativeFilePath(), but that returns a path in long format \\?\c:\foo
//which causes many problems later on when it's returned through currentPath() //which causes many problems later on when it's returned through currentPath()
return ::SetCurrentDirectory(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(entry.filePath()).utf16())) != 0; return ::SetCurrentDirectory(reinterpret_cast<const wchar_t*>(QDir::toNativeSeparators(entry.filePath()).utf16())) != 0;
@ -1350,7 +1365,7 @@ bool QFileSystemEngine::setCurrentPath(const QFileSystemEntry &entry)
QFileSystemEntry QFileSystemEngine::currentPath() QFileSystemEntry QFileSystemEngine::currentPath()
{ {
QString ret; QString ret;
#if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT) #if !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT_WIN81)
DWORD size = 0; DWORD size = 0;
wchar_t currentName[PATH_MAX]; wchar_t currentName[PATH_MAX];
size = ::GetCurrentDirectory(PATH_MAX, currentName); size = ::GetCurrentDirectory(PATH_MAX, currentName);
@ -1366,17 +1381,17 @@ QFileSystemEntry QFileSystemEngine::currentPath()
} }
if (ret.length() >= 2 && ret[1] == QLatin1Char(':')) if (ret.length() >= 2 && ret[1] == QLatin1Char(':'))
ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters. ret[0] = ret.at(0).toUpper(); // Force uppercase drive letters.
#else // !Q_OS_WINCE && !Q_OS_WINRT #else // !Q_OS_WINCE && !Q_OS_WINRT_WIN81
//TODO - a race condition exists when using currentPath / setCurrentPath from multiple threads //TODO - a race condition exists when using currentPath / setCurrentPath from multiple threads
if (qfsPrivateCurrentDir.isEmpty()) if (qfsPrivateCurrentDir.isEmpty())
#ifndef Q_OS_WINRT #ifndef Q_OS_WINRT_WIN81
qfsPrivateCurrentDir = QCoreApplication::applicationDirPath(); qfsPrivateCurrentDir = QCoreApplication::applicationDirPath();
#else #else
qfsPrivateCurrentDir = QDir::rootPath(); qfsPrivateCurrentDir = QDir::rootPath();
#endif #endif
ret = qfsPrivateCurrentDir; ret = qfsPrivateCurrentDir;
#endif // Q_OS_WINCE || Q_OS_WINRT #endif // Q_OS_WINCE || Q_OS_WINRT_WIN81
return QFileSystemEntry(ret, QFileSystemEntry::FromNativePath()); return QFileSystemEntry(ret, QFileSystemEntry::FromNativePath());
} }

View File

@ -166,6 +166,12 @@ void QFileSystemEntry::resolveNativeFilePath() const
m_nativeFilePath.remove(0,1); m_nativeFilePath.remove(0,1);
if (m_nativeFilePath.isEmpty()) if (m_nativeFilePath.isEmpty())
m_nativeFilePath.append(QLatin1Char('.')); m_nativeFilePath.append(QLatin1Char('.'));
// WinRT/MSVC2015 allows a maximum of 256 characters for a filepath
// unless //?/ is prepended which extends the rule to have a maximum
// of 256 characters in the filename plus the preprending path
#if _MSC_VER >= 1900
m_nativeFilePath.prepend("\\\\?\\");
#endif
#endif #endif
} }
} }
@ -283,9 +289,13 @@ bool QFileSystemEntry::isAbsolute() const
bool QFileSystemEntry::isDriveRoot() const bool QFileSystemEntry::isDriveRoot() const
{ {
resolveFilePath(); resolveFilePath();
#ifndef Q_OS_WINRT
return (m_filePath.length() == 3 return (m_filePath.length() == 3
&& m_filePath.at(0).isLetter() && m_filePath.at(1) == QLatin1Char(':') && m_filePath.at(0).isLetter() && m_filePath.at(1) == QLatin1Char(':')
&& m_filePath.at(2) == QLatin1Char('/')); && m_filePath.at(2) == QLatin1Char('/'));
#else // !Q_OS_WINRT
return m_filePath == QDir::rootPath();
#endif // !Q_OS_WINRT
} }
#endif #endif

View File

@ -67,7 +67,8 @@ QFileSystemIterator::QFileSystemIterator(const QFileSystemEntry &entry, QDir::Fi
if (!nativePath.endsWith(QLatin1Char('\\'))) if (!nativePath.endsWith(QLatin1Char('\\')))
nativePath.append(QLatin1Char('\\')); nativePath.append(QLatin1Char('\\'));
nativePath.append(QLatin1Char('*')); nativePath.append(QLatin1Char('*'));
#ifdef Q_OS_WINRT // In MSVC2015+ case we prepend //?/ for longer file-name support
#if defined(Q_OS_WINRT) && _MSC_VER < 1900
if (nativePath.startsWith(QLatin1Char('\\'))) if (nativePath.startsWith(QLatin1Char('\\')))
nativePath.remove(0, 1); nativePath.remove(0, 1);
#endif #endif

View File

@ -1037,7 +1037,7 @@ uchar *QFSFileEnginePrivate::map(qint64 offset, qint64 size,
offsetHi, offsetLo, size + extra); offsetHi, offsetLo, size + extra);
#else #else
LPVOID mapAddress = ::MapViewOfFileFromApp(mapHandle, access, LPVOID mapAddress = ::MapViewOfFileFromApp(mapHandle, access,
(ULONG64(offsetHi) << 32) + offsetLo, size); (ULONG64(offsetHi) << 32) + offsetLo, size + extra);
#endif #endif
if (mapAddress) { if (mapAddress) {
uchar *address = extra + static_cast<uchar*>(mapAddress); uchar *address = extra + static_cast<uchar*>(mapAddress);

View File

@ -63,4 +63,5 @@ winrt: SUBDIRS -= \
qprocess \ qprocess \
qprocess-noapplication \ qprocess-noapplication \
qprocessenvironment \ qprocessenvironment \
qstorageinfo \
qwinoverlappedionotifier qwinoverlappedionotifier

View File

@ -70,7 +70,7 @@ public:
, fd_(-1) , fd_(-1)
, stream_(0) , 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 maxSizeBits = 36; // 64 GiB
#elif defined(Q_OS_MAC) #elif defined(Q_OS_MAC)
// HFS+ does not support sparse files, so we limit file size for the test // HFS+ does not support sparse files, so we limit file size for the test
@ -135,6 +135,9 @@ private:
int fd_; int fd_;
FILE *stream_; FILE *stream_;
QSharedPointer<QTemporaryDir> m_tempDir;
QString m_previousCurrent;
}; };
/* /*
@ -229,6 +232,11 @@ QByteArray const &tst_LargeFile::getDataBlock(int index, qint64 position)
void tst_LargeFile::initTestCase() void tst_LargeFile::initTestCase()
{ {
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(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"); QFile file("qt_largefile.tmp");
QVERIFY( !file.exists() || file.remove() ); QVERIFY( !file.exists() || file.remove() );
} }
@ -240,6 +248,8 @@ void tst_LargeFile::cleanupTestCase()
QFile file("qt_largefile.tmp"); QFile file("qt_largefile.tmp");
QVERIFY( !file.exists() || file.remove() ); QVERIFY( !file.exists() || file.remove() );
QDir::setCurrent(m_previousCurrent);
} }
void tst_LargeFile::init() void tst_LargeFile::init()

View File

@ -52,6 +52,7 @@ class tst_QAbstractFileEngine
{ {
Q_OBJECT Q_OBJECT
public slots: public slots:
void initTestCase();
void cleanupTestCase(); void cleanupTestCase();
private slots: private slots:
@ -64,6 +65,8 @@ private slots:
void mounting(); void mounting();
private: private:
QStringList filesForRemoval; QStringList filesForRemoval;
QSharedPointer<QTemporaryDir> m_currentDir;
QString m_previousCurrent;
}; };
class ReferenceFileEngine class ReferenceFileEngine
@ -563,6 +566,14 @@ class FileEngineHandler
} }
}; };
void tst_QAbstractFileEngine::initTestCase()
{
m_previousCurrent = QDir::currentPath();
m_currentDir = QSharedPointer<QTemporaryDir>(new QTemporaryDir());
QVERIFY2(!m_currentDir.isNull(), qPrintable("Could not create current directory."));
QDir::setCurrent(m_currentDir->path());
}
void tst_QAbstractFileEngine::cleanupTestCase() void tst_QAbstractFileEngine::cleanupTestCase()
{ {
bool failed = false; bool failed = false;
@ -576,6 +587,8 @@ void tst_QAbstractFileEngine::cleanupTestCase()
} }
QVERIFY(!failed); QVERIFY(!failed);
QDir::setCurrent(m_previousCurrent);
} }
void tst_QAbstractFileEngine::customHandler() void tst_QAbstractFileEngine::customHandler()

View File

@ -50,6 +50,7 @@ public:
void stream_data(int noOfElements); void stream_data(int noOfElements);
public slots: public slots:
void initTestCase();
void cleanupTestCase(); void cleanupTestCase();
private slots: private slots:
@ -243,6 +244,10 @@ private:
void readqint64(QDataStream *s); void readqint64(QDataStream *s);
void readQIcon(QDataStream *s); void readQIcon(QDataStream *s);
void readQEasingCurve(QDataStream *s); void readQEasingCurve(QDataStream *s);
private:
QSharedPointer<QTemporaryDir> m_tempDir;
QString m_previousCurrent;
}; };
static int NColorRoles[] = { static int NColorRoles[] = {
@ -293,10 +298,20 @@ void tst_QDataStream::getSetCheck()
QCOMPARE(QDataStream::ReadCorruptData, obj1.status()); QCOMPARE(QDataStream::ReadCorruptData, obj1.status());
} }
void tst_QDataStream::initTestCase()
{
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(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() void tst_QDataStream::cleanupTestCase()
{ {
QFile::remove(QLatin1String("qdatastream.out")); QFile::remove(QLatin1String("qdatastream.out"));
QFile::remove(QLatin1String("datastream.tmp")); QFile::remove(QLatin1String("datastream.tmp"));
QDir::setCurrent(m_previousCurrent);
} }
static int dataIndex(const QString &tag) static int dataIndex(const QString &tag)

View File

@ -5,6 +5,9 @@ SOURCES = tst_qdir.cpp
RESOURCES += qdir.qrc RESOURCES += qdir.qrc
TESTDATA += testdir testData searchdir resources entrylist types tst_qdir.cpp TESTDATA += testdir testData searchdir resources entrylist types tst_qdir.cpp
contains(CONFIG, builtin_testdata): DEFINES += BUILTIN_TESTDATA
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0
android:!android-no-sdk { android:!android-no-sdk {

View File

@ -56,7 +56,7 @@
# include <sys/stat.h> # include <sys/stat.h>
#endif #endif
#if defined(Q_OS_VXWORKS) #if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT)
#define Q_NO_SYMLINKS #define Q_NO_SYMLINKS
#endif #endif
@ -216,7 +216,12 @@ private slots:
void cdBelowRoot(); void cdBelowRoot();
private: private:
#ifdef BUILTIN_TESTDATA
QString m_dataPath;
QSharedPointer<QTemporaryDir> m_dataDir;
#else
const QString m_dataPath; const QString m_dataPath;
#endif
}; };
Q_DECLARE_METATYPE(tst_QDir::UncHandling) Q_DECLARE_METATYPE(tst_QDir::UncHandling)
@ -224,7 +229,7 @@ Q_DECLARE_METATYPE(tst_QDir::UncHandling)
tst_QDir::tst_QDir() tst_QDir::tst_QDir()
#if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) #if defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
: m_dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)) : m_dataPath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))
#else #elif !defined(BUILTIN_TESTDATA)
: m_dataPath(QFileInfo(QFINDTESTDATA("testData")).absolutePath()) : m_dataPath(QFileInfo(QFINDTESTDATA("testData")).absolutePath())
#endif #endif
{ {
@ -261,12 +266,23 @@ void tst_QDir::init()
void tst_QDir::initTestCase() 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"); QVERIFY2(!m_dataPath.isEmpty(), "test data not found");
} }
void tst_QDir::cleanupTestCase() 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(); QDir(QDir::currentPath() + "/tmpdir").removeRecursively();
#endif
} }
// Testing get/set functions // 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") << (m_dataPath + "/resources") << true;
QTest::newRow("simple dir with slash") << (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(); const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 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 8") << uncRoot + "/asharethatshouldnotexist" << false;
QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false; QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false;
#endif #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; QTest::newRow("This drive should exist") << "C:/" << true;
// find a non-existing drive and check if it does not exist // find a non-existing drive and check if it does not exist
#ifdef QT_BUILD_INTERNAL #ifdef QT_BUILD_INTERNAL
@ -897,7 +913,7 @@ void tst_QDir::entryListSimple_data()
QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 2; QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << 2;
#endif #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(); const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
QTest::newRow("unc 1") << uncRoot << 2; QTest::newRow("unc 1") << uncRoot << 2;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2; QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2;
@ -980,7 +996,6 @@ void tst_QDir::canonicalPath_data()
QTest::newRow("relative") << "." << m_dataPath; QTest::newRow("relative") << "." << m_dataPath;
QTest::newRow("relativeSubDir") << "./testData/../testData" << m_dataPath + "/testData"; QTest::newRow("relativeSubDir") << "./testData/../testData" << m_dataPath + "/testData";
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
QTest::newRow("absPath") << m_dataPath + "/testData/../testData" << m_dataPath + "/testData"; QTest::newRow("absPath") << m_dataPath + "/testData/../testData" << m_dataPath + "/testData";
#else #else
@ -1179,7 +1194,7 @@ tst_QDir::cleanPath_data()
QTest::newRow("data10") << "/:/" << "/:"; QTest::newRow("data10") << "/:/" << "/:";
#endif #endif
#endif #endif
#ifdef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
QTest::newRow("data11") << "//foo//bar" << "//foo/bar"; QTest::newRow("data11") << "//foo//bar" << "//foo/bar";
#endif #endif
QTest::newRow("data12") << "ab/a/" << "ab/a"; // Path item with length of 2 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"; QTest::newRow("data14") << "c://foo" << "c:/foo";
// Drive letters and unc path in one string // Drive letters and unc path in one string
#ifndef Q_OS_WINRT
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
QTest::newRow("data15") << "//c:/foo" << "//c:/foo"; QTest::newRow("data15") << "//c:/foo" << "//c:/foo";
#else #else
QTest::newRow("data15") << "//c:/foo" << "/c:/foo"; QTest::newRow("data15") << "//c:/foo" << "/c:/foo";
#endif #endif
#endif // !Q_OS_WINRT
QTest::newRow("QTBUG-23892_0") << "foo/.." << "."; QTest::newRow("QTBUG-23892_0") << "foo/.." << ".";
QTest::newRow("QTBUG-23892_1") << "foo/../" << "."; QTest::newRow("QTBUG-23892_1") << "foo/../" << ".";
@ -1314,7 +1331,7 @@ void tst_QDir::absoluteFilePath_data()
QTest::newRow("2") << "/" << "passwd" << "/passwd"; QTest::newRow("2") << "/" << "passwd" << "/passwd";
QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path"; QTest::newRow("3") << "relative" << "path" << QDir::currentPath() + "/relative/path";
QTest::newRow("4") << "" << "" << QDir::currentPath(); 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"; QTest::newRow("5") << "//machine" << "share" << "//machine/share";
#endif #endif
@ -1338,7 +1355,7 @@ void tst_QDir::absolutePath_data()
QTest::addColumn<QString>("expectedPath"); QTest::addColumn<QString>("expectedPath");
QTest::newRow("0") << "/machine/share/dir1" << "/machine/share/dir1"; 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("1") << "\\machine\\share\\dir1" << "/machine/share/dir1";
QTest::newRow("2") << "//machine/share/dir1" << "//machine/share/dir1"; QTest::newRow("2") << "//machine/share/dir1" << "//machine/share/dir1";
QTest::newRow("3") << "\\\\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("27") << "C:" << "D:/" << "D:/";
QTest::newRow("28") << "C:/" << "D:" << "D:"; QTest::newRow("28") << "C:/" << "D:" << "D:";
QTest::newRow("29") << "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("30") << "C:/foo/bar" << "//anotherHost/foo/bar" << "//anotherHost/foo/bar";
QTest::newRow("31") << "//anotherHost/foo" << "//anotherHost/foo/bar" << "bar"; QTest::newRow("31") << "//anotherHost/foo" << "//anotherHost/foo/bar" << "bar";
QTest::newRow("32") << "//anotherHost/foo" << "bar" << "bar"; QTest::newRow("32") << "//anotherHost/foo" << "bar" << "bar";
QTest::newRow("33") << "//anotherHost/foo" << "C:/foo/bar" << "C:/foo/bar"; QTest::newRow("33") << "//anotherHost/foo" << "C:/foo/bar" << "C:/foo/bar";
#endif // !Q_OS_WINRT
#endif #endif
QTest::newRow("resource0") << ":/prefix" << "foo.bar" << "foo.bar"; QTest::newRow("resource0") << ":/prefix" << "foo.bar" << "foo.bar";
@ -1594,7 +1613,11 @@ void tst_QDir::homePath()
qputenv("HOME", envHome); qputenv("HOME", envHome);
#elif defined(Q_OS_WIN) #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('/')); QVERIFY(!strHome.endsWith('/'));
#endif #endif
@ -2059,6 +2082,9 @@ void tst_QDir::drives()
QVERIFY(list.count() >= 1); //system QVERIFY(list.count() >= 1); //system
QLatin1Char systemdrive('c'); QLatin1Char systemdrive('c');
#endif #endif
#if defined(Q_OS_WINRT)
QSKIP("WinRT has no concept of drives");
#endif
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
QVERIFY(list.count() <= 26); QVERIFY(list.count() <= 26);
bool foundsystem = false; bool foundsystem = false;
@ -2115,7 +2141,9 @@ void tst_QDir::equalityOperator_data()
<< true; << true;
//need a path in the root directory that is unlikely to be a symbolic link. //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/.."); QString pathinroot("c:/windows/..");
#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) #elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
QString pathinroot("/system/.."); QString pathinroot("/system/..");
@ -2246,6 +2274,10 @@ void tst_QDir::cdBelowRoot()
#define ROOT QString("/") #define ROOT QString("/")
#define DIR QString("/tmp") #define DIR QString("/tmp")
#define CD_INTO "tmp" #define CD_INTO "tmp"
#elif defined (Q_OS_WINRT)
#define ROOT QDir::rootPath()
#define DIR QDir::rootPath()
#define CD_INTO QDir::rootPath()
#else #else
#define ROOT QString::fromLocal8Bit(qgetenv("SystemDrive"))+"/" #define ROOT QString::fromLocal8Bit(qgetenv("SystemDrive"))+"/"
#define DIR QString::fromLocal8Bit(qgetenv("SystemRoot")).replace('\\', '/') #define DIR QString::fromLocal8Bit(qgetenv("SystemRoot")).replace('\\', '/')
@ -2260,6 +2292,9 @@ void tst_QDir::cdBelowRoot()
#ifdef Q_OS_UNIX #ifdef Q_OS_UNIX
if (::getuid() == 0) if (::getuid() == 0)
QSKIP("Running this test as root doesn't make sense"); QSKIP("Running this test as root doesn't make sense");
#endif
#ifdef Q_OS_WINRT
QSKIP("WinRT has no concept of system root");
#endif #endif
QDir dir(DIR); QDir dir(DIR);
QVERIFY(!dir.cd("../..")); QVERIFY(!dir.cd("../.."));

View File

@ -5,6 +5,7 @@ SOURCES = tst_qdiriterator.cpp
RESOURCES += qdiriterator.qrc RESOURCES += qdiriterator.qrc
TESTDATA += entrylist TESTDATA += entrylist
contains(CONFIG, builtin_testdata): DEFINES += BUILTIN_TESTDATA
wince*mips*|wincewm50smart-msvc200*: DEFINES += WINCE_BROKEN_ITERATE=1 wince*mips*|wincewm50smart-msvc200*: DEFINES += WINCE_BROKEN_ITERATE=1
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0

View File

@ -42,7 +42,7 @@
#include <QtCore/private/qfsfileengine_p.h> #include <QtCore/private/qfsfileengine_p.h>
#if defined(Q_OS_VXWORKS) #if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT)
#define Q_NO_SYMLINKS #define Q_NO_SYMLINKS
#endif #endif
@ -115,6 +115,10 @@ private slots:
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
void hiddenDirs_hiddenFiles(); void hiddenDirs_hiddenFiles();
#endif #endif
#ifdef BUILTIN_TESTDATA
private:
QSharedPointer<QTemporaryDir> m_dataDir;
#endif
}; };
void tst_QDirIterator::initTestCase() void tst_QDirIterator::initTestCase()
@ -141,6 +145,10 @@ void tst_QDirIterator::initTestCase()
} }
testdata_dir += QStringLiteral("/entrylist"); 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 #else
// chdir into testdata directory, then find testdata by relative paths. // chdir into testdata directory, then find testdata by relative paths.
@ -217,6 +225,11 @@ void tst_QDirIterator::cleanupTestCase()
Q_FOREACH(QString dirName, createdDirectories) Q_FOREACH(QString dirName, createdDirectories)
currentDir.rmdir(dirName); currentDir.rmdir(dirName);
#ifdef Q_OS_WINRT
QDir::setCurrent(QCoreApplication::applicationDirPath());
#endif // Q_OS_WINRT
} }
void tst_QDirIterator::iterateRelativeDirectory_data() void tst_QDirIterator::iterateRelativeDirectory_data()

View File

@ -66,7 +66,7 @@
#include <private/qfileinfo_p.h> #include <private/qfileinfo_p.h>
#include "../../../../shared/filesystem.h" #include "../../../../shared/filesystem.h"
#if defined(Q_OS_VXWORKS) #if defined(Q_OS_VXWORKS) || defined(Q_OS_WINRT)
#define Q_NO_SYMLINKS #define Q_NO_SYMLINKS
#endif #endif
@ -427,12 +427,12 @@ void tst_QFileInfo::isDir_data()
QTest::newRow("broken link") << "brokenlink.lnk" << false; 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 1") << "c:" << true;
QTest::newRow("drive 2") << "c:/" << true; QTest::newRow("drive 2") << "c:/" << true;
//QTest::newRow("drive 2") << "t:s" << false; //QTest::newRow("drive 2") << "t:s" << false;
#endif #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(); const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
QTest::newRow("unc 1") << uncRoot << true; QTest::newRow("unc 1") << uncRoot << true;
QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 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") << m_resourcesDir << false;
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << 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 1") << "c:" << false;
QTest::newRow("drive 2") << "c:/" << true; QTest::newRow("drive 2") << "c:/" << true;
QTest::newRow("drive 3") << "p:/" << false; QTest::newRow("drive 3") << "p:/" << false;
@ -513,7 +513,12 @@ void tst_QFileInfo::exists_data()
QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false; QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false;
QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false; QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false;
QTest::newRow("data10") << "." << true; 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; QTest::newRow("data11") << ". " << false;
#endif
QTest::newRow("empty") << "" << false; QTest::newRow("empty") << "" << false;
QTest::newRow("simple dir") << m_resourcesDir << true; QTest::newRow("simple dir") << m_resourcesDir << true;
@ -554,7 +559,7 @@ void tst_QFileInfo::absolutePath_data()
QTest::addColumn<QString>("filename"); QTest::addColumn<QString>("filename");
QString drivePrefix; 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); drivePrefix = QDir::currentPath().left(2);
QString nonCurrentDrivePrefix = QString nonCurrentDrivePrefix =
drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:"); drivePrefix.left(1).compare("X", Qt::CaseInsensitive) == 0 ? QString("Y:") : QString("X:");
@ -564,6 +569,8 @@ void tst_QFileInfo::absolutePath_data()
QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "my.dll" QTest::newRow("<not current drive>:my.dll") << nonCurrentDrivePrefix + "my.dll"
<< nonCurrentDrivePrefix + "/" << nonCurrentDrivePrefix + "/"
<< "my.dll"; << "my.dll";
#elif defined(Q_OS_WINRT)
drivePrefix = QDir::currentPath().left(2);
#endif #endif
QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << ""; QTest::newRow("0") << "/machine/share/dir1/" << drivePrefix + "/machine/share/dir1" << "";
QTest::newRow("1") << "/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("3") << "/usr/local/bin/" << drivePrefix + "/usr/local/bin" << "";
QTest::newRow("/test") << "/test" << drivePrefix + "/" << "test"; 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:/" QTest::newRow("c:\\autoexec.bat") << "c:\\autoexec.bat" << "C:/"
<< "autoexec.bat"; << "autoexec.bat";
QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath() QTest::newRow("c:autoexec.bat") << QDir::currentPath().left(2) + "autoexec.bat" << QDir::currentPath()
@ -735,7 +742,7 @@ void tst_QFileInfo::canonicalFilePath()
} }
#endif #endif
#ifdef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
typedef BOOL (WINAPI *PtrCreateSymbolicLink)(LPTSTR, LPTSTR, DWORD); typedef BOOL (WINAPI *PtrCreateSymbolicLink)(LPTSTR, LPTSTR, DWORD);
PtrCreateSymbolicLink ptrCreateSymbolicLink = PtrCreateSymbolicLink ptrCreateSymbolicLink =
(PtrCreateSymbolicLink)QLibrary::resolve(QLatin1String("kernel32"), "CreateSymbolicLinkW"); (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("absFilePath") << QDir::currentPath() + "/tmp.txt" << false << QDir::currentPath();
QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath(); QTest::newRow("absFilePathAbsPath") << QDir::currentPath() + "/tmp.txt" << true << QDir::currentPath();
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << true << ":/tst_qfileinfo/resources"; 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("driveWithSlash") << "C:/file1.ext1.ext2" << true << "C:/";
QTest::newRow("driveWithoutSlash") << QDir::currentPath().left(2) + "file1.ext1.ext2" << false << QDir::currentPath().left(2); QTest::newRow("driveWithoutSlash") << QDir::currentPath().left(2) + "file1.ext1.ext2" << false << QDir::currentPath().left(2);
#endif #endif
@ -1022,7 +1029,7 @@ void tst_QFileInfo::size()
void tst_QFileInfo::systemFiles() 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"); QSKIP("This is a Windows only test");
#endif #endif
QFileInfo fi("c:\\pagefile.sys"); QFileInfo fi("c:\\pagefile.sys");
@ -1193,6 +1200,8 @@ void tst_QFileInfo::fileTimes()
#endif #endif
#if defined(Q_OS_WINCE) #if defined(Q_OS_WINCE)
QEXPECT_FAIL("simple", "WinCE only stores date of access data, not the time", Continue); 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) #elif defined(Q_OS_QNX)
QEXPECT_FAIL("", "QNX uses the noatime filesystem option", Continue); QEXPECT_FAIL("", "QNX uses the noatime filesystem option", Continue);
#elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK) #elif defined(Q_OS_ANDROID) && !defined(Q_OS_ANDROID_NO_SDK)
@ -1628,7 +1637,7 @@ void tst_QFileInfo::isWritable()
QVERIFY(QFileInfo("tempfile.txt").isWritable()); QVERIFY(QFileInfo("tempfile.txt").isWritable());
tempfile.remove(); tempfile.remove();
#ifdef Q_OS_WIN #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
#ifdef Q_OS_WINCE #ifdef Q_OS_WINCE
QFileInfo fi("\\Windows\\wince.nls"); QFileInfo fi("\\Windows\\wince.nls");
#else #else

View File

@ -24,6 +24,7 @@
<file>platforms/+unix/test</file> <file>platforms/+unix/test</file>
<file>platforms/+windows/+wince/test</file> <file>platforms/+windows/+wince/test</file>
<file>platforms/+windows/+winnt/test</file> <file>platforms/+windows/+winnt/test</file>
<file>platforms/+windows/+winrt/test</file>
<file>platforms/+windows/test</file> <file>platforms/+windows/test</file>
<file>platforms/+android/test</file> <file>platforms/+android/test</file>
<file>platforms/+blackberry/test</file> <file>platforms/+blackberry/test</file>
@ -34,6 +35,7 @@
<file>platforms/+haiku/test</file> <file>platforms/+haiku/test</file>
<file>platforms/+linux/test</file> <file>platforms/+linux/test</file>
<file>platforms/+wince/test</file> <file>platforms/+wince/test</file>
<file>platforms/+winrt/test</file>
<!-- platforms/test2: shallow selection for the deepest selector --> <!-- platforms/test2: shallow selection for the deepest selector -->
<file>platforms/test2</file> <file>platforms/test2</file>
@ -45,6 +47,7 @@
<file>platforms/+linux/test2</file> <file>platforms/+linux/test2</file>
<file>platforms/+wince/test2</file> <file>platforms/+wince/test2</file>
<file>platforms/+winnt/test2</file> <file>platforms/+winnt/test2</file>
<file>platforms/+winrt/test2</file>
<!-- platforms/test3: selection for the family only --> <!-- platforms/test3: selection for the family only -->
<file>platforms/test3</file> <file>platforms/test3</file>

View File

@ -99,7 +99,7 @@ void tst_QFileSelector::basicTest_data()
expectedPlatform2File = QString(":/platforms/test2"); expectedPlatform2File = QString(":/platforms/test2");
#else #else
QString distributionName; 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(); distributionName = QSysInfo::productType();
# endif # endif
foreach (const QString &selector, QFileSelectorPrivate::platformSelectors()) { foreach (const QString &selector, QFileSelectorPrivate::platformSelectors()) {

View File

@ -43,6 +43,7 @@ class tst_QIODevice : public QObject
private slots: private slots:
void initTestCase(); void initTestCase();
void cleanupTestCase();
void getSetCheck(); void getSetCheck();
void constructing_QTcpSocket(); void constructing_QTcpSocket();
void constructing_QFile(); void constructing_QFile();
@ -60,6 +61,10 @@ private slots:
void peekBug(); void peekBug();
void readAllKeepPosition(); void readAllKeepPosition();
void writeInTextMode(); void writeInTextMode();
private:
QSharedPointer<QTemporaryDir> m_tempDir;
QString m_previousCurrent;
}; };
void tst_QIODevice::initTestCase() void tst_QIODevice::initTestCase()
@ -68,6 +73,15 @@ void tst_QIODevice::initTestCase()
QVERIFY(QFileInfo(QStringLiteral("./tst_qiodevice.cpp")).exists() QVERIFY(QFileInfo(QStringLiteral("./tst_qiodevice.cpp")).exists()
|| QFile::copy(QStringLiteral(":/tst_qiodevice.cpp"), QStringLiteral("./tst_qiodevice.cpp"))); || QFile::copy(QStringLiteral(":/tst_qiodevice.cpp"), QStringLiteral("./tst_qiodevice.cpp")));
#endif #endif
m_previousCurrent = QDir::currentPath();
m_tempDir = QSharedPointer<QTemporaryDir>(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 // Testing get/set functions

View File

@ -6,6 +6,7 @@ QT = core core-private testlib
SOURCES += tst_qloggingregistry.cpp SOURCES += tst_qloggingregistry.cpp
OTHER_FILES += qtlogging.ini OTHER_FILES += qtlogging.ini
TESTDATA += qtlogging.ini
android:!android-no-sdk: { android:!android-no-sdk: {
RESOURCES += \ RESOURCES += \

View File

@ -429,6 +429,8 @@ void tst_qstandardpaths::testFindExecutable()
void tst_qstandardpaths::testFindExecutableLinkToDirectory() void tst_qstandardpaths::testFindExecutableLinkToDirectory()
{ {
// WinRT has no link support
#ifndef Q_OS_WINRT
// link to directory // link to directory
const QString target = QDir::tempPath() + QDir::separator() + QLatin1String("link.lnk"); const QString target = QDir::tempPath() + QDir::separator() + QLatin1String("link.lnk");
QFile::remove(target); QFile::remove(target);
@ -436,15 +438,16 @@ void tst_qstandardpaths::testFindExecutableLinkToDirectory()
QVERIFY(appFile.link(target)); QVERIFY(appFile.link(target));
QVERIFY(QStandardPaths::findExecutable(target).isEmpty()); QVERIFY(QStandardPaths::findExecutable(target).isEmpty());
QFile::remove(target); QFile::remove(target);
#endif
} }
void tst_qstandardpaths::testRuntimeDirectory() void tst_qstandardpaths::testRuntimeDirectory()
{ {
#ifdef Q_XDG_PLATFORM
const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
QVERIFY(!runtimeDir.isEmpty()); QVERIFY(!runtimeDir.isEmpty());
// Check that it can automatically fix permissions // Check that it can automatically fix permissions
#ifdef Q_XDG_PLATFORM
QFile file(runtimeDir); QFile file(runtimeDir);
const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser; const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser;
const QFile::Permissions additionalPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; const QFile::Permissions additionalPerms = QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;

View File

@ -72,11 +72,14 @@ private slots:
void QTBUG43352_failedSetPermissions(); void QTBUG43352_failedSetPermissions();
public: private:
QString m_previousCurrent;
}; };
void tst_QTemporaryDir::initTestCase() void tst_QTemporaryDir::initTestCase()
{ {
m_previousCurrent = QDir::currentPath();
QDir::setCurrent(QDir::tempPath());
QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
QCoreApplication::setApplicationName("tst_qtemporarydir"); QCoreApplication::setApplicationName("tst_qtemporarydir");
} }
@ -84,6 +87,8 @@ void tst_QTemporaryDir::initTestCase()
void tst_QTemporaryDir::cleanupTestCase() void tst_QTemporaryDir::cleanupTestCase()
{ {
QVERIFY(QDir().rmdir("test-XXXXXX")); QVERIFY(QDir().rmdir("test-XXXXXX"));
QDir::setCurrent(m_previousCurrent);
} }
void tst_QTemporaryDir::construction() void tst_QTemporaryDir::construction()

View File

@ -85,10 +85,15 @@ private slots:
void QTBUG_4796_data(); void QTBUG_4796_data();
void QTBUG_4796(); void QTBUG_4796();
void guaranteeUnique(); void guaranteeUnique();
private:
QString m_previousCurrent;
}; };
void tst_QTemporaryFile::initTestCase() void tst_QTemporaryFile::initTestCase()
{ {
m_previousCurrent = QDir::currentPath();
QDir::setCurrent(QDir::tempPath());
// For QTBUG_4796 // For QTBUG_4796
QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX")); QVERIFY(QDir("test-XXXXXX").exists() || QDir().mkdir("test-XXXXXX"));
QCoreApplication::setApplicationName("tst_qtemporaryfile"); QCoreApplication::setApplicationName("tst_qtemporaryfile");
@ -116,6 +121,8 @@ void tst_QTemporaryFile::cleanupTestCase()
{ {
// From QTBUG_4796 // From QTBUG_4796
QVERIFY(QDir().rmdir("test-XXXXXX")); QVERIFY(QDir().rmdir("test-XXXXXX"));
QDir::setCurrent(m_previousCurrent);
} }
void tst_QTemporaryFile::construction() void tst_QTemporaryFile::construction()
@ -678,8 +685,11 @@ void tst_QTemporaryFile::createNativeFile_data()
const QString nativeFilePath = QFINDTESTDATA("resources/test.txt"); const QString nativeFilePath = QFINDTESTDATA("resources/test.txt");
#endif #endif
QTest::newRow("nativeFile") << nativeFilePath << (qint64)-1 << false << QByteArray(); // File might not exist locally in case of sandboxing or remote testing
QTest::newRow("nativeFileWithPos") << nativeFilePath << (qint64)5 << false << QByteArray(); 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("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"); QTest::newRow("resourceFileWithPos") << ":/resources/test.txt" << (qint64)5 << true << QByteArray("This is a test");
} }

View File

@ -3013,14 +3013,20 @@ void tst_QUrl::fromUserInputWithCwd_data()
it.next(); it.next();
QUrl url = QUrl::fromLocalFile(it.filePath()); QUrl url = QUrl::fromLocalFile(it.filePath());
if (it.fileName() == QLatin1String(".")) { 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; 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(); QDir parent = QDir::current();
QVERIFY(parent.cdUp()); QVERIFY(parent.cdUp());
QUrl parentUrl = QUrl::fromLocalFile(parent.path()); QUrl parentUrl = QUrl::fromLocalFile(parent.path());
QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl; QTest::newRow("dotdot") << ".." << QDir::currentPath() << parentUrl << parentUrl;
#endif
QTest::newRow("nonexisting") << "nonexisting" << QDir::currentPath() << QUrl("http://nonexisting") << QUrl::fromLocalFile(QDir::currentPath() + "/nonexisting"); 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"); QTest::newRow("short-url") << "example.org" << QDir::currentPath() << QUrl("http://example.org") << QUrl::fromLocalFile(QDir::currentPath() + "/example.org");