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

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

Issue 8764004: Add DEPS include rules so we don't accidentally use base (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove rules to include self where possible Created 9 years 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_transport.h ('k') | ppapi/tests/test_utils.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 (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 22 matching lines...) Expand all
33 const char kTestChannelName[] = "test"; 33 const char kTestChannelName[] = "test";
34 const int kReadBufferSize = 65536; 34 const int kReadBufferSize = 65536;
35 35
36 class StreamReader { 36 class StreamReader {
37 public: 37 public:
38 StreamReader(pp::Transport_Dev* transport, 38 StreamReader(pp::Transport_Dev* transport,
39 int expected_size, 39 int expected_size,
40 pp::CompletionCallback done_callback) 40 pp::CompletionCallback done_callback)
41 : expected_size_(expected_size), 41 : expected_size_(expected_size),
42 done_callback_(done_callback), 42 done_callback_(done_callback),
43 ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)), 43 PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)),
44 transport_(transport), 44 transport_(transport),
45 received_size_(0) { 45 received_size_(0) {
46 Read(); 46 Read();
47 } 47 }
48 48
49 const std::list<std::vector<char> >& received() { return received_; } 49 const std::list<std::vector<char> >& received() { return received_; }
50 std::list<std::string> errors() { return errors_; } 50 std::list<std::string> errors() { return errors_; }
51 51
52 private: 52 private:
53 void Read() { 53 void Read() {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 pp::CompletionCallbackFactory<StreamReader> callback_factory_; 89 pp::CompletionCallbackFactory<StreamReader> callback_factory_;
90 pp::Transport_Dev* transport_; 90 pp::Transport_Dev* transport_;
91 std::vector<char> buffer_; 91 std::vector<char> buffer_;
92 std::list<std::vector<char> > received_; 92 std::list<std::vector<char> > received_;
93 int received_size_; 93 int received_size_;
94 std::list<std::string> errors_; 94 std::list<std::string> errors_;
95 }; 95 };
96 96
97 } // namespace 97 } // namespace
98 98
99 TestTransport::~TestTransport() {
100 delete transport1_;
101 delete transport2_;
102 }
103
99 bool TestTransport::Init() { 104 bool TestTransport::Init() {
100 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>( 105 transport_interface_ = reinterpret_cast<PPB_Transport_Dev const*>(
101 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); 106 pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE));
102 return transport_interface_ && InitTestingInterface(); 107 return transport_interface_ && InitTestingInterface();
103 } 108 }
104 109
105 void TestTransport::RunTests(const std::string& filter) { 110 void TestTransport::RunTests(const std::string& filter) {
106 RUN_TEST(Create, filter); 111 RUN_TEST(Create, filter);
107 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter); 112 RUN_TEST_FORCEASYNC_AND_NOT(Connect, filter);
108 RUN_TEST(SetProperty, filter); 113 RUN_TEST(SetProperty, filter);
109 RUN_TEST_FORCEASYNC_AND_NOT(SendDataUdp, filter); 114 RUN_TEST_FORCEASYNC_AND_NOT(SendDataUdp, filter);
110 RUN_TEST_FORCEASYNC_AND_NOT(SendDataTcp, filter); 115 RUN_TEST_FORCEASYNC_AND_NOT(SendDataTcp, filter);
111 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseUdp, filter); 116 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseUdp, filter);
112 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseTcp, filter); 117 RUN_TEST_FORCEASYNC_AND_NOT(ConnectAndCloseTcp, filter);
113 } 118 }
114 119
115 std::string TestTransport::InitTargets(PP_TransportType type) { 120 std::string TestTransport::InitTargets(PP_TransportType type) {
116 transport1_.reset(new pp::Transport_Dev(instance_, kTestChannelName, type)); 121 transport1_ = new pp::Transport_Dev(instance_, kTestChannelName, type);
117 transport2_.reset(new pp::Transport_Dev(instance_, kTestChannelName, type)); 122 transport2_ = new pp::Transport_Dev(instance_, kTestChannelName, type);
118 123
119 ASSERT_TRUE(transport1_.get() != NULL); 124 ASSERT_NE(NULL, transport1_);
120 ASSERT_TRUE(transport2_.get() != NULL); 125 ASSERT_NE(NULL, transport2_);
121 126
122 PASS(); 127 PASS();
123 } 128 }
124 129
125 std::string TestTransport::Connect() { 130 std::string TestTransport::Connect() {
126 TestCompletionCallback connect_cb1(instance_->pp_instance()); 131 TestCompletionCallback connect_cb1(instance_->pp_instance());
127 TestCompletionCallback connect_cb2(instance_->pp_instance()); 132 TestCompletionCallback connect_cb2(instance_->pp_instance());
128 ASSERT_EQ(transport1_->Connect(connect_cb1), PP_OK_COMPLETIONPENDING); 133 ASSERT_EQ(transport1_->Connect(connect_cb1), PP_OK_COMPLETIONPENDING);
129 ASSERT_EQ(transport2_->Connect(connect_cb2), PP_OK_COMPLETIONPENDING); 134 ASSERT_EQ(transport2_->Connect(connect_cb2), PP_OK_COMPLETIONPENDING);
130 135
(...skipping 17 matching lines...) Expand all
148 ASSERT_EQ(connect_cb1.WaitForResult(), PP_OK); 153 ASSERT_EQ(connect_cb1.WaitForResult(), PP_OK);
149 ASSERT_EQ(connect_cb2.WaitForResult(), PP_OK); 154 ASSERT_EQ(connect_cb2.WaitForResult(), PP_OK);
150 155
151 ASSERT_TRUE(transport1_->IsWritable()); 156 ASSERT_TRUE(transport1_->IsWritable());
152 ASSERT_TRUE(transport2_->IsWritable()); 157 ASSERT_TRUE(transport2_->IsWritable());
153 158
154 PASS(); 159 PASS();
155 } 160 }
156 161
157 std::string TestTransport::Clean() { 162 std::string TestTransport::Clean() {
158 transport1_.reset(); 163 delete transport1_;
159 transport2_.reset(); 164 transport1_ = NULL;
165 delete transport2_;
166 transport2_ = NULL;
160 167
161 PASS(); 168 PASS();
162 } 169 }
163 170
164 std::string TestTransport::TestCreate() { 171 std::string TestTransport::TestCreate() {
165 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_DATAGRAM)); 172 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_DATAGRAM));
166 173
167 Clean(); 174 Clean();
168 175
169 PASS(); 176 PASS();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // that at least some packets are received (some packets may be lost). 241 // that at least some packets are received (some packets may be lost).
235 std::string TestTransport::TestSendDataUdp() { 242 std::string TestTransport::TestSendDataUdp() {
236 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_DATAGRAM)); 243 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_DATAGRAM));
237 RUN_SUBTEST(Connect()); 244 RUN_SUBTEST(Connect());
238 245
239 const int kNumPackets = 100; 246 const int kNumPackets = 100;
240 const int kSendBufferSize = 1200; 247 const int kSendBufferSize = 1200;
241 const int kUdpWaitTimeMs = 1000; // 1 second. 248 const int kUdpWaitTimeMs = 1000; // 1 second.
242 249
243 TestCompletionCallback done_cb(instance_->pp_instance()); 250 TestCompletionCallback done_cb(instance_->pp_instance());
244 StreamReader reader(transport1_.get(), kSendBufferSize * kNumPackets, 251 StreamReader reader(transport1_, kSendBufferSize * kNumPackets, done_cb);
245 done_cb);
246 252
247 std::map<int, std::vector<char> > sent_packets; 253 std::map<int, std::vector<char> > sent_packets;
248 for (int i = 0; i < kNumPackets; ++i) { 254 for (int i = 0; i < kNumPackets; ++i) {
249 std::vector<char> send_buffer(kSendBufferSize); 255 std::vector<char> send_buffer(kSendBufferSize);
250 for (size_t j = 0; j < send_buffer.size(); ++j) { 256 for (size_t j = 0; j < send_buffer.size(); ++j) {
251 send_buffer[j] = rand() % 256; 257 send_buffer[j] = rand() % 256;
252 } 258 }
253 // Put packet index in the beginning. 259 // Put packet index in the beginning.
254 memcpy(&send_buffer[0], &i, sizeof(i)); 260 memcpy(&send_buffer[0], &i, sizeof(i));
255 261
(...skipping 30 matching lines...) Expand all
286 292
287 // Creating reliable (TCP-like) connection and try sending data over 293 // Creating reliable (TCP-like) connection and try sending data over
288 // it. Verify that all data is received correctly. 294 // it. Verify that all data is received correctly.
289 std::string TestTransport::TestSendDataTcp() { 295 std::string TestTransport::TestSendDataTcp() {
290 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_STREAM)); 296 RUN_SUBTEST(InitTargets(PP_TRANSPORTTYPE_STREAM));
291 RUN_SUBTEST(Connect()); 297 RUN_SUBTEST(Connect());
292 298
293 const int kTcpSendSize = 100000; 299 const int kTcpSendSize = 100000;
294 300
295 TestCompletionCallback done_cb(instance_->pp_instance()); 301 TestCompletionCallback done_cb(instance_->pp_instance());
296 StreamReader reader(transport1_.get(), kTcpSendSize, 302 StreamReader reader(transport1_, kTcpSendSize, done_cb);
297 done_cb);
298 303
299 std::vector<char> send_buffer(kTcpSendSize); 304 std::vector<char> send_buffer(kTcpSendSize);
300 for (size_t j = 0; j < send_buffer.size(); ++j) { 305 for (size_t j = 0; j < send_buffer.size(); ++j) {
301 send_buffer[j] = rand() % 256; 306 send_buffer[j] = rand() % 256;
302 } 307 }
303 308
304 int pos = 0; 309 int pos = 0;
305 while (pos < static_cast<int>(send_buffer.size())) { 310 while (pos < static_cast<int>(send_buffer.size())) {
306 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_); 311 TestCompletionCallback send_cb(instance_->pp_instance(), force_async_);
307 int result = transport2_->Send( 312 int result = transport2_->Send(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 // Close the transport and verify that callback is aborted. 369 // Close the transport and verify that callback is aborted.
365 ASSERT_EQ(transport1_->Close(), PP_OK); 370 ASSERT_EQ(transport1_->Close(), PP_OK);
366 371
367 ASSERT_EQ(recv_cb.run_count(), 1); 372 ASSERT_EQ(recv_cb.run_count(), 1);
368 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED); 373 ASSERT_EQ(recv_cb.result(), PP_ERROR_ABORTED);
369 374
370 Clean(); 375 Clean();
371 376
372 PASS(); 377 PASS();
373 } 378 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_transport.h ('k') | ppapi/tests/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698