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));
22 ok1(!strmap_get(&map, none));
23 ok1(!strmap_del(&map, str, NULL));
24 ok1(!strmap_del(&map, none, NULL));
26 ok1(strmap_add(&map, str, val));
27 ok1(strmap_get(&map, str) == val);
28 /* We compare the string, not the pointer. */
29 ok1(strmap_get(&map, dup) == val);
30 ok1(!strmap_get(&map, none));
32 /* Add a duplicate should fail. */
33 ok1(!strmap_add(&map, dup, val));
35 ok1(strmap_get(&map, dup) == val);
37 /* Delete should return original string. */
38 ok1(strmap_del(&map, dup, &v) == str);
40 ok1(!strmap_get(&map, str));
41 ok1(!strmap_get(&map, none));
43 /* Try insert and delete of empty string. */
44 ok1(strmap_add(&map, none, none));
45 ok1(strmap_get(&map, none) == none);
46 ok1(!strmap_get(&map, str));
48 /* Delete should return original string. */
49 ok1(strmap_del(&map, "", &v) == none);
51 ok1(!strmap_get(&map, str));
52 ok1(!strmap_get(&map, none));
55 ok1(strmap_add(&map, none, none));
56 ok1(strmap_add(&map, str, val));
57 ok1(strmap_get(&map, str) == val);
58 ok1(strmap_get(&map, none) == none);
59 ok1(strmap_del(&map, "does not exist", NULL) == NULL);
60 ok1(strmap_del(&map, "", NULL) == none);
61 ok1(strmap_get(&map, str) == val);
62 ok1(strmap_del(&map, dup, &v) == str);
65 ok1(strmap_empty(&map));
68 /* This exits depending on whether all tests passed */