X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-15-append.c;h=9e82a9230568d4fe6a5e23d3546022df5aff38e2;hb=a391b2b900bc6d5c0467869a454bdb5c51b5a3be;hp=36b6162fbd0802e783c6611be8fdaf081ee90661;hpb=c02f63e60ca4c9778a1e635ffcd07d17fc8bf09d;p=ccan diff --git a/ccan/tdb2/test/run-15-append.c b/ccan/tdb2/test/run-15-append.c index 36b6162f..9e82a923 100644 --- a/ccan/tdb2/test/run-15-append.c +++ b/ccan/tdb2/test/run-15-append.c @@ -1,10 +1,4 @@ -#include -#include -#include -#include -#include -#include -#include +#include "tdb2-source.h" #include #include #include "logging.h" @@ -34,7 +28,7 @@ int main(int argc, char *argv[]) int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; - struct tdb_data key = { (unsigned char *)"key", 3 }; + struct tdb_data key = tdb_mkdata("key", 3); struct tdb_data data; buffer = malloc(MAX_SIZE); @@ -42,7 +36,7 @@ int main(int argc, char *argv[]) buffer[i] = i; plan_tests(sizeof(flags) / sizeof(flags[0]) - * ((3 + MAX_SIZE/SIZE_STEP * 4) * 2 + 6) + * ((3 + MAX_SIZE/SIZE_STEP * 5) * 2 + 7) + 1); /* Using tdb_store. */ @@ -59,7 +53,7 @@ int main(int argc, char *argv[]) data.dsize = j; ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == j); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); @@ -68,7 +62,8 @@ int main(int argc, char *argv[]) moves++; oldoff = newoff; } - ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); /* We should increase by 50% each time... */ ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); @@ -89,7 +84,7 @@ int main(int argc, char *argv[]) data.dsize = j - prev_len; ok1(tdb_append(tdb, key, data) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == j); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); @@ -99,7 +94,8 @@ int main(int argc, char *argv[]) moves++; oldoff = newoff; } - ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); /* We should increase by 50% each time... */ ok(moves <= ilog64(j / SIZE_STEP)*2, "Moved %u times", moves); tdb_close(tdb); @@ -117,11 +113,12 @@ int main(int argc, char *argv[]) data.dsize = MAX_SIZE; ok1(tdb_append(tdb, key, data) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); - data = tdb_fetch(tdb, key); + ok1(tdb_fetch(tdb, key, &data) == TDB_SUCCESS); ok1(data.dsize == MAX_SIZE); ok1(memcmp(data.dptr, buffer, data.dsize) == 0); free(data.dptr); - ok1(tdb->allrecord_lock.count == 0 && tdb->num_lockrecs == 0); + ok1(!tdb->file || (tdb->file->allrecord_lock.count == 0 + && tdb->file->num_lockrecs == 0)); tdb_close(tdb); }