Mercurial > hg > audiodb
view 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 |
line wrap: on
line source
#include <sys/types.h> #include <sys/stat.h> #include <math.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <stdio.h> void clean_remove_db(char *dbname); int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos); void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize); int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count); void makekeylistfile(char * filename, char * item); void clean_remove_db(char * dbname) { unlink(dbname); } void dump_query(adb_query_ptr adbq, adb_queryresult_ptr myadbqueryresult){ int size=0; int i=0; size=myadbqueryresult->sizeRlist; printf("Dumping query:\n"); for(i=0; i<size; i++){ printf("\t'%s' query: Result %02d:%s is dist:%f qpos:%d spos:%d\n", adbq->querytype, i, myadbqueryresult->Rlist[i], myadbqueryresult->Dist[i], myadbqueryresult->Qpos[i], myadbqueryresult->Spos[i] ); } printf("\n"); } int testoneresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, double Dist,double Qpos,double Spos){ int ret=0; double tolerance=.0001; if (strcmp(Rlist,myadbqueryresult->Rlist[i])){ ret=-1; } if (fabs((double)Dist - (double)myadbqueryresult->Dist[i]) > tolerance){ ret=-1; } if (fabs((double)Qpos - (double)myadbqueryresult->Qpos[i]) > tolerance){ ret=-1; } if (fabs((double)Spos - (double)myadbqueryresult->Spos[i]) > tolerance){ ret=-1; } return ret; } int testoneradiusresult(adb_queryresult_ptr myadbqueryresult, int i, char * Rlist, int count){ int ret=0; if (strcmp(Rlist,myadbqueryresult->Rlist[i])){ ret=-1; } /* KLUDGE: at the moment, the structure returned from "sequence" queries with a radius has two unused fields, Dist and Qpos, and the Spos field is punned to indicate the count of hits from that track. This is really ugly and needs to die. */ if (count != myadbqueryresult->Spos[i]) { ret=-1; } return ret; } void maketestfile(char * filename, int * ivals, double * dvals, int dvalsize) { FILE * myfile; myfile=fopen(filename,"w"); fwrite(ivals,sizeof(int),1,myfile); fwrite(dvals,sizeof(double),dvalsize,myfile); fflush(myfile); fclose(myfile); /* should probably test for success, but then it is a test suite already... */ } void makekeylistfile(char * filename, char * item){ FILE * myfile; myfile=fopen(filename,"w"); fprintf(myfile,"%s\n",item); fflush(myfile); fclose(myfile); }