Rename recv_frame to validator_recv_frame

pull/482/head
Fred Sundvik 9 years ago
parent 2a6696bd3d
commit 0eb62c4ce6

@ -60,7 +60,7 @@ void recv_byte(byte_stuffer_state_t* state, uint8_t data) {
if (state->next_zero == 0) {
// The frame is completed
if (state->data_pos > 0) {
recv_frame(state->data, state->data_pos);
validator_recv_frame(state->data, state->data_pos);
}
}
else {

@ -102,7 +102,7 @@ static uint32_t crc32_byte(uint8_t *p, uint32_t bytelength)
return (crc ^ 0xffffffff);
}
void recv_frame(uint8_t* data, uint16_t size) {
void validator_recv_frame(uint8_t* data, uint16_t size) {
if (size > 4) {
uint32_t frame_crc = *(uint32_t*)(data + size - 4);
uint32_t expected_crc = crc32_byte(data, size - 4);

@ -22,4 +22,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
void recv_frame(uint8_t* data, uint16_t size);
void validator_recv_frame(uint8_t* data, uint16_t size);
// The buffer pointed to by the data needs 4 additional bytes
void validator_send_frame(uint8_t* data, uint16_t size);

@ -40,7 +40,7 @@ BeforeEach(ByteStuffer) {
}
AfterEach(ByteStuffer) {}
void recv_frame(uint8_t* data, uint16_t size) {
void validator_recv_frame(uint8_t* data, uint16_t size) {
mock(data, size);
}
@ -50,29 +50,29 @@ void send_data(const uint8_t* data, uint16_t size) {
}
Ensure(ByteStuffer, receives_no_frame_for_a_single_zero_byte) {
never_expect(recv_frame);
never_expect(validator_recv_frame);
recv_byte(&state, 0);
}
Ensure(ByteStuffer, receives_no_frame_for_a_single_FF_byte) {
never_expect(recv_frame);
never_expect(validator_recv_frame);
recv_byte(&state, 0xFF);
}
Ensure(ByteStuffer, receives_no_frame_for_a_single_random_byte) {
never_expect(recv_frame);
never_expect(validator_recv_frame);
recv_byte(&state, 0x4A);
}
Ensure(ByteStuffer, receives_no_frame_for_a_zero_length_frame) {
never_expect(recv_frame);
never_expect(validator_recv_frame);
recv_byte(&state, 1);
recv_byte(&state, 0);
}
Ensure(ByteStuffer, receives_single_byte_valid_frame) {
uint8_t expected[] = {0x37};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(1)),
when(data, is_equal_to_contents_of(expected, 1))
);
@ -83,7 +83,7 @@ Ensure(ByteStuffer, receives_single_byte_valid_frame) {
Ensure(ByteStuffer, receives_three_bytes_valid_frame) {
uint8_t expected[] = {0x37, 0x99, 0xFF};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(3)),
when(data, is_equal_to_contents_of(expected, 3))
);
@ -96,7 +96,7 @@ Ensure(ByteStuffer, receives_three_bytes_valid_frame) {
Ensure(ByteStuffer, receives_single_zero_valid_frame) {
uint8_t expected[] = {0};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(1)),
when(data, is_equal_to_contents_of(expected, 1))
);
@ -107,7 +107,7 @@ Ensure(ByteStuffer, receives_single_zero_valid_frame) {
Ensure(ByteStuffer, receives_valid_frame_with_zeroes) {
uint8_t expected[] = {5, 0, 3, 0};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(4)),
when(data, is_equal_to_contents_of(expected, 4))
);
@ -122,11 +122,11 @@ Ensure(ByteStuffer, receives_valid_frame_with_zeroes) {
Ensure(ByteStuffer, receives_two_valid_frames) {
uint8_t expected1[] = {5, 0};
uint8_t expected2[] = {3};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(2)),
when(data, is_equal_to_contents_of(expected1, 2))
);
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(1)),
when(data, is_equal_to_contents_of(expected2, 1))
);
@ -141,7 +141,7 @@ Ensure(ByteStuffer, receives_two_valid_frames) {
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
uint8_t expected[] = {5, 7};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(2)),
when(data, is_equal_to_contents_of(expected, 2))
);
@ -156,7 +156,7 @@ Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
uint8_t expected[] = {5, 7};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(2)),
when(data, is_equal_to_contents_of(expected, 2))
);
@ -176,7 +176,7 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_
for (i=0;i<254;i++) {
expected[i] = i + 1;
}
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(254)),
when(data, is_equal_to_contents_of(expected, 254))
);
@ -194,7 +194,7 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
expected[i] = i + 1;
}
expected[254] = 7;
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(255)),
when(data, is_equal_to_contents_of(expected, 255))
);
@ -214,7 +214,7 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
expected[i] = i + 1;
}
expected[254] = 0;
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(255)),
when(data, is_equal_to_contents_of(expected, 255))
);
@ -239,7 +239,7 @@ Ensure(ByteStuffer, receives_two_long_frames_and_some_more) {
for (i=0;i<7;i++) {
expected[254*2+i] = i + 1;
}
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(515)),
when(data, is_equal_to_contents_of(expected, 510))
);
@ -264,7 +264,7 @@ Ensure(ByteStuffer, receives_two_long_frames_and_some_more) {
Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
uint8_t expected[MAX_FRAME_SIZE] = {};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(MAX_FRAME_SIZE)),
when(data, is_equal_to_contents_of(expected, MAX_FRAME_SIZE))
);
@ -278,7 +278,7 @@ Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
uint8_t expected[1] = {0};
never_expect(recv_frame);
never_expect(validator_recv_frame);
int i;
recv_byte(&state, 1);
for(i=0;i<MAX_FRAME_SIZE;i++) {
@ -290,7 +290,7 @@ Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) {
uint8_t expected[1] = {1};
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(1)),
when(data, is_equal_to_contents_of(expected, 1))
);
@ -432,7 +432,7 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
uint8_t original_data[] = { 1, 2, 3};
send_frame(original_data, sizeof(original_data));
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(sizeof(original_data))),
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
);
@ -445,7 +445,7 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) {
uint8_t original_data[] = { 1, 0, 3, 0, 0, 9};
send_frame(original_data, sizeof(original_data));
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(sizeof(original_data))),
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
);
@ -462,7 +462,7 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) {
original_data[i] = i + 1;
}
send_frame(original_data, sizeof(original_data));
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(sizeof(original_data))),
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
);
@ -480,7 +480,7 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) {
original_data[254] = 22;
original_data[255] = 23;
send_frame(original_data, sizeof(original_data));
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(sizeof(original_data))),
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
);
@ -497,7 +497,7 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) {
}
original_data[254] = 0;
send_frame(original_data, sizeof(original_data));
expect(recv_frame,
expect(validator_recv_frame,
when(size, is_equal_to(sizeof(original_data))),
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
);

@ -41,10 +41,10 @@ AfterEach(FrameValidator) {}
Ensure(FrameValidator, doesnt_validate_frames_under_5_bytes) {
never_expect(route_frame);
uint8_t data[] = {1, 2};
recv_frame(0, 1);
recv_frame(data, 2);
recv_frame(data, 3);
recv_frame(data, 4);
validator_recv_frame(0, 1);
validator_recv_frame(data, 2);
validator_recv_frame(data, 3);
validator_recv_frame(data, 4);
}
Ensure(FrameValidator, validates_one_byte_frame_with_correct_crc) {
@ -53,13 +53,13 @@ Ensure(FrameValidator, validates_one_byte_frame_with_correct_crc) {
when(size, is_equal_to(1)),
when(data, is_equal_to_contents_of(data, 1))
);
recv_frame(data, 5);
validator_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);
validator_recv_frame(data, 5);
}
Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) {
@ -68,7 +68,7 @@ Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) {
when(size, is_equal_to(4)),
when(data, is_equal_to_contents_of(data, 4))
);
recv_frame(data, 8);
validator_recv_frame(data, 8);
}
Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) {
@ -77,7 +77,7 @@ Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) {
when(size, is_equal_to(5)),
when(data, is_equal_to_contents_of(data, 5))
);
recv_frame(data, 9);
validator_recv_frame(data, 9);
}
Ensure(FrameValidator, sends_one_byte_with_correct_crc) {

Loading…
Cancel
Save