1
# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::XML::Report;
25
use GenTest::XML::BuildInfo;
26
use GenTest::XML::Environment;
29
# Those names are taken from Vemundo's specification for a
30
# test result XML report. Not all of them will be used
33
use constant XMLREPORT_DATE => 0;
34
use constant XMLREPORT_BUILDINFO => 1;
35
use constant XMLREPORT_TESTS => 2;
36
use constant XMLREPORT_ENVIRONMENT => 3;
37
use constant XMLREPORT_NAME => 4;
43
my $report = $class->SUPER::new({
44
environment => XMLREPORT_ENVIRONMENT,
45
date => XMLREPORT_DATE,
46
buildinfo => XMLREPORT_BUILDINFO,
47
tests => XMLREPORT_TESTS,
48
name => XMLREPORT_NAME
51
$report->[XMLREPORT_DATE] = isoUTCTimestamp() if not defined $report->[XMLREPORT_DATE];
52
$report->[XMLREPORT_ENVIRONMENT] = GenTest::XML::Environment->new() if not defined $report->[XMLREPORT_ENVIRONMENT];
64
my $writer = XML::Writer->new(
65
OUTPUT => \$report_xml,
66
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
67
DATA_INDENT => 2, # number of spaces used for indentation
68
UNSAFE => 1 # required for use of 'raw()'
71
$writer->xmlDecl('ISO-8859-1');
72
$writer->startTag('report',
73
'xmlns' => "http://regin.no.oracle.com/report/schema",
74
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
75
'xsi:schemaLocation' => "http://regin.no.oracle.com/report/schema/testresult-schema-1-2.xsd",
79
$writer->dataElement('date', $report->[XMLREPORT_DATE]);
80
if (osLinux() || osSolaris()) {
81
$writer->dataElement('operator', $ENV{'LOGNAME'});
83
$writer->dataElement('operator', $ENV{'USERNAME'});
86
$writer->raw($report->[XMLREPORT_ENVIRONMENT]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
87
$writer->raw($report->[XMLREPORT_BUILDINFO]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
89
$writer->startTag('testsuites');
90
$writer->startTag('testsuite', id => 0);
91
$writer->dataElement('name', $report->[XMLREPORT_NAME]);
92
$writer->dataElement('environment_id', 0);
93
$writer->dataElement('starttime', $report->[XMLREPORT_DATE]);
94
$writer->dataElement('endtime', isoUTCTimestamp());
95
$writer->dataElement('description', 'http://forge.mysql.com/wiki/RQG');
96
# TODO (if applicable):
97
# test-suite specific descriptions (once we have defined testsuites)?
98
#<xsd:element name="logdir" type="xsd:string" minOccurs="0" form="qualified"/>
99
#<xsd:element name="attributes" type="cassiopeia:Attributes" minOccurs="0" form="qualified"/> # pairs of (name, value)
100
$writer->startTag('tests');
102
foreach my $test (@{$report->[XMLREPORT_TESTS]}) {
103
$writer->raw($test->xml());
106
$writer->endTag('tests');
107
$writer->endTag('testsuite');
108
$writer->endTag('testsuites');
109
$writer->endTag('report');