Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This file contains tests that are shared between different implementations of | 5 // This file contains tests that are shared between different implementations of |
| 6 // |DataPipeImpl|. | 6 // |DataPipeImpl|. |
| 7 | 7 |
| 8 #include "mojo/edk/system/data_pipe_impl.h" | 8 #include "mojo/edk/system/data_pipe_impl.h" |
| 9 | 9 |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 FROM_HERE, base::Bind(&RemoteDataPipeImplTestHelper::TearDownOnIOThread, | 157 FROM_HERE, base::Bind(&RemoteDataPipeImplTestHelper::TearDownOnIOThread, |
| 158 base::Unretained(this))); | 158 base::Unretained(this))); |
| 159 } | 159 } |
| 160 | 160 |
| 161 void Create(const MojoCreateDataPipeOptions& validated_options) override { | 161 void Create(const MojoCreateDataPipeOptions& validated_options) override { |
| 162 CHECK(!dp_); | 162 CHECK(!dp_); |
| 163 dp_ = DataPipe::CreateLocal(validated_options); | 163 dp_ = DataPipe::CreateLocal(validated_options); |
| 164 } | 164 } |
| 165 | 165 |
| 166 protected: | 166 protected: |
| 167 void SendDispatcher(size_t source_i, | |
| 168 scoped_refptr<Dispatcher> to_send, | |
| 169 scoped_refptr<Dispatcher>* to_receive) { | |
| 170 DCHECK(source_i == 0 || source_i == 1); | |
| 171 size_t dest_i = source_i ^ 1; | |
| 172 | |
| 173 // Write the dispatcher to MP |source_i| (port 0). Wait and receive on MP | |
| 174 // |dest_i| (port 0). (Add the waiter first, to avoid any handling the case | |
| 175 // where it's already readable.) | |
| 176 Waiter waiter; | |
| 177 waiter.Init(); | |
| 178 ASSERT_EQ(MOJO_RESULT_OK, | |
| 179 message_pipe(dest_i)->AddAwakable( | |
| 180 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 987, nullptr)); | |
| 181 { | |
| 182 DispatcherTransport transport( | |
| 183 test::DispatcherTryStartTransport(to_send.get())); | |
| 184 ASSERT_TRUE(transport.is_valid()); | |
| 185 | |
| 186 std::vector<DispatcherTransport> transports; | |
| 187 transports.push_back(transport); | |
| 188 ASSERT_EQ(MOJO_RESULT_OK, message_pipe(source_i)->WriteMessage( | |
| 189 0, NullUserPointer(), 0, &transports, | |
| 190 MOJO_WRITE_MESSAGE_FLAG_NONE)); | |
| 191 transport.End(); | |
| 192 } | |
| 193 uint32_t context = 0; | |
| 194 ASSERT_EQ(MOJO_RESULT_OK, waiter.Wait(test::ActionDeadline(), &context)); | |
| 195 EXPECT_EQ(987u, context); | |
| 196 HandleSignalsState hss = HandleSignalsState(); | |
| 197 message_pipe(dest_i)->RemoveAwakable(0, &waiter, &hss); | |
| 198 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | |
| 199 hss.satisfied_signals); | |
| 200 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | |
| 201 char read_buffer[100] = {}; | |
| 202 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | |
| 203 DispatcherVector read_dispatchers; | |
| 204 uint32_t read_num_dispatchers = 10; // Maximum to get. | |
| 205 ASSERT_EQ(MOJO_RESULT_OK, | |
| 206 message_pipe(dest_i)->ReadMessage( | |
| 207 0, UserPointer<void>(read_buffer), | |
| 208 MakeUserPointer(&read_buffer_size), &read_dispatchers, | |
| 209 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 210 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | |
| 211 ASSERT_EQ(1u, read_dispatchers.size()); | |
| 212 ASSERT_EQ(1u, read_num_dispatchers); | |
| 213 ASSERT_TRUE(read_dispatchers[0]); | |
| 214 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | |
| 215 | |
| 216 *to_receive = read_dispatchers[0]; | |
| 217 } | |
| 218 | |
| 167 scoped_refptr<MessagePipe> message_pipe(size_t i) { | 219 scoped_refptr<MessagePipe> message_pipe(size_t i) { |
| 168 return message_pipes_[i]; | 220 return message_pipes_[i]; |
| 169 } | 221 } |
| 222 scoped_refptr<DataPipe> dp() { return dp_; } | |
| 170 | 223 |
| 224 private: | |
| 171 void EnsureMessagePipeClosed(size_t i) { | 225 void EnsureMessagePipeClosed(size_t i) { |
| 172 if (!message_pipes_[i]) | 226 if (!message_pipes_[i]) |
| 173 return; | 227 return; |
| 174 message_pipes_[i]->Close(0); | 228 message_pipes_[i]->Close(0); |
| 175 message_pipes_[i] = nullptr; | 229 message_pipes_[i] = nullptr; |
| 176 } | 230 } |
| 177 | 231 |
| 178 void SetUpOnIOThread(scoped_refptr<ChannelEndpoint> ep0, | 232 void SetUpOnIOThread(scoped_refptr<ChannelEndpoint> ep0, |
| 179 scoped_refptr<ChannelEndpoint> ep1) { | 233 scoped_refptr<ChannelEndpoint> ep1) { |
| 180 CHECK_EQ(base::MessageLoop::current(), io_thread_.message_loop()); | 234 CHECK_EQ(base::MessageLoop::current(), io_thread_.message_loop()); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 206 scoped_refptr<Channel> channels_[2]; | 260 scoped_refptr<Channel> channels_[2]; |
| 207 scoped_refptr<MessagePipe> message_pipes_[2]; | 261 scoped_refptr<MessagePipe> message_pipes_[2]; |
| 208 | 262 |
| 209 scoped_refptr<DataPipe> dp_; | 263 scoped_refptr<DataPipe> dp_; |
| 210 | 264 |
| 211 DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTestHelper); | 265 DISALLOW_COPY_AND_ASSIGN(RemoteDataPipeImplTestHelper); |
| 212 }; | 266 }; |
| 213 | 267 |
| 214 // RemoteProducerDataPipeImplTestHelper ---------------------------------------- | 268 // RemoteProducerDataPipeImplTestHelper ---------------------------------------- |
| 215 | 269 |
| 270 // Note about naming confusion: This class is named after the "local" class, | |
| 271 // i.e., |dp_| will have a |RemoteProducerDataPipeImpl|. The remote side, of | |
| 272 // course, will have a |RemoteConsumerDataPipeImpl|. | |
| 216 class RemoteProducerDataPipeImplTestHelper | 273 class RemoteProducerDataPipeImplTestHelper |
| 217 : public RemoteDataPipeImplTestHelper { | 274 : public RemoteDataPipeImplTestHelper { |
| 218 public: | 275 public: |
| 219 RemoteProducerDataPipeImplTestHelper() {} | 276 RemoteProducerDataPipeImplTestHelper() {} |
| 220 ~RemoteProducerDataPipeImplTestHelper() override {} | 277 ~RemoteProducerDataPipeImplTestHelper() override {} |
| 221 | 278 |
| 222 void DoTransfer() override { | 279 void DoTransfer() override { |
| 223 // Write the producer to MP 0 (port 0). Wait and receive on MP 1 (port 0). | 280 // This is the producer dispatcher we'll send. |
| 224 // (Add the waiter first, to avoid any handling the case where it's already | 281 scoped_refptr<DataPipeProducerDispatcher> to_send = |
| 225 // readable.) | 282 new DataPipeProducerDispatcher(); |
| 226 Waiter waiter; | 283 to_send->Init(dp()); |
| 227 waiter.Init(); | 284 scoped_refptr<Dispatcher> to_receive; |
| 228 ASSERT_EQ(MOJO_RESULT_OK, | 285 SendDispatcher(0, to_send, &to_receive); |
| 229 message_pipe(1)->AddAwakable( | 286 // |to_send| should have been closed. This is |DCHECK()|ed when it is |
| 230 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 987, nullptr)); | 287 // destroyed. |
| 231 { | 288 EXPECT_TRUE(to_send->HasOneRef()); |
| 232 // This is the producer dispatcher we'll send. | 289 to_send = nullptr; |
| 233 scoped_refptr<DataPipeProducerDispatcher> to_send = | |
| 234 new DataPipeProducerDispatcher(); | |
| 235 to_send->Init(dp_); | |
| 236 | 290 |
| 237 DispatcherTransport transport( | 291 ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, to_receive->GetType()); |
| 238 test::DispatcherTryStartTransport(to_send.get())); | |
| 239 ASSERT_TRUE(transport.is_valid()); | |
| 240 | |
| 241 std::vector<DispatcherTransport> transports; | |
| 242 transports.push_back(transport); | |
| 243 ASSERT_EQ(MOJO_RESULT_OK, message_pipe(0)->WriteMessage( | |
| 244 0, NullUserPointer(), 0, &transports, | |
| 245 MOJO_WRITE_MESSAGE_FLAG_NONE)); | |
| 246 transport.End(); | |
| 247 | |
| 248 // |to_send| should have been closed. This is |DCHECK()|ed when it is | |
| 249 // destroyed. | |
| 250 EXPECT_TRUE(to_send->HasOneRef()); | |
| 251 } | |
| 252 uint32_t context = 0; | |
| 253 ASSERT_EQ(MOJO_RESULT_OK, waiter.Wait(test::ActionDeadline(), &context)); | |
| 254 EXPECT_EQ(987u, context); | |
| 255 HandleSignalsState hss = HandleSignalsState(); | |
| 256 message_pipe(1)->RemoveAwakable(0, &waiter, &hss); | |
| 257 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | |
| 258 hss.satisfied_signals); | |
| 259 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | |
| 260 char read_buffer[100] = {}; | |
| 261 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | |
| 262 DispatcherVector read_dispatchers; | |
| 263 uint32_t read_num_dispatchers = 10; // Maximum to get. | |
| 264 ASSERT_EQ(MOJO_RESULT_OK, | |
| 265 message_pipe(1)->ReadMessage( | |
| 266 0, UserPointer<void>(read_buffer), | |
| 267 MakeUserPointer(&read_buffer_size), &read_dispatchers, | |
| 268 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 269 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | |
| 270 ASSERT_EQ(1u, read_dispatchers.size()); | |
| 271 ASSERT_EQ(1u, read_num_dispatchers); | |
| 272 ASSERT_TRUE(read_dispatchers[0]); | |
| 273 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | |
| 274 | |
| 275 ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, | |
| 276 read_dispatchers[0]->GetType()); | |
| 277 producer_dispatcher_ = | 292 producer_dispatcher_ = |
| 278 static_cast<DataPipeProducerDispatcher*>(read_dispatchers[0].get()); | 293 static_cast<DataPipeProducerDispatcher*>(to_receive.get()); |
| 279 } | 294 } |
| 280 | 295 |
| 281 DataPipe* dpp() override { | 296 DataPipe* dpp() override { |
| 282 if (producer_dispatcher_) | 297 if (producer_dispatcher_) |
| 283 return producer_dispatcher_->GetDataPipeForTest(); | 298 return producer_dispatcher_->GetDataPipeForTest(); |
| 284 return dp_.get(); | 299 return dp().get(); |
| 285 } | 300 } |
| 286 DataPipe* dpc() override { return dp_.get(); } | 301 DataPipe* dpc() override { return dp().get(); } |
| 287 | 302 |
| 288 void ProducerClose() override { | 303 void ProducerClose() override { |
| 289 if (producer_dispatcher_) | 304 if (producer_dispatcher_) |
| 290 ASSERT_EQ(MOJO_RESULT_OK, producer_dispatcher_->Close()); | 305 ASSERT_EQ(MOJO_RESULT_OK, producer_dispatcher_->Close()); |
| 291 else | 306 else |
| 292 dp_->ProducerClose(); | 307 dp()->ProducerClose(); |
| 293 } | 308 } |
| 294 void ConsumerClose() override { dp_->ConsumerClose(); } | 309 void ConsumerClose() override { dp()->ConsumerClose(); } |
| 310 | |
| 311 protected: | |
| 312 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher_; | |
| 295 | 313 |
| 296 private: | 314 private: |
| 297 scoped_refptr<DataPipeProducerDispatcher> producer_dispatcher_; | |
| 298 | |
| 299 DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper); | 315 DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper); |
| 300 }; | 316 }; |
| 301 | 317 |
| 302 // RemoteConsumerDataPipeImplTestHelper ---------------------------------------- | 318 // RemoteConsumerDataPipeImplTestHelper ---------------------------------------- |
| 303 | 319 |
| 320 // Note about naming confusion: This class is named after the "local" class, | |
| 321 // i.e., |dp_| will have a |RemoteConsumerDataPipeImpl|. The remote side, of | |
| 322 // course, will have a |RemoteProducerDataPipeImpl|. | |
| 304 class RemoteConsumerDataPipeImplTestHelper | 323 class RemoteConsumerDataPipeImplTestHelper |
| 305 : public RemoteDataPipeImplTestHelper { | 324 : public RemoteDataPipeImplTestHelper { |
| 306 public: | 325 public: |
| 307 RemoteConsumerDataPipeImplTestHelper() {} | 326 RemoteConsumerDataPipeImplTestHelper() {} |
| 308 ~RemoteConsumerDataPipeImplTestHelper() override {} | 327 ~RemoteConsumerDataPipeImplTestHelper() override {} |
| 309 | 328 |
| 310 void DoTransfer() override { | 329 void DoTransfer() override { |
| 311 // Write the consumer to MP 0 (port 0). Wait and receive on MP 1 (port 0). | 330 // This is the consumer dispatcher we'll send. |
| 312 // (Add the waiter first, to avoid any handling the case where it's already | 331 scoped_refptr<DataPipeConsumerDispatcher> to_send = |
| 313 // readable.) | 332 new DataPipeConsumerDispatcher(); |
| 314 Waiter waiter; | 333 to_send->Init(dp()); |
| 315 waiter.Init(); | 334 scoped_refptr<Dispatcher> to_receive; |
| 316 ASSERT_EQ(MOJO_RESULT_OK, | 335 SendDispatcher(0, to_send, &to_receive); |
| 317 message_pipe(1)->AddAwakable( | 336 // |to_send| should have been closed. This is |DCHECK()|ed when it is |
| 318 0, &waiter, MOJO_HANDLE_SIGNAL_READABLE, 987, nullptr)); | 337 // destroyed. |
| 319 { | 338 EXPECT_TRUE(to_send->HasOneRef()); |
| 320 // This is the consumer dispatcher we'll send. | 339 to_send = nullptr; |
| 321 scoped_refptr<DataPipeConsumerDispatcher> to_send = | |
| 322 new DataPipeConsumerDispatcher(); | |
| 323 to_send->Init(dp_); | |
| 324 | 340 |
| 325 DispatcherTransport transport( | 341 ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, to_receive->GetType()); |
| 326 test::DispatcherTryStartTransport(to_send.get())); | |
| 327 ASSERT_TRUE(transport.is_valid()); | |
| 328 | |
| 329 std::vector<DispatcherTransport> transports; | |
| 330 transports.push_back(transport); | |
| 331 ASSERT_EQ(MOJO_RESULT_OK, message_pipe(0)->WriteMessage( | |
| 332 0, NullUserPointer(), 0, &transports, | |
| 333 MOJO_WRITE_MESSAGE_FLAG_NONE)); | |
| 334 transport.End(); | |
| 335 | |
| 336 // |to_send| should have been closed. This is |DCHECK()|ed when it is | |
| 337 // destroyed. | |
| 338 EXPECT_TRUE(to_send->HasOneRef()); | |
| 339 } | |
| 340 uint32_t context = 0; | |
| 341 ASSERT_EQ(MOJO_RESULT_OK, waiter.Wait(test::ActionDeadline(), &context)); | |
| 342 EXPECT_EQ(987u, context); | |
| 343 HandleSignalsState hss = HandleSignalsState(); | |
| 344 message_pipe(1)->RemoveAwakable(0, &waiter, &hss); | |
| 345 EXPECT_EQ(MOJO_HANDLE_SIGNAL_READABLE | MOJO_HANDLE_SIGNAL_WRITABLE, | |
| 346 hss.satisfied_signals); | |
| 347 EXPECT_EQ(kAllSignals, hss.satisfiable_signals); | |
| 348 char read_buffer[100] = {}; | |
| 349 uint32_t read_buffer_size = static_cast<uint32_t>(sizeof(read_buffer)); | |
| 350 DispatcherVector read_dispatchers; | |
| 351 uint32_t read_num_dispatchers = 10; // Maximum to get. | |
| 352 ASSERT_EQ(MOJO_RESULT_OK, | |
| 353 message_pipe(1)->ReadMessage( | |
| 354 0, UserPointer<void>(read_buffer), | |
| 355 MakeUserPointer(&read_buffer_size), &read_dispatchers, | |
| 356 &read_num_dispatchers, MOJO_READ_MESSAGE_FLAG_NONE)); | |
| 357 EXPECT_EQ(0u, static_cast<size_t>(read_buffer_size)); | |
| 358 ASSERT_EQ(1u, read_dispatchers.size()); | |
| 359 ASSERT_EQ(1u, read_num_dispatchers); | |
| 360 ASSERT_TRUE(read_dispatchers[0]); | |
| 361 EXPECT_TRUE(read_dispatchers[0]->HasOneRef()); | |
| 362 | |
| 363 ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, | |
| 364 read_dispatchers[0]->GetType()); | |
| 365 consumer_dispatcher_ = | 342 consumer_dispatcher_ = |
| 366 static_cast<DataPipeConsumerDispatcher*>(read_dispatchers[0].get()); | 343 static_cast<DataPipeConsumerDispatcher*>(to_receive.get()); |
| 367 } | 344 } |
| 368 | 345 |
| 369 DataPipe* dpp() override { return dp_.get(); } | 346 DataPipe* dpp() override { return dp().get(); } |
| 370 DataPipe* dpc() override { | 347 DataPipe* dpc() override { |
| 371 if (consumer_dispatcher_) | 348 if (consumer_dispatcher_) |
| 372 return consumer_dispatcher_->GetDataPipeForTest(); | 349 return consumer_dispatcher_->GetDataPipeForTest(); |
| 373 return dp_.get(); | 350 return dp().get(); |
| 374 } | 351 } |
| 375 | 352 |
| 376 void ProducerClose() override { dp_->ProducerClose(); } | 353 void ProducerClose() override { dp()->ProducerClose(); } |
| 377 void ConsumerClose() override { | 354 void ConsumerClose() override { |
| 378 if (consumer_dispatcher_) | 355 if (consumer_dispatcher_) |
| 379 ASSERT_EQ(MOJO_RESULT_OK, consumer_dispatcher_->Close()); | 356 ASSERT_EQ(MOJO_RESULT_OK, consumer_dispatcher_->Close()); |
| 380 else | 357 else |
| 381 dp_->ConsumerClose(); | 358 dp()->ConsumerClose(); |
| 359 } | |
| 360 | |
| 361 protected: | |
| 362 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher_; | |
| 363 | |
| 364 private: | |
| 365 DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper); | |
| 366 }; | |
| 367 | |
| 368 // RemoteProducerDataPipeImplTestHelper2 --------------------------------------- | |
| 369 | |
| 370 // This is like |RemoteProducerDataPipeImplTestHelper|, but |DoTransfer()| does | |
| 371 // a second transfer. This thus tests passing a producer handle twice, and in | |
| 372 // particular tests (some of) |RemoteConsumerDataPipeImpl|'s | |
| 373 // |ProducerEndSerialize()| (instead of |LocalDataPipeImpl|'s). | |
| 374 // | |
| 375 // Note about naming confusion: This class is named after the "local" class, | |
| 376 // i.e., |dp_| will have a |RemoteProducerDataPipeImpl|. The remote side, of | |
| 377 // course, will have a |RemoteConsumerDataPipeImpl|. | |
| 378 class RemoteProducerDataPipeImplTestHelper2 | |
| 379 : public RemoteProducerDataPipeImplTestHelper { | |
| 380 public: | |
| 381 RemoteProducerDataPipeImplTestHelper2() {} | |
| 382 ~RemoteProducerDataPipeImplTestHelper2() override {} | |
| 383 | |
| 384 void DoTransfer() override { | |
| 385 // Do the first transfer. | |
| 386 RemoteProducerDataPipeImplTestHelper::DoTransfer(); | |
|
Hajime Morrita
2015/03/03 03:00:38
It might be clearer just to call SendDispatcher()
viettrungluu
2015/03/03 05:17:45
Yeah, I went back and forth on that (since the sup
| |
| 387 | |
| 388 // Now send it back the other way. | |
| 389 scoped_refptr<Dispatcher> to_receive; | |
| 390 SendDispatcher(1, producer_dispatcher_, &to_receive); | |
| 391 // |producer_dispatcher_| should have been closed. This is |DCHECK()|ed when | |
| 392 // it is destroyed. | |
| 393 EXPECT_TRUE(producer_dispatcher_->HasOneRef()); | |
| 394 producer_dispatcher_ = nullptr; | |
| 395 | |
| 396 ASSERT_EQ(Dispatcher::kTypeDataPipeProducer, to_receive->GetType()); | |
| 397 producer_dispatcher_ = | |
| 398 static_cast<DataPipeProducerDispatcher*>(to_receive.get()); | |
| 382 } | 399 } |
| 383 | 400 |
| 384 private: | 401 private: |
| 385 scoped_refptr<DataPipeConsumerDispatcher> consumer_dispatcher_; | 402 DISALLOW_COPY_AND_ASSIGN(RemoteProducerDataPipeImplTestHelper2); |
| 403 }; | |
| 386 | 404 |
| 387 DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper); | 405 // RemoteConsumerDataPipeImplTestHelper2 --------------------------------------- |
| 406 | |
| 407 // This is like |RemoteConsumerDataPipeImplTestHelper|, but |DoTransfer()| does | |
| 408 // a second transfer. This thus tests passing a consumer handle twice, and in | |
| 409 // particular tests (some of) |RemoteProducerDataPipeImpl|'s | |
| 410 // |ConsumerEndSerialize()| (instead of |LocalDataPipeImpl|'s). | |
| 411 // | |
| 412 // Note about naming confusion: This class is named after the "local" class, | |
| 413 // i.e., |dp_| will have a |RemoteConsumerDataPipeImpl|. The remote side, of | |
| 414 // course, will have a |RemoteProducerDataPipeImpl|. | |
| 415 class RemoteConsumerDataPipeImplTestHelper2 | |
| 416 : public RemoteConsumerDataPipeImplTestHelper { | |
| 417 public: | |
| 418 RemoteConsumerDataPipeImplTestHelper2() {} | |
| 419 ~RemoteConsumerDataPipeImplTestHelper2() override {} | |
| 420 | |
| 421 void DoTransfer() override { | |
| 422 // Do the first transfer. | |
| 423 RemoteConsumerDataPipeImplTestHelper::DoTransfer(); | |
|
Hajime Morrita
2015/03/03 03:00:38
Ditto.
viettrungluu
2015/03/03 05:17:45
Done.
| |
| 424 | |
| 425 // Now send it back the other way. | |
| 426 scoped_refptr<Dispatcher> to_receive; | |
| 427 SendDispatcher(1, consumer_dispatcher_, &to_receive); | |
| 428 // |consumer_dispatcher_| should have been closed. This is |DCHECK()|ed when | |
| 429 // it is destroyed. | |
| 430 EXPECT_TRUE(consumer_dispatcher_->HasOneRef()); | |
| 431 consumer_dispatcher_ = nullptr; | |
| 432 | |
| 433 ASSERT_EQ(Dispatcher::kTypeDataPipeConsumer, to_receive->GetType()); | |
| 434 consumer_dispatcher_ = | |
| 435 static_cast<DataPipeConsumerDispatcher*>(to_receive.get()); | |
| 436 } | |
| 437 | |
| 438 private: | |
| 439 DISALLOW_COPY_AND_ASSIGN(RemoteConsumerDataPipeImplTestHelper2); | |
| 388 }; | 440 }; |
| 389 | 441 |
| 390 // Test case instantiation ----------------------------------------------------- | 442 // Test case instantiation ----------------------------------------------------- |
| 391 | 443 |
| 392 typedef testing::Types<LocalDataPipeImplTestHelper, | 444 typedef testing::Types<LocalDataPipeImplTestHelper, |
| 393 RemoteProducerDataPipeImplTestHelper, | 445 RemoteProducerDataPipeImplTestHelper, |
| 394 RemoteConsumerDataPipeImplTestHelper> HelperTypes; | 446 RemoteConsumerDataPipeImplTestHelper, |
| 447 RemoteProducerDataPipeImplTestHelper2, | |
| 448 RemoteConsumerDataPipeImplTestHelper2> HelperTypes; | |
| 395 | 449 |
| 396 TYPED_TEST_CASE(DataPipeImplTest, HelperTypes); | 450 TYPED_TEST_CASE(DataPipeImplTest, HelperTypes); |
| 397 | 451 |
| 398 // Tests ----------------------------------------------------------------------- | 452 // Tests ----------------------------------------------------------------------- |
| 399 | 453 |
| 400 TYPED_TEST(DataPipeImplTest, SimpleReadWrite) { | 454 TYPED_TEST(DataPipeImplTest, SimpleReadWrite) { |
| 401 const MojoCreateDataPipeOptions options = { | 455 const MojoCreateDataPipeOptions options = { |
| 402 kSizeOfOptions, // |struct_size|. | 456 kSizeOfOptions, // |struct_size|. |
| 403 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. | 457 MOJO_CREATE_DATA_PIPE_OPTIONS_FLAG_NONE, // |flags|. |
| 404 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. | 458 static_cast<uint32_t>(sizeof(int32_t)), // |element_num_bytes|. |
| (...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1637 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, | 1691 EXPECT_EQ(MOJO_RESULT_FAILED_PRECONDITION, |
| 1638 this->dpc()->ConsumerBeginReadData( | 1692 this->dpc()->ConsumerBeginReadData( |
| 1639 MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true)); | 1693 MakeUserPointer(&read_ptr), MakeUserPointer(&num_bytes), true)); |
| 1640 | 1694 |
| 1641 this->ConsumerClose(); | 1695 this->ConsumerClose(); |
| 1642 } | 1696 } |
| 1643 | 1697 |
| 1644 } // namespace | 1698 } // namespace |
| 1645 } // namespace system | 1699 } // namespace system |
| 1646 } // namespace mojo | 1700 } // namespace mojo |
| OLD | NEW |