Update obsolete contact address.
[profile/ivi/qtxmlpatterns.git] / tests / auto / xmlpatternssdk / TestSuiteResult.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <QXmlContentHandler>
43
44 #include "Global.h"
45 #include "XMLWriter.h"
46
47 #include "TestSuiteResult.h"
48
49 using namespace QPatternistSDK;
50
51 TestSuiteResult::TestSuiteResult(const QString &testSuiteVersion,
52                                  const QDate &runDate,
53                                  const TestResult::List &results) : m_testSuiteVersion(testSuiteVersion),
54                                                                     m_runDate(runDate),
55                                                                     m_results(results)
56 {
57 }
58
59 TestSuiteResult::~TestSuiteResult()
60 {
61     qDeleteAll(m_results);
62 }
63
64 void TestSuiteResult::toXML(XMLWriter &receiver) const
65 {
66     /* If this data needs to be configurable in someway(say, another
67      * XML format is supported), then break out the info into getters(alternatively, combined
68      * with setters, or that the class is subclassed), and access the getters instead.
69      */
70     const QString organizationName          (QLatin1String("K Desktop Environment(KDE)"));
71     const QString organizationWebsite       (QLatin1String("http://www.kde.org/"));
72     const QString submittorName             (QLatin1String("Frans Englich"));
73     const QString submittorEmail            (QLatin1String("frans.englich@nokia.com"));
74     const QString implementationVersion     (QLatin1String("0.1"));
75     const QString implementationName        (QLatin1String("Patternist"));
76     const QString implementationDescription (QLatin1String(
77                                              "Patternist is an implementation written in C++ "
78                                              "and with the Qt/KDE libraries. "
79                                              "It is licensed under GNU LGPL and part of KDE, "
80                                              "the K Desktop Environment."));
81
82     /* Not currently serialized:
83      * - <implementation-defined-items>
84      * - <features>
85      * - <context-properties>
86      */
87
88     receiver.startDocument();
89     /* <test-suite-result> */
90     receiver.startPrefixMapping(QString(), Global::xqtsResultNS);
91     receiver.startElement(QLatin1String("test-suite-result"));
92     receiver.endPrefixMapping(QString());
93
94     /* <implementation> */
95     QXmlAttributes implementationAtts;
96     implementationAtts.append(QLatin1String("name"), QString(),
97                               QLatin1String("name"), implementationName);
98     implementationAtts.append(QLatin1String("version"), QString(),
99                               QLatin1String("version"), implementationVersion);
100     receiver.startElement(QLatin1String("implementation"), implementationAtts);
101
102     /* <organization> */
103     QXmlAttributes organizationAtts;
104     organizationAtts.append(QLatin1String("name"), QString(),
105                             QLatin1String("name"), organizationName);
106     organizationAtts.append(QLatin1String("website"), QString(),
107                             QLatin1String("website"), organizationWebsite);
108     receiver.startElement(QLatin1String("organization"), organizationAtts);
109
110     /* </organization> */
111     receiver.endElement(QLatin1String("organization"));
112
113     /* <submittor> */
114     QXmlAttributes submittorAtts;
115     submittorAtts.append(QLatin1String("name"), QString(), QLatin1String("name"), submittorName);
116     submittorAtts.append(QLatin1String("email"), QString(), QLatin1String("email"), submittorEmail);
117     receiver.startElement(QLatin1String("submittor"), submittorAtts);
118
119     /* </submittor> */
120     receiver.endElement(QLatin1String("submittor"));
121
122     /* <description> */
123     receiver.startElement(QLatin1String("description"));
124
125     /* <p> */
126     receiver.startElement(QLatin1String("p"));
127     receiver.characters(implementationDescription);
128
129     /* </p> */
130     receiver.endElement(QLatin1String("p"));
131     /* </description> */
132     receiver.endElement(QLatin1String("description"));
133
134     /* </implementation> */
135     receiver.endElement(QLatin1String("implementation"));
136
137     /* <syntax> */
138     receiver.startElement(QLatin1String("syntax"));
139     receiver.characters(QLatin1String(QLatin1String("XQuery")));
140
141     /* </syntax> */
142     receiver.endElement(QLatin1String("syntax"));
143
144     /* <test-run> */
145     QXmlAttributes test_runAtts;
146     test_runAtts.append(QLatin1String("dateRun"), QString(), QLatin1String("dateRun"), m_runDate.toString(QLatin1String("yyyy-MM-dd")));
147     receiver.startElement(QLatin1String("test-run"), test_runAtts);
148
149     /* <test-suite> */
150     QXmlAttributes test_suiteAtts;
151     test_suiteAtts.append(QLatin1String("version"), QString(), QLatin1String("version"), m_testSuiteVersion);
152     receiver.startElement(QLatin1String("test-suite"), test_suiteAtts);
153
154     /* </test-suite> */
155     receiver.endElement(QLatin1String("test-suite"));
156
157     /* </test-run> */
158     receiver.endElement(QLatin1String("test-run"));
159
160     /* Serialize the TestResults: tons of test-case elements. */
161     const TestResult::List::const_iterator end(m_results.constEnd());
162     TestResult::List::const_iterator it(m_results.constBegin());
163
164     for(; it != end; ++it)
165         (*it)->toXML(receiver);
166
167     /* </test-suite-result> */
168     receiver.endElement(QLatin1String("test-suite-result"));
169     receiver.endDocument();
170 }
171
172 // vim: et:ts=4:sw=4:sts=4
173