|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 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 of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef PatternistSDK_TestBaseLine_H |
|
43 #define PatternistSDK_TestBaseLine_H |
|
44 |
|
45 #include <QString> |
|
46 |
|
47 #include "Global.h" |
|
48 #include "TestResult.h" |
|
49 |
|
50 QT_BEGIN_HEADER |
|
51 |
|
52 QT_BEGIN_NAMESPACE |
|
53 |
|
54 class QDomNamedNodeMap; |
|
55 class QDomNode; |
|
56 class QDomNodeList; |
|
57 template<typename T> class QList; |
|
58 |
|
59 namespace QPatternistSDK |
|
60 { |
|
61 /** |
|
62 * @short Represents an expected test result for a test case. |
|
63 * |
|
64 * TestBaseLine represents a valid outcome for a test case, |
|
65 * the "base line". A XQTS test case can have many different valid |
|
66 * base lines, and one TestBaseLine instance represents on of them. |
|
67 * |
|
68 * Of highest interest, TestBaseLine have the function scan() and |
|
69 * scanErrors(), which allows serialized output to be |
|
70 * compared to the base line. |
|
71 * |
|
72 * @ingroup PatternistSDK |
|
73 * @author Frans Englich <frans.englich@nokia.com> |
|
74 */ |
|
75 class Q_PATTERNISTSDK_EXPORT TestBaseLine |
|
76 { |
|
77 public: |
|
78 typedef QList<TestBaseLine *> List; |
|
79 |
|
80 /** |
|
81 * Identifies what kind of comparator to use. The documentation |
|
82 * for each enumerator is copied from |
|
83 * <a href="http://www.w3.org/XML/Query/test-suite/Guidelines |
|
84 * for Running the XML Query Test Suite.html">Guidelines |
|
85 * for Running the XML Query Test Suite</a> |
|
86 */ |
|
87 enum Type |
|
88 { |
|
89 /** |
|
90 * The test harness must canonicalize both, the actual result |
|
91 * and the expected result according to the "Canonical XML" recommendation [2], |
|
92 * which refers to a number of open-source implementations. Byte-comparison can |
|
93 * then be applied to the resulting XML documents. If the test harness does |
|
94 * this process in a different manner, it must be documented. |
|
95 */ |
|
96 XML, |
|
97 |
|
98 /** |
|
99 * For XML fragments, the same root node must be created for both, |
|
100 * implementation result and test suite result. The resulting XML |
|
101 * can be compared using XML comparison. |
|
102 */ |
|
103 Fragment, |
|
104 |
|
105 /** |
|
106 * Text (that has been produced by XML serialization) is compared |
|
107 * using byte-comparison. |
|
108 */ |
|
109 Text, |
|
110 |
|
111 /** |
|
112 * No comparison needs to be applied; the result is always @c true if |
|
113 * the implementation successfully executes the test case. |
|
114 */ |
|
115 Ignore, |
|
116 |
|
117 /** |
|
118 * A human is required to make the call about correctness of the result |
|
119 * according to the description in the test case. |
|
120 */ |
|
121 Inspect, |
|
122 |
|
123 /** |
|
124 * The expected result of the test case is an error, identified as an |
|
125 * eight-character error code (e.g., XPST0003). The result of a test is |
|
126 * @c true, if the implementation raises an error. However, raising an error |
|
127 * because an implementation does not support the feature is not |
|
128 * considered a correct result. |
|
129 */ |
|
130 ExpectedError, |
|
131 |
|
132 /** |
|
133 * A special comparison for the schema validation tests. The details |
|
134 * can only be 'true' or 'false' depending on whether it is a valid |
|
135 * schema or not. |
|
136 */ |
|
137 SchemaIsValid |
|
138 }; |
|
139 |
|
140 /** |
|
141 * Takes a string identifying a comparator either in the XSL-T or the |
|
142 * XQuery test suite, and returns an enum value for it. |
|
143 * |
|
144 * If the value is unknown, the code asserts. |
|
145 */ |
|
146 static Type identifierFromString(const QString &string); |
|
147 |
|
148 /** |
|
149 * @returns a display name for @p id. For example, if Inspect was passed, "Inspect" |
|
150 * would be returned. |
|
151 */ |
|
152 static QString displayName(const Type id); |
|
153 |
|
154 /** |
|
155 * Compares @p items(typically the result of an evaluation) against |
|
156 * the base lines @p lines. |
|
157 * |
|
158 * @returns the status of the first base line which passes, |
|
159 * otherwise TestResult::Fail. |
|
160 */ |
|
161 static TestResult::Status scan(const QString &serialized, |
|
162 const TestBaseLine::List &lines); |
|
163 |
|
164 static TestResult::Status scanErrors(const ErrorHandler::Message::List &errors, |
|
165 const TestBaseLine::List &lines); |
|
166 |
|
167 /** |
|
168 * Constructs a TestBaseLine of type @p type. |
|
169 */ |
|
170 TestBaseLine(const Type type); |
|
171 |
|
172 /** |
|
173 * What @p details contains depends on the type(). If the type() is ExpectedError, |
|
174 * @p details contains the relevant error code. If the type() is one which compares |
|
175 * result against a base line, it is a filename locating the baseline. |
|
176 */ |
|
177 void setDetails(const QString &details); |
|
178 |
|
179 Type type() const; |
|
180 |
|
181 QString details() const; |
|
182 |
|
183 void toXML(XMLWriter &receiver) const; |
|
184 |
|
185 protected: |
|
186 TestResult::Status verify(const QString &serializedInput) const; |
|
187 |
|
188 private: |
|
189 static bool isDeepEqual(const QDomNode &n1, const QDomNode &n2); |
|
190 |
|
191 /** |
|
192 * @returns @c true if the nodes in @p cl1 are equal to @p cl2, by calling isDeepEqual() |
|
193 * for each pair. |
|
194 */ |
|
195 static bool isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2); |
|
196 |
|
197 /** |
|
198 * Considers @p cl1 and @p cl2 to be lists containing attributes. The list are equal |
|
199 * if they contain attributes by same value and name, but regardless of order. |
|
200 */ |
|
201 static bool isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2); |
|
202 const Type m_type; |
|
203 QString m_details; |
|
204 }; |
|
205 } |
|
206 |
|
207 QT_END_NAMESPACE |
|
208 |
|
209 QT_END_HEADER |
|
210 |
|
211 #endif |
|
212 // vim: et:ts=4:sw=4:sts=4 |