1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
7 int main(int argc
, char *argv
[])
9 struct tdb_context
*tdb
;
11 union tdb_attribute hsize
;
13 hsize
.base
.attr
= TDB_ATTRIBUTE_TDB1_HASHSIZE
;
14 hsize
.base
.next
= &tap_log_attr
;
15 hsize
.tdb1_hashsize
.hsize
= 1024;
18 tdb
= tdb_open("run-endian.tdb1",
19 TDB_VERSION1
|TDB_CONVERT
,
20 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &hsize
);
23 key
.dsize
= strlen("hi");
24 key
.dptr
= (void *)"hi";
25 data
.dsize
= strlen("world");
26 data
.dptr
= (void *)"world";
28 ok1(tdb_store(tdb
, key
, data
, TDB_MODIFY
) == TDB_ERR_NOEXIST
);
29 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == TDB_SUCCESS
);
30 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == TDB_ERR_EXISTS
);
31 ok1(tdb_store(tdb
, key
, data
, TDB_MODIFY
) == TDB_SUCCESS
);
33 ok1(tdb_fetch(tdb
, key
, &data
) == TDB_SUCCESS
);
34 ok1(data
.dsize
== strlen("world"));
35 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);
39 ok1(tdb_fetch(tdb
, key
, &data
) == TDB_ERR_NOEXIST
);
40 ok1(data
.dptr
== NULL
);
43 /* Reopen: should read it */
44 tdb
= tdb_open("run-endian.tdb1", 0, O_RDWR
, 0, NULL
);
47 key
.dsize
= strlen("hi");
48 key
.dptr
= (void *)"hi";
49 ok1(tdb_fetch(tdb
, key
, &data
) == TDB_SUCCESS
);
50 ok1(data
.dsize
== strlen("world"));
51 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);