blob: 7ea07afa60232b721dda85be1478cf3b78b830d6 [file] [log] [blame] [edit]
// 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.
library fidl.llcpp.types.test;
struct CopyableStruct {
int32 x;
};
resource struct MoveOnlyStruct {
handle? h;
};
/// Verifies that user code can manipulate these union payloads.
resource union TestUnion {
1: int32 primitive;
2: CopyableStruct copyable;
3: MoveOnlyStruct move_only;
};
flexible resource union TestXUnion {
1: int32 primitive;
2: CopyableStruct copyable;
3: handle h;
};
union TestStrictXUnion {
1: int32 primitive;
2: CopyableStruct copyable;
};
struct TestStrictXUnionInStruct {
TestStrictXUnion xu;
};
flexible union TestNonResourceXUnion {
1: int32 primitive;
};
/// Verifies that user code can manipulate these bits.
///
/// We use a uint8 since most bitwise operations will cast their operands to
/// int, and therefore special casting is required to properly compile.
strict bits StrictBits : uint8 {
B = 2;
D = 4;
E = 8;
};
/// The members should be kept in sync with those in [`StrictBits`], as we have
/// tests parameterized on both bits types.
flexible bits FlexibleBits : uint8 {
B = 2;
D = 4;
E = 8;
};
/// Verifies that user code can build and access tables.
table SampleTable {
1: uint8 x;
2: uint8 y;
3: vector<CopyableStruct> vector_of_struct;
};
/// Verifies that an empty table compiles.
table SampleEmptyTable {
};
protocol TestInterface {
TestMethod(TestUnion u) -> (TestUnion u);
};
/// Verifies that method argument types don't conflict with user-defined types.
struct FooRequest {
int32 bar;
};
struct FooResponse {
int32 bar;
};
protocol Baz {
Foo(FooRequest req) -> (FooResponse res);
};
table TableWithSubTables {
1: SampleTable t;
2: vector<SampleTable> vt;
3: array<SampleTable>:3 at;
};
strict enum StrictEnum : uint32 {
B = 2;
D = 4;
E = 8;
};
flexible enum FlexibleEnum : uint32 {
B = 2;
D = 4;
E = 8;
[Unknown] CUSTOM = 56;
};
struct EmptyStruct {
};
table TestTable {
1: uint8 x;
};
resource table TestResourceTable {
1: uint8 x;
};
/// Certain traits are only implemented for top level (i.e. request/response struct)
/// types, since LLCPP only calls encode/decode on those top level types.
/// Types used in tests that exercise these codepaths (e.g. involving HasFlexibleEnvelope)
/// should be put in a request/response struct instead of a regular struct in order
/// to reflect the actual paths exercised within a protocol.
///
/// For example, to test a union MyUnion, instead of:
/// - declaring wrapper struct `struct MyUnionStruct { MyUnion xu };`
/// - writing encode/decode tests in C++ using MyUnionStruct
/// do:
/// - add method `MyUnion() -> (MyUnion result);`
/// - write tests in C++ using MsgWrapper::MyUnionResponse
protocol MsgWrapper {
TestXUnion() -> (TestXUnion result);
TestNonResourceXUnion() -> (TestNonResourceXUnion result);
TestTable() -> (TestTable result);
TestResourceTable() -> (TestResourceTable result);
};