summaryrefslogtreecommitdiffstats
path: root/tests/auto/qxmlquery
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/qxmlquery')
-rw-r--r--tests/auto/qxmlquery/qxmlquery.pro8
-rw-r--r--tests/auto/qxmlquery/tst_qxmlquery.cpp245
2 files changed, 237 insertions, 16 deletions
diff --git a/tests/auto/qxmlquery/qxmlquery.pro b/tests/auto/qxmlquery/qxmlquery.pro
index e8ab641..cfab564 100644
--- a/tests/auto/qxmlquery/qxmlquery.pro
+++ b/tests/auto/qxmlquery/qxmlquery.pro
@@ -10,9 +10,15 @@ RESOURCES = input.qrc
QT += network
+wince* {
+ DEFINES += SRCDIR=\\\"./\\\"
+} else:!symbian {
+ DEFINES += SRCDIR=\\\"$$PWD/\\\"
+}
+
include (../xmlpatterns.pri)
-wince*: {
+wince*|symbian*: {
addFiles.sources = pushBaselines input.xml
addFiles.path = .
diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp
index fbc0e81..d9b5215 100644
--- a/tests/auto/qxmlquery/tst_qxmlquery.cpp
+++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp
@@ -65,6 +65,10 @@
#include "TestFundament.h"
#include "../network-settings.h"
+#if defined(Q_OS_SYMBIAN)
+#define SRCDIR ""
+#endif
+
/*!
\class tst_QXmlQuery
\internal
@@ -88,6 +92,7 @@ public:
, m_pushTestsCount(0)
, m_testNetwork(true)
{
+ Q_SET_DEFAULT_IAP
}
private Q_SLOTS:
@@ -155,6 +160,9 @@ private Q_SLOTS:
void setFocusQIODeviceAvoidVariableClash() const;
void setFocusQIODeviceFailure() const;
void setFocusQIODeviceTriggerWarnings() const;
+ void setFocusQString() const;
+ void setFocusQStringFailure() const;
+ void setFocusQStringSignature() const;
void recompilationWithEvaluateToResultFailing() const;
void secondEvaluationWithEvaluateToResultFailing() const;
void recompilationWithEvaluateToReceiver() const;
@@ -221,6 +229,10 @@ private Q_SLOTS:
void bindVariableQXmlQueryInvalidate() const;
void unknownSourceLocation() const;
+ void identityConstraintSuccess() const;
+ void identityConstraintFailure() const;
+ void identityConstraintFailure_data() const;
+
// TODO call all URI resolving functions where 1) the URI resolver return a null QUrl(); 2) resolves into valid, existing URI, 3) invalid, non-existing URI.
// TODO bind stringlists, variant lists, both ways.
// TODO trigger serialization error, or any error in evaluateToushCallback().
@@ -252,7 +264,7 @@ void tst_QXmlQuery::checkBaseURI(const QUrl &baseURI, const QString &candidate)
QVERIFY(QDir(baseURI.toLocalFile()).relativeFilePath(QFileInfo(candidate).canonicalFilePath()).startsWith("../"));
}
-const char *const tst_QXmlQuery::queriesDirectory = "../xmlpatterns/queries/";
+const char *const tst_QXmlQuery::queriesDirectory = SRCDIR "../xmlpatterns/queries/";
QStringList tst_QXmlQuery::queries()
{
@@ -731,7 +743,7 @@ void tst_QXmlQuery::bindVariableQStringQIODeviceWithString() const
void tst_QXmlQuery::bindVariableQStringQIODeviceWithQFile() const
{
QXmlQuery query;
- QFile inDevice(QLatin1String("input.xml"));
+ QFile inDevice(QLatin1String(SRCDIR "input.xml"));
QVERIFY(inDevice.open(QIODevice::ReadOnly));
@@ -845,7 +857,7 @@ void tst_QXmlQuery::bindVariableXSLTSuccess() const
stylesheet.bindVariable(QLatin1String("paramSelectWithTypeIntBoundWithBindVariableRequired"),
QVariant(QLatin1String("param5")));
- stylesheet.setQuery(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/parameters.xsl"))));
+ stylesheet.setQuery(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/parameters.xsl"))));
QVERIFY(stylesheet.isValid());
@@ -953,7 +965,7 @@ void tst_QXmlQuery::evaluateToReceiver()
PushBaseliner push(stream, query.namePool());
query.evaluateTo(&push);
- const QString baselineName(inputFile(QLatin1String("pushBaselines/") + inputQuery.left(inputQuery.length() - 2) + QString::fromLatin1("ref")));
+ const QString baselineName(inputFile(QLatin1String(SRCDIR "pushBaselines/") + inputQuery.left(inputQuery.length() - 2) + QString::fromLatin1("ref")));
QFile baseline(baselineName);
if(baseline.exists())
@@ -1293,7 +1305,7 @@ void tst_QXmlQuery::basicQtToXQueryTypeCheck() const
// TODO Do with different QDateTime time specs
query.bindVariable(QLatin1String("fromQDateTime"), QXmlItem(QDateTime(QDate(2001, 9, 10), QTime(1, 2, 3))));
query.bindVariable(QLatin1String("fromDouble"), QXmlItem(double(3)));
- query.bindVariable(QLatin1String("fromFloat"), QXmlItem(float(4)));
+// query.bindVariable(QLatin1String("fromFloat"), QXmlItem(float(4)));
query.bindVariable(QLatin1String("integer"), QXmlItem(5));
query.bindVariable(QLatin1String("fromQString"), QXmlItem(QString::fromLatin1("A QString")));
query.bindVariable(QLatin1String("fromQChar"), QXmlItem(QChar::fromLatin1('C')));
@@ -1786,11 +1798,11 @@ void tst_QXmlQuery::setFocusQUrl() const
{
QXmlQuery query(QXmlQuery::XSLT20);
- const TestURIResolver resolver(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/documentElement.xml"))));
+ const TestURIResolver resolver(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/documentElement.xml"))));
query.setUriResolver(&resolver);
QVERIFY(query.setFocus(QUrl(QLatin1String("arbitraryURI"))));
- query.setQuery(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/copyWholeDocument.xsl"))));
+ query.setQuery(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/copyWholeDocument.xsl"))));
QVERIFY(query.isValid());
QBuffer result;
@@ -1895,6 +1907,55 @@ void tst_QXmlQuery::setFocusQIODeviceFailure() const
}
}
+void tst_QXmlQuery::setFocusQString() const
+{
+ QXmlQuery query;
+
+ /* Basic use of focus. */
+ {
+ QVERIFY(query.setFocus(QLatin1String("<e>textNode</e>")));
+ query.setQuery(QLatin1String("string()"));
+ QVERIFY(query.isValid());
+ QString out;
+ query.evaluateTo(&out);
+ QCOMPARE(out, QString::fromLatin1("textNode\n"));
+ }
+
+ /* Set to a new focus, make sure it changes and works. */
+ {
+ QVERIFY(query.setFocus(QLatin1String("<e>newFocus</e>")));
+ QString out;
+ query.evaluateTo(&out);
+ QCOMPARE(out, QString::fromLatin1("newFocus\n"));
+ }
+}
+
+void tst_QXmlQuery::setFocusQStringFailure() const
+{
+ QXmlQuery query;
+ MessageSilencer silencer;
+
+ query.setMessageHandler(&silencer);
+ QVERIFY(!query.setFocus(QLatin1String("<notWellformed")));
+
+ /* Let's try the slight special case of a null string. */
+ QVERIFY(!query.setFocus(QString()));
+}
+
+void tst_QXmlQuery::setFocusQStringSignature() const
+{
+ QXmlQuery query;
+ MessageSilencer silencer;
+ query.setMessageHandler(&silencer);
+
+ const QString argument;
+ /* We should take a const ref. */
+ query.setFocus(argument);
+
+ /* We should return a bool. */
+ static_cast<bool>(query.setFocus(QString()));
+}
+
void tst_QXmlQuery::setFocusQIODeviceTriggerWarnings() const
{
/* A null pointer. */
@@ -1955,7 +2016,7 @@ void tst_QXmlQuery::fnDocNetworkAccessSuccess_data() const
QTest::addColumn<QByteArray>("expectedOutput");
QTest::newRow("file scheme")
- << inputFileAsURI(QLatin1String("input.xml"))
+ << inputFileAsURI(QLatin1String(SRCDIR "input.xml"))
<< QByteArray("<!-- This is just a file for testing. --><input/>");
QTest::newRow("data scheme with ASCII")
@@ -2921,6 +2982,9 @@ void tst_QXmlQuery::enumQueryLanguage() const
/* These enum values should be possible to OR for future plans. */
QCOMPARE(int(QXmlQuery::XQuery10), 1);
QCOMPARE(int(QXmlQuery::XSLT20), 2);
+ QCOMPARE(int(QXmlQuery::XmlSchema11IdentityConstraintSelector), 1024);
+ QCOMPARE(int(QXmlQuery::XmlSchema11IdentityConstraintField), 2048);
+ QCOMPARE(int(QXmlQuery::XPath20), 4096);
}
void tst_QXmlQuery::setInitialTemplateNameQXmlName() const
@@ -2933,7 +2997,7 @@ void tst_QXmlQuery::setInitialTemplateNameQXmlName() const
QCOMPARE(query.initialTemplateName(), name);
- query.setQuery(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/namedTemplate.xsl"))));
+ query.setQuery(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/namedTemplate.xsl"))));
QVERIFY(query.isValid());
QBuffer result;
@@ -2995,7 +3059,7 @@ void tst_QXmlQuery::setNetworkAccessManager() const
/* Ensure fn:doc() picks up the right QNetworkAccessManager. */
{
NetworkOverrider networkOverrider(QUrl(QLatin1String("tag:example.com:DOESNOTEXIST")),
- QUrl(inputFile(QLatin1String("../xmlpatterns/queries/simpleDocument.xml"))));
+ QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/queries/simpleDocument.xml"))));
QXmlQuery query;
query.setNetworkAccessManager(&networkOverrider);
@@ -3011,7 +3075,7 @@ void tst_QXmlQuery::setNetworkAccessManager() const
/* Ensure setQuery() is using the right network manager. */
{
NetworkOverrider networkOverrider(QUrl(QLatin1String("tag:example.com:DOESNOTEXIST")),
- QUrl(inputFile(QLatin1String("../xmlpatterns/queries/concat.xq"))));
+ QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/queries/concat.xq"))));
QXmlQuery query;
query.setNetworkAccessManager(&networkOverrider);
@@ -3069,9 +3133,9 @@ void tst_QXmlQuery::multipleDocsAndFocus() const
/* We use string concatenation, since variable bindings might disturb what
* we're testing. */
query.setQuery(QLatin1String("string(doc('") +
- inputFile(QLatin1String("../xmlpatterns/queries/simpleDocument.xml")) +
+ inputFile(QLatin1String(SRCDIR "../xmlpatterns/queries/simpleDocument.xml")) +
QLatin1String("'))"));
- query.setFocus(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/documentElement.xml"))));
+ query.setFocus(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/documentElement.xml"))));
query.setQuery(QLatin1String("string(.)"));
QStringList result;
@@ -3095,11 +3159,11 @@ void tst_QXmlQuery::multipleEvaluationsWithDifferentFocus() const
QXmlQuery query;
QStringList result;
- query.setFocus(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/documentElement.xml"))));
+ query.setFocus(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/documentElement.xml"))));
query.setQuery(QLatin1String("string(.)"));
QVERIFY(query.evaluateTo(&result));
- query.setFocus(QUrl(inputFile(QLatin1String("../xmlpatterns/stylesheets/documentElement.xml"))));
+ query.setFocus(QUrl(inputFile(QLatin1String(SRCDIR "../xmlpatterns/stylesheets/documentElement.xml"))));
QVERIFY(query.evaluateTo(&result));
}
@@ -3240,6 +3304,157 @@ void tst_QXmlQuery::unknownSourceLocation() const
query.evaluateTo(&output);
}
+void tst_QXmlQuery::identityConstraintSuccess() const
+{
+ QXmlQuery::QueryLanguage queryLanguage = QXmlQuery::XmlSchema11IdentityConstraintSelector;
+
+ /* We run this code for Selector and Field. */
+ for(int i = 0; i < 3; ++i)
+ {
+ QXmlNamePool namePool;
+ QXmlResultItems result;
+ QXmlItem node;
+
+ {
+ QXmlQuery nodeSource(namePool);
+ nodeSource.setQuery(QLatin1String("<e/>"));
+
+ nodeSource.evaluateTo(&result);
+ node = result.next();
+ }
+
+ /* Basic use:
+ * 1. The focus is undefined, but it's still valid.
+ * 2. We never evaluate. */
+ {
+ QXmlQuery query(queryLanguage);
+ query.setQuery(QLatin1String("a"));
+ QVERIFY(query.isValid());
+ }
+
+ /* Basic use:
+ * 1. The focus is undefined, but it's still valid.
+ * 2. We afterwards set the focus. */
+ {
+ QXmlQuery query(queryLanguage, namePool);
+ query.setQuery(QLatin1String("a"));
+ query.setFocus(node);
+ QVERIFY(query.isValid());
+ }
+
+ /* Basic use:
+ * 1. The focus is undefined, but it's still valid.
+ * 2. We afterwards set the focus.
+ * 3. We evaluate. */
+ {
+ QXmlQuery query(queryLanguage, namePool);
+ query.setQuery(QString(QLatin1Char('.')));
+ query.setFocus(node);
+ QVERIFY(query.isValid());
+
+ QString result;
+ QVERIFY(query.evaluateTo(&result));
+ QCOMPARE(result, QString::fromLatin1("<e/>\n"));
+ }
+
+ /* A slightly more complex Field. */
+ {
+ QXmlQuery query(queryLanguage);
+ query.setQuery(QLatin1String("* | .//xml:*/."));
+ QVERIFY(query.isValid());
+ }
+
+ /* @ is only allowed in Field. */
+ if(queryLanguage == QXmlQuery::XmlSchema11IdentityConstraintField)
+ {
+ QXmlQuery query(QXmlQuery::XmlSchema11IdentityConstraintField);
+ query.setQuery(QLatin1String("@abc"));
+ QVERIFY(query.isValid());
+ }
+
+ /* Field allows attribute:: and child:: .*/
+ if(queryLanguage == QXmlQuery::XmlSchema11IdentityConstraintField)
+ {
+ QXmlQuery query(QXmlQuery::XmlSchema11IdentityConstraintField);
+ query.setQuery(QLatin1String("attribute::name | child::name"));
+ QVERIFY(query.isValid());
+ }
+
+ /* Selector allows only child:: .*/
+ {
+ QXmlQuery query(QXmlQuery::XmlSchema11IdentityConstraintSelector);
+ query.setQuery(QLatin1String("child::name"));
+ QVERIFY(query.isValid());
+ }
+
+ if(i == 0)
+ queryLanguage = QXmlQuery::XmlSchema11IdentityConstraintField;
+ else if(i == 1)
+ queryLanguage = QXmlQuery::XPath20;
+ }
+}
+
+Q_DECLARE_METATYPE(QXmlQuery::QueryLanguage);
+
+/*!
+ We just do some basic tests for boot strapping and sanity checking. The actual regression
+ testing is in the Schema suite.
+ */
+void tst_QXmlQuery::identityConstraintFailure() const
+{
+ QFETCH(QXmlQuery::QueryLanguage, queryLanguage);
+ QFETCH(QString, inputQuery);
+
+ QXmlQuery query(queryLanguage);
+ MessageSilencer silencer;
+ query.setMessageHandler(&silencer);
+
+ query.setQuery(inputQuery);
+ QVERIFY(!query.isValid());
+}
+
+void tst_QXmlQuery::identityConstraintFailure_data() const
+{
+ QTest::addColumn<QXmlQuery::QueryLanguage>("queryLanguage");
+ QTest::addColumn<QString>("inputQuery");
+
+ QTest::newRow("We don't have element constructors in identity constraint pattern, "
+ "it's an XQuery feature(Selector).")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("<e/>");
+
+ QTest::newRow("We don't have functions in identity constraint pattern, "
+ "it's an XPath feature(Selector).")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("current-time()");
+
+ QTest::newRow("We don't have element constructors in identity constraint pattern, "
+ "it's an XQuery feature(Field).")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("<e/>");
+
+ QTest::newRow("We don't have functions in identity constraint pattern, "
+ "it's an XPath feature(Field).")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("current-time()");
+
+ QTest::newRow("@attributeName is disallowed for the selector.")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("@abc");
+
+ QTest::newRow("attribute:: is disallowed for the selector.")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("attribute::name");
+
+ QTest::newRow("ancestor::name is disallowed for the selector.")
+ << QXmlQuery::XmlSchema11IdentityConstraintSelector
+ << QString::fromLatin1("ancestor::name");
+
+ QTest::newRow("ancestor::name is disallowed for the field.")
+ << QXmlQuery::XmlSchema11IdentityConstraintField
+ << QString::fromLatin1("ancestor::name");
+}
+
QTEST_MAIN(tst_QXmlQuery)
#include "tst_qxmlquery.moc"