MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_json_escape

Function test_json_escape

lightningd/test/run-jsonrpc.c:165–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165static 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
200static void test_json_partial(void)
201{

Callers 1

mainFunction · 0.85

Calls 7

new_json_streamFunction · 0.85
json_out_contentsFunction · 0.85
tal_freeFunction · 0.85
json_object_startFunction · 0.70
json_escapeClass · 0.70
json_add_escaped_stringFunction · 0.70
json_object_endFunction · 0.70

Tested by

no test coverage detected