blob: c5d2d51ff93b9708105c947a36e5eafedd8c75ff [file] [log] [blame]
import fuchsia_controller_py
from fuchsia_controller_py import BaseHandle, Channel, Event, Handle, Socket
import fidl_test_conformance as test_conformance
import struct
import unittest
from fidl import construct_response_object
from fidl_codec import decode_standalone
class EncodeConformanceTests(unittest.TestCase):
def test_golden_bool_struct_v2_encode(self) -> None:
value = test_conformance.GoldenBoolStruct(v=True)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_int_struct_v2_encode(self) -> None:
value = test_conformance.GoldenIntStruct(v=1)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_uint_struct_v2_encode(self) -> None:
value = test_conformance.GoldenUintStruct(v=1)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_float_struct_v2_encode(self) -> None:
value = test_conformance.GoldenFloatStruct(v=0)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_double_struct_v2_encode(self) -> None:
value = test_conformance.GoldenDoubleStruct(v=0)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_string_struct_v2_encode(self) -> None:
value = test_conformance.GoldenStringStruct(v="abcd")
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_string_struct_non_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableStringStruct(v="abcd")
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_string_struct_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableStringStruct(v=None)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_enum_struct_v2_encode(self) -> None:
value = test_conformance.GoldenEnumStruct(v=1)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_bits_struct_v2_encode(self) -> None:
value = test_conformance.GoldenBitsStruct(v=1)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_table_struct_v2_encode(self) -> None:
value = test_conformance.GoldenTableStruct(v=test_conformance.GoldenTable(v=1))
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_union_struct_v2_encode(self) -> None:
value = test_conformance.GoldenUnionStruct(v=test_conformance.GoldenUnion(v=1))
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_union_struct_non_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableUnionStruct(v=test_conformance.GoldenUnion(v=1))
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_union_struct_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableUnionStruct(v=None)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_byte_array_struct_v2_encode(self) -> None:
value = test_conformance.GoldenByteArrayStruct(v=[1, 2, 3, 4])
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_struct_array_struct_v2_encode(self) -> None:
value = test_conformance.GoldenStructArrayStruct(v=[test_conformance.GoldenIntStruct(v=1), test_conformance.GoldenIntStruct(v=2)])
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_byte_vector_struct_v2_encode(self) -> None:
value = test_conformance.GoldenByteVectorStruct(v=[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4])
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x01,0x02,0x03,0x04,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_byte_nullable_vector_struct_non_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableByteVectorStruct(v=[1, 2, 3, 4])
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_byte_vector_struct_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableByteVectorStruct(v=None)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_struct_vector_struct_v2_encode(self) -> None:
value = test_conformance.GoldenStructVectorStruct(v=[test_conformance.GoldenIntStruct(v=1), test_conformance.GoldenIntStruct(v=2)])
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_struct_non_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableStruct(v=test_conformance.GoldenBoolStruct(v=True))
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_nullable_struct_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableStruct(v=None)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
def test_golden_handle_basic_rights_struct_v2_encode(self) -> None:
handle_defs: list[BaseHandle] = [
fuchsia_controller_py.Channel.create()[0],
]
value = test_conformance.GoldenHandleBasicRightsStruct(v=handle_defs[0].as_int())
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [(0, handle_defs[0].as_int(), 5, 49155, 0),])
def test_golden_nullable_handle_struct_non_null_v2_encode(self) -> None:
handle_defs: list[BaseHandle] = [
fuchsia_controller_py.Event.create()[0],
]
value = test_conformance.GoldenNullableHandleStruct(v=handle_defs[0].as_int())
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
]))
handles = [handle_defs[i].as_int() for i in [0,]]
self.assertEqual([hdl[1] for hdl in hdls], handles)
def test_golden_nullable_handle_struct_null_v2_encode(self) -> None:
value = test_conformance.GoldenNullableHandleStruct(v=None)
encoded_bytes, hdls = value.encode()
self.assertEqual(encoded_bytes, bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]))
self.assertEqual(hdls, [])
class DecodeConformanceTests(unittest.TestCase):
def test_golden_bool_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenBoolStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenBoolStruct(v=True))
def test_golden_int_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenIntStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenIntStruct(v=1))
def test_golden_uint_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenUintStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenUintStruct(v=1))
def test_golden_float_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenFloatStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenFloatStruct(v=0))
def test_golden_double_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenDoubleStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenDoubleStruct(v=0))
def test_golden_string_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenStringStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenStringStruct(v="abcd"))
def test_golden_nullable_string_struct_non_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableStringStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableStringStruct(v="abcd"))
def test_golden_nullable_string_struct_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableStringStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableStringStruct(v=None))
def test_golden_enum_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenEnumStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenEnumStruct(v=1))
def test_golden_bits_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenBitsStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenBitsStruct(v=1))
def test_golden_table_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
])
type_name = "test.conformance/GoldenTableStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenTableStruct(v=test_conformance.GoldenTable(v=1)))
def test_golden_union_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
])
type_name = "test.conformance/GoldenUnionStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenUnionStruct(v=test_conformance.GoldenUnion(v=1)))
def test_golden_nullable_union_struct_non_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
])
type_name = "test.conformance/GoldenNullableUnionStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableUnionStruct(v=test_conformance.GoldenUnion(v=1)))
def test_golden_nullable_union_struct_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableUnionStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableUnionStruct(v=None))
def test_golden_byte_array_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenByteArrayStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenByteArrayStruct(v=[1, 2, 3, 4]))
def test_golden_struct_array_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenStructArrayStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenStructArrayStruct(v=[test_conformance.GoldenIntStruct(v=1), test_conformance.GoldenIntStruct(v=2)]))
def test_golden_byte_vector_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x0c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x01,0x02,0x03,0x04,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenByteVectorStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenByteVectorStruct(v=[1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]))
def test_golden_byte_nullable_vector_struct_non_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableByteVectorStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableByteVectorStruct(v=[1, 2, 3, 4]))
def test_golden_nullable_byte_vector_struct_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableByteVectorStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableByteVectorStruct(v=None))
def test_golden_struct_vector_struct_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenStructVectorStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenStructVectorStruct(v=[test_conformance.GoldenIntStruct(v=1), test_conformance.GoldenIntStruct(v=2)]))
def test_golden_nullable_struct_non_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableStruct(v=test_conformance.GoldenBoolStruct(v=True)))
def test_golden_nullable_struct_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableStruct(v=None))
def test_golden_handle_basic_rights_struct_v2_decode(self) -> None:
handle_defs: list[BaseHandle] = [
fuchsia_controller_py.Event.create()[0],
]
handles = [handle_defs[i].as_int() for i in [
0,]]
handle_koids = [h.koid() for h in handle_defs]
encoded_bytes = bytearray([
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenHandleBasicRightsStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(fuchsia_controller_py.Handle(value.v).koid(), handle_koids[0])
def test_golden_nullable_handle_struct_non_null_v2_decode(self) -> None:
handle_defs: list[BaseHandle] = [
fuchsia_controller_py.Event.create()[0],
]
handles = [handle_defs[i].as_int() for i in [
0,]]
handle_koids = [h.koid() for h in handle_defs]
encoded_bytes = bytearray([
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableHandleStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(fuchsia_controller_py.Handle(value.v).koid(), handle_koids[0])
def test_golden_nullable_handle_struct_null_v2_decode(self) -> None:
handles: list[int] = []
encoded_bytes = bytearray([
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
])
type_name = "test.conformance/GoldenNullableHandleStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenNullableHandleStruct(v=None))
def test_golden_table_unknown_dropped_v2_decode(self) -> None:
handle_defs: list[BaseHandle] = [
fuchsia_controller_py.Event.create()[0],
]
handles = [handle_defs[i].as_int() for i in [
0,]]
handle_koids = [h.koid() for h in handle_defs]
encoded_bytes = bytearray([
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0x01,0x00,0x01,0x00,
])
type_name = "test.conformance/GoldenTableStruct"
value = decode_standalone(type_name=type_name, bytes=encoded_bytes, handles=handles)
value = construct_response_object(type_name, value)
self.assertEqual(value, test_conformance.GoldenTableStruct(v=test_conformance.GoldenTable()))
if __name__ == "__main__":
unittest.main()