def testWriteWrongArrayLength(self):
     numSentences = 13
     wrongArrayLength = True
     message = self._createMessage(numSentences, wrongArrayLength)
     writer = zserio.BitStreamWriter()
     with self.assertRaises(zserio.PythonRuntimeException):
         message.write(writer)
Beispiel #2
0
 def testFromReader(self):
     writer = zserio.BitStreamWriter()
     OneStringStructureTest._writeOneStringStructureToStream(
         writer, self.ONE_STRING)
     reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
     oneStringStructure = self.api.OneStringStructure.from_reader(reader)
     self.assertEqual(self.ONE_STRING, oneStringStructure.one_string)
 def testRead(self):
     writeWrongOffset = False
     writer = zserio.BitStreamWriter()
     self._writeAutoArrayHolderToStream(writer, writeWrongOffset)
     reader = zserio.BitStreamReader(writer.getByteArray())
     autoArrayHolder = self.api.AutoArrayHolder.fromReader(reader)
     self._checkAutoArrayHolder(autoArrayHolder)
    def testWrite(self):
        permission = self.api.Permission.Values.READ
        writer = zserio.BitStreamWriter()
        permission.write(writer)

        reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
        readPermission = self.api.Permission.from_reader(reader)
        self.assertEqual(permission, readPermission)
Beispiel #5
0
    def testWrite(self):
        permission = self.api.Permission.Values.READ
        writer = zserio.BitStreamWriter()
        permission.write(writer)

        reader = zserio.BitStreamReader(writer.getByteArray())
        readPermission = self.api.Permission.fromReader(reader)
        self.assertEqual(permission, readPermission)
Beispiel #6
0
    def testReadWrongLengthGreater(self):
        writer = zserio.BitStreamWriter()
        self.__class__._write(writer, self.WRONG_LENGTH_GREATER)
        reader = zserio.BitStreamReader(writer.getByteArray())

        arrayLengthofConstraint = self.api.ArrayLengthofConstraint()
        with self.assertRaises(zserio.PythonRuntimeException):
            arrayLengthofConstraint.read(reader)
Beispiel #7
0
 def testRead(self):
     numSentences = 10
     wrongArrayLength = False
     writer = zserio.BitStreamWriter()
     self._writeMessageToStream(writer, numSentences, wrongArrayLength)
     reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
     message = self.api.Message.from_reader(reader)
     self._checkMessage(message, numSentences)
 def testRead(self):
     writeWrongOffsets = False
     writer = zserio.BitStreamWriter()
     CompoundIndexedOffsetArrayTest._writeCompoundIndexedOffsetArrayToStream(writer, writeWrongOffsets)
     reader = zserio.BitStreamReader(writer.getByteArray())
     compoundIndexedOffsetArray = self.api.CompoundIndexedOffsetArray()
     compoundIndexedOffsetArray.read(reader)
     self._checkCompoundIndexedOffsetArray(compoundIndexedOffsetArray)
Beispiel #9
0
    def _checkRead(self, numElements):
        writer = zserio.BitStreamWriter()
        AutoArrayStructRecursionTest._writeAutoArrayRecursionToStream(
            writer, numElements)

        reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
        autoArrayRecursion = self.api.AutoArrayRecursion.from_reader(reader)
        self._checkAutoArrayRecursion(autoArrayRecursion, numElements)
Beispiel #10
0
 def testReadWrongOffsets(self):
     writeWrongOffset = True
     writer = zserio.BitStreamWriter()
     self._writeAutoArrayHolderToStream(writer, writeWrongOffset)
     reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
     with self.assertRaises(zserio.PythonRuntimeException):
         autoArrayHolder = self.api.AutoArrayHolder.from_reader(reader)
         self._checkAutoArrayHolder(autoArrayHolder)
Beispiel #11
0
    def testFromReader(self):
        writer = zserio.BitStreamWriter()
        self._writeTile(writer)

        reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
        tile = self.api.Tile.from_reader(reader)

        self._checkTile(tile)
Beispiel #12
0
    def _checkChoiceArrayFunction(self, pos):
        inner = self._createInner(pos)
        readElement = inner.getRef().funcGetElement()
        if pos >= self.NUM_ITEMS:
            self.assertEqual(self.EXPLICIT_ITEM, readElement)
        else:
            self.assertEqual(self.ITEMS[pos], readElement)

        writer = zserio.BitStreamWriter()
        inner.write(writer)
        expectedWriter = zserio.BitStreamWriter()
        self._writeOuterArrayToStream(expectedWriter, pos)
        self.assertTrue(expectedWriter.getByteArray() == writer.getByteArray())

        reader = zserio.BitStreamReader(writer.getByteArray())
        readInner = self.api.Inner.fromReader(reader)
        self.assertEqual(inner, readInner)
 def testRead(self):
     writeWrongOffsets = False
     writer = zserio.BitStreamWriter()
     VarInt32IndexedOffsetArrayTest._writeVarInt32IndexedOffsetArrayToStream(writer, writeWrongOffsets)
     reader = zserio.BitStreamReader(writer.getByteArray())
     varInt32IndexedOffsetArray = self.api.VarInt32IndexedOffsetArray()
     varInt32IndexedOffsetArray.read(reader)
     self._checkVarInt32IndexedOffsetArray(varInt32IndexedOffsetArray)
    def testWriteWrongLengthLess(self):
        arrayLengthofConstraint = self.api.ArrayLengthofConstraint()
        arrayLengthofConstraint.setArray(
            [i for i in range(self.WRONG_LENGTH_LESS)])

        writer = zserio.BitStreamWriter()
        with self.assertRaises(zserio.PythonRuntimeException):
            arrayLengthofConstraint.write(writer)
Beispiel #15
0
    def _checkWrite(self, numElements):
        autoArrayRecursion = self._createAutoArrayRecursion(numElements)
        writer = zserio.BitStreamWriter()
        autoArrayRecursion.write(writer)

        reader = zserio.BitStreamReader(writer.getByteArray())
        readAutoArrayRecursion = self.api.AutoArrayRecursion.fromReader(reader)
        self._checkAutoArrayRecursion(readAutoArrayRecursion, numElements)
Beispiel #16
0
 def testWriteWrongPurpleConstraint(self):
     structureConstraints = self.api.StructureConstraints.fromFields(self.api.BasicColor.BLACK,
                                                                     self.api.BasicColor.WHITE,
                                                                     True,
                                                                     self.api.ExtendedColor.LIME)
     writer = zserio.BitStreamWriter()
     with self.assertRaises(zserio.PythonRuntimeException):
         structureConstraints.write(writer)
    def testWriteWrongValue16Constraint(self):
        value16 = self.VALUE16_WRONG_CONSTRAINT
        unionConstraints = self.api.UnionConstraints()
        unionConstraints.setValue16(value16)

        writer = zserio.BitStreamWriter()
        with self.assertRaises(zserio.PythonRuntimeException):
            unionConstraints.write(writer)
Beispiel #18
0
 def testWriteWithPosition(self):
     createWrongOffset = True
     autoArrayHolder = self._createAutoArrayHolder(createWrongOffset)
     writer = zserio.BitStreamWriter()
     bitPosition = 2
     writer.write_bits(0, bitPosition)
     autoArrayHolder.write(writer)
     self._checkAutoArrayHolder(autoArrayHolder, bitPosition)
Beispiel #19
0
 def testWriteWithPosition(self):
     uint64Offset = self.api.UInt64Offset.fromFields(
         0, list(range(self.ARRAY_SIZE)), 0)
     writer = zserio.BitStreamWriter()
     writer.writeBits(0, 3)
     uint64Offset.write(writer)
     self.assertEqual(self.OFFSET + 1, uint64Offset.getOffset())
     self.assertEqual(self.BIT_SIZE / 8 + 1, len(writer.getByteArray()))
Beispiel #20
0
 def testWriteWithPosition(self):
     createWrongOffsets = True
     nestedOffset = self._createNestedOffset(createWrongOffsets)
     writer = zserio.BitStreamWriter()
     bitPosition = 2
     writer.write_bits(0, bitPosition)
     nestedOffset.write(writer)
     self._checkNestedOffset(nestedOffset)
 def testReadWrongOffsets(self):
     writeWrongOffsets = True
     writer = zserio.BitStreamWriter()
     CompoundIndexedOffsetArrayTest._writeCompoundIndexedOffsetArrayToStream(writer, writeWrongOffsets)
     reader = zserio.BitStreamReader(writer.getByteArray())
     compoundIndexedOffsetArray = self.api.CompoundIndexedOffsetArray()
     with self.assertRaises(zserio.PythonRuntimeException):
         compoundIndexedOffsetArray.read(reader)
    def _checkRead(self, numElements):
        writer = zserio.BitStreamWriter()
        self._writePackedAutoArrayToStream(writer, numElements)
        reader = zserio.BitStreamReader(writer.byte_array, writer.bitposition)
        packedAutoArray = self.api.PackedAutoArray.from_reader(reader)

        uint8Array = packedAutoArray.uint8_array
        self._checkPackedAutoArray(uint8Array, numElements)
    def testParamConstructorCase1Forbidden(self):
        testUnion = self.api.TestUnion(False)
        self.assertFalse(testUnion.getCase1Allowed())

        testUnion.setCase1Field(11)
        writer = zserio.BitStreamWriter()
        with self.assertRaises(zserio.PythonRuntimeException):
            testUnion.write(writer)  # raises exception
 def testRead(self):
     writeWrongOffsets = False
     writer = zserio.BitStreamWriter()
     BoolIndexedOffsetArrayTest._writeBoolIndexedOffsetArrayToStream(writer, writeWrongOffsets)
     reader = zserio.BitStreamReader(writer.getByteArray())
     boolIndexedOffsetArray = self.api.BoolIndexedOffsetArray()
     boolIndexedOffsetArray.read(reader)
     self._checkBoolIndexedOffsetArray(boolIndexedOffsetArray)
Beispiel #25
0
    def testWriteWrongLengthGreater(self):
        arrayLengthofConstraint = self.api.ArrayLengthofConstraint()
        arrayLengthofConstraint.setArray(list(range(
            self.WRONG_LENGTH_GREATER)))

        writer = zserio.BitStreamWriter()
        with self.assertRaises(zserio.PythonRuntimeException):
            arrayLengthofConstraint.write(writer)
    def _checkValueConsumerCreator(self, defaultValue, externalValue):
        valueConsumerCreator = self._createValueConsumerCreator(
            defaultValue, externalValue)
        self.assertEqual(self._calculateValue(defaultValue, externalValue),
                         valueConsumerCreator.getValueCalculator().funcValue())

        writer = zserio.BitStreamWriter()
        valueConsumerCreator.write(writer)
        expectedWriter = zserio.BitStreamWriter()
        self._writeValueConsumerCreatorToStream(expectedWriter, defaultValue,
                                                externalValue)
        self.assertTrue(expectedWriter.getByteArray() == writer.getByteArray())

        reader = zserio.BitStreamReader(writer.getByteArray())
        readValueConsumerCreator = self.api.ValueConsumerCreator.fromReader(
            reader)
        self.assertEqual(valueConsumerCreator, readValueConsumerCreator)
Beispiel #27
0
 def testReadWrongOffsets(self):
     writeWrongOffsets = True
     writer = zserio.BitStreamWriter()
     self._writeBitOffsetToStream(writer, writeWrongOffsets)
     reader = zserio.BitStreamReader(writer.getByteArray())
     with self.assertRaises(zserio.PythonRuntimeException):
         bitOffset = self.api.BitOffset.fromReader(reader)
         self._checkBitOffset(bitOffset)
Beispiel #28
0
 def testWriteWrongOffsets(self):
     createWrongOffsets = True
     autoIndexedOffsetArray = self._createAutoIndexedOffsetArray(
         createWrongOffsets)
     writer = zserio.BitStreamWriter()
     with self.assertRaises(zserio.PythonRuntimeException):
         autoIndexedOffsetArray.write(writer,
                                      zserio_call_initialize_offsets=False)
Beispiel #29
0
 def testFromReader(self):
     writer = zserio.BitStreamWriter()
     writer.writeBits(self.api.DarkColor.DARK_BLACK.value,
                      DARK_COLOR_BITSIZEOF)
     byteArray = writer.getByteArray()
     reader = zserio.BitStreamReader(byteArray)
     color = self.api.DarkColor.fromReader(reader)
     self.assertEqual(DARK_BLACK_VALUE, color.value)
Beispiel #30
0
 def testWriteWithPosition(self):
     createWrongOffset = True
     school = self._createSchool(createWrongOffset)
     writer = zserio.BitStreamWriter()
     bitPosition = 2
     writer.write_bits(0, bitPosition)
     school.write(writer)
     self._checkSchool(school, bitPosition)