Mercurial > hg > audiodb
comparison libtests/0032/prog1.c @ 355:94c18f128ce8
First version of the API, committed to the main trunk. Thanks Christophe, for all the help!
author | mas01ik |
---|---|
date | Wed, 12 Nov 2008 10:21:06 +0000 |
parents | |
children | e072aa1611f5 342822c2d49a |
comparison
equal
deleted
inserted
replaced
354:4871a3ed9e36 | 355:94c18f128ce8 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.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 | |
14 #include "../../audioDB_API.h" | |
15 #include "../test_utils_lib.h" | |
16 | |
17 | |
18 int main(int argc, char **argv){ | |
19 | |
20 int returnval=0; | |
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 | |
30 | |
31 /* remove old directory */ | |
32 //if [ -f testdb ]; then rm -f testdb; fi | |
33 clean_remove_db(databasename); | |
34 | |
35 /* create new db */ | |
36 //${AUDIODB} -d testdb -N | |
37 mydbp=audiodb_create(databasename,0,0,0); | |
38 | |
39 /* turn on l2 power */ | |
40 //${AUDIODB} -d testdb -L | |
41 if (audiodb_l2norm(mydbp)) {returnval=-1;}; | |
42 | |
43 /* make feature files */ | |
44 //intstring 2 > testfeature01 | |
45 //floatstring 0 1 >> testfeature01 | |
46 //intstring 2 > testfeature10 | |
47 //floatstring 1 0 >> testfeature10 | |
48 ivals[0]=2; | |
49 dvals[0]=0; dvals[1]=1; | |
50 maketestfile("testfeature01",ivals,dvals,2); | |
51 ivals[0]=2; | |
52 dvals[0]=1; dvals[1]=0; | |
53 maketestfile("testfeature10",ivals,dvals,2); | |
54 | |
55 | |
56 /* insertions */ | |
57 //${AUDIODB} -d testdb -I -f testfeature01 | |
58 //${AUDIODB} -d testdb -I -f testfeature10 | |
59 myinsert.features="testfeature01"; | |
60 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | |
61 myinsert.features="testfeature10"; | |
62 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | |
63 | |
64 | |
65 /* query */ | |
66 //echo "query point (0.0,0.5)" | |
67 //intstring 2 > testquery | |
68 //floatstring 0 0.5 >> testquery | |
69 ivals[0]=2; | |
70 dvals[0]=0; dvals[1]=0.5; | |
71 maketestfile("testquery",ivals,dvals,2); | |
72 | |
73 /* test a sequence query */ | |
74 //${AUDIODB} -d testdb -Q track -l 1 -f testquery > testoutput | |
75 //echo testfeature01 0.5 0 0 > test-expected-output | |
76 //echo testfeature10 0 0 0 >> test-expected-output | |
77 //cmp testoutput test-expected-output | |
78 myadbquery.querytype="track"; | |
79 myadbquery.feature="testquery"; | |
80 myadbquery.sequencelength="1"; | |
81 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
82 size=myadbqueryresult.sizeRlist; | |
83 | |
84 /* check the test values */ | |
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 | |
89 //${AUDIODB} -d testdb -Q track -l 1 -f testquery -K /dev/null > testoutput | |
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 } | |
269 |