• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2013 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[JavaPackage="org.chromium.mojo.bindings.test.mojom.test_structs"]
6module mojo.test;
7
8import "mojo/public/interfaces/bindings/tests/rect.mojom";
9
10struct NamedRegion {
11  string? name;
12  array<Rect>? rects;
13};
14
15struct RectPair {
16  Rect? first;
17  Rect? second;
18};
19
20struct EmptyStruct {
21};
22
23[Native]
24struct UnmappedNativeStruct;
25
26// Used to verify that struct fields which don't specify a default are
27// initialized to: false for bool, 0 for numbers, and null for strings,
28// handles, and structs. The "?" nullable suffix shouldn't have any
29// impact on initial field values.
30
31struct NoDefaultFieldValues {
32  bool f0;
33  int8 f1;
34  uint8 f2;
35  int16 f3;
36  uint16 f4;
37  int32 f5;
38  uint32 f6;
39  int64 f7;
40  uint64 f8;
41  float f9;
42  double f10;
43  string f11;
44  string? f12;
45  handle<message_pipe> f13;
46  handle<data_pipe_consumer> f14;
47  handle<data_pipe_producer> f15;
48  handle<message_pipe>? f16;
49  handle<data_pipe_consumer>? f17;
50  handle<data_pipe_producer>? f18;
51  handle f19;
52  handle? f20;
53  handle<shared_buffer> f21;
54  handle<shared_buffer>? f22;
55  array<string> f23;
56  array<string?> f24;
57  array<string>? f25;
58  array<string?>? f26;
59  EmptyStruct f27;
60  EmptyStruct? f28;
61};
62
63// Used to verify that struct fields with an explicit default value
64// are initialized correctly. The "?" nullable suffix shouldn't have any
65// impact on initial field values.
66
67struct DefaultFieldValues {
68  const string kFoo = "foo";
69  bool f0 = true;
70  int8 f1 = 100;
71  uint8 f2 = 100;
72  int16 f3 = 100;
73  uint16 f4 = 100;
74  int32 f5 = 100;
75  uint32 f6 = 100;
76  int64 f7 = 100;
77  uint64 f8 = 100;
78  float f9 = 100;
79  float f10 = 100.0;
80  double f11 = 100;
81  double f12 = 100.0;
82  string f13 = kFoo;
83  string? f14 = kFoo;
84  Rect f15 = default;
85  Rect? f16 = default;
86};
87
88// Used to verify that the code generated for enum and const values defined
89// within a struct is correct. Assuming that a constant's value can be a literal
90// or another constant and that enum values can either be an integer constant or
91// another value from the same enum type.
92
93struct ScopedConstants {
94  const int32 TEN = 10;
95  const int32 ALSO_TEN = TEN;
96  enum EType {
97    E0,
98    E1,
99    E2 = 10,
100    E3 = E2,
101    E4,
102  };
103  EType f0 = E0; // 0
104  EType f1 = E1; // 1
105  EType f2 = E2; // 10
106  EType f3 = E3; // 10
107  EType f4 = E4; // 11
108  int32 f5 = TEN;
109  int32 f6 = ALSO_TEN;
110};
111
112// Used to verify that all possible Map key field types can be encoded and
113// decoded successfully.
114
115struct MapKeyTypes {
116  // TODO(yzshen): WTF::HashMap doesn't support bool as key.
117  // map<bool, bool> f0;
118  map<int8, int8> f1;
119  map<uint8, uint8> f2;
120  map<int16, int16> f3;
121  map<uint16, uint16> f4;
122  map<int32, int32> f5;
123  map<uint32, uint32> f6;
124  map<int64, int64> f7;
125  map<uint64, uint64> f8;
126  map<float, float> f9;
127  map<double, double> f10;
128  map<string, string> f11;
129};
130
131// Used to verify that various map value types can be encoded and decoded
132// successfully.
133
134struct MapValueTypes {
135  map<string, array<string>> f0;
136  map<string, array<string>?> f1;
137  map<string, array<string?>> f2;
138  map<string, array<string, 2>> f3;
139  map<string, array<array<string, 2>?>> f4;
140  map<string, array<array<string, 2>, 1>> f5;
141  map<string, Rect?> f6;
142  map<string, map<string, string>> f7;
143  map<string, array<map<string, string>>> f8;
144  map<string, handle> f9;
145  map<string, array<handle>> f10;
146  map<string, map<string, handle>> f11;
147};
148
149// Used to verify that various array types can be encoded and decoded
150// successfully.
151
152struct ArrayValueTypes {
153  array<int8> f0;
154  array<int16> f1;
155  array<int32> f2;
156  array<int64> f3;
157  array<float> f4;
158  array<double> f5;
159  array<SomeInterface> f6;
160  array<SomeInterface&> f7;
161};
162
163// Used to verify that various float and double values can be encoded and
164// decoded correctly.
165
166struct FloatNumberValues {
167  const double V0 = double.INFINITY;
168  const double V1 = double.NEGATIVE_INFINITY;
169  const double V2 = double.NAN;
170  const float V3 = float.INFINITY;
171  const float V4 = float.NEGATIVE_INFINITY;
172  const float V5 = float.NAN;
173  const float V6 = 0;
174  const double V7 = 1234567890.123;
175  const double V8 = 1.2E+20;
176  const double V9 = -1.2E+20;
177
178  double f0 = V0;
179  double f1 = V1;
180  double f2 = V2;
181  float f3 = V3;
182  float f4 = V4;
183  float f5 = V5;
184  float f6 = V6;
185  double f7 = V7;
186  double f8 = V8;
187  double f9 = V9;
188};
189
190// Used to verify that various signed integer values can be encoded and
191// decoded correctly.
192
193struct IntegerNumberValues {
194  const int8 V0 = -128; // Minimum
195  const int8 V1 = -1;   // -1
196  const int8 V2 = 0;    // 0
197  const int8 V3 = 42;   // An arbitrary valid value.
198  const int8 V4 = 127;  // Maximum
199
200  const int16 V5 = -32768; // ...
201  const int16 V6 = -1;
202  const int16 V7 = 0;
203  const int16 V8 = 12345;
204  const int16 V9 = 32767;
205
206  const int32 V10 = -2147483648;
207  const int32 V11 = -1;
208  const int32 V12 = 0;
209  const int32 V13 = 1234567890;
210  const int32 V14 = 2147483647;
211
212  // The limits for JavaScript integers are +/- (2^53 - 1).
213  const int64 V15 = -9007199254740991; // Number.MIN_SAFE_INTEGER
214  const int64 V16 = -1;
215  const int64 V17 = 0;
216  const int64 V18 = 1234567890123456;
217  const int64 V19 = 9007199254740991; // Number.MAX_SAFE_INTEGER
218
219  int8 f0 = V0;
220  int8 f1 = V1;
221  int8 f2 = V2;
222  int8 f3 = V3;
223  int8 f4 = V4;
224
225  int16 f5 = V5;
226  int16 f6 = V6;
227  int16 f7 = V7;
228  int16 f8 = V8;
229  int16 f9 = V9;
230
231  int32 f10 = V10;
232  int32 f11 = V11;
233  int32 f12 = V12;
234  int32 f13 = V13;
235  int32 f14 = V14;
236
237  int64 f15 = V15;
238  int64 f16 = V16;
239  int64 f17 = V17;
240  int64 f18 = V18;
241  int64 f19 = V19;
242};
243
244// Used to verify that various unsigned integer values can be encoded and
245// decoded correctly.
246
247struct UnsignedNumberValues {
248  const uint8 V0 = 0;    // Minimum = 0.
249  const uint8 V1 = 42;   // An arbitrary valid value.
250  const uint8 V2 = 0xFF; // Maximum
251
252  const uint16 V3 = 0; // ...
253  const uint16 V4 = 12345;
254  const uint16 V5 = 0xFFFF;
255
256  const uint32 V6 = 0;
257  const uint32 V7 = 1234567890;
258  const uint32 V8 = 0xFFFFFFFF;
259
260  // The limits for JavaScript integers are +/- (2^53 - 1).
261  const uint64 V9 = 0;
262  const uint64 V10 = 1234567890123456;
263  const uint64 V11 = 9007199254740991; // Number.MAX_SAFE_INTEGER
264
265  uint8 f0 = V0;
266  uint8 f1 = V1;
267  uint8 f2 = V2;
268
269  uint16 f3 = V3;
270  uint16 f4 = V4;
271  uint16 f5 = V5;
272
273  uint32 f6 = V6;
274  uint32 f7  = V7;
275  uint32 f8 = V8;
276
277  uint64 f9 = V9;
278  uint64 f10 = V10;
279  uint64 f11 = V11;
280};
281
282// Used to verify that various (packed) boolean array values can be encoded
283// and decoded correctly.
284
285struct BitArrayValues {
286  array<bool, 1> f0;
287  array<bool, 7> f1;
288  array<bool, 9> f2;
289  array<bool> f3;
290  array<array<bool>> f4;
291  array<array<bool>?> f5;
292  array<array<bool, 2>?> f6;
293};
294
295// Used to verify that different versions can be decoded correctly.
296
297struct MultiVersionStruct {
298  [MinVersion=0]
299  int32 f_int32;
300  [MinVersion=1]
301  Rect? f_rect;
302  [MinVersion=3]
303  string? f_string;
304  [MinVersion=5]
305  array<int8>? f_array;
306  [MinVersion=7]
307  handle<message_pipe>? f_message_pipe;
308  [MinVersion=7]
309  bool f_bool;
310  [MinVersion=9]
311  int16 f_int16;
312};
313
314struct MultiVersionStructV0 {
315  [MinVersion=0]
316  int32 f_int32;
317};
318
319struct MultiVersionStructV1 {
320  [MinVersion=0]
321  int32 f_int32;
322  [MinVersion=1]
323  Rect? f_rect;
324};
325
326struct MultiVersionStructV3 {
327  [MinVersion=0]
328  int32 f_int32;
329  [MinVersion=1]
330  Rect? f_rect;
331  [MinVersion=3]
332  string? f_string;
333};
334
335struct MultiVersionStructV5 {
336  [MinVersion=0]
337  int32 f_int32;
338  [MinVersion=1]
339  Rect? f_rect;
340  [MinVersion=3]
341  string? f_string;
342  [MinVersion=5]
343  array<int8>? f_array;
344};
345
346struct MultiVersionStructV7 {
347  [MinVersion=0]
348  int32 f_int32;
349  [MinVersion=1]
350  Rect? f_rect;
351  [MinVersion=3]
352  string? f_string;
353  [MinVersion=5]
354  array<int8>? f_array;
355  [MinVersion=7]
356  handle<message_pipe>? f_message_pipe;
357  [MinVersion=7]
358  bool f_bool;
359};
360
361// Used to verify that interfaces that are struct members can be defined in the
362// same file.
363
364interface SomeInterface {
365  SomeMethod(RectPair pair) => (RectPair other_pair);
366};
367
368struct ContainsInterface {
369  SomeInterface some_interface;
370};
371
372// Verify that a field can be called |other|.
373
374struct ContainsOther {
375  int32 other;
376};
377
378// Used to verify that structs can contain interface requests.
379
380struct ContainsInterfaceRequest {
381  SomeInterface& request;
382};
383