tdb2: unify tdb1_store into tdb_store
[ccan] / ccan / tdb2 / test / run-tdb1.c
index 30de924cd205b970e5ce4d02f0e238d0309645e8..584d7d6504f45cbba413f0e894e8c2fa53a5cbd5 100644 (file)
@@ -2,16 +2,21 @@
 #include <ccan/tap/tap.h>
 #include <stdlib.h>
 #include <err.h>
-#include "tdb1-logging.h"
+#include "logging.h"
 
 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;
 
-       plan_tests(10);
-       tdb = tdb1_open_ex("run.tdb", 1024, TDB1_CLEAR_IF_FIRST,
-                         O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
+       hsize.base.attr = TDB_ATTRIBUTE_TDB1_HASHSIZE;
+       hsize.base.next = &tap_log_attr;
+       hsize.tdb1_hashsize.hsize = 1024;
+
+       plan_tests(8);
+       tdb = tdb_open("run.tdb1", TDB_VERSION1,
+                      O_CREAT|O_TRUNC|O_RDWR, 0600, &hsize);
 
        ok1(tdb);
        key.dsize = strlen("hi");
@@ -19,12 +24,10 @@ int main(int argc, char *argv[])
        data.dsize = strlen("world");
        data.dptr = (void *)"world";
 
-       ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) < 0);
-       ok1(tdb_error(tdb) == TDB_ERR_NOEXIST);
-       ok1(tdb1_store(tdb, key, data, TDB1_INSERT) == 0);
-       ok1(tdb1_store(tdb, key, data, TDB1_INSERT) < 0);
-       ok1(tdb_error(tdb) == TDB_ERR_EXISTS);
-       ok1(tdb1_store(tdb, key, data, TDB1_MODIFY) == 0);
+       ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_ERR_NOEXIST);
+       ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_SUCCESS);
+       ok1(tdb_store(tdb, key, data, TDB_INSERT) == TDB_ERR_EXISTS);
+       ok1(tdb_store(tdb, key, data, TDB_MODIFY) == TDB_SUCCESS);
 
        data = tdb1_fetch(tdb, key);
        ok1(data.dsize == strlen("world"));
@@ -34,7 +37,7 @@ int main(int argc, char *argv[])
        key.dsize++;
        data = tdb1_fetch(tdb, key);
        ok1(data.dptr == NULL);
-       tdb1_close(tdb);
+       tdb_close(tdb);
 
        return exit_status();
 }