コード例 #1
0
ファイル: test.py プロジェクト: Parrot-Developers/libpomp
    def testDecoderBase(self):
        # Allocate message, write reference payload
        msg = Message()
        msg.init(MSGID)
        msg.buf.skip(12)
        msg.buf.write(PAYLOAD)
        msg.finish()

        # Allocate and init decoder
        dec = Decoder()
        dec.init(msg)

        # Read
        try:
            i8 = dec.readI8()
            u8 = dec.readU8()
            i16 = dec.readI16()
            u16 = dec.readU16()
            i32 = dec.readI32()
            u32 = dec.readU32()
            i64 = dec.readI64()
            u64 = dec.readU64()
            sval = dec.readStr()
            buf = dec.readBuf()
            f32 = dec.readF32()
            f64 = dec.readF64()

            # Check
            self.assertEqual(VAL_I8, i8)
            self.assertEqual(VAL_U8, u8)
            self.assertEqual(VAL_I16, i16)
            self.assertEqual(VAL_U16, u16)
            self.assertEqual(VAL_I32, i32)
            self.assertEqual(VAL_U32, u32)
            self.assertEqual(VAL_I64, i64)
            self.assertEqual(VAL_U64, u64)
            self.assertEqual(VAL_STR, sval)
            self.assertEqual(len(VAL_BUF), len(buf))
            self.assertEqual(VAL_BUF, buf)
            self.assertEqual(VAL_F32, f32)
            self.assertEqual(VAL_F64, f64)
        except DecodeException as ex:
            self.fail(ex.message)

        # Clear
        dec.clear()
        msg.clear()
コード例 #2
0
ファイル: test.py プロジェクト: skyformat99/libpomp
    def testDecoderBase(self):
        # Allocate message, write reference payload
        msg = Message()
        msg.init(MSGID)
        msg.buf.skip(12)
        msg.buf.write(PAYLOAD)
        msg.finish()

        # Allocate and init decoder
        dec = Decoder()
        dec.init(msg)

        # Read
        try:
            i8 = dec.readI8()
            u8 = dec.readU8()
            i16 = dec.readI16()
            u16 = dec.readU16()
            i32 = dec.readI32()
            u32 = dec.readU32()
            i64 = dec.readI64()
            u64 = dec.readU64()
            sval = dec.readStr()
            buf = dec.readBuf()
            f32 = dec.readF32()
            f64 = dec.readF64()

            # Check
            self.assertEqual(VAL_I8, i8)
            self.assertEqual(VAL_U8, u8)
            self.assertEqual(VAL_I16, i16)
            self.assertEqual(VAL_U16, u16)
            self.assertEqual(VAL_I32, i32)
            self.assertEqual(VAL_U32, u32)
            self.assertEqual(VAL_I64, i64)
            self.assertEqual(VAL_U64, u64)
            self.assertEqual(VAL_STR, sval)
            self.assertEqual(len(VAL_BUF), len(buf))
            self.assertEqual(VAL_BUF, buf)
            self.assertEqual(VAL_F32, f32)
            self.assertEqual(VAL_F64, f64)
        except DecodeException as ex:
            self.fail(ex.message)

        # Clear
        dec.clear()
        msg.clear()
コード例 #3
0
ファイル: test.py プロジェクト: Parrot-Developers/libpomp
    def testEncoderBase(self):
        # Allocate message */
        msg = Message()
        msg.init(MSGID)

        # Allocate and init encoder
        enc = Encoder()
        enc.init(msg)

        # Write
        try:
            enc.writeI8(VAL_I8)
            enc.writeU8(VAL_U8)
            enc.writeI16(VAL_I16)
            enc.writeU16(VAL_U16)
            enc.writeI32(VAL_I32)
            enc.writeU32(VAL_U32)
            enc.writeI64(VAL_I64)
            enc.writeU64(VAL_U64)
            enc.writeStr(VAL_STR)
            enc.writeBuf(VAL_BUF)
            enc.writeF32(VAL_F32)
            enc.writeF64(VAL_F64)
        except EncodeException as ex:
            self.fail(ex.message)

        msg.finish()

        # Buffer check
        data = msg.buf.getData()
        header = data[:12]
        payload = data[12:]
        self.assertEqual(len(HEADER), len(header))
        self.assertEqual(len(PAYLOAD), len(payload))
        self.assertEqual(HEADER, header)
        self.assertEqual(PAYLOAD, payload)

        # Clear
        enc.clear()
        msg.clear()
コード例 #4
0
ファイル: test.py プロジェクト: skyformat99/libpomp
    def testEncoderBase(self):
        # Allocate message */
        msg = Message()
        msg.init(MSGID)

        # Allocate and init encoder
        enc = Encoder()
        enc.init(msg)

        # Write
        try:
            enc.writeI8(VAL_I8)
            enc.writeU8(VAL_U8)
            enc.writeI16(VAL_I16)
            enc.writeU16(VAL_U16)
            enc.writeI32(VAL_I32)
            enc.writeU32(VAL_U32)
            enc.writeI64(VAL_I64)
            enc.writeU64(VAL_U64)
            enc.writeStr(VAL_STR)
            enc.writeBuf(VAL_BUF)
            enc.writeF32(VAL_F32)
            enc.writeF64(VAL_F64)
        except EncodeException as ex:
            self.fail(ex.message)

        msg.finish()

        # Buffer check
        data = msg.buf.getData()
        header = data[:12]
        payload = data[12:]
        self.assertEqual(len(HEADER), len(header))
        self.assertEqual(len(PAYLOAD), len(payload))
        self.assertEqual(HEADER, header)
        self.assertEqual(PAYLOAD, payload)

        # Clear
        enc.clear()
        msg.clear()