summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-09-30 13:28:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-09-30 17:27:58 +0000
commit0bc3983b8a9b7222c0a85e661919ff2f2e8f958a (patch)
tree79eea7588ef88d52e8d451761d16b3fe7b93d6ef /tests
parent32f957ccc68084fe11fcf23823c5094a1833a790 (diff)
Improve messages in tst_qdir/tst_fileinfo/tst_qfiledialog2.
Introduce error messages showing the path in file existence, file type and directory entry list tests to make fails related to missing UNC shares clearer. Task-number: QTBUG-48504 Change-Id: I5fb401b94cfa8b58562a906b8d9765039e334027 Reviewed-by: Joerg Bornemann <joerg.bornemann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp65
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp94
-rw-r--r--tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp8
3 files changed, 111 insertions, 56 deletions
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index 1f98c75f3f..ae6fe7eaef 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -68,6 +68,12 @@ QT_END_NAMESPACE
#endif
+static QByteArray msgDoesNotExist(const QString &name)
+{
+ return (QLatin1Char('"') + QDir::toNativeSeparators(name)
+ + QLatin1String("\" does not exist.")).toLocal8Bit();
+}
+
class tst_QDir : public QObject
{
Q_OBJECT
@@ -354,7 +360,7 @@ void tst_QDir::mkdir()
//make sure it really exists (ie that mkdir returns the right value)
QFileInfo fi(path);
- QVERIFY(fi.exists() && fi.isDir());
+ QVERIFY2(fi.exists() && fi.isDir(), msgDoesNotExist(path).constData());
}
void tst_QDir::makedirReturnCode()
@@ -378,7 +384,7 @@ void tst_QDir::makedirReturnCode()
f.open(QIODevice::WriteOnly);
f.write("test");
f.close();
- QVERIFY(f.exists());
+ QVERIFY2(f.exists(), msgDoesNotExist(f.fileName()).constData());
QVERIFY(!QDir::current().mkdir(dirName)); // calling mkdir on an existing file will fail.
QVERIFY(!QDir::current().mkpath(dirName)); // calling mkpath on an existing file will fail.
f.remove();
@@ -474,7 +480,7 @@ void tst_QDir::removeRecursivelyFailure()
QVERIFY(!QDir().rmdir(path));
QDir dir(path);
QVERIFY(!dir.removeRecursively()); // didn't work
- QVERIFY(dir.exists()); // still exists
+ QVERIFY2(dir.exists(), msgDoesNotExist(dir.absolutePath()).constData()); // still exists
QVERIFY(dirAsFile.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)));
QVERIFY(dir.removeRecursively());
@@ -527,14 +533,15 @@ void tst_QDir::exists_data()
QTest::newRow("simple dir") << (m_dataPath + "/resources") << true;
QTest::newRow("simple dir with slash") << (m_dataPath + "/resources/") << true;
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
- QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
- QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true;
- QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true;
- QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true;
- QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true;
- QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true;
- QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false;
- QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false;
+ const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
+ QTest::newRow("unc 1") << uncRoot << true;
+ QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
+ QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
+ QTest::newRow("unc 4") << uncRoot + "/testshare/" << true;
+ QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true;
+ QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true;
+ QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false;
+ QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false;
QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false;
#endif
#if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE))
@@ -566,7 +573,10 @@ void tst_QDir::exists()
QFETCH(bool, expected);
QDir dir(path);
- QCOMPARE(dir.exists(), expected);
+ if (expected)
+ QVERIFY2(dir.exists(), msgDoesNotExist(path).constData());
+ else
+ QVERIFY(!dir.exists());
}
void tst_QDir::isRelativePath_data()
@@ -802,7 +812,7 @@ void tst_QDir::entryList()
#endif //Q_NO_SYMLINKS
QDir dir(dirName);
- QVERIFY(dir.exists());
+ QVERIFY2(dir.exists(), msgDoesNotExist(dirName).constData());
QStringList actual = dir.entryList(nameFilters, (QDir::Filters)filterspec,
(QDir::SortFlags)sortspec);
@@ -888,18 +898,25 @@ void tst_QDir::entryListSimple_data()
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << 2;
- QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << 2;
- QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << 2;
- QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << 2;
- QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << 2;
- QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << 2;
- QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << 0;
- QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << 0;
+ const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
+ QTest::newRow("unc 1") << uncRoot << 2;
+ QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << 2;
+ QTest::newRow("unc 3") << uncRoot + "/testshare" << 2;
+ QTest::newRow("unc 4") << uncRoot + "/testshare/" << 2;
+ QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << 2;
+ QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << 2;
+ QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << 0;
+ QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << 0;
QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << 0;
#endif
}
+static QByteArray msgEntryListFailed(int actual, int expectedMin, const QString &name)
+{
+ return QByteArray::number(actual) + " < " + QByteArray::number(expectedMin) + " in \""
+ + QFile::encodeName(QDir::toNativeSeparators(name)) + '"';
+}
+
void tst_QDir::entryListSimple()
{
QFETCH(QString, dirName);
@@ -907,7 +924,7 @@ void tst_QDir::entryListSimple()
QDir dir(dirName);
QStringList actual = dir.entryList();
- QVERIFY(actual.count() >= countMin);
+ QVERIFY2(actual.count() >= countMin, msgEntryListFailed(actual.count(), countMin, dirName).constData());
}
void tst_QDir::entryListWithSymLinks()
@@ -1121,7 +1138,7 @@ void tst_QDir::setNameFilters()
QFETCH(QStringList, expected);
QDir dir(dirName);
- QVERIFY(dir.exists());
+ QVERIFY2(dir.exists(), msgDoesNotExist(dirName).constData());
dir.setNameFilters(nameFilters);
QStringList actual = dir.entryList();
@@ -1504,7 +1521,7 @@ void tst_QDir::exists2()
QDir dir;
if (exists)
- QVERIFY(dir.exists(path));
+ QVERIFY2(dir.exists(path), msgDoesNotExist(path).constData());
else
QVERIFY(!dir.exists(path));
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 8784261c2b..210fdb5a12 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -149,6 +149,25 @@ static QString seedAndTemplate()
qsrand(QDateTime::currentDateTimeUtc().toTime_t());
return QDir::tempPath() + "/tst_qfileinfo-XXXXXX";
}
+
+static QByteArray msgDoesNotExist(const QString &name)
+{
+ return (QLatin1Char('"') + QDir::toNativeSeparators(name)
+ + QLatin1String("\" does not exist.")).toLocal8Bit();
+}
+
+static QByteArray msgIsNoDirectory(const QString &name)
+{
+ return (QLatin1Char('"') + QDir::toNativeSeparators(name)
+ + QLatin1String("\" is not a directory.")).toLocal8Bit();
+}
+
+static QByteArray msgIsNotRoot(const QString &name)
+{
+ return (QLatin1Char('"') + QDir::toNativeSeparators(name)
+ + QLatin1String("\" is no root directory.")).toLocal8Bit();
+}
+
class tst_QFileInfo : public QObject
{
Q_OBJECT
@@ -414,13 +433,14 @@ void tst_QFileInfo::isDir_data()
//QTest::newRow("drive 2") << "t:s" << false;
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
- QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true;
- QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true;
- QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true;
- QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true;
- QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true;
- QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false;
+ const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
+ QTest::newRow("unc 1") << uncRoot << true;
+ QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
+ QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
+ QTest::newRow("unc 4") << uncRoot + "/testshare/" << true;
+ QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true;
+ QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true;
+ QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false;
#endif
}
@@ -429,8 +449,11 @@ void tst_QFileInfo::isDir()
QFETCH(QString, path);
QFETCH(bool, expected);
- QFileInfo fi(path);
- QCOMPARE(fi.isDir(), expected);
+ const bool isDir = QFileInfo(path).isDir();
+ if (expected)
+ QVERIFY2(isDir, msgIsNoDirectory(path).constData());
+ else
+ QVERIFY(!isDir);
}
void tst_QFileInfo::isRoot_data()
@@ -453,10 +476,11 @@ void tst_QFileInfo::isRoot_data()
#endif
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
- QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
- QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true;
- QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << false;
- QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << false;
+ const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
+ QTest::newRow("unc 1") << uncRoot << true;
+ QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
+ QTest::newRow("unc 3") << uncRoot + "/testshare" << false;
+ QTest::newRow("unc 4") << uncRoot + "/testshare/" << false;
QTest::newRow("unc 7") << "//ahostthatshouldnotexist" << false;
#endif
}
@@ -466,8 +490,11 @@ void tst_QFileInfo::isRoot()
QFETCH(QString, path);
QFETCH(bool, expected);
- QFileInfo fi(path);
- QCOMPARE(fi.isRoot(), expected);
+ const bool isRoot = QFileInfo(path).isRoot();
+ if (expected)
+ QVERIFY2(isRoot, msgIsNotRoot(path).constData());
+ else
+ QVERIFY(!isRoot);
}
void tst_QFileInfo::exists_data()
@@ -493,14 +520,15 @@ void tst_QFileInfo::exists_data()
QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true;
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) && !defined(Q_OS_WINRT)
- QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true;
- QTest::newRow("unc 2") << "//" + QtNetworkSettings::winServerName() + "/" << true;
- QTest::newRow("unc 3") << "//" + QtNetworkSettings::winServerName() + "/testshare" << true;
- QTest::newRow("unc 4") << "//" + QtNetworkSettings::winServerName() + "/testshare/" << true;
- QTest::newRow("unc 5") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp" << true;
- QTest::newRow("unc 6") << "//" + QtNetworkSettings::winServerName() + "/testshare/tmp/" << true;
- QTest::newRow("unc 7") << "//" + QtNetworkSettings::winServerName() + "/testshare/adirthatshouldnotexist" << false;
- QTest::newRow("unc 8") << "//" + QtNetworkSettings::winServerName() + "/asharethatshouldnotexist" << false;
+ const QString uncRoot = QStringLiteral("//") + QtNetworkSettings::winServerName();
+ QTest::newRow("unc 1") << uncRoot << true;
+ QTest::newRow("unc 2") << uncRoot + QLatin1Char('/') << true;
+ QTest::newRow("unc 3") << uncRoot + "/testshare" << true;
+ QTest::newRow("unc 4") << uncRoot + "/testshare/" << true;
+ QTest::newRow("unc 5") << uncRoot + "/testshare/tmp" << true;
+ QTest::newRow("unc 6") << uncRoot + "/testshare/tmp/" << true;
+ QTest::newRow("unc 7") << uncRoot + "/testshare/adirthatshouldnotexist" << false;
+ QTest::newRow("unc 8") << uncRoot + "/asharethatshouldnotexist" << false;
QTest::newRow("unc 9") << "//ahostthatshouldnotexist" << false;
#endif
}
@@ -511,8 +539,12 @@ void tst_QFileInfo::exists()
QFETCH(bool, expected);
QFileInfo fi(path);
- QCOMPARE(fi.exists(), expected);
- QCOMPARE(QFileInfo::exists(path), expected);
+ const bool exists = fi.exists();
+ QCOMPARE(exists, QFileInfo::exists(path));
+ if (expected)
+ QVERIFY2(exists, msgDoesNotExist(path).constData());
+ else
+ QVERIFY(!exists);
}
void tst_QFileInfo::absolutePath_data()
@@ -994,7 +1026,7 @@ void tst_QFileInfo::systemFiles()
QSKIP("This is a Windows only test");
#endif
QFileInfo fi("c:\\pagefile.sys");
- QVERIFY(fi.exists());
+ QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData());
QVERIFY(fi.size() > 0);
QVERIFY(fi.lastModified().isValid());
}
@@ -1479,7 +1511,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
QTest::newRow("dummy") << target.path() << false << "" << target.canonicalPath();
QSKIP("link not supported by FS or insufficient privilege");
}
- QVERIFY(file.exists());
+ QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData());
QTest::newRow("absolute dir symlink") << absSymlink << true << QDir::fromNativeSeparators(absTarget) << target.canonicalPath();
QTest::newRow("relative dir symlink") << relSymlink << true << QDir::fromNativeSeparators(relTarget) << target.canonicalPath();
@@ -1510,7 +1542,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data()
QFile file(fileInJunction.absoluteFilePath());
file.open(QIODevice::ReadWrite);
file.close();
- QVERIFY(file.exists());
+ QVERIFY2(file.exists(), msgDoesNotExist(file.fileName()).constData());
QTest::newRow("file in junction") << fileInJunction.absoluteFilePath() << false << "" << fileInJunction.canonicalFilePath();
target = QDir::rootPath();
@@ -1602,7 +1634,7 @@ void tst_QFileInfo::isWritable()
#else
QFileInfo fi("c:\\pagefile.sys");
#endif
- QVERIFY(fi.exists());
+ QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData());
QVERIFY(!fi.isWritable());
#endif
#if defined (Q_OS_QNX) // On QNX /etc is usually on a read-only filesystem
@@ -1860,7 +1892,7 @@ void tst_QFileInfo::owner()
QVERIFY(testFile.write(testData) != -1);
}
QFileInfo fi(fileName);
- QVERIFY(fi.exists());
+ QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData());
QCOMPARE(fi.owner(), userName);
QFile::remove(fileName);
@@ -1895,7 +1927,7 @@ void tst_QFileInfo::group()
QVERIFY(testFile.write(testData) != -1);
testFile.close();
QFileInfo fi(fileName);
- QVERIFY(fi.exists());
+ QVERIFY2(fi.exists(), msgDoesNotExist(fi.absoluteFilePath()).constData());
QCOMPARE(fi.group(), expected);
}
diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
index ed44a5d503..d48c718d4d 100644
--- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
+++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp
@@ -81,6 +81,12 @@ public:
}
};
+static QByteArray msgDoesNotExist(const QString &name)
+{
+ return (QLatin1Char('"') + QDir::toNativeSeparators(name)
+ + QLatin1String("\" does not exist.")).toLocal8Bit();
+}
+
class tst_QFileDialog2 : public QObject
{
Q_OBJECT
@@ -307,7 +313,7 @@ void tst_QFileDialog2::unc()
#else
QString dir(QDir::currentPath());
#endif
- QVERIFY(QFile::exists(dir));
+ QVERIFY2(QFile::exists(dir), msgDoesNotExist(dir).constData());
QNonNativeFileDialog fd(0, QString(), dir);
QFileSystemModel *model = fd.findChild<QFileSystemModel*>("qt_filesystem_model");
QVERIFY(model);