s3:smbd: add exit_server to the smbd_shim hooks
[Samba/gebeck_regimport.git] / lib / tdb / test / run-endian.c
blobb19ffd373f1fa7f23b3df78c0cb6bb8d65472ac2
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"
16 int main(int argc, char *argv[])
18 struct tdb_context *tdb;
19 TDB_DATA key, data;
21 plan_tests(13);
22 tdb = tdb_open_ex("run-endian.tdb", 1024,
23 TDB_CLEAR_IF_FIRST|TDB_CONVERT,
24 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
26 ok1(tdb);
27 key.dsize = strlen("hi");
28 key.dptr = (void *)"hi";
29 data.dsize = strlen("world");
30 data.dptr = (void *)"world";
32 ok1(tdb_store(tdb, key, data, TDB_MODIFY) < 0);
33 ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
34 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
35 ok1(tdb_store(tdb, key, data, TDB_INSERT) < 0);
36 ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
37 ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
39 data = tdb_fetch(tdb, key);
40 ok1(data.dsize == strlen("world"));
41 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
42 free(data.dptr);
44 key.dsize++;
45 data = tdb_fetch(tdb, key);
46 ok1(data.dptr == NULL);
47 tdb_close(tdb);
49 /* Reopen: should read it */
50 tdb = tdb_open_ex("run-endian.tdb", 1024, 0, O_RDWR, 0,
51 &taplogctx, NULL);
52 ok1(tdb);
54 key.dsize = strlen("hi");
55 key.dptr = (void *)"hi";
56 data = tdb_fetch(tdb, key);
57 ok1(data.dsize == strlen("world"));
58 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
59 free(data.dptr);
60 tdb_close(tdb);
62 return exit_status();