| 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 "TestingSupport/Host/SocketTestUtilities.h" |
| 10 | #include "gtest/gtest.h" |
| 11 | #include "TestingSupport/SubsystemRAII.h" |
| 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 | SubsystemRAII<Socket> subsystems; |
| 20 | |
| 21 | void TestGetURI(std::string ip) { |
| 22 | std::unique_ptr<TCPSocket> socket_a_up; |
| 23 | std::unique_ptr<TCPSocket> socket_b_up; |
| 24 | CreateTCPConnectedSockets(listen_remote_ip: ip, a_up: &socket_a_up, b_up: &socket_b_up); |
| 25 | auto *socket = socket_a_up.release(); |
| 26 | ConnectionFileDescriptor connection_file_descriptor(socket); |
| 27 | |
| 28 | std::string uri(connection_file_descriptor.GetURI()); |
| 29 | EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}), |
| 30 | *URI::Parse(uri)); |
| 31 | } |
| 32 | }; |
| 33 | |
| 34 | TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) { |
| 35 | if (!HostSupportsIPv4()) |
| 36 | return; |
| 37 | TestGetURI(ip: "127.0.0.1"); |
| 38 | } |
| 39 | |
| 40 | TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) { |
| 41 | if (!HostSupportsIPv6()) |
| 42 | return; |
| 43 | TestGetURI(ip: "::1"); |
| 44 | } |
| 45 |
