stas 2003/01/14 22:19:25 Added: t/filter in_str_lc.t in_str_msg.t in_str_sandwich.t t/filter/TestFilter in_str_lc.pm in_str_msg.pm in_str_sandwich.pm Log: tests that exercise the input filtering streaming interface Revision Changes Path 1.1 modperl-2.0/t/filter/in_str_lc.t Index: in_str_lc.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; plan tests => 1; my $location = '/TestFilter::in_str_lc'; my $chunk = "[Foo BaR] "; my $data = $chunk x 250; my $expected = lc $data; my $received = POST_BODY $location, content => $data; ok t_cmp($expected, $received, "input stream filter lc") 1.1 modperl-2.0/t/filter/in_str_msg.t Index: in_str_msg.t =================================================================== use Apache::TestRequest; use Apache::Test (); use Apache::TestUtil; my $module = 'TestFilter::in_str_msg'; Apache::TestRequest::scheme('http'); #force http for t/TEST -ssl Apache::TestRequest::module($module); my $config = Apache::Test::config(); my $hostport = Apache::TestRequest::hostport($config); t_debug("connecting to $hostport"); print GET_BODY("/input_filter.html"); 1.1 modperl-2.0/t/filter/in_str_sandwich.t Index: in_str_sandwich.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; plan tests => 1; my $location = '/TestFilter::in_str_sandwich'; my $expected = join "\n", qw(HEADER BODY TAIL), ''; my $received = POST_BODY $location, content => "BODY\n"; ok t_cmp($expected, $received, "input stream filter sandwich") 1.1 modperl-2.0/t/filter/TestFilter/in_str_lc.pm Index: in_str_lc.pm =================================================================== package TestFilter::in_str_lc; use strict; use warnings FATAL => 'all'; use Apache::Filter (); use Apache::Const -compile => qw(OK M_POST); sub handler { my($filter, $bb, $mode, $block, $readbytes) = @_; while ($filter->read($mode, $block, $readbytes, my $buffer, 1024)) { #warn "FILTER READ: $buffer\n"; $filter->print(lc $buffer); } return Apache::OK; } sub response { my $r = shift; $r->content_type('text/plain'); if ($r->method_number == Apache::M_POST) { my $data = ModPerl::Test::read_post($r); #warn "HANDLER READ: $data\n"; $r->print($data); } Apache::OK; } 1; __DATA__ SetHandler modperl PerlResponseHandler TestFilter::in_str_lc::response 1.1 modperl-2.0/t/filter/TestFilter/in_str_msg.pm Index: in_str_msg.pm =================================================================== package TestFilter::in_str_msg; use strict; use warnings FATAL => 'all'; use base qw(Apache::Filter); use Apache::RequestRec (); use Apache::RequestIO (); use APR::Brigade (); use APR::Bucket (); use Apache::Const -compile => 'OK'; use APR::Const -compile => ':common'; my $from_url = '/input_filter.html'; my $to_url = '/TestFilter::in_str_msg::response'; sub handler : FilterConnectionHandler { my($filter, $bb, $mode, $block, $readbytes) = @_; warn "FILTER CALLED\n"; my $ctx = $filter->ctx; while ($filter->read($mode, $block, $readbytes, my $buffer, 1024)) { warn "FILTER READ: $buffer\n"; unless ($ctx) { $buffer =~ s|GET $from_url|GET $to_url|; $ctx = 1; # done } $filter->print($buffer); } $filter->ctx($ctx) if $ctx; return Apache::OK; } sub response { my $r = shift; $r->content_type('text/plain'); $r->puts("1..1\nok 1\n"); Apache::OK; } 1; __END__ <VirtualHost TestFilter::in_str_msg> # must be preloaded so the FilterConnectionHandler attributes will # be set by the time the filter is inserted into the filter chain PerlModule TestFilter::in_str_msg PerlInputFilterHandler TestFilter::in_str_msg <Location /TestFilter::in_str_msg::response> SetHandler modperl PerlResponseHandler TestFilter::in_str_msg::response </Location> </VirtualHost> 1.1 modperl-2.0/t/filter/TestFilter/in_str_sandwich.pm Index: in_str_sandwich.pm =================================================================== package TestFilter::in_str_sandwich; # this test verifies whether the filter can pre-insert data (using # context) and post-insert data (using the seen_eos flag) use strict; use warnings FATAL => 'all'; use Apache::Filter (); use Apache::Const -compile => qw(OK M_POST); sub handler { my($filter, $bb, $mode, $block, $readbytes) = @_; my $ctx = $filter->ctx; unless ($ctx) { $filter->print("HEADER\n"); $filter->ctx(1); } while ($filter->read($mode, $block, $readbytes, my $buffer, 1024)) { #warn "FILTER READ: $buffer\n"; $filter->print($buffer); } if ($filter->seen_eos) { $filter->print("TAIL\n"); } return Apache::OK; } sub response { my $r = shift; $r->content_type('text/plain'); if ($r->method_number == Apache::M_POST) { my $data = ModPerl::Test::read_post($r); #warn "HANDLER READ: $data\n"; $r->print($data); } return Apache::OK; } 1; __DATA__ SetHandler modperl PerlResponseHandler TestFilter::in_str_sandwich::response