]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - usr.bin/compress/tests/compress_test.sh
MFC r318591: compress: Add basic tests.
[FreeBSD/stable/10.git] / usr.bin / compress / tests / compress_test.sh
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
27 atf_test_case uncompress_file_1
28 uncompress_file_1_head()
29 {
30         atf_set "descr" \
31             "Test uncompress without options, filename with .Z"
32 }
33 uncompress_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
46 atf_test_case uncompress_file_2
47 uncompress_file_2_head()
48 {
49         atf_set "descr" \
50             "Test uncompress without options, filename without .Z"
51 }
52 uncompress_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
65 atf_test_case uncompress_stdio_1
66 uncompress_stdio_1_head()
67 {
68         atf_set "descr" \
69             "Test uncompress without parameters"
70 }
71 uncompress_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
82 atf_test_case uncompress_minusc_1
83 uncompress_minusc_1_head()
84 {
85         atf_set "descr" \
86             "Test uncompress with -c"
87 }
88 uncompress_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
101 atf_test_case compress_uncompress_stdio_1
102 compress_uncompress_stdio_1_head()
103 {
104         atf_set "descr" \
105             "Test compressing and uncompressing some data, using stdio"
106 }
107 compress_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
114 atf_test_case compress_uncompress_minusc_1
115 compress_uncompress_minusc_1_head()
116 {
117         atf_set "descr" \
118             "Test compressing and uncompressing some data, using -c"
119 }
120 compress_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
127 atf_test_case compress_uncompress_file_1
128 compress_uncompress_file_1_head()
129 {
130         atf_set "descr" \
131             "Test compressing and uncompressing some data, passing one filename"
132 }
133 compress_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
143 atf_test_case compress_uncompress_file_2
144 compress_uncompress_file_2_head()
145 {
146         atf_set "descr" \
147             "Test compressing and uncompressing some data, passing two filenames"
148 }
149 compress_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
164 atf_init_test_cases()
165 {
166         atf_add_test_case uncompress_file_1
167         atf_add_test_case uncompress_file_2
168         atf_add_test_case uncompress_stdio_1
169         atf_add_test_case uncompress_minusc_1
170         atf_add_test_case compress_uncompress_stdio_1
171         atf_add_test_case compress_uncompress_minusc_1
172         atf_add_test_case compress_uncompress_file_1
173         atf_add_test_case compress_uncompress_file_2
174 }