1//===-- PipeTest.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 "lldb/Host/Pipe.h"
10#include "TestingSupport/SubsystemRAII.h"
11#include "lldb/Host/FileSystem.h"
12#include "lldb/Host/HostInfo.h"
13#include "gtest/gtest.h"
14
15using namespace lldb_private;
16
17class PipeTest : public testing::Test {
18public:
19 SubsystemRAII<FileSystem, HostInfo> subsystems;
20};
21
22TEST_F(PipeTest, CreateWithUniqueName) {
23 Pipe pipe;
24 llvm::SmallString<0> name;
25 ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-CreateWithUniqueName",
26 /*child_process_inherit=*/false,
27 name)
28 .ToError(),
29 llvm::Succeeded());
30}
31
32// Test broken
33#ifndef _WIN32
34TEST_F(PipeTest, OpenAsReader) {
35 Pipe pipe;
36 llvm::SmallString<0> name;
37 ASSERT_THAT_ERROR(pipe.CreateWithUniqueName("PipeTest-OpenAsReader",
38 /*child_process_inherit=*/false,
39 name)
40 .ToError(),
41 llvm::Succeeded());
42
43 // Ensure name is not null-terminated
44 size_t name_len = name.size();
45 name += "foobar";
46 llvm::StringRef name_ref(name.data(), name_len);
47 ASSERT_THAT_ERROR(
48 pipe.OpenAsReader(name_ref, /*child_process_inherit=*/false).ToError(),
49 llvm::Succeeded());
50}
51#endif
52

source code of lldb/unittests/Host/PipeTest.cpp