| HTTP-WebTest documentation | Contained in the HTTP-WebTest distribution. |
HTTP::WebTest::Plugin::ContentSizeTest - Response body size checks
Not Applicable
This plugin tests the size the HTTP response content.
Minimum number of bytes expected in returned page.
Any integer less than max_bytes (if max_bytes is specified).
Maximum number of bytes expected in returned page.
Any integer greater that zero and greater than min_bytes (if
min_bytes is specified).
Copyright (c) 2000-2001 Richard Anderson. All rights reserved.
Copyright (c) 2001-2003 Ilya Martynov. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
HTTP::WebTest::API (HTTP::WebTest::API)
HTTP::WebTest::Plugins (HTTP::WebTest::Plugins)
| HTTP-WebTest documentation | Contained in the HTTP-WebTest distribution. |
# $Id: ContentSizeTest.pm,v 1.9 2003/03/02 11:52:09 m_ilya Exp $ package HTTP::WebTest::Plugin::ContentSizeTest;
use strict; use base qw(HTTP::WebTest::Plugin);
sub param_types { return q(min_bytes scalar max_bytes scalar); } sub check_response { my $self = shift; # response content length my $nbytes = length $self->webtest->current_response->content; $self->validate_params(qw(min_bytes max_bytes)); # size limits my $min_bytes = $self->test_param('min_bytes'); my $max_bytes = $self->test_param('max_bytes'); # test results my @results = (); my @ret = (); # check minimal size if(defined $min_bytes) { my $ok = $nbytes >= $min_bytes; my $comment = 'Number of returned bytes ('; $comment .= sprintf '%6d', $nbytes; $comment .= ' ) is > or ='; $comment .= sprintf '%6d', $min_bytes; $comment .= ' ?'; push @results, $self->test_result($ok, $comment); } # check maximal size if(defined $max_bytes) { my $ok = $nbytes <= $max_bytes; my $comment = 'Number of returned bytes ('; $comment .= sprintf '%6d', $nbytes; $comment .= ' ) is < or ='; $comment .= sprintf '%6d', $max_bytes; $comment .= ' ?'; push @results, $self->test_result($ok, $comment); } push @ret, [ 'Content size check', @results ] if @results; return @ret; }
1;