libsmb: add ABI/smbclient-0.2.1.sigs
[Samba/bjacke.git] / lib / ntdb / test / api-93-repack.c
blob4a30c57edfa2380d0540ce41fdf633683bacc2f5
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",
63 flags[i]|MAYBE_NOSYNC,
64 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
65 ok1(ntdb);
66 if (!ntdb)
67 break;
69 ok1(store_all(ntdb));
71 ok1(ntdb_repack(ntdb) == NTDB_SUCCESS);
72 memset(found, 0, sizeof(found));
73 ok1(ntdb_check(ntdb, NULL, NULL) == NTDB_SUCCESS);
74 ok1(ntdb_traverse(ntdb, mark_entry, found) == NUM_TESTS);
75 ok1(is_all_set(found, NUM_TESTS));
76 ntdb_close(ntdb);
79 ok1(tap_log_messages == 0);
80 return exit_status();