blob: dcd124341d06a862278d5e740f6cb1e08b97ab4c [file] [log] [blame]
Taylor Brandstetter734262c2016-08-01 16:37:14 -07001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#include "p2p/base/turnserver.h"
12#include "p2p/base/basicpacketsocketfactory.h"
13#include "rtc_base/gunit.h"
14#include "rtc_base/virtualsocketserver.h"
Taylor Brandstetter734262c2016-08-01 16:37:14 -070015
16// NOTE: This is a work in progress. Currently this file only has tests for
17// TurnServerConnection, a primitive class used by TurnServer.
18
19namespace cricket {
20
21class TurnServerConnectionTest : public testing::Test {
22 public:
deadbeef98e186c2017-05-16 18:00:06 -070023 TurnServerConnectionTest() : thread_(&vss_) {}
Taylor Brandstetter734262c2016-08-01 16:37:14 -070024
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 Brandstetter734262c2016-08-01 16:37:14 -070041 rtc::VirtualSocketServer vss_;
nisse7eaa4ea2017-05-08 05:25:41 -070042 rtc::AutoSocketServerThread thread_;
43 // Since this is constructed after |thread_|, it will pick up |threads_|'s
Taylor Brandstetter734262c2016-08-01 16:37:14 -070044 // socket server.
45 rtc::BasicPacketSocketFactory socket_factory_;
46};
47
48TEST_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