Mercurial > hg > audiodb
comparison libtests/0004/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 adb_status_t mystatus={0}; | |
23 int ivals[10]; | |
24 double dvals[10]; | |
25 FILE * myfile; | |
26 int ret=0; | |
27 adb_insert_t myinsert={0}; | |
28 unsigned int myerr=0; | |
29 adb_query_t myadbquery={0}; | |
30 adb_queryresult_t myadbqueryresult={0}; | |
31 adb_query_t myadbquery2={0}; | |
32 adb_queryresult_t myadbqueryresult2={0}; | |
33 char * databasename="testdb"; | |
34 int i=0; | |
35 int size=0; | |
36 | |
37 | |
38 /* remove old directory */ | |
39 //if [ -f testdb ]; then rm -f testdb; fi | |
40 clean_remove_db(databasename); | |
41 | |
42 /* create new db */ | |
43 //${AUDIODB} -d testdb -N | |
44 mydbp=audiodb_create(databasename,0,0,0); | |
45 | |
46 /* turn on l2norm */ | |
47 //${AUDIODB} -d testdb -L | |
48 audiodb_l2norm(mydbp); | |
49 | |
50 /* make a test file */ | |
51 //intstring 2 > testfeature | |
52 //floatstring 0 1 >> testfeature | |
53 //floatstring 1 0 >> testfeature | |
54 ivals[0]=2; | |
55 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0; | |
56 maketestfile("testfeature", ivals,dvals,4); | |
57 | |
58 | |
59 /* insert */ | |
60 //${AUDIODB} -d testdb -I -f testfeature | |
61 myinsert.features="testfeature"; | |
62 myerr=audiodb_insert(mydbp,&myinsert); | |
63 | |
64 /* testquery */ | |
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,4); | |
71 | |
72 /* query 1 */ | |
73 //${AUDIODB} -d testdb -Q point -f testquery > testoutput | |
74 //echo testfeature 0.5 0 0 > test-expected-output | |
75 //echo testfeature 0 0 1 >> test-expected-output | |
76 //cmp testoutput test-expected-output | |
77 myadbquery.querytype="point"; | |
78 myadbquery.feature="testquery"; | |
79 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
80 size=myadbqueryresult.sizeRlist; | |
81 | |
82 /* check the test values */ | |
83 if (size != 2) {returnval = -1;}; | |
84 if (testoneresult(&myadbqueryresult,0,"testfeature",.5,0,0)) {returnval = -1;}; | |
85 if (testoneresult(&myadbqueryresult,1,"testfeature",0,0,1)) {returnval = -1;}; | |
86 | |
87 /* query 2 - same but only first result */ | |
88 //${AUDIODB} -d testdb -Q point -f testquery -n 1 > testoutput | |
89 //echo testfeature 0.5 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 if (size != 1) {returnval = -1;}; | |
96 if (testoneresult(&myadbqueryresult,0,"testfeature",.5,0,0)) {returnval = -1;}; | |
97 | |
98 | |
99 /* testquery2 */ | |
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; dvals[2]=0; dvals[3]=0; | |
105 maketestfile("testquery", ivals,dvals,4); | |
106 | |
107 /* query 3 */ | |
108 //${AUDIODB} -d testdb -Q point -f testquery > testoutput | |
109 //echo testfeature 0.5 0 1 > test-expected-output | |
110 //echo testfeature 0 0 0 >> test-expected-output | |
111 //cmp testoutput test-expected-output | |
112 myadbquery2.querytype="point"; | |
113 myadbquery2.feature="testquery"; | |
114 myadbquery2.numpoints=NULL; | |
115 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
116 size=myadbqueryresult2.sizeRlist; | |
117 | |
118 /* check the test values */ | |
119 if (size != 2) {returnval = -1;}; | |
120 if (testoneresult(&myadbqueryresult2,0,"testfeature",.5,0,1)) {returnval = -1;}; | |
121 if (testoneresult(&myadbqueryresult2,1,"testfeature",0,0,0)) {returnval = -1;}; | |
122 | |
123 /* query 4 - same as 3 but only first result */ | |
124 //${AUDIODB} -d testdb -Q point -f testquery -n 1 > testoutput | |
125 //echo testfeature 0.5 0 1 > test-expected-output | |
126 //cmp testoutput test-expected-output | |
127 myadbquery2.numpoints="1"; | |
128 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
129 size=myadbqueryresult2.sizeRlist; | |
130 | |
131 | |
132 if (size != 1) {returnval = -1;}; | |
133 if (testoneresult(&myadbqueryresult2,0,"testfeature",.5,0,1)) {returnval = -1;}; | |
134 | |
135 audiodb_close(mydbp); | |
136 | |
137 | |
138 return(returnval); | |
139 } | |
140 |