| 161 | /* AUTOGENERATED MOCKS END */ |
| 162 | |
| 163 | int main(int argc, char *argv[]) |
| 164 | { |
| 165 | char *json; |
| 166 | size_t i; |
| 167 | jsmn_parser parser; |
| 168 | jsmntok_t toks[5000]; |
| 169 | const jsmntok_t *t; |
| 170 | |
| 171 | common_setup(argv[0]); |
| 172 | |
| 173 | if (argv[1]) |
| 174 | json = grab_file_str(tmpctx, argv[1]); |
| 175 | else { |
| 176 | char *dir = getenv("BOLTDIR"); |
| 177 | json = grab_file_str(tmpctx, |
| 178 | path_join(tmpctx, |
| 179 | dir ? dir : ".tmp.lightningrfc", |
| 180 | "bolt12/format-string-test.json")); |
| 181 | if (!json) { |
| 182 | printf("test file not found, skipping\n"); |
| 183 | goto out; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | jsmn_init(&parser); |
| 188 | if (jsmn_parse(&parser, json, strlen(json), toks, ARRAY_SIZE(toks)) < 0) |
| 189 | abort(); |
| 190 | |
| 191 | json_for_each_arr(i, t, toks) { |
| 192 | bool valid, actual; |
| 193 | const jsmntok_t *strtok; |
| 194 | const char *fail; |
| 195 | const char *str; |
| 196 | size_t dlen; |
| 197 | |
| 198 | assert(json_to_bool(json, json_get_member(json, t, "valid"), &valid)); |
| 199 | strtok = json_get_member(json, t, "string"); |
| 200 | str = json_escape_unescape_len(tmpctx, json + strtok->start, |
| 201 | strtok->end - strtok->start); |
| 202 | actual = (b12_string_to_data(tmpctx, str, strlen(str), |
| 203 | "lno", &dlen, &fail) != NULL); |
| 204 | assert(actual == valid); |
| 205 | printf("%s %s\n", str, valid ? "OK": "INVALID"); |
| 206 | } |
| 207 | out: |
| 208 | common_shutdown(); |
| 209 | return 0; |
| 210 | } |
nothing calls this directly
no test coverage detected