1 #include "ntdb-source.h"
2 #include "tap-interface.h"
6 int main(int argc
, char *argv
[])
9 struct ntdb_context
*ntdb
;
10 struct ntdb_layout
*layout
;
12 union ntdb_attribute seed
;
14 /* This seed value previously tickled a layout.c bug. */
15 seed
.base
.attr
= NTDB_ATTRIBUTE_SEED
;
16 seed
.seed
.seed
= 0xb1142bc054d035b4ULL
;
17 seed
.base
.next
= &tap_log_attr
;
20 key
= ntdb_mkdata("Hello", 5);
21 data
= ntdb_mkdata("world", 5);
23 /* Create a NTDB with three free tables. */
24 layout
= new_ntdb_layout();
25 ntdb_layout_add_freetable(layout
);
26 ntdb_layout_add_freetable(layout
);
27 ntdb_layout_add_freetable(layout
);
28 ntdb_layout_add_free(layout
, 80, 0);
29 /* Used record prevent coalescing. */
30 ntdb_layout_add_used(layout
, key
, data
, 6);
31 ntdb_layout_add_free(layout
, 160, 1);
33 ntdb_layout_add_used(layout
, key
, data
, 7);
34 ntdb_layout_add_free(layout
, 320, 2);
36 ntdb_layout_add_used(layout
, key
, data
, 8);
37 ntdb_layout_add_free(layout
, 40, 0);
38 ntdb
= ntdb_layout_get(layout
, free
, &seed
);
39 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
41 off
= get_free(ntdb
, 0, 80 - sizeof(struct ntdb_used_record
), 0,
43 ok1(off
== layout
->elem
[3].base
.off
);
44 ok1(ntdb
->ftable_off
== layout
->elem
[0].base
.off
);
46 off
= get_free(ntdb
, 0, 160 - sizeof(struct ntdb_used_record
), 0,
48 ok1(off
== layout
->elem
[5].base
.off
);
49 ok1(ntdb
->ftable_off
== layout
->elem
[1].base
.off
);
51 off
= get_free(ntdb
, 0, 320 - sizeof(struct ntdb_used_record
), 0,
53 ok1(off
== layout
->elem
[7].base
.off
);
54 ok1(ntdb
->ftable_off
== layout
->elem
[2].base
.off
);
56 off
= get_free(ntdb
, 0, 40 - sizeof(struct ntdb_used_record
), 0,
58 ok1(off
== layout
->elem
[9].base
.off
);
59 ok1(ntdb
->ftable_off
== layout
->elem
[0].base
.off
);
62 off
= get_free(ntdb
, 0, 0, 1, NTDB_USED_MAGIC
);
66 ntdb_layout_free(layout
);
68 ok1(tap_log_messages
== 0);