10Sstevel@tonic-gate#!/usr/local/bin/perl -w 20Sstevel@tonic-gate 30Sstevel@tonic-gate# Test ability to retrieve HTTP request info 40Sstevel@tonic-gate######################### We start with some black magic to print on failure. 50Sstevel@tonic-gateuse lib '../blib/lib','../blib/arch'; 60Sstevel@tonic-gate 70Sstevel@tonic-gateEND {print "not ok 1\n" unless $loaded;} 80Sstevel@tonic-gateuse CGI (':standard','-no_debug','*h3','start_table'); 90Sstevel@tonic-gate$loaded = 1; 100Sstevel@tonic-gateprint "ok 1\n"; 110Sstevel@tonic-gate 120Sstevel@tonic-gateBEGIN { 13*6287Sps156622 $| = 1; print "1..28\n"; 140Sstevel@tonic-gate if( $] > 5.006 ) { 150Sstevel@tonic-gate # no utf8 160Sstevel@tonic-gate require utf8; # we contain Latin-1 170Sstevel@tonic-gate utf8->unimport; 180Sstevel@tonic-gate } 190Sstevel@tonic-gate} 200Sstevel@tonic-gate 210Sstevel@tonic-gate######################### End of black magic. 220Sstevel@tonic-gate 230Sstevel@tonic-gatemy $CRLF = "\015\012"; 240Sstevel@tonic-gateif ($^O eq 'VMS') { 250Sstevel@tonic-gate $CRLF = "\n"; # via web server carriage is inserted automatically 260Sstevel@tonic-gate} 270Sstevel@tonic-gateif (ord("\t") != 9) { # EBCDIC? 280Sstevel@tonic-gate $CRLF = "\r\n"; 290Sstevel@tonic-gate} 300Sstevel@tonic-gate 310Sstevel@tonic-gate 320Sstevel@tonic-gate# util 330Sstevel@tonic-gatesub test { 340Sstevel@tonic-gate local($^W) = 0; 350Sstevel@tonic-gate my($num, $true,$msg) = @_; 360Sstevel@tonic-gate print($true ? "ok $num\n" : "not ok $num $msg\n"); 370Sstevel@tonic-gate} 380Sstevel@tonic-gate 390Sstevel@tonic-gate# all the automatic tags 400Sstevel@tonic-gatetest(2,h1() eq '<h1 />',"single tag"); 410Sstevel@tonic-gatetest(3,h1('fred') eq '<h1>fred</h1>',"open/close tag"); 420Sstevel@tonic-gatetest(4,h1('fred','agnes','maura') eq '<h1>fred agnes maura</h1>',"open/close tag multiple"); 430Sstevel@tonic-gatetest(5,h1({-align=>'CENTER'},'fred') eq '<h1 align="CENTER">fred</h1>',"open/close tag with attribute"); 440Sstevel@tonic-gatetest(6,h1({-align=>undef},'fred') eq '<h1 align>fred</h1>',"open/close tag with orphan attribute"); 450Sstevel@tonic-gatetest(7,h1({-align=>'CENTER'},['fred','agnes']) eq 460Sstevel@tonic-gate '<h1 align="CENTER">fred</h1> <h1 align="CENTER">agnes</h1>', 470Sstevel@tonic-gate "distributive tag with attribute"); 480Sstevel@tonic-gate{ 490Sstevel@tonic-gate local($") = '-'; 500Sstevel@tonic-gate test(8,h1('fred','agnes','maura') eq '<h1>fred-agnes-maura</h1>',"open/close tag \$\" interpolation"); 510Sstevel@tonic-gate} 520Sstevel@tonic-gatetest(9,header() eq "Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}","header()"); 530Sstevel@tonic-gatetest(10,header(-type=>'image/gif') eq "Content-Type: image/gif${CRLF}${CRLF}","header()"); 540Sstevel@tonic-gatetest(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${CRLF}Content-Type: image/gif${CRLF}${CRLF}","header()"); 550Sstevel@tonic-gatetest(12,header(-nph=>1) =~ m!HTTP/1.0 200 OK${CRLF}Server: cmdline${CRLF}Date:.+${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}!,"header()"); 56667Sps156622test(13,start_html() eq <<END,"start_html()"); 57667Sps156622<!DOCTYPE html 58667Sps156622 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 59667Sps156622 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 60667Sps156622<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> 61667Sps156622<head> 62667Sps156622<title>Untitled Document</title> 63667Sps156622<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 64667Sps156622</head> 65667Sps156622<body> 66667Sps156622END 67667Sps156622 ; 68667Sps156622test(14,start_html(-Title=>'The world of foo') eq <<END,"start_html()"); 690Sstevel@tonic-gate<!DOCTYPE html 700Sstevel@tonic-gate PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 710Sstevel@tonic-gate "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 72667Sps156622<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"> 73667Sps156622<head> 74667Sps156622<title>The world of foo</title> 75667Sps156622<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 76667Sps156622</head> 77667Sps156622<body> 780Sstevel@tonic-gateEND 790Sstevel@tonic-gate ; 80667Sps156622# Note that this test will turn off XHTML until we make a new CGI object. 81667Sps156622test(15,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR",-lang=>'fr') eq <<END,"start_html()"); 820Sstevel@tonic-gate<!DOCTYPE html 830Sstevel@tonic-gate PUBLIC "-//IETF//DTD HTML 3.2//FR"> 84667Sps156622<html lang="fr"><head><title>Untitled Document</title> 85667Sps156622</head> 86667Sps156622<body> 870Sstevel@tonic-gateEND 880Sstevel@tonic-gate ; 890Sstevel@tonic-gatetest(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq 'fred=chocolate&chip; path=/',"cookie()"); 900Sstevel@tonic-gatemy $h = header(-Cookie=>$cookie); 910Sstevel@tonic-gatetest(17,$h =~ m!^Set-Cookie: fred=chocolate&chip\; path=/${CRLF}Date:.*${CRLF}Content-Type: text/html; charset=ISO-8859-1${CRLF}${CRLF}!s, 920Sstevel@tonic-gate "header(-cookie)"); 930Sstevel@tonic-gatetest(18,start_h3 eq '<h3>'); 940Sstevel@tonic-gatetest(19,end_h3 eq '</h3>'); 950Sstevel@tonic-gatetest(20,start_table({-border=>undef}) eq '<table border>'); 960Sstevel@tonic-gatetest(21,h1(escapeHTML("this is <not> \x8bright\x9b")) eq '<h1>this is <not> ‹right›</h1>'); 970Sstevel@tonic-gatecharset('utf-8'); 980Sstevel@tonic-gateif (ord("\t") == 9) { 990Sstevel@tonic-gatetest(22,h1(escapeHTML("this is <not> \x8bright\x9b")) eq '<h1>this is <not> �right�</h1>'); 1000Sstevel@tonic-gate} 1010Sstevel@tonic-gateelse { 1020Sstevel@tonic-gatetest(22,h1(escapeHTML("this is <not> \x8bright\x9b")) eq '<h1>this is <not> �right�</h1>'); 1030Sstevel@tonic-gate} 1040Sstevel@tonic-gatetest(23,i(p('hello there')) eq '<i><p>hello there</p></i>'); 1050Sstevel@tonic-gatemy $q = new CGI; 1060Sstevel@tonic-gatetest(24,$q->h1('hi') eq '<h1>hi</h1>'); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate$q->autoEscape(1); 1090Sstevel@tonic-gatetest(25,$q->p({title=>"hello worldè"},'hello á') eq '<p title="hello world&egrave;">hello á</p>'); 1100Sstevel@tonic-gate$q->autoEscape(0); 1110Sstevel@tonic-gatetest(26,$q->p({title=>"hello worldè"},'hello á') eq '<p title="hello worldè">hello á</p>'); 1120Sstevel@tonic-gatetest(27,p({title=>"hello worldè"},'hello á') eq '<p title="hello world&egrave;">hello á</p>'); 113*6287Sps156622test(28,header(-type=>'image/gif',-charset=>'UTF-8') eq "Content-Type: image/gif; charset=UTF-8${CRLF}${CRLF}","header()"); 114