tdb2: unify tdb1_store into tdb_store
[ccan] / ccan / tdb2 / test / run-tdb1-traverse-in-transaction.c
index eb925be20c85ed26a71b65cb348877176a8ff5e1..90783198d91be5bf62bce6d1ce809c28e002b95d 100644 (file)
@@ -8,23 +8,23 @@
 #include <stdbool.h>
 #include <err.h>
 #include "tdb1-external-agent.h"
-#include "tdb1-logging.h"
+#include "logging.h"
 
 static struct agent *agent;
 
-static bool correct_key(TDB1_DATA key)
+static bool correct_key(TDB_DATA key)
 {
        return key.dsize == strlen("hi")
                && memcmp(key.dptr, "hi", key.dsize) == 0;
 }
 
-static bool correct_data(TDB1_DATA data)
+static bool correct_data(TDB_DATA data)
 {
        return data.dsize == strlen("world")
                && memcmp(data.dptr, "world", data.dsize) == 0;
 }
 
-static int traverse(struct tdb1_context *tdb, TDB1_DATA key, TDB1_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, TDB1_DATA key, TDB1_DATA data,
 
 int main(int argc, char *argv[])
 {
-       struct tdb1_context *tdb;
-       TDB1_DATA key, data;
+       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,29 +57,29 @@ int main(int argc, char *argv[])
        data.dptr = (void *)"world";
        data.dsize = strlen("world");
 
-       ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
+       ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
 
-       ok1(external_agent_operation1(agent, OPEN, tdb1_name(tdb)) == SUCCESS);
+       ok1(external_agent_operation1(agent, OPEN, tdb->name) == SUCCESS);
 
        ok1(tdb1_transaction_start(tdb) == 0);
-       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb1_name(tdb))
+       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
        tdb1_traverse(tdb, traverse, NULL);
 
        /* That should *not* release the transaction lock! */
-       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb1_name(tdb))
+       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
        tdb1_traverse_read(tdb, traverse, NULL);
 
        /* That should *not* release the transaction lock! */
-       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb1_name(tdb))
+       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == WOULD_HAVE_BLOCKED);
        ok1(tdb1_transaction_commit(tdb) == 0);
        /* Now we should be fine. */
-       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb1_name(tdb))
+       ok1(external_agent_operation1(agent, TRANSACTION_START, tdb->name)
            == SUCCESS);
 
-       tdb1_close(tdb);
+       tdb_close(tdb);
 
        return exit_status();
 }