#include #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(); }