Mercurial > hg > audiodb
comparison libtests/0031/prog1.c @ 498:342822c2d49a
Merge api-inversion branch (-r656:771, but I don't expect to return to
that branch) into the trunk.
I expect there to be minor performance regressions (e.g. in the SOAP
server index cacheing, which I have forcibly removed) and minor
unplugged memory leaks (e.g. in audioDB::query(), where I don't free up
the datum). I hope that these leaks and performance regressions can be
plugged in short order. I also expect that some (but maybe not all) of
the issues currently addressed in the memory-leaks branch are superseded
or fixed by this merge.
There remains much work to be done; go forth and do it.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 16:47:57 +0000 |
parents | 94c18f128ce8 |
children | bcc7a6ddb2c8 |
comparison
equal
deleted
inserted
replaced
476:a7193678280b | 498:342822c2d49a |
---|---|
1 #include <stdio.h> | 1 #include "audioDB_API.h" |
2 #include <stdlib.h> | 2 #include "test_utils_lib.h" |
3 #include <string.h> | |
4 #include <sysexits.h> | |
5 #include <fcntl.h> | |
6 #include <dirent.h> | |
7 #include <unistd.h> | |
8 #include <sys/stat.h> | |
9 /* | |
10 * * #define NDEBUG | |
11 * * */ | |
12 #include <assert.h> | |
13 | 3 |
14 #include "../../audioDB_API.h" | 4 int main(int argc, char **argv) { |
15 #include "../test_utils_lib.h" | 5 adb_t *adb; |
6 const char *keys[2]; | |
16 | 7 |
8 clean_remove_db(TESTDB); | |
9 if(!(adb = audiodb_create(TESTDB,0,0,0))) | |
10 return 1; | |
17 | 11 |
18 int main(int argc, char **argv){ | 12 adb_datum_t datum1 = {1, 2, "testfeature01", (double[4]) {0, 1}}; |
13 adb_datum_t datum2 = {1, 2, "testfeature10", (double[4]) {1, 0}}; | |
14 if(audiodb_insert_datum(adb, &datum1)) | |
15 return 1; | |
16 if(audiodb_insert_datum(adb, &datum2)) | |
17 return 1; | |
19 | 18 |
20 int returnval=0; | 19 if(audiodb_l2norm(adb)) |
21 adb_ptr mydbp={0}; | 20 return 1; |
22 int ivals[10]; | |
23 double dvals[10]; | |
24 adb_insert_t myinsert={0}; | |
25 char * databasename="testdb"; | |
26 adb_query_t myadbquery={0}; | |
27 adb_queryresult_t myadbqueryresult={0}; | |
28 int size=0; | |
29 | 21 |
22 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; | |
30 | 23 |
31 /* remove old directory */ | 24 adb_query_id_t qid = {0}; |
32 //if [ -f testdb ]; then rm -f testdb; fi | 25 qid.datum = &query; |
33 clean_remove_db(databasename); | 26 qid.sequence_length = 1; |
27 qid.sequence_start = 0; | |
28 adb_query_parameters_t parms = | |
29 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; | |
30 adb_query_refine_t refine = {0}; | |
31 refine.hopsize = 1; | |
34 | 32 |
35 /* create new db */ | 33 adb_query_spec_t spec; |
36 //${AUDIODB} -d testdb -N | 34 spec.qid = qid; |
37 mydbp=audiodb_create(databasename,0,0,0); | 35 spec.params = parms; |
36 spec.refine = refine; | |
38 | 37 |
39 ///intstring 2 > testfeature01 | 38 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
40 ///floatstring 0 1 >> testfeature01 | 39 if(!results || results->nresults != 2) return 1; |
41 ///intstring 2 > testfeature10 | 40 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
42 ///floatstring 1 0 >> testfeature10 | 41 result_present_or_fail(results, "testfeature10", 2, 0, 0); |
43 ivals[0]=2; | 42 audiodb_query_free_results(adb, &spec, results); |
44 dvals[0]=0; dvals[1]=1; | |
45 maketestfile("testfeature01",ivals,dvals,2); | |
46 ivals[0]=2; | |
47 dvals[0]=1; dvals[1]=0; | |
48 maketestfile("testfeature10",ivals,dvals,2); | |
49 | 43 |
50 ///${AUDIODB} -d testdb -I -f testfeature01 | 44 spec.refine.flags = ADB_REFINE_INCLUDE_KEYLIST; |
51 ///${AUDIODB} -d testdb -I -f testfeature10 | 45 spec.refine.include.nkeys = 0; |
46 results = audiodb_query_spec(adb, &spec); | |
47 if(!results || results->nresults != 0) return 1; | |
48 audiodb_query_free_results(adb, &spec, results); | |
52 | 49 |
53 myinsert.features="testfeature01"; | 50 spec.refine.include.nkeys = 1; |
54 if (audiodb_insert(mydbp,&myinsert)){ returnval=-1; } | 51 spec.refine.include.keys = keys; |
52 spec.refine.include.keys[0] = "testfeature01"; | |
53 results = audiodb_query_spec(adb, &spec); | |
54 if(!results || results->nresults != 1) return 1; | |
55 result_present_or_fail(results, "testfeature01", 0, 0, 0); | |
56 audiodb_query_free_results(adb, &spec, results); | |
55 | 57 |
56 myinsert.features="testfeature10"; | 58 spec.refine.include.keys[0] = "testfeature10"; |
57 if (audiodb_insert(mydbp,&myinsert)){ returnval=-1; } | 59 results = audiodb_query_spec(adb, &spec); |
60 if(!results || results->nresults != 1) return 1; | |
61 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
62 audiodb_query_free_results(adb, &spec, results); | |
58 | 63 |
59 ///# sequence queries require L2NORM | 64 spec.params.ntracks = 1; |
60 ///${AUDIODB} -d testdb -L | 65 results = audiodb_query_spec(adb, &spec); |
61 if(audiodb_l2norm(mydbp)){ returnval=-1; }; | 66 if(!results || results->nresults != 1) return 1; |
67 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
68 audiodb_query_free_results(adb, &spec, results); | |
62 | 69 |
63 ///echo "query point (0.0,0.5)" | 70 spec.params.ntracks = 10; |
64 ///intstring 2 > testquery | 71 spec.refine.flags = ADB_REFINE_EXCLUDE_KEYLIST; |
65 ///floatstring 0 0.5 >> testquery | 72 spec.refine.include.nkeys = 0; |
66 ivals[0]=2; | 73 spec.refine.include.keys = NULL; |
67 dvals[0]=0; dvals[1]=0.5; | 74 spec.refine.exclude.nkeys = 1; |
68 maketestfile("testquery",ivals,dvals,2); | 75 spec.refine.exclude.keys = keys; |
76 spec.refine.exclude.keys[0] = "testfeature01"; | |
77 results = audiodb_query_spec(adb, &spec); | |
78 if(!results || results->nresults != 1) return 1; | |
79 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
80 audiodb_query_free_results(adb, &spec, results); | |
69 | 81 |
70 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | 82 audiodb_close(adb); |
71 ///echo testfeature01 0 0 0 > test-expected-output | |
72 ///echo testfeature10 2 0 0 >> test-expected-output | |
73 ///cmp testoutput test-expected-output | |
74 myadbquery.querytype="sequence"; | |
75 myadbquery.feature="testquery"; | |
76 myadbquery.sequencelength="1"; | |
77 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
78 size=myadbqueryresult.sizeRlist; | |
79 | 83 |
80 /* check the test values */ | 84 return 104; |
81 if (size != 2) {returnval = -1;}; | |
82 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
83 if (testoneresult(&myadbqueryresult,1,"testfeature10",2,0,0)) {returnval = -1;}; | |
84 | |
85 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K /dev/null > testoutput | |
86 //cat /dev/null > test-expected-output | |
87 //cmp testoutput test-expected-output | |
88 myadbquery.querytype="sequence"; | |
89 myadbquery.feature="testquery"; | |
90 myadbquery.keylist="/dev/null"; | |
91 myadbquery.sequencelength="1"; | |
92 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
93 size=myadbqueryresult.sizeRlist; | |
94 //dump_query(&myadbquery,&myadbqueryresult); | |
95 | |
96 /* check the test values */ | |
97 if (size != 0) {returnval = -1;}; | |
98 | |
99 ///echo testfeature01 > testkl.txt | |
100 makekeylistfile("testkl.txt","testfeature01"); | |
101 | |
102 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt > testoutput | |
103 ///echo testfeature01 0 0 0 > test-expected-output | |
104 ///cmp testoutput test-expected-output | |
105 myadbquery.querytype="sequence"; | |
106 myadbquery.feature="testquery"; | |
107 myadbquery.keylist="testkl.txt"; | |
108 myadbquery.sequencelength="1"; | |
109 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
110 | |
111 size=myadbqueryresult.sizeRlist; | |
112 //dump_query(&myadbquery,&myadbqueryresult); | |
113 | |
114 /* check the test values */ | |
115 if (size != 1) {returnval = -1;}; | |
116 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
117 | |
118 ///echo testfeature10 > testkl.txt | |
119 makekeylistfile("testkl.txt","testfeature10"); | |
120 | |
121 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt > testoutput | |
122 ///echo testfeature10 2 0 0 > test-expected-output | |
123 ///cmp testoutput test-expected-output | |
124 myadbquery.querytype="sequence"; | |
125 myadbquery.feature="testquery"; | |
126 myadbquery.keylist="testkl.txt"; | |
127 myadbquery.sequencelength="1"; | |
128 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
129 | |
130 size=myadbqueryresult.sizeRlist; | |
131 //dump_query(&myadbquery,&myadbqueryresult); | |
132 | |
133 /* check the test values */ | |
134 if (size != 1) {returnval = -1;}; | |
135 if (testoneresult(&myadbqueryresult,0,"testfeature10",2,0,0)) {returnval = -1;}; | |
136 | |
137 ///echo testfeature10 > testkl.txt | |
138 makekeylistfile("testkl.txt","testfeature10"); | |
139 | |
140 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -r 1 > testoutput | |
141 ///echo testfeature10 2 0 0 > test-expected-output | |
142 ///cmp testoutput test-expected-output | |
143 myadbquery.querytype="sequence"; | |
144 myadbquery.feature="testquery"; | |
145 myadbquery.keylist="testkl.txt"; | |
146 myadbquery.sequencelength="1"; | |
147 myadbquery.resultlength="1"; | |
148 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
149 | |
150 size=myadbqueryresult.sizeRlist; | |
151 //dump_query(&myadbquery,&myadbqueryresult); | |
152 | |
153 /* check the test values */ | |
154 if (size != 1) {returnval = -1;}; | |
155 if (testoneresult(&myadbqueryresult,0,"testfeature10",2,0,0)) {returnval = -1;}; | |
156 | |
157 ///echo "query point (0.5,0.0)" | |
158 ///intstring 2 > testquery | |
159 ///floatstring 0.5 0 >> testquery | |
160 ivals[0]=2; | |
161 dvals[0]=0.5; dvals[1]=0.0; | |
162 maketestfile("testquery",ivals,dvals,2); | |
163 | |
164 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
165 ///echo testfeature10 0 0 0 > test-expected-output | |
166 ///echo testfeature01 2 0 0 >> test-expected-output | |
167 ///cmp testoutput test-expected-output | |
168 myadbquery.querytype="sequence"; | |
169 myadbquery.feature="testquery"; | |
170 myadbquery.keylist=NULL; | |
171 myadbquery.sequencelength="1"; | |
172 myadbquery.resultlength=NULL; | |
173 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
174 | |
175 size=myadbqueryresult.sizeRlist; | |
176 //dump_query(&myadbquery,&myadbqueryresult); | |
177 | |
178 /* check the test values */ | |
179 if (size != 2) {returnval = -1;}; | |
180 if (testoneresult(&myadbqueryresult,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
181 if (testoneresult(&myadbqueryresult,1,"testfeature01",2,0,0)) {returnval = -1;}; | |
182 | |
183 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K /dev/null > testoutput | |
184 ///cat /dev/null > test-expected-output | |
185 ///cmp testoutput test-expected-output | |
186 myadbquery.querytype="sequence"; | |
187 myadbquery.feature="testquery"; | |
188 myadbquery.keylist="/dev/null"; | |
189 myadbquery.sequencelength="1"; | |
190 myadbquery.resultlength=NULL; | |
191 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
192 | |
193 size=myadbqueryresult.sizeRlist; | |
194 //dump_query(&myadbquery,&myadbqueryresult); | |
195 | |
196 /* check the test values */ | |
197 if (size != 0) {returnval = -1;}; | |
198 | |
199 ///echo testfeature10 > testkl.txt | |
200 makekeylistfile("testkl.txt","testfeature10"); | |
201 | |
202 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt > testoutput | |
203 ///echo testfeature10 0 0 0 > test-expected-output | |
204 //cmp testoutput test-expected-output | |
205 myadbquery.querytype="sequence"; | |
206 myadbquery.feature="testquery"; | |
207 myadbquery.keylist="testkl.txt"; | |
208 myadbquery.sequencelength="1"; | |
209 myadbquery.resultlength=NULL; | |
210 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
211 | |
212 size=myadbqueryresult.sizeRlist; | |
213 //dump_query(&myadbquery,&myadbqueryresult); | |
214 | |
215 /* check the test values */ | |
216 if (size != 1) {returnval = -1;}; | |
217 if (testoneresult(&myadbqueryresult,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
218 | |
219 | |
220 ///echo testfeature01 > testkl.txt | |
221 makekeylistfile("testkl.txt","testfeature01"); | |
222 | |
223 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt > testoutput | |
224 ///echo testfeature01 2 0 0 > test-expected-output | |
225 ///cmp testoutput test-expected-output | |
226 myadbquery.querytype="sequence"; | |
227 myadbquery.feature="testquery"; | |
228 myadbquery.keylist="testkl.txt"; | |
229 myadbquery.sequencelength="1"; | |
230 myadbquery.resultlength=NULL; | |
231 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
232 | |
233 size=myadbqueryresult.sizeRlist; | |
234 //dump_query(&myadbquery,&myadbqueryresult); | |
235 | |
236 /* check the test values */ | |
237 if (size != 1) {returnval = -1;}; | |
238 if (testoneresult(&myadbqueryresult,0,"testfeature01",2,0,0)) {returnval = -1;}; | |
239 | |
240 ///echo testfeature01 > testkl.txt | |
241 makekeylistfile("testkl.txt","testfeature01"); | |
242 | |
243 ///${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -r 1 > testoutput | |
244 ///echo testfeature01 2 0 0 > test-expected-output | |
245 ///cmp testoutput test-expected-output | |
246 myadbquery.querytype="sequence"; | |
247 myadbquery.feature="testquery"; | |
248 myadbquery.keylist="testkl.txt"; | |
249 myadbquery.sequencelength="1"; | |
250 myadbquery.resultlength="1"; | |
251 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
252 | |
253 size=myadbqueryresult.sizeRlist; | |
254 //dump_query(&myadbquery,&myadbqueryresult); | |
255 | |
256 /* check the test values */ | |
257 if (size != 1) {returnval = -1;}; | |
258 if (testoneresult(&myadbqueryresult,0,"testfeature01",2,0,0)) {returnval = -1;}; | |
259 | |
260 | |
261 | |
262 //printf("returnval:%d\n",returnval); | |
263 | |
264 return(returnval); | |
265 } | 85 } |
266 |