* Make sure toks are passed through correctly, and also make sure * optional missing toks are set to NULL. */
| 250 | * optional missing toks are set to NULL. |
| 251 | */ |
| 252 | static void tok_tok(void) |
| 253 | { |
| 254 | { |
| 255 | unsigned int n; |
| 256 | const jsmntok_t *tok = NULL; |
| 257 | struct json *j = json_parse(cmd, "{ 'satoshi': '546' }"); |
| 258 | |
| 259 | assert(param(cmd, j->buffer, j->toks, |
| 260 | p_req("satoshi", param_tok, &tok), NULL)); |
| 261 | assert(tok); |
| 262 | assert(json_to_number(j->buffer, tok, &n)); |
| 263 | assert(n == 546); |
| 264 | } |
| 265 | // again with missing optional parameter |
| 266 | { |
| 267 | /* make sure it is *not* NULL */ |
| 268 | const jsmntok_t *tok = (const jsmntok_t *) 65535; |
| 269 | |
| 270 | struct json *j = json_parse(cmd, "{}"); |
| 271 | assert(param(cmd, j->buffer, j->toks, |
| 272 | p_opt("satoshi", param_tok, &tok), NULL)); |
| 273 | |
| 274 | /* make sure it *is* NULL */ |
| 275 | assert(tok == NULL); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /* check for valid but duplicate json name-value pairs */ |
| 280 | static void dup_names(void) |
no test coverage detected