File Coverage

blib/lib/Test/Litmus.pm
Criterion Covered Total %
statement 19 88 21.5
branch 0 8 0.0
condition 0 6 0.0
subroutine 7 15 46.6
pod 0 8 0.0
total 26 125 20.8


line stmt bran cond sub pod time code
1             # The contents of this file are subject to the Mozilla Public License Version
2             # 1.1 (the "License"); you may not use this file except in compliance with
3             # the License. You may obtain a copy of the License at
4             # http://www.mozilla.org/MPL/
5             #
6             # Software distributed under the License is distributed on an "AS IS" basis,
7             # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8             # for the specific language governing rights and limitations under the
9             # License.
10             #
11             # The Original Code is Test::Litmus.
12             #
13             # The Initial Developer of the Original Code is The Mozilla Corporation.
14             #
15             # Portions created by the Initial Developer are Copyright (C) 2006
16             # the Initial Developer. All Rights Reserved.
17             #
18             # Contributor(s): Zach Lipton
19              
20             # import these into the main namespace so our users don't have to explicitly
21             # use them as well...
22 1     1   24 BEGIN {
23             package main;
24 1     1   24052 use Test::Litmus::Log;
  1         3  
  1         31  
25 1     1   584 use Test::Litmus::Result;
  1         3  
  1         19  
26             }
27              
28             package Test::Litmus;
29              
30 1     1   11 use v5.6.1;
  1         3  
  1         42  
31 1     1   5 use strict;
  1         2  
  1         33  
32              
33 1     1   1055 use HTTP::Request::Common qw(POST);
  1         31612  
  1         92  
34 1     1   1214 use LWP::UserAgent;
  1         26785  
  1         946  
35              
36             our $VERSION = '0.03';
37              
38             sub new {
39 0     0 0   my $class = shift;
40 0           my %args = @_;
41 0           my $self = {};
42 0           bless $self;
43            
44 0   0       $self->{'server'} = $args{'-server'} ||
45             'http://litmus.mozilla.org/process_test.cgi';
46 0   0       $self->{'action'} = $args{'-action'} || 'submit';
47 0           $self->requiredField('machinename', %args);
48 0           $self->requiredField('username', %args);
49 0           $self->requiredField('authtoken', %args);
50            
51 0           return $self;
52             }
53              
54             sub sysconfig {
55 0     0 0   my $self = shift;
56 0           my %args = @_;
57            
58 0           $self->requiredField('product', %args);
59 0           $self->requiredField('platform', %args);
60 0           $self->requiredField('opsys', %args);
61 0           $self->requiredField('branch', %args);
62 0           $self->requiredField('buildid', %args);
63 0           $self->requiredField('locale', %args);
64            
65 0           $self->{'buildtype'} = $args{'-buildtype'};
66             }
67              
68             # add a Test::Litmus::Result object to ourselves
69             sub addResult {
70 0     0 0   my $self = shift;
71 0           my $result = shift;
72 0           push(@{$self->{'results'}}, $result);
  0            
73             }
74              
75             # add a Test::Litmus::Log object to ourselves
76             sub addLog {
77 0     0 0   my $self = shift;
78 0           my $log = shift;
79 0           push(@{$self->{'logs'}}, $log);
  0            
80             }
81              
82             # add fieldname to $self unless its missing, at which point we die
83             sub requiredField {
84 0     0 0   my $self = shift;
85 0           my $fieldname = shift;
86 0           my %args = @_;
87            
88 0   0       $self->{$fieldname} = $args{'-'.$fieldname} ||
89             die "You must specify a $fieldname";
90             }
91              
92             sub errstr {
93 0     0 0   my $self = shift;
94 0           return $self->{'response'}->content;
95             }
96              
97             sub toXML {
98 0     0 0   my $self = shift;
99 0           my $x;
100            
101 0           $x = ''."\n";
102 0           $x .= '
103             "-//Mozilla Corporation//Litmus Result Submission DTD//EN/"
104             "http://litmus.mozilla.org/litmus_results.dtd">'."\n";
105 0           $x .= ' 106             'Test::Litmus/'.$VERSION.' ('.$self->{'machinename'}.')" '.
107             'machinename="'.$self->{'machinename'}.'">'."\n";
108 0           $x .= '
109 0           $x .= ' authtoken="'.$self->{'authtoken'}.'"'."\n";
110 0           $x .= ' product="'.$self->{'product'}.'"'."\n";
111 0           $x .= ' platform="'.$self->{'platform'}.'"'."\n";
112 0           $x .= ' opsys="'.$self->{'opsys'}.'"'."\n";
113 0           $x .= ' branch="'.$self->{'branch'}.'"'."\n";
114 0           $x .= ' buildid="'.$self->{'buildid'}.'"'."\n";
115 0           $x .= ' locale="'.$self->{'locale'}.'"';
116 0 0         if ($self->{'buildtype'}) {
117 0           $x .= "\n".' buildtype="'.$self->{'buildtype'}.'"'.">\n";
118             } else {
119 0           $x .= ">\n";
120             }
121            
122 0 0         if ($self->{'logs'}) {
123 0           my @logs = @{$self->{'logs'}};
  0            
124 0           foreach my $curlog (@logs) {
125 0           $x .= $curlog->toXML();
126             }
127             }
128            
129 0           my @results = @{$self->{'results'}};
  0            
130 0           foreach my $curresult (@results) {
131 0           $x .= $curresult->toXML();
132             }
133            
134 0           $x .= ' '."\n";
135 0           $x .= ''."\n";
136            
137 0           return $x;
138             }
139              
140             sub submit {
141 0     0 0   my $self = shift;
142 0           $self->{'ua'} = new LWP::UserAgent;
143 0           $self->{'req'} = POST $self->{'server'}, [ data => $self->toXML() ];
144 0           $self->{'response'} = $self->{'ua'}->request($self->{'req'});
145            
146 0 0         if ($self->{'response'}->content =~ /^ok/i) { return 1 }
  0 0          
147 0           elsif ($self->{'response'}->content =~ /^Error processing result/i) { return 0 }
148 0           else { return undef }
149             }
150              
151             1;
152             __END__