tdb2: unify tdb1_traverse into tdb_traverse
[ccan] / ccan / tdb2 / test / run-tdb1-traverse-in-transaction.c
index 4d3a81f19ea3cf424fc52bf8e4de9a8081d19b1b..c4fd89dfe4b79b44996063d5dfb6b7d7ec794fcc 100644 (file)
@@ -8,7 +8,7 @@
 #include <stdbool.h>
 #include <err.h>
 #include "tdb1-external-agent.h"
-#include "tdb1-logging.h"
+#include "logging.h"
 
 static struct agent *agent;
 
@@ -24,7 +24,7 @@ static bool correct_data(TDB_DATA data)
                && memcmp(data.dptr, "world", data.dsize) == 0;
 }
 
-static int traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
+static int traverse(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data,
                     void *p)
 {
        ok1(correct_key(key));
@@ -34,17 +34,22 @@ static int traverse(struct tdb1_context *tdb, TDB_DATA key, TDB_DATA data,
 
 int main(int argc, char *argv[])
 {
-       struct tdb1_context *tdb;
+       struct tdb_context *tdb;
        TDB_DATA key, data;
+       union tdb_attribute hsize;
+
+       hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
+       hsize.base.next = &tap_log_attr;
+       hsize.tdb1_hashsize.hsize = 1024;
 
        plan_tests(13);
        agent = prepare_external_agent1();
        if (!agent)
                err(1, "preparing agent");
 
-       tdb = tdb1_open_ex("run-traverse-in-transaction.tdb",
-                         1024, TDB1_CLEAR_IF_FIRST, O_CREAT|O_TRUNC|O_RDWR,
-                         0600, &taplogctx, NULL);
+       tdb = tdb_open("run-traverse-in-transaction.tdb1",
+                      TDB_VERSION1, O_CREAT|O_TRUNC|O_RDWR,
+                      0600, &hsize);
        ok1(tdb);
 
        key.dsize = strlen("hi");
@@ -52,19 +57,19 @@ int main(int argc, char *argv[])
        data.dptr = (void *)"world";
        data.dsize = strlen("world");
 
-       ok1(tdb1_store(tdb, key, data, TDB_INSERT) == 0);
+       ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
 
        ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
 
        ok1(tdb1_transaction_start(tdb) == 0);
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
-       tdb1_traverse(tdb, traverse, NULL);
+       tdb_traverse(tdb, traverse, NULL);
 
        /* That should *not* release the transaction lock! */
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
-       tdb1_traverse_read(tdb, traverse, NULL);
+       tdb_traverse(tdb, traverse, NULL);
 
        /* That should *not* release the transaction lock! */
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
@@ -74,7 +79,7 @@ int main(int argc, char *argv[])
        ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == SUCCESS);
 
-       tdb1_close(tdb);
+       tdb_close(tdb);
 
        return exit_status();
 }