1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include <QXmlAttributes>
43 #include <QtDebug>
44 
45 #include "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 
displayName(const TestResult::Status stat)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 
statusFromString(const QString & string)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 
TestResult(const QString & n,const Status s,ASTItem * tree,const ErrorHandler::Message::List & ers,const QPatternist::Item::List & itemsP,const QString & serialized)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 
~TestResult()103 TestResult::~TestResult()
104 {
105     delete m_astTree;
106 }
107 
toXML(XMLWriter & receiver) const108 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 
setComment(const QString & comm)121 void TestResult::setComment(const QString &comm)
122 {
123     m_comment = comm;
124 }
125 
status() const126 TestResult::Status TestResult::status() const
127 {
128     return m_status;
129 }
130 
comment() const131 QString TestResult::comment() const
132 {
133     return m_comment;
134 }
135 
astTree() const136 ASTItem *TestResult::astTree() const
137 {
138     return m_astTree;
139 }
140 
messages() const141 ErrorHandler::Message::List TestResult::messages() const
142 {
143     return m_messages;
144 }
145 
items() const146 QPatternist::Item::List TestResult::items() const
147 {
148     return m_items;
149 }
150 
asSerialized() const151 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 
159