[NFC][Coroutines] Use structured binding with llvm::enumerate in CoroSplit (#116879)
[llvm-project.git] / lldb / unittests / Host / FileTest.cpp
blob35c87bb200fad41bfa64339b72c90359d8795276
1 //===-- FileTest.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 //===----------------------------------------------------------------------===//
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"
17 using namespace lldb;
18 using namespace lldb_private;
20 TEST(File, GetWaitableHandleFileno) {
21 const auto *Info = testing::UnitTest::GetInstance()->current_test_info();
23 llvm::SmallString<128> name;
24 int fd;
25 llvm::sys::fs::createTemporaryFile(llvm::Twine(Info->test_case_name()) + "-" +
26 Info->name(),
27 "test", fd, name);
28 llvm::FileRemover remover(name);
29 ASSERT_GE(fd, 0);
31 FILE *stream = fdopen(fd, "r");
32 ASSERT_TRUE(stream);
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;
41 int fd;
42 llvm::sys::fs::createTemporaryFile(llvm::Twine(Info->test_case_name()) + "-" +
43 Info->name(),
44 "test", fd, name);
46 llvm::FileRemover remover(name);
47 ASSERT_GE(fd, 0);
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);