1 #include "ntdb-source.h"
2 #include "tap-interface.h"
5 static int drop_count(struct ntdb_context *ntdb, unsigned int *count)
12 static int set_found(struct ntdb_context *ntdb, bool found[3])
16 if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach0.ntdb") == 0)
18 else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach1.ntdb") == 0)
20 else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach2.ntdb") == 0)
31 int main(int argc, char *argv[])
33 unsigned int i, count;
35 struct ntdb_context *ntdb0, *ntdb1, *ntdb;
36 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
37 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
39 plan_tests(sizeof(flags) / sizeof(flags[0]) * 8);
40 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
41 ntdb0 = ntdb_open("run-ntdb_foreach0.ntdb", flags[i],
42 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
43 ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb", flags[i],
44 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
45 ntdb = ntdb_open("run-ntdb_foreach2.ntdb", flags[i],
46 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
48 memset(found, 0, sizeof(found));
49 ntdb_foreach(set_found, found);
50 ok1(found[0] && found[1] && found[2]);
52 /* Test premature iteration termination */
54 ntdb_foreach(drop_count, &count);
58 memset(found, 0, sizeof(found));
59 ntdb_foreach(set_found, found);
60 ok1(found[0] && !found[1] && found[2]);
63 memset(found, 0, sizeof(found));
64 ntdb_foreach(set_found, found);
65 ok1(found[0] && !found[1] && !found[2]);
67 ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb", flags[i],
68 O_RDWR, 0600, &tap_log_attr);
69 memset(found, 0, sizeof(found));
70 ntdb_foreach(set_found, found);
71 ok1(found[0] && found[1] && !found[2]);
74 memset(found, 0, sizeof(found));
75 ntdb_foreach(set_found, found);
76 ok1(!found[0] && found[1] && !found[2]);
79 memset(found, 0, sizeof(found));
80 ntdb_foreach(set_found, found);
81 ok1(!found[0] && !found[1] && !found[2]);
82 ok1(tap_log_messages == 0);