• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 = "data";
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(htmlText);
697     EXPECT_EQ(TRUE_OK, reset);
698 }
699 
700 /**
701  * @tc.name: NWebPasteboardAdapter_SetPlainText_026.
702  * @tc.desc: Test the SetPlainText.
703  * @tc.type: FUNC
704  * @tc.require:issueI5O4B5
705  */
706 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPlainText_026, TestSize.Level1)
707 {
708     int result = 0;
709     std::shared_ptr<std::string> plainText = std::make_shared<std::string>("test");
710     if (plainText == nullptr) {
711         result = -1;
712     }
713     EXPECT_EQ(RESULT_OK, result);
714     bool reset = g_datarecordnull->SetPlainText(plainText);
715     EXPECT_NE(TRUE_OK, reset);
716     reset = g_datarecord->SetPlainText(plainText);
717     EXPECT_EQ(TRUE_OK, reset);
718 }
719 
720 /**
721  * @tc.name: NWebPasteboardAdapter_ImageToClipboardAlphaType_027.
722  * @tc.desc: Test the ImageToClipboardAlphaType.
723  * @tc.type: FUNC
724  * @tc.require:issueI5O4B5
725  */
726 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardAlphaType_027, TestSize.Level1)
727 {
728     Media::ImageInfo imgInfo;
729     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
730     ClipBoardImageAlphaType result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
731     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
732 
733     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
734     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
735     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE);
736 
737     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
738     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
739     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED);
740 
741     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
742     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
743     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
744 }
745 
746 /**
747  * @tc.name: NWebPasteboardAdapter_ImageToClipboardColorType_028.
748  * @tc.desc: Test the ImageToClipboardColorType.
749  * @tc.type: FUNC
750  * @tc.require:issueI5O4AZ
751  */
752 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardColorType_028, TestSize.Level1)
753 {
754     Media::ImageInfo imgInfo;
755     imgInfo.pixelFormat = Media::PixelFormat::RGBA_8888;
756     ClipBoardImageColorType result = g_datarecord->ImageToClipboardColorType(imgInfo);
757     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_RGBA_8888);
758 
759     imgInfo.pixelFormat = Media::PixelFormat::BGRA_8888;
760     result = g_datarecord->ImageToClipboardColorType(imgInfo);
761     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_BGRA_8888);
762 
763     imgInfo.pixelFormat = Media::PixelFormat::RGBA_F16;
764     result = g_datarecord->ImageToClipboardColorType(imgInfo);
765     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_UNKNOWN);
766 }
767 
768 /**
769  * @tc.name: NWebPasteboardAdapter_ClipboardToImageAlphaType_029.
770  * @tc.desc: Test the ClipboardToImageAlphaType.
771  * @tc.type: FUNC
772  * @tc.require:issueI5O4AZ
773  */
774 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageAlphaType_029, TestSize.Level1)
775 {
776     ClipBoardImageAlphaType alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN;
777     Media::AlphaType result = g_datarecord->ClipboardToImageAlphaType(alphaType);
778     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
779 
780     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE;
781     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
782     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
783 
784     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED;
785     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
786     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
787 
788     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_POSTMULTIPLIED;
789     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
790     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
791 }
792 
793 /**
794  * @tc.name: NWebPasteboardAdapter_ClipboardToImageColorType_030.
795  * @tc.desc: Test the ClipboardToImageColorType.
796  * @tc.type: FUNC
797  * @tc.require:issueI5O4AZ
798  */
799 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageColorType_030, TestSize.Level1)
800 {
801     ClipBoardImageColorType colorType = ClipBoardImageColorType::COLOR_TYPE_RGBA_8888;
802     Media::PixelFormat result = g_datarecord->ClipboardToImageColorType(colorType);
803     EXPECT_EQ(result, Media::PixelFormat::RGBA_8888);
804 
805     colorType = ClipBoardImageColorType::COLOR_TYPE_BGRA_8888;
806     result = g_datarecord->ClipboardToImageColorType(colorType);
807     EXPECT_EQ(result, Media::PixelFormat::BGRA_8888);
808 
809     colorType = ClipBoardImageColorType::COLOR_TYPE_UNKNOWN;
810     result = g_datarecord->ClipboardToImageColorType(colorType);
811     EXPECT_EQ(result, Media::PixelFormat::UNKNOWN);
812 }
813 
814 /**
815  * @tc.name: NWebPasteboardAdapter_SetImgData_031.
816  * @tc.desc: Test the SetImgData.
817  * @tc.type: FUNC
818  * @tc.require:issueI5O4AZ
819  */
820 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetImgData_031, TestSize.Level1)
821 {
822     uint32_t storage[][5] = {
823         { 0xCA, 0xDA, 0xCA, 0xC9, 0xA3 },
824         { 0xAC, 0xA8, 0x89, 0x47, 0x87 },
825         { 0x4B, 0x25, 0x25, 0x25, 0x46 },
826         { 0x90, 0x1, 0x25, 0x41, 0x33 },
827         { 0x75, 0x55, 0x44, 0x20, 0x00 },
828     };
829 
830     std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
831     image->SetColorType(ClipBoardImageColorType::COLOR_TYPE_BGRA_8888);
832     image->SetAlphaType(ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
833     image->SetData(storage[0]);
834     image->SetDataSize(sizeof(storage));
835     image->SetRowBytes(5);
836     image->SetWidth(5);
837     image->SetHeight(5);
838     bool reset = g_datarecord->SetImgData(image);
839     EXPECT_EQ(TRUE_OK, reset);
840     reset = g_datarecordnull->SetImgData(image);
841     EXPECT_NE(TRUE_OK, reset);
842     image->SetDataSize(1);
843     reset = g_datarecordnull->SetImgData(image);
844     EXPECT_NE(TRUE_OK, reset);
845     image = nullptr;
846     reset = g_datarecordnull->SetImgData(image);
847     EXPECT_NE(TRUE_OK, reset);
848 }
849 
850 /**
851  * @tc.name: NWebPasteboardAdapter_GetImgData_032.
852  * @tc.desc: Test the GetImgData.
853  * @tc.type: FUNC
854  * @tc.require:issueI5O4AZ
855  */
856 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_032, TestSize.Level1)
857 {
858     std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
859     bool reset = g_datarecordnull->GetImgData(image);
860     EXPECT_NE(TRUE_OK, reset);
861     reset = g_paster->GetImgData(image);
862     EXPECT_NE(TRUE_OK, reset);
863 }
864 
865 /**
866  * @tc.name: NWebPasteboardAdapter_GetImgData_033.
867  * @tc.desc: Test the GetImgData.
868  * @tc.type: FUNC
869  * @tc.require:issueI5O4AZ
870  */
871 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_033, TestSize.Level1)
872 {
873     std::shared_ptr<MockClipBoardImageDataAdapter> image = std::make_shared<MockClipBoardImageDataAdapter>();
874     bool reset = g_datarecord->GetImgData(image);
875     EXPECT_EQ(TRUE_OK, reset);
876 }
877 
878 /**
879  * @tc.name: NWebPasteboardAdapter_Clear_034.
880  * @tc.desc: Test the Clear.
881  * @tc.type: FUNC
882  * @tc.require:issueI5O4AZ
883  */
884 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_034, TestSize.Level1)
885 {
886     uint32_t bufferSize = 20;
887     EXPECT_NE(g_datarecord, nullptr);
888     if (g_datarecord->imgBuffer_ == nullptr) {
889         g_datarecord->imgBuffer_ = static_cast<uint8_t*>(calloc(static_cast<size_t>(bufferSize), sizeof(uint8_t)));
890     }
891     g_datarecord->Clear();
892 }
893 
894 /**
895  * @tc.name: NWebPasteboardAdapter_Clear_035.
896  * @tc.desc: Test the Clear.
897  * @tc.type: FUNC
898  * @tc.require:issueI5O4AZ
899  */
900 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_035, TestSize.Level1)
901 {
902     PasteRecordVector data;
903     data.clear();
904     EXPECT_EQ(data.size(), 0);
905     PasteBoardClientAdapterImpl::GetInstance().Clear();
906     PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data);
907     PasteBoardClientAdapterImpl::GetInstance().Clear();
908 }
909 
910 /**
911  * @tc.name: NWebPasteboardAdapter_SetUri_036.
912  * @tc.desc: Test the SetUri.
913  * @tc.type: FUNC
914  * @tc.require:issueI5QA3D
915  */
916 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetUri_036, TestSize.Level1)
917 {
918     int result = 0;
919     std::string emptyTestUri = "";
920     std::string testUri = "/data/test/path";
921     EXPECT_EQ(RESULT_OK, result);
922     bool reset = g_datarecordnull->SetUri(testUri);
923     EXPECT_NE(TRUE_OK, reset);
924     reset = g_datarecord->SetUri(emptyTestUri);
925     EXPECT_NE(TRUE_OK, reset);
926     reset = g_datarecord->SetUri(testUri);
927     EXPECT_EQ(TRUE_OK, reset);
928 }
929 
930 /**
931  * @tc.name: NWebPasteboardAdapter_SetCustomData_037.
932  * @tc.desc: Test the SetCustomData.
933  * @tc.type: FUNC
934  * @tc.require:issueI5QA3D
935  */
936 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetCustomData_037, TestSize.Level1)
937 {
938     int result = 0;
939     PasteCustomData emptyTestData;
940     std::string format = "format";
941     vector<uint8_t> data = { 0, 1, 2 };
942     PasteCustomData testData;
943     testData.insert(std::make_pair(format, data));
944     EXPECT_EQ(RESULT_OK, result);
945     bool reset = g_datarecordnull->SetCustomData(testData);
946     EXPECT_NE(TRUE_OK, reset);
947     reset = g_datarecord->SetCustomData(emptyTestData);
948     EXPECT_NE(TRUE_OK, reset);
949     reset = g_datarecord->SetCustomData(testData);
950     EXPECT_EQ(TRUE_OK, reset);
951 }
952 
953 /**
954  * @tc.name: NWebPasteboardAdapter_GetUri_038.
955  * @tc.desc: Test the GetUri.
956  * @tc.type: FUNC
957  * @tc.require:issueI5O4BN
958  */
959 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetUri_038, TestSize.Level1)
960 {
961     int result = 0;
962     g_datarecord->SetUri("/data/test/path");
963     std::shared_ptr<std::string> uri = g_datarecord->GetUri();
964     if (uri == nullptr) {
965         result = -1;
966     }
967     EXPECT_EQ(RESULT_OK, result);
968     g_datarecord->record_ = g_datarecord->builder_->SetUri(nullptr).Build();
969     uri = g_datarecord->GetUri();
970     if (uri == nullptr) {
971         result = -1;
972     }
973     EXPECT_NE(RESULT_OK, result);
974     uri = g_pasternull->GetUri();
975     if (uri == nullptr) {
976         result = -1;
977     }
978     EXPECT_NE(RESULT_OK, result);
979 }
980 
981 /**
982  * @tc.name: NWebPasteboardAdapter_GetCustomData_039.
983  * @tc.desc: Test the GetCustomData.
984  * @tc.type: FUNC
985  * @tc.require:issueI5O4BN
986  */
987 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetCustomData_039, TestSize.Level1)
988 {
989     int result = 0;
990     std::string format = "format";
991     vector<uint8_t> data = { 0, 1, 2 };
992     PasteCustomData testData;
993     g_datarecord->SetCustomData(testData);
994     std::shared_ptr<PasteCustomData> customData = g_datarecord->GetCustomData();
995     if (customData == nullptr) {
996         result = -1;
997     }
998     EXPECT_EQ(RESULT_OK, result);
999     g_datarecord->record_ = g_datarecord->builder_->SetCustomData(nullptr).Build();
1000     customData = g_datarecord->GetCustomData();
1001     if (customData == nullptr) {
1002         result = -1;
1003     }
1004     EXPECT_NE(RESULT_OK, result);
1005     customData = g_pasternull->GetCustomData();
1006     if (customData == nullptr) {
1007         result = -1;
1008     }
1009     EXPECT_NE(RESULT_OK, result);
1010 }
1011 
1012 /**
1013  * @tc.name: NWebPasteboardAdapter_OpenRemoteUri_040.
1014  * @tc.desc: Test the OpenRemoteUri.
1015  * @tc.type: FUNC
1016  * @tc.require:issueI5O4BN
1017  */
1018 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_OpenRemoteUri_040, TestSize.Level1)
1019 {
1020     std::string testUri = "datashare:////#fdFromBinder=155";
1021     int32_t fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testUri);
1022     EXPECT_EQ(155, fd);
1023     std::string testInvalidUri = "www.example.com";
1024     fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testInvalidUri);
1025     EXPECT_EQ(-1, fd);
1026 }
1027 
1028 /**
1029  * @tc.name: PasteBoardClientAdapterImpl_GetTokenId_041.
1030  * @tc.desc: Test the GetTokenId.
1031  * @tc.type: FUNC
1032  * @tc.require:issueI5O4BN
1033  */
1034 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_GetTokenId_041, TestSize.Level1)
1035 {
1036     PasteBoardClientAdapterImpl::GetInstance().Clear();
1037     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().GetTokenId());
1038 }
1039 
1040 /**
1041  * @tc.name: PasteBoardClientAdapterImpl_IsLocalPaste_042.
1042  * @tc.desc: Test the IsLocalPaste.
1043  * @tc.type: FUNC
1044  * @tc.require:issueI5O4BN
1045  */
1046 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_IsLocalPaste_042, TestSize.Level1)
1047 {
1048     PasteBoardClientAdapterImpl::GetInstance().Clear();
1049     EXPECT_EQ(false, PasteBoardClientAdapterImpl::GetInstance().IsLocalPaste());
1050 }
1051 
1052 /**
1053  * @tc.name: PasteboardObserverAdapter_OnPasteboardChanged_043.
1054  * @tc.desc: Test the CreatePasteboardObserver.
1055  * @tc.type: FUNC
1056  * @tc.require:issueI5O4BN
1057  */
1058 HWTEST_F(NWebPasteboardAdapterTest, PasteboardObserverAdapter_OnPasteboardChanged_043, TestSize.Level1)
1059 {
1060     std::shared_ptr<PasteboardObserverAdapter> observer = std::make_shared<MockPasteboardObserver>();
1061     EXPECT_NE(observer, nullptr);
1062     PasteboardObserverAdapterImpl observerImpl(observer);
1063     observerImpl.OnPasteboardChanged();
1064     observerImpl.observer_ = nullptr;
1065     observerImpl.OnPasteboardChanged();
1066 }
1067 
1068 /**
1069  * @tc.name: PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_044.
1070  * @tc.desc: Test the AddPasteboardChangedObserver.
1071  * @tc.type: FUNC
1072  * @tc.require:issueI5O4BN
1073  */
1074 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_044, TestSize.Level1)
1075 {
1076     std::shared_ptr<PasteboardObserverAdapter> observer = std::make_shared<MockPasteboardObserver>();
1077     std::shared_ptr<PasteboardObserverAdapter> observerInvalid = std::make_shared<MockPasteboardObserver>();
1078     int32_t id = PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(observer);
1079     PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(nullptr);
1080     EXPECT_EQ(1, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1081     PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(id);
1082     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1083     PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(-1);
1084     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1085 
1086     MiscServices::ShareOption option =
1087         PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::IN_APP);
1088     EXPECT_EQ(option, MiscServices::ShareOption::InApp);
1089     option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::LOCAL_DEVICE);
1090     EXPECT_EQ(option, MiscServices::ShareOption::LocalDevice);
1091     option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::CROSS_DEVICE);
1092     EXPECT_EQ(option, MiscServices::ShareOption::CrossDevice);
1093     option = PasteBoardClientAdapterImpl::GetInstance().TransitionCopyOption(CopyOptionMode::NONE);
1094     EXPECT_EQ(option, MiscServices::ShareOption::CrossDevice);
1095 }
1096 } // namespace OHOS::NWeb
1097