1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QtTest/QtTest>
46 #include "../qxmlquery/TestFundament.h"
47 #include "../network-settings.h"
49 #if defined(Q_OS_SYMBIAN)
54 \class tst_XmlPatterns
57 \brief Tests the command line interface, \c xmlpatterns, for the XQuery code.
59 This test is not intended for testing the engine, but all the gluing the
60 command line interface do: error reporting, query output, variable bindings, exit
63 In other words, if you have an engine bug; don't add it here because it won't be
64 tested properly. Instead add it to the test suite.
67 class tst_XmlPatterns : public QObject
68 , private TestFundament
78 void xquerySupport_data() const;
80 void xsltSupport_data() const;
81 void stdoutFailure() const;
82 void cleanupTestCase() const;
85 static void createNonWritable(const QString &name);
86 static void removeNonWritable(QFile &outFile);
90 * Get rid of characters that complicates on various file systems.
92 const QRegExp m_normalizeTestName;
94 * @note Perforce disallows wildcards in the name.
96 const QRegExp m_filenameInStderr;
97 const QString m_command;
101 tst_XmlPatterns::tst_XmlPatterns() : m_generatedTests(0)
102 , m_normalizeTestName(QLatin1String("[\\*\\?#\\-\\/:; ()',&]"))
103 , m_filenameInStderr(QLatin1String("file:\\/\\/.*(\\.xq|\\.gccxml|\\.xml|\\.xsl|-)(,|:)"))
104 , m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/xmlpatterns"))
109 void tst_XmlPatterns::initTestCase()
111 QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
113 QVERIFY(m_normalizeTestName.isValid());
114 QVERIFY(m_filenameInStderr.isValid());
117 process.start(m_command);
119 if(!process.waitForFinished())
124 "The command line tool (%1) could not be run, possibly because Qt was "
125 "incompletely built or installed. No tests will be run."
132 void tst_XmlPatterns::xquerySupport()
135 QSKIP("The command line utility is not in the path.");
138 QSKIP("WinCE: This test uses unsupported WinCE functionality");
139 #elif defined(Q_OS_SYMBIAN)
140 QSKIP("Symbian: This test uses unsupported Symbian functionality (QProcess with std streams)");
141 #elif defined(Q_OS_MAC)
142 QSKIP("MacOs: Failed on Mac. Will be fixed by bug fix for QTBUG-22556");
145 QFETCH(int, expectedExitCode);
146 QFETCH(QByteArray, expectedQueryOutput);
147 QFETCH(QStringList, arguments);
148 QFETCH(QString, cwd);
149 QFETCH(QString, outputFile);
154 process.setWorkingDirectory(inputFile(cwd));
156 process.start(m_command, arguments);
158 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
159 QVERIFY(process.waitForFinished());
161 if(process.exitCode() != expectedExitCode)
162 QTextStream(stderr) << "stderr:" << process.readAllStandardError();
164 QCOMPARE(process.exitCode(), expectedExitCode);
166 const QByteArray rawProducedStderr((process.readAllStandardError()));
167 QString fixedStderr(QString::fromLocal8Bit(rawProducedStderr).remove(m_filenameInStderr));
168 // convert Windows line endings to Unix ones
169 fixedStderr.replace("\r\n", "\n");
171 const QString errorFileName(inputFile(QLatin1String(SRCDIR "stderrBaselines/") +
172 QString::fromUtf8(QTest::currentDataTag()).remove(m_normalizeTestName) +
173 QLatin1String(".txt")));
175 QFile writeErr(errorFileName);
177 if(writeErr.exists())
179 QVERIFY(writeErr.open(QIODevice::ReadOnly));
180 QString rawExpectedStdErr(QString::fromLocal8Bit(writeErr.readAll()));
182 /* On Windows, at least MinGW, this differs. */
183 if(qstrcmp(QTest::currentDataTag(), "-output with a non-writable file") == 0)
185 QVERIFY(fixedStderr == rawExpectedStdErr.remove(m_filenameInStderr) ||
186 fixedStderr.trimmed() == "Failed to open file notWritable.out for writing: Access is denied.");
188 else if(qstrcmp(QTest::currentDataTag(), "Invoke -version") == 0)
190 /* There's a wide range of different version strings used. For
191 * instance, "4.4.0-rc1". */
192 const QRegExp removeVersion(QLatin1String(" Qt \\d\\.\\d.*"));
193 QVERIFY(removeVersion.isValid());
194 QCOMPARE(QString(fixedStderr).remove(removeVersion) + QChar('|'), rawExpectedStdErr + QChar('|'));
197 QCOMPARE(fixedStderr, rawExpectedStdErr.remove(m_filenameInStderr));
201 QFile writeErr(errorFileName);
202 QVERIFY(writeErr.open(QIODevice::WriteOnly));
204 QCOMPARE(writeErr.write(rawProducedStderr), qint64(rawProducedStderr.count()));
205 QTextStream(stderr) << "creating file " << errorFileName;
209 const QByteArray actual(process.readAllStandardOutput());
211 if(outputFile.isEmpty())
213 QCOMPARE(actual, expectedQueryOutput);
214 return; /* We're done, this test was not creating any output file. */
218 QVERIFY(actual.isEmpty());
220 QFile outFile(outputFile);
222 QVERIFY(outFile.exists());
223 QVERIFY(outFile.open(QIODevice::ReadOnly));
225 QCOMPARE(outFile.readAll(), expectedQueryOutput);
227 removeNonWritable(outFile);
231 void tst_XmlPatterns::xquerySupport_data() const
233 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
237 /* Check one file for existence, to avoid possible false positives. */
238 QVERIFY(QFile::exists(inputFile(QLatin1String(SRCDIR "queries/onePlusOne.xq"))));
240 QTest::addColumn<int>("expectedExitCode");
241 QTest::addColumn<QByteArray>("expectedQueryOutput");
242 QTest::addColumn<QStringList>("arguments");
243 QTest::addColumn<QString>("cwd");
244 QTest::addColumn<QString>("outputFile");
246 QTest::newRow("A simple math query")
249 << QStringList((QLatin1String(SRCDIR "queries/onePlusOne.xq")))
253 QTest::newRow("An unbound external variable")
256 << QStringList(QLatin1String(SRCDIR "queries/externalVariable.xq"))
260 QTest::newRow("Bind an external variable")
262 << QByteArray("1 4<e>1</e>true\n")
263 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
264 << QLatin1String("-param")
265 << QLatin1String("externalVariable=1"))
269 QTest::newRow("Bind an external variable, query appearing last")
271 << QByteArray("1 4<e>1</e>true\n")
272 << (QStringList() << QLatin1String("-param")
273 << QLatin1String("externalVariable=1")
274 << QLatin1String(SRCDIR "queries/externalVariable.xq"))
278 QTest::newRow("Use fn:doc")
280 << QByteArray("<e xmlns=\"http://example.com\" xmlns:p=\"http://example.com/P\" attr=\"1\" p:attr=\"\">\n <?target data?>\n <!-- a comment -->\n <e/>text <f/>text node</e>\n")
281 << QStringList(QLatin1String(SRCDIR "queries/openDocument.xq"))
285 QTest::newRow("Use fn:doc, together with -no-format, last")
287 << QByteArray("<e xmlns=\"http://example.com\" xmlns:p=\"http://example.com/P\" attr=\"1\" p:attr=\"\"><?target data?><!-- a comment --><e/>text <f/>text node</e>")
288 << (QStringList() << QLatin1String(SRCDIR "queries/openDocument.xq")
289 << QLatin1String("-no-format"))
293 QTest::newRow("Use fn:doc, together with -no-format, first")
295 << QByteArray("<e xmlns=\"http://example.com\" xmlns:p=\"http://example.com/P\" attr=\"1\" p:attr=\"\"><?target data?><!-- a comment --><e/>text <f/>text node</e>")
296 << (QStringList() << QLatin1String("-no-format")
297 << QLatin1String(SRCDIR "queries/openDocument.xq"))
301 /* This is true for the command line utility, but not QXmlQuery::setQuery(). */
302 QTest::newRow("Make sure query paths are resolved against CWD, not the location of the executable.")
305 << QStringList(QLatin1String(SRCDIR "queries/onePlusOne.xq"))
306 << QString::fromLatin1("queries")
309 QTest::newRow("Call fn:error()")
312 << QStringList(QLatin1String(SRCDIR "queries/errorFunction.xq"))
316 QTest::newRow("Evaluate a library module")
319 << QStringList(QLatin1String(SRCDIR "queries/simpleLibraryModule.xq"))
323 QTest::newRow("Trigger a static error.")
326 << QStringList(QLatin1String(SRCDIR "queries/staticError.xq"))
330 QTest::newRow("Pass -help")
333 << QStringList(QLatin1String("-help"))
337 QTest::newRow("Open an nonexistent file")
340 << QStringList(QLatin1String(SRCDIR "queries/ThisFileDoesNotExist.xq"))
344 /* The following five tests exists to test the various
345 * markup classes in the message. */
346 QTest::newRow("XQuery-function message markups")
349 << QStringList(QLatin1String(SRCDIR "queries/wrongArity.xq"))
353 QTest::newRow("XQuery-type message markups")
356 << QStringList(QLatin1String(SRCDIR "queries/typeError.xq"))
360 QTest::newRow("XQuery-data & XQuery-keyword message markups")
363 << QStringList(QLatin1String(SRCDIR "queries/zeroDivision.xq"))
367 QTest::newRow("XQuery-uri message markups")
370 << QStringList(QLatin1String(SRCDIR "queries/unsupportedCollation.xq"))
374 QTest::newRow("XQuery-expression message markups")
377 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexp.xq"))
381 QTest::newRow("Print a list of available regexp flags(The available flags are formatted in a complex way.)")
384 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexpFlag.xq"))
388 QTest::newRow("Trigger an assert in QPatternist::ColorOutput. The query naturally contains an error; XPTY0004.")
391 << QStringList(QLatin1String(SRCDIR "queries/flwor.xq"))
395 QTest::newRow("Trigger a second assert in QPatternist::ColorOutput. The query naturally contains XPST0003.")
398 << QStringList(QLatin1String(SRCDIR "queries/syntaxError.xq"))
402 QTest::newRow("-param is missing so multiple queries appear")
405 << (QStringList() << QLatin1String(SRCDIR "queries/reportGlobals.xq")
406 << QLatin1String("fileToOpen=globals.gccxml"))
410 QTest::newRow("only -no-format")
413 << (QStringList() << QLatin1String("-no-format"))
417 QTest::newRow("Basic use of -output, query first")
420 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
421 << QLatin1String("-output")
422 << QLatin1String("basicOutput.out"))
424 << QString::fromLatin1("basicOutput.out");
426 QTest::newRow("Basic use of -output, query last")
428 << QByteArray("<e/>\n")
429 << (QStringList() << QLatin1String("-output")
430 << QLatin1String("basicOutput2.out")
431 << QLatin1String(SRCDIR "queries/oneElement.xq"))
433 << QString::fromLatin1("basicOutput2.out");
435 QTest::newRow("A single query, that does not exist")
438 << (QStringList() << QLatin1String(SRCDIR "doesNotExist.xq"))
442 QTest::newRow("Specify two identical query names")
445 << (QStringList() << QLatin1String(SRCDIR "query.xq")
446 << QLatin1String(SRCDIR "query.xq"))
450 QTest::newRow("Specify no arguments at all.")
457 QTest::newRow("Use -output twice")
460 << (QStringList() << QLatin1String("-output")
461 << QLatin1String("output1")
462 << QLatin1String("-output")
463 << QLatin1String("output2"))
468 const QString filename(QString::fromLatin1("notWritable.out"));
469 createNonWritable(filename);
471 QTest::newRow("-output with a non-writable file")
474 << (QStringList() << QLatin1String("-output")
476 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
482 const QString outName(QString::fromLatin1("existingContent.out"));
483 QFile outFile(outName);
484 QVERIFY(outFile.open(QIODevice::WriteOnly));
485 QCOMPARE(outFile.write("Existing content\n"), qint64(17));
488 QTest::newRow("Use -output on a file with existing content, to ensure we truncate, not append the content we produce.")
491 << (QStringList() << QLatin1String("-output")
493 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
498 QTest::newRow("one query, and a terminating dash at the end")
501 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
502 << QLatin1String("-"))
506 QTest::newRow("one query, with a preceding dash")
509 << (QStringList() << QLatin1String("-")
510 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
514 QTest::newRow("A single dash, that's invalid")
517 << (QStringList() << QLatin1String("-"))
521 QTest::newRow("Invoke -version")
524 << (QStringList() << QLatin1String("-version"))
528 QTest::newRow("Unknown switch; -unknown-switch")
531 << (QStringList() << QLatin1String("-unknown-switch"))
535 QTest::newRow("Unknown switch; -d")
538 << (QStringList() << QLatin1String("-d"))
542 QTest::newRow("Passing a single dash is insufficient")
545 << (QStringList() << QLatin1String("-"))
549 QTest::newRow("Passing two dashes, the last is interpreted as a file name")
552 << (QStringList() << QLatin1String("-")
553 << QLatin1String("-"))
557 QTest::newRow("Pass three dashes, the two last gets interpreted as two query arguments")
560 << (QStringList() << QLatin1String("-")
561 << QLatin1String("-")
562 << QLatin1String("-"))
566 QTest::newRow("Load query via data: scheme")
568 << QByteArray("<e/>\n")
569 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml,%3Ce%2F%3E"))
573 QTest::newRow("Load query via FTP")
575 << QByteArray("This was received via FTP\n")
576 << (QStringList() << QLatin1String("-is-uri") << QString("ftp://" + QtNetworkSettings::serverName() + "/pub/qxmlquery/viaFtp.xq"))
580 QTest::newRow("Load query via HTTP")
582 << QByteArray("This was received via HTTP.\n")
583 << (QStringList() << QLatin1String("-is-uri") << QString("http://" + QtNetworkSettings::serverName() + "/qxmlquery/viaHttp.xq"))
587 QTest::newRow("We don't support -format any longer")
590 << (QStringList() << QLatin1String("-format"))
594 QTest::newRow("Run a query which evaluates to the empty sequence.")
597 << (QStringList() << QLatin1String(SRCDIR "queries/emptySequence.xq"))
601 QTest::newRow("Run a query which evaluates to a single document node with no children.")
604 << (QStringList() << QLatin1String(SRCDIR "queries/onlyDocumentNode.xq"))
608 QTest::newRow("Invoke with invalid -param value.")
611 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
612 << QLatin1String("-param")
613 << QLatin1String("EqualSignIsMissing"))
617 QTest::newRow("Invoke with colon in variable name.")
620 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
621 << QLatin1String("-param")
622 << QLatin1String("xs:name=value"))
626 QTest::newRow("Invoke with missing name in -param arg.")
629 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
630 << QLatin1String("-param")
631 << QLatin1String("=value"))
635 QTest::newRow("Invoke with -param that has two adjacent equal signs.")
637 << QByteArray("START =text END\n")
638 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
639 << QLatin1String("-param")
640 << QLatin1String("externalString==text"))
644 QTest::newRow("Pass in an external variable, but the query doesn't use it.")
647 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
648 << QLatin1String("-param")
649 << QLatin1String("externalString==text"))
653 /* This is how an empty string would have been passed in. */
654 QTest::newRow("Invoke with -param that has no value.")
656 << QByteArray("START END\n")
657 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
658 << QLatin1String("-param")
659 << QLatin1String("externalString="))
663 QTest::newRow("Ensure -is-uri can appear after the query filename")
665 << QByteArray("<e/>\n")
666 << (QStringList() << QLatin1String("data:application/xml,%3Ce%2F%3E") << QLatin1String("-is-uri"))
670 QTest::newRow("Use a native path")
673 << (QStringList() << QDir::toNativeSeparators(QLatin1String(SRCDIR "queries/onePlusOne.xq")))
677 QTest::newRow("Pass in invalid URI")
680 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml;base64,PGUvg==="))
684 /* Not relevant anymore.
685 QTest::newRow("A valid, existing query, followed by a bogus one")
688 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
689 << QLatin1String(SRCDIR "doesNotExist.xq"))
694 /* Not relevant anymore.
695 QTest::newRow("Specify two different query names")
698 << (QStringList() << QLatin1String(SRCDIR "query1.xq")
699 << QLatin1String(SRCDIR "query2.xq"))
704 // TODO use focus with xquery
705 // TODO fail to load focus with xquery
706 // TODO focus with URI with xquery
707 // TODO focus via FTP or so with xquery
710 QTest::newRow("Use -param twice")
712 << QByteArray("param1 param2\n")
713 << (QStringList() << QLatin1String(SRCDIR "queries/twoVariables.xq")
714 << QLatin1String("-param")
715 << QLatin1String("var1=param1")
716 << QLatin1String("-param")
717 << QLatin1String("var2=param2"))
721 QTest::newRow("Use -param thrice")
723 << QByteArray("param1 param2 third\n")
724 << (QStringList() << QLatin1String(SRCDIR "queries/threeVariables.xq")
725 << QLatin1String("-param")
726 << QLatin1String("var1=param1")
727 << QLatin1String("-param")
728 << QLatin1String("var2=param2")
729 << QLatin1String("-param")
730 << QLatin1String("var3=third"))
734 QTest::newRow("Specify the same parameter twice, different values")
737 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
738 << QLatin1String("-param")
739 << QLatin1String("duplicated=param1")
740 << QLatin1String("-param")
741 << QLatin1String("duplicated=param2"))
745 QTest::newRow("Specify the same parameter twice, same values")
748 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
749 << QLatin1String("-param")
750 << QLatin1String("duplicated=param1")
751 << QLatin1String("-param")
752 << QLatin1String("duplicated=param2"))
756 QTest::newRow("Open a non-existing collection.")
759 << (QStringList() << QLatin1String(SRCDIR "queries/nonexistingCollection.xq"))
764 // TODO pass external variables that allows space around the equal sign.
765 // TODO run fn:trace()
766 // TODO Trigger warning
767 // TODO what can we do with queries/nodeSequence.xq?
768 // TODO trigger serialization error
769 // TODO "xmlpatterns e.xq x" gives "binding must equal .."
771 // TODO use stdout where it's connected to a non-writable file.
772 // TODO specify -format twice, or whatever it's called.
773 // TODO query name that starts with "-".
775 // TODO Consider what we should do with paths on windows. Stuff like path\filename.xml fails.
776 // TODO use invalid URI in query name, xmlpatterns -is-uri 'as1/#(¤/¤)("#'
778 // TODO add xmlpatterns file1 file2 file3
779 // TODO add xmlpatterns -is-uri file1 file2 file3
782 void tst_XmlPatterns::createNonWritable(const QString &name)
784 /* Create an existing, empty, non-writable file. */
786 QVERIFY(outFile.open(QIODevice::ReadWrite));
787 outFile.write(QByteArray("1"));
788 QVERIFY(outFile.resize(0));
790 QVERIFY(outFile.setPermissions(QFile::Permissions(QFile::ReadOwner)));
793 void tst_XmlPatterns::removeNonWritable(QFile &outFile)
795 /* Kill off temporary files. */
796 if(!outFile.remove())
798 /* Since one file is used for testing that we can handle non-writable file by
799 * changing the permissions, we need to revert it such that we can remove it. */
800 outFile.setPermissions(QFile::WriteOwner);
806 Check that we gracefully handle writing out to stdout
807 when the latter is not writable.
809 void tst_XmlPatterns::stdoutFailure() const
811 return; // TODO It's really hard to write testing code for this.
813 const QString outName(QLatin1String("stdoutFailure.out"));
814 createNonWritable(outName);
817 // If we enable this line, waitForFinished() fails.
818 //process.setStandardOutputFile(outName);
820 process.setWorkingDirectory(QDir::current().absoluteFilePath(QString()));
821 process.start(m_command, QStringList(SRCDIR "queries/onePlusOne.xq"));
823 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
824 QVERIFY(process.waitForFinished());
826 QFile outFile(outName);
827 QVERIFY(outFile.open(QIODevice::ReadOnly));
828 QCOMPARE(outFile.readAll(), QByteArray());
830 QCOMPARE(process.exitCode(), 1);
832 removeNonWritable(outFile);
835 void tst_XmlPatterns::cleanupTestCase() const
837 /* Remove temporaries that we create. */
839 files << QLatin1String("existingContent.out")
840 << QLatin1String("notWritable.out")
841 << QLatin1String("output1");
843 for(int i = 0; i < files.count(); ++i)
845 QFile file(files.at(i));
846 removeNonWritable(file);
849 QCOMPARE(m_generatedTests, 0);
852 void tst_XmlPatterns::xsltSupport()
857 void tst_XmlPatterns::xsltSupport_data() const
860 QSKIP("The command line utility is not in the path.");
863 QSKIP("WinCE: This test uses unsupported WinCE functionality");
864 #elif defined(Q_OS_SYMBIAN)
865 QSKIP("Symbian: This test uses unsupported Symbian functionality (QProcess with std streams)");
868 QTest::addColumn<int>("expectedExitCode");
869 QTest::addColumn<QByteArray>("expectedQueryOutput");
870 QTest::addColumn<QStringList>("arguments");
871 QTest::addColumn<QString>("cwd");
872 QTest::addColumn<QString>("outputFile");
874 QTest::newRow("Evaluate a stylesheet, with no context document")
877 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
881 QTest::newRow("Pass in a stylesheet file which contains an XQuery query")
884 << (QStringList() << QLatin1String(SRCDIR "stylesheets/queryAsStylesheet.xsl")
885 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
889 QTest::newRow("Pass in a stylesheet file and a focus file which doesn't exist")
892 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
893 << QLatin1String("doesNotExist.Nope.xml"))
897 QTest::newRow("-initial-template doesn't work with XQueries.")
900 << (QStringList() << QLatin1String("-initial-template")
901 << QLatin1String("name")
902 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
906 QTest::newRow("-initial-template must be followed by a value")
909 << (QStringList() << QLatin1String("-initial-template")
910 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
914 QTest::newRow("-initial-template must be followed by a value(#2)")
917 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
918 << QLatin1String("-initial-template"))
922 QTest::newRow("Invalid template name")
925 << (QStringList() << QLatin1String("-initial-template")
926 << QLatin1String("abc:def")
927 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
931 QTest::newRow("Specify a named template, that exists")
933 << QByteArray("named-template")
934 << (QStringList() << QLatin1String("-no-format")
935 << QLatin1String("-initial-template")
936 << QLatin1String("main")
937 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
938 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
942 QTest::newRow("Specify a named template, that does not exists")
944 << QByteArray("root-template")
945 << (QStringList() << QLatin1String("-no-format")
946 << QLatin1String("-initial-template")
947 << QLatin1String("no-template-by-this-name")
948 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
949 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
953 QTest::newRow("Call a named template, and use no focus.")
955 << QByteArray("named-template")
956 << (QStringList() << QLatin1String("-no-format")
957 << QLatin1String("-initial-template")
958 << QLatin1String("main")
959 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
963 QTest::newRow("Call a named template, and use no focus.")
965 << QByteArray("namespaced-template")
966 << (QStringList() << QLatin1String("-no-format")
967 << QLatin1String("-initial-template")
968 << QLatin1String("{http://example.com/NS}main")
969 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
973 QTest::newRow("Invoke a template, and use/pass parameters.")
975 << QByteArray("defParam overridedDefaultedParam implicitlyRequiredValue\n")
976 << (QStringList() << QLatin1String("-initial-template")
977 << QLatin1String("main")
978 << QLatin1String(SRCDIR "stylesheets/useParameters.xsl")
979 << QLatin1String("-param")
980 << QLatin1String("overridedDefaultedParam=overridedDefaultedParam")
981 << QLatin1String("-param")
982 << QLatin1String("implicitlyRequiredValue=implicitlyRequiredValue"))
986 QTest::newRow("Use a simplified stylesheet module")
988 << QByteArray("<output>some text</output>\n")
989 << (QStringList() << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xsl")
990 << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xml"))
994 QTest::newRow("Not well-formed stylesheet, causes crash in coloring code.")
997 << (QStringList() << QLatin1String(SRCDIR "stylesheets/notWellformed.xsl")
998 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
1002 QTest::newRow("Not well-formed instance document, causes crash in coloring code.")
1005 << (QStringList() << QLatin1String(SRCDIR "stylesheets/bool070.xsl")
1006 << QLatin1String(SRCDIR "stylesheets/bool070.xml"))
1010 // TODO test -is-uris with context
1011 // TODO fail to load focus document when using XSL-T
1012 // TODO fail to load focus document when using XQuery
1013 // TODO focus via FTP or so with xquery
1014 // TODO use URI in focus
1015 // TODO use invalid URI in focus
1017 // TODO invoke a template which has required params.
1020 QTEST_MAIN(tst_XmlPatterns)
1022 #include "tst_xmlpatterns.moc"
1024 // vim: et:ts=4:sw=4:sts=4