henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 10 | #include "rtc_base/win32socketserver.h" |
| 11 | #include "rtc_base/gunit.h" |
| 12 | #include "rtc_base/socket_unittest.h" |
| 13 | #include "rtc_base/thread.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 14 | |
| 15 | namespace rtc { |
| 16 | |
| 17 | // Test that Win32SocketServer::Wait works as expected. |
| 18 | TEST(Win32SocketServerTest, TestWait) { |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 19 | Win32SocketServer server; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 20 | uint32_t start = Time(); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 21 | server.Wait(1000, true); |
| 22 | EXPECT_GE(TimeSince(start), 1000); |
| 23 | } |
| 24 | |
| 25 | // Test that Win32Socket::Pump does not touch general Windows messages. |
| 26 | TEST(Win32SocketServerTest, TestPump) { |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 27 | Win32SocketServer server; |
| 28 | rtc::AutoSocketServerThread thread(&server); |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 29 | EXPECT_EQ(TRUE, PostMessage(nullptr, WM_USER, 999, 0)); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 30 | server.Pump(); |
| 31 | MSG msg; |
deadbeef | 37f5ecf | 2017-02-27 14:06:41 -0800 | [diff] [blame] | 32 | EXPECT_EQ(TRUE, PeekMessage(&msg, nullptr, WM_USER, 0, PM_REMOVE)); |
danilchap | b7b9dca | 2016-08-05 05:55:43 -0700 | [diff] [blame] | 33 | EXPECT_EQ(static_cast<UINT>(WM_USER), msg.message); |
| 34 | EXPECT_EQ(999u, msg.wParam); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | // Test that Win32Socket passes all the generic Socket tests. |
| 38 | class Win32SocketTest : public SocketTest { |
| 39 | protected: |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 40 | Win32SocketTest() : thread_(&server_) {} |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 41 | Win32SocketServer server_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 42 | rtc::AutoSocketServerThread thread_; |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | TEST_F(Win32SocketTest, TestConnectIPv4) { |
| 46 | SocketTest::TestConnectIPv4(); |
| 47 | } |
| 48 | |
| 49 | TEST_F(Win32SocketTest, TestConnectIPv6) { |
| 50 | SocketTest::TestConnectIPv6(); |
| 51 | } |
| 52 | |
| 53 | TEST_F(Win32SocketTest, TestConnectWithDnsLookupIPv4) { |
| 54 | SocketTest::TestConnectWithDnsLookupIPv4(); |
| 55 | } |
| 56 | |
| 57 | TEST_F(Win32SocketTest, TestConnectWithDnsLookupIPv6) { |
| 58 | SocketTest::TestConnectWithDnsLookupIPv6(); |
| 59 | } |
| 60 | |
| 61 | TEST_F(Win32SocketTest, TestConnectFailIPv4) { |
| 62 | SocketTest::TestConnectFailIPv4(); |
| 63 | } |
| 64 | |
| 65 | TEST_F(Win32SocketTest, TestConnectFailIPv6) { |
| 66 | SocketTest::TestConnectFailIPv6(); |
| 67 | } |
| 68 | |
| 69 | TEST_F(Win32SocketTest, TestConnectWithDnsLookupFailIPv4) { |
| 70 | SocketTest::TestConnectWithDnsLookupFailIPv4(); |
| 71 | } |
| 72 | |
| 73 | TEST_F(Win32SocketTest, TestConnectWithDnsLookupFailIPv6) { |
| 74 | SocketTest::TestConnectWithDnsLookupFailIPv6(); |
| 75 | } |
| 76 | |
| 77 | TEST_F(Win32SocketTest, TestConnectWithClosedSocketIPv4) { |
| 78 | SocketTest::TestConnectWithClosedSocketIPv4(); |
| 79 | } |
| 80 | |
| 81 | TEST_F(Win32SocketTest, TestConnectWithClosedSocketIPv6) { |
| 82 | SocketTest::TestConnectWithClosedSocketIPv6(); |
| 83 | } |
| 84 | |
| 85 | TEST_F(Win32SocketTest, TestConnectWhileNotClosedIPv4) { |
| 86 | SocketTest::TestConnectWhileNotClosedIPv4(); |
| 87 | } |
| 88 | |
| 89 | TEST_F(Win32SocketTest, TestConnectWhileNotClosedIPv6) { |
| 90 | SocketTest::TestConnectWhileNotClosedIPv6(); |
| 91 | } |
| 92 | |
| 93 | TEST_F(Win32SocketTest, TestServerCloseDuringConnectIPv4) { |
| 94 | SocketTest::TestServerCloseDuringConnectIPv4(); |
| 95 | } |
| 96 | |
| 97 | TEST_F(Win32SocketTest, TestServerCloseDuringConnectIPv6) { |
| 98 | SocketTest::TestServerCloseDuringConnectIPv6(); |
| 99 | } |
| 100 | |
| 101 | TEST_F(Win32SocketTest, TestClientCloseDuringConnectIPv4) { |
| 102 | SocketTest::TestClientCloseDuringConnectIPv4(); |
| 103 | } |
| 104 | |
| 105 | TEST_F(Win32SocketTest, TestClientCloseDuringConnectIPv6) { |
| 106 | SocketTest::TestClientCloseDuringConnectIPv6(); |
| 107 | } |
| 108 | |
| 109 | TEST_F(Win32SocketTest, TestServerCloseIPv4) { |
| 110 | SocketTest::TestServerCloseIPv4(); |
| 111 | } |
| 112 | |
| 113 | TEST_F(Win32SocketTest, TestServerCloseIPv6) { |
| 114 | SocketTest::TestServerCloseIPv6(); |
| 115 | } |
| 116 | |
| 117 | TEST_F(Win32SocketTest, TestCloseInClosedCallbackIPv4) { |
| 118 | SocketTest::TestCloseInClosedCallbackIPv4(); |
| 119 | } |
| 120 | |
| 121 | TEST_F(Win32SocketTest, TestCloseInClosedCallbackIPv6) { |
| 122 | SocketTest::TestCloseInClosedCallbackIPv6(); |
| 123 | } |
| 124 | |
| 125 | TEST_F(Win32SocketTest, TestSocketServerWaitIPv4) { |
| 126 | SocketTest::TestSocketServerWaitIPv4(); |
| 127 | } |
| 128 | |
| 129 | TEST_F(Win32SocketTest, TestSocketServerWaitIPv6) { |
| 130 | SocketTest::TestSocketServerWaitIPv6(); |
| 131 | } |
| 132 | |
| 133 | TEST_F(Win32SocketTest, TestTcpIPv4) { |
| 134 | SocketTest::TestTcpIPv4(); |
| 135 | } |
| 136 | |
| 137 | TEST_F(Win32SocketTest, TestTcpIPv6) { |
| 138 | SocketTest::TestTcpIPv6(); |
| 139 | } |
| 140 | |
| 141 | TEST_F(Win32SocketTest, TestUdpIPv4) { |
| 142 | SocketTest::TestUdpIPv4(); |
| 143 | } |
| 144 | |
| 145 | TEST_F(Win32SocketTest, TestUdpIPv6) { |
| 146 | SocketTest::TestUdpIPv6(); |
| 147 | } |
| 148 | |
danilchap | b7b9dca | 2016-08-05 05:55:43 -0700 | [diff] [blame] | 149 | // Breaks win_x64_dbg bot. |
| 150 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6178 |
| 151 | TEST_F(Win32SocketTest, DISABLED_TestGetSetOptionsIPv4) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 152 | SocketTest::TestGetSetOptionsIPv4(); |
| 153 | } |
| 154 | |
danilchap | b7b9dca | 2016-08-05 05:55:43 -0700 | [diff] [blame] | 155 | // Breaks win_x64_dbg bot. |
| 156 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=6178 |
| 157 | TEST_F(Win32SocketTest, DISABLED_TestGetSetOptionsIPv6) { |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 158 | SocketTest::TestGetSetOptionsIPv6(); |
| 159 | } |
| 160 | |
| 161 | } // namespace rtc |