wintest: add option to select the dns backend
[Samba/gebeck_regimport.git] / lib / ntdb / test / api-93-repack.c
blob168bc24c0a9470a57a71512480c82093ed57dc6e
1 #include "config.h"
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include "logging.h"
9 #define NUM_TESTS 1000
11 static bool store_all(struct ntdb_context *ntdb)
13 unsigned int i;
14 NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
15 NTDB_DATA dbuf = { (unsigned char *)&i, sizeof(i) };
17 for (i = 0; i < NUM_TESTS; i++) {
18 if (ntdb_store(ntdb, key, dbuf, NTDB_INSERT) != NTDB_SUCCESS)
19 return false;
21 return true;
24 static int mark_entry(struct ntdb_context *ntdb,
25 NTDB_DATA key, NTDB_DATA data, bool found[])
27 unsigned int num;
29 if (key.dsize != sizeof(num))
30 return -1;
31 memcpy(&num, key.dptr, key.dsize);
32 if (num >= NUM_TESTS)
33 return -1;
34 if (found[num])
35 return -1;
36 found[num] = true;
37 return 0;
40 static bool is_all_set(bool found[], unsigned int num)
42 unsigned int i;
44 for (i = 0; i < num; i++)
45 if (!found[i])
46 return false;
47 return true;
50 int main(int argc, char *argv[])
52 unsigned int i;
53 bool found[NUM_TESTS];
54 struct ntdb_context *ntdb;
55 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
56 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT
59 plan_tests(sizeof(flags) / sizeof(flags[0]) * 6 + 1);
61 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
62 ntdb = ntdb_open("run-93-repack.ntdb", flags[i],
63 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
64 ok1(ntdb);
65 if (!ntdb)
66 break;
68 ok1(store_all(ntdb));
70 ok1(ntdb_repack(ntdb) == NTDB_SUCCESS);
71 memset(found, 0, sizeof(found));
72 ok1(ntdb_check(ntdb, NULL, NULL) == NTDB_SUCCESS);
73 ok1(ntdb_traverse(ntdb, mark_entry, found) == NUM_TESTS);
74 ok1(is_all_set(found, NUM_TESTS));
75 ntdb_close(ntdb);
78 ok1(tap_log_messages == 0);
79 return exit_status();