1 #include "ntdb-source.h"
2 #include "tap-interface.h"
4 #include "helprun-external-agent.h"
6 static int drop_count(struct ntdb_context *ntdb, unsigned int *count)
13 static int set_found(struct ntdb_context *ntdb, bool found[3])
17 if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach0.ntdb") == 0)
19 else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach1.ntdb") == 0)
21 else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach2.ntdb") == 0)
32 int main(int argc, char *argv[])
34 unsigned int i, count;
36 struct ntdb_context *ntdb0, *ntdb1, *ntdb;
37 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
38 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
40 plan_tests(sizeof(flags) / sizeof(flags[0]) * 8);
41 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
42 ntdb0 = ntdb_open("run-ntdb_foreach0.ntdb",
43 flags[i]|MAYBE_NOSYNC,
44 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
45 ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb",
46 flags[i]|MAYBE_NOSYNC,
47 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
48 ntdb = ntdb_open("run-ntdb_foreach2.ntdb",
49 flags[i]|MAYBE_NOSYNC,
50 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
52 memset(found, 0, sizeof(found));
53 ntdb_foreach(set_found, found);
54 ok1(found[0] && found[1] && found[2]);
56 /* Test premature iteration termination */
58 ntdb_foreach(drop_count, &count);
62 memset(found, 0, sizeof(found));
63 ntdb_foreach(set_found, found);
64 ok1(found[0] && !found[1] && found[2]);
67 memset(found, 0, sizeof(found));
68 ntdb_foreach(set_found, found);
69 ok1(found[0] && !found[1] && !found[2]);
71 ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb",
72 flags[i]|MAYBE_NOSYNC,
73 O_RDWR, 0600, &tap_log_attr);
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]);
84 memset(found, 0, sizeof(found));
85 ntdb_foreach(set_found, found);
86 ok1(!found[0] && !found[1] && !found[2]);
87 ok1(tap_log_messages == 0);