Mercurial > hg > audiodb
comparison libtests/0004/prog1.c @ 489:4cb6c611f812 api-inversion
Begin removing uses of audiodb_query()
audiodb_query() is actually an unsupportable interface. It requires
access to the filesystem, does not (and cannot) actually support whole
swathes of functionality, is only implementable using code that is no
longer part of the core of audioDB (reporter.h), is in the way of fixing
memory leaks in the SOAP server, and is horrible to use to boot.
So, begin converting the libtests uses of audiodb_query() to
audio_query_spec(). In the process, go through the test code and
remove useless comments, pointless variables, and commented-out bits
of shell scripts.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 15:32:53 +0000 |
parents | e072aa1611f5 |
children |
comparison
equal
deleted
inserted
replaced
488:f4dc8e47ee37 | 489:4cb6c611f812 |
---|---|
1 #include "audioDB_API.h" | 1 #include "audioDB_API.h" |
2 #include "test_utils_lib.h" | 2 #include "test_utils_lib.h" |
3 | 3 |
4 int main(int argc, char **argv) { | |
5 adb_t *adb; | |
4 | 6 |
5 int main(int argc, char **argv){ | 7 clean_remove_db(TESTDB); |
8 if(!(adb = audiodb_create(TESTDB, 0, 0, 0))) | |
9 return 1; | |
10 if(audiodb_l2norm(adb)) | |
11 return 1; | |
6 | 12 |
7 int returnval=0; | 13 adb_datum_t feature = {2, 2, "testfeature", (double[4]) {0, 1, 1, 0}}; |
8 adb_ptr mydbp={0}; | 14 if(audiodb_insert_datum(adb, &feature)) |
9 adb_status_t mystatus={0}; | 15 return 1; |
10 int ivals[10]; | |
11 double dvals[10]; | |
12 FILE * myfile; | |
13 int ret=0; | |
14 adb_insert_t myinsert={0}; | |
15 unsigned int myerr=0; | |
16 adb_query_t myadbquery={0}; | |
17 adb_queryresult_t myadbqueryresult={0}; | |
18 adb_query_t myadbquery2={0}; | |
19 adb_queryresult_t myadbqueryresult2={0}; | |
20 char * databasename="testdb"; | |
21 int i=0; | |
22 int size=0; | |
23 | 16 |
17 adb_datum_t query = {1, 2, "testquery", (double [2]) {0, 0.5}}; | |
24 | 18 |
25 /* remove old directory */ | 19 adb_query_id_t qid = {0}; |
26 //if [ -f testdb ]; then rm -f testdb; fi | 20 qid.datum = &query; |
27 clean_remove_db(databasename); | 21 qid.sequence_length = 1; |
22 qid.sequence_start = 0; | |
23 adb_query_parameters_t parms = | |
24 {ADB_ACCUMULATION_DB, ADB_DISTANCE_DOT_PRODUCT, 10, 0}; | |
25 adb_query_refine_t refine = {0}; | |
26 refine.hopsize = 1; | |
28 | 27 |
29 /* create new db */ | 28 adb_query_spec_t spec; |
30 //${AUDIODB} -d testdb -N | 29 spec.qid = qid; |
31 mydbp=audiodb_create(databasename,0,0,0); | 30 spec.params = parms; |
31 spec.refine = refine; | |
32 | 32 |
33 /* turn on l2norm */ | 33 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
34 //${AUDIODB} -d testdb -L | 34 if(!results || results->nresults != 2) return 1; |
35 audiodb_l2norm(mydbp); | 35 result_present_or_fail(results, "testfeature", 0.5, 0, 0); |
36 result_present_or_fail(results, "testfeature", 0, 0, 1); | |
37 audiodb_query_free_results(adb, &spec, results); | |
36 | 38 |
37 /* make a test file */ | 39 spec.params.npoints = 1; |
38 //intstring 2 > testfeature | 40 results = audiodb_query_spec(adb, &spec); |
39 //floatstring 0 1 >> testfeature | 41 if(!results || results->nresults != 1) return 1; |
40 //floatstring 1 0 >> testfeature | 42 result_present_or_fail(results, "testfeature", 0.5, 0, 0); |
41 ivals[0]=2; | 43 audiodb_query_free_results(adb, &spec, results); |
42 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0; | |
43 maketestfile("testfeature", ivals,dvals,4); | |
44 | 44 |
45 spec.qid.datum->data = (double[2]) {0.5, 0}; | |
46 spec.params.npoints = 10; | |
47 results = audiodb_query_spec(adb, &spec); | |
48 result_present_or_fail(results, "testfeature", 0.5, 0, 1); | |
49 result_present_or_fail(results, "testfeature", 0, 0, 0); | |
50 audiodb_query_free_results(adb, &spec, results); | |
45 | 51 |
46 /* insert */ | 52 spec.params.npoints = 1; |
47 //${AUDIODB} -d testdb -I -f testfeature | 53 results = audiodb_query_spec(adb, &spec); |
48 myinsert.features="testfeature"; | 54 if(!results || results->nresults != 1) return 1; |
49 myerr=audiodb_insert(mydbp,&myinsert); | 55 result_present_or_fail(results, "testfeature", 0.5, 0, 1); |
56 audiodb_query_free_results(adb, &spec, results); | |
50 | 57 |
51 /* testquery */ | 58 audiodb_close(adb); |
52 //echo "query point (0.0,0.5)" | |
53 //intstring 2 > testquery | |
54 //floatstring 0 0.5 >> testquery | |
55 ivals[0]=2; | |
56 dvals[0]=0; dvals[1]=0.5; dvals[2]=0; dvals[3]=0; | |
57 maketestfile("testquery", ivals,dvals,4); | |
58 | 59 |
59 /* query 1 */ | 60 return 104; |
60 //${AUDIODB} -d testdb -Q point -f testquery > testoutput | |
61 //echo testfeature 0.5 0 0 > test-expected-output | |
62 //echo testfeature 0 0 1 >> test-expected-output | |
63 //cmp testoutput test-expected-output | |
64 myadbquery.querytype="point"; | |
65 myadbquery.feature="testquery"; | |
66 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
67 size=myadbqueryresult.sizeRlist; | |
68 | |
69 /* check the test values */ | |
70 if (size != 2) {returnval = -1;}; | |
71 if (testoneresult(&myadbqueryresult,0,"testfeature",.5,0,0)) {returnval = -1;}; | |
72 if (testoneresult(&myadbqueryresult,1,"testfeature",0,0,1)) {returnval = -1;}; | |
73 | |
74 /* query 2 - same but only first result */ | |
75 //${AUDIODB} -d testdb -Q point -f testquery -n 1 > testoutput | |
76 //echo testfeature 0.5 0 0 > test-expected-output | |
77 //cmp testoutput test-expected-output | |
78 myadbquery.numpoints="1"; | |
79 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
80 size=myadbqueryresult.sizeRlist; | |
81 | |
82 if (size != 1) {returnval = -1;}; | |
83 if (testoneresult(&myadbqueryresult,0,"testfeature",.5,0,0)) {returnval = -1;}; | |
84 | |
85 | |
86 /* testquery2 */ | |
87 //echo "query point (0.5,0.0)" | |
88 //intstring 2 > testquery | |
89 //floatstring 0.5 0 >> testquery | |
90 ivals[0]=2; | |
91 dvals[0]=0.5; dvals[1]=0; dvals[2]=0; dvals[3]=0; | |
92 maketestfile("testquery", ivals,dvals,4); | |
93 | |
94 /* query 3 */ | |
95 //${AUDIODB} -d testdb -Q point -f testquery > testoutput | |
96 //echo testfeature 0.5 0 1 > test-expected-output | |
97 //echo testfeature 0 0 0 >> test-expected-output | |
98 //cmp testoutput test-expected-output | |
99 myadbquery2.querytype="point"; | |
100 myadbquery2.feature="testquery"; | |
101 myadbquery2.numpoints=NULL; | |
102 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
103 size=myadbqueryresult2.sizeRlist; | |
104 | |
105 /* check the test values */ | |
106 if (size != 2) {returnval = -1;}; | |
107 if (testoneresult(&myadbqueryresult2,0,"testfeature",.5,0,1)) {returnval = -1;}; | |
108 if (testoneresult(&myadbqueryresult2,1,"testfeature",0,0,0)) {returnval = -1;}; | |
109 | |
110 /* query 4 - same as 3 but only first result */ | |
111 //${AUDIODB} -d testdb -Q point -f testquery -n 1 > testoutput | |
112 //echo testfeature 0.5 0 1 > test-expected-output | |
113 //cmp testoutput test-expected-output | |
114 myadbquery2.numpoints="1"; | |
115 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
116 size=myadbqueryresult2.sizeRlist; | |
117 | |
118 | |
119 if (size != 1) {returnval = -1;}; | |
120 if (testoneresult(&myadbqueryresult2,0,"testfeature",.5,0,1)) {returnval = -1;}; | |
121 | |
122 audiodb_close(mydbp); | |
123 | |
124 | |
125 return(returnval); | |
126 } | 61 } |
127 | 62 |