Mercurial > hg > audiodb
comparison libtests/test_utils_lib.h @ 487:e072aa1611f5 api-inversion
Begin cleaning up libtests
* Delete unused functions from test_utils_lib.h.
* #include needed system header files there rather than at the head of
each of the individual C files.
* Make libtests.mk be responsible for finding audioDB_API.h and
test_utils_lib.h
* Simplify the implementation of clean_remove_db().
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 15:32:42 +0000 |
parents | 7e6c99481b8b |
children | f4dc8e47ee37 |
comparison
equal
deleted
inserted
replaced
473:b2fd8113d8bc | 487:e072aa1611f5 |
---|---|
1 void delete_dir(char * dirname); | 1 #include <sys/types.h> |
2 void clean_remove_db(char * dirname); | 2 #include <sys/stat.h> |
3 void test_status(adb_ptr d, adb_status_ptr b); | 3 #include <math.h> |
4 unsigned int test_insert( adb_ptr d, char * features, char * power, char * key); | 4 #include <unistd.h> |
5 void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult); | 5 #include <fcntl.h> |
6 #include <string.h> | |
7 #include <stdio.h> | |
8 | |
9 void clean_remove_db(char *dbname); | |
6 int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos); | 10 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); | 11 void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize); |
9 int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count); | 12 int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count); |
10 void makekeylistfile(char * filename, char * item); | 13 void makekeylistfile(char * filename, char * item); |
11 | 14 |
12 | 15 |
13 | 16 void clean_remove_db(char * dbname) { |
14 | 17 unlink(dbname); |
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 } | 18 } |
98 | 19 |
99 | 20 |
100 void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult){ | 21 void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult){ |
101 | 22 |
131 if (strcmp(Rlist,myadbqueryresult->Rlist[i])){ | 52 if (strcmp(Rlist,myadbqueryresult->Rlist[i])){ |
132 ret=-1; | 53 ret=-1; |
133 } | 54 } |
134 | 55 |
135 | 56 |
136 if (doubleabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){ | 57 if (fabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){ |
137 ret=-1; | 58 ret=-1; |
138 } | 59 } |
139 | 60 |
140 if (doubleabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){ | 61 if (fabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){ |
141 ret=-1; | 62 ret=-1; |
142 } | 63 } |
143 | 64 |
144 if (doubleabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){ | 65 if (fabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){ |
145 ret=-1; | 66 ret=-1; |
146 } | 67 } |
147 | 68 |
148 return ret; | 69 return ret; |
149 } | 70 } |
166 } | 87 } |
167 | 88 |
168 return ret; | 89 return ret; |
169 } | 90 } |
170 | 91 |
171 | |
172 double doubleabs(double foo){ | |
173 | |
174 double retval=foo; | |
175 | |
176 if (foo < 0.0) { | |
177 retval=foo * -1.0; | |
178 } | |
179 | |
180 return retval; | |
181 } | |
182 | |
183 | |
184 | |
185 void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize) { | 92 void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize) { |
186 | 93 |
187 FILE * myfile; | 94 FILE * myfile; |
188 | 95 |
189 myfile=fopen(filename,"w"); | 96 myfile=fopen(filename,"w"); |
193 fclose(myfile); | 100 fclose(myfile); |
194 | 101 |
195 /* should probably test for success, but then it is a test suite already... */ | 102 /* should probably test for success, but then it is a test suite already... */ |
196 } | 103 } |
197 | 104 |
198 | |
199 | |
200 void makekeylistfile(char * filename, char * item){ | 105 void makekeylistfile(char * filename, char * item){ |
201 | 106 |
202 FILE * myfile; | 107 FILE * myfile; |
203 | 108 |
204 myfile=fopen(filename,"w"); | 109 myfile=fopen(filename,"w"); |
205 fprintf(myfile,"%s\n",item); | 110 fprintf(myfile,"%s\n",item); |
206 fflush(myfile); | 111 fflush(myfile); |
207 fclose(myfile); | 112 fclose(myfile); |
208 | 113 |
209 } | 114 } |
210 | |
211 | |
212 | |
213 | |
214 |