Commit | Line | Data |
424ec8fa |
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'; |
93430cb4 |
8 | unshift @INC, '../lib' if -d '../lib'; |
a1a0e61e |
9 | require Config; import Config; |
424ec8fa |
10 | } |
11 | |
abfd9522 |
12 | BEGIN {$| = 1; print "1..20\n"; } |
424ec8fa |
13 | END {print "not ok 1\n" unless $loaded;} |
abfd9522 |
14 | use CGI (':standard','-no_debug','*h3','start_table'); |
424ec8fa |
15 | $loaded = 1; |
16 | print "ok 1\n"; |
17 | |
18 | ######################### End of black magic. |
19 | |
53d56f48 |
20 | my $Is_EBCDIC = $Config{'ebcdic'} eq 'define'; |
21 | |
424ec8fa |
22 | # util |
23 | sub test { |
24 | local($^W) = 0; |
25 | my($num, $true,$msg) = @_; |
26 | print($true ? "ok $num\n" : "not ok $num $msg\n"); |
27 | } |
28 | |
29 | # all the automatic tags |
30 | test(2,h1() eq '<H1>',"single tag"); |
31 | test(3,h1('fred') eq '<H1>fred</H1>',"open/close tag"); |
32 | test(4,h1('fred','agnes','maura') eq '<H1>fred agnes maura</H1>',"open/close tag multiple"); |
33 | test(5,h1({-align=>'CENTER'},'fred') eq '<H1 ALIGN="CENTER">fred</H1>',"open/close tag with attribute"); |
34 | test(6,h1({-align=>undef},'fred') eq '<H1 ALIGN>fred</H1>',"open/close tag with orphan attribute"); |
35 | test(7,h1({-align=>'CENTER'},['fred','agnes']) eq |
36 | '<H1 ALIGN="CENTER">fred</H1> <H1 ALIGN="CENTER">agnes</H1>', |
37 | "distributive tag with attribute"); |
38 | { |
39 | local($") = '-'; |
40 | test(8,h1('fred','agnes','maura') eq '<H1>fred-agnes-maura</H1>',"open/close tag \$\" interpolation"); |
41 | } |
53d56f48 |
42 | if (!$Is_EBCDIC) { |
f6b3007c |
43 | test(9,header() eq "Content-Type: text/html\015\012\015\012","header()"); |
44 | test(10,header(-type=>'image/gif') eq "Content-Type: image/gif\015\012\015\012","header()"); |
45 | test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks\015\012Content-Type: image/gif\015\012\015\012","header()"); |
46 | test(12,header(-nph=>1) eq "HTTP/1.0 200 OK\015\012Content-Type: text/html\015\012\015\012","header()"); |
53d56f48 |
47 | } else { |
48 | test(9,header() eq "Content-Type: text/html\r\n\r\n","header()"); |
49 | test(10,header(-type=>'image/gif') eq "Content-Type: image/gif\r\n\r\n","header()"); |
50 | test(11,header(-type=>'image/gif',-status=>'500 Sucks') eq "Status: 500 Sucks\r\nContent-Type: image/gif\r\n\r\n","header()"); |
51 | test(12,header(-nph=>1) eq "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n","header()"); |
52 | } |
424ec8fa |
53 | test(13,start_html() ."\n" eq <<END,"start_html()"); |
54 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
55 | <HTML><HEAD><TITLE>Untitled Document</TITLE> |
56 | </HEAD><BODY> |
57 | END |
58 | ; |
59 | test(14,start_html(-dtd=>"-//IETF//DTD HTML 3.2//FR") ."\n" eq <<END,"start_html()"); |
60 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 3.2//FR"> |
61 | <HTML><HEAD><TITLE>Untitled Document</TITLE> |
62 | </HEAD><BODY> |
63 | END |
64 | ; |
65 | test(15,start_html(-Title=>'The world of foo') ."\n" eq <<END,"start_html()"); |
66 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
67 | <HTML><HEAD><TITLE>The world of foo</TITLE> |
68 | </HEAD><BODY> |
69 | END |
70 | ; |
71 | test(16,($cookie=cookie(-name=>'fred',-value=>['chocolate','chip'],-path=>'/')) eq |
cb50131a |
72 | 'fred=chocolate&chip; path=/',"cookie()"); |
53d56f48 |
73 | if (!$Is_EBCDIC) { |
cb50131a |
74 | test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/\015\012Date:.*\015\012Content-Type: text/html\015\012\015\012!s, |
424ec8fa |
75 | "header(-cookie)"); |
53d56f48 |
76 | } else { |
cb50131a |
77 | test(17,header(-Cookie=>$cookie) =~ m!^Set-Cookie: fred=chocolate&chip\; path=/\r\nDate:.*\r\nContent-Type: text/html\r\n\r\n!s, |
53d56f48 |
78 | "header(-cookie)"); |
79 | } |
abfd9522 |
80 | test(18,start_h3 eq '<H3>'); |
81 | test(19,end_h3 eq '</H3>'); |
82 | test(20,start_table({-border=>undef}) eq '<TABLE BORDER>'); |