summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-06-29 21:48:36 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-06-29 21:48:36 (GMT)
commitd436818deded4064c5476111f980189836b360c7 (patch)
tree940b271db3c6ffead608334a615114ed7ce1f29c /tests
parent7e397e656e983931085ee0d656945b2d8ca3ce5b (diff)
Included the packed buffers in the Python bindings.
Diffstat (limited to 'tests')
-rw-r--r--tests/common/packed.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/common/packed.py b/tests/common/packed.py
new file mode 100644
index 0000000..25918d2
--- /dev/null
+++ b/tests/common/packed.py
@@ -0,0 +1,59 @@
+
+# Tests pour valider les tampons de données
+
+
+from chrysacase import ChrysalideTestCase
+from pychrysalide.common import PackedBuffer
+
+
+class TestPackedBuffers(ChrysalideTestCase):
+ """TestCase for common.PackedBuffer*"""
+
+ def testPackedBufferConstructor(self):
+ """Validate new packed buffers."""
+
+ pbuf = PackedBuffer()
+ self.assertIsNotNone(pbuf)
+
+
+ def testPackedBufferData(self):
+ """Play with packed buffer data."""
+
+ pbuf = PackedBuffer()
+
+ data = b'0123456789'
+
+ pbuf.extend(data, False)
+ pbuf.extend(data)
+
+ self.assertEqual(pbuf.payload_length, 2 * len(data))
+
+ self.assertFalse(pbuf.more_data)
+
+ pbuf.rewind()
+
+ self.assertTrue(pbuf.more_data)
+
+ got = pbuf.peek(1)
+ self.assertEqual(got, b'0')
+
+ got = pbuf.peek(2)
+ self.assertEqual(got, b'01')
+
+ pbuf.advance(3)
+
+ got = pbuf.peek(2)
+ self.assertEqual(got, b'34')
+
+ pbuf.advance(8)
+
+ got = pbuf.peek(2)
+ self.assertEqual(got, b'12')
+
+ pbuf.rewind()
+
+ got = pbuf.extract(4)
+ self.assertEqual(got, b'0123')
+
+ got = pbuf.extract(8, True)
+ self.assertEqual(got, b'10987654')