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

source code of qtxmlpatterns/tests/auto/xmlpatternssdk/TestResult.cpp