diff options
Diffstat (limited to 'quantum/serial_link/tests/frame_validator_tests.cpp')
-rw-r--r-- | quantum/serial_link/tests/frame_validator_tests.cpp | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/quantum/serial_link/tests/frame_validator_tests.cpp b/quantum/serial_link/tests/frame_validator_tests.cpp deleted file mode 100644 index 43dc57b63..000000000 --- a/quantum/serial_link/tests/frame_validator_tests.cpp +++ /dev/null | |||
@@ -1,100 +0,0 @@ | |||
1 | /* | ||
2 | The MIT License (MIT) | ||
3 | |||
4 | Copyright (c) 2016 Fred Sundvik | ||
5 | |||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | of this software and associated documentation files (the "Software"), to deal | ||
8 | in the Software without restriction, including without limitation the rights | ||
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | copies of the Software, and to permit persons to whom the Software is | ||
11 | furnished to do so, subject to the following conditions: | ||
12 | |||
13 | The above copyright notice and this permission notice shall be included in all | ||
14 | copies or substantial portions of the Software. | ||
15 | |||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
22 | SOFTWARE. | ||
23 | */ | ||
24 | |||
25 | #include "gtest/gtest.h" | ||
26 | #include "gmock/gmock.h" | ||
27 | extern "C" { | ||
28 | #include "serial_link/protocol/frame_validator.h" | ||
29 | } | ||
30 | |||
31 | using testing::_; | ||
32 | using testing::Args; | ||
33 | using testing::ElementsAreArray; | ||
34 | |||
35 | class FrameValidator : public testing::Test { | ||
36 | public: | ||
37 | FrameValidator() { Instance = this; } | ||
38 | |||
39 | ~FrameValidator() { Instance = nullptr; } | ||
40 | |||
41 | MOCK_METHOD3(route_incoming_frame, void(uint8_t link, uint8_t* data, uint16_t size)); | ||
42 | MOCK_METHOD3(byte_stuffer_send_frame, void(uint8_t link, uint8_t* data, uint16_t size)); | ||
43 | |||
44 | static FrameValidator* Instance; | ||
45 | }; | ||
46 | |||
47 | FrameValidator* FrameValidator::Instance = nullptr; | ||
48 | |||
49 | extern "C" { | ||
50 | void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->route_incoming_frame(link, data, size); } | ||
51 | |||
52 | void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->byte_stuffer_send_frame(link, data, size); } | ||
53 | } | ||
54 | |||
55 | TEST_F(FrameValidator, doesnt_validate_frames_under_5_bytes) { | ||
56 | EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0); | ||
57 | uint8_t data[] = {1, 2}; | ||
58 | validator_recv_frame(0, 0, 1); | ||
59 | validator_recv_frame(0, data, 2); | ||
60 | validator_recv_frame(0, data, 3); | ||
61 | validator_recv_frame(0, data, 4); | ||
62 | } | ||
63 | |||
64 | TEST_F(FrameValidator, validates_one_byte_frame_with_correct_crc) { | ||
65 | uint8_t data[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; | ||
66 | EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 1))); | ||
67 | validator_recv_frame(0, data, 5); | ||
68 | } | ||
69 | |||
70 | TEST_F(FrameValidator, does_not_validate_one_byte_frame_with_incorrect_crc) { | ||
71 | uint8_t data[] = {0x44, 0, 0, 0, 0}; | ||
72 | EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0); | ||
73 | validator_recv_frame(1, data, 5); | ||
74 | } | ||
75 | |||
76 | TEST_F(FrameValidator, validates_four_byte_frame_with_correct_crc) { | ||
77 | uint8_t data[] = {0x44, 0x10, 0xFF, 0x00, 0x74, 0x4E, 0x30, 0xBA}; | ||
78 | EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 4))); | ||
79 | validator_recv_frame(1, data, 8); | ||
80 | } | ||
81 | |||
82 | TEST_F(FrameValidator, validates_five_byte_frame_with_correct_crc) { | ||
83 | uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; | ||
84 | EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 5))); | ||
85 | validator_recv_frame(0, data, 9); | ||
86 | } | ||
87 | |||
88 | TEST_F(FrameValidator, sends_one_byte_with_correct_crc) { | ||
89 | uint8_t original[] = {0x44, 0, 0, 0, 0}; | ||
90 | uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; | ||
91 | EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); | ||
92 | validator_send_frame(0, original, 1); | ||
93 | } | ||
94 | |||
95 | TEST_F(FrameValidator, sends_five_bytes_with_correct_crc) { | ||
96 | uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0}; | ||
97 | uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; | ||
98 | EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); | ||
99 | validator_send_frame(0, original, 5); | ||
100 | } | ||