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 <fcntl.h>
17 #include <gtest/gtest.h>
18 #include <gmock/gmock.h>
19 #include <variant>
20 #include "accesstoken_kit.h"
21 #include "default_clip.h"
22 #include "dev_profile.h"
23 #include "distributed_file_daemon_manager.h"
24 #include "input_method_controller.h"
25 #include "input_method_property.h"
26 #include "ipc_skeleton.h"
27 #include "parameters.h"
28 #include "pasteboard_error.h"
29 #include "pasteboard_hilog.h"
30 #include "pasteboard_service.h"
31 #include "remote_file_share.h"
32 #include "eventcenter/pasteboard_event.h"
33
34 using namespace testing;
35 using namespace testing::ext;
36 using namespace OHOS;
37 using namespace OHOS::MiscServices;
38 using namespace std::chrono;
39 using namespace OHOS::Security::AccessToken;
40 using namespace OHOS::AppFileService::ModuleRemoteFileShare;
41 using namespace OHOS::Storage::DistributedFile;
42 namespace OHOS {
43 namespace {
44 const int32_t INT32_TEN = 10;
45 const int32_t INT32_ZERO = 0;
46 const int32_t INT32_TWO = 2;
47 const int32_t ACCOUNT_IDS_RANDOM = 1121;
48 const uint32_t UINT32_ONE = 1;
49 const int INT_ONE = 1;
50 const uint8_t UINT8_ONE = 1;
51 const int32_t INT32_NEGATIVE_NUMBER = -1;
52 const pid_t TEST_SERVER_UID = 3500;
53 const int64_t INT64_NEGATIVE_NUMBER = -1;
54 const uint32_t UINT32_EXCEPTION_APPID = 9999985;
55 const int INT_THREETHREETHREE = 333;
56 const uint32_t MAX_RECOGNITION_LENGTH = 1000;
57 const int64_t MIN_ASHMEM_DATA_SIZE = 32 * 1024;
58 const int32_t CONTROL_TYPE_ALLOW_SEND_RECEIVE = 1;
59 const int32_t DEVICE_COLLABORATION_UID = 5521;
60 const std::string RANDOM_STRING = "TEST_string_111";
61 const std::string URI_STRING = "https://www.a.com/";
62 const std::string HTML_STRING =
63 R"(<!DOCTYPE html><html lang="en"><head><title>S</title></head><body><h1>H</h1></body></html>)";
64 const char *MIMETYPE_TEXT_HTML = "text/html";
65 const std::u16string RANDOM_U16STRING = u"TEST_string_111";
66 using TestEvent = ClipPlugin::GlobalEvent;
67 }
68
69 class MyTestEntityRecognitionObserver : public IEntityRecognitionObserver {
OnRecognitionEvent(EntityType entityType,std::string & entity)70 void OnRecognitionEvent(EntityType entityType, std::string &entity)
71 {
72 return;
73 }
AsObject()74 sptr<IRemoteObject> AsObject()
75 {
76 return nullptr;
77 }
78 };
79
80 class MyTestPasteboardChangedObserver : public IPasteboardChangedObserver {
OnPasteboardChanged()81 void OnPasteboardChanged()
82 {
83 return;
84 }
OnPasteboardEvent(std::string bundleName,int32_t status)85 void OnPasteboardEvent(std::string bundleName, int32_t status)
86 {
87 return;
88 }
AsObject()89 sptr<IRemoteObject> AsObject()
90 {
91 return nullptr;
92 }
93 };
94
95 static int g_recordValueByType = static_cast<int32_t>(PasteboardError::E_OK);
96 class PasteboardEntryGetterImpl : public IPasteboardEntryGetter {
97 public:
PasteboardEntryGetterImpl()98 PasteboardEntryGetterImpl() {};
~PasteboardEntryGetterImpl()99 ~PasteboardEntryGetterImpl() {};
GetRecordValueByType(uint32_t recordId,PasteDataEntry & value)100 int32_t GetRecordValueByType(uint32_t recordId, PasteDataEntry &value)
101 {
102 return g_recordValueByType;
103 };
AsObject()104 sptr<IRemoteObject> AsObject()
105 {
106 return nullptr;
107 };
108 };
109
110 class PasteboardDelayGetterImpl : public IPasteboardDelayGetter {
111 public:
PasteboardDelayGetterImpl()112 PasteboardDelayGetterImpl() {}
~PasteboardDelayGetterImpl()113 ~PasteboardDelayGetterImpl() {}
GetPasteData(const std::string & type,PasteData & data)114 void GetPasteData(const std::string &type, PasteData &data) {};
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)115 void GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) {};
AsObject()116 sptr<IRemoteObject> AsObject()
117 {
118 return nullptr;
119 }
120 };
121
122 class DistributedFileDaemonManager {
123 public:
DistributedFileDaemonManager()124 DistributedFileDaemonManager() {}
~DistributedFileDaemonManager()125 ~DistributedFileDaemonManager() {}
126 int CloseP2PConnection(DmDeviceInfo &remoteDevice);
127 };
128
129 class PasteboardServiceInterface {
130 public:
PasteboardServiceInterface()131 PasteboardServiceInterface(){};
~PasteboardServiceInterface()132 virtual ~PasteboardServiceInterface(){};
133
134 virtual OHOS::ErrCode QueryActiveOsAccountIds(std::vector<int32_t> &ids);
135 virtual bool Decode(const std::vector<std::uint8_t> &buffer) = 0;
136 virtual bool Encode(std::vector<uint8_t> &buffer) const = 0;
137 virtual pid_t GetCallingUid() = 0;
138 virtual uint32_t GetCallingTokenID() = 0;
139 virtual uint64_t GetCallingFullTokenID() = 0;
140 virtual pid_t GetCallingPid() = 0;
141 virtual bool HasContent(const std::string &utdId) const = 0;
142 virtual std::shared_ptr<PasteDataRecord> GetRecordById(uint32_t recordId) const = 0;
143 virtual std::shared_ptr<PasteDataEntry> GetEntry(const std::string &utdType) = 0;
144 virtual bool IsOn() const = 0;
145 virtual bool IsDelayData() const = 0;
146 virtual bool IsDelayRecord() const = 0;
147 virtual int GetRemoteDeviceInfo(const std::string &networkId, DmDeviceInfo &remoteDevice) = 0;
148 virtual int CloseP2PConnection(DmDeviceInfo &remoteDevice) = 0;
149 virtual int VerifyAccessToken(AccessTokenID tokenID, const std::string &permissionName) = 0;
150 virtual ATokenTypeEnum GetTokenTypeFlag(AccessTokenID tokenId) = 0;
151 virtual std::vector<std::string> GetMimeTypes() = 0;
152 virtual std::string GetNetworkId() = 0;
153 virtual int GetIntParameter(const std::string &key, int def, int min, int max) = 0;
154 virtual uint32_t GetRemoteDeviceMinVersion() = 0;
155 virtual int32_t GetDfsUriFromLocal(
156 const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui) = 0;
157 virtual std::vector<std::shared_ptr<PasteDataRecord>> AllRecords() = 0;
158 virtual bool Dump(int fd, const std::vector<std::string> &args) const = 0;
159 virtual sptr<InputMethodController> GetInstance() = 0;
160 virtual void RegisterCommand(std::shared_ptr<Command> &cmd) = 0;
161 virtual int32_t GetDefaultInputMethod(std::shared_ptr<MiscServices::Property> &property) = 0;
162 virtual bool GetBoolParameter(const std::string &key, bool defaultValue) = 0;
163 };
164
165 class PasteboardServiceInterfaceMock : public PasteboardServiceInterface {
166 public:
167 PasteboardServiceInterfaceMock();
168 ~PasteboardServiceInterfaceMock() override;
169
170 MOCK_METHOD1(QueryActiveOsAccountIds, OHOS::ErrCode(std::vector<int32_t> &ids));
171 MOCK_METHOD1(Decode, bool(const std::vector<std::uint8_t> &buffer));
172 MOCK_CONST_METHOD1(Encode, bool(std::vector<uint8_t> &buffer));
173 MOCK_METHOD0(GetCallingUid, pid_t());
174 MOCK_METHOD0(GetCallingTokenID, uint32_t());
175 MOCK_METHOD0(GetCallingFullTokenID, uint64_t());
176 MOCK_METHOD0(GetCallingPid, pid_t());
177 MOCK_CONST_METHOD1(HasContent, bool(const std::string &utdId));
178 MOCK_METHOD1(GetEntry, std::shared_ptr<PasteDataEntry>(const std::string &utdType));
179 MOCK_CONST_METHOD0(IsOn, bool());
180 MOCK_CONST_METHOD0(IsDelayData, bool());
181 MOCK_CONST_METHOD0(IsDelayRecord, bool());
182 MOCK_METHOD1(CloseP2PConnection, int(DmDeviceInfo &remoteDevice));
183 MOCK_METHOD2(GetRemoteDeviceInfo, int(const std::string &networkId, DmDeviceInfo &remoteDevice));
184 MOCK_CONST_METHOD1(GetRecordById, std::shared_ptr<PasteDataRecord>(uint32_t recordId));
185 MOCK_METHOD2(VerifyAccessToken, int(AccessTokenID tokenID, const std::string &permissionName));
186 MOCK_METHOD1(GetTokenTypeFlag, ATokenTypeEnum(AccessTokenID tokenId));
187 MOCK_METHOD0(GetMimeTypes, std::vector<std::string>());
188 MOCK_METHOD1(RegisterCommand, void(std::shared_ptr<Command> &cmd));
189 MOCK_METHOD0(GetNetworkId, std::string());
190 MOCK_METHOD4(GetIntParameter, int(const std::string &key, int def, int min, int max));
191 MOCK_METHOD0(GetRemoteDeviceMinVersion, uint32_t());
192 MOCK_METHOD3(GetDfsUriFromLocal, int32_t(
193 const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui));
194 MOCK_METHOD0(AllRecords, std::vector<std::shared_ptr<PasteDataRecord>>());
195 MOCK_METHOD0(GetInstance, sptr<InputMethodController>());
196 MOCK_CONST_METHOD2(Dump, bool(int fd, const std::vector<std::string> &args));
197 MOCK_METHOD1(GetDefaultInputMethod, int32_t(std::shared_ptr<MiscServices::Property> &property));
198 MOCK_METHOD2(GetBoolParameter, bool(const std::string &key, bool defaultValue));
199 };
200
201 static void *g_interface = nullptr;
202 static bool g_accountIds = false;
203 static bool g_encodeInsert = true;
204 static int g_encodeInsertCount = 0;
205
PasteboardServiceInterfaceMock()206 PasteboardServiceInterfaceMock::PasteboardServiceInterfaceMock()
207 {
208 g_interface = reinterpret_cast<void *>(this);
209 }
210
~PasteboardServiceInterfaceMock()211 PasteboardServiceInterfaceMock::~PasteboardServiceInterfaceMock()
212 {
213 g_interface = nullptr;
214 }
215
GetPasteboardServiceInterface()216 static PasteboardServiceInterface *GetPasteboardServiceInterface()
217 {
218 return reinterpret_cast<PasteboardServiceInterface *>(g_interface);
219 }
220
221 extern "C" {
GetDefaultInputMethod(std::shared_ptr<Property> & property)222 int32_t InputMethodController::GetDefaultInputMethod(std::shared_ptr<Property> &property)
223 {
224 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
225 if (interface == nullptr) {
226 return 0;
227 }
228 if (g_encodeInsert) {
229 property = std::make_shared<Property>();
230 }
231 return interface->GetDefaultInputMethod(property);
232 }
233
GetInstance()234 PasteboardDumpHelper &PasteboardDumpHelper::GetInstance()
235 {
236 static PasteboardDumpHelper instance;
237 return instance;
238 }
239
RegisterCommand(std::shared_ptr<Command> & cmd)240 void PasteboardDumpHelper::RegisterCommand(std::shared_ptr<Command> &cmd)
241 {
242 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
243 if (interface == nullptr) {
244 return;
245 }
246 return interface->RegisterCommand(cmd);
247 }
248
GetInstance()249 sptr<InputMethodController> InputMethodController::GetInstance()
250 {
251 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
252 if (interface == nullptr) {
253 return nullptr;
254 }
255 return interface->GetInstance();
256 }
257
Dump(int fd,const std::vector<std::string> & args) const258 bool PasteboardDumpHelper::Dump(int fd, const std::vector<std::string> &args) const
259 {
260 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
261 if (interface == nullptr) {
262 return false;
263 }
264 return interface->Dump(fd, args);
265 }
266
GetMimeTypes()267 std::vector<std::string> PasteData::GetMimeTypes()
268 {
269 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
270 if (interface == nullptr) {
271 return std::vector<std::string>();
272 }
273 return interface->GetMimeTypes();
274 }
275
IsOn()276 bool DistributedModuleConfig::IsOn()
277 {
278 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
279 if (interface == nullptr) {
280 return false;
281 }
282 return interface->IsOn();
283 }
284
IsDelayData() const285 bool PasteData::IsDelayData() const
286 {
287 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
288 if (interface == nullptr) {
289 return false;
290 }
291 return interface->IsDelayData();
292 }
293
IsDelayRecord() const294 bool PasteData::IsDelayRecord() const
295 {
296 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
297 if (interface == nullptr) {
298 return false;
299 }
300 return interface->IsDelayRecord();
301 }
302
GetRemoteDeviceInfo(const std::string & networkId,DmDeviceInfo & remoteDevice)303 int DMAdapter::GetRemoteDeviceInfo(const std::string &networkId, DmDeviceInfo &remoteDevice)
304 {
305 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
306 if (interface == nullptr) {
307 return false;
308 }
309 return interface->GetRemoteDeviceInfo(networkId, remoteDevice);
310 }
311
CloseP2PConnection(DmDeviceInfo & remoteDevice)312 int DistributedFileDaemonManager::CloseP2PConnection(DmDeviceInfo &remoteDevice)
313 {
314 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
315 if (interface == nullptr) {
316 return false;
317 }
318 return interface->CloseP2PConnection(remoteDevice);
319 }
320
GetEntry(const std::string & utdType)321 std::shared_ptr<PasteDataEntry> PasteDataRecord::GetEntry(const std::string &utdType)
322 {
323 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
324 if (interface == nullptr) {
325 return nullptr;
326 }
327 return interface->GetEntry(utdType);
328 }
329
GetRecordById(uint32_t recordId) const330 std::shared_ptr<PasteDataRecord> PasteData::GetRecordById(uint32_t recordId) const
331 {
332 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
333 if (interface == nullptr) {
334 return nullptr;
335 }
336 return interface->GetRecordById(recordId);
337 }
338
HasContent(const std::string & utdId) const339 bool PasteDataEntry::HasContent(const std::string &utdId) const
340 {
341 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
342 if (interface == nullptr) {
343 return false;
344 }
345 return interface->HasContent(utdId);
346 }
347
Encode(std::vector<uint8_t> & buffer,bool isRemote) const348 bool TLVWriteable::Encode(std::vector<uint8_t> &buffer, bool isRemote) const
349 {
350 (void)isRemote;
351 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
352 if (interface == nullptr) {
353 return false;
354 }
355 return interface->Encode(buffer);
356 }
357
Decode(const std::vector<uint8_t> & buffer)358 bool TLVReadable::Decode(const std::vector<uint8_t> &buffer)
359 {
360 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
361 if (interface == nullptr) {
362 return false;
363 }
364 return interface->Decode(buffer);
365 }
366
GetCallingUid()367 pid_t IPCSkeleton::GetCallingUid()
368 {
369 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
370 if (interface == nullptr) {
371 return false;
372 }
373 return interface->GetCallingUid();
374 }
375
GetCallingTokenID()376 uint32_t IPCSkeleton::GetCallingTokenID()
377 {
378 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
379 if (interface == nullptr) {
380 return false;
381 }
382 return interface->GetCallingTokenID();
383 }
384
GetCallingFullTokenID()385 uint64_t IPCSkeleton::GetCallingFullTokenID()
386 {
387 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
388 if (interface == nullptr) {
389 return false;
390 }
391 return interface->GetCallingFullTokenID();
392 }
393
GetCallingPid()394 pid_t IPCSkeleton::GetCallingPid()
395 {
396 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
397 if (interface == nullptr) {
398 return false;
399 }
400 return interface->GetCallingPid();
401 }
402
VerifyAccessToken(AccessTokenID tokenID,const std::string & permissionName)403 int AccessTokenKit::VerifyAccessToken(AccessTokenID tokenID, const std::string &permissionName)
404 {
405 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
406 if (interface == nullptr) {
407 return false;
408 }
409 return interface->VerifyAccessToken(tokenID, permissionName);
410 }
411
GetTokenTypeFlag(AccessTokenID tokenId)412 ATokenTypeEnum AccessTokenKit::GetTokenTypeFlag(AccessTokenID tokenId)
413 {
414 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
415 if (interface == nullptr) {
416 return ATokenTypeEnum::TOKEN_INVALID;
417 }
418 return interface->GetTokenTypeFlag(tokenId);
419 }
420
GetIntParameter(const std::string & key,int def,int min,int max)421 int GetIntParameter(const std::string &key, int def, int min, int max)
422 {
423 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
424 if (interface == nullptr) {
425 return INT32_NEGATIVE_NUMBER;
426 }
427 return interface->GetIntParameter(key, def, min, max);
428 }
429
GetRemoteDeviceMinVersion()430 uint32_t DistributedModuleConfig::GetRemoteDeviceMinVersion()
431 {
432 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
433 if (interface == nullptr) {
434 return UINT_MAX;
435 }
436 return interface->GetRemoteDeviceMinVersion();
437 }
438
GetDfsUriFromLocal(const std::string & uriStr,const int32_t & userId,struct HmdfsUriInfo & hui)439 int32_t RemoteFileShare::GetDfsUriFromLocal(
440 const std::string &uriStr, const int32_t &userId, struct HmdfsUriInfo &hui)
441 {
442 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
443 if (interface == nullptr) {
444 return UINT_MAX;
445 }
446 return interface->GetDfsUriFromLocal(uriStr, userId, hui);
447 }
448
AllRecords() const449 std::vector<std::shared_ptr<PasteDataRecord>> PasteData::AllRecords() const
450 {
451 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
452 if (interface == nullptr) {
453 return std::vector<std::shared_ptr<PasteDataRecord>>();
454 }
455 return interface->AllRecords();
456 }
457 }
458
GetBoolParameter(const std::string & key,bool defaultValue)459 bool OHOS::system::GetBoolParameter(const std::string &key, bool defaultValue)
460 {
461 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
462 if (interface == nullptr) {
463 return false;
464 }
465 return interface->GetBoolParameter(key, defaultValue);
466 }
467
468 namespace MiscServices {
SendPrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)469 int32_t InputMethodController::SendPrivateCommand(
470 const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
471 {
472 return 0;
473 }
474
ReceivePrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)475 int32_t InputMethodController::ReceivePrivateCommand(
476 const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
477 {
478 return 0;
479 }
480
InputMethodController()481 InputMethodController::InputMethodController() {}
482
~InputMethodController()483 InputMethodController::~InputMethodController() {}
484
GetNetworkId() const485 std::string PasteboardEvent::GetNetworkId() const
486 {
487 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
488 if (interface == nullptr) {
489 return "";
490 }
491 return interface->GetNetworkId();
492 }
493 }
494
495 namespace AccountSA {
QueryActiveOsAccountIds(std::vector<int32_t> & ids)496 OHOS::ErrCode OsAccountManager::QueryActiveOsAccountIds(std::vector<int32_t> &ids)
497 {
498 PasteboardServiceInterface *interface = GetPasteboardServiceInterface();
499 if (interface == nullptr) {
500 return -1;
501 }
502 ids.clear();
503 if (g_accountIds) {
504 ids.push_back(ACCOUNT_IDS_RANDOM);
505 }
506 return interface->QueryActiveOsAccountIds(ids);
507 }
508 }
509
510 class PasteboardServiceTest : public testing::Test {
511 public:
512 static void SetUpTestCase(void);
513 static void TearDownTestCase(void);
514 void SetUp();
515 void TearDown();
516 };
517
SetUpTestCase(void)518 void PasteboardServiceTest::SetUpTestCase(void) { }
519
TearDownTestCase(void)520 void PasteboardServiceTest::TearDownTestCase(void) { }
521
SetUp(void)522 void PasteboardServiceTest::SetUp(void) { }
523
TearDown(void)524 void PasteboardServiceTest::TearDown(void) { }
525
526 namespace MiscServices {
527 /**
528 * @tc.name: ClearTest002
529 * @tc.desc: test Func Clear
530 * @tc.type: FUNC
531 */
532 HWTEST_F(PasteboardServiceTest, ClearTest002, TestSize.Level0)
533 {
534 PasteboardService service;
535 service.currentUserId_ = ERROR_USERID;
536 NiceMock<PasteboardServiceInterfaceMock> mock;
537 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillOnce(Return(INT_ONE));
538 int32_t result = service.Clear();
539 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_USERID_ERROR));
540 }
541
542 /**
543 * @tc.name: GetRecordValueByTypeTest001
544 * @tc.desc: test Func GetRecordValueByType
545 * @tc.type: FUNC
546 */
547 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest001, TestSize.Level0)
548 {
549 PasteboardService service;
550 uint32_t dataId = 0;
551 uint32_t recordId = 0;
552 PasteDataEntry value;
553 value.SetUtdId(RANDOM_STRING);
554 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
555 auto data = std::make_shared<PasteData>();
556 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
557 auto entry = std::make_shared<PasteDataEntry>();
558 data->SetDataId(service.delayDataId_);
559 data->AddRecord(record);
560 data->SetRemote(true);
561 entry->SetMimeType(MIMETYPE_TEXT_HTML);
562 entry->SetValue(HTML_STRING);
563
564 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
565 NiceMock<PasteboardServiceInterfaceMock> mock;
566 EXPECT_CALL(mock, GetCallingTokenID()).WillOnce(Return(service.delayTokenId_.load()));
567 EXPECT_CALL(mock, HasContent(testing::_)).WillOnce(Return(false));
568 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
569 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry));
570
571 int32_t result = service.GetRecordValueByType(service.delayDataId_, recordId, value);
572 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::PLUGIN_IS_NULL));
573 }
574
575 /**
576 * @tc.name: GetRecordValueByTypeTest002
577 * @tc.desc: test Func GetRecordValueByType when paste data is html
578 * @tc.type: FUNC
579 */
580 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest002, TestSize.Level0)
581 {
582 PasteboardService service;
583 uint32_t dataId = 0;
584 uint32_t recordId = 0;
585 PasteDataEntry value;
586 value.SetUtdId(RANDOM_STRING);
587 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
588 auto data = std::make_shared<PasteData>();
589 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
590 auto entry = std::make_shared<PasteDataEntry>();
591 data->SetDataId(service.delayDataId_);
592 data->AddRecord(record);
593 data->SetRemote(false);
594 entry->SetMimeType(MIMETYPE_TEXT_HTML);
595 entry->SetValue(HTML_STRING);
596
597 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
598 NiceMock<PasteboardServiceInterfaceMock> mock;
599 EXPECT_CALL(mock, GetCallingTokenID()).WillOnce(Return(service.delayTokenId_.load()));
600 EXPECT_CALL(mock, HasContent(testing::_)).WillOnce(Return(true));
601 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
602 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry)).WillOnce(Return(entry));
603
604 int32_t result = service.GetRecordValueByType(service.delayDataId_, recordId, value);
605 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
606 }
607
608 /**
609 * @tc.name: GetRecordValueByTypeTest003
610 * @tc.desc: test Func GetRecordValueByType when paste data is url
611 * @tc.type: FUNC
612 */
613 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest003, TestSize.Level0)
614 {
615 PasteboardService service;
616 uint32_t dataId = 0;
617 uint32_t recordId = 0;
618 PasteDataEntry value;
619 value.SetUtdId(RANDOM_STRING);
620 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
621 auto data = std::make_shared<PasteData>();
622 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
623 auto entry = std::make_shared<PasteDataEntry>();
624 data->SetDataId(service.delayDataId_);
625 data->AddRecord(record);
626 data->SetRemote(false);
627 entry->SetMimeType(MIMETYPE_TEXT_URI);
628
629
630 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
631 NiceMock<PasteboardServiceInterfaceMock> mock;
632 EXPECT_CALL(mock, GetCallingTokenID()).WillOnce(Return(service.delayTokenId_.load()));
633 EXPECT_CALL(mock, HasContent(testing::_)).WillOnce(Return(true));
634 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
635 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry)).WillOnce(Return(entry));
636
637 int32_t result = service.GetRecordValueByType(service.delayDataId_, recordId, value);
638 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
639 }
640
641 /**
642 * @tc.name: GetRecordValueByTypeTest004
643 * @tc.desc: test Func GetRecordValueByType when paste Encode return false
644 * @tc.type: FUNC
645 */
646 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest004, TestSize.Level0)
647 {
648 PasteboardService service;
649 int64_t rawDataSize = 0;
650 std::vector<uint8_t> buffer;
651 int32_t fd = 0;
652 PasteDataEntry entryValue;
653
654 NiceMock<PasteboardServiceInterfaceMock> mock;
655 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(false));
656
657 int32_t result = service.GetRecordValueByType(rawDataSize, buffer, fd, entryValue);
658 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
659 }
660
661 /**
662 * @tc.name: GetRecordValueByTypeTest005
663 * @tc.desc: test Func GetRecordValueByType when paste rawDataSize < MIN_ASHMEM_DATA_SIZE
664 * @tc.type: FUNC
665 */
666 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest005, TestSize.Level0)
667 {
668 PasteboardService service;
669 int64_t rawDataSize = 0;
670 std::vector<uint8_t> buffer;
671 int32_t fd = 0;
672 PasteDataEntry entryValue;
673 g_encodeInsert = true;
674 g_encodeInsertCount = MIN_ASHMEM_DATA_SIZE + 1;
675 NiceMock<PasteboardServiceInterfaceMock> mock;
676 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
677
678 int32_t result = service.GetRecordValueByType(rawDataSize, buffer, fd, entryValue);
679 EXPECT_EQ(result, ERR_OK);
680 }
681
682 /**
683 * @tc.name: GetRecordValueByTypeTest006
684 * @tc.desc: test Func GetRecordValueByType when paste Encode return false
685 * @tc.type: FUNC
686 */
687 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest006, TestSize.Level0)
688 {
689 PasteboardService service;
690 int64_t rawDataSize = 0;
691 std::vector<uint8_t> buffer;
692 int32_t fd = 0;
693 PasteDataEntry entryValue;
694 g_encodeInsert = true;
695 g_encodeInsertCount = INT_THREETHREETHREE;
696 NiceMock<PasteboardServiceInterfaceMock> mock;
697 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
698
699 int32_t result = service.GetRecordValueByType(rawDataSize, buffer, fd, entryValue);
700 EXPECT_EQ(result, ERR_OK);
701 }
702
703 /**
704 * @tc.name: GetRecordValueByTypeTest007
705 * @tc.desc: test Func GetRecordValueByType rawDataSize == 0
706 * @tc.type: FUNC
707 */
708 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest007, TestSize.Level0)
709 {
710 PasteboardService service;
711 uint32_t dataId = 0;
712 uint32_t recordId = 0;
713 int64_t rawDataSize = INT64_NEGATIVE_NUMBER;
714 std::vector<uint8_t> buffer;
715 int fd = 0;
716
717 int32_t result = service.GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
718 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
719 }
720
721 /**
722 * @tc.name: GetRecordValueByTypeTest008
723 * @tc.desc: test Func GetRecordValueByType rawDataSize > DEFAULT_MAX_RAW_DATA_SIZE
724 * @tc.type: FUNC
725 */
726 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest008, TestSize.Level0)
727 {
728 PasteboardService service;
729 uint32_t dataId = 0;
730 uint32_t recordId = 0;
731 int64_t rawDataSize = INT64_MAX;
732 std::vector<uint8_t> buffer;
733 int fd = 0;
734
735 int32_t result = service.GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
736 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
737 }
738
739 /**
740 * @tc.name: GetRecordValueByTypeTest009
741 * @tc.desc: test Func GetRecordValueByType rawDataSize > MIN_ASHMEM_DATA_SIZE
742 * Decode return false
743 * @tc.type: FUNC
744 */
745 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest009, TestSize.Level0)
746 {
747 PasteboardService service;
748 uint32_t dataId = 0;
749 uint32_t recordId = 0;
750 int64_t rawDataSize = MIN_ASHMEM_DATA_SIZE + 1;
751 std::vector<uint8_t> buffer;
752 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
753 int fd = open("/dev/zero", O_RDWR);
754 std::vector<char> data(rawDataSize, 'a');
755 auto pasteData = std::make_shared<PasteData>();
756 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
757 auto entry = std::make_shared<PasteDataEntry>();
758 pasteData->SetDataId(service.delayDataId_);
759 pasteData->AddRecord(record);
760 pasteData->SetRemote(false);
761 entry->SetMimeType(MIMETYPE_TEXT_URI);
762 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, pasteData);
763 NiceMock<PasteboardServiceInterfaceMock> mock;
764 EXPECT_CALL(mock, Decode(testing::_)).WillRepeatedly(Return(false));
765 int32_t result = service.GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
766 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
767 close(fd);
768 }
769
770 /**
771 * @tc.name: GetRecordValueByTypeTest010
772 * @tc.desc: test Func GetRecordValueByType Decode return false
773 * @tc.type: FUNC
774 */
775 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest010, TestSize.Level0)
776 {
777 PasteboardService service;
778 uint32_t dataId = 0;
779 uint32_t recordId = 0;
780 int64_t rawDataSize = 1024;
781 std::vector<uint8_t> buffer;
782 int fd;
783 buffer.insert(buffer.end(), rawDataSize, UINT8_ONE);
784 NiceMock<PasteboardServiceInterfaceMock> mock;
785 EXPECT_CALL(mock, Decode(testing::_)).WillRepeatedly(Return(false));
786 int32_t result = service.GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
787 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
788 }
789
790 /**
791 * @tc.name: GetRecordValueByTypeTest011
792 * @tc.desc: test Func GetRecordValueByType second child GetRecordValueByType return false
793 * @tc.type: FUNC
794 */
795 HWTEST_F(PasteboardServiceTest, GetRecordValueByTypeTest011, TestSize.Level0)
796 {
797 PasteboardService service;
798 uint32_t dataId = 0;
799 uint32_t recordId = 0;
800 int64_t rawDataSize = 1024;
801 std::vector<uint8_t> buffer;
802 int fd;
803 buffer.insert(buffer.end(), rawDataSize, UINT8_ONE);
804 NiceMock<PasteboardServiceInterfaceMock> mock;
805
806 PasteDataEntry value;
807 value.SetUtdId(RANDOM_STRING);
808 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
809 auto data = std::make_shared<PasteData>();
810 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
811 auto entry = std::make_shared<PasteDataEntry>();
812 data->SetDataId(service.delayDataId_);
813 data->AddRecord(record);
814 data->SetRemote(false);
815 entry->SetMimeType(MIMETYPE_TEXT_URI);
816
817 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
818 EXPECT_CALL(mock, Decode(testing::_)).WillRepeatedly(Return(true));
819 EXPECT_CALL(mock, GetCallingTokenID()).WillOnce(Return(service.delayTokenId_.load()));
820 EXPECT_CALL(mock, HasContent(testing::_)).WillOnce(Return(true));
821 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
822 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry)).WillOnce(Return(entry));
823
824 int32_t result = service.GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
825 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
826 }
827
828 /**
829 * @tc.name: ShowProgressTest001
830 * @tc.desc: test Func ShowProgress HasPasteData return false
831 * @tc.type: FUNC
832 */
833 HWTEST_F(PasteboardServiceTest, ShowProgressTest001, TestSize.Level0)
834 {
835 PasteboardService service;
836 service.currentUserId_ = ERROR_USERID;
837 const std::string progressKey;
838 sptr<IRemoteObject> observer;
839 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, std::make_shared<PasteData>());
840 int32_t result = service.ShowProgress(progressKey, observer);
841 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
842 }
843
844 /**
845 * @tc.name: ShowProgressTest002
846 * @tc.desc: test Func ShowProgress IsFocusedApp return false
847 * @tc.type: FUNC
848 */
849 HWTEST_F(PasteboardServiceTest, ShowProgressTest002, TestSize.Level0)
850 {
851 PasteboardService service;
852 const std::string progressKey;
853 sptr<IRemoteObject> observer;
854 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
855 auto data = std::make_shared<PasteData>();
856 g_accountIds = true;
857 service.currentScreenStatus = ScreenEvent::ScreenUnlocked;
858 service.copyTime_.InsertOrAssign(ACCOUNT_IDS_RANDOM,
859 static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count()));
860 auto tokenId = IPCSkeleton::GetCallingTokenID();
861
862 data->SetScreenStatus(ScreenEvent::ScreenUnlocked);
863 data->SetShareOption(ShareOption::LocalDevice);
864 data->SetTokenId(IPCSkeleton::GetCallingTokenID());
865 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
866 NiceMock<PasteboardServiceInterfaceMock> mock;
867 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
868 EXPECT_CALL(mock, GetCallingTokenID()).WillRepeatedly(Return(tokenId + UINT32_EXCEPTION_APPID));
869
870 int32_t result = service.ShowProgress(progressKey, observer);
871 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_DATA_ERROR));
872 }
873
874 /**
875 * @tc.name: ShowProgressTest003
876 * @tc.desc: test Func ShowProgress
877 * @tc.type: FUNC
878 */
879 HWTEST_F(PasteboardServiceTest, ShowProgressTest003, TestSize.Level0)
880 {
881 PasteboardService service;
882 const std::string progressKey;
883 sptr<IRemoteObject> observer;
884 service.currentUserId_ = ACCOUNT_IDS_RANDOM;
885 auto data = std::make_shared<PasteData>();
886 g_accountIds = true;
887 service.currentScreenStatus = ScreenEvent::ScreenUnlocked;
888 service.copyTime_.InsertOrAssign(ACCOUNT_IDS_RANDOM,
889 static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count()));
890
891 data->SetScreenStatus(ScreenEvent::ScreenUnlocked);
892 data->SetShareOption(ShareOption::LocalDevice);
893 data->SetTokenId(IPCSkeleton::GetCallingTokenID());
894 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
895 NiceMock<PasteboardServiceInterfaceMock> mock;
896 EXPECT_CALL(mock, GetTokenTypeFlag).WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
897 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE));
898 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
899
900 int32_t result = service.ShowProgress(progressKey, observer);
901 EXPECT_EQ(result, static_cast<int32_t>(ERR_OK));
902 }
903
904 /**
905 * @tc.name: HasPasteDataTest001
906 * @tc.desc: test Func HasPasteData
907 * @tc.type: FUNC
908 */
909 HWTEST_F(PasteboardServiceTest, HasPasteDataTest001, TestSize.Level0)
910 {
911 PasteboardService service;
912 bool flag = false;
913 int32_t result = service.HasPasteData(flag);
914 EXPECT_EQ(result, ERR_OK);
915 EXPECT_EQ(flag, false);
916 }
917
918 /**
919 * @tc.name: HasDataTypeTest003
920 * @tc.desc: currentScreenStatus is ScreenEvent::ScreenUnlocked.
921 * @tc.type: FUNC
922 */
923 HWTEST_F(PasteboardServiceTest, HasDataTypeTest003, TestSize.Level0)
924 {
925 auto tempPasteboard = std::make_shared<PasteboardService>();
926 ASSERT_NE(tempPasteboard, nullptr);
927 tempPasteboard->currentScreenStatus = ScreenEvent::ScreenUnlocked;
928 tempPasteboard->currentUserId_ = 1;
929 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
930 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
931 bool funcResult;
932 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
933 EXPECT_EQ(res, ERR_OK);
934 }
935
936 /**
937 * @tc.name: HasDataTypeTest004
938 * @tc.desc: clipPlugin_ is not nullptr
939 * @tc.type: FUNC
940 */
941 HWTEST_F(PasteboardServiceTest, HasDataTypeTest004, TestSize.Level0)
942 {
943 auto tempPasteboard = std::make_shared<PasteboardService>();
944 ASSERT_NE(tempPasteboard, nullptr);
945 tempPasteboard->currentScreenStatus = ScreenEvent::ScreenUnlocked;
946 tempPasteboard->currentUserId_ = 1;
947 std::string PLUGIN_NAME_VAL = "distributed_clip";
__anone99fc3ad0202(ClipPlugin *plugin) 948 auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
949 ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
950 };
951 tempPasteboard->clipPlugin_ =
952 std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
953 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
954 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(false));
955 bool funcResult;
956 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
957 EXPECT_EQ(res, ERR_OK);
958 }
959
960 /**
961 * @tc.name: GetPasteDataTest001
962 * @tc.desc: test Func GetPasteData
963 * @tc.type: FUNC
964 */
965 HWTEST_F(PasteboardServiceTest, GetPasteDataTest001, TestSize.Level0)
966 {
967 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
968 EXPECT_CALL(mock, GetTokenTypeFlag).WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
969 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
970 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
971 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE));
972 EXPECT_CALL(mock, VerifyAccessToken).WillOnce(Return(PermissionState::PERMISSION_GRANTED))
973 .WillOnce(Return(PermissionState::PERMISSION_GRANTED));
974 PasteboardService service;
975 int fd;
976 int64_t size;
977 std::vector<uint8_t> rawData;
978 int32_t syncTime;
979 int32_t result = service.GetPasteData(fd, size, rawData, "", syncTime);
980 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
981 }
982
983 /**
984 * @tc.name: GetPasteDataTest002
985 * @tc.desc: test Func GetPasteData
986 * @tc.type: FUNC
987 */
988 HWTEST_F(PasteboardServiceTest, GetPasteDataTest002, TestSize.Level0)
989 {
990 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
991 EXPECT_CALL(mock, GetTokenTypeFlag).WillOnce(Return(ATokenTypeEnum::TOKEN_HAP))
992 .WillOnce(Return(ATokenTypeEnum::TOKEN_HAP));
993 PasteboardService service;
994 service.setPasteDataUId_ = ERROR_USERID;
995 int fd;
996 int64_t size;
997 std::vector<uint8_t> rawData;
998 int32_t syncTime;
999 int32_t result = service.GetPasteData(fd, size, rawData, "", syncTime);
1000 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1001 }
1002
1003 /**
1004 * @tc.name: GetPasteDataTest003
1005 * @tc.desc: test Func GetPasteData
1006 * @tc.type: FUNC
1007 */
1008 HWTEST_F(PasteboardServiceTest, GetPasteDataTest003, TestSize.Level0)
1009 {
1010 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1011 EXPECT_CALL(mock, GetTokenTypeFlag).WillOnce(Return(ATokenTypeEnum::TOKEN_HAP))
1012 .WillOnce(Return(ATokenTypeEnum::TOKEN_HAP))
1013 .WillOnce(Return(ATokenTypeEnum::TOKEN_HAP));
1014 PasteboardService service;
1015 service.setPasteDataUId_ = TEST_SERVER_UID;
1016 int fd;
1017 int64_t size;
1018 std::vector<uint8_t> rawData;
1019 int32_t syncTime;
1020 int32_t result = service.GetPasteData(fd, size, rawData, "", syncTime);
1021 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
1022 }
1023
1024 /**
1025 * @tc.name: GetPasteDataInnerTest001
1026 * @tc.desc: test Func GetPasteDataInner
1027 * @tc.type: FUNC
1028 */
1029 HWTEST_F(PasteboardServiceTest, GetPasteDataInnerTest001, TestSize.Level0)
1030 {
1031 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1032 EXPECT_CALL(mock, GetTokenTypeFlag).WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
1033 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
1034 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE))
1035 .WillOnce(Return(ATokenTypeEnum::TOKEN_NATIVE));
1036 EXPECT_CALL(mock, VerifyAccessToken).WillOnce(Return(PermissionState::PERMISSION_GRANTED))
1037 .WillOnce(Return(PermissionState::PERMISSION_GRANTED));
1038 PasteboardService service;
1039 int fd;
1040 int64_t size;
1041 std::vector<uint8_t> rawData;
1042 int32_t syncTime;
1043 UeReportInfo ueReportInfo;
1044 int32_t result = service.GetPasteDataInner(fd, size, rawData, "", syncTime, ueReportInfo);
1045 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
1046 }
1047
1048 /**
1049 * @tc.name: SetAppShareOptionsTest001
1050 * @tc.desc: test Func SetAppShareOptions, it will be return INVALID_PARAM_ERROR.
1051 * @tc.type: FUNC
1052 */
1053 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest001, TestSize.Level0)
1054 {
1055 PasteboardService service;
1056 int32_t shareOptions = 1;
1057
1058 NiceMock<PasteboardServiceInterfaceMock> mock;
1059 EXPECT_CALL(mock, GetCallingFullTokenID).WillOnce(testing::Return(123));
1060 int32_t result = service.SetAppShareOptions(shareOptions);
1061 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
1062 }
1063
1064 /**
1065 * @tc.name: SetAppShareOptionsTest002
1066 * @tc.desc: test Func SetAppShareOptions, it will be return PERMISSION_VERIFICATION_ERROR.
1067 * @tc.type: FUNC
1068 */
1069 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest002, TestSize.Level0)
1070 {
1071 PasteboardService service;
1072 int32_t shareOptions = 0;
1073
1074 NiceMock<PasteboardServiceInterfaceMock> mock;
1075 EXPECT_CALL(mock, VerifyAccessToken).WillOnce(Return(PermissionState::PERMISSION_DENIED));
1076 EXPECT_CALL(mock, GetCallingFullTokenID).WillOnce(testing::Return(123));
1077 EXPECT_CALL(mock, GetCallingTokenID).WillOnce(testing::Return(1000));
1078 int32_t result = service.SetAppShareOptions(shareOptions);
1079 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1080 }
1081
1082 /**
1083 * @tc.name: SetAppShareOptionsTest003
1084 * @tc.desc: test Func SetAppShareOptions, it will be return PERMISSION_VERIFICATION_ERROR.
1085 * @tc.type: FUNC
1086 */
1087 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest003, TestSize.Level0)
1088 {
1089 PasteboardService service;
1090 int32_t shareOptions = 0;
1091
1092 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1093 EXPECT_CALL(ipcMock, VerifyAccessToken).WillOnce(Return(PermissionState::PERMISSION_DENIED));
1094 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967295));
1095 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
1096 int32_t result = service.SetAppShareOptions(shareOptions);
1097 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1098 }
1099
1100 /**
1101 * @tc.name: GetGlobalShareOptionTest001
1102 * @tc.desc: test Func GetGlobalShareOption, it will be return ERR_OK.
1103 * @tc.type: FUNC
1104 */
1105 HWTEST_F(PasteboardServiceTest, GetGlobalShareOptionTest001, TestSize.Level0)
1106 {
1107 PasteboardService service;
1108 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1109 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1110
1111 std::vector<uint32_t> tokenIds;
1112 std::unordered_map<uint32_t, int32_t> funcResult;
1113 int32_t result = service.GetGlobalShareOption(tokenIds, funcResult);
1114 ASSERT_EQ(result, ERR_OK);
1115 }
1116
1117 /**
1118 * @tc.name: GetGlobalShareOptionTest002
1119 * @tc.desc: test Func GetGlobalShareOption, it will be return PERMISSION_VERIFICATION_ERROR.
1120 * @tc.type: FUNC
1121 */
1122 HWTEST_F(PasteboardServiceTest, GetGlobalShareOptionTest002, TestSize.Level0)
1123 {
1124 PasteboardService service;
1125 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1126 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(0));
1127
1128 std::vector<uint32_t> tokenIds;
1129 std::unordered_map<uint32_t, int32_t> funcResult;
1130 int32_t result = service.GetGlobalShareOption(tokenIds, funcResult);
1131 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1132 }
1133
1134 /**
1135 * @tc.name: GetGlobalShareOptionTest003
1136 * @tc.desc: test Func GetGlobalShareOption, it will be return ERR_OK.
1137 * @tc.type: FUNC
1138 */
1139 HWTEST_F(PasteboardServiceTest, GetGlobalShareOptionTest003, TestSize.Level0)
1140 {
1141 PasteboardService service;
1142 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1143 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1144
1145 std::vector<uint32_t> tokenIds = {1, 2, 3};
1146 std::unordered_map<uint32_t, int32_t> funcResult;
1147 int32_t result = service.GetGlobalShareOption(tokenIds, funcResult);
1148 ASSERT_EQ(result, ERR_OK);
1149 }
1150
1151 /**
1152 * @tc.name: SetGlobalShareOptionTest001
1153 * @tc.desc: test Func SetGlobalShareOption, it will be return PERMISSION_VERIFICATION_ERROR.
1154 * @tc.type: FUNC
1155 */
1156 HWTEST_F(PasteboardServiceTest, SetGlobalShareOptionTest001, TestSize.Level0)
1157 {
1158 PasteboardService service;
1159 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1160 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(0));
1161
1162 std::unordered_map<uint32_t, int32_t> globalShareOptions = {{1, static_cast<int32_t>(InApp)}};
1163 int32_t result = service.SetGlobalShareOption(globalShareOptions);
1164 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1165 }
1166
1167 /**
1168 * @tc.name: SetGlobalShareOptionTest002
1169 * @tc.desc: test Func SetGlobalShareOption, it will be return ERR_OK.
1170 * @tc.type: FUNC
1171 */
1172 HWTEST_F(PasteboardServiceTest, SetGlobalShareOptionTest002, TestSize.Level0)
1173 {
1174 PasteboardService service;
1175 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1176 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1177
1178 std::unordered_map<uint32_t, int32_t> globalShareOptions =
1179 {{1, static_cast<int32_t>(InApp)}, {2, static_cast<int32_t>(CrossDevice)}};
1180 int32_t result = service.SetGlobalShareOption(globalShareOptions);
1181 ASSERT_EQ(result, ERR_OK);
1182 }
1183
1184 /**
1185 * @tc.name: SetGlobalShareOptionTest003
1186 * @tc.desc: test Func SetGlobalShareOption, it will be return ERR_OK.
1187 * @tc.type: FUNC
1188 */
1189 HWTEST_F(PasteboardServiceTest, SetGlobalShareOptionTest003, TestSize.Level0)
1190 {
1191 PasteboardService service;
1192 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1193 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1194
1195 std::unordered_map<uint32_t, int32_t> globalShareOptions = {{1, static_cast<int32_t>(InApp)}, {2, -1}};
1196 int32_t result = service.SetGlobalShareOption(globalShareOptions);
1197 ASSERT_EQ(result, ERR_OK);
1198 }
1199
1200 /**
1201 * @tc.name: UnsubscribeAllObserverTest001
1202 * @tc.desc: test Func UnsubscribeAllObserver, it will be return 0.
1203 * @tc.type: FUNC
1204 */
1205 HWTEST_F(PasteboardServiceTest, UnsubscribeAllObserverTest001, TestSize.Level0)
1206 {
1207 PasteboardService service;
1208 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1209 int32_t result = service.UnsubscribeAllObserver(type);
1210 ASSERT_EQ(result, 0);
1211 }
1212
1213 /**
1214 * @tc.name: UnsubscribeAllObserverTest002
1215 * @tc.desc: test Func UnsubscribeAllObserver, it will be return ERR_OK.
1216 * @tc.type: FUNC
1217 */
1218 HWTEST_F(PasteboardServiceTest, UnsubscribeAllObserverTest002, TestSize.Level0)
1219 {
1220 PasteboardService service;
1221 PasteboardObserverType type = PasteboardObserverType::OBSERVER_LOCAL;
1222 int32_t result = service.UnsubscribeAllObserver(type);
1223 ASSERT_EQ(result, ERR_OK);
1224 }
1225
1226 /**
1227 * @tc.name: UnsubscribeAllObserverTest003
1228 * @tc.desc: test Func UnsubscribeAllObserver, it will be return ERR_OK.
1229 * @tc.type: FUNC
1230 */
1231 HWTEST_F(PasteboardServiceTest, UnsubscribeAllObserverTest003, TestSize.Level0)
1232 {
1233 PasteboardService service;
1234 PasteboardObserverType type = PasteboardObserverType::OBSERVER_REMOTE;
1235
1236 int32_t result = service.UnsubscribeAllObserver(type);
1237 ASSERT_EQ(result, ERR_OK);
1238 }
1239
1240 /**
1241 * @tc.name: UnsubscribeAllObserverTest004
1242 * @tc.desc: test Func UnsubscribeAllObserver, it will be return ERR_OK.
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(PasteboardServiceTest, UnsubscribeAllObserverTest004, TestSize.Level0)
1246 {
1247 PasteboardService service;
1248 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1249 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1250 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1251
1252 int32_t result = service.UnsubscribeAllObserver(type);
1253 ASSERT_EQ(result, ERR_OK);
1254 }
1255
1256 /**
1257 * @tc.name: UnsubscribeObserverTest001
1258 * @tc.desc: test Func UnsubscribeObserver, it will be return 0.
1259 * @tc.type: FUNC
1260 */
1261 HWTEST_F(PasteboardServiceTest, UnsubscribeObserverTest001, TestSize.Level0)
1262 {
1263 PasteboardService service;
1264
1265 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1266 sptr<IPasteboardChangedObserver> observer = nullptr;
1267 int32_t result = service.UnsubscribeObserver(type, observer);
1268 ASSERT_EQ(result, 0);
1269 }
1270
1271 /**
1272 * @tc.name: UnsubscribeObserverTest002
1273 * @tc.desc: test Func UnsubscribeObserver, it will be return ERR_OK.
1274 * @tc.type: FUNC
1275 */
1276 HWTEST_F(PasteboardServiceTest, UnsubscribeObserverTest002, TestSize.Level0)
1277 {
1278 PasteboardService service;
1279 PasteboardObserverType type = PasteboardObserverType::OBSERVER_LOCAL;
1280 sptr<IPasteboardChangedObserver> observer = nullptr;
1281 int32_t result = service.UnsubscribeObserver(type, observer);
1282 ASSERT_EQ(result, ERR_OK);
1283 }
1284
1285 /**
1286 * @tc.name: UnsubscribeObserverTest003
1287 * @tc.desc: test Func UnsubscribeObserver, it will be return ERR_OK.
1288 * @tc.type: FUNC
1289 */
1290 HWTEST_F(PasteboardServiceTest, UnsubscribeObserverTest003, TestSize.Level0)
1291 {
1292 PasteboardService service;
1293 PasteboardObserverType type = PasteboardObserverType::OBSERVER_REMOTE;
1294 sptr<IPasteboardChangedObserver> observer = nullptr;
1295 int32_t result = service.UnsubscribeObserver(type, observer);
1296 ASSERT_EQ(result, ERR_OK);
1297 }
1298
1299 /**
1300 * @tc.name: UnsubscribeObserverTest004
1301 * @tc.desc: test Func UnsubscribeObserver, it will be return ERR_OK.
1302 * @tc.type: FUNC
1303 */
1304 HWTEST_F(PasteboardServiceTest, UnsubscribeObserverTest004, TestSize.Level0)
1305 {
1306 PasteboardService service;
1307 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1308 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1309
1310 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1311 sptr<IPasteboardChangedObserver> observer = nullptr;
1312 int32_t result = service.UnsubscribeObserver(type, observer);
1313 ASSERT_EQ(result, ERR_OK);
1314 }
1315
1316 /**
1317 * @tc.name: UnsubscribeObserverTest005
1318 * @tc.desc: test Func UnsubscribeObserver, it will be return ERR_OK.
1319 * @tc.type: FUNC
1320 */
1321 HWTEST_F(PasteboardServiceTest, UnsubscribeObserverTest005, TestSize.Level0)
1322 {
1323 PasteboardService service;
1324 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1325 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(0));
1326
1327 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1328 sptr<IPasteboardChangedObserver> observer = nullptr;
1329 int32_t result = service.UnsubscribeObserver(type, observer);
1330 ASSERT_EQ(result, ERR_OK);
1331 }
1332
1333 /**
1334 * @tc.name: SubscribeObserverTest001
1335 * @tc.desc: test Func SubscribeObserver, it will be return 0.
1336 * @tc.type: FUNC
1337 */
1338 HWTEST_F(PasteboardServiceTest, SubscribeObserverTest001, TestSize.Level0)
1339 {
1340 PasteboardService service;
1341
1342 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1343 sptr<IPasteboardChangedObserver> observer = nullptr;
1344 int32_t result = service.SubscribeObserver(type, observer);
1345 ASSERT_EQ(result, 0);
1346 }
1347
1348 /**
1349 * @tc.name: SubscribeObserverTest002
1350 * @tc.desc: test Func SubscribeObserver, it will be return ERR_OK.
1351 * @tc.type: FUNC
1352 */
1353 HWTEST_F(PasteboardServiceTest, SubscribeObserverTest002, TestSize.Level0)
1354 {
1355 PasteboardService service;
1356 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1357 EXPECT_CALL(ipcMock, GetCallingPid()).WillOnce(testing::Return(1234));
1358
1359 PasteboardObserverType type = PasteboardObserverType::OBSERVER_LOCAL;
1360 sptr<IPasteboardChangedObserver> observer = nullptr;
1361 int32_t result = service.SubscribeObserver(type, observer);
1362 ASSERT_EQ(result, ERR_OK);
1363 }
1364
1365 /**
1366 * @tc.name: SubscribeObserverTest003
1367 * @tc.desc: test Func SubscribeObserver, it will be return ERR_OK.
1368 * @tc.type: FUNC
1369 */
1370 HWTEST_F(PasteboardServiceTest, SubscribeObserverTest003, TestSize.Level0)
1371 {
1372 PasteboardService service;
1373 PasteboardObserverType type = PasteboardObserverType::OBSERVER_REMOTE;
1374 sptr<IPasteboardChangedObserver> observer = nullptr;
1375 int32_t result = service.SubscribeObserver(type, observer);
1376 ASSERT_EQ(result, ERR_OK);
1377 }
1378
1379 /**
1380 * @tc.name: SubscribeObserverTest004
1381 * @tc.desc: test Func SubscribeObserver, it will be return ERR_OK.
1382 * @tc.type: FUNC
1383 */
1384 HWTEST_F(PasteboardServiceTest, SubscribeObserverTest004, TestSize.Level0)
1385 {
1386 PasteboardService service;
1387 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1388 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(PasteboardService::EDM_UID));
1389 EXPECT_CALL(ipcMock, GetCallingPid()).WillOnce(testing::Return(1234));
1390
1391 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1392 sptr<IPasteboardChangedObserver> observer = nullptr;
1393 int32_t result = service.SubscribeObserver(type, observer);
1394 ASSERT_EQ(result, ERR_OK);
1395 }
1396
1397 /**
1398 * @tc.name: SubscribeObserverTest005
1399 * @tc.desc: test Func SubscribeObserver, it will be return ERR_OK.
1400 * @tc.type: FUNC
1401 */
1402 HWTEST_F(PasteboardServiceTest, SubscribeObserverTest005, TestSize.Level0)
1403 {
1404 PasteboardService service;
1405 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1406 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(0));
1407 EXPECT_CALL(ipcMock, GetCallingPid()).WillOnce(testing::Return(1234));
1408
1409 PasteboardObserverType type = PasteboardObserverType::OBSERVER_EVENT;
1410 sptr<IPasteboardChangedObserver> observer = nullptr;
1411 int32_t result = service.SubscribeObserver(type, observer);
1412 ASSERT_EQ(result, ERR_OK);
1413 }
1414
1415 /**
1416 * @tc.name: RemoveGlobalShareOptionTest001
1417 * @tc.desc: GetAllObserversSize function test
1418 * @tc.type: FUNC
1419 */
1420 HWTEST_F(PasteboardServiceTest, RemoveGlobalShareOptionTest001, TestSize.Level0)
1421 {
1422 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest001 start.");
1423
1424 std::vector<uint32_t> tokenIds = { 1001, 1002, 1003 };
1425 auto tempPasteboard = std::make_shared<PasteboardService>();
1426 EXPECT_NE(tempPasteboard, nullptr);
1427 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1428 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(-1));
1429 auto ret = tempPasteboard->RemoveGlobalShareOption(tokenIds);
1430 ASSERT_EQ(ret, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
1431 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest001 end.");
1432 }
1433
1434 /**
1435 * @tc.name: RemoveGlobalShareOptionTest002
1436 * @tc.desc: RemoveGlobalShareOption function test
1437 * @tc.type: FUNC
1438 */
1439 HWTEST_F(PasteboardServiceTest, RemoveGlobalShareOptionTest002, TestSize.Level0)
1440 {
1441 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveGlobalShareOptionTest002 start.");
1442 std::vector<uint32_t> tokenIds = { 1001, 1002, 1003 };
1443 auto tempPasteboard = std::make_shared<PasteboardService>();
1444 EXPECT_NE(tempPasteboard, nullptr);
1445 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1446 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(PasteboardService::EDM_UID));
1447 auto ret = tempPasteboard->RemoveGlobalShareOption(tokenIds);
1448 ASSERT_EQ(ret, ERR_OK);
1449 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveGlobalShareOptionTest002 end.");
1450 }
1451
1452 /**
1453 * @tc.name: RemoveAppShareOptionsTest003
1454 * @tc.desc: RemoveAppShareOptions function test
1455 * @tc.type: FUNC
1456 */
1457 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest003, TestSize.Level0)
1458 {
1459 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest003 start.");
1460 std::vector<uint32_t> tokenIds = {};
1461 auto tempPasteboard = std::make_shared<PasteboardService>();
1462 EXPECT_NE(tempPasteboard, nullptr);
1463 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1464 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(PasteboardService::EDM_UID));
1465 auto ret = tempPasteboard->RemoveGlobalShareOption(tokenIds);
1466 ASSERT_EQ(ret, ERR_OK);
1467 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest003 end.");
1468 }
1469
1470 /**
1471 * @tc.name: DumpDataTest001
1472 * @tc.desc: DumpData function test
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(PasteboardServiceTest, DumpDataTest001, TestSize.Level0)
1476 {
1477 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest001 start.");
1478 auto tempPasteboard = std::make_shared<PasteboardService>();
1479 EXPECT_NE(tempPasteboard, nullptr);
1480 NiceMock<PasteboardServiceInterfaceMock> mock;
1481 tempPasteboard->currentUserId_ = ERROR_USERID;
1482 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(INT_ONE));
1483 auto ret = tempPasteboard->DumpData();
1484 ASSERT_EQ(ret, "");
1485 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest001 end.");
1486 }
1487
1488 /**
1489 * @tc.name: DumpDataTest002
1490 * @tc.desc: DumpData function test
1491 * @tc.type: FUNC
1492 */
1493 HWTEST_F(PasteboardServiceTest, DumpDataTest002, TestSize.Level0)
1494 {
1495 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest002 start.");
1496 auto tempPasteboard = std::make_shared<PasteboardService>();
1497 EXPECT_NE(tempPasteboard, nullptr);
1498 std::string expectdStr;
1499 expectdStr.append("No copy data.").append("\n");
1500 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
1501 NiceMock<PasteboardServiceInterfaceMock> mock;
1502 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
1503 auto ret = tempPasteboard->DumpData();
1504 ASSERT_EQ(ret, expectdStr);
1505 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest002 end.");
1506 }
1507
1508 /**
1509 * @tc.name: DumpDataTest003
1510 * @tc.desc: DumpData function test
1511 * @tc.type: FUNC
1512 */
1513 HWTEST_F(PasteboardServiceTest, DumpDataTest003, TestSize.Level0)
1514 {
1515 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest003 start.");
1516 auto tempPasteboard = std::make_shared<PasteboardService>();
1517 EXPECT_NE(tempPasteboard, nullptr);
1518 std::string expectdStr;
1519 expectdStr.append("No copy data.").append("\n");
1520 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
1521 tempPasteboard->clips_.Insert(ACCOUNT_IDS_RANDOM, nullptr);
1522 NiceMock<PasteboardServiceInterfaceMock> mock;
1523 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
1524 auto ret = tempPasteboard->DumpData();
1525 ASSERT_EQ(ret, expectdStr);
1526 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest003 end.");
1527 }
1528
1529 /**
1530 * @tc.name: DumpDataTest004
1531 * @tc.desc: DumpData function test
1532 * @tc.type: FUNC
1533 */
1534 HWTEST_F(PasteboardServiceTest, DumpDataTest004, TestSize.Level0)
1535 {
1536 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest004 start.");
1537 auto tempPasteboard = std::make_shared<PasteboardService>();
1538 EXPECT_NE(tempPasteboard, nullptr);
1539 std::string expectdStr;
1540 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
1541 auto pasteData = std::make_shared<PasteData>();
1542 EXPECT_NE(pasteData, nullptr);
1543 size_t recordCounts = 1;
1544 auto tempRecord = std::make_shared<PasteDataRecord>();
1545 EXPECT_NE(tempRecord, nullptr);
1546 pasteData->records_.push_back(tempRecord);
1547 PasteDataProperty* pData = new PasteDataProperty();
1548 std::string sourceDevice = "remote";
1549 pData->isRemote = true;
1550 std::string bundleName = "pasteboard";
1551 pData->bundleName = bundleName;
1552 std::string setTime = "111111";
1553 pData->setTime = setTime;
1554 std::string shareOption = "InAPP";
1555 pData->shareOption = ShareOption::InApp;
1556 std::string mimeType = "text/plain";
1557 pData->mimeTypes.push_back(mimeType);
1558 pasteData->SetProperty(*pData);
1559 tempPasteboard->clips_.Insert(ACCOUNT_IDS_RANDOM, pasteData);
1560 expectdStr.append("|Owner : ")
1561 .append(bundleName)
1562 .append("\n")
1563 .append("|Timestamp : ")
1564 .append(setTime)
1565 .append("\n")
1566 .append("|Share Option: ")
1567 .append(shareOption)
1568 .append("\n")
1569 .append("|Record Count: ")
1570 .append(std::to_string(recordCounts))
1571 .append("\n")
1572 .append("|Mime types : {")
1573 .append(mimeType)
1574 .append(",")
1575 .append("}")
1576 .append("\n")
1577 .append("|source device: ")
1578 .append(sourceDevice);
1579 NiceMock<PasteboardServiceInterfaceMock> mock;
1580 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
1581 auto ret = tempPasteboard->DumpData();
1582 delete pData;
1583 ASSERT_EQ(ret, expectdStr);
1584 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest004 end.");
1585 }
1586
1587 /**
1588 * @tc.name: DumpDataTest005
1589 * @tc.desc: DumpData function test
1590 * @tc.type: FUNC
1591 */
1592 HWTEST_F(PasteboardServiceTest, DumpDataTest005, TestSize.Level0)
1593 {
1594 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest005 start.");
1595 auto tempPasteboard = std::make_shared<PasteboardService>();
1596 EXPECT_NE(tempPasteboard, nullptr);
1597 std::string expectdStr;
1598 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
1599 auto pasteData = std::make_shared<PasteData>();
1600 EXPECT_NE(pasteData, nullptr);
1601 size_t recordCounts = 1;
1602 auto tempRecord = std::make_shared<PasteDataRecord>();
1603 EXPECT_NE(tempRecord, nullptr);
1604 pasteData->records_.push_back(tempRecord);
1605 PasteDataProperty* pData = new PasteDataProperty();
1606 std::string sourceDevice = "local";
1607 std::string bundleName = "pasteboard";
1608 pData->bundleName = bundleName;
1609 std::string setTime = "111111";
1610 pData->setTime = setTime;
1611 std::string shareOption = "InAPP";
1612 pData->shareOption = ShareOption::InApp;
1613 pasteData->SetProperty(*pData);
1614 tempPasteboard->clips_.Insert(ACCOUNT_IDS_RANDOM, pasteData);
1615 expectdStr.append("|Owner : ")
1616 .append(bundleName)
1617 .append("\n")
1618 .append("|Timestamp : ")
1619 .append(setTime)
1620 .append("\n")
1621 .append("|Share Option: ")
1622 .append(shareOption)
1623 .append("\n")
1624 .append("|Record Count: ")
1625 .append(std::to_string(recordCounts))
1626 .append("\n")
1627 .append("|Mime types : {")
1628 .append("}")
1629 .append("\n")
1630 .append("|source device: ")
1631 .append(sourceDevice);
1632 NiceMock<PasteboardServiceInterfaceMock> mock;
1633 EXPECT_CALL(mock, QueryActiveOsAccountIds(testing::_)).WillRepeatedly(Return(ERR_OK));
1634 auto ret = tempPasteboard->DumpData();
1635 delete pData;
1636 ASSERT_EQ(ret, expectdStr);
1637 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest005 end.");
1638 }
1639
1640 /**
1641 * @tc.name: IsCallerUidValid001
1642 * @tc.desc: IsCallerUidValid001 function test
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(PasteboardServiceTest, IsCallerUidValid001, TestSize.Level0)
1646 {
1647 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid001 start.");
1648 auto tempPasteboard = std::make_shared<PasteboardService>();
1649 EXPECT_NE(tempPasteboard, nullptr);
1650 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1651 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(PasteboardService::EDM_UID));
1652 auto ret = tempPasteboard->IsCallerUidValid();
1653 ASSERT_EQ(ret, true);
1654 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid001 end.");
1655 }
1656
1657 /**
1658 * @tc.name: IsCallerUidValid002
1659 * @tc.desc: IsCallerUidValid002 function test
1660 * @tc.type: FUNC
1661 */
1662 HWTEST_F(PasteboardServiceTest, IsCallerUidValid002, TestSize.Level0)
1663 {
1664 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid002 start.");
1665 auto tempPasteboard = std::make_shared<PasteboardService>();
1666 EXPECT_NE(tempPasteboard, nullptr);
1667 tempPasteboard->uid_ = -1;
1668 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1669 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(-1));
1670 auto ret = tempPasteboard->IsCallerUidValid();
1671 ASSERT_EQ(ret, false);
1672 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid002 end.");
1673 }
1674
1675 /**
1676 * @tc.name: IsCallerUidValid003
1677 * @tc.desc: IsCallerUidValid003 function test
1678 * @tc.type: FUNC
1679 */
1680 HWTEST_F(PasteboardServiceTest, IsCallerUidValid003, TestSize.Level0)
1681 {
1682 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid003 start.");
1683 auto tempPasteboard = std::make_shared<PasteboardService>();
1684 EXPECT_NE(tempPasteboard, nullptr);
1685 tempPasteboard->uid_ = 1;
1686 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1687 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(-1));
1688 auto ret = tempPasteboard->IsCallerUidValid();
1689 ASSERT_EQ(ret, false);
1690 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid003 end.");
1691 }
1692
1693 /**
1694 * @tc.name: IsCallerUidValid004
1695 * @tc.desc: IsCallerUidValid004 function test
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(PasteboardServiceTest, IsCallerUidValid004, TestSize.Level0)
1699 {
1700 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid004 start.");
1701 auto tempPasteboard = std::make_shared<PasteboardService>();
1702 EXPECT_NE(tempPasteboard, nullptr);
1703 tempPasteboard->uid_ = -1;
1704 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1705 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(1));
1706 auto ret = tempPasteboard->IsCallerUidValid();
1707 ASSERT_EQ(ret, false);
1708 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid004 end.");
1709 }
1710
1711 /**
1712 * @tc.name: IsCallerUidValid005
1713 * @tc.desc: IsCallerUidValid005 function test
1714 * @tc.type: FUNC
1715 */
1716 HWTEST_F(PasteboardServiceTest, IsCallerUidValid005, TestSize.Level0)
1717 {
1718 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid005 start.");
1719 auto tempPasteboard = std::make_shared<PasteboardService>();
1720 EXPECT_NE(tempPasteboard, nullptr);
1721 tempPasteboard->uid_ = 1;
1722 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1723 EXPECT_CALL(ipcMock, GetCallingUid()).WillRepeatedly(testing::Return(1));
1724 auto ret = tempPasteboard->IsCallerUidValid();
1725 ASSERT_EQ(ret, true);
1726 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCallerUidValid005 end.");
1727 }
1728
1729 /**
1730 * @tc.name: GetDataSize001
1731 * @tc.desc: GetDataSize001 function test
1732 * @tc.type: FUNC
1733 */
1734 HWTEST_F(PasteboardServiceTest, GetDataSize001, TestSize.Level0)
1735 {
1736 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSize001 start.");
1737 auto tempPasteboard = std::make_shared<PasteboardService>();
1738 EXPECT_NE(tempPasteboard, nullptr);
1739 auto pasteData = std::make_shared<PasteData>();
1740 EXPECT_NE(pasteData, nullptr);
1741 size_t recordCounts = 1;
1742 auto tempRecord = std::make_shared<PasteDataRecord>();
1743 EXPECT_NE(tempRecord, nullptr);
1744 pasteData->records_.push_back(tempRecord);
1745 auto ret = tempPasteboard->GetDataSize(*pasteData);
1746 ASSERT_EQ(ret, 0);
1747 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSize001 end.");
1748 }
1749
1750 /**
1751 * @tc.name: GetDataSize002
1752 * @tc.desc: GetDataSize002 function test
1753 * @tc.type: FUNC
1754 */
1755 HWTEST_F(PasteboardServiceTest, GetDataSize002, TestSize.Level0)
1756 {
1757 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSize002 start.");
1758 auto tempPasteboard = std::make_shared<PasteboardService>();
1759 EXPECT_NE(tempPasteboard, nullptr);
1760 auto pasteData = std::make_shared<PasteData>();
1761 EXPECT_NE(pasteData, nullptr);
1762 auto ret = tempPasteboard->GetDataSize(*pasteData);
1763 ASSERT_EQ(ret, 0);
1764 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSize002 end.");
1765 }
1766
1767 /**
1768 * @tc.name: CloseDistributedStoreTest002
1769 * @tc.desc: test Func CloseDistributedStore
1770 * @tc.type: FUNC
1771 */
1772 HWTEST_F(PasteboardServiceTest, CloseDistributedStoreTest002, TestSize.Level0)
1773 {
1774 auto tempPasteboard = std::make_shared<PasteboardService>();
1775 EXPECT_NE(tempPasteboard, nullptr);
1776 int32_t user = 1;
1777 bool isNeedClear = true;
1778 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1779 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
1780 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
1781 EXPECT_EQ(tempPasteboard->GetClipPlugin(), nullptr);
1782 tempPasteboard->CloseDistributedStore(user, isNeedClear);
1783 }
1784
1785 /**
1786 * @tc.name: CloseDistributedStoreTest003
1787 * @tc.desc: test Func CloseDistributedStore
1788 * @tc.type: FUNC
1789 */
1790 HWTEST_F(PasteboardServiceTest, CloseDistributedStoreTest003, TestSize.Level0)
1791 {
1792 auto tempPasteboard = std::make_shared<PasteboardService>();
1793 EXPECT_NE(tempPasteboard, nullptr);
1794 int32_t user = 1;
1795 bool isNeedClear = true;
1796 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1797 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
1798 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
1799 tempPasteboard->clipPlugin_ = nullptr;
1800 EXPECT_NE(tempPasteboard->GetClipPlugin(), nullptr);
1801 EXPECT_NE(tempPasteboard->GetClipPlugin(), nullptr);
1802 tempPasteboard->CloseDistributedStore(user, isNeedClear);
1803 }
1804
1805 /**
1806 * @tc.name: CloseDistributedStoreTest004
1807 * @tc.desc: test Func CloseDistributedStore
1808 * @tc.type: FUNC
1809 */
1810 HWTEST_F(PasteboardServiceTest, CloseDistributedStoreTest004, TestSize.Level0)
1811 {
1812 auto tempPasteboard = std::make_shared<PasteboardService>();
1813 EXPECT_NE(tempPasteboard, nullptr);
1814 int32_t user = 1;
1815 bool isNeedClear = true;
1816 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1817 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(false));
1818 EXPECT_EQ(tempPasteboard->GetClipPlugin(), nullptr);
1819 tempPasteboard->CloseDistributedStore(user, isNeedClear);
1820 }
1821
1822 /**
1823 * @tc.name: OnConfigChangeTest001
1824 * @tc.desc: test Func OnConfigChange
1825 * @tc.type: FUNC
1826 */
1827 HWTEST_F(PasteboardServiceTest, OnConfigChangeTest001, TestSize.Level0)
1828 {
1829 auto tempPasteboard = std::make_shared<PasteboardService>();
1830 EXPECT_NE(tempPasteboard, nullptr);
1831 g_accountIds = false;
1832 tempPasteboard->currentUserId_ = 1;
1833 tempPasteboard->OnConfigChange(false);
1834 EXPECT_EQ(tempPasteboard->GetCurrentAccountId(), 1);
1835 }
1836
1837 /**
1838 * @tc.name: OnConfigChangeTest003
1839 * @tc.desc: test Func OnConfigChange
1840 * @tc.type: FUNC
1841 */
1842 HWTEST_F(PasteboardServiceTest, OnConfigChangeTest003, TestSize.Level0)
1843 {
1844 auto tempPasteboard = std::make_shared<PasteboardService>();
1845 EXPECT_NE(tempPasteboard, nullptr);
1846 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1847 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
1848 tempPasteboard->OnConfigChange(true);
1849 }
1850
1851 /**
1852 * @tc.name: OnConfigChangeTest004
1853 * @tc.desc: test Func OnConfigChange
1854 * @tc.type: FUNC
1855 */
1856 HWTEST_F(PasteboardServiceTest, OnConfigChangeTest004, TestSize.Level0)
1857 {
1858 auto tempPasteboard = std::make_shared<PasteboardService>();
1859 EXPECT_NE(tempPasteboard, nullptr);
1860 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1861 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL4;
1862 tempPasteboard->OnConfigChange(true);
1863 }
1864
1865 /**
1866 * @tc.name: OnConfigChangeTest005
1867 * @tc.desc: test Func OnConfigChange
1868 * @tc.type: FUNC
1869 */
1870 HWTEST_F(PasteboardServiceTest, OnConfigChangeTest005, TestSize.Level0)
1871 {
1872 auto tempPasteboard = std::make_shared<PasteboardService>();
1873 EXPECT_NE(tempPasteboard, nullptr);
1874 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1875 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL4;
1876 tempPasteboard->OnConfigChange(true);
1877 }
1878
1879 /**
1880 * @tc.name: PasteboardEventSubscriberTest001
1881 * @tc.desc: test Func PasteboardEventSubscriber
1882 * @tc.type: FUNC
1883 */
1884 HWTEST_F(PasteboardServiceTest, PasteboardEventSubscriberTest001, TestSize.Level0)
1885 {
1886 auto tempPasteboard = std::make_shared<PasteboardService>();
1887 EXPECT_NE(tempPasteboard, nullptr);
1888 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1889 EXPECT_CALL(mock, GetNetworkId()).WillRepeatedly(testing::Return(""));
1890 tempPasteboard->PasteboardEventSubscriber();
1891 }
1892
1893 /**
1894 * @tc.name: PasteboardEventSubscriberTest002
1895 * @tc.desc: test Func PasteboardEventSubscriber
1896 * @tc.type: FUNC
1897 */
1898 HWTEST_F(PasteboardServiceTest, PasteboardEventSubscriberTest002, TestSize.Level0)
1899 {
1900 auto tempPasteboard = std::make_shared<PasteboardService>();
1901 EXPECT_NE(tempPasteboard, nullptr);
1902 std::string networkId = "networkId1";
1903 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1904 EXPECT_CALL(mock, GetNetworkId()).WillRepeatedly(testing::Return(networkId));
1905 int32_t pid = 1234;
1906 std::string key = "key1";
1907 ConcurrentMap<std::string, int32_t> p2pMap;
1908 p2pMap.Insert(key, pid);
1909 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
1910 tempPasteboard->PasteboardEventSubscriber();
1911 EXPECT_NE(tempPasteboard->p2pMap_.Size(), 0);
1912 }
1913
1914 /**
1915 * @tc.name: PasteboardEventSubscriberTest003
1916 * @tc.desc: test Func PasteboardEventSubscriber
1917 * @tc.type: FUNC
1918 */
1919 HWTEST_F(PasteboardServiceTest, PasteboardEventSubscriberTest003, TestSize.Level0)
1920 {
1921 auto tempPasteboard = std::make_shared<PasteboardService>();
1922 EXPECT_NE(tempPasteboard, nullptr);
1923 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
1924 EXPECT_CALL(mock, GetNetworkId()).WillRepeatedly(testing::Return("networkId1"));
1925 int32_t pid = 1234;
1926 std::string key = "key1";
1927 ConcurrentMap<std::string, int32_t> p2pMap;
1928 p2pMap.Insert(key, pid);
1929 tempPasteboard->p2pMap_.Insert("networkId2", p2pMap);
1930 tempPasteboard->PasteboardEventSubscriber();
1931 EXPECT_NE(tempPasteboard->p2pMap_.Size(), 0);
1932 }
1933
1934 /**
1935 * @tc.name: SetDistributedDataTest001
1936 * @tc.desc: test Func SetDistributedData, IsAllowSendData is false
1937 * @tc.type: FUNC
1938 */
1939 HWTEST_F(PasteboardServiceTest, SetDistributedDataTest001, TestSize.Level0)
1940 {
1941 PasteboardService service;
1942 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1943 EXPECT_CALL(ipcMock, GetIntParameter(testing::_, testing::_, testing::_, testing::_))
1944 .WillRepeatedly(testing::Return(INT32_NEGATIVE_NUMBER));
1945
1946 PasteData pasteData;
1947 int32_t result = service.SetDistributedData(ACCOUNT_IDS_RANDOM, pasteData);
1948 EXPECT_EQ(result, false);
1949 }
1950
1951 /**
1952 * @tc.name: SetDistributedDataTest002
1953 * @tc.desc: test Func SetDistributedData, IsDisallowDistributed is true
1954 * @tc.type: FUNC
1955 */
1956 HWTEST_F(PasteboardServiceTest, SetDistributedDataTest002, TestSize.Level0)
1957 {
1958 PasteboardService service;
1959 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1960 EXPECT_CALL(ipcMock, GetIntParameter(testing::_, testing::_, testing::_, testing::_))
1961 .WillRepeatedly(testing::Return(CONTROL_TYPE_ALLOW_SEND_RECEIVE));
1962 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(DEVICE_COLLABORATION_UID));
1963
1964 PasteData pasteData;
1965 int32_t result = service.SetDistributedData(ACCOUNT_IDS_RANDOM, pasteData);
1966 EXPECT_EQ(result, false);
1967 }
1968
1969 /**
1970 * @tc.name: SetDistributedDataTest003
1971 * @tc.desc: test Func SetDistributedData, clipPlugin == nullptr
1972 * @tc.type: FUNC
1973 */
1974 HWTEST_F(PasteboardServiceTest, SetDistributedDataTest003, TestSize.Level0)
1975 {
1976 PasteboardService service;
1977 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1978 EXPECT_CALL(ipcMock, GetIntParameter(testing::_, testing::_, testing::_, testing::_))
1979 .WillRepeatedly(testing::Return(CONTROL_TYPE_ALLOW_SEND_RECEIVE));
1980 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(1234));
1981
1982 service.securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
1983 PasteData pasteData;
1984 int32_t result = service.SetDistributedData(ACCOUNT_IDS_RANDOM, pasteData);
1985 EXPECT_EQ(result, false);
1986 }
1987
1988 /**
1989 * @tc.name: SetDistributedDataTest004
1990 * @tc.desc: test Func SetDistributedData, return true
1991 * @tc.type: FUNC
1992 */
1993 HWTEST_F(PasteboardServiceTest, SetDistributedDataTest004, TestSize.Level0)
1994 {
1995 PasteboardService service;
1996 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
1997 EXPECT_CALL(ipcMock, GetIntParameter(testing::_, testing::_, testing::_, testing::_))
1998 .WillRepeatedly(testing::Return(CONTROL_TYPE_ALLOW_SEND_RECEIVE));
1999 EXPECT_CALL(ipcMock, GetCallingUid()).WillOnce(testing::Return(1234));
2000
2001 PasteData pasteData;
2002 int32_t result = service.SetDistributedData(ACCOUNT_IDS_RANDOM, pasteData);
2003 EXPECT_EQ(result, false);
2004 }
2005
2006 /**
2007 * @tc.name: SetCurrentDataTest001
2008 * @tc.desc: test Func SetCurrentData, clipPlugin == nullptr
2009 * @tc.type: FUNC
2010 */
2011 HWTEST_F(PasteboardServiceTest, SetCurrentDataTest001, TestSize.Level0)
2012 {
2013 PasteboardService service;
2014 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2015
2016 service.securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2017 TestEvent event;
2018 PasteData data;
2019 bool result = service.SetCurrentData(event, data);
2020 EXPECT_EQ(result, false);
2021 }
2022
2023 /**
2024 * @tc.name: SetCurrentDataTest002
2025 * @tc.desc: test Func SetCurrentData, needFull is true, encode is false
2026 * @tc.type: FUNC
2027 */
2028 HWTEST_F(PasteboardServiceTest, SetCurrentDataTest002, TestSize.Level0)
2029 {
2030 PasteboardService service;
2031 NiceMock<PasteboardServiceInterfaceMock> mock;
2032 service.securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
2033 std::string PLUGIN_NAME_VAL = "mock_clip";
__anone99fc3ad0302(ClipPlugin *plugin) 2034 auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
2035 ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
2036 };
2037 std::shared_ptr<ClipPlugin> clipPlugin =
2038 std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
2039 service.clipPlugin_ = clipPlugin;
2040 TestEvent event;
2041 PasteData data;
2042 data.AddTextRecord(RANDOM_STRING);
2043 data.SetDelayRecord(true);
2044 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2045 EXPECT_CALL(mock, GetRemoteDeviceMinVersion())
2046 .WillRepeatedly(testing::Return(DistributedModuleConfig::FIRST_VERSION));
2047
2048 bool result = service.SetCurrentData(event, data);
2049 EXPECT_EQ(result, false);
2050 }
2051
2052 /**
2053 * @tc.name: SetCurrentDataTest003
2054 * @tc.desc: test Func SetCurrentData, data.IsDelayRecord() && !needFull
2055 * @tc.type: FUNC
2056 */
2057 HWTEST_F(PasteboardServiceTest, SetCurrentDataTest003, TestSize.Level0)
2058 {
2059 PasteboardService service;
2060 NiceMock<PasteboardServiceInterfaceMock> mock;
2061 service.securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
2062 std::string PLUGIN_NAME_VAL = "mock_clip";
__anone99fc3ad0402(ClipPlugin *plugin) 2063 auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
2064 ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
2065 };
2066 std::shared_ptr<ClipPlugin> clipPlugin =
2067 std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
2068 service.clipPlugin_ = clipPlugin;
2069 TestEvent event;
2070 PasteData data;
2071 data.AddTextRecord(RANDOM_STRING);
2072 data.SetDelayRecord(true);
2073 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2074 EXPECT_CALL(mock, GetRemoteDeviceMinVersion())
2075 .WillRepeatedly(testing::Return(DistributedModuleConfig::FIRST_VERSION + 1));
2076 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
2077 bool result = service.SetCurrentData(event, data);
2078 EXPECT_EQ(result, true);
2079 }
2080
2081 /**
2082 * @tc.name: GetDistributedDelayEntryTest001
2083 * @tc.desc: test Func GetDistributedDelayEntry
2084 * @tc.type: FUNC
2085 */
2086 HWTEST_F(PasteboardServiceTest, GetDistributedDelayEntryTest001, TestSize.Level0)
2087 {
2088 PasteboardService service;
2089 TestEvent event;
2090 event.user = ACCOUNT_IDS_RANDOM;
2091 auto data = std::make_shared<PasteData>();
2092 EXPECT_NE(data, nullptr);
2093 auto record = PasteDataRecord::NewPlainTextRecord(RANDOM_STRING);
2094 data->SetDataId(service.delayDataId_);
2095 data->AddRecord(record);
2096 data->SetRemote(true);
2097 data->records_.emplace_back(record);
2098 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
2099 event.dataId == data->GetDataId();
2100 std::vector<uint8_t> rawData;
2101 auto entry = std::make_shared<PasteDataEntry>();
2102 entry->SetMimeType(MIMETYPE_TEXT_PLAIN);
2103
2104 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2105 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2106 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, service);
2107 service.entryGetters_.InsertOrAssign(
2108 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2109
2110 NiceMock<PasteboardServiceInterfaceMock> mock;
2111 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
2112 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry));
2113 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
2114 service.GetDistributedDelayEntry(event, data->GetRecordId(), RANDOM_STRING, rawData);
2115 }
2116
2117 /**
2118 * @tc.name: GetDistributedDelayEntryTest002
2119 * @tc.desc: test Func GetDistributedDelayEntry
2120 * @tc.type: FUNC
2121 */
2122 HWTEST_F(PasteboardServiceTest, GetDistributedDelayEntryTest002, TestSize.Level0)
2123 {
2124 PasteboardService service;
2125 TestEvent event;
2126 event.user = ACCOUNT_IDS_RANDOM;
2127 auto data = std::make_shared<PasteData>();
2128 EXPECT_NE(data, nullptr);
2129 OHOS::Uri uri("uri");
2130 auto record = PasteDataRecord::NewUriRecord(uri);
2131 data->SetDataId(service.delayDataId_);
2132 data->AddRecord(record);
2133 data->SetRemote(true);
2134 data->records_.emplace_back(record);
2135 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
2136 event.dataId == data->GetDataId();
2137 std::vector<uint8_t> rawData;
2138 auto entry = std::make_shared<PasteDataEntry>();
2139 entry->SetMimeType(MIMETYPE_TEXT_URI);
2140
2141 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2142 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2143 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, service);
2144 service.entryGetters_.InsertOrAssign(
2145 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2146
2147 NiceMock<PasteboardServiceInterfaceMock> mock;
2148 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
2149 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry));
2150 service.GetDistributedDelayEntry(event, data->GetRecordId(), RANDOM_STRING, rawData);
2151 }
2152
2153 /**
2154 * @tc.name: GetDistributedDelayEntryTest003
2155 * @tc.desc: test Func GetDistributedDelayEntry
2156 * @tc.type: FUNC
2157 */
2158 HWTEST_F(PasteboardServiceTest, GetDistributedDelayEntryTest003, TestSize.Level0)
2159 {
2160 PasteboardService service;
2161 TestEvent event;
2162 event.user = ACCOUNT_IDS_RANDOM;
2163 auto data = std::make_shared<PasteData>();
2164 EXPECT_NE(data, nullptr);
2165 auto record = PasteDataRecord::NewHtmlRecord(HTML_STRING);
2166 data->SetDataId(service.delayDataId_);
2167 data->AddRecord(record);
2168 data->SetRemote(true);
2169 data->records_.emplace_back(record);
2170 service.clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, data);
2171 event.dataId == data->GetDataId();
2172 std::vector<uint8_t> rawData;
2173 auto entry = std::make_shared<PasteDataEntry>();
2174 entry->SetMimeType(MIMETYPE_TEXT_HTML);
2175
2176 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2177 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2178 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, service);
2179 service.entryGetters_.InsertOrAssign(
2180 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2181
2182 NiceMock<PasteboardServiceInterfaceMock> mock;
2183 EXPECT_CALL(mock, GetRecordById(testing::_)).WillOnce(Return(record));
2184 EXPECT_CALL(mock, GetEntry(testing::_)).WillOnce(Return(entry));
2185 service.GetDistributedDelayEntry(event, data->GetRecordId(), RANDOM_STRING, rawData);
2186 }
2187
2188 /**
2189 * @tc.name: ProcessDistributedDelayUriTest003
2190 * @tc.desc: test Func ProcessDistributedDelayUri
2191 * @tc.type: FUNC
2192 */
2193 HWTEST_F(PasteboardServiceTest, ProcessDistributedDelayUriTest003, TestSize.Level0)
2194 {
2195 PasteboardService service;
2196
2197 PasteData data;
2198 OHOS::Uri uri("/");
2199 auto record = PasteDataRecord::NewUriRecord(uri);
2200 data.AddRecord(record);
2201
2202 auto entry = record->GetEntryByMimeType(MIMETYPE_TEXT_URI);
2203 auto utdId = CommonUtils::Convert2UtdId(UDMF::UDType::UD_BUTT, entry->GetMimeType());
2204 entry->SetUtdId(utdId);
2205 std::vector<uint8_t> rawData;
2206
2207 NiceMock<PasteboardServiceInterfaceMock> mock;
2208 struct HmdfsUriInfo dfsUri;
2209 EXPECT_CALL(mock, GetDfsUriFromLocal(testing::_, testing::_, testing::_))
__anone99fc3ad0502(auto, auto, struct HmdfsUriInfo &hui) 2210 .WillOnce([](auto, auto, struct HmdfsUriInfo &hui) {
2211 hui.uriStr = "uri";
2212 hui.fileSize = 0;
2213 return 0;
2214 });
2215 EXPECT_CALL(mock, Encode(testing::_)).WillOnce(Return(true));
2216 int32_t ret = service.ProcessDistributedDelayUri(ACCOUNT_IDS_RANDOM, data, *entry, rawData);
2217 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
2218 }
2219
2220 /**
2221 * @tc.name: GetClipPluginTest001
2222 * @tc.desc: test Func GetClipPlugin
2223 * @tc.type: FUNC
2224 */
2225 HWTEST_F(PasteboardServiceTest, GetClipPluginTest001, TestSize.Level0)
2226 {
2227 auto tempPasteboard = std::make_shared<PasteboardService>();
2228 ASSERT_NE(tempPasteboard, nullptr);
2229
2230 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2231 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2232
2233 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2234
2235 auto result = tempPasteboard->GetClipPlugin();
2236 EXPECT_EQ(result, nullptr);
2237 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2238 }
2239
2240 /**
2241 * @tc.name: GetClipPluginTest002
2242 * @tc.desc: test Func GetClipPlugin
2243 * @tc.type: FUNC
2244 */
2245 HWTEST_F(PasteboardServiceTest, GetClipPluginTest002, TestSize.Level0)
2246 {
2247 auto tempPasteboard = std::make_shared<PasteboardService>();
2248 ASSERT_NE(tempPasteboard, nullptr);
2249
2250 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
2251 tempPasteboard->clipPlugin_ = nullptr;
2252 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2253
2254 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2255
2256 auto result = tempPasteboard->GetClipPlugin();
2257 EXPECT_NE(result, nullptr);
2258 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2259 }
2260
2261 /**
2262 * @tc.name: GetClipPluginTest003
2263 * @tc.desc: test Func GetClipPlugin
2264 * @tc.type: FUNC
2265 */
2266 HWTEST_F(PasteboardServiceTest, GetClipPluginTest003, TestSize.Level0)
2267 {
2268 auto tempPasteboard = std::make_shared<PasteboardService>();
2269 ASSERT_NE(tempPasteboard, nullptr);
2270
2271 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
2272 tempPasteboard->clipPlugin_ = nullptr;
2273 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2274
2275 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(false));
2276
2277 auto result = tempPasteboard->GetClipPlugin();
2278 EXPECT_EQ(result, nullptr);
2279 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2280 }
2281
2282 /**
2283 * @tc.name: GetClipPluginTest004
2284 * @tc.desc: test Func GetClipPlugin
2285 * @tc.type: FUNC
2286 */
2287 HWTEST_F(PasteboardServiceTest, GetClipPluginTest004, TestSize.Level0)
2288 {
2289 auto tempPasteboard = std::make_shared<PasteboardService>();
2290 ASSERT_NE(tempPasteboard, nullptr);
2291
2292 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
2293 std::string PLUGIN_NAME_VAL = "distributed_clip";
__anone99fc3ad0602(ClipPlugin *plugin) 2294 auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
2295 ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
2296 };
2297 std::shared_ptr<ClipPlugin> clipPlugin =
2298 std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
2299 tempPasteboard->clipPlugin_ = clipPlugin;
2300 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2301
2302 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2303
2304 auto result = tempPasteboard->GetClipPlugin();
2305 EXPECT_EQ(result, clipPlugin);
2306 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2307 }
2308
2309 /**
2310 * @tc.name: CleanDistributedDataTest001
2311 * @tc.desc: test Func CleanDistributedData
2312 * @tc.type: FUNC
2313 */
2314 HWTEST_F(PasteboardServiceTest, CleanDistributedDataTest001, TestSize.Level0)
2315 {
2316 auto tempPasteboard = std::make_shared<PasteboardService>();
2317 ASSERT_NE(tempPasteboard, nullptr);
2318
2319 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2320 tempPasteboard->clipPlugin_ = nullptr;
2321 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2322
2323 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2324
2325 tempPasteboard->CleanDistributedData(ACCOUNT_IDS_RANDOM);
2326 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2327 }
2328
2329 /**
2330 * @tc.name: ChangeStoreStatusTest001
2331 * @tc.desc: test Func ChangeStoreStatus
2332 * @tc.type: FUNC
2333 */
2334 HWTEST_F(PasteboardServiceTest, ChangeStoreStatusTest001, TestSize.Level0)
2335 {
2336 auto tempPasteboard = std::make_shared<PasteboardService>();
2337 ASSERT_NE(tempPasteboard, nullptr);
2338
2339 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2340 tempPasteboard->clipPlugin_ = nullptr;
2341 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2342
2343 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2344
2345 tempPasteboard->ChangeStoreStatus(ACCOUNT_IDS_RANDOM);
2346 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2347 }
2348
2349
2350 /**
2351 * @tc.name: GetFullDelayPasteDataTest001
2352 * @tc.desc: test Func GetFullDelayPasteData
2353 * @tc.type: FUNC
2354 */
2355 HWTEST_F(PasteboardServiceTest, GetFullDelayPasteDataTest001, TestSize.Level0)
2356 {
2357 auto tempPasteboard = std::make_shared<PasteboardService>();
2358 ASSERT_NE(tempPasteboard, nullptr);
2359
2360 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2361 tempPasteboard->clipPlugin_ = nullptr;
2362
2363 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2364 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2365 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, *tempPasteboard);
2366 tempPasteboard->entryGetters_.InsertOrAssign(
2367 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2368
2369 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2370 PasteData data;
2371 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
2372 record->SetDelayRecordFlag(false);
2373 record->SetRecordId(11);
2374 record->mimeType_ = MIMETYPE_TEXT_HTML;
2375 std::vector<std::shared_ptr<PasteDataRecord>> records_;
2376 records_.push_back(record);
2377
2378 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
2379 EXPECT_CALL(mock, AllRecords()).WillRepeatedly(testing::Return(records_));
2380
2381 auto result = tempPasteboard->GetFullDelayPasteData(ACCOUNT_IDS_RANDOM, data);
2382 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
2383 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2384 }
2385
2386 /**
2387 * @tc.name: GetFullDelayPasteDataTest002
2388 * @tc.desc: test Func GetFullDelayPasteData
2389 * @tc.type: FUNC
2390 */
2391 HWTEST_F(PasteboardServiceTest, GetFullDelayPasteDataTest002, TestSize.Level0)
2392 {
2393 auto tempPasteboard = std::make_shared<PasteboardService>();
2394 ASSERT_NE(tempPasteboard, nullptr);
2395
2396 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2397 tempPasteboard->clipPlugin_ = nullptr;
2398
2399 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2400 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2401 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, *tempPasteboard);
2402 tempPasteboard->entryGetters_.InsertOrAssign(
2403 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2404
2405 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2406 PasteData data;
2407 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
2408 record->SetDelayRecordFlag(true);
2409 record->SetRecordId(11);
2410 record->mimeType_ = MIMETYPE_TEXT_HTML;
2411 std::vector<std::shared_ptr<PasteDataEntry>> entries;
2412 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
2413 auto newObject = std::make_shared<Object>();
2414 entry->SetValue(newObject);
2415 entries.emplace_back(entry);
2416 record->entries_.push_back(entry);
2417 std::vector<std::shared_ptr<PasteDataRecord>> records_;
2418 records_.push_back(record);
2419
2420 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
2421 EXPECT_CALL(mock, AllRecords()).WillRepeatedly(testing::Return(records_));
2422
2423 auto result = tempPasteboard->GetFullDelayPasteData(ACCOUNT_IDS_RANDOM, data);
2424 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
2425 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2426 }
2427
2428 /**
2429 * @tc.name: GetFullDelayPasteDataTest003
2430 * @tc.desc: test Func GetFullDelayPasteData
2431 * @tc.type: FUNC
2432 */
2433 HWTEST_F(PasteboardServiceTest, GetFullDelayPasteDataTest003, TestSize.Level0)
2434 {
2435 auto tempPasteboard = std::make_shared<PasteboardService>();
2436 ASSERT_NE(tempPasteboard, nullptr);
2437
2438 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2439 tempPasteboard->clipPlugin_ = nullptr;
2440 g_recordValueByType = static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR);
2441
2442 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2443 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2444 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, *tempPasteboard);
2445 tempPasteboard->entryGetters_.InsertOrAssign(
2446 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2447
2448 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2449 PasteData data;
2450 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
2451 record->SetDelayRecordFlag(true);
2452 record->SetRecordId(11);
2453 record->mimeType_ = MIMETYPE_TEXT_HTML;
2454 std::vector<std::shared_ptr<PasteDataEntry>> entries;
2455 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
2456 EntryValue var;
2457 entry->SetValue(var);
2458 entries.emplace_back(entry);
2459 record->entries_.push_back(entry);
2460 std::vector<std::shared_ptr<PasteDataRecord>> records_;
2461 records_.push_back(record);
2462
2463 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
2464 EXPECT_CALL(mock, AllRecords()).WillRepeatedly(testing::Return(records_));
2465
2466 auto result = tempPasteboard->GetFullDelayPasteData(ACCOUNT_IDS_RANDOM, data);
2467 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
2468 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2469 g_recordValueByType = static_cast<int32_t>(PasteboardError::E_OK);
2470 }
2471
2472 /**
2473 * @tc.name: GetFullDelayPasteDataTest004
2474 * @tc.desc: test Func GetFullDelayPasteData
2475 * @tc.type: FUNC
2476 */
2477 HWTEST_F(PasteboardServiceTest, GetFullDelayPasteDataTest004, TestSize.Level0)
2478 {
2479 auto tempPasteboard = std::make_shared<PasteboardService>();
2480 ASSERT_NE(tempPasteboard, nullptr);
2481
2482 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2483 tempPasteboard->clipPlugin_ = nullptr;
2484 g_recordValueByType = static_cast<int32_t>(PasteboardError::E_OK);
2485
2486 sptr<PasteboardEntryGetterImpl> pasteboardEntryGetterImpl = sptr<PasteboardEntryGetterImpl>::MakeSptr();
2487 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient =
2488 sptr<PasteboardService::EntryGetterDeathRecipient>::MakeSptr(ACCOUNT_IDS_RANDOM, *tempPasteboard);
2489 tempPasteboard->entryGetters_.InsertOrAssign(
2490 ACCOUNT_IDS_RANDOM, std::make_pair(pasteboardEntryGetterImpl, deathRecipient));
2491
2492 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2493 PasteData data;
2494 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
2495 record->SetDelayRecordFlag(true);
2496 record->SetRecordId(11);
2497 record->mimeType_ = MIMETYPE_TEXT_HTML;
2498 std::vector<std::shared_ptr<PasteDataEntry>> entries;
2499 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
2500 EntryValue var;
2501 entry->SetValue(var);
2502 entry->SetMimeType(MIMETYPE_TEXT_HTML);
2503 entries.emplace_back(entry);
2504 record->entries_.push_back(entry);
2505 std::vector<std::shared_ptr<PasteDataRecord>> records_;
2506 records_.push_back(record);
2507
2508 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
2509 EXPECT_CALL(mock, AllRecords()).WillRepeatedly(testing::Return(records_));
2510
2511 auto result = tempPasteboard->GetFullDelayPasteData(ACCOUNT_IDS_RANDOM, data);
2512 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
2513 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL0;
2514 g_recordValueByType = static_cast<int32_t>(PasteboardError::E_OK);
2515 }
2516
2517 /**
2518 * @tc.name: GetDistributedData002
2519 * @tc.desc: test Func GetDistributedData
2520 * @tc.type: FUNC
2521 */
2522 HWTEST_F(PasteboardServiceTest, GetDistributedData002, TestSize.Level0)
2523 {
2524 auto tempPasteboard = std::make_shared<PasteboardService>();
2525 EXPECT_NE(tempPasteboard, nullptr);
2526
2527 TestEvent event;
2528 int32_t user = 0;
2529 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2530 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2531 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
2532 std::pair<std::shared_ptr<PasteData>, PasteDateResult> result = tempPasteboard->GetDistributedData(event, user);
2533 EXPECT_EQ(result.second.errorCode, static_cast<int32_t>(PasteboardError::REMOTE_TASK_ERROR));
2534 }
2535
2536 /**
2537 * @tc.name: GetDistributedData003
2538 * @tc.desc: test Func GetDistributedData
2539 * @tc.type: FUNC
2540 */
2541 HWTEST_F(PasteboardServiceTest, GetDistributedData003, TestSize.Level0)
2542 {
2543 auto tempPasteboard = std::make_shared<PasteboardService>();
2544 EXPECT_NE(tempPasteboard, nullptr);
2545
2546 TestEvent event;
2547 int32_t user = 0;
2548 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
__anone99fc3ad0702(ClipPlugin *plugin) 2549 auto release = [](ClipPlugin *plugin) {
2550 ClipPlugin::DestroyPlugin(RANDOM_STRING, plugin);
2551 };
2552 tempPasteboard->clipPlugin_ = std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(RANDOM_STRING), release);
2553 EXPECT_CALL(mock, IsOn()).WillOnce(testing::Return(true));
2554 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL4;
2555 std::pair<std::shared_ptr<PasteData>, PasteDateResult> result = tempPasteboard->GetDistributedData(event, user);
2556 EXPECT_EQ(result.second.errorCode, static_cast<int32_t>(PasteboardError::E_OK));
2557 tempPasteboard->clipPlugin_ = nullptr;
2558 }
2559
2560 /**
2561 * @tc.name: GetPasteDataDot002
2562 * @tc.desc: test Func GetPasteDataDot
2563 * @tc.type: FUNC
2564 */
2565 HWTEST_F(PasteboardServiceTest, GetPasteDataDot002, TestSize.Level0)
2566 {
2567 auto tempPasteboard = std::make_shared<PasteboardService>();
2568 EXPECT_NE(tempPasteboard, nullptr);
2569 PasteData pasteData;
2570 pasteData.SetRemote(false);
2571 EXPECT_NO_FATAL_FAILURE(tempPasteboard->GetPasteDataDot(pasteData, RANDOM_STRING));
2572 }
2573
2574 /**
2575 * @tc.name: GetPasteDataDot003
2576 * @tc.desc: test Func GetPasteDataDot
2577 * @tc.type: FUNC
2578 */
2579 HWTEST_F(PasteboardServiceTest, GetPasteDataDot003, TestSize.Level0)
2580 {
2581 auto tempPasteboard = std::make_shared<PasteboardService>();
2582 EXPECT_NE(tempPasteboard, nullptr);
2583 PasteData pasteData;
2584 pasteData.SetRemote(true);
2585 EXPECT_NO_FATAL_FAILURE(tempPasteboard->GetPasteDataDot(pasteData, RANDOM_STRING));
2586 }
2587
2588 /**
2589 * @tc.name: DumpHistory002
2590 * @tc.desc: test Func DumpHistory
2591 * @tc.type: FUNC
2592 */
2593 HWTEST_F(PasteboardServiceTest, DumpHistory002, TestSize.Level0)
2594 {
2595 auto tempPasteboard = std::make_shared<PasteboardService>();
2596 EXPECT_NE(tempPasteboard, nullptr);
2597 tempPasteboard->dataHistory_.clear();
2598 tempPasteboard->dataHistory_.push_back(RANDOM_STRING);
2599 std::string history = tempPasteboard->DumpHistory();
2600 EXPECT_TRUE(history.find("Access history last ten times: ") != std::string::npos);
2601 tempPasteboard->dataHistory_.clear();
2602 }
2603
2604 /**
2605 * @tc.name: DumpHistory003
2606 * @tc.desc: test Func DumpHistory
2607 * @tc.type: FUNC
2608 */
2609 HWTEST_F(PasteboardServiceTest, DumpHistory003, TestSize.Level0)
2610 {
2611 auto tempPasteboard = std::make_shared<PasteboardService>();
2612 EXPECT_NE(tempPasteboard, nullptr);
2613 tempPasteboard->dataHistory_.clear();
2614 std::string history = tempPasteboard->DumpHistory();
2615 EXPECT_TRUE(history.find("Access history fail! dataHistory_ no data.") != std::string::npos);
2616 }
2617
2618 /**
2619 * @tc.name: Dump002
2620 * @tc.desc: test Func Dump when uid > maxUid
2621 * @tc.type: FUNC
2622 */
2623 HWTEST_F(PasteboardServiceTest, Dump002, TestSize.Level0)
2624 {
2625 auto tempPasteboard = std::make_shared<PasteboardService>();
2626 EXPECT_NE(tempPasteboard, nullptr);
2627 int fd = INT_ONE;
2628 std::vector<std::u16string> args;
2629 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2630 EXPECT_CALL(mock, GetCallingUid).WillOnce(testing::Return(UINT32_EXCEPTION_APPID));
2631 int result = tempPasteboard->Dump(fd, args);
2632 EXPECT_EQ(result, 0);
2633 }
2634
2635 /**
2636 * @tc.name: Dump003
2637 * @tc.desc: test Func Dump when PasteboardDumpHelper::GetInstance().Dump return false
2638 * @tc.type: FUNC
2639 */
2640 HWTEST_F(PasteboardServiceTest, Dump003, TestSize.Level0)
2641 {
2642 auto tempPasteboard = std::make_shared<PasteboardService>();
2643 EXPECT_NE(tempPasteboard, nullptr);
2644 int fd = INT_ONE;
2645 std::vector<std::u16string> args;
2646 args.push_back(RANDOM_U16STRING);
2647 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2648 EXPECT_CALL(mock, GetCallingUid).WillOnce(testing::Return(INT_THREETHREETHREE));
2649 EXPECT_CALL(mock, Dump).WillOnce(testing::Return(false));
2650 int result = tempPasteboard->Dump(fd, args);
2651 EXPECT_EQ(result, 0);
2652 }
2653
2654 /**
2655 * @tc.name: Dump004
2656 * @tc.desc: test Func Dump when PasteboardDumpHelper::GetInstance().Dump return true
2657 * @tc.type: FUNC
2658 */
2659 HWTEST_F(PasteboardServiceTest, Dump004, TestSize.Level0)
2660 {
2661 auto tempPasteboard = std::make_shared<PasteboardService>();
2662 EXPECT_NE(tempPasteboard, nullptr);
2663 int fd = INT_ONE;
2664 std::vector<std::u16string> args;
2665 args.push_back(RANDOM_U16STRING);
2666 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2667 EXPECT_CALL(mock, GetCallingUid).WillOnce(testing::Return(INT_THREETHREETHREE));
2668 EXPECT_CALL(mock, Dump).WillOnce(testing::Return(true));
2669 int result = tempPasteboard->Dump(fd, args);
2670 EXPECT_EQ(result, 0);
2671 }
2672
2673 /**
2674 * @tc.name: IsNeedThaw002
2675 * @tc.desc: test Func IsNeedThaw when InputMethodController::GetInstance return nullptr
2676 * @tc.type: FUNC
2677 */
2678 HWTEST_F(PasteboardServiceTest, IsNeedThaw002, TestSize.Level0)
2679 {
2680 auto tempPasteboard = std::make_shared<PasteboardService>();
2681 EXPECT_NE(tempPasteboard, nullptr);
2682 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2683 EXPECT_CALL(mock, GetInstance).WillOnce(testing::Return(nullptr));
2684 bool result = tempPasteboard->IsNeedThaw();
2685 EXPECT_FALSE(result);
2686 }
2687
2688 /**
2689 * @tc.name: IsNeedThaw003
2690 * @tc.desc: test Func IsNeedThaw when imc->GetDefaultInputMethod is error
2691 * @tc.type: FUNC
2692 */
2693 HWTEST_F(PasteboardServiceTest, IsNeedThaw003, TestSize.Level0)
2694 {
2695 auto tempPasteboard = std::make_shared<PasteboardService>();
2696 EXPECT_NE(tempPasteboard, nullptr);
2697 sptr<InputMethodController> instance_ = new (std::nothrow) InputMethodController();
2698 g_encodeInsert = true;
2699 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2700 EXPECT_CALL(mock, GetInstance).WillOnce(testing::Return(instance_));
2701 EXPECT_CALL(mock, GetDefaultInputMethod).WillOnce(testing::Return(INT32_NEGATIVE_NUMBER));
2702 bool result = tempPasteboard->IsNeedThaw();
2703 EXPECT_FALSE(result);
2704 }
2705
2706 /**
2707 * @tc.name: IsNeedThaw004
2708 * @tc.desc: test Func IsNeedThaw when property == nullptr
2709 * @tc.type: FUNC
2710 */
2711 HWTEST_F(PasteboardServiceTest, IsNeedThaw004, TestSize.Level0)
2712 {
2713 auto tempPasteboard = std::make_shared<PasteboardService>();
2714 EXPECT_NE(tempPasteboard, nullptr);
2715 sptr<InputMethodController> instance_ = new (std::nothrow) InputMethodController();
2716 g_encodeInsert = false;
2717 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2718 EXPECT_CALL(mock, GetInstance).WillOnce(testing::Return(instance_));
2719 EXPECT_CALL(mock, GetDefaultInputMethod).WillOnce(testing::Return(0));
2720 bool result = tempPasteboard->IsNeedThaw();
2721 EXPECT_FALSE(result);
2722 }
2723
2724 /**
2725 * @tc.name: IsNeedThaw005
2726 * @tc.desc: test Func IsNeedThaw when validity
2727 * @tc.type: FUNC
2728 */
2729 HWTEST_F(PasteboardServiceTest, IsNeedThaw005, TestSize.Level0)
2730 {
2731 auto tempPasteboard = std::make_shared<PasteboardService>();
2732 EXPECT_NE(tempPasteboard, nullptr);
2733 sptr<InputMethodController> instance_ = new (std::nothrow) InputMethodController();
2734 g_encodeInsert = true;
2735 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2736 EXPECT_CALL(mock, GetInstance).WillOnce(testing::Return(instance_));
2737 EXPECT_CALL(mock, GetDefaultInputMethod).WillOnce(testing::Return(0));
2738 bool result = tempPasteboard->IsNeedThaw();
2739 EXPECT_TRUE(result);
2740 }
2741
2742 /**
2743 * @tc.name: GrantUriPermissionTest001
2744 * @tc.desc: test Func GrantUriPermission
2745 * @tc.type: FUNC
2746 */
2747 HWTEST_F(PasteboardServiceTest, GrantUriPermissionTest001, TestSize.Level0)
2748 {
2749 auto tempPasteboard = std::make_shared<PasteboardService>();
2750 EXPECT_NE(tempPasteboard, nullptr);
2751 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2752 EXPECT_CALL(mock, GetBoolParameter(_, _)).WillRepeatedly(testing::Return(true));
2753
2754 std::vector<Uri> grantUris;
2755 std::string targetBundleName = "com.example.app";
2756 int32_t appIndex = 1;
2757 std::string uriStr = URI_STRING;
2758 auto uri = OHOS::Uri(uriStr);
2759 grantUris.push_back(uri);
2760
2761 auto result = tempPasteboard->GrantUriPermission(grantUris, targetBundleName, false, appIndex);
2762 EXPECT_NE(result, static_cast<int32_t>(PasteboardError::E_OK));
2763 }
2764
2765 /**
2766 * @tc.name: GrantUriPermissionTest002
2767 * @tc.desc: test Func GrantUriPermission
2768 * @tc.type: FUNC
2769 */
2770 HWTEST_F(PasteboardServiceTest, GrantUriPermissionTest002, TestSize.Level0)
2771 {
2772 auto tempPasteboard = std::make_shared<PasteboardService>();
2773 EXPECT_NE(tempPasteboard, nullptr);
2774 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2775 EXPECT_CALL(mock, GetBoolParameter(_, _)).WillRepeatedly(testing::Return(false));
2776
2777 std::vector<Uri> grantUris;
2778 std::string targetBundleName = "com.example.app";
2779 int32_t appIndex = 1;
2780 std::string uriStr = URI_STRING;
2781 auto uri = OHOS::Uri(uriStr);
2782 grantUris.push_back(uri);
2783
2784 auto result = tempPasteboard->GrantUriPermission(grantUris, targetBundleName, false, appIndex);
2785 EXPECT_NE(result, static_cast<int32_t>(PasteboardError::E_OK));
2786 }
2787
2788 /**
2789 * @tc.name: GrantUriPermissionTest003
2790 * @tc.desc: test Func GrantUriPermission
2791 * @tc.type: FUNC
2792 */
2793 HWTEST_F(PasteboardServiceTest, GrantUriPermissionTest003, TestSize.Level0)
2794 {
2795 auto tempPasteboard = std::make_shared<PasteboardService>();
2796 EXPECT_NE(tempPasteboard, nullptr);
2797 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2798 EXPECT_CALL(mock, GetBoolParameter(_, _)).WillRepeatedly(testing::Return(true));
2799
2800 std::vector<Uri> grantUris;
2801 std::string targetBundleName = "com.example.app";
2802 int32_t appIndex = 1;
2803 std::string uriStr = URI_STRING;
2804 auto uri = OHOS::Uri(uriStr);
2805 grantUris.push_back(uri);
2806
2807 auto result = tempPasteboard->GrantUriPermission(grantUris, targetBundleName, true, appIndex);
2808 EXPECT_NE(result, static_cast<int32_t>(PasteboardError::E_OK));
2809 }
2810
2811 /**
2812 * @tc.name: GrantUriPermissionTest004
2813 * @tc.desc: test Func GrantUriPermission
2814 * @tc.type: FUNC
2815 */
2816 HWTEST_F(PasteboardServiceTest, GrantUriPermissionTest004, TestSize.Level0)
2817 {
2818 auto tempPasteboard = std::make_shared<PasteboardService>();
2819 EXPECT_NE(tempPasteboard, nullptr);
2820 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
2821 EXPECT_CALL(mock, GetBoolParameter(_, _)).WillRepeatedly(testing::Return(false));
2822
2823 std::vector<Uri> grantUris;
2824 std::string targetBundleName = "com.example.app";
2825 int32_t appIndex = 1;
2826 std::string uriStr = URI_STRING;
2827 auto uri = OHOS::Uri(uriStr);
2828 grantUris.push_back(uri);
2829
2830 auto result = tempPasteboard->GrantUriPermission(grantUris, targetBundleName, true, appIndex);
2831 EXPECT_NE(result, static_cast<int32_t>(PasteboardError::E_OK));
2832 }
2833
2834 /**
2835 * @tc.name: SetAppShareOptionsTest004
2836 * @tc.desc: test Func SetAppShareOptions
2837 * @tc.type: FUNC
2838 */
2839 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest004, TestSize.Level0)
2840 {
2841 PasteboardService service;
2842 int32_t shareOptions = 0;
2843
2844 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2845 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967296));
2846 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2847 int32_t result = service.SetAppShareOptions(shareOptions);
2848 ASSERT_EQ(result, 0);
2849 }
2850
2851 /**
2852 * @tc.name: SetAppShareOptionsTest005
2853 * @tc.desc: test Func SetAppShareOptions
2854 * @tc.type: FUNC
2855 */
2856 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest005, TestSize.Level0)
2857 {
2858 PasteboardService service;
2859 int32_t shareOptions = 0;
2860
2861 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2862 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967296));
2863 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2864 ShareOption testOption = InApp;
2865 PasteboardService::GlobalShareOption option = {.source = PasteboardService::GlobalShareOptionSource::APP,
2866 .shareOption = testOption};
2867 service.globalShareOptions_.InsertOrAssign(1000, option);
2868 int32_t result = service.SetAppShareOptions(shareOptions);
2869 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_OPERATION_ERROR));
2870 }
2871
2872 /**
2873 * @tc.name: RemoveAppShareOptionsTest001
2874 * @tc.desc: test Func RemoveAppShareOptions
2875 * @tc.type: FUNC
2876 */
2877 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest001, TestSize.Level0)
2878 {
2879 PasteboardService service;
2880
2881 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2882 EXPECT_CALL(ipcMock, VerifyAccessToken).WillOnce(Return(PermissionState::PERMISSION_DENIED));
2883 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(123));
2884 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2885 int32_t result = service.RemoveAppShareOptions();
2886 ASSERT_EQ(result, static_cast<int32_t>(PasteboardError::PERMISSION_VERIFICATION_ERROR));
2887 }
2888
2889 /**
2890 * @tc.name: RemoveAppShareOptionsTest002
2891 * @tc.desc: test Func RemoveAppShareOptions
2892 * @tc.type: FUNC
2893 */
2894 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest002, TestSize.Level0)
2895 {
2896 PasteboardService service;
2897
2898 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2899 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967296));
2900 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2901 int32_t result = service.RemoveAppShareOptions();
2902 ASSERT_EQ(result, 0);
2903 }
2904
2905 /**
2906 * @tc.name: RemoveAppShareOptionsTest005
2907 * @tc.desc: test Func RemoveAppShareOptions
2908 * @tc.type: FUNC
2909 */
2910 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest005, TestSize.Level0)
2911 {
2912 PasteboardService service;
2913
2914 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2915 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967296));
2916 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2917 ShareOption testOption = InApp;
2918 PasteboardService::GlobalShareOption option = {.source = PasteboardService::GlobalShareOptionSource::APP,
2919 .shareOption = testOption};
2920 service.globalShareOptions_.InsertOrAssign(1000, option);
2921 int32_t result = service.RemoveAppShareOptions();
2922 ASSERT_EQ(result, 0);
2923 }
2924
2925 /**
2926 * @tc.name: RemoveAppShareOptionsTest004
2927 * @tc.desc: test Func RemoveAppShareOptions
2928 * @tc.type: FUNC
2929 */
2930 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest004, TestSize.Level0)
2931 {
2932 PasteboardService service;
2933
2934 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2935 EXPECT_CALL(ipcMock, GetCallingFullTokenID).WillOnce(testing::Return(4294967296));
2936 EXPECT_CALL(ipcMock, GetCallingTokenID).WillOnce(testing::Return(1000));
2937 ShareOption testOption = InApp;
2938 PasteboardService::GlobalShareOption option = {.source = PasteboardService::GlobalShareOptionSource::MDM,
2939 .shareOption = testOption};
2940 service.globalShareOptions_.InsertOrAssign(1000, option);
2941 int32_t result = service.RemoveAppShareOptions();
2942 ASSERT_EQ(result, 0);
2943 }
2944
2945 /**
2946 * @tc.name: CheckMdmShareOptionTest001
2947 * @tc.desc: test Func CheckMdmShareOption
2948 * @tc.type: FUNC
2949 */
2950 HWTEST_F(PasteboardServiceTest, CheckMdmShareOptionTest001, TestSize.Level0)
2951 {
2952 PasteboardService service;
2953 PasteData pasteData;
2954
2955 pasteData.SetTokenId(1000);
2956 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2957 ShareOption testOption = InApp;
2958 PasteboardService::GlobalShareOption option = {.source = PasteboardService::GlobalShareOptionSource::MDM,
2959 .shareOption = testOption};
2960 service.globalShareOptions_.InsertOrAssign(1000, option);
2961 int32_t result = service.CheckMdmShareOption(pasteData);
2962 ASSERT_EQ(result, true);
2963 }
2964
2965 /**
2966 * @tc.name: CheckMdmShareOptionTest002
2967 * @tc.desc: test Func CheckMdmShareOption
2968 * @tc.type: FUNC
2969 */
2970 HWTEST_F(PasteboardServiceTest, CheckMdmShareOptionTest002, TestSize.Level0)
2971 {
2972 PasteboardService service;
2973 PasteData pasteData;
2974
2975 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
2976 int32_t result = service.CheckMdmShareOption(pasteData);
2977 ASSERT_EQ(result, false);
2978 }
2979
2980 /**
2981 * @tc.name: SetPasteboardHistoryTest001
2982 * @tc.desc: test Func SetPasteboardHistory
2983 * @tc.type: FUNC
2984 */
2985 HWTEST_F(PasteboardServiceTest, SetPasteboardHistoryTest001, TestSize.Level0)
2986 {
2987 PasteboardService service;
2988 HistoryInfo info;
2989 for (int i = 1; i <= INT32_TEN; i++) {
2990 info.time = std::to_string(i);
2991 info.bundleName = "app" + std::to_string(i);
2992 info.state = "COPY";
2993 info.remote = "";
2994 service.SetPasteboardHistory(info);
2995 }
2996
2997 ASSERT_EQ(service.dataHistory_.size(), INT32_TEN);
2998 info.time = "11";
2999 info.bundleName = "app11";
3000 NiceMock<PasteboardServiceInterfaceMock> ipcMock;
3001
3002 int32_t result = service.SetPasteboardHistory(info);
3003 ASSERT_EQ(service.dataHistory_.size(), INT32_TEN);
3004
3005 ASSERT_EQ(result, true);
3006 EXPECT_TRUE(service.dataHistory_.front().find("2 ") == 0);
3007 EXPECT_TRUE(service.dataHistory_.back().find("11 ") == 0);
3008 }
3009
3010 /**
3011 * @tc.name: HandleDelayDataAndRecordTest001
3012 * @tc.desc: HandleDelayDataAndRecordTest001
3013 * @tc.type: FUNC
3014 */
3015 HWTEST_F(PasteboardServiceTest, HandleDelayDataAndRecordTest001, TestSize.Level0)
3016 {
3017 auto tempPasteboard = std::make_shared<PasteboardService>();
3018 EXPECT_NE(tempPasteboard, nullptr);
3019
3020 PasteData pasteData;
3021 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
3022 sptr<IPasteboardEntryGetter> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
3023 AppInfo appInfo;
3024
3025 NiceMock<PasteboardServiceInterfaceMock> mock;
3026 EXPECT_CALL(mock, IsDelayData()).WillOnce(Return(true));
3027
3028 tempPasteboard->HandleDelayDataAndRecord(pasteData, delayGetter, entryGetter, appInfo);
3029 }
3030
3031 /**
3032 * @tc.name: HandleDelayDataAndRecordTest002
3033 * @tc.desc: HandleDelayDataAndRecordTest002
3034 * @tc.type: FUNC
3035 */
3036 HWTEST_F(PasteboardServiceTest, HandleDelayDataAndRecordTest002, TestSize.Level0)
3037 {
3038 auto tempPasteboard = std::make_shared<PasteboardService>();
3039 EXPECT_NE(tempPasteboard, nullptr);
3040
3041 PasteData pasteData;
3042 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
3043 sptr<IPasteboardEntryGetter> entryGetter = nullptr;
3044 AppInfo appInfo;
3045
3046 tempPasteboard->HandleDelayDataAndRecord(pasteData, delayGetter, entryGetter, appInfo);
3047 }
3048
3049 /**
3050 * @tc.name: HandleDelayDataAndRecordTest003
3051 * @tc.desc: HandleDelayDataAndRecordTest003
3052 * @tc.type: FUNC
3053 */
3054 HWTEST_F(PasteboardServiceTest, HandleDelayDataAndRecordTest003, TestSize.Level0)
3055 {
3056 auto tempPasteboard = std::make_shared<PasteboardService>();
3057 EXPECT_NE(tempPasteboard, nullptr);
3058
3059 PasteData pasteData;
3060 sptr<IPasteboardDelayGetter> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
3061 sptr<IPasteboardEntryGetter> entryGetter = nullptr;
3062 AppInfo appInfo;
3063
3064 NiceMock<PasteboardServiceInterfaceMock> mock;
3065 EXPECT_CALL(mock, IsDelayRecord()).WillOnce(Return(true));
3066
3067 tempPasteboard->HandleDelayDataAndRecord(pasteData, delayGetter, entryGetter, appInfo);
3068 }
3069
3070 /**
3071 * @tc.name: EstablishP2PLinkTest001
3072 * @tc.desc: EstablishP2PLinkTest001
3073 * @tc.type: FUNC
3074 */
3075 HWTEST_F(PasteboardServiceTest, EstablishP2PLinkTest001, TestSize.Level0)
3076 {
3077 #ifdef PB_DEVICE_MANAGER_ENABLE
3078 auto tempPasteboard = std::make_shared<PasteboardService>();
3079 EXPECT_NE(tempPasteboard, nullptr);
3080
3081 PasteboardService service;
3082 std::string networkld = "network123";
3083 std::string pasteld = "paste123";
3084
3085 NiceMock<PasteboardServiceInterfaceMock> mock;
3086 EXPECT_CALL(mock, GetRemoteDeviceInfo(testing::_, testing::_))
3087 .WillOnce(Return(static_cast<int32_t>(PasteboardError::E_OK)));
3088
3089 tempPasteboard->EstablishP2PLink(networkld, pasteld);
3090 ASSERT_TRUE(true);
3091 #else
3092 ASSERT_TRUE(true);
3093 #endif
3094 }
3095
3096 /**
3097 * @tc.name: CloseP2PLinkTest001
3098 * @tc.desc: CloseP2PLinkTest001
3099 * @tc.type: FUNC
3100 */
3101 HWTEST_F(PasteboardServiceTest, CloseP2PLinkTest001, TestSize.Level0)
3102 {
3103 #ifdef PB_DEVICE_MANAGER_ENABLE
3104 auto tempPasteboard = std::make_shared<PasteboardService>();
3105 EXPECT_NE(tempPasteboard, nullptr);
3106
3107 std::string networkld = "network123";
3108
3109 NiceMock<PasteboardServiceInterfaceMock> mock;
3110 EXPECT_CALL(mock, GetRemoteDeviceInfo(testing::_, testing::_))
3111 .WillOnce(Return(static_cast<int32_t>(PasteboardError::E_OK)));
3112
3113 tempPasteboard->CloseP2PLink(networkld);
3114 #else
3115 ASSERT_TRUE(true);
3116 #endif
3117 }
3118
3119 /**
3120 * @tc.name: PreSyncRemotePasteboardDataTest
3121 * @tc.desc: PreSyncRemotePasteboardData
3122 * @tc.type: FUNC
3123 */
3124 HWTEST_F(PasteboardServiceTest, PreSyncRemotePasteboardDataTest, TestSize.Level0)
3125 {
3126 auto tempPasteboard = std::make_shared<PasteboardService>();
3127 EXPECT_NE(tempPasteboard, nullptr);
3128 testing::NiceMock<PasteboardServiceInterfaceMock> mock;
3129 EXPECT_CALL(mock, IsOn()).WillRepeatedly(testing::Return(true));
3130 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL1;
3131 tempPasteboard->PreSyncRemotePasteboardData();
3132 tempPasteboard->securityLevel_.securityLevel_ = DATA_SEC_LEVEL3;
3133 std::string PLUGIN_NAME_VAL = "distributed_clip";
__anone99fc3ad0802(ClipPlugin *plugin) 3134 auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
3135 ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
3136 };
3137 std::shared_ptr<ClipPlugin> clipPlugin =
3138 std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
3139 EXPECT_NE(clipPlugin, nullptr);
3140 tempPasteboard->clipPlugin_ = clipPlugin;
3141 EXPECT_NE(tempPasteboard->GetClipPlugin(), nullptr);
3142 tempPasteboard->PreSyncRemotePasteboardData();
3143 }
3144
3145 /**
3146 * @tc.name: ClearP2PEstablishTaskInfoTest
3147 * @tc.desc: ClearP2PEstablishTaskInfo
3148 * @tc.type: FUNC
3149 */
3150 HWTEST_F(PasteboardServiceTest, ClearP2PEstablishTaskInfoTest, TestSize.Level0)
3151 {
3152 auto tempPasteboard = std::make_shared<PasteboardService>();
3153 EXPECT_NE(tempPasteboard, nullptr);
3154 tempPasteboard->ClearP2PEstablishTaskInfo();
3155 }
3156
3157 /**
3158 * @tc.name: RegisterPreSyncCallbackTest
3159 * @tc.desc: RegisterPreSyncCallback
3160 * @tc.type: FUNC
3161 */
3162 HWTEST_F(PasteboardServiceTest, RegisterPreSyncCallbackTest, TestSize.Level0)
3163 {
3164 auto tempPasteboard = std::make_shared<PasteboardService>();
3165 EXPECT_NE(tempPasteboard, nullptr);
3166 tempPasteboard->RegisterPreSyncCallback(nullptr);
3167 auto clipPlugin = std::make_shared<DefaultClip>();
3168 EXPECT_NE(clipPlugin, nullptr);
3169 tempPasteboard->RegisterPreSyncCallback(clipPlugin);
3170 }
3171
3172 /**
3173 * @tc.name: PreEstablishP2PLinkCallbackTest
3174 * @tc.desc: PreEstablishP2PLinkCallback
3175 * @tc.type: FUNC
3176 */
3177 HWTEST_F(PasteboardServiceTest, PreEstablishP2PLinkCallbackTest, TestSize.Level0)
3178 {
3179 auto tempPasteboard = std::make_shared<PasteboardService>();
3180 EXPECT_NE(tempPasteboard, nullptr);
3181 std::string networkId;
3182 auto clipPlugin = std::make_shared<DefaultClip>();
3183 EXPECT_NE(clipPlugin, nullptr);
3184 tempPasteboard->PreEstablishP2PLinkCallback(networkId, clipPlugin.get());
3185 networkId = "TestNetworkId";
3186 tempPasteboard->PreEstablishP2PLinkCallback(networkId, clipPlugin.get());
3187 }
3188
3189 /**
3190 * @tc.name: PreSyncSwitchMonitorCallbackTest
3191 * @tc.desc: PreSyncSwitchMonitorCallback
3192 * @tc.type: FUNC
3193 */
3194 HWTEST_F(PasteboardServiceTest, PreSyncSwitchMonitorCallbackTest, TestSize.Level0)
3195 {
3196 auto tempPasteboard = std::make_shared<PasteboardService>();
3197 EXPECT_NE(tempPasteboard, nullptr);
3198 tempPasteboard->PreSyncSwitchMonitorCallback();
3199 }
3200
3201 /**
3202 * @tc.name: RegisterPreSyncMonitorTest
3203 * @tc.desc: RegisterPreSyncMonitor
3204 * @tc.type: FUNC
3205 */
3206 HWTEST_F(PasteboardServiceTest, RegisterPreSyncMonitorTest, TestSize.Level0)
3207 {
3208 auto tempPasteboard = std::make_shared<PasteboardService>();
3209 EXPECT_NE(tempPasteboard, nullptr);
3210 tempPasteboard->RegisterPreSyncMonitor();
3211 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3212 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3213 tempPasteboard->RegisterPreSyncMonitor();
3214 tempPasteboard->subscribeActiveId_ = 0;
3215 tempPasteboard->RegisterPreSyncMonitor();
3216 }
3217
3218 /**
3219 * @tc.name: UnRegisterPreSyncMonitorTest
3220 * @tc.desc: UnRegisterPreSyncMonitor
3221 * @tc.type: FUNC
3222 */
3223 HWTEST_F(PasteboardServiceTest, UnRegisterPreSyncMonitorTest, TestSize.Level0)
3224 {
3225 auto tempPasteboard = std::make_shared<PasteboardService>();
3226 EXPECT_NE(tempPasteboard, nullptr);
3227 tempPasteboard->subscribeActiveId_ = -1;
3228 tempPasteboard->UnRegisterPreSyncMonitor();
3229 }
3230
3231 /**
3232 * @tc.name: DeletePreSyncP2pFromP2pMapTest
3233 * @tc.desc: DeletePreSyncP2pFromP2pMap
3234 * @tc.type: FUNC
3235 */
3236 HWTEST_F(PasteboardServiceTest, DeletePreSyncP2pFromP2pMapTest, TestSize.Level0)
3237 {
3238 auto tempPasteboard = std::make_shared<PasteboardService>();
3239 EXPECT_NE(tempPasteboard, nullptr);
3240 std::string networkId = "TestNetworkId";
3241 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3242 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3243 tempPasteboard->DeletePreSyncP2pFromP2pMap(networkId);
3244 }
3245
3246 /**
3247 * @tc.name: CheckAndReuseP2PLinkTest001
3248 * @tc.desc: CheckAndReuseP2PLink
3249 * @tc.type: FUNC
3250 */
3251 HWTEST_F(PasteboardServiceTest, CheckAndReuseP2PLinkTest001, TestSize.Level0)
3252 {
3253 #ifdef PB_DEVICE_MANAGER_ENABLE
3254 auto tempPasteboard = std::make_shared<PasteboardService>();
3255 EXPECT_NE(tempPasteboard, nullptr);
3256 std::string networkId = "TestNetworkId";
3257 std::string pasteId = "P2pPreSyncId_";
3258 auto result = tempPasteboard->CheckAndReuseP2PLink(networkId, pasteId);
3259 EXPECT_EQ(result, nullptr);
3260 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3261 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3262 int32_t pid = 123;
3263 ConcurrentMap<std::string, int32_t> p2pMap;
3264 p2pMap.Insert(pasteId, pid);
3265 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
3266 std::shared_ptr<BlockObject<int32_t>> block = std::make_shared<BlockObject<int32_t>>(2000, 0);
3267 EXPECT_NE(block, nullptr);
3268 tempPasteboard->preSyncP2pMap_.insert(std::make_pair(networkId, block));
3269 result = tempPasteboard->CheckAndReuseP2PLink(networkId, pasteId);
3270 EXPECT_NE(result, nullptr);
3271 #else
3272 ASSERT_TRUE(true);
3273 #endif
3274 }
3275
3276 /**
3277 * @tc.name: EstablishP2PLinkTaskTest001
3278 * @tc.desc: EstablishP2PLinkTask
3279 * @tc.type: FUNC
3280 */
3281 HWTEST_F(PasteboardServiceTest, EstablishP2PLinkTaskTest001, TestSize.Level0)
3282 {
3283 #ifdef PB_DEVICE_MANAGER_ENABLE
3284 auto tempPasteboard = std::make_shared<PasteboardService>();
3285 EXPECT_NE(tempPasteboard, nullptr);
3286 TestEvent event;
3287 std::string pasteId = "P2pPreSyncId_";
3288 auto result = tempPasteboard->EstablishP2PLinkTask(pasteId, event);
3289 EXPECT_EQ(result, nullptr);
3290 event.deviceId = DMAdapter::GetInstance().GetLocalNetworkId();
3291 result = tempPasteboard->EstablishP2PLinkTask(pasteId, event);
3292 EXPECT_EQ(result, nullptr);
3293 event.deviceId = "TestNetworkId";
3294 std::string uriType = "text/plain";
3295 event.dataType.push_back(uriType);
3296 result = tempPasteboard->EstablishP2PLinkTask(pasteId, event);
3297 EXPECT_EQ(result, nullptr);
3298 uriType = "text/uri";
3299 event.dataType.push_back(uriType);
3300 result = tempPasteboard->EstablishP2PLinkTask(pasteId, event);
3301 EXPECT_EQ(result, nullptr);
3302 int32_t pid = 123;
3303 ConcurrentMap<std::string, int32_t> p2pMap;
3304 p2pMap.Insert(pasteId, pid);
3305 tempPasteboard->p2pMap_.Insert(event.deviceId, p2pMap);
3306 std::shared_ptr<BlockObject<int32_t>> block = std::make_shared<BlockObject<int32_t>>(2000, 0);
3307 EXPECT_NE(block, nullptr);
3308 tempPasteboard->preSyncP2pMap_.insert(std::make_pair(event.deviceId, block));
3309 result = tempPasteboard->EstablishP2PLinkTask(pasteId, event);
3310 EXPECT_NE(result, nullptr);
3311 #else
3312 ASSERT_TRUE(true);
3313 #endif
3314 }
3315
3316 /**
3317 * @tc.name: OpenP2PLinkForPreEstablishTest001
3318 * @tc.desc: OpenP2PLinkForPreEstablish
3319 * @tc.type: FUNC
3320 */
3321 HWTEST_F(PasteboardServiceTest, OpenP2PLinkForPreEstablishTest001, TestSize.Level0)
3322 {
3323 #ifdef PB_DEVICE_MANAGER_ENABLE
3324 auto tempPasteboard = std::make_shared<PasteboardService>();
3325 EXPECT_NE(tempPasteboard, nullptr);
3326 std::string networkId = "TestNetworkId";
3327 auto clipPlugin = std::make_shared<DefaultClip>();
3328 EXPECT_NE(clipPlugin, nullptr);
3329 NiceMock<PasteboardServiceInterfaceMock> mock;
3330 EXPECT_CALL(mock, GetRemoteDeviceInfo(testing::_, testing::_))
3331 .WillOnce(Return(static_cast<int32_t>(PasteboardError::OTHER_ERROR)));
3332 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3333 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3334 auto result = tempPasteboard->OpenP2PLinkForPreEstablish(networkId, clipPlugin.get());
3335 EXPECT_EQ(result, false);
3336 #else
3337 ASSERT_TRUE(true);
3338 #endif
3339 }
3340
3341 /**
3342 * @tc.name: PreEstablishP2PLinkTest001
3343 * @tc.desc: PreEstablishP2PLink
3344 * @tc.type: FUNC
3345 */
3346 HWTEST_F(PasteboardServiceTest, PreEstablishP2PLinkTest001, TestSize.Level0)
3347 {
3348 #ifdef PB_DEVICE_MANAGER_ENABLE
3349 auto tempPasteboard = std::make_shared<PasteboardService>();
3350 EXPECT_NE(tempPasteboard, nullptr);
3351 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3352 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3353 tempPasteboard->p2pEstablishInfo_.pasteBlock = std::make_shared<BlockObject<int32_t>>(2000, 0);
3354 EXPECT_NE(tempPasteboard->p2pEstablishInfo_.pasteBlock, nullptr);
3355 std::string networkId = "TestNetworkId";
3356 tempPasteboard->p2pEstablishInfo_.networkId = networkId;
3357 auto clipPlugin = std::make_shared<DefaultClip>();
3358 EXPECT_NE(clipPlugin, nullptr);
3359 tempPasteboard->PreEstablishP2PLink(networkId, clipPlugin.get());
3360 tempPasteboard->p2pEstablishInfo_.pasteBlock = nullptr;
3361 std::string p2pPresyncId = "P2pPreSyncId_";
3362 int32_t pid = 123;
3363 ConcurrentMap<std::string, int32_t> p2pMap;
3364 p2pMap.Insert(p2pPresyncId, pid);
3365 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
3366 tempPasteboard->PreEstablishP2PLink(networkId, clipPlugin.get());
3367 #else
3368 ASSERT_TRUE(true);
3369 #endif
3370 }
3371
3372 /**
3373 * @tc.name: AddPreSyncP2pTimeoutTaskTest001
3374 * @tc.desc: AddPreSyncP2pTimeoutTask
3375 * @tc.type: FUNC
3376 */
3377 HWTEST_F(PasteboardServiceTest, AddPreSyncP2pTimeoutTaskTest001, TestSize.Level0)
3378 {
3379 #ifdef PB_DEVICE_MANAGER_ENABLE
3380 auto tempPasteboard = std::make_shared<PasteboardService>();
3381 EXPECT_NE(tempPasteboard, nullptr);
3382 std::string networkId = "TestNetworkId";
3383 tempPasteboard->AddPreSyncP2pTimeoutTask(networkId);
3384 tempPasteboard->ffrtTimer_ = std::make_shared<FFRTTimer>();
3385 EXPECT_NE(tempPasteboard->ffrtTimer_, nullptr);
3386 tempPasteboard->AddPreSyncP2pTimeoutTask(networkId);
3387 #else
3388 ASSERT_TRUE(true);
3389 #endif
3390 }
3391
3392 /**
3393 * @tc.name: CheckAndGrantRemoteUriTest001
3394 * @tc.desc: CheckAndGrantRemoteUri
3395 * @tc.type: FUNC
3396 */
3397 HWTEST_F(PasteboardServiceTest, CheckAndGrantRemoteUriTest001, TestSize.Level0)
3398 {
3399 #ifdef PB_DEVICE_MANAGER_ENABLE
3400 auto tempPasteboard = std::make_shared<PasteboardService>();
3401 EXPECT_NE(tempPasteboard, nullptr);
3402 PasteData data;
3403 data.SetRemote(true);
3404 AppInfo appInfo;
3405 std::string pasteId = "TestPasteId";
3406 std::string networkId = "TestNetworkId";
3407 std::shared_ptr<BlockObject<int32_t>> block = std::make_shared<BlockObject<int32_t>>(2000, 0);
3408 EXPECT_NE(block, nullptr);
3409 int32_t result = tempPasteboard->CheckAndGrantRemoteUri(data, appInfo, pasteId, networkId, block);
3410 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
3411 #else
3412 ASSERT_TRUE(true);
3413 #endif
3414 }
3415
3416 /**
3417 * @tc.name: ResubscribeObserver001
3418 * @tc.desc: ResubscribeObserver001
3419 * @tc.type: FUNC
3420 */
3421 HWTEST_F(PasteboardServiceTest, ResubscribeObserver001, TestSize.Level0)
3422 {
3423 auto tempPasteboard = std::make_shared<PasteboardService>();
3424 EXPECT_NE(tempPasteboard, nullptr);
3425
3426 auto type = PasteboardObserverType::OBSERVER_LOCAL;
3427 const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
3428
3429 int32_t res = tempPasteboard->ResubscribeObserver(type, observer);
3430 EXPECT_EQ(res, ERR_OK);
3431 }
3432
3433 /**
3434 * @tc.name: ResubscribeObserver002
3435 * @tc.desc: ResubscribeObserver002
3436 * @tc.type: FUNC
3437 */
3438 HWTEST_F(PasteboardServiceTest, ResubscribeObserver002, TestSize.Level0)
3439 {
3440 auto tempPasteboard = std::make_shared<PasteboardService>();
3441 EXPECT_NE(tempPasteboard, nullptr);
3442
3443 auto type = PasteboardObserverType::OBSERVER_LOCAL;
3444 const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
3445
3446 NiceMock<PasteboardServiceInterfaceMock> mock;
3447 EXPECT_CALL(mock, GetTokenTypeFlag).WillRepeatedly(Return(ATokenTypeEnum::TOKEN_HAP));
3448 int32_t res = tempPasteboard->ResubscribeObserver(type, observer);
3449 EXPECT_EQ(res, ERR_OK);
3450 }
3451
3452 }
3453 } // namespace OHOS::MiscServices