Mercurial > hg > audiodb
comparison libtests/0010/prog1.c @ 498:342822c2d49a
Merge api-inversion branch (-r656:771, but I don't expect to return to
that branch) into the trunk.
I expect there to be minor performance regressions (e.g. in the SOAP
server index cacheing, which I have forcibly removed) and minor
unplugged memory leaks (e.g. in audioDB::query(), where I don't free up
the datum). I hope that these leaks and performance regressions can be
plugged in short order. I also expect that some (but maybe not all) of
the issues currently addressed in the memory-leaks branch are superseded
or fixed by this merge.
There remains much work to be done; go forth and do it.
author | mas01cr |
---|---|
date | Sat, 10 Jan 2009 16:47:57 +0000 |
parents | 94c18f128ce8 |
children | bcc7a6ddb2c8 |
comparison
equal
deleted
inserted
replaced
476:a7193678280b | 498:342822c2d49a |
---|---|
1 #include <stdio.h> | 1 #include "audioDB_API.h" |
2 #include <stdlib.h> | 2 #include "test_utils_lib.h" |
3 #include <string.h> | |
4 #include <sysexits.h> | |
5 #include <fcntl.h> | |
6 #include <dirent.h> | |
7 #include <unistd.h> | |
8 #include <sys/stat.h> | |
9 /* | |
10 * * #define NDEBUG | |
11 * * */ | |
12 #include <assert.h> | |
13 | 3 |
14 #include "../../audioDB_API.h" | 4 int main(int argc, char **argv) { |
15 #include "../test_utils_lib.h" | 5 adb_t *adb; |
16 | 6 |
7 clean_remove_db(TESTDB); | |
8 if(!(adb = audiodb_create(TESTDB, 0, 0, 0))) | |
9 return 1; | |
10 adb_datum_t datum1 = {1, 2, "testfeature01", (double[2]) {0, 1}}; | |
11 adb_datum_t datum2 = {1, 2, "testfeature10", (double[2]) {1, 0}}; | |
12 if(audiodb_insert_datum(adb, &datum1)) | |
13 return 1; | |
14 if(audiodb_insert_datum(adb, &datum2)) | |
15 return 1; | |
16 if(audiodb_l2norm(adb)) | |
17 return 1; | |
17 | 18 |
18 int main(int argc, char **argv){ | 19 adb_datum_t query = {1, 2, "testquery", (double[2]) {0, 0.5}}; |
19 | 20 |
20 int returnval=0; | 21 adb_query_id_t qid = {0}; |
21 adb_ptr mydbp={0}; | 22 qid.datum = &query; |
22 int ivals[10]; | 23 qid.sequence_length = 1; |
23 double dvals[10]; | 24 qid.sequence_start = 0; |
24 adb_insert_t myinsert={0}; | 25 adb_query_parameters_t parms = |
25 unsigned int myerr=0; | 26 {ADB_ACCUMULATION_PER_TRACK, ADB_DISTANCE_EUCLIDEAN_NORMED, 10, 10}; |
26 char * databasename="testdb"; | 27 adb_query_refine_t refine = {0}; |
27 adb_query_t myadbquery={0}; | 28 refine.flags |= ADB_REFINE_RADIUS; |
28 adb_queryresult_t myadbqueryresult={0}; | 29 refine.radius = 5; |
29 int size=0; | 30 refine.hopsize = 1; |
30 | 31 |
31 /* clean */ | 32 adb_query_spec_t spec; |
32 //if [ -f testdb ]; then rm -f testdb; fi | 33 spec.qid = qid; |
33 clean_remove_db(databasename); | 34 spec.params = parms; |
35 spec.refine = refine; | |
34 | 36 |
35 /* new db */ | 37 adb_query_results_t *results = audiodb_query_spec(adb, &spec); |
36 //${AUDIODB} -d testdb -N | 38 if(!results || results->nresults != 2) return 1; |
37 mydbp=audiodb_create(databasename,0,0,0); | 39 result_present_or_fail(results, "testfeature01", 0, 0, 0); |
40 result_present_or_fail(results, "testfeature10", 2, 0, 0); | |
41 audiodb_query_free_results(adb, &spec, results); | |
42 | |
43 /* the test in the original test suite for | |
44 * audioDB-the-command-line-program alters the parms.ntracks, which | |
45 * is not very meaningful in this context (given that we don't do | |
46 * aggregation, but simply return valid points); here instead we | |
47 * check that radius filtering works. */ | |
48 spec.refine.radius = 1; | |
49 results = audiodb_query_spec(adb, &spec); | |
50 if(!results || results->nresults != 1) return 1; | |
51 result_present_or_fail(results, "testfeature01", 0, 0, 0); | |
52 audiodb_query_free_results(adb, &spec, results); | |
38 | 53 |
39 /* test feature files */ | 54 spec.qid.datum->data = (double[2]) {0.5, 0}; |
40 //intstring 2 > testfeature01 | 55 spec.refine.radius = 5; |
41 //floatstring 0 1 >> testfeature01 | 56 results = audiodb_query_spec(adb, &spec); |
42 ivals[0]=2; | 57 if(!results || results->nresults != 2) return 1; |
43 dvals[0]=0; dvals[1]=1; | 58 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
44 maketestfile("testfeature01",ivals,dvals,2); | 59 result_present_or_fail(results, "testfeature01", 2, 0, 0); |
45 //intstring 2 > testfeature10 | 60 audiodb_query_free_results(adb, &spec, results); |
46 //floatstring 1 0 >> testfeature10 | |
47 ivals[0]=2; | |
48 dvals[0]=1; dvals[1]=0; | |
49 maketestfile("testfeature10",ivals,dvals,2); | |
50 | 61 |
51 /* inserts */ | 62 spec.refine.radius = 1; |
52 //${AUDIODB} -d testdb -I -f testfeature01 | 63 results = audiodb_query_spec(adb, &spec); |
53 //${AUDIODB} -d testdb -I -f testfeature10 | 64 if(!results || results->nresults != 1) return 1; |
54 myinsert.features="testfeature01"; | 65 result_present_or_fail(results, "testfeature10", 0, 0, 0); |
55 myerr=audiodb_insert(mydbp,&myinsert); | 66 audiodb_query_free_results(adb, &spec, results); |
56 myinsert.features="testfeature10"; | |
57 myerr=audiodb_insert(mydbp,&myinsert); | |
58 | 67 |
59 /* l2norm */ | 68 audiodb_close(adb); |
60 //# sequence queries require L2NORM | |
61 //${AUDIODB} -d testdb -L | |
62 audiodb_l2norm(mydbp); | |
63 | 69 |
64 /* query 1 */ | 70 return 104; |
65 //echo "query point (0.0,0.5)" | |
66 //intstring 2 > testquery | |
67 //floatstring 0 0.5 >> testquery | |
68 ivals[0]=2; | |
69 dvals[0]=0; dvals[1]=0.5; dvals[2]=0; dvals[3]=0; | |
70 maketestfile("testquery",ivals,dvals,2); | |
71 | |
72 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput | |
73 //echo testfeature01 1 > test-expected-output | |
74 //echo testfeature10 1 >> test-expected-output | |
75 //cmp testoutput test-expected-output | |
76 | |
77 myadbquery.querytype="sequence"; | |
78 myadbquery.feature="testquery"; | |
79 myadbquery.sequencelength="1"; | |
80 myadbquery.radius="5"; | |
81 audiodb_query(mydbp,&myadbquery,&myadbqueryresult); | |
82 size=myadbqueryresult.sizeRlist; | |
83 | |
84 dump_query(&myadbquery,&myadbqueryresult); | |
85 /* check the test values */ | |
86 if (size != 2) {returnval = -1;}; | |
87 //if (testoneresult(&myadbqueryresult,0,"testfeature",1,0,0)) {returnval = -1;}; | |
88 //if (testoneresult(&myadbqueryresult,1,"testfeature",1,0,0)) {returnval = -1;}; | |
89 | |
90 | |
91 /* query 2 */ | |
92 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -R 5 > testoutput | |
93 //echo testfeature01 1 > test-expected-output | |
94 //cmp testoutput test-expected-output | |
95 // | |
96 //echo "query point (0.5,0.0)" | |
97 //intstring 2 > testquery | |
98 //floatstring 0.5 0 >> testquery | |
99 | |
100 | |
101 /* query 3 */ | |
102 //# FIXME: because there's only one point in each track (and the query), | |
103 //# the ordering is essentially database order. We need these test | |
104 //# cases anyway because we need to test non-segfaulting, non-empty | |
105 //# results... | |
106 // | |
107 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -R 5 > testoutput | |
108 //echo testfeature01 1 > test-expected-output | |
109 //echo testfeature10 1 >> test-expected-output | |
110 //cmp testoutput test-expected-output | |
111 | |
112 | |
113 | |
114 /* query 4 */ | |
115 //${AUDIODB} -d testdb -Q sequence -l 1 -f testquery -r 1 -R 5 > testoutput | |
116 //echo testfeature01 1 > test-expected-output | |
117 //cmp testoutput test-expected-output | |
118 | |
119 | |
120 printf("returnval:%d\n",returnval); | |
121 //returnval=-1; | |
122 | |
123 return(returnval); | |
124 } | 71 } |
125 |