@@ -5,6 +5,11 @@ filenames=(
55 " tests/files/test2.txt"
66)
77
8+ filename_not_existing=(
9+ " aaaooo.txt"
10+ " "
11+ )
12+
813zip_name=" tests/files/test.zip"
914unzip_name=" tests/files/test.unzip"
1015log_name=" tests/files/output.file"
@@ -45,28 +50,35 @@ check_leaks() {
4550}
4651
4752# running with valgrind zip and unzip using as args for zip $1 and $2 for unzip, $3 is error/no_error code
53+ # usage: zip_unzip [zip_flags] [unzip_flags] [result] [filename_list_elements]
4854zip_unzip () {
55+ local zip_flags=" $1 "
56+ local unzip_flags=" $2 "
57+ local result=" $3 "
58+ shift 3
59+ local current_filenames=(" $@ " ) # list of filename array elements
60+
4961 # executing test files in order
50- for test_file in ${filenames[@]}
51- do
52- valgrind --log-file=${log_name} --leak-check=yes --tool=memcheck -s ./${ZIP_APP} ${test_file} ${zip_name} $1 > ${log_name}
62+ for test_file in " ${current_filenames[@]} " ; do
63+ valgrind --log-file=${log_name} --leak-check=yes --tool=memcheck -s ./${ZIP_APP} ${test_file} ${zip_name} ${zip_flags} > ${log_name}
5364 ZIP_RET_CODE=$?
5465 check_leaks ${log_name}
55-
56- # dont execute if zipping ended with error
57- if [ " ${ZIP_RET_CODE} " -eq 0 ]; then
58- valgrind --log-file=${log_name} --leak-check=yes --tool=memcheck -s ./${UNZIP_APP} ${zip_name} ${unzip_name} $2 > ${log_name}
66+
67+ # execute unzip if zipping ended without error and called without -h
68+ if [ " ${ZIP_RET_CODE} " -eq 0 ] && grep -vq ' h ' <<< ${zip_flags} ; then
69+ valgrind --log-file=${log_name} --leak-check=yes --tool=memcheck -s ./${UNZIP_APP} ${zip_name} ${unzip_name} ${unzip_flags} > ${log_name}
5970 UNZIP_RET_CODE=$?
6071 check_leaks ${log_name}
61- if [ " ${UNZIP_RET_CODE} " -eq 0 ]; then
72+ # compare files if unzip ended without error and called without -h
73+ if [ " ${UNZIP_RET_CODE} " -eq 0 ] && grep -vq ' h' <<< ${unzip_flags} ; then
6274 compare_files ${test_file} ${unzip_name}
6375 fi
6476 fi
6577
6678 # if one of two is error and error expected -- SUCCESS, else -- FAIL
6779 if [ " ${ZIP_RET_CODE} " -ne 0 ] || [ " ${UNZIP_RET_CODE} " -ne 0 ]; then
6880 (( count++ ))
69- if [ $3 -ne 0 ]; then
81+ if [ ${result} -ne 0 ]; then
7082 (( success++ ))
7183 echo " -------------------"
7284 echo " test $count success"
@@ -77,8 +89,16 @@ zip_unzip() {
7789 echo " -------------------"
7890 echo " test $count fail"
7991 echo " -------------------"
80- echo PARAMS ARE $1 $2 $3
92+ echo PARAMS ARE ${zip_flags} ${unzip_flags} ${result}
8193 fi
94+
95+ elif grep -q ' h' <<< ${zip_flags} || grep -q ' h' <<< ${unzip_flags} ; then
96+ (( count++ ))
97+ (( success++ ))
98+ echo " -------------------"
99+ echo " test $count success"
100+ echo " -------------------"
101+ echo
82102 fi
83103
84104 sudo rm -f ${zip_name} ${unzip_name} ${log_name} tests/files/* .zip tests/files/* .unzip
@@ -97,21 +117,28 @@ if [ -e ${ZIP_APP} ] && [ -e ${UNZIP_APP} ]; then
97117 fi
98118 if [ -e ${log_name} ]; then
99119 rm ${log_name}
100- fi
120+ fis
101121
102122 # test cases: args of zip, args of unzip and expected error(1)/no_error(0)
103- zip_unzip " " " " " 0"
104- zip_unzip " -f -c 100" " -f" " 0"
105- zip_unzip " -f -c 1" " -f" " 0"
106- zip_unzip " -f" " -f" " 0"
107- zip_unzip " -f -c -400" " -f" " 1"
108- zip_unzip " -f -c 99999999999999999999999999" " -f" " 1"
109- zip_unzip " -f -h" " " " 1"
110- zip_unzip " -f" " " " 0"
111- zip_unzip " " " -f" " 0"
112- zip_unzip " -fabc" " -f" " 1"
113- zip_unzip " -f" " -fa" " 1"
114- zip_unzip " -f" " -h" " 1"
123+ zip_unzip " " " " " 0" " ${filenames[@]} "
124+ zip_unzip " " " " " 1" " ${filename_not_existing[@]} "
125+ zip_unzip " -f -c 100" " -f" " 0" " ${filenames[@]} "
126+ zip_unzip " -f -c 100" " -f" " 1" " ${filename_not_existing[@]} "
127+ zip_unzip " -f -c 1" " -f" " 0" " ${filenames[@]} "
128+ zip_unzip " -f -c 1" " -f" " 1" " ${filename_not_existing[@]} "
129+ zip_unzip " -f" " -f" " 0" " ${filenames[@]} "
130+ zip_unzip " -f" " -f" " 1" " ${filename_not_existing[@]} "
131+ zip_unzip " -f -c -400" " -f" " 1" " ${filenames[@]} "
132+ zip_unzip " -f -c 99999999999999999999999999" " -f" " 1" " ${filenames[@]} "
133+ zip_unzip " -f -h" " " " 0" " ${filenames[@]} "
134+ zip_unzip " -f" " " " 0" " ${filenames[@]} "
135+ zip_unzip " -f" " " " 1" " ${filename_not_existing[@]} "
136+ zip_unzip " " " -f" " 0" " ${filenames[@]} "
137+ zip_unzip " " " -f" " 1" " ${filename_not_existing[@]} "
138+ zip_unzip " -fabc" " -f" " 1" " ${filenames[@]} "
139+ zip_unzip " -f" " -fa" " 1" " ${filenames[@]} "
140+ zip_unzip " -f" " -h" " 0" " ${filenames[@]} "
141+
115142
116143
117144 sudo rm -f tests/files/* .zip tests/files/* .unzip
0 commit comments