Mercurial > hg > audiodb
comparison libtests/0037/prog1.c @ 470:c26c5b7ef0d2 api-inversion
Implement libtests/0037 using audiodb_query_spec()
It's a bit wordy; there's also the struct / pointer issue in
audiodb_query_spec_t to think through. But it does work.
author | mas01cr |
---|---|
date | Wed, 31 Dec 2008 16:52:34 +0000 |
parents | 9de6d0676907 |
children | e072aa1611f5 |
comparison
equal
deleted
inserted
replaced
469:d3afc91d205d | 470:c26c5b7ef0d2 |
---|---|
11 * * */ | 11 * * */ |
12 #include <assert.h> | 12 #include <assert.h> |
13 | 13 |
14 #include "../../audioDB_API.h" | 14 #include "../../audioDB_API.h" |
15 #include "../test_utils_lib.h" | 15 #include "../test_utils_lib.h" |
16 | |
17 int result_position(adb_query_results_t *r, const char *key, float dist, uint32_t qpos, uint32_t ipos) { | |
18 for(uint32_t k = 0; k < r->nresults; k++) { | |
19 adb_result_t result = r->results[k]; | |
20 if((dist == result.dist) && (qpos == result.qpos) && | |
21 (ipos == result.ipos) && !(strcmp(key, result.key))) { | |
22 return k; | |
23 } | |
24 } | |
25 return -1; | |
26 } | |
16 | 27 |
17 int main(int argc, char *argv[]) { | 28 int main(int argc, char *argv[]) { |
18 char *dbname = "testdb"; | 29 char *dbname = "testdb"; |
19 adb_t *adb; | 30 adb_t *adb; |
20 adb_insert_t *batch = 0; | 31 adb_insert_t *batch = 0; |
41 batch[3].features = "testfeature10"; | 52 batch[3].features = "testfeature10"; |
42 batch[4].features = "testfeature01"; | 53 batch[4].features = "testfeature01"; |
43 batch[5].features = "testfeature10"; | 54 batch[5].features = "testfeature10"; |
44 | 55 |
45 audiodb_batchinsert(adb, batch, 6); | 56 audiodb_batchinsert(adb, batch, 6); |
57 free(batch); | |
46 | 58 |
47 if(audiodb_status(adb, &status)) { | 59 if(audiodb_status(adb, &status)) { |
48 return 1; | 60 return 1; |
49 } | 61 } |
50 if(status.numFiles != 2) { | 62 if(status.numFiles != 2) { |
53 | 65 |
54 if(audiodb_l2norm(adb)) { | 66 if(audiodb_l2norm(adb)) { |
55 return 1; | 67 return 1; |
56 } | 68 } |
57 | 69 |
58 maketestfile("testquery", (int [1]) {2}, (double[2]) {0, 0.5}, 2); | 70 adb_datum_t datum = {1, 2, NULL, (double [2]){0, 0.5}, NULL, NULL}; |
59 return 14; | 71 adb_query_id_t qid = {0}; |
60 /* can't do nsequence yet */ | 72 qid.datum = &datum; |
61 /* | 73 qid.sequence_length = 1; |
62 query.querytype = "nsequence"; | 74 adb_query_parameters_t parms = |
63 query.sequencelength = "1"; | 75 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; |
64 query.feature = "testquery"; | 76 adb_query_refine_t refine = {0}; |
65 if(audiodb_query(adb, &query, &result)) { | 77 refine.hopsize = 1; |
66 return 1; | 78 |
67 } | 79 /* FIXME: structs / pointers */ |
68 if(result.sizeRlist != 2) { | 80 adb_query_spec_t spec; |
69 return 1; | 81 spec.qid = qid; |
70 } | 82 spec.params = parms; |
71 if(testoneresult(&result, 0, "testfeature01" ...)); | 83 spec.refine = refine; |
84 | |
85 adb_query_results_t *results = audiodb_query_spec(adb, &spec); | |
86 | |
87 if(results->nresults != 4) return 1; | |
88 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | |
89 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | |
90 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | |
91 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | |
92 audiodb_query_free_results(adb, &spec, results); | |
93 | |
94 spec.params.npoints = 2; | |
95 results = audiodb_query_spec(adb, &spec); | |
96 | |
97 if(results->nresults != 4) return 1; | |
98 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | |
99 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | |
100 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | |
101 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | |
102 audiodb_query_free_results(adb, &spec, results); | |
103 | |
104 spec.params.npoints = 5; | |
105 results = audiodb_query_spec(adb, &spec); | |
106 | |
107 if(results->nresults != 4) return 1; | |
108 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | |
109 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | |
110 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | |
111 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | |
112 audiodb_query_free_results(adb, &spec, results); | |
113 | |
114 spec.params.npoints = 1; | |
115 results = audiodb_query_spec(adb, &spec); | |
116 | |
117 if(results->nresults != 2) return 1; | |
118 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | |
119 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | |
120 | |
121 audiodb_query_free_results(adb, &spec, results); | |
122 | |
123 spec.qid.datum->data = (double [2]) {0.5, 0}; | |
124 spec.params.npoints = 10; | |
125 results = audiodb_query_spec(adb, &spec); | |
126 | |
127 if(results->nresults != 4) return 1; | |
128 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | |
129 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | |
130 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | |
131 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | |
132 audiodb_query_free_results(adb, &spec, results); | |
133 | |
134 spec.params.npoints = 2; | |
135 results = audiodb_query_spec(adb, &spec); | |
136 | |
137 if(results->nresults != 4) return 1; | |
138 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | |
139 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | |
140 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | |
141 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | |
142 audiodb_query_free_results(adb, &spec, results); | |
143 | |
144 spec.params.npoints = 5; | |
145 results = audiodb_query_spec(adb, &spec); | |
146 | |
147 if(results->nresults != 4) return 1; | |
148 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | |
149 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | |
150 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | |
151 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | |
152 audiodb_query_free_results(adb, &spec, results); | |
153 | |
154 spec.params.npoints = 1; | |
155 results = audiodb_query_spec(adb, &spec); | |
156 | |
157 if(results->nresults != 2) return 1; | |
158 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | |
159 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | |
160 audiodb_query_free_results(adb, &spec, results); | |
161 | |
162 audiodb_close(adb); | |
163 | |
72 return 104; | 164 return 104; |
73 */ | |
74 } | 165 } |
75 | 166 |