~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to tests/test_tools/randgen/lib/GenTest/XML/Report.pm

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-10-29 15:43:40 UTC
  • mfrom: (1.2.12) (2.1.19 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20131029154340-2gp39el6cv8bwf2o
Tags: 1:7.2.3-2ubuntu1
* Merge from debian, remaining changes:
  - Link against boost_system because of boost_thread.
  - Add required libs to message/include.am
  - Add upstart job and adjust init script to be upstart compatible.
  - Disable -floop-parallelize-all due to gcc-4.8/4.9 compiler ICE
    http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57732

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2008, 2010 Oracle and/or its affiliates. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
# USA
 
17
 
 
18
package GenTest::XML::Report;
 
19
 
 
20
require Exporter;
 
21
@ISA = qw(GenTest);
 
22
 
 
23
use strict;
 
24
use GenTest;
 
25
use GenTest::XML::BuildInfo;
 
26
use GenTest::XML::Environment;
 
27
 
 
28
#
 
29
# Those names are taken from Vemundo's specification for a 
 
30
# test result XML report. Not all of them will be used
 
31
#
 
32
 
 
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;
 
38
1;
 
39
 
 
40
sub new {
 
41
        my $class = shift;
 
42
 
 
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
 
49
        }, @_);
 
50
 
 
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];
 
53
 
 
54
        return $report;
 
55
}
 
56
 
 
57
sub xml {
 
58
    my $report = shift;
 
59
 
 
60
    require XML::Writer;
 
61
 
 
62
    my $report_xml;
 
63
 
 
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()'
 
69
    );
 
70
 
 
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",
 
76
        'version'               => "1.2"
 
77
    );
 
78
 
 
79
    $writer->dataElement('date', $report->[XMLREPORT_DATE]);
 
80
    if (osLinux() || osSolaris()) {
 
81
        $writer->dataElement('operator', $ENV{'LOGNAME'});
 
82
    } else {
 
83
        $writer->dataElement('operator', $ENV{'USERNAME'});
 
84
    }
 
85
 
 
86
    $writer->raw($report->[XMLREPORT_ENVIRONMENT]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
 
87
    $writer->raw($report->[XMLREPORT_BUILDINFO]->xml()) if defined $report->[XMLREPORT_BUILDINFO];
 
88
 
 
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');
 
101
 
 
102
    foreach my $test (@{$report->[XMLREPORT_TESTS]}) {
 
103
        $writer->raw($test->xml());
 
104
    }
 
105
 
 
106
    $writer->endTag('tests');
 
107
    $writer->endTag('testsuite');
 
108
    $writer->endTag('testsuites');
 
109
    $writer->endTag('report');
 
110
 
 
111
    $writer->end();
 
112
 
 
113
    return $report_xml;
 
114
}
 
115
 
 
116
1;