Path: blob/main/usr.bin/compress/tests/compress_test.sh
34878 views
# Copyright (c) 2017 Jilles Tjoelker <[email protected]>1# All rights reserved.2#3# Redistribution and use in source and binary forms, with or without4# modification, are permitted provided that the following conditions5# are met:6# 1. Redistributions of source code must retain the above copyright7# notice, this list of conditions and the following disclaimer.8# 2. Redistributions in binary form must reproduce the above copyright9# notice, this list of conditions and the following disclaimer in the10# documentation and/or other materials provided with the distribution.11#12# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND13# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE14# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE15# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE16# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL17# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS18# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)19# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT20# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY21# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF22# SUCH DAMAGE.23#2425atf_test_case uncompress_file_126uncompress_file_1_head()27{28atf_set "descr" \29"Test uncompress without options, filename with .Z"30}31uncompress_file_1_body()32{33printf '%01000d\n' 7 >expectfile134printf "\35\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\36\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\37\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\38\050\123\252\134\211\360\206\002" >file1.Z39atf_check uncompress file1.Z40atf_check cmp file1 expectfile141atf_check test ! -e file1.Z42}4344atf_test_case uncompress_file_245uncompress_file_2_head()46{47atf_set "descr" \48"Test uncompress without options, filename without .Z"49}50uncompress_file_2_body()51{52printf '%01000d\n' 7 >expectfile153printf "\54\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\55\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\56\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\57\050\123\252\134\211\360\206\002" >file1.Z58atf_check uncompress file159atf_check cmp file1 expectfile160atf_check test ! -e file1.Z61}6263atf_test_case uncompress_stdio_164uncompress_stdio_1_head()65{66atf_set "descr" \67"Test uncompress without parameters"68}69uncompress_stdio_1_body()70{71printf '%01000d\n' 7 >expectfile172printf "\73\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\74\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\75\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\76\050\123\252\134\211\360\206\002" >file1.Z77atf_check -o file:expectfile1 -x 'uncompress <file1.Z'78}7980atf_test_case uncompress_minusc_181uncompress_minusc_1_head()82{83atf_set "descr" \84"Test uncompress with -c"85}86uncompress_minusc_1_body()87{88printf '%01000d\n' 7 >expectfile189printf "\90\037\235\220\060\002\012\034\110\260\240\301\203\010\023\052\134\91\310\260\241\303\207\020\043\112\234\110\261\242\305\213\030\063\92\152\334\310\261\243\307\217\040\103\212\034\111\262\244\311\223\93\050\123\252\134\211\360\206\002" >file1.Z94atf_check -o file:expectfile1 uncompress -c file1.Z95atf_check test -e file1.Z96atf_check test ! -e file197}9899atf_test_case compress_uncompress_stdio_1100compress_uncompress_stdio_1_head()101{102atf_set "descr" \103"Test compressing and uncompressing some data, using stdio"104}105compress_uncompress_stdio_1_body()106{107printf '%01000d\n' 7 8 >expectfile1108atf_check -x 'compress <expectfile1 >file1.Z'109atf_check -o file:expectfile1 uncompress -c file1.Z110}111112atf_test_case compress_uncompress_minusc_1113compress_uncompress_minusc_1_head()114{115atf_set "descr" \116"Test compressing and uncompressing some data, using -c"117}118compress_uncompress_minusc_1_body()119{120printf '%01000d\n' 7 8 >expectfile1121atf_check -x 'compress -c expectfile1 >file1.Z'122atf_check -o file:expectfile1 uncompress -c file1.Z123}124125atf_test_case compress_uncompress_file_1126compress_uncompress_file_1_head()127{128atf_set "descr" \129"Test compressing and uncompressing some data, passing one filename"130}131compress_uncompress_file_1_body()132{133printf '%01000d\n' 7 8 >expectfile1134cp expectfile1 file1135atf_check compress file1136atf_check -s exit:1 cmp -s file1.Z expectfile1137atf_check uncompress file1.Z138atf_check cmp file1 expectfile1139}140141atf_test_case compress_uncompress_file_2142compress_uncompress_file_2_head()143{144atf_set "descr" \145"Test compressing and uncompressing some data, passing two filenames"146}147compress_uncompress_file_2_body()148{149printf '%01000d\n' 7 8 >expectfile1150printf '%01000d\n' 8 7 >expectfile2151cp expectfile1 file1152cp expectfile2 file2153atf_check compress file1 file2154atf_check -s exit:1 cmp -s file1.Z expectfile1155atf_check -s exit:1 cmp -s file2.Z expectfile2156atf_check -s exit:1 cmp -s file1.Z file2.Z157atf_check uncompress file1.Z file2.Z158atf_check cmp file1 expectfile1159atf_check cmp file2 expectfile2160}161162atf_test_case compress_uncompress_file_minusc_1163compress_uncompress_file_minusc_1_head()164{165atf_set "descr" \166"Test compressing and uncompressing some data, passing two filenames to uncompress -c"167}168compress_uncompress_file_minusc_1_body()169{170printf '%01000d\n' 7 8 >expectfile1171printf '%01000d\n' 8 7 >expectfile2172cp expectfile1 file1173cp expectfile2 file2174atf_check compress file1 file2175atf_check -s exit:1 cmp -s file1.Z expectfile1176atf_check -s exit:1 cmp -s file2.Z expectfile2177atf_check -s exit:1 cmp -s file1.Z file2.Z178atf_check -x 'uncompress -c file1.Z file2.Z >all'179atf_check -x 'cat expectfile1 expectfile2 >expectall'180atf_check cmp all expectall181}182183atf_init_test_cases()184{185atf_add_test_case uncompress_file_1186atf_add_test_case uncompress_file_2187atf_add_test_case uncompress_stdio_1188atf_add_test_case uncompress_minusc_1189atf_add_test_case compress_uncompress_stdio_1190atf_add_test_case compress_uncompress_minusc_1191atf_add_test_case compress_uncompress_file_1192atf_add_test_case compress_uncompress_file_2193atf_add_test_case compress_uncompress_file_minusc_1194}195196197