diff options
author | Marco Bubke <marco.bubke@qt.io> | 2020-07-27 18:14:33 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2020-08-10 12:53:30 +0000 |
commit | e43c7fdb1de786a2d5b90d68830c5308319a7dcf (patch) | |
tree | baffab654aebea5569ae3ff408d18eb793765980 /tests/auto | |
parent | b5d59c75a7dee830483631cd9045d5338fc25c2d (diff) |
QmlDesigner: Split messaging and process for puppets
This will make it easier to implement custom puppets. The new connection
manager will restucture the code and it add a mechanism to capture data
too.
Task-number: QDS-2529
Change-Id: I5d15c3303ef1c9a3e25ba197d350e0d561ce813a
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Diffstat (limited to 'tests/auto')
5 files changed, 148 insertions, 11 deletions
diff --git a/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt b/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt index 83f9da98a0..fb22fbf06b 100644 --- a/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt +++ b/tests/auto/qml/qmldesigner/coretests/CMakeLists.txt @@ -17,4 +17,5 @@ add_qtc_test(tst_qml_testcore ../testview.cpp ../testview.h testrewriterview.cpp testrewriterview.h tst_testcore.cpp tst_testcore.h + ../testconnectionmanager.cpp ../testconnectionmanager.h ) diff --git a/tests/auto/qml/qmldesigner/coretests/coretests.pro b/tests/auto/qml/qmldesigner/coretests/coretests.pro index dd0f071b0e..fb0437b69f 100644 --- a/tests/auto/qml/qmldesigner/coretests/coretests.pro +++ b/tests/auto/qml/qmldesigner/coretests/coretests.pro @@ -60,11 +60,13 @@ TEMPLATE = app SOURCES += \ ../testview.cpp \ testrewriterview.cpp \ - tst_testcore.cpp + tst_testcore.cpp \ + ../testconnectionmanager.cpp HEADERS += \ ../testview.h \ testrewriterview.h \ - tst_testcore.h + tst_testcore.h \ + ../testconnectionmanager.h RESOURCES += ../data/testfiles.qrc diff --git a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp index 52fa6f519f..e843ad7a3d 100644 --- a/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp +++ b/tests/auto/qml/qmldesigner/coretests/tst_testcore.cpp @@ -46,11 +46,12 @@ #include <stylesheetmerger.h> #include <QDebug> +#include "../testconnectionmanager.h" #include "../testview.h" -#include <variantproperty.h> #include <abstractproperty.h> #include <bindingproperty.h> #include <nodeproperty.h> +#include <variantproperty.h> #include <nodelistproperty.h> #include <nodeabstractproperty.h> @@ -1999,8 +2000,9 @@ void tst_TestCore::testModelRemoveNode() QVERIFY(view.data()); model->attachView(view.data()); - NodeInstanceView *nodeInstanceView = new NodeInstanceView(model.data(), NodeInstanceServerInterface::TestModus); - model->attachView(nodeInstanceView); + TestConnectionManager connectionManager; + NodeInstanceView nodeInstanceView{connectionManager}; + model->attachView(&nodeInstanceView); QCOMPARE(view->rootModelNode().directSubModelNodes().count(), 0); @@ -2051,7 +2053,7 @@ void tst_TestCore::testModelRemoveNode() childNode = view->createModelNode("QtQuick.Item", 1, 1); childNode.destroy(); - model->detachView(nodeInstanceView); + model->detachView(&nodeInstanceView); } void tst_TestCore::reparentingNode() @@ -6140,17 +6142,21 @@ void tst_TestCore::testInstancesAttachToExistingModel() // Attach NodeInstanceView - QScopedPointer<NodeInstanceView> instanceView(new NodeInstanceView(0, NodeInstanceServerInterface::TestModus)); - QVERIFY(instanceView.data()); - model->attachView(instanceView.data()); + TestConnectionManager connectionManager; + + NodeInstanceView instanceView{connectionManager}; - NodeInstance rootInstance = instanceView->instanceForModelNode(rootNode); - NodeInstance rectangleInstance = instanceView->instanceForModelNode(rectangleNode); + model->attachView(&instanceView); + + NodeInstance rootInstance = instanceView.instanceForModelNode(rootNode); + NodeInstance rectangleInstance = instanceView.instanceForModelNode(rectangleNode); QVERIFY(rootInstance.isValid()); QVERIFY(rectangleInstance.isValid()); QCOMPARE(QVariant(100), rectangleInstance.property("width")); QVERIFY(rootInstance.instanceId() >= 0); QVERIFY(rectangleInstance.instanceId() >= 0); + + model->detachView(&instanceView); } void tst_TestCore::testQmlModelAddMultipleStates() diff --git a/tests/auto/qml/qmldesigner/testconnectionmanager.cpp b/tests/auto/qml/qmldesigner/testconnectionmanager.cpp new file mode 100644 index 0000000000..f637fb1f1a --- /dev/null +++ b/tests/auto/qml/qmldesigner/testconnectionmanager.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "testconnectionmanager.h" +#include "synchronizecommand.h" + +#include <QLocalSocket> + +namespace QmlDesigner { + +TestConnectionManager::TestConnectionManager() +{ + m_connections.emplace_back("Editor", "editormode"); +} + +void TestConnectionManager::writeCommand(const QVariant &command) +{ + TestConnectionManager::writeCommand(command); + + m_writeCommandCounter++; + + static int synchronizeId = 0; + synchronizeId++; + SynchronizeCommand synchronizeCommand(synchronizeId); + + QLocalSocket *socket = m_connections.front().socket.get(); + + writeCommandToIODevice(QVariant::fromValue(synchronizeCommand), socket, m_writeCommandCounter); + m_writeCommandCounter++; + + while (socket->waitForReadyRead(100)) { + readDataStream(m_connections.front()); + if (m_synchronizeId == synchronizeId) + return; + } +} + +void TestConnectionManager::dispatchCommand(const QVariant &command, Connection &connection) +{ + static const int synchronizeCommandType = QMetaType::type("SynchronizeCommand"); + + if (command.userType() == synchronizeCommandType) { + SynchronizeCommand synchronizeCommand = command.value<SynchronizeCommand>(); + m_synchronizeId = synchronizeCommand.synchronizeId(); + } else { + ConnectionManager::dispatchCommand(command, connection); + } +} + +} // namespace QmlDesigner diff --git a/tests/auto/qml/qmldesigner/testconnectionmanager.h b/tests/auto/qml/qmldesigner/testconnectionmanager.h new file mode 100644 index 0000000000..6ea44c1c1d --- /dev/null +++ b/tests/auto/qml/qmldesigner/testconnectionmanager.h @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include <connectionmanager.h> + +#include <QFile> +#include <QPointer> +#include <QProcess> +#include <QTimer> + +QT_BEGIN_NAMESPACE +class QLocalServer; +class QLocalSocket; +QT_END_NAMESPACE + +namespace QmlDesigner { + +class TestConnectionManager final : public ConnectionManager +{ +public: + TestConnectionManager(); + + void writeCommand(const QVariant &command) override; + +protected: + void dispatchCommand(const QVariant &command, Connection &connection) override; + +private: + int m_synchronizeId = -1; +}; + +} // namespace QmlDesigner |