Mercurial > hg > audiodb
comparison libtests/0006/prog1.c @ 490:13de7ba21966 api-inversion
Continue removing uses of audiodb_query()
Deal with four more libtests/ cases.
Of course, it would probably be "nice" or "useful" to provide an
audiodb_query() implemented in terms of audiodb_query_spec() -- but that
is not a task that I would enjoy.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 15:32:58 +0000 |
parents | e072aa1611f5 |
children | 9d8aee621afb |
comparison
equal
deleted
inserted
replaced
489:4cb6c611f812 | 490:13de7ba21966 |
---|---|
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; | |
6 | 10 |
7 int returnval=0; | 11 adb_datum_t feature = {2, 2, "testfeature", (double[4]) {0, 1, 1, 0}}; |
8 adb_ptr mydbp={0}; | 12 if(audiodb_insert_datum(adb, &feature)) |
9 int ivals[10]; | 13 return 1; |
10 double dvals[10]; | 14 audiodb_l2norm(adb); |
11 adb_insert_t myinsert={0}; | |
12 unsigned int myerr=0; | |
13 char * databasename="testdb"; | |
14 adb_query_t myadbquery={0}; | |
15 adb_queryresult_t myadbqueryresult={0}; | |
16 adb_query_t myadbquery2={0}; | |
17 adb_queryresult_t myadbqueryresult2={0}; | |
18 int size=0; | |
19 | 15 |
16 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; | |
17 adb_query_id_t qid = {0}; | |
18 qid.datum = &query; | |
19 qid.sequence_length = 1; | |
20 qid.sequence_start = 0; | |
21 adb_query_parameters_t parms = | |
22 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; | |
23 adb_query_refine_t refine = {0}; | |
24 refine.hopsize = 1; | |
20 | 25 |
21 /* remove old directory */ | 26 adb_query_spec_t spec; |
22 //if [ -f testdb ]; then rm -f testdb; fi | 27 spec.qid = qid; |
23 clean_remove_db(databasename); | 28 spec.params = parms; |
29 spec.refine = refine; | |
24 | 30 |
25 /* create new db */ | 31 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
26 //${AUDIODB} -d testdb -N | 32 if(!results || results->nresults != 2) return 1; |
27 mydbp=audiodb_create(databasename,0,0,0); | 33 result_present_or_fail(results, "testfeature", 0, 0, 0); |
34 result_present_or_fail(results, "testfeature", 2, 0, 1); | |
35 audiodb_query_free_results(adb, &spec, results); | |
28 | 36 |
29 /* create testfeature file */ | 37 spec.params.npoints = 1; |
30 //intstring 2 > testfeature | 38 results = audiodb_query_spec(adb, &spec); |
31 //floatstring 0 1 >> testfeature | 39 if(!results || results->nresults != 1) return 1; |
32 //floatstring 1 0 >> testfeature | 40 result_present_or_fail(results, "testfeature", 0, 0, 0); |
33 ivals[0]=2; | 41 audiodb_query_free_results(adb, &spec, results); |
34 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0; | |
35 maketestfile("testfeature",ivals,dvals,4); | |
36 | 42 |
43 spec.qid.datum->data = (double [2]) {0.5, 0}; | |
44 spec.params.npoints = 10; | |
45 results = audiodb_query_spec(adb, &spec); | |
46 if(!results || results->nresults != 2) return 1; | |
47 result_present_or_fail(results, "testfeature", 0, 0, 1); | |
48 result_present_or_fail(results, "testfeature", 2, 0, 0); | |
49 audiodb_query_free_results(adb, &spec, results); | |
37 | 50 |
38 /* insert */ | 51 spec.params.npoints = 1; |
39 //${AUDIODB} -d testdb -I -f testfeature | 52 results = audiodb_query_spec(adb, &spec); |
40 myinsert.features="testfeature"; | 53 if(!results || results->nresults != 1) return 1; |
41 if(audiodb_insert(mydbp,&myinsert)){ | 54 result_present_or_fail(results, "testfeature", 0, 0, 1); |
42 returnval=-1; | 55 audiodb_query_free_results(adb, &spec, results); |
43 }; | |
44 | 56 |
57 audiodb_close(adb); | |
45 | 58 |
46 /* turn on L2NORM */ | 59 return(104); |
47 //# sequence queries require L2NORM | |
48 //${AUDIODB} -d testdb -L | |
49 audiodb_l2norm(mydbp); | |
50 | |
51 /* make a test query */ | |
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,2); | |
58 | |
59 /* test a sequence query */ | |
60 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
61 //echo testfeature 1 0 0 > test-expected-output | |
62 //cmp testoutput test-expected-output | |
63 myadbquery.querytype="sequence"; | |
64 myadbquery.feature="testquery"; | |
65 myadbquery.sequencelength="1"; | |
66 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
67 size=myadbqueryresult.sizeRlist; | |
68 | |
69 /* check the test values */ | |
70 if (size != 1) {returnval = -1;}; | |
71 if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;}; | |
72 | |
73 | |
74 /* same but with limites */ | |
75 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
76 //echo testfeature 0 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 /* check the test values */ | |
83 if (size != 1) {returnval = -1;}; | |
84 if (testoneresult(&myadbqueryresult,0,"testfeature",0,0,0)) {returnval = -1;}; | |
85 | |
86 /* make another query */ | |
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.0; dvals[2]=0; dvals[3]=0; | |
92 maketestfile("testquery",ivals,dvals,2); | |
93 | |
94 | |
95 /* test new query */ | |
96 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery > testoutput | |
97 //echo testfeature 1 0 1 > test-expected-output | |
98 //cmp testoutput test-expected-output | |
99 | |
100 myadbquery2.querytype="sequence"; | |
101 myadbquery2.feature="testquery"; | |
102 myadbquery2.sequencelength="1"; | |
103 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
104 size=myadbqueryresult2.sizeRlist; | |
105 | |
106 /* check the test values */ | |
107 if (size != 1) {returnval = -1;}; | |
108 if (testoneresult(&myadbqueryresult2,0,"testfeature",1,0,1)) {returnval = -1;}; | |
109 | |
110 | |
111 /* test new query with limits */ | |
112 myadbquery2.numpoints="1"; | |
113 audiodb_query(mydbp,&myadbquery2,&myadbqueryresult2); | |
114 size=myadbqueryresult2.sizeRlist; | |
115 | |
116 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -n 1 > testoutput | |
117 //echo testfeature 0 0 1 > test-expected-output | |
118 //cmp testoutput test-expected-output | |
119 | |
120 | |
121 /* check the test values */ | |
122 if (size != 1) {returnval = -1;}; | |
123 if (testoneresult(&myadbqueryresult2,0,"testfeature",0,0,1)) {returnval = -1;}; | |
124 | |
125 | |
126 | |
127 /* close */ | |
128 audiodb_close(mydbp); | |
129 | |
130 printf("returnval:%d\n",returnval); | |
131 return(returnval); | |
132 } | 60 } |
133 | |
134 |