Mercurial > hg > audiodb
changeset 48:a7aad4c50cb9
Factor out some common utilities and setup code into test-utils.sh, and
source that file within each run-test file.
author | mas01cr |
---|---|
date | Tue, 18 Sep 2007 09:24:52 +0000 |
parents | 092648f9b532 |
children | 53616d7dda08 |
files | tests/0001/run-test.sh tests/0002/run-test.sh tests/0003/run-test.sh tests/0004/run-test.sh tests/test-utils.sh |
diffstat | 5 files changed, 50 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/0001/run-test.sh Mon Sep 17 16:12:12 2007 +0000 +++ b/tests/0001/run-test.sh Tue Sep 18 09:24:52 2007 +0000 @@ -1,6 +1,6 @@ #! /bin/sh -trap "exit 1" ERR +. ../test-utils.sh if [ -f testdb ]; then rm -f testdb; fi
--- a/tests/0002/run-test.sh Mon Sep 17 16:12:12 2007 +0000 +++ b/tests/0002/run-test.sh Tue Sep 18 09:24:52 2007 +0000 @@ -1,6 +1,6 @@ #! /bin/sh -trap "exit 1" ERR +. ../test-utils.sh if [ -f testdb ]; then rm -f testdb; fi
--- a/tests/0003/run-test.sh Mon Sep 17 16:12:12 2007 +0000 +++ b/tests/0003/run-test.sh Tue Sep 18 09:24:52 2007 +0000 @@ -1,6 +1,6 @@ #! /bin/sh -trap "exit 1" ERR +. ../test-utils.sh if [ -f testdb ]; then rm -f testdb; fi @@ -11,7 +11,8 @@ # handling. # FIXME: endianness! -printf "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0\x3f" > testfeature +intstring 1 > testfeature +floatstring 1 >> testfeature ${AUDIODB} -d testdb -I -f testfeature
--- a/tests/0004/run-test.sh Mon Sep 17 16:12:12 2007 +0000 +++ b/tests/0004/run-test.sh Tue Sep 18 09:24:52 2007 +0000 @@ -1,38 +1,20 @@ #! /bin/sh -floatstring() { - case $1 in - 0) - printf "\x00\x00\x00\x00\x00\x00\x00\x00";; - 0.5) - printf "\x00\x00\x00\x00\x00\x00\xe0\x3f";; - 1) - printf "\x00\x00\x00\x00\x00\x00\xf0\x3f";; - *) - echo "bad arg to floatstring(): $1" - exit 1;; - esac -} - -trap "exit 1" ERR +. ../test-utils.sh if [ -f testdb ]; then rm -f testdb; fi ${AUDIODB} -d testdb -N -# FIXME: endianness! -printf "\x02\x00\x00\x00" > testfeature -floatstring 0 >> testfeature -floatstring 1 >> testfeature -floatstring 1 >> testfeature -floatstring 0 >> testfeature +intstring 2 > testfeature +floatstring 0 1 >> testfeature +floatstring 1 0 >> testfeature ${AUDIODB} -d testdb -I -f testfeature echo "query point (0.0,0.5)" -printf "\x02\x00\x00\x00" > testquery -floatstring 0 >> testquery -floatstring 0.5 >> testquery +intstring 2 > testquery +floatstring 0 0.5 >> testquery ${AUDIODB} -d testdb -Q point -f testquery > testoutput wc -l testoutput | grep 2 @@ -40,9 +22,8 @@ wc -l testoutput | grep 1 echo "query point (0.5,0.0)" -printf "\x02\x00\x00\x00" > testquery -floatstring 0.5 >> testquery -floatstring 0 >> testquery +intstring 2 > testquery +floatstring 0.5 0 >> testquery ${AUDIODB} -d testdb -Q point -f testquery > testoutput wc -l testoutput | grep 2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-utils.sh Tue Sep 18 09:24:52 2007 +0000 @@ -0,0 +1,37 @@ +# no shebang line: this file should be sourced by run-test.sh files + +trap "exit 1" ERR + +if [ -z ${AUDIODB} ]; then + AUDIODB=../../audioDB +fi + +# FIXME: maybe generalize to multiple arguments? Also, implement it +# properly, rather than just for a few floats that we know how to +# encode. This might involve writing some C code, as Bash doesn't do +# Floating Point. (scanf() is probably enough). + +floatstring() { + for arg in "$@"; do + case ${arg} in + 0) + printf "\x00\x00\x00\x00\x00\x00\x00\x00";; + 0.5) + printf "\x00\x00\x00\x00\x00\x00\xe0\x3f";; + 1) + printf "\x00\x00\x00\x00\x00\x00\xf0\x3f";; + *) + echo "bad arg to floatstring(): ${arg}" + exit 1;; + esac + done +} + +# FIXME: likewise. And endianness issues (which are a reflection of +# the endianness of audioDB as of 2007-09-18, unfortunately). + +intstring() { + # works up to 9 for now + if [ $1 -ge 10 ]; then echo "intstring() arg too large: ${1}"; exit 1; fi + printf "%b\x00\x00\x00" "\\x${1}" +}