1// Copyright 2016 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5module mojo.test; 6 7// TODO(yzshen): Rename *WithTraits* types to something more readable. 8 9struct NestedStructWithTraits { 10 int32 value; 11}; 12 13enum EnumWithTraits { 14 VALUE_0, 15 VALUE_1 16}; 17 18struct StructWithTraits { 19 EnumWithTraits f_enum; 20 bool f_bool; 21 uint32 f_uint32; 22 uint64 f_uint64; 23 string f_string; 24 string f_string2; 25 array<string> f_string_array; 26 array<string> f_string_set; 27 NestedStructWithTraits f_struct; 28 array<NestedStructWithTraits> f_struct_array; 29 map<string, NestedStructWithTraits> f_struct_map; 30}; 31 32struct StructWithUnreachableTraits { 33 bool ignore_me; 34}; 35 36// Test that this container can be cloned. 37struct StructWithTraitsContainer { 38 StructWithTraits f_struct; 39}; 40 41// Maps to a pass-by-value trivial struct. 42struct TrivialStructWithTraits { 43 int32 value; 44}; 45 46// Maps to a move-only struct. 47struct MoveOnlyStructWithTraits { 48 handle f_handle; 49}; 50 51// The custom type for MoveOnlyStructWithTraits is not clonable. Test that 52// this container can compile as long as Clone() is not used. 53struct MoveOnlyStructWithTraitsContainer { 54 MoveOnlyStructWithTraits f_struct; 55}; 56 57struct StructWithTraitsForUniquePtr { 58 int32 f_int32; 59}; 60 61union UnionWithTraits { 62 int32 f_int32; 63 NestedStructWithTraits f_struct; 64}; 65 66interface TraitsTestService { 67 EchoStructWithTraits(StructWithTraits s) => (StructWithTraits passed); 68 69 EchoTrivialStructWithTraits(TrivialStructWithTraits s) => 70 (TrivialStructWithTraits passed); 71 72 EchoMoveOnlyStructWithTraits(MoveOnlyStructWithTraits s) => 73 (MoveOnlyStructWithTraits passed); 74 75 EchoNullableMoveOnlyStructWithTraits(MoveOnlyStructWithTraits? s) => 76 (MoveOnlyStructWithTraits? passed); 77 78 EchoEnumWithTraits(EnumWithTraits e) => (EnumWithTraits passed); 79 80 EchoStructWithTraitsForUniquePtr(StructWithTraitsForUniquePtr e) => ( 81 StructWithTraitsForUniquePtr passed); 82 83 EchoNullableStructWithTraitsForUniquePtr(StructWithTraitsForUniquePtr? e) => ( 84 StructWithTraitsForUniquePtr? passed); 85 86 EchoUnionWithTraits(UnionWithTraits u) => (UnionWithTraits passed); 87}; 88 89interface TestUnserializedStruct { 90 PassUnserializedStruct(StructWithUnreachableTraits s) 91 => (StructWithUnreachableTraits passed); 92}; 93 94// Test that specifying default value for a typemapped enum field works. 95struct EnumWithTraitsContainer { 96 EnumWithTraits f_field = EnumWithTraits.VALUE_1; 97}; 98 99struct StructForceSerialize { 100 int32 value; 101}; 102 103struct StructNestedForceSerialize { 104 StructForceSerialize force; 105}; 106 107interface ForceSerializeTester { 108 SendForceSerializedStruct(StructForceSerialize s) 109 => (StructForceSerialize passed); 110 SendNestedForceSerializedStruct(StructNestedForceSerialize s) 111 => (StructNestedForceSerialize passed); 112}; 113