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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "p2p/base/turnserver.h" |
| 12 | #include "p2p/base/basicpacketsocketfactory.h" |
| 13 | #include "rtc_base/gunit.h" |
| 14 | #include "rtc_base/virtualsocketserver.h" |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 15 | |
| 16 | // NOTE: This is a work in progress. Currently this file only has tests for |
| 17 | // TurnServerConnection, a primitive class used by TurnServer. |
| 18 | |
| 19 | namespace cricket { |
| 20 | |
| 21 | class TurnServerConnectionTest : public testing::Test { |
| 22 | public: |
deadbeef | 98e186c | 2017-05-16 18:00:06 -0700 | [diff] [blame] | 23 | TurnServerConnectionTest() : thread_(&vss_) {} |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 24 | |
| 25 | void ExpectEqual(const TurnServerConnection& a, |
| 26 | const TurnServerConnection& b) { |
| 27 | EXPECT_TRUE(a == b); |
| 28 | EXPECT_FALSE(a < b); |
| 29 | EXPECT_FALSE(b < a); |
| 30 | } |
| 31 | |
| 32 | void ExpectNotEqual(const TurnServerConnection& a, |
| 33 | const TurnServerConnection& b) { |
| 34 | EXPECT_FALSE(a == b); |
| 35 | // We don't care which is less than the other, as long as only one is less |
| 36 | // than the other. |
| 37 | EXPECT_TRUE((a < b) != (b < a)); |
| 38 | } |
| 39 | |
| 40 | protected: |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 41 | rtc::VirtualSocketServer vss_; |
nisse | 7eaa4ea | 2017-05-08 05:25:41 -0700 | [diff] [blame] | 42 | rtc::AutoSocketServerThread thread_; |
| 43 | // Since this is constructed after |thread_|, it will pick up |threads_|'s |
Taylor Brandstetter | 734262c | 2016-08-01 16:37:14 -0700 | [diff] [blame] | 44 | // socket server. |
| 45 | rtc::BasicPacketSocketFactory socket_factory_; |
| 46 | }; |
| 47 | |
| 48 | TEST_F(TurnServerConnectionTest, ComparisonOperators) { |
| 49 | std::unique_ptr<rtc::AsyncPacketSocket> socket1( |
| 50 | socket_factory_.CreateUdpSocket(rtc::SocketAddress("1.1.1.1", 1), 0, 0)); |
| 51 | std::unique_ptr<rtc::AsyncPacketSocket> socket2( |
| 52 | socket_factory_.CreateUdpSocket(rtc::SocketAddress("2.2.2.2", 2), 0, 0)); |
| 53 | TurnServerConnection connection1(socket2->GetLocalAddress(), PROTO_UDP, |
| 54 | socket1.get()); |
| 55 | TurnServerConnection connection2(socket2->GetLocalAddress(), PROTO_UDP, |
| 56 | socket1.get()); |
| 57 | TurnServerConnection connection3(socket1->GetLocalAddress(), PROTO_UDP, |
| 58 | socket2.get()); |
| 59 | TurnServerConnection connection4(socket2->GetLocalAddress(), PROTO_TCP, |
| 60 | socket1.get()); |
| 61 | ExpectEqual(connection1, connection2); |
| 62 | ExpectNotEqual(connection1, connection3); |
| 63 | ExpectNotEqual(connection1, connection4); |
| 64 | } |
| 65 | |
| 66 | } // namespace cricket |