1 /****************************************************************************
3 ** Copyright (C) 2011 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 #ifdef QTEST_XMLPATTERNS
48 #include "../qxmlquery/TestFundament.h"
49 #include "../network-settings.h"
51 #if defined(Q_OS_SYMBIAN)
56 \class tst_XmlPatterns
59 \brief Tests the command line interface, \c xmlpatterns, for the XQuery code.
61 This test is not intended for testing the engine, but all the gluing the
62 command line interface do: error reporting, query output, variable bindings, exit
65 In other words, if you have an engine bug; don't add it here because it won't be
66 tested properly. Instead add it to the test suite.
69 class tst_XmlPatterns : public QObject
70 , private TestFundament
80 void xquerySupport_data() const;
82 void xsltSupport_data() const;
83 void stdoutFailure() const;
84 void cleanupTestCase() const;
87 static void createNonWritable(const QString &name);
88 static void removeNonWritable(QFile &outFile);
92 * Get rid of characters that complicates on various file systems.
94 const QRegExp m_normalizeTestName;
96 * @note Perforce disallows wildcards in the name.
98 const QRegExp m_filenameInStderr;
99 const QString m_command;
103 tst_XmlPatterns::tst_XmlPatterns() : m_generatedTests(0)
104 , m_normalizeTestName(QLatin1String("[\\*\\?#\\-\\/:; ()',&]"))
105 , m_filenameInStderr(QLatin1String("file:\\/\\/.*(\\.xq|\\.gccxml|\\.xml|\\.xsl|-)(,|:)"))
106 , m_command(QLatin1String("xmlpatterns"))
112 void tst_XmlPatterns::initTestCase()
114 QVERIFY(m_normalizeTestName.isValid());
115 QVERIFY(m_filenameInStderr.isValid());
118 process.start(m_command);
120 if(!process.waitForFinished())
123 QEXPECT_FAIL("", "The command line tool is not in the path, most likely because Qt "
124 "has been partially built, such as only the sub-src rule. No tests will be run.", Abort);
130 void tst_XmlPatterns::xquerySupport()
133 QSKIP("The command line utility is not in the path.", SkipAll);
136 QSKIP("WinCE: This test uses unsupported WinCE functionality", SkipAll);
137 #elif defined(Q_OS_SYMBIAN)
138 QSKIP("Symbian: This test uses unsupported Symbian functionality (QProcess with std streams)", SkipAll);
141 QFETCH(int, expectedExitCode);
142 QFETCH(QByteArray, expectedQueryOutput);
143 QFETCH(QStringList, arguments);
144 QFETCH(QString, cwd);
145 QFETCH(QString, outputFile);
150 process.setWorkingDirectory(inputFile(cwd));
152 process.start(m_command, arguments);
154 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
155 QVERIFY(process.waitForFinished());
157 if(process.exitCode() != expectedExitCode)
158 QTextStream(stderr) << "stderr:" << process.readAllStandardError();
160 QCOMPARE(process.exitCode(), expectedExitCode);
162 const QByteArray rawProducedStderr((process.readAllStandardError()));
163 QString fixedStderr(QString::fromLocal8Bit(rawProducedStderr).remove(m_filenameInStderr));
164 // convert Windows line endings to Unix ones
165 fixedStderr.replace("\r\n", "\n");
167 const QString errorFileName(inputFile(QLatin1String(SRCDIR "stderrBaselines/") +
168 QString::fromUtf8(QTest::currentDataTag()).remove(m_normalizeTestName) +
169 QLatin1String(".txt")));
171 QFile writeErr(errorFileName);
173 if(writeErr.exists())
175 QVERIFY(writeErr.open(QIODevice::ReadOnly));
176 QString rawExpectedStdErr(QString::fromLocal8Bit(writeErr.readAll()));
178 /* On Windows, at least MinGW, this differs. */
179 if(qstrcmp(QTest::currentDataTag(), "-output with a non-writable file") == 0)
181 QVERIFY(fixedStderr == rawExpectedStdErr.remove(m_filenameInStderr) ||
182 fixedStderr.trimmed() == "Failed to open file notWritable.out for writing: Access is denied.");
184 else if(qstrcmp(QTest::currentDataTag(), "Invoke -version") == 0)
186 /* There's a wide range of different version strings used. For
187 * instance, "4.4.0-rc1". */
188 const QRegExp removeVersion(QLatin1String(" Qt \\d\\.\\d.*"));
189 QVERIFY(removeVersion.isValid());
190 QCOMPARE(QString(fixedStderr).remove(removeVersion) + QChar('|'), rawExpectedStdErr + QChar('|'));
193 QCOMPARE(fixedStderr, rawExpectedStdErr.remove(m_filenameInStderr));
197 QFile writeErr(errorFileName);
198 QVERIFY(writeErr.open(QIODevice::WriteOnly));
200 QCOMPARE(writeErr.write(rawProducedStderr), qint64(rawProducedStderr.count()));
201 QTextStream(stderr) << "creating file " << errorFileName;
205 const QByteArray actual(process.readAllStandardOutput());
207 if(outputFile.isEmpty())
209 QCOMPARE(actual, expectedQueryOutput);
210 return; /* We're done, this test was not creating any output file. */
214 QVERIFY(actual.isEmpty());
216 QFile outFile(outputFile);
218 QVERIFY(outFile.exists());
219 QVERIFY(outFile.open(QIODevice::ReadOnly));
221 QCOMPARE(outFile.readAll(), expectedQueryOutput);
223 removeNonWritable(outFile);
227 void tst_XmlPatterns::xquerySupport_data() const
229 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
233 /* Check one file for existence, to avoid possible false positives. */
234 QVERIFY(QFile::exists(inputFile(QLatin1String(SRCDIR "queries/onePlusOne.xq"))));
236 QTest::addColumn<int>("expectedExitCode");
237 QTest::addColumn<QByteArray>("expectedQueryOutput");
238 QTest::addColumn<QStringList>("arguments");
239 QTest::addColumn<QString>("cwd");
240 QTest::addColumn<QString>("outputFile");
242 QTest::newRow("A simple math query")
245 << QStringList((QLatin1String(SRCDIR "queries/onePlusOne.xq")))
249 QTest::newRow("An unbound external variable")
252 << QStringList(QLatin1String(SRCDIR "queries/externalVariable.xq"))
256 QTest::newRow("Bind an external variable")
258 << QByteArray("1 4<e>1</e>true\n")
259 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
260 << QLatin1String("-param")
261 << QLatin1String("externalVariable=1"))
265 QTest::newRow("Bind an external variable, query appearing last")
267 << QByteArray("1 4<e>1</e>true\n")
268 << (QStringList() << QLatin1String("-param")
269 << QLatin1String("externalVariable=1")
270 << QLatin1String(SRCDIR "queries/externalVariable.xq"))
274 QTest::newRow("Use fn:doc")
276 << 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")
277 << QStringList(QLatin1String(SRCDIR "queries/openDocument.xq"))
281 QTest::newRow("Use fn:doc, together with -no-format, last")
283 << 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>")
284 << (QStringList() << QLatin1String(SRCDIR "queries/openDocument.xq")
285 << QLatin1String("-no-format"))
289 QTest::newRow("Use fn:doc, together with -no-format, first")
291 << 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>")
292 << (QStringList() << QLatin1String("-no-format")
293 << QLatin1String(SRCDIR "queries/openDocument.xq"))
297 /* This is true for the command line utility, but not QXmlQuery::setQuery(). */
298 QTest::newRow("Make sure query paths are resolved against CWD, not the location of the executable.")
301 << QStringList(QLatin1String(SRCDIR "queries/onePlusOne.xq"))
302 << QString::fromLatin1("queries")
305 QTest::newRow("Call fn:error()")
308 << QStringList(QLatin1String(SRCDIR "queries/errorFunction.xq"))
312 QTest::newRow("Evaluate a library module")
315 << QStringList(QLatin1String(SRCDIR "queries/simpleLibraryModule.xq"))
319 QTest::newRow("Trigger a static error.")
322 << QStringList(QLatin1String(SRCDIR "queries/staticError.xq"))
326 QTest::newRow("Pass -help")
329 << QStringList(QLatin1String("-help"))
333 QTest::newRow("Open an nonexistent file")
336 << QStringList(QLatin1String(SRCDIR "queries/ThisFileDoesNotExist.xq"))
340 /* The following five tests exists to test the various
341 * markup classes in the message. */
342 QTest::newRow("XQuery-function message markups")
345 << QStringList(QLatin1String(SRCDIR "queries/wrongArity.xq"))
349 QTest::newRow("XQuery-type message markups")
352 << QStringList(QLatin1String(SRCDIR "queries/typeError.xq"))
356 QTest::newRow("XQuery-data & XQuery-keyword message markups")
359 << QStringList(QLatin1String(SRCDIR "queries/zeroDivision.xq"))
363 QTest::newRow("XQuery-uri message markups")
366 << QStringList(QLatin1String(SRCDIR "queries/unsupportedCollation.xq"))
370 QTest::newRow("XQuery-expression message markups")
373 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexp.xq"))
377 QTest::newRow("Print a list of available regexp flags(The available flags are formatted in a complex way.)")
380 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexpFlag.xq"))
384 QTest::newRow("Trigger an assert in QPatternist::ColorOutput. The query naturally contains an error; XPTY0004.")
387 << QStringList(QLatin1String(SRCDIR "queries/flwor.xq"))
391 QTest::newRow("Trigger a second assert in QPatternist::ColorOutput. The query naturally contains XPST0003.")
394 << QStringList(QLatin1String(SRCDIR "queries/syntaxError.xq"))
398 QTest::newRow("-param is missing so multiple queries appear")
401 << (QStringList() << QLatin1String(SRCDIR "queries/reportGlobals.xq")
402 << QLatin1String("fileToOpen=globals.gccxml"))
406 QTest::newRow("only -no-format")
409 << (QStringList() << QLatin1String("-no-format"))
413 QTest::newRow("Basic use of -output, query first")
416 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
417 << QLatin1String("-output")
418 << QLatin1String("basicOutput.out"))
420 << QString::fromLatin1("basicOutput.out");
422 QTest::newRow("Basic use of -output, query last")
424 << QByteArray("<e/>\n")
425 << (QStringList() << QLatin1String("-output")
426 << QLatin1String("basicOutput2.out")
427 << QLatin1String(SRCDIR "queries/oneElement.xq"))
429 << QString::fromLatin1("basicOutput2.out");
431 QTest::newRow("A single query, that does not exist")
434 << (QStringList() << QLatin1String(SRCDIR "doesNotExist.xq"))
438 QTest::newRow("Specify two identical query names")
441 << (QStringList() << QLatin1String(SRCDIR "query.xq")
442 << QLatin1String(SRCDIR "query.xq"))
446 QTest::newRow("Specify no arguments at all.")
453 QTest::newRow("Use -output twice")
456 << (QStringList() << QLatin1String("-output")
457 << QLatin1String("output1")
458 << QLatin1String("-output")
459 << QLatin1String("output2"))
464 const QString filename(QString::fromLatin1("notWritable.out"));
465 createNonWritable(filename);
467 QTest::newRow("-output with a non-writable file")
470 << (QStringList() << QLatin1String("-output")
472 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
478 const QString outName(QString::fromLatin1("existingContent.out"));
479 QFile outFile(outName);
480 QVERIFY(outFile.open(QIODevice::WriteOnly));
481 QCOMPARE(outFile.write("Existing content\n"), qint64(17));
484 QTest::newRow("Use -output on a file with existing content, to ensure we truncate, not append the content we produce.")
487 << (QStringList() << QLatin1String("-output")
489 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
494 QTest::newRow("one query, and a terminating dash at the end")
497 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
498 << QLatin1String("-"))
502 QTest::newRow("one query, with a preceding dash")
505 << (QStringList() << QLatin1String("-")
506 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
510 QTest::newRow("A single dash, that's invalid")
513 << (QStringList() << QLatin1String("-"))
517 QTest::newRow("Invoke -version")
520 << (QStringList() << QLatin1String("-version"))
524 QTest::newRow("Unknown switch; -unknown-switch")
527 << (QStringList() << QLatin1String("-unknown-switch"))
531 QTest::newRow("Unknown switch; -d")
534 << (QStringList() << QLatin1String("-d"))
538 QTest::newRow("Passing a single dash is insufficient")
541 << (QStringList() << QLatin1String("-"))
545 QTest::newRow("Passing two dashes, the last is interpreted as a file name")
548 << (QStringList() << QLatin1String("-")
549 << QLatin1String("-"))
553 QTest::newRow("Pass three dashes, the two last gets interpreted as two query arguments")
556 << (QStringList() << QLatin1String("-")
557 << QLatin1String("-")
558 << QLatin1String("-"))
562 QTest::newRow("Load query via data: scheme")
564 << QByteArray("<e/>\n")
565 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml,%3Ce%2F%3E"))
569 QTest::newRow("Load query via FTP")
571 << QByteArray("This was received via FTP\n")
572 << (QStringList() << QLatin1String("-is-uri") << QString("ftp://" + QtNetworkSettings::serverName() + "/pub/qxmlquery/viaFtp.xq"))
576 QTest::newRow("Load query via HTTP")
578 << QByteArray("This was received via HTTP.\n")
579 << (QStringList() << QLatin1String("-is-uri") << QString("http://" + QtNetworkSettings::serverName() + "/qxmlquery/viaHttp.xq"))
583 QTest::newRow("We don't support -format any longer")
586 << (QStringList() << QLatin1String("-format"))
590 QTest::newRow("Run a query which evaluates to the empty sequence.")
593 << (QStringList() << QLatin1String(SRCDIR "queries/emptySequence.xq"))
597 QTest::newRow("Run a query which evaluates to a single document node with no children.")
600 << (QStringList() << QLatin1String(SRCDIR "queries/onlyDocumentNode.xq"))
604 QTest::newRow("Invoke with invalid -param value.")
607 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
608 << QLatin1String("-param")
609 << QLatin1String("EqualSignIsMissing"))
613 QTest::newRow("Invoke with colon in variable name.")
616 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
617 << QLatin1String("-param")
618 << QLatin1String("xs:name=value"))
622 QTest::newRow("Invoke with missing name in -param arg.")
625 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
626 << QLatin1String("-param")
627 << QLatin1String("=value"))
631 QTest::newRow("Invoke with -param that has two adjacent equal signs.")
633 << QByteArray("START =text END\n")
634 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
635 << QLatin1String("-param")
636 << QLatin1String("externalString==text"))
640 QTest::newRow("Pass in an external variable, but the query doesn't use it.")
643 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
644 << QLatin1String("-param")
645 << QLatin1String("externalString==text"))
649 /* This is how an empty string would have been passed in. */
650 QTest::newRow("Invoke with -param that has no value.")
652 << QByteArray("START END\n")
653 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
654 << QLatin1String("-param")
655 << QLatin1String("externalString="))
659 QTest::newRow("Ensure -is-uri can appear after the query filename")
661 << QByteArray("<e/>\n")
662 << (QStringList() << QLatin1String("data:application/xml,%3Ce%2F%3E") << QLatin1String("-is-uri"))
666 QTest::newRow("Use a native path")
669 << (QStringList() << QDir::toNativeSeparators(QLatin1String(SRCDIR "queries/onePlusOne.xq")))
673 QTest::newRow("Pass in invalid URI")
676 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml;base64,PGUvg==="))
680 /* Not relevant anymore.
681 QTest::newRow("A valid, existing query, followed by a bogus one")
684 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
685 << QLatin1String(SRCDIR "doesNotExist.xq"))
690 /* Not relevant anymore.
691 QTest::newRow("Specify two different query names")
694 << (QStringList() << QLatin1String(SRCDIR "query1.xq")
695 << QLatin1String(SRCDIR "query2.xq"))
700 // TODO use focus with xquery
701 // TODO fail to load focus with xquery
702 // TODO focus with URI with xquery
703 // TODO focus via FTP or so with xquery
706 QTest::newRow("Use -param twice")
708 << QByteArray("param1 param2\n")
709 << (QStringList() << QLatin1String(SRCDIR "queries/twoVariables.xq")
710 << QLatin1String("-param")
711 << QLatin1String("var1=param1")
712 << QLatin1String("-param")
713 << QLatin1String("var2=param2"))
717 QTest::newRow("Use -param thrice")
719 << QByteArray("param1 param2 third\n")
720 << (QStringList() << QLatin1String(SRCDIR "queries/threeVariables.xq")
721 << QLatin1String("-param")
722 << QLatin1String("var1=param1")
723 << QLatin1String("-param")
724 << QLatin1String("var2=param2")
725 << QLatin1String("-param")
726 << QLatin1String("var3=third"))
730 QTest::newRow("Specify the same parameter twice, different values")
733 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
734 << QLatin1String("-param")
735 << QLatin1String("duplicated=param1")
736 << QLatin1String("-param")
737 << QLatin1String("duplicated=param2"))
741 QTest::newRow("Specify the same parameter twice, same values")
744 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
745 << QLatin1String("-param")
746 << QLatin1String("duplicated=param1")
747 << QLatin1String("-param")
748 << QLatin1String("duplicated=param2"))
752 QTest::newRow("Open a non-existing collection.")
755 << (QStringList() << QLatin1String(SRCDIR "queries/nonexistingCollection.xq"))
760 // TODO pass external variables that allows space around the equal sign.
761 // TODO run fn:trace()
762 // TODO Trigger warning
763 // TODO what can we do with queries/nodeSequence.xq?
764 // TODO trigger serialization error
765 // TODO "xmlpatterns e.xq x" gives "binding must equal .."
767 // TODO use stdout where it's connected to a non-writable file.
768 // TODO specify -format twice, or whatever it's called.
769 // TODO query name that starts with "-".
771 // TODO Consider what we should do with paths on windows. Stuff like path\filename.xml fails.
772 // TODO use invalid URI in query name, xmlpatterns -is-uri 'as1/#(¤/¤)("#'
774 // TODO add xmlpatterns file1 file2 file3
775 // TODO add xmlpatterns -is-uri file1 file2 file3
778 void tst_XmlPatterns::createNonWritable(const QString &name)
780 /* Create an existing, empty, non-writable file. */
782 QVERIFY(outFile.open(QIODevice::ReadWrite));
783 outFile.write(QByteArray("1"));
784 QVERIFY(outFile.resize(0));
786 QVERIFY(outFile.setPermissions(QFile::Permissions(QFile::ReadOwner)));
789 void tst_XmlPatterns::removeNonWritable(QFile &outFile)
791 /* Kill off temporary files. */
792 if(!outFile.remove())
794 /* Since one file is used for testing that we can handle non-writable file by
795 * changing the permissions, we need to revert it such that we can remove it. */
796 outFile.setPermissions(QFile::WriteOwner);
802 Check that we gracefully handle writing out to stdout
803 when the latter is not writable.
805 void tst_XmlPatterns::stdoutFailure() const
807 return; // TODO It's really hard to write testing code for this.
809 const QString outName(QLatin1String("stdoutFailure.out"));
810 createNonWritable(outName);
813 // If we enable this line, waitForFinished() fails.
814 //process.setStandardOutputFile(outName);
816 process.setWorkingDirectory(QDir::current().absoluteFilePath(QString()));
817 process.start(m_command, QStringList(SRCDIR "queries/onePlusOne.xq"));
819 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
820 QVERIFY(process.waitForFinished());
822 QFile outFile(outName);
823 QVERIFY(outFile.open(QIODevice::ReadOnly));
824 QCOMPARE(outFile.readAll(), QByteArray());
826 QCOMPARE(process.exitCode(), 1);
828 removeNonWritable(outFile);
831 void tst_XmlPatterns::cleanupTestCase() const
833 /* Remove temporaries that we create. */
835 files << QLatin1String("existingContent.out")
836 << QLatin1String("notWritable.out")
837 << QLatin1String("output1");
839 for(int i = 0; i < files.count(); ++i)
841 QFile file(files.at(i));
842 removeNonWritable(file);
845 QCOMPARE(m_generatedTests, 0);
848 void tst_XmlPatterns::xsltSupport()
853 void tst_XmlPatterns::xsltSupport_data() const
856 QSKIP("The command line utility is not in the path.", SkipAll);
859 QSKIP("WinCE: This test uses unsupported WinCE functionality", SkipAll);
860 #elif defined(Q_OS_SYMBIAN)
861 QSKIP("Symbian: This test uses unsupported Symbian functionality (QProcess with std streams)", SkipAll);
864 QTest::addColumn<int>("expectedExitCode");
865 QTest::addColumn<QByteArray>("expectedQueryOutput");
866 QTest::addColumn<QStringList>("arguments");
867 QTest::addColumn<QString>("cwd");
868 QTest::addColumn<QString>("outputFile");
870 QTest::newRow("Evaluate a stylesheet, with no context document")
873 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
877 QTest::newRow("Pass in a stylesheet file which contains an XQuery query")
880 << (QStringList() << QLatin1String(SRCDIR "stylesheets/queryAsStylesheet.xsl")
881 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
885 QTest::newRow("Pass in a stylesheet file and a focus file which doesn't exist")
888 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
889 << QLatin1String("doesNotExist.Nope.xml"))
893 QTest::newRow("-initial-template doesn't work with XQueries.")
896 << (QStringList() << QLatin1String("-initial-template")
897 << QLatin1String("name")
898 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
902 QTest::newRow("-initial-template must be followed by a value")
905 << (QStringList() << QLatin1String("-initial-template")
906 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
910 QTest::newRow("-initial-template must be followed by a value(#2)")
913 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
914 << QLatin1String("-initial-template"))
918 QTest::newRow("Invalid template name")
921 << (QStringList() << QLatin1String("-initial-template")
922 << QLatin1String("abc:def")
923 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
927 QTest::newRow("Specify a named template, that exists")
929 << QByteArray("named-template")
930 << (QStringList() << QLatin1String("-no-format")
931 << QLatin1String("-initial-template")
932 << QLatin1String("main")
933 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
934 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
938 QTest::newRow("Specify a named template, that does not exists")
940 << QByteArray("root-template")
941 << (QStringList() << QLatin1String("-no-format")
942 << QLatin1String("-initial-template")
943 << QLatin1String("no-template-by-this-name")
944 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
945 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
949 QTest::newRow("Call a named template, and use no focus.")
951 << QByteArray("named-template")
952 << (QStringList() << QLatin1String("-no-format")
953 << QLatin1String("-initial-template")
954 << QLatin1String("main")
955 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
959 QTest::newRow("Call a named template, and use no focus.")
961 << QByteArray("namespaced-template")
962 << (QStringList() << QLatin1String("-no-format")
963 << QLatin1String("-initial-template")
964 << QLatin1String("{http://example.com/NS}main")
965 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
969 QTest::newRow("Invoke a template, and use/pass parameters.")
971 << QByteArray("defParam overridedDefaultedParam implicitlyRequiredValue\n")
972 << (QStringList() << QLatin1String("-initial-template")
973 << QLatin1String("main")
974 << QLatin1String(SRCDIR "stylesheets/useParameters.xsl")
975 << QLatin1String("-param")
976 << QLatin1String("overridedDefaultedParam=overridedDefaultedParam")
977 << QLatin1String("-param")
978 << QLatin1String("implicitlyRequiredValue=implicitlyRequiredValue"))
982 QTest::newRow("Use a simplified stylesheet module")
984 << QByteArray("<output>some text</output>\n")
985 << (QStringList() << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xsl")
986 << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xml"))
990 QTest::newRow("Not well-formed stylesheet, causes crash in coloring code.")
993 << (QStringList() << QLatin1String(SRCDIR "stylesheets/notWellformed.xsl")
994 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
998 QTest::newRow("Not well-formed instance document, causes crash in coloring code.")
1001 << (QStringList() << QLatin1String(SRCDIR "stylesheets/bool070.xsl")
1002 << QLatin1String(SRCDIR "stylesheets/bool070.xml"))
1006 // TODO test -is-uris with context
1007 // TODO fail to load focus document when using XSL-T
1008 // TODO fail to load focus document when using XQuery
1009 // TODO focus via FTP or so with xquery
1010 // TODO use URI in focus
1011 // TODO use invalid URI in focus
1013 // TODO invoke a template which has required params.
1016 QTEST_MAIN(tst_XmlPatterns)
1018 #include "tst_xmlpatterns.moc"
1023 // vim: et:ts=4:sw=4:sts=4