view libtests/test_utils_lib.h @ 488:f4dc8e47ee37 api-inversion

Remove dump_query() function. It seems to have been used for printf debugging of test files and never removed. (Debuggers aren't great, but they are better than hand-maintained printing routines for this kind of thing; in particular, gdb will do this for you rather better than dump_query() did.)
author mas01cr
date Sat, 10 Jan 2009 15:32:49 +0000
parents e072aa1611f5
children 4cb6c611f812
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);
}

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);

}