comparison libtests/test_utils_lib.h @ 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 7e6c99481b8b
comparison
equal deleted inserted replaced
354:4871a3ed9e36 355:94c18f128ce8
1 void delete_dir(char * dirname);
2 void clean_remove_db(char * dirname);
3 void test_status(adb_ptr d, adb_status_ptr b);
4 unsigned int test_insert( adb_ptr d, char * features, char * power, char * key);
5 void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult);
6 int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos);
7 double doubleabs(double foo);
8 void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize);
9 int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist);
10 void makekeylistfile(char * filename, char * item);
11
12
13
14
15 /* clean remove */
16 void clean_remove_db(char * dbname){
17
18 FILE* db=0;
19
20 db=fopen(dbname,"r");
21
22 if (!db){
23 return;
24 }
25
26
27 fclose(db);
28 remove(dbname);
29
30 return;
31
32 }
33
34
35 /* delete directory */
36 void delete_dir(char * dirname){
37
38 struct dirent *d;
39 DIR *dir;
40 char buf[256];
41
42 printf("Deleting directory '%s' and all files\n", dirname);
43 dir = opendir(dirname);
44
45 if (dir){
46 while((d = readdir(dir))) {
47 //printf("Deleting %s in %s\n",d->d_name, dirname);
48 sprintf(buf, "%s/%s", dirname, d->d_name);
49 remove(buf);
50 }
51 }
52 closedir(dir);
53
54 rmdir(dirname);
55
56
57 return;
58
59 }
60
61
62 unsigned int test_insert(
63 adb_ptr d,
64 char * features,
65 char * power,
66 char * key
67 ){
68
69 adb_insert_t myinsert={0};
70 unsigned int myerr=0;
71
72 printf("Insert:\n");
73 myinsert.features=features;
74 myinsert.power=power;
75 myinsert.key=key;
76 myerr=audiodb_insert(d,&myinsert);
77 printf("\n");
78
79 return myerr;
80
81 }
82
83 void test_status(adb_ptr d, adb_status_ptr b){
84
85 /* get the status of the database */
86 audiodb_status(d,b);
87
88 /* could probably make this look a bit more clever, but it works for now */
89 printf("numFiles:\t%d\n",b->numFiles);
90 printf("dim:\t%d\n",b->dim);
91 printf("length:\t%d\n",b->length);
92 printf("dudCount:\t%d\n",b->dudCount);
93 printf("nullCount:\t%d\n",b->nullCount);
94 printf("flags:\t%d\n",b->flags);
95
96 return;
97 }
98
99
100 void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult){
101
102 int size=0;
103 int i=0;
104
105 size=myadbqueryresult->sizeRlist;
106
107 printf("Dumping query:\n");
108 for(i=0; i<size; i++){
109 printf("\t'%s' query: Result %02d:%s is dist:%f qpos:%d spos:%d\n",
110 adbq->querytype,
111 i,
112 myadbqueryresult->Rlist[i],
113 myadbqueryresult->Dist[i],
114 myadbqueryresult->Qpos[i],
115 myadbqueryresult->Spos[i]
116 );
117 }
118 printf("\n");
119
120 }
121
122
123
124 int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos){
125
126 int ret=0;
127 double tolerance=.0001;
128
129
130
131 if (strcmp(Rlist,myadbqueryresult->Rlist[i])){
132 ret=-1;
133 }
134
135
136 if (doubleabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){
137 ret=-1;
138 }
139
140 if (doubleabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){
141 ret=-1;
142 }
143
144 if (doubleabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){
145 ret=-1;
146 }
147
148 return ret;
149 }
150
151
152 int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist){
153
154 int ret=0;
155 double tolerance=.0001;
156
157
158
159 if (strcmp(Rlist,myadbqueryresult->Rlist[i])){
160 ret=-1;
161 }
162
163
164 if (doubleabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){
165 ret=-1;
166 }
167
168 //if (doubleabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){
169 // ret=-1;
170 //}
171
172 //if (doubleabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){
173 // ret=-1;
174 //}
175
176 return ret;
177 }
178
179
180 double doubleabs(double foo){
181
182 double retval=foo;
183
184 if (foo < 0.0) {
185 retval=foo * -1.0;
186 }
187
188 return retval;
189 }
190
191
192
193 void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize) {
194
195 FILE * myfile;
196
197 myfile=fopen(filename,"w");
198 fwrite(ivals,sizeof(int),1,myfile);
199 fwrite(dvals,sizeof(double),dvalsize,myfile);
200 fflush(myfile);
201 fclose(myfile);
202
203 /* should probably test for success, but then it is a test suite already... */
204 }
205
206
207
208 void makekeylistfile(char * filename, char * item){
209
210 FILE * myfile;
211
212 myfile=fopen(filename,"w");
213 fprintf(myfile,"%s\n",item);
214 fflush(myfile);
215 fclose(myfile);
216
217 }
218
219
220
221
222