xref: /aosp_15_r20/external/webrtc/p2p/base/turn_server_unittest.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2016 The WebRTC Project Authors. All rights reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/turn_server.h"
12*d9f75844SAndroid Build Coastguard Worker 
13*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/basic_packet_socket_factory.h"
14*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/virtual_socket_server.h"
15*d9f75844SAndroid Build Coastguard Worker #include "test/gtest.h"
16*d9f75844SAndroid Build Coastguard Worker 
17*d9f75844SAndroid Build Coastguard Worker // NOTE: This is a work in progress. Currently this file only has tests for
18*d9f75844SAndroid Build Coastguard Worker // TurnServerConnection, a primitive class used by TurnServer.
19*d9f75844SAndroid Build Coastguard Worker 
20*d9f75844SAndroid Build Coastguard Worker namespace cricket {
21*d9f75844SAndroid Build Coastguard Worker 
22*d9f75844SAndroid Build Coastguard Worker class TurnServerConnectionTest : public ::testing::Test {
23*d9f75844SAndroid Build Coastguard Worker  public:
TurnServerConnectionTest()24*d9f75844SAndroid Build Coastguard Worker   TurnServerConnectionTest() : thread_(&vss_), socket_factory_(&vss_) {}
25*d9f75844SAndroid Build Coastguard Worker 
ExpectEqual(const TurnServerConnection & a,const TurnServerConnection & b)26*d9f75844SAndroid Build Coastguard Worker   void ExpectEqual(const TurnServerConnection& a,
27*d9f75844SAndroid Build Coastguard Worker                    const TurnServerConnection& b) {
28*d9f75844SAndroid Build Coastguard Worker     EXPECT_TRUE(a == b);
29*d9f75844SAndroid Build Coastguard Worker     EXPECT_FALSE(a < b);
30*d9f75844SAndroid Build Coastguard Worker     EXPECT_FALSE(b < a);
31*d9f75844SAndroid Build Coastguard Worker   }
32*d9f75844SAndroid Build Coastguard Worker 
ExpectNotEqual(const TurnServerConnection & a,const TurnServerConnection & b)33*d9f75844SAndroid Build Coastguard Worker   void ExpectNotEqual(const TurnServerConnection& a,
34*d9f75844SAndroid Build Coastguard Worker                       const TurnServerConnection& b) {
35*d9f75844SAndroid Build Coastguard Worker     EXPECT_FALSE(a == b);
36*d9f75844SAndroid Build Coastguard Worker     // We don't care which is less than the other, as long as only one is less
37*d9f75844SAndroid Build Coastguard Worker     // than the other.
38*d9f75844SAndroid Build Coastguard Worker     EXPECT_TRUE((a < b) != (b < a));
39*d9f75844SAndroid Build Coastguard Worker   }
40*d9f75844SAndroid Build Coastguard Worker 
41*d9f75844SAndroid Build Coastguard Worker  protected:
42*d9f75844SAndroid Build Coastguard Worker   rtc::VirtualSocketServer vss_;
43*d9f75844SAndroid Build Coastguard Worker   rtc::AutoSocketServerThread thread_;
44*d9f75844SAndroid Build Coastguard Worker   rtc::BasicPacketSocketFactory socket_factory_;
45*d9f75844SAndroid Build Coastguard Worker };
46*d9f75844SAndroid Build Coastguard Worker 
TEST_F(TurnServerConnectionTest,ComparisonOperators)47*d9f75844SAndroid Build Coastguard Worker TEST_F(TurnServerConnectionTest, ComparisonOperators) {
48*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::AsyncPacketSocket> socket1(
49*d9f75844SAndroid Build Coastguard Worker       socket_factory_.CreateUdpSocket(rtc::SocketAddress("1.1.1.1", 1), 0, 0));
50*d9f75844SAndroid Build Coastguard Worker   std::unique_ptr<rtc::AsyncPacketSocket> socket2(
51*d9f75844SAndroid Build Coastguard Worker       socket_factory_.CreateUdpSocket(rtc::SocketAddress("2.2.2.2", 2), 0, 0));
52*d9f75844SAndroid Build Coastguard Worker   TurnServerConnection connection1(socket2->GetLocalAddress(), PROTO_UDP,
53*d9f75844SAndroid Build Coastguard Worker                                    socket1.get());
54*d9f75844SAndroid Build Coastguard Worker   TurnServerConnection connection2(socket2->GetLocalAddress(), PROTO_UDP,
55*d9f75844SAndroid Build Coastguard Worker                                    socket1.get());
56*d9f75844SAndroid Build Coastguard Worker   TurnServerConnection connection3(socket1->GetLocalAddress(), PROTO_UDP,
57*d9f75844SAndroid Build Coastguard Worker                                    socket2.get());
58*d9f75844SAndroid Build Coastguard Worker   TurnServerConnection connection4(socket2->GetLocalAddress(), PROTO_TCP,
59*d9f75844SAndroid Build Coastguard Worker                                    socket1.get());
60*d9f75844SAndroid Build Coastguard Worker   ExpectEqual(connection1, connection2);
61*d9f75844SAndroid Build Coastguard Worker   ExpectNotEqual(connection1, connection3);
62*d9f75844SAndroid Build Coastguard Worker   ExpectNotEqual(connection1, connection4);
63*d9f75844SAndroid Build Coastguard Worker }
64*d9f75844SAndroid Build Coastguard Worker 
65*d9f75844SAndroid Build Coastguard Worker }  // namespace cricket
66