Android: enable tst_qqmlenginedebugservice

The test was failing because it was using QML code that was embedded
directly in the test, so the dependencies were not detected and
deployed.

This patch moves QML code into separate files, so that qmlimportscanner
could provide all the necessary dependencies.

Fixes: QTBUG-100166
Pick-to: 6.3 6.2
Change-Id: I5581de9a4573204722ad60eaceae8d05a491eb13
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Ivan Solovev 2022-04-27 11:50:42 +02:00
parent 0f9abd63b9
commit ecc87ea077
8 changed files with 268 additions and 85 deletions

View File

@ -4,6 +4,12 @@
## tst_qqmlenginedebugservice Test: ## tst_qqmlenginedebugservice Test:
##################################################################### #####################################################################
# Collect test data
file(GLOB_RECURSE test_data_glob
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
data/*)
list(APPEND test_data ${test_data_glob})
qt_internal_add_test(tst_qqmlenginedebugservice qt_internal_add_test(tst_qqmlenginedebugservice
SOURCES SOURCES
../shared/debugutil.cpp ../shared/debugutil_p.h ../shared/debugutil.cpp ../shared/debugutil_p.h
@ -19,6 +25,7 @@ qt_internal_add_test(tst_qqmlenginedebugservice
Qt::QmlPrivate Qt::QmlPrivate
Qt::Quick Qt::Quick
Qt::QuickTestUtilsPrivate Qt::QuickTestUtilsPrivate
TESTDATA ${test_data}
) )
## Scopes: ## Scopes:

View File

@ -0,0 +1,54 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
import Test 1.0
Item {
id: root
width: 10; height: 20; scale: blueRect.scale;
Rectangle { id: blueRect; width: 500; height: 600; color: "blue"; }
Text { font.bold: true; color: blueRect.color; }
MouseArea {
onEntered: { console.log('hello') }
}
property variant varObj
property variant varObjList: []
property variant varObjMap
property variant simpleVar: 10.05
Component.onCompleted: {
varObj = blueRect;
var list = varObjList;
list[0] = blueRect;
varObjList = list;
var map = new Object;
map.rect = blueRect;
varObjMap = map;
}
NonScriptPropertyElement {
}
}

View File

@ -0,0 +1,31 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import Backend 1.0
CustomTypes {
}

View File

@ -0,0 +1,31 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
Item {
}

View File

@ -0,0 +1,34 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
Item {
function myMethodNoArgs() { return 3; }
function myMethod(a) { return a + 9; }
function myMethodIndirect() { myMethod(3); }
}

View File

@ -0,0 +1,31 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import JsonTest 1.0
JsonTest {
}

View File

@ -0,0 +1,53 @@
/****************************************************************************
**
** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** 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.
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.0
Rectangle {
id: rootRect
width: 100
states: [
State {
name: "state1"
PropertyChanges {
target: rootRect
width: 200
}
}
]
transitions: [
Transition {
from: "*"
to: "state1"
PropertyAnimation {
target: rootRect
property: "width"
duration: 100
}
}
]
}

View File

@ -119,12 +119,13 @@ private:
}; };
class tst_QQmlEngineDebugService : public QObject class tst_QQmlEngineDebugService : public QQmlDataTest
{ {
Q_OBJECT Q_OBJECT
public: public:
tst_QQmlEngineDebugService() tst_QQmlEngineDebugService()
: m_conn(nullptr) : QQmlDataTest(QT_QMLTEST_DATADIR)
, m_conn(nullptr)
, m_dbg(nullptr) , m_dbg(nullptr)
, m_engine(nullptr) , m_engine(nullptr)
, m_rootItem(nullptr) {} , m_rootItem(nullptr) {}
@ -150,7 +151,7 @@ private:
QObjectList m_components; QObjectList m_components;
private slots: private slots:
void initTestCase(); void initTestCase() override;
void cleanupTestCase(); void cleanupTestCase();
void watch_property(); void watch_property();
@ -331,93 +332,34 @@ void tst_QQmlEngineDebugService::getContexts()
void tst_QQmlEngineDebugService::initTestCase() void tst_QQmlEngineDebugService::initTestCase()
{ {
QQmlDataTest::initTestCase();
qmlRegisterType<NonScriptProperty>("Test", 1, 0, "NonScriptPropertyElement"); qmlRegisterType<NonScriptProperty>("Test", 1, 0, "NonScriptPropertyElement");
QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Waiting for connection on port 3768..."); QTest::ignoreMessage(QtDebugMsg, "QML Debugger: Waiting for connection on port 3768...");
m_engine = new QQmlEngine(this); m_engine = new QQmlEngine(this);
QList<QByteArray> qml;
qml << "import QtQuick 2.0\n"
"import Test 1.0\n"
"Item {"
"id: root\n"
"width: 10; height: 20; scale: blueRect.scale;"
"Rectangle { id: blueRect; width: 500; height: 600; color: \"blue\"; }"
"Text { font.bold: true; color: blueRect.color; }"
"MouseArea {"
"onEntered: { console.log('hello') }"
"}"
"property variant varObj\n"
"property variant varObjList: []\n"
"property variant varObjMap\n"
"property variant simpleVar: 10.05\n"
"Component.onCompleted: {\n"
"varObj = blueRect;\n"
"var list = varObjList;\n"
"list[0] = blueRect;\n"
"varObjList = list;\n"
"var map = new Object;\n"
"map.rect = blueRect;\n"
"varObjMap = map;\n"
"}\n"
"NonScriptPropertyElement {\n"
"}\n"
"}";
// add second component to test multiple root contexts
qml << "import QtQuick 2.0\n"
"Item {}";
// and a third to test methods
qml << "import QtQuick 2.0\n"
"Item {"
"function myMethodNoArgs() { return 3; }\n"
"function myMethod(a) { return a + 9; }\n"
"function myMethodIndirect() { myMethod(3); }\n"
"}";
// and a fourth to test states
qml << "import QtQuick 2.0\n"
"Rectangle {\n"
"id:rootRect\n"
"width:100\n"
"states: [\n"
"State {\n"
"name:\"state1\"\n"
"PropertyChanges {\n"
"target:rootRect\n"
"width:200\n"
"}\n"
"}\n"
"]\n"
"transitions: [\n"
"Transition {\n"
"from:\"*\"\n"
"to:\"state1\"\n"
"PropertyAnimation {\n"
"target:rootRect\n"
"property:\"width\"\n"
"duration:100\n"
"}\n"
"}\n"
"]\n"
"}\n"
;
// test non-streamable properties
qmlRegisterType<CustomTypes>("Backend", 1, 0, "CustomTypes"); qmlRegisterType<CustomTypes>("Backend", 1, 0, "CustomTypes");
qml << "import Backend 1.0\n"
"CustomTypes {}"
;
qmlRegisterType<JsonTest>("JsonTest", 1, 0, "JsonTest"); qmlRegisterType<JsonTest>("JsonTest", 1, 0, "JsonTest");
qml << "import JsonTest 1.0\n"
"JsonTest {}"
;
for (int i=0; i<qml.count(); i++) { // The contents of these files was previously hardcoded as QList<QByteArray>
QQmlComponent component(m_engine); // directly in this test, but that fails on Android, because the required
component.setData(qml[i], QUrl::fromLocalFile("")); // dependencies are not deployed. When the contents is moved to separate
// files, qmlimportscanner is capable of providing all the necessary
// dependencies.
// Note that the order of the files in this list matters! The test-cases
// expect Qml components to be created is certain order.
constexpr const char *fileNames[] = {
"complexItem.qml",
"emptyItem.qml",
"itemWithFunctions.qml",
"rectangleWithTransitions.qml",
"customTypes.qml",
"jsonTest.qml"
};
for (auto file : fileNames) {
QQmlComponent component(m_engine, testFileUrl(file));
QVERIFY(component.isReady()); // fails if bad syntax QVERIFY(component.isReady()); // fails if bad syntax
m_components << qobject_cast<QQuickItem*>(component.create()); m_components << qobject_cast<QQuickItem*>(component.create());
} }
@ -756,8 +698,8 @@ void tst_QQmlEngineDebugService::queryObject()
// check source as defined in main() // check source as defined in main()
QQmlEngineDebugFileReference source = obj.source; QQmlEngineDebugFileReference source = obj.source;
QCOMPARE(source.url, QUrl::fromLocalFile("")); QCOMPARE(source.url, testFileUrl("complexItem.qml"));
QCOMPARE(source.lineNumber, 3); QCOMPARE(source.lineNumber, 31); // because of license header
QCOMPARE(source.columnNumber, 1); QCOMPARE(source.columnNumber, 1);
// generically test all properties, children and childrens' properties // generically test all properties, children and childrens' properties
@ -835,7 +777,7 @@ void tst_QQmlEngineDebugService::queryObjectsForLocation()
// check source as defined in main() // check source as defined in main()
QQmlEngineDebugFileReference source = obj.source; QQmlEngineDebugFileReference source = obj.source;
QCOMPARE(source.url, QUrl(fileName)); QCOMPARE(source.url, testFileUrl(fileName));
QCOMPARE(source.lineNumber, lineNumber); QCOMPARE(source.lineNumber, lineNumber);
QCOMPARE(source.columnNumber, columnNumber); QCOMPARE(source.columnNumber, columnNumber);