• 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 "plain_text.h"
26 #include "system_defined_appitem.h"
27 #include "system_defined_form.h"
28 #include "system_defined_pixelmap.h"
29 #include "video.h"
30 namespace OHOS::MiscServices {
31 using namespace testing::ext;
32 using namespace testing;
33 using namespace OHOS::Media;
34 class PasteboardUnifiedDataTest : public testing::Test {
35 public:
36     static void SetUpTestCase(void);
37     static void TearDownTestCase(void);
38     void SetUp();
39     void TearDown();
40     UDMF::UnifiedData InitTextData();
41     UDMF::UnifiedData InitPlainData();
42     UDMF::UnifiedData InitHtmlData();
43     UDMF::UnifiedData InitWantData();
44     UDMF::UnifiedData InitLinkData();
45     UDMF::UnifiedData InitFileData();
46     UDMF::UnifiedData InitImageData();
47     UDMF::UnifiedData InitVideoData();
48     UDMF::UnifiedData InitAudioData();
49     UDMF::UnifiedData InitFolderData();
50     UDMF::UnifiedData InitSystemRecordData();
51     UDMF::UnifiedData InitSystemAppItemData();
52     UDMF::UnifiedData InitSystemFormData();
53     UDMF::UnifiedData InitSystemPixelMapData();
54     UDMF::UnifiedData InitAppDefinedData();
55 
56 protected:
57     Details details_;
58     std::vector<uint8_t> rawData_;
59     std::string text_;
60     std::string extraText_;
61     std::string uri_;
62 };
63 
SetUpTestCase(void)64 void PasteboardUnifiedDataTest::SetUpTestCase(void) { }
65 
TearDownTestCase(void)66 void PasteboardUnifiedDataTest::TearDownTestCase(void) { }
67 
SetUp(void)68 void PasteboardUnifiedDataTest::SetUp(void)
69 {
70     rawData_ = { 1, 2, 3, 4, 5, 6, 7, 8 };
71     details_.insert({ "keyString", "string_test" });
72     details_.insert({ "keyInt32", 1 });
73     details_.insert({ "keyBool", true });
74     details_.insert({ "KeyU8Array", rawData_ });
75     details_.insert({ "KeyDouble", 1.234 });
76 }
77 
TearDown(void)78 void PasteboardUnifiedDataTest::TearDown(void) { }
79 
InitTextData()80 UDMF::UnifiedData PasteboardUnifiedDataTest::InitTextData()
81 {
82     UDMF::UnifiedData data;
83     std::shared_ptr<UDMF::Text> textRecord = std::make_shared<UDMF::Text>();
84     textRecord->SetDetails(details_);
85     data.AddRecord(textRecord);
86     return data;
87 }
88 
InitPlainData()89 UDMF::UnifiedData PasteboardUnifiedDataTest::InitPlainData()
90 {
91     text_ = "helloWorld_plainText";
92     extraText_ = "helloWorld_plainAbstract";
93     UDMF::UnifiedData data;
94     std::shared_ptr<UDMF::PlainText> plainTextRecord = std::make_shared<UDMF::PlainText>(text_, extraText_);
95     plainTextRecord->SetDetails(details_);
96     data.AddRecord(plainTextRecord);
97     return data;
98 }
99 
InitHtmlData()100 UDMF::UnifiedData PasteboardUnifiedDataTest::InitHtmlData()
101 {
102     text_ = "<div class='disable'>helloWorld</div>";
103     extraText_ = "helloWorld_plainAbstract";
104     UDMF::UnifiedData data;
105     std::shared_ptr<UDMF::Html> htmlRecord = std::make_shared<UDMF::Html>(text_, extraText_);
106     htmlRecord->SetDetails(details_);
107     data.AddRecord(htmlRecord);
108     return data;
109 }
InitWantData()110 UDMF::UnifiedData PasteboardUnifiedDataTest::InitWantData()
111 {
112     using namespace OHOS::AAFwk;
113     std::shared_ptr<Want> want = std::make_shared<Want>();
114     std::string idKey = "id";
115     int32_t idValue = 123;
116     std::string deviceKey = "deviceId_key";
117     want->SetParam(idKey, idValue);
118     std::shared_ptr<UDMF::UnifiedRecord> wantRecord =
119         std::make_shared<UDMF::UnifiedRecord>(UDMF::OPENHARMONY_WANT, want);
120     UDMF::UnifiedData data;
121     data.AddRecord(wantRecord);
122     return data;
123 }
124 
InitLinkData()125 UDMF::UnifiedData PasteboardUnifiedDataTest::InitLinkData()
126 {
127     text_ = "https://www.test.com";
128     extraText_ = "https://www.test.com/content";
129     UDMF::UnifiedData data;
130     std::shared_ptr<UDMF::Link> linkRecord = std::make_shared<UDMF::Link>(text_, extraText_);
131     linkRecord->SetDetails(details_);
132     data.AddRecord(linkRecord);
133     return data;
134 }
InitFileData()135 UDMF::UnifiedData PasteboardUnifiedDataTest::InitFileData()
136 {
137     UDMF::UnifiedData data;
138     auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FILE);
139     uri_ = "file://uri";
140     std::shared_ptr<UDMF::File> fileRecord = std::make_shared<UDMF::File>(uri_);
141     fileRecord->SetDetails(details_);
142     data.AddRecord(fileRecord);
143     return data;
144 }
InitImageData()145 UDMF::UnifiedData PasteboardUnifiedDataTest::InitImageData()
146 {
147     UDMF::UnifiedData data;
148     auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::IMAGE);
149     uri_ = "file://image";
150     std::shared_ptr<UDMF::Image> imageRecord = std::make_shared<UDMF::Image>(uri_);
151     imageRecord->SetDetails(details_);
152     data.AddRecord(imageRecord);
153     return data;
154 }
InitVideoData()155 UDMF::UnifiedData PasteboardUnifiedDataTest::InitVideoData()
156 {
157     UDMF::UnifiedData data;
158     auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::VIDEO);
159     uri_ = "file://Video";
160     std::shared_ptr<UDMF::Video> videoRecord = std::make_shared<UDMF::Video>(uri_);
161     videoRecord->SetDetails(details_);
162     data.AddRecord(videoRecord);
163 
164     return data;
165 }
InitAudioData()166 UDMF::UnifiedData PasteboardUnifiedDataTest::InitAudioData()
167 {
168     UDMF::UnifiedData data;
169     auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::AUDIO);
170     uri_ = "file://Audio";
171     std::shared_ptr<UDMF::Audio> audioRecord = std::make_shared<UDMF::Audio>(uri_);
172     audioRecord->SetDetails(details_);
173     data.AddRecord(audioRecord);
174     return data;
175 }
InitFolderData()176 UDMF::UnifiedData PasteboardUnifiedDataTest::InitFolderData()
177 {
178     UDMF::UnifiedData data;
179     auto typeStr = UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::FOLDER);
180     uri_ = "file://Folder";
181     std::shared_ptr<UDMF::Folder> folderRecord = std::make_shared<UDMF::Folder>(uri_);
182     folderRecord->SetDetails(details_);
183     data.AddRecord(folderRecord);
184     return data;
185 }
InitSystemRecordData()186 UDMF::UnifiedData PasteboardUnifiedDataTest::InitSystemRecordData()
187 {
188     UDMF::UnifiedData data;
189     std::shared_ptr<UDMF::SystemDefinedRecord> systemRecord = std::make_shared<UDMF::SystemDefinedRecord>();
190     systemRecord->SetDetails(details_);
191     data.AddRecord(systemRecord);
192     return data;
193 }
InitSystemAppItemData()194 UDMF::UnifiedData PasteboardUnifiedDataTest::InitSystemAppItemData()
195 {
196     UDMF::UnifiedData data;
197     std::shared_ptr<UDMF::SystemDefinedAppItem> systemDefinedAppItem1 = std::make_shared<UDMF::SystemDefinedAppItem>();
198     std::string appId = "appId";
199     std::string appIconId = "appIconId";
200     std::string appName = "appName";
201     std::string appLabelId = "appLabelId";
202     std::string bundleName = "bundleName";
203     std::string abilityName = "abilityName";
204     systemDefinedAppItem1->SetDetails(details_);
205     systemDefinedAppItem1->SetAppId(appId);
206     systemDefinedAppItem1->SetAppName(appName);
207     systemDefinedAppItem1->SetAppIconId(appIconId);
208     systemDefinedAppItem1->SetAppLabelId(appLabelId);
209     systemDefinedAppItem1->SetBundleName(bundleName);
210     systemDefinedAppItem1->SetAbilityName(abilityName);
211     systemDefinedAppItem1->SetType(UDMF::SYSTEM_DEFINED_APP_ITEM);
212     data.AddRecord(systemDefinedAppItem1);
213     return data;
214 }
InitSystemFormData()215 UDMF::UnifiedData PasteboardUnifiedDataTest::InitSystemFormData()
216 {
217     UDMF::UnifiedData data;
218     std::shared_ptr<UDMF::SystemDefinedForm> form = std::make_shared<UDMF::SystemDefinedForm>();
219     int32_t formId = 1;
220     std::string formName = "formName";
221     std::string module = "module";
222     std::string bundleName = "bundleName";
223     std::string abilityName = "abilityName";
224     form->SetDetails(details_);
225     form->SetFormId(formId);
226     form->SetFormName(formName);
227     form->SetAbilityName(abilityName);
228     form->SetBundleName(bundleName);
229     form->SetModule(module);
230     form->SetType(UDMF::SYSTEM_DEFINED_FORM);
231     data.AddRecord(form);
232     return data;
233 }
InitSystemPixelMapData()234 UDMF::UnifiedData PasteboardUnifiedDataTest::InitSystemPixelMapData()
235 {
236     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
237     InitializationOptions opts = {
238         {5, 7},
239         PixelFormat::ARGB_8888, PixelFormat::ARGB_8888
240     };
241     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
242     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
243     std::shared_ptr<UDMF::UnifiedRecord> pixelMapRecord =
244         std::make_shared<UDMF::SystemDefinedPixelMap>(UDMF::SYSTEM_DEFINED_PIXEL_MAP, pixelMapIn);
245     UDMF::UnifiedData data;
246     data.AddRecord(pixelMapRecord);
247     return data;
248 }
249 
InitAppDefinedData()250 UDMF::UnifiedData PasteboardUnifiedDataTest::InitAppDefinedData()
251 {
252     UDMF::UnifiedData data;
253     std::shared_ptr<UDMF::ApplicationDefinedRecord> appRecord = std::make_shared<UDMF::ApplicationDefinedRecord>();
254     std::map<std::string, std::vector<uint8_t>> customData;
255     customData[UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD)] = rawData_;
256     appRecord->SetApplicationDefinedType(UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD));
257     appRecord->SetRawData(rawData_);
258     data.AddRecord(appRecord);
259     return data;
260 }
261 
262 /**
263  * @tc.name: SetText001
264  * @tc.desc: Get the source of the data.
265  * @tc.type: FUNC
266  * @tc.require:
267  * @tc.author:
268  */
269 HWTEST_F(PasteboardUnifiedDataTest, SetText001, TestSize.Level0)
270 {
271     auto data = InitTextData();
272     PasteboardClient::GetInstance()->SetUnifiedData(data);
273     UDMF::UnifiedData newData;
274     PasteboardClient::GetInstance()->GetUnifiedData(newData);
275     ASSERT_EQ(1, newData.GetRecords().size());
276     auto newRecord = newData.GetRecordAt(0);
277     auto newType = newRecord->GetType();
278     ASSERT_EQ(newType, UDMF::TEXT);
279     auto newPlainRecord = static_cast<UDMF::Text *>(newRecord.get());
280     auto newDetails = newPlainRecord->GetDetails();
281     ASSERT_EQ(newDetails, details_);
282 
283     PasteData pasteData;
284     PasteboardClient::GetInstance()->GetPasteData(pasteData);
285     ASSERT_EQ(1, pasteData.GetRecordCount());
286     auto record = pasteData.GetRecordAt(0);
287     auto type = record->GetMimeType();
288     ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::TEXT));
289     auto udType = record->GetUDType();
290     ASSERT_EQ(udType, UDMF::UDType::TEXT);
291     auto details1 = record->GetDetails();
292     ASSERT_EQ(*details1, details_);
293 }
294 
295 /**
296  * @tc.name: SetPlainText001
297  * @tc.desc: Get the source of the data.
298  * @tc.type: FUNC
299  * @tc.require:
300  * @tc.author:
301  */
302 HWTEST_F(PasteboardUnifiedDataTest, SetPlainText001, TestSize.Level0)
303 {
304     auto data = InitPlainData();
305     PasteboardClient::GetInstance()->SetUnifiedData(data);
306     UDMF::UnifiedData newData;
307     PasteboardClient::GetInstance()->GetUnifiedData(newData);
308     ASSERT_EQ(1, newData.GetRecords().size());
309     auto newRecord = newData.GetRecordAt(0);
310     auto newType = newRecord->GetType();
311     ASSERT_EQ(newType, UDMF::PLAIN_TEXT);
312     auto newPlainRecord = static_cast<UDMF::PlainText *>(newRecord.get());
313     auto newPlainText = newPlainRecord->GetContent();
314     auto newAbstract = newPlainRecord->GetAbstract();
315     auto newDetails = newPlainRecord->GetDetails();
316     ASSERT_EQ(newPlainText, text_);
317     ASSERT_EQ(newAbstract, extraText_);
318     ASSERT_EQ(newDetails, details_);
319 
320     PasteData pasteData;
321     PasteboardClient::GetInstance()->GetPasteData(pasteData);
322     ASSERT_EQ(1, pasteData.GetRecordCount());
323     auto record = pasteData.GetRecordAt(0);
324     auto type = record->GetMimeType();
325     ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN);
326     auto udType = record->GetUDType();
327     ASSERT_EQ(udType, UDMF::UDType::PLAIN_TEXT);
328     auto entries = record->GetEntries();
329     ASSERT_NE(entries.size(), 0);
330     auto entryValue = entries.front()->GetValue();
331     auto plainText = std::make_shared<UDMF::PlainText>(UDMF::PLAIN_TEXT, entryValue);
332     ASSERT_EQ(plainText->GetContent(), text_);
333     ASSERT_EQ(plainText->GetAbstract(), extraText_);
334 }
335 
336 /**
337  * @tc.name: SetLink001
338  * @tc.desc: Get the source of the data.
339  * @tc.type: FUNC
340  * @tc.require:
341  * @tc.author:
342  */
343 HWTEST_F(PasteboardUnifiedDataTest, SetLink001, TestSize.Level0)
344 {
345     auto data = InitLinkData();
346     PasteboardClient::GetInstance()->SetUnifiedData(data);
347     UDMF::UnifiedData newData;
348     PasteboardClient::GetInstance()->GetUnifiedData(newData);
349     ASSERT_EQ(1, newData.GetRecords().size());
350     auto newRecord = newData.GetRecordAt(0);
351     auto newType = newRecord->GetType();
352     ASSERT_EQ(newType, UDMF::HYPERLINK);
353     auto newPlainRecord = static_cast<UDMF::Link *>(newRecord.get());
354     auto newUrl = newPlainRecord->GetUrl();
355     auto newDescription = newPlainRecord->GetDescription();
356     auto newDetails = newPlainRecord->GetDetails();
357     ASSERT_EQ(newUrl, text_);
358     ASSERT_EQ(newDescription, extraText_);
359     ASSERT_EQ(newDetails, details_);
360 
361     PasteData pasteData;
362     PasteboardClient::GetInstance()->GetPasteData(pasteData);
363     ASSERT_EQ(1, pasteData.GetRecordCount());
364     auto record = pasteData.GetRecordAt(0);
365     auto type = record->GetMimeType();
366     ASSERT_EQ(type, MIMETYPE_TEXT_PLAIN);
367     auto udType = record->GetUDType();
368     ASSERT_EQ(udType, UDMF::UDType::HYPERLINK);
369     auto entries = record->GetEntries();
370     ASSERT_NE(entries.size(), 0);
371     auto entryValue = entries.front()->GetValue();
372     auto link = std::make_shared<UDMF::Link>(UDMF::HYPERLINK, entryValue);
373     ASSERT_EQ(link->GetUrl(), text_);
374     ASSERT_EQ(link->GetDescription(), extraText_);
375 }
376 
377 /**
378  * @tc.name: SetHtml001
379  * @tc.desc: Get the source of the data.
380  * @tc.type: FUNC
381  * @tc.require:
382  * @tc.author:
383  */
384 HWTEST_F(PasteboardUnifiedDataTest, SetHtml001, TestSize.Level0)
385 {
386     auto data = InitHtmlData();
387     PasteboardClient::GetInstance()->SetUnifiedData(data);
388     UDMF::UnifiedData newData;
389     PasteboardClient::GetInstance()->GetUnifiedData(newData);
390     ASSERT_EQ(1, newData.GetRecords().size());
391     auto newRecord = newData.GetRecordAt(0);
392     auto newType = newRecord->GetType();
393     ASSERT_EQ(newType, UDMF::HTML);
394     auto newPlainRecord = static_cast<UDMF::Html *>(newRecord.get());
395     auto newPlainText = newPlainRecord->GetHtmlContent();
396     auto newAbstract = newPlainRecord->GetPlainContent();
397     auto newDetails = newPlainRecord->GetDetails();
398     ASSERT_EQ(newPlainText, text_);
399     ASSERT_EQ(newAbstract, extraText_);
400     ASSERT_EQ(newDetails, details_);
401 
402     PasteData pasteData;
403     PasteboardClient::GetInstance()->GetPasteData(pasteData);
404     ASSERT_EQ(1, pasteData.GetRecordCount());
405     auto record = pasteData.GetRecordAt(0);
406     auto type = record->GetMimeType();
407     ASSERT_EQ(type, MIMETYPE_TEXT_HTML);
408     auto udType = record->GetUDType();
409     ASSERT_EQ(udType, UDMF::UDType::HTML);
410     auto entries = record->GetEntries();
411     ASSERT_NE(entries.size(), 0);
412     auto entryValue = entries.front()->GetValue();
413     auto html = std::make_shared<UDMF::Html>(UDMF::HTML, entryValue);
414     ASSERT_EQ(html->GetHtmlContent(), text_);
415     ASSERT_EQ(html->GetPlainContent(), extraText_);
416 }
417 
418 /**
419  * @tc.name: SetWant001
420  * @tc.desc: Get the source of the data.
421  * @tc.type: FUNC
422  * @tc.require:
423  * @tc.author:
424  */
425 HWTEST_F(PasteboardUnifiedDataTest, SetWant001, TestSize.Level0)
426 {
427     auto data = InitWantData();
428     PasteboardClient::GetInstance()->SetUnifiedData(data);
429     UDMF::UnifiedData newData;
430     PasteboardClient::GetInstance()->GetUnifiedData(newData);
431     ASSERT_EQ(1, newData.GetRecords().size());
432     auto newRecord = newData.GetRecordAt(0);
433     auto newType = newRecord->GetType();
434     ASSERT_EQ(newType, UDMF::OPENHARMONY_WANT);
435     auto recordValue = newRecord->GetValue();
436     auto wantValue = std::get_if<std::shared_ptr<OHOS::AAFwk::Want>>(&recordValue);
437     ASSERT_NE(wantValue, nullptr);
438     int32_t idValue2 = (*(wantValue))->GetIntParam("id", 0);
439     ASSERT_EQ(idValue2, 123);
440 
441     PasteData pasteData;
442     PasteboardClient::GetInstance()->GetPasteData(pasteData);
443     ASSERT_EQ(1, pasteData.GetRecordCount());
444     auto record = pasteData.GetRecordAt(0);
445     auto type = record->GetMimeType();
446     ASSERT_EQ(type, MIMETYPE_TEXT_WANT);
447     auto udType = record->GetUDType();
448     ASSERT_EQ(udType, int32_t(UDMF::UDType::OPENHARMONY_WANT));
449     auto want1 = record->GetWant();
450     int32_t idValue1 = want1->GetIntParam("id", 0);
451     ASSERT_EQ(idValue1, 123);
452 }
453 
454 /**
455  * @tc.name: SetFile001
456  * @tc.desc: Get the source of the data.
457  * @tc.type: FUNC
458  * @tc.require:
459  * @tc.author:
460  */
461 HWTEST_F(PasteboardUnifiedDataTest, SetFile001, TestSize.Level0)
462 {
463     auto data = InitFileData();
464     PasteboardClient::GetInstance()->SetUnifiedData(data);
465 
466     UDMF::UnifiedData newData;
467     PasteboardClient::GetInstance()->GetUnifiedData(newData);
468     ASSERT_EQ(1, newData.GetRecords().size());
469     auto newRecord = newData.GetRecordAt(0);
470     auto newType = newRecord->GetType();
471     ASSERT_EQ(newType, UDMF::FILE);
472     auto newFileRecord = static_cast<UDMF::File *>(newRecord.get());
473     auto newDetails = newFileRecord->GetDetails();
474     ASSERT_EQ(newDetails, details_);
475     auto uri2 = newFileRecord->GetUri();
476     ASSERT_EQ(uri2, uri_);
477 
478     PasteData pasteData;
479     PasteboardClient::GetInstance()->GetPasteData(pasteData);
480     ASSERT_EQ(1, pasteData.GetRecordCount());
481     auto record = pasteData.GetRecordAt(0);
482     auto type = record->GetMimeType();
483     ASSERT_EQ(type, MIMETYPE_TEXT_URI);
484     auto udType = record->GetUDType();
485     ASSERT_EQ(udType, UDMF::UDType::FILE);
486     auto uri1 = record->GetUriV0()->ToString();
487     ASSERT_EQ(uri1, uri_);
488     auto details1 = record->GetDetails();
489     ASSERT_EQ(*details1, details_);
490 }
491 
492 /**
493  * @tc.name: SetImage001
494  * @tc.desc: Get the source of the data.
495  * @tc.type: FUNC
496  * @tc.require:
497  * @tc.author:
498  */
499 HWTEST_F(PasteboardUnifiedDataTest, SetImage001, TestSize.Level0)
500 {
501     auto data = InitImageData();
502     PasteboardClient::GetInstance()->SetUnifiedData(data);
503     UDMF::UnifiedData newData;
504     PasteboardClient::GetInstance()->GetUnifiedData(newData);
505     ASSERT_EQ(1, newData.GetRecords().size());
506     auto newRecord = newData.GetRecordAt(0);
507     auto newType = newRecord->GetType();
508     ASSERT_EQ(newType, UDMF::IMAGE);
509     auto newImageRecord = static_cast<UDMF::Image *>(newRecord.get());
510     auto newDetails = newImageRecord->GetDetails();
511     ASSERT_EQ(newDetails, details_);
512     auto uri2 = newImageRecord->GetUri();
513     ASSERT_EQ(uri2, uri_);
514 
515     PasteData pasteData;
516     PasteboardClient::GetInstance()->GetPasteData(pasteData);
517     ASSERT_EQ(1, pasteData.GetRecordCount());
518     auto record = pasteData.GetRecordAt(0);
519     auto type = record->GetMimeType();
520     ASSERT_EQ(type, MIMETYPE_TEXT_URI);
521     auto udType = record->GetUDType();
522     ASSERT_EQ(udType, UDMF::UDType::IMAGE);
523     auto uri1 = record->GetUriV0()->ToString();
524     ASSERT_EQ(uri1, uri_);
525     auto details1 = record->GetDetails();
526     ASSERT_EQ(*details1, details_);
527 }
528 
529 /**
530  * @tc.name: SetAudio001
531  * @tc.desc: Get the source of the data.
532  * @tc.type: FUNC
533  * @tc.require:
534  * @tc.author:
535  */
536 HWTEST_F(PasteboardUnifiedDataTest, SetAudio001, TestSize.Level0)
537 {
538     auto data = InitAudioData();
539     PasteboardClient::GetInstance()->SetUnifiedData(data);
540     UDMF::UnifiedData newData;
541     PasteboardClient::GetInstance()->GetUnifiedData(newData);
542     ASSERT_EQ(1, newData.GetRecords().size());
543     auto newRecord = newData.GetRecordAt(0);
544     auto newType = newRecord->GetType();
545     ASSERT_EQ(newType, UDMF::AUDIO);
546     auto newAudioRecord = static_cast<UDMF::Audio *>(newRecord.get());
547     auto newDetails = newAudioRecord->GetDetails();
548     ASSERT_EQ(newDetails, details_);
549     auto uri2 = newAudioRecord->GetUri();
550     ASSERT_EQ(uri2, uri_);
551 
552     PasteData pasteData;
553     PasteboardClient::GetInstance()->GetPasteData(pasteData);
554     ASSERT_EQ(1, pasteData.GetRecordCount());
555     auto record = pasteData.GetRecordAt(0);
556     auto type = record->GetMimeType();
557     ASSERT_EQ(type, MIMETYPE_TEXT_URI);
558     auto udType = record->GetUDType();
559     ASSERT_EQ(udType, UDMF::UDType::AUDIO);
560     auto uri1 = record->GetUriV0()->ToString();
561     ASSERT_EQ(uri1, uri_);
562     auto details1 = record->GetDetails();
563     ASSERT_EQ(*details1, details_);
564 }
565 
566 /**
567  * @tc.name: SetVideo001
568  * @tc.desc: Get the source of the data.
569  * @tc.type: FUNC
570  * @tc.require:
571  * @tc.author:
572  */
573 HWTEST_F(PasteboardUnifiedDataTest, SetVideo001, TestSize.Level0)
574 {
575     auto data = InitVideoData();
576     PasteboardClient::GetInstance()->SetUnifiedData(data);
577     UDMF::UnifiedData newData;
578     PasteboardClient::GetInstance()->GetUnifiedData(newData);
579     ASSERT_EQ(1, newData.GetRecords().size());
580     auto newRecord = newData.GetRecordAt(0);
581     auto newType = newRecord->GetType();
582     ASSERT_EQ(newType, UDMF::VIDEO);
583     auto newVideoRecord = static_cast<UDMF::Video *>(newRecord.get());
584     auto newDetails = newVideoRecord->GetDetails();
585     ASSERT_EQ(newDetails, details_);
586     auto uri2 = newVideoRecord->GetUri();
587     ASSERT_EQ(uri2, uri_);
588 
589     PasteData pasteData;
590     PasteboardClient::GetInstance()->GetPasteData(pasteData);
591     ASSERT_EQ(1, pasteData.GetRecordCount());
592     auto record = pasteData.GetRecordAt(0);
593     auto type = record->GetMimeType();
594     ASSERT_EQ(type, MIMETYPE_TEXT_URI);
595     auto udType = record->GetUDType();
596     ASSERT_EQ(udType, UDMF::UDType::VIDEO);
597     auto uri1 = record->GetUriV0()->ToString();
598     ASSERT_EQ(uri1, uri_);
599     auto details1 = record->GetDetails();
600     ASSERT_EQ(*details1, details_);
601 }
602 
603 /**
604  * @tc.name: SetFolder001
605  * @tc.desc: Get the source of the data.
606  * @tc.type: FUNC
607  * @tc.require:
608  * @tc.author:
609  */
610 HWTEST_F(PasteboardUnifiedDataTest, SetFolder001, TestSize.Level0)
611 {
612     auto data = InitFolderData();
613     PasteboardClient::GetInstance()->SetUnifiedData(data);
614     UDMF::UnifiedData newData;
615     PasteboardClient::GetInstance()->GetUnifiedData(newData);
616     ASSERT_EQ(1, newData.GetRecords().size());
617     auto newRecord = newData.GetRecordAt(0);
618     auto newType = newRecord->GetType();
619     ASSERT_EQ(newType, UDMF::FOLDER);
620     auto newFolderRecord = static_cast<UDMF::Folder *>(newRecord.get());
621     auto newDetails = newFolderRecord->GetDetails();
622     ASSERT_EQ(newDetails, details_);
623     auto uri2 = newFolderRecord->GetUri();
624     ASSERT_EQ(uri2, uri_);
625 
626     PasteData pasteData;
627     PasteboardClient::GetInstance()->GetPasteData(pasteData);
628     ASSERT_EQ(1, pasteData.GetRecordCount());
629     auto record = pasteData.GetRecordAt(0);
630     auto type = record->GetMimeType();
631     ASSERT_EQ(type, MIMETYPE_TEXT_URI);
632     auto udType = record->GetUDType();
633     ASSERT_EQ(udType, UDMF::UDType::FOLDER);
634     auto uri1 = record->GetUriV0()->ToString();
635     ASSERT_EQ(uri1, uri_);
636     auto details1 = record->GetDetails();
637     ASSERT_EQ(*details1, details_);
638 }
639 
640 /**
641  * @tc.name: SetSystemDefined001
642  * @tc.desc: Get the source of the data.
643  * @tc.type: FUNC
644  * @tc.require:
645  * @tc.author:
646  */
647 HWTEST_F(PasteboardUnifiedDataTest, SetSystemDefined001, TestSize.Level0)
648 {
649     auto data = InitSystemRecordData();
650     PasteboardClient::GetInstance()->SetUnifiedData(data);
651     UDMF::UnifiedData newData;
652     PasteboardClient::GetInstance()->GetUnifiedData(newData);
653     ASSERT_EQ(1, newData.GetRecords().size());
654     auto newRecord = newData.GetRecordAt(0);
655     auto newType = newRecord->GetType();
656     ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_RECORD);
657     auto newSystemRecord = static_cast<UDMF::SystemDefinedRecord *>(newRecord.get());
658     ASSERT_EQ(newSystemRecord->GetDetails(), details_);
659 
660     PasteData pasteData;
661     PasteboardClient::GetInstance()->GetPasteData(pasteData);
662     ASSERT_EQ(1, pasteData.GetRecordCount());
663     auto record = pasteData.GetRecordAt(0);
664     auto type = record->GetMimeType();
665     ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_RECORD));
666     auto udType = record->GetUDType();
667     ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_RECORD);
668     auto details = record->GetDetails();
669     ASSERT_EQ(*details, details_);
670 }
671 
672 /**
673  * @tc.name: SetAppItem001
674  * @tc.desc: Get the source of the data.
675  * @tc.type: FUNC
676  * @tc.require:
677  * @tc.author:
678  */
679 HWTEST_F(PasteboardUnifiedDataTest, SetAppItem001, TestSize.Level0)
680 {
681     auto data = InitSystemAppItemData();
682     PasteboardClient::GetInstance()->SetUnifiedData(data);
683 
684     UDMF::UnifiedData newData;
685     PasteboardClient::GetInstance()->GetUnifiedData(newData);
686     ASSERT_EQ(1, newData.GetRecords().size());
687     auto newRecord = newData.GetRecordAt(0);
688     auto newType = newRecord->GetType();
689     ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_APP_ITEM);
690     auto newAppItem = static_cast<UDMF::SystemDefinedAppItem *>(newRecord.get());
691     ASSERT_EQ(newAppItem->GetAppId(), "appId");
692     ASSERT_EQ(newAppItem->GetAppIconId(), "appIconId");
693     ASSERT_EQ(newAppItem->GetAppName(), "appName");
694     ASSERT_EQ(newAppItem->GetAppLabelId(), "appLabelId");
695     ASSERT_EQ(newAppItem->GetBundleName(), "bundleName");
696     ASSERT_EQ(newAppItem->GetAbilityName(), "abilityName");
697     ASSERT_EQ(newAppItem->GetDetails(), details_);
698 
699     PasteData pasteData;
700     PasteboardClient::GetInstance()->GetPasteData(pasteData);
701     ASSERT_EQ(1, pasteData.GetRecordCount());
702     auto record = pasteData.GetRecordAt(0);
703     auto type = record->GetMimeType();
704     ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_APP_ITEM));
705     auto udType = record->GetUDType();
706     ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_APP_ITEM);
707     auto details1 = record->GetDetails();
708     ASSERT_NE(details1, nullptr);
709     ASSERT_EQ(*details1, details_);
710     auto entries = record->GetEntries();
711     ASSERT_NE(entries.size(), 0);
712     auto entryValue = entries.front()->GetValue();
713     auto newAppItem1 = std::make_shared<UDMF::SystemDefinedAppItem>(UDMF::SYSTEM_DEFINED_APP_ITEM, entryValue);
714     ASSERT_EQ(newAppItem1->GetAppId(), "appId");
715     ASSERT_EQ(newAppItem1->GetAppIconId(), "appIconId");
716     ASSERT_EQ(newAppItem1->GetAppName(), "appName");
717     ASSERT_EQ(newAppItem1->GetAppLabelId(), "appLabelId");
718     ASSERT_EQ(newAppItem1->GetBundleName(), "bundleName");
719     ASSERT_EQ(newAppItem1->GetAbilityName(), "abilityName");
720 }
721 
722 /**
723  * @tc.name: SetForm001
724  * @tc.desc: Get the source of the data.
725  * @tc.type: FUNC
726  * @tc.require:
727  * @tc.author:
728  */
729 HWTEST_F(PasteboardUnifiedDataTest, SetForm001, TestSize.Level0)
730 {
731     auto data = InitSystemFormData();
732     PasteboardClient::GetInstance()->SetUnifiedData(data);
733     UDMF::UnifiedData newData;
734     PasteboardClient::GetInstance()->GetUnifiedData(newData);
735     ASSERT_EQ(1, newData.GetRecords().size());
736     auto newRecord = newData.GetRecordAt(0);
737     auto newType = newRecord->GetType();
738     ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_FORM);
739     auto newForm = static_cast<UDMF::SystemDefinedForm *>(newRecord.get());
740     ASSERT_EQ(newForm->GetFormId(), 1);
741     ASSERT_EQ(newForm->GetFormName(), "formName");
742     ASSERT_EQ(newForm->GetModule(), "module");
743     ASSERT_EQ(newForm->GetBundleName(), "bundleName");
744     ASSERT_EQ(newForm->GetAbilityName(), "abilityName");
745     ASSERT_EQ(newForm->GetDetails(), details_);
746 
747     PasteData pasteData;
748     PasteboardClient::GetInstance()->GetPasteData(pasteData);
749     ASSERT_EQ(1, pasteData.GetRecordCount());
750     auto record = pasteData.GetRecordAt(0);
751     auto type = record->GetMimeType();
752     ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::SYSTEM_DEFINED_FORM));
753     auto udType = record->GetUDType();
754     ASSERT_EQ(udType, UDMF::SYSTEM_DEFINED_FORM);
755     auto details1 = record->GetDetails();
756     auto content = *(record->GetSystemDefinedContent());
757     ASSERT_EQ(*details1, details_);
758     auto formId1 = std::get<std::int32_t>(content["formId"]);
759     auto formName1 = std::get<std::string>(content["formName"]);
760     auto module1 = std::get<std::string>(content["module"]);
761     auto bundleName1 = std::get<std::string>(content["bundleName"]);
762     auto abilityName1 = std::get<std::string>(content["abilityName"]);
763     ASSERT_EQ(1, formId1);
764     ASSERT_EQ("formName", formName1);
765     ASSERT_EQ("module", module1);
766     ASSERT_EQ("bundleName", bundleName1);
767     ASSERT_EQ("abilityName", abilityName1);
768 }
769 
770 /**
771  * @tc.name: SetAppDefined001
772  * @tc.desc: Get the source of the data.
773  * @tc.type: FUNC
774  * @tc.require:
775  * @tc.author:
776  */
777 HWTEST_F(PasteboardUnifiedDataTest, SetAppDefined001, TestSize.Level0)
778 {
779     auto data = InitAppDefinedData();
780     PasteboardClient::GetInstance()->SetUnifiedData(data);
781 
782     UDMF::UnifiedData newData;
783     PasteboardClient::GetInstance()->GetUnifiedData(newData);
784     ASSERT_EQ(1, newData.GetRecords().size());
785     auto newRecord = newData.GetRecordAt(0);
786     auto newType = newRecord->GetType();
787     ASSERT_EQ(newType, UDMF::APPLICATION_DEFINED_RECORD);
788     auto newSystemRecord = static_cast<UDMF::ApplicationDefinedRecord *>(newRecord.get());
789     ASSERT_EQ(newSystemRecord->GetRawData(), rawData_);
790 
791     PasteData pasteData;
792     PasteboardClient::GetInstance()->GetPasteData(pasteData);
793     ASSERT_EQ(1, pasteData.GetRecordCount());
794     auto record = pasteData.GetRecordAt(0);
795     auto type = record->GetMimeType();
796     ASSERT_EQ(type, UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDMF::APPLICATION_DEFINED_RECORD));
797     auto udType = record->GetUDType();
798     ASSERT_EQ(udType, UDMF::APPLICATION_DEFINED_RECORD);
799     auto items = record->GetCustomData()->GetItemData();
800     std::map<std::string, std::vector<uint8_t>> customData {
801         {type, rawData_}
802     };
803     ASSERT_EQ(items, customData);
804 }
805 
806 /**
807  * @tc.name: SetPixelMap001
808  * @tc.desc: Get the source of the data.
809  * @tc.type: FUNC
810  * @tc.require:
811  * @tc.author:
812  */
813 HWTEST_F(PasteboardUnifiedDataTest, SetPixelMap001, TestSize.Level0)
814 {
815     auto data = InitSystemPixelMapData();
816     PasteboardClient::GetInstance()->SetUnifiedData(data);
817     // GetUnifiedData
818     UDMF::UnifiedData newData;
819     PasteboardClient::GetInstance()->GetUnifiedData(newData);
820     ASSERT_EQ(1, newData.GetRecords().size());
821     auto newRecord = newData.GetRecordAt(0);
822     auto newType = newRecord->GetType();
823     ASSERT_EQ(newType, UDMF::SYSTEM_DEFINED_PIXEL_MAP);
824     auto recordValue = newRecord->GetValue();
825     auto newPixelMap1 = std::get_if<std::shared_ptr<OHOS::Media::PixelMap>>(&recordValue);
826     ASSERT_NE(newPixelMap1, nullptr);
827     ImageInfo imageInfo1 = {};
828     (*newPixelMap1)->GetImageInfo(imageInfo1);
829     ASSERT_TRUE(imageInfo1.size.height == 7);
830     ASSERT_TRUE(imageInfo1.size.width == 5);
831     ASSERT_TRUE(imageInfo1.pixelFormat == PixelFormat::ARGB_8888);
832     // GetPasteData
833     PasteData pasteData;
834     PasteboardClient::GetInstance()->GetPasteData(pasteData);
835     ASSERT_EQ(1, pasteData.GetRecordCount());
836     auto record = pasteData.GetRecordAt(0);
837     auto type = record->GetMimeType();
838     ASSERT_EQ(type, MIMETYPE_PIXELMAP);
839     auto udType = record->GetUDType();
840     ASSERT_EQ(udType, int32_t(UDMF::UDType::SYSTEM_DEFINED_PIXEL_MAP));
841     auto newPixelMap = record->GetPixelMapV0();
842     ASSERT_TRUE(newPixelMap != nullptr);
843     ImageInfo imageInfo = {};
844     newPixelMap->GetImageInfo(imageInfo);
845     ASSERT_TRUE(imageInfo.size.height == imageInfo1.size.height);
846     ASSERT_TRUE(imageInfo.size.width == imageInfo1.size.width);
847     ASSERT_TRUE(imageInfo.pixelFormat == imageInfo1.pixelFormat);
848 }
849 } // namespace OHOS::MiscServices