From 5ed1579e55a8ef1c0735eae2fdfc251418e6e64d Mon Sep 17 00:00:00 2001 From: Raul Victor Trombin Date: Wed, 3 Apr 2024 14:51:21 -0300 Subject: [PATCH] src: tests: Add checksum error while deconding test and update test for new pattern --- tests/deserialize.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/deserialize.rs b/tests/deserialize.rs index d977d4c3b..a21000640 100644 --- a/tests/deserialize.rs +++ b/tests/deserialize.rs @@ -39,6 +39,23 @@ fn test_simple_deserialization() { panic!("Failed to use decoder with valid message"); }; + // Retry with a wrong receipt CRC + for byte in &buffer[0..buffer.len() - 2] { + dbg!(byte, &decoder.state); + assert!(matches!( + decoder.parse_byte(byte.clone()), + DecoderResult::InProgress + )); + } + assert!(matches!( + decoder.parse_byte(buffer[buffer.len() - 2]), + DecoderResult::InProgress + )); + assert!(matches!( + decoder.parse_byte(0x01), // force a crc error + DecoderResult::Error(ParseError::ChecksumError(_)) + )); + // Wrong CRC test let buffer: Vec = vec![ 0x42, 0x52, 0x02, 0x00, 0x06, 0x00, 0x00, 0x00, 0x05, 0x00, 0xa1, 0x01,