aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-06 10:49:09 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-04-08 06:12:34 +0000
commita2672370256226a40df11025635b0e201303c823 (patch)
tree127253d42a627c031881d91f2ef3e152e1a1f8f1
parente7d5b521d4df48040b6ac0f8150f60245a6179f7 (diff)
Add a test for QSharedPointer
Task-number: PYSIDE-454 Change-Id: I2cb352390a9c6fcc32f8ef871a6de3023ab03237 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 9f9026e16295b58d5b6d00cf8624c598e1090a0f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--sources/pyside6/tests/pysidetest/CMakeLists.txt5
-rw-r--r--sources/pyside6/tests/pysidetest/pysidetest_global.h1
-rw-r--r--sources/pyside6/tests/pysidetest/shared_pointer_test.py55
-rw-r--r--sources/pyside6/tests/pysidetest/sharedpointertestbench.cpp56
-rw-r--r--sources/pyside6/tests/pysidetest/sharedpointertestbench.h50
-rw-r--r--sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml5
6 files changed, 172 insertions, 0 deletions
diff --git a/sources/pyside6/tests/pysidetest/CMakeLists.txt b/sources/pyside6/tests/pysidetest/CMakeLists.txt
index a6029a81e..7640c2d63 100644
--- a/sources/pyside6/tests/pysidetest/CMakeLists.txt
+++ b/sources/pyside6/tests/pysidetest/CMakeLists.txt
@@ -22,6 +22,7 @@ flagstest.cpp
testobject.cpp
testview.cpp
hiddenobject.cpp
+sharedpointertestbench.cpp
)
set(testbinding_SRC
@@ -33,6 +34,9 @@ ${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobjectwithnamespace_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp_testobject2withnamespace_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/pysidecpp2_testobjectwithoutnamespace_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/testbinding/qsharedpointer_qobject_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/testbinding/qsharedpointer_int_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/testbinding/sharedpointertestbench_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/testview_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/testbinding/testbinding_module_wrapper.cpp
)
@@ -150,6 +154,7 @@ PYSIDE_TEST(property_python_test.py)
PYSIDE_TEST(qapp_like_a_macro_test.py)
PYSIDE_TEST(qvariant_test.py)
PYSIDE_TEST(repr_test.py)
+PYSIDE_TEST(shared_pointer_test.py)
PYSIDE_TEST(signal_tp_descr_get_test.py)
PYSIDE_TEST(signal_slot_warning.py)
PYSIDE_TEST(signalandnamespace_test.py)
diff --git a/sources/pyside6/tests/pysidetest/pysidetest_global.h b/sources/pyside6/tests/pysidetest/pysidetest_global.h
index 61dee53d9..c0c60b5b9 100644
--- a/sources/pyside6/tests/pysidetest/pysidetest_global.h
+++ b/sources/pyside6/tests/pysidetest/pysidetest_global.h
@@ -35,5 +35,6 @@
#include "testview.h"
#include "flagstest.h"
#include "hiddenobject.h"
+#include "sharedpointertestbench.h"
#endif // PYSIDETEST_GLOBAL_H
diff --git a/sources/pyside6/tests/pysidetest/shared_pointer_test.py b/sources/pyside6/tests/pysidetest/shared_pointer_test.py
new file mode 100644
index 000000000..e5baa551c
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/shared_pointer_test.py
@@ -0,0 +1,55 @@
+#############################################################################
+##
+## Copyright (C) 2022 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of Qt for Python.
+##
+## $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 gc
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(True)
+
+from testbinding import SharedPointerTestbench
+
+
+class SharedPointerTests(unittest.TestCase):
+
+ def testObjSharedPointer(self):
+ p = SharedPointerTestbench.createSharedPointerQObject()
+ self.assertEqual(p.objectName(), "TestObject")
+ SharedPointerTestbench.printSharedPointerQObject(p)
+
+ def testIntSharedPointer(self):
+ p = SharedPointerTestbench.createSharedPointerInt(42)
+ SharedPointerTestbench.printSharedPointerInt(p)
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/sources/pyside6/tests/pysidetest/sharedpointertestbench.cpp b/sources/pyside6/tests/pysidetest/sharedpointertestbench.cpp
new file mode 100644
index 000000000..f04059043
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/sharedpointertestbench.cpp
@@ -0,0 +1,56 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $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$
+**
+****************************************************************************/
+
+#include "sharedpointertestbench.h"
+
+#include <QtCore/QObject>
+#include <QtCore/QDebug>
+
+SharedPointerTestbench::SharedPointerTestbench() = default;
+
+QSharedPointer<int> SharedPointerTestbench::createSharedPointerInt(int v)
+{
+ return QSharedPointer<int>(new int(v));
+}
+
+void SharedPointerTestbench::printSharedPointerInt(const QSharedPointer<int> &p)
+{
+ qDebug() << __FUNCTION__ << *p;
+}
+
+QSharedPointer<QObject> SharedPointerTestbench::createSharedPointerQObject()
+{
+ QSharedPointer<QObject> result(new QObject);
+ result->setObjectName(u"TestObject"_qs);
+ return result;
+}
+
+void SharedPointerTestbench::printSharedPointerQObject(const QSharedPointer<QObject> &p)
+{
+ qDebug() << __FUNCTION__ << p.data();
+}
diff --git a/sources/pyside6/tests/pysidetest/sharedpointertestbench.h b/sources/pyside6/tests/pysidetest/sharedpointertestbench.h
new file mode 100644
index 000000000..1732a59e5
--- /dev/null
+++ b/sources/pyside6/tests/pysidetest/sharedpointertestbench.h
@@ -0,0 +1,50 @@
+/****************************************************************************
+**
+** Copyright (C) 2022 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite of Qt for Python.
+**
+** $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$
+**
+****************************************************************************/
+
+#ifndef SHAREDPOINTERTESTBENCH_H
+#define SHAREDPOINTERTESTBENCH_H
+
+#include "pysidetest_macros.h"
+
+#include <QtCore/QSharedPointer>
+
+QT_FORWARD_DECLARE_CLASS(QObject)
+
+class PYSIDETEST_API SharedPointerTestbench
+{
+public:
+ SharedPointerTestbench();
+
+ static QSharedPointer<int> createSharedPointerInt(int v);
+ static void printSharedPointerInt(const QSharedPointer<int> &p);
+
+ static QSharedPointer<QObject> createSharedPointerQObject();
+ static void printSharedPointerQObject(const QSharedPointer<QObject> &p);
+};
+
+#endif // SHAREDPOINTERTESTBENCH_H
diff --git a/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml b/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
index 2736f8319..7f1170466 100644
--- a/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
+++ b/sources/pyside6/tests/pysidetest/typesystem_pysidetest.xml
@@ -68,6 +68,11 @@
<object-type name="ClassForEnum" />
</namespace-type>
+ <object-type name="SharedPointerTestbench"/>
+
+ <smart-pointer-type name="QSharedPointer" type="shared" getter="data"
+ reset-method="reset"/>
+
<suppress-warning text="type 'QPyTextObject' is specified in typesystem, but not defined. This could potentially lead to compilation errors." />
<!-- Qt5: I never really understood this warning. Probably it is because there
is no way to instantiate the class. Anyway, why must this class emit this warning?