summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2018-06-18 15:14:19 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2018-06-22 13:05:03 +0000
commit4361c0ee846fb5574a05534186a01779a5e0bb82 (patch)
tree6e05af3242d688a8e882b21d2a63de315f6fd5b8 /tests/auto/testlib
parent9e15a93b89a46605e224666bffc62b342d4dc73b (diff)
findtestdata: test 'relative to test source'-fix
Before the fix is applied this test fails because QFINDTESTDATA will return "/usr/" instead of the folder with the same name in the current directory. The 'usr' folder can't be located 'next to' the application since this does not trigger the issue (QFINDTESTDATA looks for the folder next to the executable early on). So we put it in a subdirectory and change the current working directory to its parent directory. Change-Id: I627679dcb6f2f6954264e23bfc1a71de3bff7203 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Diffstat (limited to 'tests/auto/testlib')
-rw-r--r--tests/auto/testlib/selftests/findtestdata/findtestdata.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/auto/testlib/selftests/findtestdata/findtestdata.cpp b/tests/auto/testlib/selftests/findtestdata/findtestdata.cpp
index a775bc1ee5..7d5857faa0 100644
--- a/tests/auto/testlib/selftests/findtestdata/findtestdata.cpp
+++ b/tests/auto/testlib/selftests/findtestdata/findtestdata.cpp
@@ -134,6 +134,30 @@ void FindTestData::paths()
#endif
QVERIFY(QFile(testfile_path3).remove());
+#if !defined(Q_OS_WIN)
+ struct ChdirOnReturn
+ {
+ ~ChdirOnReturn() { QDir::setCurrent(dir); }
+ QString dir;
+ };
+
+ // When cross-compiling from Windows to a *nix system the __FILE__ path's canonical path is an
+ // empty string, which, when used as a prefix, would cause QFINDTESTDATA to look for files in
+ // root ('/') when trying to look for files relative to the test source.
+ QString usrPath = app_path + "/temp/usr/";
+ QVERIFY(QDir().mkpath(usrPath));
+ {
+ ChdirOnReturn chdirObject{QDir::currentPath()};
+ QDir::setCurrent(app_path + "/temp");
+ QCOMPARE(QTest::qFindTestData("usr/",
+ "C:\\path\\to\\source\\source.cpp",
+ __LINE__,
+ "C:\\path\\to\\build\\").toLower(),
+ usrPath.toLower());
+ }
+ QVERIFY(QDir().rmpath(usrPath));
+#endif
+
// Note, this is expected to generate a warning.
// We can't use ignoreMessage, because the warning comes from testlib,
// not via a "normal" qWarning. But it's OK, our caller (tst_selftests)