]> git.ozlabs.org Git - ccan/blobdiff - ccan/strmap/test/run.c
hex: Simplify hex_encode
[ccan] / ccan / strmap / test / run.c
index 349ef4f7176c040511defc65cfe87fa45e360728..f64ddc5e57918b3dc12ba5fca849733df7d59eec 100644 (file)
@@ -4,9 +4,7 @@
 
 int main(void)
 {
-       struct strmap_charp {
-               STRMAP_MEMBERS(char *);
-       } map;
+       STRMAP(char *) map;
        const char str[] = "hello";
        const char val[] = "there";
        const char none[] = "";
@@ -14,41 +12,52 @@ int main(void)
        char *v;
 
        /* This is how many tests you plan to run */
-       plan_tests(31);
+       plan_tests(42);
 
        strmap_init(&map);
 
        ok1(!strmap_get(&map, str));
+       ok1(errno == ENOENT);
        ok1(!strmap_get(&map, none));
+       ok1(errno == ENOENT);
        ok1(!strmap_del(&map, str, NULL));
+       ok1(errno == ENOENT);
        ok1(!strmap_del(&map, none, NULL));
+       ok1(errno == ENOENT);
 
        ok1(strmap_add(&map, str, val));
        ok1(strmap_get(&map, str) == val);
        /* We compare the string, not the pointer. */
        ok1(strmap_get(&map, dup) == val);
        ok1(!strmap_get(&map, none));
+       ok1(errno == ENOENT);
 
        /* Add a duplicate should fail. */
        ok1(!strmap_add(&map, dup, val));
+       ok1(errno == EEXIST);
        ok1(strmap_get(&map, dup) == val);
 
        /* Delete should return original string. */
        ok1(strmap_del(&map, dup, &v) == str);
        ok1(v == val);
        ok1(!strmap_get(&map, str));
+       ok1(errno == ENOENT);
        ok1(!strmap_get(&map, none));
+       ok1(errno == ENOENT);
 
        /* Try insert and delete of empty string. */
        ok1(strmap_add(&map, none, none));
        ok1(strmap_get(&map, none) == none);
        ok1(!strmap_get(&map, str));
+       ok1(errno == ENOENT);
 
        /* Delete should return original string. */
        ok1(strmap_del(&map, "", &v) == none);
        ok1(v == none);
        ok1(!strmap_get(&map, str));
+       ok1(errno == ENOENT);
        ok1(!strmap_get(&map, none));
+       ok1(errno == ENOENT);
 
        /* Both at once... */
        ok1(strmap_add(&map, none, none));