diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2019-10-01 10:21:12 +0900 |
commit | 93f6749e06b70ba81e15f8b77e5a18675dacddfe (patch) | |
tree | fcf75ef930800a948e5a3ba015d6759889f2284d /quantum/serial_link/tests | |
parent | da34bddba16ba7a8495dc30bfe4542551ba87ed4 (diff) |
clang-format changes
Diffstat (limited to 'quantum/serial_link/tests')
-rw-r--r-- | quantum/serial_link/tests/byte_stuffer_tests.cpp | 211 | ||||
-rw-r--r-- | quantum/serial_link/tests/frame_router_tests.cpp | 81 | ||||
-rw-r--r-- | quantum/serial_link/tests/frame_validator_tests.cpp | 45 | ||||
-rw-r--r-- | quantum/serial_link/tests/transport_tests.cpp | 28 | ||||
-rw-r--r-- | quantum/serial_link/tests/triple_buffered_object_tests.cpp | 18 |
5 files changed, 151 insertions, 232 deletions
diff --git a/quantum/serial_link/tests/byte_stuffer_tests.cpp b/quantum/serial_link/tests/byte_stuffer_tests.cpp index ff49d727bb..9e4e1768f4 100644 --- a/quantum/serial_link/tests/byte_stuffer_tests.cpp +++ b/quantum/serial_link/tests/byte_stuffer_tests.cpp @@ -33,25 +33,21 @@ extern "C" { } using testing::_; -using testing::ElementsAreArray; using testing::Args; +using testing::ElementsAreArray; -class ByteStuffer : public ::testing::Test{ -public: +class ByteStuffer : public ::testing::Test { + public: ByteStuffer() { Instance = this; init_byte_stuffer(); } - ~ByteStuffer() { - Instance = nullptr; - } + ~ByteStuffer() { Instance = nullptr; } - MOCK_METHOD3(validator_recv_frame, void (uint8_t link, uint8_t* data, uint16_t size)); + MOCK_METHOD3(validator_recv_frame, void(uint8_t link, uint8_t* data, uint16_t size)); - void send_data(uint8_t link, const uint8_t* data, uint16_t size) { - std::copy(data, data + size, std::back_inserter(sent_data)); - } + void send_data(uint8_t link, const uint8_t* data, uint16_t size) { std::copy(data, data + size, std::back_inserter(sent_data)); } std::vector<uint8_t> sent_data; static ByteStuffer* Instance; @@ -60,52 +56,42 @@ public: ByteStuffer* ByteStuffer::Instance = nullptr; extern "C" { - void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) { - ByteStuffer::Instance->validator_recv_frame(link, data, size); - } +void validator_recv_frame(uint8_t link, uint8_t* data, uint16_t size) { ByteStuffer::Instance->validator_recv_frame(link, data, size); } - void send_data(uint8_t link, const uint8_t* data, uint16_t size) { - ByteStuffer::Instance->send_data(link, data, size); - } +void send_data(uint8_t link, const uint8_t* data, uint16_t size) { ByteStuffer::Instance->send_data(link, data, size); } } TEST_F(ByteStuffer, receives_no_frame_for_a_single_zero_byte) { - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0); byte_stuffer_recv_byte(0, 0); } TEST_F(ByteStuffer, receives_no_frame_for_a_single_FF_byte) { - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0); byte_stuffer_recv_byte(0, 0xFF); } TEST_F(ByteStuffer, receives_no_frame_for_a_single_random_byte) { - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0); byte_stuffer_recv_byte(0, 0x4A); } TEST_F(ByteStuffer, receives_no_frame_for_a_zero_length_frame) { - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 0); } TEST_F(ByteStuffer, receives_single_byte_valid_frame) { uint8_t expected[] = {0x37}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 0x37); byte_stuffer_recv_byte(0, 0); } TEST_F(ByteStuffer, receives_three_bytes_valid_frame) { uint8_t expected[] = {0x37, 0x99, 0xFF}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 4); byte_stuffer_recv_byte(0, 0x37); byte_stuffer_recv_byte(0, 0x99); @@ -115,8 +101,7 @@ TEST_F(ByteStuffer, receives_three_bytes_valid_frame) { TEST_F(ByteStuffer, receives_single_zero_valid_frame) { uint8_t expected[] = {0}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 0); @@ -124,8 +109,7 @@ TEST_F(ByteStuffer, receives_single_zero_valid_frame) { TEST_F(ByteStuffer, receives_valid_frame_with_zeroes) { uint8_t expected[] = {5, 0, 3, 0}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 5); byte_stuffer_recv_byte(0, 2); @@ -134,14 +118,11 @@ TEST_F(ByteStuffer, receives_valid_frame_with_zeroes) { byte_stuffer_recv_byte(0, 0); } - TEST_F(ByteStuffer, receives_two_valid_frames) { uint8_t expected1[] = {5, 0}; uint8_t expected2[] = {3}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected1))); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected2))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected1))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected2))); byte_stuffer_recv_byte(1, 2); byte_stuffer_recv_byte(1, 5); byte_stuffer_recv_byte(1, 1); @@ -153,8 +134,7 @@ TEST_F(ByteStuffer, receives_two_valid_frames) { TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_zero) { uint8_t expected[] = {5, 7}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(1, 3); byte_stuffer_recv_byte(1, 1); byte_stuffer_recv_byte(1, 0); @@ -166,11 +146,10 @@ TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_zero) { TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) { uint8_t expected[] = {5, 7}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 9); - byte_stuffer_recv_byte(0, 4); // This should have been zero + byte_stuffer_recv_byte(0, 4); // This should have been zero byte_stuffer_recv_byte(0, 0); byte_stuffer_recv_byte(0, 3); byte_stuffer_recv_byte(0, 5); @@ -180,31 +159,29 @@ TEST_F(ByteStuffer, receives_valid_frame_after_unexpected_non_zero) { TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_and_then_end_of_frame) { uint8_t expected[254]; - int i; - for (i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { expected[i] = i + 1; } - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 0xFF); - for (i=0;i<254;i++) { - byte_stuffer_recv_byte(0, i+1); + for (i = 0; i < 254; i++) { + byte_stuffer_recv_byte(0, i + 1); } byte_stuffer_recv_byte(0, 0); } TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_non_zero) { uint8_t expected[255]; - int i; - for (i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { expected[i] = i + 1; } expected[254] = 7; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 0xFF); - for (i=0;i<254;i++) { - byte_stuffer_recv_byte(0, i+1); + for (i = 0; i < 254; i++) { + byte_stuffer_recv_byte(0, i + 1); } byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 7); @@ -213,16 +190,15 @@ TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_ TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_zero) { uint8_t expected[255]; - int i; - for (i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { expected[i] = i + 1; } expected[254] = 0; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 0xFF); - for (i=0;i<254;i++) { - byte_stuffer_recv_byte(0, i+1); + for (i = 0; i < 254; i++) { + byte_stuffer_recv_byte(0, i + 1); } byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 1); @@ -231,25 +207,24 @@ TEST_F(ByteStuffer, receives_a_valid_frame_with_over254_non_zeroes_next_byte_is_ TEST_F(ByteStuffer, receives_two_long_frames_and_some_more) { uint8_t expected[515]; - int i; - int j; - for (j=0;j<2;j++) { - for (i=0;i<254;i++) { - expected[i+254*j] = i + 1; + int i; + int j; + for (j = 0; j < 2; j++) { + for (i = 0; i < 254; i++) { + expected[i + 254 * j] = i + 1; } } - for (i=0;i<7;i++) { - expected[254*2+i] = i + 1; + for (i = 0; i < 7; i++) { + expected[254 * 2 + i] = i + 1; } - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); byte_stuffer_recv_byte(0, 0xFF); - for (i=0;i<254;i++) { - byte_stuffer_recv_byte(0, i+1); + for (i = 0; i < 254; i++) { + byte_stuffer_recv_byte(0, i + 1); } byte_stuffer_recv_byte(0, 0xFF); - for (i=0;i<254;i++) { - byte_stuffer_recv_byte(0, i+1); + for (i = 0; i < 254; i++) { + byte_stuffer_recv_byte(0, i + 1); } byte_stuffer_recv_byte(0, 8); byte_stuffer_recv_byte(0, 1); @@ -264,24 +239,22 @@ TEST_F(ByteStuffer, receives_two_long_frames_and_some_more) { TEST_F(ByteStuffer, receives_an_all_zeros_frame_that_is_maximum_size) { uint8_t expected[MAX_FRAME_SIZE] = {}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); int i; byte_stuffer_recv_byte(0, 1); - for(i=0;i<MAX_FRAME_SIZE;i++) { - byte_stuffer_recv_byte(0, 1); + for (i = 0; i < MAX_FRAME_SIZE; i++) { + byte_stuffer_recv_byte(0, 1); } byte_stuffer_recv_byte(0, 0); } TEST_F(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) { uint8_t expected[1] = {0}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).Times(0); int i; byte_stuffer_recv_byte(0, 1); - for(i=0;i<MAX_FRAME_SIZE;i++) { - byte_stuffer_recv_byte(0, 1); + for (i = 0; i < MAX_FRAME_SIZE; i++) { + byte_stuffer_recv_byte(0, 1); } byte_stuffer_recv_byte(0, 1); byte_stuffer_recv_byte(0, 0); @@ -289,12 +262,11 @@ TEST_F(ByteStuffer, doesnt_recv_a_frame_thats_too_long_all_zeroes) { TEST_F(ByteStuffer, received_frame_is_aborted_when_its_too_long) { uint8_t expected[1] = {1}; - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); int i; byte_stuffer_recv_byte(0, 1); - for(i=0;i<MAX_FRAME_SIZE;i++) { - byte_stuffer_recv_byte(0, 1); + for (i = 0; i < MAX_FRAME_SIZE; i++) { + byte_stuffer_recv_byte(0, 1); } byte_stuffer_recv_byte(0, 2); byte_stuffer_recv_byte(0, 1); @@ -364,14 +336,14 @@ TEST_F(ByteStuffer, sends_three_byte_frame_with_all_zeroes) { TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes) { uint8_t data[254]; - int i; - for(i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { data[i] = i + 1; } byte_stuffer_send_frame(0, data, 254); uint8_t expected[256]; expected[0] = 0xFF; - for(i=1;i<255;i++) { + for (i = 1; i < 255; i++) { expected[i] = i; } expected[255] = 0; @@ -380,14 +352,14 @@ TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes) { TEST_F(ByteStuffer, sends_frame_with_255_non_zeroes) { uint8_t data[255]; - int i; - for(i=0;i<255;i++) { + int i; + for (i = 0; i < 255; i++) { data[i] = i + 1; } byte_stuffer_send_frame(0, data, 255); uint8_t expected[258]; expected[0] = 0xFF; - for(i=1;i<255;i++) { + for (i = 1; i < 255; i++) { expected[i] = i; } expected[255] = 2; @@ -398,15 +370,15 @@ TEST_F(ByteStuffer, sends_frame_with_255_non_zeroes) { TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) { uint8_t data[255]; - int i; - for(i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { data[i] = i + 1; } data[254] = 0; byte_stuffer_send_frame(0, data, 255); uint8_t expected[258]; expected[0] = 0xFF; - for(i=1;i<255;i++) { + for (i = 1; i < 255; i++) { expected[i] = i; } expected[255] = 1; @@ -416,68 +388,63 @@ TEST_F(ByteStuffer, sends_frame_with_254_non_zeroes_followed_by_zero) { } TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_small_packet) { - uint8_t original_data[] = { 1, 2, 3}; + uint8_t original_data[] = {1, 2, 3}; byte_stuffer_send_frame(0, original_data, sizeof(original_data)); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(original_data))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data))); int i; - for(auto& d : sent_data) { - byte_stuffer_recv_byte(1, d); + for (auto& d : sent_data) { + byte_stuffer_recv_byte(1, d); } } TEST_F(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}; byte_stuffer_send_frame(1, original_data, sizeof(original_data)); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(original_data))); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data))); int i; - for(auto& d : sent_data) { - byte_stuffer_recv_byte(1, d); + for (auto& d : sent_data) { + byte_stuffer_recv_byte(1, d); } } TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes) { uint8_t original_data[254]; - int i; - for(i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { original_data[i] = i + 1; } byte_stuffer_send_frame(0, original_data, sizeof(original_data)); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(original_data))); - for(auto& d : sent_data) { - byte_stuffer_recv_byte(1, d); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data))); + for (auto& d : sent_data) { + byte_stuffer_recv_byte(1, d); } } TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_256_bytes) { uint8_t original_data[256]; - int i; - for(i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { original_data[i] = i + 1; } original_data[254] = 22; original_data[255] = 23; byte_stuffer_send_frame(0, original_data, sizeof(original_data)); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(original_data))); - for(auto& d : sent_data) { - byte_stuffer_recv_byte(1, d); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data))); + for (auto& d : sent_data) { + byte_stuffer_recv_byte(1, d); } } TEST_F(ByteStuffer, sends_and_receives_full_roundtrip_254_bytes_and_then_zero) { uint8_t original_data[255]; - int i; - for(i=0;i<254;i++) { + int i; + for (i = 0; i < 254; i++) { original_data[i] = i + 1; } original_data[254] = 0; byte_stuffer_send_frame(0, original_data, sizeof(original_data)); - EXPECT_CALL(*this, validator_recv_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(original_data))); - for(auto& d : sent_data) { - byte_stuffer_recv_byte(1, d); + EXPECT_CALL(*this, validator_recv_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(original_data))); + for (auto& d : sent_data) { + byte_stuffer_recv_byte(1, d); } } diff --git a/quantum/serial_link/tests/frame_router_tests.cpp b/quantum/serial_link/tests/frame_router_tests.cpp index 2bd5bf830d..f76dfb33d6 100644 --- a/quantum/serial_link/tests/frame_router_tests.cpp +++ b/quantum/serial_link/tests/frame_router_tests.cpp @@ -26,27 +26,23 @@ SOFTWARE. #include "gmock/gmock.h" #include <array> extern "C" { - #include "serial_link/protocol/transport.h" - #include "serial_link/protocol/byte_stuffer.h" - #include "serial_link/protocol/frame_router.h" +#include "serial_link/protocol/transport.h" +#include "serial_link/protocol/byte_stuffer.h" +#include "serial_link/protocol/frame_router.h" } using testing::_; -using testing::ElementsAreArray; using testing::Args; +using testing::ElementsAreArray; class FrameRouter : public testing::Test { -public: - FrameRouter() : - current_router_buffer(nullptr) - { + public: + FrameRouter() : current_router_buffer(nullptr) { Instance = this; init_byte_stuffer(); } - ~FrameRouter() { - Instance = nullptr; - } + ~FrameRouter() { Instance = nullptr; } void send_data(uint8_t link, const uint8_t* data, uint16_t size) { auto& buffer = current_router_buffer->send_buffers[link]; @@ -55,31 +51,26 @@ public: void receive_data(uint8_t link, uint8_t* data, uint16_t size) { int i; - for(i=0;i<size;i++) { + for (i = 0; i < size; i++) { byte_stuffer_recv_byte(link, data[i]); } } void activate_router(uint8_t num) { current_router_buffer = router_buffers + num; - router_set_master(num==0); + router_set_master(num == 0); } void simulate_transport(uint8_t from, uint8_t to) { - activate_router(to); - if (from > to) { - receive_data(DOWN_LINK, - router_buffers[from].send_buffers[UP_LINK].data(), - router_buffers[from].send_buffers[UP_LINK].size()); - } - else if(to > from) { - receive_data(UP_LINK, - router_buffers[from].send_buffers[DOWN_LINK].data(), - router_buffers[from].send_buffers[DOWN_LINK].size()); - } + activate_router(to); + if (from > to) { + receive_data(DOWN_LINK, router_buffers[from].send_buffers[UP_LINK].data(), router_buffers[from].send_buffers[UP_LINK].size()); + } else if (to > from) { + receive_data(UP_LINK, router_buffers[from].send_buffers[DOWN_LINK].data(), router_buffers[from].send_buffers[DOWN_LINK].size()); + } } - MOCK_METHOD3(transport_recv_frame, void (uint8_t from, uint8_t* data, uint16_t size)); + MOCK_METHOD3(transport_recv_frame, void(uint8_t from, uint8_t* data, uint16_t size)); std::vector<uint8_t> received_data; @@ -87,7 +78,7 @@ public: std::vector<uint8_t> send_buffers[2]; }; - router_buffer router_buffers[8]; + router_buffer router_buffers[8]; router_buffer* current_router_buffer; static FrameRouter* Instance; @@ -95,22 +86,15 @@ public: FrameRouter* FrameRouter::Instance = nullptr; - typedef struct { std::array<uint8_t, 4> data; - uint8_t extra[16]; + uint8_t extra[16]; } frame_buffer_t; - extern "C" { - void send_data(uint8_t link, const uint8_t* data, uint16_t size) { - FrameRouter::Instance->send_data(link, data, size); - } +void send_data(uint8_t link, const uint8_t* data, uint16_t size) { FrameRouter::Instance->send_data(link, data, size); } - - void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) { - FrameRouter::Instance->transport_recv_frame(from, data, size); - } +void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) { FrameRouter::Instance->transport_recv_frame(from, data, size); } } TEST_F(FrameRouter, master_broadcast_is_received_by_everyone) { @@ -120,14 +104,12 @@ TEST_F(FrameRouter, master_broadcast_is_received_by_everyone) { router_send_frame(0xFF, (uint8_t*)&data, 4); EXPECT_GT(router_buffers[0].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(0, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(0, 1); EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(0, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(1, 2); EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0); @@ -145,14 +127,12 @@ TEST_F(FrameRouter, master_send_is_received_by_targets) { EXPECT_GT(router_buffers[1].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[1].send_buffers[UP_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(0, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(1, 2); EXPECT_GT(router_buffers[2].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[2].send_buffers[UP_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(0, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(0, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(2, 3); EXPECT_GT(router_buffers[3].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[3].send_buffers[UP_LINK].size(), 0); @@ -166,8 +146,7 @@ TEST_F(FrameRouter, first_link_sends_to_master) { EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0); EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(1, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(1, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(1, 0); EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0); @@ -185,8 +164,7 @@ TEST_F(FrameRouter, second_link_sends_to_master) { EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0); EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(2, _, _)) - .With(Args<1, 2>(ElementsAreArray(data.data))); + EXPECT_CALL(*this, transport_recv_frame(2, _, _)).With(Args<1, 2>(ElementsAreArray(data.data))); simulate_transport(1, 0); EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0); EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0); @@ -218,12 +196,9 @@ TEST_F(FrameRouter, master_receives_on_uplink_does_nothing) { EXPECT_GT(router_buffers[1].send_buffers[UP_LINK].size(), 0); EXPECT_EQ(router_buffers[1].send_buffers[DOWN_LINK].size(), 0); - EXPECT_CALL(*this, transport_recv_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, transport_recv_frame(_, _, _)).Times(0); activate_router(0); - receive_data(UP_LINK, - router_buffers[1].send_buffers[UP_LINK].data(), - router_buffers[1].send_buffers[UP_LINK].size()); + receive_data(UP_LINK, router_buffers[1].send_buffers[UP_LINK].data(), router_buffers[1].send_buffers[UP_LINK].size()); EXPECT_EQ(router_buffers[0].send_buffers[UP_LINK].size(), 0); EXPECT_EQ(router_buffers[0].send_buffers[DOWN_LINK].size(), 0); } diff --git a/quantum/serial_link/tests/frame_validator_tests.cpp b/quantum/serial_link/tests/frame_validator_tests.cpp index 9223af83b0..43dc57b633 100644 --- a/quantum/serial_link/tests/frame_validator_tests.cpp +++ b/quantum/serial_link/tests/frame_validator_tests.cpp @@ -29,21 +29,17 @@ extern "C" { } using testing::_; -using testing::ElementsAreArray; using testing::Args; +using testing::ElementsAreArray; class FrameValidator : public testing::Test { -public: - FrameValidator() { - Instance = this; - } + public: + FrameValidator() { Instance = this; } - ~FrameValidator() { - Instance = nullptr; - } + ~FrameValidator() { Instance = nullptr; } - MOCK_METHOD3(route_incoming_frame, void (uint8_t link, uint8_t* data, uint16_t size)); - MOCK_METHOD3(byte_stuffer_send_frame, void (uint8_t link, uint8_t* data, uint16_t size)); + MOCK_METHOD3(route_incoming_frame, void(uint8_t link, uint8_t* data, uint16_t size)); + MOCK_METHOD3(byte_stuffer_send_frame, void(uint8_t link, uint8_t* data, uint16_t size)); static FrameValidator* Instance; }; @@ -51,18 +47,13 @@ public: FrameValidator* FrameValidator::Instance = nullptr; extern "C" { -void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { - FrameValidator::Instance->route_incoming_frame(link, data, size); -} +void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->route_incoming_frame(link, data, size); } -void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) { - FrameValidator::Instance->byte_stuffer_send_frame(link, data, size); -} +void byte_stuffer_send_frame(uint8_t link, uint8_t* data, uint16_t size) { FrameValidator::Instance->byte_stuffer_send_frame(link, data, size); } } TEST_F(FrameValidator, doesnt_validate_frames_under_5_bytes) { - EXPECT_CALL(*this, route_incoming_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0); uint8_t data[] = {1, 2}; validator_recv_frame(0, 0, 1); validator_recv_frame(0, data, 2); @@ -72,44 +63,38 @@ TEST_F(FrameValidator, doesnt_validate_frames_under_5_bytes) { TEST_F(FrameValidator, validates_one_byte_frame_with_correct_crc) { uint8_t data[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; - EXPECT_CALL(*this, route_incoming_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(data, 1))); + EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 1))); validator_recv_frame(0, data, 5); } TEST_F(FrameValidator, does_not_validate_one_byte_frame_with_incorrect_crc) { uint8_t data[] = {0x44, 0, 0, 0, 0}; - EXPECT_CALL(*this, route_incoming_frame(_, _, _)) - .Times(0); + EXPECT_CALL(*this, route_incoming_frame(_, _, _)).Times(0); validator_recv_frame(1, data, 5); } TEST_F(FrameValidator, validates_four_byte_frame_with_correct_crc) { uint8_t data[] = {0x44, 0x10, 0xFF, 0x00, 0x74, 0x4E, 0x30, 0xBA}; - EXPECT_CALL(*this, route_incoming_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(data, 4))); + EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 4))); validator_recv_frame(1, data, 8); } TEST_F(FrameValidator, validates_five_byte_frame_with_correct_crc) { uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; - EXPECT_CALL(*this, route_incoming_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(data, 5))); + EXPECT_CALL(*this, route_incoming_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(data, 5))); validator_recv_frame(0, data, 9); } TEST_F(FrameValidator, sends_one_byte_with_correct_crc) { uint8_t original[] = {0x44, 0, 0, 0, 0}; uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3}; - EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); validator_send_frame(0, original, 1); } TEST_F(FrameValidator, sends_five_bytes_with_correct_crc) { uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0}; uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47}; - EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)) - .With(Args<1, 2>(ElementsAreArray(expected))); + EXPECT_CALL(*this, byte_stuffer_send_frame(_, _, _)).With(Args<1, 2>(ElementsAreArray(expected))); validator_send_frame(0, original, 5); } diff --git a/quantum/serial_link/tests/transport_tests.cpp b/quantum/serial_link/tests/transport_tests.cpp index 21b7b165f6..cfd1110460 100644 --- a/quantum/serial_link/tests/transport_tests.cpp +++ b/quantum/serial_link/tests/transport_tests.cpp @@ -26,8 +26,8 @@ SOFTWARE. #include "gmock/gmock.h" using testing::_; -using testing::ElementsAreArray; using testing::Args; +using testing::ElementsAreArray; extern "C" { #include "serial_link/protocol/transport.h" @@ -53,7 +53,7 @@ static remote_object_t* test_remote_objects[] = { }; class Transport : public testing::Test { -public: + public: Transport() { Instance = this; add_remote_objects(test_remote_objects, sizeof(test_remote_objects) / sizeof(remote_object_t*)); @@ -64,8 +64,8 @@ public: reinitialize_serial_link_transport(); } - MOCK_METHOD0(signal_data_written, void ()); - MOCK_METHOD1(router_send_frame, void (uint8_t destination)); + MOCK_METHOD0(signal_data_written, void()); + MOCK_METHOD1(router_send_frame, void(uint8_t destination)); void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) { router_send_frame(destination); @@ -80,13 +80,9 @@ public: Transport* Transport::Instance = nullptr; extern "C" { -void signal_data_written(void) { - Transport::Instance->signal_data_written(); -} +void signal_data_written(void) { Transport::Instance->signal_data_written(); } -void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) { - Transport::Instance->router_send_frame(destination, data, size); -} +void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) { Transport::Instance->router_send_frame(destination, data, size); } } TEST_F(Transport, write_to_local_signals_an_event) { @@ -104,7 +100,7 @@ TEST_F(Transport, write_to_local_signals_an_event) { TEST_F(Transport, writes_from_master_to_all_slaves) { update_transport(); test_object1* obj = begin_write_master_to_slave(); - obj->test = 5; + obj->test = 5; EXPECT_CALL(*this, signal_data_written()); end_write_master_to_slave(); EXPECT_CALL(*this, router_send_frame(0xFF)); @@ -118,7 +114,7 @@ TEST_F(Transport, writes_from_master_to_all_slaves) { TEST_F(Transport, writes_from_slave_to_master) { update_transport(); test_object1* obj = begin_write_slave_to_master(); - obj->test = 7; + obj->test = 7; EXPECT_CALL(*this, signal_data_written()); end_write_slave_to_master(); EXPECT_CALL(*this, router_send_frame(0)); @@ -133,7 +129,7 @@ TEST_F(Transport, writes_from_slave_to_master) { TEST_F(Transport, writes_from_master_to_single_slave) { update_transport(); test_object1* obj = begin_write_master_to_single_slave(3); - obj->test = 7; + obj->test = 7; EXPECT_CALL(*this, signal_data_written()); end_write_master_to_single_slave(3); EXPECT_CALL(*this, router_send_frame(4)); @@ -147,7 +143,7 @@ TEST_F(Transport, writes_from_master_to_single_slave) { TEST_F(Transport, ignores_object_with_invalid_id) { update_transport(); test_object1* obj = begin_write_master_to_single_slave(3); - obj->test = 7; + obj->test = 7; EXPECT_CALL(*this, signal_data_written()); end_write_master_to_single_slave(3); EXPECT_CALL(*this, router_send_frame(4)); @@ -161,7 +157,7 @@ TEST_F(Transport, ignores_object_with_invalid_id) { TEST_F(Transport, ignores_object_with_size_too_small) { update_transport(); test_object1* obj = begin_write_master_to_slave(); - obj->test = 7; + obj->test = 7; EXPECT_CALL(*this, signal_data_written()); end_write_master_to_slave(); EXPECT_CALL(*this, router_send_frame(_)); @@ -175,7 +171,7 @@ TEST_F(Transport, ignores_object_with_size_too_small) { TEST_F(Transport, ignores_object_with_size_too_big) { update_transport(); test_object1* obj = begin_write_master_to_slave(); - obj->test = 7; + obj->test = 7; EXPECT_CALL(*this, signal_data_written()); end_write_master_to_slave(); EXPECT_CALL(*this, router_send_frame(_)); diff --git a/quantum/serial_link/tests/triple_buffered_object_tests.cpp b/quantum/serial_link/tests/triple_buffered_object_tests.cpp index 7724bbee9c..8de9bfdebf 100644 --- a/quantum/serial_link/tests/triple_buffered_object_tests.cpp +++ b/quantum/serial_link/tests/triple_buffered_object_tests.cpp @@ -27,18 +27,16 @@ extern "C" { #include "serial_link/protocol/triple_buffered_object.h" } -struct test_object{ - uint8_t state; +struct test_object { + uint8_t state; uint32_t buffer[3]; }; test_object test_object; class TripleBufferedObject : public testing::Test { -public: - TripleBufferedObject() { - triple_buffer_init((triple_buffer_object_t*)&test_object); - } + public: + TripleBufferedObject() { triple_buffer_init((triple_buffer_object_t*)&test_object); } }; TEST_F(TripleBufferedObject, writes_and_reads_object) { @@ -47,9 +45,7 @@ TEST_F(TripleBufferedObject, writes_and_reads_object) { EXPECT_EQ(*triple_buffer_read(&test_object), 0x3456ABCC); } -TEST_F(TripleBufferedObject, does_not_read_empty) { - EXPECT_EQ(triple_buffer_read(&test_object), nullptr); -} +TEST_F(TripleBufferedObject, does_not_read_empty) { EXPECT_EQ(triple_buffer_read(&test_object), nullptr); } TEST_F(TripleBufferedObject, writes_twice_and_reads_object) { *triple_buffer_begin_write(&test_object) = 0x3456ABCC; @@ -62,7 +58,7 @@ TEST_F(TripleBufferedObject, writes_twice_and_reads_object) { TEST_F(TripleBufferedObject, performs_another_write_in_the_middle_of_read) { *triple_buffer_begin_write(&test_object) = 1; triple_buffer_end_write(&test_object); - uint32_t* read = triple_buffer_read(&test_object); + uint32_t* read = triple_buffer_read(&test_object); *triple_buffer_begin_write(&test_object) = 2; triple_buffer_end_write(&test_object); EXPECT_EQ(*read, 1); @@ -73,7 +69,7 @@ TEST_F(TripleBufferedObject, performs_another_write_in_the_middle_of_read) { TEST_F(TripleBufferedObject, performs_two_writes_in_the_middle_of_read) { *triple_buffer_begin_write(&test_object) = 1; triple_buffer_end_write(&test_object); - uint32_t* read = triple_buffer_read(&test_object); + uint32_t* read = triple_buffer_read(&test_object); *triple_buffer_begin_write(&test_object) = 2; triple_buffer_end_write(&test_object); *triple_buffer_begin_write(&test_object) = 3; |