xref: /freebsd/usr.bin/compress/tests/compress_test.sh (revision 25ecdc7d52770caf1c9b44b5ec11f468f6b636f3)
1# Copyright (c) 2017 Jilles Tjoelker <jilles@FreeBSD.org>
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions
6# are met:
7# 1. Redistributions of source code must retain the above copyright
8#    notice, this list of conditions and the following disclaimer.
9# 2. Redistributions in binary form must reproduce the above copyright
10#    notice, this list of conditions and the following disclaimer in the
11#    documentation and/or other materials provided with the distribution.
12#
13# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23# SUCH DAMAGE.
24#
25# $FreeBSD$
26
27atf_test_case uncompress_file_1
28uncompress_file_1_head()
29{
30	atf_set "descr" \
31	    "Test uncompress without options, filename with .Z"
32}
33uncompress_file_1_body()
34{
35	printf '%01000d\n' 7 >expectfile1
36	printf "\
37\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
38\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
39\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
40\050\123\252\134\211\360\206\002" >file1.Z
41	atf_check uncompress file1.Z
42	atf_check cmp file1 expectfile1
43	atf_check test ! -e file1.Z
44}
45
46atf_test_case uncompress_file_2
47uncompress_file_2_head()
48{
49	atf_set "descr" \
50	    "Test uncompress without options, filename without .Z"
51}
52uncompress_file_2_body()
53{
54	printf '%01000d\n' 7 >expectfile1
55	printf "\
56\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
57\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
58\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
59\050\123\252\134\211\360\206\002" >file1.Z
60	atf_check uncompress file1
61	atf_check cmp file1 expectfile1
62	atf_check test ! -e file1.Z
63}
64
65atf_test_case uncompress_stdio_1
66uncompress_stdio_1_head()
67{
68	atf_set "descr" \
69	    "Test uncompress without parameters"
70}
71uncompress_stdio_1_body()
72{
73	printf '%01000d\n' 7 >expectfile1
74	printf "\
75\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
76\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
77\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
78\050\123\252\134\211\360\206\002" >file1.Z
79	atf_check -o file:expectfile1 -x 'uncompress <file1.Z'
80}
81
82atf_test_case uncompress_minusc_1
83uncompress_minusc_1_head()
84{
85	atf_set "descr" \
86	    "Test uncompress with -c"
87}
88uncompress_minusc_1_body()
89{
90	printf '%01000d\n' 7 >expectfile1
91	printf "\
92\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
93\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
94\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
95\050\123\252\134\211\360\206\002" >file1.Z
96	atf_check -o file:expectfile1 uncompress -c file1.Z
97	atf_check test -e file1.Z
98	atf_check test ! -e file1
99}
100
101atf_test_case compress_uncompress_stdio_1
102compress_uncompress_stdio_1_head()
103{
104	atf_set "descr" \
105	    "Test compressing and uncompressing some data, using stdio"
106}
107compress_uncompress_stdio_1_body()
108{
109	printf '%01000d\n' 7 8 >expectfile1
110	atf_check -x 'compress <expectfile1 >file1.Z'
111	atf_check -o file:expectfile1 uncompress -c file1.Z
112}
113
114atf_test_case compress_uncompress_minusc_1
115compress_uncompress_minusc_1_head()
116{
117	atf_set "descr" \
118	    "Test compressing and uncompressing some data, using -c"
119}
120compress_uncompress_minusc_1_body()
121{
122	printf '%01000d\n' 7 8 >expectfile1
123	atf_check -x 'compress -c expectfile1 >file1.Z'
124	atf_check -o file:expectfile1 uncompress -c file1.Z
125}
126
127atf_test_case compress_uncompress_file_1
128compress_uncompress_file_1_head()
129{
130	atf_set "descr" \
131	    "Test compressing and uncompressing some data, passing one filename"
132}
133compress_uncompress_file_1_body()
134{
135	printf '%01000d\n' 7 8 >expectfile1
136	cp expectfile1 file1
137	atf_check compress file1
138	atf_check -s exit:1 cmp -s file1.Z expectfile1
139	atf_check uncompress file1.Z
140	atf_check cmp file1 expectfile1
141}
142
143atf_test_case compress_uncompress_file_2
144compress_uncompress_file_2_head()
145{
146	atf_set "descr" \
147	    "Test compressing and uncompressing some data, passing two filenames"
148}
149compress_uncompress_file_2_body()
150{
151	printf '%01000d\n' 7 8 >expectfile1
152	printf '%01000d\n' 8 7 >expectfile2
153	cp expectfile1 file1
154	cp expectfile2 file2
155	atf_check compress file1 file2
156	atf_check -s exit:1 cmp -s file1.Z expectfile1
157	atf_check -s exit:1 cmp -s file2.Z expectfile2
158	atf_check -s exit:1 cmp -s file1.Z file2.Z
159	atf_check uncompress file1.Z file2.Z
160	atf_check cmp file1 expectfile1
161	atf_check cmp file2 expectfile2
162}
163
164atf_test_case compress_uncompress_file_minusc_1
165compress_uncompress_file_minusc_1_head()
166{
167	atf_set "descr" \
168	    "Test compressing and uncompressing some data, passing two filenames to uncompress -c"
169}
170compress_uncompress_file_minusc_1_body()
171{
172	printf '%01000d\n' 7 8 >expectfile1
173	printf '%01000d\n' 8 7 >expectfile2
174	cp expectfile1 file1
175	cp expectfile2 file2
176	atf_check compress file1 file2
177	atf_check -s exit:1 cmp -s file1.Z expectfile1
178	atf_check -s exit:1 cmp -s file2.Z expectfile2
179	atf_check -s exit:1 cmp -s file1.Z file2.Z
180	atf_check -x 'uncompress -c file1.Z file2.Z >all'
181	atf_check -x 'cat expectfile1 expectfile2 >expectall'
182	atf_check cmp all expectall
183}
184
185atf_init_test_cases()
186{
187	atf_add_test_case uncompress_file_1
188	atf_add_test_case uncompress_file_2
189	atf_add_test_case uncompress_stdio_1
190	atf_add_test_case uncompress_minusc_1
191	atf_add_test_case compress_uncompress_stdio_1
192	atf_add_test_case compress_uncompress_minusc_1
193	atf_add_test_case compress_uncompress_file_1
194	atf_add_test_case compress_uncompress_file_2
195	atf_add_test_case compress_uncompress_file_minusc_1
196}
197