summaryrefslogtreecommitdiff
path: root/tests/auto/qxmlquery/tst_qxmlquery.cpp
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2009-05-16 12:19:10 +0200
committerTobias Koenig <tokoe@kde.org>2009-05-16 12:19:10 +0200
commit135a028d9dc9a28a0a072665a7dc43b7e9e187be (patch)
treed259e1d265589d10a541899d4982ab4e656900eb /tests/auto/qxmlquery/tst_qxmlquery.cpp
parent210bd7b6033e41aad61fe131002dc5e496d7427a (diff)
downloadqt4-tools-135a028d9dc9a28a0a072665a7dc43b7e9e187be.tar.gz
Add W3C XML Schema validation support
This was done by Tobias Koenig, as part of an internship at Trolltech/Qt Software, started at Wed Oct 1 18:32:43 2008 +0200, and the last commit being part of this commit dating Tue Feb 24 11:03:36 2009 +0100. This is work consisting of about 650 commits squashed into one, where the first commit was 61b280386c1905a15690fdd917dcbc8eb09b6283, in the repository before Qt's history cut.
Diffstat (limited to 'tests/auto/qxmlquery/tst_qxmlquery.cpp')
-rw-r--r--tests/auto/qxmlquery/tst_qxmlquery.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp
index d4575814f5..6d8a803409 100644
--- a/tests/auto/qxmlquery/tst_qxmlquery.cpp
+++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp
@@ -220,6 +220,10 @@ private Q_SLOTS:
void bindVariableQXmlNameQXmlQuery() const;
void bindVariableQXmlQueryInvalidate() 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().
@@ -2920,6 +2924,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
@@ -3222,6 +3229,157 @@ void tst_QXmlQuery::bindVariableQXmlQueryInvalidate() const
QVERIFY(!query.isValid());
}
+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"