| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/nacl/nacl_ipc_adapter.h" | 5 #include "chrome/nacl/nacl_ipc_adapter.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 IPC::TestSink* sink_; | 67 IPC::TestSink* sink_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 // Tests a simple message getting rewritten sent from native code to NaCl. | 72 // Tests a simple message getting rewritten sent from native code to NaCl. |
| 73 TEST_F(NaClIPCAdapterTest, SimpleReceiveRewriting) { | 73 TEST_F(NaClIPCAdapterTest, SimpleReceiveRewriting) { |
| 74 int routing_id = 0x89898989; | 74 int routing_id = 0x89898989; |
| 75 uint32 type = 0x55555555; | 75 uint32 type = 0x55555555; |
| 76 IPC::Message input(routing_id, type, IPC::Message::PRIORITY_NORMAL); | 76 IPC::Message input(routing_id, type, IPC::Message::PRIORITY_NORMAL); |
| 77 uint32 flags = input.flags(); |
| 77 | 78 |
| 78 int value = 0x12345678; | 79 int value = 0x12345678; |
| 79 input.WriteInt(value); | 80 input.WriteInt(value); |
| 80 adapter_->OnMessageReceived(input); | 81 adapter_->OnMessageReceived(input); |
| 81 | 82 |
| 82 // Buffer just need to be big enough for our message with one int. | 83 // Buffer just need to be big enough for our message with one int. |
| 83 const int kBufSize = 64; | 84 const int kBufSize = 64; |
| 84 char buf[kBufSize]; | 85 char buf[kBufSize]; |
| 85 | 86 |
| 86 int bytes_read = BlockingReceive(buf, kBufSize); | 87 int bytes_read = BlockingReceive(buf, kBufSize); |
| 87 EXPECT_EQ(sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int), | 88 EXPECT_EQ(sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int), |
| 88 static_cast<size_t>(bytes_read)); | 89 static_cast<size_t>(bytes_read)); |
| 89 | 90 |
| 90 const NaClIPCAdapter::NaClMessageHeader* output_header = | 91 const NaClIPCAdapter::NaClMessageHeader* output_header = |
| 91 reinterpret_cast<const NaClIPCAdapter::NaClMessageHeader*>(buf); | 92 reinterpret_cast<const NaClIPCAdapter::NaClMessageHeader*>(buf); |
| 92 EXPECT_EQ(sizeof(int), output_header->payload_size); | 93 EXPECT_EQ(sizeof(int), output_header->payload_size); |
| 93 EXPECT_EQ(routing_id, output_header->routing); | 94 EXPECT_EQ(routing_id, output_header->routing); |
| 94 EXPECT_EQ(type, output_header->type); | 95 EXPECT_EQ(type, output_header->type); |
| 95 EXPECT_EQ(static_cast<uint32>(IPC::Message::PRIORITY_NORMAL), | 96 EXPECT_EQ(flags, output_header->flags); |
| 96 output_header->flags); | |
| 97 EXPECT_EQ(0u, output_header->num_fds); | 97 EXPECT_EQ(0u, output_header->num_fds); |
| 98 EXPECT_EQ(0u, output_header->pad); | 98 EXPECT_EQ(0u, output_header->pad); |
| 99 | 99 |
| 100 // Validate the payload. | 100 // Validate the payload. |
| 101 EXPECT_EQ(value, | 101 EXPECT_EQ(value, |
| 102 *reinterpret_cast<const int*>(&buf[ | 102 *reinterpret_cast<const int*>(&buf[ |
| 103 sizeof(NaClIPCAdapter::NaClMessageHeader)])); | 103 sizeof(NaClIPCAdapter::NaClMessageHeader)])); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Tests a simple message getting rewritten sent from NaCl to native code. | 106 // Tests a simple message getting rewritten sent from NaCl to native code. |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 EXPECT_EQ(-1, result); | 299 EXPECT_EQ(-1, result); |
| 300 | 300 |
| 301 // Test the "previously had an error" case. BlockingReceive should return | 301 // Test the "previously had an error" case. BlockingReceive should return |
| 302 // immediately if there was an error. | 302 // immediately if there was an error. |
| 303 result = BlockingReceive(buf, kBufSize); | 303 result = BlockingReceive(buf, kBufSize); |
| 304 EXPECT_EQ(-1, result); | 304 EXPECT_EQ(-1, result); |
| 305 | 305 |
| 306 thread.Join(); | 306 thread.Join(); |
| 307 } | 307 } |
| 308 | 308 |
| OLD | NEW |