annotate libtests/test_utils_lib.h @ 512:6439cfba2524 memory-leaks

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