#! /bin/sh

# https://sourceforge.net/p/sox/bugs/267
# https://sourceforge.net/p/sox/code/merge-requests/1

status=0

# Test routine takes two parameters:
# - the expected result if it is considered as a mono 16-bit signal
# - a list of 16-bit samples in decimal
testCase() {
    expected="$1"; shift
    got="`../samples "$@" | \
	${sox:-sox} -t raw -e signed -b 16 -L -r 48000 - -n stats 2>&1 | \
	grep Bit-depth | awk '{print $2}'`"
    if [ "$got" != "$expected" ]
    then
	echo "Expected $expected, got $got for $@"
	status=2
    fi
}

testCase 0/0	 0

testCase 2/16	 1
testCase 1/16	-1

testCase 2/15	 2
testCase 1/15	-2

testCase 16/16	 32767
testCase 16/16	-32767
testCase 16/16	 32767 -32767
testCase 13/16	 2765
testCase 9/16	 129
testCase 13/16	-2765
testCase 9/16	-129
testCase 13/16	 2765 -2765
testCase 9/16	 129  -129

testCase 4/15	 2  4  6  8
testCase 3/15	 2 -4  6 -8
testCase 4/15	-2  4 -6  8

testCase 2/2	16384
testCase 2/3	8192
testCase 2/15	2
testCase 2/16	1

testCase 1/2	-16384
testCase 1/3	-8192
testCase 1/15	-2
testCase 1/16	-1

testCase 2/15	 2 -2

testCase 7/15	-2 100
testCase 7/15	 2 100

testCase 2/16	-2 1

testCase 1/1	-32768

testCase 1/1	-32768 0

testCase 16/16	-32768 1

testCase 15/15	-32768 2

testCase 14/14	-32768 12

exit $status
