diff --git a/src/StringIndexer.h b/src/StringIndexer.h index 8d26de9..17d5ac1 100644 --- a/src/StringIndexer.h +++ b/src/StringIndexer.h @@ -2,7 +2,6 @@ #include #include #include -#include /*** * Allows to store up to 255 different strings with one byte class diff --git a/src/TinyMqtt.cpp b/src/TinyMqtt.cpp index da96ee1..74ca4b1 100644 --- a/src/TinyMqtt.cpp +++ b/src/TinyMqtt.cpp @@ -672,6 +672,7 @@ void MqttMessage::add(const char* p, size_t len, bool addLength) { if (addLength) { + buffer.reserve(buffer.length()+addLength+2); incoming(len>>8); incoming(len & 0xFF); } diff --git a/src/TinyMqtt.h b/src/TinyMqtt.h index ee9692e..d6dc2db 100644 --- a/src/TinyMqtt.h +++ b/src/TinyMqtt.h @@ -80,23 +80,15 @@ class MqttMessage // output buff+=2, len=length(str) static void getString(const char* &buff, uint16_t& len); - Type type() const { return state == Complete ? static_cast(buffer[0]) : Unknown; } - // shouldn't exist because it breaks constness :-( - // but this saves memory so ... - void changeType(Type type) const - { - buffer[0] = type; - } - void create(Type type) { buffer=(char)type; - buffer+='\0'; + buffer+='\0'; // reserved for msg length vheader=2; size=0; state=Create; diff --git a/tests/Makefile b/tests/Makefile index bfea400..e2d6bac 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,7 +5,7 @@ tests: $(MAKE) -C $$(dirname $$i) -j; \ done -runtests: +runtests: tests set -e; \ for i in *-tests/Makefile; do \ echo '==== Running:' $$(dirname $$i); \ diff --git a/tests/local-tests/Makefile b/tests/local-tests/Makefile index 8781b42..232112d 100644 --- a/tests/local-tests/Makefile +++ b/tests/local-tests/Makefile @@ -3,5 +3,5 @@ APP_NAME := local-tests ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock -ESP_LIBS = ESP8266WiFi +ESP_LIBS = ESP8266WiFi ESPAsyncTCP include ../../../EspMock/EspMock.mk diff --git a/tests/nowifi-tests/Makefile b/tests/nowifi-tests/Makefile index 3733f64..b5913b1 100644 --- a/tests/nowifi-tests/Makefile +++ b/tests/nowifi-tests/Makefile @@ -3,5 +3,5 @@ APP_NAME := nowifi-tests ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock -ESP_LIBS = ESP8266WiFi +ESP_LIBS = ESP8266WiFi ESPAsyncTCP include ../../../EspMock/EspMock.mk diff --git a/tests/string-indexer-tests/Makefile b/tests/string-indexer-tests/Makefile index acb264f..9673cca 100644 --- a/tests/string-indexer-tests/Makefile +++ b/tests/string-indexer-tests/Makefile @@ -3,5 +3,5 @@ APP_NAME := string-indexer-tests ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock -ESP_LIBS = ESP8266WiFi +ESP_LIBS = ESP8266WiFi ESPAsyncTCP include ../../../EspMock/EspMock.mk diff --git a/tests/string-indexer-tests/string-indexer-tests.ino b/tests/string-indexer-tests/string-indexer-tests.ino index 86b8df0..4168946 100644 --- a/tests/string-indexer-tests/string-indexer-tests.ino +++ b/tests/string-indexer-tests/string-indexer-tests.ino @@ -1,28 +1,14 @@ #include -#include +#include #include /** - * TinyMqtt local unit tests. + * TinyMqtt / StringIndexer unit tests. * - * Clients are connected to pseudo remote broker - * The remote will be 127.0.0.1:1883 - * We are using 127.0.0.1 because this is simpler to test with a single ESP - * Also, this will allow to mock and thus run Action on github **/ using namespace std; -MqttBroker broker(1883); - -std::map> published; // map[client_id] => map[topic] = count - -void onPublish(const MqttClient* srce, const Topic& topic, const char* payload, size_t length) -{ - if (srce) - published[srce->id()][topic]++; -} - test(indexer_empty) { assertEqual(StringIndexer::count(), 0);