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 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 | #ifndef PatternistSDK_TestCase_H |
30 | #define PatternistSDK_TestCase_H |
31 | |
32 | #include <QtXmlPatterns/QXmlQuery> |
33 | |
34 | #include <private/qexternalvariableloader_p.h> |
35 | |
36 | #include "ErrorHandler.h" |
37 | #include "TestBaseLine.h" |
38 | #include "Global.h" |
39 | |
40 | #include "TestItem.h" |
41 | |
42 | QT_BEGIN_NAMESPACE |
43 | |
44 | class QDate; |
45 | class QString; |
46 | class QUrl; |
47 | |
48 | namespace QPatternistSDK |
49 | { |
50 | class XMLWriter; |
51 | |
52 | /** |
53 | * @short A generic abstract base class for test cases. |
54 | * |
55 | * @ingroup PatternistSDK |
56 | * @author Frans Englich <frans.englich@nokia.com> |
57 | */ |
58 | class TestCase : public TestItem |
59 | { |
60 | public: |
61 | /** |
62 | * Corresponds to the simpleType test:scenarios-enum |
63 | */ |
64 | enum Scenario |
65 | { |
66 | /** |
67 | * The test case should evaluate normally and that the output |
68 | * should match the supplied base line. |
69 | */ |
70 | Standard = 1, |
71 | |
72 | /** |
73 | * The test case should result in a static error, a parser error. |
74 | */ |
75 | ParseError = 2, |
76 | |
77 | /** |
78 | * The test case should result in a dynamic error, a runtime error. |
79 | */ |
80 | RuntimeError = 4, |
81 | |
82 | Trivial = 8, |
83 | |
84 | /** |
85 | * ParseError and RuntimeError OR'd. |
86 | */ |
87 | AnyError = RuntimeError | ParseError |
88 | |
89 | }; |
90 | |
91 | TestCase(); |
92 | virtual ~TestCase(); |
93 | |
94 | /** |
95 | * Executes the test, and returns the result. The returned list |
96 | * will always contain exactly one TestResult. |
97 | * |
98 | * @p stage is ignored when running out-of-process. |
99 | */ |
100 | virtual TestResult::List execute(const ExecutionStage stage, |
101 | TestSuite *ts); |
102 | |
103 | /** |
104 | * Determines the corresponding Scenario enumerator from the string |
105 | * representation @p string. |
106 | * |
107 | * The following mappings are in effect: |
108 | * @arg @c Standard "standard" |
109 | * @arg @c ParseError "parse-error" |
110 | * @arg @c RuntimeError "runtime-error" |
111 | */ |
112 | static Scenario scenarioFromString(const QString &string); |
113 | |
114 | /** |
115 | * @return always @c true |
116 | */ |
117 | virtual bool isFinalNode() const; |
118 | |
119 | /** |
120 | * Calling this function makes no sense, so it always |
121 | * performs an Q_ASSERT check. |
122 | */ |
123 | virtual void appendChild(TreeItem *); |
124 | |
125 | /** |
126 | * Calling this function makes no sense, so it always |
127 | * performs an Q_ASSERT check. |
128 | */ |
129 | virtual TreeItem *child(const unsigned int) const; |
130 | |
131 | /** |
132 | * @return always zero |
133 | */ |
134 | virtual unsigned int childCount() const; |
135 | |
136 | /** |
137 | * @return always an empty list. |
138 | */ |
139 | virtual TreeItem::List children() const; |
140 | |
141 | /** |
142 | * A description of the test case for human consumption. |
143 | */ |
144 | virtual QString description() const = 0; |
145 | |
146 | /** |
147 | * The title of the test. This can be the identifier of the test, for example. |
148 | */ |
149 | virtual QString title() const = 0; |
150 | |
151 | /** |
152 | * Whether this test case only make use of XPath features. |
153 | * |
154 | * @returns @c false if the test case exercises any XQuery feature |
155 | * which is not available in XPath 2.0. |
156 | */ |
157 | virtual bool isXPath() const = 0; |
158 | |
159 | /** |
160 | * The full name of the creator of the test case. For example, "Frans Englich". |
161 | */ |
162 | virtual QString creator() const = 0; |
163 | |
164 | /** |
165 | * The date of when the test case was created or last modified. |
166 | */ |
167 | virtual QDate lastModified() const = 0; |
168 | |
169 | /** |
170 | * The test's source code. That is, the XPath/XQuery code for the test. |
171 | * |
172 | * @param ok the function sets this value to @c false if loading the query |
173 | * failed, and returns a description of the error for human consumption. If |
174 | * everything went ok, @p ok is set to @c true, and the query is returned. |
175 | */ |
176 | virtual QString sourceCode(bool &ok) const = 0; |
177 | |
178 | /** |
179 | * The path to the file containing the code of the test case. |
180 | */ |
181 | virtual QUrl testCasePath() const = 0; |
182 | |
183 | /** |
184 | * The test case's identifier. For example, "Literals001". |
185 | */ |
186 | virtual QString name() const = 0; |
187 | |
188 | /** |
189 | * What kind of test this is. For example, whether the test case |
190 | * should result in a parser error or should evaluate without errors. |
191 | * |
192 | * The vast common case is that one Scenario is returned; the bit signifiance |
193 | * is for the TestCase sub-class UserTestCase. |
194 | */ |
195 | virtual Scenario scenario() const = 0; |
196 | |
197 | static QString displayName(const Scenario scen); |
198 | |
199 | /** |
200 | * @returns the valid test baselines for this test case. If only |
201 | * one outcome is valid, the returned list only contains |
202 | * that baseline. |
203 | */ |
204 | virtual TestBaseLine::List baseLines() const = 0; |
205 | |
206 | virtual TestResult *testResult() const; |
207 | |
208 | virtual ResultSummary resultSummary() const; |
209 | |
210 | void toXML(XMLWriter &receiver) const; |
211 | |
212 | virtual QPatternist::ExternalVariableLoader::Ptr externalVariableLoader() const = 0; |
213 | |
214 | /** |
215 | * @short The XML document that should be used as focus. If none should |
216 | * be used, and hence the focus be undefined, a default constructed |
217 | * QUrl is returned. |
218 | */ |
219 | virtual QUrl contextItemSource() const = 0; |
220 | |
221 | /** |
222 | * Returns by default QXmlQuery::XQuery10. |
223 | */ |
224 | virtual QXmlQuery::QueryLanguage language() const; |
225 | |
226 | virtual QXmlName initialTemplateName() const; |
227 | private: |
228 | TestResult::List execute(const ExecutionStage stage); |
229 | TestResult *createTestResult(const TestResult::Status status, |
230 | const QString &) const; |
231 | |
232 | QPointer<TestResult> m_result; |
233 | }; |
234 | } |
235 | |
236 | QT_END_NAMESPACE |
237 | |
238 | #endif |
239 | // vim: et:ts=4:sw=4:sts=4 |
240 | |