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

Function main

common/test/run-bolt12_decode.c:150–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148/* AUTOGENERATED MOCKS END */
149
150int main(int argc, char *argv[])
151{
152 char *json;
153 size_t i;
154 jsmn_parser parser;
155 jsmntok_t toks[5000];
156 const jsmntok_t *t;
157
158 common_setup(argv[0]);
159
160 if (argv[1])
161 json = grab_file(tmpctx, argv[1]);
162 else {
163 char *dir = getenv("BOLTDIR");
164 json = grab_file(tmpctx,
165 path_join(tmpctx,
166 dir ? dir : "../bolts",
167 "bolt12/format-string-test.json"));
168 if (!json) {
169 printf("test file not found, skipping\n");
170 goto out;
171 }
172 }
173
174 jsmn_init(&parser);
175 if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0)
176 abort();
177
178 json_for_each_arr(i, t, toks) {
179 bool valid, actual;
180 const jsmntok_t *strtok;
181 char *fail;
182 const char *str;
183 size_t dlen;
184 struct json_escape *esc;
185
186 json_to_bool(json, json_get_member(json, t, "valid"), &valid);
187 strtok = json_get_member(json, t, "string");
188 esc = json_escape_string_(tmpctx, json + strtok->start,
189 strtok->end - strtok->start);
190 str = json_escape_unescape(tmpctx, esc);
191 actual = (string_to_data(tmpctx, str, strlen(str),
192 "lno", &dlen, &fail) != NULL);
193 assert(actual == valid);
194 }
195out:
196 common_shutdown();
197 return 0;
198}

Callers

nothing calls this directly

Calls 10

common_setupFunction · 0.85
grab_fileFunction · 0.85
path_joinFunction · 0.85
abortFunction · 0.85
json_escape_string_Function · 0.85
json_escape_unescapeFunction · 0.85
string_to_dataFunction · 0.85
common_shutdownFunction · 0.85
json_get_memberFunction · 0.70
json_to_boolFunction · 0.50

Tested by

no test coverage detected