Public Access
- lib/wifi (host-tested): scan_log (CSV field quoting, header/row, a once-per-interval throttle) and network_list_view (sort by signal / channel / name, filter open-only / hide-hidden / strong-only) - ScanEntry moved to lib/wifi so both are testable on the PC - Wi-Fi Tools networks view: s sort, o/h/w filters, l toggles logging to /wifi/scans/<date>.csv (header + one row per AP per logged scan, throttled 30 s, needs the clock for timestamps); foreground-only - Wi-Fi scan logs replace probe-request logs as a clean-up category - Serial: cat <path>, and key <char> injects a character Verified on the device: CSV written with header, timestamps, BSSID, channel, RSSI, security and SSID; hidden networks marked. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
69 lines
2.2 KiB
C++
69 lines
2.2 KiB
C++
#include <unity.h>
|
|
|
|
#include "scan_log.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
static ScanEntry ap(std::string ssid, std::string bssid, int ch, int rssi, std::string sec) {
|
|
return {ssid, bssid, ch, rssi, sec == "open", sec};
|
|
}
|
|
|
|
void test_plain_fields_are_unquoted() {
|
|
TEST_ASSERT_EQUAL_STRING("home", scanlog::csvField("home").c_str());
|
|
TEST_ASSERT_EQUAL_STRING("WPA2", scanlog::csvField("WPA2").c_str());
|
|
}
|
|
|
|
void test_fields_with_commas_or_quotes_are_quoted() {
|
|
TEST_ASSERT_EQUAL_STRING("\"a,b\"", scanlog::csvField("a,b").c_str());
|
|
TEST_ASSERT_EQUAL_STRING("\"say \"\"hi\"\"\"", scanlog::csvField("say \"hi\"").c_str());
|
|
}
|
|
|
|
void test_header_and_row() {
|
|
TEST_ASSERT_EQUAL_STRING("time,bssid,channel,rssi,security,ssid", scanlog::header().c_str());
|
|
auto r = scanlog::row("2026-10-03 20:45:01", ap("home", "aa:bb:cc:dd:ee:ff", 6, -55, "WPA2"));
|
|
TEST_ASSERT_EQUAL_STRING("2026-10-03 20:45:01,aa:bb:cc:dd:ee:ff,6,-55,WPA2,home", r.c_str());
|
|
}
|
|
|
|
void test_hidden_network_row() {
|
|
auto r = scanlog::row("t", ap("", "aa:bb:cc:dd:ee:ff", 1, -70, "WPA2"));
|
|
TEST_ASSERT_TRUE(r.find(",(hidden)") != std::string::npos);
|
|
}
|
|
|
|
void test_ssid_with_a_comma_is_quoted_in_the_row() {
|
|
auto r = scanlog::row("t", ap("cafe, bar", "aa:bb", 11, -40, "open"));
|
|
TEST_ASSERT_TRUE(r.find("\"cafe, bar\"") != std::string::npos);
|
|
}
|
|
|
|
void test_throttle_logs_once_per_interval() {
|
|
ScanLogThrottle t(30000);
|
|
TEST_ASSERT_TRUE(t.due(0)); // first time
|
|
t.logged(1000);
|
|
TEST_ASSERT_FALSE(t.due(30999));
|
|
TEST_ASSERT_TRUE(t.due(31000));
|
|
t.logged(31000);
|
|
TEST_ASSERT_FALSE(t.due(40000));
|
|
}
|
|
|
|
void test_reset_makes_it_due_again() {
|
|
ScanLogThrottle t(30000);
|
|
t.logged(1000);
|
|
TEST_ASSERT_FALSE(t.due(2000));
|
|
t.reset();
|
|
TEST_ASSERT_TRUE(t.due(2000));
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_plain_fields_are_unquoted);
|
|
RUN_TEST(test_fields_with_commas_or_quotes_are_quoted);
|
|
RUN_TEST(test_header_and_row);
|
|
RUN_TEST(test_hidden_network_row);
|
|
RUN_TEST(test_ssid_with_a_comma_is_quoted_in_the_row);
|
|
RUN_TEST(test_throttle_logs_once_per_interval);
|
|
RUN_TEST(test_reset_makes_it_due_again);
|
|
return UNITY_END();
|
|
}
|