Commit | Line | Data |
fdd579e2 |
1 | # |
77ea6967 |
2 | # $Id: Encoder.t,v 1.2 2002/04/10 22:28:40 dankogai Exp $ |
fdd579e2 |
3 | # |
4 | |
5 | BEGIN { |
6 | require Config; import Config; |
7 | if ($Config{'extensions'} !~ /\bEncode\b/) { |
8 | print "1..0 # Skip: Encode was not built\n"; |
9 | exit 0; |
10 | } |
11 | # should work without perlio |
12 | # unless (find PerlIO::Layer 'perlio') { |
13 | # print "1..0 # Skip: PerlIO was not built\n"; |
14 | # exit 0; |
15 | # } |
16 | # should work on EBCDIC |
17 | # if (ord("A") == 193) { |
18 | # print "1..0 # Skip: EBCDIC\n"; |
19 | # exit 0; |
20 | # } |
21 | $| = 1; |
22 | } |
23 | |
24 | use strict; |
25 | #use Test::More 'no_plan'; |
448e90bb |
26 | use Test::More tests => 516; |
27 | use Encode::Encoder qw(encoder); |
fdd579e2 |
28 | use MIME::Base64; |
29 | package Encode::Base64; |
30 | use base 'Encode::Encoding'; |
31 | __PACKAGE__->Define('base64'); |
32 | use MIME::Base64; |
33 | sub encode{ |
34 | my ($obj, $data) = @_; |
35 | return encode_base64($data); |
36 | } |
37 | sub decode{ |
38 | my ($obj, $data) = @_; |
39 | return decode_base64($data); |
40 | } |
41 | |
42 | package main; |
43 | |
448e90bb |
44 | my $e = encoder("foo", "ascii"); |
45 | ok ($e->data("bar")); |
46 | is ($e->data, "bar"); |
47 | ok ($e->encoding("latin1")); |
48 | is ($e->encoding, "iso-8859-1"); |
49 | |
fdd579e2 |
50 | my $data = ''; |
51 | for my $i (0..255){ |
52 | no warnings; |
53 | $data .= chr($i); |
54 | my $base64 = encode_base64($data); |
55 | is(encoder($data)->base64, $base64, "encode"); |
56 | is(encoder($base64)->bytes('base64'), $data, "decode"); |
57 | } |
58 | |
59 | 1; |
60 | __END__ |