xref: /freebsd/usr.bin/compress/tests/compress_test.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
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
26atf_test_case uncompress_file_1
27uncompress_file_1_head()
28{
29	atf_set "descr" \
30	    "Test uncompress without options, filename with .Z"
31}
32uncompress_file_1_body()
33{
34	printf '%01000d\n' 7 >expectfile1
35	printf "\
36\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
37\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
38\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
39\050\123\252\134\211\360\206\002" >file1.Z
40	atf_check uncompress file1.Z
41	atf_check cmp file1 expectfile1
42	atf_check test ! -e file1.Z
43}
44
45atf_test_case uncompress_file_2
46uncompress_file_2_head()
47{
48	atf_set "descr" \
49	    "Test uncompress without options, filename without .Z"
50}
51uncompress_file_2_body()
52{
53	printf '%01000d\n' 7 >expectfile1
54	printf "\
55\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
56\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
57\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
58\050\123\252\134\211\360\206\002" >file1.Z
59	atf_check uncompress file1
60	atf_check cmp file1 expectfile1
61	atf_check test ! -e file1.Z
62}
63
64atf_test_case uncompress_stdio_1
65uncompress_stdio_1_head()
66{
67	atf_set "descr" \
68	    "Test uncompress without parameters"
69}
70uncompress_stdio_1_body()
71{
72	printf '%01000d\n' 7 >expectfile1
73	printf "\
74\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
75\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
76\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
77\050\123\252\134\211\360\206\002" >file1.Z
78	atf_check -o file:expectfile1 -x 'uncompress <file1.Z'
79}
80
81atf_test_case uncompress_minusc_1
82uncompress_minusc_1_head()
83{
84	atf_set "descr" \
85	    "Test uncompress with -c"
86}
87uncompress_minusc_1_body()
88{
89	printf '%01000d\n' 7 >expectfile1
90	printf "\
91\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\
92\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\
93\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\
94\050\123\252\134\211\360\206\002" >file1.Z
95	atf_check -o file:expectfile1 uncompress -c file1.Z
96	atf_check test -e file1.Z
97	atf_check test ! -e file1
98}
99
100atf_test_case compress_uncompress_stdio_1
101compress_uncompress_stdio_1_head()
102{
103	atf_set "descr" \
104	    "Test compressing and uncompressing some data, using stdio"
105}
106compress_uncompress_stdio_1_body()
107{
108	printf '%01000d\n' 7 8 >expectfile1
109	atf_check -x 'compress <expectfile1 >file1.Z'
110	atf_check -o file:expectfile1 uncompress -c file1.Z
111}
112
113atf_test_case compress_uncompress_minusc_1
114compress_uncompress_minusc_1_head()
115{
116	atf_set "descr" \
117	    "Test compressing and uncompressing some data, using -c"
118}
119compress_uncompress_minusc_1_body()
120{
121	printf '%01000d\n' 7 8 >expectfile1
122	atf_check -x 'compress -c expectfile1 >file1.Z'
123	atf_check -o file:expectfile1 uncompress -c file1.Z
124}
125
126atf_test_case compress_uncompress_file_1
127compress_uncompress_file_1_head()
128{
129	atf_set "descr" \
130	    "Test compressing and uncompressing some data, passing one filename"
131}
132compress_uncompress_file_1_body()
133{
134	printf '%01000d\n' 7 8 >expectfile1
135	cp expectfile1 file1
136	atf_check compress file1
137	atf_check -s exit:1 cmp -s file1.Z expectfile1
138	atf_check uncompress file1.Z
139	atf_check cmp file1 expectfile1
140}
141
142atf_test_case compress_uncompress_file_2
143compress_uncompress_file_2_head()
144{
145	atf_set "descr" \
146	    "Test compressing and uncompressing some data, passing two filenames"
147}
148compress_uncompress_file_2_body()
149{
150	printf '%01000d\n' 7 8 >expectfile1
151	printf '%01000d\n' 8 7 >expectfile2
152	cp expectfile1 file1
153	cp expectfile2 file2
154	atf_check compress file1 file2
155	atf_check -s exit:1 cmp -s file1.Z expectfile1
156	atf_check -s exit:1 cmp -s file2.Z expectfile2
157	atf_check -s exit:1 cmp -s file1.Z file2.Z
158	atf_check uncompress file1.Z file2.Z
159	atf_check cmp file1 expectfile1
160	atf_check cmp file2 expectfile2
161}
162
163atf_test_case compress_uncompress_file_minusc_1
164compress_uncompress_file_minusc_1_head()
165{
166	atf_set "descr" \
167	    "Test compressing and uncompressing some data, passing two filenames to uncompress -c"
168}
169compress_uncompress_file_minusc_1_body()
170{
171	printf '%01000d\n' 7 8 >expectfile1
172	printf '%01000d\n' 8 7 >expectfile2
173	cp expectfile1 file1
174	cp expectfile2 file2
175	atf_check compress file1 file2
176	atf_check -s exit:1 cmp -s file1.Z expectfile1
177	atf_check -s exit:1 cmp -s file2.Z expectfile2
178	atf_check -s exit:1 cmp -s file1.Z file2.Z
179	atf_check -x 'uncompress -c file1.Z file2.Z >all'
180	atf_check -x 'cat expectfile1 expectfile2 >expectall'
181	atf_check cmp all expectall
182}
183
184atf_init_test_cases()
185{
186	atf_add_test_case uncompress_file_1
187	atf_add_test_case uncompress_file_2
188	atf_add_test_case uncompress_stdio_1
189	atf_add_test_case uncompress_minusc_1
190	atf_add_test_case compress_uncompress_stdio_1
191	atf_add_test_case compress_uncompress_minusc_1
192	atf_add_test_case compress_uncompress_file_1
193	atf_add_test_case compress_uncompress_file_2
194	atf_add_test_case compress_uncompress_file_minusc_1
195}
196