Remove needless include from xmlpatternsvalidator test.
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternsvalidator / tst_xmlpatternsvalidator.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite module of the Qt Toolkit.
8 **
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.
17 **
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.
21 **
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.
29 **
30 ** Other Usage
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.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QFile>
43 #include <QtTest/QtTest>
44 #include <QLibraryInfo>
45
46 #include "../qxmlquery/TestFundament.h"
47
48 /*!
49  \class tst_XmlPatterns
50  \internal
51  \since 4.6
52  \brief Tests the command line interface, \c xmlpatternsvalidator, for the XML validation code.
53  */
54 class tst_XmlPatternsValidator : public QObject
55                                , private TestFundament
56 {
57     Q_OBJECT
58
59 public:
60     tst_XmlPatternsValidator();
61
62 private Q_SLOTS:
63     void initTestCase();
64     void xsdSupport();
65     void xsdSupport_data() const;
66
67 private:
68     const QString   m_command;
69     bool            m_dontRun;
70 };
71
72 tst_XmlPatternsValidator::tst_XmlPatternsValidator()
73     : m_command(QLibraryInfo::location(QLibraryInfo::BinariesPath) + QLatin1String("/xmlpatternsvalidator"))
74     , m_dontRun(false)
75 {
76 }
77
78 void tst_XmlPatternsValidator::initTestCase()
79 {
80     QProcess process;
81     process.start(m_command);
82
83     if(!process.waitForFinished())
84     {
85         m_dontRun = true;
86         QSKIP(
87             qPrintable(QString(
88                 "The command line tool (%1) could not be run, possibly because Qt was "
89                 "incompletely built or installed. No tests will be run."
90             ).arg(m_command))
91         );
92     }
93 }
94
95 void tst_XmlPatternsValidator::xsdSupport()
96 {
97     if(m_dontRun)
98         QSKIP("The command line utility is not in the path.");
99
100 #ifdef Q_OS_WINCE
101     QSKIP("WinCE: This test uses unsupported WinCE functionality");
102 #endif
103
104     QFETCH(int,         expectedExitCode);
105     QFETCH(QStringList, arguments);
106     QFETCH(QString,     cwd);
107
108     QProcess process;
109
110     if(!cwd.isEmpty())
111         process.setWorkingDirectory(inputFile(cwd));
112
113     process.start(m_command, arguments);
114
115     QVERIFY(process.waitForFinished());
116     QCOMPARE(process.exitStatus(), QProcess::NormalExit);
117
118     if(process.exitCode() != expectedExitCode)
119         QTextStream(stderr) << "foo:" << process.readAllStandardError();
120
121     QCOMPARE(process.exitCode(), expectedExitCode);
122 }
123
124 void tst_XmlPatternsValidator::xsdSupport_data() const
125 {
126 #ifdef Q_OS_WINCE
127     return;
128 #endif
129
130     QTest::addColumn<int>("expectedExitCode");
131     QTest::addColumn<QStringList>("arguments");
132     QTest::addColumn<QString>("cwd");
133
134     QTest::newRow("No arguments")
135         << 2
136         << QStringList()
137         << QString();
138
139     QTest::newRow("A valid schema")
140         << 0
141         << QStringList(QLatin1String("files/valid_schema.xsd"))
142         << QString();
143
144     QTest::newRow("An invalid schema")
145         << 1
146         << QStringList(QLatin1String("files/invalid_schema.xsd"))
147         << QString();
148
149     QTest::newRow("An instance and valid schema")
150         << 0
151         << (QStringList() << QLatin1String("files/instance.xml")
152                           << QLatin1String("files/valid_schema.xsd"))
153         << QString();
154
155     QTest::newRow("An instance and invalid schema")
156         << 1
157         << (QStringList() << QLatin1String("files/instance.xml")
158                           << QLatin1String("files/invalid_schema.xsd"))
159         << QString();
160
161     QTest::newRow("An instance and not matching schema")
162         << 1
163         << (QStringList() << QLatin1String("files/instance.xml")
164                           << QLatin1String("files/other_valid_schema.xsd"))
165         << QString();
166
167     QTest::newRow("Two instance documents")
168         << 1
169         << (QStringList() << QLatin1String("files/instance.xml")
170                           << QLatin1String("files/instance.xml"))
171         << QString();
172
173     QTest::newRow("Three instance documents")
174         << 2
175         << (QStringList() << QLatin1String("files/instance.xml")
176                           << QLatin1String("files/instance.xml")
177                           << QLatin1String("files/instance.xml"))
178         << QString();
179
180     QTest::newRow("Two schema documents")
181         << 1
182         << (QStringList() << QLatin1String("files/valid_schema.xsd")
183                           << QLatin1String("files/valid_schema.xsd"))
184         << QString();
185
186     QTest::newRow("A schema aware valid instance document")
187         << 0
188         << (QStringList() << QLatin1String("files/sa_valid_instance.xml"))
189         << QString();
190
191     QTest::newRow("A schema aware invalid instance document")
192         << 1
193         << (QStringList() << QLatin1String("files/sa_invalid_instance.xml"))
194         << QString();
195
196     QTest::newRow("A non-schema aware instance document")
197         << 1
198         << (QStringList() << QLatin1String("files/instance.xml"))
199         << QString();
200
201     QTest::newRow("QTBUG-8394 A schema with an indirectly included type")
202         << 0
203         << (QStringList() << QLatin1String("files/indirect-include-a.xsd"))
204         << QString();
205
206     QTest::newRow("QTBUG-8394 A schema with an indirectly imported type")
207         << 0
208         << (QStringList() << QLatin1String("files/indirect-import-a.xsd"))
209         << QString();
210
211     QTest::newRow("QTBUG-8394 A schema with an indirectly redefined type")
212         << 0
213         << (QStringList() << QLatin1String("files/indirect-redefine-a.xsd"))
214         << QString();
215
216     QTest::newRow("QTBUG-8920 A schema with a complex type that indirectly includes an anonymous type")
217         << 0
218         << (QStringList() << QLatin1String("files/complex-type-including-anonymous-type.xsd"))
219         << QString();
220
221     QTest::newRow("QTBUG-11559 A schema and instance with a dateTime containing microseconds")
222         << 0
223         << (QStringList() << QLatin1String("files/dateTime-with-microseconds.xml")
224                           << QLatin1String("files/dateTime-with-microseconds.xsd"))
225         << QString();
226 }
227
228 QTEST_MAIN(tst_XmlPatternsValidator)
229
230 #include "tst_xmlpatternsvalidator.moc"
231
232 // vim: et:ts=4:sw=4:sts=4