diff options
author | Friedemann Kleint <Friedemann.Kleint@nokia.com> | 2011-12-20 09:43:24 +0100 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-12-21 22:59:13 +0100 |
commit | 5d4acbab0e243aa944f9b365fb6d72073bb1da70 (patch) | |
tree | 33fd5d4256cdb5a9b7023818427cdf29ccef7565 /src/testlib | |
parent | f1e07483b3e62dd2d2e2650e0150028dde4ca94c (diff) |
QTestLib: Fix QFINDTESTDATA for Windows.
- Scan the parent directory of the executable if it is located
in a 'Debug' or 'Release' directory
- Report with native separators in the log.
- Use the QString::arg() overloads with several string parameters.
Change-Id: I5ea84411e12978f8f958a0bce3ae10da44cc4e3f
Reviewed-by: Jason McDonald <jason.mcdonald@nokia.com>
Diffstat (limited to 'src/testlib')
-rw-r--r-- | src/testlib/qtestcase.cpp | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 2b0182541e..a00f91f4f0 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -2102,6 +2102,15 @@ void QTest::ignoreMessage(QtMsgType type, const char *message) /*! \internal */ + +#ifdef Q_OS_WIN +static inline bool isWindowsBuildDirectory(const QString &dirName) +{ + return dirName.compare(QStringLiteral("Debug"), Qt::CaseInsensitive) == 0 + || dirName.compare(QStringLiteral("Release"), Qt::CaseInsensitive) == 0; +} +#endif + QString QTest::qFindTestData(const QString& base, const char *file, int line, const char *builddir) { QString found; @@ -2110,16 +2119,23 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co // 1. relative to test binary. if (qApp) { - QString binpath = QCoreApplication::applicationDirPath(); - QString candidate = QString::fromLatin1("%1/%2").arg(binpath).arg(base); - if (QFileInfo(candidate).exists()) { - found = candidate; + QDir binDirectory(QCoreApplication::applicationDirPath()); + if (binDirectory.exists(base)) { + found = binDirectory.absoluteFilePath(base); + } +#ifdef Q_OS_WIN + // Windows: The executable is typically located in one of the + // 'Release' or 'Debug' directories. + else if (isWindowsBuildDirectory(binDirectory.dirName()) + && binDirectory.cdUp() && binDirectory.exists(base)) { + found = binDirectory.absoluteFilePath(base); } +#endif // Q_OS_WIN else if (QTestLog::verboseLevel() >= 2) { + const QString candidate = QDir::toNativeSeparators(QCoreApplication::applicationDirPath() + QLatin1Char('/') + base); QTestLog::info(qPrintable( QString::fromLatin1("testdata %1 not found relative to test binary [%2]; " - "checking next location") - .arg(base).arg(candidate)), + "checking next location").arg(base, candidate)), file, line); } } @@ -2130,9 +2146,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co if (testObjectName) { QString testsPath = QLibraryInfo::location(QLibraryInfo::TestsPath); QString candidate = QString::fromLatin1("%1/%2/%3") - .arg(testsPath) - .arg(QFile::decodeName(testObjectName).toLower()) - .arg(base); + .arg(testsPath, QFile::decodeName(testObjectName).toLower(), base); if (QFileInfo(candidate).exists()) { found = candidate; } @@ -2140,7 +2154,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co QTestLog::info(qPrintable( QString::fromLatin1("testdata %1 not found in tests install path [%2]; " "checking next location") - .arg(base).arg(candidate)), + .arg(base, QDir::toNativeSeparators(candidate))), file, line); } } @@ -2157,14 +2171,14 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co srcdir.setFile(QFile::decodeName(builddir) + QLatin1String("/") + srcdir.filePath()); } - QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath()).arg(base); + QString candidate = QString::fromLatin1("%1/%2").arg(srcdir.canonicalFilePath(), base); if (QFileInfo(candidate).exists()) { found = candidate; } else if (QTestLog::verboseLevel() >= 2) { QTestLog::info(qPrintable( QString::fromLatin1("testdata %1 not found relative to source path [%2]") - .arg(base).arg(candidate)), + .arg(base, QDir::toNativeSeparators(candidate))), file, line); } } @@ -2176,7 +2190,7 @@ QString QTest::qFindTestData(const QString& base, const char *file, int line, co } else if (QTestLog::verboseLevel() >= 1) { QTestLog::info(qPrintable( - QString::fromLatin1("testdata %1 was located at %2").arg(base).arg(found)), + QString::fromLatin1("testdata %1 was located at %2").arg(base, QDir::toNativeSeparators(found))), file, line); } |