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