#!/usr/bin/perl # Test program for the LPBFilter class. Ensures # that the length-prepended block filter works up # to specification. # Copyright 2004 by Rocco Caputo. Free software. # Same terms as Perl itself. Have fun! # This program does not test what happens when # get_pending() is called between the time an # input block's header is parsed and the rest of # the block is. Which is good, I suppose, # because the filter is broken in that situation. use warnings; use strict; use LPBFilter; print "1..4\n"; my $test_target = "this is my test target"; my $filter = LPBFilter->new(); # Generate a list of length-prepended blocks. my $streamable = $filter->put([ $test_target ]); # Pump two copies of the length-prepended block # into the filter. $filter->get_one_start($streamable); $filter->get_one_start($streamable); # Check that the filter's input buffer contains # two copies of the length-prepended block. my $buffered = $filter->get_pending(); print "not " unless ( $buffered eq $streamable->[0] x 2 ); print "ok 1\n"; # Pull one out, and verify that it matches the # original target string. my $first_out = $filter->get_one(); print "not " unless ( @$first_out == 1 and $first_out->[0] eq $test_target ); print "ok 2\n"; # Pull one out, and verify that it matches the # original target string. my $second_out = $filter->get_one(); print "not " unless ( @$second_out == 1 and $second_out->[0] eq $test_target ); print "ok 3\n"; # Try to pull one out. The resulting list should # be empty, as there should be nothing left in # the filter. my $third_out = $filter->get_one(); print "not " if @$third_out; print "ok 4\n"; exit 0;