1
0
Fork 0

Add validator send frame

This commit is contained in:
Fred Sundvik 2016-02-14 21:31:01 +02:00
parent 62058329ff
commit 2a6696bd3d
2 changed files with 31 additions and 2 deletions

View file

@ -24,6 +24,7 @@ SOFTWARE.
#include "protocol/frame_validator.h"
#include "protocol/frame_router.h"
#include "protocol/byte_stuffer.h"
const uint32_t poly8_lookup[256] =
{
@ -110,3 +111,9 @@ void recv_frame(uint8_t* data, uint16_t size) {
}
}
}
void validator_send_frame(uint8_t* data, uint16_t size) {
uint32_t* crc = (uint32_t*)(data + size);
*crc = crc32_byte(data, size);
send_frame(data, size + 4);
}

View file

@ -30,6 +30,10 @@ void route_frame(uint8_t* data, uint16_t size) {
mock(data, size);
}
void send_frame(uint8_t* data, uint16_t size) {
mock(data, size);
}
Describe(FrameValidator);
BeforeEach(FrameValidator) {}
AfterEach(FrameValidator) {}
@ -68,8 +72,6 @@ Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) {
}
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)),
@ -77,3 +79,23 @@ Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) {
);
recv_frame(data, 9);
}
Ensure(FrameValidator, sends_one_byte_with_correct_crc) {
uint8_t original[] = {0x44, 0, 0, 0, 0};
uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3};
expect(send_frame,
when(size, is_equal_to(sizeof(expected))),
when(data, is_equal_to_contents_of(expected, sizeof(expected)))
);
validator_send_frame(original, 1);
}
Ensure(FrameValidator, sends_five_bytes_with_correct_crc) {
uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0};
uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47};
expect(send_frame,
when(size, is_equal_to(sizeof(expected))),
when(data, is_equal_to_contents_of(expected, sizeof(expected)))
);
validator_send_frame(original, 5);
}