• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-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 <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 "channel_manager_mock.h"
25 #include "common_event_manager.h"
26 #include "connect_count/connect_count.h"
27 #include "connection_detector_mock.h"
28 #include "copy/file_size_utils.h"
29 #include "daemon.h"
30 #include "daemon_execute.h"
31 #include "daemon_mock.h"
32 #include "device/device_profile_adapter.h"
33 #include "device_manager_agent_mock.h"
34 #include "device_manager_impl.h"
35 #include "device_manager_impl_mock.h"
36 #include "device_profile_adapter.h"
37 #include "dfs_error.h"
38 #include "dfsu_access_token_helper.h"
39 #include "i_file_trans_listener.h"
40 #include "ipc_skeleton.h"
41 #include "network/devsl_dispatcher.h"
42 #include "network/softbus/softbus_session_listener.h"
43 #include "sandbox_helper.h"
44 #include "softbus_handler_asset_mock.h"
45 #include "softbus_handler_mock.h"
46 #include "softbus_session_listener_mock.h"
47 #include "softbus_session_pool.h"
48 #include "system_ability_definition.h"
49 #include "system_ability_manager_client_mock.h"
50 
51 namespace {
52 bool g_checkCallerPermission = true;
53 bool g_checkCallerPermissionDatasync = true;
54 int g_getHapTokenInfo = 0;
55 std::string g_physicalPath;
56 int32_t g_getPhysicalPath = 0;
57 bool g_checkValidPath = false;
58 bool g_isFolder = false;
59 bool g_isFile = false;
60 pid_t g_getCallingUid = 100;
61 std::string g_getCallingNetworkId;
62 bool g_publish;
63 bool g_subscribeCommonEvent;
64 bool g_unSubscribeCommonEvent;
65 int32_t g_getDfsVersionFromNetworkId = 0;
66 OHOS::Storage::DistributedFile::DfsVersion g_dfsVersion;
67 } // namespace
68 
69 namespace {
70 const std::string FILE_MANAGER_AUTHORITY = "docs";
71 const std::string MEDIA_AUTHORITY = "media";
72 const int32_t E_PERMISSION_DENIED_NAPI = 201;
73 const int32_t E_INVAL_ARG_NAPI = 401;
74 const int32_t E_CONNECTION_FAILED = 13900045;
75 const int32_t E_UNMOUNT = 13600004;
76 const std::string NETWORKID_ONE = "testNetWork1";
77 const std::string NETWORKID_TWO = "testNetWork2";
78 } // namespace
79 
80 namespace OHOS::Storage::DistributedFile {
GetDfsVersionFromNetworkId(const std::string & networkId,DfsVersion & dfsVersion,VersionPackageName packageName)81 int32_t DeviceProfileAdapter::GetDfsVersionFromNetworkId(const std::string &networkId,
82                                                          DfsVersion &dfsVersion,
83                                                          VersionPackageName packageName)
84 {
85     if (networkId == NETWORKID_ONE) {
86         dfsVersion.majorVersionNum = 0;
87         return OHOS::FileManagement::E_OK;
88     }
89 
90     if (networkId == NETWORKID_TWO) {
91         dfsVersion.majorVersionNum = 1;
92         return OHOS::FileManagement::E_OK;
93     }
94     dfsVersion = g_dfsVersion;
95     return g_getDfsVersionFromNetworkId;
96 }
97 } // namespace OHOS::Storage::DistributedFile
98 
99 namespace OHOS::FileManagement {
CheckCallerPermission(const std::string & permissionName)100 bool DfsuAccessTokenHelper::CheckCallerPermission(const std::string &permissionName)
101 {
102     if (permissionName == PERM_DISTRIBUTED_DATASYNC) {
103         return g_checkCallerPermissionDatasync;
104     } else {
105         return g_checkCallerPermission;
106     }
107 }
108 } // namespace OHOS::FileManagement
109 
110 namespace OHOS::Security::AccessToken {
GetHapTokenInfo(AccessTokenID callerToken,HapTokenInfo & hapTokenInfoRes)111 int AccessTokenKit::GetHapTokenInfo(AccessTokenID callerToken, HapTokenInfo &hapTokenInfoRes)
112 {
113     int32_t userID = 100;
114     hapTokenInfoRes.bundleName = "com.example.app2backup";
115     hapTokenInfoRes.userID = userID;
116     return g_getHapTokenInfo;
117 }
118 } // namespace OHOS::Security::AccessToken
119 
120 namespace OHOS::AppFileService {
GetPhysicalPath(const std::string & fileUri,const std::string & userId,std::string & physicalPath)121 int32_t SandboxHelper::GetPhysicalPath(const std::string &fileUri, const std::string &userId, std::string &physicalPath)
122 {
123     physicalPath = g_physicalPath;
124     return g_getPhysicalPath;
125 }
126 
CheckValidPath(const std::string & filePath)127 bool SandboxHelper::CheckValidPath(const std::string &filePath)
128 {
129     return g_checkValidPath;
130 }
131 } // namespace OHOS::AppFileService
132 
133 namespace OHOS::EventFwk {
SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)134 bool CommonEventManager::SubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
135 {
136     return g_subscribeCommonEvent;
137 }
138 
UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> & subscriber)139 bool CommonEventManager::UnSubscribeCommonEvent(const std::shared_ptr<CommonEventSubscriber> &subscriber)
140 {
141     return g_unSubscribeCommonEvent;
142 }
143 } // namespace OHOS::EventFwk
144 
145 namespace OHOS {
146 namespace DistributedHardware {
GetInstance()147 DeviceManager &DeviceManager::GetInstance()
148 {
149     GTEST_LOG_(INFO) << "GetInstance start";
150     return DeviceManagerImpl::GetInstance();
151 }
152 } // namespace DistributedHardware
153 } // namespace OHOS
154 
155 OHOS::DistributedHardware::DmDeviceInfo deviceInfo = {
156     .deviceId = "testdevid",
157     .deviceName = "testdevname",
158     .deviceTypeId = 1,
159     .networkId = "testNetWork1",
160     .authForm = OHOS::DistributedHardware::DmAuthForm::IDENTICAL_ACCOUNT,
161     .extraData = "{\"OS_TYPE\":10}",
162 };
163 
164 namespace OHOS {
165 #ifdef CONFIG_IPC_SINGLE
166 using namespace IPC_SINGLE;
167 #endif
GetCallingUid()168 pid_t IPCSkeleton::GetCallingUid()
169 {
170     return g_getCallingUid;
171 }
172 
GetCallingDeviceID()173 std::string IPCSkeleton::GetCallingDeviceID()
174 {
175     return g_getCallingNetworkId;
176 }
177 
Publish(sptr<IRemoteObject> systemAbility)178 bool SystemAbility::Publish(sptr<IRemoteObject> systemAbility)
179 {
180     return g_publish;
181 }
182 
AddSystemAbilityListener(int32_t systemAbilityId)183 bool SystemAbility::AddSystemAbilityListener(int32_t systemAbilityId)
184 {
185     return true;
186 }
187 } // namespace OHOS
188 
189 namespace OHOS::Storage::DistributedFile {
190 namespace Utils {
IsFolder(const std::string & name)191 bool IsFolder(const std::string &name)
192 {
193     return g_isFolder;
194 }
195 
IsFile(const std::string & path)196 bool IsFile(const std::string &path)
197 {
198     return g_isFile;
199 }
200 } // namespace Utils
201 
202 namespace Test {
203 using namespace OHOS::FileManagement;
204 using namespace testing;
205 using namespace testing::ext;
206 using namespace std;
207 using namespace OHOS::Storage::DistributedFile;
208 
209 class DaemonTest : public testing::Test {
210 public:
211     static void SetUpTestCase(void);
212     static void TearDownTestCase(void);
213     void SetUp();
214     void TearDown();
215     sptr<Daemon> daemon_;
216 
217 public:
218     static inline std::shared_ptr<ConnectionDetectorMock> connectionDetectorMock_ = nullptr;
219     static inline std::shared_ptr<DeviceManagerAgentMock> deviceManagerAgentMock_ = nullptr;
220     static inline std::shared_ptr<DfsSystemAbilityManagerClientMock> smc_ = nullptr;
221     static inline std::shared_ptr<SoftBusSessionListenerMock> softBusSessionListenerMock_ = nullptr;
222     static inline std::shared_ptr<SoftBusHandlerAssetMock> softBusHandlerAssetMock_ = nullptr;
223     static inline std::shared_ptr<SoftBusHandlerMock> softBusHandlerMock_ = nullptr;
224     static inline std::shared_ptr<DeviceManagerImplMock> deviceManagerImplMock_ = nullptr;
225     static inline std::shared_ptr<ChannelManagerMock> channelManagerMock_ = nullptr;
226 };
227 
228 class FileTransListenerMock : public IRemoteStub<IFileTransListener> {
229 public:
230     MOCK_METHOD2(OnFileReceive, int32_t(uint64_t totalBytes, uint64_t processedBytes));
231     MOCK_METHOD2(OnFailed, int32_t(const std::string &sessionName, int32_t errorCode));
232     MOCK_METHOD1(OnFinished, int32_t(const std::string &sessionName));
233 };
234 
235 class FileDfsListenerMock : public IRemoteStub<IFileDfsListener> {
236 public:
237     MOCK_METHOD2(OnStatus, void(const std::string &networkId, int32_t status));
238 };
239 
SetUpTestCase(void)240 void DaemonTest::SetUpTestCase(void)
241 {
242     GTEST_LOG_(INFO) << "SetUpTestCase";
243     connectionDetectorMock_ = std::make_shared<ConnectionDetectorMock>();
244     IConnectionDetectorMock::iConnectionDetectorMock_ = connectionDetectorMock_;
245     deviceManagerAgentMock_ = std::make_shared<DeviceManagerAgentMock>();
246     IDeviceManagerAgentMock::iDeviceManagerAgentMock_ = deviceManagerAgentMock_;
247     smc_ = std::make_shared<DfsSystemAbilityManagerClientMock>();
248     DfsSystemAbilityManagerClient::smc = smc_;
249     softBusSessionListenerMock_ = std::make_shared<SoftBusSessionListenerMock>();
250     ISoftBusSessionListenerMock::iSoftBusSessionListenerMock_ = softBusSessionListenerMock_;
251     softBusHandlerAssetMock_ = std::make_shared<SoftBusHandlerAssetMock>();
252     ISoftBusHandlerAssetMock::iSoftBusHandlerAssetMock_ = softBusHandlerAssetMock_;
253     softBusHandlerMock_ = std::make_shared<SoftBusHandlerMock>();
254     ISoftBusHandlerMock::iSoftBusHandlerMock_ = softBusHandlerMock_;
255     deviceManagerImplMock_ = std::make_shared<DeviceManagerImplMock>();
256     DfsDeviceManagerImpl::dfsDeviceManagerImpl = deviceManagerImplMock_;
257     channelManagerMock_ = std::make_shared<ChannelManagerMock>();
258     IChannelManagerMock::iChannelManagerMock = channelManagerMock_;
259 
260     std::string path = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app";
261     if (!std::filesystem::exists(path)) {
262         std::filesystem::create_directory(path);
263         std::filesystem::create_directory(path + "/docs");
264     }
265     std::string path2 = "/mnt/hmdfs/100/account/device_view/local/files/Docs/Download/111";
266     if (std::filesystem::exists(path2)) {
267         std::filesystem::remove_all(path2);
268     }
269     std::ofstream file(path + "/docs/1.txt");
270     std::ofstream file1(path + "/docs/1@.txt");
271     g_getDfsVersionFromNetworkId = 0;
272     g_dfsVersion = {0, 0, 0};
273 }
274 
TearDownTestCase(void)275 void DaemonTest::TearDownTestCase(void)
276 {
277     GTEST_LOG_(INFO) << "TearDownTestCase";
278     IConnectionDetectorMock::iConnectionDetectorMock_ = nullptr;
279     connectionDetectorMock_ = nullptr;
280     IDeviceManagerAgentMock::iDeviceManagerAgentMock_ = nullptr;
281     deviceManagerAgentMock_ = nullptr;
282     DfsSystemAbilityManagerClient::smc = nullptr;
283     smc_ = nullptr;
284     ISoftBusSessionListenerMock::iSoftBusSessionListenerMock_ = nullptr;
285     softBusSessionListenerMock_ = nullptr;
286     ISoftBusHandlerAssetMock::iSoftBusHandlerAssetMock_ = nullptr;
287     softBusHandlerAssetMock_ = nullptr;
288     ISoftBusHandlerMock::iSoftBusHandlerMock_ = nullptr;
289     softBusHandlerMock_ = nullptr;
290     deviceManagerImplMock_ = nullptr;
291     DfsDeviceManagerImpl::dfsDeviceManagerImpl = nullptr;
292     channelManagerMock_ = nullptr;
293     IChannelManagerMock::iChannelManagerMock = nullptr;
294     deviceManagerImplMock_ = nullptr;
295     DfsDeviceManagerImpl::dfsDeviceManagerImpl = nullptr;
296 
297     std::string path = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app";
298     if (std::filesystem::exists(path)) {
299         std::filesystem::remove_all(path);
300     }
301 }
302 
SetUp(void)303 void DaemonTest::SetUp(void)
304 {
305     GTEST_LOG_(INFO) << "SetUp";
306     int32_t saID = FILEMANAGEMENT_DISTRIBUTED_FILE_DAEMON_SA_ID;
307     bool runOnCreate = true;
308     daemon_ = new (std::nothrow) Daemon(saID, runOnCreate);
309     ASSERT_TRUE(daemon_ != nullptr) << "daemon_ assert failed!";
310 }
311 
TearDown(void)312 void DaemonTest::TearDown(void)
313 {
314     GTEST_LOG_(INFO) << "TearDown";
315     daemon_ = nullptr;
316 }
317 
318 /**
319  * @tc.name: DaemonTest_PublishSA_001
320  * @tc.desc: verify PublishSA.
321  * @tc.type: FUNC
322  * @tc.require: I7TDJK
323  */
324 HWTEST_F(DaemonTest, DaemonTest_PublishSA_001, TestSize.Level1)
325 {
326     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 begin";
327     ASSERT_NE(daemon_, nullptr);
328     daemon_->registerToService_ = true;
329     try {
330         daemon_->PublishSA();
331         EXPECT_TRUE(true);
332     } catch (...) {
333         EXPECT_TRUE(false);
334     }
335     daemon_->registerToService_ = false;
336     g_publish = true;
337     try {
338         daemon_->PublishSA();
339         EXPECT_EQ(daemon_->registerToService_, true);
340     } catch (...) {
341         EXPECT_TRUE(false);
342     }
343 }
344 
345 /**
346  * @tc.name: DaemonTest_PublishSA_002
347  * @tc.desc: verify PublishSA.
348  * @tc.type: FUNC
349  * @tc.require: I7TDJK
350  */
351 HWTEST_F(DaemonTest, DaemonTest_PublishSA_002, TestSize.Level1)
352 {
353     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 begin";
354     ASSERT_NE(daemon_, nullptr);
355     daemon_->registerToService_ = false;
356     g_publish = false;
357     try {
358         daemon_->PublishSA();
359         EXPECT_TRUE(false);
360     } catch (...) {
361         EXPECT_TRUE(true);
362     }
363     GTEST_LOG_(INFO) << "DaemonTest_PublishSA_001 end";
364 }
365 
366 /**
367  * @tc.name: DaemonTest_RegisterOsAccount_001
368  * @tc.desc: verify RegisterOsAccount.
369  * @tc.type: FUNC
370  * @tc.require: I7TDJK
371  */
372 HWTEST_F(DaemonTest, DaemonTest_RegisterOsAccount_001, TestSize.Level1)
373 {
374     GTEST_LOG_(INFO) << "DaemonTest_RegisterOsAccount_001 begin";
375     ASSERT_NE(daemon_, nullptr);
376     g_subscribeCommonEvent = true;
377     try {
378         daemon_->RegisterOsAccount();
379         EXPECT_TRUE(true);
380     } catch (...) {
381         EXPECT_TRUE(false);
382     }
383 
384     g_subscribeCommonEvent = false;
385     try {
386         daemon_->RegisterOsAccount();
387         EXPECT_TRUE(true);
388     } catch (...) {
389         EXPECT_TRUE(false);
390     }
391     GTEST_LOG_(INFO) << "DaemonTest_RegisterOsAccount_001 end";
392 }
393 
394 /**
395  * @tc.name: DaemonTest_OnStart_001
396  * @tc.desc: verify OnStart.
397  * @tc.type: FUNC
398  * @tc.require: I7TDJK
399  */
400 HWTEST_F(DaemonTest, DaemonTest_OnStart_001, TestSize.Level1)
401 {
402     GTEST_LOG_(INFO) << "DaemonTest_OnStart_001 begin";
403     ASSERT_NE(daemon_, nullptr);
404     daemon_->state_ = ServiceRunningState::STATE_RUNNING;
405     try {
406         daemon_->OnStart();
407         EXPECT_TRUE(true);
408     } catch (...) {
409         EXPECT_TRUE(false);
410     }
411 
412     daemon_->state_ = ServiceRunningState::STATE_NOT_START;
413     try {
414         daemon_->OnStart();
415         EXPECT_TRUE(true);
416     } catch (...) {
417         EXPECT_TRUE(false);
418     }
419     GTEST_LOG_(INFO) << "DaemonTest_OnStart_001 end";
420 }
421 
422 /**
423  * @tc.name: DaemonTest_OnStop_001
424  * @tc.desc: verify OnStop.
425  * @tc.type: FUNC
426  * @tc.require: I7TDJK
427  */
428 HWTEST_F(DaemonTest, DaemonTest_OnStop_001, TestSize.Level1)
429 {
430     GTEST_LOG_(INFO) << "DaemonTest_OnStop_001 begin";
431     ASSERT_NE(daemon_, nullptr);
432     g_unSubscribeCommonEvent = false;
433     try {
434         daemon_->OnStop();
435         EXPECT_TRUE(true);
436     } catch (...) {
437         EXPECT_TRUE(false);
438     }
439 
440     g_unSubscribeCommonEvent = true;
441     try {
442         daemon_->OnStop();
443         EXPECT_TRUE(true);
444     } catch (...) {
445         EXPECT_TRUE(false);
446     }
447     GTEST_LOG_(INFO) << "DaemonTest_OnStop_001 end";
448 }
449 
450 /**
451  * @tc.name: DaemonTest_OnAddSystemAbility_001
452  * @tc.desc: verify OnAddSystemAbility.
453  * @tc.type: FUNC
454  * @tc.require: I7TDJK
455  */
456 HWTEST_F(DaemonTest, DaemonTest_OnAddSystemAbility_001, TestSize.Level1)
457 {
458     GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_001 begin";
459     ASSERT_NE(daemon_, nullptr);
460     g_subscribeCommonEvent = false;
461     try {
462         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
463         std::shared_ptr<OsAccountObserver> subScriber = daemon_->subScriber_;
464         EXPECT_TRUE(subScriber != nullptr);
465 
466         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
467         std::shared_ptr<OsAccountObserver> subScriber1 = daemon_->subScriber_;
468         EXPECT_TRUE(subScriber == subScriber1);
469     } catch (...) {
470         EXPECT_TRUE(false);
471     }
472 
473     try {
474         daemon_->OnAddSystemAbility(SOFTBUS_SERVER_SA_ID, "");
475         EXPECT_TRUE(true);
476     } catch (...) {
477         EXPECT_TRUE(false);
478     }
479     GTEST_LOG_(INFO) << "DaemonTest_OnAddSystemAbility_001 end";
480 }
481 
482 /**
483  * @tc.name: DaemonTest_OnRemoveSystemAbility_001
484  * @tc.desc: verify OnRemoveSystemAbility.
485  * @tc.type: FUNC
486  * @tc.require: I7TDJK
487  */
488 HWTEST_F(DaemonTest, DaemonTest_OnRemoveSystemAbility_001, TestSize.Level1)
489 {
490     GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_001 begin";
491     ASSERT_NE(daemon_, nullptr);
492     try {
493         daemon_->OnAddSystemAbility(COMMON_EVENT_SERVICE_ID, "");
494         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
495         EXPECT_TRUE(daemon_->subScriber_ != nullptr);
496 
497         daemon_->subScriber_ = nullptr;
498         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
499         EXPECT_TRUE(daemon_->subScriber_ == nullptr);
500     } catch (...) {
501         EXPECT_TRUE(false);
502     }
503 
504     g_unSubscribeCommonEvent = true;
505     daemon_->RegisterOsAccount();
506     try {
507         daemon_->OnRemoveSystemAbility(COMMON_EVENT_SERVICE_ID, "");
508         EXPECT_TRUE(true);
509     } catch (...) {
510         EXPECT_TRUE(false);
511     }
512 
513     try {
514         daemon_->OnRemoveSystemAbility(SOFTBUS_SERVER_SA_ID, "");
515         EXPECT_TRUE(true);
516     } catch (...) {
517         EXPECT_TRUE(false);
518     }
519     GTEST_LOG_(INFO) << "DaemonTest_OnRemoveSystemAbility_001 end";
520 }
521 
522 /**
523  * @tc.name: DaemonTest_OpenP2PConnection_001
524  * @tc.desc: verify OpenP2PConnection.
525  * @tc.type: FUNC
526  * @tc.require: I7TDJK
527  */
528 HWTEST_F(DaemonTest, DaemonTest_OpenP2PConnection_001, TestSize.Level1)
529 {
530     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnection_001 begin";
531     ASSERT_NE(daemon_, nullptr);
532     DistributedHardware::DmDeviceInfo deviceInfo;
533     ConnectCount::GetInstance()->RemoveAllConnect();
534     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
535     EXPECT_EQ(daemon_->OpenP2PConnection(deviceInfo), ERR_BAD_VALUE);
536 
537     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
538     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
539     EXPECT_EQ(daemon_->OpenP2PConnection(deviceInfo), E_OK);
540     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnection_001 end";
541 }
542 
543 /**
544  * @tc.name: DaemonTest_ConnectionCount_001
545  * @tc.desc: verify ConnectionCount.
546  * @tc.type: FUNC
547  * @tc.require: I7TDJK
548  */
549 HWTEST_F(DaemonTest, DaemonTest_ConnectionCount_001, TestSize.Level1)
550 {
551     GTEST_LOG_(INFO) << "DaemonTest_ConnectionCount_001 begin";
552     ASSERT_NE(daemon_, nullptr);
553     DistributedHardware::DmDeviceInfo deviceInfo;
554     ConnectCount::GetInstance()->RemoveAllConnect();
555     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
556     EXPECT_EQ(daemon_->ConnectionCount(deviceInfo), ERR_BAD_VALUE);
557 
558     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
559     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
560     EXPECT_EQ(daemon_->ConnectionCount(deviceInfo), E_OK);
561     GTEST_LOG_(INFO) << "DaemonTest_ConnectionCount_001 end";
562 }
563 
564 /**
565  * @tc.name: DaemonTest_CleanUp_001
566  * @tc.desc: verify CleanUp.
567  * @tc.type: FUNC
568  * @tc.require: I7TDJK
569  */
570 HWTEST_F(DaemonTest, DaemonTest_CleanUp_001, TestSize.Level1)
571 {
572     GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 begin";
573     ASSERT_NE(daemon_, nullptr);
574     DistributedHardware::DmDeviceInfo deviceInfo;
575     ConnectCount::GetInstance()->RemoveAllConnect();
576     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((E_OK)));
577     EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_NULLPTR);
578     sleep(1);
579 
580     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return((ERR_BAD_VALUE)));
581     EXPECT_EQ(daemon_->CleanUp(deviceInfo), E_NULLPTR);
582     sleep(1);
583     GTEST_LOG_(INFO) << "DaemonTest_CleanUp_001 end";
584 }
585 
586 /**
587  * @tc.name: DaemonTest_ConnectionAndMount_001
588  * @tc.desc: verify ConnectionAndMount.
589  * @tc.type: FUNC
590  * @tc.require: I7TDJK
591  */
592 HWTEST_F(DaemonTest, DaemonTest_ConnectionAndMount_001, TestSize.Level1)
593 {
594     GTEST_LOG_(INFO) << "DaemonTest_ConnectionAndMount_001 begin";
595     ASSERT_NE(daemon_, nullptr);
596     DistributedHardware::DmDeviceInfo deviceInfo = {.networkId = "test"};
597     sptr<IFileDfsListener> remoteReverseObj = nullptr;
598     ConnectCount::GetInstance()->RemoveAllConnect();
599     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(ERR_BAD_VALUE));
600     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), ERR_BAD_VALUE);
601 
602     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillOnce(Return(E_OK));
603     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
604     g_checkCallerPermission = false;
605     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), E_OK);
606 
607     g_checkCallerPermission = true;
608     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
609     EXPECT_CALL(*deviceManagerAgentMock_, MountDfsDocs(_, _)).WillOnce(Return(ERR_BAD_VALUE));
610     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillOnce(Return(E_OK));
611     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), ERR_BAD_VALUE);
612 
613     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POnline(_)).WillRepeatedly(Return(E_OK));
614     EXPECT_CALL(*connectionDetectorMock_, RepeatGetConnectionStatus(_, _)).WillRepeatedly(Return(E_OK));
615     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
616     EXPECT_CALL(*deviceManagerAgentMock_, MountDfsDocs(_, _)).WillOnce(Return(E_OK));
617     EXPECT_EQ(daemon_->ConnectionAndMount(deviceInfo, "test", 100, remoteReverseObj), E_OK);
618     GTEST_LOG_(INFO) << "DaemonTest_ConnectionAndMount_001 end";
619 }
620 
621 /**
622  * @tc.name: DaemonTest_OpenP2PConnectionEx_001
623  * @tc.desc: verify OpenP2PConnectionEx.
624  * @tc.type: FUNC
625  * @tc.require: I7TDJK
626  */
627 HWTEST_F(DaemonTest, DaemonTest_OpenP2PConnectionEx_001, TestSize.Level1)
628 {
629     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnectionEx_001 begin";
630     ASSERT_NE(daemon_, nullptr);
631     g_checkCallerPermissionDatasync = false;
632     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", nullptr), E_PERMISSION_DENIED_NAPI);
633 
634     g_checkCallerPermissionDatasync = true;
635     daemon_->dfsListenerDeathRecipient_ = nullptr;
636     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", nullptr), E_INVAL_ARG_NAPI);
637 
638     auto listener = sptr<IFileDfsListener>(new FileDfsListenerMock());
639     EXPECT_EQ(daemon_->OpenP2PConnectionEx("", listener), E_INVAL_ARG_NAPI);
640     GTEST_LOG_(INFO) << "DaemonTest_OpenP2PConnectionEx_001 end";
641 }
642 
643 /**
644  * @tc.name: DaemonTest_CloseP2PConnectionEx_001
645  * @tc.desc: verify CloseP2PConnectionEx.
646  * @tc.type: FUNC
647  * @tc.require: I7TDJK
648  */
649 HWTEST_F(DaemonTest, DaemonTest_CloseP2PConnectionEx_001, TestSize.Level1)
650 {
651     GTEST_LOG_(INFO) << "DaemonTest_CloseP2PConnectionEx_001 begin";
652     ASSERT_NE(daemon_, nullptr);
653     g_checkCallerPermissionDatasync = false;
654     EXPECT_EQ(daemon_->CloseP2PConnectionEx(""), E_PERMISSION_DENIED_NAPI);
655 
656     g_checkCallerPermissionDatasync = true;
657     EXPECT_EQ(daemon_->CloseP2PConnectionEx(""), E_INVAL_ARG_NAPI);
658 
659     std::string networkId = "test";
660     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return(""));
661     EXPECT_EQ(daemon_->CloseP2PConnectionEx(networkId), E_CONNECTION_FAILED);
662 
663     g_checkCallerPermission = true;
664     EXPECT_CALL(*deviceManagerAgentMock_, GetDeviceIdByNetworkId(_)).WillOnce(Return("test"));
665     EXPECT_CALL(*deviceManagerAgentMock_, UMountDfsDocs(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
666     EXPECT_EQ(daemon_->CloseP2PConnectionEx(networkId), E_UNMOUNT);
667     GTEST_LOG_(INFO) << "DaemonTest_CloseP2PConnectionEx_001 end";
668 }
669 
670 /**
671  * @tc.name: DaemonTest_RequestSendFile_001
672  * @tc.desc: verify RequestSendFile.
673  * @tc.type: FUNC
674  * @tc.require: I7TDJK
675  */
676 HWTEST_F(DaemonTest, DaemonTest_RequestSendFile_001, TestSize.Level1)
677 {
678     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_001 begin";
679     ASSERT_NE(daemon_, nullptr);
680     g_getCallingNetworkId = "testNetWork1";
681     std::vector<DmDeviceInfo> deviceList;
682     deviceList.push_back(deviceInfo);
683     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
684         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
685     daemon_->eventHandler_ = nullptr;
686     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_EVENT_HANDLER);
687 
688     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
689         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
690     EXPECT_EQ(daemon_->RequestSendFile("../srcUri", "", "", ""), E_ILLEGAL_URI);
691 
692     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
693         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
694     EXPECT_EQ(daemon_->RequestSendFile("", "../dstUri", "", ""), E_ILLEGAL_URI);
695 
696     daemon_->StartEventHandler();
697     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
698         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
699     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), ERR_BAD_VALUE);
700     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_001 end";
701 }
702 
703 /**
704  * @tc.name: DaemonTest_RequestSendFile_002
705  * @tc.desc: verify RequestSendFile.
706  * @tc.type: FUNC
707  * @tc.require: I7TDJK
708  */
709 HWTEST_F(DaemonTest, DaemonTest_RequestSendFile_002, TestSize.Level1)
710 {
711     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_002 begin";
712 #ifdef SUPPORT_SAME_ACCOUNT
713     ASSERT_NE(daemon_, nullptr);
714     g_getCallingNetworkId.clear();
715     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_PERMISSION_DENIED);
716 
717     g_getCallingNetworkId = "testNetWork1";
718     std::vector<DmDeviceInfo> deviceList;
719     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
720         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
721     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_PERMISSION_DENIED);
722 
723     (void)memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_NAME_LEN - 1,
724         NETWORKID_TWO.c_str(), NETWORKID_TWO.size());
725     deviceList.push_back(deviceInfo);
726     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
727         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
728     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_PERMISSION_DENIED);
729 #endif
730     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_002 end";
731 }
732 
733 /**
734  * @tc.name: DaemonTest_RequestSendFile_003
735  * @tc.desc: verify RequestSendFile.
736  * @tc.type: FUNC
737  * @tc.require: I7TDJK
738  */
739 HWTEST_F(DaemonTest, DaemonTest_RequestSendFile_003, TestSize.Level1)
740 {
741     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_003 begin";
742 #ifdef SUPPORT_SAME_ACCOUNT
743     DistributedHardware::DmDeviceInfo deviceInfo1 = {
744         .deviceId = "test",
745         .deviceName = "testdevname",
746         .deviceTypeId = 1,
747         .networkId = "testNetWork1",
748         .authForm = DmAuthForm::ACROSS_ACCOUNT,
749         .extraData = "{\"OS_TYPE\":10}",
750     };
751     std::vector<DmDeviceInfo> deviceList;
752     deviceList.push_back(deviceInfo1);
753     g_getCallingNetworkId = "testNetWork1";
754     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
755         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
756     ASSERT_NE(daemon_, nullptr);
757     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_PERMISSION_DENIED);
758 
759     g_getCallingNetworkId = "testNetWork2";
760     deviceInfo1.authForm = DmAuthForm::IDENTICAL_ACCOUNT;
761     deviceList.clear();
762     deviceList.push_back(deviceInfo1);
763     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
764         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
765     EXPECT_EQ(daemon_->RequestSendFile("", "", "", ""), E_PERMISSION_DENIED);
766 
767     g_getCallingNetworkId = "testNetWork1";
768     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
769         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
770     EXPECT_EQ(daemon_->RequestSendFile("/data/../test/1.txt", "", "", ""), E_ILLEGAL_URI);
771 #endif
772     GTEST_LOG_(INFO) << "DaemonTest_RequestSendFile_003 end";
773 }
774 
775 /**
776  * @tc.name: DaemonTest_PrepareSession_001
777  * @tc.desc: 验证 PrepareSession 方法在多种场景下的分支覆盖
778  * @tc.type: FUNC
779  * @tc.require: I7TDJK
780  */
781 HWTEST_F(DaemonTest, DaemonTest_PrepareSession_001, TestSize.Level1)
782 {
783     GTEST_LOG_(INFO) << "DaemonTest_PrepareSession_001 start";
784     ASSERT_NE(daemon_, nullptr);
785     HmdfsInfo hmdfsInfo;
786     std::string srcUri = "file://docs/storage/el2/distributedfiles/test.txt";
787     std::string dstUri = "file://media/storage/el2/distributedfiles/test.txt?networkid=testDevice";
788     std::string srcDeviceId = "testDevice";
789     sptr<IRemoteObject> listener = new (std::nothrow) FileTransListenerMock();
790     ASSERT_TRUE(listener != nullptr) << "监听器创建失败";
791 
792     // 测试用例 1: 空监听器
793     EXPECT_EQ(daemon_->PrepareSession("", "", "", nullptr, hmdfsInfo), E_NULLPTR);
794 
795     // 测试用例 2: 有效 URI,物理路径无效
796     g_getPhysicalPath = ERR_BAD_VALUE;
797     g_checkValidPath = false;
798     EXPECT_EQ(daemon_->PrepareSession(srcUri, dstUri, srcDeviceId, listener, hmdfsInfo), EINVAL);
799 
800     // 测试用例 3: 有效 URI,物理路径有效,stat 失败
801     g_getPhysicalPath = E_OK;
802     g_physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/test.txt";
803     g_checkValidPath = true;
804     g_isFile = false;
805     EXPECT_EQ(daemon_->PrepareSession(srcUri, dstUri, srcDeviceId, listener, hmdfsInfo), E_SA_LOAD_FAILED);
806 
807     // 测试用例 4: 有效 URI,物理路径有效,stat 成功,DFS 版本为 0,文件大小 < 1GB, 走innerCopy
808     g_getPhysicalPath = E_OK;
809     g_physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
810     g_checkValidPath = true;
811     g_isFile = true;
812     g_isFolder = false;
813     std::ofstream file(g_physicalPath);
814     ASSERT_TRUE(file.good()) << "创建测试文件失败";
815     file.close();
816     EXPECT_EQ(daemon_->PrepareSession(srcUri, dstUri, NETWORKID_ONE, listener, hmdfsInfo), E_SA_LOAD_FAILED);
817 
818     // 测试用例 5: DFS 有效 URI,物理路径有效,stat 成功,DFS 版本为 1,文件大小 < 1GB, CopyBaseOnRPC
819     EXPECT_EQ(daemon_->PrepareSession(srcUri, dstUri, NETWORKID_TWO, listener, hmdfsInfo), 22);
820 
821     // 测试用例 6: DFS 有效 URI,物理路径有效,stat 成功,DFS 版本获取失败,文件大小 < 1GB, CopyBaseOnRPC
822     EXPECT_EQ(daemon_->PrepareSession(srcUri, dstUri, "invalidDevice", listener, hmdfsInfo), E_SA_LOAD_FAILED);
823 
824     // 清理
825     if (std::filesystem::exists(g_physicalPath)) {
826         std::filesystem::remove(g_physicalPath);
827     }
828 
829     GTEST_LOG_(INFO) << "DaemonTest_PrepareSession_001 end";
830 }
831 
832 /**
833  * @tc.name: DaemonTest_GetRealPath_001
834  * @tc.desc: verify GetRealPath.
835  * @tc.type: FUNC
836  * @tc.require: I7TDJK
837  */
838 HWTEST_F(DaemonTest, DaemonTest_GetRealPath_001, TestSize.Level1)
839 {
840     GTEST_LOG_(INFO) << "DaemonTest_GetRealPath_001 begin";
841     ASSERT_NE(daemon_, nullptr);
842     std::string physicalPath;
843     HmdfsInfo info;
844     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, nullptr), E_INVAL_ARG_NAPI);
845 
846     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
847     ASSERT_TRUE(daemon != nullptr) << "daemon assert failed!";
848 
849     EXPECT_EQ(daemon_->GetRealPath("../srcUri", "", physicalPath, info, daemon), E_ILLEGAL_URI);
850 
851     EXPECT_EQ(daemon_->GetRealPath("", "../dstUri", physicalPath, info, daemon), E_ILLEGAL_URI);
852 
853     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
854     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_SOFTBUS_SESSION_FAILED);
855 
856     g_getHapTokenInfo = ERR_BAD_VALUE;
857     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
858     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_USER_ID);
859 
860     g_getHapTokenInfo = Security::AccessToken::AccessTokenKitRet::RET_SUCCESS;
861     g_getPhysicalPath = ERR_BAD_VALUE;
862     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
863     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_PHYSICAL_PATH_FAILED);
864 
865     g_getPhysicalPath = E_OK;
866     g_checkValidPath = false;
867     info.dirExistFlag = false;
868     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
869     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_GET_PHYSICAL_PATH_FAILED);
870 
871     g_checkValidPath = true;
872     g_physicalPath = "test@test/test";
873     info.dirExistFlag = true;
874     std::string dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
875     EXPECT_CALL(*daemon, GetRemoteCopyInfo(_, _, _)).WillOnce(Return(E_OK));
876     EXPECT_EQ(daemon_->GetRealPath("", "", physicalPath, info, daemon), E_OK);
877     GTEST_LOG_(INFO) << "DaemonTest_GetRealPath_001 end";
878 }
879 
880 /**
881  * @tc.name: DaemonTest_CheckCopyRule_001
882  * @tc.desc: verify CheckCopyRule.
883  * @tc.type: FUNC
884  * @tc.require: I7TDJK
885  */
886 HWTEST_F(DaemonTest, DaemonTest_CheckCopyRule_001, TestSize.Level1)
887 {
888     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_001 begin";
889     ASSERT_NE(daemon_, nullptr);
890     std::string physicalPath;
891     HapTokenInfo hapTokenInfo;
892     HmdfsInfo info;
893 
894     g_isFolder = false;
895     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
896 
897     g_isFolder = false;
898     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
899     info.dirExistFlag = false;
900     g_checkValidPath = false;
901     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
902 
903     g_isFolder = false;
904     physicalPath = "test";
905     info.dirExistFlag = false;
906     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, false, info), E_GET_PHYSICAL_PATH_FAILED);
907 
908     g_isFolder = true;
909     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
910     info.dirExistFlag = true;
911     g_checkValidPath = false;
912     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, "", hapTokenInfo, true, info), E_GET_PHYSICAL_PATH_FAILED);
913 
914     g_isFolder = true;
915     physicalPath = "te@st";
916     info.dirExistFlag = true;
917     std::string dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
918     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
919 
920     g_isFolder = false;
921     physicalPath = "tes@t/test";
922     info.dirExistFlag = false;
923     g_checkValidPath = true;
924     dstUri = "file://media/data/storage/el2/distributedfiles/images/1.png";
925     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
926     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_001 end";
927 }
928 
929 /**
930  * @tc.name: DaemonTest_CheckCopyRule_002
931  * @tc.desc: verify CheckCopyRule.
932  * @tc.type: FUNC
933  * @tc.require: I7TDJK
934  */
935 HWTEST_F(DaemonTest, DaemonTest_CheckCopyRule_002, TestSize.Level1)
936 {
937     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_002 begin";
938     ASSERT_NE(daemon_, nullptr);
939     std::string physicalPath;
940     HapTokenInfo hapTokenInfo;
941     HmdfsInfo info;
942 
943     g_isFolder = true;
944     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1.txt";
945     info.dirExistFlag = true;
946     std::string dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
947     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
948 
949     g_isFolder = true;
950     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/com.example.app/docs/1@.txt";
951     info.dirExistFlag = true;
952     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
953     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
954 
955     g_isFolder = true;
956     physicalPath = "/mnt/hmdfs/100/account/device_view/local/files/Docs/Download/111";
957     info.dirExistFlag = true;
958     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
959     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK);
960 
961     g_isFolder = true;
962     physicalPath = "/mnt/hmdfs/100/account/device_view/local/data/docs/111";
963     info.dirExistFlag = true;
964     dstUri = "file://docs/data/storage/el2/distributedfiles/images/1.png";
965     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_GET_PHYSICAL_PATH_FAILED);
966 
967     g_isFolder = true;
968     physicalPath = "te@st";
969     info.dirExistFlag = true;
970     hapTokenInfo.userID = 100;
971     g_checkValidPath = false;
972     dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
973     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info),
974               E_GET_PHYSICAL_PATH_FAILED); // 4 7 15 18
975 
976     g_isFolder = true;
977     physicalPath = "te@st";
978     info.dirExistFlag = true;
979     hapTokenInfo.userID = 100;
980     g_checkValidPath = true;
981     dstUri = "file://com.example.app/data/storage/el2/distributedfiles/images/1.png";
982     EXPECT_EQ(daemon_->CheckCopyRule(physicalPath, dstUri, hapTokenInfo, false, info), E_OK); // 4 7 15 19
983     GTEST_LOG_(INFO) << "DaemonTest_CheckCopyRule_002 end";
984 }
985 
986 /**
987  * @tc.name: DaemonTest_GetRemoteCopyInfo_001
988  * @tc.desc: verify GetRemoteCopyInfo.
989  * @tc.type: FUNC
990  * @tc.require: I7TDJK
991  */
992 HWTEST_F(DaemonTest, DaemonTest_GetRemoteCopyInfo_001, TestSize.Level1)
993 {
994     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_001 begin";
995     ASSERT_NE(daemon_, nullptr);
996     g_getCallingNetworkId = "testNetWork1";
997     std::vector<DmDeviceInfo> deviceList;
998     (void)memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_NAME_LEN - 1,
999         NETWORKID_ONE.c_str(), NETWORKID_ONE.size());
1000     deviceList.push_back(deviceInfo);
1001     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
1002         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
1003     EXPECT_CALL(*softBusSessionListenerMock_, GetRealPath(_)).WillOnce(Return(""));
1004     bool isSrcFile = false;
1005     bool srcIsDir = false;
1006     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_SOFTBUS_SESSION_FAILED);
1007 
1008     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
1009         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
1010     EXPECT_CALL(*softBusSessionListenerMock_, GetRealPath(_)).WillOnce(Return("test"));
1011     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_OK);
1012     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_001 end";
1013 }
1014 
1015 /**
1016  * @tc.name: DaemonTest_GetRemoteCopyInfo_002
1017  * @tc.desc: verify GetRemoteCopyInfo.
1018  * @tc.type: FUNC
1019  * @tc.require: I7TDJK
1020  */
1021 HWTEST_F(DaemonTest, DaemonTest_GetRemoteCopyInfo_002, TestSize.Level1)
1022 {
1023     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_002 begin";
1024 #ifdef SUPPORT_SAME_ACCOUNT
1025     ASSERT_NE(daemon_, nullptr);
1026     g_getCallingNetworkId.clear();
1027     bool isSrcFile = false;
1028     bool srcIsDir = false;
1029     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_PERMISSION_DENIED);
1030 
1031     g_getCallingNetworkId = "testNetWork1";
1032     std::vector<DmDeviceInfo> deviceList;
1033     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
1034         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
1035     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_PERMISSION_DENIED);
1036 
1037     (void)memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_NAME_LEN - 1,
1038         NETWORKID_TWO.c_str(), NETWORKID_TWO.size());
1039     deviceList.push_back(deviceInfo);
1040     EXPECT_CALL(*deviceManagerImplMock_, GetTrustedDeviceList(_, _, _))
1041         .WillOnce(DoAll(SetArgReferee<2>(deviceList), Return(0)));
1042     EXPECT_EQ(daemon_->GetRemoteCopyInfo("", isSrcFile, srcIsDir), E_PERMISSION_DENIED);
1043 #endif
1044     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteCopyInfo_002 end";
1045 }
1046 
1047 /**
1048  * @tc.name: DaemonTest_GetRemoteSA_001
1049  * @tc.desc: verify GetRemoteSA.
1050  * @tc.type: FUNC
1051  * @tc.require: I7TDJK
1052  */
1053 HWTEST_F(DaemonTest, DaemonTest_GetRemoteSA_001, TestSize.Level1)
1054 {
1055     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteSA_001 begin";
1056     ASSERT_NE(daemon_, nullptr);
1057     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(nullptr));
1058     EXPECT_TRUE(daemon_->GetRemoteSA("") == nullptr);
1059 
1060     auto sysAbilityManager = sptr<ISystemAbilityManagerMock>(new ISystemAbilityManagerMock());
1061     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
1062     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(nullptr));
1063     EXPECT_TRUE(daemon_->GetRemoteSA("") == nullptr);
1064 
1065     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
1066     ASSERT_TRUE(daemon != nullptr) << "daemon assert failed!";
1067     EXPECT_CALL(*smc_, GetSystemAbilityManager()).WillOnce(Return(sysAbilityManager));
1068     EXPECT_CALL(*sysAbilityManager, GetSystemAbility(_, _)).WillOnce(Return(daemon));
1069     EXPECT_FALSE(daemon_->GetRemoteSA("") == nullptr);
1070     GTEST_LOG_(INFO) << "DaemonTest_GetRemoteSA_001 end";
1071 }
1072 
1073 /**
1074  * @tc.name: DaemonTest_Copy_001
1075  * @tc.desc: verify Copy.
1076  * @tc.type: FUNC
1077  * @tc.require: I7TDJK
1078  */
1079 HWTEST_F(DaemonTest, DaemonTest_Copy_001, TestSize.Level1)
1080 {
1081     GTEST_LOG_(INFO) << "DaemonTest_Copy_001 begin";
1082     ASSERT_NE(daemon_, nullptr);
1083     EXPECT_CALL(*deviceManagerImplMock_, GetLocalDeviceInfo(_, _))
1084         .WillOnce(Return(ERR_BAD_VALUE));
1085     EXPECT_EQ(daemon_->Copy("", "", nullptr, ""), E_GET_DEVICE_ID);
1086 
1087     EXPECT_CALL(*deviceManagerImplMock_, GetLocalDeviceInfo(_, _))
1088         .WillOnce(Return(E_OK));
1089     EXPECT_EQ(daemon_->Copy("", "", nullptr, ""), E_INVAL_ARG_NAPI);
1090 
1091     EXPECT_CALL(*deviceManagerImplMock_, GetLocalDeviceInfo(_, _))
1092         .WillOnce(Return(E_OK));
1093     sptr<DaemonMock> daemon = new (std::nothrow) DaemonMock();
1094     ASSERT_TRUE(daemon != nullptr) << "daemon assert failed!";
1095     EXPECT_CALL(*daemon, RequestSendFile(_, _, _, _)).WillOnce(Return(ERR_BAD_VALUE));
1096     EXPECT_EQ(daemon_->Copy("", "", daemon, ""), E_SA_LOAD_FAILED);
1097 
1098     EXPECT_CALL(*deviceManagerImplMock_, GetLocalDeviceInfo(_, _))
1099         .WillOnce(Return(E_OK));
1100     EXPECT_CALL(*daemon, RequestSendFile(_, _, _, _)).WillOnce(Return(E_OK));
1101     EXPECT_EQ(daemon_->Copy("", "", daemon, ""), E_OK);
1102 
1103     string srcUri = "file://docs/storage/media/100/local/files/Docs/../A/1.txt";
1104     string destPath = "/storage/media/100/local/files/Docs/aa1/";
1105     EXPECT_EQ(daemon_->Copy(srcUri, destPath, daemon, ""), E_INVAL_ARG);
1106 
1107     srcUri = "file://docs/storage/media/100/local/files/Docs/../A/1.txt?networkid=123456";
1108     EXPECT_EQ(daemon_->Copy(srcUri, destPath, daemon, ""), E_INVAL_ARG);
1109 
1110     srcUri = "file://docs/storage/media/100/local/files/Docs/1.txt";
1111     destPath = "/storage/media/100/local/files/Docs/../aa1/";
1112     EXPECT_EQ(daemon_->Copy(srcUri, destPath, daemon, ""), E_INVAL_ARG);
1113 
1114     destPath = "/storage/media/100/local/files/Docs/../aa1/?networkid=123456";
1115     EXPECT_EQ(daemon_->Copy(srcUri, destPath, daemon, ""), E_INVAL_ARG);
1116     GTEST_LOG_(INFO) << "DaemonTest_Copy_001 end";
1117 }
1118 
1119 /**
1120  * @tc.name: DaemonTest_CancelCopyTask_001
1121  * @tc.desc: verify CancelCopyTask.
1122  * @tc.type: FUNC
1123  * @tc.require: I7TDJK
1124  */
1125 HWTEST_F(DaemonTest, DaemonTest_CancelCopyTask_001, TestSize.Level1)
1126 {
1127     GTEST_LOG_(INFO) << "DaemonTest_CancelCopyTask_001 begin";
1128     ASSERT_NE(daemon_, nullptr);
1129     SoftBusSessionPool::GetInstance().DeleteSessionInfo("test");
1130     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_INVAL_ARG);
1131 
1132     SoftBusSessionPool::SessionInfo sessionInfo{.uid = 100};
1133     g_getCallingUid = 101;
1134     SoftBusSessionPool::GetInstance().AddSessionInfo("test", sessionInfo);
1135     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_PERMISSION_DENIED);
1136 
1137     g_getCallingUid = 100;
1138     EXPECT_EQ(daemon_->CancelCopyTask("test"), E_OK);
1139     SoftBusSessionPool::GetInstance().DeleteSessionInfo("test");
1140     GTEST_LOG_(INFO) << "DaemonTest_CancelCopyTask_001 end";
1141 }
1142 
1143 /**
1144  * @tc.name: DaemonTest_PushAsset_001
1145  * @tc.desc: verify PushAsset.
1146  * @tc.type: FUNC
1147  * @tc.require: I7TDJK
1148  */
1149 HWTEST_F(DaemonTest, DaemonTest_PushAsset_001, TestSize.Level1)
1150 {
1151     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_001 begin";
1152     ASSERT_NE(daemon_, nullptr);
1153     int32_t userId = 100;
1154     sptr<AssetObj> assetObj(new (std::nothrow) AssetObj());
1155     ASSERT_TRUE(assetObj != nullptr) << "assetObj assert failed!";
1156     sptr<IAssetSendCallback> assetSendCallback = new (std::nothrow) IAssetSendCallbackMock();
1157     ASSERT_TRUE(assetSendCallback != nullptr) << "assetSendCallback assert failed!";
1158     EXPECT_EQ(daemon_->PushAsset(userId, nullptr, nullptr), E_NULLPTR);
1159     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, nullptr), E_NULLPTR);
1160     EXPECT_EQ(daemon_->PushAsset(userId, nullptr, assetSendCallback), E_NULLPTR);
1161     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_NULLPTR);
1162 
1163     ASSERT_NE(assetObj, nullptr);
1164     assetObj->srcBundleName_ = "test";
1165     daemon_->eventHandler_ = nullptr;
1166     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_EVENT_HANDLER);
1167     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_001 end";
1168 }
1169 
1170 /**
1171  * @tc.name: DaemonTest_PushAsset_002
1172  * @tc.desc: verify PushAsset.
1173  * @tc.type: FUNC
1174  * @tc.require: I7TDJK
1175  */
1176 HWTEST_F(DaemonTest, DaemonTest_PushAsset_002, TestSize.Level1)
1177 {
1178     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_002 begin";
1179     ASSERT_NE(daemon_, nullptr);
1180     daemon_->StartEventHandler();
1181     int32_t userId = 100;
1182     sptr<AssetObj> assetObj(new (std::nothrow) AssetObj());
1183     ASSERT_TRUE(assetObj != nullptr) << "assetObj assert failed!";
1184     assetObj->dstNetworkId_ = "test";
1185     DevslDispatcher::devslMap_.clear();
1186     DevslDispatcher::devslMap_.insert(make_pair("test", static_cast<int32_t>(SecurityLabel::S4)));
1187     assetObj->uris_.push_back("file://com.example.app/data/storage/el2/distributedfiles/docs/1.txt");
1188     assetObj->srcBundleName_ = "com.example.app";
1189     sptr<IAssetSendCallback> assetSendCallback = new (std::nothrow) IAssetSendCallbackMock();
1190     ASSERT_TRUE(assetSendCallback != nullptr) << "assetSendCallback assert failed!";
1191     g_getPhysicalPath = E_OK;
1192     g_checkValidPath = true;
1193     g_isFolder = false;
1194     EXPECT_CALL(*softBusHandlerAssetMock_, AssetBind(_, _)).WillOnce(Return(E_OK));
1195     EXPECT_CALL(*softBusHandlerAssetMock_, AssetSendFile(_, _, _)).WillOnce(Return(E_OK));
1196     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_OK);
1197 
1198     assetObj->uris_.push_back("../srcUri");
1199     EXPECT_EQ(daemon_->PushAsset(userId, assetObj, assetSendCallback), E_ILLEGAL_URI);
1200     sleep(1);
1201     AssetCallbackManager::GetInstance().RemoveSendCallback(assetObj->srcBundleName_);
1202     GTEST_LOG_(INFO) << "DaemonTest_PushAsset_002 end";
1203 }
1204 
1205 /**
1206  * @tc.name: DaemonTest_RegisterAssetCallback_001
1207  * @tc.desc: verify RegisterAssetCallback.
1208  * @tc.type: FUNC
1209  * @tc.require: I7TDJK
1210  */
1211 HWTEST_F(DaemonTest, DaemonTest_RegisterAssetCallback_001, TestSize.Level1)
1212 {
1213     GTEST_LOG_(INFO) << "DaemonTest_RegisterAssetCallback_001 begin";
1214     ASSERT_NE(daemon_, nullptr);
1215     EXPECT_EQ(daemon_->RegisterAssetCallback(nullptr), E_NULLPTR);
1216 
1217     sptr<IAssetRecvCallback> assetRecvCallback = new (std::nothrow) IAssetRecvCallbackMock();
1218     ASSERT_TRUE(assetRecvCallback != nullptr) << "assetRecvCallback assert failed!";
1219     EXPECT_EQ(daemon_->RegisterAssetCallback(assetRecvCallback), E_OK);
1220     AssetCallbackManager::GetInstance().RemoveRecvCallback(assetRecvCallback);
1221     GTEST_LOG_(INFO) << "DaemonTest_RegisterAssetCallback_001 end";
1222 }
1223 
1224 /**
1225  * @tc.name: DaemonTest_UnRegisterAssetCallback_001
1226  * @tc.desc: verify UnRegisterAssetCallback.
1227  * @tc.type: FUNC
1228  * @tc.require: I7TDJK
1229  */
1230 HWTEST_F(DaemonTest, DaemonTest_UnRegisterAssetCallback_001, TestSize.Level1)
1231 {
1232     GTEST_LOG_(INFO) << "DaemonTest_UnRegisterAssetCallback_001 begin";
1233     ASSERT_NE(daemon_, nullptr);
1234     EXPECT_EQ(daemon_->UnRegisterAssetCallback(nullptr), E_NULLPTR);
1235 
1236     sptr<IAssetRecvCallback> assetRecvCallback = new (std::nothrow) IAssetRecvCallbackMock();
1237     ASSERT_TRUE(assetRecvCallback != nullptr) << "assetRecvCallback assert failed!";
1238     EXPECT_EQ(daemon_->UnRegisterAssetCallback(assetRecvCallback), E_OK);
1239     GTEST_LOG_(INFO) << "DaemonTest_UnRegisterAssetCallback_001 end";
1240 }
1241 
1242 /**
1243  * @tc.name: DaemonTest_StartEventHandler_001
1244  * @tc.desc: verify StartEventHandler.
1245  * @tc.type: FUNC
1246  * @tc.require: I7TDJK
1247  */
1248 HWTEST_F(DaemonTest, DaemonTest_StartEventHandler_001, TestSize.Level1)
1249 {
1250     GTEST_LOG_(INFO) << "DaemonTest_StartEventHandler_001 begin";
1251     ASSERT_NE(daemon_, nullptr);
1252     daemon_->daemonExecute_ = std::make_shared<DaemonExecute>();
1253     daemon_->StartEventHandler();
1254     GTEST_LOG_(INFO) << "DaemonTest_StartEventHandler_001 end";
1255 }
1256 
1257 /**
1258  * @tc.name: DaemonTest_InnerCopy_001
1259  * @tc.desc: verify InnerCopy.
1260  * @tc.type: FUNC
1261  * @tc.require: I7TDJK
1262  */
1263 HWTEST_F(DaemonTest, DaemonTest_InnerCopy_001, TestSize.Level1)
1264 {
1265     GTEST_LOG_(INFO) << "DaemonTest_InnerCopy_001 begin";
1266     string srcUri = "file://docs/storage/media/100/local/files/Docs/../A/1.txt";
1267     string destUri = "file://docs/storage/media/100/local/files/Docs/dest1.txt";
1268     HmdfsInfo hmdfsInfo;
1269     EXPECT_EQ(daemon_->InnerCopy(srcUri, destUri, "", nullptr, hmdfsInfo), ERR_BAD_VALUE);
1270 
1271     srcUri = "file://docs/storage/media/100/local/files/Docs/../A/1.txt?networkid=123456";
1272     EXPECT_EQ(daemon_->InnerCopy(srcUri, destUri, "", nullptr, hmdfsInfo), ERR_BAD_VALUE);
1273 
1274     srcUri = "file://docs/storage/media/100/local/files/Docs/1.txt";
1275     destUri = "file://docs/storage/media/100/local/files/Docs/../A/dest1.txt";
1276     EXPECT_EQ(daemon_->InnerCopy(srcUri, destUri, "", nullptr, hmdfsInfo), ERR_BAD_VALUE);
1277 
1278     destUri = "file://docs/storage/media/100/local/files/Docs/../A/dest1.txt?networkid=123456";
1279     EXPECT_EQ(daemon_->InnerCopy(srcUri, destUri, "", nullptr, hmdfsInfo), ERR_BAD_VALUE);
1280     GTEST_LOG_(INFO) << "DaemonTest_InnerCopy_001 end";
1281 }
1282 
1283 /**
1284  * @tc.name: DaemonTest_DisconnectByRemote_001
1285  * @tc.desc: verify DisconnectByRemote with invalid networkId
1286  * @tc.type: FUNC
1287  * @tc.require: I7TDJK
1288  */
1289 HWTEST_F(DaemonTest, DaemonTest_DisconnectByRemote_001, TestSize.Level1)
1290 {
1291     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_001 begin";
1292     ASSERT_NE(daemon_, nullptr);
1293     // Test empty networkId
1294     EXPECT_NO_THROW(daemon_->DisconnectByRemote(""));
1295 
1296     // Test invalid networkId length
1297     std::string longNetworkId(DM_MAX_DEVICE_ID_LEN + 1, 'a');
1298     EXPECT_NO_THROW(daemon_->DisconnectByRemote(longNetworkId));
1299 
1300     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_001 end";
1301 }
1302 
1303 /**
1304  * @tc.name: DaemonTest_DisconnectByRemote_002
1305  * @tc.desc: verify DisconnectByRemote with UMountDfsDocs failed
1306  * @tc.type: FUNC
1307  * @tc.require: I7TDJK
1308  */
1309 HWTEST_F(DaemonTest, DaemonTest_DisconnectByRemote_002, TestSize.Level1)
1310 {
1311     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_002 begin";
1312     ASSERT_NE(daemon_, nullptr);
1313     // Test normal case with mock
1314     EXPECT_CALL(*deviceManagerAgentMock_, UMountDfsDocs(_, _, _)).WillOnce(Return(ERR_BAD_VALUE));
1315     EXPECT_NO_THROW(daemon_->DisconnectByRemote("validNetworkId"));
1316 
1317     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_002 end";
1318 }
1319 
1320 /**
1321  * @tc.name: DaemonTest_DisconnectByRemote_003
1322  * @tc.desc: verify DisconnectByRemote with UMountDfsDocs success
1323  * @tc.type: FUNC
1324  * @tc.require: I7TDJK
1325  */
1326 HWTEST_F(DaemonTest, DaemonTest_DisconnectByRemote_003, TestSize.Level1)
1327 {
1328     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_003 begin";
1329     ASSERT_NE(daemon_, nullptr);
1330     // Test normal case with mock
1331     EXPECT_CALL(*deviceManagerAgentMock_, UMountDfsDocs(_, _, _)).WillOnce(Return(NO_ERROR));
1332     EXPECT_CALL(*deviceManagerAgentMock_, OnDeviceP2POffline(_)).WillOnce(Return(NO_ERROR));
1333     EXPECT_NO_THROW(daemon_->DisconnectByRemote("validNetworkId"));
1334 
1335     GTEST_LOG_(INFO) << "DaemonTest_DisconnectByRemote_003 end";
1336 }
1337 
1338 /**
1339  * @tc.name: DaemonTest_CreateControlLink_001
1340  * @tc.desc: verify CreatControlLink and CancelConrolLink
1341  * @tc.type: FUNC
1342  * @tc.require: I7TDJK
1343  */
1344 HWTEST_F(DaemonTest, DaemonTest_CreateControlLink_001, TestSize.Level1)
1345 {
1346     GTEST_LOG_(INFO) << "DaemonTest_CreateControlLink_001 begin";
1347     ASSERT_NE(daemon_, nullptr);
1348     // Test exist channel now
1349     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1350     EXPECT_EQ(daemon_->CreatControlLink("networkId"), FileManagement::ERR_OK);
1351 
1352     // Test no exist channel and not support with return ok
1353     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1354     EXPECT_EQ(daemon_->CreatControlLink("networkId"), FileManagement::ERR_OK);
1355 
1356     // Test no exist channel and support create but renturn failed
1357     g_dfsVersion = {6, 0, 0};
1358     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1359     EXPECT_CALL(*channelManagerMock_, CreateClientChannel(_)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1360     EXPECT_EQ(daemon_->CreatControlLink("networkId"), FileManagement::ERR_BAD_VALUE);
1361 
1362     // Test no exist channel and support create but renturn success
1363     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1364     EXPECT_CALL(*channelManagerMock_, CreateClientChannel(_)).WillOnce(Return(FileManagement::ERR_OK));
1365     EXPECT_EQ(daemon_->CreatControlLink("networkId"), FileManagement::ERR_OK);
1366 
1367     GTEST_LOG_(INFO) << "DaemonTest_CreateControlLink_001 end";
1368 }
1369 
1370 /**
1371  * @tc.name: DaemonTest_DestroyControlLink_001
1372  * @tc.desc: verify CreatControlLink and CancelConrolLink
1373  * @tc.type: FUNC
1374  * @tc.require: I7TDJK
1375  */
1376 HWTEST_F(DaemonTest, DaemonTest_DestroyControlLink_001, TestSize.Level1)
1377 {
1378     GTEST_LOG_(INFO) << "DaemonTest_DestroyControlLink_001 begin";
1379     ASSERT_NE(daemon_, nullptr);
1380     // Test not existing channel
1381     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1382     EXPECT_EQ(daemon_->CancelControlLink("networkId"), FileManagement::ERR_OK);
1383 
1384     // Test existing channel and destroy failed
1385     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1386     EXPECT_CALL(*channelManagerMock_, DestroyClientChannel(_)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1387     EXPECT_EQ(daemon_->CancelControlLink("networkId"), FileManagement::ERR_BAD_VALUE);
1388 
1389     // Test existing channel and destroy success
1390     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1391     EXPECT_CALL(*channelManagerMock_, DestroyClientChannel(_)).WillOnce(Return(FileManagement::ERR_OK));
1392     EXPECT_EQ(daemon_->CancelControlLink("networkId"), FileManagement::ERR_OK);
1393 
1394     GTEST_LOG_(INFO) << "DaemonTest_DestroyControlLink_001 end";
1395 }
1396 
1397 /**
1398  * @tc.name: DaemonTest_CheckRemoteAllowConnect_001
1399  * @tc.desc: verify CheckRemoteAllowConnect and notification functions
1400  * @tc.type: FUNC
1401  * @tc.require: I7TDJK
1402  */
1403 HWTEST_F(DaemonTest, DaemonTest_CheckRemoteAllowConnect_001, TestSize.Level1)
1404 {
1405     GTEST_LOG_(INFO) << "DaemonTest_CheckRemoteAllowConnect_001";
1406     ASSERT_NE(daemon_, nullptr);
1407     // Test CreatControlLink failed
1408     g_dfsVersion = {6, 0, 0};
1409     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1410     EXPECT_CALL(*channelManagerMock_, CreateClientChannel(_)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1411     EXPECT_EQ(daemon_->CheckRemoteAllowConnect("networkId"), FileManagement::ERR_BAD_VALUE);
1412 
1413     // Test SendRequest failed
1414     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1415     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1416     EXPECT_EQ(daemon_->CheckRemoteAllowConnect("networkId"), FileManagement::ERR_BAD_VALUE);
1417 
1418     // Test CheckRemoteAllowConnect success
1419     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1420     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_OK));
1421     EXPECT_EQ(daemon_->CheckRemoteAllowConnect("networkId"), FileManagement::ERR_OK);
1422 
1423     GTEST_LOG_(INFO) << "DaemonTest_CheckRemoteAllowConnect_001";
1424 }
1425 
1426 /**
1427  * @tc.name: DaemonTest_NotifyRemotePublishNotification_001
1428  * @tc.desc: verify NotifyRemotePublishNotification
1429  * @tc.type: FUNC
1430  * @tc.require: I7TDJK
1431  */
1432 HWTEST_F(DaemonTest, DaemonTest_NotifyRemotePublishNotification_001, TestSize.Level1)
1433 {
1434     GTEST_LOG_(INFO) << "DaemonTest_NotifyRemotePublishNotification_001";
1435     ASSERT_NE(daemon_, nullptr);
1436     // Test CreatControlLink failed
1437     g_dfsVersion = {6, 0, 0};
1438     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1439     EXPECT_CALL(*channelManagerMock_, CreateClientChannel(_)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1440     EXPECT_EQ(daemon_->NotifyRemotePublishNotification("networkId"), FileManagement::ERR_BAD_VALUE);
1441 
1442     // Test SendRequest failed
1443     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1444     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1445     EXPECT_EQ(daemon_->NotifyRemotePublishNotification("networkId"), FileManagement::ERR_BAD_VALUE);
1446 
1447     // Test CheckRemoteAllowConnect success
1448     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1449     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_OK));
1450     EXPECT_EQ(daemon_->NotifyRemotePublishNotification("networkId"), FileManagement::ERR_OK);
1451 
1452     GTEST_LOG_(INFO) << "DaemonTest_NotifyRemotePublishNotification_001";
1453 }
1454 
1455 /**
1456  * @tc.name: DaemonTest_NotifyRemoteCancelNotification_001
1457  * @tc.desc: verify NotifyRemoteCancelNotification and notification functions
1458  * @tc.type: FUNC
1459  * @tc.require: I7TDJK
1460  */
1461 HWTEST_F(DaemonTest, DaemonTest_NotifyRemoteCancelNotification_001, TestSize.Level1)
1462 {
1463     GTEST_LOG_(INFO) << "DaemonTest_NotifyRemoteCancelNotification_001";
1464     ASSERT_NE(daemon_, nullptr);
1465     // Test CreatControlLink failed
1466     g_dfsVersion = {6, 0, 0};
1467     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(false));
1468     EXPECT_CALL(*channelManagerMock_, CreateClientChannel(_)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1469     EXPECT_EQ(daemon_->NotifyRemoteCancelNotification("networkId"), FileManagement::ERR_BAD_VALUE);
1470 
1471     // Test SendRequest failed
1472     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1473     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_BAD_VALUE));
1474     EXPECT_EQ(daemon_->NotifyRemoteCancelNotification("networkId"), FileManagement::ERR_BAD_VALUE);
1475 
1476     // Test CheckRemoteAllowConnect success
1477     EXPECT_CALL(*channelManagerMock_, HasExistChannel(_)).WillOnce(Return(true));
1478     EXPECT_CALL(*channelManagerMock_, SendRequest(_, _, _, _)).WillOnce(Return(FileManagement::ERR_OK));
1479     EXPECT_EQ(daemon_->NotifyRemoteCancelNotification("networkId"), FileManagement::ERR_OK);
1480 
1481     GTEST_LOG_(INFO) << "DaemonTest_NotifyRemoteCancelNotification_001";
1482 }
1483 } // namespace Test
1484 } // namespace OHOS::Storage::DistributedFile