summaryrefslogtreecommitdiff
path: root/lib/ntdb/test/run-tdb_foreach.c
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2012-06-18 22:30:26 +0930
committerRusty Russell <rusty@rustcorp.com.au>2012-06-19 05:38:06 +0200
commit16cc345d4f84367e70e133200f7aa335c2aae8c6 (patch)
tree955a33c25c19f3127e24ba6b0e108da6b1f7f804 /lib/ntdb/test/run-tdb_foreach.c
parent76758b9767fad45ff144bbfef3ab84bca5d4650e (diff)
downloadsamba-16cc345d4f84367e70e133200f7aa335c2aae8c6.tar.gz
samba-16cc345d4f84367e70e133200f7aa335c2aae8c6.tar.bz2
samba-16cc345d4f84367e70e133200f7aa335c2aae8c6.zip
TDB2: Goodbye TDB2, Hello NTDB.
This renames everything from tdb2 to ntdb: importantly, we no longer use the tdb_ namespace, so you can link against both ntdb and tdb if you want to. This also enables building of standalone ntdb by the autobuild script. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ntdb/test/run-tdb_foreach.c')
-rw-r--r--lib/ntdb/test/run-tdb_foreach.c86
1 files changed, 86 insertions, 0 deletions
diff --git a/lib/ntdb/test/run-tdb_foreach.c b/lib/ntdb/test/run-tdb_foreach.c
new file mode 100644
index 0000000000..f1a2d00919
--- /dev/null
+++ b/lib/ntdb/test/run-tdb_foreach.c
@@ -0,0 +1,86 @@
+#include "ntdb-source.h"
+#include "tap-interface.h"
+#include "logging.h"
+
+static int drop_count(struct ntdb_context *ntdb, unsigned int *count)
+{
+ if (--(*count) == 0)
+ return 1;
+ return 0;
+}
+
+static int set_found(struct ntdb_context *ntdb, bool found[3])
+{
+ unsigned int idx;
+
+ if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach0.ntdb") == 0)
+ idx = 0;
+ else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach1.ntdb") == 0)
+ idx = 1;
+ else if (strcmp(ntdb_name(ntdb), "run-ntdb_foreach2.ntdb") == 0)
+ idx = 2;
+ else
+ abort();
+
+ if (found[idx])
+ abort();
+ found[idx] = true;
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ unsigned int i, count;
+ bool found[3];
+ struct ntdb_context *ntdb0, *ntdb1, *ntdb;
+ int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
+ NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
+
+ plan_tests(sizeof(flags) / sizeof(flags[0]) * 8);
+ for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
+ ntdb0 = ntdb_open("run-ntdb_foreach0.ntdb", flags[i],
+ O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
+ ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb", flags[i],
+ O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
+ ntdb = ntdb_open("run-ntdb_foreach2.ntdb", flags[i],
+ O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
+
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(found[0] && found[1] && found[2]);
+
+ /* Test premature iteration termination */
+ count = 1;
+ ntdb_foreach(drop_count, &count);
+ ok1(count == 0);
+
+ ntdb_close(ntdb1);
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(found[0] && !found[1] && found[2]);
+
+ ntdb_close(ntdb);
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(found[0] && !found[1] && !found[2]);
+
+ ntdb1 = ntdb_open("run-ntdb_foreach1.ntdb", flags[i],
+ O_RDWR, 0600, &tap_log_attr);
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(found[0] && found[1] && !found[2]);
+
+ ntdb_close(ntdb0);
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(!found[0] && found[1] && !found[2]);
+
+ ntdb_close(ntdb1);
+ memset(found, 0, sizeof(found));
+ ntdb_foreach(set_found, found);
+ ok1(!found[0] && !found[1] && !found[2]);
+ ok1(tap_log_messages == 0);
+ }
+
+ return exit_status();
+}