Mercurial > hg > audiodb
comparison libtests/0007/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 // adbquery myadbquery2={0}; | |
17 // adbqueryresult myadbqueryresult2={0}; | |
18 int size=0; | |
19 | 15 |
20 /* remove old directory */ | 16 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; |
21 clean_remove_db(databasename); | 17 adb_query_id_t qid = {0}; |
18 qid.datum = &query; | |
19 qid.sequence_length = 16; | |
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; | |
22 | 25 |
23 /* create new db */ | 26 adb_query_spec_t spec; |
24 mydbp=audiodb_create(databasename,0,0,0); | 27 spec.qid = qid; |
28 spec.params = parms; | |
29 spec.refine = refine; | |
30 adb_query_results_t *results = audiodb_query_spec(adb, &spec); | |
31 if(results) return 1; | |
25 | 32 |
26 //# tests that the lack of -l when the query sequence is shorter doesn't | 33 spec.params.npoints = 1; |
27 //# segfault. | 34 results = audiodb_query_spec(adb, &spec); |
35 if(results) return 1; | |
28 | 36 |
29 /* make test file */ | 37 spec.qid.datum->data = (double [2]) {0.5, 0}; |
30 //intstring 2 > testfeature | 38 spec.params.npoints = 10; |
31 //floatstring 0 1 >> testfeature | 39 results = audiodb_query_spec(adb, &spec); |
32 //floatstring 1 0 >> testfeature | 40 if(results) return 1; |
33 ivals[0]=2; | 41 |
34 dvals[0]=0; dvals[1]=1; dvals[2]=1; dvals[3]=0; | 42 spec.params.npoints = 1; |
35 maketestfile("testfeature",ivals,dvals,4); | 43 results = audiodb_query_spec(adb, &spec); |
44 if(results) return 1; | |
36 | 45 |
37 /* insert */ | 46 /* the above tests mirror those in the audioDB command-line test |
38 //${AUDIODB} -d testdb -I -f testfeature | 47 * suite. We can test for additional bad input cases too: */ |
39 myinsert.features="testfeature"; | |
40 myerr=audiodb_insert(mydbp,&myinsert); | |
41 if(myerr){ returnval=-1; }; | |
42 | 48 |
49 spec.qid.sequence_start = 1; | |
50 spec.qid.sequence_length = 1; | |
51 results = audiodb_query_spec(adb, &spec); | |
52 if(results) return 1; | |
43 | 53 |
44 /* turn on l2norm */ | 54 /* and just sanity check that we haven't broken everything */ |
45 //# sequence queries require L2NORM | 55 spec.qid.sequence_start = 0; |
46 //${AUDIODB} -d testdb -L | 56 spec.params.npoints = 2; |
47 if(audiodb_l2norm(mydbp)){ returnval=-1; }; | 57 results = audiodb_query_spec(adb, &spec); |
58 if(!results || results->nresults != 2) return 1; | |
59 audiodb_query_free_results(adb, &spec, results); | |
48 | 60 |
49 | 61 return 104; |
50 /* make query */ | |
51 //echo "query point (0.0,0.5)" | |
52 //intstring 2 > testquery | |
53 //floatstring 0 0.5 >> testquery | |
54 ivals[0]=2; | |
55 dvals[0]=0; dvals[1]=0.5; | |
56 maketestfile("testquery",ivals,dvals,2); | |
57 | |
58 | |
59 /* should fail */ | |
60 | |
61 //audioDB -Q sequence -d testdb -f testquery | |
62 //expect_clean_error_exit ${AUDIODB} -d testdb -Q sequence -f testquery | |
63 | |
64 myadbquery.querytype="sequence"; | |
65 myadbquery.feature="testquery"; | |
66 //myadbquery.sequencelength="1"; | |
67 myerr=audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
68 size=myadbqueryresult.sizeRlist; | |
69 if (!myerr){ returnval = -1;}; | |
70 | |
71 | |
72 ///* should fail */ | |
73 //expect_clean_error_exit ${AUDIODB} -d testdb -Q sequence -f testquery -n 1 | |
74 myadbquery.querytype="sequence"; | |
75 myadbquery.feature="testquery"; | |
76 myadbquery.numpoints="1"; | |
77 myerr=audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
78 if(!myerr){ returnval=-1; }; | |
79 | |
80 /* query 2 */ | |
81 //echo "query point (0.5,0.0)" | |
82 //intstring 2 > testquery | |
83 //floatstring 0.5 0 >> testquery | |
84 ivals[0]=2; | |
85 dvals[0]=0.5; dvals[1]=0.0; | |
86 maketestfile("testquery",ivals,dvals,2); | |
87 | |
88 /* should fail */ | |
89 //expect_clean_error_exit ${AUDIODB} -d testdb -Q sequence -f testquery | |
90 myadbquery.querytype="sequence"; | |
91 myadbquery.feature="testquery"; | |
92 myadbquery.numpoints=NULL; | |
93 myerr=audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
94 if(!myerr){ returnval=-1; }; | |
95 | |
96 /* should fail */ | |
97 //expect_clean_error_exit ${AUDIODB} -d testdb -Q sequence -f testquery -n 1 | |
98 myadbquery.querytype="sequence"; | |
99 myadbquery.feature="testquery"; | |
100 myadbquery.numpoints="1"; | |
101 myerr=audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
102 if(!myerr){ returnval=-1; }; | |
103 | |
104 | |
105 | |
106 | |
107 //printf("returnval:%d\n", returnval); | |
108 | |
109 return(returnval); | |
110 } | 62 } |
111 |