annotate libtests/0010/prog1.c @ 395:bc7a821004bb api-inversion

Invert audioDB::status / audiodb_status(). To do that without breaking abstractions, we actually need a new field in the status structure, storing the size of the data region. Previously, this was computed in the audioDB::status request from the database header, but I'm assuming that "user" code doesn't have access to such internals. While we're at it, name some intermediate values in audioDB::status() so that I don't get confused. Here's the thing, though: we need to make sure that the adb_t * that we have from audiodb_open() or audiodb_create() is propagated all the way through into the C++ routines that implement library functions -- in particular those which actually write to the database; otherwise we won't have a consistent view in memory of the header on-disk (as the adb header that will have been written to disk won't be the same as the one in memory). We can do that, by altering the "API" audioDB constructors to take the adb_t * argument, and setting the adb field in the audioDB object that we've already introduced to that. But now we need to be careful a couple of times: if we have one, then audioDB::initTables() mustn't stomp on it; also, if we're only constructing an audioDB instance to fulfil an API request, we mustn't audiodb_close() the one we have when we destroy the audioDB object, because the adb_t * is the one we have passed in and are going to reuse in later calls to the API. The good news is that we can be careful in just these ways with minimal code. The really good news is that once the inversion is complete, all of this horribleness will automatically go away (as there will be no code which constructs audioDB objects to fulfil API functions). Hooray! It's almost like it was all planned this way.
author mas01cr
date Tue, 25 Nov 2008 16:41:01 +0000
parents 94c18f128ce8
children e072aa1611f5 342822c2d49a
rev   line source
mas01ik@355 1 #include <stdio.h>
mas01ik@355 2 #include <stdlib.h>
mas01ik@355 3 #include <string.h>
mas01ik@355 4 #include <sysexits.h>
mas01ik@355 5 #include <fcntl.h>
mas01ik@355 6 #include <dirent.h>
mas01ik@355 7 #include <unistd.h>
mas01ik@355 8 #include <sys/stat.h>
mas01ik@355 9 /*
mas01ik@355 10 * * #define NDEBUG
mas01ik@355 11 * * */
mas01ik@355 12 #include <assert.h>
mas01ik@355 13
mas01ik@355 14 #include "../../audioDB_API.h"
mas01ik@355 15 #include "../test_utils_lib.h"
mas01ik@355 16
mas01ik@355 17
mas01ik@355 18 int main(int argc, char **argv){
mas01ik@355 19
mas01ik@355 20 int returnval=0;
mas01ik@355 21 adb_ptr mydbp={0};
mas01ik@355 22 int ivals[10];
mas01ik@355 23 double dvals[10];
mas01ik@355 24 adb_insert_t myinsert={0};
mas01ik@355 25 unsigned int myerr=0;
mas01ik@355 26 char * databasename="testdb";
mas01ik@355 27 adb_query_t myadbquery={0};
mas01ik@355 28 adb_queryresult_t myadbqueryresult={0};
mas01ik@355 29 int size=0;
mas01ik@355 30
mas01ik@355 31 /* clean */
mas01ik@355 32 //if [ -f testdb ]; then rm -f testdb; fi
mas01ik@355 33 clean_remove_db(databasename);
mas01ik@355 34
mas01ik@355 35 /* new db */
mas01ik@355 36 //${AUDIODB} -d testdb -N
mas01ik@355 37 mydbp=audiodb_create(databasename,0,0,0);
mas01ik@355 38
mas01ik@355 39 /* test feature files */
mas01ik@355 40 //intstring 2 > testfeature01
mas01ik@355 41 //floatstring 0 1 >> testfeature01
mas01ik@355 42 ivals[0]=2;
mas01ik@355 43 dvals[0]=0; dvals[1]=1;
mas01ik@355 44 maketestfile("testfeature01",ivals,dvals,2);
mas01ik@355 45 //intstring 2 > testfeature10
mas01ik@355 46 //floatstring 1 0 >> testfeature10
mas01ik@355 47 ivals[0]=2;
mas01ik@355 48 dvals[0]=1; dvals[1]=0;
mas01ik@355 49 maketestfile("testfeature10",ivals,dvals,2);
mas01ik@355 50
mas01ik@355 51 /* inserts */
mas01ik@355 52 //${AUDIODB} -d testdb -I -f testfeature01
mas01ik@355 53 //${AUDIODB} -d testdb -I -f testfeature10
mas01ik@355 54 myinsert.features="testfeature01";
mas01ik@355 55 myerr=audiodb_insert(mydbp,&myinsert);
mas01ik@355 56 myinsert.features="testfeature10";
mas01ik@355 57 myerr=audiodb_insert(mydbp,&myinsert);
mas01ik@355 58
mas01ik@355 59 /* l2norm */
mas01ik@355 60 //# sequence queries require L2NORM
mas01ik@355 61 //${AUDIODB} -d testdb -L
mas01ik@355 62 audiodb_l2norm(mydbp);
mas01ik@355 63
mas01ik@355 64 /* query 1 */
mas01ik@355 65 //echo "query point (0.0,0.5)"
mas01ik@355 66 //intstring 2 > testquery
mas01ik@355 67 //floatstring 0 0.5 >> testquery
mas01ik@355 68 ivals[0]=2;
mas01ik@355 69 dvals[0]=0; dvals[1]=0.5; dvals[2]=0; dvals[3]=0;
mas01ik@355 70 maketestfile("testquery",ivals,dvals,2);
mas01ik@355 71
mas01ik@355 72 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput
mas01ik@355 73 //echo testfeature01 1 > test-expected-output
mas01ik@355 74 //echo testfeature10 1 >> test-expected-output
mas01ik@355 75 //cmp testoutput test-expected-output
mas01ik@355 76
mas01ik@355 77 myadbquery.querytype="sequence";
mas01ik@355 78 myadbquery.feature="testquery";
mas01ik@355 79 myadbquery.sequencelength="1";
mas01ik@355 80 myadbquery.radius="5";
mas01ik@355 81 audiodb_query(mydbp,&myadbquery,&myadbqueryresult);
mas01ik@355 82 size=myadbqueryresult.sizeRlist;
mas01ik@355 83
mas01ik@355 84 dump_query(&myadbquery,&myadbqueryresult);
mas01ik@355 85 /* check the test values */
mas01ik@355 86 if (size != 2) {returnval = -1;};
mas01ik@355 87 //if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;};
mas01ik@355 88 //if (testoneresult(&myadbqueryresult,1,"testfeature",1,0,0)) {returnval = -1;};
mas01ik@355 89
mas01ik@355 90
mas01ik@355 91 /* query 2 */
mas01ik@355 92 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -R 5 > testoutput
mas01ik@355 93 //echo testfeature01 1 > test-expected-output
mas01ik@355 94 //cmp testoutput test-expected-output
mas01ik@355 95 //
mas01ik@355 96 //echo "query point (0.5,0.0)"
mas01ik@355 97 //intstring 2 > testquery
mas01ik@355 98 //floatstring 0.5 0 >> testquery
mas01ik@355 99
mas01ik@355 100
mas01ik@355 101 /* query 3 */
mas01ik@355 102 //# FIXME: because there's only one point in each track (and the query),
mas01ik@355 103 //# the ordering is essentially database order. We need these test
mas01ik@355 104 //# cases anyway because we need to test non-segfaulting, non-empty
mas01ik@355 105 //# results...
mas01ik@355 106 //
mas01ik@355 107 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput
mas01ik@355 108 //echo testfeature01 1 > test-expected-output
mas01ik@355 109 //echo testfeature10 1 >> test-expected-output
mas01ik@355 110 //cmp testoutput test-expected-output
mas01ik@355 111
mas01ik@355 112
mas01ik@355 113
mas01ik@355 114 /* query 4 */
mas01ik@355 115 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -R 5 > testoutput
mas01ik@355 116 //echo testfeature01 1 > test-expected-output
mas01ik@355 117 //cmp testoutput test-expected-output
mas01ik@355 118
mas01ik@355 119
mas01ik@355 120 printf("returnval:%d\n",returnval);
mas01ik@355 121 //returnval=-1;
mas01ik@355 122
mas01ik@355 123 return(returnval);
mas01ik@355 124 }
mas01ik@355 125