blob: d31757ead227602143aecdd2be4e979358065724 [file] [log] [blame]
#![cfg(test)]
#![allow(unused_imports)]
#![allow(invalid_from_utf8)]
use {
assert_matches::assert_matches,
fidl::{AsHandleRef, Handle, HandleDisposition, HandleInfo, HandleOp, ObjectType, Rights},
fidl::encoding::{Context, Decode, Decoder, Encoder, WireFormatVersion},
fidl_codec::{Value, Error},
fuchsia_zircon_status::Status,
fuchsia_zircon_types as zx_types,
gidl_util::{
HandleDef, HandleSubtype, copy_handle, create_handles, decode_value,
get_handle_koid, get_info_handle_valid, repeat, select_handle_infos,
select_raw_handle_infos, to_zx_handle_t, to_zx_handle_disposition_t,
},
};
fn ns() -> &'static fidl_codec::library::Namespace {
static FIDL_JSON: &str = include_str!(env!("CONFORMANCE_JSON_PATH"));
static NS: std::sync::OnceLock<fidl_codec::library::Namespace> = std::sync::OnceLock::new();
NS.get_or_init(|| {
let mut ns = fidl_codec::library::Namespace::new();
ns.load(FIDL_JSON).unwrap();
ns
})
}
#[test]
fn test_golden_bool_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenBoolStruct", false, Value::Object(vec![("v".to_owned(), Value::Bool(true))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_int_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenIntStruct", false, Value::Object(vec![("v".to_owned(), Value::I16(1i16))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_uint_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenUintStruct", false, Value::Object(vec![("v".to_owned(), Value::U16(1u16))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_float_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenFloatStruct", false, Value::Object(vec![("v".to_owned(), Value::F32(0f32))])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_double_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenDoubleStruct", false, Value::Object(vec![("v".to_owned(), Value::F64(0f64))])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_string_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenStringStruct", false, Value::Object(vec![("v".to_owned(), Value::String(String::from("abcd")))])).unwrap();
assert_eq!(bytes, &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_string_struct_non_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableStringStruct", false, Value::Object(vec![("v".to_owned(), Value::String(String::from("abcd")))])).unwrap();
assert_eq!(bytes, &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_string_struct_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableStringStruct", false, Value::Object(vec![("v".to_owned(), Value::Null)])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_enum_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenEnumStruct", false, Value::Object(vec![("v".to_owned(), Value::Enum("test.conformance/GoldenEnum".to_owned(), Box::new(Value::U16(1u16))))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_bits_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenBitsStruct", false, Value::Object(vec![("v".to_owned(), Value::Bits("test.conformance/GoldenBits".to_owned(), Box::new(Value::U16(1u16))))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_table_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenTableStruct", false, Value::Object(vec![("v".to_owned(), Value::Object(vec![("v".to_owned(), Value::I16(1i16))]))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_union_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenUnionStruct", false, Value::Object(vec![("v".to_owned(), Value::Union("test.conformance/GoldenUnion".to_owned(), "v".to_owned(), Box::new(Value::I16(1i16))))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_union_struct_non_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableUnionStruct", false, Value::Object(vec![("v".to_owned(), Value::Union("test.conformance/GoldenUnion".to_owned(), "v".to_owned(), Box::new(Value::I16(1i16))))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_union_struct_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableUnionStruct", false, Value::Object(vec![("v".to_owned(), Value::Null)])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_byte_array_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenByteArrayStruct", false, Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))])).unwrap();
assert_eq!(bytes, &[
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_struct_array_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenStructArrayStruct", false, Value::Object(vec![("v".to_owned(), Value::List(vec![Value::Object(vec![("v".to_owned(), Value::I16(1i16))]), Value::Object(vec![("v".to_owned(), Value::I16(2i16))])]))])).unwrap();
assert_eq!(bytes, &[
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_byte_vector_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenByteVectorStruct", false, Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8), Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8), Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))])).unwrap();
assert_eq!(bytes, &[
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,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_byte_nullable_vector_struct_non_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableByteVectorStruct", false, Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))])).unwrap();
assert_eq!(bytes, &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_byte_vector_struct_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableByteVectorStruct", false, Value::Object(vec![("v".to_owned(), Value::Null)])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_struct_vector_struct_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenStructVectorStruct", false, Value::Object(vec![("v".to_owned(), Value::List(vec![Value::Object(vec![("v".to_owned(), Value::I16(1i16))]), Value::Object(vec![("v".to_owned(), Value::I16(2i16))])]))])).unwrap();
assert_eq!(bytes, &[
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_struct_non_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableStruct", false, Value::Object(vec![("v".to_owned(), Value::Object(vec![("v".to_owned(), Value::Bool(true))]))])).unwrap();
assert_eq!(bytes, &[
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_nullable_struct_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableStruct", false, Value::Object(vec![("v".to_owned(), Value::Null)])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_handle_basic_rights_struct_v2_encode() {
let handle_defs = create_handles(&[
// #0
HandleDef{
subtype: HandleSubtype::Channel,
rights: Rights::from_bits(61454).unwrap(),
},
]);
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenHandleBasicRightsStruct", false, Value::Object(vec![("v".to_owned(), Value::Handle(copy_handle(&handle_defs[0]), fidl::ObjectType::EVENT))])).unwrap();
assert_eq!(bytes, &[
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
]);
assert_eq!(
handle_dispositions.iter().map(to_zx_handle_disposition_t).collect::<Vec<_>>(),
&[
zx_types::zx_handle_disposition_t {
operation: zx_types::ZX_HANDLE_OP_MOVE,
handle: handle_defs[0].handle,
type_: 5,
rights: 49155,
result: zx_types::ZX_OK,
},]
);
}
#[test]
fn test_golden_nullable_handle_struct_non_null_v2_encode() {
let handle_defs = create_handles(&[
// #0
HandleDef{
subtype: HandleSubtype::Event,
rights: Rights::from_bits(2147483648).unwrap(),
},
]);
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableHandleStruct", false, Value::Object(vec![("v".to_owned(), Value::Handle(copy_handle(&handle_defs[0]), fidl::ObjectType::NONE))])).unwrap();
assert_eq!(bytes, &[
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
]);
assert_eq!(
handle_dispositions.iter().map(to_zx_handle_t).collect::<Vec<_>>(),
&[handle_defs[0].handle,
]
);
}
#[test]
fn test_golden_nullable_handle_struct_null_v2_encode() {
let (bytes, handle_dispositions) = fidl_codec::encode(ns(), "test.conformance/GoldenNullableHandleStruct", false, Value::Object(vec![("v".to_owned(), Value::Null)])).unwrap();
assert_eq!(bytes, &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
]);
assert_eq!(handle_dispositions, &[]);
}
#[test]
fn test_golden_bool_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Bool(true))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenBoolStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_int_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::I16(1i16))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenIntStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_uint_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::U16(1u16))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenUintStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_float_struct_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::F32(0f32))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenFloatStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_double_struct_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::F64(0f64))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenDoubleStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_string_struct_v2_decode() {
let bytes = &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::String(String::from("abcd")))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenStringStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_string_struct_non_null_v2_decode() {
let bytes = &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x61,0x62,0x63,0x64,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::String(String::from("abcd")))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableStringStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_string_struct_null_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Null)]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableStringStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_enum_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Enum("test.conformance/GoldenEnum".to_owned(), Box::new(Value::U16(1u16))))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenEnumStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_bits_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Bits("test.conformance/GoldenBits".to_owned(), Box::new(Value::U16(1u16))))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenBitsStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_table_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Object(vec![("v".to_owned(), Value::I16(1i16))]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenTableStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_union_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Union("test.conformance/GoldenUnion".to_owned(), "v".to_owned(), Box::new(Value::I16(1i16))))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenUnionStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_union_struct_non_null_v2_decode() {
let bytes = &[
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x01,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Union("test.conformance/GoldenUnion".to_owned(), "v".to_owned(), Box::new(Value::I16(1i16))))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableUnionStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_union_struct_null_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Null)]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableUnionStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_byte_array_struct_v2_decode() {
let bytes = &[
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenByteArrayStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_struct_array_struct_v2_decode() {
let bytes = &[
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::List(vec![Value::Object(vec![("v".to_owned(), Value::I16(1i16))]), Value::Object(vec![("v".to_owned(), Value::I16(2i16))])]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenStructArrayStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_byte_vector_struct_v2_decode() {
let bytes = &[
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,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8), Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8), Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenByteVectorStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_byte_nullable_vector_struct_non_null_v2_decode() {
let bytes = &[
0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x02,0x03,0x04,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::List(vec![Value::U8(1u8), Value::U8(2u8), Value::U8(3u8), Value::U8(4u8)]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableByteVectorStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_byte_vector_struct_null_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Null)]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableByteVectorStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_struct_vector_struct_v2_decode() {
let bytes = &[
0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x02,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::List(vec![Value::Object(vec![("v".to_owned(), Value::I16(1i16))]), Value::Object(vec![("v".to_owned(), Value::I16(2i16))])]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenStructVectorStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_struct_non_null_v2_decode() {
let bytes = &[
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Object(vec![("v".to_owned(), Value::Bool(true))]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_struct_null_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Null)]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_handle_basic_rights_struct_v2_decode() {
let bytes = &[
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
];
let handle_defs = create_handles(&[
// #0
HandleDef{
subtype: HandleSubtype::Event,
rights: Rights::from_bits(53251).unwrap(),
},
]);
let _handle_koids = handle_defs.iter().map(get_handle_koid).collect::<Vec<_>>();
let handle_infos = select_handle_infos(&handle_defs, &[
0,]);
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Handle(copy_handle(&handle_defs[0]), fidl::ObjectType::EVENT))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenHandleBasicRightsStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_handle_struct_non_null_v2_decode() {
let bytes = &[
0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
];
let handle_defs = create_handles(&[
// #0
HandleDef{
subtype: HandleSubtype::Event,
rights: Rights::from_bits(2147483648).unwrap(),
},
]);
let _handle_koids = handle_defs.iter().map(get_handle_koid).collect::<Vec<_>>();
let handle_infos = select_handle_infos(&handle_defs, &[
0,]);
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Handle(copy_handle(&handle_defs[0]), fidl::ObjectType::NONE))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableHandleStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_nullable_handle_struct_null_v2_decode() {
let bytes = &[
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Null)]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenNullableHandleStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
}
#[test]
fn test_golden_table_unknown_dropped_v2_decode() {
let bytes = &[
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,
];
let handle_defs = create_handles(&[
// #0
HandleDef{
subtype: HandleSubtype::Event,
rights: Rights::from_bits(2147483648).unwrap(),
},
]);
let _handle_koids = handle_defs.iter().map(get_handle_koid).collect::<Vec<_>>();
let handle_infos = select_handle_infos(&handle_defs, &[
0,]);
let confirm_value = Value::Object(vec![("v".to_owned(), Value::Object(vec![]))]);
let value = fidl_codec::decode(ns(), "test.conformance/GoldenTableStruct", bytes, handle_infos).unwrap();
assert_eq!(value, confirm_value);
let unused_handles = select_raw_handle_infos(&handle_defs, &[
0,]);
assert_eq!(
unused_handles.iter().map(get_info_handle_valid).collect::<Vec<_>>(),
repeat(Err(Status::BAD_HANDLE), unused_handles.len()),
);
}
#[test]
fn test_golden_string_with_max_size2_v2_encode_failure() {
match fidl_codec::encode(ns(), "test.conformance/GoldenStringWithMaxSize2", false, Value::Object(vec![("s".to_owned(), Value::String(String::from("abc")))])) {
// TODO: Assert the specific error once the enum variants are more specific
Err(err) => assert_matches!(err, Error::EncodeError(_)|Error::RecursionLimitExceeded),
Ok(_) => panic!("unexpected successful encoding"),
}
}
#[test]
fn test_golden_string_struct_null_body_v2_decode_failure() {
let bytes = &[
0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
];
let handle_infos = Vec::new();
match fidl_codec::decode(ns(), "test.conformance/GoldenStringStruct", bytes, handle_infos) {
// TODO: Assert the specific error once the enum variants are more specific
Err(err) => assert_matches!(err, Error::DecodeError(_)|Error::Utf8Error(_)|Error::RecursionLimitExceeded),
Ok(_) => panic!("unexpected successful decoding"),
}
}