aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests/support/voidptr_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/tests/support/voidptr_test.py')
-rw-r--r--sources/pyside6/tests/support/voidptr_test.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/sources/pyside6/tests/support/voidptr_test.py b/sources/pyside6/tests/support/voidptr_test.py
new file mode 100644
index 000000000..d9ea57a61
--- /dev/null
+++ b/sources/pyside6/tests/support/voidptr_test.py
@@ -0,0 +1,49 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+import os
+import sys
+import unittest
+
+from pathlib import Path
+sys.path.append(os.fspath(Path(__file__).resolve().parents[1]))
+from init_paths import init_test_paths
+init_test_paths(False)
+
+from shiboken6 import Shiboken
+from PySide6.support import VoidPtr
+from PySide6.QtCore import QByteArray
+
+
+class PySide6Support(unittest.TestCase):
+
+ def testVoidPtr(self):
+ # Creating a VoidPtr object requires an address of
+ # a C++ object, a wrapped Shiboken Object type,
+ # an object implementing the Python Buffer interface,
+ # or another VoidPtr object.
+
+ # Original content
+ b = b"Hello world"
+ ba = QByteArray(b)
+ vp = VoidPtr(ba, ba.size())
+ self.assertIsInstance(vp, Shiboken.VoidPtr)
+
+ # Create QByteArray from voidptr byte interpretation
+ nba = QByteArray(vp.toBytes())
+ # Compare original bytes to toBytes()
+ self.assertTrue(b, vp.toBytes())
+ # Compare original with new QByteArray data
+ self.assertTrue(b, nba.data())
+ # Convert original and new to str
+ self.assertTrue(str(b), str(nba))
+
+ # Modify nba through a memoryview of vp
+ mv = memoryview(vp)
+ self.assertFalse(mv.readonly)
+ mv[6:11] = b'void*'
+ self.assertEqual(str(ba), str(b"Hello void*"))
+
+
+if __name__ == '__main__':
+ unittest.main()