annotate libtests/test_utils_lib.h @ 584:e3790284fd4a

Merged through librdf storage hooks and apache2 module. Squashed commit of the following: commit a6cfca8f04036e12e7d7fcd55c47224e802582f0 Author: Michael Jewell <mjewell@harrison.(none)> Date: Fri Jul 31 15:23:32 2009 +0100 Removed leftover bits and bobs. commit f1f0dd074d0767de3e24ba636779fd8701d73d9e Author: Michael Jewell <mjewell@harrison.(none)> Date: Fri Jul 31 15:07:20 2009 +0100 Simple test of database creation via librdf. commit 90e6350538e004d8785137e5ff2ac878c22a5d42 Author: Michael Jewell <mjewell@harrison.(none)> Date: Fri Jul 31 15:05:10 2009 +0100 Added the apache2 module which will hook into the librdf storage module commit c75bf53763b7078c83ae97fcf247da2576baa79a Author: Michael Jewell <mjewell@harrison.(none)> Date: Fri Jul 31 15:04:53 2009 +0100 Added sparql librdf source - requires the librdf sources to compile. commit 0646f0190112a73ddb2533537e2cc9832c066b52 Author: Michael Jewell <mjewell@harrison.(none)> Date: Mon Jul 27 12:12:26 2009 +0100 Adding execution to mod_audiodb commit 8f83f27ba4d917278bca0c7cb665d930e28c86df Author: Michael Jewell <mjewell@harrison.(none)> Date: Wed Jul 22 12:15:57 2009 +0100 Some initial returns for the sparql handler. commit dc639aed11943a5b0c379eb47cf293f76908b1b7 Author: Michael Jewell <mjewell@harrison.(none)> Date: Wed Jul 22 12:06:20 2009 +0100 Added a little setup.sh script to do libtoolize/autoconf etc. commit 3a679da499db647fc82cf2797daeb5cc44ed7655 Author: Michael Jewell <mjewell@harrison.(none)> Date: Wed Jul 22 12:03:42 2009 +0100 Adding initial bits for apache mod
author mas01mj
date Fri, 31 Jul 2009 14:36:12 +0000
parents e18843dc0aea
children a35ca2d5f238
rev   line source
mas01cr@498 1 #include <sys/types.h>
mas01cr@498 2 #include <sys/stat.h>
mas01cr@498 3 #include <math.h>
mas01cr@498 4 #include <unistd.h>
mas01cr@498 5 #include <fcntl.h>
mas01cr@498 6 #include <string.h>
mas01cr@498 7 #include <stdio.h>
mas01cr@498 8 #include <stdlib.h>
mas01ik@355 9
mas01cr@498 10 #define TESTDB "testdb"
mas01ik@355 11
mas01cr@498 12 void clean_remove_db(char * dbname) {
mas01cr@498 13 unlink(dbname);
mas01ik@355 14 }
mas01ik@355 15
mas01cr@498 16 void maketestfile(const char *path, int dim, double *doubles, int ndoubles) {
mas01cr@498 17 FILE *file;
mas01ik@355 18
mas01cr@498 19 file = fopen(path, "w");
mas01cr@498 20 fwrite(&dim, sizeof(int), 1, file);
mas01cr@498 21 fwrite(doubles, sizeof(double), ndoubles, file);
mas01cr@498 22 fflush(file);
mas01cr@498 23 fclose(file);
mas01ik@355 24 }
mas01ik@355 25
mas01cr@498 26 int close_enough(double a, double b, double epsilon) {
mas01cr@498 27 return (fabs(a-b) < epsilon);
mas01ik@355 28 }
mas01ik@355 29
mas01cr@498 30 int result_position(adb_query_results_t *r, const char *key, float dist, uint32_t qpos, uint32_t ipos) {
mas01cr@498 31 for(uint32_t k = 0; k < r->nresults; k++) {
mas01cr@498 32 adb_result_t result = r->results[k];
mas01cr@498 33 if(close_enough(dist, result.dist, 1e-4) && (qpos == result.qpos) &&
mas01cr@498 34 (ipos == result.ipos) && !(strcmp(key, result.key))) {
mas01cr@498 35 return k;
mas01cr@498 36 }
mas01cr@498 37 }
mas01cr@498 38 return -1;
mas01ik@355 39 }
mas01ik@355 40
mas01cr@498 41 #define result_present_or_fail(r, k, d, q, i) \
mas01cr@498 42 if(result_position(r, k, d, q, i) < 0) return 1;
mas01cr@548 43
mas01cr@548 44 int entry_position(adb_liszt_results_t *l, const char *key, uint32_t nvectors) {
mas01cr@548 45 for(uint32_t k = 0; k < l->nresults; k++) {
mas01cr@548 46 adb_track_entry_t entry = l->entries[k];
mas01cr@548 47 if((nvectors == entry.nvectors) && !strcmp(key, entry.key)) {
mas01cr@548 48 return k;
mas01cr@548 49 }
mas01cr@548 50 }
mas01cr@548 51 return -1;
mas01cr@548 52 }
mas01cr@548 53
mas01cr@548 54 #define entry_present_or_fail(l, k, n) \
mas01cr@548 55 if(entry_position(l, k, n) < 0) return 1;