1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/check.c>
8 #include <ccan/tap/tap.h>
9 #include <ccan/tdb2/transaction.c>
13 int main(int argc
, char *argv
[])
16 struct tdb_context
*tdb
;
17 struct tdb_layout
*layout
;
21 key
= tdb_mkdata("Hello", 5);
22 data
= tdb_mkdata("world", 5);
24 /* Create a TDB with three free tables. */
25 layout
= new_tdb_layout(NULL
);
26 tdb_layout_add_freetable(layout
);
27 tdb_layout_add_freetable(layout
);
28 tdb_layout_add_freetable(layout
);
29 tdb_layout_add_free(layout
, 80, 0);
30 /* Used record prevent coalescing. */
31 tdb_layout_add_used(layout
, key
, data
, 6);
32 tdb_layout_add_free(layout
, 160, 1);
34 tdb_layout_add_used(layout
, key
, data
, 7);
35 tdb_layout_add_free(layout
, 320, 2);
37 tdb_layout_add_used(layout
, key
, data
, 8);
38 tdb_layout_add_free(layout
, 40, 0);
39 tdb
= tdb_layout_get(layout
);
40 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
42 off
= get_free(tdb
, 0, 80 - sizeof(struct tdb_used_record
), 0,
44 ok1(off
== layout
->elem
[3].base
.off
);
45 ok1(tdb
->ftable_off
== layout
->elem
[0].base
.off
);
47 off
= get_free(tdb
, 0, 160 - sizeof(struct tdb_used_record
), 0,
49 ok1(off
== layout
->elem
[5].base
.off
);
50 ok1(tdb
->ftable_off
== layout
->elem
[1].base
.off
);
52 off
= get_free(tdb
, 0, 320 - sizeof(struct tdb_used_record
), 0,
54 ok1(off
== layout
->elem
[7].base
.off
);
55 ok1(tdb
->ftable_off
== layout
->elem
[2].base
.off
);
57 off
= get_free(tdb
, 0, 40 - sizeof(struct tdb_used_record
), 0,
59 ok1(off
== layout
->elem
[9].base
.off
);
60 ok1(tdb
->ftable_off
== layout
->elem
[0].base
.off
);
63 off
= get_free(tdb
, 0, 0, 1, TDB_USED_MAGIC
, 0);
67 tdb_layout_free(layout
);
69 ok1(tap_log_messages
== 0);