• 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 "dup_core.h"
17 #include "uv_fs_mock.h"
18 
19 #include <gtest/gtest.h>
20 
21 namespace OHOS::FileManagement::ModuleFileIO::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 
26 class DupCoreMockTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32     static inline shared_ptr<UvfsMock> uvMock = nullptr;
33 };
34 
SetUpTestCase(void)35 void DupCoreMockTest::SetUpTestCase(void)
36 {
37     GTEST_LOG_(INFO) << "SetUpTestCase";
38     uvMock = make_shared<UvfsMock>();
39     Uvfs::ins = uvMock;
40 }
41 
TearDownTestCase(void)42 void DupCoreMockTest::TearDownTestCase(void)
43 {
44     Uvfs::ins = nullptr;
45     uvMock = nullptr;
46     GTEST_LOG_(INFO) << "TearDownTestCase";
47 }
48 
SetUp(void)49 void DupCoreMockTest::SetUp(void)
50 {
51     GTEST_LOG_(INFO) << "SetUp";
52 }
53 
TearDown(void)54 void DupCoreMockTest::TearDown(void)
55 {
56     GTEST_LOG_(INFO) << "TearDown";
57 }
58 
59 /**
60  * @tc.name: DupCoreMockTest_DoDup_001
61  * @tc.desc: Test function of DupCore::DoDup interface for FALSE.
62  * @tc.size: MEDIUM
63  * @tc.type: FUNC
64  * @tc.level Level 1
65  */
66 HWTEST_F(DupCoreMockTest, DupCoreMockTest_DoDup_001, testing::ext::TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "DupCoreMockTest-begin DupCoreMockTest_DoDup_001";
69 
70     int32_t fd = 1;
71 
72     EXPECT_CALL(*uvMock, uv_fs_readlink(_, _, _, _)).WillOnce(Return(-1));
73     auto res = DupCore::DoDup(fd);
74     EXPECT_EQ(res.IsSuccess(), false);
75 
76     GTEST_LOG_(INFO) << "DupCoreMockTest-end DupCoreMockTest_DoDup_001";
77 }
78 
79 } // namespace OHOS::FileManagement::ModuleFileIO::Test