• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdio>
17 #include <gtest/gtest.h>
18 
19 #include "clip/clip_plugin.h"
20 #include "clip_factory.h"
21 #include "common/block_object.h"
22 #include "int_wrapper.h"
23 #include "pasteboard_client.h"
24 #include "pasteboard_service_loader.h"
25 
26 namespace OHOS::MiscServices {
27 using namespace testing::ext;
28 using namespace testing;
29 using namespace OHOS::AAFwk;
30 using namespace OHOS::Media;
31 constexpr const int32_t INVALID_FD = -1;
32 constexpr const char *FILE_URI = "/data/test/resource/pasteboardTest.txt";
33 constexpr const char *REMOTE_FILE_SIZE_LONG = "remoteFileSizeLong";
34 constexpr const char *REMOTE_FILE_SIZE = "remoteFileSize";
35 class PasteDataTest : public testing::Test {
36 public:
37     static void SetUpTestCase(void);
38     static void TearDownTestCase(void);
39     void SetUp();
40     void TearDown();
41 };
42 
SetUpTestCase(void)43 void PasteDataTest::SetUpTestCase(void) { }
44 
TearDownTestCase(void)45 void PasteDataTest::TearDownTestCase(void) { }
46 
SetUp(void)47 void PasteDataTest::SetUp(void) { }
48 
TearDown(void)49 void PasteDataTest::TearDown(void) { }
50 
ClipFactory()51 ClipFactory::ClipFactory()
52 {
53     ClipPlugin::RegCreator("distributed_clip", this);
54 }
55 
56 /**
57  * @tc.name: AddRecord001
58  * @tc.desc: PasteDataRecord AddRecord
59  * @tc.type: FUNC
60  */
61 HWTEST_F(PasteDataTest, AddRecord001, TestSize.Level0)
62 {
63     PasteData data;
64     PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI);
65     std::string uriStr = FILE_URI;
66     auto uri = std::make_shared<OHOS::Uri>(uriStr);
67     builder.SetUri(uri);
68     auto record = builder.Build();
69     EXPECT_TRUE(record != nullptr);
70     data.AddRecord(nullptr);
71     auto count = data.GetRecordCount();
72     EXPECT_TRUE(count == 0);
73 }
74 
75 /**
76  * @tc.name: AddRecord002
77  * @tc.desc: PasteDataRecord AddRecord
78  * @tc.type: FUNC
79  */
80 HWTEST_F(PasteDataTest, AddRecord002, TestSize.Level0)
81 {
82     PasteData data;
83     PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI);
84     std::string uriStr = FILE_URI;
85     auto uri = std::make_shared<OHOS::Uri>(uriStr);
86     builder.SetUri(uri);
87     auto record = builder.Build();
88     data.AddRecord(*record);
89     auto count = data.GetRecordCount();
90     EXPECT_TRUE(count == 1);
91 }
92 
93 /**
94  * @tc.name: AddRecord003
95  * @tc.desc: PasteDataRecord AddRecord, add multi records and check the order of records of data.
96  * @tc.type: FUNC
97  */
98 HWTEST_F(PasteDataTest, AddRecord003, TestSize.Level0)
99 {
100     std::vector<std::string> testTextVec = { "text001", "text002", "text003" };
101     std::vector<std::string> expectTextVec = { "text003", "text002", "text001" };
102     PasteData data;
103     for (const auto &itText : testTextVec) {
104         PasteDataRecord::Builder builder(MIMETYPE_TEXT_PLAIN);
105         auto text = std::make_shared<std::string>(itText);
106         auto record = builder.SetPlainText(text).Build();
107         ASSERT_TRUE(record != nullptr);
108         data.AddRecord(*record);
109     }
110 
111     auto count = data.GetRecordCount();
112     EXPECT_TRUE(count == testTextVec.size());
113 
114     std::vector<std::string> result;
115     for (const auto &itRec : data.AllRecords()) {
116         ASSERT_TRUE(itRec != nullptr);
117         EXPECT_TRUE(itRec->GetMimeType() == MIMETYPE_TEXT_PLAIN);
118         auto plainText = itRec->GetPlainTextV0();
119         ASSERT_TRUE(plainText != nullptr);
120         result.emplace_back(*plainText);
121     }
122 
123     EXPECT_TRUE(result.size() == expectTextVec.size());
124     EXPECT_TRUE(std::equal(result.begin(), result.end(), expectTextVec.begin(), expectTextVec.end()));
125 }
126 
127 /**
128  * @tc.name: AddRecord004
129  * @tc.desc: PasteDataRecord AddHtmlRecord, add multi records and check the order of records of data.
130  * @tc.type: FUNC
131  */
132 HWTEST_F(PasteDataTest, AddRecord004, TestSize.Level0)
133 {
134     std::vector<std::string> testHtmlVec = {
135         "<div class='disable'>html001</div>",
136         "<div class='disable'>html002</div>",
137         "<div class='disable'>html003</div>"
138     };
139     std::vector<std::string> expectHtmlVec = {
140         "<div class='disable'>html003</div>",
141         "<div class='disable'>html002</div>",
142         "<div class='disable'>html001</div>"
143     };
144     PasteData data;
145     for (const auto &itHtml: testHtmlVec) {
146         data.AddHtmlRecord(itHtml);
147     }
148 
149     auto count = data.GetRecordCount();
150     EXPECT_TRUE(count == testHtmlVec.size());
151 
152     std::vector<std::string> result;
153     for (const auto &itRec : data.AllRecords()) {
154         ASSERT_TRUE(itRec != nullptr);
155         EXPECT_TRUE(itRec->GetMimeType() == MIMETYPE_TEXT_HTML);
156         auto htmlText = itRec->GetHtmlTextV0();
157         ASSERT_TRUE(htmlText != nullptr);
158         result.emplace_back(*htmlText);
159     }
160 
161     EXPECT_TRUE(result.size() == expectHtmlVec.size());
162     EXPECT_TRUE(std::equal(result.begin(), result.end(), expectHtmlVec.begin(), expectHtmlVec.end()));
163 }
164 
165 /**
166  * @tc.name: AddRecord005
167  * @tc.desc: PasteDataRecord AddTextRecord, add multi records and check the order of records of data.
168  * @tc.type: FUNC
169  */
170 HWTEST_F(PasteDataTest, AddRecord005, TestSize.Level0)
171 {
172     std::vector<std::string> testTextVec = { "text101", "text102", "text103" };
173     std::vector<std::string> expectTextVec = { "text103", "text102", "text101" };
174     PasteData data;
175     for (const auto &itText: testTextVec) {
176         data.AddTextRecord(itText);
177     }
178 
179     auto count = data.GetRecordCount();
180     EXPECT_TRUE(count == testTextVec.size());
181 
182     std::vector<std::string> result;
183     for (const auto &itRec : data.AllRecords()) {
184         ASSERT_TRUE(itRec != nullptr);
185         EXPECT_TRUE(itRec->GetMimeType() == MIMETYPE_TEXT_PLAIN);
186         auto plainText = itRec->GetPlainTextV0();
187         ASSERT_TRUE(plainText != nullptr);
188         result.emplace_back(*plainText);
189     }
190 
191     EXPECT_TRUE(result.size() == expectTextVec.size());
192     EXPECT_TRUE(std::equal(result.begin(), result.end(), expectTextVec.begin(), expectTextVec.end()));
193 }
194 
195 /**
196  * @tc.name: AddRecord006
197  * @tc.desc: PasteDataRecord AddUriRecord, add multi records and check the order of records of data.
198  * @tc.type: FUNC
199  */
200 HWTEST_F(PasteDataTest, AddRecord006, TestSize.Level0)
201 {
202     std::vector<std::string> testUriVec = {
203         "file://pasteboard_service/test_uri_001",
204         "file://pasteboard_service/test_uri_002",
205         "file://pasteboard_service/test_uri_003"
206     };
207     std::vector<std::string> expectUriVec = {
208         "file://pasteboard_service/test_uri_003",
209         "file://pasteboard_service/test_uri_002",
210         "file://pasteboard_service/test_uri_001"
211     };
212     PasteData data;
213     for (const auto &itUri: testUriVec) {
214         data.AddUriRecord(OHOS::Uri(itUri));
215     }
216 
217     auto count = data.GetRecordCount();
218     EXPECT_TRUE(count == testUriVec.size());
219 
220     std::vector<std::string> result;
221     for (const auto &itRec : data.AllRecords()) {
222         ASSERT_TRUE(itRec != nullptr);
223         EXPECT_TRUE(itRec->GetMimeType() == MIMETYPE_TEXT_URI);
224         auto uri = itRec->GetUriV0();
225         ASSERT_TRUE(uri != nullptr);
226         result.emplace_back(uri->ToString());
227     }
228 
229     EXPECT_TRUE(result.size() == expectUriVec.size());
230     EXPECT_TRUE(std::equal(result.begin(), result.end(), expectUriVec.begin(), expectUriVec.end()));
231 }
232 
233 /**
234  * @tc.name: Marshalling001
235  * @tc.desc: PasteData Marshalling
236  * @tc.type: FUNC
237  */
238 HWTEST_F(PasteDataTest, Marshalling001, TestSize.Level0)
239 {
240     PasteData data1;
241     PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI);
242     std::string uriStr = FILE_URI;
243     auto uri = std::make_shared<OHOS::Uri>(uriStr);
244     builder.SetUri(uri);
245     auto record = builder.Build();
246     data1.AddRecord(*record);
247     auto count = data1.GetRecordCount();
248     EXPECT_TRUE(count == 1);
249     Parcel parcel;
250     data1.Marshalling(parcel);
251 
252     auto data2 = PasteData::Unmarshalling(parcel);
253     auto count2 = data2->GetRecordCount();
254     EXPECT_TRUE(count == count2);
255     std::shared_ptr<OHOS::Uri> uri2 = data2->GetPrimaryUri();
256     std::string uriStr2 = uri2->ToString();
257     EXPECT_TRUE(uriStr == uriStr2);
258 }
259 
260 /**
261  * @tc.name: MaxLength001
262  * @tc.desc: PasteDataRecord: maxLength NewHtmlRecord
263  * @tc.type: FUNC
264  * @tc.require:
265  * @tc.author:
266  */
267 HWTEST_F(PasteDataTest, MaxLength001, TestSize.Level0)
268 {
269     int maxLength = 100 * 1024 * 1024 + 1;
270     std::string res = "hello";
271     std::string temp = "world";
272     for (int i = 0; i < maxLength; i++) {
273         res += temp;
274     }
275     std::string htmlText = "<div class='disabled'>" + res + "</div>";
276     auto record = PasteboardClient::GetInstance()->CreateHtmlTextRecord(htmlText);
277     ASSERT_TRUE(record == nullptr);
278 }
279 
280 /**
281  * @tc.name: MaxLength002
282  * @tc.desc: PasteDataRecord: maxLength NewPlainTextRecord
283  * @tc.type: FUNC
284  * @tc.require:
285  * @tc.author:
286  */
287 HWTEST_F(PasteDataTest, MaxLength002, TestSize.Level0)
288 {
289     int maxLength = 100 * 1024 * 1024 + 1;
290     std::string plainText = "hello";
291     std::string temp = "world";
292     for (int i = 0; i < maxLength; i++) {
293         plainText += temp;
294     }
295     auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText);
296     ASSERT_TRUE(record == nullptr);
297 }
298 
299 /**
300  * @tc.name: ConvertToText001
301  * @tc.desc: PasteDataRecord: ConvertToText htmlText
302  * @tc.type: FUNC
303  * @tc.require: AR000HEECD
304  * @tc.author: chenyu
305  */
306 HWTEST_F(PasteDataTest, ConvertToText001, TestSize.Level0)
307 {
308     std::string htmlText = "<div class='disabled item tip user-programs'>";
309     auto record = PasteboardClient::GetInstance()->CreateHtmlTextRecord(htmlText);
310     ASSERT_TRUE(record != nullptr);
311     auto text = record->ConvertToText();
312     EXPECT_EQ(text, htmlText);
313 }
314 
315 /**
316  * @tc.name: ConvertToText002
317  * @tc.desc: PasteDataRecord: ConvertToText plainText
318  * @tc.type: FUNC
319  * @tc.require:
320  * @tc.author:
321  */
322 HWTEST_F(PasteDataTest, ConvertToText002, TestSize.Level0)
323 {
324     std::string plainText = "paste record test";
325     auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText);
326     ASSERT_TRUE(record != nullptr);
327     auto text = record->ConvertToText();
328     EXPECT_EQ(text, plainText);
329 }
330 
331 /**
332  * @tc.name: ConvertToText003
333  * @tc.desc: PasteDataRecord: ConvertToText uri
334  * @tc.type: FUNC
335  * @tc.require:
336  * @tc.author:
337  */
338 HWTEST_F(PasteDataTest, ConvertToText003, TestSize.Level0)
339 {
340     OHOS::Uri uri("uri");
341     auto record = PasteboardClient::GetInstance()->CreateUriRecord(uri);
342     ASSERT_TRUE(record != nullptr);
343     auto text = record->ConvertToText();
344     EXPECT_EQ(text, uri.ToString());
345 }
346 
347 /**
348  * @tc.name: ConvertToText004
349  * @tc.desc: PasteDataRecord: ConvertToText uri
350  * @tc.type: FUNC
351  * @tc.require:
352  * @tc.author:
353  */
354 HWTEST_F(PasteDataTest, ConvertToText004, TestSize.Level0)
355 {
356     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
357     InitializationOptions opts = {
358         {5, 7},
359         PixelFormat::ARGB_8888
360     };
361     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts);
362     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
363     auto record = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
364     ASSERT_TRUE(record != nullptr);
365     auto text = record->ConvertToText();
366     EXPECT_EQ(text, "");
367 }
368 
369 /**
370  * @tc.name: ConvertToText005
371  * @tc.desc: PasteDataRecord: ConvertToText plain
372  * @tc.type: FUNC
373  * @tc.require:
374  * @tc.author:
375  */
376 HWTEST_F(PasteDataTest, ConvertToText005, TestSize.Level0)
377 {
378     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
379     InitializationOptions opts = {
380         {5, 7},
381         PixelFormat::ARGB_8888
382     };
383     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts);
384     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
385     auto record = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
386     ASSERT_TRUE(record != nullptr);
387     std::string plainText = "hello";
388     auto plainUtdId = CommonUtils::Convert2UtdId(UDMF::UDType::UD_BUTT, MIMETYPE_TEXT_PLAIN);
389     record->AddEntryByMimeType(MIMETYPE_TEXT_PLAIN, std::make_shared<PasteDataEntry>(plainUtdId, plainText));
390     auto text = record->ConvertToText();
391     EXPECT_EQ(text, plainText);
392 }
393 
394 /**
395  * @tc.name: ConvertToText006
396  * @tc.desc: PasteDataRecord: ConvertToText html
397  * @tc.type: FUNC
398  * @tc.require:
399  * @tc.author:
400  */
401 HWTEST_F(PasteDataTest, ConvertToText006, TestSize.Level0)
402 {
403     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
404     InitializationOptions opts = {
405         {5, 7},
406         PixelFormat::ARGB_8888
407     };
408     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts);
409     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
410     auto record = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
411     ASSERT_TRUE(record != nullptr);
412     std::string htmlText = "<div class='disabled item tip'>";
413     auto htmlUtdId = CommonUtils::Convert2UtdId(UDMF::UDType::UD_BUTT, MIMETYPE_TEXT_HTML);
414     record->AddEntryByMimeType(MIMETYPE_TEXT_HTML, std::make_shared<PasteDataEntry>(htmlUtdId, htmlText));
415     auto text = record->ConvertToText();
416     EXPECT_EQ(text, htmlText);
417 }
418 
419 /**
420  * @tc.name: ConvertToText007
421  * @tc.desc: PasteDataRecord: ConvertToText uri
422  * @tc.type: FUNC
423  * @tc.require:
424  * @tc.author:
425  */
426 HWTEST_F(PasteDataTest, ConvertToText007, TestSize.Level0)
427 {
428     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
429     InitializationOptions opts = {
430         {5, 7},
431         PixelFormat::ARGB_8888
432     };
433     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts);
434     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
435     auto record = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
436     ASSERT_TRUE(record != nullptr);
437     std::string uri = "file://123.txt";
438     auto uriUtdId = CommonUtils::Convert2UtdId(UDMF::UDType::UD_BUTT, MIMETYPE_TEXT_URI);
439     record->AddEntryByMimeType(MIMETYPE_TEXT_URI, std::make_shared<PasteDataEntry>(uriUtdId, uri));
440     auto text = record->ConvertToText();
441     EXPECT_EQ(text, uri);
442 }
443 
444 /**
445  * @tc.name: GetPasteDataMsg001
446  * @tc.desc: PasteData: GetPrimaryMimeType is nullptr and so on
447  * @tc.type: FUNC
448  * @tc.require:
449  * @tc.author:
450  */
451 HWTEST_F(PasteDataTest, GetPasteDataMsg001, TestSize.Level0)
452 {
453     std::string plainText1 = "helloWorld";
454     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText1);
455     ASSERT_TRUE(pasteData != nullptr);
456     auto newPrimaryPixelMap = pasteData->GetPrimaryPixelMap();
457     ASSERT_TRUE(newPrimaryPixelMap == nullptr);
458     auto newPrimaryMimeType = pasteData->GetPrimaryMimeType();
459     ASSERT_TRUE(newPrimaryMimeType != nullptr);
460     auto newPasteData = std::make_shared<PasteData>();
461     auto newPrimaryMimeType2 = newPasteData->GetPrimaryMimeType();
462     ASSERT_TRUE(newPrimaryMimeType2 == nullptr);
463     std::string plainText2 = "plain text";
464     auto record = PasteboardClient::GetInstance()->CreatePlainTextRecord(plainText2);
465     ASSERT_TRUE(record != nullptr);
466     ASSERT_FALSE(pasteData->ReplaceRecordAt(1000, record));
467 }
468 
469 /**
470  * @tc.name: GetPasteDataMsg002
471  * @tc.desc: PasteData: GetPrimaryWant is nullptr and so on
472  * @tc.type: FUNC
473  * @tc.require:
474  * @tc.author:
475  */
476 HWTEST_F(PasteDataTest, GetPasteDataMsg002, TestSize.Level0)
477 {
478     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
479     InitializationOptions opts = {
480         {5, 7},
481         PixelFormat::ARGB_8888
482     };
483     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
484     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
485     auto newPasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn);
486     ASSERT_TRUE(newPasteData != nullptr);
487     auto pixMap = newPasteData->GetPrimaryPixelMap();
488     ASSERT_TRUE(pixMap != nullptr);
489     auto primaryWant = newPasteData->GetPrimaryWant();
490     ASSERT_TRUE(primaryWant == nullptr);
491     auto primaryText = newPasteData->GetPrimaryText();
492     ASSERT_TRUE(primaryText == nullptr);
493     auto primaryUri = newPasteData->GetPrimaryUri();
494     ASSERT_TRUE(primaryUri == nullptr);
495     auto record = newPasteData->GetRecordAt(1);
496     ASSERT_TRUE(record == nullptr);
497     auto res1 = newPasteData->RemoveRecordAt(1);
498     ASSERT_FALSE(res1);
499     std::string mimeType = "text/plain";
500     ASSERT_FALSE(newPasteData->HasMimeType(mimeType));
501 }
502 
503 /**
504  * @tc.name: ShareOptionToString001
505  * @tc.desc: PasteData: ShareOptionToString
506  * @tc.type: FUNC
507  * @tc.require:
508  * @tc.author:
509  */
510 HWTEST_F(PasteDataTest, ShareOptionToString001, TestSize.Level0)
511 {
512     std::string shareOption1;
513     PasteData::ShareOptionToString(ShareOption::InApp, shareOption1);
514     ASSERT_TRUE(shareOption1 == "InAPP");
515     std::string shareOption2;
516     PasteData::ShareOptionToString(ShareOption::LocalDevice, shareOption2);
517     ASSERT_TRUE(shareOption2 == "LocalDevice");
518     std::string shareOption3;
519     PasteData::ShareOptionToString(ShareOption::CrossDevice, shareOption3);
520     ASSERT_TRUE(shareOption3 == "CrossDevice");
521 }
522 
523 /**
524  * @tc.name: SetInvalid001
525  * @tc.desc: PasteData: SetInvalid001
526  * @tc.type: FUNC
527  * @tc.require:
528  * @tc.author:
529  */
530 HWTEST_F(PasteDataTest, SetInvalid001, TestSize.Level0)
531 {
532     bool result = true;
533     std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
534     pasteData->SetInvalid();
535     result = pasteData->IsValid();
536     ASSERT_FALSE(result);
537 }
538 
539 /**
540  * @tc.name: SetLocalOnly001
541  * @tc.desc: PasteData: SetLocalOnly
542  * @tc.type: FUNC
543  * @tc.require:
544  * @tc.author:
545  */
546 HWTEST_F(PasteDataTest, SetLocalOnly001, TestSize.Level0)
547 {
548     bool result = false;
549     std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
550     pasteData->SetLocalOnly(true);
551     result = pasteData->GetLocalOnly();
552     ASSERT_TRUE(result);
553 }
554 
555 /**
556  * @tc.name: SetAddition001
557  * @tc.desc: PasteData: SetAddition
558  * @tc.type: FUNC
559  * @tc.require:
560  * @tc.author:
561  */
562 HWTEST_F(PasteDataTest, SetAddition001, TestSize.Level0)
563 {
564     std::string plainText = "plain text";
565     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
566     int64_t fileSize = 0L;
567     pasteData->SetFileSize(fileSize);
568     AAFwk::WantParams additions;
569     pasteData->SetAdditions(additions);
570     ASSERT_TRUE(pasteData != nullptr);
571 }
572 
573 /**
574  * @tc.name: SetRemote001
575  * @tc.desc: PasteData: SetRemote
576  * @tc.type: FUNC
577  * @tc.require:
578  * @tc.author:
579  */
580 HWTEST_F(PasteDataTest, SetRemote001, TestSize.Level0)
581 {
582     bool isRemote = false;
583     std::string plainText = "plain text";
584     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
585     isRemote = true;
586     pasteData->SetRemote(isRemote);
587     bool result = pasteData->IsRemote();
588     ASSERT_TRUE(result);
589 }
590 
591 /**
592  * @tc.name: SetOriginAuthority001
593  * @tc.desc: PasteData: SetOriginAuthority
594  * @tc.type: FUNC
595  * @tc.require:
596  * @tc.author:
597  */
598 HWTEST_F(PasteDataTest, SetOriginAuthority001, TestSize.Level0)
599 {
600     std::string plainText = "plain text";
601     std::string bundleName = "com.example.myapplication";
602     int32_t appIndex = 1;
603     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
604     auto bundleIndex = std::make_pair(bundleName, appIndex);
605     pasteData->SetBundleInfo(bundleName, appIndex);
606     pasteData->SetOriginAuthority(bundleIndex);
607     std::string getBundleName = pasteData->GetBundleName();
608     int32_t getAppIndex = pasteData->GetAppIndex();
609     auto getOriginAuthority = pasteData->GetOriginAuthority();
610     ASSERT_TRUE(getBundleName == bundleName);
611     ASSERT_TRUE(getAppIndex == appIndex);
612     ASSERT_TRUE(getOriginAuthority == bundleIndex);
613     std::string time = "2023-08-09";
614     pasteData->SetTime(time);
615     std::string getTime = pasteData->GetTime();
616     ASSERT_TRUE(getTime == time);
617 }
618 
619 /**
620  * @tc.name: GetConvertUri001
621  * @tc.desc: PasteDataRecord: GetConvertUri
622  * @tc.type: FUNC
623  * @tc.require:
624  * @tc.author:
625  */
626 HWTEST_F(PasteDataTest, GetConvertUri001, TestSize.Level0)
627 {
628     std::vector<uint8_t> arrayBuffer(46);
629     arrayBuffer = { 2, 7, 6, 8, 9 };
630     std::string mimeType = "image/jpg";
631     auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer);
632     ASSERT_TRUE(pasteDataRecord != nullptr);
633     std::string convertUri_ = "/mnt/hmdfs/";
634     pasteDataRecord->SetConvertUri(convertUri_);
635     std::string result = pasteDataRecord->GetConvertUri();
636     ASSERT_TRUE(result == convertUri_);
637     std::string newUriStr = "/mnt/hmdfs/test";
638     pasteDataRecord->SetUri(std::make_shared<OHOS::Uri>(newUriStr));
639     std::shared_ptr<Uri> uri = pasteDataRecord->GetUriV0();
640     ASSERT_TRUE(uri != nullptr);
641     std::shared_ptr<Uri> getOriginUri = pasteDataRecord->GetOriginUri();
642     ASSERT_TRUE(getOriginUri != nullptr);
643 }
644 
645 /**
646  * @tc.name: GetConvertUri002
647  * @tc.desc: PasteDataRecord: GetConvertUri
648  * @tc.type: FUNC
649  * @tc.require:
650  * @tc.author:
651  */
652 HWTEST_F(PasteDataTest, GetConvertUri002, TestSize.Level0)
653 {
654     std::vector<uint8_t> arrayBuffer(46);
655     arrayBuffer = { 2, 7, 6, 8, 9 };
656     std::string mimeType = "image/jpg";
657     auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer);
658     ASSERT_TRUE(pasteDataRecord != nullptr);
659     std::string convertUri_ = "";
660     pasteDataRecord->SetConvertUri(convertUri_);
661     std::string result = pasteDataRecord->GetConvertUri();
662     ASSERT_TRUE(result == convertUri_);
663 }
664 
665 /**
666  * @tc.name: HasGrantUriPermission001
667  * @tc.desc: PasteDataRecord: HasGrantUriPermission
668  * @tc.type: FUNC
669  * @tc.require:
670  * @tc.author:
671  */
672 HWTEST_F(PasteDataTest, HasGrantUriPermission001, TestSize.Level0)
673 {
674     std::vector<uint8_t> arrayBuffer(46);
675     arrayBuffer = { 1, 2, 6, 8, 9 };
676     std::string mimeType = "image/jpg";
677     auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer);
678     ASSERT_TRUE(pasteDataRecord != nullptr);
679     pasteDataRecord->SetGrantUriPermission(true);
680     auto hasGrantUriPermission_ = pasteDataRecord->HasGrantUriPermission();
681     ASSERT_TRUE(hasGrantUriPermission_);
682 }
683 
684 /**
685  * @tc.name: LoadSystemAbilityFail001
686  * @tc.desc: PasteDataRecord: LoadSystemAbilityFail
687  * @tc.type: FUNC
688  * @tc.require:
689  * @tc.author:
690  */
691 HWTEST_F(PasteDataTest, LoadSystemAbilityFail001, TestSize.Level0)
692 {
693     std::vector<uint8_t> arrayBuffer(46);
694     std::string mimeType = "image/jpg";
695     arrayBuffer = { 1, 2, 3, 4, 6 };
696     PasteboardServiceLoader::GetInstance().LoadSystemAbilityFail();
697     auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer);
698     ASSERT_TRUE(pasteDataRecord != nullptr);
699 }
700 
701 /**
702  * @tc.name: LoadSystemAbilitySuccess001
703  * @tc.desc: PasteDataRecord: LoadSystemAbilitySuccess
704  * @tc.type: FUNC
705  * @tc.require:
706  * @tc.author:
707  */
708 HWTEST_F(PasteDataTest, LoadSystemAbilitySuccess001, TestSize.Level0)
709 {
710     std::vector<uint8_t> arrayBuffer(46);
711     std::string mimeType = "image/jpg";
712     arrayBuffer = { 1, 2, 3, 4, 6 };
713     sptr<IRemoteObject> remoteObject = nullptr;
714     PasteboardServiceLoader::GetInstance().LoadSystemAbilitySuccess(remoteObject);
715     auto pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimeType, arrayBuffer);
716     ASSERT_TRUE(pasteDataRecord != nullptr);
717 }
718 
719 /**
720  * @tc.name: SetInterval001
721  * @tc.desc: BlockObject: SetInterval
722  * @tc.type: FUNC
723  * @tc.require:
724  * @tc.author:
725  */
726 HWTEST_F(PasteDataTest, SetInterval001, TestSize.Level0)
727 {
728     uint32_t POPUP_INTERVAL = 1000;
729     auto block = std::make_shared<BlockObject<std::shared_ptr<PasteData>>>(POPUP_INTERVAL);
730     std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
731     block->SetValue(pasteData);
732     block->SetInterval(POPUP_INTERVAL);
733     auto value = block->GetValue();
734     EXPECT_TRUE(value != nullptr);
735 }
736 
737 /**
738  * @tc.name: ClipPlugin001
739  * @tc.desc: API_EXPORT: ClipPlugin
740  * @tc.type: FUNC
741  * @tc.require:
742  * @tc.author:
743  */
744 HWTEST_F(PasteDataTest, ClipPlugin001, TestSize.Level0)
745 {
746     std::string PLUGIN_NAME_VAL = "distributed_clip";
__anon5d276be00102(ClipPlugin *plugin) 747     auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
748         ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
749     };
750     auto clipPlugin_ = std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
751     ClipPlugin::Factory *factory = nullptr;
752     auto result = ClipPlugin::RegCreator(PLUGIN_NAME_VAL, factory);
753     EXPECT_FALSE(result);
754     auto userId = 10000;
755     auto events1 = clipPlugin_->GetTopEvents(1, userId);
756     EXPECT_TRUE(events1.size() == 0);
757     auto events2 = clipPlugin_->GetTopEvents(1);
758     EXPECT_TRUE(events2.size() == 0);
759     clipPlugin_->Clear();
760     clipPlugin_->Clear(userId);
761 }
762 
763 /**
764  * @tc.name: ClipPlugin002
765  * @tc.desc: API_EXPORT: ClipPlugin
766  * @tc.type: FUNC
767  * @tc.require:
768  * @tc.author:
769  */
770 HWTEST_F(PasteDataTest, ClipPlugin002, TestSize.Level0)
771 {
772     std::string PLUGIN_NAME_VAL = "distributed_clip";
__anon5d276be00202(ClipPlugin *plugin) 773     auto release = [&PLUGIN_NAME_VAL, this](ClipPlugin *plugin) {
774         ClipPlugin::DestroyPlugin(PLUGIN_NAME_VAL, plugin);
775     };
776     auto clipPlugin_ = std::shared_ptr<ClipPlugin>(ClipPlugin::CreatePlugin(PLUGIN_NAME_VAL), release);
777     ClipPlugin::Factory *factory = new ClipFactory();
778     auto result = ClipPlugin::RegCreator(PLUGIN_NAME_VAL, factory);
779     EXPECT_FALSE(result);
780     auto userId = 3701;
781     auto events1 = clipPlugin_->GetTopEvents(1, userId);
782     EXPECT_TRUE(events1.size() == 0);
783     clipPlugin_->Clear(userId);
784 }
785 
786 /**
787  * @tc.name: ClipPlugin003
788  * @tc.desc: API_EXPORT: ClipPlugin
789  * @tc.type: FUNC
790  * @tc.require:
791  * @tc.author:
792  */
793 HWTEST_F(PasteDataTest, ClipPlugin003, TestSize.Level0)
794 {
795     ClipPlugin::GlobalEvent event1;
796     event1.seqId = 0;
797     event1.deviceId = "test_device_id";
798     event1.user = 0;
799     ClipPlugin::GlobalEvent event2;
800     event2.seqId = 0;
801     event2.deviceId = "test_device_id";
802     event2.user = 1;
803     EXPECT_TRUE(event1 == event2);
804 }
805 
806 /**
807  * @tc.name: ClipPlugin004
808  * @tc.desc: API_EXPORT: ClipPlugin
809  * @tc.type: FUNC
810  * @tc.require:
811  * @tc.author:
812  */
813 HWTEST_F(PasteDataTest, ClipPlugin004, TestSize.Level0)
814 {
815     ClipPlugin::GlobalEvent event1;
816     event1.seqId = 0;
817     event1.deviceId = "test_device_id";
818     event1.user = 0;
819     ClipPlugin::GlobalEvent event2;
820     event2.seqId = 0;
821     event2.deviceId = "test_device_id1";
822     event2.user = 1;
823     EXPECT_FALSE(event1 == event2);
824 }
825 
826 /**
827  * @tc.name: ClipPlugin005
828  * @tc.desc: API_EXPORT: ClipPlugin
829  * @tc.type: FUNC
830  * @tc.require:
831  * @tc.author:
832  */
833 HWTEST_F(PasteDataTest, ClipPlugin005, TestSize.Level0)
834 {
835     ClipPlugin::GlobalEvent event1;
836     event1.seqId = 0;
837     event1.deviceId = "test_device_id";
838     event1.user = 0;
839     ClipPlugin::GlobalEvent event2;
840     event2.seqId = 1;
841     event2.deviceId = "test_device_id";
842     event2.user = 1;
843     EXPECT_FALSE(event1 == event2);
844 }
845 
846 /**
847  * @tc.name: PasteDataOperator001
848  * @tc.desc: PasteData: operator
849  * @tc.type: FUNC
850  * @tc.require:
851  * @tc.author:
852  */
853 HWTEST_F(PasteDataTest, PasteDataOperator001, TestSize.Level0)
854 {
855     PasteData data1;
856     PasteDataRecord::Builder builder1(MIMETYPE_TEXT_URI);
857     std::string uriStr1 = FILE_URI;
858     auto uri1 = std::make_shared<OHOS::Uri>(uriStr1);
859     builder1.SetUri(uri1);
860     auto record1 = builder1.Build();
861     data1.AddRecord(record1);
862     std::string bundleName1 = "com.example.myapplication";
863     int32_t appIndex1 = 1;
864     data1.SetOriginAuthority({bundleName1, appIndex1});
865     PasteData data2;
866     PasteDataRecord::Builder builder2(MIMETYPE_TEXT_URI);
867     std::string uriStr2 = FILE_URI;
868     auto uri2 = std::make_shared<OHOS::Uri>(uriStr2);
869     builder2.SetUri(uri2);
870     auto record2 = builder2.Build();
871     data2.AddRecord(record2);
872     std::string bundleName2 = "com.example.myapplication";
873     int32_t appIndex2 = 1;
874     data2.SetOriginAuthority({bundleName2, appIndex2});
875     ASSERT_TRUE(data1.GetBundleName() == data2.GetBundleName());
876     ASSERT_TRUE(data1.GetAppIndex() == data2.GetAppIndex());
877 }
878 
879 /**
880  * @tc.name: GetShareOption001
881  * @tc.desc: GetShareOption call
882  * @tc.type: FUNC
883  * @tc.require:
884  * @tc.author:
885  */
886 HWTEST_F(PasteDataTest, GetShareOption001, TestSize.Level0)
887 {
888     std::string plainText = "plain text";
889     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
890     ASSERT_TRUE(pasteData != nullptr);
891     ShareOption option = InApp;
892     pasteData->SetShareOption(option);
893     auto result = pasteData->GetShareOption();
894     ASSERT_TRUE(result == InApp);
895 }
896 
897 /**
898  * @tc.name: AddKvRecord001
899  * @tc.desc: AddKvRecord call
900  * @tc.type: FUNC
901  * @tc.require:
902  * @tc.author:
903  */
904 HWTEST_F(PasteDataTest, AddKvRecord001, TestSize.Level0)
905 {
906     PasteData data;
907     std::vector<uint8_t> arrayBuffer(46);
908     arrayBuffer = { 2, 7, 6, 8, 9 };
909     std::string mimeType = "image/jpg";
910     data.AddKvRecord(mimeType, arrayBuffer);
911     ASSERT_TRUE(data.GetRecordCount() > 0);
912 }
913 
914 /**
915  * @tc.name: GetProperty001
916  * @tc.desc: GetProperty call
917  * @tc.type: FUNC
918  * @tc.require:
919  * @tc.author:
920  */
921 HWTEST_F(PasteDataTest, GetProperty001, TestSize.Level0)
922 {
923     std::string plainText = "plain text";
924     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
925     ASSERT_TRUE(pasteData != nullptr);
926     PasteDataProperty property = pasteData->GetProperty();
927     ASSERT_TRUE(property.tokenId == 0);
928 }
929 
930 /**
931  * @tc.name: SetProperty001
932  * @tc.desc:
933  * @tc.type: FUNC
934  * @tc.require:
935  * @tc.author:
936  */
937 HWTEST_F(PasteDataTest, SetProperty001, TestSize.Level0)
938 {
939     std::string plainText = "plain text";
940     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
941     ASSERT_TRUE(pasteData != nullptr);
942     PasteDataProperty property;
943     property.tokenId = 1;
944     pasteData->SetProperty(property);
945     PasteDataProperty pasteDataProperty = pasteData->GetProperty();
946     ASSERT_TRUE(pasteDataProperty.tokenId == 1);
947 }
948 
949 /**
950  * @tc.name: SetShareOption001
951  * @tc.desc: SetShareOption call
952  * @tc.type: FUNC
953  * @tc.require:
954  * @tc.author:
955  */
956 HWTEST_F(PasteDataTest, SetShareOption001, TestSize.Level0)
957 {
958     std::string plainText = "plain text";
959     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
960     ASSERT_TRUE(pasteData != nullptr);
961     ShareOption option = LocalDevice;
962     pasteData->SetShareOption(option);
963     auto result = pasteData->GetShareOption();
964     ASSERT_TRUE(result == LocalDevice);
965 }
966 
967 /**
968  * @tc.name: SetTokenId001
969  * @tc.desc:
970  * @tc.type: FUNC
971  * @tc.require:
972  * @tc.author:
973  */
974 HWTEST_F(PasteDataTest, SetTokenId001, TestSize.Level0)
975 {
976     std::string plainText = "plain text";
977     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
978     ASSERT_TRUE(pasteData != nullptr);
979     uint32_t tokenId = 1;
980     pasteData->SetTokenId(tokenId);
981     auto result = pasteData->GetTokenId();
982     ASSERT_TRUE(result == 1);
983 }
984 
985 /**
986  * @tc.name: IsDraggedData001
987  * @tc.desc: IsDraggedData call
988  * @tc.type: FUNC
989  * @tc.require:
990  * @tc.author:
991  */
992 HWTEST_F(PasteDataTest, IsDraggedData001, TestSize.Level0)
993 {
994     std::string plainText = "plain text";
995     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
996     ASSERT_TRUE(pasteData != nullptr);
997     bool isDraggedData = false;
998     pasteData->SetDraggedDataFlag(isDraggedData);
999     auto result = pasteData->IsDraggedData();
1000     ASSERT_FALSE(result);
1001 }
1002 
1003 /**
1004  * @tc.name: SetDraggedDataFlag001
1005  * @tc.desc: SetDraggedDataFlag call
1006  * @tc.type: FUNC
1007  * @tc.require:
1008  * @tc.author:
1009  */
1010 HWTEST_F(PasteDataTest, SetDraggedDataFlag001, TestSize.Level0)
1011 {
1012     std::string plainText = "plain text";
1013     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
1014     ASSERT_TRUE(pasteData != nullptr);
1015     bool isDraggedData = true;
1016     pasteData->SetDraggedDataFlag(isDraggedData);
1017     auto result = pasteData->IsDraggedData();
1018     ASSERT_TRUE(result);
1019 }
1020 
1021 /**
1022  * @tc.name: SetScreenStatus
1023  * @tc.desc:
1024  * @tc.type: FUNC
1025  * @tc.require:
1026  * @tc.author:
1027  */
1028 HWTEST_F(PasteDataTest, SetScreenStatus, TestSize.Level0)
1029 {
1030     std::string plainText = "plain text";
1031     auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
1032     ScreenEvent event = ScreenEvent::ScreenLocked;
1033     pasteData->SetScreenStatus(event);
1034     ScreenEvent ret = pasteData->GetScreenStatus();
1035     ASSERT_TRUE(ret == ScreenEvent::ScreenLocked);
1036 }
1037 
1038 /**
1039  * @tc.name: GetMimeTypes
1040  * @tc.desc: PasteData GetMimeTypes
1041  * @tc.type: FUNC
1042  * @tc.require:
1043  * @tc.author:
1044  */
1045 HWTEST_F(PasteDataTest, GetMimeTypes, TestSize.Level0)
1046 {
1047     PasteData data;
1048     PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI);
1049     std::string uriStr = FILE_URI;
1050     auto uri = std::make_shared<OHOS::Uri>(uriStr);
1051     auto record = builder.SetUri(uri).Build();
1052     data.AddRecord(*record);
1053 
1054     PasteDataRecord::Builder builder1(MIMETYPE_TEXT_PLAIN);
1055     std::string plainText = "plain text";
1056     auto text = std::make_shared<std::string>(plainText);
1057     auto record1 = builder1.SetPlainText(text).Build();
1058     data.AddRecord(*record1);
1059 
1060     auto mimeType = data.GetMimeTypes();
1061     EXPECT_TRUE((strcmp(MIMETYPE_TEXT_PLAIN, mimeType.at(0).c_str()) == 0 &&
1062                     strcmp(MIMETYPE_TEXT_URI, mimeType.at(1).c_str()) == 0) ||
1063         (strcmp(MIMETYPE_TEXT_PLAIN, mimeType.at(1).c_str()) == 0 &&
1064             strcmp(MIMETYPE_TEXT_URI, mimeType.at(0).c_str()) == 0));
1065 }
1066 
1067 /**
1068  * @tc.name: GetReportMimeTypes
1069  * @tc.desc: PasteData GetReportMimeTypes
1070  * @tc.type: FUNC
1071  * @tc.require:
1072  * @tc.author:
1073  */
1074 HWTEST_F(PasteDataTest, GetReportMimeTypes, TestSize.Level0)
1075 {
1076     PasteData data;
1077     std::string uriStr = FILE_URI;
1078     PasteDataRecord::Builder builder(MIMETYPE_TEXT_URI);
1079     auto uri = std::make_shared<OHOS::Uri>(uriStr);
1080     auto record = builder.SetUri(uri).Build();
1081     data.AddRecord(*record);
1082 
1083     PasteDataRecord::Builder builder1(MIMETYPE_TEXT_PLAIN);
1084     std::string plainText = "plain text";
1085     auto text = std::make_shared<std::string>(plainText);
1086     auto record1 = builder1.SetPlainText(text).Build();
1087     data.AddRecord(*record1);
1088 
1089     auto mimeType = data.GetReportMimeTypes();
1090     EXPECT_TRUE((strcmp(MIMETYPE_TEXT_PLAIN, mimeType.at(0).c_str()) == 0 &&
1091                     strcmp(MIMETYPE_TEXT_URI, mimeType.at(1).c_str()) == 0) ||
1092         (strcmp(MIMETYPE_TEXT_PLAIN, mimeType.at(1).c_str()) == 0 &&
1093             strcmp(MIMETYPE_TEXT_URI, mimeType.at(0).c_str()) == 0));
1094 }
1095 
1096 /**
1097  * @tc.name: GetDeviceId
1098  * @tc.desc: Get DeviceId
1099  * @tc.type: FUNC
1100  * @tc.require:
1101  * @tc.author:
1102  */
1103 HWTEST_F(PasteDataTest, GetDeviceId, TestSize.Level0)
1104 {
1105     PasteData data;
1106     data.GetDeviceId();
1107     ASSERT_TRUE(true);
1108 }
1109 
1110 /**
1111  * @tc.name: GetRecordByIdTest001
1112  * @tc.desc: GetRecordByIdTest001
1113  * @tc.type: FUNC
1114  * @tc.require:
1115  * @tc.author:
1116  */
1117 HWTEST_F(PasteDataTest, GetRecordByIdTest001, TestSize.Level0)
1118 {
1119     //Arrange
1120     PasteData pasteData;
1121     std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
1122     record->SetRecordId(1);
1123     pasteData.AddRecord(record);
1124 
1125     //Act
1126     std::shared_ptr<PasteDataRecord> result = pasteData.GetRecordById(1);
1127 
1128     //Assert
1129     EXPECT_EQ(result, record);
1130 }
1131 
1132 /**
1133  * @tc.name: GetRecordByIdTest002
1134  * @tc.desc: GetRecordByIdTest002
1135  * @tc.type: FUNC
1136  * @tc.require:
1137  * @tc.author:
1138  */
1139 HWTEST_F(PasteDataTest, GetRecordByIdTest002, TestSize.Level0)
1140 {
1141     //Arrange
1142     PasteData pasteData;
1143     std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
1144     record->SetRecordId(1);
1145     pasteData.AddRecord(record);
1146 
1147     //Act
1148     std::shared_ptr<PasteDataRecord> result = pasteData.GetRecordById(2);
1149 
1150     //Assert
1151     EXPECT_EQ(result, nullptr);
1152 }
1153 
1154 /**
1155  * @tc.name: GetRecordByIdTest003
1156  * @tc.desc: GetRecordByIdTest003
1157  * @tc.type: FUNC
1158  * @tc.require:
1159  * @tc.author:
1160  */
1161 HWTEST_F(PasteDataTest, GetRecordByIdTest003, TestSize.Level0)
1162 {
1163     //Arrange
1164     PasteData pasteData;
1165 
1166     //Act
1167     std::shared_ptr<PasteDataRecord> result = pasteData.GetRecordById(1);
1168 
1169     //Assert
1170     EXPECT_EQ(result, nullptr);
1171 }
1172 
1173 /**
1174  * @tc.name: ReplaceRecordAtTest001
1175  * @tc.desc: ReplaceRecordAtTest001
1176  * @tc.type: FUNC
1177  * @tc.require:
1178  * @tc.author:
1179  */
1180 HWTEST_F(PasteDataTest, ReplaceRecordAtTest001, TestSize.Level0)
1181 {
1182     //Arrange
1183     PasteData pasteData;
1184 
1185     //Act
1186     std::shared_ptr<PasteDataRecord> record = nullptr;
1187 
1188     //Assert
1189     EXPECT_FALSE(pasteData.ReplaceRecordAt(0, record));
1190 }
1191 
1192 /**
1193  * @tc.name: GetFileSizeTest001
1194  * @tc.desc: GetFileSizeTest001
1195  * @tc.type: FUNC
1196  * @tc.require:
1197  * @tc.author:
1198  */
1199 HWTEST_F(PasteDataTest, GetFileSizeTest001, TestSize.Level0)
1200 {
1201     OHOS::Uri uri("uri");
1202     auto pasteData = PasteboardClient::GetInstance()->CreateUriData(uri);
1203     ASSERT_TRUE(pasteData != nullptr);
1204     PasteDataProperty property = pasteData->GetProperty();
1205     property.tokenId = 1;
1206 
1207     AAFwk::ILong *ao = nullptr;
1208     int64_t fileSize = pasteData->GetFileSize();
1209     EXPECT_EQ(fileSize, property.additions.GetIntParam(REMOTE_FILE_SIZE, -1));
1210 
1211     int64_t fileSize2 = 0L;
1212     pasteData->SetFileSize(fileSize2);
1213     int64_t fileSize3 = pasteData->GetFileSize();
1214     EXPECT_EQ(fileSize3, fileSize2);
1215 }
1216 
1217 /**
1218  * @tc.name: SetDataIdTest001
1219  * @tc.desc: SetDataId
1220  * @tc.type: FUNC
1221  * @tc.require:
1222  * @tc.author:
1223  */
1224 HWTEST_F(PasteDataTest, SetDataIdTest001, TestSize.Level0)
1225 {
1226     PasteData pasteData;
1227     pasteData.SetDataId(0);
1228     EXPECT_EQ(0, pasteData.GetDataId());
1229 }
1230 
1231 /**
1232  * @tc.name: GetReportDescriptionTest001
1233  * @tc.desc: GetReportDescription
1234  * @tc.type: FUNC
1235  */
1236 HWTEST_F(PasteDataTest, GetReportDescriptionTest001, TestSize.Level0)
1237 {
1238     PasteData pasteData;
1239     std::shared_ptr<PasteDataRecord> record = std::make_shared<PasteDataRecord>();
1240     ASSERT_TRUE(record != nullptr);
1241     pasteData.AddRecord(record);
1242     DataDescription description = pasteData.GetReportDescription();
1243     EXPECT_EQ(description.recordNum, 1);
1244 }
1245 
1246 /**
1247  * @tc.name: GetReportDescriptionTest002
1248  * @tc.desc: GetReportDescription
1249  * @tc.type: FUNC
1250  */
1251 HWTEST_F(PasteDataTest, GetReportDescriptionTest002, TestSize.Level0)
1252 {
1253     PasteData pasteData;
1254     DataDescription description = pasteData.GetReportDescription();
1255     EXPECT_EQ(description.recordNum, 0);
1256 }
1257 
1258 /**
1259  * @tc.name: GetReportDescriptionTest003
1260  * @tc.desc: GetReportDescription
1261  * @tc.type: FUNC
1262  */
1263 HWTEST_F(PasteDataTest, GetReportDescriptionTest003, TestSize.Level0)
1264 {
1265     std::shared_ptr<PasteDataRecord> record1 = nullptr;
1266     std::shared_ptr<PasteDataRecord> record2 = std::make_shared<PasteDataRecord>();
1267     std::vector<std::shared_ptr<PasteDataRecord>> records = {record1, record2};
1268     PasteData pasteData(records);
1269     DataDescription description = pasteData.GetReportDescription();
1270     EXPECT_EQ(description.recordNum, 2);
1271 }
1272 
1273 /**
1274  * @tc.name: GetPrimaryHtmlTest001
1275  * @tc.desc: GetPrimaryHtml
1276  * @tc.type: FUNC
1277  */
1278 HWTEST_F(PasteDataTest, GetPrimaryHtmlTest001, TestSize.Level0)
1279 {
1280     std::shared_ptr<PasteDataRecord> record = nullptr;
1281     std::vector<std::shared_ptr<PasteDataRecord>> records = {record};
1282     PasteData pasteData;
1283     pasteData.AddRecord(record);
1284     auto primary = pasteData.GetPrimaryHtml();
1285     EXPECT_EQ(primary, nullptr);
1286 }
1287 
1288 /**
1289  * @tc.name: GetPrimaryHtmlTest002
1290  * @tc.desc: GetPrimaryHtml
1291  * @tc.type: FUNC
1292  */
1293 HWTEST_F(PasteDataTest, GetPrimaryHtmlTest002, TestSize.Level0)
1294 {
1295     std::vector<std::string> testHtmlVec = {
1296         "<div class='disable'>html001</div>",
1297         "<div class='disable'>html002</div>",
1298         "<div class='disable'>html003</div>"
1299     };
1300     PasteData pasteData;
1301 
1302     for (const auto &itHtml: testHtmlVec) {
1303         pasteData.AddHtmlRecord(itHtml);
1304     }
1305     auto count = pasteData.GetRecordCount();
1306     EXPECT_TRUE(count == testHtmlVec.size());
1307 
1308     auto primary = pasteData.GetPrimaryHtml();
1309     EXPECT_NE(primary, nullptr);
1310 }
1311 
1312 /**
1313  * @tc.name: GetPrimaryPixelMapTest001
1314  * @tc.desc: GetPrimaryPixelMap
1315  * @tc.type: FUNC
1316  */
1317 HWTEST_F(PasteDataTest, GetPrimaryPixelMapTest001, TestSize.Level0)
1318 {
1319     std::shared_ptr<PasteDataRecord> record = nullptr;
1320     std::vector<std::shared_ptr<PasteDataRecord>> records = {record};
1321     PasteData pasteData;
1322     pasteData.AddRecord(record);
1323     auto primary = pasteData.GetPrimaryPixelMap();
1324     EXPECT_EQ(primary, nullptr);
1325 }
1326 
1327 /**
1328  * @tc.name: GetPrimaryPixelMapTest002
1329  * @tc.desc: GetPrimaryPixelMap
1330  * @tc.type: FUNC
1331  */
1332 HWTEST_F(PasteDataTest, GetPrimaryPixelMapTest002, TestSize.Level0)
1333 {
1334     uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
1335     InitializationOptions opts = {
1336         {5, 7},
1337         PixelFormat::ARGB_8888
1338     };
1339     std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, 100, opts);
1340     std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
1341     auto record = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
1342     ASSERT_TRUE(record != nullptr);
1343     PasteData pasteData;
1344 
1345     pasteData.AddRecord(record);
1346 
1347     auto primary = pasteData.GetPrimaryPixelMap();
1348     EXPECT_NE(primary, nullptr);
1349 }
1350 
1351 /**
1352  * @tc.name: GetPrimaryTextTest001
1353  * @tc.desc: GetPrimaryText
1354  * @tc.type: FUNC
1355  */
1356 HWTEST_F(PasteDataTest, GetPrimaryTextTest001, TestSize.Level0)
1357 {
1358     std::shared_ptr<PasteDataRecord> record = nullptr;
1359     std::vector<std::shared_ptr<PasteDataRecord>> records = {record};
1360     PasteData pasteData;
1361     pasteData.AddRecord(record);
1362     auto primary = pasteData.GetPrimaryText();
1363     EXPECT_EQ(primary, nullptr);
1364 }
1365 
1366 /**
1367  * @tc.name: GetPrimaryTextTest002
1368  * @tc.desc: GetPrimaryText
1369  * @tc.type: FUNC
1370  */
1371 HWTEST_F(PasteDataTest, GetPrimaryTextTest002, TestSize.Level0)
1372 {
1373     std::vector<std::string> testTextVec = { "text101", "text102", "text103" };
1374     PasteData pasteData;
1375 
1376     for (const auto &itText: testTextVec) {
1377         pasteData.AddTextRecord(itText);
1378     }
1379 
1380     auto count = pasteData.GetRecordCount();
1381     EXPECT_TRUE(count == testTextVec.size());
1382 
1383     auto primary = pasteData.GetPrimaryText();
1384     EXPECT_NE(primary, nullptr);
1385 }
1386 
1387 /**
1388  * @tc.name: GetPrimaryUriTest001
1389  * @tc.desc: GetPrimaryUri
1390  * @tc.type: FUNC
1391  */
1392 HWTEST_F(PasteDataTest, GetPrimaryUriTest001, TestSize.Level0)
1393 {
1394     std::shared_ptr<PasteDataRecord> record = nullptr;
1395     std::vector<std::shared_ptr<PasteDataRecord>> records = {record};
1396     PasteData pasteData;
1397     pasteData.AddRecord(record);
1398     auto primary = pasteData.GetPrimaryUri();
1399     EXPECT_EQ(primary, nullptr);
1400 }
1401 
1402 /**
1403  * @tc.name: GetPrimaryUriTest002
1404  * @tc.desc: GetPrimaryUri
1405  * @tc.type: FUNC
1406  */
1407 HWTEST_F(PasteDataTest, GetPrimaryUriTest002, TestSize.Level0)
1408 {
1409     std::vector<std::string> testUriVec = {
1410         "file://pasteboard_service/test_uri_001",
1411         "file://pasteboard_service/test_uri_002",
1412         "file://pasteboard_service/test_uri_003"
1413     };
1414 
1415     PasteData pasteData;
1416     for (const auto &itUri: testUriVec) {
1417         pasteData.AddUriRecord(OHOS::Uri(itUri));
1418     }
1419 
1420     auto count = pasteData.GetRecordCount();
1421     EXPECT_TRUE(count == testUriVec.size());
1422 
1423     auto primary = pasteData.GetPrimaryUri();
1424     EXPECT_NE(primary, nullptr);
1425 }
1426 
1427 /**
1428  * @tc.name: IsValidShareOptionTest001
1429  * @tc.desc: IsValidShareOption
1430  * @tc.type: FUNC
1431  */
1432 HWTEST_F(PasteDataTest, IsValidShareOptionTest001, TestSize.Level0)
1433 {
1434     int32_t shareOption = -1;
1435     auto isValid = PasteData::IsValidShareOption(shareOption);
1436     EXPECT_FALSE(isValid);
1437 }
1438 
1439 /**
1440  * @tc.name: IsValidShareOptionTest002
1441  * @tc.desc: IsValidShareOption
1442  * @tc.type: FUNC
1443  */
1444 HWTEST_F(PasteDataTest, IsValidShareOptionTest002, TestSize.Level0)
1445 {
1446     int32_t shareOption = 0;
1447     auto isValid = PasteData::IsValidShareOption(shareOption);
1448     EXPECT_TRUE(isValid);
1449 }
1450 
1451 /**
1452  * @tc.name: IsValidShareOptionTest003
1453  * @tc.desc: IsValidShareOption
1454  * @tc.type: FUNC
1455  */
1456 HWTEST_F(PasteDataTest, IsValidShareOptionTest003, TestSize.Level0)
1457 {
1458     int32_t shareOption = 1;
1459     auto isValid = PasteData::IsValidShareOption(shareOption);
1460     EXPECT_TRUE(isValid);
1461 }
1462 
1463 /**
1464  * @tc.name: IsValidShareOptionTest004
1465  * @tc.desc: IsValidShareOption
1466  * @tc.type: FUNC
1467  */
1468 HWTEST_F(PasteDataTest, IsValidShareOptionTest004, TestSize.Level0)
1469 {
1470     int32_t shareOption = 2;
1471     auto isValid = PasteData::IsValidShareOption(shareOption);
1472     EXPECT_TRUE(isValid);
1473 }
1474 
1475 /**
1476  * @tc.name: IsValidShareOptionTest005
1477  * @tc.desc: IsValidShareOption
1478  * @tc.type: FUNC
1479  */
1480 HWTEST_F(PasteDataTest, IsValidShareOptionTest005, TestSize.Level0)
1481 {
1482     int32_t shareOption = 3;
1483     auto isValid = PasteData::IsValidShareOption(shareOption);
1484     EXPECT_FALSE(isValid);
1485 }
1486 
1487 /**
1488  * @tc.name: IsValidPasteIdTest001
1489  * @tc.desc: IsValidPasteId
1490  * @tc.type: FUNC
1491  */
1492 HWTEST_F(PasteDataTest, IsValidPasteIdTest001, TestSize.Level0)
1493 {
1494     std::string pasteId = "";
1495     auto isValid = PasteData::IsValidPasteId(pasteId);
1496     EXPECT_FALSE(isValid);
1497 }
1498 
1499 /**
1500  * @tc.name: IsValidPasteIdTest002
1501  * @tc.desc: IsValidPasteId
1502  * @tc.type: FUNC
1503  */
1504 HWTEST_F(PasteDataTest, IsValidPasteIdTest002, TestSize.Level0)
1505 {
1506     std::string pasteId = "test";
1507     auto isValid = PasteData::IsValidPasteId(pasteId);
1508     EXPECT_FALSE(isValid);
1509 }
1510 
1511 /**
1512  * @tc.name: IsValidPasteIdTest003
1513  * @tc.desc: IsValidPasteId
1514  * @tc.type: FUNC
1515  */
1516 HWTEST_F(PasteDataTest, IsValidPasteIdTest003, TestSize.Level0)
1517 {
1518     std::string pasteId = "test_test_test";
1519     auto isValid = PasteData::IsValidPasteId(pasteId);
1520     EXPECT_FALSE(isValid);
1521 }
1522 
1523 /**
1524  * @tc.name: IsValidPasteIdTest004
1525  * @tc.desc: IsValidPasteId
1526  * @tc.type: FUNC
1527  */
1528 HWTEST_F(PasteDataTest, IsValidPasteIdTest004, TestSize.Level0)
1529 {
1530     pid_t pid = getpid();
1531     std::string currentPid = std::to_string(pid);
1532     std::string pasteId = "test_" + currentPid + "_001";
1533     auto isValid = PasteData::IsValidPasteId(pasteId);
1534     EXPECT_TRUE(isValid);
1535 }
1536 } // namespace OHOS::MiscServices
1537