view libtests/test_utils_lib.h @ 489:4cb6c611f812 api-inversion

Begin removing uses of audiodb_query() audiodb_query() is actually an unsupportable interface. It requires access to the filesystem, does not (and cannot) actually support whole swathes of functionality, is only implementable using code that is no longer part of the core of audioDB (reporter.h), is in the way of fixing memory leaks in the SOAP server, and is horrible to use to boot. So, begin converting the libtests uses of audiodb_query() to audio_query_spec(). In the process, go through the test code and remove useless comments, pointless variables, and commented-out bits of shell scripts.
author mas01cr
date Sat, 10 Jan 2009 15:32:53 +0000
parents f4dc8e47ee37
children 1950d76be128
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>

#define TESTDB "testdb"

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

}

int result_position(adb_query_results_t *r, const char *key, float dist, uint32_t qpos, uint32_t ipos) {
  for(uint32_t k = 0; k < r->nresults; k++) {
    adb_result_t result = r->results[k];
    if((dist == result.dist) && (qpos == result.qpos) &&
       (ipos == result.ipos) && !(strcmp(key, result.key))) {
      return k;
    }
  }
  return -1;
}

#define result_present_or_fail(r, k, d, q, i) \
  if(result_position(r, k, d, q, i) < 0) return 1;