diff options
author | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:13:16 +0200 |
---|---|---|
committer | Fred Sundvik <fsundvik@gmail.com> | 2016-02-14 21:13:16 +0200 |
commit | 62058329ff9000589ddba6454ff8ef8a551b7243 (patch) | |
tree | 7dba4d57587f5d13fca4de596c3ec0b65a29ffca /serial_link/tests | |
parent | a3ec3bbef8d46a897f59dd22c8e59d951e87a961 (diff) |
Add crc32 validation of received frames
Diffstat (limited to 'serial_link/tests')
-rw-r--r-- | serial_link/tests/frame_validator_tests.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/serial_link/tests/frame_validator_tests.c b/serial_link/tests/frame_validator_tests.c index f6a4fcd842..1aca9f95fc 100644 --- a/serial_link/tests/frame_validator_tests.c +++ b/serial_link/tests/frame_validator_tests.c @@ -42,3 +42,38 @@ Ensure(FrameValidator, doesnt_validate_frames_under_5_bytes) { recv_frame(data, 3); recv_frame(data, 4); } + +Ensure(FrameValidator, validates_one_byte_frame_with_correct_crc) { + uint8_t data[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; + expect(route_frame, + when(size, is_equal_to(1)), + when(data, is_equal_to_contents_of(data, 1)) + ); + recv_frame(data, 5); +} + +Ensure(FrameValidator, does_not_validate_one_byte_frame_with_incorrect_crc) { + uint8_t data[] = {0x44, 0, 0, 0, 0}; + never_expect(route_frame); + recv_frame(data, 5); +} + +Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) { + uint8_t data[] = {0x44, 0x10, 0xFF, 0x00, 0x74, 0x4E, 0x30, 0xBA}; + expect(route_frame, + when(size, is_equal_to(4)), + when(data, is_equal_to_contents_of(data, 4)) + ); + recv_frame(data, 8); +} + +Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) { + //0xBA304E74 + //0x470B99F4 + uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; + expect(route_frame, + when(size, is_equal_to(5)), + when(data, is_equal_to_contents_of(data, 5)) + ); + recv_frame(data, 9); +} |