xref: /freebsd/contrib/netbsd-tests/usr.bin/gzip/t_gzip.sh (revision cfd6422a5217410fbd66f7a7a8a64d9d85e61229)
1# $NetBSD: t_gzip.sh,v 1.1 2012/03/17 16:33:13 jruoho Exp $
2#
3# Copyright (c) 2008 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28atf_test_case concatenated
29concatenated_head()
30{
31	atf_set "descr" "Checks concatenated gzipped data"
32}
33concatenated_body()
34{
35	echo -n "aaaa" | gzip > tmp.gz
36	echo -n "bbbb" | gzip >> tmp.gz
37
38	atf_check -o inline:"aaaabbbb" gzip -d tmp.gz -c
39}
40
41atf_test_case pipe
42pipe_head()
43{
44	atf_set "descr" "Checks input from pipe"
45}
46pipe_body()
47{
48	atf_check -x "dd if=/dev/zero count=102400 2>/dev/null \
49| gzip -c | dd bs=1 2>/dev/null | gzip -tc"
50}
51
52atf_test_case truncated
53truncated_head()
54{
55	atf_set "descr" "Checks that gzip fails on truncated data"
56}
57truncated_body()
58{
59	cat >truncated.gz.uue <<EOF
60begin-base64 644 truncated.gz
61H4sIAAAAAAAAA0tMSk7hAgCspIpYCg==
62====
63EOF
64	uudecode -m truncated.gz.uue
65
66	atf_check -s ne:0 -e ignore gzip -d truncated.gz
67}
68
69atf_test_case crcerror
70crcerror_head()
71{
72	atf_set "descr" "Checks that gzip fails on crc error"
73}
74crcerror_body()
75{
76	cat >crcerror.gz.uue <<EOF
77begin-base64 644 crcerror.gz
78H4sIAAAAAAAAA0tMSk7hAgCspFhYBQAAAA==
79====
80EOF
81	uudecode -m crcerror.gz.uue
82
83	atf_check -s ne:0 -e ignore gzip -d crcerror.gz
84}
85
86atf_test_case good
87good_head()
88{
89	atf_set "descr" "Checks decompressing correct file"
90}
91good_body()
92{
93	cat >good.gz.uue <<EOF
94begin-base64 644 good.gz
95H4sICC8G8UAAA2FiY2QAS0xKTuECAKykilgFAAAA
96====
97EOF
98	uudecode -m good.gz.uue
99
100	atf_check gzip -d good.gz
101}
102
103atf_init_test_cases()
104{
105	atf_add_test_case concatenated
106	atf_add_test_case pipe
107	atf_add_test_case truncated
108	atf_add_test_case crcerror
109	atf_add_test_case good
110}
111