Public Access
M1 step 2: Wi-Fi Service, Saved Networks, NTP, Settings page
- lib/wifi (host-tested): SavedNetworks (up to 8, validated, hidden flag, persisted) and WifiController (joins the strongest Saved Network, tries hidden ones in turn, backoff 10/30/60 s, connect timeout, Monitoring override, radio off without Saved Networks) - WifiService carries out the controller's actions, sets the EU country code, and syncs the Clock over SNTP without touching the TZ - Wi-Fi On/Off setting; Settings > Wi-Fi page: status, add from a scan or a hidden network, forget - Status Bar: W + signal bars, W? while searching, MON while monitoring - Serial: wifi add / wifi status (replaces the step 1 heap probe) Verified on the device: joins the test network ~5 s after boot, clock set over NTP, ~129 KB free heap while connected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
#include <unity.h>
|
||||
|
||||
#include "../memory_store.h"
|
||||
#include "saved_networks.h"
|
||||
|
||||
using namespace roro;
|
||||
|
||||
void setUp() {}
|
||||
void tearDown() {}
|
||||
|
||||
void test_empty_store_has_no_networks() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
TEST_ASSERT_EQUAL(0, n.count());
|
||||
}
|
||||
|
||||
void test_added_networks_survive_reload() {
|
||||
MemoryStore store;
|
||||
{
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
TEST_ASSERT_TRUE(n.add("home", "password1").empty());
|
||||
TEST_ASSERT_TRUE(n.add("cafe", "").empty()); // open network
|
||||
}
|
||||
SavedNetworks again(store);
|
||||
again.load();
|
||||
TEST_ASSERT_EQUAL(2, again.count());
|
||||
TEST_ASSERT_EQUAL_STRING("home", again.at(0).ssid.c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("password1", again.at(0).password.c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("", again.at(1).password.c_str());
|
||||
}
|
||||
|
||||
void test_adding_an_existing_ssid_updates_its_password() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
n.add("home", "password1");
|
||||
n.add("home", "password2");
|
||||
TEST_ASSERT_EQUAL(1, n.count());
|
||||
TEST_ASSERT_EQUAL_STRING("password2", n.at(0).password.c_str());
|
||||
}
|
||||
|
||||
void test_at_most_eight_networks() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
for (int i = 0; i < 8; i++) TEST_ASSERT_TRUE(n.add("net" + std::to_string(i), "").empty());
|
||||
TEST_ASSERT_FALSE(n.add("ninth", "").empty());
|
||||
TEST_ASSERT_EQUAL(8, n.count());
|
||||
}
|
||||
|
||||
void test_forget_removes_and_persists() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
n.add("a", "");
|
||||
n.add("b", "");
|
||||
n.add("c", "");
|
||||
n.forget("b");
|
||||
SavedNetworks again(store);
|
||||
again.load();
|
||||
TEST_ASSERT_EQUAL(2, again.count());
|
||||
TEST_ASSERT_EQUAL_STRING("a", again.at(0).ssid.c_str());
|
||||
TEST_ASSERT_EQUAL_STRING("c", again.at(1).ssid.c_str());
|
||||
}
|
||||
|
||||
void test_validation_follows_wifi_limits() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
TEST_ASSERT_FALSE(n.add("", "").empty()); // SSID 1..32 bytes
|
||||
TEST_ASSERT_FALSE(n.add(std::string(33, 's'), "").empty());
|
||||
TEST_ASSERT_FALSE(n.add("home", "short").empty()); // WPA: 8..63, or empty for open
|
||||
TEST_ASSERT_FALSE(n.add("home", std::string(64, 'p')).empty());
|
||||
TEST_ASSERT_TRUE(n.add(std::string(32, 's'), std::string(63, 'p')).empty());
|
||||
}
|
||||
|
||||
void test_hidden_flag_survives_reload() {
|
||||
MemoryStore store;
|
||||
{
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
n.add("secret", "password1", true);
|
||||
}
|
||||
SavedNetworks again(store);
|
||||
again.load();
|
||||
TEST_ASSERT_TRUE(again.at(0).hidden);
|
||||
}
|
||||
|
||||
void test_find() {
|
||||
MemoryStore store;
|
||||
SavedNetworks n(store);
|
||||
n.load();
|
||||
n.add("home", "password1");
|
||||
TEST_ASSERT_NOT_NULL(n.find("home"));
|
||||
TEST_ASSERT_NULL(n.find("other"));
|
||||
}
|
||||
|
||||
int main() {
|
||||
UNITY_BEGIN();
|
||||
RUN_TEST(test_empty_store_has_no_networks);
|
||||
RUN_TEST(test_added_networks_survive_reload);
|
||||
RUN_TEST(test_adding_an_existing_ssid_updates_its_password);
|
||||
RUN_TEST(test_at_most_eight_networks);
|
||||
RUN_TEST(test_forget_removes_and_persists);
|
||||
RUN_TEST(test_validation_follows_wifi_limits);
|
||||
RUN_TEST(test_hidden_flag_survives_reload);
|
||||
RUN_TEST(test_find);
|
||||
return UNITY_END();
|
||||
}
|
||||
Reference in New Issue
Block a user