1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tdb2/check.c>
7 #include <ccan/tap/tap.h>
11 int main(int argc, char *argv[])
14 struct tdb_context *tdb;
15 struct tdb_layout *layout;
19 key.dptr = (unsigned char *)"Hello";
20 data.dptr = (unsigned char *)"world";
24 /* Create a TDB with three free lists. */
25 layout = new_tdb_layout(NULL);
26 tdb_layout_add_freelist(layout);
27 tdb_layout_add_freelist(layout);
28 tdb_layout_add_freelist(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, 0);
43 ok1(off == layout->elem[3].base.off);
44 ok1(tdb->flist_off == layout->elem[0].base.off);
46 off = get_free(tdb, 0, 160 - sizeof(struct tdb_used_record), 0, 0);
47 ok1(off == layout->elem[5].base.off);
48 ok1(tdb->flist_off == layout->elem[1].base.off);
50 off = get_free(tdb, 0, 320 - sizeof(struct tdb_used_record), 0, 0);
51 ok1(off == layout->elem[7].base.off);
52 ok1(tdb->flist_off == layout->elem[2].base.off);
54 off = get_free(tdb, 0, 40 - sizeof(struct tdb_used_record), 0, 0);
55 ok1(off == layout->elem[9].base.off);
56 ok1(tdb->flist_off == layout->elem[0].base.off);
59 off = get_free(tdb, 0, 0, 1, 0);
64 ok1(tap_log_messages == 0);