Line data Source code
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 "../common/mutex.c"
13 : #include "tap-interface.h"
14 : #include <stdlib.h>
15 : #include "logging.h"
16 :
17 1 : int main(int argc, char *argv[])
18 : {
19 : struct tdb_context *tdb;
20 : TDB_DATA key, data;
21 :
22 : plan_tests(13);
23 1 : 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);
26 :
27 1 : ok1(tdb);
28 1 : key.dsize = strlen("hi");
29 1 : key.dptr = discard_const_p(uint8_t, "hi");
30 1 : data.dsize = strlen("world");
31 1 : data.dptr = discard_const_p(uint8_t, "world");
32 :
33 1 : ok1(tdb_store(tdb, key, data, TDB_MODIFY) < 0);
34 1 : ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
35 1 : ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
36 1 : ok1(tdb_store(tdb, key, data, TDB_INSERT) < 0);
37 1 : ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
38 1 : ok1(tdb_store(tdb, key, data, TDB_MODIFY) == 0);
39 :
40 1 : data = tdb_fetch(tdb, key);
41 1 : ok1(data.dsize == strlen("world"));
42 1 : ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
43 1 : free(data.dptr);
44 :
45 1 : key.dsize++;
46 1 : data = tdb_fetch(tdb, key);
47 1 : ok1(data.dptr == NULL);
48 1 : tdb_close(tdb);
49 :
50 : /* Reopen: should read it */
51 1 : tdb = tdb_open_ex("run-endian.tdb", 1024, 0, O_RDWR, 0,
52 : &taplogctx, NULL);
53 1 : ok1(tdb);
54 :
55 1 : key.dsize = strlen("hi");
56 1 : key.dptr = discard_const_p(uint8_t, "hi");
57 1 : data = tdb_fetch(tdb, key);
58 1 : ok1(data.dsize == strlen("world"));
59 1 : ok1(memcmp(data.dptr, "world", strlen("world")) == 0);
60 1 : free(data.dptr);
61 1 : tdb_close(tdb);
62 :
63 1 : return exit_status();
64 : }
|