Home | History | Annotate | Line # | Download | only in gzip
      1  1.1  christos #!/bin/sh
      2  1.1  christos # Ensure that gzip -cdf handles mixed compressed/not-compressed data
      3  1.1  christos # Before gzip-1.5, it would produce invalid output.
      4  1.1  christos 
      5  1.1  christos # Copyright (C) 2010-2016 Free Software Foundation, Inc.
      6  1.1  christos 
      7  1.1  christos # This program is free software: you can redistribute it and/or modify
      8  1.1  christos # it under the terms of the GNU General Public License as published by
      9  1.1  christos # the Free Software Foundation, either version 3 of the License, or
     10  1.1  christos # (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos # This program is distributed in the hope that it will be useful,
     13  1.1  christos # but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos # GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos # You should have received a copy of the GNU General Public License
     18  1.1  christos # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19  1.1  christos # limit so don't run it by default.
     20  1.1  christos 
     21  1.1  christos . "${srcdir=.}/init.sh"; path_prepend_ .
     22  1.1  christos 
     23  1.1  christos printf 'xxx\nyyy\n'      > exp2 || framework_failure_
     24  1.1  christos printf 'aaa\nbbb\nccc\n' > exp3 || framework_failure_
     25  1.1  christos 
     26  1.1  christos fail=0
     27  1.1  christos 
     28  1.1  christos (echo xxx; echo yyy) > in || fail=1
     29  1.1  christos gzip -cdf < in > out || fail=1
     30  1.1  christos compare exp2 out || fail=1
     31  1.1  christos 
     32  1.1  christos # Uncompressed input, followed by compressed data.
     33  1.1  christos # Currently fails, so skip it.
     34  1.1  christos # (echo xxx; echo yyy|gzip) > in || fail=1
     35  1.1  christos # gzip -cdf < in > out || fail=1
     36  1.1  christos # compare exp2 out || fail=1
     37  1.1  christos 
     38  1.1  christos # Compressed input, followed by regular (not-compressed) data.
     39  1.1  christos (echo xxx|gzip; echo yyy) > in || fail=1
     40  1.1  christos gzip -cdf < in > out || fail=1
     41  1.1  christos compare exp2 out || fail=1
     42  1.1  christos 
     43  1.1  christos (echo xxx|gzip; echo yyy|gzip) > in || fail=1
     44  1.1  christos gzip -cdf < in > out || fail=1
     45  1.1  christos compare exp2 out || fail=1
     46  1.1  christos 
     47  1.1  christos in_str=0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-+=%
     48  1.1  christos for i in 0 1 2 3 4 5 6 7 8 9 a; do in_str="$in_str$in_str" ;done
     49  1.1  christos 
     50  1.1  christos # Start with some small sizes.  $(seq 64)
     51  1.1  christos sizes=$(i=0; while :; do echo $i; test $i = 64 && break; i=$(expr $i + 1); done)
     52  1.1  christos 
     53  1.1  christos # gzip's internal buffer size is 32KiB + 64 bytes:
     54  1.1  christos sizes="$sizes 32831 32832 32833"
     55  1.1  christos 
     56  1.1  christos # 128KiB, +/- 1
     57  1.1  christos sizes="$sizes 131071 131072 131073"
     58  1.1  christos 
     59  1.1  christos # Ensure that "gzip -cdf" acts like cat, for a range of small input files.
     60  1.1  christos i=0
     61  1.1  christos for i in $sizes; do
     62  1.1  christos   echo $i
     63  1.1  christos   printf %$i.${i}s $in_str > in
     64  1.1  christos   gzip -cdf < in > out
     65  1.1  christos   compare in out || fail=1
     66  1.1  christos done
     67  1.1  christos 
     68  1.1  christos Exit $fail
     69