MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/strset/test/run.c:5–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <ccan/tap/tap.h>
4
5int main(void)
6{
7 struct strset set;
8 const char str[] = "hello";
9 const char none[] = "";
10 char *dup = strdup(str);
11
12 /* This is how many tests you plan to run */
13 plan_tests(36);
14
15 strset_init(&set);
16
17 ok1(!strset_get(&set, str));
18 ok1(errno == ENOENT);
19 ok1(!strset_get(&set, none));
20 ok1(errno == ENOENT);
21 ok1(!strset_del(&set, str));
22 ok1(errno == ENOENT);
23 ok1(!strset_del(&set, none));
24 ok1(errno == ENOENT);
25
26 ok1(strset_add(&set, str));
27 ok1(strset_get(&set, str));
28 /* We compare the string, not the pointer. */
29 ok1(strset_get(&set, dup));
30 ok1(!strset_get(&set, none));
31 ok1(errno == ENOENT);
32
33 /* Add of duplicate should fail. */
34 ok1(!strset_add(&set, dup));
35 ok1(errno == EEXIST);
36
37 /* Delete should return original string. */
38 ok1(strset_del(&set, dup) == str);
39 ok1(!strset_get(&set, str));
40 ok1(errno == ENOENT);
41 ok1(!strset_get(&set, none));
42 ok1(errno == ENOENT);
43
44 /* Try insert and delete of empty string. */
45 ok1(strset_add(&set, none));
46 ok1(strset_get(&set, none));
47 ok1(!strset_get(&set, str));
48 ok1(errno == ENOENT);
49
50 /* Delete should return original string. */
51 ok1(strset_del(&set, "") == none);
52 ok1(!strset_get(&set, str));
53 ok1(errno == ENOENT);
54 ok1(!strset_get(&set, none));
55 ok1(errno == ENOENT);
56
57 /* Both at once... */
58 ok1(strset_add(&set, none));
59 ok1(strset_add(&set, str));
60 ok1(strset_get(&set, str));
61 ok1(strset_get(&set, none));
62 ok1(strset_del(&set, "") == none);

Callers

nothing calls this directly

Calls 4

strset_initFunction · 0.85
strset_getFunction · 0.85
strset_delFunction · 0.85
strset_addFunction · 0.85

Tested by

no test coverage detected