Skip to content

Commit

Permalink
chore: fix coverage and macos build
Browse files Browse the repository at this point in the history
  • Loading branch information
daantimmer committed Oct 20, 2023
1 parent 6ee6085 commit 8aac2ec
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 39 deletions.
39 changes: 20 additions & 19 deletions services/util/SerialCommunicationLoopback.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#include "services/util/SerialCommunicationLoopback.hpp"
#include "hal/interfaces/SerialCommunication.hpp"
#include "infra/event/EventDispatcher.hpp"

namespace services
{
SerialCommunicationLoopbackPeer::SerialCommunicationLoopbackPeer(SerialCommunicationLoopbackPeer& other)
: other{ other }
SerialCommunicationLoopback::SerialCommunicationLoopback()
: server(&client)
, client(&server)
{}

hal::SerialCommunication& SerialCommunicationLoopback::Server()
{
return server;
}

hal::SerialCommunication& SerialCommunicationLoopback::Client()
{
return client;
}

SerialCommunicationLoopback::SerialCommunicationLoopbackPeer::SerialCommunicationLoopbackPeer(SerialCommunicationLoopbackPeer* other)
: other{ *other }
{}

void SerialCommunicationLoopbackPeer::SendData(infra::ConstByteRange data, infra::Function<void()> actionOnCompletion)
void SerialCommunicationLoopback::SerialCommunicationLoopbackPeer::SendData(infra::ConstByteRange data, infra::Function<void()> actionOnCompletion)
{
this->data = data;
this->actionOnCompletion = actionOnCompletion;
Expand All @@ -19,23 +35,8 @@ namespace services
});
}

void SerialCommunicationLoopbackPeer::ReceiveData(infra::Function<void(infra::ConstByteRange data)> dataReceived)
void SerialCommunicationLoopback::SerialCommunicationLoopbackPeer::ReceiveData(infra::Function<void(infra::ConstByteRange data)> dataReceived)
{
this->dataReceived = dataReceived;
}

SerialCommunicationLoopback::SerialCommunicationLoopback()
: server(client)
, client(server)
{}

SerialCommunicationLoopbackPeer& SerialCommunicationLoopback::Server()
{
return server;
}

SerialCommunicationLoopbackPeer& SerialCommunicationLoopback::Client()
{
return client;
}
}
40 changes: 22 additions & 18 deletions services/util/SerialCommunicationLoopback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@

namespace services
{
class SerialCommunicationLoopbackPeer
: public hal::SerialCommunication
{
public:
explicit SerialCommunicationLoopbackPeer(SerialCommunicationLoopbackPeer& other);

void SendData(infra::ConstByteRange data, infra::Function<void()> actionOnCompletion) override;
void ReceiveData(infra::Function<void(infra::ConstByteRange data)> dataReceived) override;

private:
SerialCommunicationLoopbackPeer& other;

infra::ConstByteRange data;
infra::Function<void()> actionOnCompletion;
infra::Function<void(infra::ConstByteRange data)> dataReceived;
};

class SerialCommunicationLoopback
{
public:
SerialCommunicationLoopback();

SerialCommunicationLoopbackPeer& Server();
SerialCommunicationLoopbackPeer& Client();
hal::SerialCommunication& Server();
hal::SerialCommunication& Client();

private:
class SerialCommunicationLoopbackPeer
: public hal::SerialCommunication
{
public:
// pointer instead of reference to avoid defining a copy constructor
// pass by reference generates a warning with clang and -Wunitialized
explicit SerialCommunicationLoopbackPeer(SerialCommunicationLoopbackPeer* other);

void SendData(infra::ConstByteRange data, infra::Function<void()> actionOnCompletion) override;
void ReceiveData(infra::Function<void(infra::ConstByteRange data)> dataReceived) override;

private:
SerialCommunicationLoopbackPeer& other;

infra::ConstByteRange data;
infra::Function<void()> actionOnCompletion;
infra::Function<void(infra::ConstByteRange data)> dataReceived;
};

private:
SerialCommunicationLoopbackPeer server;
Expand Down
5 changes: 3 additions & 2 deletions services/util/test/TestSerialCommunicationLoopback.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "hal/interfaces/SerialCommunication.hpp"
#include "infra/event/test_helper/EventDispatcherFixture.hpp"
#include "infra/util/ByteRange.hpp"
#include "infra/util/Function.hpp"
Expand All @@ -12,8 +13,8 @@ class SerialCommunicationLoopbackTest
{
public:
services::SerialCommunicationLoopback SerialCommunicationLoopback;
services::SerialCommunicationLoopbackPeer& server{ SerialCommunicationLoopback.Server() };
services::SerialCommunicationLoopbackPeer& client{ SerialCommunicationLoopback.Client() };
hal::SerialCommunication& server{ SerialCommunicationLoopback.Server() };
hal::SerialCommunication& client{ SerialCommunicationLoopback.Client() };
};

TEST_F(SerialCommunicationLoopbackTest, SendFromServerReceiveByClient)
Expand Down

0 comments on commit 8aac2ec

Please sign in to comment.