|
| 1 | +import fastdds |
| 2 | +import pytest |
| 3 | +import sys |
| 4 | + |
| 5 | + |
| 6 | +def test_create_instance_handle_from_bytes(): |
| 7 | + ih = fastdds.InstanceHandle_t() |
| 8 | + ih.value = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" |
| 9 | + assert (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) == ih.value |
| 10 | + |
| 11 | + |
| 12 | +def test_create_instance_handle_from_bytearray(): |
| 13 | + ih = fastdds.InstanceHandle_t() |
| 14 | + ih.value = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]) |
| 15 | + assert (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) == ih.value |
| 16 | + |
| 17 | + |
| 18 | +def test_create_instance_handle_from_tuple(): |
| 19 | + ih = fastdds.InstanceHandle_t() |
| 20 | + ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) |
| 21 | + assert (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) == ih.value |
| 22 | + |
| 23 | + |
| 24 | +def test_create_instance_handle_from_list(): |
| 25 | + ih = fastdds.InstanceHandle_t() |
| 26 | + ih.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16] |
| 27 | + assert (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16) == ih.value |
| 28 | + |
| 29 | + |
| 30 | +def test_create_instance_handle_from_bytes_with_less_elements(): |
| 31 | + ih = fastdds.InstanceHandle_t() |
| 32 | + with pytest.raises(SystemError) as exception: |
| 33 | + ih.value = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e" |
| 34 | + repr = exception.getrepr() |
| 35 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 bytes" |
| 36 | + |
| 37 | + |
| 38 | +def test_create_instance_handle_from_bytes_with_more_elements(): |
| 39 | + ih = fastdds.InstanceHandle_t() |
| 40 | + with pytest.raises(SystemError) as exception: |
| 41 | + ih.value = ( |
| 42 | + b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12" |
| 43 | + ) |
| 44 | + repr = exception.getrepr() |
| 45 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 bytes" |
| 46 | + |
| 47 | + |
| 48 | +def test_create_instance_handle_from_bytearray_with_less_elements(): |
| 49 | + ih = fastdds.InstanceHandle_t() |
| 50 | + with pytest.raises(SystemError) as exception: |
| 51 | + ih.value = bytearray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) |
| 52 | + repr = exception.getrepr() |
| 53 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 bytes" |
| 54 | + |
| 55 | + |
| 56 | +def test_create_instance_handle_from_bytearray_with_more_elements(): |
| 57 | + ih = fastdds.InstanceHandle_t() |
| 58 | + with pytest.raises(SystemError) as exception: |
| 59 | + ih.value = bytearray( |
| 60 | + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] |
| 61 | + ) |
| 62 | + repr = exception.getrepr() |
| 63 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 bytes" |
| 64 | + |
| 65 | + |
| 66 | +def test_create_instance_handle_from_tuple_with_less_elements(): |
| 67 | + ih = fastdds.InstanceHandle_t() |
| 68 | + with pytest.raises(SystemError) as exception: |
| 69 | + ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14) |
| 70 | + repr = exception.getrepr() |
| 71 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 elements" |
| 72 | + |
| 73 | + |
| 74 | +def test_create_instance_handle_from_tuple_with_more_elements(): |
| 75 | + ih = fastdds.InstanceHandle_t() |
| 76 | + with pytest.raises(SystemError) as exception: |
| 77 | + ih.value = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18) |
| 78 | + repr = exception.getrepr() |
| 79 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 elements" |
| 80 | + |
| 81 | + |
| 82 | +def test_create_instance_handle_from_list_with_less_elements(): |
| 83 | + ih = fastdds.InstanceHandle_t() |
| 84 | + with pytest.raises(SystemError) as exception: |
| 85 | + ih.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] |
| 86 | + repr = exception.getrepr() |
| 87 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 elements" |
| 88 | + |
| 89 | + |
| 90 | +def test_create_instance_handle_from_list_with_more_elements(): |
| 91 | + ih = fastdds.InstanceHandle_t() |
| 92 | + with pytest.raises(SystemError) as exception: |
| 93 | + ih.value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18] |
| 94 | + repr = exception.getrepr() |
| 95 | + assert str(repr).split("\n")[0] == "ValueError: Expected 16 elements" |
0 commit comments