line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: ContentSizeTest.pm,v 1.9 2003/03/02 11:52:09 m_ilya Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package HTTP::WebTest::Plugin::ContentSizeTest; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
HTTP::WebTest::Plugin::ContentSizeTest - Response body size checks |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Not Applicable |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 DESCRIPTION |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
This plugin tests the size the HTTP response content. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
10
|
|
|
10
|
|
62
|
use strict; |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
394
|
|
20
|
|
|
|
|
|
|
|
21
|
10
|
|
|
10
|
|
57
|
use base qw(HTTP::WebTest::Plugin); |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
3732
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 TEST PARAMETERS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=for pod_merge copy params |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head2 min_bytes |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Minimum number of bytes expected in returned page. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head3 Allowed values |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Any integer less than C (if C is specified). |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 max_bytes |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Maximum number of bytes expected in returned page. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head3 Allowed values |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Any integer greater that zero and greater than C (if |
42
|
|
|
|
|
|
|
C is specified). |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub param_types { |
47
|
190
|
|
|
190
|
1
|
2187
|
return q(min_bytes scalar |
48
|
|
|
|
|
|
|
max_bytes scalar); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub check_response { |
52
|
190
|
|
|
190
|
0
|
476
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# response content length |
55
|
190
|
|
|
|
|
742
|
my $nbytes = length $self->webtest->current_response->content; |
56
|
|
|
|
|
|
|
|
57
|
190
|
|
|
|
|
7284
|
$self->validate_params(qw(min_bytes max_bytes)); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# size limits |
60
|
190
|
|
|
|
|
733
|
my $min_bytes = $self->test_param('min_bytes'); |
61
|
190
|
|
|
|
|
646
|
my $max_bytes = $self->test_param('max_bytes'); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# test results |
64
|
190
|
|
|
|
|
518
|
my @results = (); |
65
|
190
|
|
|
|
|
4762
|
my @ret = (); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# check minimal size |
68
|
190
|
100
|
|
|
|
601
|
if(defined $min_bytes) { |
69
|
4
|
|
|
|
|
10
|
my $ok = $nbytes >= $min_bytes; |
70
|
4
|
|
|
|
|
10
|
my $comment = 'Number of returned bytes ('; |
71
|
4
|
|
|
|
|
21
|
$comment .= sprintf '%6d', $nbytes; |
72
|
4
|
|
|
|
|
9
|
$comment .= ' ) is > or ='; |
73
|
4
|
|
|
|
|
13
|
$comment .= sprintf '%6d', $min_bytes; |
74
|
4
|
|
|
|
|
8
|
$comment .= ' ?'; |
75
|
|
|
|
|
|
|
|
76
|
4
|
|
|
|
|
25
|
push @results, $self->test_result($ok, $comment); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# check maximal size |
80
|
190
|
100
|
|
|
|
658
|
if(defined $max_bytes) { |
81
|
4
|
|
|
|
|
10
|
my $ok = $nbytes <= $max_bytes; |
82
|
4
|
|
|
|
|
12
|
my $comment = 'Number of returned bytes ('; |
83
|
4
|
|
|
|
|
18
|
$comment .= sprintf '%6d', $nbytes; |
84
|
4
|
|
|
|
|
10
|
$comment .= ' ) is < or ='; |
85
|
4
|
|
|
|
|
10
|
$comment .= sprintf '%6d', $max_bytes; |
86
|
4
|
|
|
|
|
6
|
$comment .= ' ?'; |
87
|
|
|
|
|
|
|
|
88
|
4
|
|
|
|
|
15
|
push @results, $self->test_result($ok, $comment); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
190
|
100
|
|
|
|
575
|
push @ret, [ 'Content size check', @results ] if @results; |
92
|
|
|
|
|
|
|
|
93
|
190
|
|
|
|
|
943
|
return @ret; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 COPYRIGHT |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Copyright (c) 2000-2001 Richard Anderson. All rights reserved. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Copyright (c) 2001-2003 Ilya Martynov. All rights reserved. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
103
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
L |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |