blob: 250ed6fe8fd37275be6cc63651192af035575f10 [file] [log] [blame]
Raphael Isemann80814282020-01-24 07:23:271//===-- ConnectionFileDescriptorTest.cpp ----------------------------------===//
Antonio Afonso3da8e5f2019-05-28 23:26:322//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
Pavel Labath59656c02022-08-24 13:59:469#include "TestingSupport/Host/SocketTestUtilities.h"
Antonio Afonso3da8e5f2019-05-28 23:26:3210#include "gtest/gtest.h"
Raphael Isemann5dca0592019-12-23 09:38:1211#include "TestingSupport/SubsystemRAII.h"
Antonio Afonso3da8e5f2019-05-28 23:26:3212#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
13#include "lldb/Utility/UriParser.h"
14
15using namespace lldb_private;
16
17class ConnectionFileDescriptorTest : public testing::Test {
18public:
Raphael Isemann5dca0592019-12-23 09:38:1219 SubsystemRAII<Socket> subsystems;
Antonio Afonso3da8e5f2019-05-28 23:26:3220
21 void TestGetURI(std::string ip) {
22 std::unique_ptr<TCPSocket> socket_a_up;
23 std::unique_ptr<TCPSocket> socket_b_up;
Antonio Afonso3da8e5f2019-05-28 23:26:3224 CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
Jonas Devlieghere9aa6a472022-04-28 19:48:1425 auto *socket = socket_a_up.release();
Antonio Afonso3da8e5f2019-05-28 23:26:3226 ConnectionFileDescriptor connection_file_descriptor(socket);
27
Antonio Afonso3da8e5f2019-05-28 23:26:3228 std::string uri(connection_file_descriptor.GetURI());
Michał Górny0e5a4142021-10-22 13:34:5429 EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}),
Fangrui Songf43886e2022-12-17 20:37:1330 *URI::Parse(uri));
Antonio Afonso3da8e5f2019-05-28 23:26:3231 }
32};
33
Pavel Labath18e96a32020-04-27 15:15:3634TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) {
35 if (!HostSupportsIPv4())
36 return;
37 TestGetURI("127.0.0.1");
38}
Antonio Afonso3da8e5f2019-05-28 23:26:3239
Pavel Labath18e96a32020-04-27 15:15:3640TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) {
41 if (!HostSupportsIPv6())
42 return;
43 TestGetURI("::1");
44}