From 49d9d3567a36477ce03e97dbc414ebf0ca04b249 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 27 Oct 2026 18:54:21 +0100 Subject: [PATCH] Keep send fault injection and callback lifetimes isolated in tests --- tools/chatgui/tests/test_file_drop.cpp | 1 + tools/chatgui/tests/test_group_edits.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/tests/test_file_drop.cpp b/tools/chatgui/tests/test_file_drop.cpp index b0de1e88a..0081aa39d 100644 --- a/tools/chatgui/tests/test_file_drop.cpp +++ b/tools/chatgui/tests/test_file_drop.cpp @@ -73,6 +73,7 @@ private slots: InputBar bar(nullptr, nullptr); bar.setRecordingContext("/tmp", "123"); auto* editor = bar.findChild(); QVERIFY(editor); QSignalSpy sends(&bar, &InputBar::sendMessage); editor->setPlainText("first"); QVERIFY(QMetaObject::invokeMethod(&bar, "onSendClicked", Qt::DirectConnection)); + QVERIFY(sends[0][2].toULongLong()); editor->setPlainText("second"); bar.submissionResult(sends[0][2].toULongLong(), true); QCOMPARE(editor->toPlainText(), QString("second")); QVERIFY(QMetaObject::invokeMethod(&bar, "onSendClicked", Qt::DirectConnection)); diff --git a/tools/chatgui/tests/test_group_edits.cpp b/tools/chatgui/tests/test_group_edits.cpp index 639f03aac..0eab1c15f 100644 --- a/tools/chatgui/tests/test_group_edits.cpp +++ b/tools/chatgui/tests/test_group_edits.cpp @@ -6,6 +6,7 @@ #include "../src/inputbar.h" #include "../src/soundsettingspage.h" #include "../src/channelsettingsdialog.h" +#include "../src/animtimer.h" #include "../db/db_manager.h" #include "../transport/utun_node.h" #include "../transport/gui_bridge.h" @@ -20,9 +21,11 @@ #include #include #include +#include extern "C" { #include "utun_instance.h" #include "chat/chat_core.h" +#include "chat/chat_event.h" #include "debug_config.h" #include "mem.h" } @@ -57,6 +60,9 @@ struct SendCore { QString channel; QByteArray original; ~SendCore() { +#ifdef Q_OS_LINUX + sendAllocationFailure = 0; +#endif delete history.data(); sendHistory.clear(); gui_bridge_set_inst(nullptr); gui_bridge_set_uasync(nullptr); gui_bridge_set_msg_submitted_cb(nullptr); db.setDb(nullptr); if (ua) uasync_mark_stopped(ua); @@ -129,14 +135,15 @@ private slots: QSignalSpy sends(core.input(), &InputBar::sendMessage); const auto before = u_get_allocated_count(); if (failure == "unavailable") gui_bridge_set_inst(nullptr); if (failure == "stopped") uasync_mark_stopped(core.ua); - const QByteArray table = core.db.msgTableName(core.channel).toUtf8(); + QByteArray table = core.db.msgTableName(core.channel).toUtf8(); + const auto clearAuthorizer = qScopeGuard([&] { sqlite3_set_authorizer(core.db.m_db, nullptr, nullptr); }); if (failure == "sql") QCOMPARE(sqlite3_set_authorizer(core.db.m_db, [](void* arg, int action, const char* table, const char*, const char*, const char*) { if (action == SQLITE_INSERT && table && !strcmp(table, static_cast(arg))) { DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "[INJECT] message INSERT refused"); return SQLITE_DENY; } return SQLITE_OK; - }, const_cast(table.constData())), SQLITE_OK); + }, table.data()), SQLITE_OK); #ifdef Q_OS_LINUX if (failure == "text-allocation") sendAllocationFailure = 1; if (failure == "queue-allocation") sendAllocationFailure = 2;