FOSS-VG/scripts/test/zlibutil.sh

47 lines
1.2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
echo "================================================================================"
echo "Testing \`zlibutil\`:"
echo "--------------------------------------------------------------------------------"
TMPDIR="$(mktemp -d -t fossvg-zlibutil-XXXXX)"
TMPDATA="$(dd if=/dev/urandom bs=33 count=1 2>/dev/null | base64)"
echo -n "Compression test... "
echo -n "$TMPDATA" >> "$TMPDIR/compress"
zlibutil "$TMPDIR/compress"
python3 <<< "
import zlib, sys
tmpfile = open('$TMPDIR/compress.zz', 'rb')
data = tmpfile.read()
tmpfile.close()
try:
if zlib.decompress(data)==b'$TMPDATA':
print('PASS')
else:
print('FAIL: Wrong data.')
except:
print('FAIL: Exception.')
"
echo -n "Decompression test... "
#TODO: create a compressed file using another implementation (Python)
python3 <<< "
import zlib
tmpfile = open('$TMPDIR/decompress.zz', 'wb')
tmpfile.write(zlib.compress(b'$TMPDATA'))
tmpfile.close()
"
zlibutil -d "$TMPDIR/decompress.zz"
if [ "$(cat "$TMPDIR/decompress")" = "$TMPDATA" ]; then
echo "PASS"
else
echo "FAIL"
fi
rm -r "$TMPDIR"
echo "================================================================================"