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

Side by Side Diff: webrtc/api/ortcfactory_unittest.cc

Issue 2632613002: Adding OrtcFactory, and changing UdpTransport to match current plan. (Closed)
Patch Set: Splitting proxy changes from this CL Created 3 years, 11 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
OLDNEW
(Empty)
1 /*
2 * Copyright 2017 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 <memory>
12
13 #include "webrtc/api/ortcfactory.h"
14 #include "webrtc/base/fakenetwork.h"
15 #include "webrtc/base/gunit.h"
16 #include "webrtc/base/physicalsocketserver.h"
17 #include "webrtc/base/virtualsocketserver.h"
18 #include "webrtc/p2p/base/udptransport.h"
19
20 namespace {
21
22 const int kDefaultTimeout = 10000; // 10 seconds.
23 static const rtc::IPAddress kIPv4LocalHostAddress =
24 rtc::IPAddress(0x7F000001); // 127.0.0.1
25
26 class PacketReceiver : public sigslot::has_slots<> {
27 public:
28 explicit PacketReceiver(rtc::PacketTransportInterface* transport) {
29 transport->SignalReadPacket.connect(this, &PacketReceiver::OnReadPacket);
30 }
31 int packets_read() const { return packets_read_; }
32
33 private:
34 void OnReadPacket(rtc::PacketTransportInterface*,
35 const char*,
36 size_t,
37 const rtc::PacketTime&,
38 int) {
39 ++packets_read_;
40 }
41
42 int packets_read_ = 0;
43 };
44
45 } // namespace
46
47 namespace webrtc {
48
49 // Used to test that things work end-to-end when using the default
50 // implementations of threads/etc. provided by OrtcFactory, with the exception
51 // of using a virtual network.
52 //
53 // By default, the virtual network manager doesn't enumerate any networks, but
54 // sockets can still be created in this state.
55 class OrtcFactoryTest : public testing::Test {
56 public:
57 OrtcFactoryTest()
58 : virtual_socket_server_(&physical_socket_server_),
59 network_thread_(&virtual_socket_server_),
60 ortc_factory_(&network_thread_,
61 nullptr,
62 nullptr,
63 &fake_network_manager_,
64 nullptr) {
65 // Sockets are bound to the ANY address, so this is needed to tell the
66 // virtual network which address to use in this case.
67 virtual_socket_server_.SetDefaultRoute(kIPv4LocalHostAddress);
68 network_thread_.Start();
69 }
70
71 protected:
72 rtc::PhysicalSocketServer physical_socket_server_;
73 rtc::VirtualSocketServer virtual_socket_server_;
74 rtc::Thread network_thread_;
75 rtc::FakeNetworkManager fake_network_manager_;
76 OrtcFactory ortc_factory_;
77 };
78
79 TEST_F(OrtcFactoryTest, EndToEndUdpTransport) {
80 std::unique_ptr<UdpTransportInterface> transport1 =
81 ortc_factory_.CreateUdpTransport(AF_INET);
82 std::unique_ptr<UdpTransportInterface> transport2 =
83 ortc_factory_.CreateUdpTransport(AF_INET);
84 ASSERT_NE(nullptr, transport1);
85 ASSERT_NE(nullptr, transport2);
86 // Sockets are bound to the ANY address, so we need to provide the IP address
87 // explicitly.
88 transport1->SetRemoteAddress(
89 rtc::SocketAddress(virtual_socket_server_.GetDefaultRoute(AF_INET),
90 transport2->GetLocalAddress().port()));
91 transport2->SetRemoteAddress(
92 rtc::SocketAddress(virtual_socket_server_.GetDefaultRoute(AF_INET),
93 transport1->GetLocalAddress().port()));
94
95 // TODO(deadbeef): Once there's something (RTP senders/receivers) that can
96 // use UdpTransport end-to-end, use that for this end-to-end test instead of
97 // making assumptions about the implementation.
98 //
99 // For now, this assumes the returned object is a UdpTransportProxy that wraps
100 // a UdpTransport.
101 cricket::UdpTransport* internal_transport1 =
102 static_cast<UdpTransportProxyWithInternal<cricket::UdpTransport>*>(
103 transport1.get())
104 ->internal();
105 cricket::UdpTransport* internal_transport2 =
106 static_cast<UdpTransportProxyWithInternal<cricket::UdpTransport>*>(
107 transport2.get())
108 ->internal();
109 // Need to call internal "SendPacket" method on network thread.
110 network_thread_.Invoke<void>(
111 RTC_FROM_HERE, [internal_transport1, internal_transport2]() {
112 PacketReceiver receiver1(internal_transport1);
113 PacketReceiver receiver2(internal_transport2);
114 internal_transport1->SendPacket("foo", sizeof("foo"),
115 rtc::PacketOptions(), 0);
116 internal_transport2->SendPacket("foo", sizeof("foo"),
117 rtc::PacketOptions(), 0);
118 EXPECT_EQ_WAIT(1, receiver1.packets_read(), kDefaultTimeout);
119 EXPECT_EQ_WAIT(1, receiver2.packets_read(), kDefaultTimeout);
120 });
121 }
122
123 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698