Mercurial > hg > audiodb
comparison libtests/0022/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 char * databasename="testdb"; | 19 if(audiodb_l2norm(adb)) |
25 adb_query_t myadbquery={0}; | 20 return 1; |
26 adb_queryresult_t myadbqueryresult={0}; | |
27 adb_query_t myadbquery2={0}; | |
28 adb_queryresult_t myadbqueryresult2={0}; | |
29 adb_insert_t ins1[2]={{0},{0}}; | |
30 int size=0; | |
31 | 21 |
32 /* remove old directory */ | 22 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; |
33 //if [ -f testdb ]; then rm -f testdb; fi | 23 adb_query_id_t qid = {0}; |
34 clean_remove_db(databasename); | 24 qid.datum = &query; |
25 qid.sequence_length = 1; | |
26 qid.sequence_start = 0; | |
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; | |
35 | 31 |
36 /* create new db */ | 32 adb_query_spec_t spec; |
37 //${AUDIODB} -d testdb -N | 33 spec.qid = qid; |
38 mydbp=audiodb_create(databasename,0,0,0); | 34 spec.params = parms; |
35 spec.refine = refine; | |
39 | 36 |
40 if (!mydbp){ returnval=-1;}; | 37 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
38 if(!results || results->nresults != 2) return 1; | |
39 result_present_or_fail(results, "testfeature01", 0, 0, 0); | |
40 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
41 audiodb_query_free_results(adb, &spec, results); | |
42 | |
43 spec.params.ntracks = 1; | |
44 results = audiodb_query_spec(adb, &spec); | |
45 if(!results || results->nresults != 1) return 1; | |
46 result_present_or_fail(results, "testfeature01", 0, 0, 0); | |
47 audiodb_query_free_results(adb, &spec, results); | |
41 | 48 |
42 //intstring 2 > testfeature01 | 49 spec.qid.datum->data = (double [2]) {0.5, 0}; |
43 //floatstring 0 1 >> testfeature01 | 50 spec.params.ntracks = 10; |
44 //intstring 2 > testfeature10 | 51 results = audiodb_query_spec(adb, &spec); |
45 //floatstring 1 0 >> testfeature10 | 52 if(!results || results->nresults != 2) return 1; |
46 ivals[0]=2; | 53 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
47 dvals[0]=0; dvals[1]=1; | 54 result_present_or_fail(results, "testfeature01", 2, 0, 0); |
48 maketestfile("testfeature01",ivals,dvals,2); | 55 audiodb_query_free_results(adb, &spec, results); |
49 ivals[0]=2; | |
50 dvals[0]=1; dvals[1]=0; | |
51 maketestfile("testfeature10",ivals,dvals,2); | |
52 | 56 |
57 spec.params.ntracks = 1; | |
58 results = audiodb_query_spec(adb, &spec); | |
59 if(!results || results->nresults != 1) return 1; | |
60 result_present_or_fail(results, "testfeature10", 0, 0, 0); | |
61 audiodb_query_free_results(adb, &spec, results); | |
53 | 62 |
54 //cat > testfeaturefiles <<EOF | 63 audiodb_close(adb); |
55 //testfeature01 | |
56 //testfeature10 | |
57 //EOF | |
58 | 64 |
59 ins1[0].features="testfeature01"; | 65 return 104; |
60 ins1[1].features="testfeature10"; | |
61 | |
62 //audioDB --BATCHINSERT -d testdb --featureList tempfeatures | |
63 //${AUDIODB} -d testdb -B -F testfeaturefiles | |
64 | |
65 if(audiodb_batchinsert(mydbp,ins1,2)){ | |
66 returnval=-1; | |
67 }; | |
68 | |
69 | |
70 //# sequence queries require L2NORM | |
71 //${AUDIODB} -d testdb -L | |
72 if(audiodb_l2norm(mydbp)){ | |
73 returnval=-1; | |
74 }; | |
75 | |
76 //echo "query point (0.0,0.5)" | |
77 //intstring 2 > testquery | |
78 //floatstring 0 0.5 >> testquery | |
79 ivals[0]=2; | |
80 dvals[0]=0; dvals[1]=0.5; | |
81 maketestfile("testquery",ivals,dvals,2); | |
82 | |
83 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
84 //echo testfeature01 0 0 0 > test-expected-output | |
85 //echo testfeature10 2 0 0 >> test-expected-output | |
86 //cmp testoutput test-expected-output | |
87 myadbquery.querytype="sequence"; | |
88 myadbquery.feature="testquery"; | |
89 myadbquery.sequencelength="1"; | |
90 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
91 size=myadbqueryresult.sizeRlist; | |
92 | |
93 //dump_query(&myadbquery,&myadbqueryresult); | |
94 ///* check the test values */ | |
95 if (size != 2) {returnval = -1;}; | |
96 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
97 if (testoneresult(&myadbqueryresult,1,"testfeature10",2,0,0)) {returnval = -1;}; | |
98 | |
99 | |
100 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 > testoutput | |
101 //echo testfeature01 0 0 0 > test-expected-output | |
102 //cmp testoutput test-expected-output | |
103 myadbquery.querytype="sequence"; | |
104 myadbquery.feature="testquery"; | |
105 myadbquery.sequencelength="1"; | |
106 myadbquery.resultlength="1"; | |
107 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
108 size=myadbqueryresult.sizeRlist; | |
109 | |
110 if (size != 1) {returnval = -1;}; | |
111 if (testoneresult(&myadbqueryresult,0,"testfeature01",0,0,0)) {returnval = -1;}; | |
112 //echo "query point (0.5,0.0)" | |
113 //intstring 2 > testquery | |
114 //floatstring 0.5 0 >> testquery | |
115 ivals[0]=2; | |
116 dvals[0]=0.5; dvals[1]=0; | |
117 maketestfile("testquery",ivals,dvals,2); | |
118 | |
119 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
120 ////echo testfeature10 0 0 0 > test-expected-output | |
121 ////echo testfeature01 2 0 0 >> test-expected-output | |
122 ////cmp testoutput test-expected-output | |
123 myadbquery2.querytype="sequence"; | |
124 myadbquery2.feature="testquery"; | |
125 myadbquery2.sequencelength="1"; | |
126 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
127 size=myadbqueryresult2.sizeRlist; | |
128 | |
129 if (size != 2) {returnval = -1;}; | |
130 if (testoneresult(&myadbqueryresult2,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
131 if (testoneresult(&myadbqueryresult2,1,"testfeature01",2,0,0)) {returnval = -1;}; | |
132 | |
133 | |
134 ////${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 > testoutput | |
135 ////echo testfeature10 0 0 0 > test-expected-output | |
136 ////cmp testoutput test-expected-output | |
137 myadbquery2.querytype="sequence"; | |
138 myadbquery2.feature="testquery"; | |
139 myadbquery2.sequencelength="1"; | |
140 myadbquery2.resultlength="1"; | |
141 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
142 size=myadbqueryresult2.sizeRlist; | |
143 | |
144 if (size != 1) {returnval = -1;}; | |
145 if (testoneresult(&myadbqueryresult2,0,"testfeature10",0,0,0)) {returnval = -1;}; | |
146 | |
147 audiodb_close(mydbp); | |
148 // fprintf(stderr,"returnval:%d\n",returnval); | |
149 | |
150 return(returnval); | |
151 } | 66 } |
152 |