v31.1-roots.1 · Commit 8: [PATCH 08/17] chore(roots): integrate v31 identity and maintenance tooling
src/qt/test/wallettests.cpp
Before: src/qt/test/wallettests.cpp · After: src/qt/test/wallettests.cpp
File metadata
index 41b00b2313b920956b7434f1174ac9dadb1d87c9..a09c3798a73e8e6e25fb369e2c4ca4d6fb9b9fc8 100644
Download original patch · Release notes
Diff rows 1–85 of 85. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
src/qt/test/wallettests.cpp
CHANGED
|
@@ -22,6 +22,11 @@
|
|
| 22 |
#include <qt/qvalidatedlineedit.h>
|
| 23 |
#include <qt/receivecoinsdialog.h>
|
| 24 |
#include <qt/receiverequestdialog.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
#include <qt/recentrequeststablemodel.h>
|
| 26 |
#include <qt/sendcoinsdialog.h>
|
| 27 |
#include <qt/sendcoinsentry.h>
|
|
@@ -126,6 +131,23 @@ bool CaptureWalletWidget(QWidget& widget, const QString& name)
|
|
| 126 |
return widget.size() == size && QDir().mkpath(directory) && widget.grab().save(directory + '/' + name + ".png");
|
| 127 |
}
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.
|
| 130 |
void ConfirmSend(QString* text = nullptr, QMessageBox::StandardButton confirm_type = QMessageBox::Yes)
|
| 131 |
{
|
|
@@ -699,6 +721,51 @@ void TestGUI(interfaces::Node& node, const std::shared_ptr<CWallet>& wallet)
|
|
| 699 |
QCOMPARE(uri.count("message=TEST_MESSAGE_1"), 2);
|
| 700 |
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_tag")->text(), QString("Message:"));
|
| 701 |
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_content")->text(), QString("TEST_MESSAGE_1"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 702 |
}
|
| 703 |
}
|
| 704 |
|
|
|
|
| 22 |
#include <qt/qvalidatedlineedit.h>
|
| 23 |
#include <qt/receivecoinsdialog.h>
|
| 24 |
#include <qt/receiverequestdialog.h>
|
| 25 |
+
#include <qt/qrimagewidget.h>
|
| 26 |
+
#include <QFileDialog>
|
| 27 |
+
#include <QFileInfo>
|
| 28 |
+
#include <QTemporaryDir>
|
| 29 |
+
#include <QTimer>
|
| 30 |
#include <qt/recentrequeststablemodel.h>
|
| 31 |
#include <qt/sendcoinsdialog.h>
|
| 32 |
#include <qt/sendcoinsentry.h>
|
|
|
|
| 131 |
return widget.size() == size && QDir().mkpath(directory) && widget.grab().save(directory + '/' + name + ".png");
|
| 132 |
}
|
| 133 |
|
| 134 |
+
//! Receive/save dialogs keep their production size; evidence records the
|
| 135 |
+
//! complete screen at the caller's resolution instead of forcing a layout.
|
| 136 |
+
bool CaptureReceiveWidget(QWidget& widget, const QString& name)
|
| 137 |
+
{
|
| 138 |
+
const QString directory{qEnvironmentVariable("ROOTS_WALLET_CAPTURE_DIR")};
|
| 139 |
+
if (directory.isEmpty()) return true;
|
| 140 |
+
const auto dimensions{qEnvironmentVariable("ROOTS_WALLET_CAPTURE_SIZE", "1280x800").split('x')};
|
| 141 |
+
if (dimensions.size() != 2) return false;
|
| 142 |
+
const QSize size{dimensions[0].toInt(), dimensions[1].toInt()};
|
| 143 |
+
widget.show();
|
| 144 |
+
qApp->processEvents();
|
| 145 |
+
widget.move(std::max(0, (size.width() - widget.width()) / 2), std::max(0, (size.height() - widget.height()) / 2));
|
| 146 |
+
QTest::qWait(50);
|
| 147 |
+
const auto screenshot{widget.screen()->grabWindow(0)};
|
| 148 |
+
return screenshot.size() == size && QDir().mkpath(directory) && screenshot.save(directory + '/' + name + ".png");
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
//! Press "Yes" or "Cancel" buttons in modal send confirmation dialog.
|
| 152 |
void ConfirmSend(QString* text = nullptr, QMessageBox::StandardButton confirm_type = QMessageBox::Yes)
|
| 153 |
{
|
|
|
|
| 721 |
QCOMPARE(uri.count("message=TEST_MESSAGE_1"), 2);
|
| 722 |
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_tag")->text(), QString("Message:"));
|
| 723 |
QCOMPARE(receiveRequestDialog->QObject::findChild<QLabel*>("message_content")->text(), QString("TEST_MESSAGE_1"));
|
| 724 |
+
#ifdef USE_QRCODE
|
| 725 |
+
auto* qr = receiveRequestDialog->findChild<QRImageWidget*>("qr_code");
|
| 726 |
+
auto* save = receiveRequestDialog->findChild<QPushButton*>("btnSaveAs");
|
| 727 |
+
QVERIFY(qr && save && save->isEnabled());
|
| 728 |
+
const QImage exported{qr->exportImage()};
|
| 729 |
+
QVERIFY(!exported.isNull());
|
| 730 |
+
// Exercise the actual receive dialog and save action with an
|
| 731 |
+
// isolated filename, never a real wallet address or directory.
|
| 732 |
+
QVERIFY(CaptureReceiveWidget(receiveCoinsDialog, "receive"));
|
| 733 |
+
QVERIFY(CaptureReceiveWidget(*receiveRequestDialog, "receive-request"));
|
| 734 |
+
QTemporaryDir export_dir;
|
| 735 |
+
QVERIFY(export_dir.isValid());
|
| 736 |
+
const QString capture_dir{qEnvironmentVariable("ROOTS_WALLET_CAPTURE_DIR")};
|
| 737 |
+
const QString filename{capture_dir.isEmpty() ? export_dir.filePath("qr.png") : capture_dir + "/qr-export.png"};
|
| 738 |
+
const bool native_dialogs_disabled{qApp->testAttribute(Qt::AA_DontUseNativeDialogs)};
|
| 739 |
+
qApp->setAttribute(Qt::AA_DontUseNativeDialogs);
|
| 740 |
+
bool saved{false};
|
| 741 |
+
QTimer::singleShot(0, [&] {
|
| 742 |
+
for (auto* top : QApplication::topLevelWidgets()) {
|
| 743 |
+
if (auto* dialog = qobject_cast<QFileDialog*>(top)) {
|
| 744 |
+
// QFileDialog's filesystem model loads asynchronously.
|
| 745 |
+
// Pin the writable test directory before selecting the
|
| 746 |
+
// name; minimal has no screenshot event-pumping delay.
|
| 747 |
+
dialog->setDirectory(QFileInfo{filename}.absolutePath());
|
| 748 |
+
dialog->selectFile(QFileInfo{filename}.fileName());
|
| 749 |
+
auto* filename_edit = dialog->findChild<QLineEdit*>("fileNameEdit");
|
| 750 |
+
if (filename_edit) filename_edit->setText(QFileInfo{filename}.fileName());
|
| 751 |
+
const bool selected{QTest::qWaitFor([&] { return dialog->selectedFiles() == QStringList{filename}; }, 1000)};
|
| 752 |
+
saved = selected && CaptureReceiveWidget(*dialog, "qr-save-dialog");
|
| 753 |
+
QMetaObject::invokeMethod(dialog, saved ? "accept" : "reject");
|
| 754 |
+
}
|
| 755 |
+
}
|
| 756 |
+
});
|
| 757 |
+
save->click();
|
| 758 |
+
qApp->setAttribute(Qt::AA_DontUseNativeDialogs, native_dialogs_disabled);
|
| 759 |
+
QVERIFY(saved);
|
| 760 |
+
QCOMPARE(QImage{filename}, exported);
|
| 761 |
+
// Font changes refresh the production QR image in-place.
|
| 762 |
+
QFont larger_font{walletModel.getOptionsModel()->getFontForMoney()};
|
| 763 |
+
larger_font.setPointSizeF(larger_font.pointSizeF() * 1.5);
|
| 764 |
+
const auto original_choice{walletModel.getOptionsModel()->data(walletModel.getOptionsModel()->index(OptionsModel::FontForMoney))};
|
| 765 |
+
QVERIFY(walletModel.getOptionsModel()->setData(walletModel.getOptionsModel()->index(OptionsModel::FontForMoney), QVariant::fromValue(OptionsModel::FontChoice{larger_font})));
|
| 766 |
+
QVERIFY(qr->exportImage().height() > exported.height());
|
| 767 |
+
QVERIFY(walletModel.getOptionsModel()->setData(walletModel.getOptionsModel()->index(OptionsModel::FontForMoney), original_choice));
|
| 768 |
+
#endif
|
| 769 |
}
|
| 770 |
}
|
| 771 |
|