mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-21 18:22:37 +10:00
Refactor WiFiManager: extract server and handlers into separate modules
- Move server lifecycle management to WiFiManagerServer - Move HTTP handlers and rendering to WiFiManagerHandlers - Move DEBUG_WM template definitions to WiFiManagerDebug - Implement lazy initialization of server manager to save memory - Add proper cleanup in destructor and on multiple createServer calls - Update tests to use getServer() and getDNSServer() accessors
This commit is contained in:
@@ -15,13 +15,13 @@ void test_dns_server_created() {
|
||||
|
||||
// Wait for DNS server to be created
|
||||
unsigned long start = millis();
|
||||
while (!wm.dnsServer && (millis() - start < 1000)) {
|
||||
while (!wm.getDNSServer() && (millis() - start < 1000)) {
|
||||
wm.process();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// DNS server should be created when portal starts
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
wm.stopConfigPortal();
|
||||
|
||||
@@ -40,13 +40,13 @@ void test_dns_server_cleanup() {
|
||||
|
||||
// Wait for DNS server to be created
|
||||
unsigned long start = millis();
|
||||
while (!wm.dnsServer && (millis() - start < 1000)) {
|
||||
while (!wm.getDNSServer() && (millis() - start < 1000)) {
|
||||
wm.process();
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// Verify DNS server exists
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
// Stop portal
|
||||
wm.stopConfigPortal();
|
||||
@@ -72,11 +72,11 @@ void test_dns_server_lifecycle_cycles() {
|
||||
wm.process();
|
||||
|
||||
unsigned long start = millis();
|
||||
while (!wm.dnsServer && (millis() - start < 1000)) {
|
||||
while (!wm.getDNSServer() && (millis() - start < 1000)) {
|
||||
wm.process();
|
||||
delay(10);
|
||||
}
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
wm.stopConfigPortal();
|
||||
wm.process();
|
||||
@@ -87,11 +87,11 @@ void test_dns_server_lifecycle_cycles() {
|
||||
wm.process();
|
||||
|
||||
start = millis();
|
||||
while (!wm.dnsServer && (millis() - start < 1000)) {
|
||||
while (!wm.getDNSServer() && (millis() - start < 1000)) {
|
||||
wm.process();
|
||||
delay(10);
|
||||
}
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
wm.stopConfigPortal();
|
||||
wm.process();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <unity.h>
|
||||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <WiFiManagerParameter.h>
|
||||
#include "../test_main.h"
|
||||
|
||||
// Test autoConnect fallback flow
|
||||
@@ -145,8 +146,8 @@ void test_portal_with_parameters_and_infrastructure() {
|
||||
TEST_ASSERT_TRUE(wm.getConfigPortalActive());
|
||||
|
||||
// Verify infrastructure
|
||||
TEST_ASSERT_NOT_NULL(wm.server);
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getServer());
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
// Verify parameters
|
||||
TEST_ASSERT_EQUAL(2, wm.getParametersCount());
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <unity.h>
|
||||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <WiFiManagerParameter.h>
|
||||
#include "../test_main.h"
|
||||
|
||||
// Test parameter value set directly
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <unity.h>
|
||||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <WiFiManagerParameter.h>
|
||||
|
||||
// Test custom parameters
|
||||
void test_create_parameter() {
|
||||
|
||||
@@ -107,10 +107,10 @@ void test_config_portal_infrastructure() {
|
||||
delay(200); // Give time for initialization
|
||||
|
||||
// Verify server object exists (must check while portal is active)
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(wm.server, "Server object should exist when portal is active");
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(wm.getServer(), "Server object should exist when portal is active");
|
||||
|
||||
// Verify DNS server exists
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(wm.dnsServer, "DNS server object should exist when portal is active");
|
||||
TEST_ASSERT_NOT_NULL_MESSAGE(wm.getDNSServer(), "DNS server object should exist when portal is active");
|
||||
|
||||
// Verify WiFi is in AP mode
|
||||
WiFiMode_t mode = WiFi.getMode();
|
||||
@@ -145,7 +145,7 @@ void test_start_web_portal() {
|
||||
wm.process();
|
||||
|
||||
// Verify server object exists
|
||||
TEST_ASSERT_NOT_NULL(wm.server);
|
||||
TEST_ASSERT_NOT_NULL(wm.getServer());
|
||||
|
||||
wm.stopWebPortal();
|
||||
|
||||
|
||||
@@ -76,8 +76,8 @@ void test_state_consistency_during_portal() {
|
||||
|
||||
// Verify state consistency
|
||||
TEST_ASSERT_TRUE(wm.getConfigPortalActive());
|
||||
TEST_ASSERT_NOT_NULL(wm.server);
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getServer());
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
// Process multiple times
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <unity.h>
|
||||
#include <Arduino.h>
|
||||
#include <WiFiManager.h>
|
||||
#include <WiFiManagerParameter.h>
|
||||
#include "../test_main.h"
|
||||
|
||||
// Test many start/stop cycles for memory leaks
|
||||
@@ -56,8 +57,8 @@ void test_long_running_portal() {
|
||||
TEST_ASSERT_TRUE(wm.getConfigPortalActive());
|
||||
|
||||
// Verify infrastructure remains
|
||||
TEST_ASSERT_NOT_NULL(wm.server);
|
||||
TEST_ASSERT_NOT_NULL(wm.dnsServer);
|
||||
TEST_ASSERT_NOT_NULL(wm.getServer());
|
||||
TEST_ASSERT_NOT_NULL(wm.getDNSServer());
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user