Ejemplo n.º 1
0
    def test_CTypesView__doublebytes(self):
        buf1 = sdlextarray.CTypesView(doublebyteseq, USHORT_SIZE, docopy=True)
        buf2 = sdlextarray.CTypesView(doublebytebuf, USHORT_SIZE, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            assert isinstance(singlebytes, sdlextarray.CTypesView)
            assert singlebytes.is_shared == shared
            assert singlebytes.bytesize == len(doublebyteseq) * 2
            offset = 0
            cnt = 0
            for val in singlebytes.to_bytes():
                if cnt > 0:
                    assert val == hibyte16(doublebyteseq[offset])
                    cnt = 0
                    offset += 1
                else:
                    assert val == lobyte16(doublebyteseq[offset])
                    cnt += 1

            offset = 0
            for val in singlebytes.to_uint16():
                assert val == doublebyteseq[offset]
                offset += 1

            offset = 0
            for val in singlebytes.to_uint32():
                seqval = create_32b(doublebyteseq, 2, offset)
                assert val == seqval
                offset += 2

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(doublebyteseq, 2, offset)
                assert val == seqval
                offset += 4
Ejemplo n.º 2
0
    def test_CTypesView__singlebytes(self):
        buf1 = sdlextarray.CTypesView(singlebyteseq, docopy=True)
        buf2 = sdlextarray.CTypesView(singlebytebuf, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            assert isinstance(singlebytes, sdlextarray.CTypesView)
            assert singlebytes.is_shared == shared
            assert singlebytes.bytesize == len(singlebyteseq)
            for index, val in enumerate(singlebytes.to_bytes()):
                assert val == singlebyteseq[index]

            offset = 0
            for val in singlebytes.to_uint16():
                seqval = create_16b(singlebyteseq, offset)
                assert val == seqval
                offset += 2

            offset = 0
            for val in singlebytes.to_uint32():
                seqval = create_32b(singlebyteseq, 1, offset)
                assert val == seqval
                offset += 4

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(singlebyteseq, 1, offset)
                assert val == seqval
                offset += 8
Ejemplo n.º 3
0
    def test_CTypesView__doublebytes(self):
        buf1 = sdlextarray.CTypesView(doublebyteseq, USHORT_SIZE, docopy=True)
        buf2 = sdlextarray.CTypesView(doublebytebuf, USHORT_SIZE, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            self.assertIsInstance(singlebytes, sdlextarray.CTypesView)
            self.assertEqual(singlebytes.is_shared, shared)
            self.assertEqual(singlebytes.bytesize, len(doublebyteseq) * 2)
            offset = 0
            cnt = 0
            for val in singlebytes.to_bytes():
                if cnt > 0:
                    self.assertEqual(val, hibyte16(doublebyteseq[offset]))
                    cnt = 0
                    offset += 1
                else:
                    self.assertEqual(val, lobyte16(doublebyteseq[offset]))
                    cnt += 1

            offset = 0
            for val in singlebytes.to_uint16():
                self.assertEqual(val, doublebyteseq[offset])
                offset += 1

            offset = 0
            for val in singlebytes.to_uint32():
                seqval = create_32b(doublebyteseq, 2, offset)
                self.assertEqual(val, seqval)
                offset += 2

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(doublebyteseq, 2, offset)
                self.assertEqual(val, seqval)
                offset += 4
Ejemplo n.º 4
0
    def test_CTypesView__singlebytes(self):
        buf1 = sdlextarray.CTypesView(singlebyteseq, docopy=True)
        buf2 = sdlextarray.CTypesView(singlebytebuf, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            self.assertIsInstance(singlebytes, sdlextarray.CTypesView)
            self.assertEqual(singlebytes.is_shared, shared)
            self.assertEqual(singlebytes.bytesize, len(singlebyteseq))
            for index, val in enumerate(singlebytes.to_bytes()):
                self.assertEqual(val, singlebyteseq[index])

            offset = 0
            for val in singlebytes.to_uint16():
                seqval = create_16b(singlebyteseq, offset)
                self.assertEqual(val, seqval)
                offset += 2

            offset = 0
            for val in singlebytes.to_uint32():
                seqval = create_32b(singlebyteseq, 1, offset)
                self.assertEqual(val, seqval)
                offset += 4

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(singlebyteseq, 1, offset)
                self.assertEqual(val, seqval)
                offset += 8
Ejemplo n.º 5
0
    def test_CTypesView__quadbytes(self):
        buf1 = sdlextarray.CTypesView(quadbyteseq, UINT_SIZE, docopy=True)
        buf2 = sdlextarray.CTypesView(quadbytebuf, UINT_SIZE, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            assert isinstance(singlebytes, sdlextarray.CTypesView)
            assert singlebytes.is_shared == shared
            assert singlebytes.bytesize == len(quadbyteseq) * 4
            offset = 0
            cnt = 0
            for val in singlebytes.to_bytes():
                assert val == ltrbyte32(quadbyteseq[offset], cnt)
                if cnt == 3:
                    offset += 1
                    cnt = 0
                else:
                    cnt += 1

            cnt = 0
            offset = 0
            for val in singlebytes.to_uint16():
                if cnt > 0:
                    assert val == hibytes32(quadbyteseq[offset])
                    cnt = 0
                    offset += 1
                else:
                    assert val == lobytes32(quadbyteseq[offset])
                    cnt += 1

            offset = 0
            for val in singlebytes.to_uint32():
                assert val == quadbyteseq[offset]
                offset += 1

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(quadbyteseq, 4, offset)
                assert val == seqval
                offset += 2
Ejemplo n.º 6
0
    def test_CTypesView__quadbytes(self):
        buf1 = sdlextarray.CTypesView(quadbyteseq, UINT_SIZE, docopy=True)
        buf2 = sdlextarray.CTypesView(quadbytebuf, UINT_SIZE, docopy=False)
        for singlebytes, shared in ((buf1, False), (buf2, True)):
            self.assertIsInstance(singlebytes, sdlextarray.CTypesView)
            self.assertEqual(singlebytes.is_shared, shared)
            self.assertEqual(singlebytes.bytesize, len(quadbyteseq) * 4)
            offset = 0
            cnt = 0
            for val in singlebytes.to_bytes():
                self.assertEqual(val, ltrbyte32(quadbyteseq[offset], cnt))
                if cnt == 3:
                    offset += 1
                    cnt = 0
                else:
                    cnt += 1

            cnt = 0
            offset = 0
            for val in singlebytes.to_uint16():
                if cnt > 0:
                    self.assertEqual(val, hibytes32(quadbyteseq[offset]))
                    cnt = 0
                    offset += 1
                else:
                    self.assertEqual(val, lobytes32(quadbyteseq[offset]))
                    cnt += 1

            offset = 0
            for val in singlebytes.to_uint32():
                self.assertEqual(val, quadbyteseq[offset])
                offset += 1

            offset = 0
            for val in singlebytes.to_uint64():
                seqval = create_64b(quadbyteseq, 4, offset)
                self.assertEqual(val, seqval)
                offset += 2
Ejemplo n.º 7
0
    def test_CTypesView__repr__(self):
        seqs = (
            (singlebyteseq, UBYTE_SIZE, 1, False),
            (doublebyteseq, USHORT_SIZE, 2, False),
            (quadbyteseq, UINT_SIZE, 4, False),
            (singlebytebuf, UBYTE_SIZE, 1, True),
            (doublebytebuf, USHORT_SIZE, 2, True),
            (quadbytebuf, UINT_SIZE, 4, True),
        )
        for seq, size, factor, shared in seqs:
            buf = sdlextarray.CTypesView(seq, size, not shared)
            otype = type(seq).__name__
            if not shared:
                otype = 'array'

            text = "CTypesView(type=%s, bytesize=%d, shared=%s)" % \
                (otype, len(seq) * factor, shared)
            assert text == repr(buf)