From db6acf866232840a5e33d6c5ce77470dacb69997 Mon Sep 17 00:00:00 2001 From: evgeny Date: Tue, 6 Oct 2026 00:25:07 +0200 Subject: [PATCH] Test quota display, stale responses and startup directory retries --- tools/chatgui/src/member_files/browser.cpp | 7 +++- .../tests/test_member_files_browser.cpp | 35 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/tools/chatgui/src/member_files/browser.cpp b/tools/chatgui/src/member_files/browser.cpp index 73583131..e87fde29 100644 --- a/tools/chatgui/src/member_files/browser.cpp +++ b/tools/chatgui/src/member_files/browser.cpp @@ -191,7 +191,11 @@ void MemberFileBrowser::refresh() { cancelRequest(m_quotaId); m_quotaId = 0; m_refreshGeneration++; m_quota->setToolTip(QString()); m_quota->setText(owner() ? text("Loading quota…") : text("Select a member to see storage quota")); - if (!server()) { m_status->setText(text("No media server in this group")); return; } + if (!server()) { + m_status->setText(text("No media server in this group")); + if (owner()) m_quota->setText(text("Quota unavailable")); + return; + } requestQuota(); mf_message q{}; q.command = MF_LIST; q.owner = owner(); if (!copyPath(q.path, m_path) || !post(q)) { m_status->setText(text("Unable to request directory")); return; } @@ -232,6 +236,7 @@ void MemberFileBrowser::onResponse(const uint8_t* data, int length) { return; } m_quotaId = 0; + m_quota->setToolTip(QString()); if (r.status) { m_quota->setText(r.status == MF_BUSY ? text("Loading quota…") : text("Quota unavailable")); m_quota->setToolTip(QString::fromUtf8(mf_status_text(r.status))); diff --git a/tools/chatgui/tests/test_member_files_browser.cpp b/tools/chatgui/tests/test_member_files_browser.cpp index 2f8764b6..e390b3cd 100644 --- a/tools/chatgui/tests/test_member_files_browser.cpp +++ b/tools/chatgui/tests/test_member_files_browser.cpp @@ -7,15 +7,22 @@ #include #include #include +#include +#include extern "C" { #include "member_files/member_files.h" #include "mem.h" } static mf_gui_request captured; +static mf_gui_request quotaCaptured; extern "C" int gui_bridge_is_uasync_ready(void) { return 1; } extern "C" UTUN_INSTANCE* gui_bridge_get_inst(void) { return nullptr; } extern "C" void gui_bridge_post_uasync_fn(void (*function)(void*), void* arg) { - if (function == member_files_gui_request) captured = *(mf_gui_request*)arg; + if (function == member_files_gui_request) { + auto* request = (mf_gui_request*)arg; + if (request->message.command == MF_QUOTA) quotaCaptured = *request; + else captured = *request; + } u_free(arg); } @@ -35,6 +42,17 @@ private slots: auto selectors = browser.findChildren(); QCOMPARE(selectors.size(), 2); QCOMPARE(selectors[0]->count(), 1); QCOMPARE(selectors[0]->currentData().toULongLong(), 33ULL); QCOMPARE(captured.message.owner, 11ULL); QCOMPARE(captured.message.command, (uint8_t)MF_LIST); + QCOMPARE(quotaCaptured.message.owner, 11ULL); QCOMPARE(quotaCaptured.message.command, (uint8_t)MF_QUOTA); + auto* quota = browser.findChild("memberFilesQuota"); QVERIFY(quota); + mf_gui_request previousQuota = quotaCaptured; + mf_message stats = quotaCaptured.message; stats.kind = MF_RESPONSE; stats.data_len = MF_QUOTA_BYTES; + mf_put64(stats.data, 2 * 1024 * 1024); mf_put64(stats.data + 8, 8 * 1024 * 1024); mf_put64(stats.data + 16, 1024 * 1024); + uint8_t quotaPacket[16 + MF_WIRE_MAX]; mf_put64(quotaPacket, 42); mf_put64(quotaPacket + 8, 33); + int quotaLength = mf_encode(&stats, quotaPacket + 16, MF_WIRE_MAX); browser.onResponse(quotaPacket, quotaLength + 16); + QCOMPARE(quota->text(), QString("Storage: %1 used / %2 total · Reserved for uploads: %3") + .arg(QLocale().formattedDataSize(2 * 1024 * 1024, 2), QLocale().formattedDataSize(8 * 1024 * 1024, 2), + QLocale().formattedDataSize(1024 * 1024, 2))); + QVERIFY(quota->toolTip().contains("2097152")); mf_gui_request previous = captured; mf_message r = previous.message; r.kind = MF_RESPONSE; r.type = MF_DIRECTORY; const char name[] = "readme.txt"; unsigned n = sizeof(name) - 1; @@ -51,8 +69,23 @@ private slots: } int own = selectors[1]->findData(QVariant::fromValue(22)); QVERIFY(own >= 0); selectors[1]->setCurrentIndex(own); QCOMPARE(captured.message.owner, 22ULL); QCOMPARE(table->topLevelItemCount(), 0); + QCOMPARE(quotaCaptured.message.owner, 22ULL); QVERIFY(quotaCaptured.message.request_id != previousQuota.message.request_id); + browser.onResponse(quotaPacket, quotaLength + 16); QCOMPARE(quota->text(), QString("Loading quota…")); + stats = quotaCaptured.message; stats.kind = MF_RESPONSE; stats.data_len = MF_QUOTA_BYTES; + mf_put64(stats.data, 3 * 1024 * 1024); mf_put64(stats.data + 8, 8 * 1024 * 1024); + quotaLength = mf_encode(&stats, quotaPacket + 16, MF_WIRE_MAX); browser.onResponse(quotaPacket, quotaLength + 16); + QString ownQuota = QString("Storage: %1 used / %2 total") + .arg(QLocale().formattedDataSize(3 * 1024 * 1024, 2), QLocale().formattedDataSize(8 * 1024 * 1024, 2)); + QCOMPARE(quota->text(), ownQuota); browser.onResponse(packet, length + 16); QCOMPARE(table->topLevelItemCount(), 0); for (auto* button : browser.findChildren()) if (button->text().startsWith("Upload")) QVERIFY(button->isEnabled()); + mf_message busy = captured.message; busy.kind = MF_RESPONSE; busy.status = MF_BUSY; + length = mf_encode(&busy, packet + 16, MF_WIRE_MAX); browser.onResponse(packet, length + 16); + QTRY_VERIFY_WITH_TIMEOUT(captured.message.request_id != busy.request_id, 1500); + QCOMPARE(captured.message.owner, 22ULL); + selectors[1]->setCurrentIndex(0); QCOMPARE(quota->text(), QString("Select a member to see storage quota")); + browser.onResponse(quotaPacket, quotaLength + 16); + QCOMPARE(quota->text(), QString("Select a member to see storage quota")); } db.setDb(nullptr); QCOMPARE(sqlite3_close(sql), SQLITE_OK); }