commit c825af3f0032fc453a1c4882abcfc215ccb1c51d
parent c46b99b3fae26f5d31f582d34b77745b2c5327cc
Author: nolash <dev@holbrook.no>
Date: Sun, 11 Apr 2021 21:57:09 +0200
Add failing test for adjacent strings
Diffstat:
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/tests/check_decoder.c b/tests/check_decoder.c
@@ -156,6 +156,34 @@ START_TEST(rlp_decode_long_list_test) {
END_TEST
+START_TEST(rlp_decode_adjacent_strings_test) {
+ int l;
+ int r;
+
+ char s[] = {0x83, 0x66, 0x6f, 0x6f, 0x84, 0x62, 0x61, 0x72, 0x0a};
+
+ char state = RLP_STRING;
+
+ rlp_encoder_t encoder;
+
+ char buf[4];
+ char *zbuf = (char*)&buf;
+
+ rlp_init(&encoder, 9, 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, 3);
+
+ 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, "foo", 3);
+ ck_assert_mem_eq(zbuf, "bar\0", 4);
+}
+END_TEST
+
Suite *rlp_decode_suite(void) {
Suite *s;
TCase *tcb;
@@ -165,14 +193,15 @@ Suite *rlp_decode_suite(void) {
tcb = tcase_create("bytes");
tcl = tcase_create("list");
- //tcase_add_test(tcb, rlp_decode_single_test);
- //tcase_add_test(tcb, rlp_decode_short_string_test);
- //tcase_add_test(tcb, rlp_decode_long_string_test);
+ tcase_add_test(tcb, rlp_decode_single_test);
+ tcase_add_test(tcb, rlp_decode_short_string_test);
+ tcase_add_test(tcb, rlp_decode_long_string_test);
suite_add_tcase(s, tcb);
tcase_add_test(tcl, rlp_decode_zero_list_test);
tcase_add_test(tcl, rlp_decode_short_list_test);
tcase_add_test(tcl, rlp_decode_long_list_test);
+ tcase_add_test(tcl, rlp_decode_adjacent_strings_test);
suite_add_tcase(s, tcl);
return s;