Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2025-05-26 08:10:11 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2025-06-06 15:54:32 +0200
commit135c10324b1533f23f34a043963ce49b324c16c0 (patch)
treeacfdb440b718d86d66aeb2ed63e635c3e1ed15f3 /sources/shiboken6
parent2365c9bec8d03fe00b9153848adc6a474c3ff945 (diff)
shiboken6: Add a test for automatic conversion from T to std::optional<T>HEADdev
Task-number: PYSIDE-3107 Change-Id: I63f182eebba887780bfa882aebc653c60e07d9ad Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'sources/shiboken6')
-rw-r--r--sources/shiboken6/tests/smartbinding/std_optional_test.py9
-rw-r--r--sources/shiboken6/tests/smartbinding/typesystem_smart.xml13
2 files changed, 22 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/smartbinding/std_optional_test.py b/sources/shiboken6/tests/smartbinding/std_optional_test.py
index cd97facfa..9e8bc8d47 100644
--- a/sources/shiboken6/tests/smartbinding/std_optional_test.py
+++ b/sources/shiboken6/tests/smartbinding/std_optional_test.py
@@ -26,6 +26,15 @@ def integer_from_value(v):
class StdOptionalTests(unittest.TestCase):
+ def testConversionFromInt(self):
+ """PYSIDE-3107: Test whether a parameter taking a 'std::optional<int>'
+ accepts 'int'."""
+ b = StdOptionalTestBench()
+ b.setOptionalInt(43)
+ self.assertEqual(b.optionalInt().value(), 43)
+ b.setOptionalInt(None)
+ self.assertFalse(b.optionalInt().has_value())
+
def testCInt(self):
b = StdOptionalTestBench()
ci = b.optionalInt()
diff --git a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
index 14b181b61..4024036fa 100644
--- a/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
+++ b/sources/shiboken6/tests/smartbinding/typesystem_smart.xml
@@ -50,6 +50,19 @@
value-check-method="has_value"
instantiations="Integer,int">
<include file-name="optional" location="global"/>
+ <!-- PYSIDE-3107: Generic rule constructing std::optional<T>' from 'T'. -->
+ <conversion-rule>
+ <target-to-native>
+ <add-conversion type="Py_None">
+ SBK_UNUSED(pyIn)
+ %out = std::nullopt;
+ </add-conversion>
+ <add-conversion type="InstType" check="%CHECKTYPE[%OUTTYPE_0](%in)">
+ %OUTTYPE_0 v = %CONVERTTOCPP[%OUTTYPE_0](%in);
+ %out = %OUTTYPE(v);
+ </add-conversion>
+ </target-to-native>
+ </conversion-rule>
</smart-pointer-type>
</namespace-type>