brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.6 KiB · ac067c4 Raw
50 lines · cpp
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-exception6//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#endif16 17using namespace lldb_private;18 19TEST(FileActionTest, Open) {20  FileAction Action;21  Action.Open(47, 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(48, 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(49, FileSpec("/tmp_1"), /*read*/ true, /*write*/ false);37#ifndef _WIN3238  EXPECT_TRUE(Action.GetActionArgument() & (O_NOCTTY | O_RDONLY));39#endif40  EXPECT_FALSE(Action.GetActionArgument() & O_WRONLY);41}42 43TEST(FileActionTest, OpenWriteOnly) {44  FileAction Action;45  Action.Open(50, 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