Просмотр исходного кода

Merge branch 'kbf-34' of kraxor/kbf into develop

Bence Balint 2 лет назад
Родитель
Сommit
823b7538d5
3 измененных файлов с 18 добавлено и 9 удалено
  1. 2 1
      src/wifi/sta.cpp
  2. 14 6
      test/wifi/test_wifi.cpp
  3. 2 2
      test/wifi/test_wifi_modeswitch.cpp

+ 2 - 1
src/wifi/sta.cpp

@@ -131,8 +131,9 @@ bool sta::connect(string ssid, string password, bool async, int maxAttempts) {
     CHECK(esp_wifi_connect());
 
     if (!async) {
-        // TODO set timeout for the case when we don't get an IP address
+        // TODO KBF-35: handle the lack of a DHCP server on the AP
         event.waitForBit(CONNECT_FINISHED);
+        return ::connected;
     }
 
     return true;

+ 14 - 6
test/wifi/test_wifi.cpp

@@ -51,7 +51,7 @@ static void singleSlave() {
     wifi::sta::onDisconnect = {[]() { TEST_FAIL(); }};
     wifi::sta::start();
 
-    wifi::sta::connect(TEST_SSID, WIFI_PASS);
+    TEST_ASSERT_TRUE(wifi::sta::connect(TEST_SSID, WIFI_PASS));
     TEST_ASSERT_EQUAL(2, state);
     TEST_ASSERT_TRUE(wifi::sta::connected());
     TEST_ASSERT_EQUAL_STRING(TEST_SSID, wifi::sta::ssid().c_str());
@@ -94,7 +94,7 @@ static void asyncSlave() {
     wifi::sta::onDisconnect = {[]() { TEST_FAIL(); }};
     wifi::sta::start();
 
-    wifi::sta::connect(TEST_SSID, WIFI_PASS, true);
+    TEST_ASSERT_TRUE(wifi::sta::connect(TEST_SSID, WIFI_PASS, true));
     TEST_ASSERT_EQUAL(0, state);
 
     event.waitForBit(0);
@@ -110,7 +110,7 @@ static void dualMaster() {
 
     wifi::ap::onConnect     = {[](wifi::STA &) {
         TEST_ASSERT_EQUAL(0, state++);
-        wifi::sta::connect(SLAVE_SSID, WIFI_PASS, true);
+        TEST_ASSERT_TRUE(wifi::sta::connect(SLAVE_SSID, WIFI_PASS, true));
     }};
     wifi::sta::onConnect    = {[]() {
         TEST_ASSERT_EQUAL(1, state++);
@@ -145,7 +145,9 @@ static void dualSlave() {
         event.setBit(0);
     }};
     wifi::dual::start(SLAVE_SSID, WIFI_PASS);
-    wifi::sta::connect(MASTER_SSID, WIFI_PASS);
+
+    // returns false because we call disconnect() before handleIp() gets called
+    TEST_ASSERT_FALSE(wifi::sta::connect(MASTER_SSID, WIFI_PASS));
 
     event.waitForBit(0);
     TEST_ASSERT_EQUAL(4, state);
@@ -180,7 +182,7 @@ static void scanSlave() {
         }
         TEST_ASSERT_TRUE(found);
 
-        wifi::sta::connect(TEST_SSID, WIFI_PASS);
+        TEST_ASSERT_TRUE(wifi::sta::connect(TEST_SSID, WIFI_PASS, true));
     }};
     wifi::sta::onConnect = {[]() { event.setBit(0); }};
 
@@ -206,7 +208,7 @@ static void ipMaster() {
 
 static void ipSlave() {
     wifi::sta::start();
-    wifi::sta::connect(TEST_SSID, WIFI_PASS);
+    TEST_ASSERT_TRUE(wifi::sta::connect(TEST_SSID, WIFI_PASS));
 
     auto ip = wifi::sta::ip().str();
     TEST_ASSERT_EQUAL_STRING("192.168.100.2", ip.c_str());
@@ -215,3 +217,9 @@ static void ipSlave() {
 }
 
 TEST_CASE_MULTIPLE_DEVICES("WiFi custom IP address", "[kbf_wifi]", ipMaster, ipSlave);
+
+TEST_CASE("WiFi connect fail", "[kbf_wifi]") {
+    wifi::sta::start();
+    TEST_ASSERT_FALSE(wifi::sta::connect("NonExistentSSID", "DefinitelyNotValid"));
+    wifi::stop();
+}

+ 2 - 2
test/wifi/test_wifi_modeswitch.cpp

@@ -106,7 +106,7 @@ void master() {
     ESP_LOGI(TAG, "3 - master switches to DUAL, slave is DUAL");
     wifi::sta::start();
     TEST_ASSERT_EQUAL(wifi::Mode::DUAL, wifi::mode());
-    wifi::sta::connect(SLAVE_SSID, WIFI_PASS);
+    TEST_ASSERT_TRUE(wifi::sta::connect(SLAVE_SSID, WIFI_PASS));
     pingOK(SLAVE_STA, 4);
     pingOK(SLAVE_AP, 5);
     waitForPing(6);
@@ -147,7 +147,7 @@ void slave() {
     pingService.start();
 
     ESP_LOGI(TAG, "1 - master: AP, slave is STA");
-    wifi::sta::connect(MASTER_SSID, WIFI_PASS);
+    TEST_ASSERT_TRUE(wifi::sta::connect(MASTER_SSID, WIFI_PASS));
     pingOK(MASTER_AP, 0);
     waitForPing(1);
     pingFail(MASTER_STA);