From d8105ee224e27bc9114b799807f5baa27767b4b1 Mon Sep 17 00:00:00 2001 From: hsaturn Date: Wed, 4 Jan 2023 22:02:00 +0100 Subject: [PATCH] EpoxyDuino upgrade --- src/TinyMqtt.cpp | 3 +++ src/TinyMqtt.h | 11 ++++++++++- tests/Makefile | 12 ++++++------ tests/classbind-tests/Makefile | 2 +- tests/classbind-tests/classbind-tests.ino | 12 ++++++------ tests/debug-mode/Makefile | 2 +- tests/local-tests/Makefile | 2 +- tests/local-tests/local-tests.ino | 12 ++++++------ tests/network-tests/Makefile | 2 +- tests/network-tests/network-tests.ino | 8 ++++---- 10 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index 9adf263..61a45e3 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -34,6 +34,7 @@ MqttBroker::~MqttBroker() // private constructor used by broker only MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client) { + dclass; connect(local_broker); debug("MqttClient private with broker"); #ifdef TINY_MQTT_ASYNC @@ -50,6 +51,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, TcpClient* new_client) MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id) : local_broker(local_broker), clientId(id) { + dclass; alive = 0; keep_alive = 0; @@ -58,6 +60,7 @@ MqttClient::MqttClient(MqttBroker* local_broker, const std::string& id) MqttClient::~MqttClient() { + dtor; close(); debug("*** MqttClient delete()"); } diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index 52592b7..5ef312e 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -57,6 +57,15 @@ #define debug(what) {} #endif +#include +#if 0 +#define dclass { Console << __LINE__ << ':' << __PRETTY_FUNCTION__ << ", this=" << (long)this << endl; } +#define dtor { Console << __LINE__ << ": ~" << __PRETTY_FUNCTION__ << ", this=" << (long)this << endl; } +#else +#define dclass +#define dtor +#endif + #ifdef TINY_MQTT_ASYNC using TcpClient = AsyncClient; using TcpServer = AsyncServer; @@ -188,7 +197,7 @@ class MqttClient /** Constructor. Broker is the adress of a local broker if not null If you want to connect elsewhere, leave broker null and use connect() **/ MqttClient(MqttBroker* broker = nullptr, const std::string& id = TINY_MQTT_DEFAULT_CLIENT_ID); - MqttClient(const std::string& id) : MqttClient(nullptr, id){} + MqttClient(const std::string& id) : MqttClient(nullptr, id){ dclass; } ~MqttClient(); diff --git a/tests/Makefile b/tests/Makefile index 4f66525..4775fec 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,29 +1,29 @@ SUB= tests: - set -e; \ + @set -e; \ for i in ${SUB}*-tests/Makefile; do \ echo '==== Making:' $$(dirname $$i); \ $(MAKE) -C $$(dirname $$i) -j; \ done debugtest: - set -e; \ + @set -e; \ $(MAKE) clean; \ $(MAKE) -C debug-mode -j; \ debug-mode/debug-tests.out runtests: debugtest - $(MAKE) clean - $(MAKE) tests - set -e; \ + @$(MAKE) clean + @$(MAKE) tests + @set -e; \ for i in ${SUB}*-tests/Makefile; do \ echo '==== Running:' $$(dirname $$i); \ $$(dirname $$i)/$$(dirname $$i).out; \ done clean: - set -e; \ + @set -e; \ for i in ${SUB}*-tests/Makefile; do \ echo '==== Cleaning:' $$(dirname $$i); \ $(MAKE) -C $$(dirname $$i) clean; \ diff --git a/tests/classbind-tests/Makefile b/tests/classbind-tests/Makefile index 7f0f8b5..2e28122 100644 --- a/tests/classbind-tests/Makefile +++ b/tests/classbind-tests/Makefile @@ -4,7 +4,7 @@ EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_TESTS # Remove flto flag from EpoxyDuino (too many ) -CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics +CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -DEPOXY_TEST APP_NAME := classbind-tests ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole diff --git a/tests/classbind-tests/classbind-tests.ino b/tests/classbind-tests/classbind-tests.ino index edfd49d..c0c7db5 100644 --- a/tests/classbind-tests/classbind-tests.ino +++ b/tests/classbind-tests/classbind-tests.ino @@ -129,7 +129,7 @@ void reset_and_start_servers(int n, bool early_accept = true) test(classbind_two_subscribers_binded_one_sender_wildcard) { - set_millis(0); + EpoxyTest::set_millis(0); reset_and_start_servers(2, true); assertEqual(WiFi.status(), WL_CONNECTED); @@ -158,7 +158,7 @@ test(classbind_two_subscribers_binded_one_sender_wildcard) for (int i =0; i<10; i++) { - add_millis(100); + EpoxyTest::add_millis(100); mqtt_a.loop(); mqtt_b.loop(); mqtt_sender.loop(); @@ -167,12 +167,12 @@ test(classbind_two_subscribers_binded_one_sender_wildcard) assertEqual(TestReceiver::messages["receiver"], 2); assertEqual(unrouted, 0); - set_real_time(); + EpoxyTest::set_real_time(); } test(classbind_one_client_receives_the_message) { - set_millis(0); + EpoxyTest::set_millis(0); reset_and_start_servers(2, true); assertEqual(WiFi.status(), WL_CONNECTED); @@ -195,14 +195,14 @@ test(classbind_one_client_receives_the_message) for (int i =0; i<10; i++) { - add_millis(100); + EpoxyTest::add_millis(100); client.loop(); broker.loop(); } assertEqual(TestReceiver::messages["receiver"], 1); assertEqual(unrouted, 0); - set_real_time(); + EpoxyTest::set_real_time(); } test(classbind_routes_should_be_empty_when_receiver_goes_out_of_scope) diff --git a/tests/debug-mode/Makefile b/tests/debug-mode/Makefile index ef0228a..1f396ba 100644 --- a/tests/debug-mode/Makefile +++ b/tests/debug-mode/Makefile @@ -1,7 +1,7 @@ # See https://github.com/bxparks/EpoxyDuino for documentation about this # Makefile to compile and run Arduino programs natively on Linux or MacOS. -EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEBUG +EXTRA_CXXFLAGS=-g3 -O0 # Remove flto flag from EpoxyDuino (too many ) CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics diff --git a/tests/local-tests/Makefile b/tests/local-tests/Makefile index 41c5d71..582ac9f 100644 --- a/tests/local-tests/Makefile +++ b/tests/local-tests/Makefile @@ -1,7 +1,7 @@ # See https://github.com/bxparks/EpoxyDuino for documentation about this # Makefile to compile and run Arduino programs natively on Linux or MacOS. -EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEFAULT_ALIVE=1 +EXTRA_CXXFLAGS=-g3 -O0 -DTINY_MQTT_DEFAULT_ALIVE=1 -DEPOXY_TEST # Remove flto flag from EpoxyDuino (too many ) CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics diff --git a/tests/local-tests/local-tests.ino b/tests/local-tests/local-tests.ino index 4f158b9..de03078 100644 --- a/tests/local-tests/local-tests.ino +++ b/tests/local-tests/local-tests.ino @@ -41,25 +41,25 @@ test(local_client_should_unregister_when_destroyed) test(local_client_alive) { - set_millis(0); + EpoxyTest::set_millis(0); MqttBroker broker(1883); MqttClient client(&broker); broker.loop(); assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is now connected - add_millis(TINY_MQTT_DEFAULT_ALIVE*1000/2); + EpoxyTest::add_millis(TINY_MQTT_DEFAULT_ALIVE*1000/2); broker.loop(); assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected - add_seconds(TINY_MQTT_DEFAULT_ALIVE*5); + EpoxyTest::add_seconds(TINY_MQTT_DEFAULT_ALIVE*5); broker.loop(); assertEqual(broker.localClientsCount(), (size_t)1); // Ensure client is still connected } test(local_wildcard_subscribe) { - set_millis(0); + EpoxyTest::set_millis(0); MqttBroker broker(1883); MqttClient client(&broker, "client"); MqttClient sender(&broker, "sender"); @@ -78,7 +78,7 @@ test(local_wildcard_subscribe) test(local_client_do_not_disconnect_after_publishing) { - set_millis(0); + EpoxyTest::set_millis(0); MqttBroker broker(1883); MqttClient client(&broker, "client"); MqttClient sender(&broker, "sender"); @@ -92,7 +92,7 @@ test(local_client_do_not_disconnect_after_publishing) sender.publish("test", "value"); broker.loop(); - add_seconds(60); + EpoxyTest::add_seconds(60); client.loop(); sender.loop(); broker.loop(); diff --git a/tests/network-tests/Makefile b/tests/network-tests/Makefile index 94f4d89..f9632ec 100644 --- a/tests/network-tests/Makefile +++ b/tests/network-tests/Makefile @@ -4,7 +4,7 @@ EXTRA_CXXFLAGS=-g3 -O0 # Remove flto flag from EpoxyDuino (too many ) -CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics +CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics -DEPOXY_TEST APP_NAME := network-tests ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP TinyConsole diff --git a/tests/network-tests/network-tests.ino b/tests/network-tests/network-tests.ino index 5981778..6c7c010 100644 --- a/tests/network-tests/network-tests.ino +++ b/tests/network-tests/network-tests.ino @@ -157,7 +157,7 @@ test(network_client_alive) const uint32_t keep_alive=1; start_servers(2, true); assertEqual(WiFi.status(), WL_CONNECTED); - set_millis(0); // Enter simulated time + EpoxyTest::set_millis(0); // Enter simulated time MqttBroker broker(1883); broker.begin(); @@ -178,18 +178,18 @@ test(network_client_alive) // All is going well if we call client.loop() // The client is able to send PingReq to the broker - add_seconds(keep_alive); + EpoxyTest::add_seconds(keep_alive); client.loop(); broker.loop(); assertEqual(broker.clientsCount(), (size_t)1); // Now simulate that the client is frozen for // a too long time - add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2); + EpoxyTest::add_seconds(TINY_MQTT_CLIENT_ALIVE_TOLERANCE*2); broker.loop(); assertEqual(broker.clientsCount(), (size_t)0); - set_real_time(); + EpoxyTest::set_real_time(); } test(network_client_keep_alive_high)