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