Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
96766f7091 | ||
|
|
354aec239f | ||
|
|
3839a0a830 | ||
|
|
0444a4c348 | ||
|
|
73207e4745 | ||
|
|
b7d44445af | ||
|
|
cce6b2ecfc |
@@ -39,10 +39,11 @@ TinyMqtt is a small, fast and capable Mqtt Broker and Client for Esp8266 / Esp32
|
|||||||
|
|
||||||
| Example | Description |
|
| Example | Description |
|
||||||
| ------------------- | ------------------------------------------ |
|
| ------------------- | ------------------------------------------ |
|
||||||
| client-without-wifi | standalone example |
|
| [client-with-wifi](https://github.com/hsaturn/TinyMqtt/tree/main/examples/client-with-wifi/client-with-wifi.ino) | standalone example |
|
||||||
| simple-client | Connect the ESP to an external Mqtt broker |
|
| [client-without-wifi](https://github.com/hsaturn/TinyMqtt/tree/main/examples/client-without-wifi/client-without-wifi.ino) | standalone example |
|
||||||
| simple-broker | Simple Mqtt broker with your ESP |
|
| [simple-client](https://github.com/hsaturn/TinyMqtt/tree/main/examples/simple-client/simple-client.ino) | Connect the ESP to an external Mqtt broker |
|
||||||
| tinymqtt-test | Complex console example |
|
| [simple-broker](https://github.com/hsaturn/TinyMqtt/tree/main/examples/simple-broker/simple-broker.ino) | Simple Mqtt broker with your ESP |
|
||||||
|
| [tinymqtt-test](https://github.com/hsaturn/TinyMqtt/tree/main/examples/tinymqtt-test/tinymqtt-test.ino) | Complex console example |
|
||||||
|
|
||||||
- tinymqtt-test : This is a complex sketch with a terminal console
|
- tinymqtt-test : This is a complex sketch with a terminal console
|
||||||
that allows to add clients publish, connect etc with interpreted commands.
|
that allows to add clients publish, connect etc with interpreted commands.
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
MqttBroker::MqttBroker(uint16_t port)
|
MqttBroker::MqttBroker(uint16_t port)
|
||||||
{
|
{
|
||||||
server = new TcpServer(port);
|
server = new TcpServer(port);
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
server->onClient(onClient, this);
|
server->onClient(onClient, this);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ MqttBroker::~MqttBroker()
|
|||||||
MqttClient::MqttClient(MqttBroker* parent, TcpClient* new_client)
|
MqttClient::MqttClient(MqttBroker* parent, TcpClient* new_client)
|
||||||
: parent(parent)
|
: parent(parent)
|
||||||
{
|
{
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
client = new_client;
|
client = new_client;
|
||||||
client->onData(onData, this);
|
client->onData(onData, this);
|
||||||
// client->onConnect() TODO
|
// client->onConnect() TODO
|
||||||
@@ -91,7 +91,7 @@ void MqttClient::connect(std::string broker, uint16_t port, uint16_t ka)
|
|||||||
client = new TcpClient;
|
client = new TcpClient;
|
||||||
|
|
||||||
debug("Trying to connect to " << broker.c_str() << ':' << port);
|
debug("Trying to connect to " << broker.c_str() << ':' << port);
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
client->onData(onData, this);
|
client->onData(onData, this);
|
||||||
client->onConnect(onConnect, this);
|
client->onConnect(onConnect, this);
|
||||||
client->connect(broker.c_str(), port);
|
client->connect(broker.c_str(), port);
|
||||||
@@ -146,7 +146,7 @@ void MqttBroker::onClient(void* broker_ptr, TcpClient* client)
|
|||||||
|
|
||||||
void MqttBroker::loop()
|
void MqttBroker::loop()
|
||||||
{
|
{
|
||||||
#ifndef TCP_ASYNC
|
#ifndef TINY_MQTT_ASYNC
|
||||||
WiFiClient client = server->available();
|
WiFiClient client = server->available();
|
||||||
|
|
||||||
if (client)
|
if (client)
|
||||||
@@ -281,7 +281,7 @@ void MqttClient::loop()
|
|||||||
// there is no need to send one PingReq per instance.
|
// there is no need to send one PingReq per instance.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef TCP_ASYNC
|
#ifndef TINY_MQTT_ASYNC
|
||||||
while(client && client->available()>0)
|
while(client && client->available()>0)
|
||||||
{
|
{
|
||||||
message.incoming(client->read());
|
message.incoming(client->read());
|
||||||
@@ -314,7 +314,7 @@ void MqttClient::onConnect(void *mqttclient_ptr, TcpClient*)
|
|||||||
mqtt->clientAlive(0);
|
mqtt->clientAlive(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
void MqttClient::onData(void* client_ptr, TcpClient*, void* data, size_t len)
|
void MqttClient::onData(void* client_ptr, TcpClient*, void* data, size_t len)
|
||||||
{
|
{
|
||||||
char* char_ptr = static_cast<char*>(data);
|
char* char_ptr = static_cast<char*>(data);
|
||||||
@@ -636,10 +636,66 @@ if (mesg->type() != MqttMessage::Type::PingReq && mesg->type() != MqttMessage::T
|
|||||||
bool Topic::matches(const Topic& topic) const
|
bool Topic::matches(const Topic& topic) const
|
||||||
{
|
{
|
||||||
if (getIndex() == topic.getIndex()) return true;
|
if (getIndex() == topic.getIndex()) return true;
|
||||||
if (str() == topic.str()) return true;
|
const char* p1 = c_str();
|
||||||
return false;
|
const char* p2 = topic.c_str();
|
||||||
|
|
||||||
|
if (p1 == p2) return true;
|
||||||
|
if (*p2 == '$' and *p1 != '$') return false;
|
||||||
|
|
||||||
|
while(*p1 and *p2)
|
||||||
|
{
|
||||||
|
if (*p1 == '+')
|
||||||
|
{
|
||||||
|
++p1;
|
||||||
|
if (*p1 and *p1!='/') return false;
|
||||||
|
if (*p1) ++p1;
|
||||||
|
while(*p2 and *p2++!='/');
|
||||||
|
}
|
||||||
|
else if (*p1 == '#')
|
||||||
|
{
|
||||||
|
if (*++p1==0) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (*p1 == '*')
|
||||||
|
{
|
||||||
|
const char c=*(p1+1);
|
||||||
|
if (c==0) return true;
|
||||||
|
if (c!='/') return false;
|
||||||
|
const char*p = p1+2;
|
||||||
|
while(*p and *p2)
|
||||||
|
{
|
||||||
|
if (*p == *p2)
|
||||||
|
{
|
||||||
|
if (*p==0) return true;
|
||||||
|
if (*p=='/')
|
||||||
|
{
|
||||||
|
p1=p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while(*p2 and *p2++!='/');
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++p;
|
||||||
|
++p2;
|
||||||
|
}
|
||||||
|
if (*p==0) return true;
|
||||||
|
}
|
||||||
|
else if (*p1 == *p2)
|
||||||
|
{
|
||||||
|
++p1;
|
||||||
|
++p2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (*p1=='/' and p1[1]=='#' and p1[2]==0) return true;
|
||||||
|
return *p1==0 and *p2==0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// publish from local client
|
// publish from local client
|
||||||
MqttError MqttClient::publish(const Topic& topic, const char* payload, size_t pay_length)
|
MqttError MqttClient::publish(const Topic& topic, const char* payload, size_t pay_length)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// TODO Should add a AUnit with both TCP_ASYNC and not TCP_ASYNC
|
// TODO Should add a AUnit with both TINY_MQTT_ASYNC and not TINY_MQTT_ASYNC
|
||||||
// #define TCP_ASYNC // Uncomment this to use ESPAsyncTCP instead of normal cnx
|
// #define TINY_MQTT_ASYNC // Uncomment this to use ESPAsyncTCP instead of normal cnx
|
||||||
|
|
||||||
#if defined(ESP8266) || defined(EPOXY_DUINO)
|
#if defined(ESP8266) || defined(EPOXY_DUINO)
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#else
|
#else
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#elif defined(ESP32)
|
#elif defined(ESP32)
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
#define debug(what) {}
|
#define debug(what) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
using TcpClient = AsyncClient;
|
using TcpClient = AsyncClient;
|
||||||
using TcpServer = AsyncServer;
|
using TcpServer = AsyncServer;
|
||||||
#else
|
#else
|
||||||
@@ -221,7 +221,6 @@ class MqttClient
|
|||||||
bool c = false;
|
bool c = false;
|
||||||
Serial << " [";
|
Serial << " [";
|
||||||
for(auto s: subscriptions)
|
for(auto s: subscriptions)
|
||||||
(void)indent;
|
|
||||||
{
|
{
|
||||||
if (c) Serial << ", ";
|
if (c) Serial << ", ";
|
||||||
Serial << s.str().c_str();
|
Serial << s.str().c_str();
|
||||||
@@ -241,7 +240,7 @@ class MqttClient
|
|||||||
|
|
||||||
// event when tcp/ip link established (real or fake)
|
// event when tcp/ip link established (real or fake)
|
||||||
static void onConnect(void * client_ptr, TcpClient*);
|
static void onConnect(void * client_ptr, TcpClient*);
|
||||||
#ifdef TCP_ASYNC
|
#ifdef TINY_MQTT_ASYNC
|
||||||
static void onData(void* client_ptr, TcpClient*, void* data, size_t len);
|
static void onData(void* client_ptr, TcpClient*, void* data, size_t len);
|
||||||
#endif
|
#endif
|
||||||
MqttError sendTopic(const Topic& topic, MqttMessage::Type type, uint8_t qos);
|
MqttError sendTopic(const Topic& topic, MqttMessage::Type type, uint8_t qos);
|
||||||
|
|||||||
@@ -5,7 +5,15 @@ tests:
|
|||||||
$(MAKE) -C $$(dirname $$i) -j; \
|
$(MAKE) -C $$(dirname $$i) -j; \
|
||||||
done
|
done
|
||||||
|
|
||||||
runtests: tests
|
debugtest:
|
||||||
|
set -e; \
|
||||||
|
$(MAKE) clean; \
|
||||||
|
$(MAKE) -C debug-mode -j; \
|
||||||
|
debug-mode/debug-tests.out
|
||||||
|
|
||||||
|
runtests: debugtest
|
||||||
|
$(MAKE) clean
|
||||||
|
$(MAKE) tests
|
||||||
set -e; \
|
set -e; \
|
||||||
for i in *-tests/Makefile; do \
|
for i in *-tests/Makefile; do \
|
||||||
echo '==== Running:' $$(dirname $$i); \
|
echo '==== Running:' $$(dirname $$i); \
|
||||||
|
|||||||
13
tests/debug-mode/Makefile
Normal file
13
tests/debug-mode/Makefile
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
# Remove flto flag from EpoxyDuino (too many <optimized out>)
|
||||||
|
CXXFLAGS = -Wextra -Wall -std=gnu++11 -fno-exceptions -fno-threadsafe-statics
|
||||||
|
|
||||||
|
APP_NAME := debug-tests
|
||||||
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsyncTCP
|
||||||
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
|
EPOXY_CORE := EPOXY_CORE_ESP8266
|
||||||
|
include ../../../EpoxyDuino/EpoxyDuino.mk
|
||||||
15
tests/debug-mode/debug-tests.ino
Normal file
15
tests/debug-mode/debug-tests.ino
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <AUnit.h>
|
||||||
|
#include <TinyMqtt.h>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// Only compilation check, so do nothing
|
||||||
|
|
||||||
|
void setup() {}
|
||||||
|
void loop() {
|
||||||
|
aunit::TestRunner::run();
|
||||||
|
}
|
||||||
@@ -93,6 +93,104 @@ test(nowifi_publish_should_be_dispatched_to_clients)
|
|||||||
assertEqual(published["B"]["a/c"], 0);
|
assertEqual(published["B"]["a/c"], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test(nowifi_subscribe_with_star_wildcard)
|
||||||
|
{
|
||||||
|
published.clear();
|
||||||
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
|
MqttClient subscriber(&broker, "A");
|
||||||
|
subscriber.setCallback(onPublish);
|
||||||
|
subscriber.subscribe("house/*/temp");
|
||||||
|
|
||||||
|
MqttClient publisher(&broker);
|
||||||
|
publisher.publish("house/bedroom/temp");
|
||||||
|
publisher.publish("house/kitchen/temp");
|
||||||
|
publisher.publish("house/living_room/tv/temp");
|
||||||
|
publisher.publish("building/location1/bedroom/temp");
|
||||||
|
|
||||||
|
assertEqual(published["A"]["house/bedroom/temp"], 1);
|
||||||
|
assertEqual(published["A"]["house/kitchen/temp"], 1);
|
||||||
|
assertEqual(published["A"]["house/living_room/tv/temp"], 1);
|
||||||
|
assertEqual(published["A"]["building/location1/bedroom/temp"], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(nowifi_subscribe_with_plus_wildcard)
|
||||||
|
{
|
||||||
|
published.clear();
|
||||||
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
|
MqttClient subscriber(&broker, "A");
|
||||||
|
subscriber.setCallback(onPublish);
|
||||||
|
subscriber.subscribe("house/+/temp");
|
||||||
|
|
||||||
|
MqttClient publisher(&broker);
|
||||||
|
publisher.publish("house/bedroom/temp");
|
||||||
|
publisher.publish("house/kitchen/temp");
|
||||||
|
publisher.publish("house/living_room/tv/temp");
|
||||||
|
publisher.publish("building/location1/bedroom/temp");
|
||||||
|
|
||||||
|
assertEqual(published["A"]["house/bedroom/temp"], 1);
|
||||||
|
assertEqual(published["A"]["house/kitchen/temp"], 1);
|
||||||
|
assertEqual(published["A"]["house/living_room/tv/temp"], 0);
|
||||||
|
assertEqual(published["A"]["building/location1/bedroom/temp"], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(nowifi_should_not_receive_sys_msg)
|
||||||
|
{
|
||||||
|
published.clear();
|
||||||
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
|
MqttClient subscriber(&broker, "A");
|
||||||
|
subscriber.setCallback(onPublish);
|
||||||
|
subscriber.subscribe("+/data");
|
||||||
|
|
||||||
|
MqttClient publisher(&broker);
|
||||||
|
publisher.publish("$SYS/data");
|
||||||
|
|
||||||
|
assertEqual(published["A"]["$SYS/data"], 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(nowifi_subscribe_with_mixed_wildcards)
|
||||||
|
{
|
||||||
|
published.clear();
|
||||||
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
|
MqttClient subscriber(&broker, "A");
|
||||||
|
subscriber.setCallback(onPublish);
|
||||||
|
subscriber.subscribe("+/data/#");
|
||||||
|
|
||||||
|
MqttClient publisher(&broker);
|
||||||
|
publisher.publish("node1/data/update");
|
||||||
|
publisher.publish("node2/data/delta");
|
||||||
|
publisher.publish("node3/data");
|
||||||
|
|
||||||
|
assertEqual(published["A"]["node1/data/update"], 1);
|
||||||
|
assertEqual(published["A"]["node2/data/delta"], 1);
|
||||||
|
assertEqual(published["A"]["node3/data"], 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
test(nowifi_unsubscribe_with_wildcards)
|
||||||
|
{
|
||||||
|
published.clear();
|
||||||
|
assertEqual(broker.clientsCount(), (size_t)0);
|
||||||
|
|
||||||
|
MqttClient subscriber(&broker, "A");
|
||||||
|
subscriber.setCallback(onPublish);
|
||||||
|
subscriber.subscribe("one/two/+");
|
||||||
|
subscriber.subscribe("one/two/three");
|
||||||
|
|
||||||
|
MqttClient publisher(&broker);
|
||||||
|
publisher.publish("one/two/three");
|
||||||
|
publisher.publish("one/two/four");
|
||||||
|
|
||||||
|
subscriber.unsubscribe("one/two/+");
|
||||||
|
publisher.publish("one/two/five");
|
||||||
|
|
||||||
|
assertEqual(published["A"]["one/two/three"], 1);
|
||||||
|
assertEqual(published["A"]["one/two/four"], 1);
|
||||||
|
assertEqual(published["A"]["one/two/five"], 0);
|
||||||
|
}
|
||||||
|
|
||||||
test(nowifi_unsubscribe)
|
test(nowifi_unsubscribe)
|
||||||
{
|
{
|
||||||
published.clear();
|
published.clear();
|
||||||
|
|||||||
10
tests/topic-tests/Makefile
Normal file
10
tests/topic-tests/Makefile
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
# 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
|
||||||
|
|
||||||
|
APP_NAME := topic-tests
|
||||||
|
ARDUINO_LIBS := AUnit AceCommon AceTime TinyMqtt EspMock ESP8266WiFi ESPAsync
|
||||||
|
ARDUINO_LIB_DIRS := ../../../EspMock/libraries
|
||||||
|
EPOXY_CORE := EPOXY_CORE_ESP8266
|
||||||
|
include ../../../EpoxyDuino/EpoxyDuino.mk
|
||||||
85
tests/topic-tests/topic-tests.ino
Normal file
85
tests/topic-tests/topic-tests.ino
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <AUnit.h>
|
||||||
|
#include <TinyMqtt.h>
|
||||||
|
#include <map>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define endl "\n"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TinyMqtt / StringIndexer unit tests.
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
bool testTopicMatch(const char* a, const char* b, bool expected)
|
||||||
|
{
|
||||||
|
Topic ta(a);
|
||||||
|
Topic tb(b);
|
||||||
|
bool match(ta.matches(tb));
|
||||||
|
cout << " " << ta.c_str() << ' ';
|
||||||
|
if (match != expected)
|
||||||
|
cout << (expected ? " should match " : " should not match ");
|
||||||
|
else
|
||||||
|
cout << (expected ? " matches " : " unmatches ");
|
||||||
|
cout << tb.c_str() << endl;
|
||||||
|
return expected == match;
|
||||||
|
}
|
||||||
|
|
||||||
|
test(topic_matches)
|
||||||
|
{
|
||||||
|
// matching
|
||||||
|
assertTrue(testTopicMatch("a/b/c" , "a/b/c" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*/c" , "a/xyz/c" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*/e" , "a/b/c/d/e" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*" , "a/b/c/d/e" , true));
|
||||||
|
assertTrue(testTopicMatch("*/c" , "a/b/c" , true));
|
||||||
|
assertTrue(testTopicMatch("/*/c" , "/a/b/c" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*" , "a/b/c/d" , true));
|
||||||
|
assertTrue(testTopicMatch("a/+/c" , "a/b/c" , true));
|
||||||
|
assertTrue(testTopicMatch("a/+/c/+/e", "a/b/c/d/e" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*/c/+/e", "a/b/c/d/e" , true));
|
||||||
|
assertTrue(testTopicMatch("/+/b" , "/a/b" , true));
|
||||||
|
assertTrue(testTopicMatch("+" , "a" , true));
|
||||||
|
assertTrue(testTopicMatch("a/b/#" , "a/b/c/d" , true));
|
||||||
|
assertTrue(testTopicMatch("a/b/#" , "a/b" , true));
|
||||||
|
assertTrue(testTopicMatch("a/*/c" , "a/*/c" , true));
|
||||||
|
|
||||||
|
// not matching
|
||||||
|
assertTrue(testTopicMatch("a/b/c" , "a/b/d" , false));
|
||||||
|
assertTrue(testTopicMatch("a/b/c" , "a/b/d" , false));
|
||||||
|
assertTrue(testTopicMatch("a/*/e" , "a/b/c/d/f" , false));
|
||||||
|
assertTrue(testTopicMatch("a/+" , "a" , false));
|
||||||
|
assertTrue(testTopicMatch("a/+" , "a/b/d" , false));
|
||||||
|
assertTrue(testTopicMatch("a/+/" , "a/" , false));
|
||||||
|
|
||||||
|
// $SYS topics
|
||||||
|
assertTrue(testTopicMatch("+/any" , "$SYS/any" , false));
|
||||||
|
assertTrue(testTopicMatch("*/any" , "$SYS/any" , false));
|
||||||
|
assertTrue(testTopicMatch("$SYS/any" , "$SYS/any" , true));
|
||||||
|
assertTrue(testTopicMatch("$SYS/+/y" , "$SYS/a/y" , true));
|
||||||
|
assertTrue(testTopicMatch("$SYS/#" , "$SYS/a/y" , true));
|
||||||
|
|
||||||
|
// not valid
|
||||||
|
assertTrue(testTopicMatch("a/#/b" , "a/x/b" , false));
|
||||||
|
assertTrue(testTopicMatch("a+" , "a/b/d" , false));
|
||||||
|
assertTrue(testTopicMatch("a/b/#/d" , "a/b/c/d" , false));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------
|
||||||
|
// setup() and loop()
|
||||||
|
void setup() {
|
||||||
|
delay(1000);
|
||||||
|
Serial.begin(115200);
|
||||||
|
while(!Serial);
|
||||||
|
|
||||||
|
Serial.println("=============[ TinyMqtt StringIndexer TESTS ]========================");
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
aunit::TestRunner::run();
|
||||||
|
|
||||||
|
// if (Serial.available()) ESP.reset();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user