Beispiel #1
0
def test_add_messages_set_rcv_error_to_true_if_message_is_corrupted():
    # Given
    nb_packet = 2
    total_bytes = 50
    pixel_size = 3
    creation = 1000
    height = 10
    length = 10
    vt = VideoTopic(nb_packet=nb_packet, total_bytes=total_bytes, height=height, length=length, pixel_size=pixel_size,
                    time_creation=creation)
    test_msg = UDPMessage()
    test_msg.crc = list(test_msg.crc)
    test_msg.crc[0] += 1
    test_msg.crc = bytes(test_msg.crc)

    # When
    vt.add_message(test_msg)

    # Then
    assert vt.rcv_error is True
Beispiel #2
0
def test_from_bytes_returns_none_if_message_is_corrupted():
    # Given
    message_nb = bytes([2, 0])
    payload = bytes([49, 49, 49, 49])
    msg_id = bytes([48, 48, 48, 48])
    topic = bytes([1, 0, 0, 0])

    # When
    msg = UDPMessage(subtopic=message_nb,
                     payload=payload,
                     code=msg_id,
                     topic=topic)
    msg.crc = bytes()
    result = UDPMessage.from_bytes(msg.to_bytes())

    # Then
    assert result is None