test(bluetooth): keep the installed network plugin and FishUI's icon provider out of the QML test

pull/18/head
reionwong 3 weeks ago
parent f9d031a5ed
commit 5311b43d05

@ -30,8 +30,11 @@ if(TARGET cutefish-framework-bluetooth AND EXISTS "${settings_page}")
find_package(Qt6 REQUIRED COMPONENTS Quick)
add_executable(tst_bluetoothqml tst_bluetoothqml.cpp)
target_link_libraries(tst_bluetoothqml PRIVATE cutefish-framework-bluetooth Qt6::Quick Qt6::Test)
# An unversioned import would load the installed network plugin over the stubs.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/stubs/Cutefish/Network/qmldir" "module Cutefish.Network\n")
target_compile_definitions(tst_bluetoothqml PRIVATE
BLUETOOTH_IMPORT_PATH="${CMAKE_CURRENT_BINARY_DIR}/.."
STUB_IMPORT_PATH="${CMAKE_CURRENT_BINARY_DIR}/stubs"
SETTINGS_BLUETOOTH_PAGE="${settings_page}"
)
add_test(NAME bluetooth-qml COMMAND ${DBUS_RUN_SESSION} -- $<TARGET_FILE:tst_bluetoothqml>)

@ -105,6 +105,7 @@ private slots:
QVERIFY(bus.registerVirtualObject(QStringLiteral("/"), &fake, QDBusConnection::SubPath));
QQmlEngine engine;
engine.addImportPath(QStringLiteral(BLUETOOTH_IMPORT_PATH));
engine.addImportPath(QStringLiteral(STUB_IMPORT_PATH));
QQmlComponent host(&engine);
host.setData(R"(
import QtQuick
@ -172,12 +173,13 @@ private slots:
QVERIFY(bus.registerService(QStringLiteral("org.bluez")));
QQmlEngine engine;
engine.addImportPath(QStringLiteral(BLUETOOTH_IMPORT_PATH));
engine.addImageProvider(QStringLiteral("icontheme"), new TestIconProvider);
engine.addImportPath(QStringLiteral(STUB_IMPORT_PATH));
QSignalSpy warnings(&engine, &QQmlEngine::warnings);
QQmlComponent host(&engine);
host.setData(R"(
import QtQuick
import QtQuick.Controls
import FishUI
ApplicationWindow {
width: 900
height: 650
@ -190,6 +192,8 @@ private slots:
QUrl());
std::unique_ptr<QObject> window(host.create());
QVERIFY2(window, qPrintable(host.errorString()));
// After FishUI's import, which installs the real provider in its place.
engine.addImageProvider(QStringLiteral("icontheme"), new TestIconProvider);
engine.rootContext()->setContextProperty(QStringLiteral("rootWindow"), window.get());
QQmlComponent component(&engine,
QUrl::fromLocalFile(QStringLiteral(SETTINGS_BLUETOOTH_PAGE)));

Loading…
Cancel
Save