• 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 {
39 namespace Test {
40 class PasteboardCapiTest : public testing::Test {
41 public:
42     static void SetUpTestCase(void);
43     static void TearDownTestCase(void);
44     void SetUp();
45     void TearDown();
46     static void CallbackFunc(void* context, Pasteboard_NotifyType type);
47     static void RemoveCallbackSideEffects();
48     static void ContextFinalizeFunc(void* context);
49     static int callbackValue;
50     static void AllocTestTokenId();
51     static void DeleteTestTokenId();
52     static void SetTestTokenId();
53     static void RestoreSelfTokenId();
54     static void* GetDataCallback(void* context, const char* type);
55     static constexpr int INIT_VALUE = 0;
56     static constexpr int UPDATE_VALUE = 1;
57     static constexpr int uriLen = 10;
58     static uint64_t selfTokenId_;
59     static AccessTokenID testTokenId_;
60     static constexpr char PLAINTEXT_CONTENT[] = "PLAINTEXT_CONTENT";
61     static constexpr char HYPERLINK_URL[] = "file://data/image.png";
62     static constexpr char HTML_URL[] = "file://data/image.png";
63     static constexpr char HTML_TEXT[] = "<P>html text</P>";
64 };
65 uint64_t PasteboardCapiTest::selfTokenId_ = 0;
66 AccessTokenID PasteboardCapiTest::testTokenId_ = 0;
67 int PasteboardCapiTest::callbackValue = 0;
68 static Pasteboard_GetDataParams *g_params = nullptr;
69 
SetUpTestCase(void)70 void PasteboardCapiTest::SetUpTestCase(void)
71 {
72     callbackValue = INIT_VALUE;
73     selfTokenId_ = GetSelfTokenID();
74     AllocTestTokenId();
75 }
76 
TearDownTestCase(void)77 void PasteboardCapiTest::TearDownTestCase(void)
78 {
79     RemoveCallbackSideEffects();
80     DeleteTestTokenId();
81 }
82 
SetUp(void)83 void PasteboardCapiTest::SetUp(void)
84 {
85 }
86 
TearDown(void)87 void PasteboardCapiTest::TearDown(void)
88 {
89 }
90 
AllocTestTokenId()91 void PasteboardCapiTest::AllocTestTokenId()
92 {
93     std::vector<int32_t> ids;
94     auto ret = AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids);
95     if (ret != ERR_OK || ids.empty()) {
96         PASTEBOARD_HILOGE(PASTEBOARD_MODULE_SERVICE, "query active user failed errCode = %{public}d", ret);
97         return;
98     }
99     HapInfoParams infoParams = {
100         .userID = ids[0],
101         .bundleName = "ohos.privacy_test.pasteboard",
102         .instIndex = 0,
103         .appIDDesc = "privacy_test.pasteboard"
104     };
105     PermissionStateFull testState = {
106         .permissionName = "ohos.permission.DUMP",
107         .isGeneral = true,
108         .resDeviceID = { "local" },
109         .grantStatus = { PermissionState::PERMISSION_GRANTED },
110         .grantFlags = { 1 }
111     };
112     HapPolicyParams policyParams = {
113         .apl = APL_NORMAL,
114         .domain = "test.domain.pasteboard",
115         .permList = {},
116         .permStateList = { testState }
117     };
118 
119     AccessTokenKit::AllocHapToken(infoParams, policyParams);
120     testTokenId_ = Security::AccessToken::AccessTokenKit::GetHapTokenID(
121         infoParams.userID, infoParams.bundleName, infoParams.instIndex);
122     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "userID = %{public}d, testTokenId = 0x%{public}x.", infoParams.userID,
123         testTokenId_);
124 }
125 
DeleteTestTokenId()126 void PasteboardCapiTest::DeleteTestTokenId()
127 {
128     AccessTokenKit::DeleteToken(testTokenId_);
129 }
130 
131 
SetTestTokenId()132 void PasteboardCapiTest::SetTestTokenId()
133 {
134     auto ret = SetSelfTokenID(testTokenId_);
135     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "testTokenId = 0x%{public}x, ret = %{public}d!", testTokenId_, ret);
136 }
137 
RestoreSelfTokenId()138 void PasteboardCapiTest::RestoreSelfTokenId()
139 {
140     auto ret = SetSelfTokenID(selfTokenId_);
141     PASTEBOARD_HILOGD(PASTEBOARD_MODULE_SERVICE, "ret = %{public}d!", ret);
142 }
143 
CallbackFunc(void * context,Pasteboard_NotifyType type)144 void PasteboardCapiTest::CallbackFunc(void* context, Pasteboard_NotifyType type)
145 {
146     callbackValue = UPDATE_VALUE;
147 }
148 
RemoveCallbackSideEffects()149 void PasteboardCapiTest::RemoveCallbackSideEffects()
150 {
151     callbackValue = INIT_VALUE;
152 }
153 
ContextFinalizeFunc(void * context)154 void PasteboardCapiTest::ContextFinalizeFunc(void* context) {}
155 
GetDataCallback(void * context,const char * type)156 void* PasteboardCapiTest::GetDataCallback(void* context, const char* type)
157 {
158     if (std::string(type) == "general.plain-text") {
159         OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
160         OH_UdsPlainText_SetContent(plainText, PLAINTEXT_CONTENT);
161         return plainText;
162     } else if (std::string(type) == "general.hyperlink") {
163         OH_UdsHyperlink* link = OH_UdsHyperlink_Create();
164         OH_UdsHyperlink_SetUrl(link, HYPERLINK_URL);
165         return link;
166     } else if (std::string(type) == "general.html") {
167         OH_UdsHtml* html = OH_UdsHtml_Create();
168         OH_UdsHtml_SetContent(html, HTML_URL);
169         return html;
170     }
171     return nullptr;
172 }
173 
174 /**
175  * @tc.name: OH_PasteboardSubscriber_Create001
176  * @tc.desc: OH_PasteboardObserver_Create test
177  * @tc.type: FUNC
178  * @tc.require: AROOOH5R5G
179  */
180 HWTEST_F(PasteboardCapiTest, OH_PasteboardSubscriber_Create001, TestSize.Level1)
181 {
182     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
183     EXPECT_NE(observer, nullptr);
184 
185     OH_PasteboardObserver_Destroy(observer);
186     OH_PasteboardObserver_Destroy(nullptr);
187 }
188 
189 /**
190  * @tc.name: OH_PasteboardObserver_SetData001
191  * @tc.desc: OH_PasteboardObserver_SetData test valid
192  * @tc.type: FUNC
193  * @tc.require: AROOOH5R5G
194  */
195 HWTEST_F(PasteboardCapiTest, OH_PasteboardObserver_SetData001, TestSize.Level1)
196 {
197     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
198     void* context = static_cast<void*>(pasteboard);
199     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
200 
201     int setRes1 = OH_PasteboardObserver_SetData(observer, context, CallbackFunc, ContextFinalizeFunc);
202     EXPECT_EQ(setRes1, ERR_OK);
203 
204     OH_PasteboardObserver_Destroy(observer);
205     OH_Pasteboard_Destroy(pasteboard);
206 }
207 
208 /**
209  * @tc.name: OH_PasteboardObserver_SetData002
210  * @tc.desc: OH_PasteboardObserver_SetData test invalid
211  * @tc.type: FUNC
212  * @tc.require: AROOOH5R5G
213  */
214 HWTEST_F(PasteboardCapiTest, OH_PasteboardObserver_SetData002, TestSize.Level1)
215 {
216     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
217     void* context = static_cast<void*>(pasteboard);
218     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
219 
220     int setRes1 = OH_PasteboardObserver_SetData(nullptr, context, CallbackFunc, ContextFinalizeFunc);
221     EXPECT_EQ(setRes1, ERR_INVALID_PARAMETER);
222 
223     int setRes2 = OH_PasteboardObserver_SetData(observer, context, nullptr, ContextFinalizeFunc);
224     EXPECT_EQ(setRes2, ERR_INVALID_PARAMETER);
225 
226     int setRes3 = OH_PasteboardObserver_SetData(observer, context, CallbackFunc, nullptr);
227     EXPECT_EQ(setRes3, ERR_INVALID_PARAMETER);
228 
229     OH_PasteboardObserver_Destroy(observer);
230     OH_Pasteboard_Destroy(pasteboard);
231 }
232 
233 /**
234  * @tc.name: OH_Pasteboard_Create001
235  * @tc.desc: OH_Pasteboard_Create test valid
236  * @tc.type: FUNC
237  * @tc.require: AROOOH5R5G
238  */
239 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Create001, TestSize.Level1)
240 {
241     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
242     EXPECT_NE(pasteboard, nullptr);
243 
244     OH_Pasteboard_Destroy(pasteboard);
245 }
246 
247 /**
248  * @tc.name: OH_Pasteboard_Subscribe001
249  * @tc.desc: OH_Pasteboard_Subscribe test valid
250  * @tc.type: FUNC
251  * @tc.require: AROOOH5R5G
252  */
253 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Subscribe001, TestSize.Level1)
254 {
255     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
256     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
257     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
258 
259     int res = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
260     EXPECT_EQ(res, ERR_OK);
261 
262     int resRepeat = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
263     EXPECT_EQ(resRepeat, ERR_OK);
264 
265     OH_Pasteboard_Destroy(pasteboard);
266     OH_PasteboardObserver_Destroy(observer);
267 }
268 
269 /**
270  * @tc.name: OH_Pasteboard_Subscribe002
271  * @tc.desc: OH_Pasteboard_Subscribe test invalid
272  * @tc.type: FUNC
273  * @tc.require: AROOOH5R5G
274  */
275 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Subscribe002, TestSize.Level1)
276 {
277     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
278     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
279     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
280 
281     int res1 = OH_Pasteboard_Subscribe(nullptr, NOTIFY_LOCAL_DATA_CHANGE, observer);
282     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
283 
284     int res2 = OH_Pasteboard_Subscribe(pasteboard, 10, observer);
285     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
286 
287     int res3 = OH_Pasteboard_Subscribe(pasteboard, -1, observer);
288     EXPECT_EQ(res3, ERR_INVALID_PARAMETER);
289 
290     int res4 = OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, nullptr);
291     EXPECT_EQ(res4, ERR_INVALID_PARAMETER);
292 
293     OH_Pasteboard_Destroy(pasteboard);
294     OH_PasteboardObserver_Destroy(observer);
295 }
296 
297 /**
298  * @tc.name: OH_Pasteboard_Unsubcribe001
299  * @tc.desc: OH_Pasteboard_Unsubcribe test valid
300  * @tc.type: FUNC
301  * @tc.require: AROOOH5R5G
302  */
303 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Unsubcribe001, TestSize.Level1)
304 {
305     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
306     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
307     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
308 
309     OH_Pasteboard_Subscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
310 
311     int res = OH_Pasteboard_Unsubscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, observer);
312     EXPECT_EQ(res, ERR_OK);
313 
314     OH_Pasteboard_Destroy(pasteboard);
315     OH_PasteboardObserver_Destroy(observer);
316 }
317 
318 /**
319  * @tc.name: OH_Pasteboard_Unsubscribe002
320  * @tc.desc: OH_Pasteboard_Unsubscribe test invalid
321  * @tc.type: FUNC
322  * @tc.require: AROOOH5R5G
323  */
324 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_Unsubcribe002, TestSize.Level1)
325 {
326     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
327     OH_PasteboardObserver* observer = OH_PasteboardObserver_Create();
328     OH_PasteboardObserver_SetData(observer, nullptr, CallbackFunc, ContextFinalizeFunc);
329 
330     int res1 = OH_Pasteboard_Unsubscribe(nullptr, NOTIFY_LOCAL_DATA_CHANGE, observer);
331     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
332 
333     int res2 = OH_Pasteboard_Unsubscribe(pasteboard, 10, observer);
334     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
335 
336     int res3 = OH_Pasteboard_Unsubscribe(pasteboard, -1, observer);
337     EXPECT_EQ(res3, ERR_INVALID_PARAMETER);
338 
339     int res4 = OH_Pasteboard_Unsubscribe(pasteboard, NOTIFY_LOCAL_DATA_CHANGE, nullptr);
340     EXPECT_EQ(res4, ERR_INVALID_PARAMETER);
341 
342     OH_Pasteboard_Destroy(pasteboard);
343     OH_PasteboardObserver_Destroy(observer);
344 }
345 
346 /**
347  * @tc.name: OH_Pasteboard_IsRemoteData001
348  * @tc.desc: OH_Pasteboard_IsRemoteData test valid
349  * @tc.type: FUNC
350  * @tc.require: AROOOH5R5G
351  */
352 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_IsRemoteData001, TestSize.Level1)
353 {
354     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
355 
356     bool res = OH_Pasteboard_IsRemoteData(pasteboard);
357     EXPECT_FALSE(res);
358 
359     OH_Pasteboard_Destroy(pasteboard);
360 }
361 
362 /**
363  * @tc.name: OH_Pasteboard_GetDataSrouce001
364  * @tc.desc: OH_Pasteboard_GetDataSrouce test valid
365  * @tc.type: FUNC
366  * @tc.require: AROOOH5R5G
367  */
368 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataSrouce001, TestSize.Level1)
369 {
370     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
371     OH_UdmfData* setData = OH_UdmfData_Create();
372     OH_UdmfRecord* record = OH_UdmfRecord_Create();
373     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
374     char content[] = "hello world";
375     OH_UdsPlainText_SetContent(plainText, content);
376     OH_UdmfRecord_AddPlainText(record, plainText);
377     OH_UdmfData_AddRecord(setData, record);
378 
379     OH_Pasteboard_SetData(pasteboard, setData);
380 
381     int len = 100;
382     char source[100];
383     int res = OH_Pasteboard_GetDataSource(pasteboard, source, len);
384     EXPECT_EQ(res, ERR_OK);
385 
386     int res1 = OH_Pasteboard_GetDataSource(nullptr, source, len);
387     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
388 
389     int res2 = OH_Pasteboard_GetDataSource(pasteboard, nullptr, len);
390     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
391 
392     int res3 = OH_Pasteboard_GetDataSource(pasteboard, source, 0);
393     EXPECT_EQ(res3, ERR_INVALID_PARAMETER);
394 
395     OH_Pasteboard_Destroy(pasteboard);
396 }
397 
398 /**
399  * @tc.name: OH_Pasteboard_GetMimeTypes001
400  * @tc.desc: OH_Pasteboard_GetMimeTypes test empty data
401  * @tc.type: FUNC
402  * @tc.require: AR20241012964265
403  */
404 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes001, TestSize.Level1)
405 {
406     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
407     ASSERT_TRUE(pasteboard);
408     OH_Pasteboard_ClearData(pasteboard);
409     unsigned int count = 1000;
410     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
411     EXPECT_EQ(0, count);
412     EXPECT_TRUE(res == nullptr);
413 }
414 
415 /**
416  * @tc.name: OH_Pasteboard_GetMimeTypes002
417  * @tc.desc: OH_Pasteboard_GetMimeTypes test plainText
418  * @tc.type: FUNC
419  * @tc.require: AR20241012964265
420  */
421 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes002, TestSize.Level1)
422 {
423     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
424     ASSERT_TRUE(pasteboard);
425     OH_UdmfData* setData = OH_UdmfData_Create();
426     ASSERT_TRUE(setData);
427     OH_UdmfRecord* record = OH_UdmfRecord_Create();
428     ASSERT_TRUE(record);
429     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
430     ASSERT_TRUE(plainText);
431     char content[] = "hello world";
432     OH_UdsPlainText_SetContent(plainText, content);
433     OH_UdmfRecord_AddPlainText(record, plainText);
434     OH_UdmfData_AddRecord(setData, record);
435     OH_Pasteboard_SetData(pasteboard, setData);
436 
437     unsigned int count = 1000;
438     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
439     EXPECT_EQ(1, count);
440     EXPECT_TRUE(res != nullptr);
441     EXPECT_STREQ(MIMETYPE_TEXT_PLAIN, res[0]);
442 
443     OH_Pasteboard_Destroy(pasteboard);
444 }
445 
446 /**
447  * @tc.name: OH_Pasteboard_GetMimeTypes003
448  * @tc.desc: OH_Pasteboard_GetMimeTypes test multi Mime types
449  * @tc.type: FUNC
450  * @tc.require: AR20241012964265
451  */
452 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes003, TestSize.Level1)
453 {
454     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
455     ASSERT_TRUE(pasteboard);
456     OH_UdmfData* setData = OH_UdmfData_Create();
457     ASSERT_TRUE(setData);
458     OH_UdmfRecord* record = OH_UdmfRecord_Create();
459     ASSERT_TRUE(record);
460     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
461     ASSERT_TRUE(plainText);
462     char content[] = "hello world";
463     OH_UdsPlainText_SetContent(plainText, content);
464     OH_UdmfRecord_AddPlainText(record, plainText);
465     OH_UdmfData_AddRecord(setData, record);
466 
467     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
468     ASSERT_TRUE(record2);
469     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
470     ASSERT_TRUE(htmlText);
471     char html[] = "<div class='disabled'>hello</div>";
472     OH_UdsHtml_SetContent(htmlText, html);
473     OH_UdmfRecord_AddHtml(record2, htmlText);
474     OH_UdmfData_AddRecord(setData, record2);
475     OH_Pasteboard_SetData(pasteboard, setData);
476 
477     unsigned int count = 1000;
478     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
479     EXPECT_EQ(2, count);
480     EXPECT_TRUE(res != nullptr);
481     EXPECT_TRUE((strcmp(MIMETYPE_TEXT_PLAIN, res[0]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[1]) == 0) ||
482         (strcmp(MIMETYPE_TEXT_PLAIN, res[1]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[0]) == 0));
483 
484     OH_Pasteboard_Destroy(pasteboard);
485 }
486 
487 /**
488  * @tc.name: OH_Pasteboard_GetMimeTypes004
489  * @tc.desc: OH_Pasteboard_GetMimeTypes test multi Mime types
490  * @tc.type: FUNC
491  * @tc.require:
492  */
493 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetMimeTypes004, TestSize.Level1)
494 {
495     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
496     ASSERT_TRUE(pasteboard);
497     OH_UdmfData* setData = OH_UdmfData_Create();
498     ASSERT_TRUE(setData);
499     OH_UdmfRecord* record = OH_UdmfRecord_Create();
500     ASSERT_TRUE(record);
501 
502     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
503     ASSERT_TRUE(plainText);
504     char content[] = "hello world";
505     OH_UdsPlainText_SetContent(plainText, content);
506 
507     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
508     ASSERT_TRUE(htmlText);
509     char html[] = "<div class='disabled'>hello</div>";
510     OH_UdsHtml_SetContent(htmlText, html);
511 
512     OH_UdmfRecord_AddPlainText(record, plainText);
513     OH_UdmfRecord_AddHtml(record, htmlText);
514     OH_UdmfData_AddRecord(setData, record);
515 
516     OH_Pasteboard_SetData(pasteboard, setData);
517 
518     unsigned int count = 1000;
519     char** res = OH_Pasteboard_GetMimeTypes(pasteboard, &count);
520     EXPECT_EQ(2, count);
521     EXPECT_TRUE(res != nullptr);
522     EXPECT_TRUE((strcmp(MIMETYPE_TEXT_PLAIN, res[0]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[1]) == 0) ||
523         (strcmp(MIMETYPE_TEXT_PLAIN, res[1]) == 0 && strcmp(MIMETYPE_TEXT_HTML, res[0]) == 0));
524 
525     OH_Pasteboard_Destroy(pasteboard);
526 }
527 
528 /**
529  * @tc.name: OH_Pasteboard_HasType001
530  * @tc.desc: OH_Pasteboard_HasType test valid
531  * @tc.type: FUNC
532  * @tc.require: AROOOH5R5G
533  */
534 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_HasType001, TestSize.Level1)
535 {
536     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
537     OH_UdmfData* setData = OH_UdmfData_Create();
538     OH_UdmfRecord* record = OH_UdmfRecord_Create();
539     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
540     char content[] = "hello world";
541     OH_UdsPlainText_SetContent(plainText, content);
542     OH_UdmfRecord_AddPlainText(record, plainText);
543     OH_UdmfData_AddRecord(setData, record);
544 
545     OH_Pasteboard_SetData(pasteboard, setData);
546     char type[] = "general.plain-text";
547     bool res = OH_Pasteboard_HasType(pasteboard, type);
548     EXPECT_FALSE(res);
549 
550     OH_Pasteboard_Destroy(pasteboard);
551 }
552 
553 /**
554  * @tc.name: OH_Pasteboard_HasType002
555  * @tc.desc: OH_Pasteboard_HasType test mutil entry
556  * @tc.type: FUNC
557  * @tc.require: AROOOH5R5G
558  */
559 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_HasType002, TestSize.Level1)
560 {
561     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
562     ASSERT_TRUE(pasteboard);
563     OH_UdmfData* setData = OH_UdmfData_Create();
564     ASSERT_TRUE(setData);
565     OH_UdmfRecord* record = OH_UdmfRecord_Create();
566     ASSERT_TRUE(record);
567 
568     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
569     ASSERT_TRUE(plainText);
570     char content[] = "hello world";
571     OH_UdsPlainText_SetContent(plainText, content);
572 
573     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
574     ASSERT_TRUE(htmlText);
575     char html[] = "<div class='disabled'>hello</div>";
576     OH_UdsHtml_SetContent(htmlText, html);
577 
578     OH_UdmfRecord_AddPlainText(record, plainText);
579     OH_UdmfRecord_AddHtml(record, htmlText);
580     OH_UdmfData_AddRecord(setData, record);
581 
582     OH_Pasteboard_SetData(pasteboard, setData);
583 
584     bool res = OH_Pasteboard_HasType(pasteboard, "text/plain");
585     EXPECT_TRUE(res);
586 
587     res = OH_Pasteboard_HasType(pasteboard, "text/html");
588     EXPECT_TRUE(res);
589 
590     OH_Pasteboard_Destroy(pasteboard);
591 }
592 
593 /**
594  * @tc.name: OH_UdmfData_HasType001
595  * @tc.desc: OH_UdmfData_HasType test mutil entry
596  * @tc.type: FUNC
597  * @tc.require: AROOOH5R5G
598  */
599 HWTEST_F(PasteboardCapiTest, OH_UdmfData_HasType001, TestSize.Level1)
600 {
601     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
602     ASSERT_TRUE(pasteboard);
603     OH_UdmfData* setData = OH_UdmfData_Create();
604     ASSERT_TRUE(setData);
605     OH_UdmfRecord* record = OH_UdmfRecord_Create();
606     ASSERT_TRUE(record);
607 
608     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
609     ASSERT_TRUE(plainText);
610     char content[] = "hello world";
611     OH_UdsPlainText_SetContent(plainText, content);
612 
613     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
614     ASSERT_TRUE(htmlText);
615     char html[] = "<div class='disabled'>hello</div>";
616     OH_UdsHtml_SetContent(htmlText, html);
617 
618     OH_UdmfRecord_AddPlainText(record, plainText);
619     OH_UdmfRecord_AddHtml(record, htmlText);
620     OH_UdmfData_AddRecord(setData, record);
621 
622     OH_Pasteboard_SetData(pasteboard, setData);
623 
624     int status = -1;
625     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
626     EXPECT_TRUE(status == 0);
627 
628     char type[] = "general.plain-text";
629     bool res = OH_UdmfData_HasType(getData, type);
630     EXPECT_TRUE(res);
631 
632     char type2[] = "general.html";
633     res = OH_UdmfData_HasType(getData, type2);
634     EXPECT_TRUE(res);
635 
636     OH_Pasteboard_Destroy(pasteboard);
637 }
638 
639 /**
640  * @tc.name: OH_Pasteboard_HasData001
641  * @tc.desc: OH_Pasteboard_HasData test valid
642  * @tc.type: FUNC
643  * @tc.require: AROOOH5R5G
644  */
645 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_HasData001, TestSize.Level1)
646 {
647     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
648     OH_Pasteboard_ClearData(pasteboard);
649     bool res = OH_Pasteboard_HasData(pasteboard);
650     EXPECT_FALSE(res);
651 
652     OH_UdmfData* setData = OH_UdmfData_Create();
653     OH_UdmfRecord* record = OH_UdmfRecord_Create();
654     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
655     char content[] = "hello world";
656     OH_UdsPlainText_SetContent(plainText, content);
657     OH_UdmfRecord_AddPlainText(record, plainText);
658     OH_UdmfData_AddRecord(setData, record);
659 
660     OH_Pasteboard_SetData(pasteboard, setData);
661 
662     res = OH_Pasteboard_HasData(pasteboard);
663     EXPECT_TRUE(res);
664 
665     OH_Pasteboard_Destroy(pasteboard);
666 }
667 
668 /**
669  * @tc.name: OH_Pasteboard_ClearData001
670  * @tc.desc: OH_Pasteboard_ClearData test valid
671  * @tc.type: FUNC
672  * @tc.require: AROOOH5R5G
673  */
674 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_ClearData001, TestSize.Level1)
675 {
676     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
677     bool res = OH_Pasteboard_ClearData(pasteboard);
678     EXPECT_EQ(res, ERR_OK);
679 
680     int res2 = OH_Pasteboard_ClearData(nullptr);
681     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
682 
683     OH_Pasteboard_Destroy(pasteboard);
684 }
685 
686 /**
687  * @tc.name: OH_Pasteboard_SetData001
688  * @tc.desc: OH_Pasteboard_SetData test valid
689  * @tc.type: FUNC
690  * @tc.require: AROOOH5R5G
691  */
692 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_SetData001, TestSize.Level1)
693 {
694     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
695     OH_UdmfData *setData = OH_UdmfData_Create();
696     OH_UdmfRecord *record = OH_UdmfRecord_Create();
697     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
698     char content[] = "hello world";
699     OH_UdsPlainText_SetContent(plainText, content);
700     OH_UdmfRecord_AddPlainText(record, plainText);
701     OH_UdmfData_AddRecord(setData, record);
702 
703     bool res = OH_Pasteboard_SetData(pasteboard, setData);
704     EXPECT_EQ(res, ERR_OK);
705 
706     int res1 = OH_Pasteboard_SetData(pasteboard, nullptr);
707     EXPECT_EQ(res1, ERR_INVALID_PARAMETER);
708 
709     int res2 = OH_Pasteboard_SetData(nullptr, setData);
710     EXPECT_EQ(res2, ERR_INVALID_PARAMETER);
711 
712     OH_Pasteboard_Destroy(pasteboard);
713     OH_UdsPlainText_Destroy(plainText);
714     OH_UdmfRecord_Destroy(record);
715     OH_UdmfData_Destroy(setData);
716 }
717 
718 /**
719  * @tc.name: OH_Pasteboard_GetData001
720  * @tc.desc: OH_Pasteboard_GetData test valid
721  * @tc.type: FUNC
722  * @tc.require: AROOOH5R5G
723  */
724 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData001, TestSize.Level1)
725 {
726     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
727     OH_UdmfData* setData = OH_UdmfData_Create();
728     OH_UdmfRecord* record = OH_UdmfRecord_Create();
729     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
730     char content[] = "hello world";
731     OH_UdsPlainText_SetContent(plainText, content);
732     OH_UdmfRecord_AddPlainText(record, plainText);
733     OH_UdmfData_AddRecord(setData, record);
734 
735     int res = OH_Pasteboard_SetData(pasteboard, setData);
736     EXPECT_EQ(res, ERR_OK);
737 
738     int status = -1;
739     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
740     EXPECT_EQ(status, ERR_OK);
741     EXPECT_NE(getData, nullptr);
742 
743     unsigned int count = 0;
744     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &count);
745     EXPECT_EQ(count, 1);
746     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
747     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
748     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
749     EXPECT_EQ(strcmp(getContent, content), 0);
750 
751     OH_Pasteboard_Destroy(pasteboard);
752     OH_UdsPlainText_Destroy(plainText);
753     OH_UdsPlainText_Destroy(getPlainText);
754     OH_UdmfRecord_Destroy(record);
755     OH_UdmfData_Destroy(setData);
756     OH_UdmfData_Destroy(getData);
757 }
758 
759 /**
760  * @tc.name: OH_Pasteboard_GetData002
761  * @tc.desc: OH_Pasteboard_GetData test valid
762  * @tc.type: FUNC
763  * @tc.require: AROOOH5R5G
764  */
765 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData002, TestSize.Level1)
766 {
767     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
768     OH_UdmfData* setData = OH_UdmfData_Create();
769     OH_UdmfRecord* record = OH_UdmfRecord_Create();
770     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
771     EXPECT_NE(provider, nullptr);
772     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
773     OH_UdmfData_AddRecord(setData, record);
774 
775     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
776     OH_UdmfRecord_SetProvider(record, types, 3, provider);
777     int res = OH_Pasteboard_SetData(pasteboard, setData);
778     EXPECT_EQ(res, ERR_OK);
779 
780     int status = -1;
781     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
782     EXPECT_EQ(status, ERR_OK);
783     EXPECT_NE(getData, nullptr);
784 
785     unsigned int count = 0;
786     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &count);
787     EXPECT_EQ(count, 1);
788     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
789     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
790     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
791     EXPECT_EQ(strcmp(getContent, PLAINTEXT_CONTENT), 0);
792 
793     OH_UdsHyperlink *getHyperLink = OH_UdsHyperlink_Create();
794     OH_UdmfRecord_GetHyperlink(getRecords[0], getHyperLink);
795     const char *getUrl = OH_UdsHyperlink_GetUrl(getHyperLink);
796     EXPECT_EQ(strcmp(getUrl, HYPERLINK_URL), 0);
797     OH_Pasteboard_Destroy(pasteboard);
798     OH_UdsPlainText_Destroy(getPlainText);
799     OH_UdsHyperlink_Destroy(getHyperLink);
800     OH_UdmfRecord_Destroy(record);
801     OH_UdmfData_Destroy(setData);
802     OH_UdmfData_Destroy(getData);
803 }
804 
805 /**
806  * @tc.name: OH_Pasteboard_GetData003
807  * @tc.desc: OH_Pasteboard_GetData test valid
808  * @tc.type: FUNC
809  * @tc.require: AROOOH5R5G
810  */
811 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData003, TestSize.Level1)
812 {
813     char typeId[] = "ApplicationDefined-myType";
814     unsigned char entry[] = "CreateGeneralRecord1";
815     unsigned int count = sizeof(entry);
816     OH_UdmfRecord *record = OH_UdmfRecord_Create();
817     int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
818     EXPECT_EQ(addRes1, ERR_OK);
819 
820     OH_UdmfData* setData = OH_UdmfData_Create();
821     OH_UdmfData_AddRecord(setData, record);
822     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
823     int res = OH_Pasteboard_SetData(pasteboard, setData);
824     EXPECT_EQ(res, ERR_OK);
825 
826     int status = -1;
827     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
828     EXPECT_EQ(status, ERR_OK);
829     EXPECT_NE(getData, nullptr);
830 
831     unsigned int getrecordCount = 0;
832     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &getrecordCount);
833     EXPECT_EQ(getrecordCount, 1);
834 
835     unsigned int getCount = 0;
836     unsigned char *getEntry;
837     int getRes = OH_UdmfRecord_GetGeneralEntry(getRecords[0], typeId, &getEntry, &getCount);
838     EXPECT_EQ(getRes, ERR_OK);
839     EXPECT_EQ(getCount, count);
840     EXPECT_EQ(memcmp(entry, getEntry, getCount), 0);
841 
842     OH_Pasteboard_Destroy(pasteboard);
843     OH_UdmfRecord_Destroy(record);
844     OH_UdmfData_Destroy(setData);
845     OH_UdmfData_Destroy(getData);
846 }
847 
848 /**
849  * @tc.name: OH_Pasteboard_GetData004
850  * @tc.desc: OH_Pasteboard_GetData test data type
851  * @tc.type: FUNC
852  */
853 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData004, TestSize.Level1)
854 {
855     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData004 start");
856     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
857     OH_UdmfData* setData = OH_UdmfData_Create();
858     OH_UdmfRecord* record = OH_UdmfRecord_Create();
859 
860     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
861     EXPECT_NE(provider, nullptr);
862     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
863 
864     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
865     OH_UdmfRecord_SetProvider(record, types, 3, provider);
866     OH_UdmfData_AddRecord(setData, record);
867 
868     int res = OH_Pasteboard_SetData(pasteboard, setData);
869     EXPECT_EQ(res, ERR_OK);
870 
871     PasteData pasteData;
872     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
873     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
874 
875     auto record1 = pasteData.GetRecordAt(0);
876     auto mimeType = record1->GetMimeType();
877     EXPECT_EQ(mimeType, MIMETYPE_TEXT_PLAIN);
878 
879     OH_Pasteboard_Destroy(pasteboard);
880     OH_UdmfRecord_Destroy(record);
881     OH_UdmfData_Destroy(setData);
882     OH_UdmfRecordProvider_Destroy(provider);
883     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData004 end");
884 }
885 
886 /**
887  * @tc.name: OH_Pasteboard_GetData005
888  * @tc.desc: OH_Pasteboard_GetData test data type
889  * @tc.type: FUNC
890  */
891 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData005, TestSize.Level1)
892 {
893     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData005 start");
894     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
895     OH_UdmfData* setData = OH_UdmfData_Create();
896     OH_UdmfRecord* record = OH_UdmfRecord_Create();
897 
898     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
899     EXPECT_NE(provider, nullptr);
900     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
901     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
902     OH_UdmfRecord_SetProvider(record, types, 3, provider);
903 
904     OH_UdsHyperlink *link = OH_UdsHyperlink_Create();
905     OH_UdsHyperlink_SetUrl(link, HYPERLINK_URL);
906     OH_UdmfRecord_AddHyperlink(record, link);
907 
908     OH_UdmfData_AddRecord(setData, record);
909     auto res = OH_Pasteboard_SetData(pasteboard, setData);
910     EXPECT_EQ(res, ERR_OK);
911 
912     PasteData pasteData;
913     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
914     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
915 
916     auto record1 = pasteData.GetRecordAt(0);
917     auto mimeType = record1->GetMimeType();
918     EXPECT_EQ(mimeType, MIMETYPE_TEXT_PLAIN);
919 
920     auto text = record1->GetPlainText();
921     EXPECT_EQ(strcmp(text->c_str(), PLAINTEXT_CONTENT), 0);
922 
923     OH_Pasteboard_Destroy(pasteboard);
924     OH_UdmfRecord_Destroy(record);
925     OH_UdmfData_Destroy(setData);
926     OH_UdsHyperlink_Destroy(link);
927     OH_UdmfRecordProvider_Destroy(provider);
928     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData005 end");
929 }
930 
931 /**
932  * @tc.name: OH_Pasteboard_GetData006
933  * @tc.desc: OH_Pasteboard_GetData test data type
934  * @tc.type: FUNC
935  */
936 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData006, TestSize.Level1)
937 {
938     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData006 start");
939     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
940     OH_UdmfData* setData = OH_UdmfData_Create();
941     OH_UdmfRecord* record = OH_UdmfRecord_Create();
942 
943     OH_UdsHtml *html = OH_UdsHtml_Create();
944     OH_UdsHtml_SetContent(html, HTML_TEXT);
945     OH_UdmfRecord_AddHtml(record, html);
946 
947     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
948     EXPECT_NE(provider, nullptr);
949     OH_UdmfRecordProvider_SetData(provider, static_cast<void *>(record), GetDataCallback, ContextFinalizeFunc);
950     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
951     OH_UdmfRecord_SetProvider(record, types, 3, provider);
952 
953     OH_UdmfData_AddRecord(setData, record);
954     bool res = OH_Pasteboard_SetData(pasteboard, setData);
955     EXPECT_EQ(res, ERR_OK);
956 
957     PasteData pasteData;
958     auto ret = PasteboardClient::GetInstance()->GetPasteData(pasteData);
959     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
960 
961     auto record1 = pasteData.GetRecordAt(0);
962     auto mimeType = record1->GetMimeType();
963     EXPECT_EQ(mimeType, MIMETYPE_TEXT_HTML);
964 
965     auto html1 = record1->GetHtmlText();
966     EXPECT_EQ(strcmp(html1->c_str(), HTML_TEXT), 0);
967 
968     OH_Pasteboard_Destroy(pasteboard);
969     OH_UdmfRecord_Destroy(record);
970     OH_UdmfData_Destroy(setData);
971     OH_UdmfRecordProvider_Destroy(provider);
972     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData006 end");
973 }
974 
975 /**
976  * @tc.name: OH_Pasteboard_GetData007
977  * @tc.desc: OH_Pasteboard_GetData test data type
978  * @tc.type: FUNC
979  */
980 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetData007, TestSize.Level1)
981 {
982     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData007 start");
983     std::string plainText = "helloWorld";
984     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
985     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
986     ASSERT_TRUE(ret == static_cast<int32_t>(PasteboardError::E_OK));
987 
988     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
989     int status = -1;
990     OH_UdmfData* getData = OH_Pasteboard_GetData(pasteboard, &status);
991     EXPECT_EQ(status, ERR_OK);
992     EXPECT_NE(getData, nullptr);
993 
994     unsigned int getrecordCount = 0;
995     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(getData, &getrecordCount);
996     EXPECT_EQ(getrecordCount, 1);
997     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
998     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
999     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
1000     EXPECT_STREQ(getContent, plainText.c_str());
1001 
1002     OH_Pasteboard_Destroy(pasteboard);
1003     PASTEBOARD_HILOGI(PASTEBOARD_MODULE_SERVICE, "OH_Pasteboard_GetData007 end");
1004 }
1005 
1006 /**
1007  * @tc.name: OH_Pasteboard_GetDataWithMultiAttributes001
1008  * @tc.desc: should get html & text when set html & text with https uri without tag
1009  * @tc.type: FUNC
1010  */
1011 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithMultiAttributes001, TestSize.Level1)
1012 {
1013     const char *htmlContent = "<p>Hello world!<img src=\"https://storage/local/files/Images/hello.png\"/></p>";
1014     const char *plainContent = "Hello world!";
1015 
1016     OH_UdsHtml *uHtml = OH_UdsHtml_Create();
1017     OH_UdsHtml_SetContent(uHtml, htmlContent);
1018     OH_UdsHtml_SetPlainContent(uHtml, plainContent);
1019 
1020     OH_UdmfRecord *uRecord = OH_UdmfRecord_Create();
1021     OH_UdmfRecord_AddHtml(uRecord, uHtml);
1022     OH_UdsHtml_Destroy(uHtml);
1023     uHtml = nullptr;
1024 
1025     OH_UdmfData *uData = OH_UdmfData_Create();
1026     OH_UdmfData_AddRecord(uData, uRecord);
1027 
1028     OH_Pasteboard *pasteboard = OH_Pasteboard_Create();
1029     int ret = OH_Pasteboard_SetData(pasteboard, uData);
1030     OH_UdmfRecord_Destroy(uRecord);
1031     OH_UdmfData_Destroy(uData);
1032     uData = nullptr;
1033     uRecord = nullptr;
1034     EXPECT_EQ(ret, ERR_OK);
1035 
1036     ret = -1;
1037     uData = OH_Pasteboard_GetData(pasteboard, &ret);
1038     OH_Pasteboard_Destroy(pasteboard);
1039     pasteboard = nullptr;
1040     EXPECT_EQ(ret, ERR_OK);
1041     EXPECT_NE(uData, nullptr);
1042 
1043     unsigned int count = 0;
1044     OH_UdmfRecord **records = OH_UdmfData_GetRecords(uData, &count);
1045     EXPECT_EQ(count, 1);
1046     EXPECT_NE(records, nullptr);
1047 
1048     if (count == 1 && records != nullptr) {
1049         uHtml = OH_UdsHtml_Create();
1050         OH_UdmfRecord_GetHtml(records[0], uHtml);
1051 
1052         const char *htmlText = OH_UdsHtml_GetContent(uHtml);
1053         const char *plainText = OH_UdsHtml_GetPlainContent(uHtml);
1054         EXPECT_STREQ(htmlText, htmlContent);
1055         EXPECT_STREQ(plainText, plainContent);
1056 
1057         OH_UdsHtml_Destroy(uHtml);
1058         uHtml = nullptr;
1059     }
1060 
1061     OH_UdmfData_Destroy(uData);
1062     uData = nullptr;
1063 }
1064 
1065 /**
1066  * @tc.name: OH_Pasteboard_GetDataWithMultiAttributes002
1067  * @tc.desc: should get html & text when set html & text with https uri and tag
1068  * @tc.type: FUNC
1069  */
1070 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithMultiAttributes002, TestSize.Level1)
1071 {
1072     const char *htmlContent = "<p>Hello world!<img src=\"https://storage/local/files/Images/hello.png\"/></p>";
1073     const char *plainContent = "Hello world!";
1074 
1075     OH_UdsHtml *uHtml = OH_UdsHtml_Create();
1076     OH_UdsHtml_SetContent(uHtml, htmlContent);
1077     OH_UdsHtml_SetPlainContent(uHtml, plainContent);
1078 
1079     OH_UdmfRecord *uRecord = OH_UdmfRecord_Create();
1080     OH_UdmfRecord_AddHtml(uRecord, uHtml);
1081     OH_UdsHtml_Destroy(uHtml);
1082     uHtml = nullptr;
1083 
1084     OH_UdmfData *uData = OH_UdmfData_Create();
1085     OH_UdmfData_AddRecord(uData, uRecord);
1086 
1087     OH_UdmfProperty *uProp = OH_UdmfProperty_Create(uData);
1088     int ret = OH_UdmfProperty_SetTag(uProp, PasteData::WEBVIEW_PASTEDATA_TAG.c_str()); // set webview tag
1089     EXPECT_EQ(ret, ERR_OK);
1090 
1091     OH_Pasteboard *pasteboard = OH_Pasteboard_Create();
1092     ret = OH_Pasteboard_SetData(pasteboard, uData);
1093     OH_UdmfRecord_Destroy(uRecord);
1094     OH_UdmfData_Destroy(uData);
1095     uData = nullptr;
1096     uRecord = nullptr;
1097     EXPECT_EQ(ret, ERR_OK);
1098 
1099     ret = -1;
1100     uData = OH_Pasteboard_GetData(pasteboard, &ret);
1101     OH_Pasteboard_Destroy(pasteboard);
1102     pasteboard = nullptr;
1103     EXPECT_EQ(ret, ERR_OK);
1104     EXPECT_NE(uData, nullptr);
1105 
1106     unsigned int count = 0;
1107     OH_UdmfRecord **records = OH_UdmfData_GetRecords(uData, &count);
1108     EXPECT_EQ(count, 1);
1109     EXPECT_NE(records, nullptr);
1110 
1111     if (count == 1 && records != nullptr) {
1112         uHtml = OH_UdsHtml_Create();
1113         OH_UdmfRecord_GetHtml(records[0], uHtml);
1114 
1115         const char *htmlText = OH_UdsHtml_GetContent(uHtml);
1116         const char *plainText = OH_UdsHtml_GetPlainContent(uHtml);
1117         EXPECT_STREQ(htmlText, htmlContent);
1118         EXPECT_STREQ(plainText, plainContent);
1119 
1120         OH_UdsHtml_Destroy(uHtml);
1121         uHtml = nullptr;
1122     }
1123 
1124     OH_UdmfData_Destroy(uData);
1125     uData = nullptr;
1126 }
1127 
OH_Pasteboard_ProgressListener(Pasteboard_ProgressInfo * progressInfo)1128 void OH_Pasteboard_ProgressListener(Pasteboard_ProgressInfo *progressInfo)
1129 {
1130     int percentage = OH_Pasteboard_ProgressInfo_GetProgress(progressInfo);
1131     printf("percentage = %d\n", percentage);
1132 }
1133 
1134 /**
1135  * @tc.name: OH_Pasteboard_GetDataWithProgress001
1136  * @tc.desc: should get html & text when set html & text with https uri and tag
1137  * @tc.type: FUNC
1138  */
1139 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress001, TestSize.Level1)
1140 {
1141     int status = -1;
1142     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1143     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, nullptr, &status);
1144     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
1145     EXPECT_EQ(getData, nullptr);
1146 
1147     g_params = OH_Pasteboard_GetDataParams_Create();
1148     EXPECT_NE(g_params, nullptr);
1149     getData = OH_Pasteboard_GetDataWithProgress(nullptr, g_params, &status);
1150     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
1151     EXPECT_EQ(getData, nullptr);
1152     getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, nullptr);
1153     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
1154     EXPECT_EQ(getData, nullptr);
1155     OH_Pasteboard_Destroy(pasteboard);
1156     OH_Pasteboard_GetDataParams_Destroy(g_params);
1157 }
1158 
1159 /**
1160  * @tc.name: OH_Pasteboard_GetDataWithProgress002
1161  * @tc.desc: should get html & text when set html & text with https uri and tag
1162  * @tc.type: FUNC
1163  */
1164 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress002, TestSize.Level1)
1165 {
1166     int status = -1;
1167     OH_Pasteboard *pasteboard = OH_Pasteboard_Create();
1168     g_params = OH_Pasteboard_GetDataParams_Create();
1169     EXPECT_NE(g_params, nullptr);
1170     const char *uri = "/data/storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/"
1171         "files/data/storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/files/data/"
1172         "storage/el2/base/haps/entry/files/data/storage/el2/base/haps/entry/files/haps/entry/files/dstFile.txt";
1173     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1174     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, strlen(uri));
1175     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
1176     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
1177     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1178     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
1179     EXPECT_EQ(getData, nullptr);
1180     OH_Pasteboard_Destroy(pasteboard);
1181     OH_Pasteboard_GetDataParams_Destroy(g_params);
1182 }
1183 
1184 /**
1185  * @tc.name: OH_Pasteboard_GetDataWithProgress003
1186  * @tc.desc: should get html & text when set html & text with https uri and tag
1187  * @tc.type: FUNC
1188  */
1189 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress003, TestSize.Level1)
1190 {
1191     int status = -1;
1192     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1193     g_params = OH_Pasteboard_GetDataParams_Create();
1194     EXPECT_NE(g_params, nullptr);
1195     const char *uri = "/data/storage/el2/base/haps/entry/files/dstFile.txt";
1196     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1197     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, uriLen);
1198     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
1199     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
1200     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1201     EXPECT_EQ(status, ERR_INVALID_PARAMETER);
1202     EXPECT_EQ(getData, nullptr);
1203     OH_Pasteboard_Destroy(pasteboard);
1204     OH_Pasteboard_GetDataParams_Destroy(g_params);
1205 }
1206 
1207 /**
1208  * @tc.name: OH_Pasteboard_GetDataWithProgress004
1209  * @tc.desc: should get html & text when set html & text with https uri and tag
1210  * @tc.type: FUNC
1211  */
1212 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress004, TestSize.Level1)
1213 {
1214     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1215     int32_t ret = OH_Pasteboard_ClearData(pasteboard);
1216     EXPECT_EQ(ret, ERR_OK);
1217     g_params = OH_Pasteboard_GetDataParams_Create();
1218     EXPECT_NE(g_params, nullptr);
1219     const char *uri = "/data/storage/el2/base/haps/entry/files/dstFile.txt";
1220     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1221     OH_Pasteboard_GetDataParams_SetDestUri(g_params, uri, strlen(uri));
1222     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_SKIP);
1223     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
1224     int status = -1;
1225     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1226     EXPECT_EQ(status, ERR_PASTEBOARD_GET_DATA_FAILED);
1227     EXPECT_EQ(getData, nullptr);
1228     OH_Pasteboard_Destroy(pasteboard);
1229     OH_Pasteboard_GetDataParams_Destroy(g_params);
1230 }
1231 
1232 /**
1233  * @tc.name: OH_Pasteboard_GetDataWithProgress005
1234  * @tc.desc: should get html & text when set html & text with https uri and tag
1235  * @tc.type: FUNC
1236  */
1237 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress005, TestSize.Level1)
1238 {
1239     std::string plainText = "helloWorld";
1240     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
1241     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
1242     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
1243 
1244     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1245     g_params = OH_Pasteboard_GetDataParams_Create();
1246     EXPECT_NE(g_params, nullptr);
1247     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1248     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_OVERWRITE);
1249     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, OH_Pasteboard_ProgressListener);
1250     int status = -1;
1251     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1252     EXPECT_EQ(status, ERR_OK);
1253     EXPECT_NE(getData, nullptr);
1254     OH_Pasteboard_Destroy(pasteboard);
1255     OH_Pasteboard_GetDataParams_Destroy(g_params);
1256 }
1257 
Pasteboard_ProgressListener(Pasteboard_ProgressInfo * progressInfo)1258 void Pasteboard_ProgressListener(Pasteboard_ProgressInfo *progressInfo)
1259 {
1260     int percentage = OH_Pasteboard_ProgressInfo_GetProgress(progressInfo);
1261     printf("percentage = %d\n", percentage);
1262     if (g_params != nullptr) {
1263         OH_Pasteboard_ProgressCancel(g_params);
1264     }
1265 }
1266 
1267 /**
1268  * @tc.name: OH_Pasteboard_GetDataWithProgress006
1269  * @tc.desc: should get html & text when set html & text with https uri and tag
1270  * @tc.type: FUNC
1271  */
1272 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetDataWithProgress006, TestSize.Level1)
1273 {
1274     std::string plainText = "helloWorld";
1275     auto newData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
1276     auto ret = PasteboardClient::GetInstance()->SetPasteData(*newData);
1277     EXPECT_EQ(ret, static_cast<int32_t>(PasteboardError::E_OK));
1278 
1279     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1280     g_params = OH_Pasteboard_GetDataParams_Create();
1281     EXPECT_NE(g_params, nullptr);
1282     OH_Pasteboard_GetDataParams_SetProgressIndicator(g_params, PASTEBOARD_NONE);
1283     OH_Pasteboard_GetDataParams_SetFileConflictOptions(g_params, PASTEBOARD_OVERWRITE);
1284     OH_Pasteboard_GetDataParams_SetProgressListener(g_params, Pasteboard_ProgressListener);
1285     int status = -1;
1286     OH_UdmfData* getData = OH_Pasteboard_GetDataWithProgress(pasteboard, g_params, &status);
1287     EXPECT_EQ(status, ERR_OK);
1288     EXPECT_NE(getData, nullptr);
1289     OH_Pasteboard_Destroy(pasteboard);
1290     OH_Pasteboard_GetDataParams_Destroy(g_params);
1291 }
1292 
1293 /**
1294  * @tc.name: OH_Pasteboard_GetChangeCount001
1295  * @tc.desc: changeCount should not change after clear pasteboard
1296  * @tc.type: FUNC
1297  * @tc.require: AROOOH5R5G
1298  */
1299 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetChangeCount001, TestSize.Level1)
1300 {
1301     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1302     uint32_t changeCount = OH_Pasteboard_GetChangeCount(pasteboard);
1303     OH_Pasteboard_ClearData(pasteboard);
1304     uint32_t newCount = OH_Pasteboard_GetChangeCount(pasteboard);
1305     EXPECT_EQ(newCount, changeCount);
1306     OH_Pasteboard_Destroy(pasteboard);
1307 }
1308 
1309 /**
1310  * @tc.name: OH_Pasteboard_GetChangeCount002
1311  * @tc.desc: changeCount should add 1 after setData
1312  * @tc.type: FUNC
1313  * @tc.require: AROOOH5R5G
1314  */
1315 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetChangeCount002, TestSize.Level1)
1316 {
1317     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1318     uint32_t changeCount = OH_Pasteboard_GetChangeCount(pasteboard);
1319     OH_UdmfData* setData = OH_UdmfData_Create();
1320     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1321     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
1322     char content[] = "hello world";
1323     OH_UdsPlainText_SetContent(plainText, content);
1324     OH_UdmfRecord_AddPlainText(record, plainText);
1325     OH_UdmfData_AddRecord(setData, record);
1326     OH_Pasteboard_SetData(pasteboard, setData);
1327     uint32_t newCount = OH_Pasteboard_GetChangeCount(pasteboard);
1328     EXPECT_EQ(newCount, changeCount + 1);
1329     OH_Pasteboard_Destroy(pasteboard);
1330 }
1331 
1332 /**
1333  * @tc.name: OH_Pasteboard_GetChangeCount003
1334  * @tc.desc: changeCount should add 2 after setData twice
1335  * @tc.type: FUNC
1336  * @tc.require: AROOOH5R5G
1337  */
1338 HWTEST_F(PasteboardCapiTest, OH_Pasteboard_GetChangeCount003, TestSize.Level1)
1339 {
1340     OH_Pasteboard* pasteboard = OH_Pasteboard_Create();
1341     uint32_t changeCount = OH_Pasteboard_GetChangeCount(pasteboard);
1342     OH_UdmfData* setData = OH_UdmfData_Create();
1343     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1344     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
1345     char content[] = "hello world";
1346     OH_UdsPlainText_SetContent(plainText, content);
1347     OH_UdmfRecord_AddPlainText(record, plainText);
1348     OH_UdmfData_AddRecord(setData, record);
1349     OH_Pasteboard_SetData(pasteboard, setData);
1350     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1351     OH_UdsHtml* htmlText = OH_UdsHtml_Create();
1352     char html[] = "<div class='disabled'>hello</div>";
1353     OH_UdsHtml_SetContent(htmlText, html);
1354     OH_UdmfRecord_AddHtml(record2, htmlText);
1355     OH_UdmfData_AddRecord(setData, record2);
1356     OH_Pasteboard_SetData(pasteboard, setData);
1357     uint32_t newCount = OH_Pasteboard_GetChangeCount(pasteboard);
1358     EXPECT_EQ(newCount, changeCount + 2);
1359     OH_Pasteboard_Destroy(pasteboard);
1360 }
1361 } // namespace Test
1362 } // namespace OHOS
1363