4 #include "tap-interface.h"
5 #include <ccan/hash/hash.h>
10 static const struct ntdb_context *curr_ntdb;
11 static const struct ntdb_file *curr_file;
13 static int owner_null_count,
14 owner_weird_count, alloc_count, free_count, expand_count;
16 static void *test_alloc(const void *owner, size_t len, void *priv_data)
22 } else if (owner != curr_ntdb && owner != curr_file) {
29 /* The first time, this is the current ntdb, next is
30 * for the file struct. */
34 } else if (!curr_file) {
38 assert(priv_data == &owner_weird_count);
42 static void *test_expand(void *old, size_t newlen, void *priv_data)
46 assert(priv_data == &owner_weird_count);
47 return realloc(old, newlen);
50 static void test_free(void *old, void *priv_data)
52 assert(priv_data == &owner_weird_count);
59 int main(int argc, char *argv[])
62 union ntdb_attribute alloc_attr;
63 struct ntdb_context *ntdb;
64 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
65 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
66 NTDB_NOMMAP|NTDB_CONVERT };
67 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
68 NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
70 alloc_attr.base.next = &tap_log_attr;
71 alloc_attr.base.attr = NTDB_ATTRIBUTE_ALLOCATOR;
73 alloc_attr.alloc.alloc = test_alloc;
74 alloc_attr.alloc.expand = test_expand;
75 alloc_attr.alloc.free = test_free;
76 alloc_attr.alloc.priv_data = &owner_weird_count;
78 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 700 * 3 + 4) + 1);
80 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
83 ntdb = ntdb_open("run-12-store.ntdb", flags[i]|MAYBE_NOSYNC,
84 O_RDWR|O_CREAT|O_TRUNC, 0600, &alloc_attr);
89 for (j = 0; j < 700; j++) {
90 NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
91 ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
92 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
93 ok1(ntdb_deq(d, data));
94 test_free(d.dptr, &owner_weird_count);
98 ok1(owner_null_count == 2+i*2);
99 ok1(owner_weird_count == 0);
100 ok1(alloc_count == free_count);
101 ok1(expand_count != 0);
104 ok1(tap_log_messages == 0);
105 return exit_status();