lib/getopt*.c: Include <config.h> only HAVE_CONFIG_H is defined.
[xz.git] / tests / test_files.sh
blob60402e73a344a34b26efdc9f50cfd15ec5e0dca9
1 #!/bin/sh
3 ###############################################################################
5 # Author: Lasse Collin
7 # This file has been put into the public domain.
8 # You can do whatever you want with this file.
10 ###############################################################################
12 # If both xz and xzdec were not build, skip this test.
13 XZ=../src/xz/xz
14 XZDEC=../src/xzdec/xzdec
15 test -x "$XZ" || XZ=
16 test -x "$XZDEC" || XZDEC=
17 if test -z "$XZ$XZDEC"; then
18 echo "xz and xzdec were not built, skipping this test."
19 exit 77
22 # If decompression support is missing, this test is skipped.
23 # This isn't perfect as if only some decompressors are disabled
24 # then some good files might not decompress and the test fails
25 # for a (kind of) wrong reason.
26 if grep 'define HAVE_DECODERS' ../config.h > /dev/null ; then
28 else
29 echo "Decompression support is disabled, skipping this test."
30 exit 77
33 # If a feature was disabled at build time, make it possible to skip
34 # some of the test files. Use exit status 77 if any files were skipped.
35 EXIT_STATUS=0
36 have_feature()
38 grep "define HAVE_$1 1" ../config.h > /dev/null && return 0
39 printf '%s: Skipping because HAVE_%s is not enabled\n' "$2" "$1"
40 EXIT_STATUS=77
41 return 1
45 #######
46 # .xz #
47 #######
49 # If these integrity check types were disabled at build time,
50 # allow the tests to pass still.
51 NO_WARN=
52 grep 'define HAVE_CHECK_CRC64' ../config.h > /dev/null || NO_WARN=-qQ
53 grep 'define HAVE_CHECK_SHA256' ../config.h > /dev/null || NO_WARN=-qQ
55 for I in "$srcdir"/files/good-*.xz
57 # If features were disabled at build time, keep this still working.
58 case $I in
59 */good-1-*delta-lzma2*.xz)
60 have_feature DECODER_DELTA "$I" || continue
62 esac
63 case $I in
64 */good-1-empty-bcj-lzma2.xz)
65 have_feature DECODER_POWERPC "$I" || continue
67 esac
68 case $I in
69 */good-1-sparc-lzma2.xz)
70 have_feature DECODER_SPARC "$I" || continue
72 esac
73 case $I in
74 */good-1-x86-lzma2.xz)
75 have_feature DECODER_X86 "$I" || continue
77 esac
78 case $I in
79 */good-1-arm64-lzma2-*.xz)
80 have_feature DECODER_ARM64 "$I" || continue
82 esac
84 if test -z "$XZ" || "$XZ" $NO_WARN -dc "$I" > /dev/null; then
86 else
87 echo "Good file failed: $I"
88 exit 1
91 if test -z "$XZDEC" || "$XZDEC" $NO_WARN "$I" > /dev/null; then
93 else
94 echo "Good file failed: $I"
95 exit 1
97 done
99 for I in "$srcdir"/files/bad-*.xz
101 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
102 echo "Bad file succeeded: $I"
103 exit 1
106 # xzdec doesn't warn about unsupported check so skip this if any of
107 # the check types were disabled at built time (NO_WARN isn't empty).
108 if test -n "$XZDEC" && test -z "$NO_WARN" \
109 && "$XZDEC" "$I" > /dev/null 2>&1; then
110 echo "Bad file succeeded: $I"
111 exit 1
113 done
115 # Testing for the lzma_index_append() bug in <= 5.2.6 needs "xz -l":
116 I="$srcdir/files/bad-3-index-uncomp-overflow.xz"
117 if test -n "$XZ" && "$XZ" -l "$I" > /dev/null 2>&1; then
118 echo "Bad file succeeded with xz -l: $I"
119 exit 1
122 for I in "$srcdir"/files/unsupported-*.xz
124 # Test these only with xz as unsupported-check.xz will exit
125 # successfully with xzdec because it doesn't warn about
126 # unsupported check type.
127 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
128 echo "Unsupported file succeeded: $I"
129 exit 1
131 done
133 # Test that this passes with --no-warn (-Q).
134 I="$srcdir/files/unsupported-check.xz"
135 if test -z "$XZ" || "$XZ" -dcqQ "$I" > /dev/null; then
137 else
138 echo "Unsupported file failed with xz -Q: $I"
139 exit 1
142 if test -z "$XZDEC" || "$XZDEC" -qQ "$I" > /dev/null; then
144 else
145 echo "Unsupported file failed with xzdec -Q: $I"
146 exit 1
150 #########
151 # .lzma #
152 #########
154 for I in "$srcdir"/files/good-*.lzma
156 if test -z "$XZ" || "$XZ" -dc "$I" > /dev/null; then
158 else
159 echo "Good file failed: $I"
160 exit 1
162 done
164 for I in "$srcdir"/files/bad-*.lzma
166 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
167 echo "Bad file succeeded: $I"
168 exit 1
170 done
173 #######
174 # .lz #
175 #######
177 if have_feature LZIP_DECODER ".lz files" ; then
178 for I in "$srcdir"/files/good-*.lz
180 if test -z "$XZ" || "$XZ" -dc "$I" > /dev/null; then
182 else
183 echo "Good file failed: $I"
184 exit 1
186 done
188 for I in "$srcdir"/files/bad-*.lz "$srcdir"/files/unsupported-*.lz
190 if test -n "$XZ" && "$XZ" -dc "$I" > /dev/null 2>&1; then
191 echo "Bad file succeeded: $I"
192 exit 1
194 done
197 exit "$EXIT_STATUS"