3 #include "tap-interface.h"
4 #include <ccan/hash/hash.h>
12 static const struct ntdb_context
*curr_ntdb
;
13 static const struct ntdb_file
*curr_file
;
15 static int owner_null_count
,
16 owner_weird_count
, alloc_count
, free_count
, expand_count
;
18 static void *test_alloc(const void *owner
, size_t len
, void *priv_data
)
24 } else if (owner
!= curr_ntdb
&& owner
!= curr_file
) {
31 /* The first time, this is the current ntdb, next is
32 * for the file struct. */
36 } else if (!curr_file
) {
40 assert(priv_data
== &owner_weird_count
);
44 static void *test_expand(void *old
, size_t newlen
, void *priv_data
)
48 assert(priv_data
== &owner_weird_count
);
49 return realloc(old
, newlen
);
52 static void test_free(void *old
, void *priv_data
)
54 assert(priv_data
== &owner_weird_count
);
61 int main(int argc
, char *argv
[])
64 union ntdb_attribute alloc_attr
;
65 struct ntdb_context
*ntdb
;
66 int flags
[] = { NTDB_INTERNAL
, NTDB_DEFAULT
, NTDB_NOMMAP
,
67 NTDB_INTERNAL
|NTDB_CONVERT
, NTDB_CONVERT
,
68 NTDB_NOMMAP
|NTDB_CONVERT
};
69 NTDB_DATA key
= { (unsigned char *)&j
, sizeof(j
) };
70 NTDB_DATA data
= { (unsigned char *)&j
, sizeof(j
) };
72 alloc_attr
.base
.next
= &tap_log_attr
;
73 alloc_attr
.base
.attr
= NTDB_ATTRIBUTE_ALLOCATOR
;
75 alloc_attr
.alloc
.alloc
= test_alloc
;
76 alloc_attr
.alloc
.expand
= test_expand
;
77 alloc_attr
.alloc
.free
= test_free
;
78 alloc_attr
.alloc
.priv_data
= &owner_weird_count
;
80 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * (1 + 700 * 3 + 4) + 1);
82 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
85 ntdb
= ntdb_open("run-12-store.ntdb", flags
[i
]|MAYBE_NOSYNC
,
86 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &alloc_attr
);
91 for (j
= 0; j
< 700; j
++) {
92 NTDB_DATA d
= { NULL
, 0 }; /* Bogus GCC warning */
93 ok1(ntdb_store(ntdb
, key
, data
, NTDB_REPLACE
) == 0);
94 ok1(ntdb_fetch(ntdb
, key
, &d
) == NTDB_SUCCESS
);
95 ok1(ntdb_deq(d
, data
));
96 test_free(d
.dptr
, &owner_weird_count
);
100 ok1(owner_null_count
== 2+i
*2);
101 ok1(owner_weird_count
== 0);
102 ok1(alloc_count
== free_count
);
103 ok1(expand_count
!= 0);
106 ok1(tap_log_messages
== 0);
107 return exit_status();