5f7b6e81ccd2ce445cbe4c6803e96764ef28acdc
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternssdk / TestResult.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef PatternistSDK_TestResult_H
43 #define PatternistSDK_TestResult_H
44
45 #include <QList>
46 #include <QObject>
47 #include <QPointer>
48 #include <QString>
49
50 #include <QtXmlPatterns/private/qitem_p.h>
51 #include "ErrorHandler.h"
52
53 #include "ASTItem.h"
54
55
56 QT_BEGIN_HEADER
57
58 QT_BEGIN_NAMESPACE
59
60 namespace QPatternistSDK
61 {
62     class ASTItem;
63     class XMLWriter;
64
65     /**
66      * @short represents the result produced by running a test case.
67      *
68      * This information TestResult houses is:
69      *
70      * - The result status() of the run. Whether the test case succeeded or not, for example.
71      * - The astTree() which reflects the compiled test case
72      * - The messages issued when compiling and running the test case, retrievable via messages()
73      * - The data -- XPath Data Model items() -- the test case evaluated to, if any.
74      *
75      * @ingroup PatternistSDK
76      * @author Frans Englich <frans.englich@nokia.com>
77      */
78     class Q_PATTERNISTSDK_EXPORT TestResult : public QObject
79     {
80         Q_OBJECT
81
82     public:
83         enum Status
84         {
85             /**
86              * Used when the status is unknown.
87              */
88             Unknown = 0,
89
90             /**
91              * The test case passed.
92              */
93             Pass,
94
95             /**
96              * The test case failed.
97              */
98             Fail,
99
100             /**
101              * The test was not run. Similar to "SKIP".
102              */
103             NotTested
104         };
105
106         /**
107          * A list of TestResult instances.
108          */
109         typedef QList<QPointer<TestResult> > List;
110
111         /**
112          * Constructs a TestResult.
113          *
114          * @param testName the name of the test. For example, @c Literal-001.
115          * @param astTree may be @c null, signalling no AST being available, or point to one.
116          * @param status the result status of running the test-case. Whether the test-case
117          * passed or failed, and so forth.
118          * @param errors the errors and warnings that were reported while running the test-case
119          * @param items the XDM items that were outputted, if any
120          * @param serialized the output when serialized
121          */
122         TestResult(const QString &testName,
123                    const Status status,
124                    ASTItem *astTree,
125                    const ErrorHandler::Message::List &errors,
126                    const QPatternist::Item::List &items,
127                    const QString &serialized);
128
129         virtual ~TestResult();
130
131         Status status() const;
132
133         QString comment() const;
134         void setComment(const QString &comment);
135
136         QPatternist::Item::List items() const;
137
138         ErrorHandler::Message::List messages() const;
139
140         /**
141          * Serializes itself to @p receiver, into a test-case element,
142          * as per @c XQTSResult.xsd.
143          */
144         void toXML(XMLWriter &receiver) const;
145
146         ASTItem *astTree() const;
147
148         /**
149          * @returns a string representation for @p status, as per the anonymous
150          * type inside the type test-case, in @c XQTSResult.xsd. For example, if @p status
151          * is NotTested, is "not tested" returned.
152          */
153         static QString displayName(const TestResult::Status status);
154
155         static Status statusFromString(const QString &string);
156
157         /**
158          * @returns the output of this test result(if any) as when
159          * being serialized.
160          */
161         QString asSerialized() const;
162
163     private:
164         const Status                        m_status;
165         QString                             m_comment;
166         const ErrorHandler::Message::List   m_messages;
167         QPointer<ASTItem>                   m_astTree;
168         QString                             m_testName;
169         const QPatternist::Item::List       m_items;
170         const QString                       m_asSerialized;
171     };
172 }
173
174 QT_END_NAMESPACE
175
176 QT_END_HEADER
177
178 #endif
179 // vim: et:ts=4:sw=4:sts=4