| 139 | } |
| 140 | |
| 141 | static void test_json_escape(void) |
| 142 | { |
| 143 | int i; |
| 144 | |
| 145 | for (i = 1; i < 256; i++) { |
| 146 | char badstr[2]; |
| 147 | struct json_stream *result = new_json_stream(NULL, NULL, NULL); |
| 148 | struct json_escape *esc; |
| 149 | |
| 150 | badstr[0] = i; |
| 151 | badstr[1] = 0; |
| 152 | |
| 153 | json_object_start(result, NULL); |
| 154 | esc = json_escape(NULL, badstr); |
| 155 | json_add_escaped_string(result, "x", take(esc)); |
| 156 | json_object_end(result); |
| 157 | |
| 158 | size_t len; |
| 159 | const char *str = json_out_contents(result->jout, &len); |
| 160 | str = tal_strndup(result, str, len); |
| 161 | if (i == '\\' || i == '"' |
| 162 | || i == '\n' || i == '\r' || i == '\b' |
| 163 | || i == '\t' || i == '\f') |
| 164 | assert(strstarts(str, "{\"x\":\"\\")); |
| 165 | else if (i < 32 || i == 127) { |
| 166 | assert(strstarts(str, "{\"x\":\"\\u00")); |
| 167 | } else { |
| 168 | char expect[] = "{\"x\":\"?\"}"; |
| 169 | expect[6] = i; |
| 170 | assert(streq(str, expect)); |
| 171 | } |
| 172 | tal_free(result); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | static void test_json_partial(void) |
| 177 | { |
no test coverage detected