librlp

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

commit 1613fdd9b3310a4ca34e6458482d44022e41483a
parent cd41ebe0bad9bb973497f74b53e874d9e305f784
Author: nolash <dev@holbrook.no>
Date:   Sun, 11 Apr 2021 12:39:13 +0200

Add long string test

Diffstat:
Mtests/check_vectors.c | 21++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/tests/check_vectors.c b/tests/check_vectors.c @@ -41,7 +41,6 @@ START_TEST(rlp_catdog_test) { char buf[1024]; char *zbuf = (char*)&buf; int l; - char state; char *x_dog = "dog"; @@ -83,16 +82,32 @@ END_TEST START_TEST(rlp_lorem_test) { rlp_encoder_t encoder; - rlp_init(&encoder, 1024, NULL); + char buf[1024]; + char *zbuf = (char*)&buf; + int l; + char state; char *lorem = "Lorem ipsum dolor sit amet, consectetur adipisicing elit"; char target[2] = {0xb8, 0x38}; + rlp_init(&encoder, 1024, NULL); rlp_add(&encoder, strlen(lorem), lorem); ck_assert_mem_eq(encoder.buf, target, 2); ck_assert_mem_eq(encoder.buf+2, lorem, strlen(lorem)); ck_assert_int_eq(encoder.size, 2 + strlen(lorem)); + // reuse for decode + state = RLP_STRING; + rlp_init(&encoder, 1024, encoder.buf); + rlp_next(&encoder, &l, &zbuf); + ck_assert_mem_eq(&encoder.state, &state, 1); + ck_assert_int_eq(l, 0x38); + ck_assert_mem_eq(zbuf, lorem, l); + + state = RLP_END; + rlp_next(&encoder, &l, &zbuf); + ck_assert_mem_eq(&encoder.state, &state, 1); + rlp_free(&encoder); } END_TEST @@ -143,7 +158,7 @@ Suite *rlp_vector_suite(void) { tcb = tcase_create("basic"); // examples from https://eth.wiki/fundamentals/rlp tcase_add_test(tcb, rlp_dog_test); tcase_add_test(tcb, rlp_catdog_test); - //tcase_add_test(tcb, rlp_lorem_test); + tcase_add_test(tcb, rlp_lorem_test); //tcase_add_test(tcb, rlp_set_theoretical_representation_of_three); suite_add_tcase(s, tcb);