test/telemetry_json: add test for string character escaping
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> Acked-by: Ciara Power <ciara.power@intel.com> Acked-by: Morten Brørup <mb@smartsharesystems.com> Acked-by: Chengwen Feng <fengchengwen@huawei.com>
This commit is contained in:
parent
babc521444
commit
56069f9832
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user