X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fintmap%2Ftest%2Frun.c;fp=ccan%2Fintmap%2Ftest%2Frun.c;h=41efc442d88aaade56eb3996bc8a85ea60fe9235;hb=d9e93014a999102aa1cc9979e041cd58e6aca724;hp=0000000000000000000000000000000000000000;hpb=3f642347378afc9e1db1768d88c9f5b2baffe9ba;p=ccan diff --git a/ccan/intmap/test/run.c b/ccan/intmap/test/run.c new file mode 100644 index 00000000..41efc442 --- /dev/null +++ b/ccan/intmap/test/run.c @@ -0,0 +1,55 @@ +#include +#include +#include + +int main(void) +{ + UINTMAP(char *) map; + const char val[] = "there"; + const char none[] = ""; + + /* This is how many tests you plan to run */ + plan_tests(28); + + uintmap_init(&map); + + ok1(!uintmap_get(&map, 1)); + ok1(errno == ENOENT); + ok1(!uintmap_get(&map, 0)); + ok1(errno == ENOENT); + ok1(!uintmap_del(&map, 1)); + ok1(errno == ENOENT); + ok1(!uintmap_del(&map, 0)); + ok1(errno == ENOENT); + + ok1(uintmap_add(&map, 1, val)); + ok1(uintmap_get(&map, 1) == val); + ok1(!uintmap_get(&map, 0)); + ok1(errno == ENOENT); + + /* Add a duplicate should fail. */ + ok1(!uintmap_add(&map, 1, val)); + ok1(errno == EEXIST); + + /* Delete should succeed. */ + ok1(uintmap_del(&map, 1) == val); + ok1(!uintmap_get(&map, 1)); + ok1(errno == ENOENT); + ok1(!uintmap_get(&map, 0)); + ok1(errno == ENOENT); + + /* Both at once... */ + ok1(uintmap_add(&map, 0, none)); + ok1(uintmap_add(&map, 1, val)); + ok1(uintmap_get(&map, 1) == val); + ok1(uintmap_get(&map, 0) == none); + ok1(!uintmap_del(&map, 2)); + ok1(uintmap_del(&map, 0) == none); + ok1(uintmap_get(&map, 1) == val); + ok1(uintmap_del(&map, 1) == val); + + ok1(uintmap_empty(&map)); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}