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

Side by Side Diff: webrtc/base/socket_unittest.cc

Issue 2209333002: Revert of Enable socketservers unittests on windows (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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 | « webrtc/base/socket_unittest.h ('k') | webrtc/base/win32socketserver_unittest.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 /* 1 /*
2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 TypedMessageData<AsyncSocket*> data(client.get()); 674 TypedMessageData<AsyncSocket*> data(client.get());
675 thread->Send(RTC_FROM_HERE, &sleeper, 0, &data); 675 thread->Send(RTC_FROM_HERE, &sleeper, 0, &data);
676 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ)); 676 EXPECT_FALSE(sink.Check(accepted.get(), testing::SSE_READ));
677 677
678 // But should signal when process_io is true. 678 // But should signal when process_io is true.
679 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout); 679 EXPECT_TRUE_WAIT((sink.Check(accepted.get(), testing::SSE_READ)), kTimeout);
680 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr)); 680 EXPECT_LT(0, accepted->Recv(buf, 1024, nullptr));
681 } 681 }
682 682
683 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size, 683 void SocketTest::TcpInternal(const IPAddress& loopback, size_t data_size,
684 ptrdiff_t max_send_size) { 684 ssize_t max_send_size) {
685 testing::StreamSink sink; 685 testing::StreamSink sink;
686 SocketAddress accept_addr; 686 SocketAddress accept_addr;
687 687
688 // Create receiving client. 688 // Create receiving client.
689 std::unique_ptr<AsyncSocket> receiver( 689 std::unique_ptr<AsyncSocket> receiver(
690 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM)); 690 ss_->CreateAsyncSocket(loopback.family(), SOCK_STREAM));
691 sink.Monitor(receiver.get()); 691 sink.Monitor(receiver.get());
692 692
693 // Create server and listen. 693 // Create server and listen.
694 std::unique_ptr<AsyncSocket> server( 694 std::unique_ptr<AsyncSocket> server(
(...skipping 17 matching lines...) Expand all
712 EXPECT_EQ(receiver->GetRemoteAddress(), sender->GetLocalAddress()); 712 EXPECT_EQ(receiver->GetRemoteAddress(), sender->GetLocalAddress());
713 EXPECT_EQ(sender->GetRemoteAddress(), receiver->GetLocalAddress()); 713 EXPECT_EQ(sender->GetRemoteAddress(), receiver->GetLocalAddress());
714 714
715 // Create test data. 715 // Create test data.
716 rtc::Buffer send_buffer(0, data_size); 716 rtc::Buffer send_buffer(0, data_size);
717 rtc::Buffer recv_buffer(0, data_size); 717 rtc::Buffer recv_buffer(0, data_size);
718 for (size_t i = 0; i < data_size; ++i) { 718 for (size_t i = 0; i < data_size; ++i) {
719 char ch = static_cast<char>(i % 256); 719 char ch = static_cast<char>(i % 256);
720 send_buffer.AppendData(&ch, sizeof(ch)); 720 send_buffer.AppendData(&ch, sizeof(ch));
721 } 721 }
722 rtc::Buffer recved_data(0, data_size);
723 722
724 // Send and receive a bunch of data. 723 // Send and receive a bunch of data.
725 size_t sent_size = 0; 724 size_t sent_size = 0;
726 bool writable = true; 725 bool writable = true;
727 bool send_called = false; 726 bool send_called = false;
728 bool readable = false; 727 bool readable = false;
729 bool recv_called = false; 728 bool recv_called = false;
730 while (recv_buffer.size() < send_buffer.size()) { 729 while (recv_buffer.size() < send_buffer.size()) {
731 // Send as much as we can while we're cleared to send. 730 // Send as much as we can while we're cleared to send.
732 while (writable && sent_size < send_buffer.size()) { 731 while (writable && sent_size < send_buffer.size()) {
733 int unsent_size = static_cast<int>(send_buffer.size() - sent_size); 732 int unsent_size = static_cast<int>(send_buffer.size() - sent_size);
734 int sent = sender->Send(send_buffer.data() + sent_size, unsent_size); 733 int sent = sender->Send(send_buffer.data() + sent_size, unsent_size);
735 if (!send_called) { 734 if (!send_called) {
736 // The first Send() after connecting or getting writability should 735 // The first Send() after connecting or getting writability should
737 // succeed and send some data. 736 // succeed and send some data.
738 EXPECT_GT(sent, 0); 737 EXPECT_GT(sent, 0);
739 send_called = true; 738 send_called = true;
740 } 739 }
741 if (sent >= 0) { 740 if (sent >= 0) {
742 EXPECT_LE(sent, unsent_size); 741 EXPECT_LE(sent, unsent_size);
743 sent_size += sent; 742 sent_size += sent;
744 if (max_send_size >= 0) { 743 if (max_send_size >= 0) {
745 EXPECT_LE(static_cast<ptrdiff_t>(sent), max_send_size); 744 EXPECT_LE(static_cast<ssize_t>(sent), max_send_size);
746 if (sent < unsent_size) { 745 if (sent < unsent_size) {
747 // If max_send_size is limiting the amount to send per call such 746 // If max_send_size is limiting the amount to send per call such
748 // that the sent amount is less than the unsent amount, we simulate 747 // that the sent amount is less than the unsent amount, we simulate
749 // that the socket is no longer writable. 748 // that the socket is no longer writable.
750 writable = false; 749 writable = false;
751 } 750 }
752 } 751 }
753 } else { 752 } else {
754 ASSERT_TRUE(sender->IsBlocking()); 753 ASSERT_TRUE(sender->IsBlocking());
755 writable = false; 754 writable = false;
756 } 755 }
757 } 756 }
758 757
759 // Read all the sent data. 758 // Read all the sent data.
760 while (recv_buffer.size() < sent_size) { 759 while (recv_buffer.size() < sent_size) {
761 if (!readable) { 760 if (!readable) {
762 // Wait until data is available. 761 // Wait until data is available.
763 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ), 762 EXPECT_TRUE_WAIT(sink.Check(receiver.get(), testing::SSE_READ),
764 kTimeout); 763 kTimeout);
765 readable = true; 764 readable = true;
766 recv_called = false; 765 recv_called = false;
767 } 766 }
768 767
769 // Receive as much as we can get in a single recv call. 768 // Receive as much as we can get in a single recv call.
770 int recved_size = receiver->Recv(recved_data.data(), data_size, nullptr); 769 char recved_data[data_size];
770 int recved_size = receiver->Recv(recved_data, data_size, nullptr);
771 771
772 if (!recv_called) { 772 if (!recv_called) {
773 // The first Recv() after getting readability should succeed and receive 773 // The first Recv() after getting readability should succeed and receive
774 // some data. 774 // some data.
775 // TODO: The following line is disabled due to flakey pulse 775 // TODO: The following line is disabled due to flakey pulse
776 // builds. Re-enable if/when possible. 776 // builds. Re-enable if/when possible.
777 // EXPECT_GT(recved_size, 0); 777 // EXPECT_GT(recved_size, 0);
778 recv_called = true; 778 recv_called = true;
779 } 779 }
780 if (recved_size >= 0) { 780 if (recved_size >= 0) {
781 EXPECT_LE(static_cast<size_t>(recved_size), 781 EXPECT_LE(static_cast<size_t>(recved_size),
782 sent_size - recv_buffer.size()); 782 sent_size - recv_buffer.size());
783 recv_buffer.AppendData(recved_data.data(), recved_size); 783 recv_buffer.AppendData(recved_data, recved_size);
784 } else { 784 } else {
785 ASSERT_TRUE(receiver->IsBlocking()); 785 ASSERT_TRUE(receiver->IsBlocking());
786 readable = false; 786 readable = false;
787 } 787 }
788 } 788 }
789 789
790 // Once all that we've sent has been received, expect to be able to send 790 // Once all that we've sent has been received, expect to be able to send
791 // again. 791 // again.
792 if (!writable) { 792 if (!writable) {
793 ASSERT_TRUE_WAIT(sink.Check(sender.get(), testing::SSE_WRITE), 793 EXPECT_TRUE_WAIT(sink.Check(sender.get(), testing::SSE_WRITE),
794 kTimeout); 794 kTimeout);
795 writable = true; 795 writable = true;
796 send_called = false; 796 send_called = false;
797 } 797 }
798 } 798 }
799 799
800 // The received data matches the sent data. 800 // The received data matches the sent data.
801 EXPECT_EQ(data_size, sent_size); 801 EXPECT_EQ(data_size, sent_size);
802 EXPECT_EQ(data_size, recv_buffer.size()); 802 EXPECT_EQ(data_size, recv_buffer.size());
803 EXPECT_EQ(recv_buffer, send_buffer); 803 EXPECT_EQ(recv_buffer, send_buffer);
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1042 1042
1043 const int64_t kTimeBetweenPacketsMs = 10; 1043 const int64_t kTimeBetweenPacketsMs = 10;
1044 Thread::SleepMs(kTimeBetweenPacketsMs); 1044 Thread::SleepMs(kTimeBetweenPacketsMs);
1045 1045
1046 socket->SendTo("bar", 3, address); 1046 socket->SendTo("bar", 3, address);
1047 socket->RecvFrom(buffer, 3, nullptr, &timestamp); 1047 socket->RecvFrom(buffer, 3, nullptr, &timestamp);
1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000); 1048 EXPECT_NEAR(timestamp, prev_timestamp + kTimeBetweenPacketsMs * 1000, 2000);
1049 } 1049 }
1050 1050
1051 } // namespace rtc 1051 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/socket_unittest.h ('k') | webrtc/base/win32socketserver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698