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