HTTP::WebTest::Plugin::ContentSizeTest - Response body size checks


HTTP-WebTest documentation Contained in the HTTP-WebTest distribution.

Index


Code Index:

NAME

Top

HTTP::WebTest::Plugin::ContentSizeTest - Response body size checks

SYNOPSIS

Top

Not Applicable

DESCRIPTION

Top

This plugin tests the size the HTTP response content.

TEST PARAMETERS

Top

min_bytes

Minimum number of bytes expected in returned page.

Allowed values

Any integer less than max_bytes (if max_bytes is specified).

max_bytes

Maximum number of bytes expected in returned page.

Allowed values

Any integer greater that zero and greater than min_bytes (if min_bytes is specified).

COPYRIGHT

Top

SEE ALSO

Top

HTTP::WebTest

HTTP::WebTest::API (HTTP::WebTest::API)

HTTP::WebTest::Plugin

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;