Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ if(KF6Notifications_FOUND AND Qt6DBus_FOUND)
KF6::Notifications
KF6::I18n)
target_compile_definitions(tst_weknotifier PRIVATE
WEK_SOURCE_DIR="${CMAKE_SOURCE_DIR}/.."
WEK_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/.."
TRANSLATION_DOMAIN="${WEK_TRANSLATION_DOMAIN}")
if(COVERAGE)
target_compile_options(tst_weknotifier PRIVATE ${_cov_compile_flags})
Expand Down Expand Up @@ -839,6 +839,8 @@ find_package(Qt6 6.7 COMPONENTS QuickTest Qml QUIET)
find_package(KF6I18n QUIET)
if(Qt6QuickTest_FOUND AND Qt6Qml_FOUND AND KF6I18n_FOUND)
add_executable(wek_qml_test_runner qml_test_runner.cpp)
target_compile_definitions(wek_qml_test_runner PRIVATE
WEK_QML_STUB_DIR="${CMAKE_CURRENT_SOURCE_DIR}/qml/_stubs/com/github/captsilver/wallpaperEngineKde")
target_link_libraries(wek_qml_test_runner PRIVATE Qt6::QuickTest Qt6::Qml KF6::I18n)
set(QML_TEST_RUNNER "$<TARGET_FILE:wek_qml_test_runner>")

Expand Down Expand Up @@ -977,10 +979,11 @@ if(Qt6QuickTest_FOUND AND Qt6Qml_FOUND AND Qt6Quick_FOUND)
"${CMAKE_CURRENT_SOURCE_DIR}/qml_integration"
"${_e2e_gen_dir}")
target_compile_definitions(tst_main_integration PRIVATE
WEK_QML_STUB_DIR="${CMAKE_CURRENT_SOURCE_DIR}/qml/_stubs/com/github/captsilver/wallpaperEngineKde"
WEKDE_REPO_DIR="${_wekde_repo_root_e2e}"
QUICK_TEST_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}/qml_integration")
target_link_libraries(tst_main_integration PRIVATE
Qt6::QuickTest Qt6::Qml Qt6::Quick)
Qt6::QuickTest Qt6::Qml Qt6::Quick KF6::I18n)
add_test(NAME tst_main_integration COMMAND tst_main_integration)
set_tests_properties(tst_main_integration PROPERTIES
ENVIRONMENT "QT_QPA_PLATFORM=offscreen")
Expand Down
20 changes: 20 additions & 0 deletions tests/QmlTestStubs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once

#include <QQmlAbstractUrlInterceptor>
#include <QString>
#include <QUrl>

// Qt can discover a second, installed qmldir when mixing versioned and
// unversioned imports, even with _stubs first on the import path. Redirect
// only this module's descriptor; leave Qt/KDE and production QML untouched.
class QmlTestStubs : public QQmlAbstractUrlInterceptor {
public:
QUrl intercept(const QUrl& url, DataType type) override {
if (type == QmldirFile &&
url.path().endsWith("/com/github/captsilver/wallpaperEngineKde/qmldir")) {
return QUrl::fromLocalFile(QStringLiteral(WEK_QML_STUB_DIR "/qmldir"));
}
return url;
}
};
12 changes: 12 additions & 0 deletions tests/qml_integration/main.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
#include <QtQuickTest/quicktest.h>

#include "../QmlTestStubs.h"
#include <QObject>
#include <QQmlContext>
#include <QQmlEngine>
#include <QString>
#include <KLocalizedContext>

#include "FakeWallpaper.h"
#include "../TestSandbox.h"

// QuickTest setup: inject `wallpaper` as a context property backed by real C++
// objects, reusing the existing tests/qml/_stubs. main.qml then loads exactly as
// in production (wallpaper is a context property, configuration is a real QObject
// whose per-key NOTIFY signals drive main.qml's reactive Connections).
class Setup : public QObject {
Q_OBJECT
QmlTestStubs stubs;
public slots:
void applicationAvailable() { wek::test_sandbox::enableIsolated(); }

void qmlEngineAvailable(QQmlEngine* engine) {
engine->addUrlInterceptor(&stubs);
const QString repo = QStringLiteral(WEKDE_REPO_DIR);
engine->addImportPath(repo + "/tests/qml/_stubs");
engine->addImportPath(repo + "/tests/qml");

QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
engine->rootContext()->setContextObject(new KLocalizedContext(engine));
QT_WARNING_POP

auto* wallpaper = buildOwnedFakeWallpaperTree(engine);

// Test-friendly overrides differing from main.xml defaults.
Expand Down
13 changes: 12 additions & 1 deletion tests/qml_integration/tst_main_integration.qml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ TestCase {

Item { id: host; anchors.fill: parent }

function test_mixed_imports_use_stubs() {
for (const version of ["", " 1.2"]) {
const object = Qt.createQmlObject(
'import QtQuick; import com.github.captsilver.wallpaperEngineKde' +
version + '; WekDiagnostics {}', host);
// Present only on the stub; native diagnostics must never run here.
compare(object.nextBundlePath, "/tmp/wekde-stub-diag.tar.gz");
object.destroy();
}
}

function _find(node, pred) {
if (!node) return null;
const buckets = [node.children || [], node.data || []];
Expand Down Expand Up @@ -40,7 +51,7 @@ TestCase {

function _mkMain(w, h) {
const comp = Qt.createComponent("../../plugin/contents/ui/main.qml");
compare(comp.status, Component.Ready);
compare(comp.status, Component.Ready, comp.errorString());
const m = comp.createObject(host, { width: w, height: h });
verify(m !== null);
return m;
Expand Down
8 changes: 4 additions & 4 deletions tests/qml_test_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// harness, matching how production actually gets its bindings, not in
// restoring an import nothing else uses.
#include "TestSandbox.h"
#include "QmlTestStubs.h"

#include <KLocalizedContext>
#include <QQmlContext>
Expand All @@ -22,15 +23,14 @@

class I18nQuickTestSetup : public QObject {
Q_OBJECT
QmlTestStubs stubs;

public slots:
// Suites that end up on a real plugin type -- the installed module can
// win over the stubs on the import path -- write through QStandardPaths
// (PlaylistManager persists playlists.json). Give the whole run its own
// HOME in Qt's test mode so those writes never reach the user's config.
// Keep QStandardPaths writes isolated even if a suite uses a real type.
void applicationAvailable() { wek::test_sandbox::enableIsolated(); }

void qmlEngineAvailable(QQmlEngine* engine) {
engine->addUrlInterceptor(&stubs);
// Production (corebindingsplugin.so) installs KLocalizedQmlContext,
// not this class -- KLocalizedContext has been deprecated in its
// favour since KF 6.8. We still use the deprecated one here: it
Expand Down
1 change: 1 addition & 0 deletions tests/scripts/test_mutation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ make_gitrepo() { # <dir> <file...>
git init -q
git config user.email t@example.com
git config user.name test
git config commit.gpgsign false
for f in "$@"; do mkdir -p "$(dirname "$f")"; echo v1 > "$f"; done
echo base > BASEFILE
git add -A && git commit -qm base
Expand Down