| 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 'mojo:bindings' as bindings; | 8 import 'mojo:bindings' as bindings; |
| 9 import 'mojo:core' as core; | 9 import 'mojo:core' as core; |
| 10 | 10 |
| 11 import 'package:mojo/dart/testing/expect.dart'; | 11 import 'package:mojo/dart/testing/expect.dart'; |
| 12 import 'package:mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.da
rt' as sample; | 12 import 'package:mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.da
rt' as sample; |
| 13 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart' a
s structs; | 13 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart' a
s structs; |
| 14 import 'package:mojo/public/interfaces/bindings/tests/rect.mojom.dart' as rect; | 14 import 'package:mojo/public/interfaces/bindings/tests/rect.mojom.dart' as rect; |
| 15 | 15 |
| 16 class ProviderImpl extends sample.Provider { | 16 class ProviderImpl implements sample.Provider { |
| 17 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) : super(endpoint) { | 17 sample.ProviderStub _stub; |
| 18 super.delegate = this; | 18 |
| 19 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 20 _stub = new sample.ProviderStub.fromEndpoint(endpoint) |
| 21 ..delegate = this |
| 22 ..listen(); |
| 19 } | 23 } |
| 20 | 24 |
| 21 echoString(String a, Function responseFactory) => | 25 echoString(String a, Function responseFactory) => |
| 22 new Future.value(responseFactory(a)); | 26 new Future.value(responseFactory(a)); |
| 23 | 27 |
| 24 echoStrings(String a, String b, Function responseFactory) => | 28 echoStrings(String a, String b, Function responseFactory) => |
| 25 new Future.value(responseFactory(a, b)); | 29 new Future.value(responseFactory(a, b)); |
| 26 | 30 |
| 27 echoMessagePipeHanlde(core.MojoHandle a, Function responseFactory) => | 31 echoMessagePipeHanlde(core.MojoHandle a, Function responseFactory) => |
| 28 new Future.value(responseFactory(a)); | 32 new Future.value(responseFactory(a)); |
| 29 | 33 |
| 30 echoEnum(int a, Function responseFactory) => | 34 echoEnum(int a, Function responseFactory) => |
| 31 new Future.value(responseFactory(a)); | 35 new Future.value(responseFactory(a)); |
| 32 } | 36 } |
| 33 | 37 |
| 34 | 38 |
| 35 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { | 39 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { |
| 36 var provider = new ProviderImpl(endpoint); | 40 new ProviderImpl(endpoint); |
| 37 provider.listen(); | |
| 38 } | 41 } |
| 39 | 42 |
| 40 | 43 |
| 41 Future<bool> testCallResponse() { | 44 Future<bool> testCallResponse() { |
| 42 var pipe = new core.MojoMessagePipe(); | 45 var pipe = new core.MojoMessagePipe(); |
| 43 var client = new sample.ProviderProxy(pipe.endpoints[0]); | 46 var clientProxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 47 var client = clientProxy.interface; |
| 44 var c = new Completer(); | 48 var c = new Completer(); |
| 45 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { | 49 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { |
| 46 client.echoString("hello!").then((echoStringResponse) { | 50 client.echoString("hello!").then((echoStringResponse) { |
| 47 Expect.equals("hello!", echoStringResponse.a); | 51 Expect.equals("hello!", echoStringResponse.a); |
| 48 }).then((_) { | 52 }).then((_) { |
| 49 client.echoStrings("hello", "mojo!").then((echoStringsResponse) { | 53 client.echoStrings("hello", "mojo!").then((echoStringsResponse) { |
| 50 Expect.equals("hello", echoStringsResponse.a); | 54 Expect.equals("hello", echoStringsResponse.a); |
| 51 Expect.equals("mojo!", echoStringsResponse.b); | 55 Expect.equals("mojo!", echoStringsResponse.b); |
| 52 client.close(); | 56 clientProxy.impl.close(); |
| 53 c.complete(true); | 57 c.complete(true); |
| 54 }); | 58 }); |
| 55 }); | 59 }); |
| 56 }); | 60 }); |
| 57 return c.future; | 61 return c.future; |
| 58 } | 62 } |
| 59 | 63 |
| 60 | 64 |
| 61 Future testAwaitCallResponse() async { | 65 Future testAwaitCallResponse() async { |
| 62 var pipe = new core.MojoMessagePipe(); | 66 var pipe = new core.MojoMessagePipe(); |
| 63 var client = new sample.ProviderProxy(pipe.endpoints[0]); | 67 var clientProxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 68 var client = clientProxy.interface; |
| 64 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); | 69 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); |
| 65 | 70 |
| 66 var echoStringResponse = await client.echoString("hello!"); | 71 var echoStringResponse = await client.echoString("hello!"); |
| 67 Expect.equals("hello!", echoStringResponse.a); | 72 Expect.equals("hello!", echoStringResponse.a); |
| 68 | 73 |
| 69 var echoStringsResponse = await client.echoStrings("hello", "mojo!"); | 74 var echoStringsResponse = await client.echoStrings("hello", "mojo!"); |
| 70 Expect.equals("hello", echoStringsResponse.a); | 75 Expect.equals("hello", echoStringsResponse.a); |
| 71 Expect.equals("mojo!", echoStringsResponse.b); | 76 Expect.equals("mojo!", echoStringsResponse.b); |
| 72 | 77 |
| 73 client.close(); | 78 clientProxy.impl.close(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 | 81 |
| 77 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => | 82 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => |
| 78 s.serializeWithHeader(new bindings.MessageHeader(0)); | 83 s.serializeWithHeader(new bindings.MessageHeader(0)); |
| 79 | 84 |
| 80 | 85 |
| 81 testSerializeNamedRegion() { | 86 testSerializeNamedRegion() { |
| 82 var r = new rect.Rect() | 87 var r = new rect.Rect() |
| 83 ..x = 1 | 88 ..x = 1 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 testSerializeNamedRegion(); | 121 testSerializeNamedRegion(); |
| 117 testSerializeArrayValueTypes(); | 122 testSerializeArrayValueTypes(); |
| 118 } | 123 } |
| 119 | 124 |
| 120 | 125 |
| 121 main() async { | 126 main() async { |
| 122 testSerializeStructs(); | 127 testSerializeStructs(); |
| 123 await testCallResponse(); | 128 await testCallResponse(); |
| 124 await testAwaitCallResponse(); | 129 await testAwaitCallResponse(); |
| 125 } | 130 } |
| OLD | NEW |