• 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 "move_core.h"
17 
18 #include <filesystem>
19 #include <gtest/gtest.h>
20 
21 
22 namespace OHOS::FileManagement::ModuleFileIO::Test {
23 using namespace testing;
24 using namespace testing::ext;
25 using namespace std;
26 
27 class MoveCoreTest : public testing::Test {
28 public:
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase(void)35 void MoveCoreTest::SetUpTestCase(void)
36 {
37     GTEST_LOG_(INFO) << "SetUpTestCase";
38 }
39 
TearDownTestCase(void)40 void MoveCoreTest::TearDownTestCase(void)
41 {
42     GTEST_LOG_(INFO) << "TearDownTestCase";
43 }
44 
SetUp(void)45 void MoveCoreTest::SetUp(void)
46 {
47     GTEST_LOG_(INFO) << "SetUp";
48 }
49 
TearDown(void)50 void MoveCoreTest::TearDown(void)
51 {
52     GTEST_LOG_(INFO) << "TearDown";
53 }
54 
55 /**
56  * @tc.name: MoveCoreTest_DoMove_001
57  * @tc.desc: Test function of MoveCore::DoMove interface for ERROR.
58  * @tc.size: MEDIUM
59  * @tc.type: FUNC
60  * @tc.level Level 1
61  */
62 HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_001, testing::ext::TestSize.Level1)
63 {
64     GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_001";
65 
66     std::string src = "";
67     std::string dest = "";
68 
69     auto res = MoveCore::DoMove(src, dest);
70     EXPECT_EQ(res.IsSuccess(), false);
71 
72     GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_001";
73 }
74 
75 /**
76  * @tc.name: MoveCoreTest_DoMove_002
77  * @tc.desc: Test function of MoveCore::DoMove interface for ERROR.
78  * @tc.size: MEDIUM
79  * @tc.type: FUNC
80  * @tc.level Level 1
81  */
82 HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_002, testing::ext::TestSize.Level1)
83 {
84     GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_002";
85 
86     std::string src = "/src.txt";
87     std::string dest = "";
88 
89     auto res = MoveCore::DoMove(src, dest);
90     EXPECT_EQ(res.IsSuccess(), false);
91 
92     GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_002";
93 }
94 
95 /**
96  * @tc.name: MoveCoreTest_DoMove_003
97  * @tc.desc: Test function of MoveCore::DoMove interface for ERROR.
98  * @tc.size: MEDIUM
99  * @tc.type: FUNC
100  * @tc.level Level 1
101  */
102 HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_003, testing::ext::TestSize.Level1)
103 {
104     GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_003";
105 
106     std::string src = "/src.txt";
107     std::string dest = "/dest.txt";
108     int mode = 3;
109 
110     auto res = MoveCore::DoMove(src, dest, mode);
111     EXPECT_EQ(res.IsSuccess(), false);
112 
113     GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_003";
114 }
115 
116 /**
117  * @tc.name: MoveCoreTest_DoMove_004
118  * @tc.desc: Test function of MoveCore::DoMove interface for FALSE.
119  * @tc.size: MEDIUM
120  * @tc.type: FUNC
121  * @tc.level Level 1
122  */
123 HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_004, testing::ext::TestSize.Level1)
124 {
125     GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_004";
126 
127     std::string src = "dir";
128     std::string dest = "/dest.txt";
129     int mode = 3;
130 
131     std::filesystem::path dirpath = "dir";
132     ASSERT_TRUE(std::filesystem::create_directories(dirpath));
133 
134     auto res = MoveCore::DoMove(src, dest, mode);
135     EXPECT_EQ(res.IsSuccess(), false);
136 
137     std::filesystem::remove(dirpath);
138     GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_004";
139 }
140 
141 /**
142  * @tc.name: MoveCoreTest_DoMove_005
143  * @tc.desc: Test function of MoveCore::DoMove interface for FALSE.
144  * @tc.size: MEDIUM
145  * @tc.type: FUNC
146  * @tc.level Level 1
147  */
148 HWTEST_F(MoveCoreTest, MoveCoreTest_DoMove_005, testing::ext::TestSize.Level1)
149 {
150     GTEST_LOG_(INFO) << "MoveCoreTest-begin MoveCoreTest_DoMove_005";
151 
152     std::string src = "/src.txt";
153     std::string dest = "dir";
154     int mode = 3;
155 
156     std::filesystem::path dirpath = "dir";
157     ASSERT_TRUE(std::filesystem::create_directories(dirpath));
158 
159     auto res = MoveCore::DoMove(src, dest, mode);
160     EXPECT_EQ(res.IsSuccess(), false);
161 
162     std::filesystem::remove(dirpath);
163     GTEST_LOG_(INFO) << "MoveCoreTest-end MoveCoreTest_DoMove_005";
164 }
165 
166 } // namespace OHOS::FileManagement::ModuleFileIO::Test