OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function runWithPipe(mojo, test) { |
| 6 var pipe = mojo.core.createMessagePipe(); |
| 7 |
| 8 test(mojo, pipe); |
| 9 |
| 10 var result0 = mojo.core.close(pipe.handle0); |
| 11 mojo.gtest.expectEqual(result0, mojo.core.RESULT_OK, |
| 12 "result0 is " + result0); |
| 13 |
| 14 var result1 = mojo.core.close(pipe.handle1); |
| 15 mojo.gtest.expectEqual(result1, mojo.core.RESULT_OK, |
| 16 "result1 is " + result1); |
| 17 } |
| 18 |
| 19 function testNop(mojo, pipe) { |
| 20 } |
| 21 |
| 22 function testReadAndWriteMessage(mojo, pipe) { |
| 23 var senderData = new Uint8Array(42); |
| 24 for (var i = 0; i < senderData.length; ++i) { |
| 25 senderData[i] = i * i; |
| 26 } |
| 27 |
| 28 var result = mojo.core.writeMessage( |
| 29 pipe.handle0, senderData, [], |
| 30 mojo.core.WRITE_MESSAGE_FLAG_NONE); |
| 31 |
| 32 mojo.gtest.expectEqual(result, mojo.core.RESULT_OK, |
| 33 "writeMessage returned RESULT_OK: " + result); |
| 34 |
| 35 var receiverData = new Uint8Array(50); |
| 36 |
| 37 var mesage = mojo.core.readMessage( |
| 38 pipe.handle1, receiverData, 10, |
| 39 mojo.core.READ_MESSAGE_FLAG_NONE) |
| 40 |
| 41 mojo.gtest.expectEqual(mesage.result, mojo.core.RESULT_OK, |
| 42 "mesage.result is " + mesage.result); |
| 43 mojo.gtest.expectEqual(mesage.bytesRead, 42, |
| 44 "mesage.bytesRead is " + mesage.bytesRead); |
| 45 mojo.gtest.expectEqual(mesage.handles.length, 0, |
| 46 "mesage.handles.length is " + mesage.handles.length); |
| 47 |
| 48 for (var i = 0; i < mesage.bytesRead; ++i) { |
| 49 mojo.gtest.expectEqual(receiverData[i], (i * i) & 0xFF, |
| 50 "receiverData[" + i + "] is " + receiverData[i]); |
| 51 } |
| 52 } |
| 53 |
| 54 function main(mojo) { |
| 55 runWithPipe(mojo, testNop); |
| 56 runWithPipe(mojo, testReadAndWriteMessage); |
| 57 } |
OLD | NEW |