annotate libtests/0023/prog1.c @ 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 bcc7a6ddb2c8
rev   line source
mas01cr@498 1 #include "audioDB_API.h"
mas01cr@498 2 #include "test_utils_lib.h"
mas01ik@355 3
mas01cr@498 4 int main(int argc, char **argv) {
mas01cr@498 5 adb_t *adb;
mas01cr@498 6 adb_insert_t batch[2]={{0},{0}};
mas01ik@355 7
mas01cr@498 8 clean_remove_db(TESTDB);
mas01cr@498 9 if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
mas01cr@498 10 return 1;
mas01ik@355 11
mas01cr@498 12 maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
mas01cr@498 13 maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
mas01ik@355 14
mas01cr@498 15 batch[0].features="testfeature01";
mas01cr@498 16 batch[1].features="testfeature10";
mas01cr@498 17 if(audiodb_batchinsert(adb, batch, 2))
mas01cr@498 18 return 1;
mas01cr@498 19 if(audiodb_l2norm(adb))
mas01cr@498 20 return 1;
mas01ik@355 21
mas01cr@498 22 adb_datum_t query = {2, 2, "testquery", (double[4]) {0, 0.5, 0.5, 0}};
mas01cr@498 23 adb_query_id_t qid = {0};
mas01cr@498 24 qid.datum = &query;
mas01cr@498 25 qid.sequence_length = 1;
mas01cr@498 26 qid.sequence_start = 0;
mas01cr@498 27 adb_query_parameters_t parms =
mas01cr@498 28 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10};
mas01cr@498 29 adb_query_refine_t refine = {0};
mas01cr@498 30 refine.hopsize = 1;
mas01ik@355 31
mas01cr@498 32 adb_query_spec_t spec;
mas01cr@498 33 spec.qid = qid;
mas01cr@498 34 spec.params = parms;
mas01cr@498 35 spec.refine = refine;
mas01cr@498 36
mas01cr@498 37 adb_query_results_t *results = audiodb_query_spec(adb, &spec);
mas01cr@498 38 if(!results || results->nresults != 2) return 1;
mas01cr@498 39 result_present_or_fail(results, "testfeature01", 0, 0, 0);
mas01cr@498 40 result_present_or_fail(results, "testfeature10", 2, 0, 0);
mas01cr@498 41 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 42
mas01cr@498 43 spec.params.ntracks = 1;
mas01cr@498 44 results = audiodb_query_spec(adb, &spec);
mas01cr@498 45 if(!results || results->nresults != 1) return 1;
mas01cr@498 46 result_present_or_fail(results, "testfeature01", 0, 0, 0);
mas01cr@498 47 audiodb_query_free_results(adb, &spec, results);
mas01cr@498 48
mas01cr@498 49 spec.qid.sequence_start = 1;
mas01cr@498 50 spec.params.ntracks = 10;
mas01cr@498 51 results = audiodb_query_spec(adb, &spec);
mas01cr@498 52 if(!results || results->nresults != 2) return 1;
mas01cr@498 53 result_present_or_fail(results, "testfeature10", 0, 1, 0);
mas01cr@498 54 result_present_or_fail(results, "testfeature01", 2, 1, 0);
mas01cr@498 55 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 56
mas01cr@498 57 spec.params.ntracks = 1;
mas01cr@498 58 results = audiodb_query_spec(adb, &spec);
mas01cr@498 59 if(!results || results->nresults != 1) return 1;
mas01cr@498 60 result_present_or_fail(results, "testfeature10", 0, 1, 0);
mas01cr@498 61 audiodb_query_free_results(adb, &spec, results);
mas01ik@355 62
mas01cr@498 63 audiodb_close(adb);
mas01ik@355 64
mas01cr@498 65 return 104;
mas01ik@355 66 }