Mercurial > hg > audiodb
comparison libtests/0006/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 /* remove old directory */ | |
35 //if [ -f testdb ]; then rm -f testdb; fi | |
36 clean_remove_db(databasename); | |
37 | |
38 /* create new db */ | |
39 //${AUDIODB} -d testdb -N | |
40 mydbp=audiodb_create(databasename,0,0,0); | |
41 | |
42 /* create testfeature file */ | |
43 //intstring 2 > testfeature | |
44 //floatstring 0 1 >> testfeature | |
45 //floatstring 1 0 >> testfeature | |
46 ivals[0]=2; | |
47 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0; | |
48 maketestfile("testfeature",ivals,dvals,4); | |
49 | |
50 | |
51 /* insert */ | |
52 //${AUDIODB} -d testdb -I -f testfeature | |
53 myinsert.features="testfeature"; | |
54 if(audiodb_insert(mydbp,&myinsert)){ | |
55 returnval=-1; | |
56 }; | |
57 | |
58 | |
59 /* turn on L2NORM */ | |
60 //# sequence queries require L2NORM | |
61 //${AUDIODB} -d testdb -L | |
62 audiodb_l2norm(mydbp); | |
63 | |
64 /* make a test query */ | |
65 //echo "query point (0.0,0.5)" | |
66 //intstring 2 > testquery | |
67 //floatstring 0 0.5 >> testquery | |
68 ivals[0]=2; | |
69 dvals[0]=0; dvals[1]=0.5; dvals[2]=0; dvals[3]=0; | |
70 maketestfile("testquery",ivals,dvals,2); | |
71 | |
72 /* test a sequence query */ | |
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 /* check the test values */ | |
83 if (size != 1) {returnval = -1;}; | |
84 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;}; | |
85 | |
86 | |
87 /* same but with limites */ | |
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.numpoints="1"; | |
92 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
93 size=myadbqueryresult.sizeRlist; | |
94 | |
95 /* check the test values */ | |
96 if (size != 1) {returnval = -1;}; | |
97 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,0)) {returnval = -1;}; | |
98 | |
99 /* make another query */ | |
100 //echo "query point (0.5,0.0)" | |
101 //intstring 2 > testquery | |
102 //floatstring 0.5 0 >> testquery | |
103 ivals[0]=2; | |
104 dvals[0]=0.5; dvals[1]=0.0; dvals[2]=0; dvals[3]=0; | |
105 maketestfile("testquery",ivals,dvals,2); | |
106 | |
107 | |
108 /* test new query */ | |
109 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
110 //echo testfeature 1 0 1 > test-expected-output | |
111 //cmp testoutput test-expected-output | |
112 | |
113 myadbquery2.querytype="sequence"; | |
114 myadbquery2.feature="testquery"; | |
115 myadbquery2.sequencelength="1"; | |
116 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
117 size=myadbqueryresult2.sizeRlist; | |
118 | |
119 /* check the test values */ | |
120 if (size != 1) {returnval = -1;}; | |
121 if (testoneresult(&myadbqueryresult2,0,"testfeature",1,0,1)) {returnval = -1;}; | |
122 | |
123 | |
124 /* test new query with limits */ | |
125 myadbquery2.numpoints="1"; | |
126 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
127 size=myadbqueryresult2.sizeRlist; | |
128 | |
129 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
130 //echo testfeature 0 0 1 > test-expected-output | |
131 //cmp testoutput test-expected-output | |
132 | |
133 | |
134 /* check the test values */ | |
135 if (size != 1) {returnval = -1;}; | |
136 if (testoneresult(&myadbqueryresult2,0,"testfeature",0,0,1)) {returnval = -1;}; | |
137 | |
138 | |
139 | |
140 /* close */ | |
141 audiodb_close(mydbp); | |
142 | |
143 printf("returnval:%d\n",returnval); | |
144 return(returnval); | |
145 } | |
146 | |
147 |