summaryrefslogtreecommitdiffstats
path: root/mojo/public/interfaces/bindings/tests/test_structs.mojom
blob: 3216caf6c91cee1caf15c5e6b5d290588dd9edfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import "mojo/public/interfaces/bindings/tests/rect.mojom";

[JavaPackage="org.chromium.mojo.bindings.test.mojom.test_structs"]
module mojo.test {

struct NamedRegion {
  string? name;
  array<Rect>? rects;
};

struct RectPair {
  Rect? first;
  Rect? second;
};

struct EmptyStruct {
};

// Used to verify that struct fields which don't specify a deafult are
// initialized to: false for bool, 0 for numbers, and null for strings,
// handles, and structs. The "?" nullable suffix shouldn't have any 
// impact on initial field values.

struct NoDefaultFieldValues {
  bool f0;
  int8 f1;
  uint8 f2;
  int16 f3;
  uint16 f4;
  int32 f5;
  uint32 f6;
  int64 f7;
  uint64 f8;
  float f9;
  double f10;
  string f11;
  string? f12;
  handle<message_pipe> f13;
  handle<data_pipe_consumer> f14;
  handle<data_pipe_producer> f15;
  handle<message_pipe>? f16;
  handle<data_pipe_consumer>? f17;
  handle<data_pipe_producer>? f18;
  handle f19;
  handle? f20;
  handle<shared_buffer> f21;
  handle<shared_buffer>? f22;
  array<string> f23;
  array<string?> f24;
  array<string>? f25;
  array<string?>? f26;
  EmptyStruct f27;
  EmptyStruct? f28;
};

// Used to verify that struct fields with an explicit default value
// are initialized correctly. The "?" nullable suffix shouldn't have any 
// impact on initial field values.

struct DefaultFieldValues {
  const string kFoo = "foo";
  bool f0 = true;
  int8 f1 = 100;
  uint8 f2 = 100;
  int16 f3 = 100;
  uint16 f4 = 100;
  int32 f5 = 100;
  uint32 f6 = 100;
  int64 f7 = 100;
  uint64 f8 = 100;
  float f9 = 100;
  float f10 = 100.0;
  double f11 = 100;
  double f12 = 100.0;
  string f13 = kFoo;
  string? f14 = kFoo;
  Rect f15 = default;
  Rect? f16 = default;
};


// Used to verify that the code generated for enum and const values defined
// within a struct is correct. Assuming that a constant's value can be a literal
// or another constant and that enum values can either be an integer constant or
// another value from the same enum type.

struct ScopedConstants {
  const int32 TEN = 10;
  const int32 ALSO_TEN = TEN;
  enum EType {
    E0,
    E1,
    E2 = 10,
    E3 = E2,
    E4,
  };
  const int32 TEN_TOO = EType.E2;
  EType f0 = E0; // 0
  EType f1 = E1; // 1
  EType f2 = E2; // 10
  EType f3 = E3; // 10
  EType f4 = E4; // 11
  int32 f5 = TEN;
  int32 f6 = ALSO_TEN;
};

// Used to verify that all possible Map key field types can be encoded and
// decoded successfully.

struct MapKeyTypes {
  map<bool, bool> f0;
  map<int8, int8> f1;
  map<uint8, uint8> f2;
  map<int16, int16> f3;
  map<uint16, uint16> f4;
  map<int32, int32> f5;
  map<uint32, uint32> f6;
  map<int64, int64> f7;
  map<uint64, uint64> f8;
  map<float, float> f9;
  map<double, double> f10;
  map<string, string> f11;
};

// Used to verify that some common or difficult value types can be encoded and
// decoded successfully.

struct MapValueTypes {
  map<string, array<string>> f0;
  map<string, array<string>?> f1;
  map<string, array<string?>> f2;
  map<string, array<string, 2>> f3;
  map<string, array<array<string, 2>?>> f4;
  map<string, array<array<string, 2>, 1>> f5;
};

}