comparison tests/test-json-destinations/test-json-destinations.sh @ 171:c1834a31029c

Merge from branch "jams"
author Chris Cannam
date Wed, 15 Oct 2014 16:09:47 +0100
parents 859d8ec60e06
children 4ef452f5fefc
comparison
equal deleted inserted replaced
163:f4f770b4356b 171:c1834a31029c
1 #!/bin/bash
2
3 . ../include.sh
4
5 infile1=$audiopath/3clicks8.wav
6 infile2=$audiopath/6clicks8.wav
7
8 infile1dot=$audiopath/3.clicks.8.wav
9
10 outfile1=3clicks8.json
11 outfile2=6clicks8.json
12
13 outfile3=3clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.json
14 outfile4=3clicks8_vamp_vamp-example-plugins_percussiononsets_detectionfunction.json
15 outfile5=6clicks8_vamp_vamp-example-plugins_percussiononsets_onsets.json
16 outfile6=6clicks8_vamp_vamp-example-plugins_percussiononsets_detectionfunction.json
17
18 outfile1dot=3.clicks.8.json
19
20 tmpjson=$mypath/tmp_1_$$.json
21
22 trap "rm -f $tmpjson $outfile1 $outfile2 $outfile3 $outfile4 $outfile5 $outfile6 $infile1dot $outfile1dot $audiopath/$outfile1 $audiopath/$outfile2 $audiopath/$outfile3 $audiopath/$outfile4 $audiopath/$outfile5 $audiopath/$outfile6 $audiopath/$outfile1dot" 0
23
24 transformdir=$mypath/transforms
25
26 failshow() {
27 echo "Test failed: $1"
28 if [ -n "$2" ]; then
29 echo "Output follows:"
30 echo "--"
31 cat $2
32 echo "--"
33 fi
34 exit 1
35 }
36
37 check_json() {
38 test -f $1 || \
39 fail "Fails to write output to expected location $1 for $2"
40 cat $1 | json_verify -q || \
41 failshow "Writes invalid JSON to location $1 for $2" $1
42 rm -f $1
43 }
44
45
46 ctx="onsets transform, one audio file, default JSON writer destination"
47
48 rm -f $audiopath/$outfile1
49
50 $r -t $transformdir/onsets.n3 -w json $infile1 2>/dev/null || \
51 fail "Fails to run with $ctx"
52
53 check_json $audiopath/$outfile1 "$ctx"
54
55
56 ctx="onsets transform, one audio file with dots in filename, default JSON writer destination"
57
58 rm -f $audiopath/$outfile1
59
60 cp $infile1 $infile1dot
61
62 $r -t $transformdir/onsets.n3 -w json $infile1dot 2>/dev/null || \
63 fail "Fails to run with $ctx"
64
65 check_json $audiopath/$outfile1dot "$ctx"
66
67 rm -f $infile1dot $audiopath/$outfile1dot
68
69
70 ctx="onsets and df transforms, one audio file, default JSON writer destination"
71
72 rm -f $audiopath/$outfile1
73
74 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json $infile1 2>/dev/null || \
75 fail "Fails to run with $ctx"
76
77 check_json $audiopath/$outfile1 "$ctx"
78
79
80 ctx="onsets transform, two audio files, default JSON writer destination"
81
82 rm -f $audiopath/$outfile1
83 rm -f $audiopath/$outfile2
84
85 $r -t $transformdir/onsets.n3 -w json $infile1 $infile2 2>/dev/null || \
86 fail "Fails to run with $ctx"
87
88 check_json $audiopath/$outfile1 "$ctx"
89 check_json $audiopath/$outfile2 "$ctx"
90
91
92 ctx="onsets transform, two audio files, one-file JSON writer"
93
94 $r -t $transformdir/onsets.n3 -w json --json-one-file $tmpjson $infile1 $infile2 2>/dev/null || \
95 fail "Fails to run with $ctx"
96
97 check_json $tmpjson "$ctx"
98
99
100 ctx="onsets transform, two audio files, stdout JSON writer"
101
102 $r -t $transformdir/onsets.n3 -w json --json-stdout $infile1 $infile2 2>/dev/null >$tmpjson || \
103 fail "Fails to run with $ctx"
104
105 check_json $tmpjson "$ctx"
106
107
108 ctx="onsets transform, one audio file, many-files JSON writer"
109
110 rm -f $audiopath/$outfile3
111
112 $r -t $transformdir/onsets.n3 -w json --json-many-files $infile1 2>/dev/null || \
113 fail "Fails to run with $ctx"
114
115 check_json $audiopath/$outfile3 "$ctx"
116
117
118 ctx="onsets transform, two audio files, many-files JSON writer"
119
120 rm -f $audiopath/$outfile3
121 rm -f $audiopath/$outfile5
122
123 $r -t $transformdir/onsets.n3 -w json --json-many-files $infile1 $infile2 2>/dev/null || \
124 fail "Fails to run with $ctx"
125
126 check_json $audiopath/$outfile3 "$ctx"
127 check_json $audiopath/$outfile5 "$ctx"
128
129
130 ctx="onsets and df transforms, two audio files, many-files JSON writer"
131
132 rm -f $audiopath/$outfile3
133 rm -f $audiopath/$outfile4
134 rm -f $audiopath/$outfile5
135 rm -f $audiopath/$outfile6
136
137 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json --json-many-files $infile1 $infile2 2>/dev/null || \
138 fail "Fails to run with $ctx"
139
140 check_json $audiopath/$outfile3 "$ctx"
141 check_json $audiopath/$outfile4 "$ctx"
142 check_json $audiopath/$outfile5 "$ctx"
143 check_json $audiopath/$outfile6 "$ctx"
144
145
146 ctx="output base directory"
147
148 rm -f ./$outfile1
149
150 $r -t $transformdir/onsets.n3 -t $transformdir/detectionfunction.n3 -w json --json-basedir . $infile1 2>/dev/null || \
151 fail "Fails to run with $ctx"
152
153 check_json ./$outfile1 "$ctx"
154
155
156 ctx="output base directory and many-files"
157
158 rm -f ./$outfile3
159 rm -f ./$outfile5
160
161 $r -t $transformdir/onsets.n3 -w json --json-basedir . --json-many-files $infile1 $infile2 2>/dev/null || \
162 fail "Fails to run with $ctx"
163
164 check_json ./$outfile3 "$ctx"
165 check_json ./$outfile5 "$ctx"
166
167
168 ctx="nonexistent output base directory"
169
170 $r -t $transformdir/onsets.n3 -w json --json-basedir ./DOES_NOT_EXIST $infile1 2>/dev/null && \
171 fail "Fails with $ctx by completing successfully (should refuse and bail out)"
172
173
174 ctx="existing output file and no --json-force"
175
176 touch $audiopath/$outfile1
177
178 $r -t $transformdir/onsets.n3 -w json $infile1 2>/dev/null && \
179 fail "Fails by completing successfully when output file already exists (should refuse and bail out)"
180
181
182 ctx="existing output file and --json-force"
183
184 touch $audiopath/$outfile1
185
186 $r -t $transformdir/onsets.n3 -w json --json-force $infile1 2>/dev/null || \
187 fail "Fails to run with $ctx"
188
189 check_json $audiopath/$outfile1 "$ctx"
190
191
192 exit 0