Skip to content

Commit

Permalink
Minor refactoring; fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeuz committed Apr 21, 2023
1 parent fb730fe commit 8b044e2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
7 changes: 6 additions & 1 deletion communication/src/coap_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,13 @@ class CoAPReliableChannel : public T
public:
template<typename... ArgsT>
explicit CoAPReliableChannel(ArgsT&&... args) :
CoAPReliableChannel(M(), std::forward<ArgsT>(args)...) {
}

template<typename... ArgsT>
explicit CoAPReliableChannel(M m, ArgsT&&... args) :
T(std::forward<ArgsT>(args)...),
millis(nullptr) {
millis(m) {
delegateChannel.init(this);
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit_tests/communication/coap_reliability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ SCENARIO("notify_client_messages_processed() is invoked when all client messages
THEN("the callback is invoked only once")
{
Verify(Method(channelMock, notify_client_messages_processed)).Once();
REQUIRE_FALSE(channel.has_unacknowledged_client_requests());
REQUIRE_FALSE(channel.has_pending_client_messages());
}
}

Expand All @@ -1229,7 +1229,7 @@ SCENARIO("notify_client_messages_processed() is invoked when all client messages
THEN("the callback is not invoked")
{
Verify(Method(channelMock, notify_client_messages_processed)).Never();
REQUIRE(channel.has_unacknowledged_client_requests());
REQUIRE(channel.has_pending_client_messages());
}
}

Expand All @@ -1247,7 +1247,7 @@ SCENARIO("notify_client_messages_processed() is invoked when all client messages
THEN("the callback is invoked only once")
{
Verify(Method(channelMock, notify_client_messages_processed)).Once();
REQUIRE_FALSE(channel.has_unacknowledged_client_requests());
REQUIRE_FALSE(channel.has_pending_client_messages());
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit_tests/communication/forward_message_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class ForwardMessageChannel : public MessageChannel
channel->notify_client_messages_processed();
}

virtual bool has_pending_client_messages() const override
{
return channel->has_pending_client_messages();
}

virtual AppStateDescriptor cached_app_state_descriptor() const override
{
return AppStateDescriptor();
Expand Down
7 changes: 6 additions & 1 deletion test/unit_tests/communication/util/coap_message_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ class CoapMessageChannel: public BufferMessageChannel<PROTOCOL_BUFFER_SIZE> {
// Returns true if there's a message received from the device
bool hasMessages() const;

// Reimplemented from AbstractMessageChannel
// Reimplemented from MessageChannel
ProtocolError send(Message& msg) override;
ProtocolError receive(Message& msg) override;
ProtocolError command(Command cmd, void* arg) override;
bool is_unreliable() override;
ProtocolError establish() override;
ProtocolError notify_established() override;
void notify_client_messages_processed() override;
bool has_pending_client_messages() const override;
AppStateDescriptor cached_app_state_descriptor() const override;
void reset() override;

Expand Down Expand Up @@ -112,6 +113,10 @@ inline ProtocolError CoapMessageChannel::notify_established() {
inline void CoapMessageChannel::notify_client_messages_processed() {
}

inline bool CoapMessageChannel::has_pending_client_messages() const {
return false;
}

inline AppStateDescriptor CoapMessageChannel::cached_app_state_descriptor() const {
return AppStateDescriptor();
}
Expand Down
5 changes: 0 additions & 5 deletions test/unit_tests/communication/util/protocol_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class ProtocolStub: public Protocol {
void init(const char* id, const SparkKeys& keys, const SparkCallbacks& cb, const SparkDescriptor& desc) override;
int command(ProtocolCommands::Enum cmd, uint32_t val, const void* data) override;
size_t build_hello(Message& msg, uint16_t flags) override;
int get_status(protocol_status* status) const override;

private:
DescriptorCallbacks desc_;
Expand Down Expand Up @@ -72,10 +71,6 @@ inline size_t ProtocolStub::build_hello(Message& msg, uint16_t flags) {
return 0;
}

inline int ProtocolStub::get_status(protocol_status* status) const {
return 0;
}

} // namespace test

} // namespace protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ test(06_register_many_functions) {
}
Particle.connect();
waitUntil(Particle.connected);
delay(6000); // Give the system some time to send a blockwise Describe message
delay(3000);
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,5 @@ test(07_register_many_variables) {
}
Particle.connect();
waitUntil(Particle.connected);
delay(6000); // Give the system some time to send a blockwise Describe message
delay(3000);
}

0 comments on commit 8b044e2

Please sign in to comment.