| 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 <QXmlContentHandler> |
| 30 | |
| 31 | #include "Global.h" |
| 32 | #include "XMLWriter.h" |
| 33 | |
| 34 | #include "TestSuiteResult.h" |
| 35 | |
| 36 | using namespace QPatternistSDK; |
| 37 | |
| 38 | TestSuiteResult::TestSuiteResult(const QString &testSuiteVersion, |
| 39 | const QDate &runDate, |
| 40 | const TestResult::List &results) : m_testSuiteVersion(testSuiteVersion), |
| 41 | m_runDate(runDate), |
| 42 | m_results(results) |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | TestSuiteResult::~TestSuiteResult() |
| 47 | { |
| 48 | qDeleteAll(c: m_results); |
| 49 | } |
| 50 | |
| 51 | void TestSuiteResult::toXML(XMLWriter &receiver) const |
| 52 | { |
| 53 | /* If this data needs to be configurable in someway(say, another |
| 54 | * XML format is supported), then break out the info into getters(alternatively, combined |
| 55 | * with setters, or that the class is subclassed), and access the getters instead. |
| 56 | */ |
| 57 | const QString organizationName (QLatin1String("K Desktop Environment(KDE)" )); |
| 58 | const QString organizationWebsite (QLatin1String("http://www.kde.org/" )); |
| 59 | const QString submittorName (QLatin1String("Frans Englich" )); |
| 60 | const QString submittorEmail (QLatin1String("frans.englich@nokia.com" )); |
| 61 | const QString implementationVersion (QLatin1String("0.1" )); |
| 62 | const QString implementationName (QLatin1String("Patternist" )); |
| 63 | const QString implementationDescription (QLatin1String( |
| 64 | "Patternist is an implementation written in C++ " |
| 65 | "and with the Qt/KDE libraries. " |
| 66 | "It is licensed under GNU LGPL and part of KDE, " |
| 67 | "the K Desktop Environment." )); |
| 68 | |
| 69 | /* Not currently serialized: |
| 70 | * - <implementation-defined-items> |
| 71 | * - <features> |
| 72 | * - <context-properties> |
| 73 | */ |
| 74 | |
| 75 | receiver.startDocument(); |
| 76 | /* <test-suite-result> */ |
| 77 | receiver.startPrefixMapping(prefix: QString(), namespaceURI: Global::xqtsResultNS); |
| 78 | receiver.startElement(qName: QLatin1String("test-suite-result" )); |
| 79 | |
| 80 | /* <implementation> */ |
| 81 | QXmlStreamAttributes implementationAtts; |
| 82 | implementationAtts.append(qualifiedName: QLatin1String("name" ), value: implementationName); |
| 83 | implementationAtts.append(qualifiedName: QLatin1String("version" ), value: implementationVersion); |
| 84 | receiver.startElement(qName: QLatin1String("implementation" ), atts: implementationAtts); |
| 85 | |
| 86 | /* <organization> */ |
| 87 | QXmlStreamAttributes organizationAtts; |
| 88 | organizationAtts.append(qualifiedName: QLatin1String("name" ), value: organizationName); |
| 89 | organizationAtts.append(qualifiedName: QLatin1String("website" ), value: organizationWebsite); |
| 90 | receiver.startElement(qName: QLatin1String("organization" ), atts: organizationAtts); |
| 91 | |
| 92 | /* </organization> */ |
| 93 | receiver.endElement(qName: QLatin1String("organization" )); |
| 94 | |
| 95 | /* <submittor> */ |
| 96 | QXmlStreamAttributes submittorAtts; |
| 97 | submittorAtts.append(qualifiedName: QLatin1String("name" ), value: submittorName); |
| 98 | submittorAtts.append(qualifiedName: QLatin1String("email" ), value: submittorEmail); |
| 99 | receiver.startElement(qName: QLatin1String("submittor" ), atts: submittorAtts); |
| 100 | |
| 101 | /* </submittor> */ |
| 102 | receiver.endElement(qName: QLatin1String("submittor" )); |
| 103 | |
| 104 | /* <description> */ |
| 105 | receiver.startElement(qName: QLatin1String("description" )); |
| 106 | |
| 107 | /* <p> */ |
| 108 | receiver.startElement(qName: QLatin1String("p" )); |
| 109 | receiver.characters(ch: implementationDescription); |
| 110 | |
| 111 | /* </p> */ |
| 112 | receiver.endElement(qName: QLatin1String("p" )); |
| 113 | /* </description> */ |
| 114 | receiver.endElement(qName: QLatin1String("description" )); |
| 115 | |
| 116 | /* </implementation> */ |
| 117 | receiver.endElement(qName: QLatin1String("implementation" )); |
| 118 | |
| 119 | /* <syntax> */ |
| 120 | receiver.startElement(qName: QLatin1String("syntax" )); |
| 121 | receiver.characters(ch: QLatin1String(QLatin1String("XQuery" ))); |
| 122 | |
| 123 | /* </syntax> */ |
| 124 | receiver.endElement(qName: QLatin1String("syntax" )); |
| 125 | |
| 126 | /* <test-run> */ |
| 127 | QXmlStreamAttributes test_runAtts; |
| 128 | test_runAtts.append(qualifiedName: QLatin1String("dateRun" ), value: m_runDate.toString(format: Qt::ISODate)); |
| 129 | receiver.startElement(qName: QLatin1String("test-run" ), atts: test_runAtts); |
| 130 | |
| 131 | /* <test-suite> */ |
| 132 | QXmlStreamAttributes test_suiteAtts; |
| 133 | test_suiteAtts.append(qualifiedName: QLatin1String("version" ), value: m_testSuiteVersion); |
| 134 | receiver.startElement(qName: QLatin1String("test-suite" ), atts: test_suiteAtts); |
| 135 | |
| 136 | /* </test-suite> */ |
| 137 | receiver.endElement(qName: QLatin1String("test-suite" )); |
| 138 | |
| 139 | /* </test-run> */ |
| 140 | receiver.endElement(qName: QLatin1String("test-run" )); |
| 141 | |
| 142 | /* Serialize the TestResults: tons of test-case elements. */ |
| 143 | const TestResult::List::const_iterator end(m_results.constEnd()); |
| 144 | TestResult::List::const_iterator it(m_results.constBegin()); |
| 145 | |
| 146 | for(; it != end; ++it) |
| 147 | (*it)->toXML(receiver); |
| 148 | |
| 149 | /* </test-suite-result> */ |
| 150 | receiver.endElement(qName: QLatin1String("test-suite-result" )); |
| 151 | receiver.endDocument(); |
| 152 | } |
| 153 | |
| 154 | // vim: et:ts=4:sw=4:sts=4 |
| 155 | |
| 156 | |