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

Side by Side Diff: talk/media/sctp/sctpdataengine_unittest.cc

Issue 1304063006: (try 2) Added send-thresholding and fixed text packet dumping (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Simplification of GetChannelFromSocket, and a dcheck moved. Created 5 years, 3 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 | « talk/media/sctp/sctpdataengine.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 virtual void SetUp() { 234 virtual void SetUp() {
235 engine_.reset(new cricket::SctpDataEngine()); 235 engine_.reset(new cricket::SctpDataEngine());
236 } 236 }
237 237
238 void SetupConnectedChannels() { 238 void SetupConnectedChannels() {
239 net1_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current())); 239 net1_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current()));
240 net2_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current())); 240 net2_.reset(new SctpFakeNetworkInterface(rtc::Thread::Current()));
241 recv1_.reset(new SctpFakeDataReceiver()); 241 recv1_.reset(new SctpFakeDataReceiver());
242 recv2_.reset(new SctpFakeDataReceiver()); 242 recv2_.reset(new SctpFakeDataReceiver());
243 chan1_ready_to_send_count_ = 0;
244 chan2_ready_to_send_count_ = 0;
243 chan1_.reset(CreateChannel(net1_.get(), recv1_.get())); 245 chan1_.reset(CreateChannel(net1_.get(), recv1_.get()));
244 chan1_->set_debug_name("chan1/connector"); 246 chan1_->set_debug_name("chan1/connector");
247 chan1_->SignalReadyToSend.connect(
248 this, &SctpDataMediaChannelTest::OnChan1ReadyToSend);
245 chan2_.reset(CreateChannel(net2_.get(), recv2_.get())); 249 chan2_.reset(CreateChannel(net2_.get(), recv2_.get()));
246 chan2_->set_debug_name("chan2/listener"); 250 chan2_->set_debug_name("chan2/listener");
251 chan2_->SignalReadyToSend.connect(
252 this, &SctpDataMediaChannelTest::OnChan2ReadyToSend);
247 // Setup two connected channels ready to send and receive. 253 // Setup two connected channels ready to send and receive.
248 net1_->SetDestination(chan2_.get()); 254 net1_->SetDestination(chan2_.get());
249 net2_->SetDestination(chan1_.get()); 255 net2_->SetDestination(chan1_.get());
250 256
251 LOG(LS_VERBOSE) << "Channel setup ----------------------------- "; 257 LOG(LS_VERBOSE) << "Channel setup ----------------------------- ";
252 AddStream(1); 258 AddStream(1);
253 AddStream(2); 259 AddStream(2);
254 260
255 LOG(LS_VERBOSE) << "Connect the channels -----------------------------"; 261 LOG(LS_VERBOSE) << "Connect the channels -----------------------------";
256 // chan1 wants to setup a data connection. 262 // chan1 wants to setup a data connection.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 } 329 }
324 } 330 }
325 return !thread->IsQuitting(); 331 return !thread->IsQuitting();
326 } 332 }
327 333
328 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); } 334 cricket::SctpDataMediaChannel* channel1() { return chan1_.get(); }
329 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); } 335 cricket::SctpDataMediaChannel* channel2() { return chan2_.get(); }
330 SctpFakeDataReceiver* receiver1() { return recv1_.get(); } 336 SctpFakeDataReceiver* receiver1() { return recv1_.get(); }
331 SctpFakeDataReceiver* receiver2() { return recv2_.get(); } 337 SctpFakeDataReceiver* receiver2() { return recv2_.get(); }
332 338
339 int channel1_ready_to_send_count() { return chan1_ready_to_send_count_; }
340 int channel2_ready_to_send_count() { return chan2_ready_to_send_count_; }
333 private: 341 private:
334 rtc::scoped_ptr<cricket::SctpDataEngine> engine_; 342 rtc::scoped_ptr<cricket::SctpDataEngine> engine_;
335 rtc::scoped_ptr<SctpFakeNetworkInterface> net1_; 343 rtc::scoped_ptr<SctpFakeNetworkInterface> net1_;
336 rtc::scoped_ptr<SctpFakeNetworkInterface> net2_; 344 rtc::scoped_ptr<SctpFakeNetworkInterface> net2_;
337 rtc::scoped_ptr<SctpFakeDataReceiver> recv1_; 345 rtc::scoped_ptr<SctpFakeDataReceiver> recv1_;
338 rtc::scoped_ptr<SctpFakeDataReceiver> recv2_; 346 rtc::scoped_ptr<SctpFakeDataReceiver> recv2_;
339 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan1_; 347 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan1_;
340 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan2_; 348 rtc::scoped_ptr<cricket::SctpDataMediaChannel> chan2_;
349
350 int chan1_ready_to_send_count_;
351 int chan2_ready_to_send_count_;
352
353 void OnChan1ReadyToSend(bool send) {
354 if (send)
355 ++chan1_ready_to_send_count_;
356 }
357 void OnChan2ReadyToSend(bool send) {
358 if (send)
359 ++chan2_ready_to_send_count_;
360 }
341 }; 361 };
342 362
343 // Verifies that SignalReadyToSend is fired. 363 // Verifies that SignalReadyToSend is fired.
344 TEST_F(SctpDataMediaChannelTest, SignalReadyToSend) { 364 TEST_F(SctpDataMediaChannelTest, SignalReadyToSend) {
345 SetupConnectedChannels(); 365 SetupConnectedChannels();
346 366
347 SignalReadyToSendObserver signal_observer_1; 367 SignalReadyToSendObserver signal_observer_1;
348 SignalReadyToSendObserver signal_observer_2; 368 SignalReadyToSendObserver signal_observer_2;
349 369
350 channel1()->SignalReadyToSend.connect(&signal_observer_1, 370 channel1()->SignalReadyToSend.connect(&signal_observer_1,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 499
480 channel2()->RemoveSendStream(2); 500 channel2()->RemoveSendStream(2);
481 channel2()->RemoveSendStream(3); 501 channel2()->RemoveSendStream(3);
482 channel2()->RemoveSendStream(4); 502 channel2()->RemoveSendStream(4);
483 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000); 503 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000);
484 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(2), 1000); 504 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(2), 1000);
485 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(3), 1000); 505 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(3), 1000);
486 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(4), 1000); 506 EXPECT_TRUE_WAIT(chan_1_sig_receiver.WasStreamClosed(4), 1000);
487 } 507 }
488 508
509 TEST_F(SctpDataMediaChannelTest, EngineSignalsRightChannel) {
510 SetupConnectedChannels();
511 EXPECT_TRUE_WAIT(channel1()->socket() != NULL, 1000);
512 struct socket *sock = const_cast<struct socket*>(channel1()->socket());
513 int prior_count = channel1_ready_to_send_count();
514 cricket::SctpDataEngine::SendThresholdCallback(sock, 0);
515 EXPECT_GT(channel1_ready_to_send_count(), prior_count);
516 }
517
489 // Flaky on Linux and Windows. See webrtc:4453. 518 // Flaky on Linux and Windows. See webrtc:4453.
490 #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX) 519 #if defined(WEBRTC_WIN) || defined(WEBRTC_LINUX)
491 #define MAYBE_ReusesAStream DISABLED_ReusesAStream 520 #define MAYBE_ReusesAStream DISABLED_ReusesAStream
492 #else 521 #else
493 #define MAYBE_ReusesAStream ReusesAStream 522 #define MAYBE_ReusesAStream ReusesAStream
494 #endif 523 #endif
495 TEST_F(SctpDataMediaChannelTest, MAYBE_ReusesAStream) { 524 TEST_F(SctpDataMediaChannelTest, MAYBE_ReusesAStream) {
496 // Shut down channel 1, then open it up again for reuse. 525 // Shut down channel 1, then open it up again for reuse.
497 SetupConnectedChannels(); 526 SetupConnectedChannels();
498 cricket::SendDataResult result; 527 cricket::SendDataResult result;
499 SignalChannelClosedObserver chan_2_sig_receiver; 528 SignalChannelClosedObserver chan_2_sig_receiver;
500 chan_2_sig_receiver.BindSelf(channel2()); 529 chan_2_sig_receiver.BindSelf(channel2());
501 530
502 ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result)); 531 ASSERT_TRUE(SendData(channel1(), 1, "hello?", &result));
503 EXPECT_EQ(cricket::SDR_SUCCESS, result); 532 EXPECT_EQ(cricket::SDR_SUCCESS, result);
504 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000); 533 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hello?"), 1000);
505 534
506 channel1()->RemoveSendStream(1); 535 channel1()->RemoveSendStream(1);
507 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000); 536 EXPECT_TRUE_WAIT(chan_2_sig_receiver.WasStreamClosed(1), 1000);
508 // Channel 1 is gone now. 537 // Channel 1 is gone now.
509 538
510 // Create a new channel 1. 539 // Create a new channel 1.
511 AddStream(1); 540 AddStream(1);
512 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result)); 541 ASSERT_TRUE(SendData(channel1(), 1, "hi?", &result));
513 EXPECT_EQ(cricket::SDR_SUCCESS, result); 542 EXPECT_EQ(cricket::SDR_SUCCESS, result);
514 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000); 543 EXPECT_TRUE_WAIT(ReceivedData(receiver2(), 1, "hi?"), 1000);
515 channel1()->RemoveSendStream(1); 544 channel1()->RemoveSendStream(1);
516 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000); 545 EXPECT_TRUE_WAIT(chan_2_sig_receiver.StreamCloseCount(1) == 2, 1000);
517 } 546 }
OLDNEW
« no previous file with comments | « talk/media/sctp/sctpdataengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698