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.tdb1", TDB_VERSION1
,
19 O_CREAT
|O_TRUNC
|O_RDWR
, 0600, &hsize
);
22 key
.dsize
= strlen("hi");
23 key
.dptr
= (void *)"hi";
24 data
.dsize
= strlen("world");
25 data
.dptr
= (void *)"world";
27 ok1(tdb_store(tdb
, key
, data
, TDB_MODIFY
) == TDB_ERR_NOEXIST
);
28 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == TDB_SUCCESS
);
29 ok1(tdb_store(tdb
, key
, data
, TDB_INSERT
) == TDB_ERR_EXISTS
);
30 ok1(tdb_store(tdb
, key
, data
, TDB_MODIFY
) == TDB_SUCCESS
);
32 ok1(tdb_fetch(tdb
, key
, &data
) == TDB_SUCCESS
);
33 ok1(data
.dsize
== strlen("world"));
34 ok1(memcmp(data
.dptr
, "world", strlen("world")) == 0);
38 ok1(tdb_fetch(tdb
, key
, &data
) == TDB_ERR_NOEXIST
);