blob: 60295f10741f2e1997a385033e1838ea6604dc23 [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020010#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.orgf0488722014-05-13 18:00:26 +000014
15namespace rtc {
16
17// Test that Win32SocketServer::Wait works as expected.
18TEST(Win32SocketServerTest, TestWait) {
nisse7eaa4ea2017-05-08 05:25:41 -070019 Win32SocketServer server;
Peter Boström0c4e06b2015-10-07 12:23:21 +020020 uint32_t start = Time();
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000021 server.Wait(1000, true);
22 EXPECT_GE(TimeSince(start), 1000);
23}
24
25// Test that Win32Socket::Pump does not touch general Windows messages.
26TEST(Win32SocketServerTest, TestPump) {
nisse7eaa4ea2017-05-08 05:25:41 -070027 Win32SocketServer server;
28 rtc::AutoSocketServerThread thread(&server);
deadbeef37f5ecf2017-02-27 14:06:41 -080029 EXPECT_EQ(TRUE, PostMessage(nullptr, WM_USER, 999, 0));
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000030 server.Pump();
31 MSG msg;
deadbeef37f5ecf2017-02-27 14:06:41 -080032 EXPECT_EQ(TRUE, PeekMessage(&msg, nullptr, WM_USER, 0, PM_REMOVE));
danilchapb7b9dca2016-08-05 05:55:43 -070033 EXPECT_EQ(static_cast<UINT>(WM_USER), msg.message);
34 EXPECT_EQ(999u, msg.wParam);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000035}
36
37// Test that Win32Socket passes all the generic Socket tests.
38class Win32SocketTest : public SocketTest {
39 protected:
nisse7eaa4ea2017-05-08 05:25:41 -070040 Win32SocketTest() : thread_(&server_) {}
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000041 Win32SocketServer server_;
nisse7eaa4ea2017-05-08 05:25:41 -070042 rtc::AutoSocketServerThread thread_;
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000043};
44
45TEST_F(Win32SocketTest, TestConnectIPv4) {
46 SocketTest::TestConnectIPv4();
47}
48
49TEST_F(Win32SocketTest, TestConnectIPv6) {
50 SocketTest::TestConnectIPv6();
51}
52
53TEST_F(Win32SocketTest, TestConnectWithDnsLookupIPv4) {
54 SocketTest::TestConnectWithDnsLookupIPv4();
55}
56
57TEST_F(Win32SocketTest, TestConnectWithDnsLookupIPv6) {
58 SocketTest::TestConnectWithDnsLookupIPv6();
59}
60
61TEST_F(Win32SocketTest, TestConnectFailIPv4) {
62 SocketTest::TestConnectFailIPv4();
63}
64
65TEST_F(Win32SocketTest, TestConnectFailIPv6) {
66 SocketTest::TestConnectFailIPv6();
67}
68
69TEST_F(Win32SocketTest, TestConnectWithDnsLookupFailIPv4) {
70 SocketTest::TestConnectWithDnsLookupFailIPv4();
71}
72
73TEST_F(Win32SocketTest, TestConnectWithDnsLookupFailIPv6) {
74 SocketTest::TestConnectWithDnsLookupFailIPv6();
75}
76
77TEST_F(Win32SocketTest, TestConnectWithClosedSocketIPv4) {
78 SocketTest::TestConnectWithClosedSocketIPv4();
79}
80
81TEST_F(Win32SocketTest, TestConnectWithClosedSocketIPv6) {
82 SocketTest::TestConnectWithClosedSocketIPv6();
83}
84
85TEST_F(Win32SocketTest, TestConnectWhileNotClosedIPv4) {
86 SocketTest::TestConnectWhileNotClosedIPv4();
87}
88
89TEST_F(Win32SocketTest, TestConnectWhileNotClosedIPv6) {
90 SocketTest::TestConnectWhileNotClosedIPv6();
91}
92
93TEST_F(Win32SocketTest, TestServerCloseDuringConnectIPv4) {
94 SocketTest::TestServerCloseDuringConnectIPv4();
95}
96
97TEST_F(Win32SocketTest, TestServerCloseDuringConnectIPv6) {
98 SocketTest::TestServerCloseDuringConnectIPv6();
99}
100
101TEST_F(Win32SocketTest, TestClientCloseDuringConnectIPv4) {
102 SocketTest::TestClientCloseDuringConnectIPv4();
103}
104
105TEST_F(Win32SocketTest, TestClientCloseDuringConnectIPv6) {
106 SocketTest::TestClientCloseDuringConnectIPv6();
107}
108
109TEST_F(Win32SocketTest, TestServerCloseIPv4) {
110 SocketTest::TestServerCloseIPv4();
111}
112
113TEST_F(Win32SocketTest, TestServerCloseIPv6) {
114 SocketTest::TestServerCloseIPv6();
115}
116
117TEST_F(Win32SocketTest, TestCloseInClosedCallbackIPv4) {
118 SocketTest::TestCloseInClosedCallbackIPv4();
119}
120
121TEST_F(Win32SocketTest, TestCloseInClosedCallbackIPv6) {
122 SocketTest::TestCloseInClosedCallbackIPv6();
123}
124
125TEST_F(Win32SocketTest, TestSocketServerWaitIPv4) {
126 SocketTest::TestSocketServerWaitIPv4();
127}
128
129TEST_F(Win32SocketTest, TestSocketServerWaitIPv6) {
130 SocketTest::TestSocketServerWaitIPv6();
131}
132
133TEST_F(Win32SocketTest, TestTcpIPv4) {
134 SocketTest::TestTcpIPv4();
135}
136
137TEST_F(Win32SocketTest, TestTcpIPv6) {
138 SocketTest::TestTcpIPv6();
139}
140
141TEST_F(Win32SocketTest, TestUdpIPv4) {
142 SocketTest::TestUdpIPv4();
143}
144
145TEST_F(Win32SocketTest, TestUdpIPv6) {
146 SocketTest::TestUdpIPv6();
147}
148
danilchapb7b9dca2016-08-05 05:55:43 -0700149// Breaks win_x64_dbg bot.
150// https://bugs.chromium.org/p/webrtc/issues/detail?id=6178
151TEST_F(Win32SocketTest, DISABLED_TestGetSetOptionsIPv4) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000152 SocketTest::TestGetSetOptionsIPv4();
153}
154
danilchapb7b9dca2016-08-05 05:55:43 -0700155// Breaks win_x64_dbg bot.
156// https://bugs.chromium.org/p/webrtc/issues/detail?id=6178
157TEST_F(Win32SocketTest, DISABLED_TestGetSetOptionsIPv6) {
henrike@webrtc.orgf0488722014-05-13 18:00:26 +0000158 SocketTest::TestGetSetOptionsIPv6();
159}
160
161} // namespace rtc