xref: /llvm-project/lldb/unittests/Host/ConnectionFileDescriptorTest.cpp (revision aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d)
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     CreateTCPConnectedSockets(ip, &socket_a_up, &socket_b_up);
26     auto *socket = socket_a_up.release();
27     ConnectionFileDescriptor connection_file_descriptor(socket);
28 
29     std::string uri(connection_file_descriptor.GetURI());
30     EXPECT_EQ((URI{"connect", ip, socket->GetRemotePortNumber(), "/"}),
31               *URI::Parse(uri));
32   }
33 };
34 
35 TEST_F(ConnectionFileDescriptorTest, TCPGetURIv4) {
36   if (!HostSupportsIPv4())
37     return;
38   TestGetURI("127.0.0.1");
39 }
40 
41 TEST_F(ConnectionFileDescriptorTest, TCPGetURIv6) {
42   if (!HostSupportsIPv6())
43     return;
44   TestGetURI("::1");
45 }
46