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 <gtest/gtest.h>
17 #include <unistd.h>
18 #include "ipc_skeleton.h"
19 #include "message_parcel_warp.h"
20 #include "pasteboard_error.h"
21 #include "pasteboard_hilog.h"
22 #include "pasteboard_service.h"
23 #include "paste_data_entry.h"
24 #include <thread>
25
26 using namespace testing;
27 using namespace testing::ext;
28 using namespace OHOS;
29 using namespace OHOS::MiscServices;
30 using namespace std::chrono;
31 using namespace OHOS::Security::AccessToken;
32
33 namespace OHOS {
34 namespace {
35 const int INT_ONE = 1;
36 const int32_t INT32_NEGATIVE_NUMBER = -1;
37 constexpr int32_t SET_VALUE_SUCCESS = 1;
38 const int INT_THREETHREETHREE = 333;
39 const uint32_t MAX_RECOGNITION_LENGTH = 1000;
40 const int32_t ACCOUNT_IDS_RANDOM = 1121;
41 const uint32_t UINT32_ONE = 1;
42 constexpr int64_t MIN_ASHMEM_DATA_SIZE = 32 * 1024;
43 constexpr uint32_t EVENT_TIME_OUT = 2000;
44 const std::string TEST_ENTITY_TEXT =
45 "清晨,从杭州市中心出发,沿着湖滨路缓缓前行。湖滨路是杭州市中心通往西湖的主要街道之一,两旁绿树成荫,湖光山色尽收眼"
46 "底。你可以选择步行或骑行,感受微风拂面的惬意。湖滨路的尽头是南山路,这里有一片开阔的广场,是欣赏西湖全景的绝佳位置"
47 "。进入南山路后,继续前行,雷峰塔的轮廓会逐渐映入眼帘。雷峰塔是西湖的标志性建筑之一,矗立在南屏山下,与西湖相映成趣"
48 "。你可以在这里稍作停留,欣赏塔的雄伟与湖水的柔美。南山路两旁有许多咖啡馆和餐厅,是补充能量的好去处。离开雷峰塔,沿"
49 "着南山路继续前行,你会看到一条蜿蜒的堤岸——杨公堤。杨公堤是西湖十景之一,堤岸两旁种满了柳树和桃树,春夏之交,柳绿桃"
50 "红,美不胜收。你可以选择沿着堤岸漫步,感受湖水的宁静与柳树的轻柔。杨公堤的尽头是湖心亭,这里是西湖的中心地带,也是"
51 "观赏西湖全景的最佳位置之一。从湖心亭出发,沿着湖畔步行至北山街。北山街是西湖北部的一条主要街道,两旁有许多历史建筑"
52 "和文化遗址。继续前行,你会看到保俶塔矗立在宝石流霞景区。保俶塔是西湖的另一座标志性建筑,与雷峰塔遥相呼应,形成“一"
53 "南一北”的独特景观。离开保俶塔,沿着北山街继续前行,你会到达断桥。断桥是西湖十景之一,冬季可欣赏断桥残雪的美景。断"
54 "桥的两旁种满了柳树,湖水清澈见底,是拍照留念的好地方。断桥的尽头是平湖秋月,这里是观赏西湖夜景的绝佳地点,夜晚灯光"
55 "亮起时,湖面倒映着月光,美轮美奂。游览结束后,沿着湖畔返回杭州市中心。沿途可以再次欣赏西湖的湖光山色,感受大自然的"
56 "和谐与宁静。如果你时间充裕,可以选择在湖畔的咖啡馆稍作休息,回味这一天的旅程。这条路线涵盖了西湖的主要经典景点,从"
57 "湖滨路到南山路,再到杨公堤、北山街,最后回到杭州市中心,整个行程大约需要一天时间。沿着这条路线,你可以领略西湖的自"
58 "然风光和文化底蕴,感受人间天堂的独特魅力。";
59 const int64_t DEFAULT_MAX_RAW_DATA_SIZE = 128 * 1024 * 1024;
60 constexpr int32_t MIMETYPE_MAX_SIZE = 1024;
61 static constexpr uint64_t ONE_HOUR_MILLISECONDS = 60 * 60 * 1000;
62 } // namespace
63
64 class MyTestEntityRecognitionObserver : public IEntityRecognitionObserver {
OnRecognitionEvent(EntityType entityType,std::string & entity)65 void OnRecognitionEvent(EntityType entityType, std::string &entity)
66 {
67 return;
68 }
AsObject()69 sptr<IRemoteObject> AsObject()
70 {
71 return nullptr;
72 }
73 };
74
75 class MyTestPasteboardChangedObserver : public IPasteboardChangedObserver {
OnPasteboardChanged()76 void OnPasteboardChanged()
77 {
78 return;
79 }
OnPasteboardEvent(std::string bundleName,int32_t status)80 void OnPasteboardEvent(std::string bundleName, int32_t status)
81 {
82 return;
83 }
AsObject()84 sptr<IRemoteObject> AsObject()
85 {
86 return nullptr;
87 }
88 };
89
90 class PasteboardEntryGetterImpl : public IPasteboardEntryGetter {
91 public:
PasteboardEntryGetterImpl()92 PasteboardEntryGetterImpl() {};
~PasteboardEntryGetterImpl()93 ~PasteboardEntryGetterImpl() {};
GetRecordValueByType(uint32_t recordId,PasteDataEntry & value)94 int32_t GetRecordValueByType(uint32_t recordId, PasteDataEntry &value)
95 {
96 return 0;
97 };
AsObject()98 sptr<IRemoteObject> AsObject()
99 {
100 return nullptr;
101 };
102 };
103
104 class PasteboardDelayGetterImpl : public IPasteboardDelayGetter {
105 public:
PasteboardDelayGetterImpl()106 PasteboardDelayGetterImpl() {};
~PasteboardDelayGetterImpl()107 ~PasteboardDelayGetterImpl() {};
GetPasteData(const std::string & type,PasteData & data)108 void GetPasteData(const std::string &type, PasteData &data) {};
GetUnifiedData(const std::string & type,UDMF::UnifiedData & data)109 void GetUnifiedData(const std::string &type, UDMF::UnifiedData &data) {};
AsObject()110 sptr<IRemoteObject> AsObject()
111 {
112 return nullptr;
113 };
114 };
115
116 class RemoteObjectTest : public IRemoteObject {
117 public:
RemoteObjectTest(std::u16string descriptor)118 explicit RemoteObjectTest(std::u16string descriptor) : IRemoteObject(descriptor) { }
~RemoteObjectTest()119 ~RemoteObjectTest() { }
120
GetObjectRefCount()121 int32_t GetObjectRefCount()
122 {
123 return 0;
124 }
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)125 int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
126 {
127 return 0;
128 }
AddDeathRecipient(const sptr<DeathRecipient> & recipient)129 bool AddDeathRecipient(const sptr<DeathRecipient> &recipient)
130 {
131 return true;
132 }
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)133 bool RemoveDeathRecipient(const sptr<DeathRecipient> &recipient)
134 {
135 return true;
136 }
Dump(int fd,const std::vector<std::u16string> & args)137 int Dump(int fd, const std::vector<std::u16string> &args)
138 {
139 return 0;
140 }
141 };
142
143 class PasteboardServiceTest : public testing::Test {
144 public:
145 static void SetUpTestCase(void);
146 static void TearDownTestCase(void);
147 void SetUp();
148 void TearDown();
149 int32_t WritePasteData(PasteData &pasteData, std::vector<uint8_t> &buffer, int &fd,
150 int64_t &tlvSize, MessageParcelWarp &messageData, MessageParcel &parcelPata);
151 using TestEvent = ClipPlugin::GlobalEvent;
152 using TaskContext = PasteboardService::RemoteDataTaskManager::TaskContext;
153 };
154
SetUpTestCase(void)155 void PasteboardServiceTest::SetUpTestCase(void) { }
156
TearDownTestCase(void)157 void PasteboardServiceTest::TearDownTestCase(void) { }
158
SetUp(void)159 void PasteboardServiceTest::SetUp(void) { }
160
TearDown(void)161 void PasteboardServiceTest::TearDown(void) { }
162
WritePasteData(PasteData & pasteData,std::vector<uint8_t> & buffer,int & fd,int64_t & tlvSize,MessageParcelWarp & messageData,MessageParcel & parcelPata)163 int32_t PasteboardServiceTest::WritePasteData(PasteData &pasteData, std::vector<uint8_t> &buffer, int &fd,
164 int64_t &tlvSize, MessageParcelWarp &messageData, MessageParcel &parcelPata)
165 {
166 std::vector<uint8_t> pasteDataTlv(0);
167 bool result = pasteData.Encode(pasteDataTlv);
168 if (!result) {
169 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "paste data encode failed.");
170 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
171 }
172 tlvSize = static_cast<int64_t>(pasteDataTlv.size());
173 if (tlvSize > MIN_ASHMEM_DATA_SIZE) {
174 if (!messageData.WriteRawData(parcelPata, pasteDataTlv.data(), pasteDataTlv.size())) {
175 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "Failed to WriteRawData");
176 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
177 }
178 fd = messageData.GetWriteDataFd();
179 pasteDataTlv.clear();
180 } else {
181 fd = messageData.CreateTmpFd();
182 if (fd < 0) {
183 PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "Failed to create tmp fd");
184 return static_cast<int32_t>(PasteboardError::SERIALIZATION_ERROR);
185 }
186 }
187 buffer = std::move(pasteDataTlv);
188 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "set: fd:%{public}d, size:%{public}" PRId64, fd, tlvSize);
189 return static_cast<int32_t>(PasteboardError::E_OK);
190 }
191
192 namespace MiscServices {
193 /**
194 * @tc.name: OnInputEventTest001
195 * @tc.desc: test Func OnInputEvent
196 * @tc.type: FUNC
197 */
198 HWTEST_F(PasteboardServiceTest, OnInputEventTest001, TestSize.Level0)
199 {
200 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest001 start");
201 auto tempPasteboard = std::make_shared<InputEventCallback>();
202 EXPECT_NE(tempPasteboard, nullptr);
203
204 MMI::KeyEvent::KeyItem keyItem1;
205 keyItem1.SetKeyCode(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
206 std::vector<MMI::KeyEvent::KeyItem> keys = {keyItem1};
207 auto keyEvent = std::make_shared<MMI::KeyEvent>(0);
208 EXPECT_NE(keyEvent, nullptr);
209
210 keyEvent->SetKeyItem(keys);
211 keyEvent->SetAction(MMI::KeyEvent::KEY_ACTION_DOWN);
212 tempPasteboard->OnInputEvent(keyEvent);
213 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest001 end");
214 }
215
216 /**
217 * @tc.name: OnInputEventTest002
218 * @tc.desc: test Func OnInputEvent
219 * @tc.type: FUNC
220 */
221 HWTEST_F(PasteboardServiceTest, OnInputEventTest002, TestSize.Level0)
222 {
223 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest002 start");
224 auto tempPasteboard = std::make_shared<InputEventCallback>();
225 EXPECT_NE(tempPasteboard, nullptr);
226
227 MMI::KeyEvent::KeyItem keyItem1;
228 keyItem1.SetKeyCode(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
229 std::vector<MMI::KeyEvent::KeyItem> keys = {keyItem1, keyItem1};
230 auto keyEvent = std::make_shared<MMI::KeyEvent>(0);
231 EXPECT_NE(keyEvent, nullptr);
232
233 keyEvent->SetKeyItem(keys);
234 keyEvent->SetAction(MMI::KeyEvent::KEY_ACTION_DOWN);
235 tempPasteboard->OnInputEvent(keyEvent);
236 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest002 end");
237 }
238
239 /**
240 * @tc.name: OnInputEventTest003
241 * @tc.desc: test Func OnInputEvent
242 * @tc.type: FUNC
243 */
244 HWTEST_F(PasteboardServiceTest, OnInputEventTest003, TestSize.Level0)
245 {
246 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest003 start");
247 auto tempPasteboard = std::make_shared<InputEventCallback>();
248 EXPECT_NE(tempPasteboard, nullptr);
249
250 MMI::KeyEvent::KeyItem keyItem1;
251 keyItem1.SetKeyCode(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
252 MMI::KeyEvent::KeyItem keyItem2;
253 keyItem2.SetKeyCode(MMI::KeyEvent::KEYCODE_V);
254 std::vector<MMI::KeyEvent::KeyItem> keys = {keyItem1, keyItem2};
255 auto keyEvent = std::make_shared<MMI::KeyEvent>(0);
256 EXPECT_NE(keyEvent, nullptr);
257
258 keyEvent->SetKeyItem(keys);
259 keyEvent->SetAction(MMI::KeyEvent::KEY_ACTION_DOWN);
260 keyEvent->SetTargetWindowId(123);
261 tempPasteboard->OnInputEvent(keyEvent);
262 tempPasteboard->OnInputEvent(keyEvent);
263 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest003 end");
264 }
265
266 /**
267 * @tc.name: OnInputEventTest004
268 * @tc.desc: test Func OnInputEvent
269 * @tc.type: FUNC
270 */
271 HWTEST_F(PasteboardServiceTest, OnInputEventTest004, TestSize.Level0)
272 {
273 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest004 start");
274 auto pasteboardServer = std::make_shared<PasteboardService>();
275 EXPECT_NE(pasteboardServer, nullptr);
276
277 auto inputCB = std::make_shared<InputEventCallback>(InputEventCallback::INPUTTYPE_PRESYNC, pasteboardServer.get());
278 EXPECT_NE(inputCB, nullptr);
279
280 MMI::KeyEvent::KeyItem keyItem1;
281 keyItem1.SetKeyCode(MMI::KeyEvent::KEYCODE_CTRL_LEFT);
282 std::vector<MMI::KeyEvent::KeyItem> keys = {keyItem1};
283 auto keyEvent = std::make_shared<MMI::KeyEvent>(0);
284 EXPECT_NE(keyEvent, nullptr);
285
286 keyEvent->SetKeyItem(keys);
287 keyEvent->SetAction(MMI::KeyEvent::KEY_ACTION_DOWN);
288 inputCB->OnInputEvent(keyEvent);
289 auto pointerEvent = MMI::PointerEvent::Create();
290 EXPECT_NE(pointerEvent, nullptr);
291
292 inputCB->OnInputEvent(pointerEvent);
293 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnInputEventTest004 end");
294 }
295
296 /**
297 * @tc.name: IsCtrlVProcessTest001
298 * @tc.desc: test Func IsCtrlVProcess
299 * @tc.type: FUNC
300 */
301 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest001, TestSize.Level0)
302 {
303 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest001 start");
304 auto tempPasteboard = std::make_shared<InputEventCallback>();
305 EXPECT_NE(tempPasteboard, nullptr);
306
307 uint32_t callingPid = 1;
308 bool isFocused = 1;
309 auto result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
310 EXPECT_EQ(result, false);
311 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest001 end");
312 }
313
314 /**
315 * @tc.name: IsCtrlVProcessTest002
316 * @tc.desc: test Func IsCtrlVProcess
317 * @tc.type: FUNC
318 */
319 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest002, TestSize.Level0)
320 {
321 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest002 start");
322 auto tempPasteboard = std::make_shared<InputEventCallback>();
323 EXPECT_NE(tempPasteboard, nullptr);
324
325 uint32_t callingPid = 1;
326 bool isFocused = true;
327 tempPasteboard->windowPid_ = callingPid;
328 tempPasteboard->actionTime_ = static_cast<uint64_t>(
329 duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
330 std::shared_ptr<BlockObject<int32_t>> block = std::make_shared<BlockObject<int32_t>>(100, 0);
331 tempPasteboard->blockMap_.insert(std::make_pair(callingPid, block));
332 auto result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
333 EXPECT_EQ(result, true);
334 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest002 end");
335 }
336
337 /**
338 * @tc.name: IsCtrlVProcessTest003
339 * @tc.desc: test Func IsCtrlVProcess
340 * @tc.type: FUNC
341 */
342 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest003, TestSize.Level0)
343 {
344 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest003 start");
345 auto tempPasteboard = std::make_shared<InputEventCallback>();
346 EXPECT_NE(tempPasteboard, nullptr);
347
348 uint32_t callingPid = 1;
349 bool isFocused = true;
350 std::shared_ptr<BlockObject<int32_t>> block = nullptr;
351 tempPasteboard->blockMap_.insert(std::make_pair(callingPid, block));
352 tempPasteboard->windowPid_ = 2;
353 tempPasteboard->actionTime_ = static_cast<uint64_t>(
354 duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
355 auto result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
356 EXPECT_EQ(result, true);
357 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest003 end");
358 }
359
360 /**
361 * @tc.name: IsCtrlVProcessTest004
362 * @tc.desc: test Func IsCtrlVProcess
363 * @tc.type: FUNC
364 */
365 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest004, TestSize.Level0)
366 {
367 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest004 start");
368 auto tempPasteboard = std::make_shared<InputEventCallback>();
369 EXPECT_NE(tempPasteboard, nullptr);
370
371 uint32_t callingPid = 1;
372 bool isFocused = false;
373 std::shared_ptr<BlockObject<int32_t>> block = nullptr;
374 tempPasteboard->blockMap_.insert(std::make_pair(callingPid, block));
375 tempPasteboard->windowPid_ = 2;
376 auto result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
377 EXPECT_EQ(result, false);
378 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest004 end");
379 }
380
381 /**
382 * @tc.name: IsCtrlVProcessTest005
383 * @tc.desc: test Func IsCtrlVProcess
384 * @tc.type: FUNC
385 */
386 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest005, TestSize.Level0)
387 {
388 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest005 start");
389 auto tempPasteboard = std::make_shared<InputEventCallback>();
390 EXPECT_NE(tempPasteboard, nullptr);
391
392 uint32_t callingPid = 1;
393 bool isFocused = true;
394 std::shared_ptr<BlockObject<int32_t>> block = nullptr;
395 tempPasteboard->blockMap_.insert(std::make_pair(callingPid, block));
396 tempPasteboard->actionTime_ = static_cast<uint64_t>(
397 duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count()) + 2000;
398 auto result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
399 EXPECT_EQ(result, false);
400 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest005 end");
401 }
402
403 /**
404 * @tc.name: IsCtrlVProcessTest006
405 * @tc.desc: test Func IsCtrlVProcess
406 * @tc.type: FUNC
407 */
408 HWTEST_F(PasteboardServiceTest, IsCtrlVProcessTest006, TestSize.Level0)
409 {
410 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest006 start");
411 auto tempPasteboard = std::make_shared<InputEventCallback>();
412 EXPECT_NE(tempPasteboard, nullptr);
413
414 uint32_t callingPid = 1;
415 bool isFocused = true;
416 std::shared_ptr<BlockObject<int32_t>> block = nullptr;
417 tempPasteboard->blockMap_.insert(std::make_pair(callingPid, block));
418 tempPasteboard->actionTime_ = static_cast<uint64_t>(
419 duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
420 auto result = true;
421 if (tempPasteboard->actionTime_ > EVENT_TIME_OUT) {
422 tempPasteboard->actionTime_ -= EVENT_TIME_OUT;
423 } else {
424 tempPasteboard->actionTime_ += EVENT_TIME_OUT;
425 }
426 result = tempPasteboard->IsCtrlVProcess(callingPid, isFocused);
427 EXPECT_EQ(result, false);
428 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCtrlVProcessTest006 end");
429 }
430
431 /**
432 * @tc.name: CallbackEnterTest001
433 * @tc.desc: test Func CallbackEnter
434 * @tc.type: FUNC
435 * @tc.require:
436 * @tc.author:
437 */
438 HWTEST_F(PasteboardServiceTest, CallbackEnterTest001, TestSize.Level0)
439 {
440 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackEnterTest001 start");
441 auto tempPasteboard = std::make_shared<PasteboardService>();
442 EXPECT_NE(tempPasteboard, nullptr);
443
444 uint32_t code = static_cast<uint32_t>(IPasteboardServiceIpcCode::COMMAND_HAS_PASTE_DATA);
445
446 int32_t res = tempPasteboard->CallbackEnter(code);
447
448 EXPECT_EQ(res, ERR_NONE);
449 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackEnterTest001 end");
450 }
451
452 /**
453 * @tc.name: CallbackEnterTest002
454 * @tc.desc: test Func CallbackEnter
455 * @tc.type: FUNC
456 * @tc.require:
457 * @tc.author:
458 */
459 HWTEST_F(PasteboardServiceTest, CallbackEnterTest002, TestSize.Level0)
460 {
461 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackEnterTest002 start");
462 auto tempPasteboard = std::make_shared<PasteboardService>();
463 EXPECT_NE(tempPasteboard, nullptr);
464
465 uint32_t code = static_cast<uint32_t>(IPasteboardServiceIpcCode::COMMAND_HAS_PASTE_DATA) + 1;
466
467 int32_t res = tempPasteboard->CallbackEnter(code);
468
469 EXPECT_EQ(res, ERR_NONE);
470 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackEnterTest002 end");
471 }
472
473 /**
474 * @tc.name: CallbackExitTest001
475 * @tc.desc: test Func CallbackExit
476 * @tc.type: FUNC
477 * @tc.require:
478 * @tc.author:
479 */
480 HWTEST_F(PasteboardServiceTest, CallbackExitTest001, TestSize.Level0)
481 {
482 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackExitTest001 start");
483 auto tempPasteboard = std::make_shared<PasteboardService>();
484 EXPECT_NE(tempPasteboard, nullptr);
485
486 uint32_t code = static_cast<uint32_t>(IPasteboardServiceIpcCode::COMMAND_HAS_PASTE_DATA);
487 int32_t result = 123;
488
489 int32_t res = tempPasteboard->CallbackExit(code, result);
490
491 EXPECT_EQ(res, ERR_NONE);
492 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackExitTest001 end");
493 }
494
495 /**
496 * @tc.name: CallbackExitTest002
497 * @tc.desc: test Func CallbackExit
498 * @tc.type: FUNC
499 * @tc.require:
500 * @tc.author:
501 */
502 HWTEST_F(PasteboardServiceTest, CallbackExitTest002, TestSize.Level0)
503 {
504 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackExitTest002 start");
505 auto tempPasteboard = std::make_shared<PasteboardService>();
506 EXPECT_NE(tempPasteboard, nullptr);
507
508 uint32_t code = static_cast<uint32_t>(IPasteboardServiceIpcCode::COMMAND_HAS_PASTE_DATA) + 1;
509 int32_t result = 456;
510
511 int32_t res = tempPasteboard->CallbackExit(code, result);
512
513 EXPECT_EQ(res, ERR_NONE);
514 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CallbackExitTest002 end");
515 }
516
517 /**
518 * @tc.name: ClearTest001
519 * @tc.desc: test Func Clear
520 * @tc.type: FUNC
521 */
522 HWTEST_F(PasteboardServiceTest, ClearTest001, TestSize.Level0)
523 {
524 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearTest001 start");
525 auto tempPasteboard = std::make_shared<PasteboardService>();
526 EXPECT_NE(tempPasteboard, nullptr);
527
528 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
529 tempPasteboard->clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, std::make_shared<PasteData>());
530 int32_t result = tempPasteboard->Clear();
531 EXPECT_EQ(result, ERR_OK);
532 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearTest001 end");
533 }
534
535 /**
536 * @tc.name: ClearTest002
537 * @tc.desc: test Func Clear
538 * @tc.type: FUNC
539 */
540 HWTEST_F(PasteboardServiceTest, ClearTest002, TestSize.Level0)
541 {
542 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearTest002 start");
543 auto tempPasteboard = std::make_shared<InputEventCallback>();
544 EXPECT_NE(tempPasteboard, nullptr);
545
546 tempPasteboard->Clear();
547 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearTest002 end");
548 }
549
550 /**
551 * @tc.name: GetMimeTypesTest001
552 * @tc.desc: test Func GetMimeTypes
553 * @tc.type: FUNC
554 */
555 HWTEST_F(PasteboardServiceTest, GetMimeTypesTest001, TestSize.Level0)
556 {
557 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest001 start");
558 auto service = std::make_shared<PasteboardService>();
559 EXPECT_NE(service, nullptr);
560
561 service->currentScreenStatus = ScreenEvent::ScreenUnlocked;
562 std::vector<std::string> funcResult;
563 int32_t result = service->GetMimeTypes(funcResult);
564 EXPECT_EQ(result, ERR_OK);
565 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest001 end");
566 }
567
568 /**
569 * @tc.name: GetMimeTypesTest002
570 * @tc.desc: test Func GetMimeTypes
571 * @tc.type: FUNC
572 */
573 HWTEST_F(PasteboardServiceTest, GetMimeTypesTest002, TestSize.Level0)
574 {
575 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest002 start");
576 auto service = std::make_shared<PasteboardService>();
577 EXPECT_NE(service, nullptr);
578
579 service->currentUserId_ = ERROR_USERID;
580 std::vector<std::string> funcResult;
581 int32_t result = service->GetMimeTypes(funcResult);
582 EXPECT_EQ(result, ERR_OK);
583 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest002 end");
584 }
585
586 /**
587 * @tc.name: GetMimeTypesTest003
588 * @tc.desc: test Func GetMimeTypes
589 * @tc.type: FUNC
590 */
591 HWTEST_F(PasteboardServiceTest, GetMimeTypesTest003, TestSize.Level0)
592 {
593 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest003 start");
594 auto service = std::make_shared<PasteboardService>();
595 EXPECT_NE(service, nullptr);
596
597 service->currentScreenStatus = ScreenEvent::Default;
598 std::vector<std::string> funcResult;
599 int32_t result = service->GetMimeTypes(funcResult);
600 EXPECT_EQ(result, ERR_OK);
601 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest003 end");
602 }
603
604 /**
605 * @tc.name: GetMimeTypesTest004
606 * @tc.desc: test Func GetMimeTypes
607 * @tc.type: FUNC
608 */
609 HWTEST_F(PasteboardServiceTest, GetMimeTypesTest004, TestSize.Level0)
610 {
611 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest004 start");
612 auto service = std::make_shared<PasteboardService>();
613 EXPECT_NE(service, nullptr);
614
615 service->currentScreenStatus = ScreenEvent::ScreenLocked;
616 std::vector<std::string> funcResult;
617 int32_t result = service->GetMimeTypes(funcResult);
618 EXPECT_EQ(result, ERR_OK);
619 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetMimeTypesTest004 end");
620 }
621
622 /**
623 * @tc.name: HasDataTypeTest001
624 * @tc.desc: test Func HasDataType, currentScreenStatus is default.
625 * @tc.type: FUNC
626 */
627 HWTEST_F(PasteboardServiceTest, HasDataTypeTest001, TestSize.Level0)
628 {
629 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest001 start");
630 auto tempPasteboard = std::make_shared<PasteboardService>();
631 ASSERT_NE(tempPasteboard, nullptr);
632
633 bool funcResult;
634 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
635 EXPECT_EQ(res, ERR_OK);
636 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest001 end");
637 }
638
639 /**
640 * @tc.name: HasDataTypeTest002
641 * @tc.desc: test Func HasDataType, currentScreenStatus is ScreenEvent::ScreenUnlocked.
642 * @tc.type: FUNC
643 */
644 HWTEST_F(PasteboardServiceTest, HasDataTypeTest002, TestSize.Level0)
645 {
646 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest002 start");
647 auto tempPasteboard = std::make_shared<PasteboardService>();
648 ASSERT_NE(tempPasteboard, nullptr);
649
650 tempPasteboard->currentScreenStatus = ScreenEvent::ScreenUnlocked;
651 tempPasteboard->currentUserId_ = 1;
652 tempPasteboard->clipPlugin_ = nullptr;
653 bool funcResult;
654 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
655 EXPECT_EQ(res, ERR_OK);
656 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest002 end");
657 }
658
659 /**
660 * @tc.name: HasDataTypeTest003
661 * @tc.desc: test Func HasDataType
662 * @tc.type: FUNC
663 * @tc.require:
664 * @tc.author:
665 */
666 HWTEST_F(PasteboardServiceTest, HasDataTypeTest003, TestSize.Level0)
667 {
668 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest003 start");
669 auto tempPasteboard = std::make_shared<PasteboardService>();
670 ASSERT_NE(tempPasteboard, nullptr);
671
672 std::string mimeType = "";
673 bool hasType = false;
674 auto ret = tempPasteboard->HasDataType(mimeType, hasType);
675 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
676 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest003 end");
677 }
678
679 /**
680 * @tc.name: HasDataTypeTest004
681 * @tc.desc: test Func HasDataType
682 * @tc.type: FUNC
683 * @tc.require:
684 * @tc.author:
685 */
686 HWTEST_F(PasteboardServiceTest, HasDataTypeTest004, TestSize.Level0)
687 {
688 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest004 start");
689 auto tempPasteboard = std::make_shared<PasteboardService>();
690 ASSERT_NE(tempPasteboard, nullptr);
691
692 std::string mimeType(MIMETYPE_MAX_SIZE + 1, 'x');
693 bool hasType = false;
694 auto ret = tempPasteboard->HasDataType(mimeType, hasType);
695 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
696 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest004 end");
697 }
698
699 /**
700 * @tc.name: HasDataTypeTest005
701 * @tc.desc: test Func HasDataType, currentScreenStatus is ScreenEvent::Default.
702 * @tc.type: FUNC
703 */
704 HWTEST_F(PasteboardServiceTest, HasDataTypeTest005, TestSize.Level0)
705 {
706 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest005 start");
707 auto tempPasteboard = std::make_shared<PasteboardService>();
708 ASSERT_NE(tempPasteboard, nullptr);
709
710 tempPasteboard->currentScreenStatus = ScreenEvent::Default;
711 tempPasteboard->currentUserId_ = 1;
712 tempPasteboard->clipPlugin_ = nullptr;
713 bool funcResult;
714 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
715 EXPECT_EQ(res, ERR_OK);
716 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest005 end");
717 }
718
719 /**
720 * @tc.name: HasDataTypeTest006
721 * @tc.desc: test Func HasDataType, currentScreenStatus is ScreenEvent::ScreenLocked.
722 * @tc.type: FUNC
723 */
724 HWTEST_F(PasteboardServiceTest, HasDataTypeTest006, TestSize.Level0)
725 {
726 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest006 start");
727 auto tempPasteboard = std::make_shared<PasteboardService>();
728 ASSERT_NE(tempPasteboard, nullptr);
729
730 tempPasteboard->currentScreenStatus = ScreenEvent::ScreenLocked;
731 tempPasteboard->currentUserId_ = 1;
732 tempPasteboard->clipPlugin_ = nullptr;
733 bool funcResult;
734 int32_t res = tempPasteboard->HasDataType(MIMETYPE_TEXT_PLAIN, funcResult);
735 EXPECT_EQ(res, ERR_OK);
736 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasDataTypeTest006 end");
737 }
738
739 /**
740 * @tc.name: DetectPatternsTest001
741 * @tc.desc: test Func DetectPatterns, return PasteboardError::NO_DATA_ERROR.
742 * @tc.type: FUNC
743 */
744 HWTEST_F(PasteboardServiceTest, DetectPatternsTest001, TestSize.Level0)
745 {
746 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest001 start");
747 auto tempPasteboard = std::make_shared<PasteboardService>();
748 ASSERT_NE(tempPasteboard, nullptr);
749
750 std::vector<Pattern> patternsToCheck;
751 std::vector<Pattern> funcResult;
752 EXPECT_EQ(tempPasteboard->DetectPatterns(patternsToCheck, funcResult),
753 static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
754 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest001 end");
755 }
756
757 /**
758 * @tc.name: DetectPatternsTest002
759 * @tc.desc: test Func DetectPatterns, return PasteboardError::NO_DATA_ERROR.
760 * @tc.type: FUNC
761 */
762 HWTEST_F(PasteboardServiceTest, DetectPatternsTest002, TestSize.Level0)
763 {
764 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest002 start");
765 auto tempPasteboard = std::make_shared<PasteboardService>();
766 ASSERT_NE(tempPasteboard, nullptr);
767
768 int32_t userId = INT32_MAX;
769 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
770 ASSERT_NE(pasteData, nullptr);
771
772 pasteData->AddTextRecord("hello");
773 tempPasteboard->clips_.InsertOrAssign(userId, pasteData);
774 std::vector<Pattern> patternsToCheck;
775 std::vector<Pattern> funcResult;
776 EXPECT_EQ(tempPasteboard->DetectPatterns(patternsToCheck, funcResult),
777 static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
778 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest002 end");
779 }
780
781 /**
782 * @tc.name: DetectPatternsTest003
783 * @tc.desc: test Func DetectPatterns, test MIMETYPE_TEXT_PLAIN
784 * @tc.type: FUNC
785 */
786 HWTEST_F(PasteboardServiceTest, DetectPatternsTest003, TestSize.Level0)
787 {
788 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest003 start");
789 auto tempPasteboard = std::make_shared<PasteboardService>();
790 ASSERT_NE(tempPasteboard, nullptr);
791
792 int32_t userId = tempPasteboard->currentUserId_ = 1;
793 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
794 ASSERT_NE(pasteData, nullptr);
795
796 pasteData->AddTextRecord("hello");
797 tempPasteboard->clips_.InsertOrAssign(userId, pasteData);
798 std::vector<Pattern> patternsToCheck;
799 std::vector<Pattern> funcResult;
800 EXPECT_EQ(tempPasteboard->DetectPatterns(patternsToCheck, funcResult),
801 static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
802 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest003 end");
803 }
804
805 /**
806 * @tc.name: DetectPatternsTest004
807 * @tc.desc: test Func DetectPatterns, test MIMETYPE_TEXT_HTML
808 * @tc.type: FUNC
809 */
810 HWTEST_F(PasteboardServiceTest, DetectPatternsTest004, TestSize.Level0)
811 {
812 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest004 start");
813 auto tempPasteboard = std::make_shared<PasteboardService>();
814 ASSERT_NE(tempPasteboard, nullptr);
815
816 int32_t userId = tempPasteboard->currentUserId_ = 1;
817 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
818 ASSERT_NE(pasteData, nullptr);
819
820 pasteData->AddHtmlRecord("<div class='disable'>helloWorld</div>");
821 tempPasteboard->clips_.InsertOrAssign(userId, pasteData);
822 std::vector<Pattern> patternsToCheck;
823 std::vector<Pattern> funcResult;
824 EXPECT_EQ(tempPasteboard->DetectPatterns(patternsToCheck, funcResult),
825 static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
826 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest004 end");
827 }
828
829 /**
830 * @tc.name: DetectPatternsTest005
831 * @tc.desc: test Func DetectPatterns, test MIMETYPE_TEXT_URI
832 * @tc.type: FUNC
833 */
834 HWTEST_F(PasteboardServiceTest, DetectPatternsTest005, TestSize.Level0)
835 {
836 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest005 start");
837 auto tempPasteboard = std::make_shared<PasteboardService>();
838 ASSERT_NE(tempPasteboard, nullptr);
839
840 int32_t userId = tempPasteboard->currentUserId_ = 1;
841 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
842 ASSERT_NE(pasteData, nullptr);
843
844 OHOS::Uri uri("/");
845 pasteData->AddUriRecord(uri);
846 tempPasteboard->clips_.InsertOrAssign(userId, pasteData);
847 std::vector<Pattern> patternsToCheck;
848 std::vector<Pattern> funcResult;
849 EXPECT_EQ(tempPasteboard->DetectPatterns(patternsToCheck, funcResult),
850 static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
851 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DetectPatternsTest005 end");
852 }
853
854 /**
855 * @tc.name: GetDataSourceTest001
856 * @tc.desc: test Func GetDataSource
857 * @tc.type: FUNC
858 */
859 HWTEST_F(PasteboardServiceTest, GetDataSourceTest001, TestSize.Level0)
860 {
861 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSourceTest001 start");
862 auto tempPasteboard = std::make_shared<PasteboardService>();
863 EXPECT_NE(tempPasteboard, nullptr);
864
865 std::string bundlename = "test";
866 tempPasteboard->GetDataSource(bundlename);
867 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSourceTest001 end");
868 }
869
870 /**
871 * @tc.name: GetDataSourceTest002
872 * @tc.desc: test Func GetDataSource
873 * @tc.type: FUNC
874 */
875 HWTEST_F(PasteboardServiceTest, GetDataSourceTest002, TestSize.Level0)
876 {
877 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSourceTest002 start");
878 auto tempPasteboard = std::make_shared<PasteboardService>();
879 EXPECT_NE(tempPasteboard, nullptr);
880
881 std::string bundleName = "test_bundle_name";
882 int32_t userId = 100;
883 tempPasteboard->currentUserId_ = userId;
884 PasteDataProperty props_;
885 auto data = std::make_shared<PasteData>();
886 data->props_.isRemote = false;
887 data->props_.tokenId = 1;
888
889 tempPasteboard->clips_.Insert(userId, data);
890 auto result = tempPasteboard->GetDataSource(bundleName);
891 EXPECT_EQ(result, ERR_OK);
892 tempPasteboard->clips_.Erase(userId);
893 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSourceTest002 end");
894 }
895
896 /**
897 * @tc.name: RemoveGlobalShareOptionTest001
898 * @tc.desc: test Func RemoveGlobalShareOption
899 * @tc.type: FUNC
900 */
901 HWTEST_F(PasteboardServiceTest, RemoveGlobalShareOptionTest001, TestSize.Level0)
902 {
903 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveGlobalShareOptionTest001 start");
904 std::vector<uint32_t> tokenIds = { 1001, 1002, 1003 };
905 auto tempPasteboard = std::make_shared<PasteboardService>();
906 EXPECT_NE(tempPasteboard, nullptr);
907
908 tempPasteboard->RemoveGlobalShareOption(tokenIds);
909 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveGlobalShareOptionTest001 end");
910 }
911
912 /**
913 * @tc.name: SetAppShareOptionsTest001
914 * @tc.desc: test Func SetAppShareOptions
915 * @tc.type: FUNC
916 * @tc.require:
917 * @tc.author:
918 */
919 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest001, TestSize.Level0)
920 {
921 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest001 start");
922 auto tempPasteboard = std::make_shared<PasteboardService>();
923 EXPECT_NE(tempPasteboard, nullptr);
924
925 int32_t shareOptions = 0;
926 tempPasteboard->SetAppShareOptions(shareOptions);
927 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest001 end");
928 }
929
930 /**
931 * @tc.name: SetAppShareOptionsTest002
932 * @tc.desc: test Func SetAppShareOptions
933 * @tc.type: FUNC
934 * @tc.require:
935 * @tc.author:
936 */
937 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest002, TestSize.Level0)
938 {
939 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest002 start");
940 auto tempPasteboard = std::make_shared<PasteboardService>();
941 int32_t shareOptions = 3;
942 auto ret = tempPasteboard->SetAppShareOptions(shareOptions);
943 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
944 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest002 end");
945 }
946
947 /**
948 * @tc.name: SetAppShareOptionsTest003
949 * @tc.desc: test Func SetAppShareOptions
950 * @tc.type: FUNC
951 * @tc.require:
952 * @tc.author:
953 */
954 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest003, TestSize.Level0)
955 {
956 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest003 start");
957 auto tempPasteboard = std::make_shared<PasteboardService>();
958 EXPECT_NE(tempPasteboard, nullptr);
959
960 int32_t shareOptions = 2;
961 auto ret = tempPasteboard->SetAppShareOptions(shareOptions);
962 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
963 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest003 end");
964 }
965
966 /**
967 * @tc.name: SetAppShareOptionsTest004
968 * @tc.desc: test Func SetAppShareOptions
969 * @tc.type: FUNC
970 * @tc.require:
971 * @tc.author:
972 */
973 HWTEST_F(PasteboardServiceTest, SetAppShareOptionsTest004, TestSize.Level0)
974 {
975 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest004 start");
976 auto tempPasteboard = std::make_shared<PasteboardService>();
977 EXPECT_NE(tempPasteboard, nullptr);
978
979 int32_t shareOptions = 1;
980 auto ret = tempPasteboard->SetAppShareOptions(shareOptions);
981 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
982 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetAppShareOptionsTest004 end");
983 }
984
985 /**
986 * @tc.name: RemoveAppShareOptionsTest001
987 * @tc.desc: test Func RemoveAppShareOptions
988 * @tc.type: FUNC
989 */
990 HWTEST_F(PasteboardServiceTest, RemoveAppShareOptionsTest001, TestSize.Level0)
991 {
992 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest001 start");
993 auto tempPasteboard = std::make_shared<PasteboardService>();
994 EXPECT_NE(tempPasteboard, nullptr);
995
996 auto ret = tempPasteboard->RemoveAppShareOptions();
997 EXPECT_EQ(0, ret);
998 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAppShareOptionsTest001 end");
999 }
1000
1001 /**
1002 * @tc.name: OnStopTest001
1003 * @tc.desc: test Func OnStop
1004 * @tc.type: FUNC
1005 */
1006 HWTEST_F(PasteboardServiceTest, OnStopTest001, TestSize.Level0)
1007 {
1008 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStopTest001 start");
1009 auto tempPasteboard = std::make_shared<PasteboardService>();
1010 EXPECT_NE(tempPasteboard, nullptr);
1011
1012 tempPasteboard->OnStop();
1013 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStopTest001 end");
1014 }
1015
1016 /**
1017 * @tc.name: PasteCompleteTest001
1018 * @tc.desc: test Func PasteComplete
1019 * @tc.type: FUNC
1020 */
1021 HWTEST_F(PasteboardServiceTest, PasteCompleteTest001, TestSize.Level0)
1022 {
1023 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteCompleteTest001 start");
1024 std::string deviceId = "testId";
1025 std::string pasteId;
1026 auto service = std::make_shared<PasteboardService>();
1027 EXPECT_NE(service, nullptr);
1028
1029 int32_t result = service->PasteComplete(deviceId, pasteId);
1030 EXPECT_EQ(result, ERR_OK);
1031 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteCompleteTest001 end");
1032 }
1033
1034 /**
1035 * @tc.name: PasteCompleteTest002
1036 * @tc.desc: test Func PasteComplete
1037 * @tc.type: FUNC
1038 */
1039 HWTEST_F(PasteboardServiceTest, PasteCompleteTest002, TestSize.Level0)
1040 {
1041 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteCompleteTest002 start");
1042 std::string deviceId;
1043 std::string pasteId;
1044 auto service = std::make_shared<PasteboardService>();
1045 EXPECT_NE(service, nullptr);
1046
1047 int32_t result = service->PasteComplete(deviceId, pasteId);
1048 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::NO_DATA_ERROR));
1049 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteCompleteTest002 end");
1050 }
1051
1052 /**
1053 * @tc.name: PasteStartTest001
1054 * @tc.desc: test Func PasteStart
1055 * @tc.type: FUNC
1056 */
1057 HWTEST_F(PasteboardServiceTest, PasteStartTest001, TestSize.Level0)
1058 {
1059 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteStartTest001 start");
1060 auto service = std::make_shared<PasteboardService>();
1061 EXPECT_NE(service, nullptr);
1062
1063 service->ffrtTimer_ = nullptr;
1064 std::string pasteId;
1065 int32_t result = service->PasteStart(pasteId);
1066 EXPECT_EQ(result, ERR_OK);
1067 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteStartTest001 end");
1068 }
1069
1070 /**
1071 * @tc.name: PasteStartTest002
1072 * @tc.desc: test Func PasteStart
1073 * @tc.type: FUNC
1074 */
1075 HWTEST_F(PasteboardServiceTest, PasteStartTest002, TestSize.Level0)
1076 {
1077 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteStartTest002 start");
1078 auto service = std::make_shared<PasteboardService>();
1079 EXPECT_NE(service, nullptr);
1080
1081 service->ffrtTimer_ = std::make_shared<FFRTTimer>();
1082 std::string pasteId;
1083 int32_t result = service->PasteStart(pasteId);
1084 EXPECT_EQ(result, ERR_OK);
1085 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteStartTest002 end");
1086 }
1087
1088 /**
1089 * @tc.name: GetRemoteDeviceNameTest001
1090 * @tc.desc: test Func GetRemoteDeviceName
1091 * @tc.type: FUNC
1092 */
1093 HWTEST_F(PasteboardServiceTest, GetRemoteDeviceNameTest001, TestSize.Level0)
1094 {
1095 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDeviceNameTest001 start");
1096 auto service = std::make_shared<PasteboardService>();
1097 EXPECT_NE(service, nullptr);
1098
1099 service->currentUserId_ = ERROR_USERID;
1100 std::string deviceName;
1101 bool isRemote = false;
1102 int32_t result = service->GetRemoteDeviceName(deviceName, isRemote);
1103 EXPECT_EQ(result, ERR_OK);
1104 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDeviceNameTest001 end");
1105 }
1106
1107 /**
1108 * @tc.name: GetRemoteDeviceNameTest002
1109 * @tc.desc: test Func GetRemoteDeviceName
1110 * @tc.type: FUNC
1111 */
1112 HWTEST_F(PasteboardServiceTest, GetRemoteDeviceNameTest002, TestSize.Level1)
1113 {
1114 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDeviceNameTest002 start");
1115 PasteboardService service;
1116 std::string deviceName;
1117 bool isRemote;
1118
1119 EXPECT_EQ(service.GetRemoteDeviceName(deviceName, isRemote), ERR_OK);
1120 EXPECT_EQ(deviceName, "local");
1121 EXPECT_FALSE(isRemote);
1122 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDeviceNameTest002 end");
1123 }
1124
1125 /**
1126 * @tc.name: DumpTest001
1127 * @tc.desc: test Func Dump
1128 * @tc.type: FUNC
1129 */
1130 HWTEST_F(PasteboardServiceTest, DumpTest001, TestSize.Level0)
1131 {
1132 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpTest001 start");
1133 auto fd = 1;
1134 std::vector<std::u16string> args;
1135 auto tempPasteboard = std::make_shared<PasteboardService>();
1136 EXPECT_NE(tempPasteboard, nullptr);
1137
1138 tempPasteboard->Dump(fd, args);
1139 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpTest001 end");
1140 }
1141
1142 /**
1143 * @tc.name: GetChangeCountTest001
1144 * @tc.desc: test Func GetChangeCount
1145 * @tc.type: FUNC
1146 */
1147 HWTEST_F(PasteboardServiceTest, GetChangeCountTest001, TestSize.Level0)
1148 {
1149 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetChangeCountTest001 start");
1150 auto service = std::make_shared<PasteboardService>();
1151 EXPECT_NE(service, nullptr);
1152
1153 uint32_t changeCount = 0;
1154 int32_t result = service->GetChangeCount(changeCount);
1155 EXPECT_EQ(result, ERR_OK);
1156 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetChangeCountTest001 end");
1157 }
1158
1159 /**
1160 * @tc.name: ChangeStoreStatusTest001
1161 * @tc.desc: test Func ChangeStoreStatus
1162 * @tc.type: FUNC
1163 */
1164 HWTEST_F(PasteboardServiceTest, ChangeStoreStatusTest001, TestSize.Level0)
1165 {
1166 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ChangeStoreStatusTest001 start");
1167 auto tempPasteboard = std::make_shared<PasteboardService>();
1168 EXPECT_NE(tempPasteboard, nullptr);
1169
1170 int32_t userId = 1;
1171 tempPasteboard->ChangeStoreStatus(userId);
1172 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ChangeStoreStatusTest001 end");
1173 }
1174
1175 /**
1176 * @tc.name: CloseDistributedStoreTest001
1177 * @tc.desc: test Func CloseDistributedStore
1178 * @tc.type: FUNC
1179 */
1180 HWTEST_F(PasteboardServiceTest, CloseDistributedStoreTest001, TestSize.Level0)
1181 {
1182 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CloseDistributedStoreTest001 start");
1183 int32_t user = ACCOUNT_IDS_RANDOM;
1184 bool isNeedClear = false;
1185 auto tempPasteboard = std::make_shared<PasteboardService>();
1186 EXPECT_NE(tempPasteboard, nullptr);
1187
1188 tempPasteboard->CloseDistributedStore(user, isNeedClear);
1189 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CloseDistributedStoreTest001 end");
1190 }
1191
1192 /**
1193 * @tc.name: GetCurrentAccountIdTest001
1194 * @tc.desc: test Func GetCurrentAccountId
1195 * @tc.type: FUNC
1196 */
1197 HWTEST_F(PasteboardServiceTest, GetCurrentAccountIdTest001, TestSize.Level1)
1198 {
1199 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest001 start");
1200 auto tempPasteboard = std::make_shared<PasteboardService>();
1201 EXPECT_NE(tempPasteboard, nullptr);
1202
1203 tempPasteboard->GetCurrentAccountId();
1204 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest001 end");
1205 }
1206
1207 /**
1208 * @tc.name: GetCurrentAccountIdTest002
1209 * @tc.desc: test Func GetCurrentAccountId
1210 * @tc.type: FUNC
1211 */
1212 HWTEST_F(PasteboardServiceTest, GetCurrentAccountIdTest002, TestSize.Level1)
1213 {
1214 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest002 start");
1215 auto tempPasteboard = std::make_shared<PasteboardService>();
1216 EXPECT_NE(tempPasteboard, nullptr);
1217
1218 tempPasteboard->currentUserId_ = 1;
1219 int32_t result = tempPasteboard->GetCurrentAccountId();
1220 EXPECT_EQ(result, 1);
1221 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest002 end");
1222 }
1223
1224 /**
1225 * @tc.name: GetCurrentAccountIdTest003
1226 * @tc.desc: test Func GetCurrentAccountId
1227 * @tc.type: FUNC
1228 */
1229 HWTEST_F(PasteboardServiceTest, GetCurrentAccountIdTest003, TestSize.Level1)
1230 {
1231 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest003 start");
1232 auto tempPasteboard = std::make_shared<PasteboardService>();
1233 EXPECT_NE(tempPasteboard, nullptr);
1234
1235 tempPasteboard->currentUserId_ = ERROR_USERID;
1236 int32_t result = tempPasteboard->GetCurrentAccountId();
1237 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentAccountIdTest003 end");
1238 }
1239
1240 /**
1241 * @tc.name: SetPasteboardHistoryTest001
1242 * @tc.desc: test Func SetPasteboardHistory
1243 * @tc.type: FUNC
1244 */
1245 HWTEST_F(PasteboardServiceTest, SetPasteboardHistoryTest001, TestSize.Level0)
1246 {
1247 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteboardHistoryTest001 start");
1248 HistoryInfo info;
1249 info.time = "2023-01-01";
1250 info.bundleName = "com.example.app";
1251 info.state = "copied";
1252 info.remote = "false";
1253 auto tempPasteboard = std::make_shared<PasteboardService>();
1254 EXPECT_NE(tempPasteboard, nullptr);
1255
1256 tempPasteboard->SetPasteboardHistory(info);
1257 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetPasteboardHistoryTest001 end");
1258 }
1259
1260 /**
1261 * @tc.name: IsFocusedAppTest001
1262 * @tc.desc: test Func IsFocusedApp
1263 * @tc.type: FUNC
1264 */
1265 HWTEST_F(PasteboardServiceTest, IsFocusedAppTest001, TestSize.Level0)
1266 {
1267 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsFocusedAppTest001 start");
1268 auto tempPasteboard = std::make_shared<PasteboardService>();
1269 EXPECT_NE(tempPasteboard, nullptr);
1270
1271 uint32_t tokenId = UINT32_ONE;
1272 tempPasteboard->IsFocusedApp(tokenId);
1273 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsFocusedAppTest001 end");
1274 }
1275
1276 /**
1277 * @tc.name: SetInputMethodPidTest001
1278 * @tc.desc: test Func SetInputMethodPid
1279 * @tc.type: FUNC
1280 */
1281 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest001, TestSize.Level0)
1282 {
1283 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest001 start");
1284 auto tempPasteboard = std::make_shared<PasteboardService>();
1285 EXPECT_NE(tempPasteboard, nullptr);
1286
1287 auto userId = tempPasteboard->GetCurrentAccountId();
1288 pid_t callPid = 1;
1289 tempPasteboard->SetInputMethodPid(userId, callPid);
1290 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest001 end");
1291 }
1292
1293 /**
1294 * @tc.name: SetInputMethodPidTest002
1295 * @tc.desc: test Func SetInputMethodPid
1296 * @tc.type: FUNC
1297 */
1298 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest002, TestSize.Level0)
1299 {
1300 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest002 start");
1301 auto tempPasteboard = std::make_shared<PasteboardService>();
1302 EXPECT_NE(tempPasteboard, nullptr);
1303
1304 auto userId = 1;
1305 pid_t callPid = 1;
1306 tempPasteboard->SetInputMethodPid(userId, callPid);
1307 auto it = tempPasteboard->imeMap_.Find(userId);
1308 auto hasPid = it.first;
1309 EXPECT_NE(hasPid, true);
1310
1311 tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
1312 it = tempPasteboard->imeMap_.Find(userId);
1313 hasPid = it.first;
1314 EXPECT_EQ(hasPid, true);
1315 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest002 end");
1316 }
1317
1318 /**
1319 * @tc.name: SetInputMethodPidTest003
1320 * @tc.desc: test Func SetInputMethodPid
1321 * @tc.type: FUNC
1322 */
1323 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest003, TestSize.Level0)
1324 {
1325 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest003 start");
1326 auto tempPasteboard = std::make_shared<PasteboardService>();
1327 EXPECT_NE(tempPasteboard, nullptr);
1328
1329 auto userId = 1;
1330 pid_t callPid = 0;
1331 tempPasteboard->SetInputMethodPid(userId, callPid);
1332 auto it = tempPasteboard->imeMap_.Find(userId);
1333 auto hasPid = it.first;
1334 EXPECT_NE(hasPid, true);
1335
1336 tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
1337 it = tempPasteboard->imeMap_.Find(userId);
1338 hasPid = it.first;
1339 EXPECT_EQ(hasPid, true);
1340
1341 tempPasteboard->ClearInputMethodPidByPid(userId + 1, callPid);
1342 it = tempPasteboard->imeMap_.Find(userId);
1343 hasPid = it.first;
1344 EXPECT_EQ(hasPid, true);
1345 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest003 end");
1346 }
1347
1348 /**
1349 * @tc.name: SetInputMethodPidTest004
1350 * @tc.desc: test Func SetInputMethodPid
1351 * @tc.type: FUNC
1352 */
1353 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest004, TestSize.Level0)
1354 {
1355 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest004 start");
1356 auto tempPasteboard = std::make_shared<PasteboardService>();
1357 EXPECT_NE(tempPasteboard, nullptr);
1358
1359 auto userId = 1;
1360 pid_t callPid = 0;
1361 tempPasteboard->SetInputMethodPid(userId, callPid);
1362 auto it = tempPasteboard->imeMap_.Find(userId);
1363 auto hasPid = it.first;
1364 EXPECT_NE(hasPid, true);
1365
1366 tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
1367 it = tempPasteboard->imeMap_.Find(userId);
1368 hasPid = it.first;
1369 EXPECT_EQ(hasPid, true);
1370
1371 tempPasteboard->ClearInputMethodPidByPid(userId, callPid + 1);
1372 it = tempPasteboard->imeMap_.Find(userId);
1373 hasPid = it.first;
1374 EXPECT_EQ(hasPid, true);
1375 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest004 end");
1376 }
1377
1378 /**
1379 * @tc.name: SetInputMethodPidTest005
1380 * @tc.desc: test Func SetInputMethodPid
1381 * @tc.type: FUNC
1382 */
1383 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest005, TestSize.Level0)
1384 {
1385 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest005 start");
1386 auto tempPasteboard = std::make_shared<PasteboardService>();
1387 EXPECT_NE(tempPasteboard, nullptr);
1388
1389 auto userId = 1;
1390 pid_t callPid = 0;
1391 tempPasteboard->SetInputMethodPid(userId, callPid);
1392 auto it = tempPasteboard->imeMap_.Find(userId);
1393 auto hasPid = it.first;
1394 EXPECT_NE(hasPid, true);
1395
1396 tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
1397 it = tempPasteboard->imeMap_.Find(userId);
1398 hasPid = it.first;
1399 EXPECT_EQ(hasPid, true);
1400
1401 tempPasteboard->ClearInputMethodPidByPid(userId + 1, callPid + 1);
1402 it = tempPasteboard->imeMap_.Find(userId);
1403 hasPid = it.first;
1404 EXPECT_EQ(hasPid, true);
1405 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest005 end");
1406 }
1407
1408 /**
1409 * @tc.name: SetInputMethodPidTest006
1410 * @tc.desc: test Func SetInputMethodPid
1411 * @tc.type: FUNC
1412 */
1413 HWTEST_F(PasteboardServiceTest, SetInputMethodPidTest006, TestSize.Level0)
1414 {
1415 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest006 start");
1416 auto tempPasteboard = std::make_shared<PasteboardService>();
1417 EXPECT_NE(tempPasteboard, nullptr);
1418
1419 auto userId = 1;
1420 pid_t callPid = 0;
1421 tempPasteboard->SetInputMethodPid(userId, callPid);
1422 auto it = tempPasteboard->imeMap_.Find(userId);
1423 auto hasPid = it.first;
1424 EXPECT_NE(hasPid, true);
1425
1426 tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
1427 it = tempPasteboard->imeMap_.Find(userId);
1428 hasPid = it.first;
1429 EXPECT_EQ(hasPid, true);
1430
1431 tempPasteboard->ClearInputMethodPidByPid(userId, callPid);
1432 it = tempPasteboard->imeMap_.Find(userId);
1433 hasPid = it.first;
1434 EXPECT_NE(hasPid, true);
1435 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetInputMethodPidTest006 end");
1436 }
1437
1438 /**
1439 * @tc.name: ClearInputMethodPidByPidTest001
1440 * @tc.desc: test Func ClearInputMethodPidByPid
1441 * @tc.type: FUNC
1442 */
1443 HWTEST_F(PasteboardServiceTest, ClearInputMethodPidByPidTest001, TestSize.Level0)
1444 {
1445 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearInputMethodPidByPidTest001 start");
1446 auto tempPasteboard = std::make_shared<PasteboardService>();
1447 EXPECT_NE(tempPasteboard, nullptr);
1448
1449 auto userId = tempPasteboard->GetCurrentAccountId();
1450 pid_t callPid = 1;
1451 tempPasteboard->ClearInputMethodPidByPid(userId, callPid);
1452 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearInputMethodPidByPidTest001 end");
1453 }
1454
1455 /**
1456 * @tc.name: ClearInputMethodPidTest001
1457 * @tc.desc: test Func ClearInputMethodPid
1458 * @tc.type: FUNC
1459 */
1460 HWTEST_F(PasteboardServiceTest, ClearInputMethodPidTest001, TestSize.Level0)
1461 {
1462 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearInputMethodPidTest001 start");
1463 auto tempPasteboard = std::make_shared<PasteboardService>();
1464 EXPECT_NE(tempPasteboard, nullptr);
1465
1466 tempPasteboard->ClearInputMethodPid();
1467 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearInputMethodPidTest001 end");
1468 }
1469
1470 /**
1471 * @tc.name: IsSystemAppByFullTokenIDTest001
1472 * @tc.desc: test Func IsSystemAppByFullTokenID
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(PasteboardServiceTest, IsSystemAppByFullTokenIDTest001, TestSize.Level0)
1476 {
1477 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsSystemAppByFullTokenIDTest001 start");
1478 auto tempPasteboard = std::make_shared<PasteboardService>();
1479 EXPECT_NE(tempPasteboard, nullptr);
1480
1481 uint32_t tokenId = UINT32_ONE;
1482 tempPasteboard->IsSystemAppByFullTokenID(tokenId);
1483 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsSystemAppByFullTokenIDTest001 end");
1484 }
1485
1486 /**
1487 * @tc.name: GetFocusedAppInfoTest001
1488 * @tc.desc: test Func GetFocusedAppInfo
1489 * @tc.type: FUNC
1490 */
1491 HWTEST_F(PasteboardServiceTest, GetFocusedAppInfoTest001, TestSize.Level0)
1492 {
1493 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetFocusedAppInfoTest001 start");
1494 auto tempPasteboard = std::make_shared<PasteboardService>();
1495 EXPECT_NE(tempPasteboard, nullptr);
1496
1497 tempPasteboard->GetFocusedAppInfo();
1498 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetFocusedAppInfoTest001 end");
1499 }
1500
1501 /**
1502 * @tc.name: OnRemoteDiedTest001
1503 * @tc.desc: test Func OnRemoteDied
1504 * @tc.type: FUNC
1505 */
1506 HWTEST_F(PasteboardServiceTest, OnRemoteDiedTest001, TestSize.Level0)
1507 {
1508 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest001 start");
1509 wptr<IRemoteObject> deadRemote;
1510 constexpr int32_t userId = 111;
1511 PasteboardService service;
1512 auto tempPasteboard = std::make_shared<PasteboardService::DelayGetterDeathRecipient>(userId, service);
1513 EXPECT_NE(tempPasteboard, nullptr);
1514
1515 tempPasteboard->OnRemoteDied(deadRemote);
1516 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest001 end");
1517 }
1518
1519 /**
1520 * @tc.name: OnRemoteDiedTest002
1521 * @tc.desc: test Func OnRemoteDied
1522 * @tc.type: FUNC
1523 */
1524 HWTEST_F(PasteboardServiceTest, OnRemoteDiedTest002, TestSize.Level0)
1525 {
1526 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest002 start");
1527 constexpr int32_t userId = 111;
1528 PasteboardService service;
1529 wptr<IRemoteObject> deadRemote;
1530 auto tempPasteboard = std::make_shared<PasteboardService::EntryGetterDeathRecipient>(userId, service);
1531 EXPECT_NE(tempPasteboard, nullptr);
1532
1533 tempPasteboard->OnRemoteDied(deadRemote);
1534 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest002 end");
1535 }
1536
1537 /**
1538 * @tc.name: OnRemoteDiedTest003
1539 * @tc.desc: test Func OnRemoteDied
1540 * @tc.type: FUNC
1541 */
1542 HWTEST_F(PasteboardServiceTest, OnRemoteDiedTest003, TestSize.Level0)
1543 {
1544 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest003 start");
1545 PasteboardService service;
1546 pid_t pid = 2;
1547 auto tempPasteboard = std::make_shared<PasteboardService::PasteboardDeathRecipient>(service, nullptr, pid);
1548 EXPECT_NE(tempPasteboard, nullptr);
1549
1550 tempPasteboard->OnRemoteDied(nullptr);
1551 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoteDiedTest003 end");
1552 }
1553
1554 /**
1555 * @tc.name: ClearRemoteDataTask001
1556 * @tc.desc: test Func ClearRemoteDataTask
1557 * @tc.type: FUNC
1558 */
1559 HWTEST_F(PasteboardServiceTest, ClearRemoteDataTask001, TestSize.Level0)
1560 {
1561 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearRemoteDataTask001 start");
1562 std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
1563 std::make_shared<PasteboardService::RemoteDataTaskManager>();
1564 EXPECT_NE(remoteDataTaskManager, nullptr);
1565
1566 TestEvent event;
1567 remoteDataTaskManager->ClearRemoteDataTask(event);
1568 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ClearRemoteDataTask001 end");
1569 }
1570
1571 /**
1572 * @tc.name: WaitRemoteData001
1573 * @tc.desc: test Func WaitRemoteData
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(PasteboardServiceTest, WaitRemoteData001, TestSize.Level0)
1577 {
1578 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WaitRemoteData001 start");
1579 std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
1580 std::make_shared<PasteboardService::RemoteDataTaskManager>();
1581 EXPECT_NE(remoteDataTaskManager, nullptr);
1582
1583 TestEvent event;
1584 remoteDataTaskManager->WaitRemoteData(event);
1585 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WaitRemoteData001 end");
1586 }
1587
1588 /**
1589 * @tc.name: WaitRemoteData002
1590 * @tc.desc: test Func WaitRemoteData
1591 * @tc.type: FUNC
1592 */
1593 HWTEST_F(PasteboardServiceTest, WaitRemoteData002, TestSize.Level0)
1594 {
1595 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WaitRemoteData002 start");
1596 std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
1597 std::make_shared<PasteboardService::RemoteDataTaskManager>();
1598 EXPECT_NE(remoteDataTaskManager, nullptr);
1599
1600 TestEvent event;
1601 event.deviceId = "12345";
1602 event.seqId = 1;
1603
1604 auto key = event.deviceId + std::to_string(event.seqId);
1605 auto it = remoteDataTaskManager->dataTasks_.find(key);
1606 it = remoteDataTaskManager->dataTasks_.emplace(key, std::make_shared<TaskContext>()).first;
1607
1608 remoteDataTaskManager->WaitRemoteData(event);
1609 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WaitRemoteData002 end");
1610 }
1611
1612 /**
1613 * @tc.name: AddSysAbilityListenerTest001
1614 * @tc.desc: test Func AddSysAbilityListener
1615 * @tc.type: FUNC
1616 */
1617 HWTEST_F(PasteboardServiceTest, AddSysAbilityListenerTest001, TestSize.Level0)
1618 {
1619 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddSysAbilityListenerTest001 start");
1620 auto tempPasteboard = std::make_shared<PasteboardService>();
1621 EXPECT_NE(tempPasteboard, nullptr);
1622
1623 tempPasteboard->AddSysAbilityListener();
1624 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddSysAbilityListenerTest001 end");
1625 }
1626
1627 /**
1628 * @tc.name: InitScreenStatusTest001
1629 * @tc.desc: test Func InitScreenStatus
1630 * @tc.type: FUNC
1631 */
1632 HWTEST_F(PasteboardServiceTest, InitScreenStatusTest001, TestSize.Level0)
1633 {
1634 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "InitScreenStatusTest001 start");
1635 auto tempPasteboard = std::make_shared<PasteboardService>();
1636 EXPECT_NE(tempPasteboard, nullptr);
1637
1638 tempPasteboard->InitScreenStatus();
1639 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "InitScreenStatusTest001 end");
1640 }
1641
1642 /**
1643 * @tc.name: GetCurrentScreenStatusTest001
1644 * @tc.desc: test Func GetCurrentScreenStatus
1645 * @tc.type: FUNC
1646 */
1647 HWTEST_F(PasteboardServiceTest, GetCurrentScreenStatusTest001, TestSize.Level0)
1648 {
1649 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentScreenStatusTest001 start");
1650 auto tempPasteboard = std::make_shared<PasteboardService>();
1651 EXPECT_NE(tempPasteboard, nullptr);
1652
1653 tempPasteboard->GetCurrentScreenStatus();
1654 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCurrentScreenStatusTest001 end");
1655 }
1656
1657 /**
1658 * @tc.name: DumpHistoryTest001
1659 * @tc.desc: test Func DumpHistory
1660 * @tc.type: FUNC
1661 */
1662 HWTEST_F(PasteboardServiceTest, DumpHistoryTest001, TestSize.Level0)
1663 {
1664 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpHistoryTest001 start");
1665 auto tempPasteboard = std::make_shared<PasteboardService>();
1666 EXPECT_NE(tempPasteboard, nullptr);
1667
1668 tempPasteboard->DumpHistory();
1669 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpHistoryTest001 end");
1670 }
1671
1672 /**
1673 * @tc.name: DumpDataTest001
1674 * @tc.desc: test Func DumpData
1675 * @tc.type: FUNC
1676 */
1677 HWTEST_F(PasteboardServiceTest, DumpDataTest001, TestSize.Level0)
1678 {
1679 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest001 start");
1680 auto tempPasteboard = std::make_shared<PasteboardService>();
1681 EXPECT_NE(tempPasteboard, nullptr);
1682
1683 tempPasteboard->DumpData();
1684 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DumpDataTest001 end");
1685 }
1686
1687 /**
1688 * @tc.name: ThawInputMethodTest001
1689 * @tc.desc: test Func ThawInputMethod
1690 * @tc.type: FUNC
1691 */
1692 HWTEST_F(PasteboardServiceTest, ThawInputMethodTest001, TestSize.Level0)
1693 {
1694 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ThawInputMethodTest001 start");
1695 auto tempPasteboard = std::make_shared<PasteboardService>();
1696 EXPECT_NE(tempPasteboard, nullptr);
1697
1698 pid_t callPid = 1;
1699 tempPasteboard->ThawInputMethod(callPid);
1700 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ThawInputMethodTest001 end");
1701 }
1702
1703 /**
1704 * @tc.name: IsNeedThawTest001
1705 * @tc.desc: test Func IsNeedThaw
1706 * @tc.type: FUNC
1707 */
1708 HWTEST_F(PasteboardServiceTest, IsNeedThawTest001, TestSize.Level0)
1709 {
1710 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsNeedThawTest001 start");
1711 auto tempPasteboard = std::make_shared<PasteboardService>();
1712 EXPECT_NE(tempPasteboard, nullptr);
1713
1714 tempPasteboard->IsNeedThaw();
1715 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsNeedThawTest001 end");
1716 }
1717
1718 /**
1719 * @tc.name: ExtractEntityTest001
1720 * @tc.desc: test Func ExtractEntity
1721 * @tc.type: FUNC
1722 */
1723 HWTEST_F(PasteboardServiceTest, ExtractEntityTest001, TestSize.Level0)
1724 {
1725 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest001 start");
1726 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1727 EXPECT_NE(tempPasteboard, nullptr);
1728
1729 std::string entity = "{\"code\": \"0\"}";
1730 std::string location = "location";
1731 tempPasteboard->ExtractEntity(entity, location);
1732 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest001 end");
1733 }
1734
1735 /**
1736 * @tc.name: ExtractEntityTest002
1737 * @tc.desc: test Func ExtractEntity
1738 * @tc.type: FUNC
1739 */
1740 HWTEST_F(PasteboardServiceTest, ExtractEntityTest002, TestSize.Level0)
1741 {
1742 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest002 start");
1743 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1744 EXPECT_NE(tempPasteboard, nullptr);
1745
1746 std::string entity = R"({"code": 0})";
1747 std::string location = "";
1748 tempPasteboard->ExtractEntity(entity, location);
1749 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest002 end");
1750 }
1751
1752 /**
1753 * @tc.name: ExtractEntityTest003
1754 * @tc.desc: test Func ExtractEntity
1755 * @tc.type: FUNC
1756 */
1757 HWTEST_F(PasteboardServiceTest, ExtractEntityTest003, TestSize.Level0)
1758 {
1759 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest003 start");
1760 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1761 EXPECT_NE(tempPasteboard, nullptr);
1762
1763 std::string entity = R"({"code": 0, "entity": {"name": "example"}})";
1764 std::string location = "";
1765 tempPasteboard->ExtractEntity(entity, location);
1766 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest003 end");
1767 }
1768
1769 /**
1770 * @tc.name: ExtractEntityTest004
1771 * @tc.desc: test Func ExtractEntity
1772 * @tc.type: FUNC
1773 */
1774 HWTEST_F(PasteboardServiceTest, ExtractEntityTest004, TestSize.Level0)
1775 {
1776 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest004 start");
1777 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1778 EXPECT_NE(tempPasteboard, nullptr);
1779
1780 std::string entity = R"({"code": 0,"entity": {"location": "room1"}})";
1781 std::string location = "";
1782 tempPasteboard->ExtractEntity(entity, location);
1783 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest004 end");
1784 }
1785
1786 /**
1787 * @tc.name: ExtractEntityTest005
1788 * @tc.desc: test Func ExtractEntity
1789 * @tc.type: FUNC
1790 */
1791 HWTEST_F(PasteboardServiceTest, ExtractEntityTest005, TestSize.Level0)
1792 {
1793 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest005 start");
1794 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1795 EXPECT_NE(tempPasteboard, nullptr);
1796
1797 std::string entity = R"({"code": 0,"entity": {"location": ["room1", "room2"]}})";
1798 std::string location = "";
1799 tempPasteboard->ExtractEntity(entity, location);
1800 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ExtractEntityTest005 end");
1801 }
1802
1803 /**
1804 * @tc.name: InitServiceHandlerTest001
1805 * @tc.desc: test Func InitServiceHandler
1806 * @tc.type: FUNC
1807 */
1808 HWTEST_F(PasteboardServiceTest, InitServiceHandlerTest001, TestSize.Level0)
1809 {
1810 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "InitServiceHandlerTest001 start");
1811 auto tempPasteboard = std::make_shared<PasteboardService>();
1812 EXPECT_NE(tempPasteboard, nullptr);
1813
1814 tempPasteboard->InitServiceHandler();
1815 tempPasteboard->InitServiceHandler();
1816 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "InitServiceHandlerTest001 end");
1817 }
1818
1819 /**
1820 * @tc.name: IsCopyableTest001
1821 * @tc.desc: test Func IsCopyable
1822 * @tc.type: FUNC
1823 */
1824 HWTEST_F(PasteboardServiceTest, IsCopyableTest001, TestSize.Level0)
1825 {
1826 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCopyableTest001 start");
1827 auto tokenId = 123;
1828 auto tempPasteboard = std::make_shared<PasteboardService>();
1829 EXPECT_NE(tempPasteboard, nullptr);
1830
1831 tempPasteboard->IsCopyable(tokenId);
1832 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsCopyableTest001 end");
1833 }
1834
1835 /**
1836 * @tc.name: SaveData001
1837 * @tc.desc: test Func SaveData
1838 * @tc.type: FUNC
1839 */
1840 HWTEST_F(PasteboardServiceTest, SaveData001, TestSize.Level0)
1841 {
1842 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SaveData001 start");
1843 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1844 EXPECT_NE(tempPasteboard, nullptr);
1845
1846 PasteData pasteData;
1847 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
1848 EXPECT_NE(delayGetter, nullptr);
1849
1850 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
1851 EXPECT_NE(entryGetter, nullptr);
1852
1853 int64_t dataSize = 0;
1854 tempPasteboard->SaveData(pasteData, dataSize, delayGetter, entryGetter);
1855 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SaveData001 end");
1856 }
1857
1858 /**
1859 * @tc.name: HandleDelayDataAndRecord001
1860 * @tc.desc: test Func HandleDelayDataAndRecord
1861 * @tc.type: FUNC
1862 */
1863 HWTEST_F(PasteboardServiceTest, HandleDelayDataAndRecord001, TestSize.Level0)
1864 {
1865 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HandleDelayDataAndRecord001 start");
1866 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
1867 EXPECT_NE(tempPasteboard, nullptr);
1868
1869 PasteData pasteData;
1870 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
1871 EXPECT_NE(delayGetter, nullptr);
1872
1873 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
1874 EXPECT_NE(entryGetter, nullptr);
1875
1876 AppInfo appInfo;
1877 tempPasteboard->HandleDelayDataAndRecord(pasteData, delayGetter, entryGetter, appInfo);
1878 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HandleDelayDataAndRecord001 end");
1879 }
1880
1881 /**
1882 * @tc.name: RemovePasteDataTest001
1883 * @tc.desc: test Func RemovePasteData
1884 * @tc.type: FUNC
1885 */
1886 HWTEST_F(PasteboardServiceTest, RemovePasteDataTest001, TestSize.Level0)
1887 {
1888 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemovePasteDataTest001 start");
1889 AppInfo appInfo;
1890 appInfo.tokenId = 123;
1891 auto tempPasteboard = std::make_shared<PasteboardService>();
1892 EXPECT_NE(tempPasteboard, nullptr);
1893
1894 tempPasteboard->RemovePasteData(appInfo);
1895 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemovePasteDataTest001 end");
1896 }
1897
1898 /**
1899 * @tc.name: RemovePasteDataTest002
1900 * @tc.desc: test Func RemovePasteData
1901 * @tc.type: FUNC
1902 */
1903 HWTEST_F(PasteboardServiceTest, RemovePasteDataTest002, TestSize.Level1)
1904 {
1905 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemovePasteDataTest002 start");
1906 AppInfo appInfo;
1907 appInfo.tokenId = 123;
1908 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
1909 EXPECT_NE(delayGetter, nullptr);
1910
1911 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
1912 EXPECT_NE(entryGetter, nullptr);
1913
1914 auto tempPasteboard = std::make_shared<PasteboardService>();
1915 EXPECT_NE(tempPasteboard, nullptr);
1916 tempPasteboard->RemovePasteData(appInfo);
1917 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemovePasteDataTest002 end");
1918 }
1919
1920 /**
1921 * @tc.name: GetValidDistributeEventTest001
1922 * @tc.desc: test Func GetValidDistributeEvent
1923 * @tc.type: FUNC
1924 */
1925 HWTEST_F(PasteboardServiceTest, GetValidDistributeEventTest001, TestSize.Level1)
1926 {
1927 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest001 start");
1928 auto tempPasteboard = std::make_shared<PasteboardService>();
1929 EXPECT_NE(tempPasteboard, nullptr);
1930
1931 int32_t user = 100;
1932 tempPasteboard->GetValidDistributeEvent(user);
1933 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest001 end");
1934 }
1935
1936 /**
1937 * @tc.name: GetValidDistributeEventTest002
1938 * @tc.desc: test Func GetValidDistributeEvent
1939 * @tc.type: FUNC
1940 */
1941 HWTEST_F(PasteboardServiceTest, GetValidDistributeEventTest002, TestSize.Level1)
1942 {
1943 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest002 start");
1944 auto tempPasteboard = std::make_shared<PasteboardService>();
1945 EXPECT_NE(tempPasteboard, nullptr);
1946
1947 TestEvent evt;
1948 int32_t user = 100;
1949 auto plugin = nullptr;
1950 auto result = tempPasteboard->GetValidDistributeEvent(user);
1951 EXPECT_EQ(result.first, static_cast<int32_t>(PasteboardError::PLUGIN_IS_NULL));
1952 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest002 end");
1953 }
1954
1955 /**
1956 * @tc.name: GetValidDistributeEventTest003
1957 * @tc.desc: test Func GetValidDistributeEvent
1958 * @tc.type: FUNC
1959 * @tc.require:
1960 * @tc.author:
1961 */
1962 HWTEST_F(PasteboardServiceTest, GetValidDistributeEventTest003, TestSize.Level0)
1963 {
1964 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest003 start");
1965 auto tempPasteboard = std::make_shared<PasteboardService>();
1966 EXPECT_NE(tempPasteboard, nullptr);
1967
1968 int32_t user = 1234;
1969
1970 tempPasteboard->GetValidDistributeEvent(user);
1971 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetValidDistributeEventTest003 end");
1972 }
1973
1974 /**
1975 * @tc.name: GetSdkVersionTest001
1976 * @tc.desc: test Func GetSdkVersion
1977 * @tc.type: FUNC
1978 */
1979 HWTEST_F(PasteboardServiceTest, GetSdkVersionTest001, TestSize.Level0)
1980 {
1981 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetSdkVersionTest001 start");
1982 auto tempPasteboard = std::make_shared<PasteboardService>();
1983 EXPECT_NE(tempPasteboard, nullptr);
1984
1985 uint32_t tokenId = 0x123456;
1986 tempPasteboard->GetSdkVersion(tokenId);
1987 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetSdkVersionTest001 end");
1988 }
1989
1990 /**
1991 * @tc.name: GetSdkVersionTest002
1992 * @tc.desc: test Func GetSdkVersion
1993 * @tc.type: FUNC
1994 * @tc.require:
1995 * @tc.author:
1996 */
1997 HWTEST_F(PasteboardServiceTest, GetSdkVersionTest002, TestSize.Level0)
1998 {
1999 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetSdkVersionTest002 start");
2000 auto tempPasteboard = std::make_shared<PasteboardService>();
2001 EXPECT_NE(tempPasteboard, nullptr);
2002
2003 uint32_t tokenId = 123;
2004
2005 int32_t result = tempPasteboard->GetSdkVersion(tokenId);
2006 EXPECT_EQ(result, -1);
2007 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetSdkVersionTest002 end");
2008 }
2009
2010 /**
2011 * @tc.name: GetCommonStateTest001
2012 * @tc.desc: test Func GetCommonState
2013 * @tc.type: FUNC
2014 */
2015 HWTEST_F(PasteboardServiceTest, GetCommonStateTest001, TestSize.Level0)
2016 {
2017 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCommonStateTest001 start");
2018 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2019 EXPECT_NE(tempPasteboard, nullptr);
2020
2021 int64_t dataSize = 0;
2022 CommonInfo info = tempPasteboard->GetCommonState(dataSize);
2023 EXPECT_EQ(info.deviceType, DMAdapter::GetInstance().GetLocalDeviceType());
2024 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetCommonStateTest001 end");
2025 }
2026
2027 /**
2028 * @tc.name: SetRadarEventTest001
2029 * @tc.desc: test Func SetRadarEvent
2030 * @tc.type: FUNC
2031 */
2032 HWTEST_F(PasteboardServiceTest, SetRadarEventTest001, TestSize.Level0)
2033 {
2034 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetRadarEventTest001 start");
2035 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2036 EXPECT_NE(tempPasteboard, nullptr);
2037
2038 PasteData pasteData;
2039 AppInfo appInfo;
2040 bool isPeerOnline = false;
2041 RadarReportInfo radarReportInfo;
2042 std::string peerNetId = "";
2043 tempPasteboard->SetRadarEvent(appInfo, pasteData, isPeerOnline, radarReportInfo, peerNetId);
2044 EXPECT_EQ(radarReportInfo.stageRes, 1);
2045 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetRadarEventTest001 end");
2046 }
2047
2048 /**
2049 * @tc.name: SetUeEventTest001
2050 * @tc.desc: test Func SetUeEvent
2051 * @tc.type: FUNC
2052 */
2053 HWTEST_F(PasteboardServiceTest, SetUeEventTest001, TestSize.Level0)
2054 {
2055 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetUeEventTest001 start");
2056 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2057 EXPECT_NE(tempPasteboard, nullptr);
2058
2059 PasteData pasteData;
2060 AppInfo appInfo;
2061 bool isPeerOnline = false;
2062 UeReportInfo ueReportInfo;
2063 std::string peerNetId = "";
2064 tempPasteboard->SetUeEvent(appInfo, pasteData, isPeerOnline, ueReportInfo, peerNetId);
2065 EXPECT_EQ(ueReportInfo.pasteInfo.onlineDevNum, DMAdapter::GetInstance().GetNetworkIds().size());
2066 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetUeEventTest001 end");
2067 }
2068
2069 /**
2070 * @tc.name: PostProcessDelayHtmlEntryTest001
2071 * @tc.desc: test Func PostProcessDelayHtmlEntry
2072 * @tc.type: FUNC
2073 */
2074 HWTEST_F(PasteboardServiceTest, PostProcessDelayHtmlEntryTest001, TestSize.Level0)
2075 {
2076 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest001 start");
2077 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2078 EXPECT_NE(tempPasteboard, nullptr);
2079
2080 PasteData pasteData;
2081 AppInfo targetAppInfo;
2082 PasteDataEntry entry;
2083 tempPasteboard->PostProcessDelayHtmlEntry(pasteData, targetAppInfo, entry);
2084 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest001 end");
2085 }
2086
2087 /**
2088 * @tc.name: PostProcessDelayHtmlEntryTest002
2089 * @tc.desc: test Func PostProcessDelayHtmlEntry
2090 * @tc.type: FUNC
2091 */
2092 HWTEST_F(PasteboardServiceTest, PostProcessDelayHtmlEntryTest002, TestSize.Level0)
2093 {
2094 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest002 start");
2095 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2096 EXPECT_NE(tempPasteboard, nullptr);
2097
2098 PasteData pasteData;
2099 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2100 AppInfo targetAppInfo;
2101 PasteDataEntry entry;
2102 entry.SetValue("test");
2103 tempPasteboard->PostProcessDelayHtmlEntry(pasteData, targetAppInfo, entry);
2104 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest002 end");
2105 }
2106
2107 /**
2108 * @tc.name: PostProcessDelayHtmlEntryTest003
2109 * @tc.desc: test Func PostProcessDelayHtmlEntry
2110 * @tc.type: FUNC
2111 */
2112 HWTEST_F(PasteboardServiceTest, PostProcessDelayHtmlEntryTest003, TestSize.Level0)
2113 {
2114 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest003 start");
2115 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2116 EXPECT_NE(tempPasteboard, nullptr);
2117
2118 PasteData pasteData;
2119 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2120 AppInfo targetAppInfo;
2121 PasteDataEntry entry;
2122 auto object = std::make_shared<Object>();
2123 EXPECT_NE(object, nullptr);
2124
2125 object->value_[UDMF::HTML_CONTENT] = "<div class='disable'>helloWorld</div>";
2126 entry.SetValue(object);
2127 tempPasteboard->PostProcessDelayHtmlEntry(pasteData, targetAppInfo, entry);
2128 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest003 end");
2129 }
2130
2131 /**
2132 * @tc.name: PostProcessDelayHtmlEntryTest004
2133 * @tc.desc: test Func PostProcessDelayHtmlEntry
2134 * @tc.type: FUNC
2135 */
2136 HWTEST_F(PasteboardServiceTest, PostProcessDelayHtmlEntryTest004, TestSize.Level0)
2137 {
2138 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest004 start");
2139 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2140 EXPECT_NE(tempPasteboard, nullptr);
2141
2142 PasteData pasteData;
2143 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2144 AppInfo targetAppInfo;
2145 PasteDataEntry entry;
2146 entry.SetValue(1);
2147 tempPasteboard->PostProcessDelayHtmlEntry(pasteData, targetAppInfo, entry);
2148 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PostProcessDelayHtmlEntryTest004 end");
2149 }
2150
2151 /**
2152 * @tc.name: GrantUriPermissionTest001
2153 * @tc.desc: test Func GrantUriPermission
2154 * @tc.type: FUNC
2155 */
2156 HWTEST_F(PasteboardServiceTest, GrantUriPermissionTest001, TestSize.Level1)
2157 {
2158 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GrantUriPermissionTest001 start");
2159 PasteboardService service;
2160 std::vector<Uri> emptyUris;
2161 std::string targetBundleName = "com.example.app";
2162 int32_t appIndex = 1;
2163 int32_t result = service.GrantUriPermission(emptyUris, targetBundleName, false, appIndex);
2164 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::E_OK));
2165 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GrantUriPermissionTest001 end");
2166 }
2167
2168 /**
2169 * @tc.name: GenerateDistributedUriTest001
2170 * @tc.desc: test Func GenerateDistributedUri
2171 * @tc.type: FUNC
2172 */
2173 HWTEST_F(PasteboardServiceTest, GenerateDistributedUriTest001, TestSize.Level0)
2174 {
2175 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest001 start");
2176 PasteData pasteData;
2177 auto tempPasteboard = std::make_shared<PasteboardService>();
2178 EXPECT_NE(tempPasteboard, nullptr);
2179 tempPasteboard->GenerateDistributedUri(pasteData);
2180 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest001 end");
2181 }
2182
2183 /**
2184 * @tc.name: GenerateDistributedUriTest002
2185 * @tc.desc: test Func GenerateDistributedUri
2186 * @tc.type: FUNC
2187 */
2188 HWTEST_F(PasteboardServiceTest, GenerateDistributedUriTest002, TestSize.Level0)
2189 {
2190 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest002 start");
2191 PasteData pasteData;
2192 auto tempPasteboard = std::make_shared<PasteboardService>();
2193 EXPECT_NE(tempPasteboard, nullptr);
2194
2195 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2196 pasteData.AddTextRecord("testRecord");
2197 pasteData.AddTextRecord(TEST_ENTITY_TEXT);
2198 pasteData.AddTextRecord("testRecord");
2199 OHOS::Uri uri("/");
2200 pasteData.AddUriRecord(uri);
2201 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2202
2203 tempPasteboard->GenerateDistributedUri(pasteData);
2204 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest002 end");
2205 }
2206
2207 /**
2208 * @tc.name: GenerateDistributedUriTest003
2209 * @tc.desc: test Func GenerateDistributedUri
2210 * @tc.type: FUNC
2211 */
2212 HWTEST_F(PasteboardServiceTest, GenerateDistributedUriTest003, TestSize.Level0)
2213 {
2214 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest003 start");
2215 PasteData pasteData;
2216 auto tempPasteboard = std::make_shared<PasteboardService>();
2217 EXPECT_NE(tempPasteboard, nullptr);
2218
2219 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2220 pasteData.AddTextRecord("testRecord");
2221 pasteData.AddTextRecord(TEST_ENTITY_TEXT);
2222 pasteData.AddTextRecord("testRecord");
2223 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
2224
2225 tempPasteboard->GenerateDistributedUri(pasteData);
2226 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GenerateDistributedUriTest003 end");
2227 }
2228
2229 /**
2230 * @tc.name: IsBundleOwnUriPermission001
2231 * @tc.desc: test Func IsBundleOwnUriPermission
2232 * @tc.type: FUNC
2233 */
2234 HWTEST_F(PasteboardServiceTest, IsBundleOwnUriPermission001, TestSize.Level0)
2235 {
2236 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBundleOwnUriPermission001 start");
2237 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2238 EXPECT_NE(tempPasteboard, nullptr);
2239 std::string bundleName = "bundleName";
2240 std::shared_ptr<Uri> uri = std::make_shared<Uri>("text/html");
2241 tempPasteboard->IsBundleOwnUriPermission(bundleName, *uri);
2242 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBundleOwnUriPermission001 end");
2243 }
2244
2245 /**
2246 * @tc.name: GetAppLabelTest001
2247 * @tc.desc: test Func GetAppLabel
2248 * @tc.type: FUNC
2249 */
2250 HWTEST_F(PasteboardServiceTest, GetAppLabelTest001, TestSize.Level0)
2251 {
2252 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppLabelTest001 start");
2253 uint32_t tokenId = UINT32_ONE;
2254 auto tempPasteboard = std::make_shared<PasteboardService>();
2255 EXPECT_NE(tempPasteboard, nullptr);
2256 tempPasteboard->GetAppLabel(tokenId);
2257 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppLabelTest001 end");
2258 }
2259
2260 /**
2261 * @tc.name: GetAppBundleManagerTest001
2262 * @tc.desc: test Func GetAppBundleManager
2263 * @tc.type: FUNC
2264 */
2265 HWTEST_F(PasteboardServiceTest, GetAppBundleManagerTest001, TestSize.Level0)
2266 {
2267 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleManagerTest001 start");
2268 auto tempPasteboard = std::make_shared<PasteboardService>();
2269 EXPECT_NE(tempPasteboard->GetAppBundleManager(), nullptr);
2270 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleManagerTest001 end");
2271 }
2272
2273 /**
2274 * @tc.name: EstablishP2PLink001
2275 * @tc.desc: test Func EstablishP2PLink
2276 * @tc.type: FUNC
2277 */
2278 HWTEST_F(PasteboardServiceTest, EstablishP2PLink001, TestSize.Level0)
2279 {
2280 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "EstablishP2PLink001 start");
2281 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2282 EXPECT_NE(tempPasteboard, nullptr);
2283
2284 std::string networkId = "networkId";
2285 std::string pasteId = "pasteId";
2286 tempPasteboard->EstablishP2PLink(networkId, pasteId);
2287 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "EstablishP2PLink001 end");
2288 }
2289
2290 /**
2291 * @tc.name: EstablishP2PLinkTaskTest001
2292 * @tc.desc: test Func EstablishP2PLinkTask
2293 * @tc.type: FUNC
2294 */
2295 HWTEST_F(PasteboardServiceTest, EstablishP2PLinkTaskTest001, TestSize.Level0)
2296 {
2297 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "EstablishP2PLinkTaskTest001 start");
2298 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2299 EXPECT_NE(tempPasteboard, nullptr);
2300
2301 std::string pasteId;
2302 ClipPlugin::GlobalEvent event{};
2303 tempPasteboard->EstablishP2PLinkTask(pasteId, event);
2304 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "EstablishP2PLinkTaskTest001 end");
2305 }
2306
2307 /**
2308 * @tc.name: OnEstablishP2PLinkTaskTest001
2309 * @tc.desc: test Func OnEstablishP2PLinkTask
2310 * @tc.type: FUNC
2311 */
2312 HWTEST_F(PasteboardServiceTest, OnEstablishP2PLinkTaskTest001, TestSize.Level0)
2313 {
2314 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnEstablishP2PLinkTaskTest001 start");
2315 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2316 EXPECT_NE(tempPasteboard, nullptr);
2317
2318 std::string networkId = "networkId";
2319 std::shared_ptr<BlockObject<int32_t>> block = std::make_shared<BlockObject<int32_t>>(2000, SET_VALUE_SUCCESS);
2320 tempPasteboard->OnEstablishP2PLinkTask(networkId, block);
2321 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnEstablishP2PLinkTaskTest001 end");
2322 }
2323
2324 /**
2325 * @tc.name: CloseP2PLink001
2326 * @tc.desc: test Func CloseP2PLink
2327 * @tc.type: FUNC
2328 */
2329 HWTEST_F(PasteboardServiceTest, CloseP2PLink001, TestSize.Level0)
2330 {
2331 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CloseP2PLink001 start");
2332 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2333 EXPECT_NE(tempPasteboard, nullptr);
2334 std::string networkId = "networkId";
2335 tempPasteboard->CloseP2PLink(networkId);
2336 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CloseP2PLink001 end");
2337 }
2338
2339 /**
2340 * @tc.name: ProcessDistributedDelayUriTest001
2341 * @tc.desc: test Func ProcessDistributedDelayUri
2342 * @tc.type: FUNC
2343 */
2344 HWTEST_F(PasteboardServiceTest, ProcessDistributedDelayUriTest001, TestSize.Level0)
2345 {
2346 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayUriTest001 start");
2347 int32_t userId = ACCOUNT_IDS_RANDOM;
2348 PasteData data;
2349 PasteDataEntry entry;
2350 std::vector<uint8_t> rawData;
2351 auto tempPasteboard = std::make_shared<PasteboardService>();
2352 EXPECT_NE(tempPasteboard, nullptr);
2353 tempPasteboard->ProcessDistributedDelayUri(userId, data, entry, rawData);
2354 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayUriTest001 end");
2355 }
2356
2357 /**
2358 * @tc.name: ProcessDistributedDelayHtmlTest001
2359 * @tc.desc: test Func ProcessDistributedDelayHtml
2360 * @tc.type: FUNC
2361 */
2362 HWTEST_F(PasteboardServiceTest, ProcessDistributedDelayHtmlTest001, TestSize.Level0)
2363 {
2364 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayHtmlTest001 start");
2365 PasteData data;
2366 PasteDataEntry entry;
2367 std::vector<uint8_t> rawData;
2368 auto tempPasteboard = std::make_shared<PasteboardService>();
2369 EXPECT_NE(tempPasteboard, nullptr);
2370 tempPasteboard->ProcessDistributedDelayHtml(data, entry, rawData);
2371 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayHtmlTest001 end");
2372 }
2373
2374 /**
2375 * @tc.name: ProcessDistributedDelayEntryTest001
2376 * @tc.desc: test Func ProcessDistributedDelayEntry
2377 * @tc.type: FUNC
2378 */
2379 HWTEST_F(PasteboardServiceTest, ProcessDistributedDelayEntryTest001, TestSize.Level0)
2380 {
2381 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayEntryTest001 start");
2382 PasteDataEntry pasteData;
2383 std::vector<uint8_t> rawData;
2384 auto tempPasteboard = std::make_shared<PasteboardService>();
2385 EXPECT_NE(tempPasteboard, nullptr);
2386 tempPasteboard->ProcessDistributedDelayEntry(pasteData, rawData);
2387 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessDistributedDelayEntryTest001 end");
2388 }
2389
2390 /**
2391 * @tc.name: ProcessRemoteDelayHtmlTest001
2392 * @tc.desc: test Func ProcessRemoteDelayHtml
2393 * @tc.type: FUNC
2394 */
2395 HWTEST_F(PasteboardServiceTest, ProcessRemoteDelayHtmlTest001, TestSize.Level0)
2396 {
2397 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessRemoteDelayHtmlTest001 start");
2398 std::string remoteDeviceId;
2399 AppInfo appInfo;
2400 const std::vector<uint8_t> rawData;
2401 PasteData data;
2402 PasteDataRecord record;
2403 PasteDataEntry entry;
2404 auto tempPasteboard = std::make_shared<PasteboardService>();
2405 EXPECT_NE(tempPasteboard, nullptr);
2406 tempPasteboard->ProcessRemoteDelayHtml(remoteDeviceId, appInfo, rawData, data, record, entry);
2407 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ProcessRemoteDelayHtmlTest001 end");
2408 }
2409
2410 /**
2411 * @tc.name: IsDisallowDistributedTest
2412 * @tc.desc: test Func IsDisallowDistributed, Check CallingUID contral collaboration.
2413 * @tc.type: FUNC
2414 */
2415 HWTEST_F(PasteboardServiceTest, IsDisallowDistributedTest, TestSize.Level0)
2416 {
2417 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDisallowDistributedTest start");
2418 auto tempPasteboard = std::make_shared<PasteboardService>();
2419 ASSERT_NE(tempPasteboard, nullptr);
2420 EXPECT_EQ(tempPasteboard->IsDisallowDistributed(), false);
2421 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDisallowDistributedTest end");
2422 }
2423
2424 /**
2425 * @tc.name: CleanDistributedDataTest001
2426 * @tc.desc: test Func CleanDistributedData
2427 * @tc.type: FUNC
2428 */
2429 HWTEST_F(PasteboardServiceTest, CleanDistributedDataTest001, TestSize.Level0)
2430 {
2431 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CleanDistributedDataTest001 start");
2432 auto tempPasteboard = std::make_shared<PasteboardService>();
2433 EXPECT_NE(tempPasteboard, nullptr);
2434
2435 int32_t user = ACCOUNT_IDS_RANDOM;
2436 tempPasteboard->CleanDistributedData(user);
2437 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CleanDistributedDataTest001 end");
2438 }
2439
2440 /**
2441 * @tc.name: OnConfigChangeTest001
2442 * @tc.desc: test Func OnConfigChange
2443 * @tc.type: FUNC
2444 */
2445 HWTEST_F(PasteboardServiceTest, OnConfigChangeTest001, TestSize.Level0)
2446 {
2447 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnConfigChangeTest001 start");
2448 auto tempPasteboard = std::make_shared<PasteboardService>();
2449 EXPECT_NE(tempPasteboard, nullptr);
2450
2451 tempPasteboard->OnConfigChange(true);
2452 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnConfigChangeTest001 end");
2453 }
2454
2455 /**
2456 * @tc.name: IncreaseChangeCountTest001
2457 * @tc.desc: test Func IncreaseChangeCount, should reset to 0 after reach maximum limit.
2458 * @tc.type: FUNC
2459 */
2460 HWTEST_F(PasteboardServiceTest, IncreaseChangeCountTest001, TestSize.Level0)
2461 {
2462 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IncreaseChangeCountTest001 start");
2463 auto tempPasteboard = std::make_shared<PasteboardService>();
2464 int32_t userId = 10;
__anon24f3f2840202(auto, uint32_t &changeCount) 2465 tempPasteboard->clipChangeCount_.Compute(userId, [](auto, uint32_t &changeCount) {
2466 changeCount = UINT32_MAX;
2467 return true;
2468 });
2469 uint32_t testCount = 0;
2470 auto it = tempPasteboard->clipChangeCount_.Find(userId);
2471 if (it.first) {
2472 testCount = it.second;
2473 }
2474 EXPECT_EQ(testCount, UINT32_MAX);
2475 tempPasteboard->IncreaseChangeCount(userId);
2476 it = tempPasteboard->clipChangeCount_.Find(userId);
2477 if (it.first) {
2478 testCount = it.second;
2479 }
2480 EXPECT_EQ(testCount, 0);
2481 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IncreaseChangeCountTest001 end");
2482 }
2483
2484 /**
2485 * @tc.name: IncreaseChangeCountTest002
2486 * @tc.desc: test Func IncreaseChangeCount, should reset to 0 after switch to a new user.
2487 * @tc.type: FUNC
2488 */
2489 HWTEST_F(PasteboardServiceTest, IncreaseChangeCountTest002, TestSize.Level0)
2490 {
2491 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IncreaseChangeCountTest002 start");
2492 auto tempPasteboard = std::make_shared<PasteboardService>();
2493 uint32_t testCount = 0;
2494 tempPasteboard->GetChangeCount(testCount);
2495 EXPECT_EQ(testCount, 0);
2496
2497 tempPasteboard->currentUserId_ = 10;
2498 auto userId = tempPasteboard->GetCurrentAccountId();
2499 tempPasteboard->IncreaseChangeCount(userId);
2500 tempPasteboard->GetChangeCount(testCount);
2501 EXPECT_EQ(testCount, 1);
2502
2503 tempPasteboard->currentUserId_ = 100;
2504 tempPasteboard->GetChangeCount(testCount);
2505 EXPECT_EQ(testCount, 0);
2506 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IncreaseChangeCountTest002 end");
2507 }
2508
2509 /**
2510 * @tc.name: GetTimeTest001
2511 * @tc.desc: test Func GetTime
2512 * @tc.type: FUNC
2513 */
2514 HWTEST_F(PasteboardServiceTest, GetTimeTest001, TestSize.Level0)
2515 {
2516 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetTimeTest001 start");
2517 auto tempPasteboard = std::make_shared<PasteboardService>();
2518 EXPECT_NE(tempPasteboard, nullptr);
2519
2520 tempPasteboard->GetTime();
2521 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetTimeTest001 end");
2522 }
2523
2524 /**
2525 * @tc.name: IsDataAgedTest001
2526 * @tc.desc: test Func IsDataAged
2527 * @tc.type: FUNC
2528 */
2529 HWTEST_F(PasteboardServiceTest, IsDataAgedTest001, TestSize.Level0)
2530 {
2531 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest001 start");
2532 auto tempPasteboard = std::make_shared<PasteboardService>();
2533 EXPECT_NE(tempPasteboard, nullptr);
2534
2535 bool ret = tempPasteboard->IsDataAged();
2536 EXPECT_EQ(ret, true);
2537 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest001 end");
2538 }
2539
2540 /**
2541 * @tc.name: IsDataAgedTest002
2542 * @tc.desc: test Func IsDataAged
2543 * @tc.type: FUNC
2544 */
2545 HWTEST_F(PasteboardServiceTest, IsDataAgedTest002, TestSize.Level0)
2546 {
2547 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest002 start");
2548 auto tempPasteboard = std::make_shared<PasteboardService>();
2549 EXPECT_NE(tempPasteboard, nullptr);
2550
2551 auto userId = tempPasteboard->GetCurrentAccountId();
2552 auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
2553 auto copyTime = curTime;
2554 tempPasteboard->copyTime_.InsertOrAssign(userId, copyTime);
2555
2556 bool ret = tempPasteboard->IsDataAged();
2557 EXPECT_EQ(ret, false);
2558 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest002 end");
2559 }
2560
2561 /**
2562 * @tc.name: IsDataAgedTest003
2563 * @tc.desc: test Func IsDataAged
2564 * @tc.type: FUNC
2565 */
2566 HWTEST_F(PasteboardServiceTest, IsDataAgedTest003, TestSize.Level0)
2567 {
2568 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest003 start");
2569 auto tempPasteboard = std::make_shared<PasteboardService>();
2570 EXPECT_NE(tempPasteboard, nullptr);
2571
2572 auto userId = tempPasteboard->GetCurrentAccountId();
2573 auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
2574 auto copyTime = curTime - ONE_HOUR_MILLISECONDS;
2575 tempPasteboard->copyTime_.InsertOrAssign(userId, copyTime);
2576
2577 bool ret = tempPasteboard->IsDataAged();
2578 EXPECT_EQ(ret, false);
2579 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest003 end");
2580 }
2581
2582 /**
2583 * @tc.name: IsDataAgedTest004
2584 * @tc.desc: test Func IsDataAged
2585 * @tc.type: FUNC
2586 */
2587 HWTEST_F(PasteboardServiceTest, IsDataAgedTest004, TestSize.Level0)
2588 {
2589 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest004 start");
2590 auto tempPasteboard = std::make_shared<PasteboardService>();
2591 EXPECT_NE(tempPasteboard, nullptr);
2592
2593 auto userId = tempPasteboard->GetCurrentAccountId();
2594 auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
2595 auto copyTime = curTime - ONE_HOUR_MILLISECONDS - ONE_HOUR_MILLISECONDS;
2596 tempPasteboard->copyTime_.InsertOrAssign(userId, copyTime);
2597
2598 bool ret = tempPasteboard->IsDataAged();
2599 EXPECT_EQ(ret, true);
2600 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest004 end");
2601 }
2602
2603 /**
2604 * @tc.name: IsDataAgedTest005
2605 * @tc.desc: test Func IsDataAged
2606 * @tc.type: FUNC
2607 */
2608 HWTEST_F(PasteboardServiceTest, IsDataAgedTest005, TestSize.Level0)
2609 {
2610 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest005 start");
2611 auto tempPasteboard = std::make_shared<PasteboardService>();
2612 EXPECT_NE(tempPasteboard, nullptr);
2613
2614 auto userId = tempPasteboard->GetCurrentAccountId();
2615 auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
2616 auto copyTime = curTime + ONE_HOUR_MILLISECONDS;
2617 tempPasteboard->copyTime_.InsertOrAssign(userId, copyTime);
2618
2619 bool ret = tempPasteboard->IsDataAged();
2620 EXPECT_EQ(ret, false);
2621 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest005 end");
2622 }
2623
2624 /**
2625 * @tc.name: IsDataAgedTest006
2626 * @tc.desc: test Func IsDataAged
2627 * @tc.type: FUNC
2628 */
2629 HWTEST_F(PasteboardServiceTest, IsDataAgedTest006, TestSize.Level0)
2630 {
2631 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest006 start");
2632 auto tempPasteboard = std::make_shared<PasteboardService>();
2633 EXPECT_NE(tempPasteboard, nullptr);
2634
2635 auto userId = tempPasteboard->GetCurrentAccountId();
2636 auto curTime = static_cast<uint64_t>(duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count());
2637 auto copyTime = curTime - ONE_HOUR_MILLISECONDS - ONE_HOUR_MILLISECONDS;
2638 tempPasteboard->copyTime_.InsertOrAssign(userId, copyTime);
2639
2640 PasteData pasteData;
2641 tempPasteboard->clips_.InsertOrAssign(userId, std::make_shared<PasteData>(pasteData));
2642
2643 bool ret = tempPasteboard->IsDataAged();
2644 EXPECT_EQ(ret, true);
2645 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataAgedTest006 end");
2646 }
2647
2648 /**
2649 * @tc.name: VerifyPermissionTest001
2650 * @tc.desc: test Func VerifyPermission
2651 * @tc.type: FUNC
2652 */
2653 HWTEST_F(PasteboardServiceTest, VerifyPermissionTest001, TestSize.Level0)
2654 {
2655 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "VerifyPermissionTest001 start");
2656 auto tempPasteboard = std::make_shared<PasteboardService>();
2657 EXPECT_NE(tempPasteboard, nullptr);
2658
2659 uint32_t tokenId = 0x123456;
2660 tempPasteboard->VerifyPermission(tokenId);
2661 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "VerifyPermissionTest001 end");
2662 }
2663
2664 /**
2665 * @tc.name: IsDataValidTest001
2666 * @tc.desc: test Func IsDataValid
2667 * @tc.type: FUNC
2668 */
2669 HWTEST_F(PasteboardServiceTest, IsDataValidTest001, TestSize.Level0)
2670 {
2671 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest001 start");
2672 auto tempPasteboard = std::make_shared<PasteboardService>();
2673 EXPECT_NE(tempPasteboard, nullptr);
2674
2675 PasteData pasteData;
2676 uint32_t tokenId = 0x123456;
2677 int32_t ret = tempPasteboard->IsDataValid(pasteData, tokenId);
2678 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::DATA_EXPIRED_ERROR));
2679 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest001 end");
2680 }
2681
2682 /**
2683 * @tc.name: IsDataValidTest002
2684 * @tc.desc: test Func IsDataValid
2685 * @tc.type: FUNC
2686 */
2687 HWTEST_F(PasteboardServiceTest, IsDataValidTest002, TestSize.Level0)
2688 {
2689 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest002 start");
2690 auto tempPasteboard = std::make_shared<PasteboardService>();
2691 EXPECT_NE(tempPasteboard, nullptr);
2692
2693 AppInfo appInfo;
2694 appInfo.userId = tempPasteboard->GetCurrentAccountId();
2695 PasteData pasteData;
2696 std::string plainText = "hello";
2697 pasteData.AddTextRecord(plainText);
2698 ScreenEvent screenEvent = ScreenEvent::ScreenUnlocked;
2699 pasteData.SetScreenStatus(screenEvent);
2700
2701 std::vector<uint8_t> pasteDataTlv(0);
2702 int fd = -1;
2703 int64_t tlvSize = 0;
2704 MessageParcelWarp messageData;
2705 MessageParcel parcelPata;
2706 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
2707 sptr<IPasteboardEntryGetter> entryGetter = nullptr;
2708
2709 int32_t ret = WritePasteData(pasteData, pasteDataTlv, fd, tlvSize, messageData, parcelPata);
2710 ret = tempPasteboard->SetPasteData(dup(fd), tlvSize, pasteDataTlv, delayGetter, entryGetter);
2711
2712 uint32_t tokenId = 0x123456;
2713 ret = tempPasteboard->IsDataValid(pasteData, tokenId);
2714 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::CROSS_BORDER_ERROR));
2715 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest002 end");
2716 }
2717
2718 /**
2719 * @tc.name: IsDataValidTest003
2720 * @tc.desc: test Func IsDataValid
2721 * @tc.type: FUNC
2722 */
2723 HWTEST_F(PasteboardServiceTest, IsDataValidTest003, TestSize.Level0)
2724 {
2725 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest003 start");
2726 auto tempPasteboard = std::make_shared<PasteboardService>();
2727 EXPECT_NE(tempPasteboard, nullptr);
2728
2729 AppInfo appInfo;
2730 appInfo.userId = tempPasteboard->GetCurrentAccountId();
2731 PasteData pasteData;
2732 std::string plainText = "hello";
2733 pasteData.AddTextRecord(plainText);
2734
2735 ShareOption shareOption = ShareOption::InApp;
2736 pasteData.SetShareOption(shareOption);
2737
2738 uint32_t tokenId = 0x123456;
2739 pasteData.SetTokenId(tokenId);
2740
2741 std::vector<uint8_t> pasteDataTlv(0);
2742 int fd = -1;
2743 int64_t tlvSize = 0;
2744 MessageParcelWarp messageData;
2745 MessageParcel parcelPata;
2746 sptr<IPasteboardDelayGetter> delayGetter = nullptr;
2747 sptr<IPasteboardEntryGetter> entryGetter = nullptr;
2748
2749 int32_t ret = WritePasteData(pasteData, pasteDataTlv, fd, tlvSize, messageData, parcelPata);
2750 ret = tempPasteboard->SetPasteData(dup(fd), tlvSize, pasteDataTlv, delayGetter, entryGetter);
2751
2752 ret = tempPasteboard->IsDataValid(pasteData, tokenId);
2753 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
2754 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsDataValidTest003 end");
2755 }
2756
2757 /**
2758 * @tc.name: GetAppInfoTest001
2759 * @tc.desc: test Func GetAppInfo
2760 * @tc.type: FUNC
2761 */
2762 HWTEST_F(PasteboardServiceTest, GetAppInfoTest001, TestSize.Level0)
2763 {
2764 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppInfoTest001 start");
2765 auto tempPasteboard = std::make_shared<PasteboardService>();
2766 EXPECT_NE(tempPasteboard, nullptr);
2767
2768 uint32_t tokenId = 0x123456;
2769 tempPasteboard->GetAppInfo(tokenId);
2770 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppInfoTest001 end");
2771 }
2772
2773 /**
2774 * @tc.name: GetAppBundleNameTest001
2775 * @tc.desc: test Func GetAppBundleName
2776 * @tc.type: FUNC
2777 */
2778 HWTEST_F(PasteboardServiceTest, GetAppBundleNameTest001, TestSize.Level0)
2779 {
2780 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest001 start");
2781 auto tempPasteboard = std::make_shared<PasteboardService>();
2782 EXPECT_NE(tempPasteboard, nullptr);
2783
2784 AppInfo appInfo;
2785 tempPasteboard->GetAppBundleName(appInfo);
2786 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest001 end");
2787 }
2788
2789 /**
2790 * @tc.name: GetAppBundleNameTest002
2791 * @tc.desc: test Func GetAppBundleName
2792 * @tc.type: FUNC
2793 */
2794 HWTEST_F(PasteboardServiceTest, GetAppBundleNameTest002, TestSize.Level0)
2795 {
2796 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest002 start");
2797 auto tempPasteboard = std::make_shared<PasteboardService>();
2798 EXPECT_NE(tempPasteboard, nullptr);
2799
2800 AppInfo appInfo;
2801 appInfo.userId = 0;
2802 appInfo.bundleName = "test";
2803 auto ret = tempPasteboard->GetAppBundleName(appInfo);
2804 EXPECT_EQ(ret, appInfo.bundleName);
2805 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest002 end");
2806 }
2807
2808 /**
2809 * @tc.name: GetAppBundleNameTest003
2810 * @tc.desc: test Func GetAppBundleName
2811 * @tc.type: FUNC
2812 */
2813 HWTEST_F(PasteboardServiceTest, GetAppBundleNameTest003, TestSize.Level0)
2814 {
2815 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest003 start");
2816 auto tempPasteboard = std::make_shared<PasteboardService>();
2817 EXPECT_NE(tempPasteboard, nullptr);
2818
2819 AppInfo appInfo;
2820 appInfo.userId = ERROR_USERID;
2821 appInfo.bundleName = "test";
2822 auto ret = tempPasteboard->GetAppBundleName(appInfo);
2823 EXPECT_EQ(ret, "error");
2824 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAppBundleNameTest003 end");
2825 }
2826
2827 /**
2828 * @tc.name: SetLocalPasteFlag001
2829 * @tc.desc: test Func SetLocalPasteFlag
2830 * @tc.type: FUNC
2831 */
2832 HWTEST_F(PasteboardServiceTest, SetLocalPasteFlag001, TestSize.Level0)
2833 {
2834 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetLocalPasteFlag001 start");
2835 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2836 EXPECT_NE(tempPasteboard, nullptr);
2837 bool isCrossPaste = false;
2838 uint32_t tokenId = 0x123456;
2839 PasteData pasteData;
2840 tempPasteboard->SetLocalPasteFlag(isCrossPaste, tokenId, pasteData);
2841 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetLocalPasteFlag001 end");
2842 }
2843
2844 /**
2845 * @tc.name: RecognizePasteDataTest001
2846 * @tc.desc: test Func RecognizePasteData
2847 * @tc.type: FUNC
2848 */
2849 HWTEST_F(PasteboardServiceTest, RecognizePasteDataTest001, TestSize.Level0)
2850 {
2851 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RecognizePasteDataTest001 start");
2852 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
2853 EXPECT_NE(tempPasteboard, nullptr);
2854 PasteData pasteData;
2855 tempPasteboard->RecognizePasteData(pasteData);
2856 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RecognizePasteDataTest001 end");
2857 }
2858
2859 /**
2860 * @tc.name: ShowHintToastTest001
2861 * @tc.desc: test Func ShowHintToast
2862 * @tc.type: FUNC
2863 */
2864 HWTEST_F(PasteboardServiceTest, ShowHintToastTest001, TestSize.Level0)
2865 {
2866 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ShowHintToastTest001 start");
2867 auto tempPasteboard = std::make_shared<PasteboardService>();
2868 EXPECT_NE(tempPasteboard, nullptr);
2869
2870 uint32_t tokenId = UINT32_ONE;
2871 uint32_t pid = 0;
2872 tempPasteboard->ShowHintToast(tokenId, pid);
2873 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ShowHintToastTest001 end");
2874 }
2875
2876 /**
2877 * @tc.name: OnAddSystemAbilityTest001
2878 * @tc.desc: test Func OnAddSystemAbility
2879 * @tc.type: FUNC
2880 */
2881 HWTEST_F(PasteboardServiceTest, OnAddSystemAbilityTest001, TestSize.Level0)
2882 {
2883 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest001 start");
2884 int32_t systemAbilityId = 1;
2885 const std::string deviceId = "test_string";
2886 auto tempPasteboard = std::make_shared<PasteboardService>();
2887 EXPECT_NE(tempPasteboard, nullptr);
2888 tempPasteboard->OnAddSystemAbility(systemAbilityId, deviceId);
2889 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest001 end");
2890 }
2891
2892 /**
2893 * @tc.name: OnAddSystemAbilityTest002
2894 * @tc.desc: test Func OnAddSystemAbility
2895 * @tc.type: FUNC
2896 */
2897 HWTEST_F(PasteboardServiceTest, OnAddSystemAbilityTest002, TestSize.Level0)
2898 {
2899 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest002 start");
2900 auto tempPasteboard = std::make_shared<PasteboardService>();
2901 EXPECT_NE(tempPasteboard, nullptr);
2902 const std::string deviceId = "test_string";
2903 tempPasteboard->OnAddSystemAbility(static_cast<int32_t>(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID), deviceId);
2904 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest002 end");
2905 }
2906
2907 /**
2908 * @tc.name: OnAddSystemAbilityTest003
2909 * @tc.desc: test Func OnAddSystemAbility
2910 * @tc.type: FUNC
2911 */
2912 HWTEST_F(PasteboardServiceTest, OnAddSystemAbilityTest003, TestSize.Level0)
2913 {
2914 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest003 start");
2915 auto pbs = std::make_shared<PasteboardService>();
2916 EXPECT_NE(pbs, nullptr);
2917
2918 pbs->OnAddSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, "");
2919 pbs->OnAddSystemAbility(MEMORY_MANAGER_SA_ID, "");
2920 pbs->OnAddSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, "");
2921 pbs->OnAddSystemAbility(PASTEBOARD_SERVICE_ID, "");
2922 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddSystemAbilityTest003 end");
2923 }
2924
2925 /**
2926 * @tc.name: OnRemoveSystemAbilityTest001
2927 * @tc.desc: test Func OnRemoveSystemAbility
2928 * @tc.type: FUNC
2929 */
2930 HWTEST_F(PasteboardServiceTest, OnRemoveSystemAbilityTest001, TestSize.Level0)
2931 {
2932 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoveSystemAbilityTest001 start");
2933 auto pbs = std::make_shared<PasteboardService>();
2934
2935 EXPECT_NE(pbs, nullptr);
2936 pbs->OnRemoveSystemAbility(DISTRIBUTED_HARDWARE_DEVICEMANAGER_SA_ID, "");
2937 pbs->OnRemoveSystemAbility(MEMORY_MANAGER_SA_ID, "");
2938 pbs->OnRemoveSystemAbility(DISTRIBUTED_DEVICE_PROFILE_SA_ID, "");
2939 pbs->OnRemoveSystemAbility(PASTEBOARD_SERVICE_ID, "");
2940 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnRemoveSystemAbilityTest001 end");
2941 }
2942
2943 /**
2944 * @tc.name: CancelCriticalTimerTest001
2945 * @tc.desc: test Func CancelCriticalTimer
2946 * @tc.type: FUNC
2947 */
2948 HWTEST_F(PasteboardServiceTest, CancelCriticalTimerTest001, TestSize.Level1)
2949 {
2950 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CancelCriticalTimerTest001 start");
2951 constexpr int32_t userId = 111;
2952 auto tempPasteboard = std::make_shared<PasteboardService>();
2953 EXPECT_NE(tempPasteboard, nullptr);
2954 tempPasteboard->OnAddMemoryManager();
2955 tempPasteboard->CancelCriticalTimer();
2956 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CancelCriticalTimerTest001 end");
2957 }
2958
2959 /**
2960 * @tc.name: CancelCriticalTimerTest002
2961 * @tc.desc: test Func CancelCriticalTimer
2962 * @tc.type: FUNC
2963 */
2964 HWTEST_F(PasteboardServiceTest, CancelCriticalTimerTest002, TestSize.Level1)
2965 {
2966 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CancelCriticalTimerTest002 start");
2967 constexpr int32_t userId = 111;
2968 auto tempPasteboard = std::make_shared<PasteboardService>();
2969 EXPECT_NE(tempPasteboard, nullptr);
2970 tempPasteboard->ffrtTimer_ = nullptr;
2971 tempPasteboard->CancelCriticalTimer();
2972 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CancelCriticalTimerTest002 end");
2973 }
2974
2975 /**
2976 * @tc.name: SetCriticalTimerTest001
2977 * @tc.desc: test Func SetCriticalTimer
2978 * @tc.type: FUNC
2979 */
2980 HWTEST_F(PasteboardServiceTest, SetCriticalTimerTest001, TestSize.Level1)
2981 {
2982 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest001 start");
2983 constexpr int32_t userId = 111;
2984 auto tempPasteboard = std::make_shared<PasteboardService>();
2985 EXPECT_NE(tempPasteboard, nullptr);
2986 tempPasteboard->OnAddMemoryManager();
2987 tempPasteboard->SetCriticalTimer();
2988 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest001 end");
2989 }
2990
2991 /**
2992 * @tc.name: SetCriticalTimerTest002
2993 * @tc.desc: test Func SetCriticalTimer
2994 * @tc.type: FUNC
2995 */
2996 HWTEST_F(PasteboardServiceTest, SetCriticalTimerTest002, TestSize.Level1)
2997 {
2998 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest002 start");
2999 constexpr int32_t userId = 111;
3000 auto tempPasteboard = std::make_shared<PasteboardService>();
3001 EXPECT_NE(tempPasteboard, nullptr);
3002 tempPasteboard->ffrtTimer_ = nullptr;
3003 tempPasteboard->SetCriticalTimer();
3004 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest002 end");
3005 }
3006
3007 /**
3008 * @tc.name: SetCriticalTimerTest003
3009 * @tc.desc: test Func SetCriticalTimer
3010 * @tc.type: FUNC
3011 */
3012 HWTEST_F(PasteboardServiceTest, SetCriticalTimerTest003, TestSize.Level1)
3013 {
3014 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest003 start");
3015 constexpr int32_t userId = 111;
3016 auto tempPasteboard = std::make_shared<PasteboardService>();
3017 EXPECT_NE(tempPasteboard, nullptr);
3018 tempPasteboard->OnAddMemoryManager();
3019 tempPasteboard->isCritical_ = true;
3020 tempPasteboard->SetCriticalTimer();
3021 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest003 end");
3022 }
3023
3024 /**
3025 * @tc.name: SetCriticalTimerTest004
3026 * @tc.desc: test Func SetCriticalTimer
3027 * @tc.type: FUNC
3028 */
3029 HWTEST_F(PasteboardServiceTest, SetCriticalTimerTest004, TestSize.Level1)
3030 {
3031 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest004 start");
3032 constexpr int32_t userId = 111;
3033 auto tempPasteboard = std::make_shared<PasteboardService>();
3034 EXPECT_NE(tempPasteboard, nullptr);
3035 tempPasteboard->OnAddMemoryManager();
3036 tempPasteboard->isCritical_ = false;
3037 tempPasteboard->SetCriticalTimer();
3038 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SetCriticalTimerTest004 end");
3039 }
3040
3041 /**
3042 * @tc.name: OnAddDeviceManagerTest001
3043 * @tc.desc: test Func OnAddDeviceManager
3044 * @tc.type: FUNC
3045 */
3046 HWTEST_F(PasteboardServiceTest, OnAddDeviceManagerTest001, TestSize.Level0)
3047 {
3048 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddDeviceManagerTest001 start");
3049 constexpr int32_t userId = 111;
3050 auto tempPasteboard = std::make_shared<PasteboardService>();
3051 EXPECT_NE(tempPasteboard, nullptr);
3052 tempPasteboard->OnAddDeviceManager();
3053 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddDeviceManagerTest001 end");
3054 }
3055
3056 /**
3057 * @tc.name: OnAddMemoryManagerTest001
3058 * @tc.desc: test Func OnAddMemoryManager
3059 * @tc.type: FUNC
3060 */
3061 HWTEST_F(PasteboardServiceTest, OnAddMemoryManagerTest001, TestSize.Level0)
3062 {
3063 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddMemoryManagerTest001 start");
3064 constexpr int32_t userId = 111;
3065 auto tempPasteboard = std::make_shared<PasteboardService>();
3066 EXPECT_NE(tempPasteboard, nullptr);
3067 tempPasteboard->OnAddMemoryManager();
3068 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnAddMemoryManagerTest001 end");
3069 }
3070
3071 /**
3072 * @tc.name: ReportUeCopyEventTest001
3073 * @tc.desc: test Func ReportUeCopyEvent
3074 * @tc.type: FUNC
3075 */
3076 HWTEST_F(PasteboardServiceTest, ReportUeCopyEventTest001, TestSize.Level0)
3077 {
3078 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ReportUeCopyEventTest001 start");
3079 constexpr int32_t result = 111;
3080 PasteData pasteData;
3081 int64_t dataSize = 0;
3082 auto tempPasteboard = std::make_shared<PasteboardService>();
3083 EXPECT_NE(tempPasteboard, nullptr);
3084 tempPasteboard->ReportUeCopyEvent(pasteData, dataSize, result);
3085 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "ReportUeCopyEventTest001 end");
3086 }
3087
3088 /**
3089 * @tc.name: HasPasteDataTest001
3090 * @tc.desc: test Func HasPasteData
3091 * @tc.type: FUNC
3092 */
3093 HWTEST_F(PasteboardServiceTest, HasPasteDataTest001, TestSize.Level0)
3094 {
3095 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest001 start");
3096 auto service = std::make_shared<PasteboardService>();
3097 EXPECT_NE(service, nullptr);
3098
3099 service->currentScreenStatus = ScreenEvent::ScreenUnlocked;
3100 bool flag = false;
3101 int32_t result = service->HasPasteData(flag);
3102 EXPECT_EQ(result, ERR_OK);
3103 EXPECT_EQ(flag, false);
3104 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest001 end");
3105 }
3106
3107 /**
3108 * @tc.name: HasPasteDataTest002
3109 * @tc.desc: test Func HasPasteData
3110 * @tc.type: FUNC
3111 */
3112 HWTEST_F(PasteboardServiceTest, HasPasteDataTest002, TestSize.Level0)
3113 {
3114 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest002 start");
3115 auto service = std::make_shared<PasteboardService>();
3116 EXPECT_NE(service, nullptr);
3117
3118 service->clips_.Clear();
3119 std::shared_ptr<PasteData> dataPtr(nullptr);
3120 int32_t userId = INT_ONE;
3121 service->clips_.InsertOrAssign(userId, dataPtr);
3122 bool flag = false;
3123 int32_t result = service->HasPasteData(flag);
3124 EXPECT_EQ(result, ERR_OK);
3125 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest002 end");
3126 }
3127
3128 /**
3129 * @tc.name: HasPasteDataTest003
3130 * @tc.desc: test Func HasPasteData
3131 * @tc.type: FUNC
3132 */
3133 HWTEST_F(PasteboardServiceTest, HasPasteDataTest003, TestSize.Level0)
3134 {
3135 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest003 start");
3136 auto service = std::make_shared<PasteboardService>();
3137 EXPECT_NE(service, nullptr);
3138
3139 service->clips_.Clear();
3140 std::shared_ptr<PasteData> dataPtr = std::make_shared<PasteData>();
3141 int32_t userId = INT_ONE;
3142 service->clips_.InsertOrAssign(userId, dataPtr);
3143 bool flag = false;
3144 int32_t result = service->HasPasteData(flag);
3145 EXPECT_EQ(result, ERR_OK);
3146 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest003 end");
3147 }
3148
3149 /**
3150 * @tc.name: HasPasteDataTest004
3151 * @tc.desc: test Func HasPasteData
3152 * @tc.type: FUNC
3153 */
3154 HWTEST_F(PasteboardServiceTest, HasPasteDataTest004, TestSize.Level0)
3155 {
3156 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest004 start");
3157 auto service = std::make_shared<PasteboardService>();
3158 EXPECT_NE(service, nullptr);
3159
3160 service->currentScreenStatus = ScreenEvent::Default;
3161 bool flag = false;
3162 int32_t result = service->HasPasteData(flag);
3163 EXPECT_EQ(result, ERR_OK);
3164 EXPECT_EQ(flag, false);
3165 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest004 end");
3166 }
3167
3168 /**
3169 * @tc.name: HasPasteDataTest005
3170 * @tc.desc: test Func HasPasteData
3171 * @tc.type: FUNC
3172 */
3173 HWTEST_F(PasteboardServiceTest, HasPasteDataTest005, TestSize.Level0)
3174 {
3175 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest005 start");
3176 auto service = std::make_shared<PasteboardService>();
3177 EXPECT_NE(service, nullptr);
3178
3179 service->currentScreenStatus = ScreenEvent::ScreenLocked;
3180 bool flag = false;
3181 int32_t result = service->HasPasteData(flag);
3182 EXPECT_EQ(result, ERR_OK);
3183 EXPECT_EQ(flag, false);
3184 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasPasteDataTest005 end");
3185 }
3186
3187 /**
3188 * @tc.name: IsRemoteDataTest001
3189 * @tc.desc: test Func IsRemoteData, funcResult is false
3190 * @tc.type: FUNC
3191 */
3192 HWTEST_F(PasteboardServiceTest, IsRemoteDataTest001, TestSize.Level0)
3193 {
3194 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest001 start");
3195 auto service = std::make_shared<PasteboardService>();
3196 EXPECT_NE(service, nullptr);
3197
3198 service->currentUserId_ = ERROR_USERID;
3199 bool funcResult;
3200 int32_t result = service->IsRemoteData(funcResult);
3201 EXPECT_EQ(result, ERR_OK);
3202 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest001 end");
3203 }
3204
3205 /**
3206 * @tc.name: IsRemoteDataTest002
3207 * @tc.desc: test Func IsRemoteData, currentUserId_ is INT32_MAX.
3208 * @tc.type: FUNC
3209 */
3210 HWTEST_F(PasteboardServiceTest, IsRemoteDataTest002, TestSize.Level0)
3211 {
3212 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest002 start");
3213 auto service = std::make_shared<PasteboardService>();
3214 EXPECT_NE(service, nullptr);
3215
3216 service->currentUserId_ = INT32_MAX;
3217 bool funcResult;
3218 int32_t result = service->IsRemoteData(funcResult);
3219 EXPECT_EQ(result, ERR_OK);
3220 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest002 end");
3221 }
3222
3223 /**
3224 * @tc.name: IsRemoteDataTest003
3225 * @tc.desc: test Func IsRemoteData, currentUserId_ is 0XF
3226 * @tc.type: FUNC
3227 */
3228 HWTEST_F(PasteboardServiceTest, IsRemoteDataTest003, TestSize.Level0)
3229 {
3230 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest003 start");
3231 auto service = std::make_shared<PasteboardService>();
3232 EXPECT_NE(service, nullptr);
3233
3234 int32_t userId = service->currentUserId_ = 0XF;
3235 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
3236 EXPECT_NE(pasteData, nullptr);
3237
3238 pasteData->AddTextRecord("hello");
3239 service->clips_.InsertOrAssign(userId, pasteData);
3240 bool funcResult;
3241 int32_t result = service->IsRemoteData(funcResult);
3242 EXPECT_EQ(result, ERR_OK);
3243 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsRemoteDataTest003 end");
3244 }
3245
3246 /**
3247 * @tc.name: DealDataTest001
3248 * @tc.desc: test Func DealData
3249 * @tc.type: FUNC
3250 */
3251 HWTEST_F(PasteboardServiceTest, DealDataTest001, TestSize.Level0)
3252 {
3253 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DealDataTest001 start");
3254 auto service = std::make_shared<PasteboardService>();
3255 int fd = -1;
3256 int64_t size;
3257 std::vector<uint8_t> rawData;
3258 PasteData data;
3259 int32_t result = service->DealData(fd, size, rawData, data);
3260 EXPECT_EQ(result, ERR_OK);
3261 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "DealDataTest001 end");
3262 }
3263
3264 /**
3265 * @tc.name: WriteRawDataTest001
3266 * @tc.desc: test Func WriteRawData
3267 * @tc.type: FUNC
3268 */
3269 HWTEST_F(PasteboardServiceTest, WriteRawDataTest001, TestSize.Level0)
3270 {
3271 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest001 start");
3272 auto service = std::make_shared<PasteboardService>();
3273 char rawData[] = "testData";
3274 int32_t fd = INT32_NEGATIVE_NUMBER;
3275 bool result = service->WriteRawData(rawData, sizeof(rawData), fd);
3276 EXPECT_EQ(result, true);
3277 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest001 end");
3278 }
3279
3280 /**
3281 * @tc.name: WriteRawDataTest002
3282 * @tc.desc: test Func WriteRawData
3283 * @tc.type: FUNC
3284 * @tc.require:
3285 * @tc.author:
3286 */
3287 HWTEST_F(PasteboardServiceTest, WriteRawDataTest002, TestSize.Level0)
3288 {
3289 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest002 start");
3290 auto tempPasteboard = std::make_shared<PasteboardService>();
3291 EXPECT_NE(tempPasteboard, nullptr);
3292
3293 int serFd = 0;
3294 int64_t size = 10;
3295
3296 bool result = tempPasteboard->WriteRawData(nullptr, size, serFd);
3297 EXPECT_FALSE(result);
3298 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest002 end");
3299 }
3300
3301 /**
3302 * @tc.name: WriteRawDataTest003
3303 * @tc.desc: test Func WriteRawData
3304 * @tc.type: FUNC
3305 * @tc.require:
3306 * @tc.author:
3307 */
3308 HWTEST_F(PasteboardServiceTest, WriteRawDataTest003, TestSize.Level0)
3309 {
3310 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest003 start");
3311 auto tempPasteboard = std::make_shared<PasteboardService>();
3312 EXPECT_NE(tempPasteboard, nullptr);
3313
3314 int serFd = 0;
3315 char data[10];
3316
3317 bool result = tempPasteboard->WriteRawData(data, 0, serFd);
3318 EXPECT_FALSE(result);
3319 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WriteRawDataTest003 end");
3320 }
3321
3322 /**
3323 * @tc.name: WritePasteDataTest001
3324 * @tc.desc: test Func WritePasteDataTest
3325 * @tc.type: FUNC
3326 * @tc.require:
3327 * @tc.author:
3328 */
3329 HWTEST_F(PasteboardServiceTest, WritePasteDataTest001, TestSize.Level0)
3330 {
3331 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest001 start");
3332 int fd = -1;
3333 int64_t rawDataSize = 0;
3334 std::vector<uint8_t> buffer;
3335 PasteData output;
3336 bool hasData = false;
3337
3338 PasteData input;
3339 input.AddTextRecord("test");
3340 bool result = input.Encode(buffer);
3341 ASSERT_TRUE(result);
3342
3343 rawDataSize = static_cast<int64_t>(buffer.size());
3344 MessageParcelWarp messageData;
3345 ASSERT_TRUE(rawDataSize <= MIN_ASHMEM_DATA_SIZE);
3346
3347 fd = messageData.CreateTmpFd();
3348 ASSERT_TRUE(fd >= 0);
3349
3350 auto tempPasteboard = std::make_shared<PasteboardService>();
3351 auto ret = tempPasteboard->WritePasteData(fd, rawDataSize, buffer, output, hasData);
3352 EXPECT_EQ(static_cast<int32_t>(PasteboardError::E_OK), ret);
3353 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest001 end");
3354 }
3355
3356 /**
3357 * @tc.name: WritePasteDataTest002
3358 * @tc.desc: test Func WritePasteDataTest
3359 * @tc.type: FUNC
3360 * @tc.require:
3361 * @tc.author:
3362 */
3363 HWTEST_F(PasteboardServiceTest, WritePasteDataTest002, TestSize.Level0)
3364 {
3365 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest002 start");
3366 int fd = -1;
3367 int64_t rawDataSize = 0;
3368 std::vector<uint8_t> buffer;
3369 PasteData output;
3370 bool hasData = false;
3371
3372 PasteData input;
3373 std::string text = "test";
3374 for (int i = 0; i < INT_THREETHREETHREE; ++i) {
3375 text += TEST_ENTITY_TEXT;
3376 }
3377 input.AddTextRecord(text);
3378 bool result = input.Encode(buffer);
3379 ASSERT_TRUE(result);
3380
3381 rawDataSize = static_cast<int64_t>(buffer.size());
3382 MessageParcelWarp messageData;
3383 MessageParcel parcelData;
3384 ASSERT_TRUE(rawDataSize > MIN_ASHMEM_DATA_SIZE);
3385
3386 result = messageData.WriteRawData(parcelData, buffer.data(), buffer.size());
3387 ASSERT_TRUE(result);
3388
3389 fd = messageData.GetWriteDataFd();
3390 buffer.clear();
3391 auto tempPasteboard = std::make_shared<PasteboardService>();
3392 auto ret = tempPasteboard->WritePasteData(fd, rawDataSize, buffer, output, hasData);
3393 EXPECT_EQ(static_cast<int32_t>(PasteboardError::E_OK), ret);
3394 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest002 end");
3395 }
3396
3397 /**
3398 * @tc.name: WritePasteDataTest003
3399 * @tc.desc: test Func WritePasteDataTest
3400 * @tc.type: FUNC
3401 * @tc.require:
3402 * @tc.author:
3403 */
3404 HWTEST_F(PasteboardServiceTest, WritePasteDataTest003, TestSize.Level0)
3405 {
3406 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest003 start");
3407 int fd = -1;
3408 int64_t rawDataSize = 0;
3409 std::vector<uint8_t> buffer;
3410 PasteData output;
3411 bool hasData = false;
3412
3413 PasteData input;
3414 std::string text = "test";
3415 for (int i = 0; i < INT_THREETHREETHREE; ++i) {
3416 text += TEST_ENTITY_TEXT;
3417 }
3418 input.AddTextRecord(text);
3419 bool result = input.Encode(buffer);
3420 ASSERT_TRUE(result);
3421
3422 rawDataSize = static_cast<int64_t>(buffer.size() + 1);
3423 MessageParcelWarp messageData;
3424 MessageParcel parcelData;
3425 ASSERT_TRUE(rawDataSize > MIN_ASHMEM_DATA_SIZE);
3426
3427 result = messageData.WriteRawData(parcelData, buffer.data(), buffer.size());
3428 ASSERT_TRUE(result);
3429
3430 fd = messageData.GetWriteDataFd();
3431 buffer.clear();
3432 auto tempPasteboard = std::make_shared<PasteboardService>();
3433 auto ret = tempPasteboard->WritePasteData(fd, rawDataSize, buffer, output, hasData);
3434 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_DATA_SIZE), ret);
3435 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "WritePasteDataTest003 end");
3436 }
3437
3438 /**
3439 * @tc.name: GetLocalMimeTypesTest001
3440 * @tc.desc: test Func GetLocalMimeTypes
3441 * @tc.type: FUNC
3442 */
3443 HWTEST_F(PasteboardServiceTest, GetLocalMimeTypesTest001, TestSize.Level0)
3444 {
3445 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest001 start");
3446 auto tempPasteboard = std::make_shared<PasteboardService>();
3447 EXPECT_NE(tempPasteboard, nullptr);
3448
3449 tempPasteboard->GetLocalMimeTypes();
3450 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest001 end");
3451 }
3452
3453 /**
3454 * @tc.name: GetLocalMimeTypesTest002
3455 * @tc.desc: test Func GetLocalMimeTypes
3456 * @tc.type: FUNC
3457 */
3458 HWTEST_F(PasteboardServiceTest, GetLocalMimeTypesTest002, TestSize.Level1)
3459 {
3460 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest002 start");
3461 auto tempPasteboard = std::make_shared<PasteboardService>();
3462 EXPECT_NE(tempPasteboard, nullptr);
3463
3464 auto userId = tempPasteboard->GetCurrentAccountId();
3465 auto result = tempPasteboard->GetLocalMimeTypes();
3466 std::vector<std::string> emptyVector;
3467 EXPECT_EQ(result, emptyVector);
3468 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest002 end");
3469 }
3470
3471 /**
3472 * @tc.name: GetLocalMimeTypesTest003
3473 * @tc.desc: test Func GetLocalMimeTypes
3474 * @tc.type: FUNC
3475 */
3476 HWTEST_F(PasteboardServiceTest, GetLocalMimeTypesTest003, TestSize.Level1)
3477 {
3478 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest003 start");
3479 auto tempPasteboard = std::make_shared<PasteboardService>();
3480 EXPECT_NE(tempPasteboard, nullptr);
3481
3482 auto userId = tempPasteboard->GetCurrentAccountId();
3483 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
3484 tempPasteboard->clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, std::make_shared<PasteData>());
3485
3486 auto result = tempPasteboard->GetLocalMimeTypes();
3487 std::vector<std::string> emptyVector;
3488 EXPECT_EQ(result, emptyVector);
3489 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalMimeTypesTest003 end");
3490 }
3491
3492 /**
3493 * @tc.name: HasLocalDataTypeTest001
3494 * @tc.desc: test Func HasLocalDataType
3495 * @tc.type: FUNC
3496 */
3497 HWTEST_F(PasteboardServiceTest, HasLocalDataTypeTest001, TestSize.Level1)
3498 {
3499 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest001 start");
3500 auto tempPasteboard = std::make_shared<PasteboardService>();
3501 EXPECT_NE(tempPasteboard, nullptr);
3502
3503 auto userId = tempPasteboard->GetCurrentAccountId();
3504 std::string mimeType = "text/html";
3505 tempPasteboard->HasLocalDataType(mimeType);
3506 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest001 end");
3507 }
3508
3509 /**
3510 * @tc.name: HasLocalDataTypeTest002
3511 * @tc.desc: test Func HasLocalDataType
3512 * @tc.type: FUNC
3513 */
3514 HWTEST_F(PasteboardServiceTest, HasLocalDataTypeTest002, TestSize.Level1)
3515 {
3516 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest002 start");
3517 auto tempPasteboard = std::make_shared<PasteboardService>();
3518 EXPECT_NE(tempPasteboard, nullptr);
3519
3520 auto userId = tempPasteboard->GetCurrentAccountId();
3521 std::string mimeType = "text/html";
3522 bool result = tempPasteboard->HasLocalDataType(mimeType);
3523 EXPECT_EQ(result, false);
3524 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest002 end");
3525 }
3526
3527 /**
3528 * @tc.name: HasLocalDataTypeTest003
3529 * @tc.desc: test Func HasLocalDataType
3530 * @tc.type: FUNC
3531 */
3532 HWTEST_F(PasteboardServiceTest, HasLocalDataTypeTest003, TestSize.Level1)
3533 {
3534 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest003 start");
3535 auto tempPasteboard = std::make_shared<PasteboardService>();
3536 EXPECT_NE(tempPasteboard, nullptr);
3537
3538 auto userId = -1;
3539 std::string mimeType = "text/html";
3540 bool result = tempPasteboard->HasLocalDataType(mimeType);
3541 EXPECT_EQ(result, false);
3542 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest003 end");
3543 }
3544
3545 /**
3546 * @tc.name: HasLocalDataTypeTest004
3547 * @tc.desc: test Func HasLocalDataType
3548 * @tc.type: FUNC
3549 */
3550 HWTEST_F(PasteboardServiceTest, HasLocalDataTypeTest004, TestSize.Level1)
3551 {
3552 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest004 start");
3553 auto tempPasteboard = std::make_shared<PasteboardService>();
3554 EXPECT_NE(tempPasteboard, nullptr);
3555
3556 tempPasteboard->currentUserId_ = ACCOUNT_IDS_RANDOM;
3557 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
3558 pasteData->AddTextRecord("hello");
3559 tempPasteboard->clips_.InsertOrAssign(ACCOUNT_IDS_RANDOM, pasteData);
3560
3561 std::string mimeType = "text/plain";
3562 bool result = tempPasteboard->HasLocalDataType(mimeType);
3563 EXPECT_EQ(result, false);
3564 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "HasLocalDataTypeTest004 end");
3565 }
3566
3567 /**
3568 * @tc.name: AddPermissionRecordTest001
3569 * @tc.desc: test Func AddPermissionRecord
3570 * @tc.type: FUNC
3571 */
3572 HWTEST_F(PasteboardServiceTest, AddPermissionRecordTest001, TestSize.Level0)
3573 {
3574 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddPermissionRecordTest001 start");
3575 auto tempPasteboard = std::make_shared<PasteboardService>();
3576 EXPECT_NE(tempPasteboard, nullptr);
3577
3578 uint32_t tokenId = 0x123456;
3579 tempPasteboard->AddPermissionRecord(tokenId, true, true);
3580 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddPermissionRecordTest001 end");
3581 }
3582
3583 /**
3584 * @tc.name: IsAllowSendDataTest001
3585 * @tc.desc: test Func IsAllowSendData
3586 * @tc.type: FUNC
3587 */
3588 HWTEST_F(PasteboardServiceTest, IsAllowSendDataTest001, TestSize.Level0)
3589 {
3590 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsAllowSendDataTest001 start");
3591 auto tempPasteboard = std::make_shared<PasteboardService>();
3592 EXPECT_NE(tempPasteboard, nullptr);
3593
3594 tempPasteboard->IsAllowSendData();
3595 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsAllowSendDataTest001 end");
3596 }
3597
3598 /**
3599 * @tc.name: UpdateShareOptionTest001
3600 * @tc.desc: test Func UpdateShareOption
3601 * @tc.type: FUNC
3602 */
3603 HWTEST_F(PasteboardServiceTest, UpdateShareOptionTest001, TestSize.Level0)
3604 {
3605 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UpdateShareOptionTest001 start");
3606 PasteData pasteData;
3607 auto tempPasteboard = std::make_shared<PasteboardService>();
3608 EXPECT_NE(tempPasteboard, nullptr);
3609
3610 tempPasteboard->UpdateShareOption(pasteData);
3611 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UpdateShareOptionTest001 end");
3612 }
3613
3614 /**
3615 * @tc.name: CheckMdmShareOptionTest001
3616 * @tc.desc: test Func CheckMdmShareOption
3617 * @tc.type: FUNC
3618 */
3619 HWTEST_F(PasteboardServiceTest, CheckMdmShareOptionTest001, TestSize.Level0)
3620 {
3621 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CheckMdmShareOptionTest001 start");
3622 PasteData pasteData;
3623 auto tempPasteboard = std::make_shared<PasteboardService>();
3624 EXPECT_NE(tempPasteboard, nullptr);
3625
3626 tempPasteboard->CheckMdmShareOption(pasteData);
3627 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CheckMdmShareOptionTest001 end");
3628 }
3629
3630 /**
3631 * @tc.name: IsBasicTypeTest001
3632 * @tc.desc: test Func IsBasicType
3633 * @tc.type: FUNC
3634 */
3635 HWTEST_F(PasteboardServiceTest, IsBasicTypeTest001, TestSize.Level0)
3636 {
3637 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest001 start");
3638 auto tempPasteboard = std::make_shared<PasteboardService>();
3639 EXPECT_NE(tempPasteboard, nullptr);
3640
3641 bool ret = tempPasteboard->IsBasicType(MIMETYPE_TEXT_HTML);
3642 EXPECT_TRUE(ret);
3643 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest001 end");
3644 }
3645
3646 /**
3647 * @tc.name: IsBasicTypeTest002
3648 * @tc.desc: test Func IsBasicType
3649 * @tc.type: FUNC
3650 */
3651 HWTEST_F(PasteboardServiceTest, IsBasicTypeTest002, TestSize.Level0)
3652 {
3653 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest002 start");
3654 auto tempPasteboard = std::make_shared<PasteboardService>();
3655 EXPECT_NE(tempPasteboard, nullptr);
3656
3657 int32_t userld = 1;
3658 PasteData data;
3659 tempPasteboard->GetDelayPasteData(userld, data);
3660
3661 bool ret = tempPasteboard->IsBasicType(MIMETYPE_TEXT_PLAIN);
3662 EXPECT_TRUE(ret);
3663 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest002 end");
3664 }
3665
3666 /**
3667 * @tc.name: IsBasicTypeTest003
3668 * @tc.desc: test Func IsBasicType
3669 * @tc.type: FUNC
3670 */
3671 HWTEST_F(PasteboardServiceTest, IsBasicTypeTest003, TestSize.Level0)
3672 {
3673 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest003 start");
3674 auto tempPasteboard = std::make_shared<PasteboardService>();
3675 EXPECT_NE(tempPasteboard, nullptr);
3676
3677 bool ret = tempPasteboard->IsBasicType(MIMETYPE_TEXT_URI);
3678 EXPECT_TRUE(ret);
3679 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest003 end");
3680 }
3681
3682 /**
3683 * @tc.name: IsBasicTypeTest004
3684 * @tc.desc: test Func IsBasicType
3685 * @tc.type: FUNC
3686 */
3687 HWTEST_F(PasteboardServiceTest, IsBasicTypeTest004, TestSize.Level0)
3688 {PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest004 start");
3689 auto tempPasteboard = std::make_shared<PasteboardService>();
3690 EXPECT_NE(tempPasteboard, nullptr);
3691
3692 bool ret = tempPasteboard->IsBasicType("application/octet-stream");
3693 EXPECT_FALSE(ret);
3694 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest004 end");
3695 }
3696
3697 /**
3698 * @tc.name: IsBasicTypeTest005
3699 * @tc.desc: test Func IsBasicType
3700 * @tc.type: FUNC
3701 */
3702 HWTEST_F(PasteboardServiceTest, IsBasicTypeTest005, TestSize.Level0)
3703 {
3704 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest005 start");
3705 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
3706 EXPECT_NE(tempPasteboard, nullptr);
3707
3708 std::string mimeType = "text/html";
3709 tempPasteboard->IsBasicType(mimeType);
3710 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "IsBasicTypeTest005 end");
3711 }
3712
3713 /**
3714 * @tc.name: RemotePasteboardChangeTest001
3715 * @tc.desc: test Func RemotePasteboardChange
3716 * @tc.type: FUNC
3717 */
3718 HWTEST_F(PasteboardServiceTest, RemotePasteboardChangeTest001, TestSize.Level0)
3719 {
3720 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemotePasteboardChangeTest001 start");
3721 auto tempPasteboard = std::make_shared<PasteboardService>();
3722 EXPECT_NE(tempPasteboard, nullptr);
3723
3724 auto result = tempPasteboard->RemotePasteboardChange();
3725 EXPECT_NE(result, nullptr);
3726 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemotePasteboardChangeTest001 end");
3727 }
3728
3729 /**
3730 * @tc.name: AppExitTest001
3731 * @tc.desc: test Func AppExit
3732 * @tc.type: FUNC
3733 */
3734 HWTEST_F(PasteboardServiceTest, AppExitTest001, TestSize.Level0)
3735 {
3736 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest001 start");
3737 auto tempPasteboard = std::make_shared<PasteboardService>();
3738 EXPECT_NE(tempPasteboard, nullptr);
3739
3740 pid_t pid = 3;
3741 tempPasteboard->AppExit(pid);
3742 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest001 end");
3743 }
3744
3745 /**
3746 * @tc.name: AppExitTest002
3747 * @tc.desc: test Func AppExit
3748 * @tc.type: FUNC
3749 */
3750 HWTEST_F(PasteboardServiceTest, AppExitTest002, TestSize.Level0)
3751 {
3752 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest002 start");
3753 auto tempPasteboard = std::make_shared<PasteboardService>();
3754 EXPECT_NE(tempPasteboard, nullptr);
3755
3756 int32_t pid = 1234;
3757 std::string networkId = "networkId1";
3758 std::string key = "key1";
3759 ConcurrentMap<std::string, int32_t> p2pMap;
3760 p2pMap.Insert(key, pid);
3761 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
3762 int32_t ret = tempPasteboard->AppExit(pid);
3763 EXPECT_EQ(ret, ERR_OK);
3764 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest002 end");
3765 }
3766
3767 /**
3768 * @tc.name: AppExitTest003
3769 * @tc.desc: test Func AppExit
3770 * @tc.type: FUNC
3771 */
3772 HWTEST_F(PasteboardServiceTest, AppExitTest003, TestSize.Level0)
3773 {
3774 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest003 start");
3775 auto tempPasteboard = std::make_shared<PasteboardService>();
3776 EXPECT_NE(tempPasteboard, nullptr);
3777
3778 int32_t pid = 1234;
3779 std::string networkId = "networkId1";
3780 std::string key = "key1";
3781 ConcurrentMap<std::string, int32_t> p2pMap;
3782 p2pMap.Insert(key, pid);
3783 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
3784 p2pMap.Clear();
3785 p2pMap.Insert(key, pid + 1);
3786 tempPasteboard->p2pMap_.Insert(networkId, p2pMap);
3787 int32_t ret = tempPasteboard->AppExit(pid);
3788 EXPECT_EQ(ret, ERR_OK);
3789 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AppExitTest003 end");
3790 }
3791
3792 /**
3793 * @tc.name: OnReceiveEventTest001
3794 * @tc.desc: test Func OnReceiveEvent
3795 * @tc.type: FUNC
3796 */
3797 HWTEST_F(PasteboardServiceTest, OnReceiveEventTest001, TestSize.Level0)
3798 {
3799 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest001 start");
3800 EventFwk::CommonEventSubscribeInfo subscribeInfo;
3801 sptr<PasteboardService> service;
3802 auto tempPasteboard = std::make_shared<PasteBoardCommonEventSubscriber>(subscribeInfo, service);
3803 EXPECT_NE(tempPasteboard, nullptr);
3804
3805 const EventFwk::CommonEventData data;
3806 tempPasteboard->OnReceiveEvent(data);
3807 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest001 end");
3808 }
3809
3810 /**
3811 * @tc.name: OnReceiveEventTest002
3812 * @tc.desc: test Func OnReceiveEvent
3813 * @tc.type: FUNC
3814 */
3815 HWTEST_F(PasteboardServiceTest, OnReceiveEventTest002, TestSize.Level0)
3816 {
3817 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest002 start");
3818 EventFwk::CommonEventSubscribeInfo subscribeInfo;
3819 sptr<PasteboardService> service = nullptr;
3820 auto tempPasteboard = std::make_shared<PasteBoardCommonEventSubscriber>(subscribeInfo, service);
3821 EXPECT_NE(tempPasteboard, nullptr);
3822
3823 EventFwk::CommonEventData data;
3824 EventFwk::Want want;
3825 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_STOPPING);
3826 data.SetWant(want);
3827 tempPasteboard->OnReceiveEvent(data);
3828 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest002 end");
3829 }
3830
3831 /**
3832 * @tc.name: OnReceiveEventTest003
3833 * @tc.desc: test Func OnReceiveEvent
3834 * @tc.type: FUNC
3835 */
3836 HWTEST_F(PasteboardServiceTest, OnReceiveEventTest003, TestSize.Level0)
3837 {
3838 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest003 start");
3839 EventFwk::CommonEventSubscribeInfo subscribeInfo;
3840 sptr<PasteboardService> service = new PasteboardService();
3841 auto tempPasteboard = std::make_shared<PasteBoardCommonEventSubscriber>(subscribeInfo, service);
3842 EXPECT_NE(tempPasteboard, nullptr);
3843
3844 EventFwk::CommonEventData data;
3845 EventFwk::Want want;
3846 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_USER_STOPPING);
3847 data.SetWant(want);
3848 tempPasteboard->OnReceiveEvent(data);
3849 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest003 end");
3850 }
3851
3852 /**
3853 * @tc.name: OnReceiveEventTest004
3854 * @tc.desc: test Func OnReceiveEvent
3855 * @tc.type: FUNC
3856 */
3857 HWTEST_F(PasteboardServiceTest, OnReceiveEventTest004, TestSize.Level0)
3858 {
3859 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest004 start");
3860 EventFwk::CommonEventSubscribeInfo subscribeInfo;
3861 sptr<PasteboardService> service = new PasteboardService();
3862 auto tempPasteboard = std::make_shared<PasteBoardCommonEventSubscriber>(subscribeInfo, service);
3863 EXPECT_NE(tempPasteboard, nullptr);
3864
3865 EventFwk::CommonEventData data;
3866 EventFwk::Want want;
3867 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_LOCKED);
3868 data.SetWant(want);
3869 tempPasteboard->OnReceiveEvent(data);
3870 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest004 end");
3871 }
3872
3873 /**
3874 * @tc.name: OnReceiveEventTest005
3875 * @tc.desc: test Func OnReceiveEvent
3876 * @tc.type: FUNC
3877 */
3878 HWTEST_F(PasteboardServiceTest, OnReceiveEventTest005, TestSize.Level0)
3879 {
3880 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest005 start");
3881 EventFwk::CommonEventSubscribeInfo subscribeInfo;
3882 sptr<PasteboardService> service = new PasteboardService();
3883 auto tempPasteboard = std::make_shared<PasteBoardCommonEventSubscriber>(subscribeInfo, service);
3884 EXPECT_NE(tempPasteboard, nullptr);
3885
3886 EventFwk::CommonEventData data;
3887 EventFwk::Want want;
3888 want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED);
3889 data.SetWant(want);
3890 tempPasteboard->OnReceiveEvent(data);
3891 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnReceiveEventTest005 end");
3892 }
3893
3894 /**
3895 * @tc.name: OnStateChangedTest001
3896 * @tc.desc: test Func OnStateChanged
3897 * @tc.type: FUNC
3898 */
3899 HWTEST_F(PasteboardServiceTest, OnStateChangedTest001, TestSize.Level0)
3900 {
3901 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest001 start");
3902 AccountSA::OsAccountSubscribeInfo subscribeInfo;
3903 sptr<PasteboardService> service;
3904 auto tempPasteboard = std::make_shared<PasteBoardAccountStateSubscriber>(subscribeInfo, service);
3905 EXPECT_NE(tempPasteboard, nullptr);
3906
3907 const AccountSA::OsAccountStateData data;
3908 tempPasteboard->OnStateChanged(data);
3909 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest001 end");
3910 }
3911
3912 /**
3913 * @tc.name: OnStateChangedTest002
3914 * @tc.desc: test Func OnStateChanged
3915 * @tc.type: FUNC
3916 */
3917 HWTEST_F(PasteboardServiceTest, OnStateChangedTest002, TestSize.Level0)
3918 {
3919 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest002 start");
3920 AccountSA::OsAccountSubscribeInfo subscribeInfo;
3921 sptr<PasteboardService> service = new PasteboardService();
3922 auto tempPasteboard = std::make_shared<PasteBoardAccountStateSubscriber>(subscribeInfo, service);
3923 EXPECT_NE(tempPasteboard, nullptr);
3924
3925 AccountSA::OsAccountStateData data;
3926 data.state = AccountSA::OsAccountState::STOPPING;
3927 data.fromId = 1;
3928 data.toId = 2;
3929 data.callback = nullptr;
3930 tempPasteboard->OnStateChanged(data);
3931 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest002 end");
3932 }
3933
3934 /**
3935 * @tc.name: OnStateChangedTest003
3936 * @tc.desc: test Func OnStateChanged
3937 * @tc.type: FUNC
3938 */
3939 HWTEST_F(PasteboardServiceTest, OnStateChangedTest003, TestSize.Level0)
3940 {
3941 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest003 start");
3942 AccountSA::OsAccountSubscribeInfo subscribeInfo;
3943 sptr<PasteboardService> service = nullptr;
3944 auto tempPasteboard = std::make_shared<PasteBoardAccountStateSubscriber>(subscribeInfo, service);
3945 EXPECT_NE(tempPasteboard, nullptr);
3946
3947 AccountSA::OsAccountStateData data;
3948 data.state = AccountSA::OsAccountState::INVALID_TYPE;
3949 data.fromId = 1;
3950 data.toId = 2;
3951 data.callback = nullptr;
3952 tempPasteboard->OnStateChanged(data);
3953 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest003 end");
3954 }
3955
3956 /**
3957 * @tc.name: OnStateChangedTest004
3958 * @tc.desc: test Func OnStateChanged
3959 * @tc.type: FUNC
3960 */
3961 HWTEST_F(PasteboardServiceTest, OnStateChangedTest004, TestSize.Level0)
3962 {
3963 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest004 start");
3964 AccountSA::OsAccountSubscribeInfo subscribeInfo;
3965 sptr<PasteboardService> service = nullptr;
3966
3967 auto tempPasteboard = std::make_shared<PasteBoardAccountStateSubscriber>(subscribeInfo, service);
3968 EXPECT_NE(tempPasteboard, nullptr);
3969
3970 AccountSA::OsAccountStateData data;
3971 data.state = AccountSA::OsAccountState::STOPPING;
3972 data.fromId = 1;
3973 data.toId = 2;
3974 data.callback = nullptr;
3975 tempPasteboard->OnStateChanged(data);
3976 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OnStateChangedTest004 end");
3977 }
3978
3979 /**
3980 * @tc.name: RegisterClientDeathObserverTest001
3981 * @tc.desc: test Func RegisterClientDeathObserver
3982 * @tc.type: FUNC
3983 */
3984 HWTEST_F(PasteboardServiceTest, RegisterClientDeathObserverTest001, TestSize.Level0)
3985 {
3986 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RegisterClientDeathObserverTest001 start");
3987 auto tempPasteboard = std::make_shared<PasteboardService>();
3988 EXPECT_NE(tempPasteboard, nullptr);
3989
3990 PasteboardService service;
3991 pid_t pid = 1;
3992 sptr<IRemoteObject> observer = sptr<RemoteObjectTest>::MakeSptr(u"test");
3993 auto result = tempPasteboard->RegisterClientDeathObserver(observer);
3994 EXPECT_EQ(result, ERR_OK);
3995 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RegisterClientDeathObserverTest001 end");
3996 }
3997
3998 /**
3999 * @tc.name: GetDelayPasteRecord002
4000 * @tc.desc: GetDelayPasteRecord002
4001 * @tc.type: FUNC
4002 */
4003 HWTEST_F(PasteboardServiceTest, GetDelayPasteRecord002, TestSize.Level0)
4004 {
4005 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4006 EXPECT_NE(tempPasteboard, nullptr);
4007 int32_t userId = 0x123456;
4008 auto record = std::make_shared<PasteDataRecord>();
4009 ASSERT_NE(record, nullptr);
4010 record->SetDelayRecordFlag(true);
4011 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
4012 ASSERT_NE(entry, nullptr);
4013 std::string utdid = "utdid";
4014 entry->SetUtdId(utdid);
4015 std::string plainText = "text/plain";
4016 entry->SetValue(plainText);
4017 record->AddEntry(utdid, entry);
4018 PasteData data;
4019 data.AddRecord(record);
4020 sptr<IPasteboardEntryGetter> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
4021 ASSERT_NE(entryGetter, nullptr);
4022 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient = new
4023 OHOS::MiscServices::PasteboardService::EntryGetterDeathRecipient(userId, *tempPasteboard);
4024 ASSERT_NE(deathRecipient, nullptr);
4025 tempPasteboard->entryGetters_.InsertOrAssign(userId, std::make_pair(entryGetter, deathRecipient));
4026 tempPasteboard->GetDelayPasteRecord(userId + 1, data);
4027 tempPasteboard->GetDelayPasteRecord(userId, data);
4028 EXPECT_EQ(tempPasteboard->entryGetters_.Size(), 1);
4029 }
4030
4031 /**
4032 * @tc.name: GetDelayPasteRecord003
4033 * @tc.desc: GetDelayPasteRecord003
4034 * @tc.type: FUNC
4035 */
4036 HWTEST_F(PasteboardServiceTest, GetDelayPasteRecord003, TestSize.Level0)
4037 {
4038 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4039 EXPECT_NE(tempPasteboard, nullptr);
4040 int32_t userId = 0x123456;
4041 auto record = std::make_shared<PasteDataRecord>();
4042 ASSERT_NE(record, nullptr);
4043 record->SetDelayRecordFlag(false);
4044 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
4045 ASSERT_NE(entry, nullptr);
4046 std::string utdid = "utdid";
4047 entry->SetUtdId(utdid);
4048 std::string plainText = "text/plain";
4049 entry->SetValue(plainText);
4050 record->AddEntry(utdid, entry);
4051 PasteData data;
4052 data.AddRecord(record);
4053 sptr<IPasteboardEntryGetter> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
4054 ASSERT_NE(entryGetter, nullptr);
4055 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient = new
4056 OHOS::MiscServices::PasteboardService::EntryGetterDeathRecipient(userId, *tempPasteboard);
4057 ASSERT_NE(deathRecipient, nullptr);
4058 tempPasteboard->entryGetters_.InsertOrAssign(userId, std::make_pair(entryGetter, deathRecipient));
4059 tempPasteboard->GetDelayPasteRecord(userId, data);
4060 EXPECT_EQ(tempPasteboard->entryGetters_.Size(), 1);
4061 }
4062
4063 /**
4064 * @tc.name: GetDelayPasteRecord004
4065 * @tc.desc: GetDelayPasteRecord004
4066 * @tc.type: FUNC
4067 */
4068 HWTEST_F(PasteboardServiceTest, GetDelayPasteRecord004, TestSize.Level0)
4069 {
4070 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4071 EXPECT_NE(tempPasteboard, nullptr);
4072 int32_t userId = 0x123456;
4073 auto record = std::make_shared<PasteDataRecord>();
4074 ASSERT_NE(record, nullptr);
4075 record->SetDelayRecordFlag(true);
4076 PasteData data;
4077 data.AddRecord(record);
4078 sptr<IPasteboardEntryGetter> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
4079 ASSERT_NE(entryGetter, nullptr);
4080 sptr<PasteboardService::EntryGetterDeathRecipient> deathRecipient = new
4081 OHOS::MiscServices::PasteboardService::EntryGetterDeathRecipient(userId, *tempPasteboard);
4082 ASSERT_NE(deathRecipient, nullptr);
4083 tempPasteboard->entryGetters_.InsertOrAssign(userId, std::make_pair(entryGetter, deathRecipient));
4084 tempPasteboard->GetDelayPasteRecord(userId, data);
4085 EXPECT_EQ(tempPasteboard->entryGetters_.Size(), 1);
4086 }
4087
4088 /**
4089 * @tc.name: CloseP2PLink002
4090 * @tc.desc: CloseP2PLink002
4091 * @tc.type: FUNC
4092 */
4093 HWTEST_F(PasteboardServiceTest, CloseP2PLink002, TestSize.Level0)
4094 {
4095 #ifdef PB_DEVICE_MANAGER_ENABLE
4096 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4097 ASSERT_NE(tempPasteboard, nullptr);
4098 std::string networkId = "networkId";
4099 tempPasteboard->CloseP2PLink(networkId);
4100 EXPECT_NE(networkId, "");
4101 #endif
4102 }
4103
4104 /**
4105 * @tc.name: SaveData002
4106 * @tc.desc: SaveData002
4107 * @tc.type: FUNC
4108 */
4109 HWTEST_F(PasteboardServiceTest, SaveData002, TestSize.Level0)
4110 {
4111 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4112 EXPECT_NE(tempPasteboard, nullptr);
4113 PasteData pasteData;
4114 sptr<PasteboardDelayGetterImpl> delayGetter = nullptr;
4115 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
4116 ASSERT_NE(entryGetter, nullptr);
4117 int64_t dataSize = 0;
4118 int32_t ret = tempPasteboard->SaveData(pasteData, dataSize, delayGetter, entryGetter);
4119 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
4120 }
4121
4122 /**
4123 * @tc.name: SaveData003
4124 * @tc.desc: SaveData003
4125 * @tc.type: FUNC
4126 */
4127 HWTEST_F(PasteboardServiceTest, SaveData003, TestSize.Level0)
4128 {
4129 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4130 EXPECT_NE(tempPasteboard, nullptr);
4131 PasteData pasteData;
4132 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
4133 ASSERT_NE(delayGetter, nullptr);
4134 sptr<PasteboardEntryGetterImpl> entryGetter = nullptr;
4135 int64_t dataSize = 0;
4136 int32_t ret = tempPasteboard->SaveData(pasteData, dataSize, delayGetter, entryGetter);
4137 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));}
4138
4139 /**
4140 * @tc.name: SaveData004
4141 * @tc.desc: SaveData004
4142 * @tc.type: FUNC
4143 */
4144 HWTEST_F(PasteboardServiceTest, SaveData004, TestSize.Level0)
4145 {
4146 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4147 EXPECT_NE(tempPasteboard, nullptr);
4148 PasteData pasteData;
4149 sptr<PasteboardDelayGetterImpl> delayGetter = sptr<PasteboardDelayGetterImpl>::MakeSptr();
4150 ASSERT_NE(delayGetter, nullptr);
4151 sptr<PasteboardEntryGetterImpl> entryGetter = sptr<PasteboardEntryGetterImpl>::MakeSptr();
4152 ASSERT_NE(entryGetter, nullptr);
4153 int64_t dataSize = INT64_MAX;
4154 int32_t ret = tempPasteboard->SaveData(pasteData, dataSize, delayGetter, entryGetter);
4155 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
4156 }
4157
4158 /**
4159 * @tc.name: GetCommonStateTest002
4160 * @tc.desc: GetCommonStateTest002
4161 * @tc.type: FUNC
4162 */
4163 HWTEST_F(PasteboardServiceTest, GetCommonStateTest002, TestSize.Level0)
4164 {
4165 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4166 EXPECT_NE(tempPasteboard, nullptr);
4167 int64_t dataSize = INT64_MAX;
4168 CommonInfo info = tempPasteboard->GetCommonState(dataSize);
4169 EXPECT_EQ(info.dataSize, dataSize);
4170 }
4171
4172 /**
4173 * @tc.name: ProcessRemoteDelayHtmlInnerTest001
4174 * @tc.desc: ProcessRemoteDelayHtmlInnerTest001
4175 * @tc.type: FUNC
4176 */
4177 HWTEST_F(PasteboardServiceTest, ProcessRemoteDelayHtmlInnerTest001, TestSize.Level0)
4178 {
4179 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4180 EXPECT_NE(tempPasteboard, nullptr);
4181 std::string remoteDeviceId = "remoteDeviceId";
4182 auto tokenId = IPCSkeleton::GetCallingTokenID();
4183 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
4184 PasteData tmpData;
4185 tmpData.SetFileSize(1);
4186 PasteData data;
4187 PasteDataEntry entry;
4188
4189 int32_t ret = tempPasteboard->ProcessRemoteDelayHtmlInner(remoteDeviceId, appInfo, tmpData, data, entry);
4190 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::REBUILD_HTML_FAILED));
4191 }
4192
4193 /**
4194 * @tc.name: ProcessRemoteDelayHtmlInnerTest002
4195 * @tc.desc: ProcessRemoteDelayHtmlInnerTest002
4196 * @tc.type: FUNC
4197 */
4198 HWTEST_F(PasteboardServiceTest, ProcessRemoteDelayHtmlInnerTest002, TestSize.Level0)
4199 {
4200 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4201 EXPECT_NE(tempPasteboard, nullptr);
4202 std::string remoteDeviceId = "remoteDeviceId";
4203 auto tokenId = IPCSkeleton::GetCallingTokenID();
4204 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
4205 PasteData tmpData;
4206 tmpData.SetFileSize(0);
4207 PasteData data;
4208 PasteDataEntry entry;
4209
4210 int32_t ret = tempPasteboard->ProcessRemoteDelayHtmlInner(remoteDeviceId, appInfo, tmpData, data, entry);
4211 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::REBUILD_HTML_FAILED));
4212 }
4213
4214 /**
4215 * @tc.name: ProcessRemoteDelayHtmlTest002
4216 * @tc.desc: ProcessRemoteDelayHtmlTest002
4217 * @tc.type: FUNC
4218 */
4219 HWTEST_F(PasteboardServiceTest, ProcessRemoteDelayHtmlTest002, TestSize.Level0)
4220 {
4221 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4222 ASSERT_NE(tempPasteboard, nullptr);
4223 std::string remoteDeviceId = "remoteDeviceId";
4224 auto tokenId = IPCSkeleton::GetCallingTokenID();
4225 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
4226 std::vector<uint8_t> rawData(0);
4227 auto record = std::make_shared<PasteDataRecord>();
4228 ASSERT_NE(record, nullptr);
4229 record->SetDelayRecordFlag(true);
4230 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
4231 ASSERT_NE(entry, nullptr);
4232 std::string utdid = "utdid";
4233 entry->SetUtdId(utdid);
4234 std::string plainText = "text/plain";
4235 entry->SetValue(plainText);
4236 record->AddEntry(utdid, entry);
4237 PasteData data;
4238 data.AddRecord(record);
4239 data.Encode(rawData);
4240
4241 int32_t ret = tempPasteboard->ProcessRemoteDelayHtml(remoteDeviceId, appInfo, rawData, data, *record, *entry);
4242 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::GET_ENTRY_VALUE_FAILED));
4243 }
4244
4245 /**
4246 * @tc.name: GetRemoteEntryValueTest001
4247 * @tc.desc: GetRemoteEntryValueTest001
4248 * @tc.type: FUNC
4249 */
4250 HWTEST_F(PasteboardServiceTest, GetRemoteEntryValueTest001, TestSize.Level0)
4251 {
4252 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4253 EXPECT_NE(tempPasteboard, nullptr);
4254 std::string remoteDeviceId = "remoteDeviceId";
4255 auto tokenId = IPCSkeleton::GetCallingTokenID();
4256 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
4257 PasteData data;
4258 PasteDataRecord record;
4259 PasteDataEntry entry;
4260
4261 int32_t ret = tempPasteboard->GetRemoteEntryValue(appInfo, data, record, entry);
4262 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::PLUGIN_IS_NULL));
4263 }
4264
4265 /**
4266 * @tc.name: ProcessRemoteDelayUriTest001
4267 * @tc.desc: ProcessRemoteDelayUriTest001
4268 * @tc.type: FUNC
4269 */
4270 HWTEST_F(PasteboardServiceTest, ProcessRemoteDelayUriTest001, TestSize.Level0)
4271 {
4272 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
4273 EXPECT_NE(tempPasteboard, nullptr);
4274 std::string deviceId = "deviceId";
4275 auto tokenId = IPCSkeleton::GetCallingTokenID();
4276 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
4277 std::vector<uint8_t> rawData(0);
4278 auto record = std::make_shared<PasteDataRecord>();
4279 ASSERT_NE(record, nullptr);
4280 record->SetDelayRecordFlag(true);
4281 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
4282 ASSERT_NE(entry, nullptr);
4283 std::string utdid = "utdid";
4284 entry->SetUtdId(utdid);
4285 std::string plainText = "text/plain";
4286 entry->SetValue(plainText);
4287 record->AddEntry(utdid, entry);
4288 PasteData data;
4289 data.AddRecord(record);
4290 data.Encode(rawData);
4291
4292 int32_t ret = tempPasteboard->ProcessRemoteDelayUri(deviceId, appInfo, data, record, entry);
4293 EXPECT_NE(ret, static_cast<int32_t>(PasteboardError::E_OK));
4294 }
4295 } // namespace MiscServices
4296 } // namespace OHOS