Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: mojo/dart/unittests/embedder_tests/bindings_generation_test.dart

Issue 2006093002: Dart: Futures -> Callbacks. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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:mojo/bindings.dart' as bindings; 10 import 'package:mojo/bindings.dart' as bindings;
(...skipping 18 matching lines...) Expand all
29 import 'package:_mojo_for_test_only/sample/sample_interfaces.mojom.dart' 29 import 'package:_mojo_for_test_only/sample/sample_interfaces.mojom.dart'
30 as sample; 30 as sample;
31 31
32 class ProviderImpl implements sample.Provider { 32 class ProviderImpl implements sample.Provider {
33 sample.ProviderStub _stub; 33 sample.ProviderStub _stub;
34 34
35 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { 35 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) {
36 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this); 36 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this);
37 } 37 }
38 38
39 echoString(String a, Function responseFactory) => 39 void echoString(String a, Function response) {
40 new Future.value(responseFactory(a)); 40 response(a);
41 }
41 42
42 echoStrings(String a, String b, Function responseFactory) => 43 void echoStrings(String a, String b, Function response) {
43 new Future.value(responseFactory(a, b)); 44 response(a, b);
45 }
44 46
45 echoMessagePipeHandle(core.MojoHandle a, Function responseFactory) => 47 void echoMessagePipeHandle(core.MojoHandle a, Function responseFactory) {
46 new Future.value(responseFactory(a)); 48 response(a);
49 }
47 50
48 echoEnum(sample.Enum a, Function responseFactory) => 51 void echoEnum(sample.Enum a, Function response) {
49 new Future.value(responseFactory(a)); 52 response(a);
53 }
50 } 54 }
51 55
52 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { 56 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) {
53 new ProviderImpl(endpoint); 57 new ProviderImpl(endpoint);
54 } 58 }
55 59
56 Future<bool> testCallResponse() {
57 var pipe = new core.MojoMessagePipe();
58 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]);
59 var c = new Completer();
60 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) {
61 client.echoString("hello!").then((echoStringResponse) {
62 Expect.equals("hello!", echoStringResponse.a);
63 }).then((_) {
64 client.echoStrings("hello", "mojo!").then((echoStringsResponse) {
65 Expect.equals("hello", echoStringsResponse.a);
66 Expect.equals("mojo!", echoStringsResponse.b);
67 client.close().then((_) {
68 c.complete(true);
69 });
70 });
71 });
72 });
73 return c.future;
74 }
75 60
76 Future testAwaitCallResponse() async { 61 Future testAwaitCallResponse() async {
77 var pipe = new core.MojoMessagePipe(); 62 var pipe = new core.MojoMessagePipe();
78 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); 63 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]);
79 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); 64 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]);
80 65
81 var echoStringResponse = await client.echoString("hello!"); 66 var c = new Completer();
82 Expect.equals("hello!", echoStringResponse.a); 67 client.echoString("hello!", (String response) {
68 c.complete(response);
69 });
70 var echoStringResponse = await client.responseOrError(c.future);
71 Expect.equals("hello!", echoStringResponse);
83 72
84 var echoStringsResponse = await client.echoStrings("hello", "mojo!"); 73 c = new Completer();
85 Expect.equals("hello", echoStringsResponse.a); 74 client.echoStrings("hello", "mojo!", (String r1, String r2) {
86 Expect.equals("mojo!", echoStringsResponse.b); 75 c.complete([r1, r2]);
76 });
77 var echoStringsResponse = await client.responseOrError(c.future);
78 Expect.equals("hello", echoStringsResponse[0]);
79 Expect.equals("mojo!", echoStringsResponse[1]);
87 80
88 await client.close(); 81 await client.close();
89 } 82 }
90 83
91 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => 84 bindings.ServiceMessage messageOfStruct(bindings.Struct s) =>
92 s.serializeWithHeader(new bindings.MessageHeader(0)); 85 s.serializeWithHeader(new bindings.MessageHeader(0));
93 86
94 testSerializeNamedRegion() { 87 testSerializeNamedRegion() {
95 var r = new rect.Rect() 88 var r = new rect.Rect()
96 ..x = 1 89 ..x = 1
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 }); 320 });
328 } 321 }
329 322
330 class Regression551Impl implements regression.Regression551 { 323 class Regression551Impl implements regression.Regression551 {
331 regression.Regression551Stub _stub; 324 regression.Regression551Stub _stub;
332 325
333 Regression551Impl(core.MojoMessagePipeEndpoint endpoint) { 326 Regression551Impl(core.MojoMessagePipeEndpoint endpoint) {
334 _stub = new regression.Regression551Stub.fromEndpoint(endpoint, this); 327 _stub = new regression.Regression551Stub.fromEndpoint(endpoint, this);
335 } 328 }
336 329
337 dynamic get(List<String> keyPrefixes, Function responseFactory) => 330 void get(List<String> keyPrefixes, Function response) {
338 responseFactory(0); 331 response(0);
332 }
339 } 333 }
340 334
341 void regression551Isolate(core.MojoMessagePipeEndpoint endpoint) { 335 void regression551Isolate(core.MojoMessagePipeEndpoint endpoint) {
342 new Regression551Impl(endpoint); 336 new Regression551Impl(endpoint);
343 } 337 }
344 338
345 Future<bool> testRegression551() { 339 Future<bool> testRegression551() {
346 var pipe = new core.MojoMessagePipe(); 340 var pipe = new core.MojoMessagePipe();
347 var client = new regression.Regression551Proxy.fromEndpoint(pipe.endpoints[0]) ; 341 var client = new regression.Regression551Proxy.fromEndpoint(pipe.endpoints[0]) ;
348 var c = new Completer(); 342 var c = new Completer();
349 Isolate.spawn(regression551Isolate, pipe.endpoints[1]).then((_) { 343 Isolate.spawn(regression551Isolate, pipe.endpoints[1]).then((_) {
350 client.get(["hello!"]).then((response) { 344 client.get(["hello!"], (int response) {
351 Expect.equals(0, response.result); 345 Expect.equals(0, response);
352 client.close().then((_) { 346 client.close().then((_) {
353 c.complete(true); 347 c.complete(true);
354 }); 348 });
355 }); 349 });
356 }); 350 });
357 return c.future; 351 return c.future;
358 } 352 }
359 353
360 class ServiceNameImpl implements regression.ServiceName { 354 class ServiceNameImpl implements regression.ServiceName {
361 regression.ServiceNameStub _stub; 355 regression.ServiceNameStub _stub;
362 356
363 ServiceNameImpl(core.MojoMessagePipeEndpoint endpoint) { 357 ServiceNameImpl(core.MojoMessagePipeEndpoint endpoint) {
364 _stub = new regression.ServiceNameStub.fromEndpoint(endpoint, this); 358 _stub = new regression.ServiceNameStub.fromEndpoint(endpoint, this);
365 } 359 }
366 360
367 dynamic serviceName_(Function responseFactory) => 361 void serviceName_(Function response) {
368 responseFactory(regression.ServiceName.serviceName); 362 response(regression.ServiceName.serviceName);
363 }
369 } 364 }
370 365
371 void serviceNameIsolate(core.MojoMessagePipeEndpoint endpoint) { 366 void serviceNameIsolate(core.MojoMessagePipeEndpoint endpoint) {
372 new ServiceNameImpl(endpoint); 367 new ServiceNameImpl(endpoint);
373 } 368 }
374 369
375 Future<bool> testServiceName() { 370 Future<bool> testServiceName() {
376 var pipe = new core.MojoMessagePipe(); 371 var pipe = new core.MojoMessagePipe();
377 var client = new regression.ServiceNameProxy.fromEndpoint(pipe.endpoints[0]); 372 var client = new regression.ServiceNameProxy.fromEndpoint(pipe.endpoints[0]);
378 var c = new Completer(); 373 var c = new Completer();
379 Isolate.spawn(serviceNameIsolate, pipe.endpoints[1]).then((_) { 374 Isolate.spawn(serviceNameIsolate, pipe.endpoints[1]).then((_) {
380 client.serviceName_().then((response) { 375 client.serviceName_((String response) {
381 Expect.equals(ServiceName.serviceName, response.serviceName_); 376 Expect.equals(ServiceName.serviceName, response);
382 client.close().then((_) { 377 client.close().then((_) {
383 c.complete(true); 378 c.complete(true);
384 }); 379 });
385 }); 380 });
386 }); 381 });
387 return c.future; 382 return c.future;
388 } 383 }
389 384
390 385
391 testCamelCase() { 386 testCamelCase() {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 653
659 _checkServiceDescription( 654 _checkServiceDescription(
660 boundsCheckStubDescription, interfaceID, shortName, fullIdentifier, 655 boundsCheckStubDescription, interfaceID, shortName, fullIdentifier,
661 methodMap); 656 methodMap);
662 } 657 }
663 658
664 _checkServiceDescription(service_describer.ServiceDescription sd, 659 _checkServiceDescription(service_describer.ServiceDescription sd,
665 String interfaceID, String shortName, String fullIdentifier, 660 String interfaceID, String shortName, String fullIdentifier,
666 Map<int, String> methodMap) { 661 Map<int, String> methodMap) {
667 // Check the top level interface, which must pass _checkMojomInterface. 662 // Check the top level interface, which must pass _checkMojomInterface.
668 Function identity = (v) => v; 663 Object sdValue;
669 mojom_types.MojomInterface mi = sd.getTopLevelInterface(identity); 664 Function setSdValue = (v) {
665 sdValue = v;
666 };
667 sd.getTopLevelInterface(setSdValue);
668 mojom_types.MojomInterface mi = sdValue;
670 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap); 669 _checkMojomInterface(mi, shortName, fullIdentifier, methodMap);
671 670
672 // Try out sd.GetTypeDefinition with the given interfaceID. 671 // Try out sd.GetTypeDefinition with the given interfaceID.
673 mojom_types.UserDefinedType udt = sd.getTypeDefinition(interfaceID, identity); 672 sd.getTypeDefinition(interfaceID, setSdValue);
673 mojom_types.UserDefinedType udt = sdValue;
674 Expect.isNotNull(udt.interfaceType); 674 Expect.isNotNull(udt.interfaceType);
675 _checkMojomInterface(udt.interfaceType, shortName, fullIdentifier, methodMap); 675 _checkMojomInterface(udt.interfaceType, shortName, fullIdentifier, methodMap);
676 676
677 // Check all type definitions. Reflect-wise, all data inside should match the 677 // Check all type definitions. Reflect-wise, all data inside should match the
678 // imported Descriptor. 678 // imported Descriptor.
679 var actualDescriptions = sd.getAllTypeDefinitions(identity); 679 sd.getAllTypeDefinitions(setSdValue);
680 var actualDescriptions = sdValue;
680 var expectedDescriptions = validation.getAllMojomTypeDefinitions(); 681 var expectedDescriptions = validation.getAllMojomTypeDefinitions();
681 Expect.mapEquals(actualDescriptions, expectedDescriptions); 682 Expect.mapEquals(actualDescriptions, expectedDescriptions);
682 } 683 }
683 684
684 _checkMojomInterface(mojom_types.MojomInterface mi, String shortName, 685 _checkMojomInterface(mojom_types.MojomInterface mi, String shortName,
685 String fullIdentifier, Map<int, String> methodMap) { 686 String fullIdentifier, Map<int, String> methodMap) {
686 // check the generated short name. 687 // check the generated short name.
687 Expect.isNotNull(mi.declData); 688 Expect.isNotNull(mi.declData);
688 Expect.equals(mi.declData.shortName, shortName); 689 Expect.equals(mi.declData.shortName, shortName);
689 Expect.equals(mi.declData.fullIdentifier, fullIdentifier); 690 Expect.equals(mi.declData.fullIdentifier, fullIdentifier);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 744 }
744 } 745 }
745 746
746 main() async { 747 main() async {
747 testSerializeStructs(); 748 testSerializeStructs();
748 testUnions(); 749 testUnions();
749 testValidateMojomTypes(); 750 testValidateMojomTypes();
750 testCamelCase(); 751 testCamelCase();
751 testSerializeErrorMessage(); 752 testSerializeErrorMessage();
752 await testEnums(); 753 await testEnums();
753 await testCallResponse();
754 await testAwaitCallResponse(); 754 await testAwaitCallResponse();
755 await runOnClosedTest(); 755 await runOnClosedTest();
756 await testRegression551(); 756 await testRegression551();
757 await testServiceName(); 757 await testServiceName();
758 } 758 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698