From 2d14e9a88497b1aad3b75304d5dfa7d37900e9c3 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Thu, 5 Oct 2023 11:47:23 +0200 Subject: Fix QScxmlStateMachineLoader::source binding loop The QScxmlStateMachineLoader::source setter assumes that the loader is managed by a QML engine, so use a helper QML file and a QQmlComponent to create a helper object and run the test for binding loops. The binding loop here is a bit tricky, as the source setter modifies two properties: source and stateMachine. The fix for the source property is trivial. The stateMachine property is read-only, so modify the setStateMachine() internal setter in such way that it does not create bindings. After that, manually call notify() if the state machine has changed. Use simpler state machines in the test, because the original ones were generating the ASAN memleak warnings from scxml compiler. Task-number: QTBUG-116542 Pick-to: 6.6 6.5 Change-Id: Ia8427ed07c1e63e5740b2f0817fe6b2cb48726b8 Reviewed-by: Ulf Hermann --- tests/auto/qml/scxmlqmlcpp/data/smlHelper.qml | 6 ++++++ tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp | 12 +++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 tests/auto/qml/scxmlqmlcpp/data/smlHelper.qml (limited to 'tests') diff --git a/tests/auto/qml/scxmlqmlcpp/data/smlHelper.qml b/tests/auto/qml/scxmlqmlcpp/data/smlHelper.qml new file mode 100644 index 0000000..8deec6e --- /dev/null +++ b/tests/auto/qml/scxmlqmlcpp/data/smlHelper.qml @@ -0,0 +1,6 @@ +import QtQuick +import QtScxml + +StateMachineLoader { + objectName: 'helper' +} diff --git a/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp b/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp index c3c3501..5d10fa5 100644 --- a/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp +++ b/tests/auto/qml/scxmlqmlcpp/tst_scxmlqmlcpp.cpp @@ -112,8 +112,8 @@ void tst_scxmlqmlcpp::stateMachineLoaderSourceStateMachineBinding() { // Test source and stateMachine together as they interact with each other - QUrl source1(testFileUrl("statemachine.scxml")); - QUrl source2(testFileUrl("topmachine.scxml")); + QUrl source1(testFileUrl("submachineA.scxml")); + QUrl source2(testFileUrl("submachineB.scxml")); // The 'setSource' of the statemachineloader assumes a valid qml context QQmlEngine engine; const QUrl smlUrl = testFileUrl("stateMachineLoader.qml"); @@ -124,9 +124,15 @@ void tst_scxmlqmlcpp::stateMachineLoaderSourceStateMachineBinding() qobject_cast(root->findChild("sml")); QVERIFY(sml != nullptr); + QQmlComponent otherComponent(&engine, testFileUrl("smlHelper.qml")); + // -- StateMachineLoader::source QTestPrivate::testReadWritePropertyBasics( - *sml, source1, source2, "source"); + *sml, source1, source2, "source", + [&otherComponent]() { + return std::unique_ptr( + qobject_cast(otherComponent.create())); + }); if (QTest::currentTestFailed()) { qWarning() << "QScxmlStateMachineLoader::source property testing failed"; return; -- cgit v1.2.3