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