5 # Copyright (C) 2006, 2007 Free Software Foundation, Inc.
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $PERL -e 1 > /dev/null 2>&1 || {
26 echo 1>&2 "$0: configure didn't find a usable version of Perl," \
27 "so can't run this test"
31 exec $PERL -w -I$srcdir/.. -MCoreutils -- - <<\EOF
35 (my $program_name = $0) =~ s|.*/||;
37 # Turn off localisation of executable's ouput.
38 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
40 # Return the encoding of a string of N 'a's.
44 my %remainder = ( 0 => '', 1 => 'YQ==', 2 => 'YWE=' );
45 return 'YWFh' x ($n / 3) . $remainder{$n % 3};
48 # Construct an encoded string of length 4KB, using 3K "a"s.
51 # A few copies, each with different number of newlines at the start.
54 (my $t = $a3k) =~ s/^/"\n"x $k/e;
58 # Return a copy of S, with newlines inserted every WIDTH bytes.
59 # Ensure that the result (if not the empty string) is newline-terminated.
63 $s =~ s/(.{$width})/$1\n/g;
64 substr ($s, -1, 1) ne "\n"
71 ['empty', {IN=>''}, {OUT=>""}],
72 ['inout', {IN=>'a'}, {OUT=>"YQ==\n"}],
73 ['wrap', '--wrap 0', {IN=>'foo'}, {OUT=>'Zm9v'}],
74 ['wrap5-39', '--wrap=5', {IN=>'a' x 39}, {OUT=>wrap enc(39),5}],
75 ['wrap5-40', '--wrap=5', {IN=>'a' x 40}, {OUT=>wrap enc(40),5}],
76 ['wrap5-41', '--wrap=5', {IN=>'a' x 41}, {OUT=>wrap enc(41),5}],
77 ['wrap5-42', '--wrap=5', {IN=>'a' x 42}, {OUT=>wrap enc(42),5}],
78 ['wrap5-43', '--wrap=5', {IN=>'a' x 43}, {OUT=>wrap enc(43),5}],
79 ['wrap5-44', '--wrap=5', {IN=>'a' x 44}, {OUT=>wrap enc(44),5}],
80 ['wrap5-45', '--wrap=5', {IN=>'a' x 45}, {OUT=>wrap enc(45),5}],
81 ['wrap5-46', '--wrap=5', {IN=>'a' x 46}, {OUT=>wrap enc(46),5}],
83 ['buf-1', '--decode', {IN=>enc 1}, {OUT=>'a' x 1}],
84 ['buf-2', '--decode', {IN=>enc 2}, {OUT=>'a' x 2}],
85 ['buf-3', '--decode', {IN=>enc 3}, {OUT=>'a' x 3}],
86 ['buf-4', '--decode', {IN=>enc 4}, {OUT=>'a' x 4}],
88 ['buf-4k0', '--decode', {IN=>enc 3072+0}, {OUT=>'a' x (3072+0)}],
89 ['buf-4k1', '--decode', {IN=>enc 3072+1}, {OUT=>'a' x (3072+1)}],
90 ['buf-4k2', '--decode', {IN=>enc 3072+2}, {OUT=>'a' x (3072+2)}],
91 ['buf-4k3', '--decode', {IN=>enc 3072+3}, {OUT=>'a' x (3072+3)}],
92 ['buf-4km1','--decode', {IN=>enc 3072-1}, {OUT=>'a' x (3072-1)}],
93 ['buf-4km2','--decode', {IN=>enc 3072-2}, {OUT=>'a' x (3072-2)}],
94 ['buf-4km3','--decode', {IN=>enc 3072-3}, {OUT=>'a' x (3072-3)}],
95 ['buf-4km4','--decode', {IN=>enc 3072-4}, {OUT=>'a' x (3072-4)}],
97 # Exercise the case in which the final base-64 byte is
98 # in a buffer all by itself.
99 ['b4k-1', '--decode', {IN=>$a3k_nl[1]}, {OUT=>'a' x (3072+0)}],
100 ['b4k-2', '--decode', {IN=>$a3k_nl[2]}, {OUT=>'a' x (3072+0)}],
101 ['b4k-3', '--decode', {IN=>$a3k_nl[3]}, {OUT=>'a' x (3072+0)}],
103 ['baddecode', '--decode', {IN=>'a'}, {OUT=>""},
104 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
105 ['baddecode2', '--decode', {IN=>'ab'}, {OUT=>"i"},
106 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
107 ['baddecode3', '--decode', {IN=>'Zzz'}, {OUT=>"g<"},
108 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
109 ['baddecode4', '--decode', {IN=>'Zz='}, {OUT=>"g"},
110 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}],
111 ['baddecode5', '--decode', {IN=>'Z==='}, {OUT=>""},
112 {ERR_SUBST => 's/.*: invalid input//'}, {ERR => "\n"}, {EXIT => 1}]
115 # For each non-failing test, create a --decode test using the
116 # expected output as input. Also, add tests inserting newlines.
118 foreach my $t (@Tests)
124 # If the test has a single option of "--decode", then skip it.
125 !ref $t->[1] && $t->[1] eq '--decode'
130 ref $e && ref $e eq 'HASH'
133 and $exit_val = $e->{EXIT};
136 if (defined $e->{OUT})
141 foreach my $i (0..$len)
144 substr ($u, $i, 0) = "\n";
157 push @new, ["d$i-$t->[0]", '--decode', {IN => $o}, {OUT => $in}];
163 my $save_temps = $ENV{DEBUG};
164 my $verbose = $ENV{VERBOSE};
166 my $prog = $ENV{PROG} || die "$0: \$PROG not specified in environment\n";
167 my $fail = run_tests ($program_name, $prog, \@Tests, $save_temps, $verbose);