• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 #include <memory>
19 #include <unistd.h>
20 
21 #include "asset_callback_manager.h"
22 #include "asset_recv_callback_mock.h"
23 #include "asset_send_callback_mock.h"
24 #include "common_event_manager.h"
25 #include "connect_count/connect_count.h"
26 #include "connection_detector_mock.h"
27 #include "daemon.h"
28 #include "daemon_execute.h"
29 #include "daemon_mock.h"
30 #include "device_manager_agent_mock.h"
31 #include "device_manager_impl.h"
32 #include "dfs_error.h"
33 #include "dfsu_access_token_helper.h"
34 #include "i_file_trans_listener.h"
35 #include "ipc_skeleton.h"
36 #include "network/softbus/softbus_session_listener.h"
37 #include "sandbox_helper.h"
38 #include "softbus_handler_asset_mock.h"
39 #include "softbus_handler_mock.h"
40 #include "softbus_session_listener_mock.h"
41 #include "softbus_session_pool.h"
42 #include "system_ability_definition.h"
43 #include "system_ability_manager_client_mock.h"
44 
45 namespace {
46 bool g_checkCallerPermission = true;
47 bool g_checkCallerPermissionDatasync = true;
48 int g_getHapTokenInfo = 0;
49 std::string g_physicalPath;
50 int32_t g_getPhysicalPath = 0;
51 bool g_checkValidPath = false;
52 bool g_isFolder = false;
53 bool g_isFile = false;
54 pid_t g_getCallingUid = 100;
55 bool g_publish;
56 bool g_subscribeCommonEvent;
57 bool g_unSubscribeCommonEvent;
58 int32_t g_getLocalDeviceInfo;
59 } // namespace
60 
61 namespace {
62 const std::string FILE_MANAGER_AUTHORITY = "docs";
63 const std::string MEDIA_AUTHORITY = "media";
64 const int32_t E_PERMISSION_DENIED_NAPI = 201;
65 const int32_t E_INVAL_ARG_NAPI = 401;
66 const int32_t E_CONNECTION_FAILED = 13900045;
67 const int32_t E_UNMOUNT = 13600004;
68 } // namespace
69 
70 namespace OHOS::FileManagement {
CheckCallerPermission(const std::string & permissionName)71 bool DfsuAccessTokenHelper::CheckCallerPermission(const std::string &permissionName)
72 {
73     if (permissionName == PERM_DISTRIBUTED_DATASYNC) {
74         return g_checkCallerPermissionDatasync;
75     } else {
76         return g_checkCallerPermission;
77     }
78 }
79 } // namespace OHOS::FileManagement
80 
81 namespace OHOS::Security::AccessToken {
GetHapTokenInfo(AccessTokenID callerToken,HapTokenInfo & hapTokenInfoRes)82 int AccessTokenKit::GetHapTokenInfo(AccessTokenID callerToken, HapTokenInfo &hapTokenInfoRes)
83 {
84     int32_t userID = 100;
85     hapTokenInfoRes.bundleName = "com.example.app2backup";
86     hapTokenInfoRes.userID = userID;
87     return g_getHapTokenInfo;
88 }
89 } // namespace OHOS::Security::AccessToken
90 
91 namespace OHOS::AppFileService {
GetPhysicalPath(const std::string & fileUri,const std::string & userId,std::string & physicalPath)92 int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::string &userId, std::string &physicalPath)
93 {
94     physicalPath = g_physicalPath;
95     return g_getPhysicalPath;
96 }
97 
CheckValidPath(const std::string & filePath)98 bool SandboxHelper::CheckValidPath(const std::string &filePath)
99 {
100     return g_checkValidPath;
101 }
102 } // namespace OHOS::AppFileService
103 
104 namespace OHOS::EventFwk {
SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)105 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
106 {
107     return g_subscribeCommonEvent;
108 }
109 
UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)110 bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
111 {
112     return g_unSubscribeCommonEvent;
113 }
114 } // namespace OHOS::EventFwk
115 
116 namespace OHOS::DistributedHardware {
GetLocalDeviceInfo(const std::string & pkgName,DmDeviceInfo & info)117 int32_t DeviceManagerImpl::GetLocalDeviceInfo(const std::string &pkgName, DmDeviceInfo &info)
118 {
119     return g_getLocalDeviceInfo;
120 }
121 } // namespace OHOS::DistributedHardware
122 
123 namespace OHOS {
124 #ifdef CONFIG_IPC_SINGLE
125 using namespace IPC_SINGLE;
126 #endif
GetCallingUid()127 pid_t IPCSkeleton::GetCallingUid()
128 {
129     return g_getCallingUid;
130 }
131 
Publish(sptr<IRemoteObject> systemAbility)132 bool SystemAbility::Publish(sptr<IRemoteObject> systemAbility)
133 {
134     return g_publish;
135 }
136 
AddSystemAbilityListener(int32_t systemAbilityId)137 bool SystemAbility::AddSystemAbilityListener(int32_t systemAbilityId)
138 {
139     return true;
140 }
141 } // namespace OHOS
142 
143 namespace OHOS::Storage::DistributedFile {
144 namespace Utils {
IsFolder(const std::string & name)145 bool IsFolder(const std::string &name)
146 {
147     return g_isFolder;
148 }
149 
IsFile(const std::string & path)150 bool IsFile(const std::string &path)
151 {
152     return g_isFile;
153 }
154 } // namespace Utils
155 
156 namespace Test {
157 using namespace OHOS::FileManagement;
158 using namespace testing;
159 using namespace testing::ext;
160 using namespace std;
161 
162 class DaemonTest : public testing::Test {
163 public:
164     static void SetUpTestCase(void);
165     static void TearDownTestCase(void);
166     void SetUp();
167     void TearDown();
168     sptr<Daemon> daemon_;
169 
170 public:
171     static inline std::shared_ptr<ConnectionDetectorMock> connectionDetectorMock_ = nullptr;
172     static inline std::shared_ptr<DeviceManagerAgentMock> deviceManagerAgentMock_ = nullptr;
173     static inline std::shared_ptr<DfsSystemAbilityManagerClientMock> smc_ = nullptr;
174     static inline std::shared_ptr<SoftBusSessionListenerMock> softBusSessionListenerMock_ = nullptr;
175     static inline std::shared_ptr<SoftBusHandlerAssetMock> softBusHandlerAssetMock_ = nullptr;
176     static inline std::shared_ptr<SoftBusHandlerMock> softBusHandlerMock_ = nullptr;
177 };
178 
179 class FileTransListenerMock : public IRemoteStub<IFileTransListener> {
180 public:
181     MOCK_METHOD2(OnFileReceive, int32_t(uint64_t totalBytes, uint64_t processedBytes));
182     MOCK_METHOD2(OnFailed, int32_t(const std::string &sessionName, int32_t errorCode));
183     MOCK_METHOD1(OnFinished, int32_t(const std::string &sessionName));
184 };
185 
186 class FileDfsListenerMock : public IRemoteStub<IFileDfsListener> {
187 public:
188     MOCK_METHOD2(OnStatus, void(const std::string &networkId, int32_t status));
189 };
190 
SetUpTestCase(void)191 void DaemonTest::SetUpTestCase(void)
192 {
193     GTEST_LOG_(INFO) << "SetUpTestCase";
194     connectionDetectorMock_ = std::make_shared<ConnectionDetectorMock>();
195     IConnectionDetectorMock::iConnectionDetectorMock_ = connectionDetectorMock_;
196     deviceManagerAgentMock_ = std::make_shared<DeviceManagerAgentMock>();
197     IDeviceManagerAgentMock::iDeviceManagerAgentMock_ = deviceManagerAgentMock_;
198     smc_ = std::make_shared<DfsSystemAbilityManagerClientMock>();
199     DfsSystemAbilityManagerClient::smc = smc_;
200     softBusSessionListenerMock_ = std::make_shared<SoftBusSessionListenerMock>();
201     ISoftBusSessionListenerMock::iSoftBusSessionListenerMock_ = softBusSessionListenerMock_;
202     softBusHandlerAssetMock_ = std::make_shared<SoftBusHandlerAssetMock>();
203     ISoftBusHandlerAssetMock::iSoftBusHandlerAssetMock_ = softBusHandlerAssetMock_;
204     softBusHandlerMock_ = std::make_shared<SoftBusHandlerMock>();
205     ISoftBusHandlerMock::iSoftBusHandlerMock_ = softBusHandlerMock_;
206 
207     std::string path = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app";
208     if (!std::filesystem::exists(path)) {
209         std::filesystem::create_directory(path);
210         std::filesystem::create_directory(path + "/docs");
211     }
212     std::string path2 = "/mnt/hmdfs/100/account/device_view/local/files/Docs/Download/111";
213     if (std::filesystem::exists(path2)) {
214         std::filesystem::remove_all(path2);
215     }
216     std::ofstream file(path + "/docs/1.txt");
217     std::ofstream file1(path + "/docs/1@.txt");
218 }
219 
TearDownTestCase(void)220 void DaemonTest::TearDownTestCase(void)
221 {
222     GTEST_LOG_(INFO) << "TearDownTestCase";
223     IConnectionDetectorMock::iConnectionDetectorMock_ = nullptr;
224     connectionDetectorMock_ = nullptr;
225     IDeviceManagerAgentMock::iDeviceManagerAgentMock_ = nullptr;
226     deviceManagerAgentMock_ = nullptr;
227     DfsSystemAbilityManagerClient::smc = nullptr;
228     smc_ = nullptr;
229     ISoftBusSessionListenerMock::iSoftBusSessionListenerMock_ = nullptr;
230     softBusSessionListenerMock_ = nullptr;
231     ISoftBusHandlerAssetMock::iSoftBusHandlerAssetMock_ = nullptr;
232     softBusHandlerAssetMock_ = nullptr;
233     ISoftBusHandlerMock::iSoftBusHandlerMock_ = nullptr;
234     softBusHandlerMock_ = nullptr;
235 
236     std::string path = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app";
237     if (std::filesystem::exists(path)) {
238         std::filesystem::remove_all(path);
239     }
240 }
241 
SetUp(void)242 void DaemonTest::SetUp(void)
243 {
244     GTEST_LOG_(INFO) << "SetUp";
245     int32_t saID = FILEMANAGEMENT_DISTRIBUTED_FILE_DAEMON_SA_ID;
246     bool runOnCreate = true;
247     daemon_ = new (std::nothrow) Daemon(saID, runOnCreate);
248 }
249 
TearDown(void)250 void DaemonTest::TearDown(void)
251 {
252     GTEST_LOG_(INFO) << "TearDown";
253     daemon_ = nullptr;
254 }
255 
256 /**
257  * @tc.name: DaemonTest_PublishSA_001
258  * @tc.desc: verify PublishSA.
259  * @tc.type: FUNC
260  * @tc.require: I7TDJK
261  */
262 HWTEST_F(DaemonTest, DaemonTest_PublishSA_001, TestSize.Level1)
263 {
264     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 begin";
265 
266     daemon_->registerToService_ = true;
267     try {
268         daemon_->PublishSA();
269         EXPECT_TRUE(true);
270     } catch (...) {
271         EXPECT_TRUE(false);
272     }
273     daemon_->registerToService_ = false;
274     g_publish = true;
275     try {
276         daemon_->PublishSA();
277         EXPECT_EQ(daemon_->registerToService_, true);
278     } catch (...) {
279         EXPECT_TRUE(false);
280     }
281 }
282 
283 /**
284  * @tc.name: DaemonTest_PublishSA_002
285  * @tc.desc: verify PublishSA.
286  * @tc.type: FUNC
287  * @tc.require: I7TDJK
288  */
289 HWTEST_F(DaemonTest, DaemonTest_PublishSA_002, TestSize.Level1)
290 {
291     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 begin";
292     daemon_->registerToService_ = false;
293     g_publish = false;
294     try {
295         daemon_->PublishSA();
296         EXPECT_TRUE(false);
297     } catch (...) {
298         EXPECT_TRUE(true);
299     }
300     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 end";
301 }
302 
303 /**
304  * @tc.name: DaemonTest_RegisterOsAccount_001
305  * @tc.desc: verify RegisterOsAccount.
306  * @tc.type: FUNC
307  * @tc.require: I7TDJK
308  */
309 HWTEST_F(DaemonTest, DaemonTest_RegisterOsAccount_001, TestSize.Level1)
310 {
311     GTEST_LOG_(INFO) << "DaemonTest_RegisterOsAccount_001 begin";
312     g_subscribeCommonEvent = true;
313     try {
314         daemon_->RegisterOsAccount();
315         EXPECT_TRUE(true);
316     } catch (...) {
317         EXPECT_TRUE(false);
318     }
319 
320     g_subscribeCommonEvent = false;
321     try {
322         daemon_->RegisterOsAccount();
323         EXPECT_TRUE(true);
324     } catch (...) {
325         EXPECT_TRUE(false);
326     }
327     GTEST_LOG_(INFO) << "DaemonTest_RegisterOsAccount_001 end";
328 }
329 
330 /**
331  * @tc.name: DaemonTest_OnStart_001
332  * @tc.desc: verify OnStart.
333  * @tc.type: FUNC
334  * @tc.require: I7TDJK
335  */
336 HWTEST_F(DaemonTest, DaemonTest_OnStart_001, TestSize.Level1)
337 {
338     GTEST_LOG_(INFO) << "DaemonTest_OnStart_001 begin";
339     daemon_->state_ = ServiceRunningState::STATE_RUNNING;
340     try {
341         daemon_->OnStart();
342         EXPECT_TRUE(true);
343     } catch (...) {
344         EXPECT_TRUE(false);
345     }
346 
347     daemon_->state_ = ServiceRunningState::STATE_NOT_START;
348     try {
349         daemon_->OnStart();
350         EXPECT_TRUE(true);
351     } catch (...) {
352         EXPECT_TRUE(false);
353     }
354     GTEST_LOG_(INFO) << "DaemonTest_OnStart_001 end";
355 }
356 
357 /**
358  * @tc.name: DaemonTest_OnStop_001
359  * @tc.desc: verify OnStop.
360  * @tc.type: FUNC
361  * @tc.require: I7TDJK
362  */
363 HWTEST_F(DaemonTest, DaemonTest_OnStop_001, TestSize.Level1)
364 {
365     GTEST_LOG_(INFO) << "DaemonTest_OnStop_001 begin";
366     g_unSubscribeCommonEvent = false;
367     try {
368         daemon_->OnStop();
369         EXPECT_TRUE(true);
370     } catch (...) {
371         EXPECT_TRUE(false);
372     }
373 
374     g_unSubscribeCommonEvent = true;
375     try {
376         daemon_->OnStop();
377         EXPECT_TRUE(true);
378     } catch (...) {
379         EXPECT_TRUE(false);
380     }
381     GTEST_LOG_(INFO) << "DaemonTest_OnStop_001 end";
382 }
383 
384 /**
385  * @tc.name: DaemonTest_OnAddSystemAbility_001
386  * @tc.desc: verify OnAddSystemAbility.
387  * @tc.type: FUNC
388  * @tc.require: I7TDJK
389  */
390 HWTEST_F(DaemonTest, DaemonTest_OnAddSystemAbility_001, TestSize.Level1)
391 {
392     GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_001 begin";
393     g_subscribeCommonEvent = false;
394     try {
395         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
396         std::shared_ptr<OsAccountObserver> subScriber = daemon_->subScriber_;
397         EXPECT_TRUE(subScriber != nullptr);
398 
399         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
400         std::shared_ptr<OsAccountObserver> subScriber1 = daemon_->subScriber_;
401         EXPECT_TRUE(subScriber == subScriber1);
402     } catch (...) {
403         EXPECT_TRUE(false);
404     }
405 
406     try {
407         daemon_->OnAddSystemAbility(SOFTBUS_SERVER_SA_ID, "");
408         EXPECT_TRUE(true);
409     } catch (...) {
410         EXPECT_TRUE(false);
411     }
412     GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_001 end";
413 }
414 
415 /**
416  * @tc.name: DaemonTest_OnRemoveSystemAbility_001
417  * @tc.desc: verify OnRemoveSystemAbility.
418  * @tc.type: FUNC
419  * @tc.require: I7TDJK
420  */
421 HWTEST_F(DaemonTest, DaemonTest_OnRemoveSystemAbility_001, TestSize.Level1)
422 {
423     GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_001 begin";
424     try {
425         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
426         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
427         EXPECT_TRUE(daemon_->subScriber_ != nullptr);
428 
429         daemon_->subScriber_ = nullptr;
430         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
431         EXPECT_TRUE(daemon_->subScriber_ == nullptr);
432     } catch (...) {
433         EXPECT_TRUE(false);
434     }
435 
436     g_unSubscribeCommonEvent = true;
437     daemon_->RegisterOsAccount();
438     try {
439         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
440         EXPECT_TRUE(true);
441     } catch (...) {
442         EXPECT_TRUE(false);
443     }
444 
445     try {
446         daemon_->OnRemoveSystemAbility(SOFTBUS_SERVER_SA_ID, "");
447         EXPECT_TRUE(true);
448     } catch (...) {
449         EXPECT_TRUE(false);
450     }
451     GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_001 end";
452 }
453 
454 /**
455  * @tc.name: DaemonTest_OpenP2PConnection_001
456  * @tc.desc: verify OpenP2PConnection.
457  * @tc.type: FUNC
458  * @tc.require: I7TDJK
459  */
460 HWTEST_F(DaemonTest, DaemonTest_OpenP2PConnection_001, TestSize.Level1)
461 {
462     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnection_001 begin";
463     DistributedHardware::DmDeviceInfo deviceInfo;
464     ConnectCount::GetInstance()->RemoveAllConnect();
465     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
466     EXPECT_EQ(daemon_->OpenP2PConnection(deviceInfo), ERR_BAD_VALUE);
467 
468     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
469     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
470     EXPECT_EQ(daemon_->OpenP2PConnection(deviceInfo), E_OK);
471     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnection_001 end";
472 }
473 
474 /**
475  * @tc.name: DaemonTest_ConnectionCount_001
476  * @tc.desc: verify ConnectionCount.
477  * @tc.type: FUNC
478  * @tc.require: I7TDJK
479  */
480 HWTEST_F(DaemonTest, DaemonTest_ConnectionCount_001, TestSize.Level1)
481 {
482     GTEST_LOG_(INFO) << "DaemonTest_ConnectionCount_001 begin";
483     DistributedHardware::DmDeviceInfo deviceInfo;
484     ConnectCount::GetInstance()->RemoveAllConnect();
485     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
486     EXPECT_EQ(daemon_->ConnectionCount(deviceInfo), ERR_BAD_VALUE);
487 
488     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
489     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
490     EXPECT_EQ(daemon_->ConnectionCount(deviceInfo), E_OK);
491     GTEST_LOG_(INFO) << "DaemonTest_ConnectionCount_001 end";
492 }
493 
494 /**
495  * @tc.name: DaemonTest_CleanUp_001
496  * @tc.desc: verify CleanUp.
497  * @tc.type: FUNC
498  * @tc.require: I7TDJK
499  */
500 HWTEST_F(DaemonTest, DaemonTest_CleanUp_001, TestSize.Level1)
501 {
502     GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 begin";
503     DistributedHardware::DmDeviceInfo deviceInfo;
504     ConnectCount::GetInstance()->RemoveAllConnect();
505     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((E_OK)));
506     EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_OK);
507     sleep(1);
508 
509     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((ERR_BAD_VALUE)));
510     EXPECT_EQ(daemon_->CleanUp(deviceInfo), ERR_BAD_VALUE);
511     sleep(1);
512     GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 end";
513 }
514 
515 /**
516  * @tc.name: DaemonTest_ConnectionAndMount_001
517  * @tc.desc: verify ConnectionAndMount.
518  * @tc.type: FUNC
519  * @tc.require: I7TDJK
520  */
521 HWTEST_F(DaemonTest, DaemonTest_ConnectionAndMount_001, TestSize.Level1)
522 {
523     GTEST_LOG_(INFO) << "DaemonTest_ConnectionAndMount_001 begin";
524     DistributedHardware::DmDeviceInfo deviceInfo = {.networkId = "test"};
525     sptr<IFileDfsListener> remoteReverseObj = nullptr;
526     ConnectCount::GetInstance()->RemoveAllConnect();
527     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
528     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), ERR_BAD_VALUE);
529 
530     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
531     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
532     g_checkCallerPermission = false;
533     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), E_OK);
534 
535     g_checkCallerPermission = true;
536     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
537     EXPECT_CALL(*deviceManagerAgentMock_, MountDfsDocs(_, _)).WillOnce(Return(ERR_BAD_VALUE));
538     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
539     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), ERR_BAD_VALUE);
540 
541     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
542     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
543     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
544     EXPECT_CALL(*deviceManagerAgentMock_, MountDfsDocs(_, _)).WillOnce(Return(E_OK));
545     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), E_OK);
546     GTEST_LOG_(INFO) << "DaemonTest_ConnectionAndMount_001 end";
547 }
548 
549 /**
550  * @tc.name: DaemonTest_OpenP2PConnectionEx_001
551  * @tc.desc: verify OpenP2PConnectionEx.
552  * @tc.type: FUNC
553  * @tc.require: I7TDJK
554  */
555 HWTEST_F(DaemonTest, DaemonTest_OpenP2PConnectionEx_001, TestSize.Level1)
556 {
557     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnectionEx_001 begin";
558     g_checkCallerPermissionDatasync = false;
559     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", nullptr), E_PERMISSION_DENIED_NAPI);
560 
561     g_checkCallerPermissionDatasync = true;
562     daemon_->dfsListenerDeathRecipient_ = nullptr;
563     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", nullptr), E_INVAL_ARG_NAPI);
564 
565     auto listener = sptr<IFileDfsListener>(new FileDfsListenerMock());
566     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", listener), E_INVAL_ARG_NAPI);
567     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnectionEx_001 end";
568 }
569 
570 /**
571  * @tc.name: DaemonTest_CloseP2PConnectionEx_001
572  * @tc.desc: verify CloseP2PConnectionEx.
573  * @tc.type: FUNC
574  * @tc.require: I7TDJK
575  */
576 HWTEST_F(DaemonTest, DaemonTest_CloseP2PConnectionEx_001, TestSize.Level1)
577 {
578     GTEST_LOG_(INFO) << "DaemonTest_CloseP2PConnectionEx_001 begin";
579     g_checkCallerPermissionDatasync = false;
580     EXPECT_EQ(daemon_->CloseP2PConnectionEx(""), E_PERMISSION_DENIED_NAPI);
581 
582     g_checkCallerPermissionDatasync = true;
583     EXPECT_EQ(daemon_->CloseP2PConnectionEx(""), E_INVAL_ARG_NAPI);
584 
585     std::string networkId = "test";
586     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return(""));
587     EXPECT_EQ(daemon_->CloseP2PConnectionEx(networkId), E_CONNECTION_FAILED);
588 
589     g_checkCallerPermission = true;
590     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
591     EXPECT_CALL(*deviceManagerAgentMock_, UMountDfsDocs(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
592     EXPECT_EQ(daemon_->CloseP2PConnectionEx(networkId), E_UNMOUNT);
593     GTEST_LOG_(INFO) << "DaemonTest_CloseP2PConnectionEx_001 end";
594 }
595 
596 /**
597  * @tc.name: DaemonTest_RequestSendFile_001
598  * @tc.desc: verify RequestSendFile.
599  * @tc.type: FUNC
600  * @tc.require: I7TDJK
601  */
602 HWTEST_F(DaemonTest, DaemonTest_RequestSendFile_001, TestSize.Level1)
603 {
604     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_001 begin";
605     daemon_->eventHandler_ = nullptr;
606     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_EVENT_HANDLER);
607 
608     daemon_->StartEventHandler();
609     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), ERR_BAD_VALUE);
610     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_001 end";
611 }
612 
613 /**
614  * @tc.name: DaemonTest_PrepareSession_001
615  * @tc.desc: verify PrepareSession.
616  * @tc.type: FUNC
617  * @tc.require: I7TDJK
618  */
619 HWTEST_F(DaemonTest, DaemonTest_PrepareSession_001, TestSize.Level1)
620 {
621     GTEST_LOG_(INFO) << "DaemonTest_PrepareSession_001 begin";
622     HmdfsInfo hmdfsInfo;
623     EXPECT_EQ(daemon_->PrepareSession("", "", "", nullptr, hmdfsInfo), E_NULLPTR);
624 
625     sptr<IRemoteObject> listener = new (std::nothrow) FileTransListenerMock();
626     sptr<ISystemAbilityManagerMock> sysAbilityManager = new (std::nothrow) ISystemAbilityManagerMock();
627     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
628     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(nullptr));
629     EXPECT_EQ(daemon_->PrepareSession("", "", "", listener, hmdfsInfo), E_SA_LOAD_FAILED);
630 
631     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
632     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
633     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(daemon));
634     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
635     EXPECT_EQ(daemon_->PrepareSession("", "", "", listener, hmdfsInfo), E_SOFTBUS_SESSION_FAILED);
636 
637     g_getHapTokenInfo = Security::AccessToken::AccessTokenKitRet::RET_SUCCESS;
638     g_getPhysicalPath = E_OK;
639     g_isFile = false;
640     g_isFolder = true;
641     hmdfsInfo.dirExistFlag = true;
642     g_physicalPath = "tes@t/test";
643     std::string dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
644     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
645     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(daemon));
646     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
647     SoftBusSessionPool::SessionInfo sessionInfo;
648     while (true) {
649         auto ret = SoftBusSessionPool::GetInstance().GenerateSessionName(sessionInfo);
650         if (ret.empty()) {
651             break;
652         }
653     }
654     EXPECT_EQ(daemon_->PrepareSession("", dstUri, "", listener, hmdfsInfo), E_SOFTBUS_SESSION_FAILED);
655     SoftBusSessionPool::GetInstance().sessionMap_.clear();
656     GTEST_LOG_(INFO) << "DaemonTest_PrepareSession_001 end";
657 }
658 
659 /**
660  * @tc.name: DaemonTest_GetRealPath_001
661  * @tc.desc: verify GetRealPath.
662  * @tc.type: FUNC
663  * @tc.require: I7TDJK
664  */
665 HWTEST_F(DaemonTest, DaemonTest_GetRealPath_001, TestSize.Level1)
666 {
667     GTEST_LOG_(INFO) << "DaemonTest_GetRealPath_001 begin";
668     std::string physicalPath;
669     HmdfsInfo info;
670     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, nullptr), E_INVAL_ARG_NAPI);
671 
672     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
673     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
674     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_SOFTBUS_SESSION_FAILED);
675 
676     g_getHapTokenInfo = ERR_BAD_VALUE;
677     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
678     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_USER_ID);
679 
680     g_getHapTokenInfo = Security::AccessToken::AccessTokenKitRet::RET_SUCCESS;
681     g_getPhysicalPath = ERR_BAD_VALUE;
682     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
683     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_PHYSICAL_PATH_FAILED);
684 
685     g_getPhysicalPath = E_OK;
686     g_checkValidPath = false;
687     info.dirExistFlag = false;
688     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
689     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_PHYSICAL_PATH_FAILED);
690 
691     g_checkValidPath = true;
692     g_physicalPath = "test@test/test";
693     info.dirExistFlag = true;
694     std::string dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
695     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
696     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_OK);
697     GTEST_LOG_(INFO) << "DaemonTest_GetRealPath_001 end";
698 }
699 
700 /**
701  * @tc.name: DaemonTest_CheckCopyRule_001
702  * @tc.desc: verify CheckCopyRule.
703  * @tc.type: FUNC
704  * @tc.require: I7TDJK
705  */
706 HWTEST_F(DaemonTest, DaemonTest_CheckCopyRule_001, TestSize.Level1)
707 {
708     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_001 begin";
709     std::string physicalPath;
710     HapTokenInfo hapTokenInfo;
711     HmdfsInfo info;
712 
713     g_isFolder = false;
714     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
715 
716     g_isFolder = false;
717     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
718     info.dirExistFlag = false;
719     g_checkValidPath = false;
720     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
721 
722     g_isFolder = false;
723     physicalPath = "test";
724     info.dirExistFlag = false;
725     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, false, info), E_GET_PHYSICAL_PATH_FAILED);
726 
727     g_isFolder = true;
728     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
729     info.dirExistFlag = true;
730     g_checkValidPath = false;
731     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
732 
733     g_isFolder = true;
734     physicalPath = "te@st";
735     info.dirExistFlag = true;
736     std::string dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
737     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
738 
739     g_isFolder = false;
740     physicalPath = "tes@t/test";
741     info.dirExistFlag = false;
742     g_checkValidPath = true;
743     dstUri = "file://media/data/storage/el2/distributedfiles/images/1.png";
744     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
745     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_001 end";
746 }
747 
748 /**
749  * @tc.name: DaemonTest_CheckCopyRule_002
750  * @tc.desc: verify CheckCopyRule.
751  * @tc.type: FUNC
752  * @tc.require: I7TDJK
753  */
754 HWTEST_F(DaemonTest, DaemonTest_CheckCopyRule_002, TestSize.Level1)
755 {
756     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_002 begin";
757     std::string physicalPath;
758     HapTokenInfo hapTokenInfo;
759     HmdfsInfo info;
760 
761     g_isFolder = true;
762     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
763     info.dirExistFlag = true;
764     std::string dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
765     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
766 
767     g_isFolder = true;
768     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1@.txt";
769     info.dirExistFlag = true;
770     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
771     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
772 
773     g_isFolder = true;
774     physicalPath = "/mnt/hmdfs/100/account/device_view/local/files/Docs/Download/111";
775     info.dirExistFlag = true;
776     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
777     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
778 
779     g_isFolder = true;
780     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/docs/111";
781     info.dirExistFlag = true;
782     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
783     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_GET_PHYSICAL_PATH_FAILED);
784 
785     g_isFolder = true;
786     physicalPath = "te@st";
787     info.dirExistFlag = true;
788     hapTokenInfo.userID = 100;
789     g_checkValidPath = false;
790     dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
791     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info),
792               E_GET_PHYSICAL_PATH_FAILED); // 4 7 15 18
793 
794     g_isFolder = true;
795     physicalPath = "te@st";
796     info.dirExistFlag = true;
797     hapTokenInfo.userID = 100;
798     g_checkValidPath = true;
799     dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
800     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK); // 4 7 15 19
801     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_002 end";
802 }
803 
804 /**
805  * @tc.name: DaemonTest_GetRemoteCopyInfo_001
806  * @tc.desc: verify GetRemoteCopyInfo.
807  * @tc.type: FUNC
808  * @tc.require: I7TDJK
809  */
810 HWTEST_F(DaemonTest, DaemonTest_GetRemoteCopyInfo_001, TestSize.Level1)
811 {
812     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_001 begin";
813     EXPECT_CALL(*softBusSessionListenerMock_, GetRealPath(_)).WillOnce(Return(""));
814     bool isSrcFile = false;
815     bool srcIsDir = false;
816     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_SOFTBUS_SESSION_FAILED);
817 
818     EXPECT_CALL(*softBusSessionListenerMock_, GetRealPath(_)).WillOnce(Return("test"));
819     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_OK);
820     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_001 end";
821 }
822 
823 /**
824  * @tc.name: DaemonTest_GetRemoteSA_001
825  * @tc.desc: verify GetRemoteSA.
826  * @tc.type: FUNC
827  * @tc.require: I7TDJK
828  */
829 HWTEST_F(DaemonTest, DaemonTest_GetRemoteSA_001, TestSize.Level1)
830 {
831     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteSA_001 begin";
832     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(nullptr));
833     EXPECT_TRUE(daemon_->GetRemoteSA("") == nullptr);
834 
835     auto sysAbilityManager = sptr<ISystemAbilityManagerMock>(new ISystemAbilityManagerMock());
836     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
837     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(nullptr));
838     EXPECT_TRUE(daemon_->GetRemoteSA("") == nullptr);
839 
840     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
841     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
842     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(daemon));
843     EXPECT_FALSE(daemon_->GetRemoteSA("") == nullptr);
844     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteSA_001 end";
845 }
846 
847 /**
848  * @tc.name: DaemonTest_Copy_001
849  * @tc.desc: verify Copy.
850  * @tc.type: FUNC
851  * @tc.require: I7TDJK
852  */
853 HWTEST_F(DaemonTest, DaemonTest_Copy_001, TestSize.Level1)
854 {
855     GTEST_LOG_(INFO) << "DaemonTest_Copy_001 begin";
856     g_getLocalDeviceInfo = ERR_BAD_VALUE;
857     EXPECT_EQ(daemon_->Copy("", "", nullptr, ""), E_GET_DEVICE_ID);
858 
859     g_getLocalDeviceInfo = E_OK;
860     EXPECT_EQ(daemon_->Copy("", "", nullptr, ""), E_INVAL_ARG_NAPI);
861 
862     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
863     EXPECT_CALL(*daemon, RequestSendFile(_, _, _, _)).WillOnce(Return(ERR_BAD_VALUE));
864     EXPECT_EQ(daemon_->Copy("", "", daemon, ""), E_SA_LOAD_FAILED);
865 
866     EXPECT_CALL(*daemon, RequestSendFile(_, _, _, _)).WillOnce(Return(E_OK));
867     EXPECT_EQ(daemon_->Copy("", "", daemon, ""), E_OK);
868     GTEST_LOG_(INFO) << "DaemonTest_Copy_001 end";
869 }
870 
871 /**
872  * @tc.name: DaemonTest_CancelCopyTask_001
873  * @tc.desc: verify CancelCopyTask.
874  * @tc.type: FUNC
875  * @tc.require: I7TDJK
876  */
877 HWTEST_F(DaemonTest, DaemonTest_CancelCopyTask_001, TestSize.Level1)
878 {
879     GTEST_LOG_(INFO) << "DaemonTest_CancelCopyTask_001 begin";
880     SoftBusSessionPool::GetInstance().DeleteSessionInfo("test");
881     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_INVAL_ARG);
882 
883     SoftBusSessionPool::SessionInfo sessionInfo{.uid = 100};
884     g_getCallingUid = 101;
885     SoftBusSessionPool::GetInstance().AddSessionInfo("test", sessionInfo);
886     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_PERMISSION_DENIED);
887 
888     g_getCallingUid = 100;
889     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_OK);
890     SoftBusSessionPool::GetInstance().DeleteSessionInfo("test");
891     GTEST_LOG_(INFO) << "DaemonTest_CancelCopyTask_001 end";
892 }
893 
894 /**
895  * @tc.name: DaemonTest_PushAsset_001
896  * @tc.desc: verify PushAsset.
897  * @tc.type: FUNC
898  * @tc.require: I7TDJK
899  */
900 HWTEST_F(DaemonTest, DaemonTest_PushAsset_001, TestSize.Level1)
901 {
902     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_001 begin";
903     int32_t userId = 100;
904     sptr<AssetObj> assetObj(new (std::nothrow) AssetObj());
905     sptr<IAssetSendCallback> assetSendCallback = new (std::nothrow) IAssetSendCallbackMock();
906     EXPECT_EQ(daemon_->PushAsset(userId, nullptr, nullptr), E_NULLPTR);
907     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, nullptr), E_NULLPTR);
908     EXPECT_EQ(daemon_->PushAsset(userId, nullptr, assetSendCallback), E_NULLPTR);
909     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_NULLPTR);
910 
911     assetObj->srcBundleName_ = "test";
912     daemon_->eventHandler_ = nullptr;
913     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_EVENT_HANDLER);
914     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_001 end";
915 }
916 
917 /**
918  * @tc.name: DaemonTest_PushAsset_002
919  * @tc.desc: verify PushAsset.
920  * @tc.type: FUNC
921  * @tc.require: I7TDJK
922  */
923 HWTEST_F(DaemonTest, DaemonTest_PushAsset_002, TestSize.Level1)
924 {
925     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_002 begin";
926     daemon_->StartEventHandler();
927     int32_t userId = 100;
928     sptr<AssetObj> assetObj(new (std::nothrow) AssetObj());
929     assetObj->uris_.push_back("file://com.example.app/data/storage/el2/distributedfiles/docs/1.txt");
930     assetObj->srcBundleName_ = "com.example.app";
931     sptr<IAssetSendCallback> assetSendCallback = new (std::nothrow) IAssetSendCallbackMock();
932     g_getPhysicalPath = E_OK;
933     g_checkValidPath = true;
934     g_isFolder = false;
935     EXPECT_CALL(*softBusHandlerAssetMock_, AssetBind(_, _)).WillOnce(Return(E_OK));
936     EXPECT_CALL(*softBusHandlerAssetMock_, AssetSendFile(_, _, _)).WillOnce(Return(E_OK));
937     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_OK);
938     sleep(1);
939     AssetCallbackManager::GetInstance().RemoveSendCallback(assetObj->srcBundleName_);
940     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_002 end";
941 }
942 
943 /**
944  * @tc.name: DaemonTest_RegisterAssetCallback_001
945  * @tc.desc: verify RegisterAssetCallback.
946  * @tc.type: FUNC
947  * @tc.require: I7TDJK
948  */
949 HWTEST_F(DaemonTest, DaemonTest_RegisterAssetCallback_001, TestSize.Level1)
950 {
951     GTEST_LOG_(INFO) << "DaemonTest_RegisterAssetCallback_001 begin";
952     EXPECT_EQ(daemon_->RegisterAssetCallback(nullptr), E_NULLPTR);
953 
954     sptr<IAssetRecvCallback> assetRecvCallback = new (std::nothrow) IAssetRecvCallbackMock();
955     EXPECT_EQ(daemon_->RegisterAssetCallback(assetRecvCallback), E_OK);
956     AssetCallbackManager::GetInstance().RemoveRecvCallback(assetRecvCallback);
957     GTEST_LOG_(INFO) << "DaemonTest_RegisterAssetCallback_001 end";
958 }
959 
960 /**
961  * @tc.name: DaemonTest_UnRegisterAssetCallback_001
962  * @tc.desc: verify UnRegisterAssetCallback.
963  * @tc.type: FUNC
964  * @tc.require: I7TDJK
965  */
966 HWTEST_F(DaemonTest, DaemonTest_UnRegisterAssetCallback_001, TestSize.Level1)
967 {
968     GTEST_LOG_(INFO) << "DaemonTest_UnRegisterAssetCallback_001 begin";
969     EXPECT_EQ(daemon_->UnRegisterAssetCallback(nullptr), E_NULLPTR);
970 
971     sptr<IAssetRecvCallback> assetRecvCallback = new (std::nothrow) IAssetRecvCallbackMock();
972     EXPECT_EQ(daemon_->UnRegisterAssetCallback(assetRecvCallback), E_OK);
973     GTEST_LOG_(INFO) << "DaemonTest_UnRegisterAssetCallback_001 end";
974 }
975 
976 /**
977  * @tc.name: DaemonTest_StartEventHandler_001
978  * @tc.desc: verify StartEventHandler.
979  * @tc.type: FUNC
980  * @tc.require: I7TDJK
981  */
982 HWTEST_F(DaemonTest, DaemonTest_StartEventHandler_001, TestSize.Level1)
983 {
984     GTEST_LOG_(INFO) << "DaemonTest_StartEventHandler_001 begin";
985     daemon_->daemonExecute_ = std::make_shared<DaemonExecute>();
986     daemon_->StartEventHandler();
987     GTEST_LOG_(INFO) << "DaemonTest_StartEventHandler_001 end";
988 }
989 } // namespace Test
990 } // namespace OHOS::Storage::DistributedFile
991