-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ wildcard added # wildcard added * wildcard added (but does not appear in mqtt specification...) $SYS messages compare is supported
- Loading branch information
hsaturn
committed
Nov 21, 2022
1 parent
354aec2
commit 96766f7
Showing
4 changed files
with
251 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |