def test_notification_decorator_struct(self): # type: () -> None """Test decoding of structure value by notification decorator""" @self.plc.notification(structs.SAdsVersion) def callback(handle, name, timestamp, value): self.assertEqual(value.version, 3) self.assertEqual(value.revision, 1) self.assertEqual(value.build, 3040) notification = create_notification_struct( bytes(structs.SAdsVersion(version=3, revision=1, build=3040))) callback(pointer(notification), "")
def test_notification_decorator_struct_array(self): # type: () -> None """Test decoding of array of structs value by notification decorator""" arr_type = structs.SAdsVersion * 4 @self.plc.notification(arr_type) def callback(handle, name, timestamp, value): self.assertEqual(len(value), 4) for i in range(4): self.assertEqual(value[i].version, i) self.assertEqual(value[i].revision, 1) self.assertEqual(value[i].build, 3040) data = b"" for i in range(4): data += bytes(structs.SAdsVersion(version=i, revision=1, build=3040)) notification = self.create_notification_struct(data) callback(pointer(notification), "")