• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "truncate_core.h"
17 
18 #include <gtest/gtest.h>
19 
20 
21 namespace OHOS::FileManagement::ModuleFileIO::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 
26 class TruncateCoreTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32 };
33 
SetUpTestCase(void)34 void TruncateCoreTest::SetUpTestCase(void)
35 {
36     GTEST_LOG_(INFO) << "SetUpTestCase";
37 }
38 
TearDownTestCase(void)39 void TruncateCoreTest::TearDownTestCase(void)
40 {
41     GTEST_LOG_(INFO) << "TearDownTestCase";
42 }
43 
SetUp(void)44 void TruncateCoreTest::SetUp(void)
45 {
46     GTEST_LOG_(INFO) << "SetUp";
47 }
48 
TearDown(void)49 void TruncateCoreTest::TearDown(void)
50 {
51     GTEST_LOG_(INFO) << "TearDown";
52 }
53 
54 /**
55  * @tc.name: TruncateCoreTest_DoTruncate_001
56  * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed.
57  * @tc.size: MEDIUM
58  * @tc.type: FUNC
59  * @tc.level Level 1
60  */
61 HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_001, testing::ext::TestSize.Level1)
62 {
63     GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_001";
64     FileInfo fileInfo;
65     fileInfo.fdg = std::make_unique<DistributedFS::FDGuard>(-1);
66 
67     auto res = TruncateCore::DoTruncate(fileInfo);
68     EXPECT_EQ(res.IsSuccess(), false);
69 
70     GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_001";
71 }
72 
73 /**
74  * @tc.name: TruncateCoreTest_DoTruncate_002
75  * @tc.desc: Test function of RmdirCore::DoTruncate interface for Failed.
76  * @tc.size: MEDIUM
77  * @tc.type: FUNC
78  * @tc.level Level 1
79  */
80 HWTEST_F(TruncateCoreTest, TruncateCoreTest_DoTruncate_002, testing::ext::TestSize.Level1)
81 {
82     GTEST_LOG_(INFO) << "TruncateCoreTest-begin TruncateCoreTest_DoTruncate_002";
83     FileInfo fileInfo;
84     std::optional<int64_t> len = std::make_optional(static_cast<int64_t>(-1));
85     fileInfo.fdg = std::make_unique<DistributedFS::FDGuard>(1);
86 
87     auto res = TruncateCore::DoTruncate(fileInfo, len);
88     EXPECT_EQ(res.IsSuccess(), false);
89 
90     GTEST_LOG_(INFO) << "TruncateCoreTest-end TruncateCoreTest_DoTruncate_002";
91 }
92 
93 } // namespace OHOS::FileManagement::ModuleFileIO::Test