diff options
Diffstat (limited to 'sources/pyside6/PySide6')
| -rw-r--r-- | sources/pyside6/PySide6/QtQuickTest/CMakeLists.txt | 44 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/QtQuickTest/typesystem_quicktest.xml | 32 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/doc/qtquicktest.rst | 62 | ||||
| -rw-r--r-- | sources/pyside6/PySide6/glue/qtquicktest.cpp | 50 |
4 files changed, 188 insertions, 0 deletions
diff --git a/sources/pyside6/PySide6/QtQuickTest/CMakeLists.txt b/sources/pyside6/PySide6/QtQuickTest/CMakeLists.txt new file mode 100644 index 000000000..cd224f2b0 --- /dev/null +++ b/sources/pyside6/PySide6/QtQuickTest/CMakeLists.txt @@ -0,0 +1,44 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +project(QtQuickTest) + +set(QtQuickTest_SRC +# module is always needed +${QtQuickTest_GEN_DIR}/qtquicktest_module_wrapper.cpp +) + +set(QtQuickTest_include_dirs ${QtQuickTest_SOURCE_DIR} + ${QtQml_SOURCE_DIR} + ${Qt${QT_MAJOR_VERSION}Core_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Gui_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}OpenGL_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Network_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Qml_INCLUDE_DIRS} + ${Qt${QT_MAJOR_VERSION}Quick_INCLUDE_DIRS} + ${libpyside_SOURCE_DIR} + ${QtGui_GEN_DIR} + ${QtOpenGL_GEN_DIR} + ${QtCore_GEN_DIR} + ${QtNetwork_GEN_DIR} + ${QtQml_GEN_DIR} + ${QtQuick_GEN_DIR} + ${QtQuickTest_GEN_DIR}) + +set(QtQuickTest_libraries pyside6 + ${Qt${QT_MAJOR_VERSION}Core_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Gui_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}OpenGL_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Network_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Qml_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}Quick_LIBRARIES} + ${Qt${QT_MAJOR_VERSION}QuickTest_LIBRARIES}) + +set(QtQuickTest_deps QtGui QtOpenGL QtNetwork QtQml QtQuick) + +create_pyside_module(NAME QtQuickTest + INCLUDE_DIRS QtQuickTest_include_dirs + LIBRARIES QtQuickTest_libraries + DEPS QtQuickTest_deps + TYPESYSTEM_PATH QtQuickTest_SOURCE_DIR + SOURCES QtQuickTest_SRC) diff --git a/sources/pyside6/PySide6/QtQuickTest/typesystem_quicktest.xml b/sources/pyside6/PySide6/QtQuickTest/typesystem_quicktest.xml new file mode 100644 index 000000000..4f30d1916 --- /dev/null +++ b/sources/pyside6/PySide6/QtQuickTest/typesystem_quicktest.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only +--> +<typesystem package="PySide6.QtQuickTest"> + <load-typesystem name="QtCore/typesystem_core.xml" generate="no"/> + + <extra-includes> + <include file-name="QtQuickTest/quicktest.h" location="global"/> + <include file-name="QtCore/QDir" location="global"/> + <include file-name="pysideqobject.h" location="global"/> + <include file-name="vector" location="global"/> + </extra-includes> + <inject-code class="native" position="beginning" + file="../glue/qtquicktest.cpp" snippet="call-quick-test-main"/> + + <add-function signature="QUICK_TEST_MAIN(QString@name@,QStringList@argv@={},QString@dir@={})" + return-type="int"> + <inject-code file="../glue/qtquicktest.cpp" snippet="quick-test-main"/> + <inject-documentation format="target" mode="append" + file="../doc/qtquicktest.rst" + snippet="quick_test_main_documentation"/> + </add-function> + <add-function signature="QUICK_TEST_MAIN_WITH_SETUP(QString@name@,PyTypeObject*@setup@,QStringList@argv@={},QString@dir@={})" + return-type="int"> + <inject-code file="../glue/qtquicktest.cpp" snippet="quick-test-main_with_setup"/> + <inject-documentation format="target" mode="append" + file="../doc/qtquicktest.rst" + snippet="quick_test_main_with_setup_documentation"/> + </add-function> +</typesystem> diff --git a/sources/pyside6/PySide6/doc/qtquicktest.rst b/sources/pyside6/PySide6/doc/qtquicktest.rst new file mode 100644 index 000000000..9df2af071 --- /dev/null +++ b/sources/pyside6/PySide6/doc/qtquicktest.rst @@ -0,0 +1,62 @@ +// @snippet quick_test_main_documentation + +Sets up the entry point for a Qt Quick Test application. +The ``name`` argument uniquely identifies this set of tests. + +``sys.argv`` should be passed to the ``argv`` argument to ensure +propagation of the command line arguments. + +.. note:: The function assumes that your test sources are in the current + directory, unless the ``QUICK_TEST_SOURCE_DIR`` environment + variable is set or a directory is passed in ``dir``. + +The following snippet demonstrates the use of this function: + +.. code-block:: Python + + import sys + from PySide6.QtQuickTest import QUICK_TEST_MAIN + + ex = QUICK_TEST_MAIN("example", sys.argv) + sys.exit(ex) + + +// @snippet quick_test_main_documentation + +// @snippet quick_test_main_with_setup_documentation + +Sets up the entry point for a Qt Quick Test application. +The ``name`` argument uniquely identifies this set of tests. + +``sys.argv`` should be passed to the ``argv`` argument to ensure +propagation of the command line arguments. + +This function is identical to ``QUICK_TEST_MAIN()``, except that it takes an +additional argument ``setup``, the type of a ``QObject``-derived +class which will be instantiated. With this class, it is possible to define +additional setup code to execute before running the QML test. + +The following snippet demonstrates the use of this function: + +.. code-block:: Python + + import sys + from PySide6.QtQuickTest import QUICK_TEST_MAIN_WITH_SETUP + + class CustomTestSetup(QObject): + def __init__(self, parent=None): + super().__init__(parent) + + @Slot(QQmlEngine) + def qmlEngineAvailable(self, qmlEngine): + pass + + ex = QUICK_TEST_MAIN_WITH_SETUP("qquicktestsetup", CustomTestSetup, sys.argv) + sys.exit(ex) + + +.. note:: The function assumes that your test sources are in the current + directory, unless the ``QUICK_TEST_SOURCE_DIR`` environment + variable is set or a directory is passed in ``dir``. + +// @snippet quick_test_main_with_setup_documentation diff --git a/sources/pyside6/PySide6/glue/qtquicktest.cpp b/sources/pyside6/PySide6/glue/qtquicktest.cpp new file mode 100644 index 000000000..f41735ddf --- /dev/null +++ b/sources/pyside6/PySide6/glue/qtquicktest.cpp @@ -0,0 +1,50 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +/********************************************************************* + * INJECT CODE + ********************************************************************/ + +// @snippet call-quick-test-main +static int callQuickTestMain(const QString &name, QObject *setup, + QStringList argv, QString dir) +{ + if (dir.isEmpty()) + dir = QDir::currentPath(); + if (argv.isEmpty()) + argv.append(name); + + std::vector<QByteArray> argvB; + std::vector<char *> argvC; + const auto argc = argv.size(); + argvB.reserve(argc); + argvC.reserve(argc); + for (const auto &arg : argv) { + argvB.emplace_back(arg.toUtf8()); + argvC.push_back(argvB.back().data()); + } + + return quick_test_main_with_setup(int(argc), argvC.data(), + name.toUtf8().constData(), + dir.toUtf8().constData(), setup); +} +// @snippet call-quick-test-main + +// @snippet quick-test-main +const int exitCode = callQuickTestMain(%1, nullptr, %2, %3); +%PYARG_0 = %CONVERTTOPYTHON[int](exitCode); +// @snippet quick-test-main + +// @snippet quick-test-main_with_setup +Shiboken::AutoDecRef pySetupObject(PyObject_CallObject(reinterpret_cast<PyObject *>(%2), nullptr)); +if (pySetupObject.isNull() || PyErr_Occurred() != nullptr) + return nullptr; + +/// Convenience to convert a PyObject to QObject +QObject *setupObject = PySide::convertToQObject(pySetupObject.object(), true /* raiseError */); +if (setupObject == nullptr) + return nullptr; + +const int exitCode = callQuickTestMain(%1, setupObject, %3, %4); +%PYARG_0 = %CONVERTTOPYTHON[int](exitCode); +// @snippet quick-test-main_with_setup |
