OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 // TODO(vtl): Factor out the remaining POSIX-specific bits of this test (once we | 5 // TODO(vtl): Factor out the remaining POSIX-specific bits of this test (once we |
6 // have a non-POSIX implementation). | 6 // have a non-POSIX implementation). |
7 | 7 |
8 #include "mojo/system/raw_channel.h" | 8 #include "mojo/system/raw_channel.h" |
9 | 9 |
10 #include <fcntl.h> | 10 #include <fcntl.h> |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 60 |
61 void InitOnIOThread(RawChannel* raw_channel) { | 61 void InitOnIOThread(RawChannel* raw_channel) { |
62 CHECK(raw_channel->Init()); | 62 CHECK(raw_channel->Init()); |
63 } | 63 } |
64 | 64 |
65 bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, | 65 bool WriteTestMessageToHandle(const embedder::PlatformHandle& handle, |
66 uint32_t num_bytes) { | 66 uint32_t num_bytes) { |
67 MessageInTransit* message = MakeTestMessage(num_bytes); | 67 MessageInTransit* message = MakeTestMessage(num_bytes); |
68 | 68 |
69 ssize_t write_size = HANDLE_EINTR( | 69 ssize_t write_size = HANDLE_EINTR( |
70 write(handle.fd, message, message->size_with_header_and_padding())); | 70 write(handle.fd, message->main_buffer(), message->main_buffer_size())); |
71 bool result = write_size == | 71 bool result = write_size == static_cast<ssize_t>(message->main_buffer_size()); |
72 static_cast<ssize_t>(message->size_with_header_and_padding()); | |
73 message->Destroy(); | 72 message->Destroy(); |
74 return result; | 73 return result; |
75 } | 74 } |
76 | 75 |
77 // ----------------------------------------------------------------------------- | 76 // ----------------------------------------------------------------------------- |
78 | 77 |
79 class RawChannelPosixTest : public test::TestWithIOThreadBase { | 78 class RawChannelPosixTest : public test::TestWithIOThreadBase { |
80 public: | 79 public: |
81 RawChannelPosixTest() {} | 80 RawChannelPosixTest() {} |
82 virtual ~RawChannelPosixTest() {} | 81 virtual ~RawChannelPosixTest() {} |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 CHECK_EQ(reinterpret_cast<size_t>(message) % | 151 CHECK_EQ(reinterpret_cast<size_t>(message) % |
153 MessageInTransit::kMessageAlignment, 0u); | 152 MessageInTransit::kMessageAlignment, 0u); |
154 | 153 |
155 if (message->data_size() != expected_size) { | 154 if (message->data_size() != expected_size) { |
156 LOG(ERROR) << "Wrong size: " << message->data_size() << " instead of " | 155 LOG(ERROR) << "Wrong size: " << message->data_size() << " instead of " |
157 << expected_size << " bytes."; | 156 << expected_size << " bytes."; |
158 return false; | 157 return false; |
159 } | 158 } |
160 | 159 |
161 // If we've read the whole message.... | 160 // If we've read the whole message.... |
162 if (bytes_.size() >= message->size_with_header_and_padding()) { | 161 if (bytes_.size() >= message->main_buffer_size()) { |
163 if (!CheckMessageData(message->data(), message->data_size())) { | 162 if (!CheckMessageData(message->data(), message->data_size())) { |
164 LOG(ERROR) << "Incorrect message data."; | 163 LOG(ERROR) << "Incorrect message data."; |
165 return false; | 164 return false; |
166 } | 165 } |
167 | 166 |
168 // Erase message data. | 167 // Erase message data. |
169 bytes_.erase(bytes_.begin(), | 168 bytes_.erase(bytes_.begin(), |
170 bytes_.begin() + | 169 bytes_.begin() + |
171 message->size_with_header_and_padding()); | 170 message->main_buffer_size()); |
172 return true; | 171 return true; |
173 } | 172 } |
174 } | 173 } |
175 | 174 |
176 if (static_cast<size_t>(read_size) < sizeof(buffer)) { | 175 if (static_cast<size_t>(read_size) < sizeof(buffer)) { |
177 i++; | 176 i++; |
178 base::PlatformThread::Sleep( | 177 base::PlatformThread::Sleep( |
179 base::TimeDelta::FromMilliseconds(kMessageReaderSleepMs)); | 178 base::TimeDelta::FromMilliseconds(kMessageReaderSleepMs)); |
180 } | 179 } |
181 } | 180 } |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 FROM_HERE, | 546 FROM_HERE, |
548 base::Bind(&RawChannel::Shutdown, | 547 base::Bind(&RawChannel::Shutdown, |
549 base::Unretained(rc.get()))); | 548 base::Unretained(rc.get()))); |
550 | 549 |
551 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); | 550 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
552 } | 551 } |
553 | 552 |
554 } // namespace | 553 } // namespace |
555 } // namespace system | 554 } // namespace system |
556 } // namespace mojo | 555 } // namespace mojo |
OLD | NEW |