Mercurial > hg > audiodb
comparison libtests/0024/prog1.c @ 498:342822c2d49a
Merge api-inversion branch (-r656:771, but I don't expect to return to
that branch) into the trunk.
I expect there to be minor performance regressions (e.g. in the SOAP
server index cacheing, which I have forcibly removed) and minor
unplugged memory leaks (e.g. in audioDB::query(), where I don't free up
the datum). I hope that these leaks and performance regressions can be
plugged in short order. I also expect that some (but maybe not all) of
the issues currently addressed in the memory-leaks branch are superseded
or fixed by this merge.
There remains much work to be done; go forth and do it.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 16:47:57 +0000 |
parents | 94c18f128ce8 |
children | bcc7a6ddb2c8 |
comparison
equal
deleted
inserted
replaced
476:a7193678280b | 498:342822c2d49a |
---|---|
1 #include <stdio.h> | 1 #include "audioDB_API.h" |
2 #include <stdlib.h> | 2 #include "test_utils_lib.h" |
3 #include <string.h> | |
4 #include <sysexits.h> | |
5 #include <fcntl.h> | |
6 #include <dirent.h> | |
7 #include <unistd.h> | |
8 #include <sys/stat.h> | |
9 /* | |
10 * * #define NDEBUG | |
11 * * */ | |
12 #include <assert.h> | |
13 | 3 |
14 #include "../../audioDB_API.h" | 4 int main(int argc, char **argv) { |
15 #include "../test_utils_lib.h" | 5 adb_t *adb; |
6 adb_insert_t batch[2]={{0}, {0}}; | |
16 | 7 |
8 clean_remove_db(TESTDB); | |
9 if(!(adb = audiodb_create(TESTDB, 0, 0, 0))) | |
10 return 1; | |
17 | 11 |
18 int main(int argc, char **argv){ | 12 maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2); |
13 maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2); | |
19 | 14 |
20 int returnval=0; | 15 batch[0].features="testfeature01"; |
21 adb_ptr mydbp={0}; | 16 batch[1].features="testfeature10"; |
22 int ivals[10]; | 17 if(audiodb_batchinsert(adb, batch, 2)) |
23 double dvals[10]; | 18 return 1; |
24 adb_insert_t myinsert={0}; | 19 if(audiodb_l2norm(adb)) |
25 unsigned int myerr=0; | 20 return 1; |
26 char * databasename="testdb"; | |
27 adb_query_t myadbquery={0}; | |
28 adb_queryresult_t myadbqueryresult={0}; | |
29 adb_query_t myadbquery2={0}; | |
30 adb_queryresult_t myadbqueryresult2={0}; | |
31 int size=0; | |
32 adb_insert_t ins1[2]={0}; | |
33 | 21 |
34 /* remove old directory */ | 22 adb_datum_t query = {2, 2, "testquery", (double[4]) {0, 0.5, 0.5, 0}}; |
35 //if [ -f testdb ]; then rm -f testdb; fi | 23 adb_query_id_t qid = {0}; |
36 clean_remove_db(databasename); | 24 qid.datum = &query; |
25 qid.sequence_length = 1; | |
26 qid.flags = ADB_QID_FLAG_EXHAUSTIVE; | |
27 adb_query_parameters_t parms = | |
28 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; | |
29 adb_query_refine_t refine = {0}; | |
30 refine.hopsize = 1; | |
37 | 31 |
38 /* create new db */ | 32 adb_query_spec_t spec; |
39 //${AUDIODB} -d testdb -N | 33 spec.qid = qid; |
40 mydbp=audiodb_create(databasename,0,0,0); | 34 spec.params = parms; |
35 spec.refine = refine; | |
36 | |
37 adb_query_results_t *results = audiodb_query_spec(adb, &spec); | |
38 if(!results || results->nresults != 4) return 1; | |
39 result_present_or_fail(results, "testfeature01", 0, 0, 0); | |
40 result_present_or_fail(results, "testfeature01", 2, 1, 0); | |
41 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
42 result_present_or_fail(results, "testfeature10", 0, 1, 0); | |
43 audiodb_query_free_results(adb, &spec, results); | |
41 | 44 |
42 //intstring 2 > testfeature01 | 45 spec.params.npoints = 1; |
43 //floatstring 0 1 >> testfeature01 | 46 results = audiodb_query_spec(adb, &spec); |
44 //intstring 2 > testfeature10 | 47 if(!results || results->nresults != 2) return 1; |
45 //floatstring 1 0 >> testfeature10 | 48 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
46 ivals[0]=2; | 49 result_present_or_fail(results, "testfeature10", 0, 1, 0); |
47 dvals[0]=0; dvals[1]=1; | 50 audiodb_query_free_results(adb, &spec, results); |
48 maketestfile("testfeature01",ivals,dvals,2); | |
49 ivals[0]=2; | |
50 dvals[0]=1; dvals[1]=0; | |
51 maketestfile("testfeature10",ivals,dvals,2); | |
52 | 51 |
53 //cat > testfeaturefiles <<EOF | 52 audiodb_close(adb); |
54 //testfeature01 | |
55 //testfeature10 | |
56 //EOF | |
57 ins1[0].features="testfeature01"; | |
58 ins1[1].features="testfeature10"; | |
59 | 53 |
60 | 54 return 104; |
61 //${AUDIODB} -d testdb -B -F testfeaturefiles | |
62 returnval=audiodb_batchinsert(mydbp,ins1,2); | |
63 | |
64 //# sequence queries require L2NORM | |
65 //${AUDIODB} -d testdb -L | |
66 audiodb_l2norm(mydbp); | |
67 | |
68 //echo "exhaustive search" | |
69 //intstring 2 > testquery | |
70 //floatstring 0 0.5 >> testquery | |
71 //floatstring 0.5 0 >> testquery | |
72 ivals[0]=2; | |
73 dvals[0]=0; dvals[1]=0.5; | |
74 dvals[2]=0.5; dvals[3]=0; | |
75 maketestfile("testquery",ivals,dvals,4); | |
76 | |
77 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -e > testoutput | |
78 //echo testfeature01 1 0 0 > test-expected-output | |
79 //echo testfeature10 1 1 0 >> test-expected-output | |
80 //cmp testoutput test-expected-output | |
81 myadbquery.querytype="sequence"; | |
82 myadbquery.feature="testquery"; | |
83 myadbquery.sequencelength="1"; | |
84 myadbquery.exhaustive=1; | |
85 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
86 size=myadbqueryresult.sizeRlist; | |
87 | |
88 //printf("size:%d\n",size); | |
89 //dump_query(&myadbquery,&myadbqueryresult); | |
90 ///* check the test values */ | |
91 if (size != 2) {returnval = -1;}; | |
92 if (testoneresult(&myadbqueryresult,0,"testfeature01",1,0,0)) {returnval = -1;}; | |
93 if (testoneresult(&myadbqueryresult,1,"testfeature10",1,1,0)) {returnval = -1;}; | |
94 | |
95 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 -e > testoutput | |
96 //echo testfeature01 0 0 0 > test-expected-output | |
97 //echo testfeature10 0 1 0 >> test-expected-output | |
98 //cmp testoutput test-expected-output | |
99 myadbquery.querytype="sequence"; | |
100 myadbquery.feature="testquery"; | |
101 myadbquery.sequencelength="1"; | |
102 myadbquery.exhaustive=1; | |
103 myadbquery.numpoints="1"; | |
104 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
105 size=myadbqueryresult.sizeRlist; | |
106 | |
107 //printf("size:%d\n",size); | |
108 //dump_query(&myadbquery,&myadbqueryresult); | |
109 ///* check the test values */ | |
110 if (size != 2) {returnval = -1;}; | |
111 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
112 if (testoneresult(&myadbqueryresult,1,"testfeature10",0,1,0)) {returnval = -1;}; | |
113 | |
114 | |
115 printf("returnval:%d\n",returnval); | |
116 return(returnval); | |
117 } | 55 } |
118 |