summaryrefslogtreecommitdiff
path: root/ext/MIME
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-06-18 04:17:15 +0000
commitb695f709e8a342e35e482b0437eb6cdacdc58b6b (patch)
tree2d16192636e6ba806ff7a907f682c74f7705a920 /ext/MIME
parentd780cd7a0195e946e636d3ee546f6ef4f21d6acc (diff)
downloadperl-b695f709e8a342e35e482b0437eb6cdacdc58b6b.tar.gz
The Grand Trek: move the *.t files from t/ to lib/ and ext/.
No doubt I made some mistakes like missed some files or misnamed some files. The naming rules were more or less: (1) if the module is from CPAN, follows its ways, be it t/*.t or test.pl. (2) otherwise if there are multiple tests for a module put them in a t/ (3) otherwise if there's only one test put it in Module.t (4) helper files go to module/ (locale, strict, warnings) (5) use longer filenames now that we can (but e.g. the compat-0.6.t and the Text::Balanced test files still were renamed to be more civil against the 8.3 people) installperl was updated appropriately not to install the *.t files or the help files from under lib. TODO: some helper files still remain under t/ that could follow their 'masters'. UPDATE: On second thoughts, why should they. They can continue to live under t/lib, and in fact the locale/strict/warnings helpers that were moved could be moved back. This way the amount of non-installable stuff under lib/ stays smaller. p4raw-id: //depot/perl@10676
Diffstat (limited to 'ext/MIME')
-rw-r--r--ext/MIME/Base64/t/base64.t383
-rw-r--r--ext/MIME/Base64/t/qp.t113
-rw-r--r--ext/MIME/Base64/t/unicode.t16
3 files changed, 512 insertions, 0 deletions
diff --git a/ext/MIME/Base64/t/base64.t b/ext/MIME/Base64/t/base64.t
new file mode 100644
index 0000000000..7a61fe9576
--- /dev/null
+++ b/ext/MIME/Base64/t/base64.t
@@ -0,0 +1,383 @@
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+use MIME::Base64;
+
+print "1..283\n";
+
+print "# Testing MIME::Base64-", $MIME::Base64::VERSION, "\n";
+
+BEGIN {
+ if (ord('A') == 41) {
+ *ASCII = sub { return $_[0] };
+ }
+ else {
+ require Encode;
+ *ASCII = sub { Encode::encode('ascii',$_[0]) };
+ }
+}
+
+$testno = 1;
+
+encodeTest();
+decodeTest();
+
+# This used to generate a warning
+print "not " unless decode_base64(encode_base64("foo")) eq "foo";
+print "ok ", $testno++, "\n";
+
+sub encodeTest
+{
+ print "# encode test\n";
+
+ my @encode_tests = (
+ # All values
+ ["\000" => "AA=="],
+ ["\001" => "AQ=="],
+ ["\002" => "Ag=="],
+ ["\003" => "Aw=="],
+ ["\004" => "BA=="],
+ ["\005" => "BQ=="],
+ ["\006" => "Bg=="],
+ ["\007" => "Bw=="],
+ ["\010" => "CA=="],
+ ["\011" => "CQ=="],
+ ["\012" => "Cg=="],
+ ["\013" => "Cw=="],
+ ["\014" => "DA=="],
+ ["\015" => "DQ=="],
+ ["\016" => "Dg=="],
+ ["\017" => "Dw=="],
+ ["\020" => "EA=="],
+ ["\021" => "EQ=="],
+ ["\022" => "Eg=="],
+ ["\023" => "Ew=="],
+ ["\024" => "FA=="],
+ ["\025" => "FQ=="],
+ ["\026" => "Fg=="],
+ ["\027" => "Fw=="],
+ ["\030" => "GA=="],
+ ["\031" => "GQ=="],
+ ["\032" => "Gg=="],
+ ["\033" => "Gw=="],
+ ["\034" => "HA=="],
+ ["\035" => "HQ=="],
+ ["\036" => "Hg=="],
+ ["\037" => "Hw=="],
+ ["\040" => "IA=="],
+ ["\041" => "IQ=="],
+ ["\042" => "Ig=="],
+ ["\043" => "Iw=="],
+ ["\044" => "JA=="],
+ ["\045" => "JQ=="],
+ ["\046" => "Jg=="],
+ ["\047" => "Jw=="],
+ ["\050" => "KA=="],
+ ["\051" => "KQ=="],
+ ["\052" => "Kg=="],
+ ["\053" => "Kw=="],
+ ["\054" => "LA=="],
+ ["\055" => "LQ=="],
+ ["\056" => "Lg=="],
+ ["\057" => "Lw=="],
+ ["\060" => "MA=="],
+ ["\061" => "MQ=="],
+ ["\062" => "Mg=="],
+ ["\063" => "Mw=="],
+ ["\064" => "NA=="],
+ ["\065" => "NQ=="],
+ ["\066" => "Ng=="],
+ ["\067" => "Nw=="],
+ ["\070" => "OA=="],
+ ["\071" => "OQ=="],
+ ["\072" => "Og=="],
+ ["\073" => "Ow=="],
+ ["\074" => "PA=="],
+ ["\075" => "PQ=="],
+ ["\076" => "Pg=="],
+ ["\077" => "Pw=="],
+ ["\100" => "QA=="],
+ ["\101" => "QQ=="],
+ ["\102" => "Qg=="],
+ ["\103" => "Qw=="],
+ ["\104" => "RA=="],
+ ["\105" => "RQ=="],
+ ["\106" => "Rg=="],
+ ["\107" => "Rw=="],
+ ["\110" => "SA=="],
+ ["\111" => "SQ=="],
+ ["\112" => "Sg=="],
+ ["\113" => "Sw=="],
+ ["\114" => "TA=="],
+ ["\115" => "TQ=="],
+ ["\116" => "Tg=="],
+ ["\117" => "Tw=="],
+ ["\120" => "UA=="],
+ ["\121" => "UQ=="],
+ ["\122" => "Ug=="],
+ ["\123" => "Uw=="],
+ ["\124" => "VA=="],
+ ["\125" => "VQ=="],
+ ["\126" => "Vg=="],
+ ["\127" => "Vw=="],
+ ["\130" => "WA=="],
+ ["\131" => "WQ=="],
+ ["\132" => "Wg=="],
+ ["\133" => "Ww=="],
+ ["\134" => "XA=="],
+ ["\135" => "XQ=="],
+ ["\136" => "Xg=="],
+ ["\137" => "Xw=="],
+ ["\140" => "YA=="],
+ ["\141" => "YQ=="],
+ ["\142" => "Yg=="],
+ ["\143" => "Yw=="],
+ ["\144" => "ZA=="],
+ ["\145" => "ZQ=="],
+ ["\146" => "Zg=="],
+ ["\147" => "Zw=="],
+ ["\150" => "aA=="],
+ ["\151" => "aQ=="],
+ ["\152" => "ag=="],
+ ["\153" => "aw=="],
+ ["\154" => "bA=="],
+ ["\155" => "bQ=="],
+ ["\156" => "bg=="],
+ ["\157" => "bw=="],
+ ["\160" => "cA=="],
+ ["\161" => "cQ=="],
+ ["\162" => "cg=="],
+ ["\163" => "cw=="],
+ ["\164" => "dA=="],
+ ["\165" => "dQ=="],
+ ["\166" => "dg=="],
+ ["\167" => "dw=="],
+ ["\170" => "eA=="],
+ ["\171" => "eQ=="],
+ ["\172" => "eg=="],
+ ["\173" => "ew=="],
+ ["\174" => "fA=="],
+ ["\175" => "fQ=="],
+ ["\176" => "fg=="],
+ ["\177" => "fw=="],
+ ["\200" => "gA=="],
+ ["\201" => "gQ=="],
+ ["\202" => "gg=="],
+ ["\203" => "gw=="],
+ ["\204" => "hA=="],
+ ["\205" => "hQ=="],
+ ["\206" => "hg=="],
+ ["\207" => "hw=="],
+ ["\210" => "iA=="],
+ ["\211" => "iQ=="],
+ ["\212" => "ig=="],
+ ["\213" => "iw=="],
+ ["\214" => "jA=="],
+ ["\215" => "jQ=="],
+ ["\216" => "jg=="],
+ ["\217" => "jw=="],
+ ["\220" => "kA=="],
+ ["\221" => "kQ=="],
+ ["\222" => "kg=="],
+ ["\223" => "kw=="],
+ ["\224" => "lA=="],
+ ["\225" => "lQ=="],
+ ["\226" => "lg=="],
+ ["\227" => "lw=="],
+ ["\230" => "mA=="],
+ ["\231" => "mQ=="],
+ ["\232" => "mg=="],
+ ["\233" => "mw=="],
+ ["\234" => "nA=="],
+ ["\235" => "nQ=="],
+ ["\236" => "ng=="],
+ ["\237" => "nw=="],
+ ["\240" => "oA=="],
+ ["\241" => "oQ=="],
+ ["\242" => "og=="],
+ ["\243" => "ow=="],
+ ["\244" => "pA=="],
+ ["\245" => "pQ=="],
+ ["\246" => "pg=="],
+ ["\247" => "pw=="],
+ ["\250" => "qA=="],
+ ["\251" => "qQ=="],
+ ["\252" => "qg=="],
+ ["\253" => "qw=="],
+ ["\254" => "rA=="],
+ ["\255" => "rQ=="],
+ ["\256" => "rg=="],
+ ["\257" => "rw=="],
+ ["\260" => "sA=="],
+ ["\261" => "sQ=="],
+ ["\262" => "sg=="],
+ ["\263" => "sw=="],
+ ["\264" => "tA=="],
+ ["\265" => "tQ=="],
+ ["\266" => "tg=="],
+ ["\267" => "tw=="],
+ ["\270" => "uA=="],
+ ["\271" => "uQ=="],
+ ["\272" => "ug=="],
+ ["\273" => "uw=="],
+ ["\274" => "vA=="],
+ ["\275" => "vQ=="],
+ ["\276" => "vg=="],
+ ["\277" => "vw=="],
+ ["\300" => "wA=="],
+ ["\301" => "wQ=="],
+ ["\302" => "wg=="],
+ ["\303" => "ww=="],
+ ["\304" => "xA=="],
+ ["\305" => "xQ=="],
+ ["\306" => "xg=="],
+ ["\307" => "xw=="],
+ ["\310" => "yA=="],
+ ["\311" => "yQ=="],
+ ["\312" => "yg=="],
+ ["\313" => "yw=="],
+ ["\314" => "zA=="],
+ ["\315" => "zQ=="],
+ ["\316" => "zg=="],
+ ["\317" => "zw=="],
+ ["\320" => "0A=="],
+ ["\321" => "0Q=="],
+ ["\322" => "0g=="],
+ ["\323" => "0w=="],
+ ["\324" => "1A=="],
+ ["\325" => "1Q=="],
+ ["\326" => "1g=="],
+ ["\327" => "1w=="],
+ ["\330" => "2A=="],
+ ["\331" => "2Q=="],
+ ["\332" => "2g=="],
+ ["\333" => "2w=="],
+ ["\334" => "3A=="],
+ ["\335" => "3Q=="],
+ ["\336" => "3g=="],
+ ["\337" => "3w=="],
+ ["\340" => "4A=="],
+ ["\341" => "4Q=="],
+ ["\342" => "4g=="],
+ ["\343" => "4w=="],
+ ["\344" => "5A=="],
+ ["\345" => "5Q=="],
+ ["\346" => "5g=="],
+ ["\347" => "5w=="],
+ ["\350" => "6A=="],
+ ["\351" => "6Q=="],
+ ["\352" => "6g=="],
+ ["\353" => "6w=="],
+ ["\354" => "7A=="],
+ ["\355" => "7Q=="],
+ ["\356" => "7g=="],
+ ["\357" => "7w=="],
+ ["\360" => "8A=="],
+ ["\361" => "8Q=="],
+ ["\362" => "8g=="],
+ ["\363" => "8w=="],
+ ["\364" => "9A=="],
+ ["\365" => "9Q=="],
+ ["\366" => "9g=="],
+ ["\367" => "9w=="],
+ ["\370" => "+A=="],
+ ["\371" => "+Q=="],
+ ["\372" => "+g=="],
+ ["\373" => "+w=="],
+ ["\374" => "/A=="],
+ ["\375" => "/Q=="],
+ ["\376" => "/g=="],
+ ["\377" => "/w=="],
+
+ ["\000\377" => "AP8="],
+ ["\377\000" => "/wA="],
+ ["\000\000\000" => "AAAA"],
+
+ ['' => ''],
+ [ASCII('a') => 'YQ=='],
+ [ASCII('aa') => 'YWE='],
+ [ASCII('aaa') => 'YWFh'],
+
+ [ASCII('aaa') => 'YWFh'],
+ [ASCII('aaa') => 'YWFh'],
+ [ASCII('aaa') => 'YWFh'],
+
+
+ # from HTTP spec
+ [ASCII('Aladdin:open sesame') => 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='],
+
+ [ASCII('a') x 100 => 'YWFh' x 33 . 'YQ=='],
+
+ [ASCII('Multipurpose Internet Mail Extensions: The Base64 Content-Transfer-Encoding is designed to represent sequences of octets in a form that is not humanly readable. ')
+ => "TXVsdGlwdXJwb3NlIEludGVybmV0IE1haWwgRXh0ZW5zaW9uczogVGhlIEJhc2U2NCBDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nIGlzIGRlc2lnbmVkIHRvIHJlcHJlc2VudCBzZXF1ZW5jZXMgb2Ygb2N0ZXRzIGluIGEgZm9ybSB0aGF0IGlzIG5vdCBodW1hbmx5IHJlYWRhYmxlLiA="],
+
+ );
+
+ for $test (@encode_tests) {
+ my($plain, $expected) = ($$test[0], $$test[1]);
+
+ my $encoded = encode_base64($plain, '');
+ if ($encoded ne $expected) {
+ print "test $testno ($plain): expected $expected, got $encoded\n";
+ print "not ";
+ }
+ my $decoded = decode_base64($encoded);
+ if ($decoded ne $plain) {
+ print "test $testno ($encoded): expected $plain, got $decoded\n";
+ print "not ";
+ }
+
+ if (ord('A') != 193) { # perl versions broken on EBCDIC
+ # Try the old Perl versions too
+ if ($encoded ne MIME::Base64::old_encode_base64($plain, '')) {
+ print "old_encode_base64 give different result.\n";
+ print "not ";
+ }
+ if ($plain ne MIME::Base64::old_decode_base64($encoded)) {
+ print "old_decode_base64 give different result.\n";
+ print "not ";
+ }
+ }
+
+ print "ok $testno\n";
+ $testno++;
+ }
+}
+
+sub decodeTest
+{
+ print "# decode test\n";
+
+ local $SIG{__WARN__} = sub { print $_[0] }; # avoid warnings on stderr
+
+ my @decode_tests = (
+ ['YWE=' => ASCII('aa')],
+ [' YWE=' => ASCII('aa')],
+ ['Y WE=' => ASCII('aa')],
+ ['YWE= ' => ASCII('aa')],
+ ["Y\nW\r\nE=" => ASCII('aa')],
+
+ # These will generate some warnings
+ ['YWE=====' => ASCII('aa')], # extra padding
+ ['YWE' => ASCII('aa')], # missing padding
+ ['YWFh====' => ASCII('aaa')],
+ ['YQ' => ASCII('a')],
+ ['Y' => ''],
+ ['x==' => ''],
+ ['' => ''],
+ [undef() => ''],
+ );
+
+ for $test (@decode_tests) {
+ my($encoded, $expected) = ($$test[0], $$test[1]);
+
+ my $decoded = decode_base64($encoded);
+ if ($decoded ne $expected) {
+ die "test $testno ($encoded): expected $expected, got $decoded\n";
+ }
+ print "ok $testno\n";
+ $testno++;
+ }
+}
diff --git a/ext/MIME/Base64/t/qp.t b/ext/MIME/Base64/t/qp.t
new file mode 100644
index 0000000000..1a7f9e4550
--- /dev/null
+++ b/ext/MIME/Base64/t/qp.t
@@ -0,0 +1,113 @@
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+use MIME::QuotedPrint;
+
+$x70 = "x" x 70;
+
+@tests =
+ (
+ # plain ascii should not be encoded
+ ["quoted printable" =>
+ "quoted printable"],
+
+ # 8-bit chars should be encoded
+ ["v\xe5re kj\xe6re norske tegn b\xf8r \xe6res" =>
+ "v=E5re kj=E6re norske tegn b=F8r =E6res"],
+
+ # trailing space should be encoded
+ [" " => "=20=20"],
+ ["\tt\t" => "\tt=09"],
+ ["test \ntest\n\t \t \n" => "test=20=20\ntest\n=09=20=09=20\n"],
+
+ # "=" is special an should be decoded
+ ["=\n" => "=3D\n"],
+ ["\0\xff" => "=00=FF"],
+
+ # Very long lines should be broken (not more than 76 chars
+ ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." =>
+ "The Quoted-Printable encoding is intended to represent data that largly con=
+sists of octets that correspond to printable characters in the ASCII charac=
+ter set."
+ ],
+
+ # Long lines after short lines were broken through 2.01.
+ ["short line
+In America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" =>
+ "short line
+In America, any boy may become president and I suppose that's just one of t=
+he risks he takes. -- Adlai Stevenson"],
+
+ # My (roderick@argon.org) first crack at fixing that bug failed for
+ # multiple long lines.
+ ["College football is a game which would be much more interesting if the faculty played instead of the students, and even more interesting if the
+trustees played. There would be a great increase in broken arms, legs, and necks, and simultaneously an appreciable diminution in the loss to humanity. -- H. L. Mencken" =>
+ "College football is a game which would be much more interesting if the facu=
+lty played instead of the students, and even more interesting if the
+trustees played. There would be a great increase in broken arms, legs, and=
+ necks, and simultaneously an appreciable diminution in the loss to humanit=
+y. -- H. L. Mencken"],
+
+ # Don't break a line that's near but not over 76 chars.
+ ["$x70!23" => "$x70!23"],
+ ["$x70!234" => "$x70!234"],
+ ["$x70!2345" => "$x70!2345"],
+ ["$x70!23456" => "$x70!23456"],
+ ["$x70!23\n" => "$x70!23\n"],
+ ["$x70!234\n" => "$x70!234\n"],
+ ["$x70!2345\n" => "$x70!2345\n"],
+ ["$x70!23456\n" => "$x70!23456\n"],
+
+ # Not allowed to break =XX escapes using soft line break
+ ["$x70===xxxx" => "$x70=3D=\n=3D=3Dxxxx"],
+ ["$x70!===xxx" => "$x70!=3D=\n=3D=3Dxxx"],
+ ["$x70!!===xx" => "$x70!!=3D=\n=3D=3Dxx"],
+ ["$x70!!!===x" => "$x70!!!=\n=3D=3D=3Dx"],
+ # ^
+ # 70123456|
+ # max
+ # line width
+);
+
+$notests = @tests + 2;
+print "1..$notests\n";
+
+$testno = 0;
+for (@tests) {
+ $testno++;
+ ($plain, $encoded) = @$_;
+ if (ord('A') == 193) { # EBCDIC 8 bit chars are different
+ if ($testno == 2) { $plain =~ s/\xe5/\x47/; $plain =~ s/\xe6/\x9c/g; $plain =~ s/\xf8/\x70/; }
+ if ($testno == 7) { $plain =~ s/\xff/\xdf/; }
+ }
+ $x = encode_qp($plain);
+ if ($x ne $encoded) {
+ print "Encode test failed\n";
+ print "Got: '$x'\n";
+ print "Expected: '$encoded'\n";
+ print "not ok $testno\n";
+ next;
+ }
+ $x = decode_qp($encoded);
+ if ($x ne $plain) {
+ print "Decode test failed\n";
+ print "Got: '$x'\n";
+ print "Expected: '$plain'\n";
+ print "not ok $testno\n";
+ next;
+ }
+ print "ok $testno\n";
+}
+
+# Some extra testing for a case that was wrong until libwww-perl-5.09
+print "not " unless decode_qp("foo \n\nfoo =\n\nfoo=20\n\n") eq
+ "foo\n\nfoo \nfoo \n\n";
+$testno++; print "ok $testno\n";
+
+# Same test but with "\r\n" terminated lines
+print "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq
+ "foo\r\n\r\nfoo \r\nfoo \r\n\r\n";
+$testno++; print "ok $testno\n";
+
diff --git a/ext/MIME/Base64/t/unicode.t b/ext/MIME/Base64/t/unicode.t
new file mode 100644
index 0000000000..0b8df1ae7c
--- /dev/null
+++ b/ext/MIME/Base64/t/unicode.t
@@ -0,0 +1,16 @@
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+}
+
+print "1..1\n";
+
+require MIME::Base64;
+
+eval {
+ MIME::Base64::encode(v300);
+};
+
+print "not " unless $@;
+print "ok 1\n";
+