diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-08-24 22:23:17 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-08-27 21:57:49 +0300 |
| commit | 0a11460175d6a838c71343c19eb4ce4699936247 (patch) | |
| tree | e2e96c421172e212d6e623127d40d4582bd02127 | |
| parent | 8a9aac6e3237a505682cc7249a8dfff6cb964343 (diff) | |
| download | qmk_firmware-0a11460175d6a838c71343c19eb4ce4699936247.tar.gz qmk_firmware-0a11460175d6a838c71343c19eb4ce4699936247.zip | |
Build actual tests, convert byte_stuffer_tests
| -rw-r--r-- | build_keyboard.mk | 6 | ||||
| -rw-r--r-- | build_test.mk | 14 | ||||
| -rw-r--r-- | common.mk | 16 | ||||
| -rw-r--r-- | quantum/serial_link/protocol/byte_stuffer.c | 3 | ||||
| -rw-r--r-- | quantum/serial_link/protocol/byte_stuffer.h | 3 | ||||
| -rw-r--r-- | quantum/serial_link/tests/byte_stuffer_tests.cpp (renamed from quantum/serial_link/tests/byte_stuffer_tests.c) | 313 | ||||
| -rw-r--r-- | quantum/serial_link/tests/rules.mk | 3 |
7 files changed, 179 insertions, 179 deletions
diff --git a/build_keyboard.mk b/build_keyboard.mk index 869d672b0..164794c63 100644 --- a/build_keyboard.mk +++ b/build_keyboard.mk | |||
| @@ -155,12 +155,8 @@ ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) | |||
| 155 | endif | 155 | endif |
| 156 | 156 | ||
| 157 | ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) | 157 | ifeq ($(strip $(SERIAL_LINK_ENABLE)), yes) |
| 158 | SERIAL_DIR = $(QUANTUM_DIR)/serial_link | ||
| 159 | SERIAL_PATH = $(QUANTUM_PATH)/serial_link | ||
| 160 | SERIAL_SRC = $(wildcard $(SERIAL_PATH)/protocol/*.c) | ||
| 161 | SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) | ||
| 162 | SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) | 158 | SRC += $(patsubst $(QUANTUM_PATH)/%,%,$(SERIAL_SRC)) |
| 163 | OPT_DEFS += -DSERIAL_LINK_ENABLE | 159 | OPT_DEFS += $(SERIAL_DEFS) |
| 164 | VAPTH += $(SERIAL_PATH) | 160 | VAPTH += $(SERIAL_PATH) |
| 165 | endif | 161 | endif |
| 166 | 162 | ||
diff --git a/build_test.mk b/build_test.mk index dac59a8f4..1d8cb08b1 100644 --- a/build_test.mk +++ b/build_test.mk | |||
| @@ -10,7 +10,9 @@ TARGET=test/$(TEST) | |||
| 10 | 10 | ||
| 11 | GTEST_OUTPUT = $(BUILD_DIR)/gtest | 11 | GTEST_OUTPUT = $(BUILD_DIR)/gtest |
| 12 | 12 | ||
| 13 | OUTPUTS := $(GTEST_OUTPUT) | 13 | TEST_OBJ = $(BUILD_DIR)/test_obj |
| 14 | |||
| 15 | OUTPUTS := $(TEST_OBJ)/$(TEST) $(GTEST_OUTPUT) | ||
| 14 | 16 | ||
| 15 | GTEST_INC := \ | 17 | GTEST_INC := \ |
| 16 | $(LIB_PATH)/googletest/googletest/include\ | 18 | $(LIB_PATH)/googletest/googletest/include\ |
| @@ -36,8 +38,16 @@ VPATH +=\ | |||
| 36 | 38 | ||
| 37 | all: elf | 39 | all: elf |
| 38 | 40 | ||
| 41 | include $(QUANTUM_PATH)/serial_link/tests/rules.mk | ||
| 42 | |||
| 43 | $(TEST_OBJ)/$(TEST)_SRC := $($(TEST)_SRC) | ||
| 44 | $(TEST_OBJ)/$(TEST)_INC := $($(TEST)_INC) $(VPATH) $(GTEST_INC) | ||
| 45 | $(TEST_OBJ)/$(TEST)_DEFS := $($(TEST)_DEFS) | ||
| 46 | |||
| 39 | include $(TMK_PATH)/native.mk | 47 | include $(TMK_PATH)/native.mk |
| 40 | include $(TMK_PATH)/rules.mk | 48 | include $(TMK_PATH)/rules.mk |
| 41 | 49 | ||
| 42 | $(shell mkdir $(BUILD_DIR)/test 2>/dev/null) | 50 | |
| 51 | $(shell mkdir -p $(BUILD_DIR)/test 2>/dev/null) | ||
| 52 | $(shell mkdir -p $(TEST_OBJ) 2>/dev/null) | ||
| 43 | 53 | ||
| @@ -9,4 +9,18 @@ LIB_PATH = $(TOP_DIR)/lib | |||
| 9 | QUANTUM_DIR = quantum | 9 | QUANTUM_DIR = quantum |
| 10 | QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) | 10 | QUANTUM_PATH = $(TOP_DIR)/$(QUANTUM_DIR) |
| 11 | 11 | ||
| 12 | BUILD_DIR := $(TOP_DIR)/.build \ No newline at end of file | 12 | BUILD_DIR := $(TOP_DIR)/.build |
| 13 | |||
| 14 | SERIAL_DIR := $(QUANTUM_DIR)/serial_link | ||
| 15 | SERIAL_PATH := $(QUANTUM_PATH)/serial_link | ||
| 16 | SERIAL_SRC := $(wildcard $(SERIAL_PATH)/protocol/*.c) | ||
| 17 | SERIAL_SRC += $(wildcard $(SERIAL_PATH)/system/*.c) | ||
| 18 | SERIAL_DEFS += -DSERIAL_LINK_ENABLE | ||
| 19 | |||
| 20 | VPATH += $(TOP_DIR) | ||
| 21 | VPATH += $(TMK_PATH) | ||
| 22 | VPATH += $(QUANTUM_PATH) | ||
| 23 | VPATH += $(QUANTUM_PATH)/keymap_extras | ||
| 24 | VPATH += $(QUANTUM_PATH)/audio | ||
| 25 | VPATH += $(QUANTUM_PATH)/process_keycode | ||
| 26 | VPATH += $(SERIAL_PATH) \ No newline at end of file | ||
diff --git a/quantum/serial_link/protocol/byte_stuffer.c b/quantum/serial_link/protocol/byte_stuffer.c index fb4c45a8d..2c87d64c2 100644 --- a/quantum/serial_link/protocol/byte_stuffer.c +++ b/quantum/serial_link/protocol/byte_stuffer.c | |||
| @@ -31,9 +31,6 @@ SOFTWARE. | |||
| 31 | // https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing | 31 | // https://en.wikipedia.org/wiki/Consistent_Overhead_Byte_Stuffing |
| 32 | // http://www.stuartcheshire.org/papers/COBSforToN.pdf | 32 | // http://www.stuartcheshire.org/papers/COBSforToN.pdf |
| 33 | 33 | ||
| 34 | #define MAX_FRAME_SIZE 1024 | ||
| 35 | #define NUM_LINKS 2 | ||
| 36 | |||
| 37 | typedef struct byte_stuffer_state { | 34 | typedef struct byte_stuffer_state { |
| 38 | uint16_t next_zero; | 35 | uint16_t next_zero; |
| 39 | uint16_t data_pos; | 36 | uint16_t data_pos; |
diff --git a/quantum/serial_link/protocol/byte_stuffer.h b/quantum/serial_link/protocol/byte_stuffer.h index 2cc88beb4..97e896856 100644 --- a/quantum/serial_link/protocol/byte_stuffer.h +++ b/quantum/serial_link/protocol/byte_stuffer.h | |||
| @@ -27,6 +27,9 @@ SOFTWARE. | |||
| 27 | 27 | ||
| 28 | #include <stdint.h> | 28 | #include <stdint.h> |
| 29 | 29 | ||
| 30 | #define MAX_FRAME_SIZE 1024 | ||
| 31 | #define NUM_LINKS 2 | ||
| 32 | |||
| 30 | void init_byte_stuffer(void); | 33 | void init_byte_stuffer(void); |
| 31 | void byte_stuffer_recv_byte(uint8_t link, uint8_t data); | 34 | void byte_stuffer_recv_byte(uint8_t link, uint8_t data); |
| 32 | void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size); | 35 | void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size); |
diff --git a/quantum/serial_link/tests/byte_stuffer_tests.c b/quantum/serial_link/tests/byte_stuffer_tests.cpp index 64b170e8c..ff49d727b 100644 --- a/quantum/serial_link/tests/byte_stuffer_tests.c +++ b/quantum/serial_link/tests/byte_stuffer_tests.cpp | |||
| @@ -22,70 +22,90 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |||
| 22 | SOFTWARE. | 22 | SOFTWARE. |
| 23 | */ | 23 | */ |
| 24 | 24 | ||
| 25 | #include <cgreen/cgreen.h> | 25 | #include "gtest/gtest.h" |
| 26 | #include <cgreen/mocks.h> | 26 | #include "gmock/gmock.h" |
| 27 | #include <vector> | ||
| 28 | #include <algorithm> | ||
| 29 | extern "C" { | ||
| 27 | #include "serial_link/protocol/byte_stuffer.h" | 30 | #include "serial_link/protocol/byte_stuffer.h" |
| 28 | #include "serial_link/protocol/byte_stuffer.c" | ||
| 29 | #include "serial_link/protocol/frame_validator.h" | 31 | #include "serial_link/protocol/frame_validator.h" |
| 30 | #include "serial_link/protocol/physical.h" | 32 | #include "serial_link/protocol/physical.h" |
| 33 | } | ||
| 31 | 34 | ||
| 32 | static uint8_t sent_data[MAX_FRAME_SIZE*2]; | 35 | using testing::_; |
| 33 | static uint16_t sent_data_size; | 36 | using testing::ElementsAreArray; |
| 37 | using testing::Args; | ||
| 34 | 38 | ||
| 35 | Describe(ByteStuffer); | 39 | class ByteStuffer : public ::testing::Test{ |
| 36 | BeforeEach(ByteStuffer) { | 40 | public: |
| 37 | init_byte_stuffer(); | 41 | ByteStuffer() { |
| 38 | sent_data_size = 0; | 42 | Instance = this; |
| 39 | } | 43 | init_byte_stuffer(); |
| 40 | AfterEach(ByteStuffer) {} | 44 | } |
| 41 | 45 | ||
| 42 | void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) { | 46 | ~ByteStuffer() { |
| 43 | mock(data, size); | 47 | Instance = nullptr; |
| 44 | } | 48 | } |
| 49 | |||
| 50 | MOCK_METHOD3(validator_recv_frame, void (uint8_t link, uint8_t* data, uint16_t size)); | ||
| 51 | |||
| 52 | void send_data(uint8_t link, const uint8_t* data, uint16_t size) { | ||
| 53 | std::copy(data, data + size, std::back_inserter(sent_data)); | ||
| 54 | } | ||
| 55 | std::vector<uint8_t> sent_data; | ||
| 45 | 56 | ||
| 46 | void send_data(uint8_t link, const uint8_t* data, uint16_t size) { | 57 | static ByteStuffer* Instance; |
| 47 | memcpy(sent_data + sent_data_size, data, size); | 58 | }; |
| 48 | sent_data_size += size; | 59 | |
| 60 | ByteStuffer* ByteStuffer::Instance = nullptr; | ||
| 61 | |||
| 62 | extern "C" { | ||
| 63 | void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) { | ||
| 64 | ByteStuffer::Instance->validator_recv_frame(link, data, size); | ||
| 65 | } | ||
| 66 | |||
| 67 | void send_data(uint8_t link, const uint8_t* data, uint16_t size) { | ||
| 68 | ByteStuffer::Instance->send_data(link, data, size); | ||
| 69 | } | ||
| 49 | } | 70 | } |
| 50 | 71 | ||
| 51 | Ensure(ByteStuffer, receives_no_frame_for_a_single_zero_byte) { | 72 | TEST_F(ByteStuffer, receives_no_frame_for_a_single_zero_byte) { |
| 52 | never_expect(validator_recv_frame); | 73 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 74 | .Times(0); | ||
| 53 | byte_stuffer_recv_byte(0, 0); | 75 | byte_stuffer_recv_byte(0, 0); |
| 54 | } | 76 | } |
| 55 | 77 | ||
| 56 | Ensure(ByteStuffer, receives_no_frame_for_a_single_FF_byte) { | 78 | TEST_F(ByteStuffer, receives_no_frame_for_a_single_FF_byte) { |
| 57 | never_expect(validator_recv_frame); | 79 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 80 | .Times(0); | ||
| 58 | byte_stuffer_recv_byte(0, 0xFF); | 81 | byte_stuffer_recv_byte(0, 0xFF); |
| 59 | } | 82 | } |
| 60 | 83 | ||
| 61 | Ensure(ByteStuffer, receives_no_frame_for_a_single_random_byte) { | 84 | TEST_F(ByteStuffer, receives_no_frame_for_a_single_random_byte) { |
| 62 | never_expect(validator_recv_frame); | 85 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 86 | .Times(0); | ||
| 63 | byte_stuffer_recv_byte(0, 0x4A); | 87 | byte_stuffer_recv_byte(0, 0x4A); |
| 64 | } | 88 | } |
| 65 | 89 | ||
| 66 | Ensure(ByteStuffer, receives_no_frame_for_a_zero_length_frame) { | 90 | TEST_F(ByteStuffer, receives_no_frame_for_a_zero_length_frame) { |
| 67 | never_expect(validator_recv_frame); | 91 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 92 | .Times(0); | ||
| 68 | byte_stuffer_recv_byte(0, 1); | 93 | byte_stuffer_recv_byte(0, 1); |
| 69 | byte_stuffer_recv_byte(0, 0); | 94 | byte_stuffer_recv_byte(0, 0); |
| 70 | } | 95 | } |
| 71 | 96 | ||
| 72 | Ensure(ByteStuffer, receives_single_byte_valid_frame) { | 97 | TEST_F(ByteStuffer, receives_single_byte_valid_frame) { |
| 73 | uint8_t expected[] = {0x37}; | 98 | uint8_t expected[] = {0x37}; |
| 74 | expect(validator_recv_frame, | 99 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 75 | when(size, is_equal_to(1)), | 100 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 76 | when(data, is_equal_to_contents_of(expected, 1)) | ||
| 77 | ); | ||
| 78 | byte_stuffer_recv_byte(0, 2); | 101 | byte_stuffer_recv_byte(0, 2); |
| 79 | byte_stuffer_recv_byte(0, 0x37); | 102 | byte_stuffer_recv_byte(0, 0x37); |
| 80 | byte_stuffer_recv_byte(0, 0); | 103 | byte_stuffer_recv_byte(0, 0); |
| 81 | } | 104 | } |
| 82 | 105 | TEST_F(ByteStuffer, receives_three_bytes_valid_frame) { | |
| 83 | Ensure(ByteStuffer, receives_three_bytes_valid_frame) { | ||
| 84 | uint8_t expected[] = {0x37, 0x99, 0xFF}; | 106 | uint8_t expected[] = {0x37, 0x99, 0xFF}; |
| 85 | expect(validator_recv_frame, | 107 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 86 | when(size, is_equal_to(3)), | 108 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 87 | when(data, is_equal_to_contents_of(expected, 3)) | ||
| 88 | ); | ||
| 89 | byte_stuffer_recv_byte(0, 4); | 109 | byte_stuffer_recv_byte(0, 4); |
| 90 | byte_stuffer_recv_byte(0, 0x37); | 110 | byte_stuffer_recv_byte(0, 0x37); |
| 91 | byte_stuffer_recv_byte(0, 0x99); | 111 | byte_stuffer_recv_byte(0, 0x99); |
| @@ -93,23 +113,19 @@ Ensure(ByteStuffer, receives_three_bytes_valid_frame) { | |||
| 93 | byte_stuffer_recv_byte(0, 0); | 113 | byte_stuffer_recv_byte(0, 0); |
| 94 | } | 114 | } |
| 95 | 115 | ||
| 96 | Ensure(ByteStuffer, receives_single_zero_valid_frame) { | 116 | TEST_F(ByteStuffer, receives_single_zero_valid_frame) { |
| 97 | uint8_t expected[] = {0}; | 117 | uint8_t expected[] = {0}; |
| 98 | expect(validator_recv_frame, | 118 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 99 | when(size, is_equal_to(1)), | 119 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 100 | when(data, is_equal_to_contents_of(expected, 1)) | ||
| 101 | ); | ||
| 102 | byte_stuffer_recv_byte(0, 1); | 120 | byte_stuffer_recv_byte(0, 1); |
| 103 | byte_stuffer_recv_byte(0, 1); | 121 | byte_stuffer_recv_byte(0, 1); |
| 104 | byte_stuffer_recv_byte(0, 0); | 122 | byte_stuffer_recv_byte(0, 0); |
| 105 | } | 123 | } |
| 106 | 124 | ||
| 107 | Ensure(ByteStuffer, receives_valid_frame_with_zeroes) { | 125 | TEST_F(ByteStuffer, receives_valid_frame_with_zeroes) { |
| 108 | uint8_t expected[] = {5, 0, 3, 0}; | 126 | uint8_t expected[] = {5, 0, 3, 0}; |
| 109 | expect(validator_recv_frame, | 127 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 110 | when(size, is_equal_to(4)), | 128 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 111 | when(data, is_equal_to_contents_of(expected, 4)) | ||
| 112 | ); | ||
| 113 | byte_stuffer_recv_byte(0, 2); | 129 | byte_stuffer_recv_byte(0, 2); |
| 114 | byte_stuffer_recv_byte(0, 5); | 130 | byte_stuffer_recv_byte(0, 5); |
| 115 | byte_stuffer_recv_byte(0, 2); | 131 | byte_stuffer_recv_byte(0, 2); |
| @@ -118,17 +134,14 @@ Ensure(ByteStuffer, receives_valid_frame_with_zeroes) { | |||
| 118 | byte_stuffer_recv_byte(0, 0); | 134 | byte_stuffer_recv_byte(0, 0); |
| 119 | } | 135 | } |
| 120 | 136 | ||
| 121 | Ensure(ByteStuffer, receives_two_valid_frames) { | 137 | |
| 138 | TEST_F(ByteStuffer, receives_two_valid_frames) { | ||
| 122 | uint8_t expected1[] = {5, 0}; | 139 | uint8_t expected1[] = {5, 0}; |
| 123 | uint8_t expected2[] = {3}; | 140 | uint8_t expected2[] = {3}; |
| 124 | expect(validator_recv_frame, | 141 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 125 | when(size, is_equal_to(2)), | 142 | .With(Args<1, 2>(ElementsAreArray(expected1))); |
| 126 | when(data, is_equal_to_contents_of(expected1, 2)) | 143 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 127 | ); | 144 | .With(Args<1, 2>(ElementsAreArray(expected2))); |
| 128 | expect(validator_recv_frame, | ||
| 129 | when(size, is_equal_to(1)), | ||
| 130 | when(data, is_equal_to_contents_of(expected2, 1)) | ||
| 131 | ); | ||
| 132 | byte_stuffer_recv_byte(1, 2); | 145 | byte_stuffer_recv_byte(1, 2); |
| 133 | byte_stuffer_recv_byte(1, 5); | 146 | byte_stuffer_recv_byte(1, 5); |
| 134 | byte_stuffer_recv_byte(1, 1); | 147 | byte_stuffer_recv_byte(1, 1); |
| @@ -138,12 +151,10 @@ Ensure(ByteStuffer, receives_two_valid_frames) { | |||
| 138 | byte_stuffer_recv_byte(1, 0); | 151 | byte_stuffer_recv_byte(1, 0); |
| 139 | } | 152 | } |
| 140 | 153 | ||
| 141 | Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) { | 154 | TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_zero) { |
| 142 | uint8_t expected[] = {5, 7}; | 155 | uint8_t expected[] = {5, 7}; |
| 143 | expect(validator_recv_frame, | 156 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 144 | when(size, is_equal_to(2)), | 157 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 145 | when(data, is_equal_to_contents_of(expected, 2)) | ||
| 146 | ); | ||
| 147 | byte_stuffer_recv_byte(1, 3); | 158 | byte_stuffer_recv_byte(1, 3); |
| 148 | byte_stuffer_recv_byte(1, 1); | 159 | byte_stuffer_recv_byte(1, 1); |
| 149 | byte_stuffer_recv_byte(1, 0); | 160 | byte_stuffer_recv_byte(1, 0); |
| @@ -153,12 +164,10 @@ Ensure(ByteStuffer, receives_valid_frame_after_unexpected_zero) { | |||
| 153 | byte_stuffer_recv_byte(1, 0); | 164 | byte_stuffer_recv_byte(1, 0); |
| 154 | } | 165 | } |
| 155 | 166 | ||
| 156 | Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) { | 167 | TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) { |
| 157 | uint8_t expected[] = {5, 7}; | 168 | uint8_t expected[] = {5, 7}; |
| 158 | expect(validator_recv_frame, | 169 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 159 | when(size, is_equal_to(2)), | 170 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 160 | when(data, is_equal_to_contents_of(expected, 2)) | ||
| 161 | ); | ||
| 162 | byte_stuffer_recv_byte(0, 2); | 171 | byte_stuffer_recv_byte(0, 2); |
| 163 | byte_stuffer_recv_byte(0, 9); | 172 | byte_stuffer_recv_byte(0, 9); |
| 164 | byte_stuffer_recv_byte(0, 4); // This should have been zero | 173 | byte_stuffer_recv_byte(0, 4); // This should have been zero |
| @@ -169,16 +178,14 @@ Ensure(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) { | |||
| 169 | byte_stuffer_recv_byte(0, 0); | 178 | byte_stuffer_recv_byte(0, 0); |
| 170 | } | 179 | } |
| 171 | 180 | ||
| 172 | Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) { | 181 | TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) { |
| 173 | uint8_t expected[254]; | 182 | uint8_t expected[254]; |
| 174 | int i; | 183 | int i; |
| 175 | for (i=0;i<254;i++) { | 184 | for (i=0;i<254;i++) { |
| 176 | expected[i] = i + 1; | 185 | expected[i] = i + 1; |
| 177 | } | 186 | } |
| 178 | expect(validator_recv_frame, | 187 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 179 | when(size, is_equal_to(254)), | 188 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 180 | when(data, is_equal_to_contents_of(expected, 254)) | ||
| 181 | ); | ||
| 182 | byte_stuffer_recv_byte(0, 0xFF); | 189 | byte_stuffer_recv_byte(0, 0xFF); |
| 183 | for (i=0;i<254;i++) { | 190 | for (i=0;i<254;i++) { |
| 184 | byte_stuffer_recv_byte(0, i+1); | 191 | byte_stuffer_recv_byte(0, i+1); |
| @@ -186,17 +193,15 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_ | |||
| 186 | byte_stuffer_recv_byte(0, 0); | 193 | byte_stuffer_recv_byte(0, 0); |
| 187 | } | 194 | } |
| 188 | 195 | ||
| 189 | Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) { | 196 | TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) { |
| 190 | uint8_t expected[255]; | 197 | uint8_t expected[255]; |
| 191 | int i; | 198 | int i; |
| 192 | for (i=0;i<254;i++) { | 199 | for (i=0;i<254;i++) { |
| 193 | expected[i] = i + 1; | 200 | expected[i] = i + 1; |
| 194 | } | 201 | } |
| 195 | expected[254] = 7; | 202 | expected[254] = 7; |
| 196 | expect(validator_recv_frame, | 203 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 197 | when(size, is_equal_to(255)), | 204 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 198 | when(data, is_equal_to_contents_of(expected, 255)) | ||
| 199 | ); | ||
| 200 | byte_stuffer_recv_byte(0, 0xFF); | 205 | byte_stuffer_recv_byte(0, 0xFF); |
| 201 | for (i=0;i<254;i++) { | 206 | for (i=0;i<254;i++) { |
| 202 | byte_stuffer_recv_byte(0, i+1); | 207 | byte_stuffer_recv_byte(0, i+1); |
| @@ -206,17 +211,15 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_ | |||
| 206 | byte_stuffer_recv_byte(0, 0); | 211 | byte_stuffer_recv_byte(0, 0); |
| 207 | } | 212 | } |
| 208 | 213 | ||
| 209 | Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) { | 214 | TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) { |
| 210 | uint8_t expected[255]; | 215 | uint8_t expected[255]; |
| 211 | int i; | 216 | int i; |
| 212 | for (i=0;i<254;i++) { | 217 | for (i=0;i<254;i++) { |
| 213 | expected[i] = i + 1; | 218 | expected[i] = i + 1; |
| 214 | } | 219 | } |
| 215 | expected[254] = 0; | 220 | expected[254] = 0; |
| 216 | expect(validator_recv_frame, | 221 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 217 | when(size, is_equal_to(255)), | 222 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 218 | when(data, is_equal_to_contents_of(expected, 255)) | ||
| 219 | ); | ||
| 220 | byte_stuffer_recv_byte(0, 0xFF); | 223 | byte_stuffer_recv_byte(0, 0xFF); |
| 221 | for (i=0;i<254;i++) { | 224 | for (i=0;i<254;i++) { |
| 222 | byte_stuffer_recv_byte(0, i+1); | 225 | byte_stuffer_recv_byte(0, i+1); |
| @@ -226,7 +229,7 @@ Ensure(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_ | |||
| 226 | byte_stuffer_recv_byte(0, 0); | 229 | byte_stuffer_recv_byte(0, 0); |
| 227 | } | 230 | } |
| 228 | 231 | ||
| 229 | Ensure(ByteStuffer, receives_two_long_frames_and_some_more) { | 232 | TEST_F(ByteStuffer, receives_two_long_frames_and_some_more) { |
| 230 | uint8_t expected[515]; | 233 | uint8_t expected[515]; |
| 231 | int i; | 234 | int i; |
| 232 | int j; | 235 | int j; |
| @@ -238,10 +241,8 @@ Ensure(ByteStuffer, receives_two_long_frames_and_some_more) { | |||
| 238 | for (i=0;i<7;i++) { | 241 | for (i=0;i<7;i++) { |
| 239 | expected[254*2+i] = i + 1; | 242 | expected[254*2+i] = i + 1; |
| 240 | } | 243 | } |
| 241 | expect(validator_recv_frame, | 244 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 242 | when(size, is_equal_to(515)), | 245 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 243 | when(data, is_equal_to_contents_of(expected, 510)) | ||
| 244 | ); | ||
| 245 | byte_stuffer_recv_byte(0, 0xFF); | 246 | byte_stuffer_recv_byte(0, 0xFF); |
| 246 | for (i=0;i<254;i++) { | 247 | for (i=0;i<254;i++) { |
| 247 | byte_stuffer_recv_byte(0, i+1); | 248 | byte_stuffer_recv_byte(0, i+1); |
| @@ -261,12 +262,10 @@ Ensure(ByteStuffer, receives_two_long_frames_and_some_more) { | |||
| 261 | byte_stuffer_recv_byte(0, 0); | 262 | byte_stuffer_recv_byte(0, 0); |
| 262 | } | 263 | } |
| 263 | 264 | ||
| 264 | Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) { | 265 | TEST_F(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) { |
| 265 | uint8_t expected[MAX_FRAME_SIZE] = {}; | 266 | uint8_t expected[MAX_FRAME_SIZE] = {}; |
| 266 | expect(validator_recv_frame, | 267 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 267 | when(size, is_equal_to(MAX_FRAME_SIZE)), | 268 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 268 | when(data, is_equal_to_contents_of(expected, MAX_FRAME_SIZE)) | ||
| 269 | ); | ||
| 270 | int i; | 269 | int i; |
| 271 | byte_stuffer_recv_byte(0, 1); | 270 | byte_stuffer_recv_byte(0, 1); |
| 272 | for(i=0;i<MAX_FRAME_SIZE;i++) { | 271 | for(i=0;i<MAX_FRAME_SIZE;i++) { |
| @@ -275,9 +274,10 @@ Ensure(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) { | |||
| 275 | byte_stuffer_recv_byte(0, 0); | 274 | byte_stuffer_recv_byte(0, 0); |
| 276 | } | 275 | } |
| 277 | 276 | ||
| 278 | Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) { | 277 | TEST_F(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) { |
| 279 | uint8_t expected[1] = {0}; | 278 | uint8_t expected[1] = {0}; |
| 280 | never_expect(validator_recv_frame); | 279 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 280 | .Times(0); | ||
| 281 | int i; | 281 | int i; |
| 282 | byte_stuffer_recv_byte(0, 1); | 282 | byte_stuffer_recv_byte(0, 1); |
| 283 | for(i=0;i<MAX_FRAME_SIZE;i++) { | 283 | for(i=0;i<MAX_FRAME_SIZE;i++) { |
| @@ -287,12 +287,10 @@ Ensure(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) { | |||
| 287 | byte_stuffer_recv_byte(0, 0); | 287 | byte_stuffer_recv_byte(0, 0); |
| 288 | } | 288 | } |
| 289 | 289 | ||
| 290 | Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) { | 290 | TEST_F(ByteStuffer, received_frame_is_aborted_when_its_too_long) { |
| 291 | uint8_t expected[1] = {1}; | 291 | uint8_t expected[1] = {1}; |
| 292 | expect(validator_recv_frame, | 292 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 293 | when(size, is_equal_to(1)), | 293 | .With(Args<1, 2>(ElementsAreArray(expected))); |
| 294 | when(data, is_equal_to_contents_of(expected, 1)) | ||
| 295 | ); | ||
| 296 | int i; | 294 | int i; |
| 297 | byte_stuffer_recv_byte(0, 1); | 295 | byte_stuffer_recv_byte(0, 1); |
| 298 | for(i=0;i<MAX_FRAME_SIZE;i++) { | 296 | for(i=0;i<MAX_FRAME_SIZE;i++) { |
| @@ -303,76 +301,68 @@ Ensure(ByteStuffer, received_frame_is_aborted_when_its_too_long) { | |||
| 303 | byte_stuffer_recv_byte(0, 0); | 301 | byte_stuffer_recv_byte(0, 0); |
| 304 | } | 302 | } |
| 305 | 303 | ||
| 306 | Ensure(ByteStuffer, does_nothing_when_sending_zero_size_frame) { | 304 | TEST_F(ByteStuffer, does_nothing_when_sending_zero_size_frame) { |
| 307 | assert_that(sent_data_size, is_equal_to(0)); | 305 | EXPECT_EQ(sent_data.size(), 0); |
| 308 | byte_stuffer_send_frame(0, NULL, 0); | 306 | byte_stuffer_send_frame(0, NULL, 0); |
| 309 | } | 307 | } |
| 310 | 308 | ||
| 311 | Ensure(ByteStuffer, send_one_byte_frame) { | 309 | TEST_F(ByteStuffer, send_one_byte_frame) { |
| 312 | uint8_t data[] = {5}; | 310 | uint8_t data[] = {5}; |
| 313 | byte_stuffer_send_frame(1, data, 1); | 311 | byte_stuffer_send_frame(1, data, 1); |
| 314 | uint8_t expected[] = {2, 5, 0}; | 312 | uint8_t expected[] = {2, 5, 0}; |
| 315 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 313 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 316 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 317 | } | 314 | } |
| 318 | 315 | ||
| 319 | Ensure(ByteStuffer, sends_two_byte_frame) { | 316 | TEST_F(ByteStuffer, sends_two_byte_frame) { |
| 320 | uint8_t data[] = {5, 0x77}; | 317 | uint8_t data[] = {5, 0x77}; |
| 321 | byte_stuffer_send_frame(0, data, 2); | 318 | byte_stuffer_send_frame(0, data, 2); |
| 322 | uint8_t expected[] = {3, 5, 0x77, 0}; | 319 | uint8_t expected[] = {3, 5, 0x77, 0}; |
| 323 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 320 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 324 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 325 | } | 321 | } |
| 326 | 322 | ||
| 327 | Ensure(ByteStuffer, sends_one_byte_frame_with_zero) { | 323 | TEST_F(ByteStuffer, sends_one_byte_frame_with_zero) { |
| 328 | uint8_t data[] = {0}; | 324 | uint8_t data[] = {0}; |
| 329 | byte_stuffer_send_frame(0, data, 1); | 325 | byte_stuffer_send_frame(0, data, 1); |
| 330 | uint8_t expected[] = {1, 1, 0}; | 326 | uint8_t expected[] = {1, 1, 0}; |
| 331 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 327 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 332 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 333 | } | 328 | } |
| 334 | 329 | ||
| 335 | Ensure(ByteStuffer, sends_two_byte_frame_starting_with_zero) { | 330 | TEST_F(ByteStuffer, sends_two_byte_frame_starting_with_zero) { |
| 336 | uint8_t data[] = {0, 9}; | 331 | uint8_t data[] = {0, 9}; |
| 337 | byte_stuffer_send_frame(1, data, 2); | 332 | byte_stuffer_send_frame(1, data, 2); |
| 338 | uint8_t expected[] = {1, 2, 9, 0}; | 333 | uint8_t expected[] = {1, 2, 9, 0}; |
| 339 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 334 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 340 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 341 | } | 335 | } |
| 342 | 336 | ||
| 343 | Ensure(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) { | 337 | TEST_F(ByteStuffer, sends_two_byte_frame_starting_with_non_zero) { |
| 344 | uint8_t data[] = {9, 0}; | 338 | uint8_t data[] = {9, 0}; |
| 345 | byte_stuffer_send_frame(1, data, 2); | 339 | byte_stuffer_send_frame(1, data, 2); |
| 346 | uint8_t expected[] = {2, 9, 1, 0}; | 340 | uint8_t expected[] = {2, 9, 1, 0}; |
| 347 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 341 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 348 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 349 | } | 342 | } |
| 350 | 343 | ||
| 351 | Ensure(ByteStuffer, sends_three_byte_frame_zero_in_the_middle) { | 344 | TEST_F(ByteStuffer, sends_three_byte_frame_zero_in_the_middle) { |
| 352 | uint8_t data[] = {9, 0, 0x68}; | 345 | uint8_t data[] = {9, 0, 0x68}; |
| 353 | byte_stuffer_send_frame(0, data, 3); | 346 | byte_stuffer_send_frame(0, data, 3); |
| 354 | uint8_t expected[] = {2, 9, 2, 0x68, 0}; | 347 | uint8_t expected[] = {2, 9, 2, 0x68, 0}; |
| 355 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 348 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 356 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 357 | } | 349 | } |
| 358 | 350 | ||
| 359 | Ensure(ByteStuffer, sends_three_byte_frame_data_in_the_middle) { | 351 | TEST_F(ByteStuffer, sends_three_byte_frame_data_in_the_middle) { |
| 360 | uint8_t data[] = {0, 0x55, 0}; | 352 | uint8_t data[] = {0, 0x55, 0}; |
| 361 | byte_stuffer_send_frame(0, data, 3); | 353 | byte_stuffer_send_frame(0, data, 3); |
| 362 | uint8_t expected[] = {1, 2, 0x55, 1, 0}; | 354 | uint8_t expected[] = {1, 2, 0x55, 1, 0}; |
| 363 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 355 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 364 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 365 | } | 356 | } |
| 366 | 357 | ||
| 367 | Ensure(ByteStuffer, sends_three_byte_frame_with_all_zeroes) { | 358 | TEST_F(ByteStuffer, sends_three_byte_frame_with_all_zeroes) { |
| 368 | uint8_t data[] = {0, 0, 0}; | 359 | uint8_t data[] = {0, 0, 0}; |
| 369 | byte_stuffer_send_frame(0, data, 3); | 360 | byte_stuffer_send_frame(0, data, 3); |
| 370 | uint8_t expected[] = {1, 1, 1, 1, 0}; | 361 | uint8_t expected[] = {1, 1, 1, 1, 0}; |
| 371 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 362 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 372 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 373 | } | 363 | } |
| 374 | 364 | ||
| 375 | Ensure(ByteStuffer, sends_frame_with_254_non_zeroes) { | 365 | TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes) { |
| 376 | uint8_t data[254]; | 366 | uint8_t data[254]; |
| 377 | int i; | 367 | int i; |
| 378 | for(i=0;i<254;i++) { | 368 | for(i=0;i<254;i++) { |
| @@ -385,11 +375,10 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes) { | |||
| 385 | expected[i] = i; | 375 | expected[i] = i; |
| 386 | } | 376 | } |
| 387 | expected[255] = 0; | 377 | expected[255] = 0; |
| 388 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 378 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 389 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 390 | } | 379 | } |
| 391 | 380 | ||
| 392 | Ensure(ByteStuffer, sends_frame_with_255_non_zeroes) { | 381 | TEST_F(ByteStuffer, sends_frame_with_255_non_zeroes) { |
| 393 | uint8_t data[255]; | 382 | uint8_t data[255]; |
| 394 | int i; | 383 | int i; |
| 395 | for(i=0;i<255;i++) { | 384 | for(i=0;i<255;i++) { |
| @@ -404,17 +393,16 @@ Ensure(ByteStuffer, sends_frame_with_255_non_zeroes) { | |||
| 404 | expected[255] = 2; | 393 | expected[255] = 2; |
| 405 | expected[256] = 255; | 394 | expected[256] = 255; |
| 406 | expected[257] = 0; | 395 | expected[257] = 0; |
| 407 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 396 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 408 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 409 | } | 397 | } |
| 410 | 398 | ||
| 411 | Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) { | 399 | TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) { |
| 412 | uint8_t data[255]; | 400 | uint8_t data[255]; |
| 413 | int i; | 401 | int i; |
| 414 | for(i=0;i<254;i++) { | 402 | for(i=0;i<254;i++) { |
| 415 | data[i] = i + 1; | 403 | data[i] = i + 1; |
| 416 | } | 404 | } |
| 417 | data[255] = 0; | 405 | data[254] = 0; |
| 418 | byte_stuffer_send_frame(0, data, 255); | 406 | byte_stuffer_send_frame(0, data, 255); |
| 419 | uint8_t expected[258]; | 407 | uint8_t expected[258]; |
| 420 | expected[0] = 0xFF; | 408 | expected[0] = 0xFF; |
| @@ -424,53 +412,46 @@ Ensure(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) { | |||
| 424 | expected[255] = 1; | 412 | expected[255] = 1; |
| 425 | expected[256] = 1; | 413 | expected[256] = 1; |
| 426 | expected[257] = 0; | 414 | expected[257] = 0; |
| 427 | assert_that(sent_data_size, is_equal_to(sizeof(expected))); | 415 | EXPECT_THAT(sent_data, ElementsAreArray(expected)); |
| 428 | assert_that(sent_data, is_equal_to_contents_of(expected, sizeof(expected))); | ||
| 429 | } | 416 | } |
| 430 | 417 | ||
| 431 | Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) { | 418 | TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) { |
| 432 | uint8_t original_data[] = { 1, 2, 3}; | 419 | uint8_t original_data[] = { 1, 2, 3}; |
| 433 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); | 420 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); |
| 434 | expect(validator_recv_frame, | 421 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 435 | when(size, is_equal_to(sizeof(original_data))), | 422 | .With(Args<1, 2>(ElementsAreArray(original_data))); |
| 436 | when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) | ||
| 437 | ); | ||
| 438 | int i; | 423 | int i; |
| 439 | for(i=0;i<sent_data_size;i++) { | 424 | for(auto& d : sent_data) { |
| 440 | byte_stuffer_recv_byte(1, sent_data[i]); | 425 | byte_stuffer_recv_byte(1, d); |
| 441 | } | 426 | } |
| 442 | } | 427 | } |
| 443 | 428 | ||
| 444 | Ensure(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) { | 429 | TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_small_packet_with_zeros) { |
| 445 | uint8_t original_data[] = { 1, 0, 3, 0, 0, 9}; | 430 | uint8_t original_data[] = { 1, 0, 3, 0, 0, 9}; |
| 446 | byte_stuffer_send_frame(1, original_data, sizeof(original_data)); | 431 | byte_stuffer_send_frame(1, original_data, sizeof(original_data)); |
| 447 | expect(validator_recv_frame, | 432 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 448 | when(size, is_equal_to(sizeof(original_data))), | 433 | .With(Args<1, 2>(ElementsAreArray(original_data))); |
| 449 | when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) | ||
| 450 | ); | ||
| 451 | int i; | 434 | int i; |
| 452 | for(i=0;i<sent_data_size;i++) { | 435 | for(auto& d : sent_data) { |
| 453 | byte_stuffer_recv_byte(0, sent_data[i]); | 436 | byte_stuffer_recv_byte(1, d); |
| 454 | } | 437 | } |
| 455 | } | 438 | } |
| 456 | 439 | ||
| 457 | Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) { | 440 | TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) { |
| 458 | uint8_t original_data[254]; | 441 | uint8_t original_data[254]; |
| 459 | int i; | 442 | int i; |
| 460 | for(i=0;i<254;i++) { | 443 | for(i=0;i<254;i++) { |
| 461 | original_data[i] = i + 1; | 444 | original_data[i] = i + 1; |
| 462 | } | 445 | } |
| 463 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); | 446 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); |
| 464 | expect(validator_recv_frame, | 447 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 465 | when(size, is_equal_to(sizeof(original_data))), | 448 | .With(Args<1, 2>(ElementsAreArray(original_data))); |
| 466 | when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) | 449 | for(auto& d : sent_data) { |
| 467 | ); | 450 | byte_stuffer_recv_byte(1, d); |
| 468 | for(i=0;i<sent_data_size;i++) { | ||
| 469 | byte_stuffer_recv_byte(1, sent_data[i]); | ||
| 470 | } | 451 | } |
| 471 | } | 452 | } |
| 472 | 453 | ||
| 473 | Ensure(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) { | 454 | TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) { |
| 474 | uint8_t original_data[256]; | 455 | uint8_t original_data[256]; |
| 475 | int i; | 456 | int i; |
| 476 | for(i=0;i<254;i++) { | 457 | for(i=0;i<254;i++) { |
| @@ -479,16 +460,14 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) { | |||
| 479 | original_data[254] = 22; | 460 | original_data[254] = 22; |
| 480 | original_data[255] = 23; | 461 | original_data[255] = 23; |
| 481 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); | 462 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); |
| 482 | expect(validator_recv_frame, | 463 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 483 | when(size, is_equal_to(sizeof(original_data))), | 464 | .With(Args<1, 2>(ElementsAreArray(original_data))); |
| 484 | when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) | 465 | for(auto& d : sent_data) { |
| 485 | ); | 466 | byte_stuffer_recv_byte(1, d); |
| 486 | for(i=0;i<sent_data_size;i++) { | ||
| 487 | byte_stuffer_recv_byte(1, sent_data[i]); | ||
| 488 | } | 467 | } |
| 489 | } | 468 | } |
| 490 | 469 | ||
| 491 | Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) { | 470 | TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) { |
| 492 | uint8_t original_data[255]; | 471 | uint8_t original_data[255]; |
| 493 | int i; | 472 | int i; |
| 494 | for(i=0;i<254;i++) { | 473 | for(i=0;i<254;i++) { |
| @@ -496,11 +475,9 @@ Ensure(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) { | |||
| 496 | } | 475 | } |
| 497 | original_data[254] = 0; | 476 | original_data[254] = 0; |
| 498 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); | 477 | byte_stuffer_send_frame(0, original_data, sizeof(original_data)); |
| 499 | expect(validator_recv_frame, | 478 | EXPECT_CALL(*this, validator_recv_frame(_, _, _)) |
| 500 | when(size, is_equal_to(sizeof(original_data))), | 479 | .With(Args<1, 2>(ElementsAreArray(original_data))); |
| 501 | when(data, is_equal_to_contents_of(original_data, sizeof(original_data))) | 480 | for(auto& d : sent_data) { |
| 502 | ); | 481 | byte_stuffer_recv_byte(1, d); |
| 503 | for(i=0;i<sent_data_size;i++) { | ||
| 504 | byte_stuffer_recv_byte(1, sent_data[i]); | ||
| 505 | } | 482 | } |
| 506 | } | 483 | } |
diff --git a/quantum/serial_link/tests/rules.mk b/quantum/serial_link/tests/rules.mk new file mode 100644 index 000000000..651f56b95 --- /dev/null +++ b/quantum/serial_link/tests/rules.mk | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | serial_link_byte_stuffer_SRC :=\ | ||
| 2 | $(SERIAL_PATH)/tests/byte_stuffer_tests.cpp \ | ||
| 3 | $(SERIAL_PATH)/protocol/byte_stuffer.c \ No newline at end of file | ||
