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