aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-12 11:06:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-04-13 17:17:14 +0200
commit02a1213bfe18d4ce86370898816fbc470c40a66b (patch)
tree648eaf0994d4868062eec819125d6b4eee0e04f0 /sources/shiboken6
parent8488a8e80644e37f99dcffe4dba8833ddc068f4e (diff)
shiboken6: Add a test for a shared pointer with a primitive type
Task-number: PYSIDE-454 Change-Id: Ic416988e58e2207ada97768af8e75f621e2e944c Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp20
-rw-r--r--sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h4
-rw-r--r--sources/shiboken6/tests/smartbinding/CMakeLists.txt1
-rw-r--r--sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py9
-rw-r--r--sources/shiboken6/tests/smartbinding/typesystem_smart.xml4
5 files changed, 36 insertions, 2 deletions
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp
index 3ee930041..7b62e5833 100644
--- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp
+++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.cpp
@@ -55,3 +55,23 @@ void StdSharedPtrTestBench::printInteger(const std::shared_ptr<Integer> &p)
std::cerr << "nullptr";
std::cerr << '\n';
}
+
+std::shared_ptr<int> StdSharedPtrTestBench::createInt(int v)
+{
+ return std::make_shared<int>(v);
+}
+
+std::shared_ptr<int> StdSharedPtrTestBench::createNullInt()
+{
+ return {};
+}
+
+void StdSharedPtrTestBench::printInt(const std::shared_ptr<int> &p)
+{
+ std::cerr << __FUNCTION__ << ' ';
+ if (p.get())
+ std::cerr << *p;
+ else
+ std::cerr << "nullptr";
+ std::cerr << '\n';
+}
diff --git a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h
index 0cf5d78a4..0397013e1 100644
--- a/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h
+++ b/sources/shiboken6/tests/libsmart/stdsharedptrtestbench.h
@@ -44,6 +44,10 @@ public:
static std::shared_ptr<Integer> createInteger(int v = 42);
static std::shared_ptr<Integer> createNullInteger();
static void printInteger(const std::shared_ptr<Integer> &);
+
+ static std::shared_ptr<int> createInt(int v = 42);
+ static std::shared_ptr<int> createNullInt();
+ static void printInt(const std::shared_ptr<int> &);
};
#endif // STDSHAREDPTRTESTBENCH_H
diff --git a/sources/shiboken6/tests/smartbinding/CMakeLists.txt b/sources/shiboken6/tests/smartbinding/CMakeLists.txt
index 1f89ce096..afe4ba9b9 100644
--- a/sources/shiboken6/tests/smartbinding/CMakeLists.txt
+++ b/sources/shiboken6/tests/smartbinding/CMakeLists.txt
@@ -15,6 +15,7 @@ ${CMAKE_CURRENT_BINARY_DIR}/smart/smart_integer2_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/sharedptr_integer2_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/stdsharedptrtestbench_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_integer_wrapper.cpp
+${CMAKE_CURRENT_BINARY_DIR}/smart/std_shared_ptr_int_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/smart/std_wrapper.cpp
)
diff --git a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py
index 4617f8932..a7d82806a 100644
--- a/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py
+++ b/sources/shiboken6/tests/smartbinding/std_shared_ptr_test.py
@@ -46,7 +46,7 @@ def call_func_on_ptr(ptr):
class StdSharedPtrTests(unittest.TestCase):
- def testIt(self):
+ def testInteger(self):
p = StdSharedPtrTestBench.createInteger()
StdSharedPtrTestBench.printInteger(p)
self.assertTrue(p)
@@ -57,6 +57,13 @@ class StdSharedPtrTests(unittest.TestCase):
self.assertFalse(np)
self.assertRaises(AttributeError, call_func_on_ptr, np)
+ def testInt(self):
+ np = StdSharedPtrTestBench.createNullInt()
+ StdSharedPtrTestBench.printInt(np)
+ self.assertFalse(np)
+ p = StdSharedPtrTestBench.createInt()
+ StdSharedPtrTestBench.printInt(p)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
index 2bbb1f56a..83720688d 100644
--- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
+++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
@@ -2,6 +2,8 @@
<typesystem package="smart">
<rejection class="*" argument-type="^std::nullptr_t&amp;?$"/>
+ <primitive-type name="int"/>
+
<template name="cpplist_to_pylist_convertion">
PyObject *%out = PyList_New(int(%in.size()));
int idx = 0;
@@ -47,7 +49,7 @@
<smart-pointer-type name="shared_ptr" type="shared" getter="get"
value-check-method="operator bool"
ref-count-method="use_count"
- instantiations="Integer">
+ instantiations="Integer,int">
<include file-name="memory" location="global"/>
</smart-pointer-type>
</namespace-type>