| 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 client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 44 var c = new Completer(); | 47 var c = new Completer(); |
| 45 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { | 48 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { |
| 46 client.echoString("hello!").then((echoStringResponse) { | 49 client.interface.echoString("hello!").then((echoStringResponse) { |
| 47 Expect.equals("hello!", echoStringResponse.a); | 50 Expect.equals("hello!", echoStringResponse.a); |
| 48 }).then((_) { | 51 }).then((_) { |
| 49 client.echoStrings("hello", "mojo!").then((echoStringsResponse) { | 52 client.interface.echoStrings("hello", "mojo!").then((echoStringsResponse)
{ |
| 50 Expect.equals("hello", echoStringsResponse.a); | 53 Expect.equals("hello", echoStringsResponse.a); |
| 51 Expect.equals("mojo!", echoStringsResponse.b); | 54 Expect.equals("mojo!", echoStringsResponse.b); |
| 52 client.close(); | 55 client.impl.close(); |
| 53 c.complete(true); | 56 c.complete(true); |
| 54 }); | 57 }); |
| 55 }); | 58 }); |
| 56 }); | 59 }); |
| 57 return c.future; | 60 return c.future; |
| 58 } | 61 } |
| 59 | 62 |
| 60 | 63 |
| 61 Future testAwaitCallResponse() async { | 64 Future testAwaitCallResponse() async { |
| 62 var pipe = new core.MojoMessagePipe(); | 65 var pipe = new core.MojoMessagePipe(); |
| 63 var client = new sample.ProviderProxy(pipe.endpoints[0]); | 66 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 64 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); | 67 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); |
| 65 | 68 |
| 66 var echoStringResponse = await client.echoString("hello!"); | 69 var echoStringResponse = await client.interface.echoString("hello!"); |
| 67 Expect.equals("hello!", echoStringResponse.a); | 70 Expect.equals("hello!", echoStringResponse.a); |
| 68 | 71 |
| 69 var echoStringsResponse = await client.echoStrings("hello", "mojo!"); | 72 var echoStringsResponse = |
| 73 await client.interface.echoStrings("hello", "mojo!"); |
| 70 Expect.equals("hello", echoStringsResponse.a); | 74 Expect.equals("hello", echoStringsResponse.a); |
| 71 Expect.equals("mojo!", echoStringsResponse.b); | 75 Expect.equals("mojo!", echoStringsResponse.b); |
| 72 | 76 |
| 73 client.close(); | 77 client.impl.close(); |
| 74 } | 78 } |
| 75 | 79 |
| 76 | 80 |
| 77 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => | 81 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => |
| 78 s.serializeWithHeader(new bindings.MessageHeader(0)); | 82 s.serializeWithHeader(new bindings.MessageHeader(0)); |
| 79 | 83 |
| 80 | 84 |
| 81 testSerializeNamedRegion() { | 85 testSerializeNamedRegion() { |
| 82 var r = new rect.Rect() | 86 var r = new rect.Rect() |
| 83 ..x = 1 | 87 ..x = 1 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 testSerializeNamedRegion(); | 120 testSerializeNamedRegion(); |
| 117 testSerializeArrayValueTypes(); | 121 testSerializeArrayValueTypes(); |
| 118 } | 122 } |
| 119 | 123 |
| 120 | 124 |
| 121 main() async { | 125 main() async { |
| 122 testSerializeStructs(); | 126 testSerializeStructs(); |
| 123 await testCallResponse(); | 127 await testCallResponse(); |
| 124 await testAwaitCallResponse(); | 128 await testAwaitCallResponse(); |
| 125 } | 129 } |
| OLD | NEW |