aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken6/tests/minimalbinding
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-20 13:51:08 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-10-21 13:03:11 +0200
commite70fbd8d91af1fa9813bc1df7dfad44b1665957e (patch)
tree459fdff3bb60d2405bd5d0a02292a44b358689d7 /sources/shiboken6/tests/minimalbinding
parentc0beb9f29f36ea3bc8be26675a05253cc5584fe4 (diff)
shiboken6: Implement opaque containers for getters returning a const reference
Add a bool m_const member to the container helper template that indicates a const container. Error out of the modification functions if that is set. Create an additional creation function for the const case. A const opaque containers is then of same Python type as the non-const version, requiring no further type checks. Pick-to: 6.2 Task-number: PYSIDE-1605 Change-Id: I45faeb0d68e6144a9dfbe25497694b8acdd98c09 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6/tests/minimalbinding')
-rw-r--r--sources/shiboken6/tests/minimalbinding/listuser_test.py5
-rw-r--r--sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml5
2 files changed, 10 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/minimalbinding/listuser_test.py b/sources/shiboken6/tests/minimalbinding/listuser_test.py
index 7bb65d359..a1fc48c08 100644
--- a/sources/shiboken6/tests/minimalbinding/listuser_test.py
+++ b/sources/shiboken6/tests/minimalbinding/listuser_test.py
@@ -351,6 +351,11 @@ class ListOfIntListConversionTest(unittest.TestCase):
self.assertEqual(len(lu.m_stdIntList), 4)
self.assertEqual(lu.m_stdIntList[3], 6)
+ # Access a const list via getter and verify that it cannot be modified
+ const_l = lu.getConstIntList()
+ self.assertEqual(len(const_l), 4)
+ self.assertRaises(TypeError, const_l.append, 6)
+
if __name__ == '__main__':
unittest.main()
diff --git a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml
index 94ec4a649..9bb7e7b7e 100644
--- a/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml
+++ b/sources/shiboken6/tests/minimalbinding/typesystem_minimal.xml
@@ -53,6 +53,11 @@
<replace-type modified-type="StdIntList"/>
</modify-argument>
</modify-function>
+ <modify-function signature="getConstIntList()const">
+ <modify-argument index="return">
+ <replace-type modified-type="StdIntList"/>
+ </modify-argument>
+ </modify-function>
</value-type>
<value-type name="MinBoolUser"/>