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 #include "mojo/system/raw_channel.h" | 5 #include "mojo/system/raw_channel.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 namespace { | 35 namespace { |
36 | 36 |
37 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { | 37 scoped_ptr<MessageInTransit> MakeTestMessage(uint32_t num_bytes) { |
38 std::vector<unsigned char> bytes(num_bytes, 0); | 38 std::vector<unsigned char> bytes(num_bytes, 0); |
39 for (size_t i = 0; i < num_bytes; i++) | 39 for (size_t i = 0; i < num_bytes; i++) |
40 bytes[i] = static_cast<unsigned char>(i + num_bytes); | 40 bytes[i] = static_cast<unsigned char>(i + num_bytes); |
41 return make_scoped_ptr( | 41 return make_scoped_ptr( |
42 new MessageInTransit(MessageInTransit::kTypeMessagePipeEndpoint, | 42 new MessageInTransit(MessageInTransit::kTypeMessagePipeEndpoint, |
43 MessageInTransit::kSubtypeMessagePipeEndpointData, | 43 MessageInTransit::kSubtypeMessagePipeEndpointData, |
44 num_bytes, | 44 num_bytes, |
45 bytes.empty() ? NULL : &bytes[0])); | 45 bytes.empty() ? nullptr : &bytes[0])); |
46 } | 46 } |
47 | 47 |
48 bool CheckMessageData(const void* bytes, uint32_t num_bytes) { | 48 bool CheckMessageData(const void* bytes, uint32_t num_bytes) { |
49 const unsigned char* b = static_cast<const unsigned char*>(bytes); | 49 const unsigned char* b = static_cast<const unsigned char*>(bytes); |
50 for (uint32_t i = 0; i < num_bytes; i++) { | 50 for (uint32_t i = 0; i < num_bytes; i++) { |
51 if (b[i] != static_cast<unsigned char>(i + num_bytes)) | 51 if (b[i] != static_cast<unsigned char>(i + num_bytes)) |
52 return false; | 52 return false; |
53 } | 53 } |
54 return true; | 54 return true; |
55 } | 55 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 size_t read_size = 0; | 137 size_t read_size = 0; |
138 CHECK(mojo::test::NonBlockingRead( | 138 CHECK(mojo::test::NonBlockingRead( |
139 handle_, buffer, sizeof(buffer), &read_size)); | 139 handle_, buffer, sizeof(buffer), &read_size)); |
140 | 140 |
141 // Append newly-read data to |bytes_|. | 141 // Append newly-read data to |bytes_|. |
142 bytes_.insert(bytes_.end(), buffer, buffer + read_size); | 142 bytes_.insert(bytes_.end(), buffer, buffer + read_size); |
143 | 143 |
144 // If we have the header.... | 144 // If we have the header.... |
145 size_t message_size; | 145 size_t message_size; |
146 if (MessageInTransit::GetNextMessageSize( | 146 if (MessageInTransit::GetNextMessageSize( |
147 bytes_.empty() ? NULL : &bytes_[0], | 147 bytes_.empty() ? nullptr : &bytes_[0], |
148 bytes_.size(), | 148 bytes_.size(), |
149 &message_size)) { | 149 &message_size)) { |
150 // If we've read the whole message.... | 150 // If we've read the whole message.... |
151 if (bytes_.size() >= message_size) { | 151 if (bytes_.size() >= message_size) { |
152 bool rv = true; | 152 bool rv = true; |
153 MessageInTransit::View message_view(message_size, &bytes_[0]); | 153 MessageInTransit::View message_view(message_size, &bytes_[0]); |
154 CHECK_EQ(message_view.main_buffer_size(), message_size); | 154 CHECK_EQ(message_view.main_buffer_size(), message_size); |
155 | 155 |
156 if (message_view.num_bytes() != expected_size) { | 156 if (message_view.num_bytes() != expected_size) { |
157 LOG(ERROR) << "Wrong size: " << message_size << " instead of " | 157 LOG(ERROR) << "Wrong size: " << message_size << " instead of " |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 | 679 |
680 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); | 680 EXPECT_FALSE(rc->WriteMessage(MakeTestMessage(1))); |
681 | 681 |
682 // Wait for the delegate, which will shut the |RawChannel| down. | 682 // Wait for the delegate, which will shut the |RawChannel| down. |
683 delegate.Wait(); | 683 delegate.Wait(); |
684 } | 684 } |
685 | 685 |
686 } // namespace | 686 } // namespace |
687 } // namespace system | 687 } // namespace system |
688 } // namespace mojo | 688 } // namespace mojo |
OLD | NEW |