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_TestBaseLine_H |
30 | #define PatternistSDK_TestBaseLine_H |
31 | |
32 | #include <QString> |
33 | |
34 | #include "Global.h" |
35 | #include "TestResult.h" |
36 | |
37 | QT_BEGIN_NAMESPACE |
38 | |
39 | class QDomNamedNodeMap; |
40 | class QDomNode; |
41 | class QDomNodeList; |
42 | template<typename T> class QList; |
43 | |
44 | namespace QPatternistSDK |
45 | { |
46 | /** |
47 | * @short Represents an expected test result for a test case. |
48 | * |
49 | * TestBaseLine represents a valid outcome for a test case, |
50 | * the "base line". A XQTS test case can have many different valid |
51 | * base lines, and one TestBaseLine instance represents on of them. |
52 | * |
53 | * Of highest interest, TestBaseLine have the function scan() and |
54 | * scanErrors(), which allows serialized output to be |
55 | * compared to the base line. |
56 | * |
57 | * @ingroup PatternistSDK |
58 | * @author Frans Englich <frans.englich@nokia.com> |
59 | */ |
60 | class TestBaseLine |
61 | { |
62 | public: |
63 | typedef QList<TestBaseLine *> List; |
64 | |
65 | /** |
66 | * Identifies what kind of comparator to use. The documentation |
67 | * for each enumerator is copied from |
68 | * <a href="http://www.w3.org/XML/Query/test-suite/Guidelines |
69 | * for Running the XML Query Test Suite.html">Guidelines |
70 | * for Running the XML Query Test Suite</a> |
71 | */ |
72 | enum Type |
73 | { |
74 | /** |
75 | * The test harness must canonicalize both, the actual result |
76 | * and the expected result according to the "Canonical XML" recommendation [2], |
77 | * which refers to a number of open-source implementations. Byte-comparison can |
78 | * then be applied to the resulting XML documents. If the test harness does |
79 | * this process in a different manner, it must be documented. |
80 | */ |
81 | XML, |
82 | |
83 | /** |
84 | * For XML fragments, the same root node must be created for both, |
85 | * implementation result and test suite result. The resulting XML |
86 | * can be compared using XML comparison. |
87 | */ |
88 | Fragment, |
89 | |
90 | /** |
91 | * Text (that has been produced by XML serialization) is compared |
92 | * using byte-comparison. |
93 | */ |
94 | Text, |
95 | |
96 | /** |
97 | * No comparison needs to be applied; the result is always @c true if |
98 | * the implementation successfully executes the test case. |
99 | */ |
100 | Ignore, |
101 | |
102 | /** |
103 | * A human is required to make the call about correctness of the result |
104 | * according to the description in the test case. |
105 | */ |
106 | Inspect, |
107 | |
108 | /** |
109 | * The expected result of the test case is an error, identified as an |
110 | * eight-character error code (e.g., XPST0003). The result of a test is |
111 | * @c true, if the implementation raises an error. However, raising an error |
112 | * because an implementation does not support the feature is not |
113 | * considered a correct result. |
114 | */ |
115 | ExpectedError, |
116 | |
117 | /** |
118 | * A special comparison for the schema validation tests. The details |
119 | * can only be 'true' or 'false' depending on whether it is a valid |
120 | * schema or not. |
121 | */ |
122 | SchemaIsValid |
123 | }; |
124 | |
125 | /** |
126 | * Takes a string identifying a comparator either in the XSL-T or the |
127 | * XQuery test suite, and returns an enum value for it. |
128 | * |
129 | * If the value is unknown, the code asserts. |
130 | */ |
131 | static Type identifierFromString(const QString &string); |
132 | |
133 | /** |
134 | * @returns a display name for @p id. For example, if Inspect was passed, "Inspect" |
135 | * would be returned. |
136 | */ |
137 | static QString displayName(const Type id); |
138 | |
139 | /** |
140 | * Compares @p items(typically the result of an evaluation) against |
141 | * the base lines @p lines. |
142 | * |
143 | * @returns the status of the first base line which passes, |
144 | * otherwise TestResult::Fail. |
145 | */ |
146 | static TestResult::Status scan(const QString &serialized, |
147 | const TestBaseLine::List &lines); |
148 | |
149 | static TestResult::Status scanErrors(const ErrorHandler::Message::List &errors, |
150 | const TestBaseLine::List &lines); |
151 | |
152 | /** |
153 | * Constructs a TestBaseLine of type @p type. |
154 | */ |
155 | TestBaseLine(const Type type); |
156 | |
157 | /** |
158 | * What @p details contains depends on the type(). If the type() is ExpectedError, |
159 | * @p details contains the relevant error code. If the type() is one which compares |
160 | * result against a base line, it is a filename locating the baseline. |
161 | */ |
162 | void setDetails(const QString &details); |
163 | |
164 | Type type() const; |
165 | |
166 | QString details() const; |
167 | |
168 | void toXML(XMLWriter &receiver) const; |
169 | |
170 | protected: |
171 | TestResult::Status verify(const QString &serializedInput) const; |
172 | |
173 | private: |
174 | static bool isDeepEqual(const QDomNode &n1, const QDomNode &n2); |
175 | |
176 | /** |
177 | * @returns @c true if the nodes in @p cl1 are equal to @p cl2, by calling isDeepEqual() |
178 | * for each pair. |
179 | */ |
180 | static bool isChildrenDeepEqual(const QDomNodeList &cl1, const QDomNodeList &cl2); |
181 | |
182 | /** |
183 | * Considers @p cl1 and @p cl2 to be lists containing attributes. The list are equal |
184 | * if they contain attributes by same value and name, but regardless of order. |
185 | */ |
186 | static bool isAttributesEqual(const QDomNamedNodeMap &cl1, const QDomNamedNodeMap &cl2); |
187 | const Type m_type; |
188 | QString m_details; |
189 | }; |
190 | } |
191 | |
192 | QT_END_NAMESPACE |
193 | |
194 | #endif |
195 | // vim: et:ts=4:sw=4:sts=4 |
196 | |