Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:isolate'; | 6 import 'dart:isolate'; |
| 7 import 'dart:typed_data'; | 7 import 'dart:typed_data'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:_testing/expect.dart'; | 10 import 'package:_testing/expect.dart'; |
| 11 import 'package:mojo/bindings.dart' as bindings; | 11 import 'package:mojo/bindings.dart' as bindings; |
| 12 import 'package:mojo/core.dart' as core; | 12 import 'package:mojo/core.dart' as core; |
| 13 import 'package:mojo/mojo/mojom_types.mojom.dart' as mojom_types; | |
| 14 import 'package:mojo/mojo/service_describer.mojom.dart' as service_describer; | |
| 13 import 'package:mojom/sample/sample_interfaces.mojom.dart' as sample; | 15 import 'package:mojom/sample/sample_interfaces.mojom.dart' as sample; |
| 14 import 'package:mojom/mojo/test/test_structs.mojom.dart' as structs; | 16 import 'package:mojom/mojo/test/test_structs.mojom.dart' as structs; |
| 15 import 'package:mojom/mojo/test/test_unions.mojom.dart' as unions; | 17 import 'package:mojom/mojo/test/test_unions.mojom.dart' as unions; |
| 18 import 'package:mojom/mojo/test/validation_test_interfaces.mojom.dart' | |
| 19 as validation; | |
| 16 import 'package:mojom/mojo/test/rect.mojom.dart' as rect; | 20 import 'package:mojom/mojo/test/rect.mojom.dart' as rect; |
| 17 import 'package:mojom/mojo/test/serialization_test_structs.mojom.dart' as serial ization; | 21 import 'package:mojom/mojo/test/serialization_test_structs.mojom.dart' |
| 18 import 'package:mojom/regression_tests/regression_tests.mojom.dart' as regressio n; | 22 as serialization; |
| 23 import 'package:mojom/regression_tests/regression_tests.mojom.dart' | |
| 24 as regression; | |
| 19 | 25 |
| 20 class ProviderImpl implements sample.Provider { | 26 class ProviderImpl implements sample.Provider { |
| 21 sample.ProviderStub _stub; | 27 sample.ProviderStub _stub; |
| 22 | 28 |
| 23 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { | 29 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 24 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this); | 30 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this); |
| 25 } | 31 } |
| 26 | 32 |
| 27 echoString(String a, Function responseFactory) => | 33 echoString(String a, Function responseFactory) => |
| 28 new Future.value(responseFactory(a)); | 34 new Future.value(responseFactory(a)); |
| 29 | 35 |
| 30 echoStrings(String a, String b, Function responseFactory) => | 36 echoStrings(String a, String b, Function responseFactory) => |
| 31 new Future.value(responseFactory(a, b)); | 37 new Future.value(responseFactory(a, b)); |
| 32 | 38 |
| 33 echoMessagePipeHanlde(core.MojoHandle a, Function responseFactory) => | 39 echoMessagePipeHandle(core.MojoHandle a, Function responseFactory) => |
| 34 new Future.value(responseFactory(a)); | 40 new Future.value(responseFactory(a)); |
| 35 | 41 |
| 36 echoEnum(sample.Enum a, Function responseFactory) => | 42 echoEnum(sample.Enum a, Function responseFactory) => |
| 37 new Future.value(responseFactory(a)); | 43 new Future.value(responseFactory(a)); |
| 38 } | 44 } |
| 39 | 45 |
| 40 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { | 46 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { |
| 41 new ProviderImpl(endpoint); | 47 new ProviderImpl(endpoint); |
| 42 } | 48 } |
| 43 | 49 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 ..height = 4; | 125 ..height = 4; |
| 120 | 126 |
| 121 var encodedRect = JSON.encode(r); | 127 var encodedRect = JSON.encode(r); |
| 122 var goldenEncoding = "{\"x\":1,\"y\":2,\"width\":3,\"height\":4}"; | 128 var goldenEncoding = "{\"x\":1,\"y\":2,\"width\":3,\"height\":4}"; |
| 123 Expect.equals(goldenEncoding, encodedRect); | 129 Expect.equals(goldenEncoding, encodedRect); |
| 124 } | 130 } |
| 125 | 131 |
| 126 testSerializeHandleToJSON() { | 132 testSerializeHandleToJSON() { |
| 127 var s = new serialization.Struct2(); | 133 var s = new serialization.Struct2(); |
| 128 | 134 |
| 129 Expect.throws(() => JSON.encode(s), | 135 Expect.throws( |
| 130 (e) => e.cause is bindings.MojoCodecError); | 136 () => JSON.encode(s), (e) => e.cause is bindings.MojoCodecError); |
| 131 } | 137 } |
| 132 | 138 |
| 133 testSerializeStructs() { | 139 testSerializeStructs() { |
| 134 testSerializeNamedRegion(); | 140 testSerializeNamedRegion(); |
| 135 testSerializeArrayValueTypes(); | 141 testSerializeArrayValueTypes(); |
| 136 testSerializeToJSON(); | 142 testSerializeToJSON(); |
| 137 testSerializeHandleToJSON(); | 143 testSerializeHandleToJSON(); |
| 138 } | 144 } |
| 139 | 145 |
| 140 testSerializePodUnions() { | 146 testSerializePodUnions() { |
| 141 var s = new unions.WrapperStruct() | 147 var s = new unions.WrapperStruct()..podUnion = new unions.PodUnion(); |
| 142 ..podUnion = new unions.PodUnion(); | |
| 143 s.podUnion.fUint32 = 32; | 148 s.podUnion.fUint32 = 32; |
| 144 | 149 |
| 145 Expect.equals(unions.PodUnionTag.fUint32, s.podUnion.tag); | 150 Expect.equals(unions.PodUnionTag.fUint32, s.podUnion.tag); |
| 146 Expect.equals(32, s.podUnion.fUint32); | 151 Expect.equals(32, s.podUnion.fUint32); |
| 147 | 152 |
| 148 var message = messageOfStruct(s); | 153 var message = messageOfStruct(s); |
| 149 var s2 = unions.WrapperStruct.deserialize(message.payload); | 154 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 150 | 155 |
| 151 Expect.equals(s.podUnion.fUint32, s2.podUnion.fUint32); | 156 Expect.equals(s.podUnion.fUint32, s2.podUnion.fUint32); |
| 152 } | 157 } |
| 153 | 158 |
| 154 testSerializeStructInUnion() { | 159 testSerializeStructInUnion() { |
| 155 var s = new unions.WrapperStruct() | 160 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 156 ..objectUnion = new unions.ObjectUnion(); | 161 s.objectUnion.fDummy = new unions.DummyStruct()..fInt8 = 8; |
| 157 s.objectUnion.fDummy = new unions.DummyStruct() | |
| 158 ..fInt8 = 8; | |
| 159 | 162 |
| 160 var message = messageOfStruct(s); | 163 var message = messageOfStruct(s); |
| 161 var s2 = unions.WrapperStruct.deserialize(message.payload); | 164 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 162 | 165 |
| 163 Expect.equals(s.objectUnion.fDummy.fInt8, s2.objectUnion.fDummy.fInt8); | 166 Expect.equals(s.objectUnion.fDummy.fInt8, s2.objectUnion.fDummy.fInt8); |
| 164 } | 167 } |
| 165 | 168 |
| 166 testSerializeArrayInUnion() { | 169 testSerializeArrayInUnion() { |
| 167 var s = new unions.WrapperStruct() | 170 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 168 ..objectUnion = new unions.ObjectUnion(); | |
| 169 s.objectUnion.fArrayInt8 = [1, 2, 3]; | 171 s.objectUnion.fArrayInt8 = [1, 2, 3]; |
| 170 | 172 |
| 171 var message = messageOfStruct(s); | 173 var message = messageOfStruct(s); |
| 172 var s2 = unions.WrapperStruct.deserialize(message.payload); | 174 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 173 | 175 |
| 174 Expect.listEquals(s.objectUnion.fArrayInt8, s2.objectUnion.fArrayInt8); | 176 Expect.listEquals(s.objectUnion.fArrayInt8, s2.objectUnion.fArrayInt8); |
| 175 } | 177 } |
| 176 | 178 |
| 177 testSerializeMapInUnion() { | 179 testSerializeMapInUnion() { |
| 178 var s = new unions.WrapperStruct() | 180 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 179 ..objectUnion = new unions.ObjectUnion(); | 181 s.objectUnion.fMapInt8 = {"one": 1, "two": 2,}; |
| 180 s.objectUnion.fMapInt8 = { | |
| 181 "one": 1, | |
| 182 "two": 2, | |
| 183 }; | |
| 184 | 182 |
| 185 var message = messageOfStruct(s); | 183 var message = messageOfStruct(s); |
| 186 var s2 = unions.WrapperStruct.deserialize(message.payload); | 184 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 187 | 185 |
| 188 Expect.equals(1, s.objectUnion.fMapInt8["one"]); | 186 Expect.equals(1, s.objectUnion.fMapInt8["one"]); |
| 189 Expect.equals(2, s.objectUnion.fMapInt8["two"]); | 187 Expect.equals(2, s.objectUnion.fMapInt8["two"]); |
| 190 } | 188 } |
| 191 | 189 |
| 192 testSerializeUnionInArray() { | 190 testSerializeUnionInArray() { |
| 193 var s = new unions.SmallStruct() | 191 var s = new unions.SmallStruct() |
| 194 ..podUnionArray = [ | 192 ..podUnionArray = [ |
| 195 new unions.PodUnion() | 193 new unions.PodUnion()..fUint16 = 16, |
| 196 ..fUint16 = 16, | 194 new unions.PodUnion()..fUint32 = 32, |
| 197 new unions.PodUnion() | |
| 198 ..fUint32 = 32, | |
| 199 ]; | 195 ]; |
| 200 | 196 |
| 201 var message = messageOfStruct(s); | 197 var message = messageOfStruct(s); |
| 202 | 198 |
| 203 var s2 = unions.SmallStruct.deserialize(message.payload); | 199 var s2 = unions.SmallStruct.deserialize(message.payload); |
| 204 | 200 |
| 205 Expect.equals(16, s2.podUnionArray[0].fUint16); | 201 Expect.equals(16, s2.podUnionArray[0].fUint16); |
| 206 Expect.equals(32, s2.podUnionArray[1].fUint32); | 202 Expect.equals(32, s2.podUnionArray[1].fUint32); |
| 207 } | 203 } |
| 208 | 204 |
| 209 testSerializeUnionInMap() { | 205 testSerializeUnionInMap() { |
| 210 var s = new unions.SmallStruct() | 206 var s = new unions.SmallStruct() |
| 211 ..podUnionMap = { | 207 ..podUnionMap = { |
| 212 'one': new unions.PodUnion() | 208 'one': new unions.PodUnion()..fUint16 = 16, |
| 213 ..fUint16 = 16, | 209 'two': new unions.PodUnion()..fUint32 = 32, |
| 214 'two': new unions.PodUnion() | |
| 215 ..fUint32 = 32, | |
| 216 }; | 210 }; |
| 217 | 211 |
| 218 var message = messageOfStruct(s); | 212 var message = messageOfStruct(s); |
| 219 | 213 |
| 220 var s2 = unions.SmallStruct.deserialize(message.payload); | 214 var s2 = unions.SmallStruct.deserialize(message.payload); |
| 221 | 215 |
| 222 Expect.equals(16, s2.podUnionMap['one'].fUint16); | 216 Expect.equals(16, s2.podUnionMap['one'].fUint16); |
| 223 Expect.equals(32, s2.podUnionMap['two'].fUint32); | 217 Expect.equals(32, s2.podUnionMap['two'].fUint32); |
| 224 } | 218 } |
| 225 | 219 |
| 226 testSerializeUnionInUnion() { | 220 testSerializeUnionInUnion() { |
| 227 var s = new unions.WrapperStruct() | 221 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 228 ..objectUnion = new unions.ObjectUnion(); | 222 s.objectUnion.fPodUnion = new unions.PodUnion()..fUint32 = 32; |
| 229 s.objectUnion.fPodUnion = new unions.PodUnion() | |
| 230 ..fUint32 = 32; | |
| 231 | 223 |
| 232 var message = messageOfStruct(s); | 224 var message = messageOfStruct(s); |
| 233 var s2 = unions.WrapperStruct.deserialize(message.payload); | 225 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 234 | 226 |
| 235 Expect.equals(32, s2.objectUnion.fPodUnion.fUint32); | 227 Expect.equals(32, s2.objectUnion.fPodUnion.fUint32); |
| 236 } | 228 } |
| 237 | 229 |
| 238 testUnionsToString() { | 230 testUnionsToString() { |
| 239 var podUnion = new unions.PodUnion(); | 231 var podUnion = new unions.PodUnion(); |
| 240 podUnion.fUint32 = 32; | 232 podUnion.fUint32 = 32; |
| 241 Expect.equals("PodUnion(fUint32: 32)", podUnion.toString()); | 233 Expect.equals("PodUnion(fUint32: 32)", podUnion.toString()); |
| 242 } | 234 } |
| 243 | 235 |
| 244 testUnions() { | 236 testUnions() { |
| 245 testSerializePodUnions(); | 237 testSerializePodUnions(); |
| 246 testSerializeStructInUnion(); | 238 testSerializeStructInUnion(); |
| 247 testSerializeArrayInUnion(); | 239 testSerializeArrayInUnion(); |
| 248 testSerializeMapInUnion(); | 240 testSerializeMapInUnion(); |
| 249 testSerializeUnionInArray(); | 241 testSerializeUnionInArray(); |
| 250 testSerializeUnionInMap(); | 242 testSerializeUnionInMap(); |
| 251 testSerializeUnionInUnion(); | 243 testSerializeUnionInUnion(); |
| 252 testUnionsToString(); | 244 testUnionsToString(); |
| 253 } | 245 } |
| 254 | 246 |
| 247 testValidateMojomTypes() { | |
| 248 testValidateEnumType(); | |
| 249 testValidateStructType(); | |
| 250 testValidateUnionType(); | |
| 251 testValidateTestStructWithImportType(); | |
| 252 testValidateInterfaceType(); | |
| 253 } | |
| 254 | |
| 255 // Test that mojom type descriptors were generated correctly for validation's | |
| 256 // BasicEnum. | |
| 257 testValidateEnumType() { | |
| 258 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | |
| 259 String enumID = "_validation_test_interfaces_BasicEnum__"; | |
| 260 String shortName = "BasicEnum"; | |
| 261 Map<String, int> labelMap = <String, int>{ | |
| 262 "A": 0, | |
| 263 "B": 1, | |
| 264 "C": 0, | |
| 265 "D": -3, | |
| 266 "E": 0xA, | |
| 267 }; | |
| 268 | |
| 269 // Extract the UserDefinedType from the descriptor using enumID. | |
| 270 mojom_types.UserDefinedType udt = testValidationDescriptor[enumID]; | |
| 271 Expect.isNotNull(udt); | |
| 272 | |
| 273 // The enumType must be present and declared properly. | |
| 274 mojom_types.MojomEnum me = udt.enumType; | |
| 275 Expect.isNotNull(me); | |
| 276 Expect.isNotNull(me.declData); | |
| 277 Expect.equals(me.declData.shortName, shortName); | |
| 278 | |
| 279 // Now compare the labels to verify that the enum labels match the expected on es. | |
|
rudominer
2015/11/13 02:18:18
line too long
alexfandrianto
2015/11/13 22:11:01
Done.
| |
| 280 Expect.equals(me.values.length, labelMap.length); | |
| 281 me.values.forEach((mojom_types.EnumValue ev) { | |
| 282 // Check that the declData is correct... | |
| 283 Expect.isNotNull(ev.declData); | |
| 284 Expect.isNotNull(labelMap[ev.declData.shortName]); | |
| 285 | |
| 286 // Check that the enumTypeKey matches the enumID. | |
| 287 Expect.equals(ev.enumTypeKey, enumID); | |
| 288 Expect.equals(ev.intValue, labelMap[ev.declData.shortName]); | |
| 289 }); | |
| 290 } | |
| 291 | |
| 292 // Test that mojom type descriptors were generated correctly for validation's | |
| 293 // StructE. | |
| 294 testValidateStructType() { | |
| 295 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | |
| 296 String structID = "_validation_test_interfaces_StructE__"; | |
| 297 String shortName = "StructE"; | |
| 298 Map<int, String> expectedFields = <int, String>{ | |
| 299 0: "StructD", | |
| 300 1: "DataPipeConsumer", | |
| 301 }; | |
| 302 | |
| 303 // Extract the UserDefinedType from the descriptor using structID. | |
| 304 mojom_types.UserDefinedType udt = testValidationDescriptor[structID]; | |
| 305 Expect.isNotNull(udt); | |
| 306 | |
| 307 // The structType must be present and declared properly. | |
| 308 mojom_types.MojomStruct ms = udt.structType; | |
| 309 Expect.isNotNull(ms); | |
| 310 Expect.isNotNull(ms.declData); | |
| 311 Expect.equals(ms.declData.shortName, shortName); | |
| 312 | |
| 313 // Now compare the fields to verify that the struct fields match the expected ones. | |
|
rudominer
2015/11/13 02:18:18
line too long
alexfandrianto
2015/11/13 22:11:01
Done.
| |
| 314 Expect.equals(ms.fields.length, expectedFields.length); | |
| 315 int i = 0; | |
| 316 ms.fields.forEach((mojom_types.StructField field) { | |
| 317 // Check that the declData is correct... | |
| 318 Expect.isNotNull(field.declData); | |
| 319 Expect.equals(expectedFields[i], field.declData.shortName); | |
| 320 | |
| 321 // Special case each field since we already know what should be inside. | |
| 322 switch (i) { | |
| 323 case 0: // This is a TypeReference to StructD. | |
| 324 mojom_types.Type t = field.type; | |
| 325 Expect.isNotNull(t.typeReference); | |
| 326 | |
| 327 // Type key, identifier, and expected reference id should match up. | |
| 328 mojom_types.TypeReference tr = t.typeReference; | |
| 329 String expectedRefID = "_validation_test_interfaces_StructD__"; | |
| 330 Expect.equals(expectedRefID, tr.identifier); | |
| 331 Expect.equals(expectedRefID, tr.typeKey); | |
| 332 break; | |
| 333 case 1: // This is a non-nullable DataPipeConsumer HandleType. | |
| 334 mojom_types.Type t = field.type; | |
| 335 Expect.isNotNull(t.handleType); | |
| 336 | |
| 337 mojom_types.HandleType ht = t.handleType; | |
| 338 Expect.isFalse(ht.nullable); | |
| 339 Expect.equals(mojom_types.HandleTypeKind.DATA_PIPE_CONSUMER, ht.kind); | |
| 340 break; | |
| 341 default: | |
| 342 assert(false); | |
| 343 } | |
| 344 | |
| 345 i++; | |
| 346 }); | |
| 347 } | |
| 348 | |
| 349 // Test that mojom type descriptors were generated correctly for validation's | |
| 350 // UnionB. | |
| 351 testValidateUnionType() { | |
| 352 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | |
| 353 String unionID = "_validation_test_interfaces_UnionB__"; | |
| 354 String shortName = "UnionB"; | |
| 355 Map<int, String> expectedFields = <int, String>{ | |
| 356 0: "A", | |
| 357 1: "B", | |
| 358 2: "C", | |
| 359 3: "D", | |
| 360 }; | |
| 361 | |
| 362 // Extract the UserDefinedType from the descriptor using unionID. | |
| 363 mojom_types.UserDefinedType udt = testValidationDescriptor[unionID]; | |
| 364 Expect.isNotNull(udt); | |
| 365 | |
| 366 // The unionType must be present and declared properly. | |
| 367 mojom_types.MojomUnion mu = udt.unionType; | |
| 368 Expect.isNotNull(mu); | |
| 369 Expect.isNotNull(mu.declData); | |
| 370 Expect.equals(mu.declData.shortName, shortName); | |
| 371 | |
| 372 // Now compare the fields to verify that the union fields match the expected o nes. | |
| 373 Expect.equals(mu.fields.length, expectedFields.length); | |
| 374 mu.fields.forEach((mojom_types.UnionField field) { | |
| 375 int ordinal = field.tag; | |
| 376 | |
| 377 // Check that the declData is correct... | |
| 378 Expect.isNotNull(field.declData); | |
| 379 Expect.equals(expectedFields[ordinal], field.declData.shortName); | |
| 380 | |
| 381 // Special: It turns out that all types are simple types. | |
| 382 mojom_types.Type t = field.type; | |
| 383 Expect.isNotNull(t.simpleType); | |
| 384 mojom_types.SimpleType st = t.simpleType; | |
| 385 | |
| 386 // Special case each field since we already know what should be inside. | |
| 387 switch (ordinal) { | |
| 388 case 0: // Uint16 | |
| 389 Expect.equals(st, mojom_types.SimpleType.UINT16); | |
| 390 break; | |
| 391 case 1: // Uint32 | |
| 392 case 3: | |
| 393 Expect.equals(st, mojom_types.SimpleType.UINT32); | |
| 394 break; | |
| 395 case 2: // Uint64 | |
| 396 Expect.equals(st, mojom_types.SimpleType.UINT64); | |
| 397 break; | |
| 398 default: | |
| 399 assert(false); | |
| 400 } | |
| 401 }); | |
| 402 } | |
| 403 | |
| 404 // Test that mojom type descriptors were generated correctly for validation's | |
| 405 // IncludingStruct, which contains a union imported from test_included_unions. | |
| 406 testValidateTestStructWithImportType() { | |
| 407 var testUnionsDescriptor = unions.getAllMojomTypeDefinitions(); | |
| 408 String structID = "_test_unions_IncludingStruct__"; | |
| 409 String shortName = "IncludingStruct"; | |
| 410 Map<int, String> expectedFields = <int, String>{0: "A",}; | |
| 411 | |
| 412 // Extract the UserDefinedType from the descriptor using structID. | |
| 413 mojom_types.UserDefinedType udt = testUnionsDescriptor[structID]; | |
| 414 Expect.isNotNull(udt); | |
| 415 | |
| 416 // The structType must be present and declared properly. | |
| 417 mojom_types.MojomStruct ms = udt.structType; | |
| 418 Expect.isNotNull(ms); | |
| 419 Expect.isNotNull(ms.declData); | |
| 420 Expect.equals(ms.declData.shortName, shortName); | |
| 421 | |
| 422 // Now compare the fields to verify that the struct fields match the expected ones. | |
| 423 Expect.equals(ms.fields.length, expectedFields.length); | |
| 424 int i = 0; | |
| 425 ms.fields.forEach((mojom_types.StructField field) { | |
| 426 // Check that the declData is correct... | |
| 427 Expect.isNotNull(field.declData); | |
| 428 Expect.equals(expectedFields[i], field.declData.shortName); | |
| 429 | |
| 430 // Special case each field since we already know what should be inside. | |
| 431 switch (i) { | |
| 432 case 0: // This is a TypeReference to a Union. | |
| 433 mojom_types.Type t = field.type; | |
| 434 Expect.isNotNull(t.typeReference); | |
| 435 | |
| 436 // Type key, identifier, and expected reference id should match up. | |
| 437 mojom_types.TypeReference tr = t.typeReference; | |
| 438 String expectedRefID = "_test_included_unions_IncludedUnion__"; | |
| 439 Expect.equals(expectedRefID, tr.identifier); | |
| 440 Expect.equals(expectedRefID, tr.typeKey); | |
| 441 break; | |
| 442 default: | |
| 443 assert(false); | |
| 444 } | |
| 445 | |
| 446 i++; | |
| 447 }); | |
| 448 } | |
| 449 | |
| 450 // Used by the testValidateInterfaceType test. | |
| 451 class _BoundsCheckTestInterfaceFakeImplementation | |
| 452 extends validation.BoundsCheckTestInterface { | |
| 453 dynamic method0(int param0, [Function responseFactory = null]) {} | |
| 454 void method1(int param0) {} | |
| 455 } | |
| 456 | |
| 457 // Test that mojom type descriptors were generated correctly for validation's | |
| 458 // BoundsCheckTestInterface. | |
| 459 testValidateInterfaceType() { | |
| 460 // interface BoundsCheckTestInterface { | |
| 461 // Method0(uint8 param0) => (uint8 param0); | |
| 462 // Method1(uint8 param0); | |
| 463 // }; | |
| 464 | |
| 465 var testValidationDescriptor = validation.getAllMojomTypeDefinitions(); | |
| 466 String interfaceID = "_validation_test_interfaces_BoundsCheckTestInterface__"; | |
| 467 String shortName = "BoundsCheckTestInterface"; | |
| 468 Map<int, String> methodMap = <int, String>{0: "Method0", 1: "Method1",}; | |
| 469 | |
| 470 mojom_types.UserDefinedType udt = testValidationDescriptor[interfaceID]; | |
| 471 Expect.isNotNull(udt); | |
| 472 | |
| 473 mojom_types.MojomInterface mi = udt.interfaceType; | |
| 474 Expect.isNotNull(mi); | |
| 475 | |
| 476 _checkMojomInterface(mi, shortName, methodMap); | |
| 477 | |
| 478 var bcti_p = new validation.BoundsCheckTestInterfaceProxyImpl.unbound(); | |
| 479 var bcti_f = new _BoundsCheckTestInterfaceFakeImplementation(); | |
| 480 | |
| 481 _checkServiceDescription( | |
| 482 bcti_p.serviceDescription, interfaceID, shortName, methodMap); | |
| 483 _checkServiceDescription( | |
| 484 bcti_f.serviceDescription, interfaceID, shortName, methodMap); | |
| 485 } | |
| 486 | |
| 487 _checkServiceDescription(service_describer.ServiceDescription sd, | |
| 488 String interfaceID, String shortName, Map<int, String> methodMap) { | |
| 489 // Check the top level interface, which must pass _checkMojomInterface. | |
| 490 mojom_types.MojomInterface mi = sd.getTopLevelInterface(); | |
| 491 _checkMojomInterface(mi, shortName, methodMap); | |
| 492 | |
| 493 // Try out sd.GetTypeDefinition with the given interfaceID. | |
| 494 mojom_types.UserDefinedType udt = sd.getTypeDefinition(interfaceID); | |
| 495 Expect.isNotNull(udt.interfaceType); | |
| 496 _checkMojomInterface(udt.interfaceType, shortName, methodMap); | |
| 497 | |
| 498 // Check all type definitions. Reflect-wise, all data inside should match the | |
| 499 // imported Descriptor. | |
| 500 var actualDescriptions = sd.getAllTypeDefinitions(); | |
| 501 var expectedDescriptions = validation.getAllMojomTypeDefinitions(); | |
| 502 Expect.mapEquals(actualDescriptions, expectedDescriptions); | |
| 503 } | |
| 504 | |
| 505 _checkMojomInterface(mojom_types.MojomInterface mi, String shortName, | |
| 506 Map<int, String> methodMap) { | |
| 507 // check the generated short name. | |
| 508 Expect.isNotNull(mi.declData); | |
| 509 Expect.equals(mi.declData.shortName, shortName); | |
| 510 | |
| 511 // Verify that the number of methods matches the expected ones. | |
| 512 Expect.equals(mi.methods.length, methodMap.length); | |
| 513 | |
| 514 // Each MojomMethod must be named, typed, and "ordinal"ed correctly. | |
| 515 mi.methods.forEach((int ordinal, mojom_types.MojomMethod method) { | |
| 516 Expect.isNotNull(method.declData); | |
| 517 Expect.equals(methodMap[ordinal], method.declData.shortName); | |
| 518 | |
| 519 // Special case each method since we know what's inside. | |
| 520 switch (ordinal) { | |
| 521 case 0: // Has request and response params. | |
| 522 // Request is a single uint8 input. | |
| 523 mojom_types.MojomStruct params = method.parameters; | |
| 524 Expect.equals(params.fields.length, 1); | |
| 525 Expect.equals( | |
| 526 params.fields[0].type.simpleType, mojom_types.SimpleType.UINT8); | |
| 527 | |
| 528 // Response is a single uint8 output. | |
| 529 mojom_types.MojomStruct response = method.responseParams; | |
| 530 Expect.isNotNull(response); | |
| 531 Expect.equals(response.fields.length, 1); | |
| 532 Expect.equals( | |
| 533 response.fields[0].type.simpleType, mojom_types.SimpleType.UINT8); | |
| 534 break; | |
| 535 case 1: // Only has request params. | |
| 536 // Request is a single uint8 input. | |
| 537 mojom_types.MojomStruct params = method.parameters; | |
| 538 Expect.equals(params.fields.length, 1); | |
| 539 Expect.equals( | |
| 540 params.fields[0].type.simpleType, mojom_types.SimpleType.UINT8); | |
| 541 | |
| 542 // Response is a single uint8 output. | |
| 543 mojom_types.MojomStruct response = method.responseParams; | |
| 544 Expect.isNull(response); | |
| 545 break; | |
| 546 default: | |
| 547 assert(false); | |
| 548 } | |
| 549 }); | |
| 550 } | |
| 551 | |
| 255 class CheckEnumCapsImpl implements regression.CheckEnumCaps { | 552 class CheckEnumCapsImpl implements regression.CheckEnumCaps { |
| 256 regression.CheckEnumCapsStub _stub; | 553 regression.CheckEnumCapsStub _stub; |
| 257 | 554 |
| 258 CheckEnumCapsImpl(core.MojoMessagePipeEndpoint endpoint) { | 555 CheckEnumCapsImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 259 _stub = new regression.CheckEnumCapsStub.fromEndpoint(endpoint, this); | 556 _stub = new regression.CheckEnumCapsStub.fromEndpoint(endpoint, this); |
| 260 } | 557 } |
| 261 | 558 |
| 262 setEnumWithInternalAllCaps(regression.EnumWithInternalAllCaps e) {} | 559 setEnumWithInternalAllCaps(regression.EnumWithInternalAllCaps e) {} |
| 263 } | 560 } |
| 264 | 561 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 proxy.impl.onError = () => testCompleter.complete(true); | 603 proxy.impl.onError = () => testCompleter.complete(true); |
| 307 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); | 604 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); |
| 308 return testCompleter.future.then((b) { | 605 return testCompleter.future.then((b) { |
| 309 Expect.isTrue(b); | 606 Expect.isTrue(b); |
| 310 }); | 607 }); |
| 311 } | 608 } |
| 312 | 609 |
| 313 main() async { | 610 main() async { |
| 314 testSerializeStructs(); | 611 testSerializeStructs(); |
| 315 testUnions(); | 612 testUnions(); |
| 613 testValidateMojomTypes(); | |
| 316 await testEnums(); | 614 await testEnums(); |
| 317 await testCallResponse(); | 615 await testCallResponse(); |
| 318 await testAwaitCallResponse(); | 616 await testAwaitCallResponse(); |
| 319 await runOnClosedTest(); | 617 await runOnClosedTest(); |
| 320 } | 618 } |
| OLD | NEW |