Mercurial > hg > audiodb
comparison libtests/0032/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; | |
11 if(audiodb_l2norm(adb)) | |
12 return 1; | |
17 | 13 |
18 int main(int argc, char **argv){ | 14 adb_datum_t datum1 = {1, 2, "testfeature01", (double[2]) {0, 1}}; |
15 adb_datum_t datum2 = {1, 2, "testfeature10", (double[2]) {1, 0}}; | |
16 if(audiodb_insert_datum(adb, &datum1)) | |
17 return 1; | |
18 if(audiodb_insert_datum(adb, &datum2)) | |
19 return 1; | |
19 | 20 |
20 int returnval=0; | 21 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; |
21 adb_ptr mydbp={0}; | |
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 | 22 |
23 adb_query_id_t qid = {0}; | |
24 qid.datum = &query; | |
25 qid.sequence_length = 1; | |
26 qid.sequence_start = 0; | |
27 adb_query_parameters_t parms = | |
28 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_DOT_PRODUCT, 10, 10}; | |
29 adb_query_refine_t refine = {0}; | |
30 refine.hopsize = 1; | |
30 | 31 |
31 /* remove old directory */ | 32 adb_query_spec_t spec; |
32 //if [ -f testdb ]; then rm -f testdb; fi | 33 spec.qid = qid; |
33 clean_remove_db(databasename); | 34 spec.params = parms; |
35 spec.refine = refine; | |
34 | 36 |
35 /* create new db */ | 37 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
36 //${AUDIODB} -d testdb -N | 38 if(!results || results->nresults != 2) return 1; |
37 mydbp=audiodb_create(databasename,0,0,0); | 39 result_present_or_fail(results, "testfeature01", 0.5, 0, 0); |
40 result_present_or_fail(results, "testfeature10", 0, 0, 0); | |
41 audiodb_query_free_results(adb, &spec, results); | |
38 | 42 |
39 /* turn on l2 power */ | 43 spec.refine.flags = ADB_REFINE_INCLUDE_KEYLIST; |
40 //${AUDIODB} -d testdb -L | 44 spec.refine.include.nkeys = 0; |
41 if (audiodb_l2norm(mydbp)) {returnval=-1;}; | 45 results = audiodb_query_spec(adb, &spec); |
46 if(!results || results->nresults != 0) return 1; | |
47 audiodb_query_free_results(adb, &spec, results); | |
42 | 48 |
43 /* make feature files */ | 49 spec.refine.include.nkeys = 1; |
44 //intstring 2 > testfeature01 | 50 spec.refine.include.keys = keys; |
45 //floatstring 0 1 >> testfeature01 | 51 spec.refine.include.keys[0] = "testfeature01"; |
46 //intstring 2 > testfeature10 | 52 results = audiodb_query_spec(adb, &spec); |
47 //floatstring 1 0 >> testfeature10 | 53 if(!results || results->nresults != 1) return 1; |
48 ivals[0]=2; | 54 result_present_or_fail(results, "testfeature01", 0.5, 0, 0); |
49 dvals[0]=0; dvals[1]=1; | 55 audiodb_query_free_results(adb, &spec, results); |
50 maketestfile("testfeature01",ivals,dvals,2); | |
51 ivals[0]=2; | |
52 dvals[0]=1; dvals[1]=0; | |
53 maketestfile("testfeature10",ivals,dvals,2); | |
54 | 56 |
57 spec.refine.include.keys[0] = "testfeature10"; | |
58 results = audiodb_query_spec(adb, &spec); | |
59 if(!results || results->nresults != 1) return 1; | |
60 result_present_or_fail(results, "testfeature10", 0, 0, 0); | |
61 audiodb_query_free_results(adb, &spec, results); | |
55 | 62 |
56 /* insertions */ | 63 spec.refine.include.nkeys = 2; |
57 //${AUDIODB} -d testdb -I -f testfeature01 | 64 spec.refine.include.keys[0] = "testfeature01"; |
58 //${AUDIODB} -d testdb -I -f testfeature10 | 65 spec.refine.include.keys[1] = "testfeature10"; |
59 myinsert.features="testfeature01"; | 66 results = audiodb_query_spec(adb, &spec); |
60 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | 67 if(!results || results->nresults != 2) return 1; |
61 myinsert.features="testfeature10"; | 68 result_present_or_fail(results, "testfeature01", 0.5, 0, 0); |
62 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | 69 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
63 | 70 audiodb_query_free_results(adb, &spec, results); |
64 | 71 |
65 /* query */ | 72 spec.refine.include.nkeys = 0; |
66 //echo "query point (0.0,0.5)" | 73 spec.refine.include.keys = NULL; |
67 //intstring 2 > testquery | 74 spec.refine.flags = ADB_REFINE_EXCLUDE_KEYLIST; |
68 //floatstring 0 0.5 >> testquery | 75 spec.refine.exclude.nkeys = 1; |
69 ivals[0]=2; | 76 spec.refine.exclude.keys = keys; |
70 dvals[0]=0; dvals[1]=0.5; | 77 spec.refine.exclude.keys[0] = "testfeature10"; |
71 maketestfile("testquery",ivals,dvals,2); | 78 results = audiodb_query_spec(adb, &spec); |
79 if(!results || results->nresults != 1) return 1; | |
80 result_present_or_fail(results, "testfeature01", 0.5, 0, 0); | |
81 audiodb_query_free_results(adb, &spec, results); | |
72 | 82 |
73 /* test a sequence query */ | 83 spec.refine.exclude.keys[0] = "testfeature01"; |
74 //${AUDIODB} -d testdb -Q track -l 1 -f testquery > testoutput | 84 results = audiodb_query_spec(adb, &spec); |
75 //echo testfeature01 0.5 0 0 > test-expected-output | 85 if(!results || results->nresults != 1) return 1; |
76 //echo testfeature10 0 0 0 >> test-expected-output | 86 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
77 //cmp testoutput test-expected-output | 87 audiodb_query_free_results(adb, &spec, results); |
78 myadbquery.querytype="track"; | |
79 myadbquery.feature="testquery"; | |
80 myadbquery.sequencelength="1"; | |
81 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
82 size=myadbqueryresult.sizeRlist; | |
83 | 88 |
84 /* check the test values */ | 89 audiodb_close(adb); |
85 if (size != 2) {returnval = -1;}; | |
86 if (testoneresult(&myadbqueryresult,0,"testfeature01",0.5,0,0)) {returnval = -1;}; | |
87 if (testoneresult(&myadbqueryresult,1,"testfeature10",0,0,0)) {returnval = -1;}; | |
88 | 90 |
89 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K /dev/null > testoutput | 91 return 104; |
90 //cat /dev/null > test-expected-output | |
91 //cmp testoutput test-expected-output | |
92 myadbquery.querytype="track"; | |
93 myadbquery.feature="testquery"; | |
94 myadbquery.keylist="/dev/null"; | |
95 myadbquery.sequencelength="1"; | |
96 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
97 size=myadbqueryresult.sizeRlist; | |
98 | |
99 /* check the test values */ | |
100 if (size != 0) {returnval = -1;}; | |
101 | |
102 | |
103 | |
104 //echo testfeature01 > testkl.txt | |
105 makekeylistfile("testkl.txt","testfeature01"); | |
106 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt > testoutput | |
107 //echo testfeature01 0.5 0 0 > test-expected-output | |
108 //cmp testoutput test-expected-output | |
109 myadbquery.querytype="track"; | |
110 myadbquery.feature="testquery"; | |
111 myadbquery.keylist="testkl.txt"; | |
112 myadbquery.sequencelength="1"; | |
113 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
114 | |
115 size=myadbqueryresult.sizeRlist; | |
116 //dump_query(&myadbquery,&myadbqueryresult); | |
117 | |
118 /* check the test values */ | |
119 if (size != 1) {returnval = -1;}; | |
120 if (testoneresult(&myadbqueryresult,0,"testfeature01",0.5,0,0)) {returnval = -1;}; | |
121 | |
122 | |
123 | |
124 | |
125 //echo testfeature10 > testkl.txt | |
126 makekeylistfile("testkl.txt","testfeature10"); | |
127 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt > testoutput | |
128 //echo testfeature10 0 0 0 > test-expected-output | |
129 //cmp testoutput test-expected-output | |
130 myadbquery.querytype="track"; | |
131 myadbquery.feature="testquery"; | |
132 myadbquery.keylist="testkl.txt"; | |
133 myadbquery.sequencelength="1"; | |
134 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
135 | |
136 size=myadbqueryresult.sizeRlist; | |
137 //dump_query(&myadbquery,&myadbqueryresult); | |
138 | |
139 /* check the test values */ | |
140 if (size != 1) {returnval = -1;}; | |
141 if (testoneresult(&myadbqueryresult,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
142 | |
143 | |
144 | |
145 //echo testfeature10 > testkl.txt | |
146 makekeylistfile("testkl.txt","testfeature10"); | |
147 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt -r 1 > testoutput | |
148 //echo testfeature10 0 0 0 > test-expected-output | |
149 //cmp testoutput test-expected-output | |
150 myadbquery.querytype="track"; | |
151 myadbquery.feature="testquery"; | |
152 myadbquery.keylist="testkl.txt"; | |
153 myadbquery.sequencelength="1"; | |
154 myadbquery.resultlength="1"; | |
155 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
156 | |
157 size=myadbqueryresult.sizeRlist; | |
158 //dump_query(&myadbquery,&myadbqueryresult); | |
159 | |
160 /* check the test values */ | |
161 if (size != 1) {returnval = -1;}; | |
162 if (testoneresult(&myadbqueryresult,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
163 | |
164 //echo "query point (0.5,0.0)" | |
165 //intstring 2 > testquery | |
166 //floatstring 0.5 0 >> testquery | |
167 ivals[0]=2; | |
168 dvals[0]=0.5; dvals[1]=0.0; | |
169 maketestfile("testquery",ivals,dvals,2); | |
170 | |
171 //${AUDIODB} -d testdb -Q track -l 1 -f testquery > testoutput | |
172 //echo testfeature10 0.5 0 0 > test-expected-output | |
173 //echo testfeature01 0 0 0 >> test-expected-output | |
174 //cmp testoutput test-expected-output | |
175 myadbquery.querytype="track"; | |
176 myadbquery.feature="testquery"; | |
177 myadbquery.keylist=NULL; | |
178 myadbquery.sequencelength="1"; | |
179 myadbquery.resultlength=NULL; | |
180 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
181 | |
182 size=myadbqueryresult.sizeRlist; | |
183 //dump_query(&myadbquery,&myadbqueryresult); | |
184 | |
185 /* check the test values */ | |
186 if (size != 2) {returnval = -1;}; | |
187 if (testoneresult(&myadbqueryresult,0,"testfeature10",0.5,0,0)) {returnval = -1;}; | |
188 if (testoneresult(&myadbqueryresult,1,"testfeature01",0,0,0)) {returnval = -1;}; | |
189 | |
190 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K /dev/null > testoutput | |
191 //cat /dev/null > test-expected-output | |
192 //cmp testoutput test-expected-output | |
193 myadbquery.querytype="track"; | |
194 myadbquery.feature="testquery"; | |
195 myadbquery.keylist="/dev/null"; | |
196 myadbquery.sequencelength="1"; | |
197 myadbquery.resultlength=NULL; | |
198 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
199 | |
200 size=myadbqueryresult.sizeRlist; | |
201 //dump_query(&myadbquery,&myadbqueryresult); | |
202 | |
203 /* check the test values */ | |
204 if (size != 0) {returnval = -1;}; | |
205 | |
206 //echo testfeature10 > testkl.txt | |
207 makekeylistfile("testkl.txt","testfeature10"); | |
208 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt > testoutput | |
209 //echo testfeature10 0.5 0 0 > test-expected-output | |
210 //cmp testoutput test-expected-output | |
211 myadbquery.querytype="track"; | |
212 myadbquery.feature="testquery"; | |
213 myadbquery.keylist="testkl.txt"; | |
214 myadbquery.sequencelength="1"; | |
215 myadbquery.resultlength=NULL; | |
216 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
217 | |
218 size=myadbqueryresult.sizeRlist; | |
219 //dump_query(&myadbquery,&myadbqueryresult); | |
220 | |
221 /* check the test values */ | |
222 if (size != 1) {returnval = -1;}; | |
223 if (testoneresult(&myadbqueryresult,0,"testfeature10",0.5,0,0)) {returnval = -1;}; | |
224 | |
225 //echo testfeature01 > testkl.txt | |
226 makekeylistfile("testkl.txt","testfeature01"); | |
227 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt > testoutput | |
228 //echo testfeature01 0 0 0 > test-expected-output | |
229 //cmp testoutput test-expected-output | |
230 myadbquery.querytype="track"; | |
231 myadbquery.feature="testquery"; | |
232 myadbquery.keylist="testkl.txt"; | |
233 myadbquery.sequencelength="1"; | |
234 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
235 | |
236 size=myadbqueryresult.sizeRlist; | |
237 //dump_query(&myadbquery,&myadbqueryresult); | |
238 | |
239 /* check the test values */ | |
240 if (size != 1) {returnval = -1;}; | |
241 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
242 | |
243 //echo testfeature01 > testkl.txt | |
244 makekeylistfile("testkl.txt","testfeature01"); | |
245 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K testkl.txt -r 1 > testoutput | |
246 //echo testfeature01 0 0 0 > test-expected-output | |
247 //cmp testoutput test-expected-output | |
248 myadbquery.querytype="track"; | |
249 myadbquery.feature="testquery"; | |
250 myadbquery.keylist="testkl.txt"; | |
251 myadbquery.sequencelength="1"; | |
252 myadbquery.resultlength="1"; | |
253 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
254 | |
255 size=myadbqueryresult.sizeRlist; | |
256 //dump_query(&myadbquery,&myadbqueryresult); | |
257 | |
258 /* check the test values */ | |
259 if (size != 1) {returnval = -1;}; | |
260 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
261 | |
262 | |
263 | |
264 | |
265 // printf("returnval:%d\n", returnval); | |
266 | |
267 return(returnval); | |
268 } | 92 } |
269 |