librlp

C library for the Recursive Length Prefix (RLP) serialization format
git clone git://git.defalsify.org/librlp.git
Log | Files | Refs | LICENSE

commit 23d3f33a813bb905909412bb16276450e554a4f1
parent 68af64b2767413d8fef74f3af7f210ee62ae450b
Author: nolash <dev@holbrook.no>
Date:   Tue, 13 Apr 2021 05:59:34 +0200

Add test for trailing zeros

Diffstat:
Dsrc/decode.h | 0
Dsrc/encode.h | 0
Mtests/check_decoder.c | 26++++++++++++++++++++++++++
3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/decode.h b/src/decode.h diff --git a/src/encode.h b/src/encode.h diff --git a/tests/check_decoder.c b/tests/check_decoder.c @@ -54,6 +54,31 @@ START_TEST(rlp_decode_short_string_test) { END_TEST +START_TEST(rlp_decode_string_trailing_zeros_test) { + int r; + char s[5] = {0x84, 0x66, 0x6f, 0x6f, 0x00}; + char target[] = "foo\0"; + + int l; + char buf[1024]; + char *zbuf = (char*)buf; + + char state = RLP_STRING; + + rlp_encoder_t encoder; + + rlp_init(&encoder, 5, s); + r = rlp_next(&encoder, &l, &zbuf); + ck_assert_mem_eq(&encoder.state, &state, 1); + ck_assert_int_eq(r, 0); + ck_assert_int_eq(l, 4); + ck_assert_mem_eq(zbuf, target, l); + + rlp_free(&encoder); + +} +END_TEST + START_TEST(rlp_decode_long_string_test) { int l; int r; @@ -195,6 +220,7 @@ Suite *rlp_decode_suite(void) { tcase_add_test(tcb, rlp_decode_single_test); tcase_add_test(tcb, rlp_decode_short_string_test); + tcase_add_test(tcb, rlp_decode_string_trailing_zeros_test); tcase_add_test(tcb, rlp_decode_long_string_test); suite_add_tcase(s, tcb);