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

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

Issue 6899055: PPAPI: Force async callback invocation option. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 | « ppapi/tests/test_graphics_2d.cc ('k') | ppapi/tests/test_url_loader.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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_transport.h" 5 #include "ppapi/tests/test_transport.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9 9
10 #include <list> 10 #include <list>
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 const std::list<std::vector<char> >& received() { return received_; } 48 const std::list<std::vector<char> >& received() { return received_; }
49 std::list<std::string> errors() { return errors_; } 49 std::list<std::string> errors() { return errors_; }
50 50
51 private: 51 private:
52 void Read() { 52 void Read() {
53 while (true) { 53 while (true) {
54 buffer_.resize(kReadBufferSize); 54 buffer_.resize(kReadBufferSize);
55 int result = transport_->Recv( 55 int result = transport_->Recv(
56 &buffer_[0], buffer_.size(), 56 &buffer_[0], buffer_.size(),
57 callback_factory_.NewCallback(&StreamReader::OnReadFinished)); 57 callback_factory_.NewOptionalCallback(&StreamReader::OnReadFinished));
58 if (result > 0) 58 if (result > 0)
59 DidFinishRead(result); 59 DidFinishRead(result);
60 else 60 else
61 break; 61 break;
62 } 62 }
63 } 63 }
64 64
65 void OnReadFinished(int result) { 65 void OnReadFinished(int result) {
66 DidFinishRead(result); 66 DidFinishRead(result);
67 if (result > 0) 67 if (result > 0)
(...skipping 29 matching lines...) Expand all
97 97
98 bool TestTransport::Init() { 98 bool TestTransport::Init() {
99 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>( 99 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>(
100 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); 100 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE));
101 return transport_interface_ && InitTestingInterface(); 101 return transport_interface_ && InitTestingInterface();
102 } 102 }
103 103
104 void TestTransport::RunTest() { 104 void TestTransport::RunTest() {
105 RUN_TEST(Create); 105 RUN_TEST(Create);
106 RUN_TEST(Connect); 106 RUN_TEST(Connect);
107 RUN_TEST(SendDataUdp); 107 RUN_TEST_FORCEASYNC(SendDataUdp);
108 RUN_TEST(SendDataTcp); 108 RUN_TEST(SendDataTcp);
109 RUN_TEST(ConnectAndCloseUdp); 109 RUN_TEST(ConnectAndCloseUdp);
110 RUN_TEST(ConnectAndCloseTcp); 110 RUN_TEST(ConnectAndCloseTcp);
111 } 111 }
112 112
113 std::string TestTransport::InitTargets(const char* proto) { 113 std::string TestTransport::InitTargets(const char* proto) {
114 transport1_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto)); 114 transport1_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto));
115 transport2_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto)); 115 transport2_.reset(new pp::Transport_Dev(instance_, kTestChannelName, proto));
116 116
117 ASSERT_TRUE(transport1_.get() != NULL); 117 ASSERT_TRUE(transport1_.get() != NULL);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 std::map<int, std::vector<char> > sent_packets; 192 std::map<int, std::vector<char> > sent_packets;
193 for (int i = 0; i < kNumPackets; ++i) { 193 for (int i = 0; i < kNumPackets; ++i) {
194 std::vector<char> send_buffer(kSendBufferSize); 194 std::vector<char> send_buffer(kSendBufferSize);
195 for (size_t j = 0; j < send_buffer.size(); ++j) { 195 for (size_t j = 0; j < send_buffer.size(); ++j) {
196 send_buffer[j] = rand() % 256; 196 send_buffer[j] = rand() % 256;
197 } 197 }
198 // Put packet index in the beginning. 198 // Put packet index in the beginning.
199 memcpy(&send_buffer[0], &i, sizeof(i)); 199 memcpy(&send_buffer[0], &i, sizeof(i));
200 200
201 TestCompletionCallback send_cb(instance_->pp_instance()); 201 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_);
202 ASSERT_EQ( 202 int32_t result = transport2_->Send(&send_buffer[0], send_buffer.size(),
203 transport2_->Send(&send_buffer[0], send_buffer.size(), send_cb), 203 send_cb);
204 static_cast<int>(send_buffer.size())); 204 if (force_async_) {
205 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING);
206 ASSERT_EQ(send_cb.WaitForResult(), static_cast<int>(send_buffer.size()));
207 } else {
208 ASSERT_EQ(result, static_cast<int>(send_buffer.size()));
209 }
205 sent_packets[i] = send_buffer; 210 sent_packets[i] = send_buffer;
206 } 211 }
207 212
208 // Limit waiting time. 213 // Limit waiting time.
209 pp::Module::Get()->core()->CallOnMainThread(kUdpWaitTimeMs, done_cb); 214 pp::Module::Get()->core()->CallOnMainThread(kUdpWaitTimeMs, done_cb);
210 ASSERT_EQ(done_cb.WaitForResult(), PP_OK); 215 ASSERT_EQ(done_cb.WaitForResult(), PP_OK);
211 216
212 ASSERT_TRUE(reader.errors().size() == 0); 217 ASSERT_TRUE(reader.errors().size() == 0);
213 ASSERT_TRUE(reader.received().size() > 0); 218 ASSERT_TRUE(reader.received().size() > 0);
214 for (std::list<std::vector<char> >::const_iterator it = 219 for (std::list<std::vector<char> >::const_iterator it =
(...skipping 21 matching lines...) Expand all
236 StreamReader reader(transport1_.get(), kTcpSendSize, 241 StreamReader reader(transport1_.get(), kTcpSendSize,
237 done_cb); 242 done_cb);
238 243
239 std::vector<char> send_buffer(kTcpSendSize); 244 std::vector<char> send_buffer(kTcpSendSize);
240 for (size_t j = 0; j < send_buffer.size(); ++j) { 245 for (size_t j = 0; j < send_buffer.size(); ++j) {
241 send_buffer[j] = rand() % 256; 246 send_buffer[j] = rand() % 256;
242 } 247 }
243 248
244 int pos = 0; 249 int pos = 0;
245 while (pos < static_cast<int>(send_buffer.size())) { 250 while (pos < static_cast<int>(send_buffer.size())) {
246 TestCompletionCallback send_cb(instance_->pp_instance()); 251 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_);
247 int result = transport2_->Send( 252 int result = transport2_->Send(
248 &send_buffer[0] + pos, send_buffer.size() - pos, send_cb); 253 &send_buffer[0] + pos, send_buffer.size() - pos, send_cb);
254 if (force_async_)
255 ASSERT_EQ(result, PP_OK_COMPLETIONPENDING);
249 if (result == PP_OK_COMPLETIONPENDING) 256 if (result == PP_OK_COMPLETIONPENDING)
250 result = send_cb.WaitForResult(); 257 result = send_cb.WaitForResult();
251 ASSERT_TRUE(result > 0); 258 ASSERT_TRUE(result > 0);
252 pos += result; 259 pos += result;
253 } 260 }
254 261
255 // Limit waiting time. 262 // Limit waiting time.
256 pp::Module::Get()->core()->CallOnMainThread(kTimeoutMs, done_cb); 263 pp::Module::Get()->core()->CallOnMainThread(kTimeoutMs, done_cb);
257 ASSERT_EQ(done_cb.WaitForResult(), PP_OK); 264 ASSERT_EQ(done_cb.WaitForResult(), PP_OK);
258 265
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // Close the transport and verify that callback is aborted. 311 // Close the transport and verify that callback is aborted.
305 ASSERT_EQ(transport1_->Close(), PP_OK); 312 ASSERT_EQ(transport1_->Close(), PP_OK);
306 313
307 ASSERT_EQ(recv_cb.run_count(), 1); 314 ASSERT_EQ(recv_cb.run_count(), 1);
308 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED); 315 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED);
309 316
310 Clean(); 317 Clean();
311 318
312 PASS(); 319 PASS();
313 } 320 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_graphics_2d.cc ('k') | ppapi/tests/test_url_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698