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 PasteboardServiceGetDataTest : 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 PasteboardServiceGetDataTest::SetUpTestCase(void) { }
156
TearDownTestCase(void)157 void PasteboardServiceGetDataTest::TearDownTestCase(void) { }
158
SetUp(void)159 void PasteboardServiceGetDataTest::SetUp(void) { }
160
TearDown(void)161 void PasteboardServiceGetDataTest::TearDown(void) { }
162
WritePasteData(PasteData & pasteData,std::vector<uint8_t> & buffer,int & fd,int64_t & tlvSize,MessageParcelWarp & messageData,MessageParcel & parcelPata)163 int32_t PasteboardServiceGetDataTest::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: GetPasteDataTest001
195 * @tc.desc: test Func GetPasteData
196 * @tc.type: FUNC
197 * @tc.require:
198 * @tc.author:
199 */
200 HWTEST_F(PasteboardServiceGetDataTest, GetPasteDataTest001, TestSize.Level0)
201 {
202 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataTest001 start");
203 auto tempPasteboard = std::make_shared<PasteboardService>();
204 EXPECT_NE(tempPasteboard, nullptr);
205
206 int32_t syncTime = 0;
207 int fd = -1;
208 int64_t rawDataSize = 0;
209 std::vector<uint8_t> recvTLV;
210 std::string pasteId = "GetPasteData_001";
211 auto ret = tempPasteboard->GetPasteData(fd, rawDataSize, recvTLV, pasteId, syncTime);
212 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
213 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataTest001 end");
214 }
215
216 /**
217 * @tc.name: GetPasteDataTest002
218 * @tc.desc: test Func GetPasteData
219 * @tc.type: FUNC
220 * @tc.require:
221 * @tc.author:
222 */
223 HWTEST_F(PasteboardServiceGetDataTest, GetPasteDataTest002, TestSize.Level0)
224 {
225 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataTest002 start");
226 auto tempPasteboard = std::make_shared<PasteboardService>();
227 EXPECT_NE(tempPasteboard, nullptr);
228
229 int32_t syncTime = 0;
230 int fd = -1;
231 int64_t rawDataSize = 0;
232 std::vector<uint8_t> recvTLV;
233 std::string pasteId = "GetPasteData_test_002";
234 auto ret = tempPasteboard->GetPasteData(fd, rawDataSize, recvTLV, pasteId, syncTime);
235 EXPECT_EQ(static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR), ret);
236 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataTest002 end");
237 }
238
239 /**
240 * @tc.name: GetPasteDataDotTest001
241 * @tc.desc: test Func GetPasteDataDot
242 * @tc.type: FUNC
243 */
244 HWTEST_F(PasteboardServiceGetDataTest, GetPasteDataDotTest001, TestSize.Level0)
245 {
246 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataDotTest001 start");
247 PasteData pasteData;
248 std::string bundleName;
249 auto tempPasteboard = std::make_shared<PasteboardService>();
250 EXPECT_NE(tempPasteboard, nullptr);
251
252 tempPasteboard->GetPasteDataDot(pasteData, bundleName);
253 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetPasteDataDotTest001 end");
254 }
255
256 /**
257 * @tc.name: GetDataSizeTest001
258 * @tc.desc: test Func GetDataSize
259 * @tc.type: FUNC
260 */
261 HWTEST_F(PasteboardServiceGetDataTest, GetDataSizeTest001, TestSize.Level0)
262 {
263 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSizeTest001 start");
264 PasteData data;
265 auto tempPasteboard = std::make_shared<PasteboardService>();
266 EXPECT_NE(tempPasteboard, nullptr);
267
268 tempPasteboard->GetDataSize(data);
269 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDataSizeTest001 end");
270 }
271
272 /**
273 * @tc.name: GetRemoteDataTask001
274 * @tc.desc: test Func GetRemoteDataTask
275 * @tc.type: FUNC
276 */
277 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteDataTask001, TestSize.Level0)
278 {
279 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDataTask001 start");
280 std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
281 std::make_shared<PasteboardService::RemoteDataTaskManager>();
282 EXPECT_NE(remoteDataTaskManager, nullptr);
283
284 TestEvent event;
285 remoteDataTaskManager->GetRemoteDataTask(event);
286 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDataTask001 end");
287 }
288
289 /**
290 * @tc.name: GetRemoteDataTask002
291 * @tc.desc: test Func GetRemoteDataTask
292 * @tc.type: FUNC
293 */
294 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteDataTask002, TestSize.Level0)
295 {
296 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDataTask002 start");
297 std::shared_ptr<PasteboardService::RemoteDataTaskManager> remoteDataTaskManager =
298 std::make_shared<PasteboardService::RemoteDataTaskManager>();
299 EXPECT_NE(remoteDataTaskManager, nullptr);
300
301 TestEvent event;
302 event.deviceId = "12345";
303 event.seqId = 1;
304
305 auto key = event.deviceId + std::to_string(event.seqId);
306 auto it = remoteDataTaskManager->dataTasks_.find(key);
307 it = remoteDataTaskManager->dataTasks_.emplace(key, std::make_shared<TaskContext>()).first;
308
309 remoteDataTaskManager->GetRemoteDataTask(event);
310 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteDataTask002 end");
311 }
312
313 /**
314 * @tc.name: GetRemoteData001
315 * @tc.desc: test Func GetRemoteData
316 * @tc.type: FUNC
317 */
318 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteData001, TestSize.Level0)
319 {
320 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData001 start");
321 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
322 EXPECT_NE(tempPasteboard, nullptr);
323
324 int32_t userId = 0x123456;
325 TestEvent event;
326 PasteData data;
327 int32_t syncTime = 1000;
328 auto ret = tempPasteboard->GetRemoteData(userId, event, data, syncTime);
329 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::PLUGIN_IS_NULL));
330 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData001 end");
331 }
332
333 /**
334 * @tc.name: GetRemoteData002
335 * @tc.desc: test Func GetRemoteData
336 * @tc.type: FUNC
337 */
338 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteData002, TestSize.Level0)
339 {
340 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData002 start");
341 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
342 EXPECT_NE(tempPasteboard, nullptr);
343
344 int32_t userId = 0x123456;
345 TestEvent event;
346 PasteData data;
347 int32_t syncTime = 1000;
348
349 PasteData pasteData;
350 tempPasteboard->clips_.InsertOrAssign(userId, std::make_shared<PasteData>(pasteData));
351 auto ret = tempPasteboard->GetRemoteData(userId, event, data, syncTime);
352 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
353 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData002 end");
354 }
355
356 /**
357 * @tc.name: GetRemoteData003
358 * @tc.desc: test Func GetRemoteData
359 * @tc.type: FUNC
360 */
361 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteData003, TestSize.Level0)
362 {
363 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData003 start");
364 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
365 EXPECT_NE(tempPasteboard, nullptr);
366
367 int32_t userId = 0x123456;
368 TestEvent event;
369 PasteData data;
370 int32_t syncTime = 1000;
371 event.seqId = 1;
372
373 PasteData pasteData;
374 tempPasteboard->clips_.InsertOrAssign(userId, std::make_shared<PasteData>(pasteData));
375 auto ret = tempPasteboard->GetRemoteData(userId, event, data, syncTime);
376 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
377 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteData003 end");
378 }
379
380 /**
381 * @tc.name: GetRemotePasteData001
382 * @tc.desc: test Func GetRemotePasteData
383 * @tc.type: FUNC
384 */
385 HWTEST_F(PasteboardServiceGetDataTest, GetRemotePasteData001, TestSize.Level0)
386 {
387 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemotePasteData001 start");
388 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
389 EXPECT_NE(tempPasteboard, nullptr);
390
391 int32_t userId = 0x123456;
392 TestEvent event;
393 PasteData data;
394 int32_t syncTime = 1000;
395 tempPasteboard->GetRemotePasteData(userId, event, data, syncTime);
396 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemotePasteData001 end");
397 }
398
399 /**
400 * @tc.name: GetDelayPasteRecord001
401 * @tc.desc: test Func GetDelayPasteRecord
402 * @tc.type: FUNC
403 */
404 HWTEST_F(PasteboardServiceGetDataTest, GetDelayPasteRecord001, TestSize.Level0)
405 {
406 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDelayPasteRecord001 start");
407 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
408 EXPECT_NE(tempPasteboard, nullptr);
409
410 int32_t userId = 0x123456;
411 PasteData data;
412 tempPasteboard->GetDelayPasteRecord(userId, data);
413 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDelayPasteRecord001 end");
414 }
415
416 /**
417 * @tc.name: GetDelayPasteData001
418 * @tc.desc: test Func GetDelayPasteData
419 * @tc.type: FUNC
420 */
421 HWTEST_F(PasteboardServiceGetDataTest, GetDelayPasteData001, TestSize.Level0)
422 {
423 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDelayPasteData001 start");
424 std::shared_ptr<PasteboardService> tempPasteboard = std::make_shared<PasteboardService>();
425 EXPECT_NE(tempPasteboard, nullptr);
426 int32_t userId = 0x123456;
427 PasteData data;
428 tempPasteboard->GetDelayPasteData(userId, data);
429 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDelayPasteData001 end");
430 }
431
432 /**
433 * @tc.name: GetDistributedDataTest001
434 * @tc.desc: test Func GetDistributedData
435 * @tc.type: FUNC
436 */
437 HWTEST_F(PasteboardServiceGetDataTest, GetDistributedDataTest001, TestSize.Level0)
438 {
439 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDataTest001 start");
440 ClipPlugin::GlobalEvent event {};
441 int32_t user = ACCOUNT_IDS_RANDOM;
442 auto tempPasteboard = std::make_shared<PasteboardService>();
443 EXPECT_NE(tempPasteboard, nullptr);
444 tempPasteboard->GetDistributedData(event, user);
445 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDataTest001 end");
446 }
447
448 /**
449 * @tc.name: GetDistributedDelayDataTest001
450 * @tc.desc: test Func GetDistributedDelayData
451 * @tc.type: FUNC
452 */
453 HWTEST_F(PasteboardServiceGetDataTest, GetDistributedDelayDataTest001, TestSize.Level0)
454 {
455 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDelayDataTest001 start");
456 auto tempPasteboard = std::make_shared<PasteboardService>();
457 EXPECT_NE(tempPasteboard, nullptr);
458
459 TestEvent event;
460 std::vector<uint8_t> rawData;
461 tempPasteboard->GetDistributedDelayData(event, 0, rawData);
462 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDelayDataTest001 end");
463 }
464
465 /**
466 * @tc.name: GetDistributedDelayEntryTest001
467 * @tc.desc: test Func GetDistributedDelayEntry
468 * @tc.type: FUNC
469 */
470 HWTEST_F(PasteboardServiceGetDataTest, GetDistributedDelayEntryTest001, TestSize.Level0)
471 {
472 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDelayEntryTest001 start");
473 ClipPlugin::GlobalEvent evt {};
474 uint32_t recordId = UINT32_ONE;
475 std::string utdId;
476 std::vector<uint8_t> rawData;
477 auto tempPasteboard = std::make_shared<PasteboardService>();
478 EXPECT_NE(tempPasteboard, nullptr);
479 tempPasteboard->GetDistributedDelayEntry(evt, recordId, utdId, rawData);
480 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetDistributedDelayEntryTest001 end");
481 }
482
483 /**
484 * @tc.name: GetLocalEntryValueTest001
485 * @tc.desc: test Func GetLocalEntryValue
486 * @tc.type: FUNC
487 */
488 HWTEST_F(PasteboardServiceGetDataTest, GetLocalEntryValueTest001, TestSize.Level0)
489 {
490 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalEntryValueTest001 start");
491 auto tempPasteboard = std::make_shared<PasteboardService>();
492 EXPECT_NE(tempPasteboard, nullptr);
493
494 int32_t userId = 1;
495 PasteData pasteData;
496 PasteDataRecord record;
497 PasteDataEntry entry;
498 tempPasteboard->GetLocalEntryValue(userId, pasteData, record, entry);
499 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetLocalEntryValueTest001 end");
500 }
501
502 /**
503 * @tc.name: GetFullDelayPasteDataTest001
504 * @tc.desc: test Func GetFullDelayPasteData
505 * @tc.type: FUNC
506 */
507 HWTEST_F(PasteboardServiceGetDataTest, GetFullDelayPasteDataTest001, TestSize.Level0)
508 {
509 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetFullDelayPasteDataTest001 start");
510 int32_t userId = ACCOUNT_IDS_RANDOM;
511 PasteData pasteData;
512 auto tempPasteboard = std::make_shared<PasteboardService>();
513 EXPECT_NE(tempPasteboard, nullptr);
514
515 tempPasteboard->GetFullDelayPasteData(userId, pasteData);
516 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetFullDelayPasteDataTest001 end");
517 }
518
519 /**
520 * @tc.name: GetRecordValueByTypeTest002
521 * @tc.desc: test Func GetRecordValueByType
522 * @tc.type: FUNC
523 * @tc.require:
524 * @tc.author:
525 */
526 HWTEST_F(PasteboardServiceGetDataTest, GetRecordValueByTypeTest002, TestSize.Level0)
527 {
528 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRecordValueByTypeTest002 start");
529 auto tempPasteboard = std::make_shared<PasteboardService>();
530 EXPECT_NE(tempPasteboard, nullptr);
531
532 uint32_t dataId = 1;
533 uint32_t recordId = 1;
534 int64_t rawDataSize = 1024;
535 std::vector<uint8_t> buffer;
536 int fd = 0;
537
538 int32_t result = tempPasteboard->GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
539 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRecordValueByTypeTest002 end");
540 }
541
542 /**
543 * @tc.name: GetAllEntryPlainTextTest001
544 * @tc.desc: test Func GetAllEntryPlainText
545 * @tc.type: FUNC
546 */
547 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest001, TestSize.Level0)
548 {
549 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest001 start");
550 uint32_t dataId = 1;
551 uint32_t recordId = 1;
552 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
553 std::string primaryText = "hello";
554 auto tempPasteboard = std::make_shared<PasteboardService>();
555 EXPECT_NE(tempPasteboard, nullptr);
556
557 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
558 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
559 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest001 end");
560 }
561
562 /**
563 * @tc.name: GetAllEntryPlainTextTest002
564 * @tc.desc: test Func GetAllEntryPlainText
565 * @tc.type: FUNC
566 */
567 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest002, TestSize.Level0)
568 {
569 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest002 start");
570 uint32_t dataId = 1;
571 uint32_t recordId = 0;
572 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
573 tempEntries.emplace_back(std::make_shared<PasteDataEntry>());
574 std::string primaryText = TEST_ENTITY_TEXT;
575 auto tempPasteboard = std::make_shared<PasteboardService>();
576 EXPECT_NE(tempPasteboard, nullptr);
577
578 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
579 EXPECT_NE(pasteData, nullptr);
580
581 pasteData->SetDataId(dataId);
582 pasteData->AddTextRecord("test");
583 auto tokenId = IPCSkeleton::GetCallingTokenID();
584 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
585 tempPasteboard->clips_.InsertOrAssign(appInfo.userId, pasteData);
586 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
587 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::EXCEEDING_LIMIT_EXCEPTION));
588
589 tempPasteboard->clips_.Clear();
590 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest002 end");
591 }
592
593 /**
594 * @tc.name: GetAllEntryPlainTextTest003
595 * @tc.desc: test Func GetAllEntryPlainText
596 * @tc.type: FUNC
597 */
598 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest003, TestSize.Level0)
599 {
600 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest003 start");
601 uint32_t dataId = 1;
602 uint32_t recordId = 0;
603 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
604 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
605 EXPECT_NE(entry, nullptr);
606
607 entry->SetMimeType(MIMETYPE_TEXT_URI);
608 tempEntries.emplace_back(entry);
609 std::string primaryText = "";
610 auto tempPasteboard = std::make_shared<PasteboardService>();
611 EXPECT_NE(tempPasteboard, nullptr);
612
613 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
614 EXPECT_NE(pasteData, nullptr);
615
616 pasteData->SetDataId(dataId);
617 pasteData->AddTextRecord("test");
618 auto tokenId = IPCSkeleton::GetCallingTokenID();
619 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
620 tempPasteboard->clips_.InsertOrAssign(appInfo.userId, pasteData);
621 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
622 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
623
624 tempPasteboard->clips_.Clear();
625 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest003 end");
626 }
627
628 /**
629 * @tc.name: GetAllEntryPlainTextTest004
630 * @tc.desc: test Func GetAllEntryPlainText
631 * @tc.type: FUNC
632 */
633 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest004, TestSize.Level0)
634 {
635 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest004 start");
636 uint32_t dataId = 1;
637 uint32_t recordId = 0;
638 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
639 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
640 EXPECT_NE(entry, nullptr);
641
642 entry->SetMimeType(MIMETYPE_TEXT_PLAIN);
643 tempEntries.emplace_back(entry);
644 std::string primaryText = "";
645 auto tempPasteboard = std::make_shared<PasteboardService>();
646 EXPECT_NE(tempPasteboard, nullptr);
647 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
648 EXPECT_NE(pasteData, nullptr);
649
650 pasteData->SetDataId(dataId);
651 pasteData->AddTextRecord("test");
652 auto tokenId = IPCSkeleton::GetCallingTokenID();
653 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
654 tempPasteboard->clips_.InsertOrAssign(appInfo.userId, pasteData);
655 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
656 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
657
658 tempPasteboard->clips_.Clear();
659 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest004 end");
660 }
661
662 /**
663 * @tc.name: GetAllEntryPlainTextTest005
664 * @tc.desc: test Func GetAllEntryPlainText
665 * @tc.type: FUNC
666 */
667 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest005, TestSize.Level0)
668 {
669 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest005 start");
670 uint32_t dataId = 1;
671 uint32_t recordId = 0;
672 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
673 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
674 EXPECT_NE(entry, nullptr);
675
676 entry->SetMimeType(MIMETYPE_TEXT_PLAIN);
677 entry->SetValue("test");
678 tempEntries.emplace_back(entry);
679 std::string primaryText = "";
680 auto tempPasteboard = std::make_shared<PasteboardService>();
681 EXPECT_NE(tempPasteboard, nullptr);
682
683 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
684 EXPECT_NE(pasteData, nullptr);
685
686 pasteData->SetDataId(dataId);
687 pasteData->AddTextRecord("test");
688 auto tokenId = IPCSkeleton::GetCallingTokenID();
689 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
690 tempPasteboard->clips_.InsertOrAssign(appInfo.userId, pasteData);
691 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
692 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
693
694 tempPasteboard->clips_.Clear();
695 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest005 end");
696 }
697
698 /**
699 * @tc.name: GetAllEntryPlainTextTest006
700 * @tc.desc: test Func GetAllEntryPlainText
701 * @tc.type: FUNC
702 */
703 HWTEST_F(PasteboardServiceGetDataTest, GetAllEntryPlainTextTest006, TestSize.Level0)
704 {
705 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest006 start");
706 uint32_t dataId = 1;
707 uint32_t recordId = 0;
708 std::vector<std::shared_ptr<PasteDataEntry>> tempEntries;
709 std::shared_ptr<PasteDataEntry> entry = std::make_shared<PasteDataEntry>();
710 entry->SetMimeType(MIMETYPE_TEXT_URI);
711 entry->SetValue(1);
712 tempEntries.emplace_back(entry);
713 std::string primaryText = "";
714 auto tempPasteboard = std::make_shared<PasteboardService>();
715 EXPECT_NE(tempPasteboard, nullptr);
716
717 std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
718 EXPECT_NE(pasteData, nullptr);
719
720 pasteData->SetDataId(dataId);
721 pasteData->AddTextRecord("test");
722 auto tokenId = IPCSkeleton::GetCallingTokenID();
723 auto appInfo = tempPasteboard->GetAppInfo(tokenId);
724 tempPasteboard->clips_.InsertOrAssign(appInfo.userId, pasteData);
725 auto ret = tempPasteboard->GetAllEntryPlainText(dataId, recordId, tempEntries, primaryText);
726 EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
727
728 tempPasteboard->clips_.Clear();
729 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllEntryPlainTextTest006 end");
730 }
731
732 /**
733 * @tc.name: GetAllPrimaryTextTest001
734 * @tc.desc: test Func GetAllPrimaryText
735 * @tc.type: FUNC
736 */
737 HWTEST_F(PasteboardServiceGetDataTest, GetAllPrimaryTextTest001, TestSize.Level0)
738 {
739 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllPrimaryTextTest001 start");
740 PasteData pasteData;
741 auto tempPasteboard = std::make_shared<PasteboardService>();
742 EXPECT_NE(tempPasteboard, nullptr);
743 auto ret = tempPasteboard->GetAllPrimaryText(pasteData);
744
745 EXPECT_EQ(ret, "");
746 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllPrimaryTextTest001 end");
747 }
748
749 /**
750 * @tc.name: GetAllPrimaryTextTest002
751 * @tc.desc: test Func GetAllPrimaryText
752 * @tc.type: FUNC
753 */
754 HWTEST_F(PasteboardServiceGetDataTest, GetAllPrimaryTextTest002, TestSize.Level0)
755 {
756 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllPrimaryTextTest002 start");
757 PasteData pasteData;
758 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
759 pasteData.AddTextRecord("testRecord");
760 pasteData.AddTextRecord(TEST_ENTITY_TEXT);
761 pasteData.AddTextRecord("testRecord");
762 pasteData.AddHtmlRecord("<div class='disable'>helloWorld</div>");
763 auto tempPasteboard = std::make_shared<PasteboardService>();
764 EXPECT_NE(tempPasteboard, nullptr);
765
766 auto ret = tempPasteboard->GetAllPrimaryText(pasteData);
767 EXPECT_EQ(ret, "");
768 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetAllPrimaryTextTest002 end");
769 }
770
771 /**
772 * @tc.name: GetRemoteEntryValueTest001
773 * @tc.desc: test Func GetRemoteEntryValue
774 * @tc.type: FUNC
775 */
776 HWTEST_F(PasteboardServiceGetDataTest, GetRemoteEntryValueTest001, TestSize.Level0)
777 {
778 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteEntryValueTest001 start");
779 auto tempPasteboard = std::make_shared<PasteboardService>();
780 EXPECT_NE(tempPasteboard, nullptr);
781
782 AppInfo appInfo;
783 PasteData pasteData;
784 PasteDataRecord record;
785 PasteDataEntry entry;
786 tempPasteboard->GetRemoteEntryValue(appInfo, pasteData, record, entry);
787 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRemoteEntryValueTest001 end");
788 }
789
790 /**
791 * @tc.name: GetRecordValueByTypeTest001
792 * @tc.desc: test Func GetRecordValueByType
793 * @tc.type: FUNC
794 * @tc.require:
795 * @tc.author:
796 */
797 HWTEST_F(PasteboardServiceGetDataTest, GetRecordValueByTypeTest001, TestSize.Level0)
798 {
799 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRecordValueByTypeTest001 start");
800 auto tempPasteboard = std::make_shared<PasteboardService>();
801 EXPECT_NE(tempPasteboard, nullptr);
802
803 uint32_t dataId = 1;
804 uint32_t recordId = 1;
805 int64_t rawDataSize = -1;
806 std::vector<uint8_t> buffer;
807 int fd = 0;
808
809 int32_t result = tempPasteboard->GetRecordValueByType(dataId, recordId, rawDataSize, buffer, fd);
810 EXPECT_EQ(result, static_cast<int32_t>(PasteboardError::INVALID_PARAM_ERROR));
811 PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "GetRecordValueByTypeTest001 end");
812 }
813
814 } // namespace MiscServices
815 } // namespace OHOS