annotate tests/test-as-advertised/test-as-advertised.sh @ 197:3b7ec45abd1c

Add mandatory option --json-format to JSON feature writer, in preparation for supporting multiple JSON formats (perhaps) in future
author Chris Cannam
date Tue, 01 Sep 2015 17:05:32 +0100
parents b3d73c08b6ce
children f35bbb3e4d41
rev   line source
Chris@0 1 #!/bin/bash
Chris@0 2
Chris@119 3 . ../include.sh
Chris@0 4
Chris@119 5 infile=$audiopath/3clicks8.wav
Chris@0 6 tmpdir=$mypath/tmp_1_$$.dir
Chris@0 7 tmpwav=$tmpdir/test.wav
Chris@0 8
Chris@0 9 trap "rm -rf $tmpdir" 0
Chris@0 10
Chris@144 11 types=`$r --list-writers`
Chris@0 12 [ -n "$types" ] || \
Chris@144 13 fail "Fails to report list of writers"
Chris@0 14
Chris@119 15 onsets=$mypath/transforms/percussiononsets-onsets.n3
Chris@119 16 df=$mypath/transforms/percussiononsets-detectionfunction.n3
Chris@0 17
Chris@0 18 adbdir=$tmpdir/audiodb-test
Chris@0 19
Chris@0 20 for type in $types; do
Chris@0 21
Chris@0 22 mkdir -p $tmpdir
Chris@0 23 cp $infile $tmpwav
Chris@0 24
Chris@0 25 # Some of these are special cases:
Chris@0 26 #
Chris@0 27 # * The "default" writer type always prints to stdout instead of
Chris@0 28 # to a file.
Chris@0 29 #
Chris@0 30 # * The "audiodb" writer will not print any output for features
Chris@0 31 # that have no values (but are only point events). I don't know
Chris@0 32 # how reasonable that is, but it's clearly intentional. It also
Chris@0 33 # writes to a subdirectory $basedir/$catid/$trackid.$output
Chris@197 34 #
Chris@197 35 # * The "json" reader has a mandatory --json-format parameter that
Chris@197 36 # currently only accepts one argument ("jams"). It should fail if
Chris@197 37 # run with any other value or without this parameter.
Chris@0 38
Chris@0 39 case $type in
Chris@0 40 audiodb)
Chris@144 41 mkdir -p $adbdir
Chris@0 42 $r -t $df -w $type $tmpwav --audiodb-basedir $tmpdir --audiodb-catid `basename $adbdir` 2>/dev/null || \
Chris@0 43 fail "Fails to run with reader type \"$type\" and default options"
Chris@0 44 ;;
Chris@0 45 default)
Chris@0 46 $r -t $onsets -w $type $tmpwav > $tmpdir/test.out 2>/dev/null || \
Chris@0 47 fail "Fails to run with reader type \"$type\" and default options"
Chris@0 48 ;;
Chris@197 49 json)
Chris@197 50 $r -t $onsets -w $type $tmpwav 2>/dev/null && \
Chris@197 51 fail "Wrongly succeeds in running with reader type \"$type\" and default options"
Chris@197 52 $r -t $onsets -w $type $tmpwav --json-format blah 2>/dev/null && \
Chris@197 53 fail "Wrongly succeeds in running with reader type \"$type\" and unknown json-format option"
Chris@197 54 $r -t $onsets -w $type $tmpwav --json-format 2>/dev/null && \
Chris@197 55 fail "Wrongly succeeds in running with reader type \"$type\" and empty json-format option"
Chris@197 56 $r -t $onsets -w $type $tmpwav --json-format jams 2>/dev/null || \
Chris@197 57 fail "Fails to run with reader type \"$type\" and correct json-format option"
Chris@197 58 ;;
Chris@0 59 *)
Chris@0 60 $r -t $onsets -w $type $tmpwav 2>/dev/null || \
Chris@0 61 fail "Fails to run with reader type \"$type\" and default options"
Chris@0 62 ;;
Chris@0 63 esac
Chris@0 64 newfiles=`ls $tmpdir | fgrep -v .wav`
Chris@0 65 if [ "$type" = audiodb ]; then newfiles=`ls $adbdir`; fi
Chris@0 66
Chris@0 67 [ -n "$newfiles" ] || \
Chris@0 68 fail "Fails to create output file for reader \"$type\" with default options"
Chris@0 69
Chris@0 70 case `echo $newfiles | wc -w` in
Chris@0 71 [2-9])
Chris@0 72 if [ "$type" != audiodb ]; then
Chris@0 73 fail "Produces more than one output file for reader \"$type\" with default options"
Chris@0 74 fi
Chris@0 75 ;;
Chris@0 76 1)
Chris@0 77 if [ "$type" = audiodb ]; then
Chris@0 78 fail "Produces only one output file for reader \"$type\" with default options (expected two)"
Chris@0 79 fi
Chris@0 80 ;;
Chris@0 81 esac
Chris@0 82
Chris@0 83 rm -r $tmpdir
Chris@0 84 done
Chris@0 85
Chris@119 86 exit 0
Chris@119 87