| // 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. |
| |
| library fidl.test.compatibility; |
| |
| // This is not a reference to library zx to avoid complexity in the test data. |
| // A local handle is defined here that contains subtypes that this test cares |
| // about. |
| enum obj_type : uint32 { |
| NONE = 0; |
| PROCESS = 1; |
| THREAD = 2; |
| VMO = 3; |
| CHANNEL = 4; |
| EVENT = 5; |
| PORT = 6; |
| INTERRUPT = 9; |
| LOG = 12; |
| SOCKET = 14; |
| EVENTPAIR = 16; |
| JOB = 17; |
| VMAR = 18; |
| FIFO = 19; |
| TIMER = 22; |
| }; |
| |
| resource_definition handle : uint32 { |
| properties { |
| obj_type subtype; |
| }; |
| }; |
| |
| struct this_is_a_struct { |
| string s; |
| }; |
| |
| struct this_is_an_empty_struct { |
| }; |
| |
| union this_is_a_union { |
| 1: string s; |
| 2: bool b; |
| }; |
| |
| table this_is_a_table { |
| 1: string s; |
| }; |
| |
| flexible union this_is_a_xunion { |
| 1: string s; |
| 2: bool b; |
| }; |
| |
| struct primitive_types { |
| bool b; |
| int8 i8; |
| int16 i16; |
| int32 i32; |
| int64 i64; |
| uint8 u8; |
| uint16 u16; |
| uint32 u32; |
| uint64 u64; |
| float32 f32; |
| float64 f64; |
| }; |
| |
| struct default_values { |
| bool b1 = true; |
| bool b2 = false; |
| int8 i8 = -23; |
| int16 i16 = 34; |
| int32 i32 = -34595; |
| int64 i64 = 3948038; |
| uint8 u8 = 0; |
| uint16 u16 = 348; |
| uint32 u32 = 9038; |
| uint64 u64 = 19835; |
| float32 f32 = 1.30; |
| float64 f64 = 0.0000054; |
| string s = "hello"; |
| }; |
| |
| // Arbitrary, but must be small enough such that a single message doesn't exceed |
| // kMaxMessageSize or kMaxMessageHandles. |
| const uint32 arrays_size = 3; |
| |
| resource struct arrays { |
| array<bool>:1 b_0; |
| array<int8>:1 i8_0; |
| array<int16>:1 i16_0; |
| array<int32>:1 i32_0; |
| array<int64>:1 i64_0; |
| array<uint8>:1 u8_0; |
| array<uint16>:1 u16_0; |
| array<uint32>:1 u32_0; |
| array<uint64>:1 u64_0; |
| array<float32>:1 f32_0; |
| array<float64>:1 f64_0; |
| array<handle>:1 handle_0; |
| array<bool>:arrays_size b_1; |
| array<int8>:arrays_size i8_1; |
| array<int16>:arrays_size i16_1; |
| array<int32>:arrays_size i32_1; |
| array<int64>:arrays_size i64_1; |
| array<uint8>:arrays_size u8_1; |
| array<uint16>:arrays_size u16_1; |
| array<uint32>:arrays_size u32_1; |
| array<uint64>:arrays_size u64_1; |
| array<float32>:arrays_size f32_1; |
| array<float64>:arrays_size f64_1; |
| array<handle>:arrays_size handle_1; |
| }; |
| |
| resource struct arrays_2d { |
| array<array<bool>:2>:arrays_size b; |
| array<array<int8>:2>:arrays_size i8; |
| array<array<int16>:2>:arrays_size i16; |
| array<array<int32>:2>:arrays_size i32; |
| array<array<int64>:2>:arrays_size i64; |
| array<array<uint8>:2>:arrays_size u8; |
| array<array<uint16>:2>:arrays_size u16; |
| array<array<uint32>:2>:arrays_size u32; |
| array<array<uint64>:2>:arrays_size u64; |
| array<array<float32>:2>:arrays_size f32; |
| array<array<float64>:2>:arrays_size f64; |
| array<array<handle>:2>:arrays_size handle_handle; |
| }; |
| |
| // Arbitrary, but must be small enough such that a single message doesn't exceed |
| // kMaxMessageSize or kMaxMessageHandles. |
| const uint32 vectors_size = 3; |
| |
| resource struct vectors { |
| vector<bool> b_0; |
| vector<int8> i8_0; |
| vector<int16> i16_0; |
| vector<int32> i32_0; |
| vector<int64> i64_0; |
| vector<uint8> u8_0; |
| vector<uint16> u16_0; |
| vector<uint32> u32_0; |
| vector<uint64> u64_0; |
| vector<float32> f32_0; |
| vector<float64> f64_0; |
| vector<handle> handle_0; |
| vector<vector<bool>:2> b_1; |
| vector<vector<int8>:2> i8_1; |
| vector<vector<int16>:2> i16_1; |
| vector<vector<int32>:2> i32_1; |
| vector<vector<int64>:2> i64_1; |
| vector<vector<uint8>:2> u8_1; |
| vector<vector<uint16>:2> u16_1; |
| vector<vector<uint32>:2> u32_1; |
| vector<vector<uint64>:2> u64_1; |
| vector<vector<float32>:2> f32_1; |
| vector<vector<float64>:2> f64_1; |
| vector<vector<handle>:2> handle_1; |
| vector<bool>:1 b_sized_0; |
| vector<int8>:1 i8_sized_0; |
| vector<int16>:1 i16_sized_0; |
| vector<int32>:1 i32_sized_0; |
| vector<int64>:1 i64_sized_0; |
| vector<uint8>:1 u8_sized_0; |
| vector<uint16>:1 u16_sized_0; |
| vector<uint32>:1 u32_sized_0; |
| vector<uint64>:1 u64_sized_0; |
| vector<float32>:1 f32_sized_0; |
| vector<float64>:1 f64_sized_0; |
| vector<handle>:1 handle_sized_0; |
| vector<bool>:vectors_size b_sized_1; |
| vector<int8>:vectors_size i8_sized_1; |
| vector<int16>:vectors_size i16_sized_1; |
| vector<int32>:vectors_size i32_sized_1; |
| vector<int64>:vectors_size i64_sized_1; |
| vector<uint8>:vectors_size u8_sized_1; |
| vector<uint16>:vectors_size u16_sized_1; |
| vector<uint32>:vectors_size u32_sized_1; |
| vector<uint64>:vectors_size u64_sized_1; |
| vector<float32>:vectors_size f32_sized_1; |
| vector<float64>:vectors_size f64_sized_1; |
| vector<handle>:vectors_size handle_sized_1; |
| vector<vector<bool>:2>:vectors_size b_sized_2; |
| vector<vector<int8>:2>:vectors_size i8_sized_2; |
| vector<vector<int16>:2>:vectors_size i16_sized_2; |
| vector<vector<int32>:2>:vectors_size i32_sized_2; |
| vector<vector<int64>:2>:vectors_size i64_sized_2; |
| vector<vector<uint8>:2>:vectors_size u8_sized_2; |
| vector<vector<uint16>:2>:vectors_size u16_sized_2; |
| vector<vector<uint32>:2>:vectors_size u32_sized_2; |
| vector<vector<uint64>:2>:vectors_size u64_sized_2; |
| vector<vector<float32>:2>:vectors_size f32_sized_2; |
| vector<vector<float64>:2>:vectors_size f64_sized_2; |
| vector<vector<handle>:2>:vectors_size handle_sized_2; |
| vector<bool>:1? b_nullable_0; |
| vector<int8>:1? i8_nullable_0; |
| vector<int16>:1? i16_nullable_0; |
| vector<int32>:1? i32_nullable_0; |
| vector<int64>:1? i64_nullable_0; |
| vector<uint8>:1? u8_nullable_0; |
| vector<uint16>:1? u16_nullable_0; |
| vector<uint32>:1? u32_nullable_0; |
| vector<uint64>:1? u64_nullable_0; |
| vector<float32>:1? f32_nullable_0; |
| vector<float64>:1? f64_nullable_0; |
| vector<handle>:1? handle_nullable_0; |
| vector<vector<bool>:2>? b_nullable_1; |
| vector<vector<int8>:2>? i8_nullable_1; |
| vector<vector<int16>:2>? i16_nullable_1; |
| vector<vector<int32>:2>? i32_nullable_1; |
| vector<vector<int64>:2>? i64_nullable_1; |
| vector<vector<uint8>:2>? u8_nullable_1; |
| vector<vector<uint16>:2>? u16_nullable_1; |
| vector<vector<uint32>:2>? u32_nullable_1; |
| vector<vector<uint64>:2>? u64_nullable_1; |
| vector<vector<float32>:2>? f32_nullable_1; |
| vector<vector<float64>:2>? f64_nullable_1; |
| vector<vector<handle>:2>? handle_nullable_1; |
| vector<bool>:1? b_nullable_sized_0; |
| vector<int8>:1? i8_nullable_sized_0; |
| vector<int16>:1? i16_nullable_sized_0; |
| vector<int32>:1? i32_nullable_sized_0; |
| vector<int64>:1? i64_nullable_sized_0; |
| vector<uint8>:1? u8_nullable_sized_0; |
| vector<uint16>:1? u16_nullable_sized_0; |
| vector<uint32>:1? u32_nullable_sized_0; |
| vector<uint64>:1? u64_nullable_sized_0; |
| vector<float32>:1? f32_nullable_sized_0; |
| vector<float64>:1? f64_nullable_sized_0; |
| vector<handle>:1? handle_nullable_sized_0; |
| vector<bool>:vectors_size? b_nullable_sized_1; |
| vector<int8>:vectors_size? i8_nullable_sized_1; |
| vector<int16>:vectors_size? i16_nullable_sized_1; |
| vector<int32>:vectors_size? i32_nullable_sized_1; |
| vector<int64>:vectors_size? i64_nullable_sized_1; |
| vector<uint8>:vectors_size? u8_nullable_sized_1; |
| vector<uint16>:vectors_size? u16_nullable_sized_1; |
| vector<uint32>:vectors_size? u32_nullable_sized_1; |
| vector<uint64>:vectors_size? u64_nullable_sized_1; |
| vector<float32>:vectors_size? f32_nullable_sized_1; |
| vector<float64>:vectors_size? f64_nullable_sized_1; |
| vector<handle>:vectors_size? handle_nullable_sized_1; |
| vector<vector<bool>:2>:vectors_size? b_nullable_sized_2; |
| vector<vector<int8>:2>:vectors_size? i8_nullable_sized_2; |
| vector<vector<int16>:2>:vectors_size? i16_nullable_sized_2; |
| vector<vector<int32>:2>:vectors_size? i32_nullable_sized_2; |
| vector<vector<int64>:2>:vectors_size? i64_nullable_sized_2; |
| vector<vector<uint8>:2>:vectors_size? u8_nullable_sized_2; |
| vector<vector<uint16>:2>:vectors_size? u16_nullable_sized_2; |
| vector<vector<uint32>:2>:vectors_size? u32_nullable_sized_2; |
| vector<vector<uint64>:2>:vectors_size? u64_nullable_sized_2; |
| vector<vector<float32>:2>:vectors_size? f32_nullable_sized_2; |
| vector<vector<float64>:2>:vectors_size? f64_nullable_sized_2; |
| vector<vector<handle>:2>:vectors_size? handle_nullable_sized_2; |
| }; |
| |
| // We don't test handle types that don't support duplication |
| // (supports_duplication in zx/object_traits.h) or that require special |
| // privileges to create. |
| resource struct handles { |
| handle handle_handle; |
| handle:PROCESS process_handle; |
| handle:THREAD thread_handle; |
| handle:VMO vmo_handle; |
| handle:EVENT event_handle; |
| handle:PORT port_handle; |
| handle:SOCKET socket_handle; |
| handle:EVENTPAIR eventpair_handle; |
| handle:JOB job_handle; |
| handle:VMAR vmar_handle; |
| handle:FIFO fifo_handle; |
| handle:TIMER timer_handle; |
| handle? nullable_handle_handle; |
| handle:PROCESS? nullable_process_handle; |
| handle:THREAD? nullable_thread_handle; |
| handle:VMO? nullable_vmo_handle; |
| handle:CHANNEL? nullable_channel_handle; |
| handle:EVENT? nullable_event_handle; |
| handle:PORT? nullable_port_handle; |
| handle:INTERRUPT? nullable_interrupt_handle; |
| handle:LOG? nullable_log_handle; |
| handle:SOCKET? nullable_socket_handle; |
| handle:EVENTPAIR? nullable_eventpair_handle; |
| handle:JOB? nullable_job_handle; |
| handle:VMAR? nullable_vmar_handle; |
| handle:FIFO? nullable_fifo_handle; |
| handle:TIMER? nullable_timer_handle; |
| }; |
| |
| // Arbitrary. |
| const uint32 strings_size = 32; |
| |
| struct strings { |
| string s; |
| string? nullable_s; |
| string:2 size_0_s; |
| string:strings_size size_1_s; |
| string:2? nullable_size_0_s; |
| string:strings_size? nullable_size_1_s; |
| }; |
| |
| enum default_enum { |
| kZero = 0; |
| kOne = 1; |
| }; |
| |
| enum i8_enum : int8 { |
| kNegativeOne = -1; |
| kOne = 1; |
| }; |
| |
| enum i16_enum : int16 { |
| kNegativeOne = -1; |
| kOne = 1; |
| kTwo = 2; |
| }; |
| |
| enum i32_enum : int32 { |
| kNegativeOne = -1; |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| }; |
| |
| enum i64_enum : int64 { |
| kNegativeOne = -1; |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| kFour = 4; |
| }; |
| |
| enum u8_enum : uint8 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| kFour = 4; |
| kFive = 5; |
| }; |
| |
| enum u16_enum : uint16 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| kFour = 4; |
| kFive = 5; |
| kSix = 6; |
| }; |
| |
| enum u32_enum : uint32 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| kFour = 4; |
| kFive = 5; |
| kSix = 6; |
| kSeven = 7; |
| }; |
| |
| enum u64_enum : uint64 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 3; |
| kFour = 4; |
| kFive = 5; |
| kSix = 6; |
| kSeven = 7; |
| kEight = 8; |
| }; |
| |
| bits default_bits { |
| kOne = 1; |
| kTwo = 2; |
| }; |
| |
| bits u8_bits : uint8 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 4; |
| kFour = 8; |
| kFive = 16; |
| }; |
| |
| bits u16_bits : uint16 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 4; |
| kFour = 8; |
| kFive = 16; |
| kSix = 32; |
| }; |
| |
| bits u32_bits : uint32 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 4; |
| kFour = 8; |
| kFive = 16; |
| kSix = 32; |
| kSeven = 64; |
| }; |
| |
| bits u64_bits : uint64 { |
| kOne = 1; |
| kTwo = 2; |
| kThree = 4; |
| kFour = 8; |
| kFive = 16; |
| kSix = 32; |
| kSeven = 64; |
| kEight = 128; |
| }; |
| |
| struct structs { |
| this_is_a_struct s; |
| this_is_a_struct? nullable_s; |
| this_is_an_empty_struct es; |
| }; |
| |
| struct unions { |
| this_is_a_union u; |
| this_is_a_union? nullable_u; |
| }; |
| |
| // This struct is meant to exercise almost all features of FIDL. |
| resource struct Struct { |
| primitive_types primitive_types; |
| default_values default_values; |
| arrays arrays; |
| arrays_2d arrays_2d; |
| vectors vectors; |
| handles handles; |
| strings strings; |
| default_enum default_enum; |
| i8_enum i8_enum; |
| i16_enum i16_enum; |
| i32_enum i32_enum; |
| i64_enum i64_enum; |
| u8_enum u8_enum; |
| u16_enum u16_enum; |
| u32_enum u32_enum; |
| u64_enum u64_enum; |
| default_bits default_bits; |
| u8_bits u8_bits; |
| u16_bits u16_bits; |
| u32_bits u32_bits; |
| u64_bits u64_bits; |
| structs structs; |
| unions unions; |
| this_is_a_table table; |
| this_is_a_xunion xunion; |
| bool b; |
| }; |
| |
| // This struct contains arrays of all different kinds of FIDL types. |
| resource struct ArraysStruct { |
| array<bool>:arrays_size bools; |
| array<int8>:arrays_size int8s; |
| array<int16>:arrays_size int16s; |
| array<int32>:arrays_size int32s; |
| array<int64>:arrays_size int64s; |
| array<uint8>:arrays_size uint8s; |
| array<uint16>:arrays_size uint16s; |
| array<uint32>:arrays_size uint32s; |
| array<uint64>:arrays_size uint64s; |
| array<float32>:arrays_size float32s; |
| array<float64>:arrays_size float64s; |
| array<default_enum>:arrays_size enums; |
| array<default_bits>:arrays_size bits; |
| array<handle>:arrays_size handles; |
| array<handle?>:arrays_size nullable_handles; |
| array<string>:arrays_size strings; |
| array<string?>:arrays_size nullable_strings; |
| array<this_is_a_struct>:arrays_size structs; |
| array<this_is_a_struct?>:arrays_size nullable_structs; |
| array<this_is_a_union>:arrays_size unions; |
| array<this_is_a_union?>:arrays_size nullable_unions; |
| array<array<uint32>:arrays_size>:arrays_size arrays; |
| array<vector<uint32>>:arrays_size vectors; |
| array<vector<uint32>?>:arrays_size nullable_vectors; |
| array<this_is_a_table>:arrays_size tables; |
| array<this_is_a_xunion>:arrays_size xunions; |
| }; |
| |
| // This struct contains vectors of all different kinds of FIDL types. |
| resource struct VectorsStruct { |
| vector<bool>:vectors_size bools; |
| vector<int8>:vectors_size int8s; |
| vector<int16>:vectors_size int16s; |
| vector<int32>:vectors_size int32s; |
| vector<int64>:vectors_size int64s; |
| vector<uint8>:vectors_size uint8s; |
| vector<uint16>:vectors_size uint16s; |
| vector<uint32>:vectors_size uint32s; |
| vector<uint64>:vectors_size uint64s; |
| vector<float32>:vectors_size float32s; |
| vector<float64>:vectors_size float64s; |
| vector<default_enum>:vectors_size enums; |
| vector<default_bits>:vectors_size bits; |
| vector<handle>:vectors_size handles; |
| vector<handle?>:vectors_size nullable_handles; |
| vector<string>:vectors_size strings; |
| vector<string?>:vectors_size nullable_strings; |
| vector<this_is_a_struct>:vectors_size structs; |
| vector<this_is_a_struct?>:vectors_size nullable_structs; |
| vector<this_is_a_union>:vectors_size unions; |
| vector<this_is_a_union?>:vectors_size nullable_unions; |
| vector<array<uint32>:vectors_size>:vectors_size arrays; |
| vector<vector<uint32>>:vectors_size vectors; |
| vector<vector<uint32>?>:vectors_size nullable_vectors; |
| vector<this_is_a_table>:vectors_size tables; |
| vector<this_is_a_xunion>:vectors_size xunions; |
| }; |
| |
| // This table has members all different FIDL types. |
| resource table AllTypesTable { |
| 1: bool bool_member; |
| 2: int8 int8_member; |
| 3: int16 int16_member; |
| 4: int32 int32_member; |
| 5: int64 int64_member; |
| 6: uint8 uint8_member; |
| 7: uint16 uint16_member; |
| 8: uint32 uint32_member; |
| 9: uint64 uint64_member; |
| 10: float32 float32_member; |
| 11: float64 float64_member; |
| 12: default_enum enum_member; |
| 13: default_bits bits_member; |
| 14: handle handle_member; |
| 15: string string_member; |
| 16: this_is_a_struct struct_member; |
| 17: this_is_a_union union_member; |
| 18: array<uint32>:arrays_size array_member; |
| 19: vector<uint32> vector_member; |
| 20: this_is_a_table table_member; |
| 21: this_is_a_xunion xunion_member; |
| }; |
| |
| // This xunion has members all different FIDL types. |
| flexible resource union AllTypesXunion { |
| 1: bool bool_member; |
| 2: int8 int8_member; |
| 3: int16 int16_member; |
| 4: int32 int32_member; |
| 5: int64 int64_member; |
| 6: uint8 uint8_member; |
| 7: uint16 uint16_member; |
| 8: uint32 uint32_member; |
| 9: uint64 uint64_member; |
| 10: float32 float32_member; |
| 11: float64 float64_member; |
| 12: default_enum enum_member; |
| 13: default_bits bits_member; |
| 14: handle handle_member; |
| 15: string string_member; |
| 16: this_is_a_struct struct_member; |
| 17: this_is_a_union union_member; |
| 18: array<uint32>:arrays_size array_member; |
| 19: vector<uint32> vector_member; |
| 20: this_is_a_table table_member; |
| 21: this_is_a_xunion xunion_member; |
| }; |
| |
| enum RespondWith { |
| SUCCESS = 1; |
| ERR = 2; |
| }; |
| |
| [Discoverable] |
| protocol Echo { |
| // If `forward_to_server` is empty, just returns `value`. |
| // If `forward_to_server` is not empty, it is treated as the URL of a server |
| // which implements this interface. The server that recieves the non-empty |
| // `forward_to_server` arg acts as a proxy for that other server. |
| // For the error variants: if should_error is true, the provided err result |
| // error is sent, otherwise the response variant is sent. |
| EchoStruct(Struct value, string forward_to_server) -> (Struct value); |
| EchoStructWithError( |
| Struct value, default_enum result_err, string forward_to_server, RespondWith result_variant) |
| -> (Struct value) error default_enum; |
| |
| // Same as the above, but the server should use the event to return the |
| // response, rather than a return value. |
| EchoStructNoRetVal(Struct value, string forward_to_server); |
| -> EchoEvent(Struct value); |
| EchoArrays(ArraysStruct value, string forward_to_server) -> (ArraysStruct value); |
| EchoArraysWithError( |
| ArraysStruct value, default_enum result_err, string forward_to_server, RespondWith result_variant) |
| -> (ArraysStruct value) error default_enum; |
| |
| EchoVectors(VectorsStruct value, string forward_to_server) -> (VectorsStruct value); |
| EchoVectorsWithError( |
| VectorsStruct value, default_enum result_err, string forward_to_server, RespondWith result_variant) |
| -> (VectorsStruct value) error default_enum; |
| |
| EchoTable(AllTypesTable value, string forward_to_server) -> (AllTypesTable value); |
| EchoTableWithError( |
| AllTypesTable value, default_enum result_err, string forward_to_server, RespondWith result_variant) |
| -> (AllTypesTable value) error default_enum; |
| |
| EchoXunions(vector<AllTypesXunion> value, string forward_to_server) -> (vector<AllTypesXunion> value); |
| EchoXunionsWithError( |
| vector<AllTypesXunion> value, default_enum result_err, string forward_to_server, RespondWith result_variant) |
| -> (vector<AllTypesXunion> value) error default_enum; |
| }; |