Home | History | Annotate | Download | only in base
      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  */
     10 #include "webrtc/base/gunit.h"
     11 #include "webrtc/base/socket_unittest.h"
     12 #include "webrtc/base/thread.h"
     13 #include "webrtc/base/win32socketserver.h"
     14 
     15 namespace rtc {
     16 
     17 // Test that Win32SocketServer::Wait works as expected.
     18 TEST(Win32SocketServerTest, TestWait) {
     19   Win32SocketServer server(NULL);
     20   uint32_t start = Time();
     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) {
     27   Win32SocketServer server(NULL);
     28   SocketServerScope scope(&server);
     29   EXPECT_EQ(TRUE, PostMessage(NULL, WM_USER, 999, 0));
     30   server.Pump();
     31   MSG msg;
     32   EXPECT_EQ(TRUE, PeekMessage(&msg, NULL, WM_USER, 0, PM_REMOVE));
     33   EXPECT_EQ(WM_USER, msg.message);
     34   EXPECT_EQ(999, msg.wParam);
     35 }
     36 
     37 // Test that Win32Socket passes all the generic Socket tests.
     38 class Win32SocketTest : public SocketTest {
     39  protected:
     40   Win32SocketTest() : server_(NULL), scope_(&server_) {}
     41   Win32SocketServer server_;
     42   SocketServerScope scope_;
     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 
    149 TEST_F(Win32SocketTest, TestGetSetOptionsIPv4) {
    150   SocketTest::TestGetSetOptionsIPv4();
    151 }
    152 
    153 TEST_F(Win32SocketTest, TestGetSetOptionsIPv6) {
    154   SocketTest::TestGetSetOptionsIPv6();
    155 }
    156 
    157 }  // namespace rtc
    158