Browse Source

Test quota display, stale responses and startup directory retries

master
evgeny 1 week ago
parent
commit
db6acf8662
  1. 7
      tools/chatgui/src/member_files/browser.cpp
  2. 35
      tools/chatgui/tests/test_member_files_browser.cpp

7
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)));

35
tools/chatgui/tests/test_member_files_browser.cpp

@ -7,15 +7,22 @@
#include <QComboBox>
#include <QTreeWidget>
#include <QPushButton>
#include <QLabel>
#include <QLocale>
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<QComboBox*>(); 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<QLabel*>("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<qulonglong>(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<QPushButton*>()) 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);
}

Loading…
Cancel
Save