| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# $Id: Test.pm,v 1.7 2003/03/02 11:52:10 m_ilya Exp $ |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTTP::WebTest::Test; |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
HTTP::WebTest::Test - Test object class |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use HTTP::WebTest::Test; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $test = HTTP::WebTest::Test->new(%params); |
|
14
|
|
|
|
|
|
|
my $test = HTTP::WebTest::Test->convert($raw_test); |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my $value = $test->param($param); |
|
17
|
|
|
|
|
|
|
my $value = $test->params->{$param}; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $results = $test->results; |
|
20
|
|
|
|
|
|
|
my $result = $test->result->[0]; |
|
21
|
|
|
|
|
|
|
$test->result->[0] = $result; |
|
22
|
|
|
|
|
|
|
$test->results([ @results ]); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $request = $test->request; |
|
25
|
|
|
|
|
|
|
$test->request($request); |
|
26
|
|
|
|
|
|
|
my $response = $test->response; |
|
27
|
|
|
|
|
|
|
$test->response($response); |
|
28
|
|
|
|
|
|
|
my $response_time = $test->response_time; |
|
29
|
|
|
|
|
|
|
$test->response_time($response_time); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Objects of this class represent tests. They store both test parameters and |
|
34
|
|
|
|
|
|
|
test results. |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 CLASS METHODS |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
|
39
|
|
|
|
|
|
|
|
|
40
|
20
|
|
|
20
|
|
166
|
use strict; |
|
|
20
|
|
|
|
|
46
|
|
|
|
20
|
|
|
|
|
808
|
|
|
41
|
|
|
|
|
|
|
|
|
42
|
20
|
|
|
20
|
|
106
|
use HTTP::WebTest::Utils qw(make_access_method); |
|
|
20
|
|
|
|
|
34
|
|
|
|
20
|
|
|
|
|
19284
|
|
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 new (%params) |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Constructor. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head3 Parameters |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=over 4 |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * %params |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
A hash with test parameters. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head3 Returns |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
A new C object. |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
|
65
|
194
|
|
|
194
|
1
|
315
|
my $class = shift; |
|
66
|
194
|
|
|
|
|
636
|
my %params = @_; |
|
67
|
|
|
|
|
|
|
|
|
68
|
194
|
|
|
|
|
739
|
my $self = bless {}, $class; |
|
69
|
194
|
|
|
|
|
1061
|
$self->params({ %params }); |
|
70
|
|
|
|
|
|
|
|
|
71
|
194
|
|
|
|
|
769
|
return $self; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 params |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head3 Returns |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
A reference to a hash with all test parameters. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
*params = make_access_method('PARAMS', sub { {} }); |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 param ($param) |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head3 Returns |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
A value of test parameter named C<$param>. |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub param { |
|
93
|
11691
|
|
|
11691
|
1
|
19950
|
my $self = shift; |
|
94
|
11691
|
|
|
|
|
16752
|
my $param = shift; |
|
95
|
|
|
|
|
|
|
|
|
96
|
11691
|
|
|
|
|
36417
|
return $self->params->{$param}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 results ($optional_results) |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Can set L objects |
|
102
|
|
|
|
|
|
|
for this C object if an array reference |
|
103
|
|
|
|
|
|
|
C<$optional_results> is passed. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head3 Returns |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
A reference to an array that contains |
|
108
|
|
|
|
|
|
|
L objects. |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
*results = make_access_method('RESULTS', sub { [] }); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 request ($optional_request) |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
If parameter C<$optional_request> is passed, |
|
117
|
|
|
|
|
|
|
set L object for this |
|
118
|
|
|
|
|
|
|
C object. |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head3 Returns |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
A L object. |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
*request = make_access_method('REQUEST'); |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 response ($optional_response) |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
If parameter C<$optional_response> is passed, |
|
131
|
|
|
|
|
|
|
set L object for this |
|
132
|
|
|
|
|
|
|
C object. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head3 Returns |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
A L object. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
*response = make_access_method('RESPONSE'); |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 response_time ($optional_response_time) |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
If parameter C<$optional_response_time> is passed, |
|
145
|
|
|
|
|
|
|
set response time for this C object. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head3 Returns |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
A response time. |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
*response_time = make_access_method('RESPONSE_TIME'); |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=head2 convert ($test) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Tries to convert test definition in some form into |
|
158
|
|
|
|
|
|
|
C object. Currenlty supports test defintion in |
|
159
|
|
|
|
|
|
|
form of C object (it is just passed through) or in |
|
160
|
|
|
|
|
|
|
the form of hash reference: |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
{ test_param1 => test_value1, test_param2 => test_value2 } |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head3 Returns |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
A new C object. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
sub convert { |
|
171
|
387
|
|
|
387
|
1
|
687
|
my $class = shift; |
|
172
|
387
|
|
|
|
|
609
|
my $test = shift; |
|
173
|
|
|
|
|
|
|
|
|
174
|
387
|
100
|
|
|
|
2795
|
return $test if UNIVERSAL::isa($test, 'HTTP::WebTest::Test'); |
|
175
|
|
|
|
|
|
|
|
|
176
|
194
|
|
|
|
|
3449
|
my $conv_test = $class->new(%$test); |
|
177
|
|
|
|
|
|
|
|
|
178
|
194
|
|
|
|
|
905
|
return $conv_test; |
|
179
|
|
|
|
|
|
|
} |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 reset () |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Resets test object |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=cut |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub reset { |
|
188
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
189
|
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
|
$self->request(undef); |
|
191
|
0
|
|
|
|
|
|
$self->response(undef); |
|
192
|
0
|
|
|
|
|
|
$self->response_time(undef); |
|
193
|
0
|
|
|
|
|
|
$self->results(undef); |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright (c) 2001-2003 Ilya Martynov. All rights reserved. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
|
201
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
L |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
L |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
L |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=cut |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
1; |