diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2019-09-20 10:46:42 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-09-20 11:33:02 +0200 |
commit | af8b508de56fee70d6f3c971254fcb848805d18f (patch) | |
tree | ffe733d7ec5f491f7e866e24eb42cd60bdeb9733 /tests/auto | |
parent | 7c5edab6d578be7fb1f6da9b5788ee6f628029cc (diff) | |
download | qtxmlpatterns-af8b508de56fee70d6f3c971254fcb848805d18f.tar.gz |
Make a test conditional on its set-up having succeededv5.14.0-beta1v5.14.0-alpha1
tst_QXmlQuery::setQueryQUrlFailure()'s sub-test "Query via file:/ that
does not have read permissions." depends on the file it tries to read
being unreadable. The test's set-up contained a comment explaining why
we don't QVERIFY() that it succeeded, but went ahead with adding the
test-case regardless. Oddly enough, when the set-up fails to deny
permissions, the test fails because the file can be read, so isn't
found invalid.
Made addition of the test-case conditional on the set-up having
succeeded. This made a long line over-long; and it included a
duplicated long slab of boring code, used in another test, so extract
that piece of code as a lambda and use it twice to save
duplication. The tests were also passing raw C-strings to QUrl(),
which wants a QString, so give it QStringLiteral() in one case and the
existing QString with the relevant name in the other.
Fixes: QTBUG-78560
Change-Id: I2e9ca6fe526edfc021cb4978c81fc9204e047c7f
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qxmlquery/tst_qxmlquery.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp index 09d3816..d1b125b 100644 --- a/tests/auto/qxmlquery/tst_qxmlquery.cpp +++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp @@ -2595,13 +2595,16 @@ void tst_QXmlQuery::setQueryQUrlFailure() const void tst_QXmlQuery::setQueryQUrlFailure_data() const { + const auto localFileUrl = [](const QString &relPath) { + return QUrl::fromLocalFile(QCoreApplication::applicationFilePath()).resolved(QUrl(relPath)); + }; QTest::addColumn<QUrl>("queryURI"); QTest::newRow("Query via file:// that does not exist.") << QUrl::fromEncoded("file://example.com/does/not/exist"); QTest::newRow("A query via file:// that is completely empty, but readable.") - << QUrl::fromLocalFile(QCoreApplication::applicationFilePath()).resolved(QUrl("../xmlpatterns/queries/completelyEmptyQuery.xq")); + << localFileUrl(QStringLiteral("../xmlpatterns/queries/completelyEmptyQuery.xq")); { const QString name(QLatin1String("nonReadableFile.xq")); @@ -2610,10 +2613,10 @@ void tst_QXmlQuery::setQueryQUrlFailure_data() const outFile.write(QByteArray("1")); outFile.close(); /* On some windows versions, this fails, so we don't check that this works with QVERIFY. */ - outFile.setPermissions(QFile::Permissions(QFile::Permissions())); - - QTest::newRow("Query via file:/ that does not have read permissions.") - << QUrl::fromLocalFile(QCoreApplication::applicationFilePath()).resolved(QUrl("nonReadableFile.xq")); + if (outFile.setPermissions(QFile::Permissions())) { + QTest::newRow("Query via file:/ that does not have read permissions.") + << localFileUrl(name); + } } if(!m_testNetwork) |