• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <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 PasteboardServiceSubscribeTest : 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 PasteboardServiceSubscribeTest::SetUpTestCase(void) { }
156 
TearDownTestCase(void)157 void PasteboardServiceSubscribeTest::TearDownTestCase(void) { }
158 
SetUp(void)159 void PasteboardServiceSubscribeTest::SetUp(void) { }
160 
TearDown(void)161 void PasteboardServiceSubscribeTest::TearDown(void) { }
162 
WritePasteData(PasteData & pasteData,std::vector<uint8_t> & buffer,int & fd,int64_t & tlvSize,MessageParcelWarp & messageData,MessageParcel & parcelPata)163 int32_t PasteboardServiceSubscribeTest::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: SubscribeEntityObserverTest001
195  * @tc.desc: test Func SubscribeEntityObserver
196  * @tc.type: FUNC
197  */
198 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeEntityObserverTest001, TestSize.Level0)
199 {
200     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest001 start");
201     auto service = std::make_shared<PasteboardService>();
202     EXPECT_NE(service, nullptr);
203 
204     EntityType entityType = EntityType::ADDRESS;
205     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
206     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
207 
208     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
209     EXPECT_EQ(result, ERR_OK);
210     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest001 end");
211 }
212 
213 /**
214  * @tc.name: SubscribeEntityObserverTest002
215  * @tc.desc: test Func SubscribeEntityObserver
216  * @tc.type: FUNC
217  */
218 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeEntityObserverTest002, TestSize.Level0)
219 {
220     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest002 start");
221     auto service = std::make_shared<PasteboardService>();
222     EXPECT_NE(service, nullptr);
223 
224     EntityType entityType = EntityType::ADDRESS;
225     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
226     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
227 
228     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
229     result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
230     EXPECT_EQ(result, ERR_OK);
231     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest002 end");
232 }
233 
234 /**
235  * @tc.name: SubscribeEntityObserverTest003
236  * @tc.desc: test Func SubscribeEntityObserver
237  * @tc.type: FUNC
238  */
239 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeEntityObserverTest003, TestSize.Level0)
240 {
241     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest003 start");
242     auto service = std::make_shared<PasteboardService>();
243     EXPECT_NE(service, nullptr);
244 
245     EntityType entityType = EntityType::ADDRESS;
246     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
247     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
248 
249     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
250     result = service->SubscribeEntityObserver(entityType, 1, observer);
251     EXPECT_EQ(result, ERR_OK);
252     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeEntityObserverTest003 end");
253 }
254 
255 /**
256  * @tc.name: UnsubscribeEntityObserverTest001
257  * @tc.desc: test Func UnsubscribeEntityObserver
258  * @tc.type: FUNC
259  */
260 HWTEST_F(PasteboardServiceSubscribeTest, UnsubscribeEntityObserverTest001, TestSize.Level0)
261 {
262     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest001 start");
263     auto service = std::make_shared<PasteboardService>();
264     EXPECT_NE(service, nullptr);
265 
266     EntityType entityType = EntityType::ADDRESS;
267     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
268     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
269 
270     int32_t result = service->UnsubscribeEntityObserver(entityType, expectedDataLength, observer);
271     EXPECT_EQ(result, ERR_OK);
272     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest001 end");
273 }
274 
275 /**
276  * @tc.name: UnsubscribeEntityObserverTest002
277  * @tc.desc: test Func UnsubscribeEntityObserver
278  * @tc.type: FUNC
279  */
280 HWTEST_F(PasteboardServiceSubscribeTest, UnsubscribeEntityObserverTest002, TestSize.Level0)
281 {
282     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest002 start");
283     auto service = std::make_shared<PasteboardService>();
284     EXPECT_NE(service, nullptr);
285 
286     EntityType entityType = EntityType::ADDRESS;
287     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
288     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
289 
290     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
291     result = service->UnsubscribeEntityObserver(entityType, 1, observer);
292     EXPECT_EQ(result, ERR_OK);
293     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest002 end");
294 }
295 
296 /**
297  * @tc.name: UnsubscribeEntityObserverTest003
298  * @tc.desc: test Func UnsubscribeEntityObserver
299  * @tc.type: FUNC
300  */
301 HWTEST_F(PasteboardServiceSubscribeTest, UnsubscribeEntityObserverTest003, TestSize.Level0)
302 {
303     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest003 start");
304     auto service = std::make_shared<PasteboardService>();
305     EXPECT_NE(service, nullptr);
306 
307     EntityType entityType = EntityType::ADDRESS;
308     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
309     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
310 
311     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
312     result = service->UnsubscribeEntityObserver(entityType, expectedDataLength, observer);
313     EXPECT_EQ(result, ERR_OK);
314     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest003 end");
315 }
316 
317 /**
318  * @tc.name: UnsubscribeEntityObserverTest004
319  * @tc.desc: test Func UnsubscribeEntityObserver
320  * @tc.type: FUNC
321  */
322 HWTEST_F(PasteboardServiceSubscribeTest, UnsubscribeEntityObserverTest004, TestSize.Level0)
323 {
324     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest004 start");
325     auto service = std::make_shared<PasteboardService>();
326     EXPECT_NE(service, nullptr);
327 
328     EntityType entityType = EntityType::ADDRESS;
329     uint32_t expectedDataLength = MAX_RECOGNITION_LENGTH;
330     const sptr<IEntityRecognitionObserver> observer = sptr<MyTestEntityRecognitionObserver>::MakeSptr();
331 
332     int32_t result = service->SubscribeEntityObserver(entityType, expectedDataLength, observer);
333     result = service->SubscribeEntityObserver(entityType, 1, observer);
334     result = service->UnsubscribeEntityObserver(entityType, expectedDataLength, observer);
335     EXPECT_EQ(result, ERR_OK);
336     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeEntityObserverTest004 end");
337 }
338 
339 /**
340  * @tc.name: SubscribeObserverTest001
341  * @tc.desc: test Func SubscribeObserver
342  * @tc.type: FUNC
343  */
344 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeObserverTest001, TestSize.Level0)
345 {
346     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest001 start");
347     auto tempPasteboard = std::make_shared<PasteboardService>();
348     EXPECT_NE(tempPasteboard, nullptr);
349 
350     const sptr<IPasteboardChangedObserver> observer = nullptr;
351     auto ret = tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_LOCAL, observer);
352     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::ADD_OBSERVER_FAILED));
353     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest001 end");
354 }
355 
356 /**
357  * @tc.name: SubscribeObserverTest002
358  * @tc.desc: test Func SubscribeObserver
359  * @tc.type: FUNC
360  */
361 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeObserverTest002, TestSize.Level0)
362 {
363     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest002 start");
364     auto tempPasteboard = std::make_shared<PasteboardService>();
365     EXPECT_NE(tempPasteboard, nullptr);
366 
367     const sptr<IPasteboardChangedObserver> observer = nullptr;
368     auto ret = tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_REMOTE, observer);
369     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::ADD_OBSERVER_FAILED));
370     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest002 end");
371 }
372 
373 /**
374  * @tc.name: SubscribeObserverTest003
375  * @tc.desc: test Func SubscribeObserver
376  * @tc.type: FUNC
377  */
378 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeObserverTest003, TestSize.Level0)
379 {
380     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest003 start");
381     auto tempPasteboard = std::make_shared<PasteboardService>();
382     EXPECT_NE(tempPasteboard, nullptr);
383 
384     const sptr<IPasteboardChangedObserver> observer = nullptr;
385     auto ret = tempPasteboard->SubscribeObserver(PasteboardObserverType::OBSERVER_EVENT, observer);
386     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::ADD_OBSERVER_FAILED));
387     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeObserverTest003 end");
388 }
389 
390 /**
391  * @tc.name: UnsubscribeAllEntityObserverTest001
392  * @tc.desc: test Func UnsubscribeAllEntityObserver
393  * @tc.type: FUNC
394  */
395 HWTEST_F(PasteboardServiceSubscribeTest, UnsubscribeAllEntityObserverTest001, TestSize.Level0)
396 {
397     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeAllEntityObserverTest001 start");
398     auto tempPasteboard = std::make_shared<PasteboardService>();
399     EXPECT_NE(tempPasteboard, nullptr);
400 
401     tempPasteboard->UnsubscribeAllEntityObserver();
402     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "UnsubscribeAllEntityObserverTest001 end");
403 }
404 
405 /**
406  * @tc.name: SubscribeKeyboardEventTest001
407  * @tc.desc: test Func SubscribeKeyboardEvent
408  * @tc.type: FUNC
409  */
410 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeKeyboardEventTest001, TestSize.Level0)
411 {
412     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeKeyboardEventTest001 start");
413     auto tempPasteboard = std::make_shared<PasteboardService>();
414     auto result = tempPasteboard->SubscribeKeyboardEvent();
415     EXPECT_EQ(result, true);
416     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeKeyboardEventTest001 end");
417 }
418 
419 /**
420  * @tc.name: SubscribeKeyboardEventTest002
421  * @tc.desc: test Func SubscribeKeyboardEvent
422  * @tc.type: FUNC
423  */
424 HWTEST_F(PasteboardServiceSubscribeTest, SubscribeKeyboardEventTest002, TestSize.Level0)
425 {
426     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeKeyboardEventTest002 start");
427     auto tempPasteboard = std::make_shared<PasteboardService>();
428     auto result = tempPasteboard->SubscribeKeyboardEvent();
429     result = tempPasteboard->SubscribeKeyboardEvent();
430     EXPECT_EQ(result, true);
431     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "SubscribeKeyboardEventTest002 end");
432 }
433 
434 /**
435  * @tc.name: PasteboardEventSubscriberTest001
436  * @tc.desc: test Func PasteboardEventSubscriber
437  * @tc.type: FUNC
438  */
439 HWTEST_F(PasteboardServiceSubscribeTest, PasteboardEventSubscriberTest001, TestSize.Level0)
440 {
441     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteboardEventSubscriberTest001 start");
442     auto tempPasteboard = std::make_shared<PasteboardService>();
443     EXPECT_NE(tempPasteboard, nullptr);
444     tempPasteboard->PasteboardEventSubscriber();
445     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "PasteboardEventSubscriberTest001 end");
446 }
447 
448 /**
449  * @tc.name: CommonEventSubscriberTest001
450  * @tc.desc: test Func CommonEventSubscriber
451  * @tc.type: FUNC
452  */
453 HWTEST_F(PasteboardServiceSubscribeTest, CommonEventSubscriberTest001, TestSize.Level0)
454 {
455     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CommonEventSubscriberTest001 start");
456     auto tempPasteboard = std::make_shared<PasteboardService>();
457     EXPECT_NE(tempPasteboard, nullptr);
458     tempPasteboard->CommonEventSubscriber();
459     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CommonEventSubscriberTest001 end");
460 }
461 
462 /**
463  * @tc.name: CommonEventSubscriberTest002
464  * @tc.desc: test Func CommonEventSubscriber
465  * @tc.type: FUNC
466  */
467 HWTEST_F(PasteboardServiceSubscribeTest, CommonEventSubscriberTest002, TestSize.Level0)
468 {
469     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CommonEventSubscriberTest002 start");
470     auto tempPasteboard = std::make_shared<PasteboardService>();
471     EXPECT_NE(tempPasteboard, nullptr);
472 
473     tempPasteboard->CommonEventSubscriber();
474     tempPasteboard->CommonEventSubscriber();
475     EXPECT_NE(tempPasteboard->commonEventSubscriber_, nullptr);
476     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "CommonEventSubscriberTest002 end");
477 }
478 
479 /**
480  * @tc.name: AccountStateSubscriberTest001
481  * @tc.desc: test Func AccountStateSubscriber
482  * @tc.type: FUNC
483  */
484 HWTEST_F(PasteboardServiceSubscribeTest, AccountStateSubscriberTest001, TestSize.Level0)
485 {
486     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AccountStateSubscriberTest001 start");
487     sptr<PasteboardService> tempPasteboard = new PasteboardService();
488     EXPECT_NE(tempPasteboard, nullptr);
489 
490     std::set<AccountSA::OsAccountState> states = {AccountSA::OsAccountState::STOPPING};
491     AccountSA::OsAccountSubscribeInfo subscribeInfo(states, true);
492     tempPasteboard->accountStateSubscriber_ = std::make_shared<PasteBoardAccountStateSubscriber>(subscribeInfo,
493         tempPasteboard);
494     tempPasteboard->AccountStateSubscriber();
495     EXPECT_NE(tempPasteboard->accountStateSubscriber_, nullptr);
496     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AccountStateSubscriberTest001 end");
497 }
498 
499 /**
500  * @tc.name: AddObserverTest001
501  * @tc.desc: test Func AddObserver
502  * @tc.type: FUNC
503  * @tc.require:
504  * @tc.author:
505  */
506 HWTEST_F(PasteboardServiceSubscribeTest, AddObserverTest001, TestSize.Level0)
507 {
508     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddObserverTest001 start");
509     auto tempPasteboard = std::make_shared<PasteboardService>();
510     EXPECT_NE(tempPasteboard, nullptr);
511 
512     PasteboardService::ObserverMap observerMap;
513     int32_t user = 1234;
514 
515     tempPasteboard->AddObserver(user, nullptr, observerMap);
516     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddObserverTest001 end");
517 }
518 
519 /**
520  * @tc.name: AddObserverTest002
521  * @tc.desc: test Func AddObserver
522  * @tc.type: FUNC
523  * @tc.require:
524  * @tc.author:
525  */
526 HWTEST_F(PasteboardServiceSubscribeTest, AddObserverTest002, TestSize.Level0)
527 {
528     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddObserverTest002 start");
529     auto tempPasteboard = std::make_shared<PasteboardService>();
530     EXPECT_NE(tempPasteboard, nullptr);
531 
532     sptr<IPasteboardChangedObserver> observer;
533     PasteboardService::ObserverMap observerMap;
534     int32_t user = 1234;
535 
536     tempPasteboard->AddObserver(user, observer, observerMap);
537     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "AddObserverTest002 end");
538 }
539 
540 /**
541  * @tc.name: GetObserversSizeTest001
542  * @tc.desc: test Func GetObserversSize
543  * @tc.type: FUNC
544  */
545 HWTEST_F(PasteboardServiceSubscribeTest, GetObserversSizeTest001, TestSize.Level0)
546 {
547     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetObserversSizeTest001 start");
548     auto tempPasteboard = std::make_shared<PasteboardService>();
549     EXPECT_NE(tempPasteboard, nullptr);
550 
551     int32_t userId = 1;
552     pid_t pid = 1;
553     PasteboardService::ObserverMap observerMap;
554     tempPasteboard->GetObserversSize(userId, pid, observerMap);
555     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetObserversSizeTest001 end");
556 }
557 
558 /**
559  * @tc.name: GetObserversSizeTest002
560  * @tc.desc: test Func GetObserversSize
561  * @tc.type: FUNC
562  */
563 HWTEST_F(PasteboardServiceSubscribeTest, GetObserversSizeTest002, TestSize.Level0)
564 {
565     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetObserversSizeTest002 start");
566     auto tempPasteboard = std::make_shared<PasteboardService>();
567     EXPECT_NE(tempPasteboard, nullptr);
568 
569     int32_t userId = 1;
570     pid_t pid = 1;
571     PasteboardService::ObserverMap observerMap;
572     auto result = tempPasteboard->GetObserversSize(userId, pid, observerMap);
573     EXPECT_EQ(result, 0);
574     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetObserversSizeTest002 end");
575 }
576 
577 /**
578  * @tc.name: GetAllObserversSizeTest001
579  * @tc.desc: test Func GetAllObserversSize
580  * @tc.type: FUNC
581  */
582 HWTEST_F(PasteboardServiceSubscribeTest, GetAllObserversSizeTest001, TestSize.Level0)
583 {
584     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllObserversSizeTest001 start");
585     auto userId = 123;
586     auto tokenId = 123;
587     auto tempPasteboard = std::make_shared<PasteboardService>();
588     EXPECT_NE(tempPasteboard, nullptr);
589 
590     tempPasteboard->GetAllObserversSize(userId, tokenId);
591     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllObserversSizeTest001 end");
592 }
593 
594 /**
595  * @tc.name: RemoveSingleObserverddObserverTest001
596  * @tc.desc: test Func RemoveSingleObserverddObserver
597  * @tc.type: FUNC
598  * @tc.require:
599  * @tc.author:
600  */
601 HWTEST_F(PasteboardServiceSubscribeTest, RemoveSingleObserverddObserverTest001, TestSize.Level0)
602 {
603     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveSingleObserverddObserverTest001 start");
604     auto tempPasteboard = std::make_shared<PasteboardService>();
605     EXPECT_NE(tempPasteboard, nullptr);
606 
607     PasteboardService::ObserverMap observerMap;
608     int32_t user = 1234;
609 
610     tempPasteboard->RemoveSingleObserver(user, nullptr, observerMap);
611     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveSingleObserverddObserverTest001 end");
612 }
613 
614 /**
615  * @tc.name: RemoveAllObserverTest001
616  * @tc.desc: test Func RemoveAllObserver
617  * @tc.type: FUNC
618  */
619 HWTEST_F(PasteboardServiceSubscribeTest, RemoveAllObserverTest001, TestSize.Level0)
620 {
621     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAllObserverTest001 start");
622     auto tempPasteboard = std::make_shared<PasteboardService>();
623     EXPECT_NE(tempPasteboard, nullptr);
624 
625     int32_t userId = 1;
626     PasteboardService::ObserverMap observerMap;
627     tempPasteboard->RemoveAllObserver(userId, observerMap);
628     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveAllObserverTest001 end");
629 }
630 
631 /**
632  * @tc.name: RemoveObserverByPidTest001
633  * @tc.desc: test Func RemoveObserverByPid
634  * @tc.type: FUNC
635  */
636 HWTEST_F(PasteboardServiceSubscribeTest, RemoveObserverByPidTest001, TestSize.Level0)
637 {
638     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveObserverByPidTest001 start");
639     auto tempPasteboard = std::make_shared<PasteboardService>();
640     EXPECT_NE(tempPasteboard, nullptr);
641 
642     int32_t userId = 1;
643     pid_t pid = 1;
644     PasteboardService::ObserverMap observerMap;
645     tempPasteboard->RemoveObserverByPid(userId, pid, observerMap);
646     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveObserverByPidTest001 end");
647 }
648 
649 /**
650  * @tc.name: RemoveObserverByPidTest002
651  * @tc.desc: test Func RemoveObserverByPid
652  * @tc.type: FUNC
653  */
654 HWTEST_F(PasteboardServiceSubscribeTest, RemoveObserverByPidTest002, TestSize.Level0)
655 {
656     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveObserverByPidTest002 start");
657     auto tempPasteboard = std::make_shared<PasteboardService>();
658     EXPECT_NE(tempPasteboard, nullptr);
659 
660     int32_t userId = 1;
661     pid_t pid = 1;
662     struct classcomp {};
663     std::pair<int32_t, pid_t> callObserverKey = std::make_pair(userId, pid);
664     PasteboardService::ObserverMap observerMap;
665     observerMap.insert(std::make_pair(callObserverKey, nullptr));
666     tempPasteboard->RemoveObserverByPid(userId, pid, observerMap);
667     EXPECT_EQ(observerMap.size(), 0);
668     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "RemoveObserverByPidTest002 end");
669 }
670 
671 } // namespace MiscServices
672 } // namespace OHOS