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::Test;
27
# Those names are taken from Vemundo's specification for a
28
# test result XML report. Not all of them will be used
31
use constant TEST_ID => 0;
32
use constant TEST_NAME => 1;
33
use constant TEST_ENVIRONMENT_ID => 2;
34
use constant TEST_STARTTIME => 3;
35
use constant TEST_ENDTIME => 4;
36
use constant TEST_LOGDIR => 5;
37
use constant TEST_RESULT => 6;
38
use constant TEST_DESCRIPTION => 7;
39
use constant TEST_ATTRIBUTES => 8;
40
use constant TEST_INCIDENTS => 9;
47
my $test = $class->SUPER::new({
50
environment_id => TEST_ENVIRONMENT_ID,
51
starttime => TEST_STARTTIME,
52
endtime => TEST_ENDTIME,
53
logdir => TEST_LOGDIR,
54
result => TEST_RESULT,
55
description => TEST_DESCRIPTION,
56
attributes => TEST_ATTRIBUTES,
57
incidents => TEST_INCIDENTS
60
$test->[TEST_STARTTIME] = isoTimestamp() if not defined $test->[TEST_STARTTIME];
61
$test->[TEST_ENVIRONMENT_ID] = 0 if not defined $test->[TEST_ENVIRONMENT_ID];
67
my ($test, $result) = @_;
68
$test->[TEST_ENDTIME] = isoTimestamp();
69
$test->[TEST_RESULT] = $result;
77
$test->end() if not defined $test->[TEST_ENDTIME];
80
my $writer = XML::Writer->new(
82
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
83
DATA_INDENT => 2, # number of spaces used for indentation
84
UNSAFE => 1 # required for raw(), used when including incidents
87
$writer->startTag('test', id => $test->[TEST_ID]);
89
$writer->dataElement('name', $test->[TEST_NAME] ? $test->[TEST_NAME] : "NO_NAME");
90
$writer->dataElement('environment_id', $test->[TEST_ENVIRONMENT_ID]);
91
$writer->dataElement('starttime', $test->[TEST_STARTTIME]);
92
$writer->dataElement('endtime', $test->[TEST_ENDTIME]);
93
$writer->dataElement('logdir', $test->[TEST_LOGDIR]);
94
$writer->dataElement('result', $test->[TEST_RESULT]);
95
$writer->dataElement('description', $test->[TEST_DESCRIPTION]);
97
if (defined $test->[TEST_ATTRIBUTES]) {
98
$writer->startTag('attributes');
99
while (my ($name, $value) = each %{$test->[TEST_ATTRIBUTES]}) {
100
$writer->startTag('attribute');
101
$writer->dataElement('name', $name);
102
$writer->dataElement('value', $value);
103
$writer->endTag('attribute');
105
$writer->endTag('attributes');
108
if (defined $test->[TEST_INCIDENTS]) {
109
$writer->startTag('incidents');
110
foreach my $incident (@{$test->[TEST_INCIDENTS]}) {
111
$writer->raw($incident->xml());
113
$writer->endTag('incidents');
116
# TODO: <metrics> (name, value, unit, attributes, timestamp)
118
$writer->endTag('test');
126
$_[0]->[TEST_ID] = $_[1];
130
my ($test, $incident) = @_;
131
$test->[TEST_INCIDENTS] = [] if not defined $test->[TEST_INCIDENTS];
132
push @{$test->[TEST_INCIDENTS]}, $incident;
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::Test;
27
# Those names are taken from Vemundo's specification for a
28
# test result XML report. Not all of them will be used
31
use constant TEST_ID => 0;
32
use constant TEST_NAME => 1;
33
use constant TEST_ENVIRONMENT_ID => 2;
34
use constant TEST_STARTTIME => 3;
35
use constant TEST_ENDTIME => 4;
36
use constant TEST_LOGDIR => 5;
37
use constant TEST_RESULT => 6;
38
use constant TEST_DESCRIPTION => 7;
39
use constant TEST_ATTRIBUTES => 8;
40
use constant TEST_INCIDENTS => 9;
47
my $test = $class->SUPER::new({
50
environment_id => TEST_ENVIRONMENT_ID,
51
starttime => TEST_STARTTIME,
52
endtime => TEST_ENDTIME,
53
logdir => TEST_LOGDIR,
54
result => TEST_RESULT,
55
description => TEST_DESCRIPTION,
56
attributes => TEST_ATTRIBUTES,
57
incidents => TEST_INCIDENTS
60
$test->[TEST_STARTTIME] = isoTimestamp() if not defined $test->[TEST_STARTTIME];
61
$test->[TEST_ENVIRONMENT_ID] = 0 if not defined $test->[TEST_ENVIRONMENT_ID];
67
my ($test, $result) = @_;
68
$test->[TEST_ENDTIME] = isoTimestamp();
69
$test->[TEST_RESULT] = $result;
77
$test->end() if not defined $test->[TEST_ENDTIME];
80
my $writer = XML::Writer->new(
82
DATA_MODE => 1, # this and DATA_INDENT to have line breaks and indentation after each element
83
DATA_INDENT => 2, # number of spaces used for indentation
84
UNSAFE => 1 # required for raw(), used when including incidents
87
$writer->startTag('test', id => $test->[TEST_ID]);
89
$writer->dataElement('name', $test->[TEST_NAME] ? $test->[TEST_NAME] : "NO_NAME");
90
$writer->dataElement('environment_id', $test->[TEST_ENVIRONMENT_ID]);
91
$writer->dataElement('starttime', $test->[TEST_STARTTIME]);
92
$writer->dataElement('endtime', $test->[TEST_ENDTIME]);
93
$writer->dataElement('logdir', $test->[TEST_LOGDIR]);
94
$writer->dataElement('result', $test->[TEST_RESULT]);
95
$writer->dataElement('description', $test->[TEST_DESCRIPTION]);
97
if (defined $test->[TEST_ATTRIBUTES]) {
98
$writer->startTag('attributes');
99
while (my ($name, $value) = each %{$test->[TEST_ATTRIBUTES]}) {
100
$writer->startTag('attribute');
101
$writer->dataElement('name', $name);
102
$writer->dataElement('value', $value);
103
$writer->endTag('attribute');
105
$writer->endTag('attributes');
108
if (defined $test->[TEST_INCIDENTS]) {
109
$writer->startTag('incidents');
110
foreach my $incident (@{$test->[TEST_INCIDENTS]}) {
111
$writer->raw($incident->xml());
113
$writer->endTag('incidents');
116
# TODO: <metrics> (name, value, unit, attributes, timestamp)
118
$writer->endTag('test');
126
$_[0]->[TEST_ID] = $_[1];
130
my ($test, $incident) = @_;
131
$test->[TEST_INCIDENTS] = [] if not defined $test->[TEST_INCIDENTS];
132
push @{$test->[TEST_INCIDENTS]}, $incident;