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