[RFC,4/6] test/telemetry_json: add test for string character escaping
Checks
Commit Message
Add unit test to validate that when creating a string response in json,
that characters such as \n or quotes are properly escaped.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
app/test/test_telemetry_json.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
@@ -125,6 +125,22 @@ test_large_obj_element(void)
return strncmp(expected, buf, sizeof(buf));
}
+static int
+test_string_char_escaping(void)
+{
+ static const char str[] = "A string across\ntwo lines and \"with quotes\"!";
+ const char *expected = "\"A string across\\ntwo lines and \\\"with quotes\\\"!\"";
+ char buf[sizeof(str) + 10];
+ int used = 0;
+
+ used = rte_tel_json_str(buf, sizeof(buf), used, str);
+ printf("%s: buf = '%s', expected = '%s'\n", __func__, buf, expected);
+ if (used != (int)strlen(expected))
+ return -1;
+
+ return strncmp(expected, buf, sizeof(buf));
+}
+
typedef int (*test_fn)(void);
static int
@@ -138,6 +154,7 @@ test_telemetry_json(void)
test_overflow_obj,
test_large_array_element,
test_large_obj_element,
+ test_string_char_escaping,
};
for (i = 0; i < RTE_DIM(fns); i++)
if (fns[i]() == 0)