1N/ABEGIN {
1N/A if ($ENV{PERL_CORE}) {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A }
1N/A}
1N/A
1N/Ause MIME::QuotedPrint;
1N/A
1N/A$x70 = "x" x 70;
1N/A
1N/A@tests =
1N/A (
1N/A # plain ascii should not be encoded
1N/A ["quoted printable" =>
1N/A "quoted printable"],
1N/A
1N/A # 8-bit chars should be encoded
1N/A ["v\xe5re kj\xe6re norske tegn b\xf8r \xe6res" =>
1N/A "v=E5re kj=E6re norske tegn b=F8r =E6res"],
1N/A
1N/A # trailing space should be encoded
1N/A [" " => "=20=20"],
1N/A ["\tt\t" => "\tt=09"],
1N/A ["test \ntest\n\t \t \n" => "test=20=20\ntest\n=09=20=09=20\n"],
1N/A
1N/A # "=" is special an should be decoded
1N/A ["=30\n" => "=3D30\n"],
1N/A ["\0\xff0" => "=00=FF0"],
1N/A
1N/A # Very long lines should be broken (not more than 76 chars
1N/A ["The Quoted-Printable encoding is intended to represent data that largly consists of octets that correspond to printable characters in the ASCII character set." =>
1N/A "The Quoted-Printable encoding is intended to represent data that largly con=
1N/Asists of octets that correspond to printable characters in the ASCII charac=
1N/Ater set."
1N/A ],
1N/A
1N/A # Long lines after short lines were broken through 2.01.
1N/A ["short line
1N/AIn America, any boy may become president and I suppose that's just one of the risks he takes. -- Adlai Stevenson" =>
1N/A "short line
1N/AIn America, any boy may become president and I suppose that's just one of t=
1N/Ahe risks he takes. -- Adlai Stevenson"],
1N/A
1N/A # My (roderick@argon.org) first crack at fixing that bug failed for
1N/A # multiple long lines.
1N/A ["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
1N/Atrustees 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" =>
1N/A "College football is a game which would be much more interesting if the facu=
1N/Alty played instead of the students, and even more interesting if the
1N/Atrustees played. There would be a great increase in broken arms, legs, and=
1N/A necks, and simultaneously an appreciable diminution in the loss to humanit=
1N/Ay. -- H. L. Mencken"],
1N/A
1N/A # Don't break a line that's near but not over 76 chars.
1N/A ["$x70!23" => "$x70!23"],
1N/A ["$x70!234" => "$x70!234"],
1N/A ["$x70!2345" => "$x70!2345"],
1N/A ["$x70!23456" => "$x70!23456"],
1N/A ["$x70!234567" => "$x70!2345=\n67"],
1N/A ["$x70!23456=" => "$x70!2345=\n6=3D"],
1N/A ["$x70!23\n" => "$x70!23\n"],
1N/A ["$x70!234\n" => "$x70!234\n"],
1N/A ["$x70!2345\n" => "$x70!2345\n"],
1N/A ["$x70!23456\n" => "$x70!23456\n"],
1N/A ["$x70!234567\n" => "$x70!2345=\n67\n"],
1N/A ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"],
1N/A
1N/A # Not allowed to break =XX escapes using soft line break
1N/A ["$x70===xxxxx" => "$x70=3D=\n=3D=3Dxxxxx"],
1N/A ["$x70!===xxxx" => "$x70!=3D=\n=3D=3Dxxxx"],
1N/A ["$x70!2===xxx" => "$x70!2=3D=\n=3D=3Dxxx"],
1N/A ["$x70!23===xx" => "$x70!23=\n=3D=3D=3Dxx"],
1N/A ["$x70!234===x" => "$x70!234=\n=3D=3D=3Dx"],
1N/A ["$x70!2=\n" => "$x70!2=3D\n"],
1N/A ["$x70!23=\n" => "$x70!23=\n=3D\n"],
1N/A ["$x70!234=\n" => "$x70!234=\n=3D\n"],
1N/A ["$x70!2345=\n" => "$x70!2345=\n=3D\n"],
1N/A ["$x70!23456=\n" => "$x70!2345=\n6=3D\n"],
1N/A # ^
1N/A # 70123456|
1N/A # max
1N/A # line width
1N/A
1N/A # some extra special cases we have had problems with
1N/A ["$x70!2=x=x" => "$x70!2=3D=\nx=3Dx"],
1N/A ["$x70!2345$x70!2345$x70!23456\n", "$x70!2345=\n$x70!2345=\n$x70!23456\n"],
1N/A
1N/A # trailing whitespace
1N/A ["foo \t ", "foo=20=09=20"],
1N/A ["foo\t \n \t", "foo=09=20\n=20=09"],
1N/A);
1N/A
1N/A$notests = @tests + 13;
1N/Aprint "1..$notests\n";
1N/A
1N/A$testno = 0;
1N/Afor (@tests) {
1N/A $testno++;
1N/A ($plain, $encoded) = @$_;
1N/A if (ord('A') == 193) { # EBCDIC 8 bit chars are different
1N/A if ($testno == 2) { $plain =~ s/\xe5/\x47/; $plain =~ s/\xe6/\x9c/g; $plain =~ s/\xf8/\x70/; }
1N/A if ($testno == 7) { $plain =~ s/\xff/\xdf/; }
1N/A }
1N/A $x = encode_qp($plain);
1N/A if ($x ne $encoded) {
1N/A print "Encode test failed\n";
1N/A print "Got: '$x'\n";
1N/A print "Expected: '$encoded'\n";
1N/A print "not ok $testno\n";
1N/A next;
1N/A }
1N/A $x = decode_qp($encoded);
1N/A if ($x ne $plain) {
1N/A print "Decode test failed\n";
1N/A print "Got: '$x'\n";
1N/A print "Expected: '$plain'\n";
1N/A print "not ok $testno\n";
1N/A next;
1N/A }
1N/A print "ok $testno\n";
1N/A}
1N/A
1N/A# Some extra testing for a case that was wrong until libwww-perl-5.09
1N/Aprint "not " unless decode_qp("foo \n\nfoo =\n\nfoo=20\n\n") eq
1N/A "foo\n\nfoo \nfoo \n\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/A# Same test but with "\r\n" terminated lines
1N/Aprint "not " unless decode_qp("foo \r\n\r\nfoo =\r\n\r\nfoo=20\r\n\r\n") eq
1N/A "foo\n\nfoo \nfoo \n\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/A# Trailing whitespace
1N/Aprint "not " unless decode_qp("foo ") eq "foo ";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo \n") eq "foo\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo = \t\x20\nbar\t\x20\n") eq "foo bar\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo = \t\x20\r\nbar\t\x20\r\n") eq "foo bar\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo = \t\x20\n") eq "foo ";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo = \t\x20\r\n") eq "foo ";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo = \t\x20y\r\n") eq "foo = \t\x20y\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " unless decode_qp("foo =xy\n") eq "foo =xy\n";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/A# Test with with alternative line break
1N/Aprint "not " unless encode_qp("$x70!2345$x70\n", "***") eq "$x70!2345=***$x70***";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/A# Test with no line breaks
1N/Aprint "not " unless encode_qp("$x70!2345$x70\n", "") eq "$x70!2345$x70=0A";
1N/A$testno++; print "ok $testno\n";
1N/A
1N/Aprint "not " if $] >= 5.006 && (eval 'encode_qp("XXX \x{100}")' || !$@);
1N/A$testno++; print "ok $testno\n";