1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/open.c>
3 #include <ccan/tdb2/free.c>
4 #include <ccan/tdb2/lock.c>
5 #include <ccan/tdb2/io.c>
6 #include <ccan/tdb2/hash.c>
7 #include <ccan/tdb2/transaction.c>
8 #include <ccan/tdb2/check.c>
9 #include <ccan/tap/tap.h>
12 static int drop_count(struct tdb_context *tdb, unsigned int *count)
19 static int set_found(struct tdb_context *tdb, bool found[3])
23 if (strcmp(tdb_name(tdb), "run-tdb_foreach0.tdb") == 0)
25 else if (strcmp(tdb_name(tdb), "run-tdb_foreach1.tdb") == 0)
27 else if (strcmp(tdb_name(tdb), "run-tdb_foreach2.tdb") == 0)
38 int main(int argc, char *argv[])
40 unsigned int i, count;
42 struct tdb_context *tdb0, *tdb1, *tdb2;
43 int flags[] = { TDB_DEFAULT, TDB_NOMMAP,
44 TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT };
46 plan_tests(sizeof(flags) / sizeof(flags[0]) * 8);
47 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
48 tdb0 = tdb_open("run-tdb_foreach0.tdb", flags[i],
49 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
50 tdb1 = tdb_open("run-tdb_foreach1.tdb", flags[i],
51 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
52 tdb2 = tdb_open("run-tdb_foreach2.tdb", flags[i],
53 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
55 memset(found, 0, sizeof(found));
56 tdb_foreach(set_found, found);
57 ok1(found[0] && found[1] && found[2]);
59 /* Test premature iteration termination */
61 tdb_foreach(drop_count, &count);
65 memset(found, 0, sizeof(found));
66 tdb_foreach(set_found, found);
67 ok1(found[0] && !found[1] && found[2]);
70 memset(found, 0, sizeof(found));
71 tdb_foreach(set_found, found);
72 ok1(found[0] && !found[1] && !found[2]);
74 tdb1 = tdb_open("run-tdb_foreach1.tdb", flags[i],
75 O_RDWR, 0600, &tap_log_attr);
76 memset(found, 0, sizeof(found));
77 tdb_foreach(set_found, found);
78 ok1(found[0] && found[1] && !found[2]);
81 memset(found, 0, sizeof(found));
82 tdb_foreach(set_found, found);
83 ok1(!found[0] && found[1] && !found[2]);
86 memset(found, 0, sizeof(found));
87 tdb_foreach(set_found, found);
88 ok1(!found[0] && !found[1] && !found[2]);
89 ok1(tap_log_messages == 0);