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

Side by Side Diff: mojo/system/raw_channel_posix_unittest.cc

Issue 173333002: Mojo: Make MessageInTransit more opaque still. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/raw_channel_posix.cc ('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 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 read(handle_.fd, buffer, sizeof(buffer))); 138 read(handle_.fd, buffer, sizeof(buffer)));
139 if (read_size < 0) { 139 if (read_size < 0) {
140 PCHECK(errno == EAGAIN || errno == EWOULDBLOCK); 140 PCHECK(errno == EAGAIN || errno == EWOULDBLOCK);
141 read_size = 0; 141 read_size = 0;
142 } 142 }
143 143
144 // Append newly-read data to |bytes_|. 144 // Append newly-read data to |bytes_|.
145 bytes_.insert(bytes_.end(), buffer, buffer + read_size); 145 bytes_.insert(bytes_.end(), buffer, buffer + read_size);
146 146
147 // If we have the header.... 147 // If we have the header....
148 if (bytes_.size() >= sizeof(MessageInTransit)) { 148 size_t message_size;
149 const MessageInTransit* message = 149 if (MessageInTransit::GetNextMessageSize(bytes_.data(), bytes_.size(),
150 reinterpret_cast<const MessageInTransit*>(bytes_.data()); 150 &message_size)) {
151 CHECK_EQ(reinterpret_cast<size_t>(message) % 151 // If we've read the whole message....
152 MessageInTransit::kMessageAlignment, 0u); 152 if (bytes_.size() >= message_size) {
153 const MessageInTransit* message =
154 MessageInTransit::CreateReadOnlyFromBuffer(bytes_.data());
155 CHECK_EQ(message->main_buffer_size(), message_size);
153 156
154 if (message->data_size() != expected_size) { 157 if (message->data_size() != expected_size) {
155 LOG(ERROR) << "Wrong size: " << message->data_size() << " instead of " 158 LOG(ERROR) << "Wrong size: " << message_size << " instead of "
156 << expected_size << " bytes."; 159 << expected_size << " bytes.";
157 return false; 160 return false;
158 } 161 }
159 162
160 // If we've read the whole message....
161 if (bytes_.size() >= message->main_buffer_size()) {
162 if (!CheckMessageData(message->data(), message->data_size())) { 163 if (!CheckMessageData(message->data(), message->data_size())) {
163 LOG(ERROR) << "Incorrect message data."; 164 LOG(ERROR) << "Incorrect message data.";
164 return false; 165 return false;
165 } 166 }
166 167
167 // Erase message data. 168 // Erase message data.
168 bytes_.erase(bytes_.begin(), 169 bytes_.erase(bytes_.begin(),
169 bytes_.begin() + 170 bytes_.begin() +
170 message->main_buffer_size()); 171 message->main_buffer_size());
171 return true; 172 return true;
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 FROM_HERE, 547 FROM_HERE,
547 base::Bind(&RawChannel::Shutdown, 548 base::Bind(&RawChannel::Shutdown,
548 base::Unretained(rc.get()))); 549 base::Unretained(rc.get())));
549 550
550 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); 551 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1)));
551 } 552 }
552 553
553 } // namespace 554 } // namespace
554 } // namespace system 555 } // namespace system
555 } // namespace mojo 556 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/raw_channel_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698