010b5545aa14c052e1f8c1582ee115a02b4223f5
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternssdk / TestResult.cpp
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 #include <QXmlAttributes>
43 #include <QtDebug>
44
45 #include <private/qdebug_p.h>
46 #include "Global.h"
47 #include "XMLWriter.h"
48
49 #include "TestResult.h"
50
51 using namespace QPatternistSDK;
52 using namespace QPatternist;
53
54 QString TestResult::displayName(const TestResult::Status stat)
55 {
56     switch(stat)
57     {
58         case Pass:
59             return QLatin1String("pass");
60         case Fail:
61             return QLatin1String("fail");
62         case NotTested:
63             return QLatin1String("not tested");
64         case Unknown:
65             Q_ASSERT(false);
66     }
67
68     Q_ASSERT(false);
69     return QString();
70 }
71
72 TestResult::Status TestResult::statusFromString(const QString &string)
73 {
74     if(string == QLatin1String("pass"))
75         return Pass;
76     else if(string == QLatin1String("fail"))
77         return Fail;
78     else if(string == QLatin1String("not tested"))
79         return NotTested;
80     else
81     {
82         Q_ASSERT(false);
83         return Fail;
84     }
85 }
86
87 TestResult::TestResult(const QString &n,
88                        const Status s,
89                        ASTItem *tree,
90                        const ErrorHandler::Message::List &ers,
91                        const QPatternist::Item::List &itemsP,
92                        const QString &serialized) : m_status(s),
93                                                     m_messages(ers),
94                                                     m_astTree(tree),
95                                                     m_testName(n),
96                                                     m_items(itemsP),
97                                                     m_asSerialized(serialized)
98 {
99     Q_ASSERT(!n.isEmpty());
100     Q_ASSERT(s != 0);
101 }
102
103 TestResult::~TestResult()
104 {
105     delete m_astTree;
106 }
107
108 void TestResult::toXML(XMLWriter &receiver) const
109 {
110     QXmlAttributes atts;
111     atts.append(QLatin1String("name"), QString(), QLatin1String("name"), m_testName);
112     atts.append(QLatin1String("result"), QString(), QLatin1String("result"), displayName(m_status));
113
114     if(!m_comment.isEmpty())
115         atts.append(QLatin1String("comment"), QString(), QLatin1String("comment"), m_comment);
116
117     receiver.startElement(QLatin1String("test-case"), atts);
118     receiver.endElement(QLatin1String("test-case"));
119 }
120
121 void TestResult::setComment(const QString &comm)
122 {
123     m_comment = comm;
124 }
125
126 TestResult::Status TestResult::status() const
127 {
128     return m_status;
129 }
130
131 QString TestResult::comment() const
132 {
133     return m_comment;
134 }
135
136 ASTItem *TestResult::astTree() const
137 {
138     return m_astTree;
139 }
140
141 ErrorHandler::Message::List TestResult::messages() const
142 {
143     return m_messages;
144 }
145
146 QPatternist::Item::List TestResult::items() const
147 {
148     return m_items;
149 }
150
151 QString TestResult::asSerialized() const
152 {
153     pDebug() << "asSerialized: " << m_asSerialized;
154     return m_asSerialized;
155 }
156
157 // vim: et:ts=4:sw=4:sts=4
158