aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-12-19 09:24:49 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-01-05 21:29:27 +0100
commitafba8e4a28d92c8584f2faa233372dd69887031c (patch)
tree3b46c79ebf40c2b1a86865b7c82e734632d701fd /sources/pyside6/tests
parenta8fcf44147167e186a1c7da7488ab821cc041291 (diff)
Fix qCompress/qUncompress() taking a PyBuffer/len arguments
The overloads taking a uchar * data argument were generated using the converter for uchar, causing warnings: qbytearray.h:639: There's no user provided way (conversion rule, argument removal, custom code, etc) to handle the primitive type 'const uchar *' of argument 1 in function 'qCompress(const uchar * data, qsizetype nbytes, int compressionLevel)'. qbytearray.h:640: There's no user provided way (conversion rule, argument removal, custom code, etc) to handle the primitive type 'const uchar *' of argument 1 in function 'qUncompress(const uchar * data, qsizetype nbytes)'. This was never noticed since we have a conversion from PyBuffer to QByteArray and the overload decisor checks only whether the minimum argument is satifisfied, so, so qCompress(data,len,level) it called qCompress(bytearry,len), passing the length as level. To fix this, modify the argument to PyBuffer as is done for QImage and give it overload-number 0, so that PyBuffer is checked first without conversion to QByteArray. Add a test for both cases. Amends ae51319fa8a7c02642f5d35f5d613c22e9ce8ecb. Task-number: PYSIDE-838 Change-Id: Ib9b22a24257fcf93ce3458d8514cdda2e4843f64 Reviewed-by: Christian Tismer <tismer@stackless.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'sources/pyside6/tests')
-rw-r--r--sources/pyside6/tests/QtCore/qbytearray_test.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/sources/pyside6/tests/QtCore/qbytearray_test.py b/sources/pyside6/tests/QtCore/qbytearray_test.py
index c00674859..555faf1c9 100644
--- a/sources/pyside6/tests/QtCore/qbytearray_test.py
+++ b/sources/pyside6/tests/QtCore/qbytearray_test.py
@@ -15,7 +15,8 @@ from init_paths import init_test_paths
init_test_paths(False)
-from PySide6.QtCore import QByteArray, QSettings, QObject, QDataStream, QIODevice
+from PySide6.QtCore import (QByteArray, QSettings, QObject, QDataStream,
+ QIODevice, qCompress, qUncompress)
class QByteArrayTestToNumber(unittest.TestCase):
@@ -256,5 +257,26 @@ class QByteArraySliceAssignment(unittest.TestCase):
self.assertEqual(orig_bytes, actual_bytes)
+class QCompressTest(unittest.TestCase):
+ def testQByteArrayCompression(self):
+ """Compress/uncompress a QByteArray."""
+ data = bytes(10 * 'long redundant sentence bla bla', "UTF8")
+ ba = QByteArray(data)
+ compressed = qCompress(ba)
+ self.assertTrue(len(compressed) < len(data))
+ uncompressed = qUncompress(compressed)
+ self.assertEqual(uncompressed, data)
+
+ def testBufferCompression(self):
+ """Compress/uncompress portions of bytes without converting to
+ QByteArray."""
+ data = bytes(10 * 'long redundant sentence bla bla', "UTF8")
+ used_len = int(len(data) / 2)
+ compressed = qCompress(data, used_len, -1)
+ self.assertTrue(len(compressed) < used_len)
+ uncompressed = qUncompress(compressed.data(), len(compressed))
+ self.assertEqual(uncompressed, data[:used_len])
+
+
if __name__ == '__main__':
unittest.main()