Home | History | Annotate | Download | only in tests
      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 
      5 module mojo.test;
      6 
      7 // TODO(yzshen): Rename *WithTraits* types to something more readable.
      8 
      9 struct NestedStructWithTraits {
     10   int32 value;
     11 };
     12 
     13 enum EnumWithTraits {
     14   VALUE_0,
     15   VALUE_1
     16 };
     17 
     18 struct 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 
     32 // Test that this container can be cloned.
     33 struct StructWithTraitsContainer {
     34   StructWithTraits f_struct;
     35 };
     36 
     37 // Maps to a pass-by-value trivial struct.
     38 struct TrivialStructWithTraits {
     39   int32 value;
     40 };
     41 
     42 // Maps to a move-only struct.
     43 struct MoveOnlyStructWithTraits {
     44   handle f_handle;
     45 };
     46 
     47 // The custom type for MoveOnlyStructWithTraits is not clonable. Test that
     48 // this container can compile as long as Clone() is not used.
     49 struct MoveOnlyStructWithTraitsContainer {
     50   MoveOnlyStructWithTraits f_struct;
     51 };
     52 
     53 struct StructWithTraitsForUniquePtr {
     54   int32 f_int32;
     55 };
     56 
     57 union UnionWithTraits {
     58   int32 f_int32;
     59   NestedStructWithTraits f_struct;
     60 };
     61 
     62 interface TraitsTestService {
     63   EchoStructWithTraits(StructWithTraits s) => (StructWithTraits passed);
     64 
     65   EchoTrivialStructWithTraits(TrivialStructWithTraits s) =>
     66       (TrivialStructWithTraits passed);
     67 
     68   EchoMoveOnlyStructWithTraits(MoveOnlyStructWithTraits s) =>
     69       (MoveOnlyStructWithTraits passed);
     70 
     71   EchoNullableMoveOnlyStructWithTraits(MoveOnlyStructWithTraits? s) =>
     72       (MoveOnlyStructWithTraits? passed);
     73 
     74   EchoEnumWithTraits(EnumWithTraits e) => (EnumWithTraits passed);
     75 
     76   EchoStructWithTraitsForUniquePtr(StructWithTraitsForUniquePtr e) => (
     77       StructWithTraitsForUniquePtr passed);
     78 
     79   EchoNullableStructWithTraitsForUniquePtr(StructWithTraitsForUniquePtr? e) => (
     80       StructWithTraitsForUniquePtr? passed);
     81 
     82   EchoUnionWithTraits(UnionWithTraits u) => (UnionWithTraits passed);
     83 };
     84