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

Side by Side Diff: mojo/dart/test/bindings_generation_test.dart

Issue 982673002: Dart: Removes need to call listen(). (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Merge and Format Created 5 years, 9 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
« no previous file with comments | « mojo/dart/embedder/test/dart_to_cpp_tests.dart ('k') | mojo/dart/test/interface_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 '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' 12 import 'package:mojo/public/interfaces/bindings/tests/sample_interfaces.mojom.da rt'
13 as sample; 13 as sample;
14 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart' 14 import 'package:mojo/public/interfaces/bindings/tests/test_structs.mojom.dart'
15 as structs; 15 as structs;
16 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;
17 17
18 class ProviderImpl implements sample.Provider { 18 class ProviderImpl implements sample.Provider {
19 sample.ProviderStub _stub; 19 sample.ProviderStub _stub;
20 20
21 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) { 21 ProviderImpl(core.MojoMessagePipeEndpoint endpoint) {
22 _stub = new sample.ProviderStub.fromEndpoint(endpoint, impl: this); 22 _stub = new sample.ProviderStub.fromEndpoint(endpoint, this);
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));
33 33
34 echoEnum(int a, Function responseFactory) => 34 echoEnum(int a, Function responseFactory) =>
35 new Future.value(responseFactory(a)); 35 new Future.value(responseFactory(a));
36 } 36 }
37 37
38
39 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) { 38 void providerIsolate(core.MojoMessagePipeEndpoint endpoint) {
40 new ProviderImpl(endpoint); 39 new ProviderImpl(endpoint);
41 } 40 }
42 41
43
44 Future<bool> testCallResponse() { 42 Future<bool> testCallResponse() {
45 var pipe = new core.MojoMessagePipe(); 43 var pipe = new core.MojoMessagePipe();
46 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); 44 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]);
47 var c = new Completer(); 45 var c = new Completer();
48 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) { 46 Isolate.spawn(providerIsolate, pipe.endpoints[1]).then((_) {
49 client.ptr.echoString("hello!").then((echoStringResponse) { 47 client.ptr.echoString("hello!").then((echoStringResponse) {
50 Expect.equals("hello!", echoStringResponse.a); 48 Expect.equals("hello!", echoStringResponse.a);
51 }).then((_) { 49 }).then((_) {
52 client.ptr.echoStrings("hello", "mojo!").then((echoStringsResponse) { 50 client.ptr.echoStrings("hello", "mojo!").then((echoStringsResponse) {
53 Expect.equals("hello", echoStringsResponse.a); 51 Expect.equals("hello", echoStringsResponse.a);
54 Expect.equals("mojo!", echoStringsResponse.b); 52 Expect.equals("mojo!", echoStringsResponse.b);
55 client.close(); 53 client.close();
56 c.complete(true); 54 c.complete(true);
57 }); 55 });
58 }); 56 });
59 }); 57 });
60 return c.future; 58 return c.future;
61 } 59 }
62 60
63
64 Future testAwaitCallResponse() async { 61 Future testAwaitCallResponse() async {
65 var pipe = new core.MojoMessagePipe(); 62 var pipe = new core.MojoMessagePipe();
66 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]); 63 var client = new sample.ProviderProxy.fromEndpoint(pipe.endpoints[0]);
67 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]); 64 var isolate = await Isolate.spawn(providerIsolate, pipe.endpoints[1]);
68 65
69 var echoStringResponse = await client.ptr.echoString("hello!"); 66 var echoStringResponse = await client.ptr.echoString("hello!");
70 Expect.equals("hello!", echoStringResponse.a); 67 Expect.equals("hello!", echoStringResponse.a);
71 68
72 var echoStringsResponse = await client.ptr.echoStrings("hello", "mojo!"); 69 var echoStringsResponse = await client.ptr.echoStrings("hello", "mojo!");
73 Expect.equals("hello", echoStringsResponse.a); 70 Expect.equals("hello", echoStringsResponse.a);
74 Expect.equals("mojo!", echoStringsResponse.b); 71 Expect.equals("mojo!", echoStringsResponse.b);
75 72
76 client.close(); 73 client.close();
77 } 74 }
78 75
79
80 bindings.ServiceMessage messageOfStruct(bindings.Struct s) => 76 bindings.ServiceMessage messageOfStruct(bindings.Struct s) =>
81 s.serializeWithHeader(new bindings.MessageHeader(0)); 77 s.serializeWithHeader(new bindings.MessageHeader(0));
82 78
83
84 testSerializeNamedRegion() { 79 testSerializeNamedRegion() {
85 var r = new rect.Rect() 80 var r = new rect.Rect()
86 ..x = 1 81 ..x = 1
87 ..y = 2 82 ..y = 2
88 ..width = 3 83 ..width = 3
89 ..height = 4; 84 ..height = 4;
90 var namedRegion = new structs.NamedRegion() 85 var namedRegion = new structs.NamedRegion()
91 ..name = "name" 86 ..name = "name"
92 ..rects = [r]; 87 ..rects = [r];
93 var message = messageOfStruct(namedRegion); 88 var message = messageOfStruct(namedRegion);
94 var namedRegion2 = structs.NamedRegion.deserialize(message.payload); 89 var namedRegion2 = structs.NamedRegion.deserialize(message.payload);
95 Expect.equals(namedRegion.name, namedRegion2.name); 90 Expect.equals(namedRegion.name, namedRegion2.name);
96 } 91 }
97 92
98
99 testSerializeArrayValueTypes() { 93 testSerializeArrayValueTypes() {
100 var arrayValues = new structs.ArrayValueTypes() 94 var arrayValues = new structs.ArrayValueTypes()
101 ..f0 = [0, 1, -1, 0x7f, -0x10] 95 ..f0 = [0, 1, -1, 0x7f, -0x10]
102 ..f1 = [0, 1, -1, 0x7fff, -0x1000] 96 ..f1 = [0, 1, -1, 0x7fff, -0x1000]
103 ..f2 = [0, 1, -1, 0x7fffffff, -0x10000000] 97 ..f2 = [0, 1, -1, 0x7fffffff, -0x10000000]
104 ..f3 = [0, 1, -1, 0x7fffffffffffffff, -0x1000000000000000] 98 ..f3 = [0, 1, -1, 0x7fffffffffffffff, -0x1000000000000000]
105 ..f4 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9] 99 ..f4 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9]
106 ..f5 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9]; 100 ..f5 = [0.0, 1.0, -1.0, 4.0e9, -4.0e9];
107 var message = messageOfStruct(arrayValues); 101 var message = messageOfStruct(arrayValues);
108 var arrayValues2 = structs.ArrayValueTypes.deserialize(message.payload); 102 var arrayValues2 = structs.ArrayValueTypes.deserialize(message.payload);
109 Expect.listEquals(arrayValues.f0, arrayValues2.f0); 103 Expect.listEquals(arrayValues.f0, arrayValues2.f0);
110 Expect.listEquals(arrayValues.f1, arrayValues2.f1); 104 Expect.listEquals(arrayValues.f1, arrayValues2.f1);
111 Expect.listEquals(arrayValues.f2, arrayValues2.f2); 105 Expect.listEquals(arrayValues.f2, arrayValues2.f2);
112 Expect.listEquals(arrayValues.f3, arrayValues2.f3); 106 Expect.listEquals(arrayValues.f3, arrayValues2.f3);
113 Expect.listEquals(arrayValues.f4, arrayValues2.f4); 107 Expect.listEquals(arrayValues.f4, arrayValues2.f4);
114 Expect.listEquals(arrayValues.f5, arrayValues2.f5); 108 Expect.listEquals(arrayValues.f5, arrayValues2.f5);
115 } 109 }
116 110
117
118 testSerializeStructs() { 111 testSerializeStructs() {
119 testSerializeNamedRegion(); 112 testSerializeNamedRegion();
120 testSerializeArrayValueTypes(); 113 testSerializeArrayValueTypes();
121 } 114 }
122 115
123
124 main() async { 116 main() async {
125 testSerializeStructs(); 117 testSerializeStructs();
126 await testCallResponse(); 118 await testCallResponse();
127 await testAwaitCallResponse(); 119 await testAwaitCallResponse();
128 } 120 }
OLDNEW
« no previous file with comments | « mojo/dart/embedder/test/dart_to_cpp_tests.dart ('k') | mojo/dart/test/interface_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698