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

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

Issue 2877023002: Move webrtc/{base => rtc_base} (Closed)
Patch Set: update presubmit.py and DEPS include rules Created 3 years, 5 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/testclient.cc ('k') | webrtc/base/testechoserver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2006 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 #include "webrtc/base/testclient.h"
12 #include "webrtc/base/gunit.h"
13 #include "webrtc/base/nethelpers.h"
14 #include "webrtc/base/physicalsocketserver.h"
15 #include "webrtc/base/ptr_util.h"
16 #include "webrtc/base/testechoserver.h"
17 #include "webrtc/base/thread.h"
18
19 using namespace rtc;
20
21 #define MAYBE_SKIP_IPV4 \
22 if (!HasIPv4Enabled()) { \
23 LOG(LS_INFO) << "No IPv4... skipping"; \
24 return; \
25 }
26
27 #define MAYBE_SKIP_IPV6 \
28 if (!HasIPv6Enabled()) { \
29 LOG(LS_INFO) << "No IPv6... skipping"; \
30 return; \
31 }
32
33 void TestUdpInternal(const SocketAddress& loopback) {
34 Thread *main = Thread::Current();
35 AsyncSocket* socket = main->socketserver()
36 ->CreateAsyncSocket(loopback.family(), SOCK_DGRAM);
37 socket->Bind(loopback);
38
39 TestClient client(MakeUnique<AsyncUDPSocket>(socket));
40 SocketAddress addr = client.address(), from;
41 EXPECT_EQ(3, client.SendTo("foo", 3, addr));
42 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from));
43 EXPECT_EQ(from, addr);
44 EXPECT_TRUE(client.CheckNoPacket());
45 }
46
47 void TestTcpInternal(const SocketAddress& loopback) {
48 Thread *main = Thread::Current();
49 TestEchoServer server(main, loopback);
50
51 AsyncSocket* socket = main->socketserver()
52 ->CreateAsyncSocket(loopback.family(), SOCK_STREAM);
53 std::unique_ptr<AsyncTCPSocket> tcp_socket =
54 WrapUnique(AsyncTCPSocket::Create(socket, loopback, server.address()));
55 ASSERT_TRUE(tcp_socket != nullptr);
56
57 TestClient client(std::move(tcp_socket));
58 SocketAddress addr = client.address(), from;
59 EXPECT_TRUE(client.CheckConnected());
60 EXPECT_EQ(3, client.Send("foo", 3));
61 EXPECT_TRUE(client.CheckNextPacket("foo", 3, &from));
62 EXPECT_EQ(from, server.address());
63 EXPECT_TRUE(client.CheckNoPacket());
64 }
65
66 // Tests whether the TestClient can send UDP to itself.
67 TEST(TestClientTest, TestUdpIPv4) {
68 MAYBE_SKIP_IPV4;
69 TestUdpInternal(SocketAddress("127.0.0.1", 0));
70 }
71
72 #if defined(WEBRTC_LINUX)
73 #define MAYBE_TestUdpIPv6 DISABLED_TestUdpIPv6
74 #else
75 #define MAYBE_TestUdpIPv6 TestUdpIPv6
76 #endif
77 TEST(TestClientTest, MAYBE_TestUdpIPv6) {
78 MAYBE_SKIP_IPV6;
79 TestUdpInternal(SocketAddress("::1", 0));
80 }
81
82 // Tests whether the TestClient can connect to a server and exchange data.
83 TEST(TestClientTest, TestTcpIPv4) {
84 MAYBE_SKIP_IPV4;
85 TestTcpInternal(SocketAddress("127.0.0.1", 0));
86 }
87
88 #if defined(WEBRTC_LINUX)
89 #define MAYBE_TestTcpIPv6 DISABLED_TestTcpIPv6
90 #else
91 #define MAYBE_TestTcpIPv6 TestTcpIPv6
92 #endif
93 TEST(TestClientTest, MAYBE_TestTcpIPv6) {
94 MAYBE_SKIP_IPV6;
95 TestTcpInternal(SocketAddress("::1", 0));
96 }
OLDNEW
« no previous file with comments | « webrtc/base/testclient.cc ('k') | webrtc/base/testechoserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698