OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2012 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 | |
11 // Tests for the UdpSocketWrapper interface. | |
12 // This will test the UdpSocket implementations on various platforms. | |
13 // Note that this test is using a real SocketManager, which starts up | |
14 // an extra worker thread, making the testing more complex than it | |
15 // should be. | |
16 // This is because on Posix, the CloseBlocking function waits for the | |
17 // ReadyForDeletion function to be called, which has to be called after | |
18 // CloseBlocking, and thus has to be called from another thread. | |
19 // The manager is the one actually doing the deleting. | |
20 // This is done differently in the Winsock2 code, but that code | |
21 // will also hang if the destructor is called directly. | |
22 | |
23 #include "testing/gmock/include/gmock/gmock.h" | |
24 #include "testing/gtest/include/gtest/gtest.h" | |
25 #include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" | |
26 #include "webrtc/test/channel_transport/udp_socket_wrapper.h" | |
27 | |
28 using ::testing::_; | |
29 using ::testing::Return; | |
30 | |
31 namespace webrtc { | |
32 namespace test { | |
33 | |
34 class MockSocketManager : public UdpSocketManager { | |
35 public: | |
36 MockSocketManager() {} | |
37 // Access to protected destructor. | |
38 void Destroy() { | |
39 delete this; | |
40 } | |
41 MOCK_METHOD2(Init, bool(int32_t, uint8_t&)); | |
42 MOCK_METHOD0(Start, bool()); | |
43 MOCK_METHOD0(Stop, bool()); | |
44 MOCK_METHOD1(AddSocket, bool(UdpSocketWrapper*)); | |
45 MOCK_METHOD1(RemoveSocket, bool(UdpSocketWrapper*)); | |
46 }; | |
47 | |
48 // Creates a socket using the static constructor method and verifies that | |
49 // it's added to the socket manager. | |
50 TEST(UdpSocketWrapper, CreateSocket) { | |
51 int32_t id = 42; | |
52 // We can't test deletion of sockets without a socket manager. | |
53 uint8_t threads = 1; | |
54 UdpSocketManager* mgr = UdpSocketManager::Create(id, threads); | |
55 UdpSocketWrapper* socket = | |
56 UdpSocketWrapper::CreateSocket(id, | |
57 mgr, | |
58 NULL, // CallbackObj | |
59 NULL, // IncomingSocketCallback | |
60 false, // ipV6Enable | |
61 false); // disableGQOS | |
62 socket->CloseBlocking(); | |
63 UdpSocketManager::Return(); | |
64 } | |
65 | |
66 } // namespace test | |
67 } // namespace webrtc | |
OLD | NEW |