| 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' |
| 13 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart' a
s structs; | 13 as sample; |
| 14 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart' |
| 15 as structs; |
| 14 import 'package:mojo/public/interfaces/bindings/tests/rect.mojom.dart' as rect; | 16 import 'package:mojo/public/interfaces/bindings/tests/rect.mojom.dart' as rect; |
| 15 | 17 |
| 16 class ProviderImpl implements sample.Provider { | 18 class ProviderImpl implements sample.Provider { |
| 17 sample.ProviderStub _stub; | 19 sample.ProviderStub _stub; |
| 18 | 20 |
| 19 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { | 21 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 20 _stub = new sample.ProviderStub.fromEndpoint(endpoint) | 22 _stub = new sample.ProviderStub.fromEndpoint(endpoint, impl: this); |
| 21 ..delegate = this | |
| 22 ..listen(); | |
| 23 } | 23 } |
| 24 | 24 |
| 25 echoString(String a, Function responseFactory) => | 25 echoString(String a, Function responseFactory) => |
| 26 new Future.value(responseFactory(a)); | 26 new Future.value(responseFactory(a)); |
| 27 | 27 |
| 28 echoStrings(String a, String b, Function responseFactory) => | 28 echoStrings(String a, String b, Function responseFactory) => |
| 29 new Future.value(responseFactory(a, b)); | 29 new Future.value(responseFactory(a, b)); |
| 30 | 30 |
| 31 echoMessagePipeHanlde(core.MojoHandle a, Function responseFactory) => | 31 echoMessagePipeHanlde(core.MojoHandle a, Function responseFactory) => |
| 32 new Future.value(responseFactory(a)); | 32 new Future.value(responseFactory(a)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 62 | 62 |
| 63 | 63 |
| 64 Future testAwaitCallResponse() async { | 64 Future testAwaitCallResponse() async { |
| 65 var pipe = new core.MojoMessagePipe(); | 65 var pipe = new core.MojoMessagePipe(); |
| 66 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); | 66 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 67 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); | 67 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); |
| 68 | 68 |
| 69 var echoStringResponse = await client.ptr.echoString("hello!"); | 69 var echoStringResponse = await client.ptr.echoString("hello!"); |
| 70 Expect.equals("hello!", echoStringResponse.a); | 70 Expect.equals("hello!", echoStringResponse.a); |
| 71 | 71 |
| 72 var echoStringsResponse = | 72 var echoStringsResponse = await client.ptr.echoStrings("hello", "mojo!"); |
| 73 await client.ptr.echoStrings("hello", "mojo!"); | |
| 74 Expect.equals("hello", echoStringsResponse.a); | 73 Expect.equals("hello", echoStringsResponse.a); |
| 75 Expect.equals("mojo!", echoStringsResponse.b); | 74 Expect.equals("mojo!", echoStringsResponse.b); |
| 76 | 75 |
| 77 client.close(); | 76 client.close(); |
| 78 } | 77 } |
| 79 | 78 |
| 80 | 79 |
| 81 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => | 80 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => |
| 82 s.serializeWithHeader(new bindings.MessageHeader(0)); | 81 s.serializeWithHeader(new bindings.MessageHeader(0)); |
| 83 | 82 |
| 84 | 83 |
| 85 testSerializeNamedRegion() { | 84 testSerializeNamedRegion() { |
| 86 var r = new rect.Rect() | 85 var r = new rect.Rect() |
| 87 ..x = 1 | 86 ..x = 1 |
| 88 ..y = 2 | 87 ..y = 2 |
| 89 ..width = 3 | 88 ..width = 3 |
| 90 ..height = 4; | 89 ..height = 4; |
| 91 var namedRegion = new structs.NamedRegion() | 90 var namedRegion = new structs.NamedRegion() |
| 92 ..name = "name" | 91 ..name = "name" |
| 93 ..rects = [r]; | 92 ..rects = [r]; |
| 94 var message = messageOfStruct(namedRegion); | 93 var message = messageOfStruct(namedRegion); |
| 95 var namedRegion2 = structs.NamedRegion.deserialize(message.payload); | 94 var namedRegion2 = structs.NamedRegion.deserialize(message.payload); |
| 96 Expect.equals(namedRegion.name, namedRegion2.name); | 95 Expect.equals(namedRegion.name, namedRegion2.name); |
| 97 } | 96 } |
| 98 | 97 |
| 99 | 98 |
| 100 testSerializeArrayValueTypes() { | 99 testSerializeArrayValueTypes() { |
| 101 var arrayValues = new structs.ArrayValueTypes() | 100 var arrayValues = new structs.ArrayValueTypes() |
| 102 ..f0 = [0, 1, -1, 0x7f, -0x10] | 101 ..f0 = [0, 1, -1, 0x7f, -0x10] |
| 103 ..f1 = [0, 1, -1, 0x7fff, -0x1000] | 102 ..f1 = [0, 1, -1, 0x7fff, -0x1000] |
| 104 ..f2 = [0, 1, -1, 0x7fffffff, -0x10000000] | 103 ..f2 = [0, 1, -1, 0x7fffffff, -0x10000000] |
| 105 ..f3 = [0, 1, -1, 0x7fffffffffffffff, -0x1000000000000000] | 104 ..f3 = [0, 1, -1, 0x7fffffffffffffff, -0x1000000000000000] |
| 106 ..f4 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9] | 105 ..f4 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9] |
| 107 ..f5 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9]; | 106 ..f5 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9]; |
| 108 var message = messageOfStruct(arrayValues); | 107 var message = messageOfStruct(arrayValues); |
| 109 var arrayValues2 = structs.ArrayValueTypes.deserialize(message.payload); | 108 var arrayValues2 = structs.ArrayValueTypes.deserialize(message.payload); |
| 110 Expect.listEquals(arrayValues.f0, arrayValues2.f0); | 109 Expect.listEquals(arrayValues.f0, arrayValues2.f0); |
| 111 Expect.listEquals(arrayValues.f1, arrayValues2.f1); | 110 Expect.listEquals(arrayValues.f1, arrayValues2.f1); |
| 112 Expect.listEquals(arrayValues.f2, arrayValues2.f2); | 111 Expect.listEquals(arrayValues.f2, arrayValues2.f2); |
| 113 Expect.listEquals(arrayValues.f3, arrayValues2.f3); | 112 Expect.listEquals(arrayValues.f3, arrayValues2.f3); |
| 114 Expect.listEquals(arrayValues.f4, arrayValues2.f4); | 113 Expect.listEquals(arrayValues.f4, arrayValues2.f4); |
| 115 Expect.listEquals(arrayValues.f5, arrayValues2.f5); | 114 Expect.listEquals(arrayValues.f5, arrayValues2.f5); |
| 116 } | 115 } |
| 117 | 116 |
| 118 | 117 |
| 119 testSerializeStructs() { | 118 testSerializeStructs() { |
| 120 testSerializeNamedRegion(); | 119 testSerializeNamedRegion(); |
| 121 testSerializeArrayValueTypes(); | 120 testSerializeArrayValueTypes(); |
| 122 } | 121 } |
| 123 | 122 |
| 124 | 123 |
| 125 main() async { | 124 main() async { |
| 126 testSerializeStructs(); | 125 testSerializeStructs(); |
| 127 await testCallResponse(); | 126 await testCallResponse(); |
| 128 await testAwaitCallResponse(); | 127 await testAwaitCallResponse(); |
| 129 } | 128 } |
| OLD | NEW |