| // Copyright 2021 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. |
| |
| // This file defines GIDL tests used for GIDL golden generation. |
| // The output of the golden test can be used to understand the differences |
| // due to a change in GIDL and track regressions. |
| |
| // While these tests are compiled and run just like the other *.gidl files, |
| // the primary purpose of this file is NOT testing binding correctness. |
| |
| // Simple primitive types. |
| success("GoldenBoolStruct") { |
| value = GoldenBoolStruct { |
| v: true, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):1, padding:7, |
| ], |
| }, |
| } |
| success("GoldenIntStruct") { |
| value = GoldenIntStruct { |
| v: 1, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):2, padding:6, |
| ], |
| }, |
| } |
| success("GoldenUintStruct") { |
| value = GoldenUintStruct { |
| v: 1, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):2, padding:6, |
| ], |
| }, |
| } |
| success("GoldenFloatStruct") { |
| value = GoldenFloatStruct { |
| v: 0.0, |
| }, |
| bytes = { |
| v1 = [ |
| num(0):4, padding:4, |
| ], |
| }, |
| } |
| success("GoldenDoubleStruct") { |
| value = GoldenDoubleStruct { |
| v: 0.0, |
| }, |
| bytes = { |
| v1 = [ |
| num(0):8 |
| ], |
| }, |
| } |
| success("GoldenStringStruct") { |
| value = GoldenStringStruct { |
| v: "abcd", |
| }, |
| bytes = { |
| v1 = [ |
| num(4):8, |
| repeat(0xff):8, |
| 0x61, 0x62, 0x63, 0x64, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableStringStructNonNull") { |
| value = GoldenNullableStringStruct { |
| v: "abcd", |
| }, |
| bytes = { |
| v1 = [ |
| num(4):8, |
| repeat(0xff):8, |
| 0x61, 0x62, 0x63, 0x64, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableStringStructNull") { |
| value = GoldenNullableStringStruct { |
| v: null, |
| }, |
| bytes = { |
| v1 = [ |
| num(0):8, |
| repeat(0x00):8, |
| ], |
| }, |
| } |
| success("GoldenEnumStruct") { |
| value = GoldenEnumStruct { |
| v: 1, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):2, padding:6, |
| ], |
| }, |
| } |
| success("GoldenBitsStruct") { |
| value = GoldenBitsStruct { |
| v: 1, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):2, padding:6, |
| ], |
| }, |
| } |
| success("GoldenTableStruct") { |
| value = GoldenTableStruct { |
| v: GoldenTable{ |
| v: 1, |
| }, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):8, |
| repeat(0xff):8, |
| num(8):4, padding:4, |
| repeat(0xff):8, |
| num(1):4, padding:4, |
| ], |
| }, |
| } |
| success("GoldenUnionStruct") { |
| value = GoldenUnionStruct { |
| v: GoldenUnion{ |
| v: 1, |
| }, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):8, |
| num(8):4, padding:4, |
| repeat(0xff):8, |
| num(1):4, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableUnionStructNonNull") { |
| value = GoldenNullableUnionStruct { |
| v: GoldenUnion{ |
| v: 1, |
| }, |
| }, |
| bytes = { |
| v1 = [ |
| num(1):8, |
| num(8):4, padding:4, |
| repeat(0xff):8, |
| num(1):4, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableUnionStructNull") { |
| value = GoldenNullableUnionStruct { |
| v: null, |
| }, |
| bytes = { |
| v1 = [ |
| num(0):8, |
| padding:8, |
| repeat(0x00):8, |
| ], |
| }, |
| } |
| success("GoldenByteArrayStruct") { |
| value = GoldenByteArrayStruct { |
| v: [1, 2, 3, 4], |
| }, |
| bytes = { |
| v1 = [ |
| 0x01, 0x02, 0x03, 0x04, padding:4, |
| ], |
| }, |
| } |
| // Sometimes GIDL generators might have different behavior for non-byte |
| // or primitive arrays. |
| success("GoldenStructArrayStruct") { |
| value = GoldenStructArrayStruct { |
| v: [ |
| GoldenIntStruct{v: 1}, |
| GoldenIntStruct{v: 2}, |
| ], |
| }, |
| bytes = { |
| v1 = [ |
| 0x01, 0x00, 0x02, 0x00, padding:4, |
| ], |
| }, |
| } |
| success("GoldenByteVectorStruct") { |
| value = GoldenByteVectorStruct { |
| v: [1, 2, 3, 4], |
| }, |
| bytes = { |
| v1 = [ |
| num(4):8, |
| repeat(0xff):8, |
| 0x01, 0x02, 0x03, 0x04, padding:4, |
| ], |
| }, |
| } |
| success("GoldenByteNullableVectorStructNonNull") { |
| // TODO(fxbug.dev/73159) Remove the denylist |
| bindings_denylist = [llcpp,rust,hlcpp], |
| value = GoldenNullableByteVectorStruct { |
| v: [1, 2, 3, 4], |
| }, |
| bytes = { |
| v1 = [ |
| num(4):8, |
| repeat(0xff):8, |
| 0x01, 0x02, 0x03, 0x04, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableByteVectorStructNull") { |
| // TODO(fxbug.dev/73159) Remove the denylist |
| bindings_denylist = [llcpp,rust,hlcpp], |
| value = GoldenNullableByteVectorStruct { |
| v: null, |
| }, |
| bytes = { |
| v1 = [ |
| num(0):8, |
| repeat(0x00):8, |
| ], |
| }, |
| } |
| // Sometimes GIDL generators might have different behavior for non-byte |
| // or primitive vectors. |
| success("GoldenStructVectorStruct") { |
| value = GoldenStructVectorStruct { |
| v: [ |
| GoldenIntStruct{v: 1}, |
| GoldenIntStruct{v: 2}, |
| ], |
| }, |
| bytes = { |
| v1 = [ |
| num(2):8, |
| repeat(0xff):8, |
| 0x01, 0x00, 0x02, 0x00, padding:4, |
| ], |
| }, |
| } |
| success("GoldenNullableStructNonNull") { |
| value = GoldenNullableStruct { |
| v: GoldenBoolStruct { |
| v: true, |
| }, |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0xff):8, |
| num(1):1, padding:7, |
| ], |
| }, |
| } |
| success("GoldenNullableStructNull") { |
| value = GoldenNullableStruct { |
| v: null, |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0x00):8, |
| ], |
| }, |
| } |
| encode_success("GoldenHandleBasicRightsStruct") { |
| bindings_allowlist = [llcpp, hlcpp, go], |
| handle_defs = { |
| #0 = channel(rights: channel_default), |
| }, |
| value = GoldenHandleBasicRightsStruct { |
| v: #0, |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0xff):4, padding:4, |
| ], |
| }, |
| handle_dispositions = { |
| v1 = [ |
| { #0, type: event, rights: basic }, |
| ], |
| } |
| } |
| decode_success("GoldenHandleBasicRightsStruct") { |
| bindings_allowlist = [llcpp, hlcpp, go], |
| handle_defs = { |
| #0 = event(rights: event_default), |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0xff):4, padding:4, |
| ], |
| }, |
| handles = { |
| v1 = [ |
| #0, |
| ], |
| }, |
| value = GoldenHandleBasicRightsStruct { |
| v: restrict(#0, rights: basic), |
| }, |
| } |
| success("GoldenNullableHandleStructNonNull") { |
| handle_defs = { |
| #0 = event(), |
| }, |
| value = GoldenNullableHandleStruct { |
| v: #0, |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0xff):4, padding:4, |
| ], |
| }, |
| handles = { |
| v1 = [ |
| #0, |
| ], |
| } |
| } |
| success("GoldenNullableHandleStructNull") { |
| value = GoldenNullableHandleStruct { |
| v: null, |
| }, |
| bytes = { |
| v1 = [ |
| repeat(0x00):4, padding:4, |
| ], |
| } |
| } |
| |
| encode_failure("GoldenStringWithMaxSize2") { |
| // TODO(fxbug.dev/37304) Enforce size bounds in rust |
| bindings_denylist = [rust, dart], |
| value = GoldenStringWithMaxSize2 { |
| s: "abc", // exceeds the string length |
| }, |
| err = STRING_TOO_LONG |
| } |
| |
| decode_failure("GoldenStringStructNullBody") { |
| type = GoldenStringStruct, |
| bytes = { |
| v1 = [ |
| 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // length of string data |
| 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // invalid null pointer to content |
| ], |
| }, |
| err = NON_EMPTY_STRING_WITH_NULL_BODY, |
| } |