Mercurial > hg > audiodb
comparison libtests/0037/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 | 1327b5cf4cb5 |
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 result_position(adb_query_results_t *r, const char *key, float dist, uint32_t qpos, uint32_t ipos) { | |
5 for(uint32_t k = 0; k < r->nresults; k++) { | |
6 adb_result_t result = r->results[k]; | |
7 if((dist == result.dist) && (qpos == result.qpos) && | |
8 (ipos == result.ipos) && !(strcmp(key, result.key))) { | |
9 return k; | |
10 } | |
11 } | |
12 return -1; | |
13 } | |
14 | |
15 int main(int argc, char *argv[]) { | 4 int main(int argc, char *argv[]) { |
16 char *dbname = "testdb"; | |
17 adb_t *adb; | 5 adb_t *adb; |
18 adb_insert_t *batch = 0; | 6 adb_insert_t *batch = 0; |
19 adb_status_t status; | 7 adb_status_t status; |
20 adb_query_t query = {0}; | 8 adb_query_t query = {0}; |
21 adb_queryresult_t result; | 9 adb_queryresult_t result; |
22 | 10 |
23 clean_remove_db(dbname); | 11 clean_remove_db(TESTDB); |
24 adb = audiodb_create("testdb", 0, 0, 0); | 12 adb = audiodb_create(TESTDB, 0, 0, 0); |
25 if(!adb) { | 13 if(!adb) { |
26 return 1; | 14 return 1; |
27 } | 15 } |
28 | 16 |
29 maketestfile("testfeature01", (int[1]) {2}, (double[4]) {0,1,1,0}, 4); | 17 maketestfile("testfeature01", (int[1]) {2}, (double[4]) {0,1,1,0}, 4); |
69 spec.params = parms; | 57 spec.params = parms; |
70 spec.refine = refine; | 58 spec.refine = refine; |
71 | 59 |
72 adb_query_results_t *results = audiodb_query_spec(adb, &spec); | 60 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
73 | 61 |
74 if(results->nresults != 4) return 1; | 62 if(!results || results->nresults != 4) return 1; |
75 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | 63 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
76 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | 64 result_present_or_fail(results, "testfeature01", 2, 0, 1); |
77 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | 65 result_present_or_fail(results, "testfeature10", 0, 0, 1); |
78 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | 66 result_present_or_fail(results, "testfeature10", 2, 0, 0); |
79 audiodb_query_free_results(adb, &spec, results); | 67 audiodb_query_free_results(adb, &spec, results); |
80 | 68 |
81 spec.params.npoints = 2; | 69 spec.params.npoints = 2; |
82 results = audiodb_query_spec(adb, &spec); | 70 results = audiodb_query_spec(adb, &spec); |
83 | 71 |
84 if(results->nresults != 4) return 1; | 72 if(!results || results->nresults != 4) return 1; |
85 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | 73 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
86 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | 74 result_present_or_fail(results, "testfeature01", 2, 0, 1); |
87 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | 75 result_present_or_fail(results, "testfeature10", 0, 0, 1); |
88 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | 76 result_present_or_fail(results, "testfeature10", 2, 0, 0); |
89 audiodb_query_free_results(adb, &spec, results); | 77 audiodb_query_free_results(adb, &spec, results); |
90 | 78 |
91 spec.params.npoints = 5; | 79 spec.params.npoints = 5; |
92 results = audiodb_query_spec(adb, &spec); | 80 results = audiodb_query_spec(adb, &spec); |
93 | 81 |
94 if(results->nresults != 4) return 1; | 82 if(!results || results->nresults != 4) return 1; |
95 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | 83 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
96 if(result_position(results, "testfeature01", 2, 0, 1) < 0) return 1; | 84 result_present_or_fail(results, "testfeature01", 2, 0, 1); |
97 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | 85 result_present_or_fail(results, "testfeature10", 0, 0, 1); |
98 if(result_position(results, "testfeature10", 2, 0, 0) < 0) return 1; | 86 result_present_or_fail(results, "testfeature10", 2, 0, 0); |
99 audiodb_query_free_results(adb, &spec, results); | 87 audiodb_query_free_results(adb, &spec, results); |
100 | 88 |
101 spec.params.npoints = 1; | 89 spec.params.npoints = 1; |
102 results = audiodb_query_spec(adb, &spec); | 90 results = audiodb_query_spec(adb, &spec); |
103 | 91 |
104 if(results->nresults != 2) return 1; | 92 if(!results || results->nresults != 2) return 1; |
105 if(result_position(results, "testfeature01", 0, 0, 0) < 0) return 1; | 93 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
106 if(result_position(results, "testfeature10", 0, 0, 1) < 0) return 1; | 94 result_present_or_fail(results, "testfeature10", 0, 0, 1); |
107 | 95 |
108 audiodb_query_free_results(adb, &spec, results); | 96 audiodb_query_free_results(adb, &spec, results); |
109 | 97 |
110 spec.qid.datum->data = (double [2]) {0.5, 0}; | 98 spec.qid.datum->data = (double [2]) {0.5, 0}; |
111 spec.params.npoints = 10; | 99 spec.params.npoints = 10; |
112 results = audiodb_query_spec(adb, &spec); | 100 results = audiodb_query_spec(adb, &spec); |
113 | 101 |
114 if(results->nresults != 4) return 1; | 102 if(!results || results->nresults != 4) return 1; |
115 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | 103 result_present_or_fail(results, "testfeature01", 0, 0, 1); |
116 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | 104 result_present_or_fail(results, "testfeature01", 2, 0, 0); |
117 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | 105 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
118 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | 106 result_present_or_fail(results, "testfeature10", 2, 0, 1); |
119 audiodb_query_free_results(adb, &spec, results); | 107 audiodb_query_free_results(adb, &spec, results); |
120 | 108 |
121 spec.params.npoints = 2; | 109 spec.params.npoints = 2; |
122 results = audiodb_query_spec(adb, &spec); | 110 results = audiodb_query_spec(adb, &spec); |
123 | 111 |
124 if(results->nresults != 4) return 1; | 112 if(!results || results->nresults != 4) return 1; |
125 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | 113 result_present_or_fail(results, "testfeature01", 0, 0, 1); |
126 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | 114 result_present_or_fail(results, "testfeature01", 2, 0, 0); |
127 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | 115 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
128 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | 116 result_present_or_fail(results, "testfeature10", 2, 0, 1); |
129 audiodb_query_free_results(adb, &spec, results); | 117 audiodb_query_free_results(adb, &spec, results); |
130 | 118 |
131 spec.params.npoints = 5; | 119 spec.params.npoints = 5; |
132 results = audiodb_query_spec(adb, &spec); | 120 results = audiodb_query_spec(adb, &spec); |
133 | 121 |
134 if(results->nresults != 4) return 1; | 122 if(!results || results->nresults != 4) return 1; |
135 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | 123 result_present_or_fail(results, "testfeature01", 0, 0, 1); |
136 if(result_position(results, "testfeature01", 2, 0, 0) < 0) return 1; | 124 result_present_or_fail(results, "testfeature01", 2, 0, 0); |
137 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | 125 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
138 if(result_position(results, "testfeature10", 2, 0, 1) < 0) return 1; | 126 result_present_or_fail(results, "testfeature10", 2, 0, 1); |
139 audiodb_query_free_results(adb, &spec, results); | 127 audiodb_query_free_results(adb, &spec, results); |
140 | 128 |
141 spec.params.npoints = 1; | 129 spec.params.npoints = 1; |
142 results = audiodb_query_spec(adb, &spec); | 130 results = audiodb_query_spec(adb, &spec); |
143 | 131 |
144 if(results->nresults != 2) return 1; | 132 if(!results || results->nresults != 2) return 1; |
145 if(result_position(results, "testfeature01", 0, 0, 1) < 0) return 1; | 133 result_present_or_fail(results, "testfeature01", 0, 0, 1); |
146 if(result_position(results, "testfeature10", 0, 0, 0) < 0) return 1; | 134 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
147 audiodb_query_free_results(adb, &spec, results); | 135 audiodb_query_free_results(adb, &spec, results); |
148 | 136 |
149 audiodb_close(adb); | 137 audiodb_close(adb); |
150 | 138 |
151 return 104; | 139 return 104; |