|
|
@ -39,34 +39,34 @@ BeforeEach(ByteStuffer) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AfterEach(ByteStuffer) {}
|
|
|
|
AfterEach(ByteStuffer) {}
|
|
|
|
|
|
|
|
|
|
|
|
void validator_recv_frame(uint8_t* data, uint16_t size) {
|
|
|
|
void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) {
|
|
|
|
mock(data, size);
|
|
|
|
mock(data, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void send_data(const uint8_t* data, uint16_t size) {
|
|
|
|
void send_data(uint8_t link, const uint8_t* data, uint16_t size) {
|
|
|
|
memcpy(sent_data + sent_data_size, data, size);
|
|
|
|
memcpy(sent_data + sent_data_size, data, size);
|
|
|
|
sent_data_size += size;
|
|
|
|
sent_data_size += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_zero_byte) {
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_zero_byte) {
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_FF_byte) {
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_FF_byte) {
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_random_byte) {
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_single_random_byte) {
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
recv_byte(0x4A);
|
|
|
|
recv_byte(0, 0x4A);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_zero_length_frame) {
|
|
|
|
Ensure(ByteStuffer, receives_no_frame_for_a_zero_length_frame) {
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_single_byte_valid_frame) {
|
|
|
|
Ensure(ByteStuffer, receives_single_byte_valid_frame) {
|
|
|
@ -75,9 +75,9 @@ Ensure(ByteStuffer, receives_single_byte_valid_frame) {
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(0x37);
|
|
|
|
recv_byte(0, 0x37);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_three_bytes_valid_frame) {
|
|
|
|
Ensure(ByteStuffer, receives_three_bytes_valid_frame) {
|
|
|
@ -86,11 +86,11 @@ Ensure(ByteStuffer, receives_three_bytes_valid_frame) {
|
|
|
|
when(size, is_equal_to(3)),
|
|
|
|
when(size, is_equal_to(3)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 3))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 3))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(4);
|
|
|
|
recv_byte(0, 4);
|
|
|
|
recv_byte(0x37);
|
|
|
|
recv_byte(0, 0x37);
|
|
|
|
recv_byte(0x99);
|
|
|
|
recv_byte(0, 0x99);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_single_zero_valid_frame) {
|
|
|
|
Ensure(ByteStuffer, receives_single_zero_valid_frame) {
|
|
|
@ -99,9 +99,9 @@ Ensure(ByteStuffer, receives_single_zero_valid_frame) {
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_with_zeroes) {
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_with_zeroes) {
|
|
|
@ -110,12 +110,12 @@ Ensure(ByteStuffer, receives_valid_frame_with_zeroes) {
|
|
|
|
when(size, is_equal_to(4)),
|
|
|
|
when(size, is_equal_to(4)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 4))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 4))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(5);
|
|
|
|
recv_byte(0, 5);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(0, 3);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_two_valid_frames) {
|
|
|
|
Ensure(ByteStuffer, receives_two_valid_frames) {
|
|
|
@ -129,13 +129,13 @@ Ensure(ByteStuffer, receives_two_valid_frames) {
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(size, is_equal_to(1)),
|
|
|
|
when(data, is_equal_to_contents_of(expected2, 1))
|
|
|
|
when(data, is_equal_to_contents_of(expected2, 1))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(1, 2);
|
|
|
|
recv_byte(5);
|
|
|
|
recv_byte(1, 5);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(1, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(1, 0);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(1, 2);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(1, 3);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
|
|
|
@ -144,13 +144,13 @@ Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) {
|
|
|
|
when(size, is_equal_to(2)),
|
|
|
|
when(size, is_equal_to(2)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 2))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 2))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(1, 3);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(1, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(1, 0);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(1, 3);
|
|
|
|
recv_byte(5);
|
|
|
|
recv_byte(1, 5);
|
|
|
|
recv_byte(7);
|
|
|
|
recv_byte(1, 7);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
|
|
|
|
Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
|
|
|
@ -159,14 +159,14 @@ Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) {
|
|
|
|
when(size, is_equal_to(2)),
|
|
|
|
when(size, is_equal_to(2)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 2))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 2))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(9);
|
|
|
|
recv_byte(0, 9);
|
|
|
|
recv_byte(4); // This should have been zero
|
|
|
|
recv_byte(0, 4); // This should have been zero
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(0, 3);
|
|
|
|
recv_byte(5);
|
|
|
|
recv_byte(0, 5);
|
|
|
|
recv_byte(7);
|
|
|
|
recv_byte(0, 7);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) {
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) {
|
|
|
@ -179,11 +179,11 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_
|
|
|
|
when(size, is_equal_to(254)),
|
|
|
|
when(size, is_equal_to(254)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 254))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 254))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
recv_byte(i+1);
|
|
|
|
recv_byte(0, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) {
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) {
|
|
|
@ -197,13 +197,13 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
|
|
|
|
when(size, is_equal_to(255)),
|
|
|
|
when(size, is_equal_to(255)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 255))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 255))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
recv_byte(i+1);
|
|
|
|
recv_byte(0, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(7);
|
|
|
|
recv_byte(0, 7);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) {
|
|
|
|
Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) {
|
|
|
@ -217,13 +217,13 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_
|
|
|
|
when(size, is_equal_to(255)),
|
|
|
|
when(size, is_equal_to(255)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 255))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 255))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
recv_byte(i+1);
|
|
|
|
recv_byte(0, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_two_long_frames_and_some_more) {
|
|
|
|
Ensure(ByteStuffer, receives_two_long_frames_and_some_more) {
|
|
|
@ -242,23 +242,23 @@ Ensure(ByteStuffer, receives_two_long_frames_and_some_more) {
|
|
|
|
when(size, is_equal_to(515)),
|
|
|
|
when(size, is_equal_to(515)),
|
|
|
|
when(data, is_equal_to_contents_of(expected, 510))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 510))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
recv_byte(i+1);
|
|
|
|
recv_byte(0, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(0xFF);
|
|
|
|
recv_byte(0, 0xFF);
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
for (i=0;i<254;i++) {
|
|
|
|
recv_byte(i+1);
|
|
|
|
recv_byte(0, i+1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(8);
|
|
|
|
recv_byte(0, 8);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(3);
|
|
|
|
recv_byte(0, 3);
|
|
|
|
recv_byte(4);
|
|
|
|
recv_byte(0, 4);
|
|
|
|
recv_byte(5);
|
|
|
|
recv_byte(0, 5);
|
|
|
|
recv_byte(6);
|
|
|
|
recv_byte(0, 6);
|
|
|
|
recv_byte(7);
|
|
|
|
recv_byte(0, 7);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
|
|
|
|
Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
|
|
|
@ -268,23 +268,23 @@ Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) {
|
|
|
|
when(data, is_equal_to_contents_of(expected, MAX_FRAME_SIZE))
|
|
|
|
when(data, is_equal_to_contents_of(expected, MAX_FRAME_SIZE))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
|
|
|
|
Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) {
|
|
|
|
uint8_t expected[1] = {0};
|
|
|
|
uint8_t expected[1] = {0};
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
never_expect(validator_recv_frame);
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) {
|
|
|
|
Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) {
|
|
|
@ -294,23 +294,23 @@ Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) {
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
when(data, is_equal_to_contents_of(expected, 1))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
for(i=0;i<MAX_FRAME_SIZE;i++) {
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
recv_byte(2);
|
|
|
|
recv_byte(0, 2);
|
|
|
|
recv_byte(1);
|
|
|
|
recv_byte(0, 1);
|
|
|
|
recv_byte(0);
|
|
|
|
recv_byte(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, does_nothing_when_sending_zero_size_frame) {
|
|
|
|
Ensure(ByteStuffer, does_nothing_when_sending_zero_size_frame) {
|
|
|
|
assert_that(sent_data_size, is_equal_to(0));
|
|
|
|
assert_that(sent_data_size, is_equal_to(0));
|
|
|
|
send_frame(NULL, 0);
|
|
|
|
send_frame(0, NULL, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, send_one_byte_frame) {
|
|
|
|
Ensure(ByteStuffer, send_one_byte_frame) {
|
|
|
|
uint8_t data[] = {5};
|
|
|
|
uint8_t data[] = {5};
|
|
|
|
send_frame(data, 1);
|
|
|
|
send_frame(1, data, 1);
|
|
|
|
uint8_t expected[] = {2, 5, 0};
|
|
|
|
uint8_t expected[] = {2, 5, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -318,7 +318,7 @@ Ensure(ByteStuffer, send_one_byte_frame) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame) {
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame) {
|
|
|
|
uint8_t data[] = {5, 0x77};
|
|
|
|
uint8_t data[] = {5, 0x77};
|
|
|
|
send_frame(data, 2);
|
|
|
|
send_frame(0, data, 2);
|
|
|
|
uint8_t expected[] = {3, 5, 0x77, 0};
|
|
|
|
uint8_t expected[] = {3, 5, 0x77, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -326,7 +326,7 @@ Ensure(ByteStuffer, sends_two_byte_frame) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_one_byte_frame_with_zero) {
|
|
|
|
Ensure(ByteStuffer, sends_one_byte_frame_with_zero) {
|
|
|
|
uint8_t data[] = {0};
|
|
|
|
uint8_t data[] = {0};
|
|
|
|
send_frame(data, 1);
|
|
|
|
send_frame(0, data, 1);
|
|
|
|
uint8_t expected[] = {1, 1, 0};
|
|
|
|
uint8_t expected[] = {1, 1, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -334,7 +334,7 @@ Ensure(ByteStuffer, sends_one_byte_frame_with_zero) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame_starting_with_zero) {
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame_starting_with_zero) {
|
|
|
|
uint8_t data[] = {0, 9};
|
|
|
|
uint8_t data[] = {0, 9};
|
|
|
|
send_frame(data, 2);
|
|
|
|
send_frame(1, data, 2);
|
|
|
|
uint8_t expected[] = {1, 2, 9, 0};
|
|
|
|
uint8_t expected[] = {1, 2, 9, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -342,7 +342,7 @@ Ensure(ByteStuffer, sends_two_byte_frame_starting_with_zero) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) {
|
|
|
|
Ensure(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) {
|
|
|
|
uint8_t data[] = {9, 0};
|
|
|
|
uint8_t data[] = {9, 0};
|
|
|
|
send_frame(data, 2);
|
|
|
|
send_frame(1, data, 2);
|
|
|
|
uint8_t expected[] = {2, 9, 1, 0};
|
|
|
|
uint8_t expected[] = {2, 9, 1, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -350,7 +350,7 @@ Ensure(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_zero_in_the_middle) {
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_zero_in_the_middle) {
|
|
|
|
uint8_t data[] = {9, 0, 0x68};
|
|
|
|
uint8_t data[] = {9, 0, 0x68};
|
|
|
|
send_frame(data, 3);
|
|
|
|
send_frame(0, data, 3);
|
|
|
|
uint8_t expected[] = {2, 9, 2, 0x68, 0};
|
|
|
|
uint8_t expected[] = {2, 9, 2, 0x68, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -358,7 +358,7 @@ Ensure(ByteStuffer, sends_three_byte_frame_zero_in_the_middle) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_data_in_the_middle) {
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_data_in_the_middle) {
|
|
|
|
uint8_t data[] = {0, 0x55, 0};
|
|
|
|
uint8_t data[] = {0, 0x55, 0};
|
|
|
|
send_frame(data, 3);
|
|
|
|
send_frame(0, data, 3);
|
|
|
|
uint8_t expected[] = {1, 2, 0x55, 1, 0};
|
|
|
|
uint8_t expected[] = {1, 2, 0x55, 1, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -366,7 +366,7 @@ Ensure(ByteStuffer, sends_three_byte_frame_data_in_the_middle) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_with_all_zeroes) {
|
|
|
|
Ensure(ByteStuffer, sends_three_byte_frame_with_all_zeroes) {
|
|
|
|
uint8_t data[] = {0, 0, 0};
|
|
|
|
uint8_t data[] = {0, 0, 0};
|
|
|
|
send_frame(data, 3);
|
|
|
|
send_frame(0, data, 3);
|
|
|
|
uint8_t expected[] = {1, 1, 1, 1, 0};
|
|
|
|
uint8_t expected[] = {1, 1, 1, 1, 0};
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data_size, is_equal_to(sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
|
assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected)));
|
|
|
@ -378,7 +378,7 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes) {
|
|
|
|
for(i=0;i<254;i++) {
|
|
|
|
for(i=0;i<254;i++) {
|
|
|
|
data[i] = i + 1;
|
|
|
|
data[i] = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_frame(data, 254);
|
|
|
|
send_frame(0, data, 254);
|
|
|
|
uint8_t expected[256];
|
|
|
|
uint8_t expected[256];
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
@ -395,7 +395,7 @@ Ensure(ByteStuffer, sends_frame_with_255_non_zeroes) {
|
|
|
|
for(i=0;i<255;i++) {
|
|
|
|
for(i=0;i<255;i++) {
|
|
|
|
data[i] = i + 1;
|
|
|
|
data[i] = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_frame(data, 255);
|
|
|
|
send_frame(0, data, 255);
|
|
|
|
uint8_t expected[258];
|
|
|
|
uint8_t expected[258];
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
@ -415,7 +415,7 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
|
|
|
|
data[i] = i + 1;
|
|
|
|
data[i] = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data[255] = 0;
|
|
|
|
data[255] = 0;
|
|
|
|
send_frame(data, 255);
|
|
|
|
send_frame(0, data, 255);
|
|
|
|
uint8_t expected[258];
|
|
|
|
uint8_t expected[258];
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
expected[0] = 0xFF;
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
|
for(i=1;i<255;i++) {
|
|
|
@ -430,27 +430,27 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) {
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
|
|
|
|
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) {
|
|
|
|
uint8_t original_data[] = { 1, 2, 3};
|
|
|
|
uint8_t original_data[] = { 1, 2, 3};
|
|
|
|
send_frame(original_data, sizeof(original_data));
|
|
|
|
send_frame(0, original_data, sizeof(original_data));
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
recv_byte(sent_data[i]);
|
|
|
|
recv_byte(1, sent_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) {
|
|
|
|
Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) {
|
|
|
|
uint8_t original_data[] = { 1, 0, 3, 0, 0, 9};
|
|
|
|
uint8_t original_data[] = { 1, 0, 3, 0, 0, 9};
|
|
|
|
send_frame(original_data, sizeof(original_data));
|
|
|
|
send_frame(1, original_data, sizeof(original_data));
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
int i;
|
|
|
|
int i;
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
recv_byte(sent_data[i]);
|
|
|
|
recv_byte(0, sent_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -460,13 +460,13 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) {
|
|
|
|
for(i=0;i<254;i++) {
|
|
|
|
for(i=0;i<254;i++) {
|
|
|
|
original_data[i] = i + 1;
|
|
|
|
original_data[i] = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
send_frame(original_data, sizeof(original_data));
|
|
|
|
send_frame(0, original_data, sizeof(original_data));
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
recv_byte(sent_data[i]);
|
|
|
|
recv_byte(1, sent_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -478,13 +478,13 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
original_data[254] = 22;
|
|
|
|
original_data[254] = 22;
|
|
|
|
original_data[255] = 23;
|
|
|
|
original_data[255] = 23;
|
|
|
|
send_frame(original_data, sizeof(original_data));
|
|
|
|
send_frame(0, original_data, sizeof(original_data));
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
recv_byte(sent_data[i]);
|
|
|
|
recv_byte(1, sent_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -495,12 +495,12 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) {
|
|
|
|
original_data[i] = i + 1;
|
|
|
|
original_data[i] = i + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
original_data[254] = 0;
|
|
|
|
original_data[254] = 0;
|
|
|
|
send_frame(original_data, sizeof(original_data));
|
|
|
|
send_frame(0, original_data, sizeof(original_data));
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
expect(validator_recv_frame,
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(size, is_equal_to(sizeof(original_data))),
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
when(data, is_equal_to_contents_of(original_data, sizeof(original_data)))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
for(i=0;i<sent_data_size;i++) {
|
|
|
|
recv_byte(sent_data[i]);
|
|
|
|
recv_byte(1, sent_data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|