Keep send fault injection and callback lifetimes isolated in tests
This commit is contained in:
1 parent
426973ae86
commit
49d9d3567a
2 files changed
+10
-2
No files matched your search
@@ -73,6 +73,7 @@ private slots:
|
||||
InputBar bar(nullptr, nullptr); bar.setRecordingContext("/tmp", "123");
|
||||
auto* editor = bar.findChild<QTextEdit*>(); 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));
|
||||
|
||||
@@ -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 <QPointer>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <atomic>
|
||||
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<const char*>(arg))) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_CHAT_SYNC, "[INJECT] message INSERT refused"); return SQLITE_DENY;
|
||||
}
|
||||
return SQLITE_OK;
|
||||
}, const_cast<char*>(table.constData())), SQLITE_OK);
|
||||
}, table.data()), SQLITE_OK);
|
||||
#ifdef Q_OS_LINUX
|
||||
if (failure == "text-allocation") sendAllocationFailure = 1;
|
||||
if (failure == "queue-allocation") sendAllocationFailure = 2;
|
||||
|
||||
Reference in new issue
Block a user