Files
utun2/tools/chatgui/tests/test_config_updater.cpp
T
Evgeny 1889d23240 metrics: RTT/loss histograms + Ed25519 signing + peer exchange via INIT handshake + file logging to stats/<peer>.dat
- etcp_metrics struct: 12-bucket RTT histogram, 11-bucket loss histogram, 10-min snapshots (>=200 pkts)
- Total counters: packets/bytes sent/rcvd, losses (retrans + probe gap detection)
- CSV append to <stats_dir>/<peer_id>.dat every 10 min
- Ed25519 pubkey exchange in INIT handshake (V3), always present
- Signed metrics exchange via ETCP_SECTION_METRICS (0x0A)
- Received metrics saved as from_<peer_id>.dat with signature hex
- on_metrics_rcvd callback in ETCP_BINDINGS
- stats_dir derived from config file path, mkdir'd at instance init
- Simplified versioning: ETCP_INIT_REQ_SIZE / ETCP_INIT_RESP_SIZE via sizeof
2026-07-07 17:16:45 +03:00

110 lines
3.4 KiB
C++

// tests/test_config_updater.cpp — Verify universal config updater
#include "../transport/config_updater.h"
#include <QFile>
#include <QString>
#include <QIODevice>
static void test_new_file() {
const char* path = "/tmp/test_cfg_new.ini";
QFile::remove(path);
bool ok = config_update_option(path, "global", "my_name", "testnode");
Q_ASSERT(ok);
QFile f(path);
Q_ASSERT(f.open(QIODevice::ReadOnly | QIODevice::Text));
QString content = f.readAll();
f.close();
Q_ASSERT(content.contains("[global]"));
Q_ASSERT(content.contains("my_name=testnode"));
QFile::remove(path);
}
static void test_replace_existing() {
const char* path = "/tmp/test_cfg_replace.ini";
QFile f(path);
Q_ASSERT(f.open(QIODevice::WriteOnly | QIODevice::Text));
f.write("[global]\nmy_name=oldname\nmy_id=abc\n\n[control]\naddr=1.2.3.4\n");
f.close();
bool ok = config_update_option(path, "global", "my_name", "newname");
Q_ASSERT(ok);
Q_ASSERT(f.open(QIODevice::ReadOnly | QIODevice::Text));
QString content = f.readAll();
f.close();
Q_ASSERT(!content.contains("my_name=oldname"));
Q_ASSERT(content.contains("my_name=newname"));
Q_ASSERT(content.contains("my_id=abc"));
Q_ASSERT(content.contains("[control]"));
Q_ASSERT(content.contains("addr=1.2.3.4"));
QFile::remove(path);
}
static void test_replace_new_param_in_section() {
const char* path = "/tmp/test_cfg_newparam.ini";
QFile f(path);
Q_ASSERT(f.open(QIODevice::WriteOnly | QIODevice::Text));
f.write("[global]\nmy_name=test\n\n[control]\naddr=1.2.3.4\n");
f.close();
bool ok = config_update_option(path, "global", "new_param", "newval");
Q_ASSERT(ok);
Q_ASSERT(f.open(QIODevice::ReadOnly | QIODevice::Text));
QString content = f.readAll();
f.close();
Q_ASSERT(content.contains("my_name=test"));
Q_ASSERT(content.contains("new_param=newval"));
Q_ASSERT(content.contains("[control]"));
QFile::remove(path);
}
static void test_append_mode() {
const char* path = "/tmp/test_cfg_append.ini";
QFile f(path);
Q_ASSERT(f.open(QIODevice::WriteOnly | QIODevice::Text));
f.write("[client:peer1]\nlink=srv:addr1:port1\nlink=srv:addr2:port2\n\n[global]\nname=x\n");
f.close();
bool ok = config_update_option(path, "client:peer1", "link", "srv:addr3:port3", CONFIG_UPDATE_APPEND);
Q_ASSERT(ok);
Q_ASSERT(f.open(QIODevice::ReadOnly | QIODevice::Text));
QString content = f.readAll();
f.close();
Q_ASSERT(content.contains("link=srv:addr1:port1"));
Q_ASSERT(content.contains("link=srv:addr2:port2"));
Q_ASSERT(content.contains("link=srv:addr3:port3"));
QFile::remove(path);
}
static void test_new_section() {
const char* path = "/tmp/test_cfg_newsect.ini";
QFile f(path);
Q_ASSERT(f.open(QIODevice::WriteOnly | QIODevice::Text));
f.write("[global]\nname=x\n");
f.close();
bool ok = config_update_option(path, "gui", "theme", "dark");
Q_ASSERT(ok);
Q_ASSERT(f.open(QIODevice::ReadOnly | QIODevice::Text));
QString content = f.readAll();
f.close();
Q_ASSERT(content.contains("[global]"));
Q_ASSERT(content.contains("name=x"));
Q_ASSERT(content.contains("[gui]"));
Q_ASSERT(content.contains("theme=dark"));
QFile::remove(path);
}
int main() {
test_new_file();
test_replace_existing();
test_replace_new_param_in_section();
test_append_mode();
test_new_section();
return 0;
}