• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #define LOG_TAG "PasteboardCapiTest"
17 
18 #include <gtest/gtest.h>
19 #include <unistd.h>
20 
21 #include "token_setproc.h"
22 #include "accesstoken_kit.h"
23 #include "nativetoken_kit.h"
24 
25 #include "oh_pasteboard.h"
26 #include "oh_pasteboard_err_code.h"
27 #include "oh_pasteboard_observer_impl.h"
28 #include "udmf.h"
29 #include "uds.h"
30 #include "pasteboard_hilog.h"
31 #include "pasteboard_client.h"
32 #include "os_account_manager.h"
33 
34 using namespace testing::ext;
35 using namespace OHOS::Security::AccessToken;
36 using namespace OHOS::MiscServices;
37 
38 namespace OHOS::Test {
39 class PasteboardCapiTest : public testing::Test {
40 public:
41     static void SetUpTestCase(void);
42     static void TearDownTestCase(void);
43     void SetUp();
44     void TearDown();
45     static void CallbackFunc(void* context, Pasteboard_NotifyType type);
46     static void RemoveCallbackSideEffects();
47     static void ContextFinalizeFunc(void* context);
48     static int callbackValue;
49     static void AllocTestTokenId();
50     static void DeleteTestTokenId();
51     static void SetTestTokenId();
52     static void RestoreSelfTokenId();
53     static void* GetDataCallback(void* context, const char* type);
54     static constexpr int INIT_VALUE = 0;
55     static constexpr int UPDATE_VALUE = 1;
56     static constexpr int uriLen = 10;
57     static uint64_t selfTokenId_;
58     static AccessTokenID testTokenId_;
59     static constexpr char PLAINTEXT_CONTENT[] = "PLAINTEXT_CONTENT";
60     static constexpr char HYPERLINK_URL[] = "file://data/image.png";
61     static constexpr char HTML_URL[] = "file://data/image.png";
62     static constexpr char HTML_TEXT[] = "<P>html text</P>";
63 };
64 uint64_t PasteboardCapiTest::selfTokenId_ = 0;
65 AccessTokenID PasteboardCapiTest::testTokenId_ = 0;
66 int PasteboardCapiTest::callbackValue = 0;
67 static Pasteboard_GetDataParams *g_params = nullptr;
68 
SetUpTestCase(void)69 void PasteboardCapiTest::SetUpTestCase(void)
70 {
71     callbackValue = INIT_VALUE;
72     selfTokenId_ = GetSelfTokenID();
73     AllocTestTokenId();
74 }
75 
TearDownTestCase(void)76 void PasteboardCapiTest::TearDownTestCase(void)
77 {
78     RemoveCallbackSideEffects();
79     DeleteTestTokenId();
80 }
81 
SetUp(void)82 void PasteboardCapiTest::SetUp(void)
83 {
84 }
85 
TearDown(void)86 void PasteboardCapiTest::TearDown(void)
87 {
88 }
89 
AllocTestTokenId()90 void PasteboardCapiTest::AllocTestTokenId()
91 {
92     std::vector<int32_t> ids;
93     auto ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
94     if (ret != ERR_OK || ids.empty()) {
95         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "query active user failed errCode = %{public}d", ret);
96         return;
97     }
98     HapInfoParams infoParams = {
99         .userID = ids[0],
100         .bundleName = "ohos.privacy_test.pasteboard",
101         .instIndex = 0,
102         .appIDDesc = "privacy_test.pasteboard"
103     };
104     PermissionStateFull testState = {
105         .permissionName = "ohos.permission.DUMP",
106         .isGeneral = true,
107         .resDeviceID = { "local" },
108         .grantStatus = { PermissionState::PERMISSION_GRANTED },
109         .grantFlags = { 1 }
110     };
111     HapPolicyParams policyParams = {
112         .apl = APL_NORMAL,
113         .domain = "test.domain.pasteboard",
114         .permList = {},
115         .permStateList = { testState }
116     };
117 
118     AccessTokenKit::AllocHapToken(infoParams, policyParams);
119     testTokenId_ = Security::AccessToken::AccessTokenKit::GetHapTokenID(
120         infoParams.userID, infoParams.bundleName, infoParams.instIndex);
121     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "userID = %{public}d, testTokenId = 0x%{public}x.", infoParams.userID,
122         testTokenId_);
123 }
124 
DeleteTestTokenId()125 void PasteboardCapiTest::DeleteTestTokenId()
126 {
127     AccessTokenKit::DeleteToken(testTokenId_);
128 }
129 
130 
SetTestTokenId()131 void PasteboardCapiTest::SetTestTokenId()
132 {
133     auto ret = SetSelfTokenID(testTokenId_);
134     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "testTokenId = 0x%{public}x, ret = %{public}d!", testTokenId_, ret);
135 }
136 
RestoreSelfTokenId()137 void PasteboardCapiTest::RestoreSelfTokenId()
138 {
139     auto ret = SetSelfTokenID(selfTokenId_);
140     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "ret = %{public}d!", ret);
141 }
142 
CallbackFunc(void * context,Pasteboard_NotifyType type)143 void PasteboardCapiTest::CallbackFunc(void* context, Pasteboard_NotifyType type)
144 {
145     callbackValue = UPDATE_VALUE;
146 }
147 
RemoveCallbackSideEffects()148 void PasteboardCapiTest::RemoveCallbackSideEffects()
149 {
150     callbackValue = INIT_VALUE;
151 }
152 
ContextFinalizeFunc(void * context)153 void PasteboardCapiTest::ContextFinalizeFunc(void* context) {}
154 
GetDataCallback(void * context,const char * type)155 void* PasteboardCapiTest::GetDataCallback(void* context, const char* type)
156 {
157     if (std::string(type) == "general.plain-text") {
158         OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
159         OH_UdsPlainText_SetContent(plainText, PLAINTEXT_CONTENT);
160         return plainText;
161     } else if (std::string(type) == "general.hyperlink") {
162         OH_UdsHyperlink* link = OH_UdsHyperlink_Create();
163         OH_UdsHyperlink_SetUrl(link, HYPERLINK_URL);
164         return link;
165     } else if (std::string(type) == "general.html") {
166         OH_UdsHtml* html = OH_UdsHtml_Create();
167         OH_UdsHtml_SetContent(html, HTML_URL);
168         return html;
169     }
170     return nullptr;
171 }
172 
173 /**
174  * @tc.name: OH_PasteboardSubscriber_Create001
175  * @tc.desc: OH_PasteboardObserver_Create test
176  * @tc.type: FUNC
177  * @tc.require: AROOOH5R5G
178  */
179 HWTEST_F(PasteboardCapiTest, OH_PasteboardSubscriber_Create001, TestSize.Level1)
180 {
181     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
182     EXPECT_NE(observer, nullptr);
183 
184     OH_PasteboardObserver_Destroy(observer);
185     OH_PasteboardObserver_Destroy(nullptr);
186 }
187 
188 /**
189  * @tc.name: OH_PasteboardObserver_SetData001
190  * @tc.desc: OH_PasteboardObserver_SetData test valid
191  * @tc.type: FUNC
192  * @tc.require: AROOOH5R5G
193  */
194 HWTEST_F(PasteboardCapiTest, OH_PasteboardObserver_SetData001, TestSize.Level1)
195 {
196     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
197     void* context = static_cast<void*>(pasteboard);
198     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
199 
200     int setRes1 = OH_PasteboardObserver_SetData(observer, context, CallbackFunc, ContextFinalizeFunc);
201     EXPECT_EQ(setRes1, ERR_OK);
202 
203     OH_PasteboardObserver_Destroy(observer);
204     OH_Pasteboard_Destroy(pasteboard);
205 }
206 
207 /**
208  * @tc.name: OH_PasteboardObserver_SetData002
209  * @tc.desc: OH_PasteboardObserver_SetData test invalid
210  * @tc.type: FUNC
211  * @tc.require: AROOOH5R5G
212  */
213 HWTEST_F(PasteboardCapiTest, OH_PasteboardObserver_SetData002, TestSize.Level1)
214 {
215     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
216     void* context = static_cast<void*>(pasteboard);
217     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
218 
219     int setRes1 = OH_PasteboardObserver_SetData(nullptr, context, CallbackFunc, ContextFinalizeFunc);
220     EXPECT_EQ(setRes1, ERR_INVALID_PARAMETER);
221 
222     int setRes2 = OH_PasteboardObserver_SetData(observer, context, nullptr, ContextFinalizeFunc);
223     EXPECT_EQ(setRes2, ERR_INVALID_PARAMETER);
224 
225     int setRes3 = OH_PasteboardObserver_SetData(observer, context, CallbackFunc, nullptr);
226     EXPECT_EQ(setRes3, ERR_INVALID_PARAMETER);
227 
228     OH_PasteboardObserver_Destroy(observer);
229     OH_Pasteboard_Destroy(pasteboard);
230 }
231 
232 /**
233  * @tc.name: OH_Pasteboard_Create001
234  * @tc.desc: OH_Pasteboard_Create test valid
235  * @tc.type: FUNC
236  * @tc.require: AROOOH5R5G
237  */
238 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Create001, TestSize.Level1)
239 {
240     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
241     EXPECT_NE(pasteboard, nullptr);
242 
243     OH_Pasteboard_Destroy(pasteboard);
244 }
245 
246 /**
247  * @tc.name: OH_Pasteboard_Subscribe001
248  * @tc.desc: OH_Pasteboard_Subscribe test valid
249  * @tc.type: FUNC
250  * @tc.require: AROOOH5R5G
251  */
252 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Subscribe001, TestSize.Level1)
253 {
254     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
255     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
256     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
257 
258     int res = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
259     EXPECT_EQ(res, ERR_OK);
260 
261     int resRepeat = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
262     EXPECT_EQ(resRepeat, ERR_OK);
263 
264     OH_Pasteboard_Destroy(pasteboard);
265     OH_PasteboardObserver_Destroy(observer);
266 }
267 
268 /**
269  * @tc.name: OH_Pasteboard_Subscribe002
270  * @tc.desc: OH_Pasteboard_Subscribe test invalid
271  * @tc.type: FUNC
272  * @tc.require: AROOOH5R5G
273  */
274 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Subscribe002, TestSize.Level1)
275 {
276     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
277     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
278     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
279 
280     int res1 = OH_Pasteboard_Subscribe(nullptr, NOTIFY_LOCAL_DATA_CHANGE, observer);
281     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
282 
283     int res2 = OH_Pasteboard_Subscribe(pasteboard, 10, observer);
284     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
285 
286     int res3 = OH_Pasteboard_Subscribe(pasteboard, -1, observer);
287     EXPECT_EQ(res3, ERR_INVALID_PARAMETER);
288 
289     int res4 = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, nullptr);
290     EXPECT_EQ(res4, ERR_INVALID_PARAMETER);
291 
292     OH_Pasteboard_Destroy(pasteboard);
293     OH_PasteboardObserver_Destroy(observer);
294 }
295 
296 /**
297  * @tc.name: OH_Pasteboard_Unsubcribe001
298  * @tc.desc: OH_Pasteboard_Unsubcribe test valid
299  * @tc.type: FUNC
300  * @tc.require: AROOOH5R5G
301  */
302 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Unsubcribe001, TestSize.Level1)
303 {
304     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
305     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
306     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
307 
308     OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
309 
310     int res = OH_Pasteboard_Unsubscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
311     EXPECT_EQ(res, ERR_OK);
312 
313     OH_Pasteboard_Destroy(pasteboard);
314     OH_PasteboardObserver_Destroy(observer);
315 }
316 
317 /**
318  * @tc.name: OH_Pasteboard_Unsubscribe002
319  * @tc.desc: OH_Pasteboard_Unsubscribe test invalid
320  * @tc.type: FUNC
321  * @tc.require: AROOOH5R5G
322  */
323 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Unsubcribe002, TestSize.Level1)
324 {
325     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
326     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
327     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
328 
329     int res1 = OH_Pasteboard_Unsubscribe(nullptr, NOTIFY_LOCAL_DATA_CHANGE, observer);
330     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
331 
332     int res2 = OH_Pasteboard_Unsubscribe(pasteboard, 10, observer);
333     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
334 
335     int res3 = OH_Pasteboard_Unsubscribe(pasteboard, -1, observer);
336     EXPECT_EQ(res3, ERR_INVALID_PARAMETER);
337 
338     int res4 = OH_Pasteboard_Unsubscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, nullptr);
339     EXPECT_EQ(res4, ERR_INVALID_PARAMETER);
340 
341     OH_Pasteboard_Destroy(pasteboard);
342     OH_PasteboardObserver_Destroy(observer);
343 }
344 
345 /**
346  * @tc.name: OH_Pasteboard_IsRemoteData001
347  * @tc.desc: OH_Pasteboard_IsRemoteData test valid
348  * @tc.type: FUNC
349  * @tc.require: AROOOH5R5G
350  */
351 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_IsRemoteData001, TestSize.Level1)
352 {
353     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
354 
355     bool res = OH_Pasteboard_IsRemoteData(pasteboard);
356     EXPECT_FALSE(res);
357 
358     OH_Pasteboard_Destroy(pasteboard);
359 }
360 
361 /**
362  * @tc.name: OH_Pasteboard_GetDataSrouce001
363  * @tc.desc: OH_Pasteboard_GetDataSrouce test valid
364  * @tc.type: FUNC
365  * @tc.require: AROOOH5R5G
366  */
367 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataSrouce001, TestSize.Level1)
368 {
369     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
370     OH_UdmfData* setData = OH_UdmfData_Create();
371     OH_UdmfRecord* record = OH_UdmfRecord_Create();
372     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
373     char content[] = "hello world";
374     OH_UdsPlainText_SetContent(plainText, content);
375     OH_UdmfRecord_AddPlainText(record, plainText);
376     OH_UdmfData_AddRecord(setData, record);
377 
378     OH_Pasteboard_SetData(pasteboard, setData);
379 
380     int len = 100;
381     char source[100];
382     int res = OH_Pasteboard_GetDataSource(pasteboard, source, len);
383     EXPECT_EQ(res, ERR_OK);
384 
385     OH_Pasteboard_Destroy(pasteboard);
386 }
387 
388 /**
389  * @tc.name: OH_Pasteboard_GetMimeTypes001
390  * @tc.desc: OH_Pasteboard_GetMimeTypes test empty data
391  * @tc.type: FUNC
392  * @tc.require: AR20241012964265
393  */
394 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes001, TestSize.Level1)
395 {
396     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
397     ASSERT_TRUE(pasteboard);
398     OH_Pasteboard_ClearData(pasteboard);
399     unsigned int count = 1000;
400     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
401     EXPECT_EQ(0, count);
402     EXPECT_TRUE(res == nullptr);
403 }
404 
405 /**
406  * @tc.name: OH_Pasteboard_GetMimeTypes002
407  * @tc.desc: OH_Pasteboard_GetMimeTypes test plainText
408  * @tc.type: FUNC
409  * @tc.require: AR20241012964265
410  */
411 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes002, TestSize.Level1)
412 {
413     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
414     ASSERT_TRUE(pasteboard);
415     OH_UdmfData* setData = OH_UdmfData_Create();
416     ASSERT_TRUE(setData);
417     OH_UdmfRecord* record = OH_UdmfRecord_Create();
418     ASSERT_TRUE(record);
419     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
420     ASSERT_TRUE(plainText);
421     char content[] = "hello world";
422     OH_UdsPlainText_SetContent(plainText, content);
423     OH_UdmfRecord_AddPlainText(record, plainText);
424     OH_UdmfData_AddRecord(setData, record);
425     OH_Pasteboard_SetData(pasteboard, setData);
426 
427     unsigned int count = 1000;
428     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
429     EXPECT_EQ(1, count);
430     EXPECT_TRUE(res != nullptr);
431     EXPECT_STREQ(MIMETYPE_TEXT_PLAIN, res[0]);
432 
433     OH_Pasteboard_Destroy(pasteboard);
434 }
435 
436 /**
437  * @tc.name: OH_Pasteboard_GetMimeTypes003
438  * @tc.desc: OH_Pasteboard_GetMimeTypes test multi Mime types
439  * @tc.type: FUNC
440  * @tc.require: AR20241012964265
441  */
442 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes003, TestSize.Level1)
443 {
444     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
445     ASSERT_TRUE(pasteboard);
446     OH_UdmfData* setData = OH_UdmfData_Create();
447     ASSERT_TRUE(setData);
448     OH_UdmfRecord* record = OH_UdmfRecord_Create();
449     ASSERT_TRUE(record);
450     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
451     ASSERT_TRUE(plainText);
452     char content[] = "hello world";
453     OH_UdsPlainText_SetContent(plainText, content);
454     OH_UdmfRecord_AddPlainText(record, plainText);
455     OH_UdmfData_AddRecord(setData, record);
456 
457     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
458     ASSERT_TRUE(record2);
459     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
460     ASSERT_TRUE(htmlText);
461     char html[] = "<div class='disabled'>hello</div>";
462     OH_UdsHtml_SetContent(htmlText, html);
463     OH_UdmfRecord_AddHtml(record2, htmlText);
464     OH_UdmfData_AddRecord(setData, record2);
465     OH_Pasteboard_SetData(pasteboard, setData);
466 
467     unsigned int count = 1000;
468     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
469     EXPECT_EQ(2, count);
470     EXPECT_TRUE(res != nullptr);
471     EXPECT_TRUE((strcmp(MIMETYPE_TEXT_PLAIN, res[0]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[1]) == 0) ||
472         (strcmp(MIMETYPE_TEXT_PLAIN, res[1]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[0]) == 0));
473 
474     OH_Pasteboard_Destroy(pasteboard);
475 }
476 
477 /**
478  * @tc.name: OH_Pasteboard_HasType001
479  * @tc.desc: OH_Pasteboard_HasType test valid
480  * @tc.type: FUNC
481  * @tc.require: AROOOH5R5G
482  */
483 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_HasType001, TestSize.Level1)
484 {
485     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
486     OH_UdmfData* setData = OH_UdmfData_Create();
487     OH_UdmfRecord* record = OH_UdmfRecord_Create();
488     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
489     char content[] = "hello world";
490     OH_UdsPlainText_SetContent(plainText, content);
491     OH_UdmfRecord_AddPlainText(record, plainText);
492     OH_UdmfData_AddRecord(setData, record);
493 
494     OH_Pasteboard_SetData(pasteboard, setData);
495     char type[] = "general.plain-text";
496     bool res = OH_Pasteboard_HasType(pasteboard, type);
497     EXPECT_FALSE(res);
498 
499     OH_Pasteboard_Destroy(pasteboard);
500 }
501 
502 /**
503  * @tc.name: OH_Pasteboard_HasData001
504  * @tc.desc: OH_Pasteboard_HasData test valid
505  * @tc.type: FUNC
506  * @tc.require: AROOOH5R5G
507  */
508 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_HasData001, TestSize.Level1)
509 {
510     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
511     OH_Pasteboard_ClearData(pasteboard);
512     bool res = OH_Pasteboard_HasData(pasteboard);
513     EXPECT_FALSE(res);
514 
515     OH_UdmfData* setData = OH_UdmfData_Create();
516     OH_UdmfRecord* record = OH_UdmfRecord_Create();
517     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
518     char content[] = "hello world";
519     OH_UdsPlainText_SetContent(plainText, content);
520     OH_UdmfRecord_AddPlainText(record, plainText);
521     OH_UdmfData_AddRecord(setData, record);
522 
523     OH_Pasteboard_SetData(pasteboard, setData);
524 
525     res = OH_Pasteboard_HasData(pasteboard);
526     EXPECT_TRUE(res);
527 
528     OH_Pasteboard_Destroy(pasteboard);
529 }
530 
531 /**
532  * @tc.name: OH_Pasteboard_ClearData001
533  * @tc.desc: OH_Pasteboard_ClearData test valid
534  * @tc.type: FUNC
535  * @tc.require: AROOOH5R5G
536  */
537 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_ClearData001, TestSize.Level1)
538 {
539     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
540     bool res = OH_Pasteboard_ClearData(pasteboard);
541     EXPECT_EQ(res, ERR_OK);
542 
543     OH_Pasteboard_Destroy(pasteboard);
544 }
545 
546 /**
547  * @tc.name: OH_Pasteboard_SetData001
548  * @tc.desc: OH_Pasteboard_SetData test valid
549  * @tc.type: FUNC
550  * @tc.require: AROOOH5R5G
551  */
552 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_SetData001, TestSize.Level1)
553 {
554     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
555     OH_UdmfData *setData = OH_UdmfData_Create();
556     OH_UdmfRecord *record = OH_UdmfRecord_Create();
557     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
558     char content[] = "hello world";
559     OH_UdsPlainText_SetContent(plainText, content);
560     OH_UdmfRecord_AddPlainText(record, plainText);
561     OH_UdmfData_AddRecord(setData, record);
562 
563     bool res = OH_Pasteboard_SetData(pasteboard, setData);
564     EXPECT_EQ(res, ERR_OK);
565 
566     OH_Pasteboard_Destroy(pasteboard);
567     OH_UdsPlainText_Destroy(plainText);
568     OH_UdmfRecord_Destroy(record);
569     OH_UdmfData_Destroy(setData);
570 }
571 
572 /**
573  * @tc.name: OH_Pasteboard_GetData001
574  * @tc.desc: OH_Pasteboard_GetData test valid
575  * @tc.type: FUNC
576  * @tc.require: AROOOH5R5G
577  */
578 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData001, TestSize.Level1)
579 {
580     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
581     OH_UdmfData* setData = OH_UdmfData_Create();
582     OH_UdmfRecord* record = OH_UdmfRecord_Create();
583     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
584     char content[] = "hello world";
585     OH_UdsPlainText_SetContent(plainText, content);
586     OH_UdmfRecord_AddPlainText(record, plainText);
587     OH_UdmfData_AddRecord(setData, record);
588 
589     int res = OH_Pasteboard_SetData(pasteboard, setData);
590     EXPECT_EQ(res, ERR_OK);
591 
592     int status = -1;
593     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
594     EXPECT_EQ(status, ERR_OK);
595     EXPECT_NE(getData, nullptr);
596 
597     unsigned int count = 0;
598     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &count);
599     EXPECT_EQ(count, 1);
600     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
601     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
602     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
603     EXPECT_EQ(strcmp(getContent, content), 0);
604 
605     OH_Pasteboard_Destroy(pasteboard);
606     OH_UdsPlainText_Destroy(plainText);
607     OH_UdsPlainText_Destroy(getPlainText);
608     OH_UdmfRecord_Destroy(record);
609     OH_UdmfData_Destroy(setData);
610     OH_UdmfData_Destroy(getData);
611 }
612 
613 /**
614  * @tc.name: OH_Pasteboard_GetData002
615  * @tc.desc: OH_Pasteboard_GetData test valid
616  * @tc.type: FUNC
617  * @tc.require: AROOOH5R5G
618  */
619 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData002, TestSize.Level1)
620 {
621     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
622     OH_UdmfData* setData = OH_UdmfData_Create();
623     OH_UdmfRecord* record = OH_UdmfRecord_Create();
624     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
625     EXPECT_NE(provider, nullptr);
626     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
627     OH_UdmfData_AddRecord(setData, record);
628 
629     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
630     OH_UdmfRecord_SetProvider(record, types, 3, provider);
631     int res = OH_Pasteboard_SetData(pasteboard, setData);
632     EXPECT_EQ(res, ERR_OK);
633 
634     int status = -1;
635     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
636     EXPECT_EQ(status, ERR_OK);
637     EXPECT_NE(getData, nullptr);
638 
639     unsigned int count = 0;
640     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &count);
641     EXPECT_EQ(count, 1);
642     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
643     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
644     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
645     EXPECT_EQ(strcmp(getContent, PLAINTEXT_CONTENT), 0);
646 
647     OH_UdsHyperlink *getHyperLink = OH_UdsHyperlink_Create();
648     OH_UdmfRecord_GetHyperlink(getRecords[0], getHyperLink);
649     const char *getUrl = OH_UdsHyperlink_GetUrl(getHyperLink);
650     EXPECT_EQ(strcmp(getUrl, HYPERLINK_URL), 0);
651     OH_Pasteboard_Destroy(pasteboard);
652     OH_UdsPlainText_Destroy(getPlainText);
653     OH_UdsHyperlink_Destroy(getHyperLink);
654     OH_UdmfRecord_Destroy(record);
655     OH_UdmfData_Destroy(setData);
656     OH_UdmfData_Destroy(getData);
657 }
658 
659 /**
660  * @tc.name: OH_Pasteboard_GetData003
661  * @tc.desc: OH_Pasteboard_GetData test valid
662  * @tc.type: FUNC
663  * @tc.require: AROOOH5R5G
664  */
665 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData003, TestSize.Level1)
666 {
667     char typeId[] = "ApplicationDefined-myType";
668     unsigned char entry[] = "CreateGeneralRecord1";
669     unsigned int count = sizeof(entry);
670     OH_UdmfRecord *record = OH_UdmfRecord_Create();
671     int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
672     EXPECT_EQ(addRes1, ERR_OK);
673 
674     OH_UdmfData* setData = OH_UdmfData_Create();
675     OH_UdmfData_AddRecord(setData, record);
676     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
677     int res = OH_Pasteboard_SetData(pasteboard, setData);
678     EXPECT_EQ(res, ERR_OK);
679 
680     int status = -1;
681     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
682     EXPECT_EQ(status, ERR_OK);
683     EXPECT_NE(getData, nullptr);
684 
685     unsigned int getrecordCount = 0;
686     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &getrecordCount);
687     EXPECT_EQ(getrecordCount, 1);
688 
689     unsigned int getCount = 0;
690     unsigned char *getEntry;
691     int getRes = OH_UdmfRecord_GetGeneralEntry(getRecords[0], typeId, &getEntry, &getCount);
692     EXPECT_EQ(getRes, ERR_OK);
693     EXPECT_EQ(getCount, count);
694     EXPECT_EQ(memcmp(entry, getEntry, getCount), 0);
695 
696     OH_Pasteboard_Destroy(pasteboard);
697     OH_UdmfRecord_Destroy(record);
698     OH_UdmfData_Destroy(setData);
699     OH_UdmfData_Destroy(getData);
700 }
701 
702 /**
703  * @tc.name: OH_Pasteboard_GetData004
704  * @tc.desc: OH_Pasteboard_GetData test data type
705  * @tc.type: FUNC
706  */
707 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData004, TestSize.Level1)
708 {
709     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData004 start");
710     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
711     OH_UdmfData* setData = OH_UdmfData_Create();
712     OH_UdmfRecord* record = OH_UdmfRecord_Create();
713 
714     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
715     EXPECT_NE(provider, nullptr);
716     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
717 
718     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
719     OH_UdmfRecord_SetProvider(record, types, 3, provider);
720     OH_UdmfData_AddRecord(setData, record);
721 
722     int res = OH_Pasteboard_SetData(pasteboard, setData);
723     EXPECT_EQ(res, ERR_OK);
724 
725     PasteData pasteData;
726     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
727     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
728 
729     auto record1 = pasteData.GetRecordAt(0);
730     auto mimeType = record1->GetMimeType();
731     EXPECT_EQ(mimeType, MIMETYPE_TEXT_PLAIN);
732 
733     OH_Pasteboard_Destroy(pasteboard);
734     OH_UdmfRecord_Destroy(record);
735     OH_UdmfData_Destroy(setData);
736     OH_UdmfRecordProvider_Destroy(provider);
737     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData004 end");
738 }
739 
740 /**
741  * @tc.name: OH_Pasteboard_GetData005
742  * @tc.desc: OH_Pasteboard_GetData test data type
743  * @tc.type: FUNC
744  */
745 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData005, TestSize.Level1)
746 {
747     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData005 start");
748     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
749     OH_UdmfData* setData = OH_UdmfData_Create();
750     OH_UdmfRecord* record = OH_UdmfRecord_Create();
751 
752     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
753     EXPECT_NE(provider, nullptr);
754     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
755     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
756     OH_UdmfRecord_SetProvider(record, types, 3, provider);
757 
758     OH_UdsHyperlink *link = OH_UdsHyperlink_Create();
759     OH_UdsHyperlink_SetUrl(link, HYPERLINK_URL);
760     OH_UdmfRecord_AddHyperlink(record, link);
761 
762     OH_UdmfData_AddRecord(setData, record);
763     auto res = OH_Pasteboard_SetData(pasteboard, setData);
764     EXPECT_EQ(res, ERR_OK);
765 
766     PasteData pasteData;
767     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
768     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
769 
770     auto record1 = pasteData.GetRecordAt(0);
771     auto mimeType = record1->GetMimeType();
772     EXPECT_EQ(mimeType, MIMETYPE_TEXT_PLAIN);
773 
774     auto text = record1->GetPlainText();
775     EXPECT_EQ(strcmp(text->c_str(), PLAINTEXT_CONTENT), 0);
776 
777     OH_Pasteboard_Destroy(pasteboard);
778     OH_UdmfRecord_Destroy(record);
779     OH_UdmfData_Destroy(setData);
780     OH_UdsHyperlink_Destroy(link);
781     OH_UdmfRecordProvider_Destroy(provider);
782     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData005 end");
783 }
784 
785 /**
786  * @tc.name: OH_Pasteboard_GetData006
787  * @tc.desc: OH_Pasteboard_GetData test data type
788  * @tc.type: FUNC
789  */
790 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData006, TestSize.Level1)
791 {
792     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData006 start");
793     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
794     OH_UdmfData* setData = OH_UdmfData_Create();
795     OH_UdmfRecord* record = OH_UdmfRecord_Create();
796 
797     OH_UdsHtml *html = OH_UdsHtml_Create();
798     OH_UdsHtml_SetContent(html, HTML_TEXT);
799     OH_UdmfRecord_AddHtml(record, html);
800 
801     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
802     EXPECT_NE(provider, nullptr);
803     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
804     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
805     OH_UdmfRecord_SetProvider(record, types, 3, provider);
806 
807     OH_UdmfData_AddRecord(setData, record);
808     bool res = OH_Pasteboard_SetData(pasteboard, setData);
809     EXPECT_EQ(res, ERR_OK);
810 
811     PasteData pasteData;
812     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
813     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
814 
815     auto record1 = pasteData.GetRecordAt(0);
816     auto mimeType = record1->GetMimeType();
817     EXPECT_EQ(mimeType, MIMETYPE_TEXT_HTML);
818 
819     auto html1 = record1->GetHtmlText();
820     EXPECT_EQ(strcmp(html1->c_str(), HTML_TEXT), 0);
821 
822     OH_Pasteboard_Destroy(pasteboard);
823     OH_UdmfRecord_Destroy(record);
824     OH_UdmfData_Destroy(setData);
825     OH_UdmfRecordProvider_Destroy(provider);
826     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData006 end");
827 }
828 
829 /**
830  * @tc.name: OH_Pasteboard_GetData007
831  * @tc.desc: OH_Pasteboard_GetData test data type
832  * @tc.type: FUNC
833  */
834 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData007, TestSize.Level1)
835 {
836     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData007 start");
837     std::string plainText = "helloWorld";
838     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
839     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
840     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
841 
842     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
843     int status = -1;
844     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
845     EXPECT_EQ(status, ERR_OK);
846     EXPECT_NE(getData, nullptr);
847 
848     unsigned int getrecordCount = 0;
849     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &getrecordCount);
850     EXPECT_EQ(getrecordCount, 1);
851     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
852     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
853     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
854     EXPECT_STREQ(getContent, plainText.c_str());
855 
856     OH_Pasteboard_Destroy(pasteboard);
857     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData007 end");
858 }
859 
OH_Pasteboard_ProgressListener(Pasteboard_ProgressInfo * progressInfo)860 void OH_Pasteboard_ProgressListener(Pasteboard_ProgressInfo *progressInfo)
861 {
862     int percentage = OH_Pasteboard_ProgressInfo_GetProgress(progressInfo);
863     printf("percentage = %d\n", percentage);
864 }
865 
866 /**
867  * @tc.name: OH_Pasteboard_GetDataWithProgress001
868  * @tc.desc: should get html & text when set html & text with https uri and tag
869  * @tc.type: FUNC
870  */
871 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress001, TestSize.Level1)
872 {
873     int status = -1;
874     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
875     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, nullptr, &status);
876     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
877     EXPECT_EQ(getData, nullptr);
878 
879     g_params = OH_Pasteboard_GetDataParams_Create();
880     EXPECT_NE(g_params, nullptr);
881     getData = OH_Pasteboard_GetDataWithProgress(nullptr, g_params, &status);
882     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
883     EXPECT_EQ(getData, nullptr);
884     getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, nullptr);
885     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
886     EXPECT_EQ(getData, nullptr);
887     OH_Pasteboard_Destroy(pasteboard);
888     OH_Pasteboard_GetDataParams_Destroy(g_params);
889 }
890 
891 /**
892  * @tc.name: OH_Pasteboard_GetDataWithProgress002
893  * @tc.desc: should get html & text when set html & text with https uri and tag
894  * @tc.type: FUNC
895  */
896 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress002, TestSize.Level1)
897 {
898     int status = -1;
899     OH_Pasteboard *pasteboard = OH_Pasteboard_Create();
900     g_params = OH_Pasteboard_GetDataParams_Create();
901     EXPECT_NE(g_params, nullptr);
902     const char *uri = "/data/storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/"
903         "files/data/storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/files/data/"
904         "storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/files/haps/entry/files/dstFile.txt";
905     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
906     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, strlen(uri));
907     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
908     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
909     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
910     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
911     EXPECT_EQ(getData, nullptr);
912     OH_Pasteboard_Destroy(pasteboard);
913     OH_Pasteboard_GetDataParams_Destroy(g_params);
914 }
915 
916 /**
917  * @tc.name: OH_Pasteboard_GetDataWithProgress003
918  * @tc.desc: should get html & text when set html & text with https uri and tag
919  * @tc.type: FUNC
920  */
921 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress003, TestSize.Level1)
922 {
923     int status = -1;
924     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
925     g_params = OH_Pasteboard_GetDataParams_Create();
926     EXPECT_NE(g_params, nullptr);
927     const char *uri = "/data/storage/el2/base/haps/entry/files/dstFile.txt";
928     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
929     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, uriLen);
930     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
931     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
932     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
933     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
934     EXPECT_EQ(getData, nullptr);
935     OH_Pasteboard_Destroy(pasteboard);
936     OH_Pasteboard_GetDataParams_Destroy(g_params);
937 }
938 
939 /**
940  * @tc.name: OH_Pasteboard_GetDataWithProgress004
941  * @tc.desc: should get html & text when set html & text with https uri and tag
942  * @tc.type: FUNC
943  */
944 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress004, TestSize.Level1)
945 {
946     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
947     int32_t ret = OH_Pasteboard_ClearData(pasteboard);
948     EXPECT_EQ(ret, ERR_OK);
949     g_params = OH_Pasteboard_GetDataParams_Create();
950     EXPECT_NE(g_params, nullptr);
951     const char *uri = "/data/storage/el2/base/haps/entry/files/dstFile.txt";
952     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
953     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, strlen(uri));
954     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
955     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
956     int status = -1;
957     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
958     EXPECT_EQ(status, ERR_PASTEBOARD_GET_DATA_FAILED);
959     EXPECT_EQ(getData, nullptr);
960     OH_Pasteboard_Destroy(pasteboard);
961     OH_Pasteboard_GetDataParams_Destroy(g_params);
962 }
963 
964 /**
965  * @tc.name: OH_Pasteboard_GetDataWithProgress005
966  * @tc.desc: should get html & text when set html & text with https uri and tag
967  * @tc.type: FUNC
968  */
969 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress005, TestSize.Level1)
970 {
971     std::string plainText = "helloWorld";
972     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
973     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
974     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
975 
976     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
977     g_params = OH_Pasteboard_GetDataParams_Create();
978     EXPECT_NE(g_params, nullptr);
979     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
980     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_OVERWRITE);
981     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
982     int status = -1;
983     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
984     EXPECT_EQ(status, ERR_OK);
985     EXPECT_NE(getData, nullptr);
986     OH_Pasteboard_Destroy(pasteboard);
987     OH_Pasteboard_GetDataParams_Destroy(g_params);
988 }
989 
Pasteboard_ProgressListener(Pasteboard_ProgressInfo * progressInfo)990 void Pasteboard_ProgressListener(Pasteboard_ProgressInfo *progressInfo)
991 {
992     int percentage = OH_Pasteboard_ProgressInfo_GetProgress(progressInfo);
993     printf("percentage = %d\n", percentage);
994     if (g_params != nullptr) {
995         OH_Pasteboard_ProgressCancel(g_params);
996     }
997 }
998 
999 /**
1000  * @tc.name: OH_Pasteboard_GetDataWithProgress006
1001  * @tc.desc: should get html & text when set html & text with https uri and tag
1002  * @tc.type: FUNC
1003  */
1004 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress006, TestSize.Level1)
1005 {
1006     std::string plainText = "helloWorld";
1007     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
1008     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
1009     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
1010 
1011     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1012     g_params = OH_Pasteboard_GetDataParams_Create();
1013     EXPECT_NE(g_params, nullptr);
1014     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1015     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_OVERWRITE);
1016     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, Pasteboard_ProgressListener);
1017     int status = -1;
1018     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1019     EXPECT_EQ(status, ERR_OK);
1020     EXPECT_NE(getData, nullptr);
1021     OH_Pasteboard_Destroy(pasteboard);
1022     OH_Pasteboard_GetDataParams_Destroy(g_params);
1023 }
1024 } // namespace OHOS::Test
1025