wintest: add option to select the dns backend
[Samba/gebeck_regimport.git] / lib / ntdb / test / run-seed.c
blob2514f728ac933af469c74fe40ee8a22c48a43d33
1 #include "ntdb-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
5 static int log_count = 0;
7 /* Normally we get a log when setting random seed. */
8 static void my_log_fn(struct ntdb_context *ntdb,
9 enum ntdb_log_level level,
10 enum NTDB_ERROR ecode,
11 const char *message, void *priv)
13 log_count++;
16 static union ntdb_attribute log_attr = {
17 .log = { .base = { .attr = NTDB_ATTRIBUTE_LOG },
18 .fn = my_log_fn }
21 int main(int argc, char *argv[])
23 unsigned int i;
24 struct ntdb_context *ntdb;
25 union ntdb_attribute attr;
26 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
27 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
28 NTDB_NOMMAP|NTDB_CONVERT };
30 attr.seed.base.attr = NTDB_ATTRIBUTE_SEED;
31 attr.seed.base.next = &log_attr;
32 attr.seed.seed = 42;
34 plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 4 * 3);
35 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
36 struct ntdb_header hdr;
37 int fd;
38 ntdb = ntdb_open("run-seed.ntdb", flags[i],
39 O_RDWR|O_CREAT|O_TRUNC, 0600, &attr);
40 ok1(ntdb);
41 if (!ntdb)
42 continue;
43 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
44 ok1(ntdb->hash_seed == 42);
45 ok1(log_count == 0);
46 ntdb_close(ntdb);
48 if (flags[i] & NTDB_INTERNAL)
49 continue;
51 fd = open("run-seed.ntdb", O_RDONLY);
52 ok1(fd >= 0);
53 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
54 if (flags[i] & NTDB_CONVERT)
55 ok1(bswap_64(hdr.hash_seed) == 42);
56 else
57 ok1(hdr.hash_seed == 42);
58 close(fd);
60 return exit_status();