Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 152 lines (139 sloc) 3.751 kb
a1fe32d Total Test Overhaul! Most of these were stubs, and still are.
Joe Atzberger authored
1 #!/usr/bin/perl
2 #
3
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
4 use strict;
a1fe32d Total Test Overhaul! Most of these were stubs, and still are.
Joe Atzberger authored
5 use C4::Interface::CGI::Output; #
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
6
7 use vars qw( @tests );
8 use vars qw( $loaded );
9
10 BEGIN {
11 @tests = (
12 [
13 'Normal HTML without meta tag',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
14 sub { guesscharset($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
15 undef,
16 <<EOF
17 <title>control case</title>
18 EOF
19 ], [
20 'Result of guesscharset with normal HTML with irrelevant meta tag',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
21 sub { guesscharset($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
22 undef,
23 <<EOF
24 <meta http-equiv="Content-Language" content="zh-TW">
25 EOF
26 ], [
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
27 'Result of guesstype with normal HTML with irrelevant meta tag',
28 sub { guesstype($_[0]) },
29 'text/html',
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
30 <<EOF
31 <meta http-equiv="Content-Language" content="zh-TW">
32 EOF
33 ], [
34 'Result of guesscharset with normal HTML with relevant meta tag',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
35 sub { guesscharset($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
36 'big5',
37 <<EOF
38 <meta http-equiv="Content-Type" content="text/html; charset=big5">
39 EOF
40 ], [
41 'Result of guesstype with normal HTML with relevant meta tag',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
42 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
43 'text/html; charset=big5',
44 <<EOF
45 <meta http-equiv="Content-Type" content="text/html; charset=big5">
46 EOF
47 ], [
48 'Variant 1 using single quotes',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
49 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
50 'text/html; charset=iso-2022-jp',
51 <<EOF
52 <meta http-equiv="Content-Type" content='text/html; charset=iso-2022-jp'>
53 EOF
54 ], [
55 'Variant 2 using single quotes',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
56 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
57 'text/html; charset=utf-8',
58 <<EOF
59 <meta http-equiv='Content-Type' content="text/html; charset=utf-8">
60 EOF
61 ], [
62 'Unquoted Content-Type',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
63 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
64 'text/html; charset=big5',
65 <<EOF
66 <meta http-equiv=Content-Type content="text/html; charset=big5">
67 EOF
68 ], [
69 'XML syntax',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
70 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
71 'text/html; charset=iso-8859-2',
72 <<EOF
73 <meta http-equiv=Content-Type content="text/html; charset=iso-8859-2" />
74 EOF
75 ], [
76 'Expected attributes in reverse order',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
77 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
78 'text/html; charset=big5',
79 <<EOF
80 <meta content="text/html; charset=big5" http-equiv="Content-Type">
81 EOF
82 ], [
83 'Extra whitespace at end',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
84 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
85 'text/html; charset=big5',
86 <<EOF
87 <meta http-equiv="Content-Type" content="text/html; charset=big5" >
88 EOF
89 ], [
90 'Multiple lines',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
91 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
92 'text/html; charset=big5',
93 <<EOF
94 <meta
95 http-equiv="Content-Type"
96 content="text/html; charset=big5"
97 >
98 EOF
99 ], [
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
100 # FIXME - THIS IS NOT A WELL-WRITTEN TEST CASE!!!
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
101 'With surrounding HTML',
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
102 sub { guesstype($_[0]) },
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
103 'text/html; charset=us-ascii',
104 <<EOF
105 <html>
106 <head>
107 <title>Test case with surrounding HTML</title>
108 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
109 </head>
110 <body>
111 The return value should not be contaiminated with any surround HTML
112 FIXME: Auth.pm returns in code that can contaminate the charset
113 FIXME: if we do not explicitly disallow whitespace in the charset
114 </body>
115 </html>
116 EOF
117 ],
118 );
119 }
120
121 BEGIN { $| = 1; printf "1..%d\n", scalar(@tests); }
122 END {print "not ok 1\n" unless $loaded;}
123 $loaded = 1;
124
125
126 # Run all tests in sequence
127 for (my $i = 1; $i <= scalar @tests; $i += 1) {
128 my $test = $tests[$i - 1];
129 my($title, $f, $expected, $input) = @$test;
130 die "not ok $i (malformed test case)\n"
131 unless @$test == 4 && ref $f eq 'CODE';
132
133 my $output = &$f($input);
134 if (
135 (!defined $output && !defined $expected)
136 || (defined $output && defined $expected && $output eq $expected)
137 ) {
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
138 print "ok $i - $title\n";
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
139 } else {
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
140 print "not ok $i - $title: got ",
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
141 (defined $output? "\"$output\"": 'undef'),
142 ', expected ',
143 (defined $expected? "\"$expected\"": 'undef'),
52a5fd4 Moved C4/Charset.pm to C4/Interface/CGI/Output.pm
acli authored
144 "\n";
ea50c2a Preliminary fix of the CGI.pm problem of always assuming that everything...
acli authored
145 }
146 }
147
148
149
150
151
Something went wrong with that request. Please try again.