| 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:mojom/sample/sample_interfaces.mojom.dart' as sample; | 13 import 'package:mojom/sample/sample_interfaces.mojom.dart' as sample; |
| 14 import 'package:mojom/mojo/test/test_structs.mojom.dart' as structs; | 14 import 'package:mojom/mojo/test/test_structs.mojom.dart' as structs; |
| 15 import 'package:mojom/mojo/test/test_unions.mojom.dart' as unions; | 15 import 'package:mojom/mojo/test/test_unions.mojom.dart' as unions; |
| 16 import 'package:mojom/mojo/test/rect.mojom.dart' as rect; | 16 import 'package:mojom/mojo/test/rect.mojom.dart' as rect; |
| 17 import 'package:mojom/mojo/test/serialization_test_structs.mojom.dart' as serial
ization; | 17 import 'package:mojom/mojo/test/serialization_test_structs.mojom.dart' |
| 18 import 'package:mojom/regression_tests/regression_tests.mojom.dart' as regressio
n; | 18 as serialization; |
| 19 import 'package:mojom/regression_tests/regression_tests.mojom.dart' |
| 20 as regression; |
| 19 | 21 |
| 20 class ProviderImpl implements sample.Provider { | 22 class ProviderImpl implements sample.Provider { |
| 21 sample.ProviderStub _stub; | 23 sample.ProviderStub _stub; |
| 22 | 24 |
| 23 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { | 25 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { |
| 24 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this); | 26 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this); |
| 25 } | 27 } |
| 26 | 28 |
| 27 echoString(String a, Function responseFactory) => | 29 echoString(String a, Function responseFactory) => |
| 28 new Future.value(responseFactory(a)); | 30 new Future.value(responseFactory(a)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 ..height = 4; | 121 ..height = 4; |
| 120 | 122 |
| 121 var encodedRect = JSON.encode(r); | 123 var encodedRect = JSON.encode(r); |
| 122 var goldenEncoding = "{\"x\":1,\"y\":2,\"width\":3,\"height\":4}"; | 124 var goldenEncoding = "{\"x\":1,\"y\":2,\"width\":3,\"height\":4}"; |
| 123 Expect.equals(goldenEncoding, encodedRect); | 125 Expect.equals(goldenEncoding, encodedRect); |
| 124 } | 126 } |
| 125 | 127 |
| 126 testSerializeHandleToJSON() { | 128 testSerializeHandleToJSON() { |
| 127 var s = new serialization.Struct2(); | 129 var s = new serialization.Struct2(); |
| 128 | 130 |
| 129 Expect.throws(() => JSON.encode(s), | 131 Expect.throws( |
| 130 (e) => e.cause is bindings.MojoCodecError); | 132 () => JSON.encode(s), (e) => e.cause is bindings.MojoCodecError); |
| 131 } | 133 } |
| 132 | 134 |
| 133 testSerializeStructs() { | 135 testSerializeStructs() { |
| 134 testSerializeNamedRegion(); | 136 testSerializeNamedRegion(); |
| 135 testSerializeArrayValueTypes(); | 137 testSerializeArrayValueTypes(); |
| 136 testSerializeToJSON(); | 138 testSerializeToJSON(); |
| 137 testSerializeHandleToJSON(); | 139 testSerializeHandleToJSON(); |
| 138 } | 140 } |
| 139 | 141 |
| 140 testSerializePodUnions() { | 142 testSerializePodUnions() { |
| 141 var s = new unions.WrapperStruct() | 143 var s = new unions.WrapperStruct()..podUnion = new unions.PodUnion(); |
| 142 ..podUnion = new unions.PodUnion(); | |
| 143 s.podUnion.fUint32 = 32; | 144 s.podUnion.fUint32 = 32; |
| 144 | 145 |
| 145 Expect.equals(unions.PodUnionTag.fUint32, s.podUnion.tag); | 146 Expect.equals(unions.PodUnionTag.fUint32, s.podUnion.tag); |
| 146 Expect.equals(32, s.podUnion.fUint32); | 147 Expect.equals(32, s.podUnion.fUint32); |
| 147 | 148 |
| 148 var message = messageOfStruct(s); | 149 var message = messageOfStruct(s); |
| 149 var s2 = unions.WrapperStruct.deserialize(message.payload); | 150 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 150 | 151 |
| 151 Expect.equals(s.podUnion.fUint32, s2.podUnion.fUint32); | 152 Expect.equals(s.podUnion.fUint32, s2.podUnion.fUint32); |
| 152 } | 153 } |
| 153 | 154 |
| 154 testSerializeStructInUnion() { | 155 testSerializeStructInUnion() { |
| 155 var s = new unions.WrapperStruct() | 156 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 156 ..objectUnion = new unions.ObjectUnion(); | 157 s.objectUnion.fDummy = new unions.DummyStruct()..fInt8 = 8; |
| 157 s.objectUnion.fDummy = new unions.DummyStruct() | |
| 158 ..fInt8 = 8; | |
| 159 | 158 |
| 160 var message = messageOfStruct(s); | 159 var message = messageOfStruct(s); |
| 161 var s2 = unions.WrapperStruct.deserialize(message.payload); | 160 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 162 | 161 |
| 163 Expect.equals(s.objectUnion.fDummy.fInt8, s2.objectUnion.fDummy.fInt8); | 162 Expect.equals(s.objectUnion.fDummy.fInt8, s2.objectUnion.fDummy.fInt8); |
| 164 } | 163 } |
| 165 | 164 |
| 166 testSerializeArrayInUnion() { | 165 testSerializeArrayInUnion() { |
| 167 var s = new unions.WrapperStruct() | 166 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 168 ..objectUnion = new unions.ObjectUnion(); | |
| 169 s.objectUnion.fArrayInt8 = [1, 2, 3]; | 167 s.objectUnion.fArrayInt8 = [1, 2, 3]; |
| 170 | 168 |
| 171 var message = messageOfStruct(s); | 169 var message = messageOfStruct(s); |
| 172 var s2 = unions.WrapperStruct.deserialize(message.payload); | 170 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 173 | 171 |
| 174 Expect.listEquals(s.objectUnion.fArrayInt8, s2.objectUnion.fArrayInt8); | 172 Expect.listEquals(s.objectUnion.fArrayInt8, s2.objectUnion.fArrayInt8); |
| 175 } | 173 } |
| 176 | 174 |
| 177 testSerializeMapInUnion() { | 175 testSerializeMapInUnion() { |
| 178 var s = new unions.WrapperStruct() | 176 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 179 ..objectUnion = new unions.ObjectUnion(); | 177 s.objectUnion.fMapInt8 = {"one": 1, "two": 2,}; |
| 180 s.objectUnion.fMapInt8 = { | |
| 181 "one": 1, | |
| 182 "two": 2, | |
| 183 }; | |
| 184 | 178 |
| 185 var message = messageOfStruct(s); | 179 var message = messageOfStruct(s); |
| 186 var s2 = unions.WrapperStruct.deserialize(message.payload); | 180 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 187 | 181 |
| 188 Expect.equals(1, s.objectUnion.fMapInt8["one"]); | 182 Expect.equals(1, s.objectUnion.fMapInt8["one"]); |
| 189 Expect.equals(2, s.objectUnion.fMapInt8["two"]); | 183 Expect.equals(2, s.objectUnion.fMapInt8["two"]); |
| 190 } | 184 } |
| 191 | 185 |
| 192 testSerializeUnionInArray() { | 186 testSerializeUnionInArray() { |
| 193 var s = new unions.SmallStruct() | 187 var s = new unions.SmallStruct() |
| 194 ..podUnionArray = [ | 188 ..podUnionArray = [ |
| 195 new unions.PodUnion() | 189 new unions.PodUnion()..fUint16 = 16, |
| 196 ..fUint16 = 16, | 190 new unions.PodUnion()..fUint32 = 32, |
| 197 new unions.PodUnion() | |
| 198 ..fUint32 = 32, | |
| 199 ]; | 191 ]; |
| 200 | 192 |
| 201 var message = messageOfStruct(s); | 193 var message = messageOfStruct(s); |
| 202 | 194 |
| 203 var s2 = unions.SmallStruct.deserialize(message.payload); | 195 var s2 = unions.SmallStruct.deserialize(message.payload); |
| 204 | 196 |
| 205 Expect.equals(16, s2.podUnionArray[0].fUint16); | 197 Expect.equals(16, s2.podUnionArray[0].fUint16); |
| 206 Expect.equals(32, s2.podUnionArray[1].fUint32); | 198 Expect.equals(32, s2.podUnionArray[1].fUint32); |
| 207 } | 199 } |
| 208 | 200 |
| 209 testSerializeUnionInMap() { | 201 testSerializeUnionInMap() { |
| 210 var s = new unions.SmallStruct() | 202 var s = new unions.SmallStruct() |
| 211 ..podUnionMap = { | 203 ..podUnionMap = { |
| 212 'one': new unions.PodUnion() | 204 'one': new unions.PodUnion()..fUint16 = 16, |
| 213 ..fUint16 = 16, | 205 'two': new unions.PodUnion()..fUint32 = 32, |
| 214 'two': new unions.PodUnion() | |
| 215 ..fUint32 = 32, | |
| 216 }; | 206 }; |
| 217 | 207 |
| 218 var message = messageOfStruct(s); | 208 var message = messageOfStruct(s); |
| 219 | 209 |
| 220 var s2 = unions.SmallStruct.deserialize(message.payload); | 210 var s2 = unions.SmallStruct.deserialize(message.payload); |
| 221 | 211 |
| 222 Expect.equals(16, s2.podUnionMap['one'].fUint16); | 212 Expect.equals(16, s2.podUnionMap['one'].fUint16); |
| 223 Expect.equals(32, s2.podUnionMap['two'].fUint32); | 213 Expect.equals(32, s2.podUnionMap['two'].fUint32); |
| 224 } | 214 } |
| 225 | 215 |
| 226 testSerializeUnionInUnion() { | 216 testSerializeUnionInUnion() { |
| 227 var s = new unions.WrapperStruct() | 217 var s = new unions.WrapperStruct()..objectUnion = new unions.ObjectUnion(); |
| 228 ..objectUnion = new unions.ObjectUnion(); | 218 s.objectUnion.fPodUnion = new unions.PodUnion()..fUint32 = 32; |
| 229 s.objectUnion.fPodUnion = new unions.PodUnion() | |
| 230 ..fUint32 = 32; | |
| 231 | 219 |
| 232 var message = messageOfStruct(s); | 220 var message = messageOfStruct(s); |
| 233 var s2 = unions.WrapperStruct.deserialize(message.payload); | 221 var s2 = unions.WrapperStruct.deserialize(message.payload); |
| 234 | 222 |
| 235 Expect.equals(32, s2.objectUnion.fPodUnion.fUint32); | 223 Expect.equals(32, s2.objectUnion.fPodUnion.fUint32); |
| 236 } | 224 } |
| 237 | 225 |
| 238 testUnionsToString() { | 226 testUnionsToString() { |
| 239 var podUnion = new unions.PodUnion(); | 227 var podUnion = new unions.PodUnion(); |
| 240 podUnion.fUint32 = 32; | 228 podUnion.fUint32 = 32; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 284 |
| 297 void closingProviderIsolate(core.MojoMessagePipeEndpoint endpoint) { | 285 void closingProviderIsolate(core.MojoMessagePipeEndpoint endpoint) { |
| 298 var provider = new ProviderImpl(endpoint); | 286 var provider = new ProviderImpl(endpoint); |
| 299 provider._stub.close(); | 287 provider._stub.close(); |
| 300 } | 288 } |
| 301 | 289 |
| 302 Future<bool> runOnClosedTest() { | 290 Future<bool> runOnClosedTest() { |
| 303 var testCompleter = new Completer(); | 291 var testCompleter = new Completer(); |
| 304 var pipe = new core.MojoMessagePipe(); | 292 var pipe = new core.MojoMessagePipe(); |
| 305 var proxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); | 293 var proxy = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); |
| 306 proxy.impl.onError = () => testCompleter.complete(true); | 294 proxy.impl.onError = (_) => testCompleter.complete(true); |
| 307 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); | 295 Isolate.spawn(closingProviderIsolate, pipe.endpoints[1]); |
| 308 return testCompleter.future.then((b) { | 296 return testCompleter.future.then((b) { |
| 309 Expect.isTrue(b); | 297 Expect.isTrue(b); |
| 310 }); | 298 }); |
| 311 } | 299 } |
| 312 | 300 |
| 313 main() async { | 301 main() async { |
| 314 testSerializeStructs(); | 302 testSerializeStructs(); |
| 315 testUnions(); | 303 testUnions(); |
| 316 await testEnums(); | 304 await testEnums(); |
| 317 await testCallResponse(); | 305 await testCallResponse(); |
| 318 await testAwaitCallResponse(); | 306 await testAwaitCallResponse(); |
| 319 await runOnClosedTest(); | 307 await runOnClosedTest(); |
| 320 } | 308 } |
| OLD | NEW |