f49e85055e561a788bbc7e030f2ffa3a2349419d
[metze/samba/wip.git] / ctdb / lib / tdb / test / run.c
1 #include "../common/tdb_private.h"
2 #include "../common/io.c"
3 #include "../common/tdb.c"
4 #include "../common/lock.c"
5 #include "../common/freelist.c"
6 #include "../common/traverse.c"
7 #include "../common/transaction.c"
8 #include "../common/error.c"
9 #include "../common/open.c"
10 #include "../common/check.c"
11 #include "../common/hash.c"
12 #include "tap-interface.h"
13 #include <stdlib.h>
14 #include "logging.h"
15
16 int main(int argc, char *argv[])
17 {
18         struct tdb_context *tdb;
19         TDB_DATA key, data;
20
21         plan_tests(10);
22         tdb = tdb_open_ex("run.tdb", 1024, TDB_CLEAR_IF_FIRST,
23                           O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
24
25         ok1(tdb);
26         key.dsize = strlen("hi");
27         key.dptr = (void *)"hi";
28         data.dsize = strlen("world");
29         data.dptr = (void *)"world";
30
31         ok1(tdb_store(tdb, key, data, TDB_MODIFY) < 0);
32         ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
33         ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
34         ok1(tdb_store(tdb, key, data, TDB_INSERT) < 0);
35         ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
36         ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
37
38         data = tdb_fetch(tdb, key);
39         ok1(data.dsize == strlen("world"));
40         ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
41         free(data.dptr);
42
43         key.dsize++;
44         data = tdb_fetch(tdb, key);
45         ok1(data.dptr == NULL);
46         tdb_close(tdb);
47
48         return exit_status();
49 }