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

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

Issue 1027603002: Dart: Removes all but native calls and the handle watcher from the snapshot. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Hoist application interface dependence 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/test/compile_all_interfaces_test.dart ('k') | mojo/dart/test/exception_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:typed_data'; 5 import 'dart:typed_data';
6 import 'dart:mojo.core';
7 6
8 import 'package:mojo/dart/testing/expect.dart'; 7 import 'package:mojo/dart/testing/expect.dart';
8 import 'package:mojo/public/dart/core.dart';
9 9
10 invalidHandleTest() { 10 invalidHandleTest() {
11 MojoHandle invalidHandle = new MojoHandle(MojoHandle.INVALID); 11 MojoHandle invalidHandle = new MojoHandle(MojoHandle.INVALID);
12 12
13 // Close. 13 // Close.
14 MojoResult result = invalidHandle.close(); 14 MojoResult result = invalidHandle.close();
15 Expect.isTrue(result.isInvalidArgument); 15 Expect.isTrue(result.isInvalidArgument);
16 16
17 // Wait. 17 // Wait.
18 MojoWaitResult mwr = invalidHandle.wait(MojoHandleSignals.kReadWrite, 1000000) ; 18 MojoWaitResult mwr =
19 invalidHandle.wait(MojoHandleSignals.kReadWrite, 1000000);
19 Expect.isTrue(mwr.result.isInvalidArgument); 20 Expect.isTrue(mwr.result.isInvalidArgument);
20 21
21 MojoWaitManyResult mwmr = MojoHandle.waitMany([invalidHandle.h], 22 MojoWaitManyResult mwmr = MojoHandle.waitMany([invalidHandle.h], [
22 [MojoHandleSignals.kReadWrite], 23 MojoHandleSignals.kReadWrite
23 MojoHandle.DEADLINE_INDEFINITE); 24 ], MojoHandle.DEADLINE_INDEFINITE);
24 Expect.isTrue(mwmr.result.isInvalidArgument); 25 Expect.isTrue(mwmr.result.isInvalidArgument);
25 26
26 // Message pipe. 27 // Message pipe.
27 MojoMessagePipe pipe = new MojoMessagePipe(); 28 MojoMessagePipe pipe = new MojoMessagePipe();
28 Expect.isNotNull(pipe); 29 Expect.isNotNull(pipe);
29 ByteData bd = new ByteData(10); 30 ByteData bd = new ByteData(10);
30 pipe.endpoints[0].handle.close(); 31 pipe.endpoints[0].handle.close();
31 pipe.endpoints[1].handle.close(); 32 pipe.endpoints[1].handle.close();
32 result = pipe.endpoints[0].write(bd); 33 result = pipe.endpoints[0].write(bd);
33 Expect.isTrue(result.isInvalidArgument); 34 Expect.isTrue(result.isInvalidArgument);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate(sharedBuffer); 67 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate(sharedBuffer);
67 Expect.isNull(duplicate); 68 Expect.isNull(duplicate);
68 69
69 sharedBuffer = new MojoSharedBuffer.create(10); 70 sharedBuffer = new MojoSharedBuffer.create(10);
70 Expect.isNotNull(sharedBuffer); 71 Expect.isNotNull(sharedBuffer);
71 sharedBuffer.close(); 72 sharedBuffer.close();
72 result = sharedBuffer.map(0, 10); 73 result = sharedBuffer.map(0, 10);
73 Expect.isTrue(result.isInvalidArgument); 74 Expect.isTrue(result.isInvalidArgument);
74 } 75 }
75 76
76
77 basicMessagePipeTest() { 77 basicMessagePipeTest() {
78 MojoMessagePipe pipe = new MojoMessagePipe(); 78 MojoMessagePipe pipe = new MojoMessagePipe();
79 Expect.isNotNull(pipe); 79 Expect.isNotNull(pipe);
80 Expect.isTrue(pipe.status.isOk); 80 Expect.isTrue(pipe.status.isOk);
81 Expect.isNotNull(pipe.endpoints); 81 Expect.isNotNull(pipe.endpoints);
82 82
83 MojoMessagePipeEndpoint end0 = pipe.endpoints[0]; 83 MojoMessagePipeEndpoint end0 = pipe.endpoints[0];
84 MojoMessagePipeEndpoint end1 = pipe.endpoints[1]; 84 MojoMessagePipeEndpoint end1 = pipe.endpoints[1];
85 Expect.isTrue(end0.handle.isValid); 85 Expect.isTrue(end0.handle.isValid);
86 Expect.isTrue(end1.handle.isValid); 86 Expect.isTrue(end1.handle.isValid);
(...skipping 12 matching lines...) Expand all
99 Expect.isTrue(end0.status.isShouldWait); 99 Expect.isTrue(end0.status.isShouldWait);
100 100
101 // Write end1. 101 // Write end1.
102 String hello = "hello"; 102 String hello = "hello";
103 ByteData helloData = 103 ByteData helloData =
104 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); 104 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer);
105 MojoResult result = end1.write(helloData); 105 MojoResult result = end1.write(helloData);
106 Expect.isTrue(result.isOk); 106 Expect.isTrue(result.isOk);
107 107
108 // end0 should now be readable. 108 // end0 should now be readable.
109 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h], 109 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h], [
110 [MojoHandleSignals.kReadable], 110 MojoHandleSignals.kReadable
111 MojoHandle.DEADLINE_INDEFINITE); 111 ], MojoHandle.DEADLINE_INDEFINITE);
112 Expect.isTrue(mwmr.result.isOk); 112 Expect.isTrue(mwmr.result.isOk);
113 113
114 // Read from end0. 114 // Read from end0.
115 MojoMessagePipeReadResult readResult = end0.read(data); 115 MojoMessagePipeReadResult readResult = end0.read(data);
116 Expect.isNotNull(readResult); 116 Expect.isNotNull(readResult);
117 Expect.isTrue(readResult.status.isOk); 117 Expect.isTrue(readResult.status.isOk);
118 Expect.equals(readResult.bytesRead, helloData.lengthInBytes); 118 Expect.equals(readResult.bytesRead, helloData.lengthInBytes);
119 Expect.equals(readResult.handlesRead, 0); 119 Expect.equals(readResult.handlesRead, 0);
120 120
121 String hello_result = new String.fromCharCodes( 121 String hello_result = new String.fromCharCodes(
122 data.buffer.asUint8List().sublist(0, readResult.bytesRead).toList()); 122 data.buffer.asUint8List().sublist(0, readResult.bytesRead).toList());
123 Expect.equals(hello_result, "hello"); 123 Expect.equals(hello_result, "hello");
124 124
125 // end0 should no longer be readable. 125 // end0 should no longer be readable.
126 mwr = end0.handle.wait(MojoHandleSignals.kReadable, 10); 126 mwr = end0.handle.wait(MojoHandleSignals.kReadable, 10);
127 Expect.isTrue(mwr.result.isDeadlineExceeded); 127 Expect.isTrue(mwr.result.isDeadlineExceeded);
128 128
129 // Close end0's handle. 129 // Close end0's handle.
130 result = end0.handle.close(); 130 result = end0.handle.close();
131 Expect.isTrue(result.isOk); 131 Expect.isTrue(result.isOk);
132 132
133 // end1 should no longer be readable or writable. 133 // end1 should no longer be readable or writable.
134 mwr = end1.handle.wait(MojoHandleSignals.kReadWrite, 1000); 134 mwr = end1.handle.wait(MojoHandleSignals.kReadWrite, 1000);
135 Expect.isTrue(mwr.result.isFailedPrecondition); 135 Expect.isTrue(mwr.result.isFailedPrecondition);
136 136
137 result = end1.handle.close(); 137 result = end1.handle.close();
138 Expect.isTrue(result.isOk); 138 Expect.isTrue(result.isOk);
139 } 139 }
140 140
141
142 basicDataPipeTest() { 141 basicDataPipeTest() {
143 MojoDataPipe pipe = new MojoDataPipe(); 142 MojoDataPipe pipe = new MojoDataPipe();
144 Expect.isNotNull(pipe); 143 Expect.isNotNull(pipe);
145 Expect.isTrue(pipe.status.isOk); 144 Expect.isTrue(pipe.status.isOk);
146 Expect.isTrue(pipe.consumer.handle.isValid); 145 Expect.isTrue(pipe.consumer.handle.isValid);
147 Expect.isTrue(pipe.producer.handle.isValid); 146 Expect.isTrue(pipe.producer.handle.isValid);
148 147
149 MojoDataPipeProducer producer = pipe.producer; 148 MojoDataPipeProducer producer = pipe.producer;
150 MojoDataPipeConsumer consumer = pipe.consumer; 149 MojoDataPipeConsumer consumer = pipe.consumer;
151 Expect.isTrue(producer.handle.isValid); 150 Expect.isTrue(producer.handle.isValid);
(...skipping 20 matching lines...) Expand all
172 // Write to producer. 171 // Write to producer.
173 String hello = "hello "; 172 String hello = "hello ";
174 ByteData helloData = 173 ByteData helloData =
175 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); 174 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer);
176 int written = producer.write( 175 int written = producer.write(
177 helloData, helloData.lengthInBytes, MojoDataPipeProducer.FLAG_NONE); 176 helloData, helloData.lengthInBytes, MojoDataPipeProducer.FLAG_NONE);
178 Expect.isTrue(producer.status.isOk); 177 Expect.isTrue(producer.status.isOk);
179 Expect.equals(written, helloData.lengthInBytes); 178 Expect.equals(written, helloData.lengthInBytes);
180 179
181 // Now that we have written, the consumer should be readable. 180 // Now that we have written, the consumer should be readable.
182 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h], 181 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h], [
183 [MojoHandleSignals.kReadable], 182 MojoHandleSignals.kReadable
184 MojoHandle.DEADLINE_INDEFINITE); 183 ], MojoHandle.DEADLINE_INDEFINITE);
185 Expect.isTrue(mwr.result.isOk); 184 Expect.isTrue(mwr.result.isOk);
186 185
187 // Do a two-phase write to the producer. 186 // Do a two-phase write to the producer.
188 ByteData twoPhaseWrite = producer.beginWrite( 187 ByteData twoPhaseWrite =
189 20, MojoDataPipeProducer.FLAG_NONE); 188 producer.beginWrite(20, MojoDataPipeProducer.FLAG_NONE);
190 Expect.isTrue(producer.status.isOk); 189 Expect.isTrue(producer.status.isOk);
191 Expect.isNotNull(twoPhaseWrite); 190 Expect.isNotNull(twoPhaseWrite);
192 Expect.isTrue(twoPhaseWrite.lengthInBytes >= 20); 191 Expect.isTrue(twoPhaseWrite.lengthInBytes >= 20);
193 192
194 String world = "world"; 193 String world = "world";
195 twoPhaseWrite.buffer.asUint8List().setAll(0, world.codeUnits); 194 twoPhaseWrite.buffer.asUint8List().setAll(0, world.codeUnits);
196 producer.endWrite(Uint8List.BYTES_PER_ELEMENT * world.codeUnits.length); 195 producer.endWrite(Uint8List.BYTES_PER_ELEMENT * world.codeUnits.length);
197 Expect.isTrue(producer.status.isOk); 196 Expect.isTrue(producer.status.isOk);
198 197
199 // Read one character from consumer. 198 // Read one character from consumer.
200 int read = consumer.read(buffer, 1, MojoDataPipeConsumer.FLAG_NONE); 199 int read = consumer.read(buffer, 1, MojoDataPipeConsumer.FLAG_NONE);
201 Expect.isTrue(consumer.status.isOk); 200 Expect.isTrue(consumer.status.isOk);
202 Expect.equals(read, 1); 201 Expect.equals(read, 1);
203 202
204 // Close the producer. 203 // Close the producer.
205 MojoResult result = producer.handle.close(); 204 MojoResult result = producer.handle.close();
206 Expect.isTrue(result.isOk); 205 Expect.isTrue(result.isOk);
207 206
208 // Consumer should still be readable. 207 // Consumer should still be readable.
209 mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); 208 mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0);
210 Expect.isTrue(mwr.result.isOk); 209 Expect.isTrue(mwr.result.isOk);
211 210
212 // Get the number of remaining bytes. 211 // Get the number of remaining bytes.
213 int remaining = consumer.read( 212 int remaining = consumer.read(null, 0, MojoDataPipeConsumer.FLAG_QUERY);
214 null, 0, MojoDataPipeConsumer.FLAG_QUERY);
215 Expect.isTrue(consumer.status.isOk); 213 Expect.isTrue(consumer.status.isOk);
216 Expect.equals(remaining, "hello world".length - 1); 214 Expect.equals(remaining, "hello world".length - 1);
217 215
218 // Do a two-phase read. 216 // Do a two-phase read.
219 ByteData twoPhaseRead = consumer.beginRead( 217 ByteData twoPhaseRead =
220 remaining, MojoDataPipeConsumer.FLAG_NONE); 218 consumer.beginRead(remaining, MojoDataPipeConsumer.FLAG_NONE);
221 Expect.isTrue(consumer.status.isOk); 219 Expect.isTrue(consumer.status.isOk);
222 Expect.isNotNull(twoPhaseRead); 220 Expect.isNotNull(twoPhaseRead);
223 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining); 221 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining);
224 222
225 Uint8List uint8_list = buffer.buffer.asUint8List(); 223 Uint8List uint8_list = buffer.buffer.asUint8List();
226 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List()); 224 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List());
227 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes); 225 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes);
228 226
229 consumer.endRead(twoPhaseRead.lengthInBytes); 227 consumer.endRead(twoPhaseRead.lengthInBytes);
230 Expect.isTrue(consumer.status.isOk); 228 Expect.isTrue(consumer.status.isOk);
231 229
232 String helloWorld = new String.fromCharCodes( 230 String helloWorld = new String.fromCharCodes(uint8_list.toList());
233 uint8_list.toList());
234 Expect.equals("hello world", helloWorld); 231 Expect.equals("hello world", helloWorld);
235 232
236 result = consumer.handle.close(); 233 result = consumer.handle.close();
237 Expect.isTrue(result.isOk); 234 Expect.isTrue(result.isOk);
238 } 235 }
239 236
240
241 basicSharedBufferTest() { 237 basicSharedBufferTest() {
242 MojoSharedBuffer mojoBuffer = new MojoSharedBuffer.create( 238 MojoSharedBuffer mojoBuffer =
243 100, MojoSharedBuffer.CREATE_FLAG_NONE); 239 new MojoSharedBuffer.create(100, MojoSharedBuffer.CREATE_FLAG_NONE);
244 Expect.isNotNull(mojoBuffer); 240 Expect.isNotNull(mojoBuffer);
245 Expect.isNotNull(mojoBuffer.status); 241 Expect.isNotNull(mojoBuffer.status);
246 Expect.isTrue(mojoBuffer.status.isOk); 242 Expect.isTrue(mojoBuffer.status.isOk);
247 Expect.isNotNull(mojoBuffer.handle); 243 Expect.isNotNull(mojoBuffer.handle);
248 Expect.isTrue(mojoBuffer.handle is MojoHandle); 244 Expect.isTrue(mojoBuffer.handle is MojoHandle);
249 Expect.isTrue(mojoBuffer.handle.isValid); 245 Expect.isTrue(mojoBuffer.handle.isValid);
250 246
251 mojoBuffer.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE); 247 mojoBuffer.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE);
252 Expect.isNotNull(mojoBuffer.status); 248 Expect.isNotNull(mojoBuffer.status);
253 Expect.isTrue(mojoBuffer.status.isOk); 249 Expect.isTrue(mojoBuffer.status.isOk);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 286
291 duplicate.unmap(); 287 duplicate.unmap();
292 Expect.isNotNull(duplicate.status); 288 Expect.isNotNull(duplicate.status);
293 Expect.isTrue(duplicate.status.isOk); 289 Expect.isTrue(duplicate.status.isOk);
294 Expect.isNull(duplicate.mapping); 290 Expect.isNull(duplicate.mapping);
295 291
296 duplicate.close(); 292 duplicate.close();
297 duplicate = null; 293 duplicate = null;
298 } 294 }
299 295
300
301 main() { 296 main() {
302 invalidHandleTest(); 297 invalidHandleTest();
303 basicMessagePipeTest(); 298 basicMessagePipeTest();
304 basicDataPipeTest(); 299 basicDataPipeTest();
305 basicSharedBufferTest(); 300 basicSharedBufferTest();
306 } 301 }
OLDNEW
« no previous file with comments | « mojo/dart/test/compile_all_interfaces_test.dart ('k') | mojo/dart/test/exception_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698