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(inputFile(QLatin1String(SRCDIR "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 const 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 /* Check one file for existence, to avoid possible false positives. */
231 QVERIFY(QFile::exists(inputFile(QLatin1String(SRCDIR "queries/onePlusOne.xq"))));
233 QTest::addColumn<int>("expectedExitCode");
234 QTest::addColumn<QByteArray>("expectedQueryOutput");
235 QTest::addColumn<QStringList>("arguments");
236 QTest::addColumn<QString>("cwd");
237 QTest::addColumn<QString>("outputFile");
239 QTest::newRow("A simple math query")
242 << QStringList((QLatin1String(SRCDIR "queries/onePlusOne.xq")))
246 QTest::newRow("An unbound external variable")
249 << QStringList(QLatin1String(SRCDIR "queries/externalVariable.xq"))
253 QTest::newRow("Bind an external variable")
255 << QByteArray("1 4<e>1</e>true\n")
256 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
257 << QLatin1String("-param")
258 << QLatin1String("externalVariable=1"))
262 QTest::newRow("Bind an external variable, query appearing last")
264 << QByteArray("1 4<e>1</e>true\n")
265 << (QStringList() << QLatin1String("-param")
266 << QLatin1String("externalVariable=1")
267 << QLatin1String(SRCDIR "queries/externalVariable.xq"))
271 QTest::newRow("Use fn:doc")
273 << 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")
274 << QStringList(QLatin1String(SRCDIR "queries/openDocument.xq"))
278 QTest::newRow("Use fn:doc, together with -no-format, last")
280 << 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>")
281 << (QStringList() << QLatin1String(SRCDIR "queries/openDocument.xq")
282 << QLatin1String("-no-format"))
286 QTest::newRow("Use fn:doc, together with -no-format, first")
288 << 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>")
289 << (QStringList() << QLatin1String("-no-format")
290 << QLatin1String(SRCDIR "queries/openDocument.xq"))
294 /* This is true for the command line utility, but not QXmlQuery::setQuery(). */
295 QTest::newRow("Make sure query paths are resolved against CWD, not the location of the executable.")
298 << QStringList(QLatin1String(SRCDIR "queries/onePlusOne.xq"))
299 << QString::fromLatin1("queries")
302 QTest::newRow("Call fn:error()")
305 << QStringList(QLatin1String(SRCDIR "queries/errorFunction.xq"))
309 QTest::newRow("Evaluate a library module")
312 << QStringList(QLatin1String(SRCDIR "queries/simpleLibraryModule.xq"))
316 QTest::newRow("Trigger a static error.")
319 << QStringList(QLatin1String(SRCDIR "queries/staticError.xq"))
323 QTest::newRow("Pass -help")
326 << QStringList(QLatin1String("-help"))
330 QTest::newRow("Open an nonexistent file")
333 << QStringList(QLatin1String(SRCDIR "queries/ThisFileDoesNotExist.xq"))
337 /* The following five tests exists to test the various
338 * markup classes in the message. */
339 QTest::newRow("XQuery-function message markups")
342 << QStringList(QLatin1String(SRCDIR "queries/wrongArity.xq"))
346 QTest::newRow("XQuery-type message markups")
349 << QStringList(QLatin1String(SRCDIR "queries/typeError.xq"))
353 QTest::newRow("XQuery-data & XQuery-keyword message markups")
356 << QStringList(QLatin1String(SRCDIR "queries/zeroDivision.xq"))
360 QTest::newRow("XQuery-uri message markups")
363 << QStringList(QLatin1String(SRCDIR "queries/unsupportedCollation.xq"))
367 QTest::newRow("XQuery-expression message markups")
370 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexp.xq"))
374 QTest::newRow("Print a list of available regexp flags(The available flags are formatted in a complex way.)")
377 << QStringList(QLatin1String(SRCDIR "queries/invalidRegexpFlag.xq"))
381 QTest::newRow("Trigger an assert in QPatternist::ColorOutput. The query naturally contains an error; XPTY0004.")
384 << QStringList(QLatin1String(SRCDIR "queries/flwor.xq"))
388 QTest::newRow("Trigger a second assert in QPatternist::ColorOutput. The query naturally contains XPST0003.")
391 << QStringList(QLatin1String(SRCDIR "queries/syntaxError.xq"))
395 QTest::newRow("-param is missing so multiple queries appear")
398 << (QStringList() << QLatin1String(SRCDIR "queries/reportGlobals.xq")
399 << QLatin1String("fileToOpen=globals.gccxml"))
403 QTest::newRow("only -no-format")
406 << (QStringList() << QLatin1String("-no-format"))
410 QTest::newRow("Basic use of -output, query first")
413 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
414 << QLatin1String("-output")
415 << QLatin1String("basicOutput.out"))
417 << QString::fromLatin1("basicOutput.out");
419 QTest::newRow("Basic use of -output, query last")
421 << QByteArray("<e/>\n")
422 << (QStringList() << QLatin1String("-output")
423 << QLatin1String("basicOutput2.out")
424 << QLatin1String(SRCDIR "queries/oneElement.xq"))
426 << QString::fromLatin1("basicOutput2.out");
428 QTest::newRow("A single query, that does not exist")
431 << (QStringList() << QLatin1String(SRCDIR "doesNotExist.xq"))
435 QTest::newRow("Specify two identical query names")
438 << (QStringList() << QLatin1String(SRCDIR "query.xq")
439 << QLatin1String(SRCDIR "query.xq"))
443 QTest::newRow("Specify no arguments at all.")
450 QTest::newRow("Use -output twice")
453 << (QStringList() << QLatin1String("-output")
454 << QLatin1String("output1")
455 << QLatin1String("-output")
456 << QLatin1String("output2"))
461 const QString filename(QString::fromLatin1("notWritable.out"));
462 createNonWritable(filename);
464 QTest::newRow("-output with a non-writable file")
467 << (QStringList() << QLatin1String("-output")
469 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
475 const QString outName(QString::fromLatin1("existingContent.out"));
476 QFile outFile(outName);
477 QVERIFY(outFile.open(QIODevice::WriteOnly));
478 QCOMPARE(outFile.write("Existing content\n"), qint64(17));
481 QTest::newRow("Use -output on a file with existing content, to ensure we truncate, not append the content we produce.")
484 << (QStringList() << QLatin1String("-output")
486 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
491 QTest::newRow("one query, and a terminating dash at the end")
494 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
495 << QLatin1String("-"))
499 QTest::newRow("one query, with a preceding dash")
502 << (QStringList() << QLatin1String("-")
503 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
507 QTest::newRow("A single dash, that's invalid")
510 << (QStringList() << QLatin1String("-"))
514 QTest::newRow("Invoke -version")
517 << (QStringList() << QLatin1String("-version"))
521 QTest::newRow("Unknown switch; -unknown-switch")
524 << (QStringList() << QLatin1String("-unknown-switch"))
528 QTest::newRow("Unknown switch; -d")
531 << (QStringList() << QLatin1String("-d"))
535 QTest::newRow("Passing a single dash is insufficient")
538 << (QStringList() << QLatin1String("-"))
542 QTest::newRow("Passing two dashes, the last is interpreted as a file name")
545 << (QStringList() << QLatin1String("-")
546 << QLatin1String("-"))
550 QTest::newRow("Pass three dashes, the two last gets interpreted as two query arguments")
553 << (QStringList() << QLatin1String("-")
554 << QLatin1String("-")
555 << QLatin1String("-"))
559 QTest::newRow("Load query via data: scheme")
561 << QByteArray("<e/>\n")
562 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml,%3Ce%2F%3E"))
566 QTest::newRow("Load query via FTP")
568 << QByteArray("This was received via FTP\n")
569 << (QStringList() << QLatin1String("-is-uri") << QString("ftp://" + QtNetworkSettings::serverName() + "/pub/qxmlquery/viaFtp.xq"))
573 QTest::newRow("Load query via HTTP")
575 << QByteArray("This was received via HTTP.\n")
576 << (QStringList() << QLatin1String("-is-uri") << QString("http://" + QtNetworkSettings::serverName() + "/qxmlquery/viaHttp.xq"))
580 QTest::newRow("We don't support -format any longer")
583 << (QStringList() << QLatin1String("-format"))
587 QTest::newRow("Run a query which evaluates to the empty sequence.")
590 << (QStringList() << QLatin1String(SRCDIR "queries/emptySequence.xq"))
594 QTest::newRow("Run a query which evaluates to a single document node with no children.")
597 << (QStringList() << QLatin1String(SRCDIR "queries/onlyDocumentNode.xq"))
601 QTest::newRow("Invoke with invalid -param value.")
604 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
605 << QLatin1String("-param")
606 << QLatin1String("EqualSignIsMissing"))
610 QTest::newRow("Invoke with colon in variable name.")
613 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
614 << QLatin1String("-param")
615 << QLatin1String("xs:name=value"))
619 QTest::newRow("Invoke with missing name in -param arg.")
622 << (QStringList() << QLatin1String(SRCDIR "queries/externalVariable.xq")
623 << QLatin1String("-param")
624 << QLatin1String("=value"))
628 QTest::newRow("Invoke with -param that has two adjacent equal signs.")
630 << QByteArray("START =text END\n")
631 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
632 << QLatin1String("-param")
633 << QLatin1String("externalString==text"))
637 QTest::newRow("Pass in an external variable, but the query doesn't use it.")
640 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
641 << QLatin1String("-param")
642 << QLatin1String("externalString==text"))
646 /* This is how an empty string would have been passed in. */
647 QTest::newRow("Invoke with -param that has no value.")
649 << QByteArray("START END\n")
650 << (QStringList() << QLatin1String(SRCDIR "queries/externalStringVariable.xq")
651 << QLatin1String("-param")
652 << QLatin1String("externalString="))
656 QTest::newRow("Ensure -is-uri can appear after the query filename")
658 << QByteArray("<e/>\n")
659 << (QStringList() << QLatin1String("data:application/xml,%3Ce%2F%3E") << QLatin1String("-is-uri"))
663 QTest::newRow("Use a native path")
666 << (QStringList() << QDir::toNativeSeparators(QLatin1String(SRCDIR "queries/onePlusOne.xq")))
670 QTest::newRow("Pass in invalid URI")
673 << (QStringList() << QLatin1String("-is-uri") << QLatin1String("data:application/xml;base64,PGUvg==="))
677 /* Not relevant anymore.
678 QTest::newRow("A valid, existing query, followed by a bogus one")
681 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
682 << QLatin1String(SRCDIR "doesNotExist.xq"))
687 /* Not relevant anymore.
688 QTest::newRow("Specify two different query names")
691 << (QStringList() << QLatin1String(SRCDIR "query1.xq")
692 << QLatin1String(SRCDIR "query2.xq"))
697 // TODO use focus with xquery
698 // TODO fail to load focus with xquery
699 // TODO focus with URI with xquery
700 // TODO focus via FTP or so with xquery
703 QTest::newRow("Use -param twice")
705 << QByteArray("param1 param2\n")
706 << (QStringList() << QLatin1String(SRCDIR "queries/twoVariables.xq")
707 << QLatin1String("-param")
708 << QLatin1String("var1=param1")
709 << QLatin1String("-param")
710 << QLatin1String("var2=param2"))
714 QTest::newRow("Use -param thrice")
716 << QByteArray("param1 param2 third\n")
717 << (QStringList() << QLatin1String(SRCDIR "queries/threeVariables.xq")
718 << QLatin1String("-param")
719 << QLatin1String("var1=param1")
720 << QLatin1String("-param")
721 << QLatin1String("var2=param2")
722 << QLatin1String("-param")
723 << QLatin1String("var3=third"))
727 QTest::newRow("Specify the same parameter twice, different values")
730 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
731 << QLatin1String("-param")
732 << QLatin1String("duplicated=param1")
733 << QLatin1String("-param")
734 << QLatin1String("duplicated=param2"))
738 QTest::newRow("Specify the same parameter twice, same values")
741 << (QStringList() << QLatin1String(SRCDIR "queries/onePlusOne.xq")
742 << QLatin1String("-param")
743 << QLatin1String("duplicated=param1")
744 << QLatin1String("-param")
745 << QLatin1String("duplicated=param2"))
749 QTest::newRow("Open a non-existing collection.")
752 << (QStringList() << QLatin1String(SRCDIR "queries/nonexistingCollection.xq"))
757 // TODO pass external variables that allows space around the equal sign.
758 // TODO run fn:trace()
759 // TODO Trigger warning
760 // TODO what can we do with queries/nodeSequence.xq?
761 // TODO trigger serialization error
762 // TODO "xmlpatterns e.xq x" gives "binding must equal .."
764 // TODO use stdout where it's connected to a non-writable file.
765 // TODO specify -format twice, or whatever it's called.
766 // TODO query name that starts with "-".
768 // TODO Consider what we should do with paths on windows. Stuff like path\filename.xml fails.
769 // TODO use invalid URI in query name, xmlpatterns -is-uri 'as1/#(¤/¤)("#'
771 // TODO add xmlpatterns file1 file2 file3
772 // TODO add xmlpatterns -is-uri file1 file2 file3
775 void tst_XmlPatterns::createNonWritable(const QString &name)
777 /* Create an existing, empty, non-writable file. */
779 QVERIFY(outFile.open(QIODevice::ReadWrite));
780 outFile.write(QByteArray("1"));
781 QVERIFY(outFile.resize(0));
783 QVERIFY(outFile.setPermissions(QFile::Permissions(QFile::ReadOwner)));
786 void tst_XmlPatterns::removeNonWritable(QFile &outFile)
788 /* Kill off temporary files. */
789 if(!outFile.remove())
791 /* Since one file is used for testing that we can handle non-writable file by
792 * changing the permissions, we need to revert it such that we can remove it. */
793 outFile.setPermissions(QFile::WriteOwner);
799 Check that we gracefully handle writing out to stdout
800 when the latter is not writable.
802 void tst_XmlPatterns::stdoutFailure() const
804 return; // TODO It's really hard to write testing code for this.
806 const QString outName(QLatin1String("stdoutFailure.out"));
807 createNonWritable(outName);
810 // If we enable this line, waitForFinished() fails.
811 //process.setStandardOutputFile(outName);
813 process.setWorkingDirectory(QDir::current().absoluteFilePath(QString()));
814 process.start(m_command, QStringList(SRCDIR "queries/onePlusOne.xq"));
816 QCOMPARE(process.exitStatus(), QProcess::NormalExit);
817 QVERIFY(process.waitForFinished());
819 QFile outFile(outName);
820 QVERIFY(outFile.open(QIODevice::ReadOnly));
821 QCOMPARE(outFile.readAll(), QByteArray());
823 QCOMPARE(process.exitCode(), 1);
825 removeNonWritable(outFile);
828 void tst_XmlPatterns::cleanupTestCase() const
830 /* Remove temporaries that we create. */
832 files << QLatin1String("existingContent.out")
833 << QLatin1String("notWritable.out")
834 << QLatin1String("output1");
836 for(int i = 0; i < files.count(); ++i)
838 QFile file(files.at(i));
839 removeNonWritable(file);
842 QCOMPARE(m_generatedTests, 0);
845 void tst_XmlPatterns::xsltSupport()
850 void tst_XmlPatterns::xsltSupport_data() const
853 QSKIP("The command line utility is not in the path.");
856 QSKIP("WinCE: This test uses unsupported WinCE functionality");
859 QTest::addColumn<int>("expectedExitCode");
860 QTest::addColumn<QByteArray>("expectedQueryOutput");
861 QTest::addColumn<QStringList>("arguments");
862 QTest::addColumn<QString>("cwd");
863 QTest::addColumn<QString>("outputFile");
865 QTest::newRow("Evaluate a stylesheet, with no context document")
868 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
872 QTest::newRow("Pass in a stylesheet file which contains an XQuery query")
875 << (QStringList() << QLatin1String(SRCDIR "stylesheets/queryAsStylesheet.xsl")
876 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
880 QTest::newRow("Pass in a stylesheet file and a focus file which doesn't exist")
883 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
884 << QLatin1String("doesNotExist.Nope.xml"))
888 QTest::newRow("-initial-template doesn't work with XQueries.")
891 << (QStringList() << QLatin1String("-initial-template")
892 << QLatin1String("name")
893 << QLatin1String(SRCDIR "queries/onePlusOne.xq"))
897 QTest::newRow("-initial-template must be followed by a value")
900 << (QStringList() << QLatin1String("-initial-template")
901 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
905 QTest::newRow("-initial-template must be followed by a value(#2)")
908 << (QStringList() << QLatin1String("stylesheets/onlyRootTemplate.xsl")
909 << QLatin1String("-initial-template"))
913 QTest::newRow("Invalid template name")
916 << (QStringList() << QLatin1String("-initial-template")
917 << QLatin1String("abc:def")
918 << QLatin1String("stylesheets/onlyRootTemplate.xsl"))
922 QTest::newRow("Specify a named template, that exists")
924 << QByteArray("named-template")
925 << (QStringList() << QLatin1String("-no-format")
926 << QLatin1String("-initial-template")
927 << QLatin1String("main")
928 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
929 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
933 QTest::newRow("Specify a named template, that does not exists")
935 << QByteArray("root-template")
936 << (QStringList() << QLatin1String("-no-format")
937 << QLatin1String("-initial-template")
938 << QLatin1String("no-template-by-this-name")
939 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl")
940 << QLatin1String(SRCDIR "stylesheets/documentElement.xml"))
944 QTest::newRow("Call a named template, and use no focus.")
946 << QByteArray("named-template")
947 << (QStringList() << QLatin1String("-no-format")
948 << QLatin1String("-initial-template")
949 << QLatin1String("main")
950 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
954 QTest::newRow("Call a named template, and use no focus.")
956 << QByteArray("namespaced-template")
957 << (QStringList() << QLatin1String("-no-format")
958 << QLatin1String("-initial-template")
959 << QLatin1String("{http://example.com/NS}main")
960 << QLatin1String(SRCDIR "stylesheets/namedAndRootTemplate.xsl"))
964 QTest::newRow("Invoke a template, and use/pass parameters.")
966 << QByteArray("defParam overridedDefaultedParam implicitlyRequiredValue\n")
967 << (QStringList() << QLatin1String("-initial-template")
968 << QLatin1String("main")
969 << QLatin1String(SRCDIR "stylesheets/useParameters.xsl")
970 << QLatin1String("-param")
971 << QLatin1String("overridedDefaultedParam=overridedDefaultedParam")
972 << QLatin1String("-param")
973 << QLatin1String("implicitlyRequiredValue=implicitlyRequiredValue"))
977 QTest::newRow("Use a simplified stylesheet module")
979 << QByteArray("<output>some text</output>\n")
980 << (QStringList() << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xsl")
981 << QLatin1String(SRCDIR "stylesheets/simplifiedStylesheetModule.xml"))
985 QTest::newRow("Not well-formed stylesheet, causes crash in coloring code.")
988 << (QStringList() << QLatin1String(SRCDIR "stylesheets/notWellformed.xsl")
989 << QLatin1String(SRCDIR "queries/simpleDocument.xml"))
993 QTest::newRow("Not well-formed instance document, causes crash in coloring code.")
996 << (QStringList() << QLatin1String(SRCDIR "stylesheets/bool070.xsl")
997 << QLatin1String(SRCDIR "stylesheets/bool070.xml"))
1001 // TODO test -is-uris with context
1002 // TODO fail to load focus document when using XSL-T
1003 // TODO fail to load focus document when using XQuery
1004 // TODO focus via FTP or so with xquery
1005 // TODO use URI in focus
1006 // TODO use invalid URI in focus
1008 // TODO invoke a template which has required params.
1012 Return a copy of some stderr text with some irrelevant things filtered.
1014 QString tst_XmlPatterns::filterStderr(const QString &in)
1016 static QList<QRegExp> irrelevant = QList<QRegExp>()
1018 // specific filenames
1019 << QRegExp(QLatin1String("file:\\/\\/.*(\\.xq|\\.gccxml|\\.xml|\\.xsl|-)(,|:)"))
1021 // warning messages about old-style plugins
1022 << QRegExp(QLatin1String("Old plugin format found in lib [^\n]+\n"))
1023 << QRegExp(QLatin1String("Qt plugin loader: Compatibility plugin [^\n]+\n"))
1027 foreach (const QRegExp& rx, irrelevant) {
1028 out = out.remove(rx);
1034 QTEST_MAIN(tst_XmlPatterns)
1036 #include "tst_xmlpatterns.moc"
1038 // vim: et:ts=4:sw=4:sts=4