• 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 
17 #include "symlink_core.h"
18 #include "uv_fs_mock.h"
19 
20 #include <gtest/gtest.h>
21 
22 namespace OHOS::FileManagement::ModuleFileIO::Test {
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace std;
26 
27 class SymlinkCoreMockTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33     static inline shared_ptr<UvfsMock> uvMock = nullptr;
34 };
35 
SetUpTestCase(void)36 void SymlinkCoreMockTest::SetUpTestCase(void)
37 {
38     GTEST_LOG_(INFO) << "SetUpTestCase";
39     uvMock = make_shared<UvfsMock>();
40     Uvfs::ins = uvMock;
41 }
42 
TearDownTestCase(void)43 void SymlinkCoreMockTest::TearDownTestCase(void)
44 {
45     GTEST_LOG_(INFO) << "TearDownTestCase";
46     Uvfs::ins = nullptr;
47     uvMock = nullptr;
48 }
49 
SetUp(void)50 void SymlinkCoreMockTest::SetUp(void)
51 {
52     GTEST_LOG_(INFO) << "SetUp";
53 }
54 
TearDown(void)55 void SymlinkCoreMockTest::TearDown(void)
56 {
57     GTEST_LOG_(INFO) << "TearDown";
58 }
59 
60 /**
61  * @tc.name: SymlinkCoreMockTest_DoSymlink_001
62  * @tc.desc: Test function of SymlinkCore::DoSymlink interface for FALSE.
63  * @tc.size: MEDIUM
64  * @tc.type: FUNC
65  * @tc.level Level 1
66  */
67 HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_001, testing::ext::TestSize.Level1)
68 {
69     GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_001";
70 
71     string target;
72     string srcPath;
73 
74     EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(-1));
75 
76     auto res = SymlinkCore::DoSymlink(target, srcPath);
77     EXPECT_EQ(res.IsSuccess(), false);
78 
79     GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_001";
80 }
81 
82 /**
83  * @tc.name: SymlinkCoreMockTest_DoSymlink_002
84  * @tc.desc: Test function of SymlinkCore::DoSymlink interface for SUCCESS.
85  * @tc.size: MEDIUM
86  * @tc.type: FUNC
87  * @tc.level Level 1
88  */
89 HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_002, testing::ext::TestSize.Level1)
90 {
91     GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_002";
92 
93     string target;
94     string srcPath;
95 
96     EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(1));
97 
98     auto res = SymlinkCore::DoSymlink(target, srcPath);
99     EXPECT_EQ(res.IsSuccess(), true);
100 
101     GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_002";
102 }
103 
104 } // OHOS::FileManagement::ModuleFileIO::Test
105