diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-23 13:36:05 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-11-25 08:55:21 +0100 |
commit | 3c24f0a856a166b4672921c4e1c2347ca397fdac (patch) | |
tree | 794320edfa0f275592bb26b25bb58a6b498cbc98 | |
parent | dd35e0a62896b3d85cdcd5f8c483136c95667ce4 (diff) |
shiboken6: Add a test for operator nb_bool of smart pointers
Task-number: PYSIDE-454
Change-Id: I849d0a855395846f7cbe9cd97685457627dfd1a2
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit df72cfdfffc00c74f542f27475d651f7c6d088fa)
-rw-r--r-- | sources/shiboken6/tests/libsmart/smart.cpp | 12 | ||||
-rw-r--r-- | sources/shiboken6/tests/libsmart/smart_obj.h | 3 | ||||
-rw-r--r-- | sources/shiboken6/tests/smartbinding/smart_pointer_test.py | 7 |
3 files changed, 22 insertions, 0 deletions
diff --git a/sources/shiboken6/tests/libsmart/smart.cpp b/sources/shiboken6/tests/libsmart/smart.cpp index 81fa30c7e..f5d318e59 100644 --- a/sources/shiboken6/tests/libsmart/smart.cpp +++ b/sources/shiboken6/tests/libsmart/smart.cpp @@ -153,6 +153,18 @@ Integer Obj::takeInteger(Integer val) return val; } +SharedPtr<Integer> Obj::createSharedPtrToInteger(int value) +{ + auto *i = new Integer; + i->setValue(value); + return SharedPtr<Integer>(i); +} + +SharedPtr<Integer> Obj::createNullSharedPtrToInteger() +{ + return {}; +} + Integer::Integer() : m_int(456) { Registry::getInstance()->add(this); diff --git a/sources/shiboken6/tests/libsmart/smart_obj.h b/sources/shiboken6/tests/libsmart/smart_obj.h index 8fe45993f..579f3db4a 100644 --- a/sources/shiboken6/tests/libsmart/smart_obj.h +++ b/sources/shiboken6/tests/libsmart/smart_obj.h @@ -55,6 +55,9 @@ public: int takeSharedPtrToObj(SharedPtr<Obj> pObj); int takeSharedPtrToInteger(SharedPtr<Integer> pInt); + static SharedPtr<Integer> createSharedPtrToInteger(int value); + static SharedPtr<Integer> createNullSharedPtrToInteger(); + int m_integer; // public for testing member field access. Integer *m_internalInteger; }; diff --git a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py index 10e761149..a9ea91be6 100644 --- a/sources/shiboken6/tests/smartbinding/smart_pointer_test.py +++ b/sources/shiboken6/tests/smartbinding/smart_pointer_test.py @@ -239,5 +239,12 @@ class SmartPointerTests(unittest.TestCase): r = o.takeSharedPtrToInteger(integer2) self.assertEqual(r, integer2.value()) + def testOperatorNbBool(self): + null_ptr = Obj.createNullSharedPtrToInteger() + self.assertFalse(null_ptr) + zero = Obj.createSharedPtrToInteger(0) + self.assertTrue(zero) + + if __name__ == '__main__': unittest.main() |