diff options
author | David Lamparter <equinox@diac24.net> | 2021-03-22 10:12:42 +0100 |
---|---|---|
committer | David Lamparter <equinox@diac24.net> | 2021-03-30 22:34:56 +0200 |
commit | 7798203f5cf93b35aed96925f3ffd6fa00a44790 (patch) | |
tree | 11649e2d2d210eef677ac6a07065b805278cd636 /tests/lib/test_printfrr.c | |
parent | lib: add `%*pHX` + `%*pHS` hexdump in printfrr (diff) | |
download | frr-7798203f5cf93b35aed96925f3ffd6fa00a44790.tar.xz frr-7798203f5cf93b35aed96925f3ffd6fa00a44790.zip |
lib: add `%pSQ` and `%pSE` string escape formats
These are for string quoting (`%pSQ`) and string escaping (`%pSE`); the
sets / escape methods are currently rather "basic" and might be extended
in the future.
Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to '')
-rw-r--r-- | tests/lib/test_printfrr.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/tests/lib/test_printfrr.c b/tests/lib/test_printfrr.c index 1ef10b19d..21b3a916b 100644 --- a/tests/lib/test_printfrr.c +++ b/tests/lib/test_printfrr.c @@ -218,13 +218,40 @@ int main(int argc, char **argv) uint8_t randhex[] = { 0x12, 0x34, 0x00, 0xca, 0xfe, 0x00, 0xaa, 0x55 }; - printchk("12 34 00 ca fe 00 aa 55", "%.8pHX", randhex); - printchk("12 34 00 ca fe 00 aa 55", "%.*pHX", + FMT_NSTD(printchk("12 34 00 ca fe 00 aa 55", "%.8pHX", randhex)); + FMT_NSTD(printchk("12 34 00 ca fe 00 aa 55", "%.*pHX", + (int)sizeof(randhex), randhex)); + FMT_NSTD(printchk("12 34 00 ca", "%.4pHX", randhex)); + + printchk("12 34 00 ca fe 00 aa 55", "%8pHX", randhex); + printchk("12 34 00 ca fe 00 aa 55", "%*pHX", (int)sizeof(randhex), randhex); - printchk("12 34 00 ca", "%.4pHX", randhex); + printchk("12 34 00 ca", "%4pHX", randhex); + + printchk("", "%pHX", randhex); + + printchk("12:34:00:ca:fe:00:aa:55", "%8pHXc", randhex); + printchk("123400cafe00aa55", "%8pHXn", randhex); + + printchk("/test/pa\\ th/\\~spe\\ncial\\x01/file.name", "%pSE", + "/test/pa th/~spe\ncial\x01/file.name"); + printchk("/test/pa\\ th/\\~spe\\n", "%17pSE", + "/test/pa th/~spe\ncial\x01/file.name"); + + char nulltest[] = { 'n', 'u', 0, 'l', 'l' }; + + printchk("nu\\x00ll", "%5pSE", nulltest); + printchk("nu\\x00ll", "%*pSE", 5, nulltest); - printchk("12:34:00:ca:fe:00:aa:55", "%.8pHXc", randhex); - printchk("123400cafe00aa55", "%.8pHXn", randhex); + printchk("bl\\\"ah\\x01te[st\\nab]c", "%pSQ", + "bl\"ah\x01te[st\nab]c"); + printchk("\"bl\\\"ah\\x01te[st\\nab]c\"", "%pSQq", + "bl\"ah\x01te[st\nab]c"); + printchk("\"bl\\\"ah\\x01te[st\\x0aab\\]c\"", "%pSQqs", + "bl\"ah\x01te[st\nab]c"); + printchk("\"\"", "%pSQqn", ""); + printchk("\"\"", "%pSQqn", (char *)NULL); + printchk("(null)", "%pSQq", (char *)NULL); return !!errors; } |