| 163 | } |
| 164 | |
| 165 | static void test_json_escape(void) |
| 166 | { |
| 167 | int i; |
| 168 | |
| 169 | for (i = 1; i < 256; i++) { |
| 170 | char badstr[2]; |
| 171 | struct json_stream *result = new_json_stream(NULL, NULL, NULL); |
| 172 | struct json_escape *esc; |
| 173 | |
| 174 | badstr[0] = i; |
| 175 | badstr[1] = 0; |
| 176 | |
| 177 | json_object_start(result, NULL); |
| 178 | esc = json_escape(NULL, badstr); |
| 179 | json_add_escaped_string(result, "x", take(esc)); |
| 180 | json_object_end(result); |
| 181 | |
| 182 | size_t len; |
| 183 | const char *str = json_out_contents(result->jout, &len); |
| 184 | str = tal_strndup(result, str, len); |
| 185 | if (i == '\\' || i == '"' |
| 186 | || i == '\n' || i == '\r' || i == '\b' |
| 187 | || i == '\t' || i == '\f') |
| 188 | assert(strstarts(str, "{\"x\":\"\\")); |
| 189 | else if (i < 32 || i == 127) { |
| 190 | assert(strstarts(str, "{\"x\":\"\\u00")); |
| 191 | } else { |
| 192 | char expect[] = "{\"x\":\"?\"}"; |
| 193 | expect[6] = i; |
| 194 | assert(streq(str, expect)); |
| 195 | } |
| 196 | tal_free(result); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | static void test_json_partial(void) |
| 201 | { |
no test coverage detected