annotate libtests/test_utils_lib.h @ 548:e18843dc0aea

Implement a rudimentary API for audioDB::liszt The API is rudimentary because we've dropped support for the incremental retrieval of tracks and their number of vectors (at the API level; the SOAP and command-line support is still there -- no changes should be visible). This is potentially bad for the large-scale databases, of course; one million tracks will take of the order of 16MB of RAM, more if I'm unlucky about how std::string.c_str() is implemented. Both this liszt operation and querying (and sampling, forthcoming...) would benefit from a `cursor-like' interface to retrieval results: for an API like that, instead of getting a struct with the data there, you get a cookie with which you can ask the database for successive results. This would be neat for all sorts of reasons. In the meantime, at least this change fixes SOAP memory leaks related to liszt. Make liszt.o part of LIBOBJS rather than ordinary OBJS, so that the liszt functionality is actually compiled into the library. Add a test for this library functionality; also modify the command-line test file to run the SOAP server on its own port.
author mas01cr
date Wed, 11 Feb 2009 12:38:03 +0000
parents 342822c2d49a
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;