Rusty Russell
7 years ago
committed by
Christian Decker
3 changed files with 49 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||
#include "../json.c" |
|||
#include <stdio.h> |
|||
|
|||
/* AUTOGENERATED MOCKS START */ |
|||
/* AUTOGENERATED MOCKS END */ |
|||
|
|||
int main(void) |
|||
{ |
|||
struct json_result *result = new_json_result(NULL); |
|||
jsmntok_t *toks; |
|||
const jsmntok_t *x; |
|||
bool valid; |
|||
int i; |
|||
char *badstr = tal_arr(result, char, 256); |
|||
const char *str; |
|||
|
|||
/* Fill with junk, and nul-terminate (256 -> 0) */ |
|||
for (i = 1; i < 257; i++) |
|||
badstr[i-1] = i; |
|||
|
|||
json_object_start(result, NULL); |
|||
json_add_string(result, "x", badstr); |
|||
json_object_end(result); |
|||
|
|||
/* Parse back in, make sure nothing crazy. */ |
|||
str = json_result_string(result); |
|||
|
|||
toks = json_parse_input(str, strlen(str), &valid); |
|||
assert(valid); |
|||
assert(toks); |
|||
|
|||
assert(toks[0].type == JSMN_OBJECT); |
|||
x = json_get_member(str, toks, "x"); |
|||
assert(x); |
|||
assert(x->type == JSMN_STRING); |
|||
assert((x->end - x->start) == 255); |
|||
for (i = x->start; i < x->end; i++) { |
|||
assert(cisprint(str[i])); |
|||
assert(str[i] != '\\'); |
|||
assert(str[i] != '"'); |
|||
assert(str[i] == '?' || str[i] == badstr[i - x->start]); |
|||
} |
|||
tal_free(result); |
|||
return 0; |
|||
} |
Loading…
Reference in new issue