|
@@ -5,11 +5,23 @@
|
|
|
|
|
|
#include "kbf/net.h"
|
|
|
|
|
|
-#define KBF_TEST_MDNS_SSID "kbf_test_wifi_ap"
|
|
|
-#define KBF_TEST_MDNS_PASS "Pas$w0Rd1337"
|
|
|
-#define KBF_TEST_MDNS_MASTER "master"
|
|
|
-#define KBF_TEST_MDNS_SLAVE "slave"
|
|
|
-#define KBF_TEST_MDNS_SIGNAL "ready"
|
|
|
+#define KBF_TEST_MDNS_SSID "kbf_test_wifi_ap"
|
|
|
+#define KBF_TEST_MDNS_PASS "Pas$w0Rd1337"
|
|
|
+#define KBF_TEST_MDNS_MASTER "master"
|
|
|
+#define KBF_TEST_MDNS_SLAVE "slave"
|
|
|
+#define KBF_TEST_MDNS_SIGNAL "ready"
|
|
|
+
|
|
|
+#define KBF_TEST_SERVICE1_TYPE "_hax"
|
|
|
+#define KBF_TEST_SERVICE1_PORT 1337
|
|
|
+#define KBF_TEST_SERVICE1_INST "Test TCP service"
|
|
|
+
|
|
|
+#define KBF_TEST_SERVICE2_TYPE "_http"
|
|
|
+#define KBF_TEST_SERVICE2_PORT 80
|
|
|
+#define KBF_TEST_SERVICE2_INST "Test TCP/HTTP service"
|
|
|
+
|
|
|
+#define KBF_TEST_SERVICE3_TYPE "_hax"
|
|
|
+#define KBF_TEST_SERVICE3_PORT 31337
|
|
|
+#define KBF_TEST_SERVICE3_INST "Test UDP service"
|
|
|
|
|
|
using namespace kbf;
|
|
|
|
|
@@ -61,7 +73,6 @@ TEST_CASE("IP address functions", "[kbf_net]") {
|
|
|
using std::shared_ptr;
|
|
|
|
|
|
static rtos::EventGroup eventGroup;
|
|
|
-static net::MDNS *mdns;
|
|
|
|
|
|
static shared_ptr<kbf::UART> setupUart() {
|
|
|
auto uart1 = new kbf::UART(1);
|
|
@@ -71,12 +82,12 @@ static shared_ptr<kbf::UART> setupUart() {
|
|
|
|
|
|
void mdnsMaster() {
|
|
|
wifi::start(wifi::AP::create(KBF_TEST_MDNS_SSID, KBF_TEST_MDNS_PASS));
|
|
|
- mdns = new net::MDNS();
|
|
|
+ auto mdns = new net::MDNS();
|
|
|
mdns->setHostname(KBF_TEST_MDNS_MASTER);
|
|
|
|
|
|
setupUart()->waitFor(KBF_TEST_MDNS_SIGNAL);
|
|
|
|
|
|
- auto ip = mdns->query(KBF_TEST_MDNS_SLAVE);
|
|
|
+ auto ip = mdns->queryA(KBF_TEST_MDNS_SLAVE);
|
|
|
TEST_ASSERT_NOT_NULL(ip)
|
|
|
TEST_ASSERT_EQUAL_STRING("192.168.4.2", ip->str().c_str());
|
|
|
|
|
@@ -90,13 +101,15 @@ void mdnsSlave() {
|
|
|
eventGroup.clear();
|
|
|
|
|
|
sta->onIp = {[]() {
|
|
|
- mdns = new net::MDNS(KBF_TEST_MDNS_SLAVE);
|
|
|
+ auto mdns = new net::MDNS(KBF_TEST_MDNS_SLAVE);
|
|
|
|
|
|
- TEST_ASSERT_NULL(mdns->query("nonexistent"))
|
|
|
+ TEST_ASSERT_NULL(mdns->queryA("nonexistent"))
|
|
|
|
|
|
- auto ip = mdns->query(KBF_TEST_MDNS_MASTER);
|
|
|
+ auto ip = mdns->queryA(KBF_TEST_MDNS_MASTER);
|
|
|
TEST_ASSERT_NOT_NULL(ip)
|
|
|
TEST_ASSERT_EQUAL_STRING("192.168.4.1", ip->str().c_str());
|
|
|
+
|
|
|
+ delete mdns;
|
|
|
setupUart()->write(KBF_TEST_MDNS_SIGNAL);
|
|
|
}};
|
|
|
|
|
@@ -107,8 +120,81 @@ void mdnsSlave() {
|
|
|
sta->connect(KBF_TEST_MDNS_SSID, KBF_TEST_MDNS_PASS);
|
|
|
|
|
|
eventGroup.waitForBit(0);
|
|
|
- delete mdns;
|
|
|
wifi::stop();
|
|
|
}
|
|
|
|
|
|
TEST_CASE_MULTIPLE_DEVICES("mDNS", "[kbf_net]", mdnsMaster, mdnsSlave)
|
|
|
+
|
|
|
+void mdnsServiceMaster() {
|
|
|
+ eventGroup.clear();
|
|
|
+ wifi::start(wifi::AP::create(KBF_TEST_MDNS_SSID, KBF_TEST_MDNS_PASS));
|
|
|
+ wifi::getAP()->onDisconnect = {[](wifi::AP::STA &) {
|
|
|
+ eventGroup.setBit(0);
|
|
|
+ }};
|
|
|
+
|
|
|
+ auto mdns = new net::MDNS();
|
|
|
+ mdns->setHostname(KBF_TEST_MDNS_MASTER);
|
|
|
+ mdns->addService(KBF_TEST_SERVICE1_TYPE, KBF_TEST_SERVICE1_PORT, KBF_TEST_SERVICE1_INST);
|
|
|
+ mdns->addService(KBF_TEST_SERVICE2_TYPE, KBF_TEST_SERVICE2_PORT, KBF_TEST_SERVICE2_INST);
|
|
|
+ mdns->addService(KBF_TEST_SERVICE3_TYPE, KBF_TEST_SERVICE3_PORT, KBF_TEST_SERVICE3_INST, net::Proto::UDP);
|
|
|
+
|
|
|
+ TEST_ASSERT_TRUE(eventGroup.waitForBit(0, 20000));
|
|
|
+ delete mdns;
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+void mdnsServiceSlave() {
|
|
|
+ eventGroup.clear();
|
|
|
+ wifi::start();
|
|
|
+ wifi::getSTA()->connect(KBF_TEST_MDNS_SSID, KBF_TEST_MDNS_PASS);
|
|
|
+ wifi::getSTA()->onIp = {[]() {
|
|
|
+ eventGroup.setBit(0);
|
|
|
+ }};
|
|
|
+ wifi::getSTA()->onDisconnect = {[]() {
|
|
|
+ TEST_ASSERT_EQUAL_STRING("", "connection error");
|
|
|
+ }};
|
|
|
+
|
|
|
+ eventGroup.waitForBit(0);
|
|
|
+ auto mdns = new net::MDNS();
|
|
|
+
|
|
|
+ auto results = mdns->queryPTR("_nonexistent", 2000);
|
|
|
+ TEST_ASSERT_EQUAL(0, results.size());
|
|
|
+
|
|
|
+ results = mdns->queryPTR(KBF_TEST_SERVICE1_TYPE, 2000);
|
|
|
+ TEST_ASSERT_EQUAL(1, results.size());
|
|
|
+// TEST_ASSERT_EQUAL(net::Interface::STA, results[0].interface);
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_MDNS_MASTER, results[0].hostName.c_str());
|
|
|
+ TEST_ASSERT_EQUAL(net::Proto::TCP, results[0].protocol);
|
|
|
+// TEST_ASSERT_EQUAL(net::IPVersion::V4, results[0].ipVersion);
|
|
|
+ TEST_ASSERT_EQUAL(KBF_TEST_SERVICE1_PORT, results[0].port);
|
|
|
+ TEST_ASSERT_EQUAL(1, results[0].addresses.size());
|
|
|
+ TEST_ASSERT_EQUAL_STRING("192.168.4.1", results[0].addresses[0].str().c_str());
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_SERVICE1_INST, results[0].instanceName.c_str());
|
|
|
+
|
|
|
+ results = mdns->queryPTR(KBF_TEST_SERVICE2_TYPE, 2000);
|
|
|
+ TEST_ASSERT_EQUAL(1, results.size());
|
|
|
+// TEST_ASSERT_EQUAL(net::Interface::STA, results[1].interface);
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_MDNS_MASTER, results[0].hostName.c_str());
|
|
|
+ TEST_ASSERT_EQUAL(net::Proto::TCP, results[0].protocol);
|
|
|
+// TEST_ASSERT_EQUAL(net::IPVersion::V4, results[1].ipVersion);
|
|
|
+ TEST_ASSERT_EQUAL(KBF_TEST_SERVICE2_PORT, results[0].port);
|
|
|
+ TEST_ASSERT_EQUAL(1, results[0].addresses.size());
|
|
|
+ TEST_ASSERT_EQUAL_STRING("192.168.4.1", results[0].addresses[0].str().c_str());
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_SERVICE2_INST, results[0].instanceName.c_str());
|
|
|
+
|
|
|
+ results = mdns->queryPTR(KBF_TEST_SERVICE3_TYPE, 2000, net::Proto::UDP);
|
|
|
+ TEST_ASSERT_EQUAL(1, results.size());
|
|
|
+// TEST_ASSERT_EQUAL(net::Interface::STA, results[0].interface);
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_MDNS_MASTER, results[0].hostName.c_str());
|
|
|
+ TEST_ASSERT_EQUAL(net::Proto::UDP, results[0].protocol);
|
|
|
+// TEST_ASSERT_EQUAL(net::IPVersion::V4, results[0].ipVersion);
|
|
|
+ TEST_ASSERT_EQUAL(KBF_TEST_SERVICE3_PORT, results[0].port);
|
|
|
+ TEST_ASSERT_EQUAL(1, results[0].addresses.size());
|
|
|
+ TEST_ASSERT_EQUAL_STRING("192.168.4.1", results[0].addresses[0].str().c_str());
|
|
|
+ TEST_ASSERT_EQUAL_STRING(KBF_TEST_SERVICE3_INST, results[0].instanceName.c_str());
|
|
|
+
|
|
|
+ delete mdns;
|
|
|
+ wifi::stop();
|
|
|
+}
|
|
|
+
|
|
|
+TEST_CASE_MULTIPLE_DEVICES("mDNS", "[kbf_net]", mdnsServiceMaster, mdnsServiceSlave)
|