Merge branch 'AsyncTcp' of github.com:hsaturn/TinyMqtt into AsyncTcp

This commit is contained in:
hsaturn
2021-04-10 15:57:13 +02:00
8 changed files with 8 additions and 30 deletions

View File

@@ -2,7 +2,6 @@
#include <map>
#include <string>
#include <string.h>
#include <ESP8266WiFi.h>
/***
* Allows to store up to 255 different strings with one byte class

View File

@@ -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);
}

View File

@@ -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<Type>(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;

View File

@@ -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); \

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,28 +1,14 @@
#include <AUnit.h>
#include <TinyMqtt.h>
#include <StringIndexer.h>
#include <map>
/**
* 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<std::string, std::map<Topic, int>> 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);