| 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: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:_testing/expect.dart'; | 10 import 'package:_testing/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.INVALID); |
| 15 | 15 |
| 16 // Close. | 16 // Close. |
| 17 MojoResult result = invalidHandle.close(); | 17 int result = invalidHandle.close(); |
| 18 Expect.isTrue(result.isInvalidArgument); | 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.isInvalidArgument); | 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.DEADLINE_INDEFINITE); |
| 27 Expect.isTrue(mwmr.result.isInvalidArgument); | 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.isInvalidArgument); | 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.isInvalidArgument); | 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.isInvalidArgument); | 48 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument); |
| 49 | 49 |
| 50 ByteData writeData = dataPipe.producer.beginWrite(10); | 50 ByteData writeData = dataPipe.producer.beginWrite(10); |
| 51 Expect.isNull(writeData); | 51 Expect.isNull(writeData); |
| 52 Expect.isTrue(dataPipe.producer.status.isInvalidArgument); | 52 Expect.isTrue(dataPipe.producer.status == MojoResult.kInvalidArgument); |
| 53 dataPipe.producer.endWrite(10); | 53 dataPipe.producer.endWrite(10); |
| 54 Expect.isTrue(dataPipe.producer.status.isInvalidArgument); | 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.isInvalidArgument); | 57 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument); |
| 58 | 58 |
| 59 ByteData readData = dataPipe.consumer.beginRead(10); | 59 ByteData readData = dataPipe.consumer.beginRead(10); |
| 60 Expect.isNull(readData); | 60 Expect.isNull(readData); |
| 61 Expect.isTrue(dataPipe.consumer.status.isInvalidArgument); | 61 Expect.isTrue(dataPipe.consumer.status == MojoResult.kInvalidArgument); |
| 62 dataPipe.consumer.endRead(10); | 62 dataPipe.consumer.endRead(10); |
| 63 Expect.isTrue(dataPipe.consumer.status.isInvalidArgument); | 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); |
| 70 Expect.isNull(duplicate); | 70 Expect.isNull(duplicate); |
| 71 | 71 |
| 72 sharedBuffer = new MojoSharedBuffer.create(10); | 72 sharedBuffer = new MojoSharedBuffer.create(10); |
| 73 Expect.isNotNull(sharedBuffer); | 73 Expect.isNotNull(sharedBuffer); |
| 74 sharedBuffer.close(); | 74 sharedBuffer.close(); |
| 75 result = sharedBuffer.map(0, 10); | 75 result = sharedBuffer.map(0, 10); |
| 76 Expect.isTrue(result.isInvalidArgument); | 76 Expect.isTrue(result == MojoResult.kInvalidArgument); |
| 77 } | 77 } |
| 78 | 78 |
| 79 basicMessagePipeTest() { | 79 basicMessagePipeTest() { |
| 80 MojoMessagePipe pipe = new MojoMessagePipe(); | 80 MojoMessagePipe pipe = new MojoMessagePipe(); |
| 81 Expect.isNotNull(pipe); | 81 Expect.isNotNull(pipe); |
| 82 Expect.isTrue(pipe.status.isOk); | 82 Expect.isTrue(pipe.status == MojoResult.kOk); |
| 83 Expect.isNotNull(pipe.endpoints); | 83 Expect.isNotNull(pipe.endpoints); |
| 84 | 84 |
| 85 MojoMessagePipeEndpoint end0 = pipe.endpoints[0]; | 85 MojoMessagePipeEndpoint end0 = pipe.endpoints[0]; |
| 86 MojoMessagePipeEndpoint end1 = pipe.endpoints[1]; | 86 MojoMessagePipeEndpoint end1 = pipe.endpoints[1]; |
| 87 Expect.isTrue(end0.handle.isValid); | 87 Expect.isTrue(end0.handle.isValid); |
| 88 Expect.isTrue(end1.handle.isValid); | 88 Expect.isTrue(end1.handle.isValid); |
| 89 | 89 |
| 90 // Not readable, yet. | 90 // Not readable, yet. |
| 91 MojoWaitResult mwr = end0.handle.wait(MojoHandleSignals.kReadable, 0); | 91 MojoWaitResult mwr = end0.handle.wait(MojoHandleSignals.kReadable, 0); |
| 92 Expect.isTrue(mwr.result.isDeadlineExceeded); | 92 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded); |
| 93 | 93 |
| 94 // Should be writable. | 94 // Should be writable. |
| 95 mwr = end0.handle.wait(MojoHandleSignals.kWritable, 0); | 95 mwr = end0.handle.wait(MojoHandleSignals.kWritable, 0); |
| 96 Expect.isTrue(mwr.result.isOk); | 96 Expect.isTrue(mwr.result == MojoResult.kOk); |
| 97 | 97 |
| 98 // Try to read. | 98 // Try to read. |
| 99 ByteData data = new ByteData(10); | 99 ByteData data = new ByteData(10); |
| 100 end0.read(data); | 100 end0.read(data); |
| 101 Expect.isTrue(end0.status.isShouldWait); | 101 Expect.isTrue(end0.status == MojoResult.kShouldWait); |
| 102 | 102 |
| 103 // Write end1. | 103 // Write end1. |
| 104 String hello = "hello"; | 104 String hello = "hello"; |
| 105 ByteData helloData = | 105 ByteData helloData = |
| 106 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); | 106 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); |
| 107 MojoResult result = end1.write(helloData); | 107 int result = end1.write(helloData); |
| 108 Expect.isTrue(result.isOk); | 108 Expect.isTrue(result == MojoResult.kOk); |
| 109 | 109 |
| 110 // end0 should now be readable. | 110 // end0 should now be readable. |
| 111 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h], | 111 MojoWaitManyResult mwmr = MojoHandle.waitMany([end0.handle.h], |
| 112 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); | 112 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); |
| 113 Expect.isTrue(mwmr.result.isOk); | 113 Expect.isTrue(mwmr.result == MojoResult.kOk); |
| 114 | 114 |
| 115 // Read from end0. | 115 // Read from end0. |
| 116 MojoMessagePipeReadResult readResult = end0.read(data); | 116 MojoMessagePipeReadResult readResult = end0.read(data); |
| 117 Expect.isNotNull(readResult); | 117 Expect.isNotNull(readResult); |
| 118 Expect.isTrue(readResult.status.isOk); | 118 Expect.isTrue(readResult.status == MojoResult.kOk); |
| 119 Expect.equals(readResult.bytesRead, helloData.lengthInBytes); | 119 Expect.equals(readResult.bytesRead, helloData.lengthInBytes); |
| 120 Expect.equals(readResult.handlesRead, 0); | 120 Expect.equals(readResult.handlesRead, 0); |
| 121 | 121 |
| 122 String hello_result = new String.fromCharCodes( | 122 String hello_result = new String.fromCharCodes( |
| 123 data.buffer.asUint8List().sublist(0, readResult.bytesRead).toList()); | 123 data.buffer.asUint8List().sublist(0, readResult.bytesRead).toList()); |
| 124 Expect.equals(hello_result, "hello"); | 124 Expect.equals(hello_result, "hello"); |
| 125 | 125 |
| 126 // end0 should no longer be readable. | 126 // end0 should no longer be readable. |
| 127 mwr = end0.handle.wait(MojoHandleSignals.kReadable, 10); | 127 mwr = end0.handle.wait(MojoHandleSignals.kReadable, 10); |
| 128 Expect.isTrue(mwr.result.isDeadlineExceeded); | 128 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded); |
| 129 | 129 |
| 130 // Close end0's handle. | 130 // Close end0's handle. |
| 131 result = end0.handle.close(); | 131 result = end0.handle.close(); |
| 132 Expect.isTrue(result.isOk); | 132 Expect.isTrue(result == MojoResult.kOk); |
| 133 | 133 |
| 134 // end1 should no longer be readable or writable. | 134 // end1 should no longer be readable or writable. |
| 135 mwr = end1.handle.wait(MojoHandleSignals.kReadWrite, 1000); | 135 mwr = end1.handle.wait(MojoHandleSignals.kReadWrite, 1000); |
| 136 Expect.isTrue(mwr.result.isFailedPrecondition); | 136 Expect.isTrue(mwr.result == MojoResult.kFailedPrecondition); |
| 137 | 137 |
| 138 result = end1.handle.close(); | 138 result = end1.handle.close(); |
| 139 Expect.isTrue(result.isOk); | 139 Expect.isTrue(result == MojoResult.kOk); |
| 140 } | 140 } |
| 141 | 141 |
| 142 basicDataPipeTest() { | 142 basicDataPipeTest() { |
| 143 MojoDataPipe pipe = new MojoDataPipe(); | 143 MojoDataPipe pipe = new MojoDataPipe(); |
| 144 Expect.isNotNull(pipe); | 144 Expect.isNotNull(pipe); |
| 145 Expect.isTrue(pipe.status.isOk); | 145 Expect.isTrue(pipe.status == MojoResult.kOk); |
| 146 Expect.isTrue(pipe.consumer.handle.isValid); | 146 Expect.isTrue(pipe.consumer.handle.isValid); |
| 147 Expect.isTrue(pipe.producer.handle.isValid); | 147 Expect.isTrue(pipe.producer.handle.isValid); |
| 148 | 148 |
| 149 MojoDataPipeProducer producer = pipe.producer; | 149 MojoDataPipeProducer producer = pipe.producer; |
| 150 MojoDataPipeConsumer consumer = pipe.consumer; | 150 MojoDataPipeConsumer consumer = pipe.consumer; |
| 151 Expect.isTrue(producer.handle.isValid); | 151 Expect.isTrue(producer.handle.isValid); |
| 152 Expect.isTrue(consumer.handle.isValid); | 152 Expect.isTrue(consumer.handle.isValid); |
| 153 | 153 |
| 154 // Consumer should not be readable. | 154 // Consumer should not be readable. |
| 155 MojoWaitResult mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); | 155 MojoWaitResult mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); |
| 156 Expect.isTrue(mwr.result.isDeadlineExceeded); | 156 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded); |
| 157 | 157 |
| 158 // Producer should be writable. | 158 // Producer should be writable. |
| 159 mwr = producer.handle.wait(MojoHandleSignals.kWritable, 0); | 159 mwr = producer.handle.wait(MojoHandleSignals.kWritable, 0); |
| 160 Expect.isTrue(mwr.result.isOk); | 160 Expect.isTrue(mwr.result == MojoResult.kOk); |
| 161 | 161 |
| 162 // Try to read from consumer. | 162 // Try to read from consumer. |
| 163 ByteData buffer = new ByteData(20); | 163 ByteData buffer = new ByteData(20); |
| 164 consumer.read(buffer, buffer.lengthInBytes, MojoDataPipeConsumer.FLAG_NONE); | 164 consumer.read(buffer, buffer.lengthInBytes, MojoDataPipeConsumer.FLAG_NONE); |
| 165 Expect.isTrue(consumer.status.isShouldWait); | 165 Expect.isTrue(consumer.status == MojoResult.kShouldWait); |
| 166 | 166 |
| 167 // Try to begin a two-phase read from consumer. | 167 // Try to begin a two-phase read from consumer. |
| 168 ByteData b = consumer.beginRead(20, MojoDataPipeConsumer.FLAG_NONE); | 168 ByteData b = consumer.beginRead(20, MojoDataPipeConsumer.FLAG_NONE); |
| 169 Expect.isNull(b); | 169 Expect.isNull(b); |
| 170 Expect.isTrue(consumer.status.isShouldWait); | 170 Expect.isTrue(consumer.status == MojoResult.kShouldWait); |
| 171 | 171 |
| 172 // Write to producer. | 172 // Write to producer. |
| 173 String hello = "hello "; | 173 String hello = "hello "; |
| 174 ByteData helloData = | 174 ByteData helloData = |
| 175 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); | 175 new ByteData.view((new Uint8List.fromList(hello.codeUnits)).buffer); |
| 176 int written = producer.write( | 176 int written = producer.write( |
| 177 helloData, helloData.lengthInBytes, MojoDataPipeProducer.FLAG_NONE); | 177 helloData, helloData.lengthInBytes, MojoDataPipeProducer.FLAG_NONE); |
| 178 Expect.isTrue(producer.status.isOk); | 178 Expect.isTrue(producer.status == MojoResult.kOk); |
| 179 Expect.equals(written, helloData.lengthInBytes); | 179 Expect.equals(written, helloData.lengthInBytes); |
| 180 | 180 |
| 181 // Now that we have written, the consumer should be readable. | 181 // Now that we have written, the consumer should be readable. |
| 182 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h], | 182 MojoWaitManyResult mwmr = MojoHandle.waitMany([consumer.handle.h], |
| 183 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); | 183 [MojoHandleSignals.kReadable], MojoHandle.DEADLINE_INDEFINITE); |
| 184 Expect.isTrue(mwr.result.isOk); | 184 Expect.isTrue(mwr.result == MojoResult.kOk); |
| 185 | 185 |
| 186 // Do a two-phase write to the producer. | 186 // Do a two-phase write to the producer. |
| 187 ByteData twoPhaseWrite = | 187 ByteData twoPhaseWrite = |
| 188 producer.beginWrite(20, MojoDataPipeProducer.FLAG_NONE); | 188 producer.beginWrite(20, MojoDataPipeProducer.FLAG_NONE); |
| 189 Expect.isTrue(producer.status.isOk); | 189 Expect.isTrue(producer.status == MojoResult.kOk); |
| 190 Expect.isNotNull(twoPhaseWrite); | 190 Expect.isNotNull(twoPhaseWrite); |
| 191 Expect.isTrue(twoPhaseWrite.lengthInBytes >= 20); | 191 Expect.isTrue(twoPhaseWrite.lengthInBytes >= 20); |
| 192 | 192 |
| 193 String world = "world"; | 193 String world = "world"; |
| 194 twoPhaseWrite.buffer.asUint8List().setAll(0, world.codeUnits); | 194 twoPhaseWrite.buffer.asUint8List().setAll(0, world.codeUnits); |
| 195 producer.endWrite(Uint8List.BYTES_PER_ELEMENT * world.codeUnits.length); | 195 producer.endWrite(Uint8List.BYTES_PER_ELEMENT * world.codeUnits.length); |
| 196 Expect.isTrue(producer.status.isOk); | 196 Expect.isTrue(producer.status == MojoResult.kOk); |
| 197 | 197 |
| 198 // Read one character from consumer. | 198 // Read one character from consumer. |
| 199 int read = consumer.read(buffer, 1, MojoDataPipeConsumer.FLAG_NONE); | 199 int read = consumer.read(buffer, 1, MojoDataPipeConsumer.FLAG_NONE); |
| 200 Expect.isTrue(consumer.status.isOk); | 200 Expect.isTrue(consumer.status == MojoResult.kOk); |
| 201 Expect.equals(read, 1); | 201 Expect.equals(read, 1); |
| 202 | 202 |
| 203 // Close the producer. | 203 // Close the producer. |
| 204 MojoResult result = producer.handle.close(); | 204 int result = producer.handle.close(); |
| 205 Expect.isTrue(result.isOk); | 205 Expect.isTrue(result == MojoResult.kOk); |
| 206 | 206 |
| 207 // Consumer should still be readable. | 207 // Consumer should still be readable. |
| 208 mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); | 208 mwr = consumer.handle.wait(MojoHandleSignals.kReadable, 0); |
| 209 Expect.isTrue(mwr.result.isOk); | 209 Expect.isTrue(mwr.result == MojoResult.kOk); |
| 210 | 210 |
| 211 // Get the number of remaining bytes. | 211 // Get the number of remaining bytes. |
| 212 int remaining = consumer.read(null, 0, MojoDataPipeConsumer.FLAG_QUERY); | 212 int remaining = consumer.read(null, 0, MojoDataPipeConsumer.FLAG_QUERY); |
| 213 Expect.isTrue(consumer.status.isOk); | 213 Expect.isTrue(consumer.status == MojoResult.kOk); |
| 214 Expect.equals(remaining, "hello world".length - 1); | 214 Expect.equals(remaining, "hello world".length - 1); |
| 215 | 215 |
| 216 // Do a two-phase read. | 216 // Do a two-phase read. |
| 217 ByteData twoPhaseRead = | 217 ByteData twoPhaseRead = |
| 218 consumer.beginRead(remaining, MojoDataPipeConsumer.FLAG_NONE); | 218 consumer.beginRead(remaining, MojoDataPipeConsumer.FLAG_NONE); |
| 219 Expect.isTrue(consumer.status.isOk); | 219 Expect.isTrue(consumer.status == MojoResult.kOk); |
| 220 Expect.isNotNull(twoPhaseRead); | 220 Expect.isNotNull(twoPhaseRead); |
| 221 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining); | 221 Expect.isTrue(twoPhaseRead.lengthInBytes <= remaining); |
| 222 | 222 |
| 223 Uint8List uint8_list = buffer.buffer.asUint8List(); | 223 Uint8List uint8_list = buffer.buffer.asUint8List(); |
| 224 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List()); | 224 uint8_list.setAll(1, twoPhaseRead.buffer.asUint8List()); |
| 225 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes); | 225 uint8_list = uint8_list.sublist(0, 1 + twoPhaseRead.lengthInBytes); |
| 226 | 226 |
| 227 consumer.endRead(twoPhaseRead.lengthInBytes); | 227 consumer.endRead(twoPhaseRead.lengthInBytes); |
| 228 Expect.isTrue(consumer.status.isOk); | 228 Expect.isTrue(consumer.status == MojoResult.kOk); |
| 229 | 229 |
| 230 String helloWorld = new String.fromCharCodes(uint8_list.toList()); | 230 String helloWorld = new String.fromCharCodes(uint8_list.toList()); |
| 231 Expect.equals("hello world", helloWorld); | 231 Expect.equals("hello world", helloWorld); |
| 232 | 232 |
| 233 result = consumer.handle.close(); | 233 result = consumer.handle.close(); |
| 234 Expect.isTrue(result.isOk); | 234 Expect.isTrue(result == MojoResult.kOk); |
| 235 } | 235 } |
| 236 | 236 |
| 237 basicSharedBufferTest() { | 237 basicSharedBufferTest() { |
| 238 MojoSharedBuffer mojoBuffer = | 238 MojoSharedBuffer mojoBuffer = |
| 239 new MojoSharedBuffer.create(100, MojoSharedBuffer.CREATE_FLAG_NONE); | 239 new MojoSharedBuffer.create(100, MojoSharedBuffer.CREATE_FLAG_NONE); |
| 240 Expect.isNotNull(mojoBuffer); | 240 Expect.isNotNull(mojoBuffer); |
| 241 Expect.isNotNull(mojoBuffer.status); | 241 Expect.isNotNull(mojoBuffer.status); |
| 242 Expect.isTrue(mojoBuffer.status.isOk); | 242 Expect.isTrue(mojoBuffer.status == MojoResult.kOk); |
| 243 Expect.isNotNull(mojoBuffer.handle); | 243 Expect.isNotNull(mojoBuffer.handle); |
| 244 Expect.isTrue(mojoBuffer.handle is MojoHandle); | 244 Expect.isTrue(mojoBuffer.handle is MojoHandle); |
| 245 Expect.isTrue(mojoBuffer.handle.isValid); | 245 Expect.isTrue(mojoBuffer.handle.isValid); |
| 246 | 246 |
| 247 mojoBuffer.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE); | 247 mojoBuffer.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE); |
| 248 Expect.isNotNull(mojoBuffer.status); | 248 Expect.isNotNull(mojoBuffer.status); |
| 249 Expect.isTrue(mojoBuffer.status.isOk); | 249 Expect.isTrue(mojoBuffer.status == MojoResult.kOk); |
| 250 Expect.isNotNull(mojoBuffer.mapping); | 250 Expect.isNotNull(mojoBuffer.mapping); |
| 251 Expect.isTrue(mojoBuffer.mapping is ByteData); | 251 Expect.isTrue(mojoBuffer.mapping is ByteData); |
| 252 | 252 |
| 253 mojoBuffer.mapping.setInt8(50, 42); | 253 mojoBuffer.mapping.setInt8(50, 42); |
| 254 | 254 |
| 255 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate( | 255 MojoSharedBuffer duplicate = new MojoSharedBuffer.duplicate( |
| 256 mojoBuffer, MojoSharedBuffer.DUPLICATE_FLAG_NONE); | 256 mojoBuffer, MojoSharedBuffer.DUPLICATE_FLAG_NONE); |
| 257 Expect.isNotNull(duplicate); | 257 Expect.isNotNull(duplicate); |
| 258 Expect.isNotNull(duplicate.status); | 258 Expect.isNotNull(duplicate.status); |
| 259 Expect.isTrue(duplicate.status.isOk); | 259 Expect.isTrue(duplicate.status == MojoResult.kOk); |
| 260 Expect.isTrue(duplicate.handle is MojoHandle); | 260 Expect.isTrue(duplicate.handle is MojoHandle); |
| 261 Expect.isTrue(duplicate.handle.isValid); | 261 Expect.isTrue(duplicate.handle.isValid); |
| 262 | 262 |
| 263 duplicate.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE); | 263 duplicate.map(0, 100, MojoSharedBuffer.MAP_FLAG_NONE); |
| 264 Expect.isTrue(duplicate.status.isOk); | 264 Expect.isTrue(duplicate.status == MojoResult.kOk); |
| 265 Expect.isNotNull(duplicate.mapping); | 265 Expect.isNotNull(duplicate.mapping); |
| 266 Expect.isTrue(duplicate.mapping is ByteData); | 266 Expect.isTrue(duplicate.mapping is ByteData); |
| 267 | 267 |
| 268 mojoBuffer.close(); | 268 mojoBuffer.close(); |
| 269 mojoBuffer = null; | 269 mojoBuffer = null; |
| 270 | 270 |
| 271 duplicate.mapping.setInt8(51, 43); | 271 duplicate.mapping.setInt8(51, 43); |
| 272 | 272 |
| 273 duplicate.unmap(); | 273 duplicate.unmap(); |
| 274 Expect.isNotNull(duplicate.status); | 274 Expect.isNotNull(duplicate.status); |
| 275 Expect.isTrue(duplicate.status.isOk); | 275 Expect.isTrue(duplicate.status == MojoResult.kOk); |
| 276 Expect.isNull(duplicate.mapping); | 276 Expect.isNull(duplicate.mapping); |
| 277 | 277 |
| 278 duplicate.map(50, 50, MojoSharedBuffer.MAP_FLAG_NONE); | 278 duplicate.map(50, 50, MojoSharedBuffer.MAP_FLAG_NONE); |
| 279 Expect.isNotNull(duplicate.status); | 279 Expect.isNotNull(duplicate.status); |
| 280 Expect.isTrue(duplicate.status.isOk); | 280 Expect.isTrue(duplicate.status == MojoResult.kOk); |
| 281 Expect.isNotNull(duplicate.mapping); | 281 Expect.isNotNull(duplicate.mapping); |
| 282 Expect.isTrue(duplicate.mapping is ByteData); | 282 Expect.isTrue(duplicate.mapping is ByteData); |
| 283 | 283 |
| 284 Expect.equals(duplicate.mapping.getInt8(0), 42); | 284 Expect.equals(duplicate.mapping.getInt8(0), 42); |
| 285 Expect.equals(duplicate.mapping.getInt8(1), 43); | 285 Expect.equals(duplicate.mapping.getInt8(1), 43); |
| 286 | 286 |
| 287 duplicate.unmap(); | 287 duplicate.unmap(); |
| 288 Expect.isNotNull(duplicate.status); | 288 Expect.isNotNull(duplicate.status); |
| 289 Expect.isTrue(duplicate.status.isOk); | 289 Expect.isTrue(duplicate.status == MojoResult.kOk); |
| 290 Expect.isNull(duplicate.mapping); | 290 Expect.isNull(duplicate.mapping); |
| 291 | 291 |
| 292 duplicate.close(); | 292 duplicate.close(); |
| 293 duplicate = null; | 293 duplicate = null; |
| 294 } | 294 } |
| 295 | 295 |
| 296 fillerDrainerTest() async { | 296 fillerDrainerTest() async { |
| 297 MojoDataPipe pipe = new MojoDataPipe(); | 297 MojoDataPipe pipe = new MojoDataPipe(); |
| 298 Expect.isNotNull(pipe); | 298 Expect.isNotNull(pipe); |
| 299 Expect.isTrue(pipe.status.isOk); | 299 Expect.isTrue(pipe.status == MojoResult.kOk); |
| 300 Expect.isTrue(pipe.consumer.handle.isValid); | 300 Expect.isTrue(pipe.consumer.handle.isValid); |
| 301 Expect.isTrue(pipe.producer.handle.isValid); | 301 Expect.isTrue(pipe.producer.handle.isValid); |
| 302 | 302 |
| 303 MojoDataPipeProducer producer = pipe.producer; | 303 MojoDataPipeProducer producer = pipe.producer; |
| 304 MojoDataPipeConsumer consumer = pipe.consumer; | 304 MojoDataPipeConsumer consumer = pipe.consumer; |
| 305 Expect.isTrue(producer.handle.isValid); | 305 Expect.isTrue(producer.handle.isValid); |
| 306 Expect.isTrue(consumer.handle.isValid); | 306 Expect.isTrue(consumer.handle.isValid); |
| 307 | 307 |
| 308 String sentMessage = "Hello world!" * 1000; | 308 String sentMessage = "Hello world!" * 1000; |
| 309 ByteData producerData = new ByteData.view(UTF8.encode(sentMessage).buffer); | 309 ByteData producerData = new ByteData.view(UTF8.encode(sentMessage).buffer); |
| 310 DataPipeFiller.fillHandle(producer, producerData); | 310 DataPipeFiller.fillHandle(producer, producerData); |
| 311 | 311 |
| 312 ByteData consumerData = await DataPipeDrainer.drainHandle(consumer); | 312 ByteData consumerData = await DataPipeDrainer.drainHandle(consumer); |
| 313 Uint8List receivedBytes = new Uint8List.view(consumerData.buffer); | 313 Uint8List receivedBytes = new Uint8List.view(consumerData.buffer); |
| 314 String receivedMessage = new String.fromCharCodes(receivedBytes); | 314 String receivedMessage = new String.fromCharCodes(receivedBytes); |
| 315 | 315 |
| 316 Expect.equals(sentMessage, receivedMessage); | 316 Expect.equals(sentMessage, receivedMessage); |
| 317 Expect.isTrue(producer.status.isOk); | 317 Expect.isTrue(producer.status == MojoResult.kOk); |
| 318 Expect.isTrue(consumer.status.isOk); | 318 Expect.isTrue(consumer.status == MojoResult.kOk); |
| 319 } | 319 } |
| 320 | 320 |
| 321 utilsTest() { | 321 utilsTest() { |
| 322 int ticksa = getTimeTicksNow(); | 322 int ticksa = getTimeTicksNow(); |
| 323 Expect.isTrue(1000 < ticksa); | 323 Expect.isTrue(1000 < ticksa); |
| 324 | 324 |
| 325 // Wait for the clock to advance. | 325 // Wait for the clock to advance. |
| 326 MojoWaitResult mwr = (new MojoMessagePipe()).endpoints[0].handle.wait( | 326 MojoWaitResult mwr = (new MojoMessagePipe()).endpoints[0] |
| 327 MojoHandleSignals.kReadable, 1); | 327 .handle |
| 328 Expect.isTrue(mwr.result.isDeadlineExceeded); | 328 .wait(MojoHandleSignals.kReadable, 1); |
| 329 Expect.isTrue(mwr.result == MojoResult.kDeadlineExceeded); |
| 329 | 330 |
| 330 int ticksb = getTimeTicksNow(); | 331 int ticksb = getTimeTicksNow(); |
| 331 Expect.isTrue(ticksa < ticksb); | 332 Expect.isTrue(ticksa < ticksb); |
| 332 } | 333 } |
| 334 |
| 333 // TODO(rudominer) This probably belongs in a different file. | 335 // TODO(rudominer) This probably belongs in a different file. |
| 334 processTest() { | 336 processTest() { |
| 335 Expect.isTrue(pid > 0); | 337 Expect.isTrue(pid > 0); |
| 336 } | 338 } |
| 337 | 339 |
| 338 main() async { | 340 main() async { |
| 339 invalidHandleTest(); | 341 invalidHandleTest(); |
| 340 basicMessagePipeTest(); | 342 basicMessagePipeTest(); |
| 341 basicDataPipeTest(); | 343 basicDataPipeTest(); |
| 342 basicSharedBufferTest(); | 344 basicSharedBufferTest(); |
| 343 await fillerDrainerTest(); | 345 await fillerDrainerTest(); |
| 344 utilsTest(); | 346 utilsTest(); |
| 345 processTest(); | 347 processTest(); |
| 346 } | 348 } |
| OLD | NEW |