• 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 "rename_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 RenameCoreMockTest : 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>  uvfs = nullptr;
33 };
34 
SetUpTestCase(void)35 void RenameCoreMockTest::SetUpTestCase(void)
36 {
37     uvfs = std::make_shared<UvfsMock>();
38     Uvfs::ins = uvfs;
39     GTEST_LOG_(INFO) << "SetUpTestCase";
40 }
41 
TearDownTestCase(void)42 void RenameCoreMockTest::TearDownTestCase(void)
43 {
44     Uvfs::ins = nullptr;
45     uvfs = nullptr;
46     GTEST_LOG_(INFO) << "TearDownTestCase";
47 }
48 
SetUp(void)49 void RenameCoreMockTest::SetUp(void)
50 {
51     GTEST_LOG_(INFO) << "SetUp";
52 }
53 
TearDown(void)54 void RenameCoreMockTest::TearDown(void)
55 {
56     GTEST_LOG_(INFO) << "TearDown";
57 }
58 
59 /**
60  * @tc.name: RenameCoreMockTest_DoRename_001
61  * @tc.desc: Test function of RenameCore::DoRename interface for FALSE.
62  * @tc.size: MEDIUM
63  * @tc.type: FUNC
64  * @tc.level Level 1
65  */
66 HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_001, testing::ext::TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_001";
69     string src;
70     string dest;
71 
72     EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1));
73 
74     auto res = RenameCore::DoRename(src, dest);
75     EXPECT_EQ(res.IsSuccess(), false);
76 
77     GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_001";
78 }
79 
80 /**
81  * @tc.name: RenameCoreMockTest_DoRename_002
82  * @tc.desc: Test function of RenameCore::DoRename interface for SUCCESS.
83  * @tc.size: MEDIUM
84  * @tc.type: FUNC
85  * @tc.level Level 1
86  */
87 HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_002, testing::ext::TestSize.Level1)
88 {
89     GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_002";
90     string src;
91     string dest;
92 
93     EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(1));
94 
95     auto res = RenameCore::DoRename(src, dest);
96     EXPECT_EQ(res.IsSuccess(), true);
97 
98     GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_002";
99 }
100 
101 
102 } // namespace OHOS::FileManagement::ModuleFileIO::Test