Reduce invocations of QFINDTESTDATA in tst_qfileinfo.

Introduce variables for the paths used in the test and
check in initTestCase().

Change-Id: Ie801266e30cd860e5bdf079c1182fe385f9598c7
Reviewed-by: David Faure (KDE) <faure@kde.org>
This commit is contained in:
Friedemann Kleint 2013-01-21 10:35:18 +01:00 committed by The Qt Project
parent 52e14e05fa
commit 04773fe72e

View File

@ -81,6 +81,7 @@ class tst_QFileInfo : public QObject
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
void getSetCheck();
@ -190,8 +191,20 @@ private slots:
void invalidState();
void nonExistingFileDates();
private:
QString m_sourceFile;
QString m_resourcesDir;
};
void tst_QFileInfo::initTestCase()
{
m_sourceFile = QFINDTESTDATA("tst_qfileinfo.cpp");
QVERIFY(!m_sourceFile.isEmpty());
m_resourcesDir = QFINDTESTDATA("resources");
QVERIFY(!m_resourcesDir.isEmpty());
}
void tst_QFileInfo::cleanupTestCase()
{
QFile::remove("brokenlink.lnk");
@ -286,7 +299,7 @@ void tst_QFileInfo::isFile_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << false;
QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true;
QTest::newRow("data1") << m_sourceFile << true;
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false;
@ -319,13 +332,13 @@ void tst_QFileInfo::isDir_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << true;
QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << false;
QTest::newRow("data1") << m_sourceFile << false;
QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << true;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << false;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false;
QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true;
QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true;
QTest::newRow("simple dir") << m_resourcesDir << true;
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true;
QTest::newRow("broken link") << "brokenlink.lnk" << false;
@ -365,8 +378,8 @@ void tst_QFileInfo::isRoot_data()
QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false;
QTest::newRow("data5") << ":/" << true;
QTest::newRow("simple dir") << QFINDTESTDATA("resources") << false;
QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << false;
QTest::newRow("simple dir") << m_resourcesDir << false;
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << false;
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
QTest::newRow("drive 1") << "c:" << false;
QTest::newRow("drive 2") << "c:/" << true;
@ -397,21 +410,21 @@ void tst_QFileInfo::exists_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QDir::currentPath() << true;
QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true;
QTest::newRow("data1") << m_sourceFile << true;
QTest::newRow("data2") << "/I/do_not_expect_this_path_to_exist/" << false;
QTest::newRow("data3") << ":/tst_qfileinfo/resources/" << true;
QTest::newRow("data4") << ":/tst_qfileinfo/resources/file1" << true;
QTest::newRow("data5") << ":/I/do_not_expect_this_path_to_exist/" << false;
QTest::newRow("data6") << (QFINDTESTDATA("resources/") + "*") << false;
QTest::newRow("data7") << (QFINDTESTDATA("resources/") + "*.foo") << false;
QTest::newRow("data8") << (QFINDTESTDATA("resources/") + "*.ext1") << false;
QTest::newRow("data9") << (QFINDTESTDATA("resources/") + "file?.ext1") << false;
QTest::newRow("data6") << (m_resourcesDir + "/*") << false;
QTest::newRow("data7") << (m_resourcesDir + "/*.foo") << false;
QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false;
QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false;
QTest::newRow("data10") << "." << true;
QTest::newRow("data11") << ". " << false;
QTest::newRow("empty") << "" << false;
QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true;
QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true;
QTest::newRow("simple dir") << m_resourcesDir << true;
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true;
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
@ -560,7 +573,7 @@ void tst_QFileInfo::canonicalFilePath()
// test symlinks
QFile::remove("link.lnk");
{
QFile file(QFINDTESTDATA("tst_qfileinfo.cpp"));
QFile file(m_sourceFile);
if (file.link("link.lnk")) {
QFileInfo info1(file);
QFileInfo info2("link.lnk");
@ -586,7 +599,7 @@ void tst_QFileInfo::canonicalFilePath()
QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath());
QFileInfo info3(link + QDir::separator() + "link.lnk");
QFileInfo info4(QFINDTESTDATA("tst_qfileinfo.cpp"));
QFileInfo info4(m_sourceFile);
QVERIFY(!info3.canonicalFilePath().isEmpty());
QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath());
@ -620,20 +633,21 @@ void tst_QFileInfo::canonicalFilePath()
// 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);
const QString linkTarget = QStringLiteral("res");
BOOL ret = ptrCreateSymbolicLink((wchar_t*)linkTarget.utf16(), (wchar_t*)m_resourcesDir.utf16(), 1);
DWORD dwErr = GetLastError();
if (!ret)
QSKIP("Symbolic links aren't supported by FS");
QString currentPath = QDir::currentPath();
bool is_res_Current = QDir::setCurrent("res");
bool is_res_Current = QDir::setCurrent(linkTarget);
if (!is_res_Current && dwErr == 1314)
QSKIP("Not enough privilages to create Symbolic links");
QCOMPARE(is_res_Current, true);
const QString actualCanonicalPath = QFileInfo("file1").canonicalFilePath();
QVERIFY(QDir::setCurrent(currentPath));
QCOMPARE(actualCanonicalPath, m_resourcesDir + QStringLiteral("/file1"));
QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1");
QCOMPARE(QDir::setCurrent(currentPath), true);
QDir::current().rmdir("res");
QDir::current().rmdir(linkTarget);
}
#endif
}
@ -854,7 +868,7 @@ void tst_QFileInfo::permission_data()
QTest::addColumn<bool>("expected");
QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true;
QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << int(QFile::ReadUser) << true;
QTest::newRow("data1") << m_sourceFile << int(QFile::ReadUser) << true;
QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true;
QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false;
QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false;
@ -920,13 +934,15 @@ void tst_QFileInfo::compare_data()
if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6)
caseSensitiveOnMac = false;
#endif
QString caseChangedSource = m_sourceFile;
caseChangedSource.replace("info", "Info");
QTest::newRow("data0")
<< QFINDTESTDATA("tst_qfileinfo.cpp")
<< QFINDTESTDATA("tst_qfileinfo.cpp")
<< m_sourceFile
<< m_sourceFile
<< true;
QTest::newRow("data1")
<< QFINDTESTDATA("tst_qfileinfo.cpp")
<< m_sourceFile
<< QString::fromLatin1("/tst_qfileinfo.cpp")
<< false;
QTest::newRow("data2")
@ -934,8 +950,8 @@ void tst_QFileInfo::compare_data()
<< QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp")
<< true;
QTest::newRow("casesense1")
<< QFINDTESTDATA("tst_qfileinfo.cpp").replace("info", "Info")
<< QFINDTESTDATA("tst_qfileinfo.cpp")
<< caseChangedSource
<< m_sourceFile
#if defined(Q_OS_WIN)
<< true;
#elif defined(Q_OS_MAC)
@ -1139,7 +1155,7 @@ void tst_QFileInfo::isSymLink_data()
QFile::remove("brokenlink.lnk");
QFile::remove("dummyfile");
QFile file1(QFINDTESTDATA("tst_qfileinfo.cpp"));
QFile file1(m_sourceFile);
QVERIFY(file1.link("link.lnk"));
QFile file2("dummyfile");
@ -1151,8 +1167,8 @@ void tst_QFileInfo::isSymLink_data()
QTest::addColumn<bool>("isSymLink");
QTest::addColumn<QString>("linkTarget");
QTest::newRow("existent file") << QFINDTESTDATA("tst_qfileinfo.cpp") << false << "";
QTest::newRow("link") << "link.lnk" << true << QFileInfo(QFINDTESTDATA("tst_qfileinfo.cpp")).absoluteFilePath();
QTest::newRow("existent file") << m_sourceFile << false << "";
QTest::newRow("link") << "link.lnk" << true << QFileInfo(m_sourceFile).absoluteFilePath();
QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath();
}
@ -1389,7 +1405,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
}
{
//File symlinks
QFileInfo target(QFINDTESTDATA("tst_qfileinfo.cpp"));
QFileInfo target(m_sourceFile);
QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath());
QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp");
QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath()));