]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/test/run-tdb1-open-during-transaction.c
tdb2: unify tdb1_open into tdb_open
[ccan] / ccan / tdb2 / test / run-tdb1-open-during-transaction.c
index ad6c6d60747ad1fce02cd17bd0e52f5e863135e6..fd3a48086cd3ede713c8c7b10a8b371342c27974 100644 (file)
@@ -18,13 +18,12 @@ static int ftruncate_check(int fd, off_t length);
 #include <stdarg.h>
 #include <err.h>
 #include "tdb1-external-agent.h"
-#include "tdb1-logging.h"
+#include "logging.h"
 
 static struct agent *agent;
 static bool opened;
 static int errors = 0;
-static bool clear_if_first;
-#define TEST_DBNAME "run-open-during-transaction.tdb"
+#define TEST_DBNAME "run-open-during-transaction.tdb1"
 
 #undef write
 #undef pwrite
@@ -70,10 +69,7 @@ static void check_file_intact(int fd)
        }
 
        /* Ask agent to open file. */
-       ret = external_agent_operation1(agent, clear_if_first ?
-                                      OPEN_WITH_CLEAR_IF_FIRST :
-                                      OPEN,
-                                      TEST_DBNAME);
+       ret = external_agent_operation1(agent, OPEN, TEST_DBNAME);
 
        /* It's OK to open it, but it must not have changed! */
        if (!compare_file(fd, contents, st.st_size)) {
@@ -132,29 +128,31 @@ static int ftruncate_check(int fd, off_t length)
 
 int main(int argc, char *argv[])
 {
-       const int flags[] = { TDB1_DEFAULT,
-                             TDB1_CLEAR_IF_FIRST,
-                             TDB1_NOMMAP,
-                             TDB1_CLEAR_IF_FIRST | TDB1_NOMMAP };
+       const int flags[] = { TDB_DEFAULT,
+                             TDB_NOMMAP };
        int i;
-       struct tdb1_context *tdb;
+       struct tdb_context *tdb;
        TDB_DATA key, data;
+       union tdb_attribute hsize;
 
-       plan_tests(20);
+       hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
+       hsize.base.next = &tap_log_attr;
+       hsize.tdb1_hashsize.hsize = 1024;
+
+       plan_tests(10);
        agent = prepare_external_agent1();
        if (!agent)
                err(1, "preparing agent");
 
        unlock_callback1 = after_unlock;
        for (i = 0; i < sizeof(flags)/sizeof(flags[0]); i++) {
-               clear_if_first = (flags[i] & TDB1_CLEAR_IF_FIRST);
                diag("Test with %s and %s\n",
-                    clear_if_first ? "CLEAR" : "DEFAULT",
-                    (flags[i] & TDB1_NOMMAP) ? "no mmap" : "mmap");
+                    "DEFAULT",
+                    (flags[i] & TDB_NOMMAP) ? "no mmap" : "mmap");
                unlink(TEST_DBNAME);
-               tdb = tdb1_open_ex(TEST_DBNAME, 1024, flags[i],
-                                 O_CREAT|O_TRUNC|O_RDWR, 0600,
-                                 &taplogctx, NULL);
+               tdb = tdb_open(TEST_DBNAME, flags[i]|TDB_VERSION1,
+                              O_CREAT|O_TRUNC|O_RDWR, 0600,
+                              &hsize);
                ok1(tdb);
 
                opened = true;
@@ -169,7 +167,7 @@ int main(int argc, char *argv[])
                ok(!errors, "We had %u open errors", errors);
 
                opened = false;
-               tdb1_close(tdb);
+               tdb_close(tdb);
        }
 
        return exit_status();