xref: /aosp_15_r20/external/brotli/tests/compatibility_test.sh (revision f4ee7fba7774faf2a30f13154332c0a06550dbc4)
1*f4ee7fbaSAndroid Build Coastguard Worker#!/usr/bin/env bash
2*f4ee7fbaSAndroid Build Coastguard Worker#
3*f4ee7fbaSAndroid Build Coastguard Worker# Test that the brotli command-line tool can decompress old brotli-compressed
4*f4ee7fbaSAndroid Build Coastguard Worker# files.
5*f4ee7fbaSAndroid Build Coastguard Worker#
6*f4ee7fbaSAndroid Build Coastguard Worker# The first argument may be a wrapper for brotli, such as 'qemu-arm'.
7*f4ee7fbaSAndroid Build Coastguard Worker
8*f4ee7fbaSAndroid Build Coastguard Workerset -o errexit
9*f4ee7fbaSAndroid Build Coastguard Worker
10*f4ee7fbaSAndroid Build Coastguard WorkerBROTLI_WRAPPER=$1
11*f4ee7fbaSAndroid Build Coastguard WorkerBROTLI="${BROTLI_WRAPPER} bin/brotli"
12*f4ee7fbaSAndroid Build Coastguard WorkerTMP_DIR=bin/tmp
13*f4ee7fbaSAndroid Build Coastguard Worker
14*f4ee7fbaSAndroid Build Coastguard Workerfor file in tests/testdata/*.compressed*; do
15*f4ee7fbaSAndroid Build Coastguard Worker  echo "Testing decompression of file $file"
16*f4ee7fbaSAndroid Build Coastguard Worker  expected=${file%.compressed*}
17*f4ee7fbaSAndroid Build Coastguard Worker  uncompressed=${TMP_DIR}/${expected##*/}.uncompressed
18*f4ee7fbaSAndroid Build Coastguard Worker  echo $uncompressed
19*f4ee7fbaSAndroid Build Coastguard Worker  $BROTLI $file -fdo $uncompressed
20*f4ee7fbaSAndroid Build Coastguard Worker  diff -q $uncompressed $expected
21*f4ee7fbaSAndroid Build Coastguard Worker  # Test the streaming version
22*f4ee7fbaSAndroid Build Coastguard Worker  cat $file | $BROTLI -dc > $uncompressed
23*f4ee7fbaSAndroid Build Coastguard Worker  diff -q $uncompressed $expected
24*f4ee7fbaSAndroid Build Coastguard Worker  rm -f $uncompressed
25*f4ee7fbaSAndroid Build Coastguard Workerdone
26