Mercurial > hg > audiodb
comparison libtests/0011/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; |
16 | 6 |
7 clean_remove_db(TESTDB); | |
8 if(!(adb = audiodb_create(TESTDB, 0, 0, 0))) | |
9 return 1; | |
17 | 10 |
18 int main(int argc, char **argv){ | 11 adb_datum_t datum = {2, 2, "testfeature", (double[4]) {0, 0.5, 0.5, 0}}; |
12 if(audiodb_insert_datum(adb, &datum)) | |
13 return 1; | |
14 if(audiodb_l2norm(adb)) | |
15 return 1; | |
19 | 16 |
20 int returnval=0; | 17 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; |
21 adb_ptr mydbp={0}; | 18 adb_query_id_t qid = {0}; |
22 int ivals[10]; | 19 qid.datum = &query; |
23 double dvals[10]; | 20 qid.sequence_length = 1; |
24 adb_insert_t myinsert={0}; | 21 qid.sequence_start = 0; |
25 unsigned int myerr=0; | 22 adb_query_parameters_t parms = |
26 char * databasename="testdb"; | 23 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; |
27 adb_query_t myadbquery={0}; | 24 adb_query_refine_t refine = {0}; |
28 adb_queryresult_t myadbqueryresult={0}; | 25 refine.hopsize = 1; |
29 adb_query_t myadbquery2={0}; | |
30 adb_queryresult_t myadbqueryresult2={0}; | |
31 int size=0; | |
32 | 26 |
27 adb_query_spec_t spec; | |
28 spec.qid = qid; | |
29 spec.params = parms; | |
30 spec.refine = refine; | |
33 | 31 |
34 //if [ -f testdb ]; then rm -f testdb; fi | 32 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
35 /* remove old directory */ | 33 if(!results || results->nresults != 2) return 1; |
36 clean_remove_db(databasename); | 34 result_present_or_fail(results, "testfeature", 0, 0, 0); |
35 result_present_or_fail(results, "testfeature", 2, 0, 1); | |
36 audiodb_query_free_results(adb, &spec, results); | |
37 | 37 |
38 spec.params.npoints = 1; | |
39 results = audiodb_query_spec(adb, &spec); | |
40 if(!results || results->nresults != 1) return 1; | |
41 result_present_or_fail(results, "testfeature", 0, 0, 0); | |
42 audiodb_query_free_results(adb, &spec, results); | |
38 | 43 |
39 //${AUDIODB} -d testdb -N | 44 spec.qid.datum->data = (double[2]) {0.5, 0}; |
40 /* create new db */ | 45 spec.params.npoints = 10; |
41 mydbp=audiodb_create(databasename,0,0,0); | 46 results = audiodb_query_spec(adb, &spec); |
47 if(!results || results->nresults != 2) return 1; | |
48 result_present_or_fail(results, "testfeature", 0, 0, 1); | |
49 result_present_or_fail(results, "testfeature", 2, 0, 0); | |
50 audiodb_query_free_results(adb, &spec, results); | |
51 | |
52 spec.params.npoints = 1; | |
53 results = audiodb_query_spec(adb, &spec); | |
54 if(!results || results->nresults != 1) return 1; | |
55 result_present_or_fail(results, "testfeature", 0, 0, 1); | |
56 audiodb_query_free_results(adb, &spec, results); | |
42 | 57 |
58 audiodb_close(adb); | |
43 | 59 |
44 /* create testfeature01 file */ | 60 return 104; |
45 //intstring 2 > testfeature | |
46 //floatstring 0 0.5 >> testfeature | |
47 //floatstring 0.5 0 >> testfeature | |
48 ivals[0]=2; | |
49 dvals[0]=0; dvals[1]=0.5; dvals[2]=0.5; dvals[3]=0; | |
50 maketestfile("testfeature",ivals,dvals,4); | |
51 | |
52 /* insert */ | |
53 //${AUDIODB} -d testdb -I -f testfeature | |
54 myinsert.features="testfeature"; | |
55 myerr=audiodb_insert(mydbp,&myinsert); | |
56 | |
57 /* create testquery file */ | |
58 //echo "query point (0.0,0.5)" | |
59 //intstring 2 > testquery | |
60 //floatstring 0 0.5 >> testquery | |
61 ivals[0]=2; | |
62 dvals[0]=0.0; dvals[1]=0.5; dvals[2]=0; dvals[3]=0; | |
63 maketestfile("testquery",ivals,dvals,2); | |
64 | |
65 /* l2norm */ | |
66 //# sequence queries require L2NORM | |
67 //${AUDIODB} -d testdb -L | |
68 audiodb_l2norm(mydbp); | |
69 | |
70 /* query */ | |
71 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
72 //echo testfeature 1 0 0 > test-expected-output | |
73 //cmp testoutput test-expected-output | |
74 myadbquery.querytype="sequence"; | |
75 myadbquery.feature="testquery"; | |
76 myadbquery.sequencelength="1"; | |
77 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
78 size=myadbqueryresult.sizeRlist; | |
79 | |
80 /* check the test values */ | |
81 if (size != 1) {returnval = -1;}; | |
82 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;}; | |
83 | |
84 /* query2 */ | |
85 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
86 //echo testfeature 0 0 0 > test-expected-output | |
87 //cmp testoutput test-expected-output | |
88 myadbquery.querytype="sequence"; | |
89 myadbquery.feature="testquery"; | |
90 myadbquery.sequencelength="1"; | |
91 myadbquery.numpoints="1"; | |
92 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
93 size=myadbqueryresult.sizeRlist; | |
94 | |
95 /* check the test values */ | |
96 if (size != 1) {returnval = -1;}; | |
97 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,0)) {returnval = -1;}; | |
98 | |
99 /* query3 */ | |
100 //echo "query point (0.5,0.0)" | |
101 //intstring 2 > testquery | |
102 //floatstring 0.5 0 >> testquery | |
103 ivals[0]=2; | |
104 dvals[0]=0.5; dvals[1]=0; | |
105 maketestfile("testquery",ivals,dvals,2); | |
106 | |
107 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
108 //echo testfeature 1 0 1 > test-expected-output | |
109 //cmp testoutput test-expected-output | |
110 myadbquery2.querytype="sequence"; | |
111 myadbquery2.feature="testquery"; | |
112 myadbquery2.sequencelength="1"; | |
113 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
114 size=myadbqueryresult2.sizeRlist; | |
115 | |
116 | |
117 /* check the test values */ | |
118 if (size != 1) {returnval = -1;}; | |
119 if (testoneresult(&myadbqueryresult2,0,"testfeature",1,0,1)) {returnval = -1;}; | |
120 | |
121 | |
122 /* query4 */ | |
123 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
124 //echo testfeature 0 0 1 > test-expected-output | |
125 //cmp testoutput test-expected-output | |
126 myadbquery2.querytype="sequence"; | |
127 myadbquery2.feature="testquery"; | |
128 myadbquery2.sequencelength="1"; | |
129 myadbquery2.numpoints="1"; | |
130 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
131 size=myadbqueryresult2.sizeRlist; | |
132 | |
133 /* check the test values */ | |
134 if (size != 1) {returnval = -1;}; | |
135 if (testoneresult(&myadbqueryresult2,0,"testfeature",0,0,1)) {returnval = -1;}; | |
136 | |
137 | |
138 | |
139 return(returnval); | |
140 } | 61 } |
141 |