mas01ik@355
|
1 #include <stdio.h>
|
mas01ik@355
|
2 #include <stdlib.h>
|
mas01ik@355
|
3 #include <string.h>
|
mas01ik@355
|
4 #include <sysexits.h>
|
mas01ik@355
|
5 #include <fcntl.h>
|
mas01ik@355
|
6 #include <dirent.h>
|
mas01ik@355
|
7 #include <unistd.h>
|
mas01ik@355
|
8 #include <sys/stat.h>
|
mas01ik@355
|
9 /*
|
mas01ik@355
|
10 * * #define NDEBUG
|
mas01ik@355
|
11 * * */
|
mas01ik@355
|
12 #include <assert.h>
|
mas01ik@355
|
13
|
mas01ik@355
|
14 #include "../../audioDB_API.h"
|
mas01ik@355
|
15 #include "../test_utils_lib.h"
|
mas01ik@355
|
16
|
mas01ik@355
|
17 void maketimesfile(char * filename);
|
mas01ik@355
|
18
|
mas01ik@355
|
19 int main(int argc, char **argv){
|
mas01ik@355
|
20
|
mas01ik@355
|
21 int returnval=0;
|
mas01ik@355
|
22 adb_ptr mydbp={0};
|
mas01ik@355
|
23 int ivals[10];
|
mas01ik@355
|
24 double dvals[10];
|
mas01ik@355
|
25 adb_insert_t myinsert={0};
|
mas01ik@355
|
26 char * databasename="testdb";
|
mas01ik@355
|
27 adb_query_t myadbquery={0};
|
mas01ik@355
|
28 adb_queryresult_t myadbqueryresult={0};
|
mas01ik@355
|
29 int size=0;
|
mas01ik@355
|
30
|
mas01ik@355
|
31 /* remove old directory */
|
mas01ik@355
|
32 //if [ -f testdb ]; then rm -f testdb; fi
|
mas01ik@355
|
33 clean_remove_db(databasename);
|
mas01ik@355
|
34
|
mas01ik@355
|
35 /* create new db */
|
mas01ik@355
|
36 //${AUDIODB} -d testdb -N
|
mas01ik@355
|
37 mydbp=audiodb_create(databasename,0,0,0);
|
mas01ik@355
|
38
|
mas01ik@355
|
39 //intstring 2 > testfeature
|
mas01ik@355
|
40 //floatstring 0 0.5 >> testfeature
|
mas01ik@355
|
41 //floatstring 0.5 0 >> testfeature
|
mas01ik@355
|
42 ivals[0]=2;
|
mas01ik@355
|
43 dvals[0]=0; dvals[1]=0.5; dvals[2]=0.5; dvals[3]=0;
|
mas01ik@355
|
44 maketestfile("testfeature",ivals,dvals,4);
|
mas01ik@355
|
45
|
mas01ik@355
|
46
|
mas01ik@355
|
47 //cat > testtimes <<EOF
|
mas01ik@355
|
48 //0
|
mas01ik@355
|
49 //1
|
mas01ik@355
|
50 //2
|
mas01ik@355
|
51 //EOF
|
mas01ik@355
|
52 maketimesfile("testtimes");
|
mas01ik@355
|
53
|
mas01ik@355
|
54 //${AUDIODB} -d testdb -I -f testfeature -t testtimes
|
mas01ik@355
|
55 myinsert.features="testfeature";
|
mas01ik@355
|
56 if(audiodb_insert(mydbp,&myinsert)){
|
mas01ik@355
|
57 returnval=-1;
|
mas01ik@355
|
58 };
|
mas01ik@355
|
59
|
mas01ik@355
|
60 //# sequence queries require L2NORM
|
mas01ik@355
|
61 //${AUDIODB} -d testdb -L
|
mas01ik@355
|
62 if(audiodb_l2norm(mydbp)){
|
mas01ik@355
|
63 returnval=-1;
|
mas01ik@355
|
64 };
|
mas01ik@355
|
65
|
mas01ik@355
|
66 //echo "query point (0.0,0.5)"
|
mas01ik@355
|
67 //intstring 2 > testquery
|
mas01ik@355
|
68 //floatstring 0 0.5 >> testquery
|
mas01ik@355
|
69 ivals[0]=2;
|
mas01ik@355
|
70 dvals[0]=0; dvals[1]=0.5;
|
mas01ik@355
|
71 maketestfile("testquery",ivals,dvals,2);
|
mas01ik@355
|
72
|
mas01ik@355
|
73 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput
|
mas01ik@355
|
74 //echo testfeature 1 0 0 > test-expected-output
|
mas01ik@355
|
75 //cmp testoutput test-expected-output
|
mas01ik@355
|
76 myadbquery.querytype="sequence";
|
mas01ik@355
|
77 myadbquery.feature="testquery";
|
mas01ik@355
|
78 myadbquery.sequencelength="1";
|
mas01ik@355
|
79 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
80 size=myadbqueryresult.sizeRlist;
|
mas01ik@355
|
81
|
mas01ik@355
|
82 //dump_query(&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
83 ///* check the test values */
|
mas01ik@355
|
84 if (size != 1) {returnval = -1;};
|
mas01ik@355
|
85 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;};
|
mas01ik@355
|
86
|
mas01ik@355
|
87
|
mas01ik@355
|
88 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput
|
mas01ik@355
|
89 ////echo testfeature 0 0 0 > test-expected-output
|
mas01ik@355
|
90 ////cmp testoutput test-expected-output
|
mas01ik@355
|
91 myadbquery.querytype="sequence";
|
mas01ik@355
|
92 myadbquery.feature="testquery";
|
mas01ik@355
|
93 myadbquery.sequencelength="1";
|
mas01ik@355
|
94 myadbquery.numpoints="1";
|
mas01ik@355
|
95 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
96 size=myadbqueryresult.sizeRlist;
|
mas01ik@355
|
97
|
mas01ik@355
|
98 //dump_query(&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
99 ///* check the test values */
|
mas01ik@355
|
100 if (size != 1) {returnval = -1;};
|
mas01ik@355
|
101 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,0)) {returnval = -1;};
|
mas01ik@355
|
102
|
mas01ik@355
|
103 ////echo "query point (0.5,0.0)"
|
mas01ik@355
|
104 ////intstring 2 > testquery
|
mas01ik@355
|
105 ////floatstring 0.5 0 >> testquery
|
mas01ik@355
|
106 ivals[0]=2;
|
mas01ik@355
|
107 dvals[0]=0.5; dvals[1]=0.0;
|
mas01ik@355
|
108 maketestfile("testquery",ivals,dvals,2);
|
mas01ik@355
|
109
|
mas01ik@355
|
110 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput
|
mas01ik@355
|
111 ////echo testfeature 1 0 1 > test-expected-output
|
mas01ik@355
|
112 ////cmp testoutput test-expected-output
|
mas01ik@355
|
113 myadbquery.querytype="sequence";
|
mas01ik@355
|
114 myadbquery.feature="testquery";
|
mas01ik@355
|
115 myadbquery.sequencelength="1";
|
mas01ik@355
|
116 myadbquery.numpoints=NULL;
|
mas01ik@355
|
117 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
118 size=myadbqueryresult.sizeRlist;
|
mas01ik@355
|
119
|
mas01ik@355
|
120 //dump_query(&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
121 ///* check the test values */
|
mas01ik@355
|
122 if (size != 1) {returnval = -1;};
|
mas01ik@355
|
123 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,1)) {returnval = -1;};
|
mas01ik@355
|
124
|
mas01ik@355
|
125
|
mas01ik@355
|
126 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput
|
mas01ik@355
|
127 ////echo testfeature 0 0 1 > test-expected-output
|
mas01ik@355
|
128 ////cmp testoutput test-expected-output
|
mas01ik@355
|
129 myadbquery.querytype="sequence";
|
mas01ik@355
|
130 myadbquery.feature="testquery";
|
mas01ik@355
|
131 myadbquery.sequencelength="1";
|
mas01ik@355
|
132 myadbquery.numpoints="1";
|
mas01ik@355
|
133 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
134 size=myadbqueryresult.sizeRlist;
|
mas01ik@355
|
135
|
mas01ik@355
|
136 //dump_query(&myadbquery,&myadbqueryresult);
|
mas01ik@355
|
137 ///* check the test values */
|
mas01ik@355
|
138 if (size != 1) {returnval = -1;};
|
mas01ik@355
|
139 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,1)) {returnval = -1;};
|
mas01ik@355
|
140
|
mas01ik@355
|
141
|
mas01ik@355
|
142
|
mas01ik@355
|
143 //printf("returnval:%d\n",returnval);
|
mas01ik@355
|
144 return(returnval);
|
mas01ik@355
|
145 }
|
mas01ik@355
|
146
|
mas01ik@355
|
147 void maketimesfile(char * filename){
|
mas01ik@355
|
148
|
mas01ik@355
|
149 FILE * myfile;
|
mas01ik@355
|
150
|
mas01ik@355
|
151 myfile=fopen(filename,"w");
|
mas01ik@355
|
152 fprintf(myfile,"0\n");
|
mas01ik@355
|
153 fprintf(myfile,"1\n");
|
mas01ik@355
|
154 fprintf(myfile,"2\n");
|
mas01ik@355
|
155 fflush(myfile);
|
mas01ik@355
|
156 fclose(myfile);
|
mas01ik@355
|
157
|
mas01ik@355
|
158 }
|