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

Side by Side Diff: ppapi/tests/test_udp_socket.cc

Issue 915403003: Enable size_t to int truncation warnings in PPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ppapi_unittests win x64 Created 5 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
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.cc ('k') | ppapi/tests/test_udp_socket_private.cc » ('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 "ppapi/tests/test_udp_socket.h" 5 #include "ppapi/tests/test_udp_socket.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ppapi/cpp/pass_ref.h" 9 #include "ppapi/cpp/pass_ref.h"
10 #include "ppapi/cpp/tcp_socket.h" 10 #include "ppapi/cpp/tcp_socket.h"
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 } 149 }
150 150
151 std::string TestUDPSocket::ReadSocket(pp::UDPSocket* socket, 151 std::string TestUDPSocket::ReadSocket(pp::UDPSocket* socket,
152 pp::NetAddress* address, 152 pp::NetAddress* address,
153 size_t size, 153 size_t size,
154 std::string* message) { 154 std::string* message) {
155 std::vector<char> buffer(size); 155 std::vector<char> buffer(size);
156 TestCompletionCallbackWithOutput<pp::NetAddress> callback( 156 TestCompletionCallbackWithOutput<pp::NetAddress> callback(
157 instance_->pp_instance(), callback_type()); 157 instance_->pp_instance(), callback_type());
158 callback.WaitForResult( 158 callback.WaitForResult(
159 socket->RecvFrom(&buffer[0], size, callback.GetCallback())); 159 socket->RecvFrom(&buffer[0], static_cast<int32_t>(size),
160 callback.GetCallback()));
160 CHECK_CALLBACK_BEHAVIOR(callback); 161 CHECK_CALLBACK_BEHAVIOR(callback);
161 ASSERT_FALSE(callback.result() < 0); 162 ASSERT_FALSE(callback.result() < 0);
162 ASSERT_EQ(size, static_cast<size_t>(callback.result())); 163 ASSERT_EQ(size, static_cast<size_t>(callback.result()));
163 *address = callback.output(); 164 *address = callback.output();
164 message->assign(buffer.begin(), buffer.end()); 165 message->assign(buffer.begin(), buffer.end());
165 PASS(); 166 PASS();
166 } 167 }
167 168
168 std::string TestUDPSocket::PassMessage(pp::UDPSocket* target, 169 std::string TestUDPSocket::PassMessage(pp::UDPSocket* target,
169 pp::UDPSocket* source, 170 pp::UDPSocket* source,
170 const pp::NetAddress& target_address, 171 const pp::NetAddress& target_address,
171 const std::string& message, 172 const std::string& message,
172 pp::NetAddress* recvfrom_address) { 173 pp::NetAddress* recvfrom_address) {
173 TestCompletionCallback callback(instance_->pp_instance(), callback_type()); 174 TestCompletionCallback callback(instance_->pp_instance(), callback_type());
174 int32_t rv = source->SendTo(message.c_str(), message.size(), 175 int32_t rv = source->SendTo(message.c_str(),
176 static_cast<int32_t>(message.size()),
175 target_address, 177 target_address,
176 callback.GetCallback()); 178 callback.GetCallback());
177 std::string str; 179 std::string str;
178 ASSERT_SUBTEST_SUCCESS(ReadSocket(target, recvfrom_address, message.size(), 180 ASSERT_SUBTEST_SUCCESS(ReadSocket(target, recvfrom_address, message.size(),
179 &str)); 181 &str));
180 182
181 callback.WaitForResult(rv); 183 callback.WaitForResult(rv);
182 CHECK_CALLBACK_BEHAVIOR(callback); 184 CHECK_CALLBACK_BEHAVIOR(callback);
183 ASSERT_FALSE(callback.result() < 0); 185 ASSERT_FALSE(callback.result() < 0);
184 ASSERT_EQ(message.size(), static_cast<size_t>(callback.result())); 186 ASSERT_EQ(message.size(), static_cast<size_t>(callback.result()));
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 336
335 const size_t kParallelSends = 10; 337 const size_t kParallelSends = 10;
336 std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends); 338 std::vector<TestCompletionCallback*> sendto_callbacks(kParallelSends);
337 std::vector<int32_t> sendto_results(kParallelSends); 339 std::vector<int32_t> sendto_results(kParallelSends);
338 size_t pending = 0; 340 size_t pending = 0;
339 for (size_t i = 0; i < kParallelSends; i++) { 341 for (size_t i = 0; i < kParallelSends; i++) {
340 sendto_callbacks[i] = 342 sendto_callbacks[i] =
341 new TestCompletionCallback(instance_->pp_instance(), callback_type()); 343 new TestCompletionCallback(instance_->pp_instance(), callback_type());
342 sendto_results[i] = 344 sendto_results[i] =
343 client_socket.SendTo(message.c_str(), 345 client_socket.SendTo(message.c_str(),
344 message.size(), 346 static_cast<int32_t>(message.size()),
345 server_address, 347 server_address,
346 sendto_callbacks[i]->GetCallback()); 348 sendto_callbacks[i]->GetCallback());
347 349
348 if (sendto_results[i] == PP_ERROR_INPROGRESS) { 350 if (sendto_results[i] == PP_ERROR_INPROGRESS) {
349 // Run a pending send to completion to free a slot for the current send. 351 // Run a pending send to completion to free a slot for the current send.
350 ASSERT_GT(i, pending); 352 ASSERT_GT(i, pending);
351 sendto_callbacks[pending]->WaitForResult(sendto_results[pending]); 353 sendto_callbacks[pending]->WaitForResult(sendto_results[pending]);
352 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]); 354 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[pending]);
353 ASSERT_EQ(message.size(), 355 ASSERT_EQ(message.size(),
354 static_cast<size_t>(sendto_callbacks[pending]->result())); 356 static_cast<size_t>(sendto_callbacks[pending]->result()));
355 pending++; 357 pending++;
356 // Try to send the message again. 358 // Try to send the message again.
357 sendto_results[i] = 359 sendto_results[i] =
358 client_socket.SendTo(message.c_str(), 360 client_socket.SendTo(message.c_str(),
359 message.size(), 361 static_cast<int32_t>(message.size()),
360 server_address, 362 server_address,
361 sendto_callbacks[i]->GetCallback()); 363 sendto_callbacks[i]->GetCallback());
362 ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]); 364 ASSERT_NE(PP_ERROR_INPROGRESS, sendto_results[i]);
363 } 365 }
364 } 366 }
365 367
366 // Finish all pending sends. 368 // Finish all pending sends.
367 for (size_t i = pending; i < kParallelSends; i++) { 369 for (size_t i = pending; i < kParallelSends; i++) {
368 sendto_callbacks[i]->WaitForResult(sendto_results[i]); 370 sendto_callbacks[i]->WaitForResult(sendto_results[i]);
369 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]); 371 CHECK_CALLBACK_BEHAVIOR(*sendto_callbacks[i]);
370 ASSERT_EQ(message.size(), 372 ASSERT_EQ(message.size(),
371 static_cast<size_t>(sendto_callbacks[i]->result())); 373 static_cast<size_t>(sendto_callbacks[i]->result()));
372 } 374 }
373 375
374 for (size_t i = 0; i < kParallelSends; ++i) 376 for (size_t i = 0; i < kParallelSends; ++i)
375 delete sendto_callbacks[i]; 377 delete sendto_callbacks[i];
376 378
377 for (size_t i = 0; i < kParallelSends; i++) { 379 for (size_t i = 0; i < kParallelSends; i++) {
378 std::string str; 380 std::string str;
379 ASSERT_SUBTEST_SUCCESS( 381 ASSERT_SUBTEST_SUCCESS(
380 ReadSocket(&server_socket, &recvfrom_address, message.size(), &str)); 382 ReadSocket(&server_socket, &recvfrom_address, message.size(), &str));
381 ASSERT_EQ(message, str); 383 ASSERT_EQ(message, str);
382 } 384 }
383 385
384 server_socket.Close(); 386 server_socket.Close();
385 client_socket.Close(); 387 client_socket.Close();
386 388
387 PASS(); 389 PASS();
388 } 390 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_tcp_socket_private.cc ('k') | ppapi/tests/test_udp_socket_private.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698