Mercurial > hg > audiodb
comparison libtests/0023/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 adb_query_t myadbquery2={0}; | |
29 adb_queryresult_t myadbqueryresult2={0}; | |
30 adb_query_t myadbquery3={0}; | |
31 adb_queryresult_t myadbqueryresult3={0}; | |
32 int size=0; | |
33 adb_insert_t ins1[2]={{0},{0}}; | |
34 | |
35 /* remove old directory */ | |
36 //if [ -f testdb ]; then rm -f testdb; fi | |
37 clean_remove_db(databasename); | |
38 | |
39 /* create new db */ | |
40 //${AUDIODB} -d testdb -N | |
41 mydbp=audiodb_create(databasename,0,0,0); | |
42 | |
43 //intstring 2 > testfeature01 | |
44 //floatstring 0 1 >> testfeature01 | |
45 //intstring 2 > testfeature10 | |
46 //floatstring 1 0 >> testfeature10 | |
47 ivals[0]=2; | |
48 dvals[0]=0; dvals[1]=1; | |
49 maketestfile("testfeature01",ivals,dvals,2); | |
50 ivals[0]=2; | |
51 dvals[0]=1; dvals[1]=0; | |
52 maketestfile("testfeature10",ivals,dvals,2); | |
53 | |
54 //cat > testfeaturefiles <<EOF | |
55 //testfeature01 | |
56 //testfeature10 | |
57 //EOF | |
58 ins1[0].features="testfeature01"; | |
59 ins1[1].features="testfeature10"; | |
60 | |
61 //audioDB -B -d testdb -F tempfeatures | |
62 //${AUDIODB} -d testdb -B -F testfeaturefiles | |
63 if(audiodb_batchinsert(mydbp,ins1,2)){ | |
64 returnval=-1; | |
65 }; | |
66 | |
67 //# sequence queries require L2NORM | |
68 //${AUDIODB} -d testdb -L | |
69 if(audiodb_l2norm(mydbp)){ | |
70 returnval=-1; | |
71 }; | |
72 | |
73 ////echo "query point (0.0,0.5)" | |
74 ////intstring 2 > testquery | |
75 ////floatstring 0 0.5 >> testquery | |
76 ////floatstring 0.5 0 >> testquery | |
77 | |
78 ivals[0]=2; | |
79 dvals[0]=0; dvals[1]=0.5; | |
80 dvals[2]=0.5; dvals[3]=0; | |
81 maketestfile("testquery",ivals,dvals,4); | |
82 | |
83 | |
84 | |
85 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -p 0 > testoutput | |
86 //echo testfeature01 0 0 0 > test-expected-output | |
87 //echo testfeature10 2 0 0 >> test-expected-output | |
88 //cmp testoutput test-expected-output | |
89 myadbquery.querytype="sequence"; | |
90 myadbquery.feature="testquery"; | |
91 myadbquery.sequencelength="1"; | |
92 myadbquery.qpoint="0"; | |
93 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
94 size=myadbqueryresult.sizeRlist; | |
95 | |
96 //printf("size:%d\n",size); | |
97 | |
98 //dump_query(&myadbquery,&myadbqueryresult); | |
99 ///* check the test values */ | |
100 if (size != 2) {returnval = -1;}; | |
101 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
102 if (testoneresult(&myadbqueryresult,1,"testfeature10",2,0,0)) {returnval = -1;}; | |
103 | |
104 | |
105 | |
106 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -p 0 > testoutput | |
107 //echo testfeature01 0 0 0 > test-expected-output | |
108 //cmp testoutput test-expected-output | |
109 myadbquery2.querytype="sequence"; | |
110 myadbquery2.feature="testquery"; | |
111 myadbquery2.sequencelength="1"; | |
112 myadbquery2.resultlength="1"; | |
113 myadbquery2.qpoint="0"; | |
114 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
115 size=myadbqueryresult2.sizeRlist; | |
116 | |
117 ///* check the test values */ | |
118 if (size != 1) {returnval = -1;}; | |
119 if (testoneresult(&myadbqueryresult2,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
120 | |
121 | |
122 //echo "query point (0.5,0.0)" | |
123 | |
124 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -p 1 > testoutput | |
125 //echo testfeature10 0 1 0 > test-expected-output | |
126 //echo testfeature01 2 1 0 >> test-expected-output | |
127 //cmp testoutput test-expected-output | |
128 myadbquery3.querytype="sequence"; | |
129 myadbquery3.feature="testquery"; | |
130 myadbquery3.sequencelength="1"; | |
131 myadbquery3.qpoint="1"; | |
132 audiodb_query(mydbp,&myadbquery3,&myadbqueryresult3); | |
133 size=myadbqueryresult3.sizeRlist; | |
134 | |
135 // dump_query(&myadbquery3,&myadbqueryresult3); | |
136 if (size != 2) {returnval = -1;}; | |
137 if (testoneresult(&myadbqueryresult3,0,"testfeature10",0,1,0)) {returnval = -1;}; | |
138 if (testoneresult(&myadbqueryresult3,1,"testfeature01",2,1,0)) {returnval = -1;}; | |
139 | |
140 | |
141 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -p 1 > testoutput | |
142 ////echo testfeature10 0 1 0 > test-expected-output | |
143 ////cmp testoutput test-expected-output | |
144 myadbquery2.querytype="sequence"; | |
145 myadbquery2.feature="testquery"; | |
146 myadbquery2.sequencelength="1"; | |
147 myadbquery2.qpoint="1"; | |
148 myadbquery2.resultlength="1"; | |
149 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
150 size=myadbqueryresult2.sizeRlist; | |
151 | |
152 if (size != 1) {returnval = -1;}; | |
153 if (testoneresult(&myadbqueryresult2,0,"testfeature10",0,1,0)) {returnval = -1;}; | |
154 | |
155 | |
156 // printf("returnval:%d\n",returnval); | |
157 | |
158 return(returnval); | |
159 } | |
160 |