• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <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 PasteboardServiceNotifyTest : 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 PasteboardServiceNotifyTest::SetUpTestCase(void) { }
156 
TearDownTestCase(void)157 void PasteboardServiceNotifyTest::TearDownTestCase(void) { }
158 
SetUp(void)159 void PasteboardServiceNotifyTest::SetUp(void) { }
160 
TearDown(void)161 void PasteboardServiceNotifyTest::TearDown(void) { }
162 
WritePasteData(PasteData & pasteData,std::vector<uint8_t> & buffer,int & fd,int64_t & tlvSize,MessageParcelWarp & messageData,MessageParcel & parcelPata)163 int32_t PasteboardServiceNotifyTest::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: NotifyDelayGetterDiedTest001
195  * @tc.desc: test Func NotifyDelayGetterDied
196  * @tc.type: FUNC
197  */
198 HWTEST_F(PasteboardServiceNotifyTest, NotifyDelayGetterDiedTest001, TestSize.Level0)
199 {
200     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyDelayGetterDiedTest001 start");
201     constexpr int32_t userId = 111;
202     auto tempPasteboard = std::make_shared<PasteboardService>();
203     EXPECT_NE(tempPasteboard, nullptr);
204 
205     tempPasteboard->NotifyDelayGetterDied(userId);
206     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyDelayGetterDiedTest001 end");
207 }
208 
209 /**
210  * @tc.name: NotifyDelayGetterDiedTest002
211  * @tc.desc: test Func NotifyDelayGetterDied
212  * @tc.type: FUNC
213  */
214 HWTEST_F(PasteboardServiceNotifyTest, NotifyDelayGetterDiedTest002, TestSize.Level0)
215 {
216     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyDelayGetterDiedTest002 start");
217     constexpr int32_t userId = -1;
218     auto tempPasteboard = std::make_shared<PasteboardService>();
219     EXPECT_NE(tempPasteboard, nullptr);
220 
221     tempPasteboard->NotifyDelayGetterDied(userId);
222     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyDelayGetterDiedTest002 end");
223 }
224 
225 /**
226  * @tc.name: NotifyEntryGetterDiedTest001
227  * @tc.desc: test Func NotifyEntryGetterDied
228  * @tc.type: FUNC
229  */
230 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntryGetterDiedTest001, TestSize.Level0)
231 {
232     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntryGetterDiedTest001 start");
233     constexpr int32_t userId = 111;
234     auto tempPasteboard = std::make_shared<PasteboardService>();
235     EXPECT_NE(tempPasteboard, nullptr);
236 
237     tempPasteboard->NotifyEntryGetterDied(userId);
238     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntryGetterDiedTest001 end");
239 }
240 
241 /**
242  * @tc.name: NotifyEntryGetterDiedTest002
243  * @tc.desc: test Func NotifyEntryGetterDied
244  * @tc.type: FUNC
245  */
246 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntryGetterDiedTest002, TestSize.Level0)
247 {
248     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntryGetterDiedTest002 start");
249     constexpr int32_t userId = -1;
250     auto tempPasteboard = std::make_shared<PasteboardService>();
251     EXPECT_NE(tempPasteboard, nullptr);
252 
253     tempPasteboard->NotifyEntryGetterDied(userId);
254     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntryGetterDiedTest002 end");
255 }
256 
257 /**
258  * @tc.name: Notify001
259  * @tc.desc: test Func Notify
260  * @tc.type: FUNC
261  */
262 HWTEST_F(PasteboardServiceNotifyTest, Notify001, TestSize.Level0)
263 {
264     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Notify001 start");
265     std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
266         std::make_shared<PasteboardService::RemoteDataTaskManager>();
267     EXPECT_NE(remoteDataTaskManager, nullptr);
268 
269     TestEvent event;
270     std::shared_ptr<PasteDateTime> data;
271     remoteDataTaskManager->Notify(event, data);
272     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Notify001 end");
273 }
274 
275 /**
276  * @tc.name: Notify002
277  * @tc.desc: test Func Notify
278  * @tc.type: FUNC
279  */
280 HWTEST_F(PasteboardServiceNotifyTest, Notify002, TestSize.Level0)
281 {
282     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Notify002 start");
283     std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
284         std::make_shared<PasteboardService::RemoteDataTaskManager>();
285     EXPECT_NE(remoteDataTaskManager, nullptr);
286 
287     TestEvent event;
288     event.deviceId = "12345";
289     event.seqId = 1;
290 
291     auto key = event.deviceId + std::to_string(event.seqId);
292     auto it = remoteDataTaskManager->dataTasks_.find(key);
293     it = remoteDataTaskManager->dataTasks_.emplace(key, std::make_shared<TaskContext>()).first;
294 
295     std::shared_ptr<PasteDateTime> data;
296     remoteDataTaskManager->Notify(event, data);
297     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "Notify002 end");
298 }
299 
300 /**
301  * @tc.name: NotifyEntityObserversTest001
302  * @tc.desc: test Func NotifyEntityObservers
303  * @tc.type: FUNC
304  */
305 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntityObserversTest001, TestSize.Level0)
306 {
307     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest001 start");
308     std::string entity = "hello";
309     uint32_t dataLength = 1;
310     auto tempPasteboard = std::make_shared<PasteboardService>();
311     EXPECT_NE(tempPasteboard, nullptr);
312 
313     tempPasteboard->NotifyEntityObservers(entity, EntityType::ADDRESS, dataLength);
314     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest001 end");
315 }
316 
317 /**
318  * @tc.name: NotifyEntityObserversTest002
319  * @tc.desc: test Func NotifyEntityObservers
320  * @tc.type: FUNC
321  */
322 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntityObserversTest002, TestSize.Level0)
323 {
324     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest002 start");
325     std::string entity = "hello";
326     uint32_t dataLength = 100;
327     auto tempPasteboard = std::make_shared<PasteboardService>();
328     EXPECT_NE(tempPasteboard, nullptr);
329 
330     EntityType entityType = EntityType::ADDRESS;
331     uint32_t expectedDataLength = 10;
332     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
333     int32_t result = tempPasteboard->SubscribeEntityObserver(entityType, expectedDataLength, observer);
334     EXPECT_EQ(result, ERR_OK);
335 
336     tempPasteboard->NotifyEntityObservers(entity, EntityType::MAX, dataLength);
337     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest002 end");
338 }
339 
340 /**
341  * @tc.name: NotifyEntityObserversTest003
342  * @tc.desc: test Func NotifyEntityObservers
343  * @tc.type: FUNC
344  */
345 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntityObserversTest003, TestSize.Level0)
346 {
347     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest003 start");
348     std::string entity = "hello";
349     uint32_t dataLength = 100;
350     auto tempPasteboard = std::make_shared<PasteboardService>();
351     EXPECT_NE(tempPasteboard, nullptr);
352 
353     EntityType entityType = EntityType::ADDRESS;
354     uint32_t expectedDataLength = 10;
355     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
356     int32_t result = tempPasteboard->SubscribeEntityObserver(entityType, expectedDataLength, observer);
357     EXPECT_EQ(result, ERR_OK);
358 
359     tempPasteboard->NotifyEntityObservers(entity, EntityType::ADDRESS, dataLength);
360     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest003 end");
361 }
362 
363 /**
364  * @tc.name: NotifyEntityObserversTest004
365  * @tc.desc: test Func NotifyEntityObservers
366  * @tc.type: FUNC
367  */
368 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntityObserversTest004, TestSize.Level0)
369 {
370     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest004 start");
371     std::string entity = "hello";
372     uint32_t dataLength = 1;
373     auto tempPasteboard = std::make_shared<PasteboardService>();
374     EXPECT_NE(tempPasteboard, nullptr);
375 
376     EntityType entityType = EntityType::ADDRESS;
377     uint32_t expectedDataLength = 10;
378     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
379     int32_t result = tempPasteboard->SubscribeEntityObserver(entityType, expectedDataLength, observer);
380     EXPECT_EQ(result, ERR_OK);
381 
382     tempPasteboard->NotifyEntityObservers(entity, EntityType::ADDRESS, dataLength);
383     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest004 end");
384 }
385 
386 /**
387  * @tc.name: NotifyEntityObserversTest005
388  * @tc.desc: test Func NotifyEntityObservers
389  * @tc.type: FUNC
390  */
391 HWTEST_F(PasteboardServiceNotifyTest, NotifyEntityObserversTest005, TestSize.Level0)
392 {
393     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest005 start");
394     std::string entity = "hello";
395     uint32_t dataLength = 1;
396     auto tempPasteboard = std::make_shared<PasteboardService>();
397     EXPECT_NE(tempPasteboard, nullptr);
398 
399     EntityType entityType = EntityType::ADDRESS;
400     uint32_t expectedDataLength = 10;
401     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
402     int32_t result = tempPasteboard->SubscribeEntityObserver(entityType, expectedDataLength, observer);
403     EXPECT_EQ(result, ERR_OK);
404 
405     tempPasteboard->NotifyEntityObservers(entity, EntityType::MAX, dataLength);
406     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyEntityObserversTest005 end");
407 }
408 
409 /**
410  * @tc.name: NotifyObserversTest001
411  * @tc.desc: test Func NotifyObservers
412  * @tc.type: FUNC
413  */
414 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest001, TestSize.Level0)
415 {
416     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest001 start");
417     auto tempPasteboard = std::make_shared<PasteboardService>();
418     EXPECT_NE(tempPasteboard, nullptr);
419 
420     auto userId = 1;
421     pid_t callPid = 1;
422     AppInfo appInfo;
423     tempPasteboard->GetAppBundleName(appInfo);
424     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
425     auto it = tempPasteboard->imeMap_.Find(userId);
426     auto hasPid = it.first;
427     EXPECT_EQ(hasPid, true);
428 
429     tempPasteboard->NotifyObservers(appInfo.bundleName, userId, PasteboardEventStatus::PASTEBOARD_WRITE);
430     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest001 end");
431 }
432 
433 /**
434  * @tc.name: NotifyObserversTest002
435  * @tc.desc: test Func NotifyObservers
436  * @tc.type: FUNC
437  */
438 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest002, TestSize.Level0)
439 {
440     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest002 start");
441     auto tempPasteboard = std::make_shared<PasteboardService>();
442     EXPECT_NE(tempPasteboard, nullptr);
443 
444     auto userId = 1;
445     pid_t callPid = 1;
446     AppInfo appInfo;
447     tempPasteboard->GetAppBundleName(appInfo);
448     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
449     auto it = tempPasteboard->imeMap_.Find(userId + 1);
450     auto hasPid = it.first;
451     EXPECT_NE(hasPid, true);
452 
453     tempPasteboard->NotifyObservers(appInfo.bundleName, userId + 1, PasteboardEventStatus::PASTEBOARD_WRITE);
454     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest002 end");
455 }
456 
457 /**
458  * @tc.name: NotifyObserversTest003
459  * @tc.desc: test Func NotifyObservers
460  * @tc.type: FUNC
461  */
462 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest003, TestSize.Level0)
463 {
464     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest003 start");
465     auto tempPasteboard = std::make_shared<PasteboardService>();
466     EXPECT_NE(tempPasteboard, nullptr);
467 
468     auto userId = 1;
469     pid_t callPid = 1;
470     AppInfo appInfo;
471     tempPasteboard->GetAppBundleName(appInfo);
472     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
473     auto it = tempPasteboard->imeMap_.Find(userId + 1);
474     auto hasPid = it.first;
475     EXPECT_NE(hasPid, true);
476 
477     const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
478     EXPECT_NE(observer, nullptr);
479 
480     tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_LOCAL, observer);
481     tempPasteboard->NotifyObservers(appInfo.bundleName, userId, PasteboardEventStatus::PASTEBOARD_WRITE);
482     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest003 end");
483 }
484 
485 /**
486  * @tc.name: NotifyObserversTest004
487  * @tc.desc: test Func NotifyObservers
488  * @tc.type: FUNC
489  */
490 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest004, TestSize.Level0)
491 {
492     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest004 start");
493     auto tempPasteboard = std::make_shared<PasteboardService>();
494     EXPECT_NE(tempPasteboard, nullptr);
495 
496     auto userId = 1;
497     pid_t callPid = 1;
498     AppInfo appInfo;
499     tempPasteboard->GetAppBundleName(appInfo);
500     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
501     auto it = tempPasteboard->imeMap_.Find(userId);
502     auto hasPid = it.first;
503     EXPECT_EQ(hasPid, true);
504 
505     const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
506     EXPECT_NE(observer, nullptr);
507 
508     tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_LOCAL, observer);
509     tempPasteboard->NotifyObservers(appInfo.bundleName, userId + 1, PasteboardEventStatus::PASTEBOARD_WRITE);
510     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest004 end");
511 }
512 
513 /**
514  * @tc.name: NotifyObserversTest005
515  * @tc.desc: test Func NotifyObservers
516  * @tc.type: FUNC
517  */
518 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest005, TestSize.Level0)
519 {
520     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest005 start");
521     auto tempPasteboard = std::make_shared<PasteboardService>();
522     EXPECT_NE(tempPasteboard, nullptr);
523 
524     auto userId = 1;
525     pid_t callPid = 1;
526     AppInfo appInfo;
527     tempPasteboard->GetAppBundleName(appInfo);
528     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
529     auto it = tempPasteboard->imeMap_.Find(userId + 1);
530     auto hasPid = it.first;
531     EXPECT_NE(hasPid, true);
532 
533     const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
534     EXPECT_NE(observer, nullptr);
535 
536     tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_LOCAL, observer);
537     tempPasteboard->NotifyObservers(appInfo.bundleName, userId, PasteboardEventStatus::PASTEBOARD_READ);
538     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest005 end");
539 }
540 
541 /**
542  * @tc.name: NotifyObserversTest006
543  * @tc.desc: test Func NotifyObservers
544  * @tc.type: FUNC
545  */
546 HWTEST_F(PasteboardServiceNotifyTest, NotifyObserversTest006, TestSize.Level0)
547 {
548     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest006 start");
549     auto tempPasteboard = std::make_shared<PasteboardService>();
550     EXPECT_NE(tempPasteboard, nullptr);
551 
552     auto userId = 1;
553     pid_t callPid = 1;
554     AppInfo appInfo;
555     tempPasteboard->GetAppBundleName(appInfo);
556     tempPasteboard->imeMap_.InsertOrAssign(userId, callPid);
557     auto it = tempPasteboard->imeMap_.Find(userId);
558     auto hasPid = it.first;
559     EXPECT_EQ(hasPid, true);
560 
561     const sptr<IPasteboardChangedObserver> observer = sptr<MyTestPasteboardChangedObserver>::MakeSptr();
562     EXPECT_NE(observer, nullptr);
563 
564     tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_LOCAL, observer);
565     tempPasteboard->NotifyObservers(appInfo.bundleName, userId + 1, PasteboardEventStatus::PASTEBOARD_READ);
566     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "NotifyObserversTest006 end");
567 }
568 
569 } // namespace MiscServices
570 } // namespace OHOS