diff options
| author | Fred Sundvik <fsundvik@gmail.com> | 2016-08-27 13:54:16 +0300 |
|---|---|---|
| committer | Fred Sundvik <fsundvik@gmail.com> | 2016-08-27 21:57:49 +0300 |
| commit | b3eba797af74ace19b9f2e762bdd33d9449e3f94 (patch) | |
| tree | e45e127534e60318d034a2b1c06f80b479088b64 /quantum/serial_link/tests/frame_validator_tests.c | |
| parent | cdd0913bcc63334fa20f1a7bd46bdce4d4f2843b (diff) | |
| download | qmk_firmware-b3eba797af74ace19b9f2e762bdd33d9449e3f94.tar.gz qmk_firmware-b3eba797af74ace19b9f2e762bdd33d9449e3f94.zip | |
Convert frame_validator_tests to GTest
Diffstat (limited to 'quantum/serial_link/tests/frame_validator_tests.c')
| -rw-r--r-- | quantum/serial_link/tests/frame_validator_tests.c | 101 |
1 files changed, 0 insertions, 101 deletions
diff --git a/quantum/serial_link/tests/frame_validator_tests.c b/quantum/serial_link/tests/frame_validator_tests.c deleted file mode 100644 index d20947e2c..000000000 --- a/quantum/serial_link/tests/frame_validator_tests.c +++ /dev/null | |||
| @@ -1,101 +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 <cgreen/cgreen.h> | ||
| 26 | #include <cgreen/mocks.h> | ||
| 27 | #include "serial_link/protocol/frame_validator.c" | ||
| 28 | |||
| 29 | void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { | ||
| 30 | mock(data, size); | ||
| 31 | } | ||
| 32 | |||
| 33 | void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) { | ||
| 34 | mock(data, size); | ||
| 35 | } | ||
| 36 | |||
| 37 | Describe(FrameValidator); | ||
| 38 | BeforeEach(FrameValidator) {} | ||
| 39 | AfterEach(FrameValidator) {} | ||
| 40 | |||
| 41 | Ensure(FrameValidator, doesnt_validate_frames_under_5_bytes) { | ||
| 42 | never_expect(route_incoming_frame); | ||
| 43 | uint8_t data[] = {1, 2}; | ||
| 44 | validator_recv_frame(0, 0, 1); | ||
| 45 | validator_recv_frame(0, data, 2); | ||
| 46 | validator_recv_frame(0, data, 3); | ||
| 47 | validator_recv_frame(0, data, 4); | ||
| 48 | } | ||
| 49 | |||
| 50 | Ensure(FrameValidator, validates_one_byte_frame_with_correct_crc) { | ||
| 51 | uint8_t data[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; | ||
| 52 | expect(route_incoming_frame, | ||
| 53 | when(size, is_equal_to(1)), | ||
| 54 | when(data, is_equal_to_contents_of(data, 1)) | ||
| 55 | ); | ||
| 56 | validator_recv_frame(0, data, 5); | ||
| 57 | } | ||
| 58 | |||
| 59 | Ensure(FrameValidator, does_not_validate_one_byte_frame_with_incorrect_crc) { | ||
| 60 | uint8_t data[] = {0x44, 0, 0, 0, 0}; | ||
| 61 | never_expect(route_incoming_frame); | ||
| 62 | validator_recv_frame(1, data, 5); | ||
| 63 | } | ||
| 64 | |||
| 65 | Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) { | ||
| 66 | uint8_t data[] = {0x44, 0x10, 0xFF, 0x00, 0x74, 0x4E, 0x30, 0xBA}; | ||
| 67 | expect(route_incoming_frame, | ||
| 68 | when(size, is_equal_to(4)), | ||
| 69 | when(data, is_equal_to_contents_of(data, 4)) | ||
| 70 | ); | ||
| 71 | validator_recv_frame(1, data, 8); | ||
| 72 | } | ||
| 73 | |||
| 74 | Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) { | ||
| 75 | uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; | ||
| 76 | expect(route_incoming_frame, | ||
| 77 | when(size, is_equal_to(5)), | ||
| 78 | when(data, is_equal_to_contents_of(data, 5)) | ||
| 79 | ); | ||
| 80 | validator_recv_frame(0, data, 9); | ||
| 81 | } | ||
| 82 | |||
| 83 | Ensure(FrameValidator, sends_one_byte_with_correct_crc) { | ||
| 84 | uint8_t original[] = {0x44, 0, 0, 0, 0}; | ||
| 85 | uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; | ||
| 86 | expect(byte_stuffer_send_frame, | ||
| 87 | when(size, is_equal_to(sizeof(expected))), | ||
| 88 | when(data, is_equal_to_contents_of(expected, sizeof(expected))) | ||
| 89 | ); | ||
| 90 | validator_send_frame(0, original, 1); | ||
| 91 | } | ||
| 92 | |||
| 93 | Ensure(FrameValidator, sends_five_bytes_with_correct_crc) { | ||
| 94 | uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0}; | ||
| 95 | uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; | ||
| 96 | expect(byte_stuffer_send_frame, | ||
| 97 | when(size, is_equal_to(sizeof(expected))), | ||
| 98 | when(data, is_equal_to_contents_of(expected, sizeof(expected))) | ||
| 99 | ); | ||
| 100 | validator_send_frame(0, original, 5); | ||
| 101 | } | ||
