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

Side by Side Diff: components/nacl/loader/nacl_ipc_adapter_unittest.cc

Issue 1548113002: Switch to standard integer types in components/, part 2 of 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gn Created 4 years, 12 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
« no previous file with comments | « components/nacl/loader/nacl_ipc_adapter.cc ('k') | components/nacl/loader/nacl_listener.h » ('j') | 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 #include "components/nacl/loader/nacl_ipc_adapter.h" 5 #include "components/nacl/loader/nacl_ipc_adapter.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
7 #include <string.h> 9 #include <string.h>
8 10
9 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
10 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
11 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
12 #include "base/threading/simple_thread.h" 14 #include "base/threading/simple_thread.h"
13 #include "ipc/ipc_test_sink.h" 15 #include "ipc/ipc_test_sink.h"
14 #include "native_client/src/public/nacl_desc_custom.h" 16 #include "native_client/src/public/nacl_desc_custom.h"
15 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 17 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
16 #include "ppapi/c/ppb_file_io.h" 18 #include "ppapi/c/ppb_file_io.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 // In real life the adapter needs to take ownership so the channel can be 68 // In real life the adapter needs to take ownership so the channel can be
67 // destroyed on the right thread. 69 // destroyed on the right thread.
68 IPC::TestSink* sink_; 70 IPC::TestSink* sink_;
69 }; 71 };
70 72
71 } // namespace 73 } // namespace
72 74
73 // Tests a simple message getting rewritten sent from native code to NaCl. 75 // Tests a simple message getting rewritten sent from native code to NaCl.
74 TEST_F(NaClIPCAdapterTest, SimpleReceiveRewriting) { 76 TEST_F(NaClIPCAdapterTest, SimpleReceiveRewriting) {
75 int routing_id = 0x89898989; 77 int routing_id = 0x89898989;
76 uint32 type = 0x55555555; 78 uint32_t type = 0x55555555;
77 IPC::Message input(routing_id, type, IPC::Message::PRIORITY_NORMAL); 79 IPC::Message input(routing_id, type, IPC::Message::PRIORITY_NORMAL);
78 uint32 flags = input.flags(); 80 uint32_t flags = input.flags();
79 81
80 int value = 0x12345678; 82 int value = 0x12345678;
81 input.WriteInt(value); 83 input.WriteInt(value);
82 adapter_->OnMessageReceived(input); 84 adapter_->OnMessageReceived(input);
83 85
84 // Buffer just need to be big enough for our message with one int. 86 // Buffer just need to be big enough for our message with one int.
85 const int kBufSize = 64; 87 const int kBufSize = 64;
86 char buf[kBufSize]; 88 char buf[kBufSize];
87 89
88 int bytes_read = BlockingReceive(buf, kBufSize); 90 int bytes_read = BlockingReceive(buf, kBufSize);
(...skipping 11 matching lines...) Expand all
100 102
101 // Validate the payload. 103 // Validate the payload.
102 EXPECT_EQ(value, 104 EXPECT_EQ(value,
103 *reinterpret_cast<const int*>(&buf[ 105 *reinterpret_cast<const int*>(&buf[
104 sizeof(NaClIPCAdapter::NaClMessageHeader)])); 106 sizeof(NaClIPCAdapter::NaClMessageHeader)]));
105 } 107 }
106 108
107 // Tests a simple message getting rewritten sent from NaCl to native code. 109 // Tests a simple message getting rewritten sent from NaCl to native code.
108 TEST_F(NaClIPCAdapterTest, SendRewriting) { 110 TEST_F(NaClIPCAdapterTest, SendRewriting) {
109 int routing_id = 0x89898989; 111 int routing_id = 0x89898989;
110 uint32 type = 0x55555555; 112 uint32_t type = 0x55555555;
111 int value = 0x12345678; 113 int value = 0x12345678;
112 114
113 // Send a message with one int inside it. 115 // Send a message with one int inside it.
114 const int buf_size = sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int); 116 const int buf_size = sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int);
115 char buf[buf_size] = {0}; 117 char buf[buf_size] = {0};
116 118
117 NaClIPCAdapter::NaClMessageHeader* header = 119 NaClIPCAdapter::NaClMessageHeader* header =
118 reinterpret_cast<NaClIPCAdapter::NaClMessageHeader*>(buf); 120 reinterpret_cast<NaClIPCAdapter::NaClMessageHeader*>(buf);
119 header->payload_size = sizeof(int); 121 header->payload_size = sizeof(int);
120 header->routing = routing_id; 122 header->routing = routing_id;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ASSERT_EQ(1u, sink_->message_count()); 168 ASSERT_EQ(1u, sink_->message_count());
167 msg = sink_->GetMessageAt(0); 169 msg = sink_->GetMessageAt(0);
168 EXPECT_EQ(sizeof(int), msg->payload_size()); 170 EXPECT_EQ(sizeof(int), msg->payload_size());
169 EXPECT_EQ(header->routing, msg->routing_id()); 171 EXPECT_EQ(header->routing, msg->routing_id());
170 EXPECT_EQ(header->type, msg->type()); 172 EXPECT_EQ(header->type, msg->type());
171 } 173 }
172 174
173 // Tests when a buffer is too small to receive the entire message. 175 // Tests when a buffer is too small to receive the entire message.
174 TEST_F(NaClIPCAdapterTest, PartialReceive) { 176 TEST_F(NaClIPCAdapterTest, PartialReceive) {
175 int routing_id_1 = 0x89898989; 177 int routing_id_1 = 0x89898989;
176 uint32 type_1 = 0x55555555; 178 uint32_t type_1 = 0x55555555;
177 IPC::Message input_1(routing_id_1, type_1, IPC::Message::PRIORITY_NORMAL); 179 IPC::Message input_1(routing_id_1, type_1, IPC::Message::PRIORITY_NORMAL);
178 int value_1 = 0x12121212; 180 int value_1 = 0x12121212;
179 input_1.WriteInt(value_1); 181 input_1.WriteInt(value_1);
180 adapter_->OnMessageReceived(input_1); 182 adapter_->OnMessageReceived(input_1);
181 183
182 int routing_id_2 = 0x90909090; 184 int routing_id_2 = 0x90909090;
183 uint32 type_2 = 0x66666666; 185 uint32_t type_2 = 0x66666666;
184 IPC::Message input_2(routing_id_2, type_2, IPC::Message::PRIORITY_NORMAL); 186 IPC::Message input_2(routing_id_2, type_2, IPC::Message::PRIORITY_NORMAL);
185 int value_2 = 0x23232323; 187 int value_2 = 0x23232323;
186 input_2.WriteInt(value_2); 188 input_2.WriteInt(value_2);
187 adapter_->OnMessageReceived(input_2); 189 adapter_->OnMessageReceived(input_2);
188 190
189 const int kBufSize = 64; 191 const int kBufSize = 64;
190 char buf[kBufSize]; 192 char buf[kBufSize];
191 193
192 // Read part of the first message. 194 // Read part of the first message.
193 int bytes_requested = 7; 195 int bytes_requested = 7;
(...skipping 22 matching lines...) Expand all
216 EXPECT_EQ(sizeof(int), output_header->payload_size); 218 EXPECT_EQ(sizeof(int), output_header->payload_size);
217 EXPECT_EQ(routing_id_2, output_header->routing); 219 EXPECT_EQ(routing_id_2, output_header->routing);
218 EXPECT_EQ(type_2, output_header->type); 220 EXPECT_EQ(type_2, output_header->type);
219 } 221 }
220 222
221 // Tests sending messages that are too large. We test sends that are too 223 // Tests sending messages that are too large. We test sends that are too
222 // small implicitly here and in the success case because in that case it 224 // small implicitly here and in the success case because in that case it
223 // succeeds and buffers the data. 225 // succeeds and buffers the data.
224 TEST_F(NaClIPCAdapterTest, SendOverflow) { 226 TEST_F(NaClIPCAdapterTest, SendOverflow) {
225 int routing_id = 0x89898989; 227 int routing_id = 0x89898989;
226 uint32 type = 0x55555555; 228 uint32_t type = 0x55555555;
227 int value = 0x12345678; 229 int value = 0x12345678;
228 230
229 // Make a message with one int inside it. Reserve some extra space so 231 // Make a message with one int inside it. Reserve some extra space so
230 // we can test what happens when we send too much data. 232 // we can test what happens when we send too much data.
231 const int buf_size = sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int); 233 const int buf_size = sizeof(NaClIPCAdapter::NaClMessageHeader) + sizeof(int);
232 const int big_buf_size = buf_size + 4; 234 const int big_buf_size = buf_size + 4;
233 char buf[big_buf_size] = {0}; 235 char buf[big_buf_size] = {0};
234 236
235 NaClIPCAdapter::NaClMessageHeader* header = 237 NaClIPCAdapter::NaClMessageHeader* header =
236 reinterpret_cast<NaClIPCAdapter::NaClMessageHeader*>(buf); 238 reinterpret_cast<NaClIPCAdapter::NaClMessageHeader*>(buf);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 EXPECT_EQ(NACL_ABI_O_RDONLY, 349 EXPECT_EQ(NACL_ABI_O_RDONLY,
348 TranslatePepperFileReadWriteOpenFlagsForTesting( 350 TranslatePepperFileReadWriteOpenFlagsForTesting(
349 PP_FILEOPENFLAG_CREATE)); 351 PP_FILEOPENFLAG_CREATE));
350 EXPECT_EQ(NACL_ABI_O_RDONLY, 352 EXPECT_EQ(NACL_ABI_O_RDONLY,
351 TranslatePepperFileReadWriteOpenFlagsForTesting( 353 TranslatePepperFileReadWriteOpenFlagsForTesting(
352 PP_FILEOPENFLAG_TRUNCATE)); 354 PP_FILEOPENFLAG_TRUNCATE));
353 EXPECT_EQ(NACL_ABI_O_RDONLY, 355 EXPECT_EQ(NACL_ABI_O_RDONLY,
354 TranslatePepperFileReadWriteOpenFlagsForTesting( 356 TranslatePepperFileReadWriteOpenFlagsForTesting(
355 PP_FILEOPENFLAG_EXCLUSIVE)); 357 PP_FILEOPENFLAG_EXCLUSIVE));
356 } 358 }
OLDNEW
« no previous file with comments | « components/nacl/loader/nacl_ipc_adapter.cc ('k') | components/nacl/loader/nacl_listener.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698