| // Copyright 2018 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. |
| // A set of structs and interface methods designed to exercise FIDL code. |
| // For now covering fidl_linearize. |
| |
| // TODO(https://fxbug.dev/42125015) Auto-generate extra_messages.h |
| |
| library fidl.test.coding; |
| |
| type IntStruct = struct { |
| v int64; |
| }; |
| |
| type SimpleTable = table { |
| 1: x IntStruct; |
| 5: y IntStruct; |
| }; |
| |
| type ResourceSimpleTable = resource table { |
| 1: x IntStruct; |
| 5: y IntStruct; |
| }; |
| |
| type OlderSimpleTable = table { |
| 1: x IntStruct; |
| }; |
| |
| type NewerSimpleTable = table { |
| 1: x IntStruct; |
| 5: y IntStruct; |
| 6: z IntStruct; |
| }; |
| |
| type SampleUnion = strict union { |
| 1: i IntStruct; |
| 2: st SimpleTable; |
| 3: raw_int int32; |
| }; |
| |
| type SampleXUnion = flexible union { |
| 1: i IntStruct; |
| 2: st SimpleTable; |
| 3: raw_int int32; |
| }; |
| |
| type SampleStrictXUnion = strict union { |
| 1: i IntStruct; |
| 2: st SimpleTable; |
| 3: raw_int int32; |
| }; |
| |
| type SampleStrictXUnionStruct = struct { |
| xu SampleStrictXUnion; |
| }; |
| |
| type SampleXUnionStruct = struct { |
| xu SampleXUnion; |
| }; |
| |
| type SampleNullableXUnionStruct = struct { |
| opt_xu SampleXUnion:optional; |
| }; |
| |
| type LLCPPStyleUnion = flexible union { |
| 1: primitive int32; |
| }; |
| |
| type LLCPPStyleUnionStruct = struct { |
| u LLCPPStyleUnion; |
| }; |
| |
| type Int16Bits = strict bits : uint16 { |
| BIT_1 = 1; |
| BIT_3 = 4; |
| BIT_5 = 16; |
| }; |
| |
| type Int16BitsStruct = struct { |
| bits Int16Bits; |
| }; |
| |
| type Int32Bits = strict bits : uint32 { |
| BIT_7 = 64; |
| BIT_12 = 2048; |
| BIT_27 = 67108864; |
| }; |
| |
| type Int32BitsStruct = struct { |
| bits Int32Bits; |
| }; |
| |
| // For the enum validation tests, we will define enums of all the possible |
| // underlying types, and for each of them, create three valid elements: |
| // - std::numeric_limits<UnderlyingType>::min() |
| // - std::numeric_limits<UnderlyingType>::max() |
| // - 42 |
| type Int8Enum = strict enum : int8 { |
| VALID_MIN = -128; |
| VALID_MAX = 127; |
| VALID_42 = 42; |
| }; |
| |
| type Int8EnumStruct = struct { |
| e Int8Enum; |
| }; |
| |
| type Uint8Enum = strict enum : uint8 { |
| VALID_MIN = 0; |
| VALID_MAX = 255; |
| VALID_42 = 42; |
| }; |
| |
| type Uint8EnumStruct = struct { |
| e Uint8Enum; |
| }; |
| |
| type Int16Enum = strict enum : int16 { |
| VALID_MIN = -32768; |
| VALID_MAX = 32767; |
| VALID_42 = 42; |
| }; |
| |
| type Int16EnumStruct = struct { |
| e Int16Enum; |
| }; |
| |
| type Uint16Enum = strict enum : uint16 { |
| VALID_MIN = 0; |
| VALID_MAX = 65535; |
| VALID_42 = 42; |
| }; |
| |
| type Uint16EnumStruct = struct { |
| e Uint16Enum; |
| }; |
| |
| type Int32Enum = strict enum : int32 { |
| VALID_MIN = -2147483648; |
| VALID_MAX = 2147483647; |
| VALID_42 = 42; |
| }; |
| |
| type Int32EnumStruct = struct { |
| e Int32Enum; |
| }; |
| |
| type Uint32Enum = strict enum : uint32 { |
| VALID_MIN = 0; |
| VALID_MAX = 4294967295; |
| VALID_42 = 42; |
| }; |
| |
| type Uint32EnumStruct = struct { |
| e Uint32Enum; |
| }; |
| |
| type Int64Enum = strict enum : int64 { |
| VALID_MIN = -9223372036854775808; |
| VALID_MAX = 9223372036854775807; |
| VALID_42 = 42; |
| }; |
| |
| type Int64EnumStruct = struct { |
| e Int64Enum; |
| }; |
| |
| type Uint64Enum = strict enum : uint64 { |
| VALID_MIN = 0; |
| VALID_MAX = 18446744073709551615; |
| VALID_42 = 42; |
| }; |
| |
| type Uint64EnumStruct = struct { |
| e Uint64Enum; |
| }; |
| |
| type Uint32VectorStruct = struct { |
| vec vector<uint32>; |
| }; |
| |
| type StringStruct = struct { |
| str string; |
| }; |
| |
| type RecursiveOptional = struct { |
| inner box<RecursiveOptional>; |
| }; |
| |
| type RecursiveTable = table { |
| 1: inner RecursiveOptional; |
| }; |
| |
| type BoolStruct = struct { |
| val bool; |
| }; |
| |
| type OptionalBoolStruct = struct { |
| inner box<BoolStruct>; |
| }; |