s3: winbindd: Old NT Domain code sets struct winbind_domain->alt_name to be NULL...
[Samba.git] / lib / ntdb / test / run-50-multiple-freelists.c
blob5496e3e0dd2a9e657ed71822cf07bf74c5c20710
1 #include "ntdb-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
4 #include "layout.h"
6 int main(int argc, char *argv[])
8 ntdb_off_t off;
9 struct ntdb_context *ntdb;
10 struct ntdb_layout *layout;
11 NTDB_DATA key, data;
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;
19 plan_tests(11);
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);
32 key.dsize--;
33 ntdb_layout_add_used(layout, key, data, 7);
34 ntdb_layout_add_free(layout, 320, 2);
35 key.dsize--;
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,
42 NTDB_USED_MAGIC);
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,
47 NTDB_USED_MAGIC);
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,
52 NTDB_USED_MAGIC);
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,
57 NTDB_USED_MAGIC);
58 ok1(off == layout->elem[9].base.off);
59 ok1(ntdb->ftable_off == layout->elem[0].base.off);
61 /* Now we fail. */
62 off = get_free(ntdb, 0, 0, 1, NTDB_USED_MAGIC);
63 ok1(off == 0);
65 ntdb_close(ntdb);
66 ntdb_layout_free(layout);
68 ok1(tap_log_messages == 0);
69 return exit_status();