blob: e97f1d07d0dedb869a27201a2d2e8a7dfcc3e5cf [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
success("UnionWithBoundString") {
value = UnionWithBoundStringStruct {
v: UnionWithBoundString {
boundFiveStr: "abcd",
},
},
bytes = {
v1 = [
// primary object
num(1):8, // ordinal
num(24):4, num(0):4, repeat(0xff):8, // envelope
// secondary object 1: union
num(4):8, repeat(0xff):8, // boundFiveStr size, present
// secondary object 2: boundFiveStr
'a', 'b', 'c', 'd', padding:4,
],
},
}
encode_failure("UnionWithBoundString_ExceedsBounds") {
// TODO(fxbug.dev/37304) Enforce size bounds in rust
bindings_denylist = [rust, dart],
value = UnionWithBoundStringStruct {
v: UnionWithBoundString {
boundFiveStr: "abcdef",
},
},
err = STRING_TOO_LONG,
}
success("UnionMigration_SingleVariant") {
value = SingleVariantUnionStruct {
u: SingleVariantUnion {
x: 42,
},
},
bytes = {
v1 = [
// primary object
num(1):8, // ordinal
num(8):4, num(0):4, repeat(0xff):8, // envelope
// secondary object 1: x
num(42):4, padding:4,
],
},
}
success("ReverseOrdinalUnion") {
value = ReverseOrdinalUnionStruct {
u: ReverseOrdinalUnion {
x: 42,
},
},
bytes = {
v1 = [
// primary object
num(4):8, // ordinal
num(8):4, num(0):4, repeat(0xff):8, // envelope
// secondary object 1: x
num(42):8,
],
},
}
// ======================== UNKNOWN VARIANT TESTS ==========================
success("FlexibleUnionUnknownValue") {
// llcpp is tested by hand since it cannot construct unknown unions (and
// they do not store bytes & handles), see fxr/423117
bindings_denylist = [llcpp],
value = TestFlexibleXUnionInStruct {
xu: SampleXUnion{
1234: {
// padding must be included in the raw bytes
bytes = [repeat(0xab):20, padding:4],
},
},
},
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(0):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
}
success("FlexibleResourceUnionUnknownValue") {
// llcpp is tested by hand since it cannot construct unknown unions (and
// they do not store bytes & handles), see fxr/423117
// TODO(fxbug.dev/64141): re-enable for Go
bindings_denylist = [llcpp],
value = TestFlexibleResourceXUnionInStruct {
xu: SampleResourceXUnion{
1234: {
// padding must be included in the raw bytes
bytes = [repeat(0xab):20, padding:4],
},
},
},
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(0):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
}
success("FlexibleResourceUnionUnknownValueWithHandles") {
// llcpp is tested by hand since it cannot construct unknown unions (and
// they do not store bytes & handles), see fxr/423117
bindings_denylist = [llcpp],
handle_defs = {
#0 = event(),
#1 = event(),
#2 = channel(),
#3 = channel(),
},
value = TestFlexibleResourceXUnionInStruct {
xu: SampleResourceXUnion {
1234: {
// padding must be included in the raw bytes
bytes = [repeat(0xab):20, padding:4],
handles = [#0, #1, #2, #3],
},
},
},
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(4):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
handles = {
v1 = [
#0, #1, #2, #3,
]
}
}
decode_failure("StrictUnionUnknownValue") {
type = TestStrictXUnionInStruct,
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(0):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
err = STRICT_UNION_UNKNOWN_FIELD,
}
decode_failure("StrictUnionUnknownValueWithHandles") {
handle_defs = {
#0 = event(),
#1 = event(),
#2 = channel(),
#3 = channel(),
},
type = TestStrictXUnionInStruct,
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(4):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
handles = {
v1 = [
#0, #1, #2, #3,
]
},
err = STRICT_UNION_UNKNOWN_FIELD,
}
decode_failure("FlexibleUnionUnknownValueWithHandles") {
// LLCPP does not store handles, so does not fail when decoding unknown
// handles for a value type.
bindings_denylist = [llcpp],
handle_defs = {
#0 = event(),
#1 = event(),
#2 = channel(),
#3 = channel(),
},
type = TestFlexibleXUnionInStruct,
bytes = {
v1 = [
num(1234):8, // unknown ordinal
num(24):4, num(4):4, repeat(0xff):8, // envelope
repeat(0xab):20, padding:4, // unknown bytes
],
},
handles = {
v1 = [
#0, #1, #2, #3,
]
},
err = NON_RESOURCE_UNKNOWN_HANDLES,
}
encode_failure("StrictUnionUnknownValue") {
// Currently no bindings allow constructing a strict union with an unknown variant
bindings_allowlist = [],
value = TestStrictXUnionInStruct {
xu: SampleStrictXUnion{
1234: {
// padding must be included in the raw bytes
bytes = [repeat(0xab):20, padding:4],
}
}
},
err = STRICT_UNION_UNKNOWN_FIELD,
}