diff options
author | João Abecasis <joao@abecasis.name> | 2009-09-22 15:42:43 (GMT) |
---|---|---|
committer | João Abecasis <joao@abecasis.name> | 2009-09-22 16:50:34 (GMT) |
commit | 0d8d7427c8cc0d9b47a81ca8343773b0481b87ad (patch) | |
tree | 5a87fbec0dd262ce9190386008c0e29c1c41987f | |
parent | 074c697177ea699e55970f7678b558f335984782 (diff) | |
download | Qt-0d8d7427c8cc0d9b47a81ca8343773b0481b87ad.zip Qt-0d8d7427c8cc0d9b47a81ca8343773b0481b87ad.tar.gz Qt-0d8d7427c8cc0d9b47a81ca8343773b0481b87ad.tar.bz2 |
Fix QFileInfo autotest to run from a shadow build
Also, don't depend on the existence of ~/.qt/
Reviewed-by: Olivier Goffart
-rw-r--r-- | tests/auto/qfileinfo/qfileinfo.pro | 10 | ||||
-rw-r--r-- | tests/auto/qfileinfo/tst_qfileinfo.cpp | 115 |
2 files changed, 90 insertions, 35 deletions
diff --git a/tests/auto/qfileinfo/qfileinfo.pro b/tests/auto/qfileinfo/qfileinfo.pro index c3be825..93599f4 100644 --- a/tests/auto/qfileinfo/qfileinfo.pro +++ b/tests/auto/qfileinfo/qfileinfo.pro @@ -17,3 +17,13 @@ symbian { TARGET.CAPABILITY=AllFiles LIBS *= -lefsrv } + +# support for running test from shadow build directory +wince* { + DEFINES += SRCDIR=\\\"\\\" +} else:symbian { + # do not define SRCDIR at all +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + diff --git a/tests/auto/qfileinfo/tst_qfileinfo.cpp b/tests/auto/qfileinfo/tst_qfileinfo.cpp index 7c320ff..21edbcf 100644 --- a/tests/auto/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/qfileinfo/tst_qfileinfo.cpp @@ -66,6 +66,10 @@ #include "../network-settings.h" #include <private/qfileinfo_p.h> +#if defined(Q_OS_SYMBIAN) +# define SRCDIR "" +#endif + //TESTED_CLASS= //TESTED_FILES= @@ -183,6 +187,12 @@ tst_QFileInfo::~tst_QFileInfo() #ifdef Q_OS_SYMBIAN QFile::remove("hidden.txt"); QFile::remove("nothidden.txt"); +#else + QFile::remove("tempfile.txt"); +#endif + +#if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) + QDir().rmdir("./.hidden-directory"); #endif } @@ -254,7 +264,7 @@ void tst_QFileInfo::isFile_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << false; - QTest::newRow("data1") << "tst_qfileinfo.cpp" << true; + QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << true; QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true; QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; @@ -287,13 +297,13 @@ void tst_QFileInfo::isDir_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << "tst_qfileinfo.cpp" << false; + QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << 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") << "resources" << true; - QTest::newRow("simple dir with slash") << "resources/" << true; + QTest::newRow("simple dir") << SRCDIR "resources" << true; + QTest::newRow("simple dir with slash") << SRCDIR "resources/" << true; QTest::newRow("broken link") << "brokenlink.lnk" << false; @@ -333,8 +343,8 @@ void tst_QFileInfo::isRoot_data() QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data5") << ":/" << true; - QTest::newRow("simple dir") << "resources" << false; - QTest::newRow("simple dir with slash") << "resources/" << false; + QTest::newRow("simple dir") << SRCDIR "resources" << false; + QTest::newRow("simple dir with slash") << SRCDIR "resources/" << false; #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN) QTest::newRow("drive 1") << "c:" << false; QTest::newRow("drive 2") << "c:/" << true; @@ -365,20 +375,20 @@ void tst_QFileInfo::exists_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << "tst_qfileinfo.cpp" << true; + QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << 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") << "resources/*" << false; - QTest::newRow("data7") << "resources/*.foo" << false; - QTest::newRow("data8") << "resources/*.ext1" << false; - QTest::newRow("data9") << "resources/file?.ext1" << false; + QTest::newRow("data6") << SRCDIR "resources/*" << false; + QTest::newRow("data7") << SRCDIR "resources/*.foo" << false; + QTest::newRow("data8") << SRCDIR "resources/*.ext1" << false; + QTest::newRow("data9") << SRCDIR "resources/file?.ext1" << false; QTest::newRow("data10") << "." << true; QTest::newRow("data11") << ". " << false; - QTest::newRow("simple dir") << "resources" << true; - QTest::newRow("simple dir with slash") << "resources/" << true; + QTest::newRow("simple dir") << SRCDIR "resources" << true; + QTest::newRow("simple dir with slash") << SRCDIR "resources/" << true; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; @@ -507,7 +517,7 @@ void tst_QFileInfo::canonicalFilePath() // test symlinks QFile::remove("link.lnk"); { - QFile file("tst_qfileinfo.cpp"); + QFile file(SRCDIR "tst_qfileinfo.cpp"); if (file.link("link.lnk")) { QFileInfo info1(file); QFileInfo info2("link.lnk"); @@ -521,16 +531,25 @@ void tst_QFileInfo::canonicalFilePath() QFile::remove(link); QFile file(QDir::currentPath()); if (file.link(link)) { - QFileInfo info1("tst_qfileinfo.cpp"); - QFileInfo info2(link + QDir::separator() + "tst_qfileinfo.cpp"); + QFile tempfile("tempfile.txt"); + tempfile.open(QIODevice::ReadWrite); + tempfile.write("This file is generated by the QFileInfo autotest."); + QVERIFY(tempfile.flush()); + tempfile.close(); + + QFileInfo info1("tempfile.txt"); + QFileInfo info2(link + QDir::separator() + "tempfile.txt"); - QVERIFY2(info1.exists(), "If this fails, one reason might be the test system has failed to copy the files."); - QVERIFY2(info2.exists(), "If this fails, one reason might be the test system has failed to copy the files."); + QVERIFY(info1.exists()); + QVERIFY(info2.exists()); QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); QFileInfo info3(link + QDir::separator() + "link.lnk"); + QFileInfo info4(SRCDIR "tst_qfileinfo.cpp"); QVERIFY(!info3.canonicalFilePath().isEmpty()); - QCOMPARE(info1.canonicalFilePath(), info3.canonicalFilePath()); + QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath()); + + tempfile.remove(); } } { @@ -743,7 +762,7 @@ void tst_QFileInfo::permission_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true; - QTest::newRow("data1") << "tst_qfileinfo.cpp" << int(QFile::ReadUser) << true; + QTest::newRow("data1") << SRCDIR "tst_qfileinfo.cpp" << int(QFile::ReadUser) << true; // QTest::newRow("data2") << "tst_qfileinfo.cpp" << int(QFile::WriteUser) << false; QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true; QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false; @@ -803,16 +822,25 @@ void tst_QFileInfo::compare_data() QTest::addColumn<QString>("file2"); QTest::addColumn<bool>("same"); - QTest::newRow("data0") << QString::fromLatin1("tst_qfileinfo.cpp") << QString::fromLatin1("tst_qfileinfo.cpp") << true; - QTest::newRow("data1") << QString::fromLatin1("tst_qfileinfo.cpp") << QString::fromLatin1("/tst_qfileinfo.cpp") << false; - QTest::newRow("data2") << QString::fromLatin1("tst_qfileinfo.cpp") - << QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") << true; - QTest::newRow("casesense1") << QString::fromLatin1("tst_qfileInfo.cpp") - << QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") + QTest::newRow("data0") + << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") + << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") + << true; + QTest::newRow("data1") + << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") + << QString::fromLatin1("/tst_qfileinfo.cpp") + << false; + QTest::newRow("data2") + << QString::fromLatin1("tst_qfileinfo.cpp") + << QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") + << true; + QTest::newRow("casesense1") + << QString::fromLatin1(SRCDIR "tst_qfileInfo.cpp") + << QString::fromLatin1(SRCDIR "tst_qfileinfo.cpp") #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) - << true; + << true; #else - << false; + << false; #endif } @@ -994,7 +1022,7 @@ void tst_QFileInfo::isSymLink_data() QFile::remove("brokenlink.lnk"); QFile::remove("dummyfile"); - QFile file1("tst_qfileinfo.cpp"); + QFile file1(SRCDIR "tst_qfileinfo.cpp"); QVERIFY(file1.link("link.lnk")); QFile file2("dummyfile"); @@ -1006,8 +1034,8 @@ void tst_QFileInfo::isSymLink_data() QTest::addColumn<bool>("isSymLink"); QTest::addColumn<QString>("linkTarget"); - QTest::newRow("existent file") << "tst_qfileinfo.cpp" << false << ""; - QTest::newRow("link") << "link.lnk" << true << QFileInfo("tst_qfileinfo.cpp").absoluteFilePath(); + QTest::newRow("existent file") << SRCDIR "tst_qfileinfo.cpp" << false << ""; + QTest::newRow("link") << "link.lnk" << true << QFileInfo(SRCDIR "tst_qfileinfo.cpp").absoluteFilePath(); QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) @@ -1044,9 +1072,18 @@ void tst_QFileInfo::isHidden_data() QTest::newRow("C:/RECYCLER/..") << QString::fromLatin1("C:/RECYCLER/..") << false; #endif #if defined(Q_OS_UNIX) && !defined(Q_OS_SYMBIAN) - QTest::newRow("~/.qt") << QDir::homePath() + QString("/.qt") << true; - QTest::newRow("~/.qt/.") << QDir::homePath() + QString("/.qt/.") << false; - QTest::newRow("~/.qt/..") << QDir::homePath() + QString("/.qt/..") << false; + + if (!QDir("./.hidden-directory").exists() + && !QDir().mkdir("./.hidden-directory")) + qWarning("Unable to create directory './.hidden-directory'. Some tests will fail."); + + QTest::newRow("./.hidden-directory") << QString("./.hidden-directory") << true; + QTest::newRow("./.hidden-directory/.") << QString("./.hidden-directory/.") << false; + QTest::newRow("./.hidden-directory/..") << QString("./.hidden-directory/..") << false; + + QTest::newRow("/path/to/.hidden-directory") << QDir::currentPath() + QString("/.hidden-directory") << true; + QTest::newRow("/path/to/.hidden-directory/.") << QDir::currentPath() + QString("/.hidden-directory/.") << false; + QTest::newRow("/path/to/.hidden-directory/..") << QDir::currentPath() + QString("/.hidden-directory/..") << false; #endif #if defined(Q_OS_MAC) @@ -1107,6 +1144,7 @@ void tst_QFileInfo::isHidden() QFETCH(QString, path); QFETCH(bool, isHidden); QFileInfo fi(path); + QCOMPARE(fi.isHidden(), isHidden); } @@ -1223,7 +1261,14 @@ void tst_QFileInfo::isWritable() QSKIP("Currently skipped on Symbian OS, but surely there is a writeable file somewhere???", SkipAll); #endif - QVERIFY(QFileInfo("tst_qfileinfo.cpp").isWritable()); + QFile tempfile("tempfile.txt"); + tempfile.open(QIODevice::WriteOnly); + tempfile.write("This file is generated by the QFileInfo autotest."); + tempfile.close(); + + QVERIFY(QFileInfo("tempfile.txt").isWritable()); + tempfile.remove(); + #ifdef Q_OS_WIN #ifdef Q_OS_WINCE QFileInfo fi("\\Windows\\wince.nls"); |