Пример #1
0
    def test_ads_notification_stream(self):
        dt = datetime.datetime(2017, 9, 1, 10, 10, 10)
        filetime = dt_to_filetime(dt)

        stream = structs.AdsNotificationStream([
            structs.AdsStampHeader(
                timestamp=filetime,
                samples=[
                    structs.AdsNotificationSample(
                        handle=1,
                        sample_size=ctypes.sizeof(pyads.PLCTYPE_INT),
                        data=struct.pack("<H", 12),
                    )
                ],
            )
        ])

        self.assertEqual(
            b"\x16\x00\x00\x00"  # length
            b"\x01\x00\x00\x00"  # stamp count
            b"\x00\xadT~\n#\xd3\x01"  # stamp timestamp
            b"\x01\x00\x00\x00"  # stamp sample count
            b"\x01\x00\x00\x00"  # sample handle
            b"\x02\x00\x00\x00"  # sample sample_size
            b"\x0C\x00",  # sample data
            stream.to_bytes(),
        )

        self.assertEqual(stream.length, 30)
    def test_ads_notification_sample(self):
        sample = structs.AdsNotificationSample(handle=1,
                                               sample_size=ctypes.sizeof(
                                                   pyads.PLCTYPE_INT),
                                               data=struct.pack('<H', 12))

        self.assertEqual(
            b'\x01\x00\x00\x00'  # handle
            b'\x02\x00\x00\x00'  # sample_size
            b'\x0C\x00',  # data
            sample.to_bytes())

        self.assertEqual(sample.length, 10)
    def test_ads_stamp_header(self):
        dt = datetime.datetime(2017, 9, 1, 10, 10, 10)
        filetime = dt_to_filetime(dt)
        stamp_header = structs.AdsStampHeader(
            timestamp=filetime,
            samples=[
                structs.AdsNotificationSample(handle=1,
                                              sample_size=ctypes.sizeof(
                                                  pyads.PLCTYPE_INT),
                                              data=struct.pack('<H', 12))
            ])

        self.assertEqual(
            b'\x00\xadT~\n#\xd3\x01'  # timestamp
            b'\x01\x00\x00\x00'  # sample count
            b'\x01\x00\x00\x00'  # sample handle
            b'\x02\x00\x00\x00'  # sample sample_size
            b'\x0C\x00',  # sample data
            stamp_header.to_bytes())

        self.assertEqual(stamp_header.length, 22)