summaryrefslogtreecommitdiffstats
path: root/tests/auto/qxmlquery
diff options
context:
space:
mode:
authorJason Barron <jbarron@trolltech.com>2009-07-24 09:45:33 (GMT)
committerJason Barron <jbarron@trolltech.com>2009-07-27 13:04:30 (GMT)
commit3643028959f0b38350e57e60ba4000435b75e592 (patch)
treec129e4dee11487abd437ab8ebd993ba261e06fa6 /tests/auto/qxmlquery
parentcf66c667a97c0079141eb3f2d9e997b7378ae792 (diff)
parentc36139c665e61866aff4bf8572890a735167a7d0 (diff)
downloadQt-3643028959f0b38350e57e60ba4000435b75e592.zip
Qt-3643028959f0b38350e57e60ba4000435b75e592.tar.gz
Qt-3643028959f0b38350e57e60ba4000435b75e592.tar.bz2
Merge commit 'qt/master-stable'
Conflicts: configure.exe qmake/Makefile.unix qmake/generators/makefile.cpp src/corelib/global/qglobal.h src/corelib/kernel/kernel.pri src/corelib/kernel/qcoreevent.cpp src/corelib/kernel/qsharedmemory_unix.cpp src/gui/graphicsview/qgraphicsscene.cpp src/gui/kernel/qaction.cpp src/gui/kernel/qaction.h src/gui/kernel/qaction_p.h src/gui/kernel/qapplication.cpp src/gui/kernel/qapplication.h src/gui/kernel/qwidget.cpp src/gui/kernel/qwidget.h src/gui/kernel/qwidget_mac.mm src/gui/painting/qgraphicssystemfactory.cpp src/gui/styles/qwindowsstyle.cpp src/gui/text/qfontengine_qpf.cpp src/gui/widgets/qabstractscrollarea_p.h src/network/access/qnetworkaccessdebugpipebackend.cpp src/network/socket/qlocalsocket_unix.cpp src/network/socket/qnativesocketengine_p.h src/network/socket/qnativesocketengine_unix.cpp src/openvg/qpaintengine_vg.cpp tests/auto/q3sqlcursor/tst_q3sqlcursor.cpp tests/auto/qcssparser/qcssparser.pro tests/auto/qdir/tst_qdir.cpp tests/auto/qfile/tst_qfile.cpp tests/auto/qobject/tst_qobject.cpp tests/auto/qpathclipper/qpathclipper.pro tests/auto/qprocess/tst_qprocess.cpp tests/auto/qsettings/tst_qsettings.cpp tests/auto/qsharedpointer/qsharedpointer.pro tests/auto/qsqlquerymodel/qsqlquerymodel.pro tests/auto/qsqlrelationaltablemodel/qsqlrelationaltablemodel.pro tests/auto/qsqltablemodel/qsqltablemodel.pro tests/auto/qsqlthread/qsqlthread.pro tests/auto/qwidget/tst_qwidget.cpp
Diffstat (limited to 'tests/auto/qxmlquery')
-rw-r--r--tests/auto/qxmlquery/tst_qxmlquery.cpp176
1 files changed, 176 insertions, 0 deletions
diff --git a/tests/auto/qxmlquery/tst_qxmlquery.cpp b/tests/auto/qxmlquery/tst_qxmlquery.cpp
index 1846dcb..ebf992d 100644
--- a/tests/auto/qxmlquery/tst_qxmlquery.cpp
+++ b/tests/auto/qxmlquery/tst_qxmlquery.cpp
@@ -223,6 +223,11 @@ private Q_SLOTS:
void bindVariableQXmlNameQXmlQuerySignature() const;
void bindVariableQXmlNameQXmlQuery() const;
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.
@@ -2973,6 +2978,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
@@ -3275,6 +3283,174 @@ void tst_QXmlQuery::bindVariableQXmlQueryInvalidate() const
QVERIFY(!query.isValid());
}
+void tst_QXmlQuery::unknownSourceLocation() const
+{
+ QBuffer b;
+ b.setData("<a><b/><b/></a>");
+ b.open(QIODevice::ReadOnly);
+
+ MessageSilencer silencer;
+ QXmlQuery query;
+ query.bindVariable(QLatin1String("inputDocument"), &b);
+ query.setMessageHandler(&silencer);
+
+ query.setQuery(QLatin1String("doc($inputDocument)/a/(let $v := b/string() return if ($v) then $v else ())"));
+
+ QString output;
+ 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"