comparison libtests/0033/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 adb_datum_t datum1 = {1, 2, "testfeature01", (double[2]) {0, 1}};
12 adb_datum_t datum2 = {1, 2, "testfeature10", (double[2]) {1, 0}};
13 if(audiodb_insert_datum(adb, &datum1))
14 return 1;
15 if(audiodb_insert_datum(adb, &datum2))
16 return 1;
17 if(audiodb_l2norm(adb))
18 return 1;
17 19
18 int main(int argc, char **argv){ 20 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}};
19 21
20 int returnval=0; 22 adb_query_id_t qid = {0};
21 adb_ptr mydbp={0}; 23 qid.datum = &query;
22 int ivals[10]; 24 qid.sequence_length = 1;
23 double dvals[10]; 25 qid.sequence_start = 0;
24 adb_insert_t myinsert={0}; 26 adb_query_parameters_t parms =
25 char * databasename="testdb"; 27 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10};
26 adb_query_t myadbquery={0}; 28 adb_query_refine_t refine = {0};
27 adb_queryresult_t myadbqueryresult={0}; 29 refine.flags |= ADB_REFINE_RADIUS;
28 int size=0; 30 refine.radius = 5;
31 refine.hopsize = 1;
29 32
30 /* remove old directory */ 33 adb_query_spec_t spec;
31 //if [ -f testdb ]; then rm -f testdb; fi 34 spec.qid = qid;
32 clean_remove_db(databasename); 35 spec.params = parms;
36 spec.refine = refine;
33 37
34 /* create new db */ 38 adb_query_results_t *results = audiodb_query_spec(adb, &spec);
35 //${AUDIODB} -d testdb -N 39 if(!results || results->nresults != 2) return 1;
36 mydbp=audiodb_create(databasename,0,0,0); 40 result_present_or_fail(results, "testfeature01", 0, 0, 0);
41 result_present_or_fail(results, "testfeature10", 2, 0, 0);
42 audiodb_query_free_results(adb, &spec, results);
37 43
38 //intstring 2 > testfeature01 44 /* the test in the original test suite for
39 //floatstring 0 1 >> testfeature01 45 * audioDB-the-command-line-program alters the parms.ntracks, which
40 //intstring 2 > testfeature10 46 * is not very meaningful in this context (given that we don't do
41 //floatstring 1 0 >> testfeature10 47 * aggregation, but simply return valid points); here instead we
42 ivals[0]=2; 48 * check that radius filtering works. */
43 dvals[0]=0; dvals[1]=1; 49 spec.refine.radius = 1;
44 maketestfile("testfeature01",ivals,dvals,2); 50 results = audiodb_query_spec(adb, &spec);
45 ivals[0]=2; 51 if(!results || results->nresults != 1) return 1;
46 dvals[0]=1; dvals[1]=0; 52 result_present_or_fail(results, "testfeature01", 0, 0, 0);
47 maketestfile("testfeature10",ivals,dvals,2); 53 audiodb_query_free_results(adb, &spec, results);
48 54
49 //${AUDIODB} -d testdb -I -f testfeature01 55 spec.refine.radius = 5;
50 //${AUDIODB} -d testdb -I -f testfeature10 56 spec.refine.flags |= ADB_REFINE_INCLUDE_KEYLIST;
51 myinsert.features="testfeature01"; 57 spec.refine.include.nkeys = 0;
52 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; 58 spec.refine.include.keys = keys;
53 myinsert.features="testfeature10"; 59 results = audiodb_query_spec(adb, &spec);
54 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; 60 if(!results || results->nresults != 0) return 1;
61 audiodb_query_free_results(adb, &spec, results);
55 62
56 //# sequence queries require L2NORM 63 spec.refine.include.nkeys = 1;
57 //${AUDIODB} -d testdb -L 64 spec.refine.include.keys[0] = "testfeature01";
58 if (audiodb_l2norm(mydbp)) {returnval=-1;}; 65 results = audiodb_query_spec(adb, &spec);
66 if(!results || results->nresults != 1) return 1;
67 result_present_or_fail(results, "testfeature01", 0, 0, 0);
68 audiodb_query_free_results(adb, &spec, results);
59 69
60 //echo "query point (0.0,0.5)" 70 spec.refine.radius = 1;
61 //intstring 2 > testquery 71 results = audiodb_query_spec(adb, &spec);
62 //floatstring 0 0.5 >> testquery 72 if(!results || results->nresults != 1) return 1;
63 ivals[0]=2; 73 result_present_or_fail(results, "testfeature01", 0, 0, 0);
64 dvals[0]=0; dvals[1]=0.5; 74 audiodb_query_free_results(adb, &spec, results);
65 maketestfile("testquery",ivals,dvals,2);
66 75
67 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput 76 spec.refine.radius = 5;
68 //audioDB -Q sequence -d testdb -f testquery -R 5 -l 1 77 spec.refine.include.keys[0] = "testfeature10";
69 //echo testfeature01 1 > test-expected-output 78 results = audiodb_query_spec(adb, &spec);
70 //echo testfeature10 1 >> test-expected-output 79 if(!results || results->nresults != 1) return 1;
71 //cmp testoutput test-expected-output 80 result_present_or_fail(results, "testfeature10", 2, 0, 0);
72 myadbquery.querytype="sequence"; 81 audiodb_query_free_results(adb, &spec, results);
73 myadbquery.feature="testquery";
74 myadbquery.sequencelength="1";
75 myadbquery.radius="5";
76 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
77 size=myadbqueryresult.sizeRlist;
78 82
79 /* check the test values */ 83 spec.refine.radius = 1;
80 if (size != 2) {returnval = -1;}; 84 spec.refine.include.keys[0] = "testfeature10";
81 if (testoneradiusresult(&myadbqueryresult,0,"testfeature01",1)) {returnval = -1;}; 85 results = audiodb_query_spec(adb, &spec);
82 if (testoneradiusresult(&myadbqueryresult,1,"testfeature10",1)) {returnval = -1;}; 86 if(!results || results->nresults != 0) return 1;
87 audiodb_query_free_results(adb, &spec, results);
83 88
84 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K /dev/null -R 5 > testoutput 89 audiodb_close(adb);
85 //cat /dev/null > test-expected-output
86 //cmp testoutput test-expected-output
87 myadbquery.querytype="sequence";
88 myadbquery.feature="testquery";
89 myadbquery.keylist="/dev/null";
90 myadbquery.sequencelength="1";
91 myadbquery.radius="5";
92 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
93 size=myadbqueryresult.sizeRlist;
94 90
95 /* check the test values */ 91 return 104;
96 if (size != 0) {returnval = -1;};
97
98
99
100 //echo testfeature01 > testkl.txt
101 makekeylistfile("testkl.txt","testfeature01");
102 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -R 5 > testoutput
103 //echo testfeature01 1 > 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 myadbquery.radius="5";
110 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
111 size=myadbqueryresult.sizeRlist;
112
113 /* check the test values */
114 if (size != 1) {returnval = -1;};
115 if (testoneradiusresult(&myadbqueryresult,0,"testfeature01",1)) {returnval = -1;};
116
117 //echo testfeature10 > testkl.txt
118 makekeylistfile("testkl.txt","testfeature10");
119 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -R 5 > testoutput
120 //echo testfeature10 1 > test-expected-output
121 //cmp testoutput test-expected-output
122 myadbquery.querytype="sequence";
123 myadbquery.feature="testquery";
124 myadbquery.keylist="testkl.txt";
125 myadbquery.sequencelength="1";
126 myadbquery.radius="5";
127 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
128 size=myadbqueryresult.sizeRlist;
129
130 /* check the test values */
131 if (size != 1) {returnval = -1;};
132 if (testoneradiusresult(&myadbqueryresult,0,"testfeature10",1)) {returnval = -1;};
133
134 //echo testfeature10 > testkl.txt
135 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -r 1 -R 5 > testoutput
136 //echo testfeature10 1 > test-expected-output
137 //cmp testoutput test-expected-output
138 myadbquery.querytype="sequence";
139 myadbquery.feature="testquery";
140 myadbquery.keylist="testkl.txt";
141 myadbquery.sequencelength="1";
142 myadbquery.radius="5";
143 myadbquery.resultlength="1";
144 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
145 size=myadbqueryresult.sizeRlist;
146
147 /* check the test values */
148 if (size != 1) {returnval = -1;};
149 if (testoneradiusresult(&myadbqueryresult,0,"testfeature10",1)) {returnval = -1;};
150
151
152 //# NB: one might be tempted to insert a test here for having both keys
153 //# in the keylist, but in non-database order, and then checking that
154 //# the result list is also in that non-database order. I think that
155 //# would be misguided, as the efficient way of dealing with such a
156 //# keylist is to advance as-sequentially-as-possible through the
157 //# database; it just so happens that our current implementation is not
158 //# so smart.
159
160 //echo "query point (0.5,0.0)"
161 //intstring 2 > testquery
162 //floatstring 0.5 0 >> testquery
163 ivals[0]=2;
164 dvals[0]=0.5; dvals[1]=0.0;
165 maketestfile("testquery",ivals,dvals,2);
166
167 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput
168 //echo testfeature01 1 > test-expected-output
169 //echo testfeature10 1 >> test-expected-output
170 //cmp testoutput test-expected-output
171 myadbquery.querytype="sequence";
172 myadbquery.feature="testquery";
173 myadbquery.keylist=NULL;
174 myadbquery.sequencelength="1";
175 myadbquery.radius="5";
176 myadbquery.resultlength=NULL;
177 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
178 size=myadbqueryresult.sizeRlist;
179
180 /* check the test values */
181 if (size != 2) {returnval = -1;};
182 if (testoneradiusresult(&myadbqueryresult,0,"testfeature01",1)) {returnval = -1;};
183 if (testoneradiusresult(&myadbqueryresult,1,"testfeature10",1)) {returnval = -1;};
184
185 //echo testfeature10 > testkl.txt
186 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K testkl.txt -r 1 -R 5 > testoutput
187 //echo testfeature10 1 > test-expected-output
188 //cmp testoutput test-expected-output
189 myadbquery.querytype="sequence";
190 myadbquery.feature="testquery";
191 myadbquery.keylist="testkl.txt";
192 myadbquery.sequencelength="1";
193 myadbquery.radius="5";
194 myadbquery.resultlength="1";
195 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
196 size=myadbqueryresult.sizeRlist;
197
198 /* check the test values */
199 if (size != 1) {returnval = -1;};
200 if (testoneradiusresult(&myadbqueryresult,0,"testfeature10",1)) {returnval = -1;};
201
202
203 //fprintf(stderr,"returnval:%d\n",returnval);
204 return(returnval);
205 } 92 }
206