You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

61 lines
3.7 KiB

/* Реальный браузер Qt с захватом bridge-команд: выбор подписанного storage через
* NAT, права чужого UID и отбрасывание старого LIST после смены каталога. */
#include "../src/member_files/browser.h"
#include "../db/db_manager.h"
#include "../transport/gui_bridge.h"
#include <QtTest>
#include <QComboBox>
#include <QTreeWidget>
#include <QPushButton>
extern "C" {
#include "member_files/member_files.h"
#include "mem.h"
}
static mf_gui_request captured;
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;
u_free(arg);
}
class BrowserTest : public QObject {
Q_OBJECT
private slots:
void rolePermissionsAndLateResponse() {
sqlite3* sql = nullptr; QCOMPARE(sqlite3_open(":memory:", &sql), SQLITE_OK);
QCOMPARE(sqlite3_exec(sql, "CREATE TABLE accounts(node_id INTEGER,display_name TEXT);"
"INSERT INTO accounts VALUES(11,'Author'),(22,'Reader'),(33,'Server');"
"CREATE TABLE peers_42(node_id INTEGER,storage INTEGER,adm_tags TEXT,adm_tags_sig BLOB,deleted INTEGER,source INTEGER);"
"INSERT INTO peers_42 VALUES(11,0,'{}',NULL,0,0),(22,0,'{}',NULL,0,0),"
"(33,0,'{\"storage\":\"yes\"}',zeroblob(64),0,0);", nullptr, nullptr, nullptr), SQLITE_OK);
DbManager db; db.setDb(sql); db.setMyNodeId(22);
{
MemberFileBrowser browser(&db); browser.setChannel("42", 11);
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);
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;
r.data[0] = (uint8_t)n; r.data[2] = MF_FILE; mf_put64(r.data + 3, 123);
memcpy(r.data + MF_ENTRY_HEADER, name, n); r.data_len = MF_ENTRY_HEADER + n;
uint8_t packet[16 + MF_WIRE_MAX]; mf_put64(packet, 42); mf_put64(packet + 8, 33);
int length = mf_encode(&r, packet + 16, MF_WIRE_MAX); browser.onResponse(packet, length + 16);
auto* table = browser.findChild<QTreeWidget*>(); QCOMPARE(table->topLevelItemCount(), 1);
table->setCurrentItem(table->topLevelItem(0));
for (auto* button : browser.findChildren<QPushButton*>()) {
if (button->text().startsWith("Upload") || button->text().startsWith("Rename") || button->text() == "Delete")
QVERIFY(!button->isEnabled());
if (button->text().startsWith("Download")) QVERIFY(button->isEnabled());
}
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);
browser.onResponse(packet, length + 16); QCOMPARE(table->topLevelItemCount(), 0);
for (auto* button : browser.findChildren<QPushButton*>()) if (button->text().startsWith("Upload")) QVERIFY(button->isEnabled());
}
db.setDb(nullptr); QCOMPARE(sqlite3_close(sql), SQLITE_OK);
}
};
QTEST_MAIN(BrowserTest)
#include "test_member_files_browser.moc"