1//===-- FileActionTest.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 <fcntl.h>
10
11#include "lldb/Host/FileAction.h"
12#include "gtest/gtest.h"
13#if defined(_WIN32)
14#include "lldb/Host/windows/PosixApi.h"
15#endif
16
17using namespace lldb_private;
18
19TEST(FileActionTest, Open) {
20 FileAction Action;
21 Action.Open(fd: 47, file_spec: FileSpec("/tmp"), /*read*/ true, /*write*/ false);
22 EXPECT_EQ(Action.GetAction(), FileAction::eFileActionOpen);
23 EXPECT_EQ(Action.GetFileSpec(), FileSpec("/tmp"));
24}
25
26TEST(FileActionTest, OpenReadWrite) {
27 FileAction Action;
28 Action.Open(fd: 48, file_spec: FileSpec("/tmp_0"), /*read*/ true, /*write*/ true);
29 EXPECT_TRUE(Action.GetActionArgument() & (O_NOCTTY | O_CREAT | O_RDWR));
30 EXPECT_FALSE(Action.GetActionArgument() & O_RDONLY);
31 EXPECT_FALSE(Action.GetActionArgument() & O_WRONLY);
32}
33
34TEST(FileActionTest, OpenReadOnly) {
35 FileAction Action;
36 Action.Open(fd: 49, file_spec: FileSpec("/tmp_1"), /*read*/ true, /*write*/ false);
37#ifndef _WIN32
38 EXPECT_TRUE(Action.GetActionArgument() & (O_NOCTTY | O_RDONLY));
39#endif
40 EXPECT_FALSE(Action.GetActionArgument() & O_WRONLY);
41}
42
43TEST(FileActionTest, OpenWriteOnly) {
44 FileAction Action;
45 Action.Open(fd: 50, file_spec: FileSpec("/tmp_2"), /*read*/ false, /*write*/ true);
46 EXPECT_TRUE(Action.GetActionArgument() &
47 (O_NOCTTY | O_CREAT | O_WRONLY | O_TRUNC));
48 EXPECT_FALSE(Action.GetActionArgument() & O_RDONLY);
49}
50

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