diff options
author | markm <markm@FreeBSD.org> | 2002-03-16 20:14:30 +0000 |
---|---|---|
committer | markm <markm@FreeBSD.org> | 2002-03-16 20:14:30 +0000 |
commit | 3eac21f49bc763a6c0044b4afbc0c7ece760144f (patch) | |
tree | 4cf1274fa3ca68f7ecf6a3051e0c2243e378afc5 /contrib/perl5/t/lib/cgi-function.t | |
parent | 259bd53c06712c4ffb0ab7e06898c19ebf221b21 (diff) | |
download | FreeBSD-src-3eac21f49bc763a6c0044b4afbc0c7ece760144f.zip FreeBSD-src-3eac21f49bc763a6c0044b4afbc0c7ece760144f.tar.gz |
Vendor import Perl 5.6.1
Diffstat (limited to 'contrib/perl5/t/lib/cgi-function.t')
-rwxr-xr-x | contrib/perl5/t/lib/cgi-function.t | 77 |
1 files changed, 49 insertions, 28 deletions
diff --git a/contrib/perl5/t/lib/cgi-function.t b/contrib/perl5/t/lib/cgi-function.t index b4cd568..3b9722e 100755 --- a/contrib/perl5/t/lib/cgi-function.t +++ b/contrib/perl5/t/lib/cgi-function.t @@ -1,14 +1,15 @@ -#!./perl - -# Test ability to retrieve HTTP request info -######################### We start with some black magic to print on failure. +#!/usr/local/bin/perl -w BEGIN { - chdir 't' if -d 't'; - unshift @INC, '../lib' if -d '../lib'; + chdir('t') if -d 't'; + @INC = '../lib'; } -BEGIN {$| = 1; print "1..24\n"; } +# Test ability to retrieve HTTP request info +######################### We start with some black magic to print on failure. +use lib '../blib/lib','../blib/arch'; + +BEGIN {$| = 1; print "1..27\n"; } END {print "not ok 1\n" unless $loaded;} use Config; use CGI (':standard','keywords'); @@ -24,6 +25,22 @@ sub test { print($true ? "ok $num\n" : "not ok $num $msg\n"); } +my $CRLF = "\015\012"; + +# A peculiarity of sending "\n" through MBX|Socket|web-server on VMS +# is that a CR character gets inserted automatically in the web server +# case but not internal to perl's double quoted strings "\n". This +# test would need to be modified to use the "\015\012" on VMS if it +# were actually run through a web server. +# Thanks to Peter Prymmer for this + +if ($^O eq 'VMS') { $CRLF = "\n"; } + +# Web servers on EBCDIC hosts are typically set up to do an EBCDIC -> ASCII +# translation hence CRLF is used as \r\n within CGI.pm on such machines. + +if (ord("\t") != 9) { $CRLF = "\r\n"; } + # Set up a CGI environment $ENV{REQUEST_METHOD}='GET'; $ENV{QUERY_STRING} ='game=chess&game=checkers&weather=dull'; @@ -36,7 +53,7 @@ $ENV{SERVER_NAME} = 'the.good.ship.lollypop.com'; $ENV{HTTP_LOVE} = 'true'; test(2,request_method() eq 'GET',"CGI::request_method()"); -test(3,query_string() eq 'game=chess&game=checkers&weather=dull',"CGI::query_string()"); +test(3,query_string() eq 'game=chess;game=checkers;weather=dull',"CGI::query_string()"); test(4,param() == 2,"CGI::param()"); test(5,join(' ',sort {$a cmp $b} param()) eq 'game weather',"CGI::param()"); test(6,param('game') eq 'chess',"CGI::param()"); @@ -44,18 +61,18 @@ test(7,param('weather') eq 'dull',"CGI::param()"); test(8,join(' ',param('game')) eq 'chess checkers',"CGI::param()"); test(9,param(-name=>'foo',-value=>'bar'),'CGI::param() put'); test(10,param(-name=>'foo') eq 'bar','CGI::param() get'); -test(11,query_string() eq 'game=chess&game=checkers&weather=dull&foo=bar',"CGI::query_string() redux"); +test(11,query_string() eq 'game=chess;game=checkers;weather=dull;foo=bar',"CGI::query_string() redux"); test(12,http('love') eq 'true',"CGI::http()"); test(13,script_name() eq '/cgi-bin/foo.cgi',"CGI::script_name()"); test(14,url() eq 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi',"CGI::url()"); test(15,self_url() eq - 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'http://the.good.ship.lollypop.com:8080/cgi-bin/foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', "CGI::url()"); test(16,url(-absolute=>1) eq '/cgi-bin/foo.cgi','CGI::url(-absolute=>1)'); test(17,url(-relative=>1) eq 'foo.cgi','CGI::url(-relative=>1)'); test(18,url(-relative=>1,-path=>1) eq 'foo.cgi/somewhere/else','CGI::url(-relative=>1,-path=>1)'); test(19,url(-relative=>1,-path=>1,-query=>1) eq - 'foo.cgi/somewhere/else?game=chess&game=checkers&weather=dull&foo=bar', + 'foo.cgi/somewhere/else?game=chess;game=checkers;weather=dull;foo=bar', 'CGI::url(-relative=>1,-path=>1,-query=>1)'); Delete('foo'); test(20,!param('foo'),'CGI::delete()'); @@ -65,21 +82,25 @@ $ENV{QUERY_STRING}='mary+had+a+little+lamb'; test(21,join(' ',keywords()) eq 'mary had a little lamb','CGI::keywords'); test(22,join(' ',param('keywords')) eq 'mary had a little lamb','CGI::keywords'); -if (!$Config{d_fork} or $^O eq 'MSWin32' or $^O eq 'VMS') { - for (23,24) { print "ok $_ # Skipped: fork n/a\n" } -} -else { - CGI::_reset_globals; - $test_string = 'game=soccer&game=baseball&weather=nice'; - $ENV{REQUEST_METHOD}='POST'; - $ENV{CONTENT_LENGTH}=length($test_string); - $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; - if (open(CHILD,"|-")) { # cparent - print CHILD $test_string; - close CHILD; - exit 0; - } - # at this point, we're in a new (child) process - test(23,param('weather') eq 'nice',"CGI::param() from POST"); - test(24,url_param('big_balls') eq 'basketball',"CGI::url_param()"); +CGI::_reset_globals; +if ($Config{d_fork}) { + $test_string = 'game=soccer&game=baseball&weather=nice'; + $ENV{REQUEST_METHOD}='POST'; + $ENV{CONTENT_LENGTH}=length($test_string); + $ENV{QUERY_STRING}='big_balls=basketball&small_balls=golf'; + if (open(CHILD,"|-")) { # cparent + print CHILD $test_string; + close CHILD; + exit 0; + } + # at this point, we're in a new (child) process + test(23,param('weather') eq 'nice',"CGI::param() from POST"); + test(24,(url_param('big_balls') eq 'basketball'),"CGI::url_param()"); +} else { + print "ok 23 # Skip\n"; + print "ok 24 # Skip\n"; } +test(25,redirect('http://somewhere.else') eq "Status: 302 Moved${CRLF}location: http://somewhere.else${CRLF}${CRLF}","CGI::redirect() 1"); +my $h = redirect(-Location=>'http://somewhere.else',-Type=>'text/html'); +test(26,$h eq "Status: 302 Moved${CRLF}location: http://somewhere.else${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}","CGI::redirect() 2"); +test(27,redirect(-Location=>'http://somewhere.else/bin/foo&bar',-Type=>'text/html') eq "Status: 302 Moved${CRLF}location: http://somewhere.else/bin/foo&bar${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}","CGI::redirect() 2"); |