1 #include <ccan/strmap/strmap.h>
2 #include <ccan/strmap/strmap.c>
3 #include <ccan/tap/tap.h>
8 const char str[] = "hello";
9 const char val[] = "there";
10 const char none[] = "";
11 char *dup = strdup(str);
14 /* This is how many tests you plan to run */
19 ok1(!strmap_get(&map, str));
21 ok1(!strmap_get(&map, none));
23 ok1(!strmap_del(&map, str, NULL));
25 ok1(!strmap_del(&map, none, NULL));
28 ok1(strmap_add(&map, str, val));
29 ok1(strmap_get(&map, str) == val);
30 /* We compare the string, not the pointer. */
31 ok1(strmap_get(&map, dup) == val);
32 ok1(!strmap_get(&map, none));
35 /* Add a duplicate should fail. */
36 ok1(!strmap_add(&map, dup, val));
38 ok1(strmap_get(&map, dup) == val);
40 /* Delete should return original string. */
41 ok1(strmap_del(&map, dup, &v) == str);
43 ok1(!strmap_get(&map, str));
45 ok1(!strmap_get(&map, none));
48 /* Try insert and delete of empty string. */
49 ok1(strmap_add(&map, none, none));
50 ok1(strmap_get(&map, none) == none);
51 ok1(!strmap_get(&map, str));
54 /* Delete should return original string. */
55 ok1(strmap_del(&map, "", &v) == none);
57 ok1(!strmap_get(&map, str));
59 ok1(!strmap_get(&map, none));
63 ok1(strmap_add(&map, none, none));
64 ok1(strmap_add(&map, str, val));
65 ok1(strmap_get(&map, str) == val);
66 ok1(strmap_get(&map, none) == none);
67 ok1(strmap_del(&map, "does not exist", NULL) == NULL);
68 ok1(strmap_del(&map, "", NULL) == none);
69 ok1(strmap_get(&map, str) == val);
70 ok1(strmap_del(&map, dup, &v) == str);
73 ok1(strmap_empty(&map));
76 /* This exits depending on whether all tests passed */