Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "p2p/base/turn_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 13 | #include "p2p/base/basic_packet_socket_factory.h" |
| 14 | #include "rtc_base/virtual_socket_server.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 15 | #include "test/gtest.h" |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 16 | |
| 17 | // NOTE: This is a work in progress. Currently this file only has tests for |
| 18 | // TurnServerConnection, a primitive class used by TurnServer. |
| 19 | |
| 20 | namespace cricket { |
| 21 | |
Mirko Bonadei | 6a489f2 | 2019-04-09 15:11:12 +0200 | [diff] [blame] | 22 | class TurnServerConnectionTest : public ::testing::Test { |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 23 | public: |
Niels Möller | 66be895 | 2021-09-03 10:55:12 +0200 | [diff] [blame] | 24 | TurnServerConnectionTest() : thread_(&vss_), socket_factory_(&vss_) {} |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 25 | |
| 26 | void ExpectEqual(const TurnServerConnection& a, |
| 27 | const TurnServerConnection& b) { |
| 28 | EXPECT_TRUE(a == b); |
| 29 | EXPECT_FALSE(a < b); |
| 30 | EXPECT_FALSE(b < a); |
| 31 | } |
| 32 | |
| 33 | void ExpectNotEqual(const TurnServerConnection& a, |
| 34 | const TurnServerConnection& b) { |
| 35 | EXPECT_FALSE(a == b); |
| 36 | // We don't care which is less than the other, as long as only one is less |
| 37 | // than the other. |
| 38 | EXPECT_TRUE((a < b) != (b < a)); |
| 39 | } |
| 40 | |
| 41 | protected: |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 42 | rtc::VirtualSocketServer vss_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 43 | rtc::AutoSocketServerThread thread_; |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 44 | rtc::BasicPacketSocketFactory socket_factory_; |
| 45 | }; |
| 46 | |
| 47 | TEST_F(TurnServerConnectionTest, ComparisonOperators) { |
| 48 | std::unique_ptr<rtc::AsyncPacketSocket> socket1( |
| 49 | socket_factory_.CreateUdpSocket(rtc::SocketAddress("1.1.1.1", 1), 0, 0)); |
| 50 | std::unique_ptr<rtc::AsyncPacketSocket> socket2( |
| 51 | socket_factory_.CreateUdpSocket(rtc::SocketAddress("2.2.2.2", 2), 0, 0)); |
| 52 | TurnServerConnection connection1(socket2->GetLocalAddress(), PROTO_UDP, |
| 53 | socket1.get()); |
| 54 | TurnServerConnection connection2(socket2->GetLocalAddress(), PROTO_UDP, |
| 55 | socket1.get()); |
| 56 | TurnServerConnection connection3(socket1->GetLocalAddress(), PROTO_UDP, |
| 57 | socket2.get()); |
| 58 | TurnServerConnection connection4(socket2->GetLocalAddress(), PROTO_TCP, |
| 59 | socket1.get()); |
| 60 | ExpectEqual(connection1, connection2); |
| 61 | ExpectNotEqual(connection1, connection3); |
| 62 | ExpectNotEqual(connection1, connection4); |
| 63 | } |
| 64 | |
| 65 | } // namespace cricket |