1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the test suite module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #include <QFile> |
30 | #include <QtTest/QtTest> |
31 | #include <QLibraryInfo> |
32 | |
33 | #include "../qxmlquery/TestFundament.h" |
34 | |
35 | /*! |
36 | \class tst_XmlPatterns |
37 | \internal |
38 | \since 4.6 |
39 | \brief Tests the command line interface, \c xmlpatternsvalidator, for the XML validation code. |
40 | */ |
41 | class tst_XmlPatternsValidator : public QObject |
42 | , private TestFundament |
43 | { |
44 | Q_OBJECT |
45 | |
46 | public: |
47 | tst_XmlPatternsValidator(); |
48 | |
49 | private Q_SLOTS: |
50 | void initTestCase(); |
51 | void xsdSupport(); |
52 | void xsdSupport_data() const; |
53 | |
54 | private: |
55 | const QString m_command; |
56 | bool m_dontRun; |
57 | }; |
58 | |
59 | tst_XmlPatternsValidator::tst_XmlPatternsValidator() |
60 | : m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/xmlpatternsvalidator" )) |
61 | , m_dontRun(false) |
62 | { |
63 | } |
64 | |
65 | void tst_XmlPatternsValidator::initTestCase() |
66 | { |
67 | #ifndef QT_NO_PROCESS |
68 | QProcess process; |
69 | process.start(command: m_command); |
70 | |
71 | if(!process.waitForFinished()) |
72 | { |
73 | m_dontRun = true; |
74 | QSKIP( |
75 | qPrintable(QString( |
76 | "The command line tool (%1) could not be run, possibly because Qt was " |
77 | "incompletely built or installed. No tests will be run." |
78 | ).arg(m_command)) |
79 | ); |
80 | } |
81 | #else |
82 | QSKIP("Skipping test due to not having process support" ); |
83 | #endif // QT_NO_PROCESS |
84 | } |
85 | |
86 | void tst_XmlPatternsValidator::xsdSupport() |
87 | { |
88 | if(m_dontRun) |
89 | QSKIP("The command line utility is not in the path." ); |
90 | |
91 | #ifndef QT_NO_PROCESS |
92 | QFETCH(int, expectedExitCode); |
93 | QFETCH(QStringList, arguments); |
94 | QFETCH(QString, cwd); |
95 | |
96 | QProcess process; |
97 | |
98 | if(!cwd.isEmpty()) |
99 | process.setWorkingDirectory(inputFile(file: cwd)); |
100 | |
101 | process.start(program: m_command, arguments); |
102 | |
103 | QVERIFY(process.waitForFinished()); |
104 | QCOMPARE(process.exitStatus(), QProcess::NormalExit); |
105 | |
106 | if(process.exitCode() != expectedExitCode) |
107 | QTextStream(stderr) << "foo:" << process.readAllStandardError(); |
108 | |
109 | QCOMPARE(process.exitCode(), expectedExitCode); |
110 | #else |
111 | QSKIP("Skipping test due to not having process support" ); |
112 | #endif // QT_NO_PROCESS |
113 | } |
114 | |
115 | void tst_XmlPatternsValidator::xsdSupport_data() const |
116 | { |
117 | QString path = QFINDTESTDATA("files/" ); |
118 | |
119 | /* Check one file for existence, to avoid a flood of failures. */ |
120 | QVERIFY(QFile::exists(path + QLatin1String("instance.xml" ))); |
121 | |
122 | QTest::addColumn<int>(name: "expectedExitCode" ); |
123 | QTest::addColumn<QStringList>(name: "arguments" ); |
124 | QTest::addColumn<QString>(name: "cwd" ); |
125 | |
126 | QTest::newRow(dataTag: "No arguments" ) |
127 | << 2 |
128 | << QStringList() |
129 | << QString(); |
130 | |
131 | QTest::newRow(dataTag: "A valid schema" ) |
132 | << 0 |
133 | << QStringList(path + QLatin1String("valid_schema.xsd" )) |
134 | << QString(); |
135 | |
136 | QTest::newRow(dataTag: "An invalid schema" ) |
137 | << 1 |
138 | << QStringList(path + QLatin1String("invalid_schema.xsd" )) |
139 | << QString(); |
140 | |
141 | QTest::newRow(dataTag: "An instance and valid schema" ) |
142 | << 0 |
143 | << (QStringList() << path + QLatin1String("instance.xml" ) |
144 | << path + QLatin1String("valid_schema.xsd" )) |
145 | << QString(); |
146 | |
147 | QTest::newRow(dataTag: "An instance and invalid schema" ) |
148 | << 1 |
149 | << (QStringList() << path + QLatin1String("instance.xml" ) |
150 | << path + QLatin1String("invalid_schema.xsd" )) |
151 | << QString(); |
152 | |
153 | QTest::newRow(dataTag: "An instance and not matching schema" ) |
154 | << 1 |
155 | << (QStringList() << path + QLatin1String("instance.xml" ) |
156 | << path + QLatin1String("other_valid_schema.xsd" )) |
157 | << QString(); |
158 | |
159 | QTest::newRow(dataTag: "Two instance documents" ) |
160 | << 1 |
161 | << (QStringList() << path + QLatin1String("instance.xml" ) |
162 | << path + QLatin1String("instance.xml" )) |
163 | << QString(); |
164 | |
165 | QTest::newRow(dataTag: "Three instance documents" ) |
166 | << 2 |
167 | << (QStringList() << path + QLatin1String("instance.xml" ) |
168 | << path + QLatin1String("instance.xml" ) |
169 | << path + QLatin1String("instance.xml" )) |
170 | << QString(); |
171 | |
172 | QTest::newRow(dataTag: "Two schema documents" ) |
173 | << 1 |
174 | << (QStringList() << path + QLatin1String("valid_schema.xsd" ) |
175 | << path + QLatin1String("valid_schema.xsd" )) |
176 | << QString(); |
177 | |
178 | QTest::newRow(dataTag: "A schema aware valid instance document" ) |
179 | << 0 |
180 | << (QStringList() << path + QLatin1String("sa_valid_instance.xml" )) |
181 | << QString(); |
182 | |
183 | QTest::newRow(dataTag: "A schema aware invalid instance document" ) |
184 | << 1 |
185 | << (QStringList() << path + QLatin1String("sa_invalid_instance.xml" )) |
186 | << QString(); |
187 | |
188 | QTest::newRow(dataTag: "A non-schema aware instance document" ) |
189 | << 1 |
190 | << (QStringList() << path + QLatin1String("instance.xml" )) |
191 | << QString(); |
192 | |
193 | QTest::newRow(dataTag: "QTBUG-8394 A schema with an indirectly included type" ) |
194 | << 0 |
195 | << (QStringList() << path + QLatin1String("indirect-include-a.xsd" )) |
196 | << QString(); |
197 | |
198 | QTest::newRow(dataTag: "QTBUG-8394 A schema with an indirectly imported type" ) |
199 | << 0 |
200 | << (QStringList() << path + QLatin1String("indirect-import-a.xsd" )) |
201 | << QString(); |
202 | |
203 | QTest::newRow(dataTag: "QTBUG-8394 A schema with an indirectly redefined type" ) |
204 | << 0 |
205 | << (QStringList() << path + QLatin1String("indirect-redefine-a.xsd" )) |
206 | << QString(); |
207 | |
208 | QTest::newRow(dataTag: "QTBUG-8920 A schema with a complex type that indirectly includes an anonymous type" ) |
209 | << 0 |
210 | << (QStringList() << path + QLatin1String("complex-type-including-anonymous-type.xsd" )) |
211 | << QString(); |
212 | |
213 | QTest::newRow(dataTag: "QTBUG-11559 A schema and instance with a dateTime containing microseconds" ) |
214 | << 0 |
215 | << (QStringList() << path + QLatin1String("dateTime-with-microseconds.xml" ) |
216 | << path + QLatin1String("dateTime-with-microseconds.xsd" )) |
217 | << QString(); |
218 | |
219 | QTest::newRow(dataTag: "A document with a valid substitution group" ) |
220 | << 0 |
221 | << (QStringList() << path + QLatin1String("substitution-group-valid.xml" ) |
222 | << path + QLatin1String("substitution-group.xsd" )) |
223 | << QString(); |
224 | |
225 | QTest::newRow(dataTag: "A document attempting to use a prohibited substitution" ) |
226 | << 1 |
227 | << (QStringList() << path + QLatin1String("substitution-group-invalid.xml" ) |
228 | << path + QLatin1String("substitution-group.xsd" )) |
229 | << QString(); |
230 | QTest::newRow(dataTag: "QTBUG-58245 fraction digits should ignore trailing 0" ) |
231 | << 0 |
232 | << (QStringList() << path + QLatin1String("fractiondigits.xml" ) |
233 | << path + QLatin1String("fractiondigits.xsd" )) |
234 | << QString(); |
235 | QTest::newRow(dataTag: "QTBUG-58245 fraction digits should ignore trailing 0 with no dots" ) |
236 | << 0 |
237 | << (QStringList() << path + QLatin1String("fractiondigits-nodot.xml" ) |
238 | << path + QLatin1String("fractiondigits.xsd" )) |
239 | << QString(); |
240 | QTest::newRow(dataTag: "QTBUG-58245 fraction digits should ignore trailing 0 with no number before dot" ) |
241 | << 0 |
242 | << (QStringList() << path + QLatin1String("fractiondigits-nonumber.xml" ) |
243 | << path + QLatin1String("fractiondigits.xsd" )) |
244 | << QString(); |
245 | QTest::newRow(dataTag: "QTBUG-58245 fraction digits should ignore trailing 0 invalid" ) |
246 | << 1 |
247 | << (QStringList() << path + QLatin1String("fractiondigits-invalid.xml" ) |
248 | << path + QLatin1String("fractiondigits.xsd" )) |
249 | << QString(); |
250 | } |
251 | |
252 | QTEST_MAIN(tst_XmlPatternsValidator) |
253 | |
254 | #include "tst_xmlpatternsvalidator.moc" |
255 | |
256 | // vim: et:ts=4:sw=4:sts=4 |
257 | |