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