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