diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-06 13:19:09 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-10-10 11:46:11 +0200 |
commit | 0c71a7086aefbdd3c3f6a4e0e76fa8804ee8d8ea (patch) | |
tree | 922361fab8dfe656d2c021656ba9cf39bf322549 /sources/shiboken6/tests | |
parent | 8b9d69fac87cb18777e33103512c8592edd05ff4 (diff) |
shiboken tests: Fix test for user added constructors
The test injected code to manipulate the overload number of the
overload decisor and change values based on that which lead to
unpleasant surprises when adding copy and move constructors. Spell it
out to do some basic string parsing instead.
Pick-to: 6.6
Task-number: PYSIDE-2479
Change-Id: I7a6fb9c8c22532a20711b4854f5c9b3b0d81d213
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/shiboken6/tests')
3 files changed, 25 insertions, 8 deletions
diff --git a/sources/shiboken6/tests/samplebinding/samplesnippets.cpp b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp index 40f9c6db3..43e6b08de 100644 --- a/sources/shiboken6/tests/samplebinding/samplesnippets.cpp +++ b/sources/shiboken6/tests/samplebinding/samplesnippets.cpp @@ -35,3 +35,20 @@ static PyObject *Sbk_IntWrapper_add_ints(PyObject * /* self */, PyObject *args) %RETURN_TYPE %0 = %CPPSELF.pow(%1); %PYARG_0 = %CONVERTTOPYTHON[%RETURN_TYPE](%0); // @snippet stdcomplex_pow + +// @snippet size_char_ct +// Convert a string "{width}x{height}" specification +{ + double width = -1; + double height = -1; + const std::string s = %1; + const auto pos = s.find('x'); + if (pos != std::string::npos) { + std::istringstream wstr(s.substr(0, pos)); + wstr >> width; + std::istringstream hstr(s.substr(pos + 1, s.size() - pos - 1)); + hstr >> height; + } + %0 = new %TYPE(width, height); +} +// @snippet size_char_ct diff --git a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml index bc291482d..6fd096519 100644 --- a/sources/shiboken6/tests/samplebinding/typesystem_sample.xml +++ b/sources/shiboken6/tests/samplebinding/typesystem_sample.xml @@ -1894,13 +1894,13 @@ </value-type> <value-type name="Size"> + <extra-includes> + <include file-name="string" location="global"/> + <include file-name="sstream" location="global"/> + </extra-includes> <add-function signature="Size(const char*)"> - <inject-code class="target" position="beginning"> - %0 = new %TYPE(); - </inject-code> - <inject-code class="target" position="end"> - Shiboken::AutoDecRef result(PyObject_CallMethod(%PYSELF, const_cast<char*>("setHeight"), const_cast<char*>("i"), 2)); - </inject-code> + <inject-code class="target" position="beginning" + file="samplesnippets.cpp" snippet="size_char_ct"/> </add-function> </value-type> <value-type name="SizeF"/> diff --git a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py index 3aee8d6f7..28cbd96fd 100644 --- a/sources/shiboken6/tests/samplebinding/useraddedctor_test.py +++ b/sources/shiboken6/tests/samplebinding/useraddedctor_test.py @@ -12,12 +12,12 @@ from pathlib import Path sys.path.append(os.fspath(Path(__file__).resolve().parents[1])) from shiboken_paths import init_paths init_paths() -from sample import * +from sample import Size class PointTest(unittest.TestCase): def testUsingSelfOnCtor(self): # This is a user added ctor and no errors should happen! - s = Size("oi") + s = Size("3x2") self.assertEqual(s.height(), 2) if __name__ == '__main__': |