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;
44
my $report = $class->SUPER::new({
45
environment => XMLREPORT_ENVIRONMENT,
46
date => XMLREPORT_DATE,
47
buildinfo => XMLREPORT_BUILDINFO,
48
tests => XMLREPORT_TESTS,
49
name => XMLREPORT_NAME
52
$report->[XMLREPORT_DATE] = isoTimestamp() if not defined $report->[XMLREPORT_DATE];
53
$report->[XMLREPORT_ENVIRONMENT] = GenTest::XML::Environment->new() if not defined $report->[XMLREPORT_ENVIRONMENT];
65
my $writer = XML::Writer->new(
66
OUTPUT => \$report_xml,
67
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
68
DATA_INDENT => 2, # number of spaces used for indentation
69
UNSAFE => 1 # required for use of 'raw()'
72
$writer->xmlDecl('ISO-8859-1');
73
$writer->startTag('report',
74
'xmlns' => "http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia",
75
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
76
'xsi:schemaLocation' => "http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia/testresult-schema-1-2.xsd",
80
$writer->dataElement('date', $report->[XMLREPORT_DATE]);
81
if (osLinux() || osSolaris())
83
$writer->dataElement('operator', $ENV{'LOGNAME'});
87
$writer->dataElement('operator', $ENV{'USERNAME'});
90
$writer->raw($report->[XMLREPORT_ENVIRONMENT]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
91
$writer->raw($report->[XMLREPORT_BUILDINFO]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
93
$writer->startTag('testsuites');
94
$writer->startTag('testsuite', id => 0);
95
$writer->dataElement('name', $report->[XMLREPORT_NAME]);
96
$writer->dataElement('environment_id', 0);
97
$writer->dataElement('starttime', $report->[XMLREPORT_DATE]);
98
$writer->dataElement('endtime', isoTimestamp());
99
$writer->dataElement('description', 'http://forge.mysql.com/wiki/RQG');
100
# TODO (if applicable):
101
# test-suite specific descriptions (once we have defined testsuites)?
102
#<xsd:element name="logdir" type="xsd:string" minOccurs="0" form="qualified"/>
103
#<xsd:element name="attributes" type="cassiopeia:Attributes" minOccurs="0" form="qualified"/> # pairs of (name, value)
104
$writer->startTag('tests');
106
foreach my $test (@{$report->[XMLREPORT_TESTS]}) {
107
$writer->raw($test->xml());
110
$writer->endTag('tests');
111
$writer->endTag('testsuite');
112
$writer->endTag('testsuites');
113
$writer->endTag('report');
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;
44
my $report = $class->SUPER::new({
45
environment => XMLREPORT_ENVIRONMENT,
46
date => XMLREPORT_DATE,
47
buildinfo => XMLREPORT_BUILDINFO,
48
tests => XMLREPORT_TESTS,
49
name => XMLREPORT_NAME
52
$report->[XMLREPORT_DATE] = isoTimestamp() if not defined $report->[XMLREPORT_DATE];
53
$report->[XMLREPORT_ENVIRONMENT] = GenTest::XML::Environment->new() if not defined $report->[XMLREPORT_ENVIRONMENT];
65
my $writer = XML::Writer->new(
66
OUTPUT => \$report_xml,
67
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
68
DATA_INDENT => 2, # number of spaces used for indentation
69
UNSAFE => 1 # required for use of 'raw()'
72
$writer->xmlDecl('ISO-8859-1');
73
$writer->startTag('report',
74
'xmlns' => "http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia",
75
'xmlns:xsi' => "http://www.w3.org/2001/XMLSchema-instance",
76
'xsi:schemaLocation' => "http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia http://clustra.norway.sun.com/intraweb/organization/qa/cassiopeia/testresult-schema-1-2.xsd",
80
$writer->dataElement('date', $report->[XMLREPORT_DATE]);
81
if (osLinux() || osSolaris())
83
$writer->dataElement('operator', $ENV{'LOGNAME'});
87
$writer->dataElement('operator', $ENV{'USERNAME'});
90
$writer->raw($report->[XMLREPORT_ENVIRONMENT]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
91
$writer->raw($report->[XMLREPORT_BUILDINFO]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
93
$writer->startTag('testsuites');
94
$writer->startTag('testsuite', id => 0);
95
$writer->dataElement('name', $report->[XMLREPORT_NAME]);
96
$writer->dataElement('environment_id', 0);
97
$writer->dataElement('starttime', $report->[XMLREPORT_DATE]);
98
$writer->dataElement('endtime', isoTimestamp());
99
$writer->dataElement('description', 'http://forge.mysql.com/wiki/RQG');
100
# TODO (if applicable):
101
# test-suite specific descriptions (once we have defined testsuites)?
102
#<xsd:element name="logdir" type="xsd:string" minOccurs="0" form="qualified"/>
103
#<xsd:element name="attributes" type="cassiopeia:Attributes" minOccurs="0" form="qualified"/> # pairs of (name, value)
104
$writer->startTag('tests');
106
foreach my $test (@{$report->[XMLREPORT_TESTS]}) {
107
$writer->raw($test->xml());
110
$writer->endTag('tests');
111
$writer->endTag('testsuite');
112
$writer->endTag('testsuites');
113
$writer->endTag('report');