s3:smb2_break: make use of file_fsp_smb2()
[Samba/gebeck_regimport.git] / lib / tdb / test / run-endian.c
blobbf6e71389f8af27b8243cd495d0bd71d32e7c761
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 <err.h>
15 #include "logging.h"
17 int main(int argc, char *argv[])
19 struct tdb_context *tdb;
20 TDB_DATA key, data;
22 plan_tests(13);
23 tdb = tdb_open_ex("run-endian.tdb", 1024,
24 TDB_CLEAR_IF_FIRST|TDB_CONVERT,
25 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
27 ok1(tdb);
28 key.dsize = strlen("hi");
29 key.dptr = (void *)"hi";
30 data.dsize = strlen("world");
31 data.dptr = (void *)"world";
33 ok1(tdb_store(tdb, key, data, TDB_MODIFY) < 0);
34 ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
35 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36 ok1(tdb_store(tdb, key, data, TDB_INSERT) < 0);
37 ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
38 ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
40 data = tdb_fetch(tdb, key);
41 ok1(data.dsize == strlen("world"));
42 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
43 free(data.dptr);
45 key.dsize++;
46 data = tdb_fetch(tdb, key);
47 ok1(data.dptr == NULL);
48 tdb_close(tdb);
50 /* Reopen: should read it */
51 tdb = tdb_open_ex("run-endian.tdb", 1024, 0, O_RDWR, 0,
52 &taplogctx, NULL);
53 ok1(tdb);
55 key.dsize = strlen("hi");
56 key.dptr = (void *)"hi";
57 data = tdb_fetch(tdb, key);
58 ok1(data.dsize == strlen("world"));
59 ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
60 free(data.dptr);
61 tdb_close(tdb);
63 return exit_status();