]> git.ozlabs.org Git - ccan/blobdiff - ccan/tdb2/test/run-03-coalesce.c
tdb2: feature support.
[ccan] / ccan / tdb2 / test / run-03-coalesce.c
index a382ae08ddcb9b10a053201ee08f68d119e9bcfd..7325a4498c81e5d8c1b1497f8cc64c8b770e7b7b 100644 (file)
 static tdb_len_t free_record_length(struct tdb_context *tdb, tdb_off_t off)
 {
        struct tdb_free_record f;
+       enum TDB_ERROR ecode;
 
-       if (tdb_read_convert(tdb, off, &f, sizeof(f)) != 0)
-               return TDB_OFF_ERR;
+       ecode = tdb_read_convert(tdb, off, &f, sizeof(f));
+       if (ecode != TDB_SUCCESS)
+               return ecode;
        if (frec_magic(&f) != TDB_FREE_MAGIC)
-               return TDB_OFF_ERR;
+               return TDB_ERR_CORRUPT;
        return frec_len(&f);
 }
 
@@ -54,6 +56,7 @@ int main(int argc, char *argv[])
        ok1(free_record_length(tdb, layout->elem[1].base.off) == len);
        ok1(tdb_check(tdb, NULL, NULL) == 0);
        tdb_close(tdb);
+       tdb_layout_free(layout);
 
        /* No coalescing can be done due to used record */
        layout = new_tdb_layout(NULL);
@@ -73,6 +76,7 @@ int main(int argc, char *argv[])
        ok1(free_record_length(tdb, layout->elem[1].base.off) == 1024);
        ok1(tdb_check(tdb, NULL, NULL) == 0);
        tdb_close(tdb);
+       tdb_layout_free(layout);
 
        /* Coalescing can be done due to two free records, then EOF */
        layout = new_tdb_layout(NULL);
@@ -94,6 +98,7 @@ int main(int argc, char *argv[])
            == 1024 + sizeof(struct tdb_used_record) + 2048);
        ok1(tdb_check(tdb, NULL, NULL) == 0);
        tdb_close(tdb);
+       tdb_layout_free(layout);
 
        /* Coalescing can be done due to two free records, then data */
        layout = new_tdb_layout(NULL);
@@ -116,6 +121,7 @@ int main(int argc, char *argv[])
            == 1024 + sizeof(struct tdb_used_record) + 512);
        ok1(tdb_check(tdb, NULL, NULL) == 0);
        tdb_close(tdb);
+       tdb_layout_free(layout);
 
        /* Coalescing can be done due to three free records, then EOF */
        layout = new_tdb_layout(NULL);
@@ -140,6 +146,7 @@ int main(int argc, char *argv[])
            + sizeof(struct tdb_used_record) + 256);
        ok1(tdb_check(tdb, NULL, NULL) == 0);
        tdb_close(tdb);
+       tdb_layout_free(layout);
 
        ok1(tap_log_messages == 0);
        return exit_status();