1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** 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"
50 \class tst_XmlPatterns
53 \brief Tests the command line interface, \c xmlpatterns, for the XQuery code.
55 This test is not intended for testing the engine, but all the gluing the
56 command line interface do: error reporting, query output, variable bindings, exit
59 In other words, if you have an engine bug; don't add it here because it won't be
60 tested properly. Instead add it to the test suite.
63 class tst_XmlPatterns : public QObject
64 , private TestFundament
74 void xquerySupport_data() const;
76 void xsltSupport_data() const;
77 void stdoutFailure() const;
78 void cleanupTestCase() const;
81 static void createNonWritable(const QString &name);
82 static void removeNonWritable(QFile &outFile);
84 QString filterStderr(const QString &in);
88 * Get rid of characters that complicates on various file systems.
90 const QRegExp m_normalizeTestName;
92 * @note Perforce disallows wildcards in the name.
94 const QString m_command;
98 tst_XmlPatterns::tst_XmlPatterns() : m_generatedTests(0)
99 , m_normalizeTestName(QLatin1String("[\\*\\?#\\-\\/:; ()',&]"))
100 , m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/xmlpatterns"))
105 void tst_XmlPatterns::initTestCase()
107 QVERIFY(QtNetworkSettings::verifyTestNetworkSettings());
109 QVERIFY(m_normalizeTestName.isValid());
112 process.start(m_command);
114 if(!process.waitForFinished())
119 "The command line tool (%1) could not be run, possibly because Qt was "
120 "incompletely built or installed. No tests will be run."
127 void tst_XmlPatterns::xquerySupport()
130 QSKIP("The command line utility is not in the path.");
133 QSKIP("WinCE: This test uses unsupported WinCE functionality");
134 #elif defined(Q_OS_MAC)
135 QSKIP("MacOs: Failed on Mac. Will be fixed by bug fix for QTBUG-22556");
138 QFETCH(int, expectedExitCode);
139 QFETCH(QByteArray, expectedQueryOutput);
140 QFETCH(QStringList, arguments);
141 QFETCH(QString, cwd);
142 QFETCH(QString, outputFile);
147 process.setWorkingDirectory(inputFile(cwd));
149 process.start(m_command, arguments);
151 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
152 QVERIFY(process.waitForFinished());
154 if(process.exitCode() != expectedExitCode)
155 QTextStream(stderr) << "stderr:" << process.readAllStandardError();
157 QCOMPARE(process.exitCode(), expectedExitCode);
159 const QByteArray rawProducedStderr((process.readAllStandardError()));
160 QString fixedStderr = filterStderr(QString::fromLocal8Bit(rawProducedStderr));
161 // convert Windows line endings to Unix ones
162 fixedStderr.replace("\r\n", "\n");
164 const QString errorFileName(QFINDTESTDATA("stderrBaselines/") +
165 QString::fromUtf8(QTest::currentDataTag()).remove(m_normalizeTestName) +
166 QLatin1String(".txt"));
168 QFile writeErr(errorFileName);
170 if(writeErr.exists())
172 QVERIFY(writeErr.open(QIODevice::ReadOnly));
173 QString rawExpectedStdErr(QString::fromLocal8Bit(writeErr.readAll()));
175 /* On Windows, at least MinGW, this differs. */
176 if(qstrcmp(QTest::currentDataTag(), "-output with a non-writable file") == 0)
178 QVERIFY(fixedStderr == filterStderr(rawExpectedStdErr) ||
179 fixedStderr.trimmed() == "Failed to open file notWritable.out for writing: Access is denied.");
181 else if(qstrcmp(QTest::currentDataTag(), "Invoke -version") == 0)
183 /* There's a wide range of different version strings used. For
184 * instance, "4.4.0-rc1". */
185 QRegExp removeVersion(QLatin1String(" Qt \\d\\.\\d.*"));
186 QVERIFY(removeVersion.isValid());
187 QCOMPARE(QString(fixedStderr).remove(removeVersion) + QChar('|'), rawExpectedStdErr + QChar('|'));
190 QCOMPARE(fixedStderr, filterStderr(rawExpectedStdErr));
194 QFile writeErr(errorFileName);
195 QVERIFY(writeErr.open(QIODevice::WriteOnly));
197 QCOMPARE(writeErr.write(rawProducedStderr), qint64(rawProducedStderr.count()));
198 QTextStream(stderr) << "creating file " << errorFileName;
202 const QByteArray actual(process.readAllStandardOutput());
204 if(outputFile.isEmpty())
206 QCOMPARE(actual, expectedQueryOutput);
207 return; /* We're done, this test was not creating any output file. */
211 QVERIFY(actual.isEmpty());
213 QFile outFile(outputFile);
215 QVERIFY(outFile.exists());
216 QVERIFY(outFile.open(QIODevice::ReadOnly));
218 QCOMPARE(outFile.readAll(), expectedQueryOutput);
220 removeNonWritable(outFile);
224 void tst_XmlPatterns::xquerySupport_data() const
226 #if defined(Q_OS_WINCE)
230 QString path = QFINDTESTDATA("queries/");
232 /* Check one file for existence, to avoid possible false positives. */
233 QVERIFY(QFile::exists(path + QLatin1String("onePlusOne.xq")));
235 QTest::addColumn<int>("expectedExitCode");
236 QTest::addColumn<QByteArray>("expectedQueryOutput");
237 QTest::addColumn<QStringList>("arguments");
238 QTest::addColumn<QString>("cwd");
239 QTest::addColumn<QString>("outputFile");
241 QTest::newRow("A simple math query")
244 << QStringList((path + QLatin1String("onePlusOne.xq")))
248 QTest::newRow("An unbound external variable")
251 << QStringList(path + QLatin1String("externalVariable.xq"))
255 QTest::newRow("Bind an external variable")
257 << QByteArray("1 4<e>1</e>true\n")
258 << (QStringList() << path + QLatin1String("externalVariable.xq")
259 << QLatin1String("-param")
260 << QLatin1String("externalVariable=1"))
264 QTest::newRow("Bind an external variable, query appearing last")
266 << QByteArray("1 4<e>1</e>true\n")
267 << (QStringList() << QLatin1String("-param")
268 << QLatin1String("externalVariable=1")
269 << path + QLatin1String("externalVariable.xq"))
273 QTest::newRow("Use fn:doc")
275 << 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")
276 << QStringList(path + QLatin1String("openDocument.xq"))
280 QTest::newRow("Use fn:doc, together with -no-format, last")
282 << 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>")
283 << (QStringList() << path + QLatin1String("openDocument.xq")
284 << QLatin1String("-no-format"))
288 QTest::newRow("Use fn:doc, together with -no-format, first")
290 << 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>")
291 << (QStringList() << QLatin1String("-no-format")
292 << path + QLatin1String("openDocument.xq"))
296 /* This is true for the command line utility, but not QXmlQuery::setQuery(). */
297 QTest::newRow("Make sure query paths are resolved against CWD, not the location of the executable.")
300 << QStringList(QFINDTESTDATA("queries/onePlusOne.xq"))
301 << QFINDTESTDATA("queries")
304 QTest::newRow("Call fn:error()")
307 << QStringList(path + QLatin1String("errorFunction.xq"))
311 QTest::newRow("Evaluate a library module")
314 << QStringList(path + QLatin1String("simpleLibraryModule.xq"))
318 QTest::newRow("Trigger a static error.")
321 << QStringList(path + QLatin1String("staticError.xq"))
325 QTest::newRow("Pass -help")
328 << QStringList(QLatin1String("-help"))
332 QTest::newRow("Open an nonexistent file")
335 << QStringList(path + QLatin1String("ThisFileDoesNotExist.xq"))
339 /* The following five tests exists to test the various
340 * markup classes in the message. */
341 QTest::newRow("XQuery-function message markups")
344 << QStringList(path + QLatin1String("wrongArity.xq"))
348 QTest::newRow("XQuery-type message markups")
351 << QStringList(path + QLatin1String("typeError.xq"))
355 QTest::newRow("XQuery-data & XQuery-keyword message markups")
358 << QStringList(path + QLatin1String("zeroDivision.xq"))
362 QTest::newRow("XQuery-uri message markups")
365 << QStringList(path + QLatin1String("unsupportedCollation.xq"))
369 QTest::newRow("XQuery-expression message markups")
372 << QStringList(path + QLatin1String("invalidRegexp.xq"))
376 QTest::newRow("Print a list of available regexp flags(The available flags are formatted in a complex way.)")
379 << QStringList(path + QLatin1String("invalidRegexpFlag.xq"))
383 QTest::newRow("Trigger an assert in QPatternist::ColorOutput. The query naturally contains an error; XPTY0004.")
386 << QStringList(path + QLatin1String("flwor.xq"))
390 QTest::newRow("Trigger a second assert in QPatternist::ColorOutput. The query naturally contains XPST0003.")
393 << QStringList(path + QLatin1String("syntaxError.xq"))
397 QTest::newRow("-param is missing so multiple queries appear")
400 << (QStringList() << path + QLatin1String("reportGlobals.xq")
401 << QLatin1String("fileToOpen=globals.gccxml"))
405 QTest::newRow("only -no-format")
408 << (QStringList() << QLatin1String("-no-format"))
412 QTest::newRow("Basic use of -output, query first")
415 << (QStringList() << path + QLatin1String("onePlusOne.xq")
416 << QLatin1String("-output")
417 << QLatin1String("basicOutput.out"))
419 << QString::fromLatin1("basicOutput.out");
421 QTest::newRow("Basic use of -output, query last")
423 << QByteArray("<e/>\n")
424 << (QStringList() << QLatin1String("-output")
425 << QLatin1String("basicOutput2.out")
426 << path + QLatin1String("oneElement.xq"))
428 << QString::fromLatin1("basicOutput2.out");
430 QTest::newRow("A single query, that does not exist")
433 << (QStringList() << path + QLatin1String("doesNotExist.xq"))
437 QTest::newRow("Specify two identical query names")
440 << (QStringList() << path + QLatin1String("query.xq")
441 << path + QLatin1String("query.xq"))
445 QTest::newRow("Specify no arguments at all.")
452 QTest::newRow("Use -output twice")
455 << (QStringList() << QLatin1String("-output")
456 << QLatin1String("output1")
457 << QLatin1String("-output")
458 << QLatin1String("output2"))
463 const QString filename(QString::fromLatin1("notWritable.out"));
464 createNonWritable(filename);
466 QTest::newRow("-output with a non-writable file")
469 << (QStringList() << QLatin1String("-output")
471 << path + QLatin1String("onePlusOne.xq"))
477 const QString outName(QString::fromLatin1("existingContent.out"));
478 QFile outFile(outName);
479 QVERIFY(outFile.open(QIODevice::WriteOnly));
480 QCOMPARE(outFile.write("Existing content\n"), qint64(17));
483 QTest::newRow("Use -output on a file with existing content, to ensure we truncate, not append the content we produce.")
486 << (QStringList() << QLatin1String("-output")
488 << path + QLatin1String("onePlusOne.xq"))
493 QTest::newRow("one query, and a terminating dash at the end")
496 << (QStringList() << path + QLatin1String("onePlusOne.xq")
497 << QLatin1String("-"))
501 QTest::newRow("one query, with a preceding dash")
504 << (QStringList() << QLatin1String("-")
505 << path + QLatin1String("onePlusOne.xq"))
509 QTest::newRow("A single dash, that's invalid")
512 << (QStringList() << QLatin1String("-"))
516 QTest::newRow("Invoke -version")
519 << (QStringList() << QLatin1String("-version"))
523 QTest::newRow("Unknown switch; -unknown-switch")
526 << (QStringList() << QLatin1String("-unknown-switch"))
530 QTest::newRow("Unknown switch; -d")
533 << (QStringList() << QLatin1String("-d"))
537 QTest::newRow("Passing a single dash is insufficient")
540 << (QStringList() << QLatin1String("-"))
544 QTest::newRow("Passing two dashes, the last is interpreted as a file name")
547 << (QStringList() << QLatin1String("-")
548 << QLatin1String("-"))
552 QTest::newRow("Pass three dashes, the two last gets interpreted as two query arguments")
555 << (QStringList() << QLatin1String("-")
556 << QLatin1String("-")
557 << QLatin1String("-"))
561 QTest::newRow("Load query via data: scheme")
563 << QByteArray("<e/>\n")
564 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml,%3Ce%2F%3E"))
568 QTest::newRow("Load query via FTP")
570 << QByteArray("This was received via FTP\n")
571 << (QStringList() << QLatin1String("-is-uri") << QString("ftp://" + QtNetworkSettings::serverName() + "/pub/qxmlquery/viaFtp.xq"))
575 QTest::newRow("Load query via HTTP")
577 << QByteArray("This was received via HTTP.\n")
578 << (QStringList() << QLatin1String("-is-uri") << QString("http://" + QtNetworkSettings::serverName() + "/qxmlquery/viaHttp.xq"))
582 QTest::newRow("We don't support -format any longer")
585 << (QStringList() << QLatin1String("-format"))
589 QTest::newRow("Run a query which evaluates to the empty sequence.")
592 << (QStringList() << path + QLatin1String("emptySequence.xq"))
596 QTest::newRow("Run a query which evaluates to a single document node with no children.")
599 << (QStringList() << path + QLatin1String("onlyDocumentNode.xq"))
603 QTest::newRow("Invoke with invalid -param value.")
606 << (QStringList() << path + QLatin1String("externalVariable.xq")
607 << QLatin1String("-param")
608 << QLatin1String("EqualSignIsMissing"))
612 QTest::newRow("Invoke with colon in variable name.")
615 << (QStringList() << path + QLatin1String("externalVariable.xq")
616 << QLatin1String("-param")
617 << QLatin1String("xs:name=value"))
621 QTest::newRow("Invoke with missing name in -param arg.")
624 << (QStringList() << path + QLatin1String("externalVariable.xq")
625 << QLatin1String("-param")
626 << QLatin1String("=value"))
630 QTest::newRow("Invoke with -param that has two adjacent equal signs.")
632 << QByteArray("START =text END\n")
633 << (QStringList() << path + QLatin1String("externalStringVariable.xq")
634 << QLatin1String("-param")
635 << QLatin1String("externalString==text"))
639 QTest::newRow("Pass in an external variable, but the query doesn't use it.")
642 << (QStringList() << path + QLatin1String("onePlusOne.xq")
643 << QLatin1String("-param")
644 << QLatin1String("externalString==text"))
648 /* This is how an empty string would have been passed in. */
649 QTest::newRow("Invoke with -param that has no value.")
651 << QByteArray("START END\n")
652 << (QStringList() << path + QLatin1String("externalStringVariable.xq")
653 << QLatin1String("-param")
654 << QLatin1String("externalString="))
658 QTest::newRow("Ensure -is-uri can appear after the query filename")
660 << QByteArray("<e/>\n")
661 << (QStringList() << QLatin1String("data:application/xml,%3Ce%2F%3E") << QLatin1String("-is-uri"))
665 QTest::newRow("Use a native path")
668 << (QStringList() << QDir::toNativeSeparators(path + QLatin1String("onePlusOne.xq")))
672 QTest::newRow("Pass in invalid URI")
675 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml;base64,PGUvg==="))
679 /* Not relevant anymore.
680 QTest::newRow("A valid, existing query, followed by a bogus one")
683 << (QStringList() << path + QLatin1String("onePlusOne.xq")
684 << path + QLatin1String("doesNotExist.xq"))
689 /* Not relevant anymore.
690 QTest::newRow("Specify two different query names")
693 << (QStringList() << path + QLatin1String("query1.xq")
694 << path + QLatin1String("query2.xq"))
699 // TODO use focus with xquery
700 // TODO fail to load focus with xquery
701 // TODO focus with URI with xquery
702 // TODO focus via FTP or so with xquery
705 QTest::newRow("Use -param twice")
707 << QByteArray("param1 param2\n")
708 << (QStringList() << path + QLatin1String("twoVariables.xq")
709 << QLatin1String("-param")
710 << QLatin1String("var1=param1")
711 << QLatin1String("-param")
712 << QLatin1String("var2=param2"))
716 QTest::newRow("Use -param thrice")
718 << QByteArray("param1 param2 third\n")
719 << (QStringList() << path + QLatin1String("threeVariables.xq")
720 << QLatin1String("-param")
721 << QLatin1String("var1=param1")
722 << QLatin1String("-param")
723 << QLatin1String("var2=param2")
724 << QLatin1String("-param")
725 << QLatin1String("var3=third"))
729 QTest::newRow("Specify the same parameter twice, different values")
732 << (QStringList() << path + QLatin1String("onePlusOne.xq")
733 << QLatin1String("-param")
734 << QLatin1String("duplicated=param1")
735 << QLatin1String("-param")
736 << QLatin1String("duplicated=param2"))
740 QTest::newRow("Specify the same parameter twice, same values")
743 << (QStringList() << path + QLatin1String("onePlusOne.xq")
744 << QLatin1String("-param")
745 << QLatin1String("duplicated=param1")
746 << QLatin1String("-param")
747 << QLatin1String("duplicated=param2"))
751 QTest::newRow("Open a non-existing collection.")
754 << (QStringList() << path + QLatin1String("nonexistingCollection.xq"))
759 // TODO pass external variables that allows space around the equal sign.
760 // TODO run fn:trace()
761 // TODO Trigger warning
762 // TODO what can we do with queries/nodeSequence.xq?
763 // TODO trigger serialization error
764 // TODO "xmlpatterns e.xq x" gives "binding must equal .."
766 // TODO use stdout where it's connected to a non-writable file.
767 // TODO specify -format twice, or whatever it's called.
768 // TODO query name that starts with "-".
770 // TODO Consider what we should do with paths on windows. Stuff like path\filename.xml fails.
771 // TODO use invalid URI in query name, xmlpatterns -is-uri 'as1/#(¤/¤)("#'
773 // TODO add xmlpatterns file1 file2 file3
774 // TODO add xmlpatterns -is-uri file1 file2 file3
777 void tst_XmlPatterns::createNonWritable(const QString &name)
779 /* Create an existing, empty, non-writable file. */
781 QVERIFY(outFile.open(QIODevice::ReadWrite));
782 outFile.write(QByteArray("1"));
783 QVERIFY(outFile.resize(0));
785 QVERIFY(outFile.setPermissions(QFile::Permissions(QFile::ReadOwner)));
788 void tst_XmlPatterns::removeNonWritable(QFile &outFile)
790 /* Kill off temporary files. */
791 if(!outFile.remove())
793 /* Since one file is used for testing that we can handle non-writable file by
794 * changing the permissions, we need to revert it such that we can remove it. */
795 outFile.setPermissions(QFile::WriteOwner);
801 Check that we gracefully handle writing out to stdout
802 when the latter is not writable.
804 void tst_XmlPatterns::stdoutFailure() const
806 return; // TODO It's really hard to write testing code for this.
808 const QString outName(QLatin1String("stdoutFailure.out"));
809 createNonWritable(outName);
812 // If we enable this line, waitForFinished() fails.
813 //process.setStandardOutputFile(outName);
815 process.setWorkingDirectory(QDir::current().absoluteFilePath(QString()));
816 process.start(m_command, QStringList(QFINDTESTDATA("queries/onePlusOne.xq")));
818 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
819 QVERIFY(process.waitForFinished());
821 QFile outFile(outName);
822 QVERIFY(outFile.open(QIODevice::ReadOnly));
823 QCOMPARE(outFile.readAll(), QByteArray());
825 QCOMPARE(process.exitCode(), 1);
827 removeNonWritable(outFile);
830 void tst_XmlPatterns::cleanupTestCase() const
832 /* Remove temporaries that we create. */
834 files << QLatin1String("existingContent.out")
835 << QLatin1String("notWritable.out")
836 << QLatin1String("output1");
838 for(int i = 0; i < files.count(); ++i)
840 QFile file(files.at(i));
841 removeNonWritable(file);
844 QCOMPARE(m_generatedTests, 0);
847 void tst_XmlPatterns::xsltSupport()
852 void tst_XmlPatterns::xsltSupport_data() const
855 QSKIP("The command line utility is not in the path.");
858 QSKIP("WinCE: This test uses unsupported WinCE functionality");
861 QString spath = QFINDTESTDATA("stylesheets/");
862 QString qpath = QFINDTESTDATA("queries/");
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() << spath + QLatin1String("queryAsStylesheet.xsl")
881 << qpath + QLatin1String("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 << qpath + QLatin1String("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 << spath + QLatin1String("namedAndRootTemplate.xsl")
934 << spath + QLatin1String("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 << spath + QLatin1String("namedAndRootTemplate.xsl")
945 << spath + QLatin1String("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 << spath + QLatin1String("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 << spath + QLatin1String("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 << spath + QLatin1String("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() << spath + QLatin1String("simplifiedStylesheetModule.xsl")
986 << spath + QLatin1String("simplifiedStylesheetModule.xml"))
990 QTest::newRow("Not well-formed stylesheet, causes crash in coloring code.")
993 << (QStringList() << spath + QLatin1String("notWellformed.xsl")
994 << qpath + QLatin1String("simpleDocument.xml"))
998 QTest::newRow("Not well-formed instance document, causes crash in coloring code.")
1001 << (QStringList() << spath + QLatin1String("bool070.xsl")
1002 << spath + QLatin1String("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.
1017 Return a copy of some stderr text with some irrelevant things filtered.
1019 QString tst_XmlPatterns::filterStderr(const QString &in)
1021 static QList<QRegExp> irrelevant = QList<QRegExp>()
1023 // specific filenames
1024 << QRegExp(QLatin1String("file:\\/\\/.*(\\.xq|\\.gccxml|\\.xml|\\.xsl|-)(,|:)"))
1026 // warning messages about old-style plugins
1027 << QRegExp(QLatin1String("Old plugin format found in lib [^\n]+\n"))
1028 << QRegExp(QLatin1String("Qt plugin loader: Compatibility plugin [^\n]+\n"))
1032 foreach (const QRegExp& rx, irrelevant) {
1033 out = out.remove(rx);
1039 QTEST_MAIN(tst_XmlPatterns)
1041 #include "tst_xmlpatterns.moc"
1043 // vim: et:ts=4:sw=4:sts=4