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 
18 #include "pasteboard_client.h"
19 #include "pasteboard_error.h"
20 
21 #include "application_defined_record.h"
22 #include "audio.h"
23 #include "folder.h"
24 #include "html.h"
25 #include "image.h"
26 #include "link.h"
27 #include "plain_text.h"
28 #include "system_defined_appitem.h"
29 #include "system_defined_form.h"
30 #include "system_defined_record.h"
31 #include "system_defined_pixelmap.h"
32 #include "text.h"
33 #include "unified_data.h"
34 #include "unified_record.h"
35 #include "video.h"
36 #include "pixel_map.h"
37 #include "want.h"
38 
39 using namespace OHOS::AAFwk;
40 using namespace OHOS::Media;
41 using namespace OHOS::MiscServices;
42 using namespace OHOS::UDMF;
43 using namespace testing::ext;
44 namespace OHOS::Test {
45 class PasteboardClientUdmfDelayTest : public testing::Test {
46 public:
47     static void SetUpTestCase();
48     static void TearDownTestCase();
49     void SetUp() override;
50     void TearDown() override;
51 
52     void SetUnifiedData();
53     void SetTextUnifiedData();
54     void SetPlainTextUnifiedData();
55     void SetLinkUnifiedData();
56     void SetHtmlUnifiedData();
57     void SetFileUnifiedData();
58     void SetImageUnifiedData();
59     void SetVideoUnifiedData();
60     void SetAudioUnifiedData();
61     void SetFolderUnifiedData();
62     void SetSysRecordUnifiedData();
63     void SetSysFormUnifiedData();
64     void SetSysAppItemUnifiedData();
65     void SetAppRecordUnifiedData();
66     void SetWantUnifiedData();
67     void SetPixelMapUnifiedData();
68 
69     void CompareDetails(const UDDetails &details);
70 
71     static PasteData pasteData_;
72     static UnifiedData unifiedData_;
73 };
74 
75 PasteData PasteboardClientUdmfDelayTest::pasteData_;
76 UnifiedData PasteboardClientUdmfDelayTest::unifiedData_;
77 
78 class PasteboardDelayGetterImpl : public MiscServices::PasteboardDelayGetter {
79 public:
GetPasteData(const std::string & type,PasteData & data)80     void GetPasteData(const std::string &type, PasteData &data) override
81     {
82         (void)type;
83         data = PasteboardClientUdmfDelayTest::pasteData_;
84     }
85 
GetUnifiedData(const std::string & type,UnifiedData & data)86     void GetUnifiedData(const std::string &type, UnifiedData &data) override
87     {
88         (void)type;
89         data = PasteboardClientUdmfDelayTest::unifiedData_;
90     }
91 };
92 
SetUpTestCase()93 void PasteboardClientUdmfDelayTest::SetUpTestCase()
94 {
95 }
96 
TearDownTestCase()97 void PasteboardClientUdmfDelayTest::TearDownTestCase()
98 {
99 }
100 
SetUp()101 void PasteboardClientUdmfDelayTest::SetUp()
102 {
103     PasteboardClient::GetInstance()->Clear();
104 }
105 
TearDown()106 void PasteboardClientUdmfDelayTest::TearDown()
107 {
108 }
109 
SetUnifiedData()110 void PasteboardClientUdmfDelayTest::SetUnifiedData()
111 {
112     UnifiedData delayData;
113     std::shared_ptr<PasteboardDelayGetter> delayGetter = std::make_shared<PasteboardDelayGetterImpl>();
114     auto status = PasteboardClient::GetInstance()->SetUnifiedData(delayData, delayGetter);
115     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
116 }
117 
SetTextUnifiedData()118 void PasteboardClientUdmfDelayTest::SetTextUnifiedData()
119 {
120     Text text;
121     UDDetails details;
122     details.insert({ "udmf_key", "udmf_value" });
123     text.SetDetails(details);
124     std::shared_ptr<UnifiedRecord> record = std::make_shared<Text>(text);
125     UnifiedData data;
126     data.AddRecord(record);
127     unifiedData_ = data;
128     SetUnifiedData();
129 }
130 
SetPlainTextUnifiedData()131 void PasteboardClientUdmfDelayTest::SetPlainTextUnifiedData()
132 {
133     PlainText plainText;
134     UDDetails details;
135     details.insert({ "udmf_key", "udmf_value" });
136     plainText.SetDetails(details);
137     plainText.SetContent("content");
138     plainText.SetAbstract("abstract");
139     std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(plainText);
140     UnifiedData data;
141     data.AddRecord(record);
142     unifiedData_ = data;
143     SetUnifiedData();
144 }
145 
SetLinkUnifiedData()146 void PasteboardClientUdmfDelayTest::SetLinkUnifiedData()
147 {
148     Link link;
149     UDDetails details;
150     details.insert({ "udmf_key", "udmf_value" });
151     link.SetDetails(details);
152     link.SetUrl("url");
153     link.SetDescription("description");
154     std::shared_ptr<UnifiedRecord> record = std::make_shared<Link>(link);
155     UnifiedData data;
156     data.AddRecord(record);
157     unifiedData_ = data;
158     SetUnifiedData();
159 }
160 
SetHtmlUnifiedData()161 void PasteboardClientUdmfDelayTest::SetHtmlUnifiedData()
162 {
163     Html html;
164     UDDetails details;
165     details.insert({ "udmf_key", "udmf_value" });
166     html.SetDetails(details);
167     html.SetHtmlContent("htmlContent");
168     html.SetPlainContent("plainContent");
169     std::shared_ptr<UnifiedRecord> record = std::make_shared<Html>(html);
170     UnifiedData data;
171     data.AddRecord(record);
172     unifiedData_ = data;
173     SetUnifiedData();
174 }
175 
SetFileUnifiedData()176 void PasteboardClientUdmfDelayTest::SetFileUnifiedData()
177 {
178     File file;
179     file.SetUri("uri");
180     UDDetails details;
181     details.insert({ "udmf_key", "udmf_value" });
182     file.SetDetails(details);
183     std::shared_ptr<UnifiedRecord> record = std::make_shared<File>(file);
184     UnifiedData data;
185     data.AddRecord(record);
186     unifiedData_ = data;
187     SetUnifiedData();
188 }
189 
SetImageUnifiedData()190 void PasteboardClientUdmfDelayTest::SetImageUnifiedData()
191 {
192     Image image;
193     UDDetails details;
194     details.insert({ "udmf_key", "udmf_value" });
195     image.SetDetails(details);
196     image.SetUri("uri");
197     std::shared_ptr<UnifiedRecord> record = std::make_shared<Image>(image);
198     UnifiedData data;
199     data.AddRecord(record);
200     unifiedData_ = data;
201     SetUnifiedData();
202 }
203 
SetVideoUnifiedData()204 void PasteboardClientUdmfDelayTest::SetVideoUnifiedData()
205 {
206     Video video;
207     UDDetails details;
208     details.insert({ "udmf_key", "udmf_value" });
209     video.SetDetails(details);
210     video.SetUri("uri");
211     std::shared_ptr<UnifiedRecord> record = std::make_shared<Video>(video);
212     UnifiedData data;
213     data.AddRecord(record);
214     unifiedData_ = data;
215     SetUnifiedData();
216 }
217 
SetAudioUnifiedData()218 void PasteboardClientUdmfDelayTest::SetAudioUnifiedData()
219 {
220     Audio audio;
221     UDDetails details;
222     details.insert({ "udmf_key", "udmf_value" });
223     audio.SetDetails(details);
224     audio.SetUri("uri");
225     std::shared_ptr<UnifiedRecord> record = std::make_shared<Audio>(audio);
226     UnifiedData data;
227     data.AddRecord(record);
228     unifiedData_ = data;
229     SetUnifiedData();
230 }
231 
SetFolderUnifiedData()232 void PasteboardClientUdmfDelayTest::SetFolderUnifiedData()
233 {
234     Folder folder;
235     UDDetails details;
236     details.insert({ "udmf_key", "udmf_value" });
237     folder.SetDetails(details);
238     folder.SetUri("uri");
239     std::shared_ptr<UnifiedRecord> record = std::make_shared<Folder>(folder);
240     UnifiedData data;
241     data.AddRecord(record);
242     unifiedData_ = data;
243     SetUnifiedData();
244 }
245 
SetSysRecordUnifiedData()246 void PasteboardClientUdmfDelayTest::SetSysRecordUnifiedData()
247 {
248     SystemDefinedRecord systemDefinedRecord;
249     UDDetails details;
250     details.insert({ "udmf_key", "udmf_value" });
251     systemDefinedRecord.SetDetails(details);
252     std::shared_ptr<UnifiedRecord> record = std::make_shared<SystemDefinedRecord>(systemDefinedRecord);
253     UnifiedData data;
254     data.AddRecord(record);
255     unifiedData_ = data;
256     SetUnifiedData();
257 }
258 
SetSysFormUnifiedData()259 void PasteboardClientUdmfDelayTest::SetSysFormUnifiedData()
260 {
261     SystemDefinedForm systemDefinedForm;
262     UDDetails details;
263     int32_t formId = 1;
264     details.insert({ "udmf_key", "udmf_value" });
265     systemDefinedForm.SetDetails(details);
266     systemDefinedForm.SetFormId(formId);
267     systemDefinedForm.SetFormName("formName");
268     systemDefinedForm.SetModule("module");
269     systemDefinedForm.SetAbilityName("abilityName");
270     systemDefinedForm.SetBundleName("bundleName");
271     std::shared_ptr<UnifiedRecord> record = std::make_shared<SystemDefinedForm>(systemDefinedForm);
272     UnifiedData data;
273     data.AddRecord(record);
274     unifiedData_ = data;
275     SetUnifiedData();
276 }
277 
SetSysAppItemUnifiedData()278 void PasteboardClientUdmfDelayTest::SetSysAppItemUnifiedData()
279 {
280     SystemDefinedAppItem systemDefinedAppItem;
281     UDDetails details;
282     details.insert({ "udmf_key", "udmf_value" });
283     systemDefinedAppItem.SetDetails(details);
284     systemDefinedAppItem.SetAppId("appId");
285     systemDefinedAppItem.SetAppName("appName");
286     systemDefinedAppItem.SetAppIconId("appIconId");
287     systemDefinedAppItem.SetAppLabelId("appLabelId");
288     systemDefinedAppItem.SetBundleName("bundleName");
289     systemDefinedAppItem.SetAbilityName("abilityName");
290     std::shared_ptr<UnifiedRecord> record = std::make_shared<SystemDefinedAppItem>(systemDefinedAppItem);
291     UnifiedData data;
292     data.AddRecord(record);
293     unifiedData_ = data;
294     SetUnifiedData();
295 }
296 
SetAppRecordUnifiedData()297 void PasteboardClientUdmfDelayTest::SetAppRecordUnifiedData()
298 {
299     ApplicationDefinedRecord applicationDefinedRecord;
300     applicationDefinedRecord.SetApplicationDefinedType("applicationDefinedType");
301     std::vector<uint8_t> rawData = { 1, 2, 3, 4, 5 };
302     applicationDefinedRecord.SetRawData(rawData);
303     std::shared_ptr<UnifiedRecord> record = std::make_shared<ApplicationDefinedRecord>(applicationDefinedRecord);
304     UnifiedData data;
305     data.AddRecord(record);
306     unifiedData_ = data;
307     SetUnifiedData();
308 }
309 
SetWantUnifiedData()310 void PasteboardClientUdmfDelayTest::SetWantUnifiedData()
311 {
312     std::shared_ptr<Want> want = std::make_shared<Want>();
313     std::string idKey = "id";
314     int32_t idValue = 456;
315     std::string deviceKey = "deviceId_key";
316     std::string deviceValue = "deviceId_value";
317     want->SetParam(idKey, idValue);
318     want->SetParam(deviceKey, deviceValue);
319     std::shared_ptr<UDMF::UnifiedRecord> record = std::make_shared<UDMF::UnifiedRecord>(UDMF::OPENHARMONY_WANT, want);
320     UnifiedData data;
321     data.AddRecord(record);
322     unifiedData_ = data;
323     SetUnifiedData();
324 }
325 
SetPixelMapUnifiedData()326 void PasteboardClientUdmfDelayTest::SetPixelMapUnifiedData()
327 {
328     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
329     InitializationOptions opts = { { 5, 7 }, PixelFormat::ARGB_8888, PixelFormat::ARGB_8888 };
330     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
331     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
332     std::shared_ptr<UnifiedRecord> record =
333         std::make_shared<SystemDefinedPixelMap>(SYSTEM_DEFINED_PIXEL_MAP, pixelMapIn);
334     UnifiedData data;
335     data.AddRecord(record);
336     unifiedData_ = data;
337     SetUnifiedData();
338 }
339 
CompareDetails(const UDDetails & details)340 void PasteboardClientUdmfDelayTest::CompareDetails(const UDDetails &details)
341 {
342     for (const auto &detail : details) {
343         auto key = detail.first;
344         ASSERT_EQ(key, "udmf_key");
345         auto value = detail.second;
346         auto str = std::get<std::string>(value);
347         ASSERT_EQ(str, "udmf_value");
348     }
349 }
350 
351 /**
352 * @tc.name: SetTextDataTest001
353 * @tc.desc: SetUnifiedData of Text with delay getter and GetUnifiedData and GetPasteData
354 * @tc.type: FUNC
355 */
356 HWTEST_F(PasteboardClientUdmfDelayTest, SetTextDataTest001, TestSize.Level1)
357 {
358     SetTextUnifiedData();
359 
360     UnifiedData unifiedData;
361     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
362     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
363     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
364     ASSERT_NE(unifiedRecord, nullptr);
365     auto type = unifiedRecord->GetType();
366     ASSERT_EQ(type, UDType::TEXT);
367     auto text = static_cast<Text *>(unifiedRecord.get());
368     ASSERT_NE(text, nullptr);
369     CompareDetails(text->GetDetails());
370 
371     PasteData pasteData;
372     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
373     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
374     auto pasteRecord = pasteData.GetRecordAt(0);
375     ASSERT_NE(pasteRecord, nullptr);
376     ASSERT_EQ(pasteRecord->GetMimeType(), "general.text");
377 }
378 
379 /**
380 * @tc.name: SetPlainTextDataTest001
381 * @tc.desc: SetUnifiedData of PlainText with delay getter and GetUnifiedData and GetPasteData
382 * @tc.type: FUNC
383 */
384 HWTEST_F(PasteboardClientUdmfDelayTest, SetPlainTextDataTest001, TestSize.Level1)
385 {
386     SetPlainTextUnifiedData();
387 
388     UnifiedData unifiedData;
389     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
390     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
391     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
392     ASSERT_NE(unifiedRecord, nullptr);
393     auto type = unifiedRecord->GetType();
394     ASSERT_EQ(type, UDType::PLAIN_TEXT);
395     auto text = static_cast<Text *>(unifiedRecord.get());
396     ASSERT_NE(text, nullptr);
397     CompareDetails(text->GetDetails());
398     auto plainText1 = static_cast<PlainText *>(unifiedRecord.get());
399     ASSERT_NE(plainText1, nullptr);
400     EXPECT_EQ(plainText1->GetContent(), "content");
401     EXPECT_EQ(plainText1->GetAbstract(), "abstract");
402 
403     PasteData pasteData;
404     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
405     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
406     auto pasteRecord = pasteData.GetRecordAt(0);
407     ASSERT_NE(pasteRecord, nullptr);
408     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_PLAIN);
409     auto plainText2 = pasteData.GetPrimaryText();
410     ASSERT_NE(plainText2, nullptr);
411     ASSERT_EQ(*plainText2, "content");
412 }
413 
414 /**
415 * @tc.name: SetLinkDataTest001
416 * @tc.desc: SetUnifiedData of Link with delay getter and GetUnifiedData and GetPasteData
417 * @tc.type: FUNC
418 */
419 HWTEST_F(PasteboardClientUdmfDelayTest, SetLinkDataTest001, TestSize.Level1)
420 {
421     SetLinkUnifiedData();
422 
423     UnifiedData unifiedData;
424     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
425     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
426     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
427     ASSERT_NE(unifiedRecord, nullptr);
428     auto type = unifiedRecord->GetType();
429     ASSERT_EQ(type, UDType::HYPERLINK);
430     auto text = static_cast<Text *>(unifiedRecord.get());
431     ASSERT_NE(text, nullptr);
432     CompareDetails(text->GetDetails());
433     auto link = static_cast<Link *>(unifiedRecord.get());
434     ASSERT_NE(link, nullptr);
435     EXPECT_EQ(link->GetUrl(), "url");
436     EXPECT_EQ(link->GetDescription(), "description");
437 
438     PasteData pasteData;
439     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
440     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
441     auto pasteRecord = pasteData.GetRecordAt(0);
442     ASSERT_NE(pasteRecord, nullptr);
443     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_PLAIN);
444     auto plainText = pasteData.GetPrimaryText();
445     ASSERT_NE(plainText, nullptr);
446     ASSERT_EQ(*plainText, "url");
447 }
448 
449 /**
450 * @tc.name: SetHtmlDataTest001
451 * @tc.desc: SetUnifiedData of Html with delay getter and GetUnifiedData and GetPasteData
452 * @tc.type: FUNC
453 */
454 HWTEST_F(PasteboardClientUdmfDelayTest, SetHtmlDataTest001, TestSize.Level1)
455 {
456     SetHtmlUnifiedData();
457 
458     UnifiedData unifiedData;
459     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
460     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
461     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
462     ASSERT_NE(unifiedRecord, nullptr);
463     auto type = unifiedRecord->GetType();
464     ASSERT_EQ(type, UDType::HTML);
465     auto text = static_cast<Text *>(unifiedRecord.get());
466     ASSERT_NE(text, nullptr);
467     CompareDetails(text->GetDetails());
468     auto html = static_cast<Html *>(unifiedRecord.get());
469     ASSERT_NE(html, nullptr);
470     EXPECT_EQ(html->GetHtmlContent(), "htmlContent");
471     EXPECT_EQ(html->GetPlainContent(), "plainContent");
472 
473     PasteData pasteData;
474     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
475     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
476     auto pasteRecord = pasteData.GetRecordAt(0);
477     ASSERT_NE(pasteRecord, nullptr);
478     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_HTML);
479     auto htmlText = pasteRecord->GetHtmlText();
480     ASSERT_NE(htmlText, nullptr);
481     ASSERT_EQ(*htmlText, "htmlContent");
482 }
483 
484 /**
485 * @tc.name: SetFileDataTest001
486 * @tc.desc: SetUnifiedData of File with delay getter and GetUnifiedData and GetPasteData
487 * @tc.type: FUNC
488 */
489 HWTEST_F(PasteboardClientUdmfDelayTest, SetFileDataTest001, TestSize.Level1)
490 {
491     SetFileUnifiedData();
492 
493     UnifiedData unifiedData;
494     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
495     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
496     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
497     ASSERT_NE(unifiedRecord, nullptr);
498     auto type = unifiedRecord->GetType();
499     ASSERT_EQ(type, UDType::FILE);
500     auto file = static_cast<File *>(unifiedRecord.get());
501     ASSERT_NE(file, nullptr);
502     EXPECT_EQ(file->GetUri(), "uri");
503     CompareDetails(file->GetDetails());
504 
505     PasteData pasteData;
506     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
507     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
508     auto pasteRecord = pasteData.GetRecordAt(0);
509     ASSERT_NE(pasteRecord, nullptr);
510     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_URI);
511     auto uri = pasteRecord->GetUri();
512     ASSERT_NE(uri, nullptr);
513     ASSERT_EQ(uri->ToString(), "uri");
514 }
515 
516 /**
517 * @tc.name: SetImageDataTest001
518 * @tc.desc: SetUnifiedData of Image with delay getter and GetUnifiedData and GetPasteData
519 * @tc.type: FUNC
520 */
521 HWTEST_F(PasteboardClientUdmfDelayTest, SetImageDataTest001, TestSize.Level1)
522 {
523     SetImageUnifiedData();
524 
525     UnifiedData unifiedData;
526     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
527     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
528     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
529     ASSERT_NE(unifiedRecord, nullptr);
530     auto type = unifiedRecord->GetType();
531     ASSERT_EQ(type, UDType::IMAGE);
532     auto file = static_cast<File *>(unifiedRecord.get());
533     ASSERT_NE(file, nullptr);
534     CompareDetails(file->GetDetails());
535     auto image = static_cast<Image *>(unifiedRecord.get());
536     ASSERT_NE(image, nullptr);
537     EXPECT_EQ(image->GetUri(), "uri");
538 
539     PasteData pasteData;
540     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
541     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
542     auto pasteRecord = pasteData.GetRecordAt(0);
543     ASSERT_NE(pasteRecord, nullptr);
544     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_URI);
545     auto uri = pasteRecord->GetUri();
546     ASSERT_NE(uri, nullptr);
547     ASSERT_EQ(uri->ToString(), "uri");
548 }
549 
550 /**
551 * @tc.name: SetVideoDataTest001
552 * @tc.desc: SetUnifiedData of Video with delay getter and GetUnifiedData and GetPasteData
553 * @tc.type: FUNC
554 */
555 HWTEST_F(PasteboardClientUdmfDelayTest, SetVideoDataTest001, TestSize.Level1)
556 {
557     SetVideoUnifiedData();
558 
559     UnifiedData unifiedData;
560     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
561     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
562     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
563     ASSERT_NE(unifiedRecord, nullptr);
564     auto type = unifiedRecord->GetType();
565     ASSERT_EQ(type, UDType::VIDEO);
566     auto file = static_cast<File *>(unifiedRecord.get());
567     ASSERT_NE(file, nullptr);
568     CompareDetails(file->GetDetails());
569     auto video = static_cast<Video *>(unifiedRecord.get());
570     ASSERT_NE(video, nullptr);
571     EXPECT_EQ(video->GetUri(), "uri");
572 
573     PasteData pasteData;
574     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
575     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
576     auto pasteRecord = pasteData.GetRecordAt(0);
577     ASSERT_NE(pasteRecord, nullptr);
578     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_URI);
579     auto uri = pasteRecord->GetUri();
580     ASSERT_NE(uri, nullptr);
581     ASSERT_EQ(uri->ToString(), "uri");
582 }
583 
584 /**
585 * @tc.name: SetAudioDataTest001
586 * @tc.desc: SetUnifiedData of Audio with delay getter and GetUnifiedData and GetPasteData
587 * @tc.type: FUNC
588 */
589 HWTEST_F(PasteboardClientUdmfDelayTest, SetAudioDataTest001, TestSize.Level1)
590 {
591     SetAudioUnifiedData();
592 
593     UnifiedData unifiedData;
594     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
595     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
596     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
597     ASSERT_NE(unifiedRecord, nullptr);
598     auto type = unifiedRecord->GetType();
599     ASSERT_EQ(type, UDType::AUDIO);
600     auto file = static_cast<File *>(unifiedRecord.get());
601     ASSERT_NE(file, nullptr);
602     CompareDetails(file->GetDetails());
603     auto audio = static_cast<Audio *>(unifiedRecord.get());
604     ASSERT_NE(audio, nullptr);
605     EXPECT_EQ(audio->GetUri(), "uri");
606 
607     PasteData pasteData;
608     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
609     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
610     auto pasteRecord = pasteData.GetRecordAt(0);
611     ASSERT_NE(pasteRecord, nullptr);
612     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_URI);
613     auto uri = pasteRecord->GetUri();
614     ASSERT_NE(uri, nullptr);
615     ASSERT_EQ(uri->ToString(), "uri");
616 }
617 
618 /**
619 * @tc.name: SetFolderDataTest001
620 * @tc.desc: Set UnifiedData of Folder with delay getter and GetUnifiedData and GetPasteData
621 * @tc.type: FUNC
622 */
623 HWTEST_F(PasteboardClientUdmfDelayTest, SetFolderDataTest001, TestSize.Level1)
624 {
625     SetFolderUnifiedData();
626 
627     UnifiedData unifiedData;
628     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
629     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
630     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
631     ASSERT_NE(unifiedRecord, nullptr);
632     auto type = unifiedRecord->GetType();
633     ASSERT_EQ(type, UDType::FOLDER);
634     auto file = static_cast<File *>(unifiedRecord.get());
635     ASSERT_NE(file, nullptr);
636     CompareDetails(file->GetDetails());
637     auto folder = static_cast<Folder *>(unifiedRecord.get());
638     ASSERT_NE(folder, nullptr);
639     EXPECT_EQ(folder->GetUri(), "uri");
640 
641     PasteData pasteData;
642     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
643     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
644     auto pasteRecord = pasteData.GetRecordAt(0);
645     ASSERT_NE(pasteRecord, nullptr);
646     ASSERT_EQ(pasteRecord->GetMimeType(), MIMETYPE_TEXT_URI);
647     auto uri = pasteRecord->GetUri();
648     ASSERT_NE(uri, nullptr);
649     ASSERT_EQ(uri->ToString(), "uri");
650 }
651 
652 /**
653 * @tc.name: SetSysRecordDataTest001
654 * @tc.desc: SetUnifiedData of SysRecord with delay getter and GetUnifiedData and GetPasteData
655 * @tc.type: FUNC
656 */
657 HWTEST_F(PasteboardClientUdmfDelayTest, SetSysRecordDataTest001, TestSize.Level1)
658 {
659     SetSysRecordUnifiedData();
660 
661     UnifiedData unifiedData;
662     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
663     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
664     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
665     ASSERT_NE(unifiedRecord, nullptr);
666     auto type = unifiedRecord->GetType();
667     ASSERT_EQ(type, UDType::SYSTEM_DEFINED_RECORD);
668     auto systemDefinedRecord = static_cast<SystemDefinedRecord *>(unifiedRecord.get());
669     ASSERT_NE(systemDefinedRecord, nullptr);
670     CompareDetails(systemDefinedRecord->GetDetails());
671 
672     PasteData pasteData;
673     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
674     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
675     auto pasteRecord = pasteData.GetRecordAt(0);
676     ASSERT_NE(pasteRecord, nullptr);
677     auto customData = pasteRecord->GetCustomData();
678     ASSERT_NE(customData, nullptr);
679     auto itemData = customData->GetItemData();
680     ASSERT_EQ(itemData.size(), 1);
681     auto item = itemData.find("SystemDefinedType");
682     ASSERT_NE(item, itemData.end());
683 }
684 
685 /**
686 * @tc.name: SetSysFormDataTest001
687 * @tc.desc: SetUnifiedData of SysForm with delay getter and GetUnifiedData and GetPasteData
688 * @tc.type: FUNC
689 */
690 HWTEST_F(PasteboardClientUdmfDelayTest, SetSysFormDataTest001, TestSize.Level1)
691 {
692     SetSysFormUnifiedData();
693 
694     UnifiedData unifiedData;
695     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
696     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
697     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
698     ASSERT_NE(unifiedRecord, nullptr);
699     auto type = unifiedRecord->GetType();
700     ASSERT_EQ(type, UDType::SYSTEM_DEFINED_FORM);
701     auto systemDefinedRecord = static_cast<SystemDefinedRecord *>(unifiedRecord.get());
702     ASSERT_NE(systemDefinedRecord, nullptr);
703     CompareDetails(systemDefinedRecord->GetDetails());
704     auto systemDefinedForm = static_cast<SystemDefinedForm *>(unifiedRecord.get());
705     ASSERT_NE(systemDefinedForm, nullptr);
706     ASSERT_EQ(systemDefinedForm->GetFormId(), 1);
707     ASSERT_EQ(systemDefinedForm->GetFormName(), "formName");
708     ASSERT_EQ(systemDefinedForm->GetBundleName(), "bundleName");
709     ASSERT_EQ(systemDefinedForm->GetAbilityName(), "abilityName");
710     ASSERT_EQ(systemDefinedForm->GetModule(), "module");
711 
712     PasteData pasteData;
713     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
714     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
715     auto pasteRecord = pasteData.GetRecordAt(0);
716     ASSERT_NE(pasteRecord, nullptr);
717     auto customData = pasteRecord->GetCustomData();
718     ASSERT_NE(customData, nullptr);
719     auto itemData = customData->GetItemData();
720     ASSERT_EQ(itemData.size(), 1);
721     auto item = itemData.find("openharmony.form");
722     ASSERT_NE(item, itemData.end());
723 }
724 
725 /**
726 * @tc.name: SetSysAppItemDataTest001
727 * @tc.desc: SetUnifiedData of SysAppItem with delay getter and GetUnifiedData and GetPasteData
728 * @tc.type: FUNC
729 */
730 HWTEST_F(PasteboardClientUdmfDelayTest, SetSysAppItemDataTest001, TestSize.Level1)
731 {
732     SetSysAppItemUnifiedData();
733 
734     UnifiedData unifiedData;
735     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
736     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
737     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
738     ASSERT_NE(unifiedRecord, nullptr);
739     auto type = unifiedRecord->GetType();
740     ASSERT_EQ(type, UDType::SYSTEM_DEFINED_APP_ITEM);
741     auto systemDefinedRecord = static_cast<SystemDefinedRecord *>(unifiedRecord.get());
742     ASSERT_NE(systemDefinedRecord, nullptr);
743     CompareDetails(systemDefinedRecord->GetDetails());
744     auto systemDefinedAppItem = static_cast<SystemDefinedAppItem *>(unifiedRecord.get());
745     ASSERT_NE(systemDefinedAppItem, nullptr);
746     ASSERT_EQ(systemDefinedAppItem->GetAppId(), "appId");
747     ASSERT_EQ(systemDefinedAppItem->GetAppName(), "appName");
748     ASSERT_EQ(systemDefinedAppItem->GetBundleName(), "bundleName");
749     ASSERT_EQ(systemDefinedAppItem->GetAbilityName(), "abilityName");
750     ASSERT_EQ(systemDefinedAppItem->GetAppIconId(), "appIconId");
751     ASSERT_EQ(systemDefinedAppItem->GetAppLabelId(), "appLabelId");
752 
753     PasteData pasteData;
754     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
755     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
756     auto pasteRecord = pasteData.GetRecordAt(0);
757     ASSERT_NE(pasteRecord, nullptr);
758     auto details1 = pasteRecord->GetDetails();
759     auto udmfValue = pasteRecord->GetUDMFValue();
760     ASSERT_NE(udmfValue, nullptr);
761     auto newAppItem1 = std::make_shared<UDMF::SystemDefinedAppItem>(UDMF::SYSTEM_DEFINED_APP_ITEM, *udmfValue);
762     ASSERT_EQ(newAppItem1->GetAppId(), "appId");
763     ASSERT_EQ(newAppItem1->GetAppIconId(), "appIconId");
764     ASSERT_EQ(newAppItem1->GetAppName(), "appName");
765     ASSERT_EQ(newAppItem1->GetAppLabelId(), "appLabelId");
766     ASSERT_EQ(newAppItem1->GetBundleName(), "bundleName");
767     ASSERT_EQ(newAppItem1->GetAbilityName(), "abilityName");
768 }
769 
770 /**
771 * @tc.name: SetAppRecordDataTest001
772 * @tc.desc: Set UnifiedData of AppRecord with delay getter and GetUnifiedData and GetPasteData
773 * @tc.type: FUNC
774 */
775 HWTEST_F(PasteboardClientUdmfDelayTest, SetAppRecordDataTest001, TestSize.Level1)
776 {
777     SetAppRecordUnifiedData();
778 
779     UnifiedData unifiedData;
780     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
781     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
782     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
783     ASSERT_NE(unifiedRecord, nullptr);
784     auto type = unifiedRecord->GetType();
785     ASSERT_EQ(type, UDType::APPLICATION_DEFINED_RECORD);
786     auto applicationDefinedRecord = static_cast<ApplicationDefinedRecord *>(unifiedRecord.get());
787     ASSERT_NE(applicationDefinedRecord, nullptr);
788     ASSERT_EQ(applicationDefinedRecord->GetApplicationDefinedType(), "applicationDefinedType");
789     auto outputRawData = applicationDefinedRecord->GetRawData();
790     std::vector<uint8_t> inputRawData = { 1, 2, 3, 4, 5 };
791     ASSERT_EQ(outputRawData.size(), inputRawData.size());
792     for (uint32_t i = 0; i < outputRawData.size(); ++i) {
793         ASSERT_EQ(outputRawData[i], inputRawData[i]);
794     }
795 
796     PasteData pasteData;
797     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
798     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
799     auto pasteRecord = pasteData.GetRecordAt(0);
800     ASSERT_NE(pasteRecord, nullptr);
801     auto customData = pasteRecord->GetCustomData();
802     ASSERT_NE(customData, nullptr);
803     auto itemData = customData->GetItemData();
804     ASSERT_EQ(itemData.size(), 1);
805     auto item = itemData.find("applicationDefinedType");
806     ASSERT_NE(item, itemData.end());
807 }
808 
809 /**
810 * @tc.name: SetWantDataTest001
811 * @tc.desc: Set UnifiedData of Want with delay getter and GetUnifiedData and GetPasteData
812 * @tc.type: FUNC
813 */
814 HWTEST_F(PasteboardClientUdmfDelayTest, SetWantDataTest001, TestSize.Level1)
815 {
816     SetWantUnifiedData();
817 
818     UnifiedData unifiedData;
819     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
820     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
821     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
822     ASSERT_NE(unifiedRecord, nullptr);
823     auto type = unifiedRecord->GetType();
824     ASSERT_EQ(type, UDType::OPENHARMONY_WANT);
825     auto value = unifiedRecord->GetValue();
826     auto want = std::get_if<std::shared_ptr<Want>>(&value);
827     ASSERT_NE(want, nullptr);
828     auto idValue1 = (*(want))->GetIntParam("id", 0);
829     ASSERT_EQ(idValue1, 456);
830     auto deviceValue1 = (*(want))->GetStringParam("deviceId_key");
831     ASSERT_EQ(deviceValue1, "deviceId_value");
832 
833 
834     PasteData pasteData;
835     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
836     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
837     auto pasteRecord = pasteData.GetPrimaryWant();
838     ASSERT_NE(pasteRecord, nullptr);
839     auto idValue2 = pasteRecord->GetIntParam("id", 0);
840     ASSERT_EQ(idValue2, 456);
841     auto deviceValue2 = pasteRecord->GetStringParam("deviceId_key");
842     ASSERT_EQ(deviceValue2, "deviceId_value");
843 }
844 
845 /**
846 * @tc.name: SetPixelMapDataTest001
847 * @tc.desc: Set UnifiedData of PixelMap with delay getter and GetUnifiedData and GetPasteData
848 * @tc.type: FUNC
849 */
850 HWTEST_F(PasteboardClientUdmfDelayTest, SetPixelMapDataTest001, TestSize.Level1)
851 {
852     SetPixelMapUnifiedData();
853 
854     UnifiedData unifiedData;
855     auto status = PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
856     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
857     std::shared_ptr<UnifiedRecord> unifiedRecord = unifiedData.GetRecordAt(0);
858     ASSERT_NE(unifiedRecord, nullptr);
859     auto type = unifiedRecord->GetType();
860     ASSERT_EQ(type, UDType::SYSTEM_DEFINED_PIXEL_MAP);
861     auto value = unifiedRecord->GetValue();
862     auto pixelMap = std::get_if<std::shared_ptr<PixelMap>>(&value);
863     ASSERT_NE(pixelMap, nullptr);
864     ImageInfo imageInfo1 = {};
865     (*pixelMap)->GetImageInfo(imageInfo1);
866     ASSERT_EQ(imageInfo1.size.height, 7);
867     ASSERT_EQ(imageInfo1.size.width, 5);
868     ASSERT_EQ(imageInfo1.pixelFormat, PixelFormat::ARGB_8888);
869 
870     PasteData pasteData;
871     status = PasteboardClient::GetInstance()->GetPasteData(pasteData);
872     ASSERT_EQ(status, static_cast<int32_t>(PasteboardError::E_OK));
873     auto pasteRecord = pasteData.GetPrimaryPixelMap();
874     ASSERT_NE(pasteRecord, nullptr);
875     ImageInfo imageInfo2 = {};
876     pasteRecord->GetImageInfo(imageInfo2);
877     ASSERT_EQ(imageInfo2.size.height, 7);
878     ASSERT_EQ(imageInfo2.size.width, 5);
879     ASSERT_EQ(imageInfo2.pixelFormat, PixelFormat::ARGB_8888);
880 }
881 } // OHOS::Test