diff options
author | skullY <skullydazed@gmail.com> | 2019-08-30 11:19:03 -0700 |
---|---|---|
committer | skullydazed <skullydazed@users.noreply.github.com> | 2019-08-30 15:01:52 -0700 |
commit | b624f32f944acdc59dcb130674c09090c5c404cb (patch) | |
tree | bc13adbba137d122d9a2c2fb2fafcbb08ac10e25 /quantum/serial_link/tests/frame_router_tests.cpp | |
parent | 61af76a10d00aba185b8338604171de490a13e3b (diff) | |
download | qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.tar.gz qmk_firmware-b624f32f944acdc59dcb130674c09090c5c404cb.zip |
clang-format changes
Diffstat (limited to 'quantum/serial_link/tests/frame_router_tests.cpp')
-rw-r--r-- | quantum/serial_link/tests/frame_router_tests.cpp | 81 |
1 files changed, 28 insertions, 53 deletions
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); } |