Initial import from FreeBSD RELENG_4:
[games.git] / contrib / perl5 / t / lib / cgi-html.t
1 #!./perl
2
3 # Test ability to retrieve HTTP request info
4 ######################### We start with some black magic to print on failure.
5
6 BEGIN {
7     chdir 't' if -d 't';
8     @INC = '../lib' if -d '../lib';
9 }
10
11 BEGIN {$| = 1; print "1..20\n"; }
12 BEGIN {$eol = $^O eq 'VMS' ? "\n" : "\cM\cJ";
13        $eol = "\r\n" if $^O eq 'os390'; }
14 END {print "not ok 1\n" unless $loaded;}
15 use CGI (':standard','-no_debug','*h3','start_table');
16 $loaded = 1;
17 print "ok 1\n";
18
19 ######################### End of black magic.
20
21 # util
22 sub test {
23     local($^W) = 0;
24     my($num, $true,$msg) = @_;
25     print($true ? "ok $num\n" : "not ok $num $msg\n");
26 }
27
28 # all the automatic tags
29 test(2,h1() eq '<H1>',"single tag");
30 test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag");
31 test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple");
32 test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute");
33 test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute");
34 test(7,h1({-align=>'CENTER'},['fred','agnes']) eq 
35      '<H1 ALIGN="CENTER">fred</H1> <H1 ALIGN="CENTER">agnes</H1>',
36      "distributive tag with attribute");
37 {
38     local($") = '-'; 
39     test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation");
40 }
41 test(9,header() eq "Content-Type: text/html${eol}${eol}","header()");
42 test(10,header(-type=>'image/gif') eq "Content-Type: image/gif${eol}${eol}","header()");
43 test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks${eol}Content-Type: image/gif${eol}${eol}","header()");
44 test(12,header(-nph=>1) eq "HTTP/1.0 200 OK${eol}Content-Type: text/html${eol}${eol}","header()");
45 test(13,start_html() ."\n" eq <<END,"start_html()");
46 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
47 <HTML><HEAD><TITLE>Untitled Document</TITLE>
48 </HEAD><BODY>
49 END
50     ;
51 test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html()");
52 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//FR">
53 <HTML><HEAD><TITLE>Untitled Document</TITLE>
54 </HEAD><BODY>
55 END
56     ;
57 test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()");
58 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
59 <HTML><HEAD><TITLE>The world of foo</TITLE>
60 </HEAD><BODY>
61 END
62     ;
63 test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq 
64      'fred=chocolate&chip; path=/',"cookie()");
65 test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/${eol}Date:.*${eol}Content-Type: text/html${eol}${eol}!s,
66      "header(-cookie)");
67 test(18,start_h3 eq '<H3>');
68 test(19,end_h3 eq '</H3>');
69 test(20,start_table({-border=>undef}) eq '<TABLE BORDER>');