From 8b044e20c6d6b05456a0fed6c1dc557d712d224e Mon Sep 17 00:00:00 2001 From: Sergey Polyakov Date: Wed, 19 Oct 2022 16:44:33 +0400 Subject: [PATCH] Minor refactoring; fix tests --- communication/src/coap_channel.h | 7 ++++++- test/unit_tests/communication/coap_reliability.cpp | 6 +++--- test/unit_tests/communication/forward_message_channel.h | 5 +++++ test/unit_tests/communication/util/coap_message_channel.h | 7 ++++++- test/unit_tests/communication/util/protocol_stub.h | 5 ----- .../integration/communication/functions/functions.cpp | 2 +- .../integration/communication/variables/variables.cpp | 2 +- 7 files changed, 22 insertions(+), 12 deletions(-) diff --git a/communication/src/coap_channel.h b/communication/src/coap_channel.h index c3d951b5ee..314b2030dd 100644 --- a/communication/src/coap_channel.h +++ b/communication/src/coap_channel.h @@ -560,8 +560,13 @@ class CoAPReliableChannel : public T public: template explicit CoAPReliableChannel(ArgsT&&... args) : + CoAPReliableChannel(M(), std::forward(args)...) { + } + + template + explicit CoAPReliableChannel(M m, ArgsT&&... args) : T(std::forward(args)...), - millis(nullptr) { + millis(m) { delegateChannel.init(this); } diff --git a/test/unit_tests/communication/coap_reliability.cpp b/test/unit_tests/communication/coap_reliability.cpp index 9fd85d76ef..03dbb3af32 100644 --- a/test/unit_tests/communication/coap_reliability.cpp +++ b/test/unit_tests/communication/coap_reliability.cpp @@ -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()); } } @@ -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()); } } @@ -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()); } } } diff --git a/test/unit_tests/communication/forward_message_channel.h b/test/unit_tests/communication/forward_message_channel.h index 4a7141056a..b321fe9da6 100644 --- a/test/unit_tests/communication/forward_message_channel.h +++ b/test/unit_tests/communication/forward_message_channel.h @@ -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(); diff --git a/test/unit_tests/communication/util/coap_message_channel.h b/test/unit_tests/communication/util/coap_message_channel.h index a2a3a4a98d..3f3a3a9d0b 100644 --- a/test/unit_tests/communication/util/coap_message_channel.h +++ b/test/unit_tests/communication/util/coap_message_channel.h @@ -44,7 +44,7 @@ class CoapMessageChannel: public BufferMessageChannel { // 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; @@ -52,6 +52,7 @@ class CoapMessageChannel: public BufferMessageChannel { 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; @@ -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(); } diff --git a/test/unit_tests/communication/util/protocol_stub.h b/test/unit_tests/communication/util/protocol_stub.h index 8dfe110974..935b1ed62a 100644 --- a/test/unit_tests/communication/util/protocol_stub.h +++ b/test/unit_tests/communication/util/protocol_stub.h @@ -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_; @@ -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 diff --git a/user/tests/integration/communication/functions/functions.cpp b/user/tests/integration/communication/functions/functions.cpp index 0351dd3ab2..d30f29134d 100644 --- a/user/tests/integration/communication/functions/functions.cpp +++ b/user/tests/integration/communication/functions/functions.cpp @@ -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); } diff --git a/user/tests/integration/communication/variables/variables.cpp b/user/tests/integration/communication/variables/variables.cpp index a9bf9221db..ce94c69ba8 100644 --- a/user/tests/integration/communication/variables/variables.cpp +++ b/user/tests/integration/communication/variables/variables.cpp @@ -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); }