1 #include <ccan/strmap/strmap.h>
2 #include <ccan/strmap/strmap.c>
3 #include <ccan/tap/tap.h>
8 STRMAP_MEMBERS(char *);
10 const char str[] = "hello";
11 const char val[] = "there";
12 const char none[] = "";
13 char *dup = strdup(str);
16 /* This is how many tests you plan to run */
21 ok1(!strmap_get(&map, str));
23 ok1(!strmap_get(&map, none));
25 ok1(!strmap_del(&map, str, NULL));
27 ok1(!strmap_del(&map, none, NULL));
30 ok1(strmap_add(&map, str, val));
31 ok1(strmap_get(&map, str) == val);
32 /* We compare the string, not the pointer. */
33 ok1(strmap_get(&map, dup) == val);
34 ok1(!strmap_get(&map, none));
37 /* Add a duplicate should fail. */
38 ok1(!strmap_add(&map, dup, val));
40 ok1(strmap_get(&map, dup) == val);
42 /* Delete should return original string. */
43 ok1(strmap_del(&map, dup, &v) == str);
45 ok1(!strmap_get(&map, str));
47 ok1(!strmap_get(&map, none));
50 /* Try insert and delete of empty string. */
51 ok1(strmap_add(&map, none, none));
52 ok1(strmap_get(&map, none) == none);
53 ok1(!strmap_get(&map, str));
56 /* Delete should return original string. */
57 ok1(strmap_del(&map, "", &v) == none);
59 ok1(!strmap_get(&map, str));
61 ok1(!strmap_get(&map, none));
65 ok1(strmap_add(&map, none, none));
66 ok1(strmap_add(&map, str, val));
67 ok1(strmap_get(&map, str) == val);
68 ok1(strmap_get(&map, none) == none);
69 ok1(strmap_del(&map, "does not exist", NULL) == NULL);
70 ok1(strmap_del(&map, "", NULL) == none);
71 ok1(strmap_get(&map, str) == val);
72 ok1(strmap_del(&map, dup, &v) == str);
75 ok1(strmap_empty(&map));
78 /* This exits depending on whether all tests passed */