Mercurial > hg > audiodb
comparison libtests/0007/prog1.c @ 355:94c18f128ce8
First version of the API, committed to the main trunk. Thanks Christophe, for all the help!
author | mas01ik |
---|---|
date | Wed, 12 Nov 2008 10:21:06 +0000 |
parents | |
children | e072aa1611f5 342822c2d49a |
comparison
equal
deleted
inserted
replaced
354:4871a3ed9e36 | 355:94c18f128ce8 |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.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 | |
14 #include "../../audioDB_API.h" | |
15 #include "../test_utils_lib.h" | |
16 | |
17 | |
18 int main(int argc, char **argv){ | |
19 | |
20 int returnval=0; | |
21 adb_ptr mydbp={0}; | |
22 int ivals[10]; | |
23 double dvals[10]; | |
24 adb_insert_t myinsert={0}; | |
25 unsigned int myerr=0; | |
26 char * databasename="testdb"; | |
27 adb_query_t myadbquery={0}; | |
28 adb_queryresult_t myadbqueryresult={0}; | |
29 // adbquery myadbquery2={0}; | |
30 // adbqueryresult myadbqueryresult2={0}; | |
31 int size=0; | |
32 | |
33 /* remove old directory */ | |
34 clean_remove_db(databasename); | |
35 | |
36 /* create new db */ | |
37 mydbp=audiodb_create(databasename,0,0,0); | |
38 | |
39 //# tests that the lack of -l when the query sequence is shorter doesn't | |
40 //# segfault. | |
41 | |
42 /* make test file */ | |
43 //intstring 2 > testfeature | |
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 | |
50 /* insert */ | |
51 //${AUDIODB} -d testdb -I -f testfeature | |
52 myinsert.features="testfeature"; | |
53 myerr=audiodb_insert(mydbp,&myinsert); | |
54 if(myerr){ returnval=-1; }; | |
55 | |
56 | |
57 /* turn on l2norm */ | |
58 //# sequence queries require L2NORM | |
59 //${AUDIODB} -d testdb -L | |
60 if(audiodb_l2norm(mydbp)){ returnval=-1; }; | |
61 | |
62 | |
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 } | |
124 |