comparison libtests/0034/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
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;
6 adb_insert_t insert = {0};
7 adb_status_t status = {0};
8 adb_insert_t batch[4] = {{0},{0},{0},{0}};
16 9
10 clean_remove_db(TESTDB);
11 if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
12 return 1;
17 13
18 int main(int argc, char **argv){ 14 maketestfile("testfeature", 2, (double[2]) {1, 1}, 2);
15 maketestfile("testfeature01", 2, (double[2]) {0, 1}, 2);
16 maketestfile("testfeature10", 2, (double[2]) {1, 0}, 2);
19 17
20 int returnval=0; 18 insert.features = "testfeature";
21 adb_ptr mydbp={0}; 19 if(audiodb_insert(adb, &insert))
22 int ivals[10]; 20 return 1;
23 double dvals[10]; 21 if(audiodb_status(adb, &status) || status.numFiles != 1)
24 adb_insert_t myinsert={0}; 22 return 1;
25 char * databasename="testdb"; 23
26 adb_status_t mystatus={0}; 24 /* reinserts using audiodb_insert() should silently not fail and
27 adb_insert_t ins1[3]={{0},{0},{0}}; 25 * silently not insert, to support legacy command-line behaviour. */
26 if(audiodb_insert(adb, &insert))
27 return 1;
28 if(audiodb_status(adb, &status) || status.numFiles != 1)
29 return 1;
28 30
31 /* reinserts using audiodb_insert_datum() should fail. */
32 adb_datum_t datum = {1, 2, "testfeature", (double[2]) {1, 1}};
33 if(!audiodb_insert_datum(adb, &datum))
34 return 1;
29 35
36 insert.features = "testfeature01";
37 if(audiodb_insert(adb, &insert))
38 return 1;
39 if(audiodb_status(adb, &status) || status.numFiles != 2)
40 return 1;
30 41
31 /* remove old directory */ 42 insert.features = "testfeature10";
32 //if [ -f testdb ]; then rm -f testdb; fi 43 if(audiodb_insert(adb, &insert))
33 clean_remove_db(databasename); 44 return 1;
45 if(audiodb_status(adb, &status) || status.numFiles != 3)
46 return 1;
47
48 audiodb_close(adb);
34 49
35 /* create new db */ 50 clean_remove_db(TESTDB);
36 //${AUDIODB} -d testdb -N 51 if(!(adb = audiodb_create(TESTDB, 0, 0, 0)))
37 mydbp=audiodb_create(databasename,0,0,0); 52 return 1;
38 53
54 batch[0].features = "testfeature";
55 batch[1].features = "testfeature01";
56 batch[2].features = "testfeature10";
57 batch[3].features = "testfeature10";
58 if(audiodb_batchinsert(adb, batch, 4))
59 return 1;
60 if(audiodb_status(adb, &status) || status.numFiles != 3)
61 return 1;
39 62
40 //intstring 2 > testfeature 63 audiodb_close(adb);
41 //floatstring 1 1 >> testfeature
42 //intstring 2 > testfeature01
43 //floatstring 0 1 >> testfeature01
44 //intstring 2 > testfeature10
45 //floatstring 1 0 >> testfeature10
46 ivals[0]=2;
47 dvals[0]=1; dvals[1]=1;
48 maketestfile("testfeature",ivals,dvals,2);
49 ivals[0]=2;
50 dvals[0]=0; dvals[1]=1;
51 maketestfile("testfeature01",ivals,dvals,2);
52 ivals[0]=2;
53 dvals[0]=1; dvals[1]=0;
54 maketestfile("testfeature10",ivals,dvals,2);
55 64
56 //${AUDIODB} -d testdb -I -f testfeature 65 return 104;
57 myinsert.features="testfeature";
58 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
59
60 //${AUDIODB} -d testdb -S | grep "num files:1"
61 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
62 if(mystatus.numFiles != 1) { returnval = -1; }
63
64 //${AUDIODB} -d testdb -I -f testfeature
65 myinsert.features="testfeature";
66 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
67
68 //${AUDIODB} -d testdb -S | grep "num files:1"
69 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
70 if(mystatus.numFiles != 1) { returnval = -1; }
71
72 //${AUDIODB} -d testdb -I -f testfeature01
73 myinsert.features="testfeature01";
74 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
75
76 //${AUDIODB} -d testdb -S | grep "num files:2"
77 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
78 if(mystatus.numFiles != 2) { returnval = -1; }
79
80 //${AUDIODB} -d testdb -I -f testfeature10
81 myinsert.features="testfeature10";
82 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
83
84 //${AUDIODB} -d testdb -S | grep "num files:3"
85 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
86 if(mystatus.numFiles != 3) { returnval = -1; }
87
88 //rm -f testdb
89 clean_remove_db(databasename);
90
91 /* create new db */
92 //${AUDIODB} -d testdb -N
93 mydbp=audiodb_create(databasename,0,0,0);
94
95
96 //${AUDIODB} -d testdb -I -f testfeature01
97 myinsert.features="testfeature01";
98 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
99
100 //${AUDIODB} -d testdb -S | grep "num files:1"
101 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
102 if(mystatus.numFiles != 1) { returnval = -1; }
103
104 //${AUDIODB} -d testdb -I -f testfeature01
105 myinsert.features="testfeature01";
106 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
107
108 //${AUDIODB} -d testdb -S | grep "num files:1"
109 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
110 if(mystatus.numFiles != 1) { returnval = -1; }
111
112 //${AUDIODB} -d testdb -I -f testfeature10
113 myinsert.features="testfeature10";
114 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
115
116 //${AUDIODB} -d testdb -S | grep "num files:2"
117 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
118 if(mystatus.numFiles != 2) { returnval = -1; }
119
120 //${AUDIODB} -d testdb -I -f testfeature
121 myinsert.features="testfeature";
122 if(audiodb_insert(mydbp,&myinsert)) {returnval = -1; };
123
124 //${AUDIODB} -d testdb -S | grep "num files:3"
125 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
126 if(mystatus.numFiles != 3) { returnval = -1; }
127
128
129
130
131 //rm -f testdb
132 clean_remove_db(databasename);
133
134 /* create new db */
135 //${AUDIODB} -d testdb -N
136 mydbp=audiodb_create(databasename,0,0,0);
137
138 //echo testfeature > testfeaturelist.txt
139 //echo testfeature01 >> testfeaturelist.txt
140 //echo testfeature10 >> testfeaturelist.txt
141 //${AUDIODB} -B -F testfeaturelist.txt -d testdb
142 ins1[0].features="testfeature";
143 ins1[1].features="testfeature01";
144 ins1[2].features="testfeature10";
145 if(audiodb_batchinsert(mydbp,ins1,3)){
146 returnval=-1;
147 };
148
149 //${AUDIODB} -d testdb -S | grep "num files:3"
150 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
151 if(mystatus.numFiles != 3) { returnval = -1; }
152
153
154
155
156 //rm -f testdb
157 clean_remove_db(databasename);
158
159 /* create new db */
160 //${AUDIODB} -d testdb -N
161 mydbp=audiodb_create(databasename,0,0,0);
162
163
164 //echo testfeature01 > testfeaturelist.txt
165 //echo testfeature10 >> testfeaturelist.txt
166 //echo testfeature >> testfeaturelist.txt
167 //${AUDIODB} -B -F testfeaturelist.txt -d testdb
168 ins1[0].features="testfeature";
169 ins1[1].features="testfeature01";
170 ins1[2].features="testfeature10";
171 if(audiodb_batchinsert(mydbp,ins1,3)){
172 returnval=-1;
173 };
174
175 //${AUDIODB} -d testdb -S | grep "num files:3"
176 if(audiodb_status(mydbp,&mystatus)) {returnval = -1; };
177 if(mystatus.numFiles != 3) { returnval = -1; }
178
179
180
181 fprintf(stderr,"returnval:%d\n",returnval);
182 return(returnval);
183 } 66 }