Verify desktop image previews decode asynchronously and paint without file I/O
This commit is contained in:
1 parent
154c76068c
commit
199eaa0429
1 file changed
+28
@@ -6,6 +6,7 @@
|
||||
#include "../db/db_manager.h"
|
||||
#include "../src/inputbar.h"
|
||||
#include "../src/messagedelegate.h"
|
||||
#include "../src/messagelist.h"
|
||||
#include "../src/sound_manager.h"
|
||||
#include <QtTest>
|
||||
#include <QTemporaryDir>
|
||||
@@ -186,6 +187,33 @@ private slots:
|
||||
QCOMPARE(outstanding.size(), size_t(0));
|
||||
#endif
|
||||
}
|
||||
void imagePreviewPreparedOutsidePaint() {
|
||||
QTemporaryDir directory; QVERIFY(directory.isValid());
|
||||
const QString path = directory.filePath("image.png");
|
||||
QImage original(1200, 1800, QImage::Format_ARGB32); original.fill(Qt::red); QVERIFY(original.save(path));
|
||||
MessageList history; history.resize(600, 500); history.show();
|
||||
auto* model = history.findChild<QStandardItemModel*>(); QVERIFY(model);
|
||||
auto* view = history.findChild<QListView*>(); QVERIFY(view);
|
||||
auto* item = new QStandardItem;
|
||||
item->setData("image/png", MsgContentTypeRole); item->setData(path, MsgVoiceFileRole);
|
||||
item->setData(1200, MsgImageWidthRole); item->setData(1800, MsgImageHeightRole);
|
||||
item->setData(2, MsgFileDownloadStateRole); model->appendRow(item);
|
||||
QTRY_VERIFY_WITH_TIMEOUT(!item->data(MsgImagePreviewRole).value<QImage>().isNull(), 3000);
|
||||
const QImage preview = item->data(MsgImagePreviewRole).value<QImage>();
|
||||
QVERIFY(preview.width() <= 600 && preview.height() <= 600);
|
||||
QCOMPARE(preview.width() * 3, preview.height() * 2); QVERIFY(!item->data(MsgImageErrorRole).toBool());
|
||||
QVERIFY(QFile::remove(path)); // Paint обязан использовать подготовленное превью даже без файла на диске.
|
||||
QImage canvas(600, 400, QImage::Format_ARGB32); canvas.fill(Qt::black);
|
||||
QStyleOptionViewItem option; option.initFrom(view); option.rect = canvas.rect();
|
||||
QPainter painter(&canvas); view->itemDelegate()->paint(&painter, option, model->index(0, 0)); painter.end();
|
||||
int red = 0;
|
||||
for (int y = 0; y < canvas.height(); ++y) for (int x = 0; x < canvas.width(); ++x) {
|
||||
const QColor color = canvas.pixelColor(x, y);
|
||||
if (color.red() > 220 && color.green() < 30 && color.blue() < 30) ++red;
|
||||
}
|
||||
QVERIFY(red > 1000);
|
||||
}
|
||||
|
||||
void boundCommand_data() {
|
||||
QTest::addColumn<QString>("scenario");
|
||||
for (const auto& name : {"unavailable", "stopped", "cancelled", "executed"}) QTest::newRow(name) << QString(name);
|
||||
|
||||
Reference in new issue
Block a user