Skip to content

Commit d86ff2f

Browse files
Johnny CarlsonJohnny Carlson
authored andcommitted
qml: add imageprovider to test setup
1 parent d663fdd commit d86ff2f

File tree

4 files changed

+159
-6
lines changed

4 files changed

+159
-6
lines changed

src/Makefile.qmltest.include

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@
55
bin_PROGRAMS += qml/test/test_bitcoin-qt
66
TESTS += qml/test/test_bitcoin-qt
77

8-
TEST_QML_MOC_CPP =
8+
TEST_QML_MOC_CPP = qml/test/moc_onboardingtests.cpp
99

10-
TEST_QML_H =
10+
TEST_QML_H = qml/test/onboardingtests.h qml/test/imageprovider.h
1111

1212
qml_test_test_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
13-
$(QT_INCLUDES) $(QT_TEST_INCLUDES) $(BOOST_CPPFLAGS)
13+
$(QT_INCLUDES) $(QT_TEST_INCLUDES) $(QT_QUICKTEST_INCLUDES) $(BOOST_CPPFLAGS)
1414

1515
qml_test_test_bitcoin_qt_SOURCES = \
16+
$(TEST_QML_MOC_CPP) \
1617
qml/test/onboardingtests.cpp \
18+
qml/qrc_bitcoin.cpp \
19+
qml/bitcoin_qml.qrc \
20+
qml/test/imageprovider.cpp \
1721
$(TEST_QML_H)
1822

19-
nodist_qml_test_test_bitcoin_qt_SOURCES = $(TEST_QML_MOC_CPP)
23+
nodist_qml_test_test_bitcoin_qt_SOURCES = $(TEST_QML_MOC_CPP) $(QML_QRC_CPP)
2024

21-
qml_test_test_bitcoin_qt_LDADD = $(QT_QUICKTEST_LIBS)
25+
qml_test_test_bitcoin_qt_LDADD = $(QT_QUICKTEST_LIBS) $(QT_TEST_LIBS) $(QT_LIBS)
2226
qml_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(PTHREAD_FLAGS)
2327
qml_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)
2428

src/qml/test/imageprovider.cpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) 2023 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <qml/test/imageprovider.h>
6+
7+
#include <QIcon>
8+
#include <QPixmap>
9+
#include <QQuickImageProvider>
10+
#include <QSize>
11+
#include <QString>
12+
13+
TestImageProvider::TestImageProvider()
14+
: QQuickImageProvider{QQuickImageProvider::Pixmap}
15+
{
16+
}
17+
18+
QPixmap TestImageProvider::requestPixmap(const QString& id, QSize* size, const QSize& requested_size)
19+
{
20+
if (!size || !requested_size.isValid()) {
21+
return {};
22+
}
23+
24+
if (id == "arrow-down") {
25+
*size = requested_size;
26+
return QIcon(":/icons/arrow-down").pixmap(requested_size);
27+
}
28+
29+
if (id == "arrow-up") {
30+
*size = requested_size;
31+
return QIcon(":/icons/arrow-up").pixmap(requested_size);
32+
}
33+
34+
if (id == "bitcoin-circle") {
35+
*size = requested_size;
36+
return QIcon(":/icons/bitcoin-circle").pixmap(requested_size);
37+
}
38+
39+
if (id == "blocktime-dark") {
40+
*size = requested_size;
41+
return QIcon(":/icons/blocktime-dark").pixmap(requested_size);
42+
}
43+
44+
if (id == "blocktime-light") {
45+
*size = requested_size;
46+
return QIcon(":/icons/blocktime-light").pixmap(requested_size);
47+
}
48+
49+
if (id == "app") {
50+
*size = requested_size;
51+
return QIcon(":/icons/bitcoin").pixmap(requested_size);
52+
}
53+
54+
if (id == "caret-left") {
55+
*size = requested_size;
56+
return QIcon(":/icons/caret-left").pixmap(requested_size);
57+
}
58+
59+
if (id == "caret-right") {
60+
*size = requested_size;
61+
return QIcon(":/icons/caret-right").pixmap(requested_size);
62+
}
63+
64+
if (id == "check") {
65+
*size = requested_size;
66+
return QIcon(":/icons/check").pixmap(requested_size);
67+
}
68+
69+
if (id == "cross") {
70+
*size = requested_size;
71+
return QIcon(":/icons/cross").pixmap(requested_size);
72+
}
73+
74+
if (id == "export") {
75+
*size = requested_size;
76+
return QIcon(":/icons/export").pixmap(requested_size);
77+
}
78+
79+
if (id == "gear") {
80+
*size = requested_size;
81+
return QIcon(":/icons/gear").pixmap(requested_size);
82+
}
83+
84+
if (id == "info") {
85+
*size = requested_size;
86+
return QIcon(":/icons/info").pixmap(requested_size);
87+
}
88+
89+
if (id == "network-dark") {
90+
*size = requested_size;
91+
return QIcon(":/icons/network-dark").pixmap(requested_size);
92+
}
93+
94+
if (id == "network-light") {
95+
*size = requested_size;
96+
return QIcon(":/icons/network-light").pixmap(requested_size);
97+
}
98+
99+
if (id == "storage-dark") {
100+
*size = requested_size;
101+
return QIcon(":/icons/storage-dark").pixmap(requested_size);
102+
}
103+
104+
if (id == "storage-light") {
105+
*size = requested_size;
106+
return QIcon(":/icons/storage-light").pixmap(requested_size);
107+
}
108+
109+
return {};
110+
}

src/qml/test/imageprovider.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2021 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#ifndef BITCOIN_QML_TEST_IMAGEPROVIDER_H
6+
#define BITCOIN_QML_TEST_IMAGEPROVIDER_H
7+
8+
#include <QPixmap>
9+
#include <QQuickImageProvider>
10+
11+
QT_BEGIN_NAMESPACE
12+
class QSize;
13+
class QString;
14+
QT_END_NAMESPACE
15+
16+
class TestImageProvider : public QQuickImageProvider
17+
{
18+
public:
19+
explicit TestImageProvider();
20+
21+
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requested_size) override;
22+
23+
};
24+
25+
#endif // BITCOIN_QML_IMAGEPROVIDER_H

src/qml/test/onboardingtests.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
11
#include <QtQuickTest>
2-
QUICK_TEST_MAIN(onboarding)
2+
#include <QQmlEngine>
3+
#include <QQmlContext>
4+
#include <qml/test/imageprovider.h>
5+
#include <qml/test/onboardingtests.h>
6+
#include <qt/networkstyle.h>
7+
8+
Setup::Setup()
9+
{
10+
}
11+
12+
void Setup::qmlEngineAvailable(QQmlEngine * engine) {
13+
engine->addImageProvider(QStringLiteral("images"), new TestImageProvider());
14+
}
15+
16+
QUICK_TEST_MAIN_WITH_SETUP(onboarding, Setup)

0 commit comments

Comments
 (0)