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 <fcntl.h>
17 #include <filesystem>
18 #include <gmock/gmock.h>
19 #include <gtest/gtest.h>
20
21 #include "copy_core.h"
22 #include "inotify_mock.h"
23 #include "mock_progress_listener.h"
24 #include "poll_mock.h"
25 #include "unistd_mock.h"
26 #include "uv_fs_mock.h"
27
28 namespace OHOS::FileManagement::ModuleFileIO::Test {
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace std;
32
33 class CopyCoreMockTest : public testing::Test {
34 public:
35 static void SetUpTestCase(void);
36 static void TearDownTestCase(void);
37 void SetUp();
38 void TearDown();
39 static inline shared_ptr<UvfsMock> uvMock = nullptr;
40
41 static const string testDir;
42 static const string srcDir;
43 static const string destDir;
44 static const string srcFile;
45 static const string destFile;
46
47 private:
48 // rwxr-xr-x
49 static constexpr mode_t permission0755 = 0755;
50 // rw-r--r--
51 static constexpr mode_t permission0644 = 0644;
52 };
53
54 const string CopyCoreMockTest::testDir = "/data/test/CopyCoreMockTest";
55 const string CopyCoreMockTest::srcDir = testDir + "/src";
56 const string CopyCoreMockTest::destDir = testDir + "/dest";
57 const string CopyCoreMockTest::srcFile = srcDir + "/src.txt";
58 const string CopyCoreMockTest::destFile = destDir + "/dest.txt";
59
SetUpTestCase(void)60 void CopyCoreMockTest::SetUpTestCase(void)
61 {
62 GTEST_LOG_(INFO) << "SetUpTestCase";
63 mkdir(testDir.c_str(), permission0755);
64 mkdir(srcDir.c_str(), permission0755);
65 mkdir(destDir.c_str(), permission0755);
66 int32_t fd = open(srcFile.c_str(), O_CREAT | O_RDWR, permission0644);
67 if (fd < 0) {
68 EXPECT_TRUE(false);
69 }
70 close(fd);
71 uvMock = std::make_shared<UvfsMock>();
72 Uvfs::ins = uvMock;
73 InotifyMock::EnableMock();
74 PollMock::EnableMock();
75 UnistdMock::EnableMock();
76 }
77
TearDownTestCase(void)78 void CopyCoreMockTest::TearDownTestCase(void)
79 {
80 GTEST_LOG_(INFO) << "TearDownTestCase";
81 int ret = remove(srcFile.c_str());
82 EXPECT_TRUE(ret == 0);
83 rmdir(srcDir.c_str());
84 rmdir(destDir.c_str());
85 rmdir(testDir.c_str());
86 Uvfs::ins = nullptr;
87 uvMock = nullptr;
88 InotifyMock::DisableMock();
89 PollMock::DisableMock();
90 UnistdMock::DisableMock();
91 }
92
SetUp(void)93 void CopyCoreMockTest::SetUp(void)
94 {
95 GTEST_LOG_(INFO) << "SetUp";
96 }
97
TearDown(void)98 void CopyCoreMockTest::TearDown(void)
99 {
100 CopyCore::callbackMap_.clear();
101 GTEST_LOG_(INFO) << "TearDown";
102 }
103
104 /**
105 * @tc.name: CopyCoreMockTest_CopyFile_001
106 * @tc.desc: Test function of CopyCore::CopyFile interface for FALSE.
107 * @tc.size: MEDIUM
108 * @tc.type: FUNC
109 * @tc.level Level 1
110 */
111 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_CopyFile_001, testing::ext::TestSize.Level1)
112 {
113 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_CopyFile_001";
114
115 auto infos = make_shared<FsFileInfos>();
116 infos->isFile = true;
117 infos->srcPath = CopyCoreMockTest::srcFile;
118 infos->destPath = CopyCoreMockTest::destFile;
119 auto unistdMock = UnistdMock::GetMock();
120
121 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1));
122 EXPECT_CALL(*uvMock, uv_fs_sendfile(_, _, _, _, _, _, _)).WillOnce(Return(-1));
123
124 auto res = CopyCore::CopyFile(srcFile, destFile, infos);
125 EXPECT_EQ(res, errno);
126
127 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_CopyFile_001";
128 }
129
130 /**
131 * @tc.name: CopyCoreMockTest_DoCopy_001
132 * @tc.desc: Test function of CopyCore::DoCopy interface for SUCCESS.
133 * @tc.size: MEDIUM
134 * @tc.type: FUNC
135 * @tc.level Level 1
136 */
137 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_DoCopy_001, testing::ext::TestSize.Level1)
138 {
139 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_DoCopy_001";
140
141 string srcUri = "file://" + srcFile;
142 string destUri = "file://" + destFile;
143 optional<CopyOptions> options;
144 auto unistdMock = UnistdMock::GetMock();
145
146 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1));
147 EXPECT_CALL(*uvMock, uv_fs_sendfile(_, _, _, _, _, _, _)).WillOnce(Return(0));
148
149 auto res = CopyCore::DoCopy(srcUri, destUri, options);
150 EXPECT_EQ(res.IsSuccess(), true);
151 EXPECT_TRUE(filesystem::exists(destFile));
152 int ret = remove(destFile.c_str());
153 EXPECT_TRUE(ret == 0);
154
155 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_DoCopy_001";
156 }
157
158 /**
159 * @tc.name: CopyCoreMockTest_CopySubDir_001
160 * @tc.desc: Test function of CopyCore::CopySubDir interface for success.
161 * @tc.size: MEDIUM
162 * @tc.type: FUNC
163 * @tc.level Level 1
164 */
165 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_CopySubDir_001, testing::ext::TestSize.Level1)
166 {
167 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_CopySubDir_001";
168
169 string subDir = srcDir + "/sub_dir";
170 mkdir(subDir.c_str(), permission0755);
171 string subFile = subDir + "/sub_file.txt";
172 int fd = open(subFile.c_str(), O_CREAT | O_RDWR, permission0644);
173 if (fd < 0) {
174 EXPECT_TRUE(false);
175 }
176 close(fd);
177
178 auto inotifyMock = InotifyMock::GetMock();
179 string destSubDir = destDir + "/sub_dir";
180 auto infos = make_shared<FsFileInfos>();
181 infos->notifyFd = 1;
182 auto unistdMock = UnistdMock::GetMock();
183
184 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1));
185 EXPECT_CALL(*inotifyMock, inotify_add_watch(testing::_, testing::_, testing::_)).WillOnce(testing::Return(0));
186 auto res = CopyCore::CopySubDir(subDir, destSubDir, infos);
187 EXPECT_EQ(res, UNKNOWN_ERR);
188
189 int ret = remove(subFile.c_str());
190 EXPECT_TRUE(ret == 0);
191 rmdir(subDir.c_str());
192 rmdir(destSubDir.c_str());
193 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_CopySubDir_001";
194 }
195
196 /**
197 * @tc.name: CopyCoreMockTest_CopySubDir_002
198 * @tc.desc: Test CopyCore::CopySubDir when iter == CopyCore::callbackMap_.end()
199 * @tc.size: MEDIUM
200 * @tc.type: FUNC
201 * @tc.level Level 1
202 */
203 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_CopySubDir_002, testing::ext::TestSize.Level1)
204 {
205 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_CopySubDir_002";
206
207 string subDir = srcDir + "/sub_dir";
208 mkdir(subDir.c_str(), permission0755);
209 string subFile = subDir + "/sub_file.txt";
210 int fd = open(subFile.c_str(), O_CREAT | O_RDWR, permission0644);
211 if (fd < 0) {
212 EXPECT_TRUE(false);
213 }
214 close(fd);
215
216 auto inotifyMock = InotifyMock::GetMock();
217 string destSubDir = destDir + "/sub_dir";
218 auto infos = make_shared<FsFileInfos>();
219 infos->notifyFd = 1;
220 auto unistdMock = UnistdMock::GetMock();
221 CopyCore::callbackMap_.clear();
222
223 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1));
224 EXPECT_CALL(*inotifyMock, inotify_add_watch(testing::_, testing::_, testing::_)).WillOnce(testing::Return(0));
225 auto res = CopyCore::CopySubDir(subDir, destSubDir, infos);
226 EXPECT_EQ(res, UNKNOWN_ERR);
227
228 int ret = remove(subFile.c_str());
229 EXPECT_TRUE(ret == 0);
230 rmdir(subDir.c_str());
231 rmdir(destSubDir.c_str());
232 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_CopySubDir_002";
233 }
234
235 /**
236 * @tc.name: CopyCoreMockTest_CopySubDir_003
237 * @tc.desc: Test CopyCore::CopySubDir when iter->second == nullptr
238 * @tc.size: MEDIUM
239 * @tc.type: FUNC
240 * @tc.level Level 1
241 */
242 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_CopySubDir_003, testing::ext::TestSize.Level1)
243 {
244 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_CopySubDir_003";
245
246 string subDir = srcDir + "/sub_dir";
247 mkdir(subDir.c_str(), permission0755);
248 string subFile = subDir + "/sub_file.txt";
249 int fd = open(subFile.c_str(), O_CREAT | O_RDWR, permission0644);
250 if (fd < 0) {
251 GTEST_LOG_(INFO) << "Open test file failed! ret: " << fd << ", errno: " << errno;
252 EXPECT_TRUE(false);
253 }
254 close(fd);
255
256 auto inotifyMock = InotifyMock::GetMock();
257 string destSubDir = destDir + "/sub_dir";
258 auto infos = make_shared<FsFileInfos>();
259 infos->notifyFd = 1;
260 auto unistdMock = UnistdMock::GetMock();
261 CopyCore::callbackMap_[*infos] = nullptr;
262
263 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).WillRepeatedly(testing::Return(1));
264 EXPECT_CALL(*inotifyMock, inotify_add_watch(testing::_, testing::_, testing::_)).WillOnce(testing::Return(0));
265 auto res = CopyCore::CopySubDir(subDir, destSubDir, infos);
266 EXPECT_EQ(res, UNKNOWN_ERR);
267
268 int ret = remove(subFile.c_str());
269 EXPECT_TRUE(ret == 0);
270 rmdir(subDir.c_str());
271 rmdir(destSubDir.c_str());
272 CopyCore::callbackMap_.clear();
273
274 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_CopySubDir_003";
275 }
276
277 /**
278 * @tc.name: CopyCoreMockTest_ReceiveComplete_001
279 * @tc.desc: Test CopyCore::ReceiveComplete in normal case
280 * @tc.size: MEDIUM
281 * @tc.type: FUNC
282 * @tc.level Level 1
283 */
284 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReceiveComplete_001, testing::ext::TestSize.Level1)
285 {
286 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReceiveComplete_001";
287
288 auto mockListener = std::make_shared<MockProgressListener>();
289 auto callback = std::make_shared<FsCallbackObject>(mockListener);
290 callback->maxProgressSize = 50;
291 auto entry = std::make_shared<FsUvEntry>(callback);
292 // 当前已经拷贝的字节数
293 entry->progressSize = 100;
294 // 需要拷贝的字节数
295 entry->totalSize = 200;
296
297 EXPECT_CALL(*mockListener, InvokeListener(entry->progressSize, entry->totalSize)).Times(1);
298 CopyCore::ReceiveComplete(entry);
299
300 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReceiveComplete_001";
301 }
302
303 /**
304 * @tc.name: CopyCoreMockTest_ReceiveComplete_002
305 * @tc.desc: Test CopyCore::ReceiveComplete when processedSize < entry->callback->maxProgressSize
306 * @tc.size: MEDIUM
307 * @tc.type: FUNC
308 * @tc.level Level 1
309 */
310 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReceiveComplete_002, testing::ext::TestSize.Level1)
311 {
312 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReceiveComplete_002";
313
314 auto mockListener = std::make_shared<MockProgressListener>();
315 auto callback = std::make_shared<FsCallbackObject>(mockListener);
316 callback->maxProgressSize = 100;
317 auto entry = std::make_shared<FsUvEntry>(callback);
318 entry->progressSize = 50; // Mock valid progressSize
319 entry->totalSize = 200; // Mock valid totalSize, and progressSize < totalSize
320
321 EXPECT_CALL(*mockListener, InvokeListener(testing::_, testing::_)).Times(0);
322 CopyCore::ReceiveComplete(entry);
323
324 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReceiveComplete_002";
325 }
326
327 /**
328 * @tc.name: CopyCoreMockTest_ReadNotifyEvent_001
329 * @tc.desc: Test function of CopyCoreMockTest::ReadNotifyEvent interface for SUCCESS when read valid event data.
330 * @tc.size: MEDIUM
331 * @tc.type: FUNC
332 * @tc.level Level 0
333 */
334 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReadNotifyEvent_001, testing::ext::TestSize.Level0)
335 {
336 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReadNotifyEvent_001";
337 // Prepare test condition
338 auto infos = make_shared<FsFileInfos>();
339 infos->run = true;
340 auto callback = CopyCore::RegisterListener(infos);
341 int32_t len = static_cast<int32_t>(sizeof(struct inotify_event));
342 // Set mock behaviors
343 auto unistdMock = UnistdMock::GetMock();
344 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).Times(1).WillOnce(testing::Return(len));
345 // Do testing
346 CopyCore::ReadNotifyEvent(infos);
347 // Verify results
348 EXPECT_NE(callback, nullptr);
349 testing::Mock::VerifyAndClearExpectations(unistdMock.get());
350 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReadNotifyEvent_001";
351 }
352
353 /**
354 * @tc.name: CopyCoreMockTest_ReadNotifyEvent_002
355 * @tc.desc: Test function of CopyCore::ReadNotifyEvent interface for FAILURE when read returns -1.
356 * @tc.size: MEDIUM
357 * @tc.type: FUNC
358 * @tc.level Level 1
359 */
360 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReadNotifyEvent_002, testing::ext::TestSize.Level1)
361 {
362 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReadNotifyEvent_002";
363 // Prepare test condition
364 auto infos = make_shared<FsFileInfos>();
365 infos->run = true;
366 auto callback = CopyCore::RegisterListener(infos);
367 // Set mock behaviors
368 auto unistdMock = UnistdMock::GetMock();
369 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_))
370 .Times(1)
371 .WillOnce(testing::SetErrnoAndReturn(EIO, -1));
372 // Do testing
373 CopyCore::ReadNotifyEvent(infos);
374 // Verify results
375 EXPECT_NE(callback, nullptr);
376 testing::Mock::VerifyAndClearExpectations(unistdMock.get());
377 EXPECT_EQ(errno, EIO);
378 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReadNotifyEvent_002";
379 }
380
381 /**
382 * @tc.name: CopyCoreMockTest_ReadNotifyEvent_003
383 * @tc.desc: Test function of CopyCore::ReadNotifyEvent interface for SUCCESS when read returns 0 (EOF).
384 * @tc.size: SMALL
385 * @tc.type: FUNC
386 * @tc.level Level 1
387 */
388 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReadNotifyEvent_003, testing::ext::TestSize.Level1)
389 {
390 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReadNotifyEvent_003";
391 // Prepare test condition
392 auto infos = make_shared<FsFileInfos>();
393 infos->run = true;
394 auto callback = CopyCore::RegisterListener(infos);
395 // Set mock behaviors
396 auto unistdMock = UnistdMock::GetMock();
397 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_))
398 .Times(1)
399 .WillOnce(testing::SetErrnoAndReturn(0, 0));
400 // Do testing
401 CopyCore::ReadNotifyEvent(infos);
402 // Verify results
403 EXPECT_NE(callback, nullptr);
404 testing::Mock::VerifyAndClearExpectations(unistdMock.get());
405 EXPECT_EQ(errno, 0);
406 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReadNotifyEvent_003";
407 }
408
409 /**
410 * @tc.name: CopyCoreMockTest_ReadNotifyEventLocked_001
411 * @tc.desc: Test ReadNotifyEventLocked when closed is false.
412 * @tc.size: SMALL
413 * @tc.type: FUNC
414 * @tc.level Level 0
415 */
416 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReadNotifyEventLocked_001, testing::ext::TestSize.Level0)
417 {
418 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReadNotifyEventLocked_001";
419 // Prepare test condition
420 auto infos = make_shared<FsFileInfos>();
421 auto callback = std::make_shared<FsCallbackObject>(nullptr);
422 callback->closed = false;
423 // Set mock behaviors
424 auto unistdMock = UnistdMock::GetMock();
425 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_)).Times(1).WillOnce(testing::Return(0));
426 EXPECT_CALL(*unistdMock, close(testing::_)).Times(0);
427 // Do testing
428 CopyCore::ReadNotifyEventLocked(infos, callback);
429 // Verify results
430 testing::Mock::VerifyAndClearExpectations(unistdMock.get());
431 EXPECT_FALSE(callback->reading);
432 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReadNotifyEventLocked_001";
433 }
434
435 /**
436 * @tc.name: CopyCoreMockTest_ReadNotifyEventLocked_002
437 * @tc.desc: Test ReadNotifyEventLocked when close after read.
438 * @tc.size: SMALL
439 * @tc.type: FUNC
440 * @tc.level Level 1
441 */
442 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_ReadNotifyEventLocked_002, testing::ext::TestSize.Level1)
443 {
444 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_ReadNotifyEventLocked_002";
445 // Prepare test condition
446 auto infos = make_shared<FsFileInfos>();
447 auto callback = std::make_shared<FsCallbackObject>(nullptr);
448 callback->closed = false;
449 // Set mock behaviors
450 auto unistdMock = UnistdMock::GetMock();
451 EXPECT_CALL(*unistdMock, read(testing::_, testing::_, testing::_))
452 .Times(1)
__anon923434810102(int fd, void *buf, size_t count) 453 .WillOnce([callback](int fd, void *buf, size_t count) {
454 errno = EIO;
455 callback->closed = true;
456 return 0;
457 });
458 EXPECT_CALL(*unistdMock, close(testing::_)).WillRepeatedly(testing::Return(0));
459 // Do testing
460 CopyCore::ReadNotifyEventLocked(infos, callback);
461 // Verify results
462 testing::Mock::VerifyAndClearExpectations(unistdMock.get());
463 EXPECT_FALSE(callback->closed);
464 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_ReadNotifyEventLocked_002";
465 }
466
467 /**
468 * @tc.name: CopyCoreMockTest_GetNotifyId_001
469 * @tc.desc: Test function of CopyCore::GetNotifyId interface for SUCCESS.
470 * @tc.size: SMALL
471 * @tc.type: FUNC
472 * @tc.level Level 0
473 */
474 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_GetNotifyId_001, testing::ext::TestSize.Level0)
475 {
476 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_GetNotifyId_001";
477 // Prepare test condition
478 auto infos = make_shared<FsFileInfos>();
479 infos->run = true;
480 infos->exceptionCode = ERRNO_NOERR;
481 infos->eventFd = 1;
482 infos->notifyFd = 1;
483
484 auto callback = CopyCore::RegisterListener(infos);
485 // Set mock behaviors
486 auto pollMock = PollMock::GetMock();
487 EXPECT_CALL(*pollMock, poll(testing::_, testing::_, testing::_))
488 .Times(1)
__anon923434810202(struct pollfd *fds, nfds_t n, int timeout) 489 .WillOnce([infos](struct pollfd *fds, nfds_t n, int timeout) {
490 fds[1].revents = POLLIN;
491 // Ensure the loop will exit
492 infos->run = false;
493 return 1;
494 });
495 // Do testing
496 CopyCore::GetNotifyEvent(infos);
497 // Verify results
498 testing::Mock::VerifyAndClearExpectations(pollMock.get());
499 EXPECT_NE(callback, nullptr);
500 EXPECT_FALSE(infos->run);
501 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_GetNotifyId_001";
502 }
503
504 /**
505 * @tc.name: CopyCoreMockTest_GetNotifyId_002
506 * @tc.desc: Test function of CopyCore::GetNotifyId interface fails when callback is nullptr.
507 * @tc.size: SMALL
508 * @tc.type: FUNC
509 * @tc.level Level 0
510 */
511 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_GetNotifyId_002, testing::ext::TestSize.Level0)
512 {
513 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_GetNotifyId_002";
514 // Prepare test condition
515 auto infos = make_shared<FsFileInfos>();
516 // Do testing
517 CopyCore::GetNotifyEvent(infos);
518 // Verify results
519 EXPECT_EQ(infos->exceptionCode, EINVAL);
520 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_GetNotifyId_002";
521 }
522
523 /**
524 * @tc.name: CopyCoreMockTest_CreateFileInfos_001
525 * @tc.desc: Test function of CopyCore::CreateFileInfos interface with listener and copySignal.
526 * @tc.size: MEDIUM
527 * @tc.type: FUNC
528 * @tc.level Level 1
529 */
530 HWTEST_F(CopyCoreMockTest, CopyCoreMockTest_CreateFileInfos_001, testing::ext::TestSize.Level1)
531 {
532 GTEST_LOG_(INFO) << "CopyCoreMockTest-begin CopyCoreMockTest_CreateFileInfos_001";
533
534 auto copySignal = std::make_shared<FsTaskSignal>();
535 copySignal->taskSignal_ = std::make_shared<TaskSignal>();
536 auto options = std::make_optional<CopyOptions>();
537 options->progressListener = std::make_shared<MockProgressListener>();
538 options->copySignal = copySignal.get();
539
540 auto [errCode, infos] = CopyCore::CreateFileInfos(srcFile, destFile, options);
541 EXPECT_EQ(errCode, ERRNO_NOERR);
542 EXPECT_NE(infos, nullptr);
543 if (infos) {
544 EXPECT_TRUE(infos->hasListener);
545 EXPECT_NE(infos->listener, nullptr);
546 EXPECT_NE(infos->taskSignal, nullptr);
547 }
548
549 GTEST_LOG_(INFO) << "CopyCoreMockTest-end CopyCoreMockTest_CreateFileInfos_001";
550 }
551
552 } // namespace OHOS::FileManagement::ModuleFileIO::Test
553