~zisis00/drizzle/ldap_policy

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Incident.pm

  • Committer: Zisis Sialveras
  • Date: 2012-08-09 18:18:22 UTC
  • mfrom: (2553.1.25 workspace)
  • Revision ID: zisis00@gmail.com-20120809181822-9wobhdfdx411tu5w
Some changes in ldap_policy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008-2009 Sun Microsystems, Inc. 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::Incident;
19
 
 
20
 
require Exporter;
21
 
@ISA = qw(GenTest);
22
 
 
23
 
use strict;
24
 
use GenTest;
25
 
 
26
 
#
27
 
# Those names are taken from an XML specification for a 
28
 
# test result XML report (see XML/Report.pm). Not all of them will be used.
29
 
# See commented tags / statements for omitted stuff.
30
 
#
31
 
 
32
 
use constant INCIDENT_ID            => 0;
33
 
use constant INCIDENT_TIMESTAMP     => 1;
34
 
use constant INCIDENT_RESULT        => 2;
35
 
use constant INCIDENT_DESCRIPTION   => 3;   
36
 
use constant INCIDENT_SIGNATURE     => 4;
37
 
use constant INCIDENT_COREFILE      => 5;
38
 
use constant INCIDENT_ANALYSIS      => 6;
39
 
use constant INCIDENT_CLASS         => 7;
40
 
use constant INCIDENT_BUG_ID        => 8;
41
 
use constant INCIDENT_DEBUGS        => 9;
42
 
 
43
 
use constant INCIDENT_DEBUG_TYPE    => 0;
44
 
use constant INCIDENT_DEBUG_TEXT    => 1;
45
 
 
46
 
my $id = 0;
47
 
 
48
 
1;
49
 
 
50
 
sub new {
51
 
    my $class = shift;
52
 
 
53
 
    my $incident = $class->SUPER::new({
54
 
        id          => INCIDENT_ID,
55
 
        timestamp   => INCIDENT_TIMESTAMP,
56
 
        result      => INCIDENT_RESULT,
57
 
        description => INCIDENT_DESCRIPTION,
58
 
        signature   => INCIDENT_SIGNATURE,
59
 
        corefile    => INCIDENT_COREFILE,
60
 
        analysis    => INCIDENT_ANALYSIS,
61
 
        class       => INCIDENT_CLASS,
62
 
        bug_id      => INCIDENT_BUG_ID,
63
 
        debugs      => INCIDENT_DEBUGS
64
 
    }, @_);
65
 
 
66
 
    $incident->[INCIDENT_TIMESTAMP] = isoTimestamp() if not defined $incident->[INCIDENT_TIMESTAMP];
67
 
    $incident->[INCIDENT_ID] = $id++ if not defined $incident->[INCIDENT_ID];
68
 
 
69
 
    return $incident;
70
 
}
71
 
 
72
 
sub xml {
73
 
    require XML::Writer;
74
 
 
75
 
    my $incident = shift;
76
 
    my $incident_xml;
77
 
 
78
 
    my $writer = XML::Writer->new(
79
 
        OUTPUT      => \$incident_xml,
80
 
        DATA_MODE   => 1,   # this and DATA_INDENT to have line breaks and indentation after each element
81
 
        DATA_INDENT => 2,   # number of spaces used for indentation
82
 
        UNSAFE      => 1
83
 
    );
84
 
 
85
 
    $writer->startTag('incident', 'id' => $incident->[INCIDENT_ID]);
86
 
 
87
 
    # this is a sequence in the XML schema, so the order of elements is significant.
88
 
    $writer->dataElement('timestamp', $incident->[INCIDENT_TIMESTAMP]) if defined $incident->[INCIDENT_TIMESTAMP];
89
 
    $writer->dataElement('result', $incident->[INCIDENT_RESULT]) if defined $incident->[INCIDENT_RESULT];
90
 
    $writer->dataElement('description', $incident->[INCIDENT_DESCRIPTION]) if defined $incident->[INCIDENT_DESCRIPTION];
91
 
    $writer->cdataElement('signature', $incident->[INCIDENT_SIGNATURE]) if defined $incident->[INCIDENT_SIGNATURE];
92
 
    $writer->dataElement('corefile', $incident->[INCIDENT_COREFILE]) if defined $incident->[INCIDENT_COREFILE];
93
 
    $writer->dataElement('analysis', $incident->[INCIDENT_ANALYSIS]) if defined $incident->[INCIDENT_ANALYSIS];
94
 
    $writer->dataElement('class', $incident->[INCIDENT_CLASS]) if defined $incident->[INCIDENT_CLASS];
95
 
    $writer->dataElement('bug_id', $incident->[INCIDENT_BUG_ID]) if defined $incident->[INCIDENT_BUG_ID];
96
 
 
97
 
    if (defined $incident->[INCIDENT_DEBUGS]) {
98
 
        foreach my $debug (@{$incident->[INCIDENT_DEBUGS]}) {
99
 
            $writer->startTag('debug');
100
 
            $writer->dataElement('type', $debug->[INCIDENT_DEBUG_TYPE]);
101
 
            $writer->cdataElement('text', $debug->[INCIDENT_DEBUG_TEXT]);
102
 
            $writer->endTag('debug');
103
 
        }
104
 
    }
105
 
    
106
 
    #$writer->dataElement('host', $incident->[INCIDENT_HOST]) if defined $incident->[INCIDENT_HOST]; # hostname
107
 
    #$writer->dataElement('build_id', $incident->[INCIDENT_BUILD_ID]) if defined $incident->[INCIDENT_BUILD_ID]; # int
108
 
    #$writer->dataElement('binary', $incident->[INCIDENT_BINARY]) if defined $incident->[INCIDENT_BINARY]; # string
109
 
    #$writer->dataElement('role', $incident->[INCIDENT_ROLE]) if defined $incident->[INCIDENT_ROLE]; # string
110
 
 
111
 
    $writer->endTag('incident');
112
 
 
113
 
    $writer->end();
114
 
 
115
 
    return $incident_xml;
116
 
}
117
 
 
118
 
sub setId {
119
 
    $_[0]->[INCIDENT_ID] = $_[1];
120
 
}
121
 
 
122
 
1;