1 /*
2 * Copyright (c) 2022 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 <cstring>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #define private public
21 #include "pasteboard_client_adapter_impl.h"
22 #undef private
23
24 #include "ohos_adapter_helper.h"
25 #include "paste_data.h"
26 #include "paste_data_record.h"
27 #include "pasteboard_client_adapter.h"
28
29 using namespace testing;
30 using namespace testing::ext;
31 using namespace OHOS;
32 using namespace OHOS::MiscServices;
33 using namespace OHOS::Media;
34
35 namespace OHOS::NWeb {
36 namespace {
37 const int RESULT_OK = 0;
38 const bool TRUE_OK = true;
39 const std::string g_mimeType = "text/html";
40 std::shared_ptr<std::string> g_htmlText;
41 std::shared_ptr<std::string> g_plainText;
42 std::shared_ptr<PasteDataRecordAdapterImpl> g_paster;
43 std::shared_ptr<PasteDataRecordAdapterImpl> g_pasternull;
44 std::shared_ptr<PasteDataRecordAdapterImpl> g_datarecord;
45 std::shared_ptr<PasteDataRecordAdapterImpl> g_datarecordnull;
46 std::shared_ptr<PasteDataAdapterImpl> g_dataAdapter;
47 std::shared_ptr<PasteDataAdapterImpl> g_dataAdapterNull;
48 } // namespace
49
50 class NWebPasteboardAdapterTest : public testing::Test {
51 public:
52 static void SetUpTestCase(void);
53 static void TearDownTestCase(void);
54 void SetUp();
55 void TearDown();
56 };
57
SetUpTestCase(void)58 void NWebPasteboardAdapterTest::SetUpTestCase(void)
59 {
60 int result = 0;
61 g_dataAdapterNull = std::make_shared<PasteDataAdapterImpl>();
62 if (g_dataAdapterNull == nullptr) {
63 result = -1;
64 }
65 EXPECT_EQ(RESULT_OK, result);
66 g_dataAdapterNull->data_ = nullptr;
67
68 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
69 if (record == nullptr) {
70 result = -1;
71 }
72 EXPECT_EQ(RESULT_OK, result);
73 g_pasternull = std::make_shared<PasteDataRecordAdapterImpl>(record);
74 if (g_pasternull == nullptr) {
75 result = -1;
76 }
77 EXPECT_EQ(RESULT_OK, result);
78 g_pasternull->record_ = nullptr;
79
80 std::string mimeType = "pixelMap";
81 g_datarecordnull = std::make_shared<PasteDataRecordAdapterImpl>(mimeType);
82 if (g_datarecordnull == nullptr) {
83 result = -1;
84 }
85 EXPECT_EQ(RESULT_OK, result);
86 g_datarecordnull->builder_ = nullptr;
87 g_datarecordnull->record_ = nullptr;
88
89 result = 0;
90 g_datarecord = std::make_shared<PasteDataRecordAdapterImpl>(mimeType);
91 if (g_datarecord == nullptr) {
92 result = -1;
93 }
94 EXPECT_EQ(RESULT_OK, result);
95 }
96
TearDownTestCase(void)97 void NWebPasteboardAdapterTest::TearDownTestCase(void) {}
98
SetUp(void)99 void NWebPasteboardAdapterTest::SetUp(void) {}
100
TearDown(void)101 void NWebPasteboardAdapterTest::TearDown(void) {}
102
103 class MockPasteData : public PasteData {
104 public:
105 MOCK_METHOD1(GetRecordAt, std::shared_ptr<PasteDataRecord>(std::size_t));
106 MOCK_METHOD0(GetRecordCount, std::size_t());
107 MOCK_METHOD1(Encode, bool(std::vector<uint8_t>&));
108 MOCK_METHOD1(Decode, bool(const std::vector<uint8_t>&));
109 };
110
111 class MockPasteDataRecord : public PasteDataRecord {
112 public:
113 MOCK_METHOD0(GetPixelMap, std::shared_ptr<PixelMap>());
114 MOCK_METHOD1(Encode, bool(std::vector<uint8_t>&));
115 MOCK_METHOD1(Decode, bool(const std::vector<uint8_t>&));
116 };
117
118 class MockPasteboardObserver : public PasteboardObserverAdapter {
119 public:
120 MockPasteboardObserver() = default;
OnPasteboardChanged()121 void OnPasteboardChanged() override {}
122 };
123
124 class MockClipBoardImageDataAdapter : public ClipBoardImageDataAdapter {
125 public:
126 MockClipBoardImageDataAdapter() = default;
127
GetColorType()128 ClipBoardImageColorType GetColorType() override
129 {
130 return colorType;
131 }
132
GetAlphaType()133 ClipBoardImageAlphaType GetAlphaType() override
134 {
135 return alphaType;
136 }
137
GetData()138 uint32_t* GetData() override
139 {
140 return data;
141 }
142
GetDataSize()143 size_t GetDataSize() override
144 {
145 return dataSize;
146 }
147
GetRowBytes()148 size_t GetRowBytes() override
149 {
150 return rowBytes;
151 }
152
GetWidth()153 int32_t GetWidth() override
154 {
155 return width;
156 }
157
GetHeight()158 int32_t GetHeight() override
159 {
160 return height;
161 }
162
SetColorType(ClipBoardImageColorType color)163 void SetColorType(ClipBoardImageColorType color) override
164 {
165 colorType = color;
166 }
167
SetAlphaType(ClipBoardImageAlphaType alpha)168 void SetAlphaType(ClipBoardImageAlphaType alpha) override
169 {
170 alphaType = alpha;
171 }
172
SetData(uint32_t * d)173 void SetData(uint32_t* d) override
174 {
175 data = d;
176 }
177
SetDataSize(size_t size)178 void SetDataSize(size_t size) override
179 {
180 dataSize = size;
181 }
182
SetRowBytes(size_t r)183 void SetRowBytes(size_t r) override
184 {
185 rowBytes = r;
186 }
187
SetWidth(int32_t w)188 void SetWidth(int32_t w) override
189 {
190 width = w;
191 }
192
SetHeight(int32_t h)193 void SetHeight(int32_t h) override
194 {
195 height = h;
196 }
197
198 ClipBoardImageColorType colorType;
199 ClipBoardImageAlphaType alphaType;
200 uint32_t* data;
201 size_t dataSize;
202 size_t rowBytes;
203 int32_t width;
204 int32_t height;
205 };
206
207 /**
208 * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_001.
209 * @tc.desc: Test the PasteDataRecordAdapterImpl.
210 * @tc.type: FUNC
211 * @tc.require:issueI5O4BN
212 */
213 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_001, TestSize.Level1)
214 {
215 int result = 0;
216 std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
217 if (record == nullptr) {
218 result = -1;
219 }
220 EXPECT_EQ(RESULT_OK, result);
221 std::shared_ptr<PasteDataRecordAdapterImpl> pasterimpl = std::make_shared<PasteDataRecordAdapterImpl>(record);
222 if (pasterimpl == nullptr) {
223 result = -1;
224 }
225 EXPECT_EQ(RESULT_OK, result);
226 pasterimpl->GetImgData(nullptr);
227 }
228
229 /**
230 * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_002.
231 * @tc.desc: Test the PasteDataRecordAdapterImpl.
232 * @tc.type: FUNC
233 * @tc.require:issueI5O4BN
234 */
235 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_002, TestSize.Level1)
236 {
237 int result = 0;
238 g_htmlText = std::make_shared<std::string>("htmlText");
239 if (g_htmlText == nullptr) {
240 result = -1;
241 }
242 EXPECT_EQ(RESULT_OK, result);
243 g_plainText = std::make_shared<std::string>("plainText");
244 if (g_plainText == nullptr) {
245 result = -1;
246 }
247 EXPECT_EQ(RESULT_OK, result);
248 g_paster = std::make_shared<PasteDataRecordAdapterImpl>(g_mimeType);
249 if (g_paster == nullptr) {
250 result = -1;
251 }
252 g_paster->SetHtmlText(g_htmlText);
253 g_paster->SetPlainText(g_plainText);
254 EXPECT_EQ(RESULT_OK, result);
255 }
256
257 /**
258 * @tc.name: NWebPasteboardAdapter_NewRecord_003.
259 * @tc.desc: Test the NewRecord.
260 * @tc.type: FUNC
261 * @tc.require:issueI5O4BN
262 */
263 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_NewRecord_003, TestSize.Level1)
264 {
265 int result = 0;
266 std::shared_ptr<PasteDataRecordAdapter> record =
267 PasteDataRecordAdapter::NewRecord(g_mimeType, g_htmlText, g_plainText);
268 if (record == nullptr) {
269 result = -1;
270 }
271 EXPECT_EQ(RESULT_OK, result);
272 }
273
274 /**
275 * @tc.name: NWebPasteboardAdapter_GetMimeType_004.
276 * @tc.desc: Test the GetMimeType.
277 * @tc.type: FUNC
278 * @tc.require:issueI5O4BN
279 */
280 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetMimeType_004, TestSize.Level1)
281 {
282 int ret = 0;
283 std::string mimeType = g_paster->GetMimeType();
284 if (mimeType.empty()) {
285 ret = -1;
286 }
287 EXPECT_EQ(RESULT_OK, ret);
288 mimeType = g_pasternull->GetMimeType();
289 if (mimeType.empty()) {
290 ret = -1;
291 }
292 EXPECT_NE(RESULT_OK, ret);
293 }
294
295 /**
296 * @tc.name: NWebPasteboardAdapter_GetHtmlText_005.
297 * @tc.desc: Test the GetHtmlText.
298 * @tc.type: FUNC
299 * @tc.require:issueI5O4BN
300 */
301 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetHtmlText_005, TestSize.Level1)
302 {
303 int result = 0;
304 std::shared_ptr<std::string> htmlText = g_paster->GetHtmlText();
305 if (htmlText == nullptr) {
306 result = -1;
307 }
308 EXPECT_EQ(RESULT_OK, result);
309 std::shared_ptr<std::string> html = g_pasternull->GetHtmlText();
310 if (html == nullptr) {
311 result = -1;
312 }
313 EXPECT_NE(RESULT_OK, result);
314 }
315
316 /**
317 * @tc.name: NWebPasteboardAdapter_GetPlainText_006.
318 * @tc.desc: Test the GetPlainText.
319 * @tc.type: FUNC
320 * @tc.require:issueI5O4BN
321 */
322 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPlainText_006, TestSize.Level1)
323 {
324 int result = 0;
325 std::shared_ptr<std::string> plainText = g_paster->GetPlainText();
326 if (plainText == nullptr) {
327 result = -1;
328 }
329 EXPECT_EQ(RESULT_OK, result);
330 std::shared_ptr<std::string> plain = g_pasternull->GetPlainText();
331 if (plain == nullptr) {
332 result = -1;
333 }
334 EXPECT_NE(RESULT_OK, result);
335 }
336
337 /**
338 * @tc.name: NWebPasteboardAdapter_GetRecord_007.
339 * @tc.desc: Test the GetRecord.
340 * @tc.type: FUNC
341 * @tc.require:issueI5O4BN
342 */
343 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecord_007, TestSize.Level1)
344 {
345 int result = 0;
346 std::shared_ptr<PasteDataRecord> record = g_paster->GetRecord();
347 if (record == nullptr) {
348 result = -1;
349 }
350 EXPECT_EQ(RESULT_OK, result);
351 }
352
353 /**
354 * @tc.name: NWebPasteboardAdapter_PasteDataAdapterImpl_008.
355 * @tc.desc: Test the PasteDataAdapterImpl.
356 * @tc.type: FUNC
357 * @tc.require:issueI5O4BN
358 */
359 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataAdapterImpl_008, TestSize.Level1)
360 {
361 int result = 0;
362 g_dataAdapter = std::make_shared<PasteDataAdapterImpl>();
363 if (g_dataAdapter == nullptr) {
364 result = -1;
365 }
366 EXPECT_EQ(RESULT_OK, result);
367 }
368
369 /**
370 * @tc.name: NWebPasteboardAdapter_PasteDataAdapterImpl_009.
371 * @tc.desc: Test the PasteDataAdapterImpl.
372 * @tc.type: FUNC
373 * @tc.require:issueI5O4BB
374 */
375 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataAdapterImpl_009, TestSize.Level1)
376 {
377 int result = 0;
378 std::shared_ptr<PasteData> data = std::make_shared<PasteData>();
379 if (data == nullptr) {
380 result = -1;
381 }
382 EXPECT_EQ(RESULT_OK, result);
383 std::shared_ptr<PasteDataAdapterImpl> dataAdapter = std::make_shared<PasteDataAdapterImpl>(data);
384 if (dataAdapter == nullptr) {
385 result = -1;
386 }
387 EXPECT_EQ(RESULT_OK, result);
388 }
389
390 /**
391 * @tc.name: NWebPasteboardAdapter_AddHtmlRecord_010.
392 * @tc.desc: Test the AddHtmlRecord.
393 * @tc.type: FUNC
394 * @tc.require:issueI5O4BB
395 */
396 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AddHtmlRecord_010, TestSize.Level1)
397 {
398 std::string htmlName = "test";
399 EXPECT_NE(g_dataAdapter, nullptr);
400 g_dataAdapter->AddHtmlRecord(htmlName);
401 g_dataAdapterNull->AddHtmlRecord(htmlName);
402 }
403
404 /**
405 * @tc.name: NWebPasteboardAdapter_AddTextRecord_011.
406 * @tc.desc: Test the AddTextRecord.
407 * @tc.type: FUNC
408 * @tc.require:issueI5O4BB
409 */
410 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AddTextRecord_011, TestSize.Level1)
411 {
412 std::string htmlName = "test";
413 EXPECT_NE(g_dataAdapter, nullptr);
414 g_dataAdapter->AddTextRecord(htmlName);
415 g_dataAdapterNull->AddTextRecord(htmlName);
416 }
417
418 /**
419 * @tc.name: NWebPasteboardAdapter_GetMimeTypes_012.
420 * @tc.desc: Test the GetMimeTypes.
421 * @tc.type: FUNC
422 * @tc.require:issueI5O4BB
423 */
424 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetMimeTypes_012, TestSize.Level1)
425 {
426 int result = 0;
427 std::vector<std::string> mimeTypes = g_dataAdapter->GetMimeTypes();
428 if (mimeTypes.empty()) {
429 result = -1;
430 }
431 EXPECT_EQ(RESULT_OK, result);
432 std::vector<std::string> types = g_dataAdapterNull->GetMimeTypes();
433 if (types.empty()) {
434 result = -1;
435 }
436 EXPECT_NE(RESULT_OK, result);
437 }
438
439 /**
440 * @tc.name: NWebPasteboardAdapter_GetPrimaryHtml_013.
441 * @tc.desc: Test the GetPrimaryHtml.
442 * @tc.type: FUNC
443 * @tc.require:issueI5O4BB
444 */
445 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryHtml_013, TestSize.Level1)
446 {
447 int result = 0;
448 std::shared_ptr<std::string> primaryHtml = g_dataAdapter->GetPrimaryHtml();
449 if (primaryHtml == nullptr) {
450 result = -1;
451 }
452 EXPECT_EQ(RESULT_OK, result);
453 std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryHtml();
454 if (primary == nullptr) {
455 result = -1;
456 }
457 EXPECT_NE(RESULT_OK, result);
458 }
459
460 /**
461 * @tc.name: NWebPasteboardAdapter_GetPrimaryText_014.
462 * @tc.desc: Test the GetPrimaryText.
463 * @tc.type: FUNC
464 * @tc.require:issueI5O4BB
465 */
466 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryText_014, TestSize.Level1)
467 {
468 int result = 0;
469 std::size_t index = 0;
470 std::shared_ptr<std::string> primaryText = g_dataAdapter->GetPrimaryText();
471 if (primaryText == nullptr) {
472 result = -1;
473 }
474 EXPECT_EQ(RESULT_OK, result);
475 result = 0;
476 std::shared_ptr<PasteDataRecordAdapter> record = g_dataAdapter->GetRecordAt(index);
477 if (record == nullptr) {
478 result = -1;
479 }
480 EXPECT_EQ(RESULT_OK, result);
481 result = 0;
482 PasteRecordVector recordVector = g_dataAdapter->AllRecords();
483 if (recordVector.empty()) {
484 result = -1;
485 }
486 EXPECT_EQ(RESULT_OK, result);
487 result = 0;
488 std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryText();
489 if (primary == nullptr) {
490 result = -1;
491 }
492 EXPECT_NE(RESULT_OK, result);
493 }
494
495 /**
496 * @tc.name: NWebPasteboardAdapter_GetPrimaryMimeType_015.
497 * @tc.desc: Test the GetPrimaryMimeType.
498 * @tc.type: FUNC
499 * @tc.require:issueI5O4BB
500 */
501 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryMimeType_015, TestSize.Level1)
502 {
503 int result = 0;
504 std::shared_ptr<std::string> primaryMimeType = g_dataAdapter->GetPrimaryMimeType();
505 if (primaryMimeType == nullptr) {
506 result = -1;
507 }
508 EXPECT_EQ(RESULT_OK, result);
509 std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryMimeType();
510 if (primary == nullptr) {
511 result = -1;
512 }
513 EXPECT_NE(RESULT_OK, result);
514 }
515
516 /**
517 * @tc.name: NWebPasteboardAdapter_GetRecordAt_016.
518 * @tc.desc: Test the GetRecordAt.
519 * @tc.type: FUNC
520 * @tc.require:issueI5O4BB
521 */
522 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordAt_016, TestSize.Level1)
523 {
524 int result = 0;
525 std::size_t index = 1;
526 std::shared_ptr<PasteDataRecordAdapter> record = g_dataAdapterNull->GetRecordAt(index);
527 if (record == nullptr) {
528 result = -1;
529 }
530 EXPECT_NE(RESULT_OK, result);
531 }
532
533 /**
534 * @tc.name: NWebPasteboardAdapter_GetRecordAt_017.
535 * @tc.desc: Test the GetRecordAt.
536 * @tc.type: FUNC
537 * @tc.require:issueI5O4B5
538 */
539 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordAt_017, TestSize.Level1)
540 {
541 int result = 0;
542 std::size_t index = 0;
543 MockPasteData* mock1 = new MockPasteData();
544 g_dataAdapterNull->data_.reset((PasteData*)mock1);
545 std::shared_ptr<PasteDataRecordAdapter> str = g_dataAdapterNull->GetRecordAt(index);
546 if (str == nullptr) {
547 result = -1;
548 }
549 EXPECT_NE(RESULT_OK, result);
550 g_dataAdapterNull->data_ = nullptr;
551 }
552
553 /**
554 * @tc.name: NWebPasteboardAdapter_GetRecordCount_018.
555 * @tc.desc: Test the GetRecordCount.
556 * @tc.type: FUNC
557 * @tc.require:issueI5O4B5
558 */
559 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordCount_018, TestSize.Level1)
560 {
561 int result = 0;
562 std::size_t record = g_dataAdapterNull->GetRecordCount();
563 if (record != 0) {
564 result = -1;
565 }
566 EXPECT_EQ(RESULT_OK, result);
567 result = 0;
568 MockPasteData* mock2 = new MockPasteData();
569 g_dataAdapterNull->data_.reset((PasteData*)mock2);
570 std::size_t count = g_dataAdapterNull->GetRecordCount();
571 EXPECT_EQ(RESULT_OK, count);
572 g_dataAdapterNull->data_ = nullptr;
573 }
574
575 /**
576 * @tc.name: NWebPasteboardAdapter_AllRecords_019.
577 * @tc.desc: Test the AllRecords.
578 * @tc.type: FUNC
579 * @tc.require:issueI5O4B5
580 */
581 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AllRecords_019, TestSize.Level1)
582 {
583 int result = 0;
584 PasteRecordVector record = g_dataAdapterNull->AllRecords();
585 if (record.empty()) {
586 result = -1;
587 }
588 EXPECT_NE(RESULT_OK, result);
589 result = 0;
590 MockPasteData* mock = new MockPasteData();
591 g_dataAdapterNull->data_.reset((PasteData*)mock);
592 PasteRecordVector str = g_dataAdapterNull->AllRecords();
593 if (str.empty()) {
594 result = -1;
595 }
596 EXPECT_NE(RESULT_OK, result);
597 }
598
599 /**
600 * @tc.name: NWebPasteboardAdapter_SetPasteData_020.
601 * @tc.desc: Test the SetPasteData.
602 * @tc.type: FUNC
603 * @tc.require:issueI5O4B5
604 */
605 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPasteData_020, TestSize.Level1)
606 {
607 PasteRecordVector data;
608 std::shared_ptr<PasteDataRecordAdapter> record = PasteDataRecordAdapter::NewRecord("text/html");
609 EXPECT_NE(record, nullptr);
610 std::shared_ptr<std::string> pasteData = std::make_shared<std::string>("test");
611 EXPECT_NE(pasteData, nullptr);
612 record->SetHtmlText(pasteData);
613 data.push_back(record);
614 PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data);
615 PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data, CopyOptionMode::NONE);
616 }
617
618 /**
619 * @tc.name: NWebPasteboardAdapter_GetPasteData_021.
620 * @tc.desc: Test the GetPasteData.
621 * @tc.type: FUNC
622 * @tc.require:issueI5O4B5
623 */
624 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPasteData_021, TestSize.Level1)
625 {
626 PasteBoardClientAdapterImpl::GetInstance().Clear();
627 PasteRecordVector data;
628 bool result = PasteBoardClientAdapterImpl::GetInstance().GetPasteData(data);
629 EXPECT_EQ(false, result);
630 std::shared_ptr<PasteDataRecordAdapter> adapter = std::make_shared<PasteDataRecordAdapterImpl>("test");
631 data.push_back(adapter);
632 result = PasteBoardClientAdapterImpl::GetInstance().GetPasteData(data);
633 EXPECT_EQ(false, result);
634 }
635
636 /**
637 * @tc.name: NWebPasteboardAdapter_HasPasteData_022.
638 * @tc.desc: Test the HasPasteData.
639 * @tc.type: FUNC
640 * @tc.require:issueI5O4B5
641 */
642 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_HasPasteData_022, TestSize.Level1)
643 {
644 bool result = PasteBoardClientAdapterImpl::GetInstance().HasPasteData();
645 EXPECT_EQ(false, result);
646 }
647
648 /**
649 * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_023.
650 * @tc.desc: Test the PasteDataRecordAdapterImpl.
651 * @tc.type: FUNC
652 * @tc.require:issueI5O4B5
653 */
654 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_023, TestSize.Level1)
655 {
656 int result = 0;
657 std::string mimeType = "test";
658 std::shared_ptr<PasteDataRecordAdapterImpl> datarecord = std::make_shared<PasteDataRecordAdapterImpl>(mimeType);
659 if (datarecord == nullptr) {
660 result = -1;
661 }
662 EXPECT_EQ(RESULT_OK, result);
663 }
664
665 /**
666 * @tc.name: NWebPasteboardAdapter_NewRecord_024.
667 * @tc.desc: Test the NewRecord.
668 * @tc.type: FUNC
669 * @tc.require:issueI5O4B5
670 */
671 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_NewRecord_024, TestSize.Level1)
672 {
673 int result = 0;
674 std::string mimeType = "test";
675 std::shared_ptr<PasteDataRecordAdapter> record = PasteDataRecordAdapter::NewRecord(mimeType);
676 if (record == nullptr) {
677 result = -1;
678 }
679 EXPECT_EQ(RESULT_OK, result);
680 }
681
682 /**
683 * @tc.name: NWebPasteboardAdapter_SetHtmlText_025.
684 * @tc.desc: Test the SetHtmlText.
685 * @tc.type: FUNC
686 * @tc.require:issueI5O4B5
687 */
688 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetHtmlText_025, TestSize.Level1)
689 {
690 int result = 0;
691 std::shared_ptr<std::string> htmlText = std::make_shared<std::string>("test");
692 if (htmlText == nullptr) {
693 result = -1;
694 }
695 EXPECT_EQ(RESULT_OK, result);
696 bool reset = g_datarecordnull->SetHtmlText(htmlText);
697 EXPECT_NE(TRUE_OK, reset);
698 reset = g_datarecord->SetHtmlText(nullptr);
699 EXPECT_NE(TRUE_OK, reset);
700 reset = g_datarecord->SetHtmlText(htmlText);
701 EXPECT_EQ(TRUE_OK, reset);
702 }
703
704 /**
705 * @tc.name: NWebPasteboardAdapter_SetPlainText_026.
706 * @tc.desc: Test the SetPlainText.
707 * @tc.type: FUNC
708 * @tc.require:issueI5O4B5
709 */
710 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPlainText_026, TestSize.Level1)
711 {
712 int result = 0;
713 std::shared_ptr<std::string> plainText = std::make_shared<std::string>("test");
714 if (plainText == nullptr) {
715 result = -1;
716 }
717 EXPECT_EQ(RESULT_OK, result);
718 bool reset = g_datarecordnull->SetPlainText(plainText);
719 EXPECT_NE(TRUE_OK, reset);
720 reset = g_datarecord->SetPlainText(plainText);
721 EXPECT_EQ(TRUE_OK, reset);
722 }
723
724 /**
725 * @tc.name: NWebPasteboardAdapter_ImageToClipboardAlphaType_027.
726 * @tc.desc: Test the ImageToClipboardAlphaType.
727 * @tc.type: FUNC
728 * @tc.require:issueI5O4B5
729 */
730 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardAlphaType_027, TestSize.Level1)
731 {
732 Media::ImageInfo imgInfo;
733 imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
734 ClipBoardImageAlphaType result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
735 EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
736
737 imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
738 result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
739 EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE);
740
741 imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
742 result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
743 EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED);
744
745 imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
746 result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
747 EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
748 }
749
750 /**
751 * @tc.name: NWebPasteboardAdapter_ImageToClipboardColorType_028.
752 * @tc.desc: Test the ImageToClipboardColorType.
753 * @tc.type: FUNC
754 * @tc.require:issueI5O4AZ
755 */
756 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardColorType_028, TestSize.Level1)
757 {
758 Media::ImageInfo imgInfo;
759 imgInfo.pixelFormat = Media::PixelFormat::RGBA_8888;
760 ClipBoardImageColorType result = g_datarecord->ImageToClipboardColorType(imgInfo);
761 EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_RGBA_8888);
762
763 imgInfo.pixelFormat = Media::PixelFormat::BGRA_8888;
764 result = g_datarecord->ImageToClipboardColorType(imgInfo);
765 EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_BGRA_8888);
766
767 imgInfo.pixelFormat = Media::PixelFormat::RGBA_F16;
768 result = g_datarecord->ImageToClipboardColorType(imgInfo);
769 EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_UNKNOWN);
770 }
771
772 /**
773 * @tc.name: NWebPasteboardAdapter_ClipboardToImageAlphaType_029.
774 * @tc.desc: Test the ClipboardToImageAlphaType.
775 * @tc.type: FUNC
776 * @tc.require:issueI5O4AZ
777 */
778 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageAlphaType_029, TestSize.Level1)
779 {
780 ClipBoardImageAlphaType alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN;
781 Media::AlphaType result = g_datarecord->ClipboardToImageAlphaType(alphaType);
782 EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
783
784 alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE;
785 result = g_datarecord->ClipboardToImageAlphaType(alphaType);
786 EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
787
788 alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED;
789 result = g_datarecord->ClipboardToImageAlphaType(alphaType);
790 EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
791
792 alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_POSTMULTIPLIED;
793 result = g_datarecord->ClipboardToImageAlphaType(alphaType);
794 EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
795 }
796
797 /**
798 * @tc.name: NWebPasteboardAdapter_ClipboardToImageColorType_030.
799 * @tc.desc: Test the ClipboardToImageColorType.
800 * @tc.type: FUNC
801 * @tc.require:issueI5O4AZ
802 */
803 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageColorType_030, TestSize.Level1)
804 {
805 ClipBoardImageColorType colorType = ClipBoardImageColorType::COLOR_TYPE_RGBA_8888;
806 Media::PixelFormat result = g_datarecord->ClipboardToImageColorType(colorType);
807 EXPECT_EQ(result, Media::PixelFormat::RGBA_8888);
808
809 colorType = ClipBoardImageColorType::COLOR_TYPE_BGRA_8888;
810 result = g_datarecord->ClipboardToImageColorType(colorType);
811 EXPECT_EQ(result, Media::PixelFormat::BGRA_8888);
812
813 colorType = ClipBoardImageColorType::COLOR_TYPE_UNKNOWN;
814 result = g_datarecord->ClipboardToImageColorType(colorType);
815 EXPECT_EQ(result, Media::PixelFormat::UNKNOWN);
816 }
817
818 /**
819 * @tc.name: NWebPasteboardAdapter_SetImgData_031.
820 * @tc.desc: Test the SetImgData.
821 * @tc.type: FUNC
822 * @tc.require:issueI5O4AZ
823 */
824 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetImgData_031, TestSize.Level1)
825 {
826 uint32_t storage[][5] = {
827 { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
828 { 0xAC, 0xA8, 0x89, 0x47, 0x87 },
829 { 0x4B, 0x25, 0x25, 0x25, 0x46 },
830 { 0x90, 0x1, 0x25, 0x41, 0x33 },
831 { 0x75, 0x55, 0x44, 0x20, 0x00 },
832 };
833
834 std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
835 image->SetColorType(ClipBoardImageColorType::COLOR_TYPE_BGRA_8888);
836 image->SetAlphaType(ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
837 image->SetData(storage[0]);
838 image->SetDataSize(sizeof(storage));
839 image->SetRowBytes(5);
840 image->SetWidth(5);
841 image->SetHeight(5);
842 bool reset = g_datarecord->SetImgData(image);
843 EXPECT_EQ(TRUE_OK, reset);
844 reset = g_datarecordnull->SetImgData(image);
845 EXPECT_NE(TRUE_OK, reset);
846 image->SetDataSize(1);
847 reset = g_datarecordnull->SetImgData(image);
848 EXPECT_NE(TRUE_OK, reset);
849 image = nullptr;
850 reset = g_datarecordnull->SetImgData(image);
851 EXPECT_NE(TRUE_OK, reset);
852 }
853
854 /**
855 * @tc.name: NWebPasteboardAdapter_GetImgData_032.
856 * @tc.desc: Test the GetImgData.
857 * @tc.type: FUNC
858 * @tc.require:issueI5O4AZ
859 */
860 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_032, TestSize.Level1)
861 {
862 std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
863 bool reset = g_datarecordnull->GetImgData(image);
864 EXPECT_NE(TRUE_OK, reset);
865 reset = g_datarecordnull->GetPixelMap() == nullptr;
866 EXPECT_EQ(TRUE_OK, reset);
867 reset = g_paster->GetImgData(image);
868 EXPECT_NE(TRUE_OK, reset);
869 }
870
871 /**
872 * @tc.name: NWebPasteboardAdapter_GetImgData_033.
873 * @tc.desc: Test the GetImgData.
874 * @tc.type: FUNC
875 * @tc.require:issueI5O4AZ
876 */
877 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_033, TestSize.Level1)
878 {
879 std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
880 bool reset = g_datarecord->GetImgData(image);
881 EXPECT_EQ(TRUE_OK, reset);
882 }
883
884 /**
885 * @tc.name: NWebPasteboardAdapter_Clear_034.
886 * @tc.desc: Test the Clear.
887 * @tc.type: FUNC
888 * @tc.require:issueI5O4AZ
889 */
890 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_034, TestSize.Level1)
891 {
892 uint32_t bufferSize = 20;
893 EXPECT_NE(g_datarecord, nullptr);
894 if (g_datarecord->imgBuffer_ == nullptr) {
895 g_datarecord->imgBuffer_ = static_cast<uint8_t*>(calloc(static_cast<size_t>(bufferSize), sizeof(uint8_t)));
896 }
897 g_datarecord->Clear();
898 }
899
900 /**
901 * @tc.name: NWebPasteboardAdapter_Clear_035.
902 * @tc.desc: Test the Clear.
903 * @tc.type: FUNC
904 * @tc.require:issueI5O4AZ
905 */
906 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_035, TestSize.Level1)
907 {
908 PasteRecordVector data;
909 data.clear();
910 EXPECT_EQ(data.size(), 0);
911 PasteBoardClientAdapterImpl::GetInstance().Clear();
912 PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data);
913 PasteBoardClientAdapterImpl::GetInstance().Clear();
914 }
915
916 /**
917 * @tc.name: NWebPasteboardAdapter_SetUri_036.
918 * @tc.desc: Test the SetUri.
919 * @tc.type: FUNC
920 * @tc.require:issueI5QA3D
921 */
922 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetUri_036, TestSize.Level1)
923 {
924 int result = 0;
925 std::string emptyTestUri = "";
926 std::string testUri = "/data/test/path";
927 EXPECT_EQ(RESULT_OK, result);
928 bool reset = g_datarecordnull->SetUri(testUri);
929 EXPECT_NE(TRUE_OK, reset);
930 reset = g_datarecord->SetUri(emptyTestUri);
931 EXPECT_NE(TRUE_OK, reset);
932 reset = g_datarecord->SetUri(testUri);
933 EXPECT_EQ(TRUE_OK, reset);
934 }
935
936 /**
937 * @tc.name: NWebPasteboardAdapter_SetCustomData_037.
938 * @tc.desc: Test the SetCustomData.
939 * @tc.type: FUNC
940 * @tc.require:issueI5QA3D
941 */
942 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetCustomData_037, TestSize.Level1)
943 {
944 int result = 0;
945 PasteCustomData emptyTestData;
946 std::string format = "format";
947 vector<uint8_t> data = { 0, 1, 2 };
948 PasteCustomData testData;
949 testData.insert(std::make_pair(format, data));
950 EXPECT_EQ(RESULT_OK, result);
951 bool reset = g_datarecordnull->SetCustomData(testData);
952 EXPECT_NE(TRUE_OK, reset);
953 reset = g_datarecord->SetCustomData(emptyTestData);
954 EXPECT_NE(TRUE_OK, reset);
955 reset = g_datarecord->SetCustomData(testData);
956 EXPECT_EQ(TRUE_OK, reset);
957 }
958
959 /**
960 * @tc.name: NWebPasteboardAdapter_GetUri_038.
961 * @tc.desc: Test the GetUri.
962 * @tc.type: FUNC
963 * @tc.require:issueI5O4BN
964 */
965 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetUri_038, TestSize.Level1)
966 {
967 int result = 0;
968 g_datarecord->SetUri("/data/test/path");
969 std::shared_ptr<std::string> uri = g_datarecord->GetUri();
970 if (uri == nullptr) {
971 result = -1;
972 }
973 EXPECT_EQ(RESULT_OK, result);
974 g_datarecord = std::make_shared<PasteDataRecordAdapterImpl>(g_mimeType);
975 g_datarecord->record_ = g_datarecord->builder_->SetUri(nullptr).Build();
976 uri = g_datarecord->GetUri();
977 if (uri == nullptr) {
978 result = -1;
979 }
980 EXPECT_NE(RESULT_OK, result);
981 uri = g_pasternull->GetUri();
982 if (uri == nullptr) {
983 result = -1;
984 }
985 EXPECT_NE(RESULT_OK, result);
986 }
987
988 /**
989 * @tc.name: NWebPasteboardAdapter_GetCustomData_039.
990 * @tc.desc: Test the GetCustomData.
991 * @tc.type: FUNC
992 * @tc.require:issueI5O4BN
993 */
994 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetCustomData_039, TestSize.Level1)
995 {
996 int result = 0;
997 std::string format = "openharmony.arkweb.custom-data";
998 vector<uint8_t> data = { 0, 1, 2 };
999 PasteCustomData testData = { { format, data } };
1000 g_datarecord->SetCustomData(testData);
1001 std::shared_ptr<PasteCustomData> customData = g_datarecord->GetCustomData();
1002 if (customData == nullptr) {
1003 result = -1;
1004 }
1005 EXPECT_EQ(RESULT_OK, result);
1006 g_datarecord = std::make_shared<PasteDataRecordAdapterImpl>(format);
1007 g_datarecord->record_ = g_datarecord->builder_->SetCustomData(nullptr).Build();
1008 customData = g_datarecord->GetCustomData();
1009 if (customData == nullptr) {
1010 result = -1;
1011 }
1012 EXPECT_NE(RESULT_OK, result);
1013 customData = g_pasternull->GetCustomData();
1014 if (customData == nullptr) {
1015 result = -1;
1016 }
1017 EXPECT_NE(RESULT_OK, result);
1018 }
1019
1020 /**
1021 * @tc.name: NWebPasteboardAdapter_OpenRemoteUri_040.
1022 * @tc.desc: Test the OpenRemoteUri.
1023 * @tc.type: FUNC
1024 * @tc.require:issueI5O4BN
1025 */
1026 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_OpenRemoteUri_040, TestSize.Level1)
1027 {
1028 std::string testUri = "datashare:////#fdFromBinder=155";
1029 int32_t fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testUri);
1030 EXPECT_EQ(155, fd);
1031 std::string testInvalidUri = "www.example.com";
1032 fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testInvalidUri);
1033 EXPECT_EQ(-1, fd);
1034 }
1035
1036 /**
1037 * @tc.name: PasteBoardClientAdapterImpl_GetTokenId_041.
1038 * @tc.desc: Test the GetTokenId.
1039 * @tc.type: FUNC
1040 * @tc.require:issueI5O4BN
1041 */
1042 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_GetTokenId_041, TestSize.Level1)
1043 {
1044 PasteBoardClientAdapterImpl::GetInstance().Clear();
1045 EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().GetTokenId());
1046 }
1047
1048 /**
1049 * @tc.name: PasteBoardClientAdapterImpl_IsLocalPaste_042.
1050 * @tc.desc: Test the IsLocalPaste.
1051 * @tc.type: FUNC
1052 * @tc.require:issueI5O4BN
1053 */
1054 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_IsLocalPaste_042, TestSize.Level1)
1055 {
1056 PasteBoardClientAdapterImpl::GetInstance().Clear();
1057 EXPECT_EQ(false, PasteBoardClientAdapterImpl::GetInstance().IsLocalPaste());
1058 }
1059
1060 /**
1061 * @tc.name: PasteboardObserverAdapter_OnPasteboardChanged_043.
1062 * @tc.desc: Test the CreatePasteboardObserver.
1063 * @tc.type: FUNC
1064 * @tc.require:issueI5O4BN
1065 */
1066 HWTEST_F(NWebPasteboardAdapterTest, PasteboardObserverAdapter_OnPasteboardChanged_043, TestSize.Level1)
1067 {
1068 std::shared_ptr<PasteboardObserverAdapter> observer = std::make_shared<MockPasteboardObserver>();
1069 EXPECT_NE(observer, nullptr);
1070 PasteboardObserverAdapterImpl observerImpl(observer);
1071 observerImpl.OnPasteboardChanged();
1072 observerImpl.observer_ = nullptr;
1073 observerImpl.OnPasteboardChanged();
1074 }
1075
1076 /**
1077 * @tc.name: PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_044.
1078 * @tc.desc: Test the AddPasteboardChangedObserver.
1079 * @tc.type: FUNC
1080 * @tc.require:issueI5O4BN
1081 */
1082 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_044, TestSize.Level1)
1083 {
1084 std::shared_ptr<PasteboardObserverAdapter> observer = std::make_shared<MockPasteboardObserver>();
1085 std::shared_ptr<PasteboardObserverAdapter> observerInvalid = std::make_shared<MockPasteboardObserver>();
1086 int32_t id = PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(observer);
1087 PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(nullptr);
1088 EXPECT_EQ(1, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1089 PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(id);
1090 EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1091 PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(-1);
1092 EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1093
1094 MiscServices::ShareOption option =
1095 PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::IN_APP);
1096 EXPECT_EQ(option, MiscServices::ShareOption::InApp);
1097 option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::LOCAL_DEVICE);
1098 EXPECT_EQ(option, MiscServices::ShareOption::LocalDevice);
1099 option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::CROSS_DEVICE);
1100 EXPECT_EQ(option, MiscServices::ShareOption::CrossDevice);
1101 option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::NONE);
1102 EXPECT_EQ(option, MiscServices::ShareOption::CrossDevice);
1103 }
1104
1105 /**
1106 * @tc.name: NWebPasteboardAdapter_SetPlainText_045.
1107 * @tc.desc: Test the SetPlainText.
1108 * @tc.type: FUNC
1109 * @tc.require:issueI5O4B5
1110 */
1111 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPlainText_045, TestSize.Level1)
1112 {
1113 auto plainText = std::make_shared<std::string>("test");
1114 EXPECT_NE(nullptr, plainText);
1115 auto textRecord = std::make_shared<PasteDataRecordAdapterImpl>();
1116 EXPECT_NE(nullptr, textRecord);
1117 auto plainTextPtr = textRecord->GetPlainText();
1118 EXPECT_EQ(nullptr, plainTextPtr);
1119 auto result = textRecord->SetPlainText(nullptr);
1120 EXPECT_FALSE(result);
1121 result = textRecord->SetPlainText(plainText);
1122 EXPECT_TRUE(result);
1123 plainTextPtr = textRecord->GetPlainText();
1124 EXPECT_NE(nullptr, plainTextPtr);
1125 EXPECT_FALSE(plainTextPtr->empty());
1126 }
1127 } // namespace OHOS::NWeb
1128