1 //===-- FileTest.cpp ------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Host/File.h"
10 #include "llvm/ADT/SmallString.h"
11 #include "llvm/Support/FileSystem.h"
12 #include "llvm/Support/FileUtilities.h"
13 #include "llvm/Support/Path.h"
14 #include "llvm/Support/Program.h"
15 #include "gtest/gtest.h"
18 using namespace lldb_private
;
20 TEST(File
, GetWaitableHandleFileno
) {
21 const auto *Info
= testing::UnitTest::GetInstance()->current_test_info();
23 llvm::SmallString
<128> name
;
25 llvm::sys::fs::createTemporaryFile(llvm::Twine(Info
->test_case_name()) + "-" +
28 llvm::FileRemover
remover(name
);
31 FILE *stream
= fdopen(fd
, "r");
34 NativeFile
file(stream
, true);
35 EXPECT_EQ(file
.GetWaitableHandle(), fd
);
38 TEST(File
, GetStreamFromDescriptor
) {
39 const auto *Info
= testing::UnitTest::GetInstance()->current_test_info();
40 llvm::SmallString
<128> name
;
42 llvm::sys::fs::createTemporaryFile(llvm::Twine(Info
->test_case_name()) + "-" +
46 llvm::FileRemover
remover(name
);
49 NativeFile
file(fd
, File::eOpenOptionWriteOnly
, true);
50 ASSERT_TRUE(file
.IsValid());
52 FILE *stream
= file
.GetStream();
53 ASSERT_TRUE(stream
!= NULL
);
55 EXPECT_EQ(file
.GetDescriptor(), fd
);
56 EXPECT_EQ(file
.GetWaitableHandle(), fd
);