Test quota display, stale responses and startup directory retries
This commit is contained in:
1 parent
594017ba5f
commit
db6acf8662
2 files changed
+40
-2
No files matched your search
@@ -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);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user