source: trunk/src/testlib/qxmltestlogger.cpp@ 117

Last change on this file since 117 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtTest module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include <stdio.h>
43#include <string.h>
44#include <QtCore/qglobal.h>
45
46#include "QtTest/private/qxmltestlogger_p.h"
47#include "QtTest/private/qtestresult_p.h"
48#include "QtTest/private/qbenchmark_p.h"
49
50QT_BEGIN_NAMESPACE
51
52namespace QTest {
53
54 static const char* xmlMessageType2String(QAbstractTestLogger::MessageTypes type)
55 {
56 switch (type) {
57 case QAbstractTestLogger::Warn:
58 return "warn";
59 case QAbstractTestLogger::QSystem:
60 return "system";
61 case QAbstractTestLogger::QDebug:
62 return "qdebug";
63 case QAbstractTestLogger::QWarning:
64 return "qwarn";
65 case QAbstractTestLogger::QFatal:
66 return "qfatal";
67 case QAbstractTestLogger::Skip:
68 return "skip";
69 case QAbstractTestLogger::Info:
70 return "info";
71 }
72 return "??????";
73 }
74
75 static const char* xmlIncidentType2String(QAbstractTestLogger::IncidentTypes type)
76 {
77 switch (type) {
78 case QAbstractTestLogger::Pass:
79 return "pass";
80 case QAbstractTestLogger::XFail:
81 return "xfail";
82 case QAbstractTestLogger::Fail:
83 return "fail";
84 case QAbstractTestLogger::XPass:
85 return "xpass";
86 }
87 return "??????";
88 }
89
90}
91
92
93QXmlTestLogger::QXmlTestLogger(XmlMode mode ):
94 xmlmode(mode)
95{
96
97}
98
99QXmlTestLogger::~QXmlTestLogger()
100{
101
102}
103
104
105void QXmlTestLogger::startLogging()
106{
107 QAbstractTestLogger::startLogging();
108 char buf[1024];
109
110 if (xmlmode == QXmlTestLogger::Complete) {
111 QTest::qt_snprintf(buf, sizeof(buf),
112 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
113 "<TestCase name=\"%s\">\n", QTestResult::currentTestObjectName());
114 outputString(buf);
115 }
116
117 QTest::qt_snprintf(buf, sizeof(buf),
118 "<Environment>\n"
119 " <QtVersion>%s</QtVersion>\n"
120 " <QTestVersion>"QTEST_VERSION_STR"</QTestVersion>\n"
121 "</Environment>\n", qVersion());
122 outputString(buf);
123}
124
125void QXmlTestLogger::stopLogging()
126{
127 if (xmlmode == QXmlTestLogger::Complete) {
128 outputString("</TestCase>\n");
129 }
130
131 QAbstractTestLogger::stopLogging();
132}
133
134void QXmlTestLogger::enterTestFunction(const char *function)
135{
136 char buf[1024];
137 QTest::qt_snprintf(buf, sizeof(buf), "<TestFunction name=\"%s\">\n", function);
138 outputString(buf);
139}
140
141void QXmlTestLogger::leaveTestFunction()
142{
143 outputString("</TestFunction>\n");
144}
145
146namespace QTest
147{
148
149inline static bool isEmpty(const char *str)
150{
151 return !str || !str[0];
152}
153
154static const char *incidentFormatString(bool noDescription, bool noTag)
155{
156 if (noDescription) {
157 if (noTag)
158 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\" />\n";
159 else
160 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
161 " <DataTag><![CDATA[%s%s%s%s]]></DataTag>\n"
162 "</Incident>\n";
163 } else {
164 if (noTag)
165 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"
166 " <Description><![CDATA[%s%s%s%s]]></Description>\n"
167 "</Incident>\n";
168 else
169 return "<Incident type=\"%s\" file=\"%s\" line=\"%d\">\n"