1 //===-- ConnectionFileDescriptorTest.cpp ------------------------*- C++ -*-===// 2 // 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 9 #include "SocketTestUtilities.h" 10 #include "gtest/gtest.h" 11 12 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h" 13 #include "lldb/Utility/UriParser.h" 14 15 using namespace lldb_private; 16 17 class ConnectionFileDescriptorTest : public testing::Test { 18 public: 19 void SetUp() override { 20 ASSERT_THAT_ERROR(Socket::Initialize(), llvm::Succeeded()); 21 } 22 23 void TearDown() override { Socket::Terminate(); } 24 25 void TestGetURI(std::string ip) { 26 std::unique_ptr<TCPSocket> socket_a_up; 27 std::unique_ptr<TCPSocket> socket_b_up; 28 if (!IsAddressFamilySupported(ip)) { 29 GTEST_LOG_(WARNING) << "Skipping test due to missing IPv" 30 << (IsIPv4(ip) ? "4" : "6") << " support."; 31 return; 32 } 33 CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up); 34 auto socket = socket_a_up.release(); 35 ConnectionFileDescriptor connection_file_descriptor(socket); 36 37 llvm::StringRef scheme; 38 llvm::StringRef hostname; 39 int port; 40 llvm::StringRef path; 41 std::string uri(connection_file_descriptor.GetURI()); 42 EXPECT_TRUE(UriParser::Parse(uri, scheme, hostname, port, path)); 43 EXPECT_EQ(ip, hostname); 44 EXPECT_EQ(socket->GetRemotePortNumber(), port); 45 } 46 }; 47 48 TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) { TestGetURI("127.0.0.1"); } 49 50 TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) { TestGetURI("::1"); } 51