• 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 "paste_data.h"
25 #include "paste_data_record.h"
26 #include "pasteboard_client_adapter.h"
27 #include "ohos_adapter_helper.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 {}
99 
SetUp(void)100 void NWebPasteboardAdapterTest::SetUp(void)
101 {}
102 
TearDown(void)103 void NWebPasteboardAdapterTest::TearDown(void)
104 {}
105 
106 class MockPasteData : public PasteData {
107 public:
108     MOCK_METHOD1(GetRecordAt, std::shared_ptr<PasteDataRecord>(std::size_t));
109     MOCK_METHOD0(GetRecordCount, std::size_t());
110     MOCK_METHOD1(Encode, bool(std::vector<uint8_t> &));
111     MOCK_METHOD1(Decode, bool(const std::vector<uint8_t> &));
112 };
113 
114 class MockPasteDataRecord : public PasteDataRecord {
115 public:
116     MOCK_METHOD0(GetPixelMap, std::shared_ptr<PixelMap>());
117     MOCK_METHOD1(Encode, bool(std::vector<uint8_t> &));
118     MOCK_METHOD1(Decode, bool(const std::vector<uint8_t> &));
119 };
120 
121 class MockPasteboardObserver : public PasteboardObserverAdapter {
122 public:
123     MockPasteboardObserver() = default;
OnPasteboardChanged()124     void OnPasteboardChanged() override {}
125 };
126 
127 /**
128  * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_001.
129  * @tc.desc: Test the PasteDataRecordAdapterImpl.
130  * @tc.type: FUNC
131  * @tc.require:issueI5O4BN
132  */
133 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_001, TestSize.Level1)
134 {
135     int result = 0;
136     std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
137     if (record == nullptr) {
138         result = -1;
139     }
140     EXPECT_EQ(RESULT_OK, result);
141     std::shared_ptr<PasteDataRecordAdapterImpl> pasterimpl = std::make_shared<PasteDataRecordAdapterImpl>(record);
142     if (pasterimpl == nullptr) {
143         result = -1;
144     }
145     EXPECT_EQ(RESULT_OK, result);
146 }
147 
148 /**
149  * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_002.
150  * @tc.desc: Test the PasteDataRecordAdapterImpl.
151  * @tc.type: FUNC
152  * @tc.require:issueI5O4BN
153  */
154 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_002, TestSize.Level1)
155 {
156     int result = 0;
157     g_htmlText = std::make_shared<std::string>("htmlText");
158     if (g_htmlText == nullptr) {
159         result = -1;
160     }
161     EXPECT_EQ(RESULT_OK, result);
162     g_plainText = std::make_shared<std::string>("plainText");
163     if (g_plainText == nullptr) {
164         result = -1;
165     }
166     EXPECT_EQ(RESULT_OK, result);
167     g_paster = std::make_shared<PasteDataRecordAdapterImpl>(g_mimeType, g_htmlText, g_plainText);
168     if (g_paster == nullptr) {
169         result = -1;
170     }
171     EXPECT_EQ(RESULT_OK, result);
172 }
173 
174 /**
175  * @tc.name: NWebPasteboardAdapter_NewRecord_003.
176  * @tc.desc: Test the NewRecord.
177  * @tc.type: FUNC
178  * @tc.require:issueI5O4BN
179  */
180 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_NewRecord_003, TestSize.Level1)
181 {
182     int result = 0;
183     std::shared_ptr<PasteDataRecordAdapter> record =
184         PasteDataRecordAdapter::NewRecord(g_mimeType, g_htmlText, g_plainText);
185     if (record == nullptr) {
186         result = -1;
187     }
188     EXPECT_EQ(RESULT_OK, result);
189 }
190 
191 /**
192  * @tc.name: NWebPasteboardAdapter_GetMimeType_004.
193  * @tc.desc: Test the GetMimeType.
194  * @tc.type: FUNC
195  * @tc.require:issueI5O4BN
196  */
197 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetMimeType_004, TestSize.Level1)
198 {
199     int ret = 0;
200     std::string mimeType = g_paster->GetMimeType();
201     if (mimeType.empty()) {
202         ret = -1;
203     }
204     EXPECT_EQ(RESULT_OK, ret);
205     mimeType = g_pasternull->GetMimeType();
206     if (mimeType.empty()) {
207         ret = -1;
208     }
209     EXPECT_NE(RESULT_OK, ret);
210 }
211 
212 /**
213  * @tc.name: NWebPasteboardAdapter_GetHtmlText_005.
214  * @tc.desc: Test the GetHtmlText.
215  * @tc.type: FUNC
216  * @tc.require:issueI5O4BN
217  */
218 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetHtmlText_005, TestSize.Level1)
219 {
220     int result = 0;
221     std::shared_ptr<std::string> htmlText = g_paster->GetHtmlText();
222     if (htmlText == nullptr) {
223         result = -1;
224     }
225     EXPECT_EQ(RESULT_OK, result);
226     std::shared_ptr<std::string> html = g_pasternull->GetHtmlText();
227     if (html == nullptr) {
228         result = -1;
229     }
230     EXPECT_NE(RESULT_OK, result);
231 }
232 
233 /**
234  * @tc.name: NWebPasteboardAdapter_GetPlainText_006.
235  * @tc.desc: Test the GetPlainText.
236  * @tc.type: FUNC
237  * @tc.require:issueI5O4BN
238  */
239 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPlainText_006, TestSize.Level1)
240 {
241     int result = 0;
242     std::shared_ptr<std::string> plainText = g_paster->GetPlainText();
243     if (plainText == nullptr) {
244         result = -1;
245     }
246     EXPECT_EQ(RESULT_OK, result);
247     std::shared_ptr<std::string> plain = g_pasternull->GetPlainText();
248     if (plain == nullptr) {
249         result = -1;
250     }
251     EXPECT_NE(RESULT_OK, result);
252 }
253 
254 /**
255  * @tc.name: NWebPasteboardAdapter_GetRecord_007.
256  * @tc.desc: Test the GetRecord.
257  * @tc.type: FUNC
258  * @tc.require:issueI5O4BN
259  */
260 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecord_007, TestSize.Level1)
261 {
262     int result = 0;
263     std::shared_ptr<PasteDataRecord> record = g_paster->GetRecord();
264     if (record == nullptr) {
265         result = -1;
266     }
267     EXPECT_EQ(RESULT_OK, result);
268 }
269 
270 /**
271  * @tc.name: NWebPasteboardAdapter_PasteDataAdapterImpl_008.
272  * @tc.desc: Test the PasteDataAdapterImpl.
273  * @tc.type: FUNC
274  * @tc.require:issueI5O4BN
275  */
276 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataAdapterImpl_008, TestSize.Level1)
277 {
278     int result = 0;
279     g_dataAdapter = std::make_shared<PasteDataAdapterImpl>();
280     if (g_dataAdapter == nullptr) {
281         result = -1;
282     }
283     EXPECT_EQ(RESULT_OK, result);
284 }
285 
286 /**
287  * @tc.name: NWebPasteboardAdapter_PasteDataAdapterImpl_009.
288  * @tc.desc: Test the PasteDataAdapterImpl.
289  * @tc.type: FUNC
290  * @tc.require:issueI5O4BB
291  */
292 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataAdapterImpl_009, TestSize.Level1)
293 {
294     int result = 0;
295     std::shared_ptr<PasteData> data = std::make_shared<PasteData>();
296     if (data == nullptr) {
297         result = -1;
298     }
299     EXPECT_EQ(RESULT_OK, result);
300     std::shared_ptr<PasteDataAdapterImpl> dataAdapter = std::make_shared<PasteDataAdapterImpl>(data);
301     if (dataAdapter == nullptr) {
302         result = -1;
303     }
304     EXPECT_EQ(RESULT_OK, result);
305 }
306 
307 /**
308  * @tc.name: NWebPasteboardAdapter_AddHtmlRecord_010.
309  * @tc.desc: Test the AddHtmlRecord.
310  * @tc.type: FUNC
311  * @tc.require:issueI5O4BB
312  */
313 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AddHtmlRecord_010, TestSize.Level1)
314 {
315     std::string htmlName = "test";
316     g_dataAdapter->AddHtmlRecord(htmlName);
317     g_dataAdapterNull->AddHtmlRecord(htmlName);
318 }
319 
320 /**
321  * @tc.name: NWebPasteboardAdapter_AddTextRecord_011.
322  * @tc.desc: Test the AddTextRecord.
323  * @tc.type: FUNC
324  * @tc.require:issueI5O4BB
325  */
326 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AddTextRecord_011, TestSize.Level1)
327 {
328     std::string htmlName = "test";
329     g_dataAdapter->AddTextRecord(htmlName);
330     g_dataAdapterNull->AddTextRecord(htmlName);
331 }
332 
333 /**
334  * @tc.name: NWebPasteboardAdapter_GetMimeTypes_012.
335  * @tc.desc: Test the GetMimeTypes.
336  * @tc.type: FUNC
337  * @tc.require:issueI5O4BB
338  */
339 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetMimeTypes_012, TestSize.Level1)
340 {
341     int result = 0;
342     std::vector<std::string> mimeTypes = g_dataAdapter->GetMimeTypes();
343     if (mimeTypes.empty()) {
344         result = -1;
345     }
346     EXPECT_EQ(RESULT_OK, result);
347     std::vector<std::string> types = g_dataAdapterNull->GetMimeTypes();
348     if (types.empty()) {
349         result = -1;
350     }
351     EXPECT_NE(RESULT_OK, result);
352 }
353 
354 /**
355  * @tc.name: NWebPasteboardAdapter_GetPrimaryHtml_013.
356  * @tc.desc: Test the GetPrimaryHtml.
357  * @tc.type: FUNC
358  * @tc.require:issueI5O4BB
359  */
360 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryHtml_013, TestSize.Level1)
361 {
362     int result = 0;
363     std::shared_ptr<std::string> primaryHtml = g_dataAdapter->GetPrimaryHtml();
364     if (primaryHtml == nullptr) {
365         result = -1;
366     }
367     EXPECT_EQ(RESULT_OK, result);
368     std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryHtml();
369     if (primary == nullptr) {
370         result = -1;
371     }
372     EXPECT_NE(RESULT_OK, result);
373 }
374 
375 /**
376  * @tc.name: NWebPasteboardAdapter_GetPrimaryText_014.
377  * @tc.desc: Test the GetPrimaryText.
378  * @tc.type: FUNC
379  * @tc.require:issueI5O4BB
380  */
381 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryText_014, TestSize.Level1)
382 {
383     int result = 0;
384     std::size_t index = 0;
385     std::shared_ptr<std::string> primaryText = g_dataAdapter->GetPrimaryText();
386     if (primaryText == nullptr) {
387         result = -1;
388     }
389     EXPECT_EQ(RESULT_OK, result);
390     result = 0;
391     std::shared_ptr<PasteDataRecordAdapter> record = g_dataAdapter->GetRecordAt(index);
392     if (record == nullptr) {
393         result = -1;
394     }
395     EXPECT_EQ(RESULT_OK, result);
396     result = 0;
397     PasteRecordList recordList = g_dataAdapter->AllRecords();
398     if (recordList.empty()) {
399         result = -1;
400     }
401     EXPECT_EQ(RESULT_OK, result);
402     result = 0;
403     std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryText();
404     if (primary == nullptr) {
405         result = -1;
406     }
407     EXPECT_NE(RESULT_OK, result);
408 }
409 
410 /**
411  * @tc.name: NWebPasteboardAdapter_GetPrimaryMimeType_015.
412  * @tc.desc: Test the GetPrimaryMimeType.
413  * @tc.type: FUNC
414  * @tc.require:issueI5O4BB
415  */
416 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPrimaryMimeType_015, TestSize.Level1)
417 {
418     int result = 0;
419     std::shared_ptr<std::string> primaryMimeType = g_dataAdapter->GetPrimaryMimeType();
420     if (primaryMimeType == nullptr) {
421         result = -1;
422     }
423     EXPECT_EQ(RESULT_OK, result);
424     std::shared_ptr<std::string> primary = g_dataAdapterNull->GetPrimaryMimeType();
425     if (primary == nullptr) {
426         result = -1;
427     }
428     EXPECT_NE(RESULT_OK, result);
429 }
430 
431 /**
432  * @tc.name: NWebPasteboardAdapter_GetRecordAt_016.
433  * @tc.desc: Test the GetRecordAt.
434  * @tc.type: FUNC
435  * @tc.require:issueI5O4BB
436  */
437 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordAt_016, TestSize.Level1)
438 {
439     int result = 0;
440     std::size_t index = 1;
441     std::shared_ptr<PasteDataRecordAdapter> record = g_dataAdapterNull->GetRecordAt(index);
442     if (record == nullptr) {
443         result = -1;
444     }
445     EXPECT_NE(RESULT_OK, result);
446 }
447 
448 /**
449  * @tc.name: NWebPasteboardAdapter_GetRecordAt_017.
450  * @tc.desc: Test the GetRecordAt.
451  * @tc.type: FUNC
452  * @tc.require:issueI5O4B5
453  */
454 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordAt_017, TestSize.Level1)
455 {
456     int result = 0;
457     std::size_t index = 0;
458     MockPasteData *mock1 = new MockPasteData();
459     g_dataAdapterNull->data_.reset((PasteData *)mock1);
460     std::shared_ptr<PasteDataRecordAdapter> str = g_dataAdapterNull->GetRecordAt(index);
461     if (str == nullptr) {
462         result = -1;
463     }
464     EXPECT_NE(RESULT_OK, result);
465     g_dataAdapterNull->data_ = nullptr;
466 }
467 
468 /**
469  * @tc.name: NWebPasteboardAdapter_GetRecordCount_018.
470  * @tc.desc: Test the GetRecordCount.
471  * @tc.type: FUNC
472  * @tc.require:issueI5O4B5
473  */
474 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetRecordCount_018, TestSize.Level1)
475 {
476     int result = 0;
477     std::size_t record = g_dataAdapterNull->GetRecordCount();
478     if (record != 0) {
479         result = -1;
480     }
481     EXPECT_EQ(RESULT_OK, result);
482     result = 0;
483     MockPasteData *mock2 = new MockPasteData();
484     g_dataAdapterNull->data_.reset((PasteData *)mock2);
485     std::size_t count = g_dataAdapterNull->GetRecordCount();
486     EXPECT_EQ(RESULT_OK, count);
487     g_dataAdapterNull->data_ = nullptr;
488 }
489 
490 /**
491  * @tc.name: NWebPasteboardAdapter_AllRecords_019.
492  * @tc.desc: Test the AllRecords.
493  * @tc.type: FUNC
494  * @tc.require:issueI5O4B5
495  */
496 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_AllRecords_019, TestSize.Level1)
497 {
498     int result = 0;
499     PasteRecordList record = g_dataAdapterNull->AllRecords();
500     if (record.empty()) {
501         result = -1;
502     }
503     EXPECT_NE(RESULT_OK, result);
504     result = 0;
505     MockPasteData *mock = new MockPasteData();
506     g_dataAdapterNull->data_.reset((PasteData *)mock);
507     PasteRecordList str = g_dataAdapterNull->AllRecords();
508     if (str.empty()) {
509         result = -1;
510     }
511     EXPECT_NE(RESULT_OK, result);
512 }
513 
514 /**
515  * @tc.name: NWebPasteboardAdapter_GetInstance_020.
516  * @tc.desc: Test the GetInstance.
517  * @tc.type: FUNC
518  * @tc.require:issueI5O4B5
519  */
520 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetInstance_020, TestSize.Level1)
521 {
522     PasteBoardClientAdapterImpl::GetInstance();
523 }
524 
525 /**
526  * @tc.name: NWebPasteboardAdapter_SetPasteData_021.
527  * @tc.desc: Test the SetPasteData.
528  * @tc.type: FUNC
529  * @tc.require:issueI5O4B5
530  */
531 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPasteData_021, TestSize.Level1)
532 {
533     int result = 0;
534     PasteRecordList data;
535     std::shared_ptr<PasteDataRecordAdapter> record = PasteDataRecordAdapter::NewRecord("text/html");
536     if (record == nullptr) {
537         result = -1;
538     }
539     std::shared_ptr<std::string> pasteData = std::make_shared<std::string>("test");
540     record->SetHtmlText(pasteData);
541     data.push_back(record);
542     PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data);
543 }
544 
545 /**
546  * @tc.name: NWebPasteboardAdapter_GetPasteData_022.
547  * @tc.desc: Test the GetPasteData.
548  * @tc.type: FUNC
549  * @tc.require:issueI5O4B5
550  */
551 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetPasteData_022, TestSize.Level1)
552 {
553     PasteBoardClientAdapterImpl::GetInstance().Clear();
554     PasteRecordList data;
555     bool result = PasteBoardClientAdapterImpl::GetInstance().GetPasteData(data);
556     EXPECT_EQ(false, result);
557 }
558 
559 /**
560  * @tc.name: NWebPasteboardAdapter_HasPasteData_023.
561  * @tc.desc: Test the HasPasteData.
562  * @tc.type: FUNC
563  * @tc.require:issueI5O4B5
564  */
565 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_HasPasteData_023, TestSize.Level1)
566 {
567     bool result = PasteBoardClientAdapterImpl::GetInstance().HasPasteData();
568     EXPECT_EQ(false, result);
569 }
570 
571 /**
572  * @tc.name: NWebPasteboardAdapter_PasteDataRecordAdapterImpl_024.
573  * @tc.desc: Test the PasteDataRecordAdapterImpl.
574  * @tc.type: FUNC
575  * @tc.require:issueI5O4B5
576  */
577 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_PasteDataRecordAdapterImpl_024, TestSize.Level1)
578 {
579     int result = 0;
580     std::string mimeType = "test";
581     std::shared_ptr<PasteDataRecordAdapterImpl> datarecord = std::make_shared<PasteDataRecordAdapterImpl>(mimeType);
582     if (datarecord == nullptr) {
583         result = -1;
584     }
585     EXPECT_EQ(RESULT_OK, result);
586 }
587 
588 /**
589  * @tc.name: NWebPasteboardAdapter_NewRecord_025.
590  * @tc.desc: Test the NewRecord.
591  * @tc.type: FUNC
592  * @tc.require:issueI5O4B5
593  */
594 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_NewRecord_025, TestSize.Level1)
595 {
596     int result = 0;
597     std::string mimeType = "test";
598     std::shared_ptr<PasteDataRecordAdapter> record = PasteDataRecordAdapter::NewRecord(mimeType);
599     if (record == nullptr) {
600         result = -1;
601     }
602     EXPECT_EQ(RESULT_OK, result);
603 }
604 
605 /**
606  * @tc.name: NWebPasteboardAdapter_SetHtmlText_026.
607  * @tc.desc: Test the SetHtmlText.
608  * @tc.type: FUNC
609  * @tc.require:issueI5O4B5
610  */
611 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetHtmlText_026, TestSize.Level1)
612 {
613     int result = 0;
614     std::shared_ptr<std::string> htmlText = std::make_shared<std::string>("test");
615     if (htmlText == nullptr) {
616         result = -1;
617     }
618     EXPECT_EQ(RESULT_OK, result);
619     bool reset = g_datarecordnull->SetHtmlText(htmlText);
620     EXPECT_NE(TRUE_OK, reset);
621     reset = g_datarecord->SetHtmlText(htmlText);
622     EXPECT_EQ(TRUE_OK, reset);
623 }
624 
625 /**
626  * @tc.name: NWebPasteboardAdapter_SetPlainText_027.
627  * @tc.desc: Test the SetPlainText.
628  * @tc.type: FUNC
629  * @tc.require:issueI5O4B5
630  */
631 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetPlainText_027, TestSize.Level1)
632 {
633     int result = 0;
634     std::shared_ptr<std::string> plainText = std::make_shared<std::string>("test");
635     if (plainText == nullptr) {
636         result = -1;
637     }
638     EXPECT_EQ(RESULT_OK, result);
639     bool reset = g_datarecordnull->SetPlainText(plainText);
640     EXPECT_NE(TRUE_OK, reset);
641     reset = g_datarecord->SetPlainText(plainText);
642     EXPECT_EQ(TRUE_OK, reset);
643 }
644 
645 /**
646  * @tc.name: NWebPasteboardAdapter_ImageToClipboardAlphaType_028.
647  * @tc.desc: Test the ImageToClipboardAlphaType.
648  * @tc.type: FUNC
649  * @tc.require:issueI5O4B5
650  */
651 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardAlphaType_028, TestSize.Level1)
652 {
653     Media::ImageInfo imgInfo;
654     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN;
655     ClipBoardImageAlphaType result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
656     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
657 
658     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE;
659     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
660     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE);
661 
662     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL;
663     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
664     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED);
665 
666     imgInfo.alphaType = Media::AlphaType::IMAGE_ALPHA_TYPE_UNPREMUL;
667     result = g_datarecord->ImageToClipboardAlphaType(imgInfo);
668     EXPECT_EQ(result, ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN);
669 }
670 
671 /**
672  * @tc.name: NWebPasteboardAdapter_ImageToClipboardColorType_029.
673  * @tc.desc: Test the ImageToClipboardColorType.
674  * @tc.type: FUNC
675  * @tc.require:issueI5O4AZ
676  */
677 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ImageToClipboardColorType_029, TestSize.Level1)
678 {
679     Media::ImageInfo imgInfo;
680     imgInfo.pixelFormat = Media::PixelFormat::RGBA_8888;
681     ClipBoardImageColorType result = g_datarecord->ImageToClipboardColorType(imgInfo);
682     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_RGBA_8888);
683 
684     imgInfo.pixelFormat = Media::PixelFormat::BGRA_8888;
685     result = g_datarecord->ImageToClipboardColorType(imgInfo);
686     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_BGRA_8888);
687 
688     imgInfo.pixelFormat = Media::PixelFormat::RGBA_F16;
689     result = g_datarecord->ImageToClipboardColorType(imgInfo);
690     EXPECT_EQ(result, ClipBoardImageColorType::COLOR_TYPE_UNKNOWN);
691 }
692 
693 /**
694  * @tc.name: NWebPasteboardAdapter_ClipboardToImageAlphaType_030.
695  * @tc.desc: Test the ClipboardToImageAlphaType.
696  * @tc.type: FUNC
697  * @tc.require:issueI5O4AZ
698  */
699 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageAlphaType_030, TestSize.Level1)
700 {
701     ClipBoardImageAlphaType alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN;
702     Media::AlphaType result = g_datarecord->ClipboardToImageAlphaType(alphaType);
703     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
704 
705     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_OPAQUE;
706     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
707     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_OPAQUE);
708 
709     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_PREMULTIPLIED;
710     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
711     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_PREMUL);
712 
713     alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_POSTMULTIPLIED;
714     result = g_datarecord->ClipboardToImageAlphaType(alphaType);
715     EXPECT_EQ(result, Media::AlphaType::IMAGE_ALPHA_TYPE_UNKNOWN);
716 }
717 
718 /**
719  * @tc.name: NWebPasteboardAdapter_ClipboardToImageColorType_031.
720  * @tc.desc: Test the ClipboardToImageColorType.
721  * @tc.type: FUNC
722  * @tc.require:issueI5O4AZ
723  */
724 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_ClipboardToImageColorType_031, TestSize.Level1)
725 {
726     ClipBoardImageColorType colorType = ClipBoardImageColorType::COLOR_TYPE_RGBA_8888;
727     Media::PixelFormat result = g_datarecord->ClipboardToImageColorType(colorType);
728     EXPECT_EQ(result, Media::PixelFormat::RGBA_8888);
729 
730     colorType = ClipBoardImageColorType::COLOR_TYPE_BGRA_8888;
731     result = g_datarecord->ClipboardToImageColorType(colorType);
732     EXPECT_EQ(result, Media::PixelFormat::BGRA_8888);
733 
734     colorType = ClipBoardImageColorType::COLOR_TYPE_UNKNOWN;
735     result = g_datarecord->ClipboardToImageColorType(colorType);
736     EXPECT_EQ(result, Media::PixelFormat::UNKNOWN);
737 }
738 
739 /**
740  * @tc.name: NWebPasteboardAdapter_SetImgData_032.
741  * @tc.desc: Test the SetImgData.
742  * @tc.type: FUNC
743  * @tc.require:issueI5O4AZ
744  */
745 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetImgData_032, TestSize.Level1)
746 {
747     uint32_t storage[][5] = {
748         {0xCA, 0xDA, 0xCA, 0xC9, 0xA3},
749         {0xAC, 0xA8, 0x89, 0x47, 0x87},
750         {0x4B, 0x25, 0x25, 0x25, 0x46},
751         {0x90, 0x1, 0x25, 0x41, 0x33},
752         {0x75, 0x55, 0x44, 0x20, 0x00},
753     };
754     ClipBoardImageData *image = new ClipBoardImageData;
755     image->colorType = ClipBoardImageColorType::COLOR_TYPE_BGRA_8888;
756     image->alphaType = ClipBoardImageAlphaType::ALPHA_TYPE_UNKNOWN;
757     image->data = storage[0];
758     image->dataSize = sizeof(storage);
759     image->rowBytes = 5;
760     image->width = 5;
761     image->height = 5;
762     std::shared_ptr<ClipBoardImageData> imageData(image);
763     bool reset = g_datarecord->SetImgData(imageData);
764     EXPECT_EQ(TRUE_OK, reset);
765     reset = g_datarecordnull->SetImgData(imageData);
766     EXPECT_NE(TRUE_OK, reset);
767     imageData->dataSize = 1;
768     reset = g_datarecordnull->SetImgData(imageData);
769     EXPECT_NE(TRUE_OK, reset);
770     imageData = nullptr;
771     reset = g_datarecordnull->SetImgData(imageData);
772     EXPECT_NE(TRUE_OK, reset);
773 }
774 
775 /**
776  * @tc.name: NWebPasteboardAdapter_GetImgData_033.
777  * @tc.desc: Test the GetImgData.
778  * @tc.type: FUNC
779  * @tc.require:issueI5O4AZ
780  */
781 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_033, TestSize.Level1)
782 {
783     ClipBoardImageData image;
784     bool reset = g_datarecordnull->GetImgData(image);
785     EXPECT_NE(TRUE_OK, reset);
786     reset = g_paster->GetImgData(image);
787     EXPECT_NE(TRUE_OK, reset);
788 }
789 
790 /**
791  * @tc.name: NWebPasteboardAdapter_GetImgData_034.
792  * @tc.desc: Test the GetImgData.
793  * @tc.type: FUNC
794  * @tc.require:issueI5O4AZ
795  */
796 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetImgData_034, TestSize.Level1)
797 {
798     ClipBoardImageData image;
799     bool reset = g_datarecord->GetImgData(image);
800     EXPECT_EQ(TRUE_OK, reset);
801 }
802 
803 /**
804  * @tc.name: NWebPasteboardAdapter_Clear_035.
805  * @tc.desc: Test the Clear.
806  * @tc.type: FUNC
807  * @tc.require:issueI5O4AZ
808  */
809 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_035, TestSize.Level1)
810 {
811     uint32_t bufferSize = 20;
812     if (g_datarecord->imgBuffer_ == nullptr) {
813         g_datarecord->imgBuffer_ = static_cast<uint8_t *>(calloc(static_cast<size_t>(bufferSize), sizeof(uint8_t)));
814     }
815     g_datarecord->Clear();
816 }
817 
818 /**
819  * @tc.name: NWebPasteboardAdapter_Clear_036.
820  * @tc.desc: Test the Clear.
821  * @tc.type: FUNC
822  * @tc.require:issueI5O4AZ
823  */
824 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_Clear_036, TestSize.Level1)
825 {
826     PasteRecordList data;
827     data.clear();
828     PasteBoardClientAdapterImpl::GetInstance().Clear();
829     PasteBoardClientAdapterImpl::GetInstance().SetPasteData(data);
830     PasteBoardClientAdapterImpl::GetInstance().Clear();
831 }
832 
833 /**
834  * @tc.name: NWebPasteboardAdapter_SetUri_037.
835  * @tc.desc: Test the SetUri.
836  * @tc.type: FUNC
837  * @tc.require:issueI5QA3D
838  */
839 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetUri_037, TestSize.Level1)
840 {
841     int result = 0;
842     std::string emptyTestUri = "";
843     std::string testUri = "/data/test/path";
844     EXPECT_EQ(RESULT_OK, result);
845     bool reset = g_datarecordnull->SetUri(testUri);
846     EXPECT_NE(TRUE_OK, reset);
847     reset = g_datarecord->SetUri(emptyTestUri);
848     EXPECT_NE(TRUE_OK, reset);
849     reset = g_datarecord->SetUri(testUri);
850     EXPECT_EQ(TRUE_OK, reset);
851 }
852 
853 /**
854  * @tc.name: NWebPasteboardAdapter_SetCustomData_038.
855  * @tc.desc: Test the SetCustomData.
856  * @tc.type: FUNC
857  * @tc.require:issueI5QA3D
858  */
859 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_SetCustomData_038, TestSize.Level1)
860 {
861     int result = 0;
862     PasteCustomData emptyTestData;
863     std::string format = "format";
864     vector<uint8_t> data = {0, 1, 2};
865     PasteCustomData testData;
866     testData.insert(std::make_pair(format, data));
867     EXPECT_EQ(RESULT_OK, result);
868     bool reset = g_datarecordnull->SetCustomData(testData);
869     EXPECT_NE(TRUE_OK, reset);
870     reset = g_datarecord->SetCustomData(emptyTestData);
871     EXPECT_NE(TRUE_OK, reset);
872     reset = g_datarecord->SetCustomData(testData);
873     EXPECT_EQ(TRUE_OK, reset);
874 }
875 
876 /**
877  * @tc.name: NWebPasteboardAdapter_GetUri_039.
878  * @tc.desc: Test the GetUri.
879  * @tc.type: FUNC
880  * @tc.require:issueI5O4BN
881  */
882 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetUri_039, TestSize.Level1)
883 {
884     int result = 0;
885     g_datarecord->SetUri("/data/test/path");
886     std::shared_ptr<std::string> uri = g_datarecord->GetUri();
887     if (uri == nullptr) {
888         result = -1;
889     }
890     EXPECT_EQ(RESULT_OK, result);
891     g_datarecord->record_ = g_datarecord->builder_->SetUri(nullptr).Build();
892     uri = g_datarecord->GetUri();
893     if (uri == nullptr) {
894         result = -1;
895     }
896     EXPECT_NE(RESULT_OK, result);
897     uri = g_pasternull->GetUri();
898     if (uri == nullptr) {
899         result = -1;
900     }
901     EXPECT_NE(RESULT_OK, result);
902 }
903 
904 /**
905  * @tc.name: NWebPasteboardAdapter_GetCustomData_040.
906  * @tc.desc: Test the GetCustomData.
907  * @tc.type: FUNC
908  * @tc.require:issueI5O4BN
909  */
910 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_GetCustomData_040, TestSize.Level1)
911 {
912     int result = 0;
913     std::string format = "format";
914     vector<uint8_t> data = {0, 1, 2};
915     PasteCustomData testData;
916     g_datarecord->SetCustomData(testData);
917     std::shared_ptr<PasteCustomData> customData = g_datarecord->GetCustomData();
918     if (customData == nullptr) {
919         result = -1;
920     }
921     EXPECT_EQ(RESULT_OK, result);
922     g_datarecord->record_ = g_datarecord->builder_->SetCustomData(nullptr).Build();
923     customData = g_datarecord->GetCustomData();
924     if (customData == nullptr) {
925         result = -1;
926     }
927     EXPECT_NE(RESULT_OK, result);
928     customData = g_pasternull->GetCustomData();
929     if (customData == nullptr) {
930         result = -1;
931     }
932     EXPECT_NE(RESULT_OK, result);
933 }
934 
935 /**
936  * @tc.name: NWebPasteboardAdapter_OpenRemoteUri_041.
937  * @tc.desc: Test the OpenRemoteUri.
938  * @tc.type: FUNC
939  * @tc.require:issueI5O4BN
940  */
941 HWTEST_F(NWebPasteboardAdapterTest, NWebPasteboardAdapter_OpenRemoteUri_041, TestSize.Level1)
942 {
943     std::string testUri = "datashare:////#fdFromBinder=155";
944     int32_t fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testUri);
945     EXPECT_EQ(155, fd);
946     std::string testInvalidUri = "www.example.com";
947     fd = PasteBoardClientAdapterImpl::GetInstance().OpenRemoteUri(testInvalidUri);
948     EXPECT_EQ(-1, fd);
949 }
950 
951 /**
952  * @tc.name: PasteBoardClientAdapterImpl_GetTokenId_042.
953  * @tc.desc: Test the GetTokenId.
954  * @tc.type: FUNC
955  * @tc.require:issueI5O4BN
956  */
957 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_GetTokenId_042, TestSize.Level1)
958 {
959     PasteBoardClientAdapterImpl::GetInstance().Clear();
960     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().GetTokenId());
961 }
962 
963 /**
964  * @tc.name: PasteBoardClientAdapterImpl_IsLocalPaste_043.
965  * @tc.desc: Test the IsLocalPaste.
966  * @tc.type: FUNC
967  * @tc.require:issueI5O4BN
968  */
969 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_IsLocalPaste_043, TestSize.Level1)
970 {
971     PasteBoardClientAdapterImpl::GetInstance().Clear();
972     EXPECT_EQ(false, PasteBoardClientAdapterImpl::GetInstance().IsLocalPaste());
973 }
974 
975 /**
976  * @tc.name: PasteboardObserverAdapter_OnPasteboardChanged_044.
977  * @tc.desc: Test the CreatePasteboardObserver.
978  * @tc.type: FUNC
979  * @tc.require:issueI5O4BN
980  */
981 HWTEST_F(NWebPasteboardAdapterTest, PasteboardObserverAdapter_OnPasteboardChanged_044, TestSize.Level1)
982 {
983     std::shared_ptr<PasteboardObserverAdapter> observer =
984         std::make_shared<MockPasteboardObserver>();
985     PasteboardObserverAdapterImpl observerImpl(observer);
986     observerImpl.OnPasteboardChanged();
987     observerImpl.observer_ = nullptr;
988     observerImpl.OnPasteboardChanged();
989 }
990 
991 /**
992  * @tc.name: PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_045.
993  * @tc.desc: Test the AddPasteboardChangedObserver.
994  * @tc.type: FUNC
995  * @tc.require:issueI5O4BN
996  */
997 HWTEST_F(NWebPasteboardAdapterTest, PasteBoardClientAdapterImpl_AddPasteboardChangedObserver_045, TestSize.Level1)
998 {
999     std::shared_ptr<PasteboardObserverAdapter> observer =
1000         std::make_shared<MockPasteboardObserver>();
1001     std::shared_ptr<PasteboardObserverAdapter> observerInvalid =
1002         std::make_shared<MockPasteboardObserver>();
1003     PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(observer);
1004     PasteBoardClientAdapterImpl::GetInstance().AddPasteboardChangedObserver(nullptr);
1005     EXPECT_EQ(1, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1006     PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(observer);
1007     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1008     PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(observerInvalid);
1009     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1010     PasteBoardClientAdapterImpl::GetInstance().RemovePasteboardChangedObserver(nullptr);
1011     EXPECT_EQ(0, PasteBoardClientAdapterImpl::GetInstance().reg_.size());
1012 }
1013 }