Raphael Isemann | 8081428 | 2020-01-24 07:23:27 | [diff] [blame] | 1 | //===-- ConnectionFileDescriptorTest.cpp ----------------------------------===// |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 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 | |
Pavel Labath | 59656c0 | 2022-08-24 13:59:46 | [diff] [blame] | 9 | #include "TestingSupport/Host/SocketTestUtilities.h" |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 10 | #include "gtest/gtest.h" |
Raphael Isemann | 5dca059 | 2019-12-23 09:38:12 | [diff] [blame] | 11 | #include "TestingSupport/SubsystemRAII.h" |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 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: |
Raphael Isemann | 5dca059 | 2019-12-23 09:38:12 | [diff] [blame] | 19 | SubsystemRAII<Socket> subsystems; |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 20 | |
| 21 | void TestGetURI(std::string ip) { |
| 22 | std::unique_ptr<TCPSocket> socket_a_up; |
| 23 | std::unique_ptr<TCPSocket> socket_b_up; |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 24 | CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up); |
Jonas Devlieghere | 9aa6a47 | 2022-04-28 19:48:14 | [diff] [blame] | 25 | auto *socket = socket_a_up.release(); |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 26 | ConnectionFileDescriptor connection_file_descriptor(socket); |
| 27 | |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 28 | std::string uri(connection_file_descriptor.GetURI()); |
Michał Górny | 0e5a414 | 2021-10-22 13:34:54 | [diff] [blame] | 29 | EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}), |
Fangrui Song | f43886e | 2022-12-17 20:37:13 | [diff] [blame] | 30 | *URI::Parse(uri)); |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 31 | } |
| 32 | }; |
| 33 | |
Pavel Labath | 18e96a3 | 2020-04-27 15:15:36 | [diff] [blame] | 34 | TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) { |
| 35 | if (!HostSupportsIPv4()) |
| 36 | return; |
| 37 | TestGetURI("127.0.0.1"); |
| 38 | } |
Antonio Afonso | 3da8e5f | 2019-05-28 23:26:32 | [diff] [blame] | 39 | |
Pavel Labath | 18e96a3 | 2020-04-27 15:15:36 | [diff] [blame] | 40 | TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) { |
| 41 | if (!HostSupportsIPv6()) |
| 42 | return; |
| 43 | TestGetURI("::1"); |
| 44 | } |