Mercurial > hg > audiodb
comparison libtests/0033/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 /* remove old directory */ | |
31 //if [ -f testdb ]; then rm -f testdb; fi | |
32 clean_remove_db(databasename); | |
33 | |
34 /* create new db */ | |
35 //${AUDIODB} -d testdb -N | |
36 mydbp=audiodb_create(databasename,0,0,0); | |
37 | |
38 //intstring 2 > testfeature01 | |
39 //floatstring 0 1 >> testfeature01 | |
40 //intstring 2 > testfeature10 | |
41 //floatstring 1 0 >> testfeature10 | |
42 ivals[0]=2; | |
43 dvals[0]=0; dvals[1]=1; | |
44 maketestfile("testfeature01",ivals,dvals,2); | |
45 ivals[0]=2; | |
46 dvals[0]=1; dvals[1]=0; | |
47 maketestfile("testfeature10",ivals,dvals,2); | |
48 | |
49 //${AUDIODB} -d testdb -I -f testfeature01 | |
50 //${AUDIODB} -d testdb -I -f testfeature10 | |
51 myinsert.features="testfeature01"; | |
52 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | |
53 myinsert.features="testfeature10"; | |
54 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; }; | |
55 | |
56 //# sequence queries require L2NORM | |
57 //${AUDIODB} -d testdb -L | |
58 if (audiodb_l2norm(mydbp)) {returnval=-1;}; | |
59 | |
60 //echo "query point (0.0,0.5)" | |
61 //intstring 2 > testquery | |
62 //floatstring 0 0.5 >> testquery | |
63 ivals[0]=2; | |
64 dvals[0]=0; dvals[1]=0.5; | |
65 maketestfile("testquery",ivals,dvals,2); | |
66 | |
67 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput | |
68 //audioDB -Q sequence -d testdb -f testquery -R 5 -l 1 | |
69 //echo testfeature01 1 > test-expected-output | |
70 //echo testfeature10 1 >> test-expected-output | |
71 //cmp testoutput test-expected-output | |
72 myadbquery.querytype="sequence"; | |
73 myadbquery.feature="testquery"; | |
74 myadbquery.sequencelength="1"; | |
75 myadbquery.radius="5"; | |
76 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
77 size=myadbqueryresult.sizeRlist; | |
78 | |
79 /* check the test values */ | |
80 if (size != 2) {returnval = -1;}; | |
81 if (testoneradiusresult(&myadbqueryresult,0,"testfeature01",1)) {returnval = -1;}; | |
82 if (testoneradiusresult(&myadbqueryresult,1,"testfeature10",1)) {returnval = -1;}; | |
83 | |
84 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -K /dev/null -R 5 > testoutput | |
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 | |
95 /* check the test values */ | |
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 } | |
206 |