5b21d50f5854791e06b60a6424c069a170da3ddc
[pspp] / tests / libpspp / zip.at
1 dnl PSPP - a program for statistical analysis.
2 dnl Copyright (C) 2017 Free Software Foundation, Inc.
3 dnl
4 dnl This program is free software: you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation, either version 3 of the License, or
7 dnl (at your option) any later version.
8 dnl
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 dnl
17 AT_BANNER([zip])
18
19 AT_SETUP([basic zip - unzip test])
20 AT_KEYWORDS([compression])
21 here=`pwd`
22 dir1=$here/original
23 dir2=$here/recovered
24
25 mkdir -p "$dir1"
26
27 # Generate files of differing sizes with random data in them
28 names=""
29 s=1;
30 while test $s -le 8192 ; do
31         name="$dir1/$s"
32         dd if=/dev/urandom of="$name" count=1 bs=$s 2> /dev/null
33         s=$(($s * 2));
34         bn=`basename "$name"`;
35         names="$names $bn";
36 done
37
38 AT_CHECK([cd "$dir1" && zip-test w foo.zip $names])
39
40 # If zipinfo is installed, make sure it can read the zipfile.
41 if (zipinfo -v) >/dev/null 2>&1; then
42     AT_CHECK([zipinfo "$dir1/foo.zip"], [0], [ignore])
43 fi
44
45 mkdir -p "$dir2"
46 cp "$dir1/foo.zip" "$dir2"
47 cd "$dir2"
48
49 AT_CHECK([zip-test r foo.zip $names])
50
51 AT_CHECK([
52     # Compare the files to their originals
53     for f in $names; do
54      diff "$dir1/$f" "$dir2/$f";
55      if test $? -ne 0 ; then exit 1; fi;
56     done
57 ])
58 AT_CLEANUP
59
60
61 AT_SETUP([zip to pipe])
62 AT_KEYWORDS([compression])
63 here=`pwd`
64 dir1=$here/original
65 dir2=$here/recovered
66
67 mkdir -p "$dir1"
68
69 # Generate files of differing sizes with random data in them
70 names=""
71 s=1;
72 while test $s -le 8192 ; do
73         name="$dir1/$s"
74         dd if=/dev/urandom of="$name" count=1 bs=$s 2> /dev/null
75         s=$(($s * 2));
76         bn=`basename "$name"`;
77         names="$names $bn";
78 done
79
80 # The pipe through "cat" below is essential because it makes the
81 # output file un-seekable.
82 AT_CHECK([cd "$dir1" && zip-test w - $names | cat > foo.zip])
83
84 # If zipinfo is installed, make sure it can read the zipfile.
85 if (zipinfo -v) >/dev/null 2>&1; then
86     AT_CHECK([zipinfo "$dir1/foo.zip"], [0], [ignore])
87 fi
88
89 mkdir -p "$dir2"
90 cp "$dir1/foo.zip" "$dir2"
91 cd "$dir2"
92
93 AT_CHECK([zip-test r foo.zip $names])
94
95 AT_CHECK([
96     # Compare the files to their originals
97     for f in $names; do
98      diff "$dir1/$f" "$dir2/$f";
99      if test $? -ne 0 ; then exit 1; fi;
100     done
101 ])
102 AT_CLEANUP