comparison libtests/0001/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 #include <errno.h>
10 /*
11 * * #define NDEBUG
12 * * */
13 #include <assert.h>
14 3
15 #include "../../audioDB_API.h" 4 int main(int argc, char **argv) {
16 #include "../test_utils_lib.h" 5 adb_t *adb;
6 struct stat st;
17 7
8 clean_remove_db(TESTDB);
18 9
19 int main(int argc, char **argv){ 10 adb = audiodb_open(TESTDB, O_RDWR);
11 if(adb)
12 return 1;
20 13
21 int returnval=0; 14 adb = audiodb_create(TESTDB, 0, 0, 0);
22 adb_ptr mydbp={0}; 15 if (!adb)
23 adb_ptr mydbp2={0}; 16 return 1;
24 struct stat statbuf;
25 int statval=0;
26 17
27 char * databasename="testdb"; 18 if(stat(TESTDB, &st))
19 return 1;
28 20
29 //if [ -f testdb ]; then rm -f testdb; fi 21 audiodb_close(adb);
30 /* remove old directory */
31 clean_remove_db(databasename);
32 22
33 /* create new db */ 23 adb = audiodb_create(TESTDB, 0, 0, 0);
34 //# creation 24 if(adb)
35 //${AUDIODB} -N -d testdb 25 return 1;
36 mydbp=audiodb_open(databasename);
37 26
27 adb = audiodb_open(TESTDB, O_RDONLY);
28 if (!adb)
29 return 1;
38 30
39 /* open should fail (return NULL), so create a new db */ 31 audiodb_close(adb);
40 if (!mydbp){
41 mydbp=audiodb_create(databasename,0,0,0);
42 }
43 32
44 33 return 104;
45
46 if (!mydbp){
47 printf("fail\n");
48 returnval=-1;
49 }
50
51
52 /* stat testdb - let's make sure that it is there */
53 //stat testdb
54 statval=stat(databasename, &statbuf);
55
56 if (statval){
57 returnval=-1;
58 }
59
60 audiodb_close(mydbp);
61
62 /* try to create should fail, because db exists now */
63 mydbp2=audiodb_create(databasename,0,0,0);
64
65 if (mydbp2){
66 returnval=-1;
67 }
68
69
70 /* should pass now - db exists */
71 //expect_clean_error_exit ${AUDIODB} -N -d testdb
72 mydbp2=audiodb_open(databasename);
73 if (!mydbp2){
74 returnval=-1;
75 }
76
77 //this test would fail at compile time because of the API interface
78 //# should fail (no db given)
79 //expect_clean_error_exit ${AUDIODB} -N
80
81
82 audiodb_close(mydbp2);
83
84 // printf("returnval:%d\n",returnval);
85
86 return(returnval);
87 } 34 }
88