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

Side by Side Diff: mojo/dart/unittests/embedder_tests/core_test.dart

Issue 1694413003: Cleanups in the Mojo package. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address comments. Created 4 years, 10 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/packages/mojo/sdk_ext_sources.gni ('k') | no next file » | 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:convert'; 6 import 'dart:convert';
7 import 'dart:io'; 7 import 'dart:io';
8 import 'dart:typed_data'; 8 import 'dart:typed_data';
9 9
10 import 'package:_mojo_for_test_only/expect.dart'; 10 import 'package:_mojo_for_test_only/expect.dart';
11 import 'package:mojo/core.dart'; 11 import 'package:mojo/core.dart';
12 12
13 invalidHandleTest() { 13 invalidHandleTest() {
14 MojoHandle invalidHandle = new MojoHandle(MojoHandle.INVALID); 14 MojoHandle invalidHandle = new MojoHandle(MojoHandle.invalidHandle);
15 15
16 // Close. 16 // Close.
17 int result = invalidHandle.close(); 17 int result = invalidHandle.close();
18 Expect.isTrue(result == MojoResult.kInvalidArgument); 18 Expect.isTrue(result == MojoResult.kInvalidArgument);
19 19
20 // Wait. 20 // Wait.
21 MojoWaitResult mwr = 21 MojoWaitResult mwr =
22 invalidHandle.wait(MojoHandleSignals.kReadWrite, 1000000); 22 invalidHandle.wait(MojoHandleSignals.kReadWrite, 1000000);
23 Expect.isTrue(mwr.result == MojoResult.kInvalidArgument); 23 Expect.isTrue(mwr.result == MojoResult.kInvalidArgument);
24 24
25 MojoWaitManyResult mwmr = MojoHandle.waitMany([invalidHandle.h], 25 MojoWaitManyResult mwmr = MojoHandle.waitMany([invalidHandle.h],
26 [MojoHandleSignals.kReadWrite], MojoHandle.DEADLINE_INDEFINITE); 26 [MojoHandleSignals.kReadWrite], MojoHandle.deadlineIndefinite);
27 Expect.isTrue(mwmr.result == MojoResult.kInvalidArgument); 27 Expect.isTrue(mwmr.result == MojoResult.kInvalidArgument);
28 28
29 // Message pipe. 29 // Message pipe.
30 MojoMessagePipe pipe = new MojoMessagePipe(); 30 MojoMessagePipe pipe = new MojoMessagePipe();
31 Expect.isNotNull(pipe); 31 Expect.isNotNull(pipe);
32 ByteData bd = new ByteData(10); 32 ByteData bd = new ByteData(10);
33 pipe.endpoints[0].handle.close(); 33 pipe.endpoints[0].handle.close();
34 pipe.endpoints[1].handle.close(); 34 pipe.endpoints[1].handle.close();
35 result = pipe.endpoints[0].write(bd); 35 result = pipe.endpoints[0].write(bd);
36 Expect.isTrue(result == MojoResult.kInvalidArgument); 36 Expect.isTrue(result == MojoResult.kInvalidArgument);
37 37
38 MojoMessagePipeReadResult readResult = pipe.endpoints[0].read(bd); 38 MojoMessagePipeReadResult readResult = pipe.endpoints[0].read(bd);
39 Expect.isTrue(pipe.endpoints[0].status == MojoResult.kInvalidArgument); 39 Expect.isTrue(pipe.endpoints[0].status == MojoResult.kInvalidArgument);
40 40
41 // Data pipe. 41 // Data pipe.
42 MojoDataPipe dataPipe = new MojoDataPipe(); 42 MojoDataPipe dataPipe = new MojoDataPipe();
43 Expect.isNotNull(dataPipe); 43 Expect.isNotNull(dataPipe);
44 dataPipe.producer.handle.close(); 44 dataPipe.producer.handle.close();
45 dataPipe.consumer.handle.close(); 45 dataPipe.consumer.handle.close();
46 46
47 int bytesWritten = dataPipe.producer.write(bd); 47 int bytesWritten = dataPipe.producer.write(bd);
48 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument); 48 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument);
49 49
50 ByteData writeData = dataPipe.producer.beginWrite(10); 50 ByteData writeData = dataPipe.producer.beginWrite();
51 Expect.isNull(writeData); 51 Expect.isNull(writeData);
52 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument); 52 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument);
53 dataPipe.producer.endWrite(10); 53 dataPipe.producer.endWrite(10);
54 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument); 54 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument);
55 55
56 int read = dataPipe.consumer.read(bd); 56 int read = dataPipe.consumer.read(bd);
57 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument); 57 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument);
58 58
59 ByteData readData = dataPipe.consumer.beginRead(10); 59 ByteData readData = dataPipe.consumer.beginRead();
60 Expect.isNull(readData); 60 Expect.isNull(readData);
61 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument); 61 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument);
62 dataPipe.consumer.endRead(10); 62 dataPipe.consumer.endRead(10);
63 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument); 63 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument);
64 64
65 // Shared buffer. 65 // Shared buffer.
66 MojoSharedBuffer sharedBuffer = new MojoSharedBuffer.create(10); 66 MojoSharedBuffer sharedBuffer = new MojoSharedBuffer.create(10);
67 Expect.isNotNull(sharedBuffer); 67 Expect.isNotNull(sharedBuffer);
68 sharedBuffer.close(); 68 sharedBuffer.close();
69 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate(sharedBuffer); 69 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate(sharedBuffer);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 103
104 // Write end1. 104 // Write end1.
105 String hello = "hello"; 105 String hello = "hello";
106 ByteData helloData = 106 ByteData helloData =
107 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); 107 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer);
108 int result = end1.write(helloData); 108 int result = end1.write(helloData);
109 Expect.isTrue(result == MojoResult.kOk); 109 Expect.isTrue(result == MojoResult.kOk);
110 110
111 // end0 should now be readable. 111 // end0 should now be readable.
112 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h], 112 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h],
113 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); 113 [MojoHandleSignals.kReadable], MojoHandle.deadlineIndefinite);
114 Expect.isTrue(mwmr.result == MojoResult.kOk); 114 Expect.isTrue(mwmr.result == MojoResult.kOk);
115 115
116 // Read from end0. 116 // Read from end0.
117 MojoMessagePipeReadResult readResult = end0.read(data); 117 MojoMessagePipeReadResult readResult = end0.read(data);
118 Expect.isNotNull(readResult); 118 Expect.isNotNull(readResult);
119 Expect.isTrue(readResult.status == MojoResult.kOk); 119 Expect.isTrue(readResult.status == MojoResult.kOk);
120 Expect.equals(readResult.bytesRead, helloData.lengthInBytes); 120 Expect.equals(readResult.bytesRead, helloData.lengthInBytes);
121 Expect.equals(readResult.handlesRead, 0); 121 Expect.equals(readResult.handlesRead, 0);
122 122
123 String hello_result = new String.fromCharCodes( 123 String hello_result = new String.fromCharCodes(
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // Consumer should not be readable. 155 // Consumer should not be readable.
156 MojoWaitResult mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); 156 MojoWaitResult mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0);
157 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded); 157 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded);
158 158
159 // Producer should be writable. 159 // Producer should be writable.
160 mwr = producer.handle.wait(MojoHandleSignals.kWritable, 0); 160 mwr = producer.handle.wait(MojoHandleSignals.kWritable, 0);
161 Expect.isTrue(mwr.result == MojoResult.kOk); 161 Expect.isTrue(mwr.result == MojoResult.kOk);
162 162
163 // Try to read from consumer. 163 // Try to read from consumer.
164 ByteData buffer = new ByteData(20); 164 ByteData buffer = new ByteData(20);
165 consumer.read(buffer, buffer.lengthInBytes, MojoDataPipeConsumer.FLAG_NONE); 165 consumer.read(buffer, buffer.lengthInBytes, MojoDataPipeConsumer.flagNone);
166 Expect.isTrue(consumer.status == MojoResult.kShouldWait); 166 Expect.isTrue(consumer.status == MojoResult.kShouldWait);
167 167
168 // Try to begin a two-phase read from consumer. 168 // Try to begin a two-phase read from consumer.
169 ByteData b = consumer.beginRead(20, MojoDataPipeConsumer.FLAG_NONE); 169 ByteData b = consumer.beginRead(MojoDataPipeConsumer.flagNone);
170 Expect.isNull(b); 170 Expect.isNull(b);
171 Expect.isTrue(consumer.status == MojoResult.kShouldWait); 171 Expect.isTrue(consumer.status == MojoResult.kShouldWait);
172 172
173 // Write to producer. 173 // Write to producer.
174 String hello = "hello "; 174 String hello = "hello ";
175 ByteData helloData = 175 ByteData helloData =
176 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); 176 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer);
177 int written = producer.write( 177 int written = producer.write(
178 helloData, helloData.lengthInBytes, MojoDataPipeProducer.FLAG_NONE); 178 helloData, helloData.lengthInBytes, MojoDataPipeProducer.flagNone);
179 Expect.isTrue(producer.status == MojoResult.kOk); 179 Expect.isTrue(producer.status == MojoResult.kOk);
180 Expect.equals(written, helloData.lengthInBytes); 180 Expect.equals(written, helloData.lengthInBytes);
181 181
182 // Now that we have written, the consumer should be readable. 182 // Now that we have written, the consumer should be readable.
183 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h], 183 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h],
184 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); 184 [MojoHandleSignals.kReadable], MojoHandle.deadlineIndefinite);
185 Expect.isTrue(mwr.result == MojoResult.kOk); 185 Expect.isTrue(mwr.result == MojoResult.kOk);
186 186
187 // Do a two-phase write to the producer. 187 // Do a two-phase write to the producer.
188 ByteData twoPhaseWrite = 188 ByteData twoPhaseWrite = producer.beginWrite(MojoDataPipeProducer.flagNone);
189 producer.beginWrite(20, MojoDataPipeProducer.FLAG_NONE);
190 Expect.isTrue(producer.status == MojoResult.kOk); 189 Expect.isTrue(producer.status == MojoResult.kOk);
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 == MojoResult.kOk); 196 Expect.isTrue(producer.status == MojoResult.kOk);
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.flagNone);
201 Expect.isTrue(consumer.status == MojoResult.kOk); 200 Expect.isTrue(consumer.status == MojoResult.kOk);
202 Expect.equals(read, 1); 201 Expect.equals(read, 1);
203 202
204 // Close the producer. 203 // Close the producer.
205 int result = producer.handle.close(); 204 int result = producer.handle.close();
206 Expect.isTrue(result == MojoResult.kOk); 205 Expect.isTrue(result == MojoResult.kOk);
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 == MojoResult.kOk); 209 Expect.isTrue(mwr.result == MojoResult.kOk);
211 210
212 // Get the number of remaining bytes. 211 // Get the number of remaining bytes.
213 int remaining = consumer.read(null, 0, MojoDataPipeConsumer.FLAG_QUERY); 212 int remaining = consumer.read(null, 0, MojoDataPipeConsumer.flagQuery);
214 Expect.isTrue(consumer.status == MojoResult.kOk); 213 Expect.isTrue(consumer.status == MojoResult.kOk);
215 Expect.equals(remaining, "hello world".length - 1); 214 Expect.equals(remaining, "hello world".length - 1);
216 215
217 // Do a two-phase read. 216 // Do a two-phase read.
218 ByteData twoPhaseRead = 217 ByteData twoPhaseRead = consumer.beginRead(MojoDataPipeConsumer.flagNone);
219 consumer.beginRead(remaining, MojoDataPipeConsumer.FLAG_NONE);
220 Expect.isTrue(consumer.status == MojoResult.kOk); 218 Expect.isTrue(consumer.status == MojoResult.kOk);
221 Expect.isNotNull(twoPhaseRead); 219 Expect.isNotNull(twoPhaseRead);
222 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining); 220 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining);
223 221
224 Uint8List uint8_list = buffer.buffer.asUint8List(); 222 Uint8List uint8_list = buffer.buffer.asUint8List();
225 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List()); 223 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List());
226 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes); 224 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes);
227 225
228 consumer.endRead(twoPhaseRead.lengthInBytes); 226 consumer.endRead(twoPhaseRead.lengthInBytes);
229 Expect.isTrue(consumer.status == MojoResult.kOk); 227 Expect.isTrue(consumer.status == MojoResult.kOk);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 328
331 main() async { 329 main() async {
332 invalidHandleTest(); 330 invalidHandleTest();
333 basicMessagePipeTest(); 331 basicMessagePipeTest();
334 basicDataPipeTest(); 332 basicDataPipeTest();
335 basicSharedBufferTest(); 333 basicSharedBufferTest();
336 await fillerDrainerTest(); 334 await fillerDrainerTest();
337 utilsTest(); 335 utilsTest();
338 processTest(); 336 processTest();
339 } 337 }
OLDNEW
« no previous file with comments | « mojo/dart/packages/mojo/sdk_ext_sources.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698