10 print "# Testing MIME::Base64-", $MIME::Base64::VERSION, "\n";
17 # This used to generate a warning
18 print "not " unless decode_base64(encode_base64("foo")) eq "foo";
19 print "ok ", $testno++, "\n";
23 print "# encode test\n";
35 ["\000\377" => "AP8="],
36 ["\377\000" => "/wA="],
37 ["\000\000\000" => "AAAA"],
40 ['Aladdin:open sesame' => 'QWxhZGRpbjpvcGVuIHNlc2FtZQ=='],
42 ['a' x 100 => 'YWFh' x 33 . 'YQ=='],
44 ['Multipurpose Internet Mail Extensions: The Base64 Content-Transfer-Encoding is designed to represent sequences of octets in a form that is not humanly readable. '
45 => "TXVsdGlwdXJwb3NlIEludGVybmV0IE1haWwgRXh0ZW5zaW9uczogVGhlIEJhc2U2NCBDb250ZW50LVRyYW5zZmVyLUVuY29kaW5nIGlzIGRlc2lnbmVkIHRvIHJlcHJlc2VudCBzZXF1ZW5jZXMgb2Ygb2N0ZXRzIGluIGEgZm9ybSB0aGF0IGlzIG5vdCBodW1hbmx5IHJlYWRhYmxlLiA="],
306 for $test (@encode_tests) {
307 my($plain, $expected) = ($$test[0], $$test[1]);
309 my $encoded = encode_base64($plain, '');
310 if ($encoded ne $expected) {
311 print "test $testno ($plain): expected $expected, got $encoded\n";
314 my $decoded = decode_base64($encoded);
315 if ($decoded ne $plain) {
316 print "test $testno ($plain): expected $expected, got $encoded\n";
320 # Try the old C versions too
321 if ($encoded ne MIME::Base64::old_encode_base64($plain, '')) {
322 print "old_encode_base64 give different result.\n";
325 if ($plain ne MIME::Base64::old_decode_base64($encoded)) {
326 print "old_decode_base64 give different result.\n";
330 print "ok $testno\n";
337 print "# decode test\n";
339 local $SIG{__WARN__} = sub { print $_[0] }; # avoid warnings on stderr
346 ["Y\nW\r\nE=" => 'aa'],
348 # These will generate some warnings
349 ['YWE=====' => 'aa'], # extra padding
350 ['YWE' => 'aa'], # missing padding
351 ['YWFh====' => 'aaa'],
358 for $test (@decode_tests) {
359 my($encoded, $expected) = ($$test[0], $$test[1]);
361 my $decoded = decode_base64($encoded);
362 if ($decoded ne $expected) {
363 die "test $testno ($encoded): expected $expected, got $decoded\n";
365 print "ok $testno\n";