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