Mercurial > hg > audiodb
comparison libtests/0025/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 void maketimesfile(char * filename); | |
18 | |
19 int main(int argc, char **argv){ | |
20 | |
21 int returnval=0; | |
22 adb_ptr mydbp={0}; | |
23 int ivals[10]; | |
24 double dvals[10]; | |
25 adb_insert_t myinsert={0}; | |
26 char * databasename="testdb"; | |
27 adb_query_t myadbquery={0}; | |
28 adb_queryresult_t myadbqueryresult={0}; | |
29 int size=0; | |
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 //intstring 2 > testfeature | |
40 //floatstring 0 0.5 >> testfeature | |
41 //floatstring 0.5 0 >> testfeature | |
42 ivals[0]=2; | |
43 dvals[0]=0; dvals[1]=0.5; dvals[2]=0.5; dvals[3]=0; | |
44 maketestfile("testfeature",ivals,dvals,4); | |
45 | |
46 | |
47 //cat > testtimes <<EOF | |
48 //0 | |
49 //1 | |
50 //2 | |
51 //EOF | |
52 maketimesfile("testtimes"); | |
53 | |
54 //${AUDIODB} -d testdb -I -f testfeature -t testtimes | |
55 myinsert.features="testfeature"; | |
56 if(audiodb_insert(mydbp,&myinsert)){ | |
57 returnval=-1; | |
58 }; | |
59 | |
60 //# sequence queries require L2NORM | |
61 //${AUDIODB} -d testdb -L | |
62 if(audiodb_l2norm(mydbp)){ | |
63 returnval=-1; | |
64 }; | |
65 | |
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 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
74 //echo testfeature 1 0 0 > test-expected-output | |
75 //cmp testoutput test-expected-output | |
76 myadbquery.querytype="sequence"; | |
77 myadbquery.feature="testquery"; | |
78 myadbquery.sequencelength="1"; | |
79 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
80 size=myadbqueryresult.sizeRlist; | |
81 | |
82 //dump_query(&myadbquery,&myadbqueryresult); | |
83 ///* check the test values */ | |
84 if (size != 1) {returnval = -1;}; | |
85 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;}; | |
86 | |
87 | |
88 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
89 ////echo testfeature 0 0 0 > test-expected-output | |
90 ////cmp testoutput test-expected-output | |
91 myadbquery.querytype="sequence"; | |
92 myadbquery.feature="testquery"; | |
93 myadbquery.sequencelength="1"; | |
94 myadbquery.numpoints="1"; | |
95 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
96 size=myadbqueryresult.sizeRlist; | |
97 | |
98 //dump_query(&myadbquery,&myadbqueryresult); | |
99 ///* check the test values */ | |
100 if (size != 1) {returnval = -1;}; | |
101 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,0)) {returnval = -1;}; | |
102 | |
103 ////echo "query point (0.5,0.0)" | |
104 ////intstring 2 > testquery | |
105 ////floatstring 0.5 0 >> testquery | |
106 ivals[0]=2; | |
107 dvals[0]=0.5; dvals[1]=0.0; | |
108 maketestfile("testquery",ivals,dvals,2); | |
109 | |
110 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
111 ////echo testfeature 1 0 1 > test-expected-output | |
112 ////cmp testoutput test-expected-output | |
113 myadbquery.querytype="sequence"; | |
114 myadbquery.feature="testquery"; | |
115 myadbquery.sequencelength="1"; | |
116 myadbquery.numpoints=NULL; | |
117 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
118 size=myadbqueryresult.sizeRlist; | |
119 | |
120 //dump_query(&myadbquery,&myadbqueryresult); | |
121 ///* check the test values */ | |
122 if (size != 1) {returnval = -1;}; | |
123 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,1)) {returnval = -1;}; | |
124 | |
125 | |
126 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
127 ////echo testfeature 0 0 1 > test-expected-output | |
128 ////cmp testoutput test-expected-output | |
129 myadbquery.querytype="sequence"; | |
130 myadbquery.feature="testquery"; | |
131 myadbquery.sequencelength="1"; | |
132 myadbquery.numpoints="1"; | |
133 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
134 size=myadbqueryresult.sizeRlist; | |
135 | |
136 //dump_query(&myadbquery,&myadbqueryresult); | |
137 ///* check the test values */ | |
138 if (size != 1) {returnval = -1;}; | |
139 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,1)) {returnval = -1;}; | |
140 | |
141 | |
142 | |
143 //printf("returnval:%d\n",returnval); | |
144 return(returnval); | |
145 } | |
146 | |
147 void maketimesfile(char * filename){ | |
148 | |
149 FILE * myfile; | |
150 | |
151 myfile=fopen(filename,"w"); | |
152 fprintf(myfile,"0\n"); | |
153 fprintf(myfile,"1\n"); | |
154 fprintf(myfile,"2\n"); | |
155 fflush(myfile); | |
156 fclose(myfile); | |
157 | |
158 } |