diff options
author | Prasanth Ullattil <prasanth.ullattil@nokia.com> | 2010-12-06 13:24:58 (GMT) |
---|---|---|
committer | Prasanth Ullattil <prasanth.ullattil@nokia.com> | 2010-12-06 14:00:18 (GMT) |
commit | 5bdc4ec60655aba2972f0e6cb2b09ee5f012690b (patch) | |
tree | 1a9ab18b8c9291e6cdc13361abf5f81e5ee97ae2 | |
parent | fb43ea28e2712073de06644d78ed5a97a40f016b (diff) | |
download | Qt-5bdc4ec60655aba2972f0e6cb2b09ee5f012690b.zip Qt-5bdc4ec60655aba2972f0e6cb2b09ee5f012690b.tar.gz Qt-5bdc4ec60655aba2972f0e6cb2b09ee5f012690b.tar.bz2 |
Fix tst_QFileInfo::canonicalFilePath failure on Windows
When the test application is running without administrative privilages,
the CreateSymbolicLink() can incorrectly return success. To handle this
we need to check whether GetLastError() returns ERROR_PRIVILEGE_NOT_HELD
or not.
Reviewed-by: Joao
-rw-r--r-- | tests/auto/qfileinfo/tst_qfileinfo.cpp | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 3bbe2ca..96a0d77 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -621,18 +621,27 @@ void tst_QFileInfo::canonicalFilePath() PtrCreateSymbolicLink ptrCreateSymbolicLink = (PtrCreateSymbolicLink)QLibrary::resolve(QLatin1String("kernel32"), "CreateSymbolicLinkW"); - if (!ptrCreateSymbolicLink || - ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1) == 0) { + if (!ptrCreateSymbolicLink) { QSKIP("Symbolic links aren't supported by FS", SkipAll); + } else { + // CreateSymbolicLink can return TRUE & still fail to create the link, + // the error code in that case is ERROR_PRIVILEGE_NOT_HELD (1314) + SetLastError(0); + BOOL ret = ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1); + DWORD dwErr = GetLastError(); + if (!ret) + QSKIP("Symbolic links aren't supported by FS", SkipAll); + QString currentPath = QDir::currentPath(); + bool is_res_Current = QDir::setCurrent("res"); + if (!is_res_Current && dwErr == 1314) + QSKIP("Not enough privilages to create Symbolic links", SkipAll); + QCOMPARE(is_res_Current, true); + + QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1"); + + QCOMPARE(QDir::setCurrent(currentPath), true); + QDir::current().rmdir("res"); } - - QString currentPath = QDir::currentPath(); - QCOMPARE(QDir::setCurrent("res"), true); - - QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1"); - - QCOMPARE(QDir::setCurrent(currentPath), true); - QDir::current().rmdir("res"); #endif } |