* Use `mktemp` instead of playing with date(1).
* Use -f instead of removing the file every time.
* "echo ERROR; exit 1" is what die() is for.
* Some cosmetic renamings ('k' to 'comp' for compression etc).
* Remove the MacOSX comment. It's not MacOSX specific,
  and it's not a problem anyway. The number behaves just right.
* Remove the $((${size}+10)). It's not needed, and it's a lie.
  In fact, the actual test FAILs (369513 with -5 vs 369516 with -6),
  but this +10 hides it!

Two more things not addressed in this diff:

1.
The input test file (noisy-sine.wav) needs to be present already,
probably as an artifact of some previous test. So ./test_compression
does not work standalone. I am leaving this till I figure out the right
uniform way for all the test* to have their test files generated.

2.
The 'wc -c' needs to actually read the whole file.
Not much work with noisy-sine.wav, but when we test with big files?
Why not "ls -l | awk '{print$5}'" ?
Put it in a function in common.sh, probably.

        Jan


--- test_compression.sh.orig    Wed Dec  3 22:53:11 2014
+++ test_compression.sh Wed Dec  3 23:01:16 2014
@@ -23,24 +23,22 @@ PATH=`pwd`/../src/flac:$PATH
 
 echo "Using FLAC binary :" $(which flac)
 
-date=`date "+%Y%m%dT%H%M%S"`
-fname="comp${date}.flac"
+ofile=`mktemp`.$$
+ifile="noisy-sine.wav"
 
-last_k=0
-last_size=$(wc -c < noisy-sine.wav)
+prevcomp=0
+prevsize=`wc -c < $ifile`
+echo "Original file size $prevsize bytes."
 
-echo "Original file size ${last_size} bytes."
+for comp in 0 1 2 3 4 5 6 7 8 ; do
+       flac${EXE} -f -$comp --silent $ifile -o $ofile
+       size=`wc -c < $ofile`
+       echo Compression level $comp, file size $size bytes.
+       if test $prevsize -lt $size ; then
+               die "Error: level $prevcomp produces smaller file than $comp"
+       fi
+       prevsize=$size
+       prevcomp=$comp
+done
 
-for k in 0 1 2 3 4 5 6 7 8 ; do
-       flac${EXE} -${k} --silent noisy-sine.wav -o ${fname}
-       size=$(wc -c < ${fname})
-       echo "Compression level ${k}, file size ${size} bytes."
-       if test ${last_size} -lt ${size} ; then
-               echo "Error : Compression ${last_k} size ${last_size} >= 
compression ${k} size ${size}."
-               exit 1
-               fi
-       # Need this because OSX's 'wc -c' returns a number with leading 
whitespace.
-       last_size=$((${size}+10))
-       last_k=${k}
-       rm -f ${fname}
-       done
+rm -f $ofile
_______________________________________________
flac-dev mailing list
flac-dev@xiph.org
http://lists.xiph.org/mailman/listinfo/flac-dev

Reply via email to