• 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 "UDMFTEST"
17 #include <gtest/gtest.h>
18 #include "token_setproc.h"
19 #include "accesstoken_kit.h"
20 #include "directory_ex.h"
21 #include "nativetoken_kit.h"
22 #include <unistd.h>
23 #include <memory>
24 #include "udmf.h"
25 #include "uds.h"
26 #include "udmf_err_code.h"
27 #include "unified_data.h"
28 #include "unified_record.h"
29 #include "udmf_capi_common.h"
30 #include "udmf_client.h"
31 #include "plain_text.h"
32 #include "udmf_meta.h"
33 #include "data_provider_impl.h"
34 #include "image.h"
35 #include "audio.h"
36 #include "file.h"
37 #include "folder.h"
38 #include "video.h"
39 #include "logger.h"
40 
41 using namespace testing::ext;
42 using namespace OHOS::Security::AccessToken;
43 using namespace OHOS::UDMF;
44 
45 namespace OHOS::Test {
46 class UDMFTest : public testing::Test {
47 public:
48     static void SetUpTestCase(void);
49     static void TearDownTestCase(void);
50     void SetUp();
51     void TearDown();
52     static void AllocHapToken1();
53     static void AllocHapToken2();
54     void SetHapToken1();
55     bool CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size);
56     static void FinalizeFunc(void* context);
57     static void* GetDataCallbackFunc(void* context, const char* type);
58     static constexpr int USER_ID = 100;
59     static constexpr int INST_INDEX = 0;
60 };
61 
SetUpTestCase()62 void UDMFTest::SetUpTestCase()
63 {
64     AllocHapToken1();
65     AllocHapToken2();
66 }
67 
TearDownTestCase()68 void UDMFTest::TearDownTestCase()
69 {
70     auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
71     AccessTokenKit::DeleteToken(tokenId);
72     tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
73     AccessTokenKit::DeleteToken(tokenId);
74 }
75 
SetUp()76 void UDMFTest::SetUp()
77 {
78     SetHapToken1();
79 }
80 
TearDown()81 void UDMFTest::TearDown()
82 {
83 }
84 
AllocHapToken1()85 void UDMFTest::AllocHapToken1()
86 {
87     HapInfoParams info = {
88         .userID = USER_ID,
89         .bundleName = "ohos.test.demo1",
90         .instIndex = INST_INDEX,
91         .appIDDesc = "ohos.test.demo1"
92     };
93 
94     HapPolicyParams policy = {
95         .apl = APL_NORMAL,
96         .domain = "test.domain",
97         .permList = {
98             {
99                 .permissionName = "ohos.permission.test",
100                 .bundleName = "ohos.test.demo1",
101                 .grantMode = 1,
102                 .availableLevel = APL_NORMAL,
103                 .label = "label",
104                 .labelId = 1,
105                 .description = "test1",
106                 .descriptionId = 1
107             }
108         },
109         .permStateList = {
110             {
111                 .permissionName = "ohos.permission.test",
112                 .isGeneral = true,
113                 .resDeviceID = { "local" },
114                 .grantStatus = { PermissionState::PERMISSION_GRANTED },
115                 .grantFlags = { 1 }
116             }
117         }
118     };
119     auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
120     SetSelfTokenID(tokenID.tokenIDEx);
121 }
122 
AllocHapToken2()123 void UDMFTest::AllocHapToken2()
124 {
125     HapInfoParams info = {
126         .userID = USER_ID,
127         .bundleName = "ohos.test.demo2",
128         .instIndex = INST_INDEX,
129         .appIDDesc = "ohos.test.demo2"
130     };
131 
132     HapPolicyParams policy = {
133         .apl = APL_NORMAL,
134         .domain = "test.domain",
135         .permList = {
136             {
137                 .permissionName = "ohos.permission.test",
138                 .bundleName = "ohos.test.demo2",
139                 .grantMode = 1,
140                 .availableLevel = APL_NORMAL,
141                 .label = "label",
142                 .labelId = 1,
143                 .description = "test2",
144                 .descriptionId = 1
145             }
146         },
147         .permStateList = {
148             {
149                 .permissionName = "ohos.permission.test",
150                 .isGeneral = true,
151                 .resDeviceID = { "local" },
152                 .grantStatus = { PermissionState::PERMISSION_GRANTED },
153                 .grantFlags = { 1 }
154             }
155         }
156     };
157     auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
158     SetSelfTokenID(tokenID.tokenIDEx);
159 }
160 
SetHapToken1()161 void UDMFTest::SetHapToken1()
162 {
163     auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
164     SetSelfTokenID(tokenId);
165 }
166 
CheckUnsignedChar(unsigned char * dst,unsigned char * src,int size)167 bool UDMFTest::CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size)
168 {
169     EXPECT_NE(dst, nullptr);
170     EXPECT_NE(src, nullptr);
171     for (int i = 0; i < size; ++i) {
172         if (dst[i] != src[i]) {
173             return false;
174         }
175     }
176     return true;
177 }
178 
FinalizeFunc(void * context)179 void UDMFTest::FinalizeFunc(void* context) {}
180 
GetDataCallbackFunc(void * context,const char * type)181 void* UDMFTest::GetDataCallbackFunc(void* context, const char* type)
182 {
183     auto plainText = OH_UdsPlainText_Create();
184     OH_UdsPlainText_SetAbstract(plainText, "doing something");
185     OH_UdsPlainText_SetContent(plainText, "doing something");
186     return plainText;
187 }
188 
189 /**
190  * @tc.name: OH_Udmf_CreateUnifiedData001
191  * @tc.desc: test OH_UdmfData_Create
192  * @tc.type: FUNC
193  * @tc.require: AROOOH5R5G
194  */
195 HWTEST_F(UDMFTest, OH_Udmf_CreateUnifiedData001, TestSize.Level0)
196 {
197     OH_UdmfData *unifiedData = OH_UdmfData_Create();
198     EXPECT_NE(unifiedData, nullptr);
199     EXPECT_NE(unifiedData->unifiedData_, nullptr);
200     OH_UdmfData_Destroy(unifiedData);
201 }
202 
203 /**
204  * @tc.name: OH_Udmf_AddRecordToUnifiedData001
205  * @tc.desc: OH_UdmfData_AddRecord with return UDMF_E_INVALID_PARAM
206  * @tc.type: FUNC
207  * @tc.require: AROOOH5R5G
208  */
209 HWTEST_F(UDMFTest, OH_Udmf_AddRecordToUnifiedData001, TestSize.Level0)
210 {
211     OH_UdmfRecord *record = OH_UdmfRecord_Create();
212     OH_UdmfData *unifiedData = OH_UdmfData_Create();
213 
214     int invalidRes1 = OH_UdmfData_AddRecord(nullptr, record);
215     EXPECT_EQ(invalidRes1, UDMF_E_INVALID_PARAM);
216 
217     OH_UdmfData unifiedData1;
218     int invalidRes2 = OH_UdmfData_AddRecord(&unifiedData1, record);
219     EXPECT_EQ(invalidRes2, UDMF_E_INVALID_PARAM);
220 
221     int invalidRes3 = OH_UdmfData_AddRecord(unifiedData, nullptr);
222     EXPECT_EQ(invalidRes3, UDMF_E_INVALID_PARAM);
223 
224     OH_UdmfRecord unifiedRecord1;
225     int invalidRes4 = OH_UdmfData_AddRecord(unifiedData, nullptr);
226     EXPECT_EQ(invalidRes4, UDMF_E_INVALID_PARAM);
227     OH_UdmfRecord_Destroy(record);
228     OH_UdmfData_Destroy(unifiedData);
229 }
230 
231 /**
232  * @tc.name: OH_Udmf_AddRecordToUnifiedData002
233  * @tc.desc: OH_UdmfData_AddRecord with return UDMF_E_OK
234  * @tc.type: FUNC
235  * @tc.require: AROOOH5R5G
236  */
237 HWTEST_F(UDMFTest, OH_Udmf_AddRecordToUnifiedData002, TestSize.Level0)
238 {
239     OH_UdmfRecord *record = OH_UdmfRecord_Create();
240     OH_UdmfData *unifiedData = OH_UdmfData_Create();
241     int status = OH_UdmfData_AddRecord(unifiedData, record);
242     EXPECT_EQ(status, UDMF_E_OK);
243 
244     OH_UdmfRecord_Destroy(record);
245     OH_UdmfData_Destroy(unifiedData);
246 }
247 
248 /**
249  * @tc.name: OH_Udmf_HasUnifiedDataType001
250  * @tc.desc: OH_UdmfData_HasType with return UDMF_E_INVALID_PARAM
251  * @tc.type: FUNC
252  * @tc.require: AROOOH5R5G
253  */
254 HWTEST_F(UDMFTest, OH_Udmf_HasUnifiedDataType001, TestSize.Level0)
255 {
256     OH_UdmfData *unifiedData = OH_UdmfData_Create();
257     char type[] = "general.plain-text";
258 
259     bool status1 = OH_UdmfData_HasType(nullptr, type);
260     EXPECT_FALSE(status1);
261 
262     bool status2 = OH_UdmfData_HasType(unifiedData, nullptr);
263     EXPECT_FALSE(status2);
264 
265     OH_UdmfData unifiedData1;
266     bool status3 = OH_UdmfData_HasType(&unifiedData1, nullptr);
267     EXPECT_FALSE(status3);
268 
269     bool status4 = OH_UdmfData_HasType(nullptr, nullptr);
270     EXPECT_FALSE(status4);
271 
272     OH_UdmfData_Destroy(unifiedData);
273 }
274 
275 /**
276  * @tc.name: OH_Udmf_HasUnifiedDataType002
277  * @tc.desc: OH_UdmfData_HasType with return whether has type, number 1 represent true, number 0 represent false
278  * @tc.type: FUNC
279  * @tc.require: AROOOH5R5G
280  */
281 HWTEST_F(UDMFTest, OH_Udmf_HasUnifiedDataType002, TestSize.Level0)
282 {
283     OH_UdmfData *unifiedData = OH_UdmfData_Create();
284     OH_UdmfRecord *record = OH_UdmfRecord_Create();
285     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
286     OH_UdmfRecord_AddPlainText(record, plainText);
287     OH_UdmfData_AddRecord(unifiedData, record);
288 
289     char type1[] = "general.plain-text";
290     int hasType1 = OH_UdmfData_HasType(unifiedData, type1);
291     EXPECT_EQ(hasType1, 1);
292 
293     char type2[] = "general.html";
294     int hasType2 = OH_UdmfData_HasType(unifiedData, type2);
295     EXPECT_EQ(hasType2, 0);
296 
297     OH_UdsPlainText_Destroy(plainText);
298     OH_UdmfRecord_Destroy(record);
299     OH_UdmfData_Destroy(unifiedData);
300 }
301 
302 /**
303  * @tc.name: OH_Udmf_GetUnifiedDataTypes001
304  * @tc.desc: OH_UdmfData_GetTypes with invalid params
305  * @tc.type: FUNC
306  * @tc.require: AROOOH5R5G
307  */
308 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataTypes001, TestSize.Level0)
309 {
310     OH_UdmfData *unifiedData = OH_UdmfData_Create();
311 
312     unsigned int count1 = 0;
313     char **types1 = OH_UdmfData_GetTypes(nullptr, &count1);
314     EXPECT_EQ(types1, nullptr);
315 
316     OH_UdmfData data;
317     char **types2 = OH_UdmfData_GetTypes(&data, &count1);
318     EXPECT_EQ(types2, nullptr);
319 
320     char **types3 = OH_UdmfData_GetTypes(unifiedData, nullptr);
321     EXPECT_EQ(types3, nullptr);
322 
323     OH_UdmfData_Destroy(unifiedData);
324 }
325 
326 /**
327  * @tc.name: OH_Udmf_GetUnifiedDataTypes002
328  * @tc.desc: OH_UdmfData_GetTypes with valid params
329  * @tc.type: FUNC
330  * @tc.require: AROOOH5R5G
331  */
332 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataTypes002, TestSize.Level0)
333 {
334     OH_UdmfData *unifiedData = OH_UdmfData_Create();
335     OH_UdmfRecord *record = OH_UdmfRecord_Create();
336     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
337     OH_UdmfRecord_AddPlainText(record, plainText);
338     OH_UdmfData_AddRecord(unifiedData, record);
339     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
340     OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
341     OH_UdmfRecord_AddHyperlink(record1, hyperlink);
342     OH_UdmfData_AddRecord(unifiedData, record1);
343 
344     unsigned int count1 = 0;
345     char **types1 = OH_UdmfData_GetTypes(unifiedData, &count1);
346     EXPECT_NE(types1, nullptr);
347     EXPECT_EQ(count1, 2);
348 
349     char **types2 = OH_UdmfData_GetTypes(unifiedData, &count1);
350     EXPECT_EQ(types1, types2);
351 
352     OH_UdsPlainText_Destroy(plainText);
353     OH_UdsHyperlink_Destroy(hyperlink);
354     OH_UdmfRecord_Destroy(record);
355     OH_UdmfData_Destroy(unifiedData);
356 }
357 
358 /**
359  * @tc.name: OH_Udmf_GetUnifiedRecordTypes001
360  * @tc.desc: OH_UdmfRecord_GetTypes with invalid params
361  * @tc.type: FUNC
362  * @tc.require: AROOOH5R5G
363  */
364 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedRecordTypes001, TestSize.Level0)
365 {
366     OH_UdmfRecord *record = OH_UdmfRecord_Create();
367     unsigned int count = 0;
368     char **types1 = OH_UdmfRecord_GetTypes(nullptr, &count);
369     EXPECT_EQ(types1, nullptr);
370 
371     char **types2 = OH_UdmfRecord_GetTypes(record, nullptr);
372     EXPECT_EQ(types2, nullptr);
373 
374     OH_UdmfRecord recordCp;
375     char **types3 = OH_UdmfRecord_GetTypes(&recordCp, nullptr);
376     EXPECT_EQ(types3, nullptr);
377 
378     OH_UdmfRecord_Destroy(record);
379 }
380 
381 /**
382  * @tc.name: OH_Udmf_GetUnifiedRecordTypes002
383  * @tc.desc: OH_UdmfRecord_GetTypes with valid params
384  * @tc.type: FUNC
385  * @tc.require: AROOOH5R5G
386  */
387 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedRecordTypes002, TestSize.Level0)
388 {
389     OH_UdmfRecord *record = OH_UdmfRecord_Create();
390     OH_UdsPlainText *plaintext = OH_UdsPlainText_Create();
391     OH_UdmfRecord_AddPlainText(record, plaintext);
392     unsigned int count = 0;
393     char **types1 = OH_UdmfRecord_GetTypes(record, &count);
394     EXPECT_NE(types1, nullptr);
395     EXPECT_EQ(count, 1);
396 
397     char **types2 = OH_UdmfRecord_GetTypes(record, &count);
398     EXPECT_NE(types2, nullptr);
399     EXPECT_EQ(count, 1);
400     EXPECT_EQ(types2, types1);
401 
402     OH_UdsPlainText_Destroy(plaintext);
403     OH_UdmfRecord_Destroy(record);
404 }
405 
406 /**
407  * @tc.name: OH_Udmf_GetRecords001
408  * @tc.desc: OH_UdmfRecord_GetTypes with invalid params
409  * @tc.type: FUNC
410  * @tc.require: AROOOH5R5G
411  */
412 HWTEST_F(UDMFTest, OH_Udmf_GetRecords001, TestSize.Level0)
413 {
414     OH_UdmfData *unifiedData = OH_UdmfData_Create();
415 
416     unsigned int count1 = 0;
417     OH_UdmfRecord **records1 = OH_UdmfData_GetRecords(nullptr, &count1);
418     EXPECT_EQ(records1, nullptr);
419 
420     OH_UdmfData data;
421     OH_UdmfRecord **records2 = OH_UdmfData_GetRecords(&data, &count1);
422     EXPECT_EQ(records2, nullptr);
423 
424     OH_UdmfRecord **records3 = OH_UdmfData_GetRecords(unifiedData, nullptr);
425     EXPECT_EQ(records3, nullptr);
426 
427     OH_UdmfData_Destroy(unifiedData);
428 }
429 
430 /**
431  * @tc.name: OH_Udmf_GetRecords002
432  * @tc.desc: OH_UdmfRecord_GetTypes with valid params
433  * @tc.type: FUNC
434  * @tc.require: AROOOH5R5G
435  */
436 HWTEST_F(UDMFTest, OH_Udmf_GetRecords002, TestSize.Level0)
437 {
438     OH_UdmfData *unifiedData = OH_UdmfData_Create();
439     OH_UdmfRecord *record = OH_UdmfRecord_Create();
440     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
441     OH_UdmfRecord_AddPlainText(record, plainText);
442     OH_UdmfData_AddRecord(unifiedData, record);
443     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
444     OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
445     OH_UdmfRecord_AddHyperlink(record1, hyperlink);
446     OH_UdmfData_AddRecord(unifiedData, record1);
447 
448     unsigned int count = 0;
449     OH_UdmfRecord **records1 = OH_UdmfData_GetRecords(unifiedData, &count);
450     EXPECT_EQ(count, 2);
451     EXPECT_NE(records1, nullptr);
452 
453     OH_UdmfRecord **records2 = OH_UdmfData_GetRecords(unifiedData, &count);
454     EXPECT_EQ(count, 2);
455     EXPECT_NE(records2, nullptr);
456     EXPECT_EQ(records2, records1);
457 
458     OH_UdsPlainText_Destroy(plainText);
459     OH_UdsHyperlink_Destroy(hyperlink);
460     OH_UdmfRecord_Destroy(record);
461     OH_UdmfRecord_Destroy(record1);
462     OH_UdmfData_Destroy(unifiedData);
463 }
464 
465 /**
466  * @tc.name: OH_Udmf_SetUnifiedData001
467  * @tc.desc: OH_Udmf_SetUnifiedData with invalid param
468  * @tc.type: FUNC
469  * @tc.require: AROOOH5R5G
470  */
471 HWTEST_F(UDMFTest, UdmfTest006, TestSize.Level0)
472 {
473     Udmf_Intention intention = UDMF_INTENTION_DRAG;
474     int setRes1 = OH_Udmf_SetUnifiedData(intention, nullptr, nullptr, 0);
475     EXPECT_EQ(setRes1, UDMF_E_INVALID_PARAM);
476 
477     OH_UdmfData unifiedData;
478     int setRes2 = OH_Udmf_SetUnifiedData(intention, &unifiedData, nullptr, 0);
479     EXPECT_EQ(setRes2, UDMF_E_INVALID_PARAM);
480 
481     OH_UdmfData *unifiedData1 = OH_UdmfData_Create();
482     int setRes3 = OH_Udmf_SetUnifiedData(intention, unifiedData1, nullptr, 0);
483     EXPECT_EQ(setRes3, UDMF_E_INVALID_PARAM);
484 
485     char key[] = "key";
486     int setRes4 = OH_Udmf_SetUnifiedData(intention, unifiedData1, key, 0);
487     EXPECT_EQ(setRes4, UDMF_E_INVALID_PARAM);
488 
489     intention = static_cast<Udmf_Intention>(10);
490     int setRes5 = OH_Udmf_SetUnifiedData(intention, unifiedData1, key, UDMF_KEY_BUFFER_LEN);
491     EXPECT_EQ(setRes5, UDMF_E_INVALID_PARAM);
492 
493     OH_UdmfData_Destroy(unifiedData1);
494 }
495 
496 /**
497  * @tc.name: OH_Udmf_GetUnifiedData001
498  * @tc.desc: OH_Udmf_GetUnifiedData with invalid param
499  * @tc.type: FUNC
500  * @tc.require: AROOOH5R5G
501  */
502 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedData001, TestSize.Level0)
503 {
504     Udmf_Intention intention = UDMF_INTENTION_DRAG;
505     int getRes1 = OH_Udmf_GetUnifiedData(nullptr, intention, nullptr);
506     EXPECT_EQ(getRes1, UDMF_E_INVALID_PARAM);
507 
508     OH_UdmfData unifiedData;
509     int getRes2 = OH_Udmf_GetUnifiedData(nullptr, intention, &unifiedData);
510     EXPECT_EQ(getRes2, UDMF_E_INVALID_PARAM);
511 
512     OH_UdmfData *unifiedData1 = OH_UdmfData_Create();
513     int getRes3 = OH_Udmf_GetUnifiedData(nullptr, intention, unifiedData1);
514     EXPECT_EQ(getRes3, UDMF_E_INVALID_PARAM);
515 
516     int getRes4 = OH_Udmf_GetUnifiedData("KEY", UDMF_INTENTION_PASTEBOARD, unifiedData1);
517     EXPECT_EQ(getRes4, UDMF_E_INVALID_PARAM);
518 
519     OH_UdmfData_Destroy(unifiedData1);
520 }
521 
522 /**
523  * @tc.name: OH_Udmf_SetAndGetUnifiedData001
524  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with valid param
525  * @tc.type: FUNC
526  * @tc.require: AROOOH5R5G
527  */
528 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData001, TestSize.Level0)
529 {
530     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
531     OH_UdmfRecord *record = OH_UdmfRecord_Create();
532     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
533     char content[] = "hello world";
534     OH_UdsPlainText_SetContent(plainText, content);
535     OH_UdmfRecord_AddPlainText(record, plainText);
536     OH_UdmfData_AddRecord(udmfUnifiedData, record);
537     Udmf_Intention intention = UDMF_INTENTION_DRAG;
538     char key[UDMF_KEY_BUFFER_LEN];
539 
540     int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
541     EXPECT_EQ(setRes, UDMF_E_OK);
542     EXPECT_NE(key[0], '\0');
543     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
544     int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
545     EXPECT_EQ(getRes, UDMF_E_OK);
546     unsigned int count = 0;
547     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
548     EXPECT_EQ(count, 1);
549     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
550     OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
551     const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
552     EXPECT_EQ(strcmp(getContent, content), 0);
553 
554     OH_UdsPlainText_Destroy(plainText);
555     OH_UdmfRecord_Destroy(record);
556     OH_UdmfData_Destroy(udmfUnifiedData);
557 
558     OH_UdsPlainText_Destroy(getPlainText);
559     OH_UdmfData_Destroy(readUnifiedData);
560 }
561 
562 /**
563  * @tc.name: OH_Udmf_SetAndGetUnifiedData002
564  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with valid param
565  * @tc.type: FUNC
566  * @tc.require: AROOOH5R5G
567  */
568 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData002, TestSize.Level0)
569 {
570     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
571     char typeId[] = "ApplicationDefined-myType";
572     unsigned char entry[] = "CreateGeneralRecord";
573     unsigned int count = sizeof(entry);
574     OH_UdmfRecord *record = OH_UdmfRecord_Create();
575     int setRes = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
576     EXPECT_EQ(setRes, UDMF_E_OK);
577     setRes = OH_UdmfData_AddRecord(udmfUnifiedData, record);
578     EXPECT_EQ(setRes, UDMF_E_OK);
579     Udmf_Intention intention = UDMF_INTENTION_DRAG;
580     char key[UDMF_KEY_BUFFER_LEN];
581 
582     setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
583     EXPECT_EQ(setRes, UDMF_E_OK);
584     EXPECT_NE(key[0], '\0');
585     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
586     int getUnifiedDataRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
587     EXPECT_EQ(getUnifiedDataRes, UDMF_E_OK);
588     unsigned int getRecordsCount = 0;
589     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &getRecordsCount);
590     EXPECT_EQ(getRecordsCount, 1);
591     EXPECT_NE(getRecords, nullptr);
592 
593     OH_UdmfRecord_Destroy(record);
594     OH_UdmfData_Destroy(readUnifiedData);
595     OH_UdmfData_Destroy(udmfUnifiedData);
596 }
597 
598 /**
599  * @tc.name: OH_Udmf_CreateUnifiedRecord001
600  * @tc.desc: OH_Udmf_CreateUnifiedRecord001
601  * @tc.type: FUNC
602  * @tc.require: AROOOH5R5G
603  */
604 HWTEST_F(UDMFTest, OH_Udmf_CreateUnifiedRecord001, TestSize.Level0)
605 {
606     OH_UdmfRecord *record = OH_UdmfRecord_Create();
607     EXPECT_NE(record, nullptr);
608     EXPECT_NE(record->record_, nullptr);
609     OH_UdmfRecord_Destroy(record);
610 }
611 
612 /**
613  * @tc.name: OH_Udmf_AddGeneralEntry001
614  * @tc.desc: test OH_UdmfRecord_AddGeneralEntry with invalid param
615  * @tc.type: FUNC
616  * @tc.require: AROOOH5R5G
617  */
618 HWTEST_F(UDMFTest, OH_Udmf_AddGeneralEntry001, TestSize.Level0)
619 {
620     int addRes1 = OH_UdmfRecord_AddGeneralEntry(nullptr, nullptr, nullptr, 0);
621     EXPECT_EQ(addRes1, UDMF_E_INVALID_PARAM);
622 
623     OH_UdmfRecord record1;
624     int addRes2 = OH_UdmfRecord_AddGeneralEntry(&record1, nullptr, nullptr, 0);
625     EXPECT_EQ(addRes2, UDMF_E_INVALID_PARAM);
626 
627     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
628     int addRes3 = OH_UdmfRecord_AddGeneralEntry(record2, nullptr, nullptr, 0);
629     EXPECT_EQ(addRes3, UDMF_E_INVALID_PARAM);
630 
631     char typeId[] = "general.plain-text";
632     int addRes4 = OH_UdmfRecord_AddGeneralEntry(record2, typeId, nullptr, 0);
633     EXPECT_EQ(addRes4, UDMF_E_INVALID_PARAM);
634 
635     OH_UdmfRecord_Destroy(record2);
636 }
637 
638 /**
639  * @tc.name: OH_Udmf_GetGeneralEntry001
640  * @tc.desc: test OH_UdmfRecord_GetGeneralEntry with invalid param
641  * @tc.type: FUNC
642  * @tc.require: AROOOH5R5G
643  */
644 HWTEST_F(UDMFTest, OH_Udmf_GetGeneralEntry001, TestSize.Level0)
645 {
646     int addRes1 = OH_UdmfRecord_GetGeneralEntry(nullptr, nullptr, nullptr, 0);
647     EXPECT_EQ(addRes1, UDMF_E_INVALID_PARAM);
648 
649     OH_UdmfRecord record1;
650     int addRes2 = OH_UdmfRecord_GetGeneralEntry(&record1, nullptr, nullptr, 0);
651     EXPECT_EQ(addRes2, UDMF_E_INVALID_PARAM);
652 
653     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
654     int addRes3 = OH_UdmfRecord_GetGeneralEntry(record2, nullptr, nullptr, 0);
655     EXPECT_EQ(addRes3, UDMF_E_INVALID_PARAM);
656 
657     char typeId[] = "general.plain-text";
658     int addRes4 = OH_UdmfRecord_GetGeneralEntry(record2, typeId, nullptr, 0);
659     EXPECT_EQ(addRes4, UDMF_E_INVALID_PARAM);
660     OH_UdmfRecord_Destroy(record2);
661 }
662 
663 /**
664  * @tc.name: OH_Udmf_AddAndGetGeneralEntry002
665  * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with valid param
666  * @tc.type: FUNC
667  * @tc.require: AROOOH5R5G
668  */
669 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry002, TestSize.Level0)
670 {
671     char typeId[] = "general.plain-text-1";
672     unsigned char entry[] = "CreateGeneralRecord";
673     unsigned int count = sizeof(entry);
674     OH_UdmfRecord *record = OH_UdmfRecord_Create();
675     int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
676     EXPECT_EQ(addRes1, UDMF_E_OK);
677 }
678 
679 /**
680  * @tc.name: OH_Udmf_AddAndGetGeneralEntry003
681  * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with appdefined type
682  * @tc.type: FUNC
683  * @tc.require:
684  */
685 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry003, TestSize.Level0)
686 {
687     char typeId[] = "ApplicationDefined-myType";
688     unsigned char entry[] = "CreateGeneralRecord1";
689     unsigned int count = sizeof(entry);
690     OH_UdmfRecord *record = OH_UdmfRecord_Create();
691     int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
692     EXPECT_EQ(addRes1, UDMF_E_OK);
693 
694     unsigned int getCount = 0;
695     unsigned char *getEntry;
696     int getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId, &getEntry, &getCount);
697     EXPECT_EQ(getRes, UDMF_E_OK);
698     EXPECT_EQ(getCount, count);
699     ASSERT_TRUE(CheckUnsignedChar(entry, getEntry, getCount));
700     OH_UdmfRecord_Destroy(record);
701 }
702 
703 /**
704  * @tc.name: OH_Udmf_AddAndGetGeneralEntry004
705  * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with appdefined diff types
706  * @tc.type: FUNC
707  * @tc.require:
708  */
709 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry004, TestSize.Level0)
710 {
711     char typeId1[] = "ApplicationDefined-myType1";
712     unsigned char entry1[] = "CreateGeneralRecord1";
713     unsigned int count1 = sizeof(entry1);
714     char typeId2[] = "ApplicationDefined-myType2";
715     unsigned char entry2[] = "CreateGeneralRecord2";
716     unsigned int count2 = sizeof(entry2);
717     OH_UdmfRecord *record = OH_UdmfRecord_Create();
718     int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId1, entry1, count1);
719     EXPECT_EQ(addRes1, UDMF_E_OK);
720     addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId2, entry2, count2);
721     EXPECT_EQ(addRes1, UDMF_E_OK);
722 
723     unsigned int getCount1 = 0;
724     unsigned char *getEntry1;
725     int getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId1, &getEntry1, &getCount1);
726     EXPECT_EQ(getRes, UDMF_E_OK);
727     EXPECT_EQ(getCount1, count1);
728     ASSERT_TRUE(CheckUnsignedChar(entry1, getEntry1, getCount1));
729 
730     unsigned int getCount2 = 0;
731     unsigned char *getEntry2;
732     getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId2, &getEntry2, &getCount2);
733     EXPECT_EQ(getRes, UDMF_E_OK);
734     EXPECT_EQ(getCount2, count2);
735     ASSERT_TRUE(CheckUnsignedChar(entry2, getEntry2, getCount2));
736 
737     OH_UdmfRecord_Destroy(record);
738 }
739 
740 /**
741  * @tc.name: OH_Udmf_BuildRecordByPlainText001
742  * @tc.desc: test OH_UdmfRecord_AddPlainText with invalid param
743  * @tc.type: FUNC
744  * @tc.require: AROOOH5R5G
745  */
746 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByPlainText001, TestSize.Level0)
747 {
748     int buildRes1 = OH_UdmfRecord_AddPlainText(nullptr, nullptr);
749     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
750 
751     OH_UdmfRecord record1;
752     int buildRes2 = OH_UdmfRecord_AddPlainText(&record1, nullptr);
753     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
754 
755     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
756     int buildRes3 = OH_UdmfRecord_AddPlainText(record2, nullptr);
757     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
758 
759     OH_UdsPlainText plainText;
760     int buildRes4 = OH_UdmfRecord_AddPlainText(record2, &plainText);
761     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
762 
763     OH_UdmfRecord_Destroy(record2);
764 }
765 
766 /**
767  * @tc.name: OH_Udmf_GetPlainTextFromRecord001
768  * @tc.desc: test OH_UdmfRecord_GetPlainText with invalid param
769  * @tc.type: FUNC
770  * @tc.require: AROOOH5R5G
771  */
772 HWTEST_F(UDMFTest, OH_Udmf_GetPlainTextFromRecord001, TestSize.Level0)
773 {
774     int buildRes1 = OH_UdmfRecord_GetPlainText(nullptr, nullptr);
775     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
776 
777     OH_UdmfRecord record1;
778     int buildRes2 = OH_UdmfRecord_GetPlainText(&record1, nullptr);
779     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
780 
781     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
782     int buildRes3 = OH_UdmfRecord_GetPlainText(record2, nullptr);
783     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
784 
785     OH_UdsPlainText plainText;
786     int buildRes4 = OH_UdmfRecord_GetPlainText(record2, &plainText);
787     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
788 
789     OH_UdmfRecord_Destroy(record2);
790 }
791 
792 /**
793  * @tc.name: OH_Udmf_BuildAndGetPlainTextFromRecord001
794  * @tc.desc: test OH_UdmfRecord_GetPlainText and OH_Udmf_BuildPlainTextFromRecord with invalid param
795  * @tc.type: FUNC
796  * @tc.require: AROOOH5R5G
797  */
798 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetPlainTextFromRecord001, TestSize.Level0)
799 {
800     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
801     OH_UdsPlainText *plainText1 = OH_UdsPlainText_Create();
802     char content[] = "hello world";
803     OH_UdsPlainText_SetContent(plainText1, content);
804     int buildRes = OH_UdmfRecord_AddPlainText(record1, plainText1);
805     EXPECT_EQ(buildRes, UDMF_E_OK);
806 
807     OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
808     int getRes = OH_UdmfRecord_GetPlainText(record1, plainText2);
809     EXPECT_EQ(getRes, UDMF_E_OK);
810 
811     const char *getContent = OH_UdsPlainText_GetContent(plainText2);
812     EXPECT_EQ(strcmp(content, getContent), 0);
813 
814     OH_UdmfRecord_Destroy(record1);
815     OH_UdsPlainText_Destroy(plainText1);
816     OH_UdsPlainText_Destroy(plainText2);
817 }
818 
819 /**
820  * @tc.name: OH_Udmf_BuildRecordByHyperlink001
821  * @tc.desc: test OH_UdmfRecord_AddHyperlink with invalid param
822  * @tc.type: FUNC
823  * @tc.require: AROOOH5R5G
824  */
825 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByHyperlink001, TestSize.Level0)
826 {
827     int buildRes1 = OH_UdmfRecord_AddHyperlink(nullptr, nullptr);
828     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
829 
830     OH_UdmfRecord record1;
831     int buildRes2 = OH_UdmfRecord_AddHyperlink(&record1, nullptr);
832     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
833 
834     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
835     int buildRes3 = OH_UdmfRecord_AddHyperlink(record2, nullptr);
836     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
837 
838     OH_UdsHyperlink hyperlink;
839     int buildRes4 = OH_UdmfRecord_AddHyperlink(record2, &hyperlink);
840     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
841 
842     OH_UdmfRecord_Destroy(record2);
843 }
844 
845 /**
846  * @tc.name: OH_Udmf_GetHyperlinkFromRecord001
847  * @tc.desc: test OH_UdmfRecord_GetHyperlink with invalid param
848  * @tc.type: FUNC
849  * @tc.require: AROOOH5R5G
850  */
851 HWTEST_F(UDMFTest, OH_Udmf_GetHyperlinkFromRecord001, TestSize.Level0)
852 {
853     int buildRes1 = OH_UdmfRecord_GetHyperlink(nullptr, nullptr);
854     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
855 
856     OH_UdmfRecord record1;
857     int buildRes2 = OH_UdmfRecord_GetHyperlink(&record1, nullptr);
858     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
859 
860     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
861     int buildRes3 = OH_UdmfRecord_GetHyperlink(record2, nullptr);
862     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
863 
864     OH_UdsHyperlink hyperlink;
865     int buildRes4 = OH_UdmfRecord_GetHyperlink(record2, &hyperlink);
866     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
867 
868     OH_UdmfRecord_Destroy(record2);
869 }
870 
871 /**
872  * @tc.name: OH_Udmf_BuildAndGetHyperlinkFromRecord001
873  * @tc.desc: test OH_Udmf_BuildAndGetHyperlinkFromRecord with invalid param
874  * @tc.type: FUNC
875  * @tc.require: AROOOH5R5G
876  */
877 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetHyperlinkFromRecord001, TestSize.Level0)
878 {
879     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
880     OH_UdsHyperlink *hyperlink1 = OH_UdsHyperlink_Create();
881     char url[] = "https://gitee.com/openharmony/distributeddatamgr_udmf/members";
882     OH_UdsHyperlink_SetUrl(hyperlink1, url);
883     int buildRes = OH_UdmfRecord_AddHyperlink(record1, hyperlink1);
884     EXPECT_EQ(buildRes, UDMF_E_OK);
885 
886     OH_UdsHyperlink *hyperlink2 = OH_UdsHyperlink_Create();
887     int getRes = OH_UdmfRecord_GetHyperlink(record1, hyperlink2);
888     EXPECT_EQ(getRes, UDMF_E_OK);
889 
890     const char *getUrl = OH_UdsHyperlink_GetUrl(hyperlink2);
891     EXPECT_EQ(strcmp(url, getUrl), 0);
892 
893     OH_UdmfRecord_Destroy(record1);
894     OH_UdsHyperlink_Destroy(hyperlink1);
895     OH_UdsHyperlink_Destroy(hyperlink2);
896 }
897 
898 /**
899  * @tc.name: OH_Udmf_BuildRecordByHtml001
900  * @tc.desc: test OH_UdmfRecord_AddHtml with invalid param
901  * @tc.type: FUNC
902  * @tc.require: AROOOH5R5G
903  */
904 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByHtml001, TestSize.Level0)
905 {
906     int buildRes1 = OH_UdmfRecord_AddHtml(nullptr, nullptr);
907     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
908 
909     OH_UdmfRecord record1;
910     int buildRes2 = OH_UdmfRecord_AddHtml(&record1, nullptr);
911     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
912 
913     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
914     int buildRes3 = OH_UdmfRecord_AddHtml(record2, nullptr);
915     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
916 
917     OH_UdsHtml html;
918     int buildRes4 = OH_UdmfRecord_AddHtml(record2, &html);
919     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
920 
921     OH_UdmfRecord_Destroy(record2);
922 }
923 
924 /**
925  * @tc.name: OH_Udmf_GetHtmlFromRecord001
926  * @tc.desc: test OH_UdmfRecord_GetHtml with invalid param
927  * @tc.type: FUNC
928  * @tc.require: AROOOH5R5G
929  */
930 HWTEST_F(UDMFTest, OH_Udmf_GetHtmlFromRecord001, TestSize.Level0)
931 {
932     int buildRes1 = OH_UdmfRecord_GetHtml(nullptr, nullptr);
933     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
934 
935     OH_UdmfRecord record1;
936     int buildRes2 = OH_UdmfRecord_GetHtml(&record1, nullptr);
937     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
938 
939     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
940     int buildRes3 = OH_UdmfRecord_GetHtml(record2, nullptr);
941     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
942 
943     OH_UdsHtml html;
944     int buildRes4 = OH_UdmfRecord_GetHtml(record2, &html);
945     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
946 
947     OH_UdmfRecord_Destroy(record2);
948 }
949 
950 /**
951  * @tc.name: OH_Udmf_BuildAndGetHtmlFromRecord001
952  * @tc.desc: test OH_Udmf_BuildAndGetHtmlFromRecord with invalid param
953  * @tc.type: FUNC
954  * @tc.require: AROOOH5R5G
955  */
956 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetHtmlFromRecord001, TestSize.Level0)
957 {
958     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
959     OH_UdsHtml *html1 = OH_UdsHtml_Create();
960     char content[] = "hello world";
961     OH_UdsHtml_SetContent(html1, content);
962     int buildRes = OH_UdmfRecord_AddHtml(record1, html1);
963     EXPECT_EQ(buildRes, UDMF_E_OK);
964 
965     OH_UdsHtml *html2 = OH_UdsHtml_Create();
966     int getRes = OH_UdmfRecord_GetHtml(record1, html2);
967     EXPECT_EQ(getRes, UDMF_E_OK);
968 
969     const char *getContent = OH_UdsHtml_GetContent(html2);
970     EXPECT_EQ(strcmp(content, getContent), 0);
971 
972     OH_UdmfRecord_Destroy(record1);
973     OH_UdsHtml_Destroy(html1);
974     OH_UdsHtml_Destroy(html2);
975 }
976 
977 /**
978  * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyAppItem001
979  * @tc.desc: test OH_UdmfRecord_AddAppItem with invalid param
980  * @tc.type: FUNC
981  * @tc.require: AROOOH5R5G
982  */
983 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyAppItem001, TestSize.Level0)
984 {
985     int buildRes1 = OH_UdmfRecord_AddAppItem(nullptr, nullptr);
986     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
987 
988     OH_UdmfRecord record1;
989     int buildRes2 = OH_UdmfRecord_AddAppItem(&record1, nullptr);
990     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
991 
992     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
993     int buildRes3 = OH_UdmfRecord_AddAppItem(record2, nullptr);
994     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
995 
996     OH_UdsAppItem appItem;
997     int buildRes4 = OH_UdmfRecord_AddAppItem(record2, &appItem);
998     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
999 
1000     OH_UdmfRecord_Destroy(record2);
1001 }
1002 
1003 /**
1004  * @tc.name: OH_Udmf_GetOpenHarmonyAppItemFromRecord001
1005  * @tc.desc: test OH_UdmfRecord_GetAppItem with invalid param
1006  * @tc.type: FUNC
1007  * @tc.require: AROOOH5R5G
1008  */
1009 HWTEST_F(UDMFTest, OH_Udmf_GetOpenHarmonyAppItemFromRecord001, TestSize.Level0)
1010 {
1011     int buildRes1 = OH_UdmfRecord_GetAppItem(nullptr, nullptr);
1012     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1013 
1014     OH_UdmfRecord record1;
1015     int buildRes2 = OH_UdmfRecord_GetAppItem(&record1, nullptr);
1016     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1017 
1018     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1019     int buildRes3 = OH_UdmfRecord_GetAppItem(record2, nullptr);
1020     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1021 
1022     OH_UdsAppItem appItem;
1023     int buildRes4 = OH_UdmfRecord_GetAppItem(record2, &appItem);
1024     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1025 
1026     OH_UdmfRecord_Destroy(record2);
1027 }
1028 
1029 /**
1030  * @tc.name: OH_Udmf_BuildAndGetAppItemFromRecord001
1031  * @tc.desc: test OH_Udmf_BuildAndGetAppItemFromRecord with invalid param
1032  * @tc.type: FUNC
1033  * @tc.require: AROOOH5R5G
1034  */
1035 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetAppItemFromRecord001, TestSize.Level0)
1036 {
1037     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1038     OH_UdsAppItem *appItem1 = OH_UdsAppItem_Create();
1039     char name[] = "appItem";
1040     OH_UdsAppItem_SetName(appItem1, name);
1041     int buildRes = OH_UdmfRecord_AddAppItem(record1, appItem1);
1042     EXPECT_EQ(buildRes, UDMF_E_OK);
1043 
1044     OH_UdsAppItem *appItem2 = OH_UdsAppItem_Create();
1045     int getRes = OH_UdmfRecord_GetAppItem(record1, appItem2);
1046     EXPECT_EQ(getRes, UDMF_E_OK);
1047 
1048     const char *getName = OH_UdsAppItem_GetName(appItem2);
1049     EXPECT_EQ(strcmp(name, getName), 0);
1050 
1051     OH_UdmfRecord_Destroy(record1);
1052     OH_UdsAppItem_Destroy(appItem1);
1053     OH_UdsAppItem_Destroy(appItem2);
1054 }
1055 
1056 /**
1057  * @tc.name: OH_Udmf_CreatePropertiesFromUnifiedData001
1058  * @tc.desc: Normal testcase of OH_UdmfProperty_Create
1059  * @tc.type: FUNC
1060  */
1061 HWTEST_F(UDMFTest, OH_Udmf_CreatePropertiesFromUnifiedData001, TestSize.Level1)
1062 {
1063     OH_UdmfData *data = OH_UdmfData_Create();
1064     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1065     auto duration = std::chrono::system_clock::now().time_since_epoch();
1066     EXPECT_LE(properties->properties_->timestamp,
1067         std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
1068     OH_UdmfData_Destroy(data);
1069     OH_UdmfProperty_Destroy(properties);
1070 }
1071 
1072 /**
1073  * @tc.name: OH_Udmf_SetPropertiesTag001
1074  * @tc.desc: Normal testcase of OH_Udmf_SetPropertiesTag001
1075  * @tc.type: FUNC
1076  */
1077 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesTag001, TestSize.Level1)
1078 {
1079     OH_UdmfData *data = OH_UdmfData_Create();
1080     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1081     std::string tag("tag");
1082     int result = OH_UdmfProperty_SetTag(properties, tag.c_str());
1083     EXPECT_EQ(UDMF_E_OK, result);
1084     EXPECT_EQ(tag, OH_UdmfProperty_GetTag(properties));
1085     OH_UdmfProperty_Destroy(properties);
1086     OH_UdmfData_Destroy(data);
1087 }
1088 
1089 /**
1090  * @tc.name: OH_Udmf_SetPropertiesShareOption001
1091  * @tc.desc: set properties IN_APP
1092  * @tc.type: FUNC
1093  */
1094 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption001, TestSize.Level1)
1095 {
1096     OH_UdmfData *data = OH_UdmfData_Create();
1097     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1098     int result = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_IN_APP);
1099     EXPECT_EQ(UDMF_E_OK, result);
1100     EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_IN_APP, OH_UdmfProperty_GetShareOption(properties));
1101     OH_UdmfData_Destroy(data);
1102     OH_UdmfProperty_Destroy(properties);
1103 }
1104 
1105 /**
1106  * @tc.name: OH_Udmf_SetPropertiesShareOption002
1107  * @tc.desc: set properties CROSS_APP
1108  * @tc.type: FUNC
1109  */
1110 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption002, TestSize.Level1)
1111 {
1112     OH_UdmfData *data = OH_UdmfData_Create();
1113     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1114     int result = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP);
1115     EXPECT_EQ(UDMF_E_OK, result);
1116     EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP, OH_UdmfProperty_GetShareOption(properties));
1117     OH_UdmfData_Destroy(data);
1118     OH_UdmfProperty_Destroy(properties);
1119 }
1120 
1121 /**
1122  * @tc.name: OH_Udmf_SetPropertiesShareOption003
1123  * @tc.desc: set invalid properties
1124  * @tc.type: FUNC
1125  */
1126 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption003, TestSize.Level1)
1127 {
1128     OH_UdmfProperty *property = nullptr;
1129     EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_INVALID, OH_UdmfProperty_GetShareOption(property));
1130 }
1131 
1132 /**
1133  * @tc.name: OH_Udmf_SetPropertiesExtrasIntParam001
1134  * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasIntParam
1135  * @tc.type: FUNC
1136  */
1137 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesExtrasIntParam001, TestSize.Level1)
1138 {
1139     OH_UdmfData *data = OH_UdmfData_Create();
1140     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1141     int result = OH_UdmfProperty_SetExtrasIntParam(properties, "keyInt", 0);
1142     EXPECT_EQ(UDMF_E_OK, result);
1143     EXPECT_EQ(0, OH_UdmfProperty_GetExtrasIntParam(properties, "keyInt", -1));
1144     OH_UdmfData_Destroy(data);
1145     OH_UdmfProperty_Destroy(properties);
1146 }
1147 
1148 /**
1149  * @tc.name: OH_Udmf_SetPropertiesExtrasStringParam001
1150  * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1151  * @tc.type: FUNC
1152  */
1153 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesExtrasStringParam001, TestSize.Level1)
1154 {
1155     OH_UdmfData *data = OH_UdmfData_Create();
1156     OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1157     std::string str("str");
1158     int result = OH_UdmfProperty_SetExtrasStringParam(properties, "keyStr", str.c_str());
1159     EXPECT_EQ(UDMF_E_OK, result);
1160     std::string actualStr(OH_UdmfProperty_GetExtrasStringParam(properties, "keyStr"));
1161     EXPECT_EQ(str, actualStr);
1162     OH_UdmfData_Destroy(data);
1163     OH_UdmfProperty_Destroy(properties);
1164 }
1165 
1166 /**
1167  * @tc.name: OH_Udmf_MultiStyleRecord001
1168  * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1169  * @tc.type: FUNC
1170  */
1171 HWTEST_F(UDMFTest, OH_Udmf_MultiStyleRecord001, TestSize.Level1)
1172 {
1173     OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
1174     char plainTextContent[] = "plain text";
1175     OH_UdsPlainText_SetContent(plainText, plainTextContent);
1176 
1177     OH_UdsHyperlink* hyperlink = OH_UdsHyperlink_Create();
1178     char url[] = "hyper link";
1179     OH_UdsHyperlink_SetUrl(hyperlink, url);
1180 
1181     OH_UdsHtml* html = OH_UdsHtml_Create();
1182     char htmlContent[] = "html";
1183     OH_UdsHtml_SetContent(html, htmlContent);
1184 
1185     OH_UdsAppItem* appItem = OH_UdsAppItem_Create();
1186     char name[] = "appItem";
1187     OH_UdsAppItem_SetName(appItem, name);
1188 
1189     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1190 
1191     OH_UdmfRecord_AddPlainText(record, plainText);
1192     OH_UdmfRecord_AddHyperlink(record, hyperlink);
1193     OH_UdmfRecord_AddHtml(record, html);
1194     OH_UdmfRecord_AddAppItem(record, appItem);
1195 
1196     unsigned int count = 0;
1197     char** types = OH_UdmfRecord_GetTypes(record, &count);
1198     EXPECT_NE(types, nullptr);
1199     EXPECT_EQ(count, 4);
1200 
1201     OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
1202     OH_UdmfRecord_GetPlainText(record, getPlainText);
1203     const char *getPlainTextContent = OH_UdsPlainText_GetContent(getPlainText);
1204     EXPECT_EQ(strcmp(getPlainTextContent, plainTextContent), 0);
1205 
1206     OH_UdsHyperlink *getHyperLink = OH_UdsHyperlink_Create();
1207     OH_UdmfRecord_GetHyperlink(record, getHyperLink);
1208     const char *getUrl = OH_UdsHyperlink_GetUrl(getHyperLink);
1209     EXPECT_EQ(strcmp(getUrl, url), 0);
1210 
1211     OH_UdsHtml *getHtml = OH_UdsHtml_Create();
1212     OH_UdmfRecord_GetHtml(record, getHtml);
1213     const char *getHtmlContent = OH_UdsHtml_GetContent(getHtml);
1214     EXPECT_EQ(strcmp(getHtmlContent, htmlContent), 0);
1215 
1216     OH_UdsAppItem *getAppItem = OH_UdsAppItem_Create();
1217     OH_UdmfRecord_GetAppItem(record, getAppItem);
1218     const char *getName = OH_UdsAppItem_GetName(getAppItem);
1219     EXPECT_EQ(strcmp(getName, name), 0);
1220 
1221     OH_UdmfData* data = OH_UdmfData_Create();
1222     OH_UdmfData_AddRecord(data, record);
1223 
1224     unsigned int count2 = 0;
1225     char** types2 = OH_UdmfData_GetTypes(data, &count2);
1226     EXPECT_NE(types2, nullptr);
1227     EXPECT_EQ(count2, 4);
1228 
1229     char plianTextType[] = "general.plain-text";
1230     char hyperLinkType[] = "general.hyperlink";
1231     char htmlType[] = "general.html";
1232     char appItemType[] = "openharmony.app-item";
1233 
1234     EXPECT_TRUE(OH_UdmfData_HasType(data, plianTextType));
1235     EXPECT_TRUE(OH_UdmfData_HasType(data, hyperLinkType));
1236     EXPECT_TRUE(OH_UdmfData_HasType(data, htmlType));
1237     EXPECT_TRUE(OH_UdmfData_HasType(data, appItemType));
1238 
1239     OH_UdsPlainText_Destroy(plainText);
1240     OH_UdsPlainText_Destroy(getPlainText);
1241     OH_UdsHyperlink_Destroy(hyperlink);
1242     OH_UdsHyperlink_Destroy(getHyperLink);
1243     OH_UdsHtml_Destroy(html);
1244     OH_UdsHtml_Destroy(getHtml);
1245     OH_UdsAppItem_Destroy(appItem);
1246     OH_UdsAppItem_Destroy(getAppItem);
1247     OH_UdmfRecord_Destroy(record);
1248     OH_UdmfData_Destroy(data);
1249 }
1250 
1251 /**
1252  * @tc.name: OH_Udmf_MultiStyleRecord002
1253  * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1254  * @tc.type: FUNC
1255  */
1256 HWTEST_F(UDMFTest, OH_Udmf_MultiStyleRecord002, TestSize.Level1)
1257 {
1258     LOG_INFO(UDMF_TEST, "GetSummary005 begin.");
1259 
1260     CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1261     UnifiedData data;
1262     std::string key;
1263     auto object = std::make_shared<Object>();
1264     object->value_[UNIFORM_DATA_TYPE] = UtdUtils::GetUtdIdFromUtdEnum(UDType::PLAIN_TEXT);
1265     object->value_[CONTENT] = "content_";
1266     object->value_[ABSTRACT] = "abstract_";
1267     auto record = std::make_shared<UnifiedRecord>(UDType::PLAIN_TEXT, object);
1268 
1269     std::vector<uint8_t> raw = {1, 2, 3, 4, 5};
1270     std::shared_ptr<Object> obj = std::make_shared<Object>();
1271     obj->value_[UNIFORM_DATA_TYPE] = "general.content-form";
1272     obj->value_[THUMB_DATA] = raw;
1273     obj->value_[THUMB_DATA_LENGTH] = 5;
1274     obj->value_[DESCRIPTION] = "descritpion";
1275     obj->value_[TITLE] = "title";
1276     obj->value_[APP_ICON_LENGTH] = 5;
1277     obj->value_[APP_NAME] = "appName";
1278     obj->value_[LINK_URL] = "linkUri";
1279     auto contentForm = UnifiedRecord(CONTENT_FORM, obj);
1280     record->AddEntry(contentForm.GetUtdId(), contentForm.GetOriginValue());
1281 
1282     data.AddRecord(record);
1283 
1284     auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1285     ASSERT_EQ(status, E_OK);
1286 
1287     ASSERT_EQ(status, E_OK);
1288     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
1289     int getRes = OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, readUnifiedData);
1290     ASSERT_EQ(getRes, E_OK);
1291     unsigned int count = 0;
1292     OH_UdmfRecord** readRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
1293     ASSERT_EQ(count, 1);
1294     for (int i = 0; i < count; i++) {
1295         OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
1296         OH_UdmfRecord_GetContentForm(readRecords[i], contentForm);
1297         const char* desc = OH_UdsContentForm_GetDescription(contentForm);
1298         EXPECT_EQ(std::string(desc), "descritpion");
1299         OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1300         OH_UdmfRecord_GetPlainText(readRecords[i], plainText);
1301         const char* text = OH_UdsPlainText_GetContent(plainText);
1302         EXPECT_EQ(std::string(text), "content_");
1303     }
1304 }
1305 
1306 /**
1307  * @tc.name: OH_UdmfRecordProvider_Create001
1308  * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Create
1309  * @tc.type: FUNC
1310  */
1311 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Create001, TestSize.Level1)
1312 {
1313     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1314     EXPECT_NE(provider, nullptr);
1315     OH_UdmfRecordProvider_Destroy(provider);
1316 }
1317 
1318 /**
1319  * @tc.name: OH_UdmfRecordProvider_Destroy001
1320  * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Destroy
1321  * @tc.type: FUNC
1322  */
1323 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy001, TestSize.Level1)
1324 {
1325     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1326     EXPECT_NE(provider, nullptr);
1327     int num = 1;
1328     void* context = &num;
1329     OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1330     int res1 = OH_UdmfRecordProvider_Destroy(provider);
1331     EXPECT_EQ(res1, UDMF_E_OK);
1332 }
1333 
1334 /**
1335  * @tc.name: OH_UdmfRecordProvider_Destroy002
1336  * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_Destroy
1337  * @tc.type: FUNC
1338  */
1339 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy002, TestSize.Level1)
1340 {
1341     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1342     EXPECT_NE(provider, nullptr);
1343     int num = 1;
1344     void* context = &num;
1345     OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1346     int res1 = OH_UdmfRecordProvider_Destroy(provider);
1347     EXPECT_EQ(res1, UDMF_E_OK);
1348 }
1349 
1350 /**
1351  * @tc.name: OH_UdmfRecordProvider_SetData001
1352  * @tc.desc: Normal testcase of OH_UdmfRecordProvider_SetData
1353  * @tc.type: FUNC
1354  */
1355 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData001, TestSize.Level1)
1356 {
1357     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1358     EXPECT_NE(provider, nullptr);
1359     int num = 1;
1360     void* context = &num;
1361     int res = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1362     EXPECT_NE(provider->context, nullptr);
1363     EXPECT_NE(provider->callback, nullptr);
1364     EXPECT_NE(provider->finalize, nullptr);
1365     EXPECT_EQ(res, UDMF_E_OK);
1366     OH_UdmfRecordProvider_Destroy(provider);
1367 }
1368 
1369 /**
1370  * @tc.name: OH_UdmfRecordProvider_SetData002
1371  * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_SetData
1372  * @tc.type: FUNC
1373  */
1374 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData002, TestSize.Level1)
1375 {
1376     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1377     EXPECT_NE(provider, nullptr);
1378     int num = 1;
1379     void* context = &num;
1380     int res1 = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1381     EXPECT_EQ(provider->context, nullptr);
1382     EXPECT_EQ(provider->finalize, nullptr);
1383     EXPECT_EQ(res1, UDMF_E_INVALID_PARAM);
1384 
1385     int res2 = OH_UdmfRecordProvider_SetData(nullptr, context, GetDataCallbackFunc, nullptr);
1386     EXPECT_EQ(res2, UDMF_E_INVALID_PARAM);
1387 
1388     int res3 = OH_UdmfRecordProvider_SetData(provider, context, nullptr, nullptr);
1389     EXPECT_EQ(res3, UDMF_E_INVALID_PARAM);
1390     OH_UdmfRecordProvider_Destroy(provider);
1391 }
1392 
1393 /**
1394  * @tc.name: OH_UdmfRecord_SetProvider001
1395  * @tc.desc: Normal testcase of OH_UdmfRecord_SetProvider
1396  * @tc.type: FUNC
1397  */
1398 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider001, TestSize.Level1)
1399 {
1400     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1401     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1402     char content[] = "hello world";
1403     OH_UdsPlainText_SetContent(plainText, content);
1404     OH_UdmfRecord_AddPlainText(record, plainText);
1405     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1406     EXPECT_NE(provider, nullptr);
1407     int num = 1;
1408     void* context = &num;
1409     OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1410     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1411 
1412     int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1413     EXPECT_EQ(res, UDMF_E_OK);
1414     OH_UdmfRecordProvider_Destroy(provider);
1415 }
1416 
1417 /**
1418  * @tc.name: OH_UdmfRecord_SetProvider002
1419  * @tc.desc: invalid parameters testcase of OH_UdmfRecord_SetProvider
1420  * @tc.type: FUNC
1421  */
1422 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider002, TestSize.Level1)
1423 {
1424     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1425     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1426     char content[] = "hello world";
1427     OH_UdsPlainText_SetContent(plainText, content);
1428     OH_UdmfRecord_AddPlainText(record, plainText);
1429     OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1430     EXPECT_NE(provider, nullptr);
1431     int num = 1;
1432     void* context = &num;
1433     OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1434     const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1435 
1436     int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1437     EXPECT_EQ(res, UDMF_E_OK);
1438     OH_UdmfRecordProvider_Destroy(provider);
1439 }
1440 
1441 /**
1442  * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001
1443  * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1444  * @tc.type: FUNC
1445  */
1446 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001, TestSize.Level0)
1447 {
1448     int buildRes1 = OH_UdmfRecord_AddArrayBuffer(nullptr, nullptr, nullptr);
1449     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1450 
1451     OH_UdmfRecord record1;
1452     int buildRes2 = OH_UdmfRecord_AddArrayBuffer(&record1, nullptr, nullptr);
1453     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1454 
1455     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1456     int buildRes3 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, nullptr);
1457     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1458 
1459     OH_UdsArrayBuffer buffer;
1460     int buildRes4 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, &buffer);
1461     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1462 
1463     OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1464     int buildRes5 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, buffer2);
1465     EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1466 
1467     char type[] = "general.plain-text";
1468     int buildRes6 = OH_UdmfRecord_AddArrayBuffer(record2, type, buffer2);
1469     EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1470 
1471     char type2[] = "ApplicationDefined-myType1";
1472     int buildRes7 = OH_UdmfRecord_AddArrayBuffer(record2, type2, buffer2);
1473     EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1474 
1475     OH_UdmfRecord_Destroy(record2);
1476     OH_UdsArrayBuffer_Destroy(buffer2);
1477 }
1478 
1479 /**
1480  * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002
1481  * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1482  * @tc.type: FUNC
1483  */
1484 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002, TestSize.Level0)
1485 {
1486     int buildRes1 = OH_UdmfRecord_GetArrayBuffer(nullptr, nullptr, nullptr);
1487     EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1488 
1489     OH_UdmfRecord record1;
1490     int buildRes2 = OH_UdmfRecord_GetArrayBuffer(&record1, nullptr, nullptr);
1491     EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1492 
1493     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1494     int buildRes3 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, nullptr);
1495     EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1496 
1497     OH_UdsArrayBuffer buffer;
1498     int buildRes4 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, &buffer);
1499     EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1500 
1501     OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1502     int buildRes5 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, buffer2);
1503     EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1504 
1505     char type[] = "general.plain-text";
1506     int buildRes6 = OH_UdmfRecord_GetArrayBuffer(record2, type, buffer2);
1507     EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1508 
1509     char type2[] = "ApplicationDefined-myType1";
1510     int buildRes7 = OH_UdmfRecord_GetArrayBuffer(record2, type2, buffer2);
1511     EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1512 
1513     OH_UdmfRecord_Destroy(record2);
1514     OH_UdsArrayBuffer_Destroy(buffer2);
1515 }
1516 
1517 /**
1518  * @tc.name: OH_Udmf_GetArrayBufferFromRecord001
1519  * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1520  * @tc.type: FUNC
1521  */
1522 HWTEST_F(UDMFTest, OH_Udmf_GetArrayBufferFromRecord001, TestSize.Level0)
1523 {
1524     unsigned char data1[] = "Hello world";
1525     unsigned int len1 = sizeof(data1);
1526     OH_UdsArrayBuffer *buffer1 = OH_UdsArrayBuffer_Create();
1527     OH_UdsArrayBuffer_SetData(buffer1, data1, len1);
1528 
1529     char type1[] = "ApplicationDefined-myType1";
1530     OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1531     int buildRes = OH_UdmfRecord_AddArrayBuffer(record1, type1, buffer1);
1532     ASSERT_EQ(buildRes, UDMF_E_OK);
1533 
1534     char type2[] = "ApplicationDefined-myType2";
1535     OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1536     int getRes = OH_UdmfRecord_GetArrayBuffer(record1, type2, buffer2);
1537     EXPECT_EQ(getRes, UDMF_E_INVALID_PARAM);
1538 
1539     int getRes2 = OH_UdmfRecord_GetArrayBuffer(record1, type1, buffer2);
1540     ASSERT_EQ(getRes2, UDMF_E_OK);
1541 
1542     unsigned int getLen = 0;
1543     unsigned char *getData;
1544     int getRes3 = OH_UdsArrayBuffer_GetData(buffer2, &getData, &getLen);
1545     ASSERT_EQ(getRes3, UDMF_E_OK);
1546     ASSERT_EQ(len1, getLen);
1547     ASSERT_TRUE(CheckUnsignedChar(data1, getData, getLen));
1548 
1549     OH_UdmfRecord_Destroy(record1);
1550     OH_UdsArrayBuffer_Destroy(buffer1);
1551     OH_UdsArrayBuffer_Destroy(buffer2);
1552 }
1553 
1554 /**
1555  * @tc.name: OH_UdmfData_GetPrimaryPlainText001
1556  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1557  * @tc.type: FUNC
1558  */
1559 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText001, TestSize.Level1)
1560 {
1561     int result = OH_UdmfData_GetPrimaryPlainText(nullptr, nullptr);
1562     EXPECT_EQ(result, UDMF_E_INVALID_PARAM);
1563 
1564     OH_UdmfData data;
1565     int result2 = OH_UdmfData_GetPrimaryPlainText(&data, nullptr);
1566     EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1567 
1568     OH_UdmfData *data2 = OH_UdmfData_Create();
1569     int result3 = OH_UdmfData_GetPrimaryPlainText(data2, nullptr);
1570     EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1571 
1572     OH_UdsPlainText plainText;
1573     int result4 = OH_UdmfData_GetPrimaryPlainText(data2, &plainText);
1574     EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1575 
1576     OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1577     int result5 = OH_UdmfData_GetPrimaryPlainText(data2, plainText2);
1578     EXPECT_EQ(result5, UDMF_ERR);
1579 
1580     OH_UdsPlainText_Destroy(plainText2);
1581     OH_UdmfData_Destroy(data2);
1582 }
1583 
1584 /**
1585  * @tc.name: OH_UdmfData_GetPrimaryPlainText002
1586  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1587  * @tc.type: FUNC
1588  */
1589 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText002, TestSize.Level1)
1590 {
1591     const char *helloWorld = "Hello world";
1592 
1593     OH_UdmfData *data = OH_UdmfData_Create();
1594     OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1595     int result = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1596     EXPECT_EQ(result, UDMF_ERR);
1597 
1598     OH_UdmfData *data2 = OH_UdmfData_Create();
1599     OH_UdsHtml *html = OH_UdsHtml_Create();
1600     OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1601     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1602     OH_UdmfRecord_AddHtml(record, html);
1603     OH_UdmfData_AddRecord(data2, record);
1604     int result2 = OH_UdmfData_GetPrimaryPlainText(data2, plainTextOutput);
1605     EXPECT_EQ(result2, UDMF_ERR);
1606 
1607     OH_UdmfData *data3 = OH_UdmfData_Create();
1608     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1609     OH_UdsPlainText_SetContent(plainText, helloWorld);
1610     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1611     OH_UdmfRecord_AddPlainText(record2, plainText);
1612     OH_UdmfData_AddRecord(data3, record);
1613     OH_UdmfData_AddRecord(data3, record2);
1614     int result3 = OH_UdmfData_GetPrimaryPlainText(data3, plainTextOutput);
1615     ASSERT_EQ(result3, UDMF_E_OK);
1616     auto *content = OH_UdsPlainText_GetContent(plainTextOutput);
1617     EXPECT_EQ(strcmp(content, helloWorld), 0);
1618 
1619     OH_UdsHtml_Destroy(html);
1620     OH_UdsPlainText_Destroy(plainTextOutput);
1621     OH_UdsPlainText_Destroy(plainText);
1622     OH_UdmfRecord_Destroy(record);
1623     OH_UdmfRecord_Destroy(record2);
1624     OH_UdmfData_Destroy(data);
1625     OH_UdmfData_Destroy(data2);
1626     OH_UdmfData_Destroy(data3);
1627 }
1628 
1629 /**
1630  * @tc.name: OH_UdmfData_GetPrimaryPlainText003
1631  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1632  * @tc.type: FUNC
1633  */
1634 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText003, TestSize.Level1)
1635 {
1636     const char *helloWorld = "Hello world";
1637     const char *helloWorld2 = "Hello world2";
1638 
1639     OH_UdsHtml *html = OH_UdsHtml_Create();
1640     OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1641     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1642     OH_UdmfRecord_AddHtml(record, html);
1643 
1644     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1645     OH_UdsPlainText_SetContent(plainText, helloWorld);
1646     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1647     OH_UdmfRecord_AddPlainText(record2, plainText);
1648 
1649 
1650     OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1651     OH_UdsPlainText_SetContent(plainText2, helloWorld2);
1652     OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1653     OH_UdmfRecord_AddPlainText(record3, plainText2);
1654 
1655     OH_UdmfData *data = OH_UdmfData_Create();
1656     OH_UdmfData_AddRecord(data, record3);
1657     OH_UdmfData_AddRecord(data, record2);
1658     OH_UdmfData_AddRecord(data, record);
1659     OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1660     int result4 = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1661     ASSERT_EQ(result4, UDMF_E_OK);
1662     auto *content2 = OH_UdsPlainText_GetContent(plainTextOutput);
1663     EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1664 
1665     OH_UdsHtml_Destroy(html);
1666     OH_UdsPlainText_Destroy(plainTextOutput);
1667     OH_UdsPlainText_Destroy(plainText);
1668     OH_UdsPlainText_Destroy(plainText2);
1669     OH_UdmfRecord_Destroy(record);
1670     OH_UdmfRecord_Destroy(record2);
1671     OH_UdmfRecord_Destroy(record3);
1672     OH_UdmfData_Destroy(data);
1673 }
1674 
1675 /**
1676  * @tc.name: OH_UdmfData_GetPrimaryHtml001
1677  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1678  * @tc.type: FUNC
1679  */
1680 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml001, TestSize.Level1)
1681 {
1682     int result1 = OH_UdmfData_GetPrimaryHtml(nullptr, nullptr);
1683     EXPECT_EQ(result1, UDMF_E_INVALID_PARAM);
1684 
1685     OH_UdmfData data;
1686     int result2 = OH_UdmfData_GetPrimaryHtml(&data, nullptr);
1687     EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1688 
1689     OH_UdmfData *data2 = OH_UdmfData_Create();
1690     int result3 = OH_UdmfData_GetPrimaryHtml(data2, nullptr);
1691     EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1692 
1693     OH_UdsHtml html;
1694     int result4 = OH_UdmfData_GetPrimaryHtml(data2, &html);
1695     EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1696 
1697     OH_UdsHtml *html2 = OH_UdsHtml_Create();
1698     int result5 = OH_UdmfData_GetPrimaryHtml(data2, html2);
1699     EXPECT_EQ(result5, UDMF_ERR);
1700 
1701     OH_UdsHtml_Destroy(html2);
1702     OH_UdmfData_Destroy(data2);
1703 }
1704 
1705 /**
1706  * @tc.name: OH_UdmfData_GetPrimaryHtml002
1707  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1708  * @tc.type: FUNC
1709  */
1710 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml002, TestSize.Level1)
1711 {
1712     const char *helloWorld = "<p>Hello world</p>";
1713 
1714     OH_UdmfData *data = OH_UdmfData_Create();
1715     OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1716     int result = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1717     EXPECT_EQ(result, UDMF_ERR);
1718 
1719     OH_UdmfData *data2 = OH_UdmfData_Create();
1720     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1721     OH_UdsPlainText_SetContent(plainText, "Hello world");
1722     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1723     OH_UdmfRecord_AddPlainText(record, plainText);
1724     OH_UdmfData_AddRecord(data2, record);
1725     int result2 = OH_UdmfData_GetPrimaryHtml(data2, htmlOutput);
1726     EXPECT_EQ(result2, UDMF_ERR);
1727 
1728     OH_UdmfData *data3 = OH_UdmfData_Create();
1729     OH_UdsHtml *html = OH_UdsHtml_Create();
1730     OH_UdsHtml_SetContent(html, helloWorld);
1731     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1732     OH_UdmfRecord_AddHtml(record2, html);
1733     OH_UdmfData_AddRecord(data3, record);
1734     OH_UdmfData_AddRecord(data3, record2);
1735     int result3 = OH_UdmfData_GetPrimaryHtml(data3, htmlOutput);
1736     ASSERT_EQ(result3, UDMF_E_OK);
1737     auto content = OH_UdsHtml_GetContent(htmlOutput);
1738     EXPECT_EQ(strcmp(content, helloWorld), 0);
1739 
1740     OH_UdsHtml_Destroy(html);
1741     OH_UdsHtml_Destroy(htmlOutput);
1742     OH_UdsPlainText_Destroy(plainText);
1743     OH_UdmfRecord_Destroy(record);
1744     OH_UdmfRecord_Destroy(record2);
1745     OH_UdmfData_Destroy(data);
1746     OH_UdmfData_Destroy(data2);
1747     OH_UdmfData_Destroy(data3);
1748 }
1749 
1750 /**
1751  * @tc.name: OH_UdmfData_GetPrimaryHtml003
1752  * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1753  * @tc.type: FUNC
1754  */
1755 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml003, TestSize.Level1)
1756 {
1757     const char *helloWorld = "<p>Hello world</p>";
1758     const char *helloWorld2 = "<p>Hello world2</p>";
1759 
1760     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1761     OH_UdsPlainText_SetContent(plainText, "Hello world");
1762     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1763     OH_UdmfRecord_AddPlainText(record, plainText);
1764 
1765     OH_UdsHtml *html = OH_UdsHtml_Create();
1766     OH_UdsHtml_SetContent(html, helloWorld);
1767     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1768     OH_UdmfRecord_AddHtml(record2, html);
1769 
1770     OH_UdsHtml *html2 = OH_UdsHtml_Create();
1771     OH_UdsHtml_SetContent(html2, helloWorld2);
1772     OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1773     OH_UdmfRecord_AddHtml(record3, html2);
1774 
1775     OH_UdmfData *data = OH_UdmfData_Create();
1776     OH_UdmfData_AddRecord(data, record3);
1777     OH_UdmfData_AddRecord(data, record2);
1778     OH_UdmfData_AddRecord(data, record);
1779     OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1780     int result4 = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1781     ASSERT_EQ(result4, UDMF_E_OK);
1782     auto content2 = OH_UdsHtml_GetContent(htmlOutput);
1783     EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1784 
1785     OH_UdsHtml_Destroy(html);
1786     OH_UdsHtml_Destroy(html2);
1787     OH_UdsHtml_Destroy(htmlOutput);
1788     OH_UdsPlainText_Destroy(plainText);
1789     OH_UdmfRecord_Destroy(record);
1790     OH_UdmfRecord_Destroy(record2);
1791     OH_UdmfRecord_Destroy(record3);
1792     OH_UdmfData_Destroy(data);
1793 }
1794 
1795 /**
1796  * @tc.name: OH_UdmfData_GetRecordCount001
1797  * @tc.desc: Normal testcase of OH_UdmfData_GetRecordCount
1798  * @tc.type: FUNC
1799  */
1800 HWTEST_F(UDMFTest, OH_UdmfData_GetRecordCount001, TestSize.Level1)
1801 {
1802     int result = OH_UdmfData_GetRecordCount(nullptr);
1803     EXPECT_EQ(result, 0);
1804 
1805     OH_UdmfData data;
1806     int result2 = OH_UdmfData_GetRecordCount(&data);
1807     EXPECT_EQ(result2, 0);
1808 
1809     OH_UdmfData *data2 = OH_UdmfData_Create();
1810     int result3 = OH_UdmfData_GetRecordCount(data2);
1811     EXPECT_EQ(result3, 0);
1812 
1813     OH_UdmfData *data3 = OH_UdmfData_Create();
1814     OH_UdmfRecord *record = OH_UdmfRecord_Create();
1815     OH_UdmfData_AddRecord(data3, record);
1816     int result4 = OH_UdmfData_GetRecordCount(data3);
1817     EXPECT_EQ(result4, 1);
1818 
1819     OH_UdmfData *data4 = OH_UdmfData_Create();
1820     OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1821     OH_UdmfData_AddRecord(data4, record);
1822     OH_UdmfData_AddRecord(data4, record2);
1823     int result5 = OH_UdmfData_GetRecordCount(data4);
1824     EXPECT_EQ(result5, 2);
1825 
1826     OH_UdmfRecord_Destroy(record);
1827     OH_UdmfRecord_Destroy(record2);
1828     OH_UdmfData_Destroy(data2);
1829     OH_UdmfData_Destroy(data3);
1830     OH_UdmfData_Destroy(data4);
1831 }
1832 
1833 /**
1834  * @tc.name: OH_UdmfData_GetRecord001
1835  * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1836  * @tc.type: FUNC
1837  */
1838 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord001, TestSize.Level1)
1839 {
1840     OH_UdmfRecord *result = OH_UdmfData_GetRecord(nullptr, -1);
1841     EXPECT_EQ(result, nullptr);
1842 
1843     OH_UdmfData data;
1844     OH_UdmfRecord *result2 = OH_UdmfData_GetRecord(&data, -1);
1845     EXPECT_EQ(result2, nullptr);
1846 
1847     OH_UdmfRecord *result3 = OH_UdmfData_GetRecord(&data, 0);
1848     EXPECT_EQ(result3, nullptr);
1849 
1850     OH_UdmfData *data2 = OH_UdmfData_Create();
1851     OH_UdmfRecord *result4 = OH_UdmfData_GetRecord(data2, -1);
1852     EXPECT_EQ(result4, nullptr);
1853 
1854     OH_UdmfRecord *result5 = OH_UdmfData_GetRecord(data2, 0);
1855     EXPECT_EQ(result5, nullptr);
1856 
1857     OH_UdmfRecord *result6 = OH_UdmfData_GetRecord(data2, 1);
1858     EXPECT_EQ(result6, nullptr);
1859 
1860     OH_UdmfData *data3 = OH_UdmfData_Create();
1861     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1862     OH_UdmfData_AddRecord(data3, record);
1863     EXPECT_EQ(OH_UdmfData_GetRecordCount(data3), 1);
1864     OH_UdmfRecord *result7 = OH_UdmfData_GetRecord(data3, -1);
1865     EXPECT_EQ(result7, nullptr);
1866     OH_UdmfRecord *result8 = OH_UdmfData_GetRecord(data3, 1);
1867     EXPECT_EQ(result8, nullptr);
1868     OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1869     EXPECT_NE(result9, nullptr);
1870 
1871     OH_UdmfRecord_Destroy(record);
1872     OH_UdmfData_Destroy(data2);
1873     OH_UdmfData_Destroy(data3);
1874 }
1875 
1876 /**
1877  * @tc.name: OH_UdmfData_GetRecord002
1878  * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1879  * @tc.type: FUNC
1880  */
1881 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord002, TestSize.Level1)
1882 {
1883     const char *helloWorld = "Hello world";
1884     const char *helloWorld2 = "Hello world2";
1885 
1886     OH_UdmfData *data3 = OH_UdmfData_Create();
1887     OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1888     OH_UdsPlainText_SetContent(plainText, helloWorld);
1889     OH_UdmfRecord* record = OH_UdmfRecord_Create();
1890     OH_UdmfRecord_AddPlainText(record, plainText);
1891     OH_UdmfData_AddRecord(data3, record);
1892     OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1893     EXPECT_NE(result9, nullptr);
1894     OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1895     OH_UdmfRecord_GetPlainText(result9, plainText2);
1896     auto content = OH_UdsPlainText_GetContent(plainText2);
1897     EXPECT_EQ(strcmp(content, helloWorld), 0);
1898 
1899     OH_UdmfData *data4 = OH_UdmfData_Create();
1900     OH_UdsPlainText *plainText3 = OH_UdsPlainText_Create();
1901     OH_UdsPlainText_SetContent(plainText3, helloWorld2);
1902     OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1903     OH_UdmfRecord_AddPlainText(record2, plainText3);
1904     OH_UdmfData_AddRecord(data4, record);
1905     OH_UdmfData_AddRecord(data4, record2);
1906     OH_UdmfRecord *result10 = OH_UdmfData_GetRecord(data4, -1);
1907     EXPECT_EQ(result10, nullptr);
1908     OH_UdmfRecord *result11 = OH_UdmfData_GetRecord(data4, 2);
1909     EXPECT_EQ(result11, nullptr);
1910     OH_UdmfRecord *result12 = OH_UdmfData_GetRecord(data4, 0);
1911     ASSERT_NE(result12, nullptr);
1912     OH_UdsPlainText *plainText4 = OH_UdsPlainText_Create();
1913     OH_UdmfRecord_GetPlainText(result12, plainText4);
1914     auto content2 = OH_UdsPlainText_GetContent(plainText4);
1915     EXPECT_EQ(strcmp(content2, helloWorld), 0);
1916     OH_UdmfRecord *result13 = OH_UdmfData_GetRecord(data4, 1);
1917     ASSERT_NE(result13, nullptr);
1918     OH_UdsPlainText *plainText5 = OH_UdsPlainText_Create();
1919     OH_UdmfRecord_GetPlainText(result13, plainText5);
1920     auto content3 = OH_UdsPlainText_GetContent(plainText5);
1921     EXPECT_EQ(strcmp(content3, helloWorld2), 0);
1922 
1923     OH_UdsPlainText_Destroy(plainText);
1924     OH_UdsPlainText_Destroy(plainText2);
1925     OH_UdmfRecord_Destroy(record);
1926     OH_UdmfRecord_Destroy(record2);
1927     OH_UdmfData_Destroy(data3);
1928     OH_UdmfData_Destroy(data4);
1929 }
1930 
1931 /**
1932  * @tc.name: OH_UdmfData_IsLocal001
1933  * @tc.desc: Normal testcase of OH_UdmfData_IsLocal
1934  * @tc.type: FUNC
1935  */
1936 HWTEST_F(UDMFTest, OH_UdmfData_IsLocal001, TestSize.Level1)
1937 {
1938     bool result = OH_UdmfData_IsLocal(nullptr);
1939     EXPECT_EQ(result, true);
1940 
1941     OH_UdmfData data;
1942     bool result2 = OH_UdmfData_IsLocal(&data);
1943     EXPECT_EQ(result2, true);
1944 
1945     OH_UdmfData *data2 = OH_UdmfData_Create();
1946     bool result3 = OH_UdmfData_IsLocal(data2);
1947     EXPECT_EQ(result3, true);
1948 
1949     OH_UdmfData_Destroy(data2);
1950 }
1951 
1952 /**
1953  * @tc.name: FileUriTest001
1954  * @tc.desc: test fileUri between js and capi
1955  * @tc.type: FUNC
1956  */
1957 HWTEST_F(UDMFTest, FileUriTest001, TestSize.Level1)
1958 {
1959     std::string uri = "https://xxx/xx/xx.jpg";
1960     std::shared_ptr<Image> image = std::make_shared<Image>();
1961     image->SetUri(uri);
1962     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
1963     unifiedData->AddRecord(image);
1964     std::string key;
1965     CustomOption option = {
1966         .intention = UD_INTENTION_DRAG
1967     };
1968     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
1969     EXPECT_EQ(setRet, E_OK);
1970 
1971     OH_UdmfData* udmfData = OH_UdmfData_Create();
1972     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
1973 
1974     unsigned int dataTypeCount;
1975     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
1976     EXPECT_EQ(dataTypeCount, 2);
1977     EXPECT_NE(dataTypes, nullptr);
1978     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
1979     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1980 
1981     unsigned int recordCount;
1982     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
1983     EXPECT_EQ(recordCount, 1);
1984     EXPECT_NE(records, nullptr);
1985 
1986     for (unsigned int idx = 0; idx < recordCount; ++idx) {
1987         unsigned int recordTypeCount;
1988         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
1989         EXPECT_EQ(recordTypeCount, 1);
1990         EXPECT_NE(recordTypes, nullptr);
1991         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
1992         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
1993             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
1994                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
1995                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
1996                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
1997                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
1998                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
1999             }
2000         }
2001     }
2002 }
2003 
2004 /**
2005  * @tc.name: FileUriTest002
2006  * @tc.desc: test fileUri between js and capi
2007  * @tc.type: FUNC
2008  */
2009 HWTEST_F(UDMFTest, FileUriTest002, TestSize.Level1)
2010 {
2011     std::string uri = "https://xxx/xx/xx.jpg";
2012     std::string content = "content";
2013     std::shared_ptr<Image> image = std::make_shared<Image>();
2014     image->SetUri(uri);
2015     std::shared_ptr<PlainText> plaintext = std::make_shared<PlainText>();
2016     plaintext->SetContent(content);
2017     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2018     unifiedData->AddRecord(image);
2019     unifiedData->AddRecord(plaintext);
2020     std::string key;
2021     CustomOption option = {
2022         .intention = UD_INTENTION_DRAG
2023     };
2024     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2025     EXPECT_EQ(setRet, E_OK);
2026 
2027     OH_UdmfData* udmfData = OH_UdmfData_Create();
2028     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2029 
2030     unsigned int dataTypeCount;
2031     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2032     EXPECT_EQ(dataTypeCount, 3);
2033     EXPECT_NE(dataTypes, nullptr);
2034     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
2035     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_PLAIN_TEXT), 0);
2036     EXPECT_EQ(strcmp(dataTypes[2], UDMF_META_GENERAL_FILE_URI), 0);
2037 
2038     unsigned int recordCount;
2039     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2040     EXPECT_EQ(recordCount, 2);
2041     EXPECT_NE(records, nullptr);
2042 
2043     unsigned int recordTypeCount;
2044     char** recordTypes = OH_UdmfRecord_GetTypes(records[0], &recordTypeCount);
2045     EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2046     EXPECT_EQ(recordTypeCount, 1);
2047     OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2048     int getFileUriRet = OH_UdmfRecord_GetFileUri(records[0], fileUri);
2049     EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2050     const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2051     EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2052 
2053     recordTypes = OH_UdmfRecord_GetTypes(records[1], &recordTypeCount);
2054     EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_PLAIN_TEXT), 0);
2055     EXPECT_EQ(recordTypeCount, 1);
2056     OH_UdsPlainText* text = OH_UdsPlainText_Create();
2057     int getPlaintextRet = OH_UdmfRecord_GetPlainText(records[1], text);
2058     EXPECT_EQ(getPlaintextRet, UDMF_E_OK);
2059     const char* getContent = OH_UdsPlainText_GetContent(text);
2060     EXPECT_EQ(strcmp(getContent, content.c_str()), 0);
2061 }
2062 
2063 /**
2064  * @tc.name: FileUriTest003
2065  * @tc.desc: test fileUri between js and capi
2066  * @tc.type: FUNC
2067  */
2068 HWTEST_F(UDMFTest, FileUriTest003, TestSize.Level1)
2069 {
2070     std::string uri = "https://xxx/xx/xx.jpg";
2071     std::shared_ptr<Audio> audio = std::make_shared<Audio>();
2072     audio->SetUri(uri);
2073     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2074     unifiedData->AddRecord(audio);
2075     std::string key;
2076     CustomOption option = {
2077         .intention = UD_INTENTION_DRAG
2078     };
2079     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2080     EXPECT_EQ(setRet, E_OK);
2081 
2082     OH_UdmfData* udmfData = OH_UdmfData_Create();
2083     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2084 
2085     unsigned int dataTypeCount;
2086     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2087     EXPECT_EQ(dataTypeCount, 2);
2088     EXPECT_NE(dataTypes, nullptr);
2089     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_AUDIO), 0);
2090     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2091 
2092     unsigned int recordCount;
2093     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2094     EXPECT_EQ(recordCount, 1);
2095     EXPECT_NE(records, nullptr);
2096 
2097     for (unsigned int idx = 0; idx < recordCount; ++idx) {
2098         unsigned int recordTypeCount;
2099         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2100         EXPECT_EQ(recordTypeCount, 1);
2101         EXPECT_NE(recordTypes, nullptr);
2102         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2103         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2104             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2105                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2106                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2107                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2108                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2109                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2110             }
2111         }
2112     }
2113 }
2114 
2115 /**
2116  * @tc.name: FileUriTest004
2117  * @tc.desc: test fileUri between js and capi
2118  * @tc.type: FUNC
2119  */
2120 HWTEST_F(UDMFTest, FileUriTest004, TestSize.Level1)
2121 {
2122     std::string uri = "https://xxx/xx/xx.jpg";
2123     std::shared_ptr<File> file = std::make_shared<File>();
2124     file->SetUri(uri);
2125     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2126     unifiedData->AddRecord(file);
2127     std::string key;
2128     CustomOption option = {
2129         .intention = UD_INTENTION_DRAG
2130     };
2131     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2132     EXPECT_EQ(setRet, E_OK);
2133 
2134     OH_UdmfData* udmfData = OH_UdmfData_Create();
2135     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2136 
2137     unsigned int dataTypeCount;
2138     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2139     EXPECT_EQ(dataTypeCount, 2);
2140     EXPECT_NE(dataTypes, nullptr);
2141     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_GENERAL_FILE), 0);
2142     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2143 
2144     unsigned int recordCount;
2145     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2146     EXPECT_EQ(recordCount, 1);
2147     EXPECT_NE(records, nullptr);
2148 
2149     for (unsigned int idx = 0; idx < recordCount; ++idx) {
2150         unsigned int recordTypeCount;
2151         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2152         EXPECT_EQ(recordTypeCount, 1);
2153         EXPECT_NE(recordTypes, nullptr);
2154         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2155         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2156             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2157                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2158                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2159                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2160                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2161                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2162             }
2163         }
2164     }
2165 }
2166 
2167 /**
2168  * @tc.name: FileUriTest005
2169  * @tc.desc: test fileUri between js and capi
2170  * @tc.type: FUNC
2171  */
2172 HWTEST_F(UDMFTest, FileUriTest005, TestSize.Level1)
2173 {
2174     std::string uri = "https://xxx/xx/xx.jpg";
2175     std::shared_ptr<Object> obj = std::make_shared<Object>();
2176     obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2177     obj->value_[FILE_URI_PARAM] = uri;
2178     obj->value_[FILE_TYPE] = "general.img";
2179     auto record = std::make_shared<UnifiedRecord>(UDType::FOLDER, obj);
2180     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2181     unifiedData->AddRecord(record);
2182     std::string key;
2183     CustomOption option = {
2184         .intention = UD_INTENTION_DRAG
2185     };
2186     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2187     EXPECT_EQ(setRet, E_OK);
2188 
2189     OH_UdmfData* udmfData = OH_UdmfData_Create();
2190     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2191 
2192     unsigned int dataTypeCount;
2193     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2194     EXPECT_EQ(dataTypeCount, 2);
2195     EXPECT_NE(dataTypes, nullptr);
2196     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_FOLDER), 0);
2197     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2198 
2199     unsigned int recordCount;
2200     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2201     EXPECT_EQ(recordCount, 1);
2202     EXPECT_NE(records, nullptr);
2203 
2204     for (unsigned int idx = 0; idx < recordCount; ++idx) {
2205         unsigned int recordTypeCount;
2206         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2207         EXPECT_EQ(recordTypeCount, 2);
2208         EXPECT_NE(recordTypes, nullptr);
2209         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_FOLDER), 0);
2210         EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2211         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2212             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2213                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2214                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2215                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2216                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2217                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2218             }
2219         }
2220     }
2221 }
2222 
2223 /**
2224  * @tc.name: FileUriTest006
2225  * @tc.desc: test fileUri between js and capi
2226  * @tc.type: FUNC
2227  */
2228 HWTEST_F(UDMFTest, FileUriTest006, TestSize.Level1)
2229 {
2230     std::string uri = "https://xxx/xx/xx.jpg";
2231     std::shared_ptr<Video> video = std::make_shared<Video>();
2232     video->SetUri(uri);
2233     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2234     unifiedData->AddRecord(video);
2235     std::string key;
2236     CustomOption option = {
2237         .intention = UD_INTENTION_DRAG
2238     };
2239     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2240     EXPECT_EQ(setRet, E_OK);
2241 
2242     OH_UdmfData* udmfData = OH_UdmfData_Create();
2243     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2244 
2245     unsigned int dataTypeCount;
2246     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2247     EXPECT_EQ(dataTypeCount, 2);
2248     EXPECT_NE(dataTypes, nullptr);
2249     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2250     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2251 
2252     unsigned int recordCount;
2253     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2254     EXPECT_EQ(recordCount, 1);
2255     EXPECT_NE(records, nullptr);
2256 
2257     for (unsigned int idx = 0; idx < recordCount; ++idx) {
2258         unsigned int recordTypeCount;
2259         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2260         EXPECT_EQ(recordTypeCount, 1);
2261         EXPECT_NE(recordTypes, nullptr);
2262         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2263         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2264             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2265                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2266                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2267                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2268                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2269                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2270             }
2271         }
2272     }
2273 }
2274 
2275 /**
2276  * @tc.name: FileUriTest007
2277  * @tc.desc: test fileUri between js and capi
2278  * @tc.type: FUNC
2279  */
2280 HWTEST_F(UDMFTest, FileUriTest007, TestSize.Level1)
2281 {
2282     std::string uri = "https://xxx/xx/xx.jpg";
2283 
2284     std::shared_ptr<Object> obj = std::make_shared<Object>();
2285     obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2286     obj->value_[FILE_URI_PARAM] = uri;
2287     obj->value_[FILE_TYPE] = "general.img";
2288     auto record = std::make_shared<UnifiedRecord>(UDType::VIDEO, obj);
2289     std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2290     unifiedData->AddRecord(record);
2291     std::string key;
2292     CustomOption option = {
2293         .intention = UD_INTENTION_DRAG
2294     };
2295     int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2296     EXPECT_EQ(setRet, E_OK);
2297 
2298     OH_UdmfData* udmfData = OH_UdmfData_Create();
2299     OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2300 
2301     unsigned int dataTypeCount;
2302     char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2303     EXPECT_EQ(dataTypeCount, 2);
2304     EXPECT_NE(dataTypes, nullptr);
2305     EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2306     EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2307 
2308     unsigned int recordCount;
2309     OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2310     EXPECT_EQ(recordCount, 1);
2311     EXPECT_NE(records, nullptr);
2312 
2313     for (unsigned int idx = 0; idx < recordCount; ++idx) {
2314         unsigned int recordTypeCount;
2315         char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2316         EXPECT_EQ(recordTypeCount, 2);
2317         EXPECT_NE(recordTypes, nullptr);
2318         EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_VIDEO), 0);
2319         EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2320         for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2321             if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2322                 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2323                 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2324                 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2325                 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2326                 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2327             }
2328         }
2329     }
2330 }
2331 
2332 /**
2333  * @tc.name: OH_Udmf_SetAndGetUnifiedData003
2334  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2335  * @tc.type: FUNC
2336  * @tc.require: AROOOH5R5G
2337  */
2338 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData003, TestSize.Level1)
2339 {
2340     std::string uri = "https://xxx/xx/xx.jpg";
2341     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2342     OH_UdmfRecord *record = OH_UdmfRecord_Create();
2343     OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2344     OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2345     OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
2346     OH_UdmfRecord_AddFileUri(record, fileUri);
2347     OH_UdmfData_AddRecord(udmfUnifiedData, record);
2348     Udmf_Intention intention = UDMF_INTENTION_DRAG;
2349     char key[UDMF_KEY_BUFFER_LEN];
2350 
2351     int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2352     EXPECT_EQ(setRes, UDMF_E_OK);
2353     EXPECT_NE(key[0], '\0');
2354     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2355     int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2356     EXPECT_EQ(getRes, UDMF_E_OK);
2357     unsigned int count = 0;
2358     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2359     EXPECT_EQ(count, 1);
2360     OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2361     OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2362     const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2363     EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2364 
2365     OH_UdsFileUri_Destroy(fileUri);
2366     OH_UdmfRecord_Destroy(record);
2367     OH_UdmfData_Destroy(udmfUnifiedData);
2368 
2369     OH_UdsFileUri_Destroy(getFileUri);
2370     OH_UdmfData_Destroy(readUnifiedData);
2371 }
2372 
2373 /**
2374  * @tc.name: OH_Udmf_SetAndGetUnifiedData004
2375  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2376  * @tc.type: FUNC
2377  * @tc.require: AROOOH5R5G
2378  */
2379 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData004, TestSize.Level1)
2380 {
2381     std::string uri = "https://xxx/xx/xx.jpg";
2382     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2383     OH_UdmfRecord *record = OH_UdmfRecord_Create();
2384     OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2385     OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2386     OH_UdmfRecord_AddFileUri(record, fileUri);
2387     OH_UdmfData_AddRecord(udmfUnifiedData, record);
2388     Udmf_Intention intention = UDMF_INTENTION_DRAG;
2389     char key[UDMF_KEY_BUFFER_LEN];
2390 
2391     int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2392     EXPECT_EQ(setRes, UDMF_E_OK);
2393     EXPECT_NE(key[0], '\0');
2394     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2395     int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2396     EXPECT_EQ(getRes, UDMF_E_OK);
2397     unsigned int count = 0;
2398     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2399     EXPECT_EQ(count, 1);
2400     OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2401     OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2402     const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2403     EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2404 
2405     OH_UdsFileUri_Destroy(fileUri);
2406     OH_UdmfRecord_Destroy(record);
2407     OH_UdmfData_Destroy(udmfUnifiedData);
2408 
2409     OH_UdsFileUri_Destroy(getFileUri);
2410     OH_UdmfData_Destroy(readUnifiedData);
2411 }
2412 
2413 /**
2414  * @tc.name: OH_Udmf_SetAndGetUnifiedData005
2415  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2416  * @tc.type: FUNC
2417  * @tc.require: AROOOH5R5G
2418  */
2419 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData005, TestSize.Level1)
2420 {
2421     std::string uri = "https://xxx/xx/xx.jpg";
2422     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2423     OH_UdmfRecord *record = OH_UdmfRecord_Create();
2424     OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2425     OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2426     OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2427     OH_UdmfRecord_AddFileUri(record, fileUri);
2428     OH_UdmfData_AddRecord(udmfUnifiedData, record);
2429     Udmf_Intention intention = UDMF_INTENTION_DRAG;
2430     char key[UDMF_KEY_BUFFER_LEN];
2431 
2432     int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2433     EXPECT_EQ(setRes, UDMF_E_OK);
2434     EXPECT_NE(key[0], '\0');
2435     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2436     int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2437     EXPECT_EQ(getRes, UDMF_E_OK);
2438     unsigned int count = 0;
2439     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2440     EXPECT_EQ(count, 1);
2441     OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2442     OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2443     const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2444     EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2445 
2446     OH_UdsFileUri_Destroy(fileUri);
2447     OH_UdmfRecord_Destroy(record);
2448     OH_UdmfData_Destroy(udmfUnifiedData);
2449 
2450     OH_UdsFileUri_Destroy(getFileUri);
2451     OH_UdmfData_Destroy(readUnifiedData);
2452 }
2453 
2454 /**
2455  * @tc.name: OH_Udmf_SetAndGetUnifiedData006
2456  * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2457  * @tc.type: FUNC
2458  */
2459 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData006, TestSize.Level1)
2460 {
2461     OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2462     OH_UdmfRecord *record = OH_UdmfRecord_Create();
2463     OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
2464     unsigned char thumbData[] = {0, 1, 2, 3, 4};
2465     OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
2466     OH_UdsContentForm_SetDescription(contentForm, "description");
2467     OH_UdmfRecord_AddContentForm(record, contentForm);
2468     OH_UdmfData_AddRecord(udmfUnifiedData, record);
2469     Udmf_Intention intention = UDMF_INTENTION_DRAG;
2470     char key[UDMF_KEY_BUFFER_LEN];
2471 
2472     int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2473     EXPECT_EQ(setRes, UDMF_E_OK);
2474     EXPECT_NE(key[0], '\0');
2475     OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2476     int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2477     EXPECT_EQ(getRes, UDMF_E_OK);
2478     unsigned int count = 0;
2479     OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2480     EXPECT_EQ(count, 1);
2481     OH_UdsContentForm *getContentForm = OH_UdsContentForm_Create();
2482     OH_UdmfRecord_GetContentForm(getRecords[0], getContentForm);
2483     EXPECT_EQ("description", std::string(OH_UdsContentForm_GetDescription(getContentForm)));
2484 
2485     unsigned char *readThumbData;
2486     unsigned int thumbDataLen = 0;
2487     OH_UdsContentForm_GetThumbData(getContentForm, &readThumbData, &thumbDataLen);
2488     ASSERT_EQ(5, thumbDataLen);
2489     ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
2490 
2491     OH_UdsContentForm_Destroy(contentForm);
2492     OH_UdmfRecord_Destroy(record);
2493     OH_UdmfData_Destroy(udmfUnifiedData);
2494 
2495     OH_UdsContentForm_Destroy(getContentForm);
2496     OH_UdmfData_Destroy(readUnifiedData);
2497 }
2498 }
2499