X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Finvbloom%2Ftest%2Frun-subtract.c;fp=ccan%2Finvbloom%2Ftest%2Frun-subtract.c;h=ae47642322d3d78646c67f405c20855a3abfe19b;hb=49bb40e9615ada5a3e0d06bc45613744f441895c;hp=0000000000000000000000000000000000000000;hpb=5d34cc6b30b457ceb821bd8e4b352fd029e7dab0;p=ccan diff --git a/ccan/invbloom/test/run-subtract.c b/ccan/invbloom/test/run-subtract.c new file mode 100644 index 00000000..ae476423 --- /dev/null +++ b/ccan/invbloom/test/run-subtract.c @@ -0,0 +1,42 @@ +#include +/* Include the C files directly. */ +#include +#include + +int main(void) +{ + struct invbloom *ib1, *ib2; + const tal_t *ctx = tal(NULL, char); + int val = 1, val2 = 2, *ip; + + /* This is how many tests you plan to run */ + plan_tests(8); + + ib1 = invbloom_new(ctx, int, 1024, 0); + ib2 = invbloom_new(ctx, int, 1024, 0); + invbloom_insert(ib1, &val); + invbloom_insert(ib2, &val2); + + invbloom_subtract(ib1, ib2); + + ip = invbloom_extract(ctx, ib1); + ok1(ip); + ok1(tal_parent(ip) == ctx); + ok1(*ip == val); + + ip = invbloom_extract(ctx, ib1); + ok1(!ip); + + ip = invbloom_extract_negative(ctx, ib1); + ok1(ip); + ok1(tal_parent(ip) == ctx); + ok1(*ip == val2); + + ip = invbloom_extract_negative(ctx, ib1); + ok1(!ip); + + tal_free(ctx); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}