Public Access
The IRC App edited the live config while the IRC task could be reading it to connect. The App now edits a copy; applyConfig() validates it and swaps it in under the lock, and the task connects from a snapshot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
89 lines
2.7 KiB
C++
89 lines
2.7 KiB
C++
#include <unity.h>
|
|
|
|
#include "../memory_store.h"
|
|
#include "irc_config.h"
|
|
|
|
using namespace roro;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_defaults_point_at_libera_over_tls() {
|
|
MemoryStore store;
|
|
IrcConfig c(store);
|
|
c.load("roro_2fa4");
|
|
TEST_ASSERT_EQUAL_STRING("irc.libera.chat", c.host.c_str());
|
|
TEST_ASSERT_EQUAL(6697, c.port);
|
|
TEST_ASSERT_TRUE(c.tls);
|
|
TEST_ASSERT_FALSE(c.allowSelfSigned);
|
|
TEST_ASSERT_EQUAL_STRING("roro_2fa4", c.nick.c_str());
|
|
TEST_ASSERT_TRUE(c.autojoin.empty());
|
|
}
|
|
|
|
void test_save_and_reload() {
|
|
MemoryStore store;
|
|
{
|
|
IrcConfig c(store);
|
|
c.load("x");
|
|
c.nick = "clement";
|
|
c.saslUser = "clement";
|
|
c.saslPassword = "s3cret";
|
|
c.autojoin = {"#roro", "#meshtastic"};
|
|
TEST_ASSERT_TRUE(c.save().empty());
|
|
}
|
|
IrcConfig again(store);
|
|
again.load("x");
|
|
TEST_ASSERT_EQUAL_STRING("clement", again.nick.c_str());
|
|
TEST_ASSERT_EQUAL_STRING("s3cret", again.saslPassword.c_str());
|
|
TEST_ASSERT_EQUAL(2, again.autojoin.size());
|
|
TEST_ASSERT_EQUAL_STRING("#meshtastic", again.autojoin[1].c_str());
|
|
}
|
|
|
|
void test_invalid_values_are_refused_with_a_reason() {
|
|
MemoryStore store;
|
|
IrcConfig c(store);
|
|
c.load("x");
|
|
c.nick = "1abc"; // can't start with a digit
|
|
TEST_ASSERT_FALSE(c.save().empty());
|
|
c.nick = "has space";
|
|
TEST_ASSERT_FALSE(c.save().empty());
|
|
c.nick = "ok_nick[1]";
|
|
c.port = 0;
|
|
TEST_ASSERT_FALSE(c.save().empty());
|
|
c.port = 6697;
|
|
c.host = "";
|
|
TEST_ASSERT_FALSE(c.save().empty());
|
|
c.host = "irc.libera.chat";
|
|
c.autojoin = {"roro"}; // IRC channels start with # or &
|
|
TEST_ASSERT_FALSE(c.save().empty());
|
|
}
|
|
|
|
void test_autojoin_text_round_trip() {
|
|
TEST_ASSERT_EQUAL(2, IrcConfig::parseChannels("#a, #b").size());
|
|
TEST_ASSERT_EQUAL(2, IrcConfig::parseChannels("#a #b").size());
|
|
TEST_ASSERT_EQUAL_STRING("#a #b", IrcConfig::formatChannels({"#a", "#b"}).c_str());
|
|
}
|
|
|
|
void test_copy_settings_from_a_draft() {
|
|
MemoryStore store;
|
|
IrcConfig live(store);
|
|
live.load("x");
|
|
IrcConfig draft = live;
|
|
draft.host = "irc.example.org";
|
|
draft.autojoin = {"#a"};
|
|
TEST_ASSERT_EQUAL_STRING("irc.libera.chat", live.host.c_str()); // the draft is independent
|
|
live.copySettingsFrom(draft);
|
|
TEST_ASSERT_EQUAL_STRING("irc.example.org", live.host.c_str());
|
|
TEST_ASSERT_EQUAL(1, live.autojoin.size());
|
|
}
|
|
|
|
int main() {
|
|
UNITY_BEGIN();
|
|
RUN_TEST(test_defaults_point_at_libera_over_tls);
|
|
RUN_TEST(test_save_and_reload);
|
|
RUN_TEST(test_invalid_values_are_refused_with_a_reason);
|
|
RUN_TEST(test_autojoin_text_round_trip);
|
|
RUN_TEST(test_copy_settings_from_a_draft);
|
|
return UNITY_END();
|
|
}
|