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
41using namespace testing::ext;
42using namespace OHOS::Security::AccessToken;
43using namespace OHOS::UDMF;
44
45namespace OHOS::Test {
46class UDMFTest : public testing::Test {
47public:
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
62void UDMFTest::SetUpTestCase()
63{
64    AllocHapToken1();
65    AllocHapToken2();
66}
67
68void 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
76void UDMFTest::SetUp()
77{
78    SetHapToken1();
79}
80
81void UDMFTest::TearDown()
82{
83}
84
85void 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
123void 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
161void UDMFTest::SetHapToken1()
162{
163    auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
164    SetSelfTokenID(tokenId);
165}
166
167bool 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
179void UDMFTest::FinalizeFunc(void* context) {}
180
181void* 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 */
195HWTEST_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 */
209HWTEST_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 */
237HWTEST_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 */
254HWTEST_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 */
281HWTEST_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 */
308HWTEST_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 */
332HWTEST_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 */
364HWTEST_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 */
387HWTEST_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 */
412HWTEST_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 */
436HWTEST_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 */
471HWTEST_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 */
502HWTEST_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 */
528HWTEST_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 */
568HWTEST_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 */
604HWTEST_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 */
618HWTEST_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 */
644HWTEST_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 */
669HWTEST_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 */
685HWTEST_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 */
709HWTEST_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 */
746HWTEST_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 */
772HWTEST_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 */
798HWTEST_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 */
825HWTEST_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 */
851HWTEST_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 */
877HWTEST_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 */
904HWTEST_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 */
930HWTEST_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 */
956HWTEST_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 */
983HWTEST_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 */
1009HWTEST_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 */
1035HWTEST_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 */
1061HWTEST_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 */
1077HWTEST_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 */
1094HWTEST_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 */
1110HWTEST_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 */
1126HWTEST_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 */
1137HWTEST_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 */
1153HWTEST_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 */
1171HWTEST_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_UdmfRecordProvider_Create001
1253 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Create
1254 * @tc.type: FUNC
1255 */
1256HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Create001, TestSize.Level1)
1257{
1258    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1259    EXPECT_NE(provider, nullptr);
1260    OH_UdmfRecordProvider_Destroy(provider);
1261}
1262
1263/**
1264 * @tc.name: OH_UdmfRecordProvider_Destroy001
1265 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Destroy
1266 * @tc.type: FUNC
1267 */
1268HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy001, TestSize.Level1)
1269{
1270    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1271    EXPECT_NE(provider, nullptr);
1272    int num = 1;
1273    void* context = &num;
1274    OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1275    int res1 = OH_UdmfRecordProvider_Destroy(provider);
1276    EXPECT_EQ(res1, UDMF_E_OK);
1277}
1278
1279/**
1280 * @tc.name: OH_UdmfRecordProvider_Destroy002
1281 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_Destroy
1282 * @tc.type: FUNC
1283 */
1284HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy002, TestSize.Level1)
1285{
1286    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1287    EXPECT_NE(provider, nullptr);
1288    int num = 1;
1289    void* context = &num;
1290    OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1291    int res1 = OH_UdmfRecordProvider_Destroy(provider);
1292    EXPECT_EQ(res1, UDMF_E_OK);
1293}
1294
1295/**
1296 * @tc.name: OH_UdmfRecordProvider_SetData001
1297 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_SetData
1298 * @tc.type: FUNC
1299 */
1300HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData001, TestSize.Level1)
1301{
1302    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1303    EXPECT_NE(provider, nullptr);
1304    int num = 1;
1305    void* context = &num;
1306    int res = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1307    EXPECT_NE(provider->context, nullptr);
1308    EXPECT_NE(provider->callback, nullptr);
1309    EXPECT_NE(provider->finalize, nullptr);
1310    EXPECT_EQ(res, UDMF_E_OK);
1311    OH_UdmfRecordProvider_Destroy(provider);
1312}
1313
1314/**
1315 * @tc.name: OH_UdmfRecordProvider_SetData002
1316 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_SetData
1317 * @tc.type: FUNC
1318 */
1319HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData002, TestSize.Level1)
1320{
1321    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1322    EXPECT_NE(provider, nullptr);
1323    int num = 1;
1324    void* context = &num;
1325    int res1 = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1326    EXPECT_EQ(provider->context, nullptr);
1327    EXPECT_EQ(provider->finalize, nullptr);
1328    EXPECT_EQ(res1, UDMF_E_INVALID_PARAM);
1329
1330    int res2 = OH_UdmfRecordProvider_SetData(nullptr, context, GetDataCallbackFunc, nullptr);
1331    EXPECT_EQ(res2, UDMF_E_INVALID_PARAM);
1332
1333    int res3 = OH_UdmfRecordProvider_SetData(provider, context, nullptr, nullptr);
1334    EXPECT_EQ(res3, UDMF_E_INVALID_PARAM);
1335    OH_UdmfRecordProvider_Destroy(provider);
1336}
1337
1338/**
1339 * @tc.name: OH_UdmfRecord_SetProvider001
1340 * @tc.desc: Normal testcase of OH_UdmfRecord_SetProvider
1341 * @tc.type: FUNC
1342 */
1343HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider001, TestSize.Level1)
1344{
1345    OH_UdmfRecord *record = OH_UdmfRecord_Create();
1346    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1347    char content[] = "hello world";
1348    OH_UdsPlainText_SetContent(plainText, content);
1349    OH_UdmfRecord_AddPlainText(record, plainText);
1350    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1351    EXPECT_NE(provider, nullptr);
1352    int num = 1;
1353    void* context = &num;
1354    OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1355    const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1356
1357    int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1358    EXPECT_EQ(res, UDMF_E_OK);
1359    OH_UdmfRecordProvider_Destroy(provider);
1360}
1361
1362/**
1363 * @tc.name: OH_UdmfRecord_SetProvider002
1364 * @tc.desc: invalid parameters testcase of OH_UdmfRecord_SetProvider
1365 * @tc.type: FUNC
1366 */
1367HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider002, TestSize.Level1)
1368{
1369    OH_UdmfRecord *record = OH_UdmfRecord_Create();
1370    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1371    char content[] = "hello world";
1372    OH_UdsPlainText_SetContent(plainText, content);
1373    OH_UdmfRecord_AddPlainText(record, plainText);
1374    OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1375    EXPECT_NE(provider, nullptr);
1376    int num = 1;
1377    void* context = &num;
1378    OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1379    const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1380
1381    int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1382    EXPECT_EQ(res, UDMF_E_OK);
1383    OH_UdmfRecordProvider_Destroy(provider);
1384}
1385
1386/**
1387 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001
1388 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1389 * @tc.type: FUNC
1390 */
1391HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001, TestSize.Level0)
1392{
1393    int buildRes1 = OH_UdmfRecord_AddArrayBuffer(nullptr, nullptr, nullptr);
1394    EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1395
1396    OH_UdmfRecord record1;
1397    int buildRes2 = OH_UdmfRecord_AddArrayBuffer(&record1, nullptr, nullptr);
1398    EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1399
1400    OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1401    int buildRes3 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, nullptr);
1402    EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1403
1404    OH_UdsArrayBuffer buffer;
1405    int buildRes4 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, &buffer);
1406    EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1407
1408    OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1409    int buildRes5 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, buffer2);
1410    EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1411
1412    char type[] = "general.plain-text";
1413    int buildRes6 = OH_UdmfRecord_AddArrayBuffer(record2, type, buffer2);
1414    EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1415
1416    char type2[] = "ApplicationDefined-myType1";
1417    int buildRes7 = OH_UdmfRecord_AddArrayBuffer(record2, type2, buffer2);
1418    EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1419
1420    OH_UdmfRecord_Destroy(record2);
1421    OH_UdsArrayBuffer_Destroy(buffer2);
1422}
1423
1424/**
1425 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002
1426 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1427 * @tc.type: FUNC
1428 */
1429HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002, TestSize.Level0)
1430{
1431    int buildRes1 = OH_UdmfRecord_GetArrayBuffer(nullptr, nullptr, nullptr);
1432    EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1433
1434    OH_UdmfRecord record1;
1435    int buildRes2 = OH_UdmfRecord_GetArrayBuffer(&record1, nullptr, nullptr);
1436    EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1437
1438    OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1439    int buildRes3 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, nullptr);
1440    EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1441
1442    OH_UdsArrayBuffer buffer;
1443    int buildRes4 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, &buffer);
1444    EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1445
1446    OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1447    int buildRes5 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, buffer2);
1448    EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1449
1450    char type[] = "general.plain-text";
1451    int buildRes6 = OH_UdmfRecord_GetArrayBuffer(record2, type, buffer2);
1452    EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1453
1454    char type2[] = "ApplicationDefined-myType1";
1455    int buildRes7 = OH_UdmfRecord_GetArrayBuffer(record2, type2, buffer2);
1456    EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1457
1458    OH_UdmfRecord_Destroy(record2);
1459    OH_UdsArrayBuffer_Destroy(buffer2);
1460}
1461
1462/**
1463 * @tc.name: OH_Udmf_GetArrayBufferFromRecord001
1464 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1465 * @tc.type: FUNC
1466 */
1467HWTEST_F(UDMFTest, OH_Udmf_GetArrayBufferFromRecord001, TestSize.Level0)
1468{
1469    unsigned char data1[] = "Hello world";
1470    unsigned int len1 = sizeof(data1);
1471    OH_UdsArrayBuffer *buffer1 = OH_UdsArrayBuffer_Create();
1472    OH_UdsArrayBuffer_SetData(buffer1, data1, len1);
1473
1474    char type1[] = "ApplicationDefined-myType1";
1475    OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1476    int buildRes = OH_UdmfRecord_AddArrayBuffer(record1, type1, buffer1);
1477    ASSERT_EQ(buildRes, UDMF_E_OK);
1478
1479    char type2[] = "ApplicationDefined-myType2";
1480    OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1481    int getRes = OH_UdmfRecord_GetArrayBuffer(record1, type2, buffer2);
1482    EXPECT_EQ(getRes, UDMF_E_INVALID_PARAM);
1483
1484    int getRes2 = OH_UdmfRecord_GetArrayBuffer(record1, type1, buffer2);
1485    ASSERT_EQ(getRes2, UDMF_E_OK);
1486
1487    unsigned int getLen = 0;
1488    unsigned char *getData;
1489    int getRes3 = OH_UdsArrayBuffer_GetData(buffer2, &getData, &getLen);
1490    ASSERT_EQ(getRes3, UDMF_E_OK);
1491    ASSERT_EQ(len1, getLen);
1492    ASSERT_TRUE(CheckUnsignedChar(data1, getData, getLen));
1493
1494    OH_UdmfRecord_Destroy(record1);
1495    OH_UdsArrayBuffer_Destroy(buffer1);
1496    OH_UdsArrayBuffer_Destroy(buffer2);
1497}
1498
1499/**
1500 * @tc.name: OH_UdmfData_GetPrimaryPlainText001
1501 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1502 * @tc.type: FUNC
1503 */
1504HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText001, TestSize.Level1)
1505{
1506    int result = OH_UdmfData_GetPrimaryPlainText(nullptr, nullptr);
1507    EXPECT_EQ(result, UDMF_E_INVALID_PARAM);
1508
1509    OH_UdmfData data;
1510    int result2 = OH_UdmfData_GetPrimaryPlainText(&data, nullptr);
1511    EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1512
1513    OH_UdmfData *data2 = OH_UdmfData_Create();
1514    int result3 = OH_UdmfData_GetPrimaryPlainText(data2, nullptr);
1515    EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1516
1517    OH_UdsPlainText plainText;
1518    int result4 = OH_UdmfData_GetPrimaryPlainText(data2, &plainText);
1519    EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1520
1521    OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1522    int result5 = OH_UdmfData_GetPrimaryPlainText(data2, plainText2);
1523    EXPECT_EQ(result5, UDMF_ERR);
1524
1525    OH_UdsPlainText_Destroy(plainText2);
1526    OH_UdmfData_Destroy(data2);
1527}
1528
1529/**
1530 * @tc.name: OH_UdmfData_GetPrimaryPlainText002
1531 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1532 * @tc.type: FUNC
1533 */
1534HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText002, TestSize.Level1)
1535{
1536    const char *helloWorld = "Hello world";
1537
1538    OH_UdmfData *data = OH_UdmfData_Create();
1539    OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1540    int result = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1541    EXPECT_EQ(result, UDMF_ERR);
1542
1543    OH_UdmfData *data2 = OH_UdmfData_Create();
1544    OH_UdsHtml *html = OH_UdsHtml_Create();
1545    OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1546    OH_UdmfRecord *record = OH_UdmfRecord_Create();
1547    OH_UdmfRecord_AddHtml(record, html);
1548    OH_UdmfData_AddRecord(data2, record);
1549    int result2 = OH_UdmfData_GetPrimaryPlainText(data2, plainTextOutput);
1550    EXPECT_EQ(result2, UDMF_ERR);
1551
1552    OH_UdmfData *data3 = OH_UdmfData_Create();
1553    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1554    OH_UdsPlainText_SetContent(plainText, helloWorld);
1555    OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1556    OH_UdmfRecord_AddPlainText(record2, plainText);
1557    OH_UdmfData_AddRecord(data3, record);
1558    OH_UdmfData_AddRecord(data3, record2);
1559    int result3 = OH_UdmfData_GetPrimaryPlainText(data3, plainTextOutput);
1560    ASSERT_EQ(result3, UDMF_E_OK);
1561    auto *content = OH_UdsPlainText_GetContent(plainTextOutput);
1562    EXPECT_EQ(strcmp(content, helloWorld), 0);
1563
1564    OH_UdsHtml_Destroy(html);
1565    OH_UdsPlainText_Destroy(plainTextOutput);
1566    OH_UdsPlainText_Destroy(plainText);
1567    OH_UdmfRecord_Destroy(record);
1568    OH_UdmfRecord_Destroy(record2);
1569    OH_UdmfData_Destroy(data);
1570    OH_UdmfData_Destroy(data2);
1571    OH_UdmfData_Destroy(data3);
1572}
1573
1574/**
1575 * @tc.name: OH_UdmfData_GetPrimaryPlainText003
1576 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1577 * @tc.type: FUNC
1578 */
1579HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText003, TestSize.Level1)
1580{
1581    const char *helloWorld = "Hello world";
1582    const char *helloWorld2 = "Hello world2";
1583
1584    OH_UdsHtml *html = OH_UdsHtml_Create();
1585    OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1586    OH_UdmfRecord *record = OH_UdmfRecord_Create();
1587    OH_UdmfRecord_AddHtml(record, html);
1588
1589    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1590    OH_UdsPlainText_SetContent(plainText, helloWorld);
1591    OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1592    OH_UdmfRecord_AddPlainText(record2, plainText);
1593
1594
1595    OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1596    OH_UdsPlainText_SetContent(plainText2, helloWorld2);
1597    OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1598    OH_UdmfRecord_AddPlainText(record3, plainText2);
1599
1600    OH_UdmfData *data = OH_UdmfData_Create();
1601    OH_UdmfData_AddRecord(data, record3);
1602    OH_UdmfData_AddRecord(data, record2);
1603    OH_UdmfData_AddRecord(data, record);
1604    OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1605    int result4 = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1606    ASSERT_EQ(result4, UDMF_E_OK);
1607    auto *content2 = OH_UdsPlainText_GetContent(plainTextOutput);
1608    EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1609
1610    OH_UdsHtml_Destroy(html);
1611    OH_UdsPlainText_Destroy(plainTextOutput);
1612    OH_UdsPlainText_Destroy(plainText);
1613    OH_UdsPlainText_Destroy(plainText2);
1614    OH_UdmfRecord_Destroy(record);
1615    OH_UdmfRecord_Destroy(record2);
1616    OH_UdmfRecord_Destroy(record3);
1617    OH_UdmfData_Destroy(data);
1618}
1619
1620/**
1621 * @tc.name: OH_UdmfData_GetPrimaryHtml001
1622 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1623 * @tc.type: FUNC
1624 */
1625HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml001, TestSize.Level1)
1626{
1627    int result1 = OH_UdmfData_GetPrimaryHtml(nullptr, nullptr);
1628    EXPECT_EQ(result1, UDMF_E_INVALID_PARAM);
1629
1630    OH_UdmfData data;
1631    int result2 = OH_UdmfData_GetPrimaryHtml(&data, nullptr);
1632    EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1633
1634    OH_UdmfData *data2 = OH_UdmfData_Create();
1635    int result3 = OH_UdmfData_GetPrimaryHtml(data2, nullptr);
1636    EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1637
1638    OH_UdsHtml html;
1639    int result4 = OH_UdmfData_GetPrimaryHtml(data2, &html);
1640    EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1641
1642    OH_UdsHtml *html2 = OH_UdsHtml_Create();
1643    int result5 = OH_UdmfData_GetPrimaryHtml(data2, html2);
1644    EXPECT_EQ(result5, UDMF_ERR);
1645
1646    OH_UdsHtml_Destroy(html2);
1647    OH_UdmfData_Destroy(data2);
1648}
1649
1650/**
1651 * @tc.name: OH_UdmfData_GetPrimaryHtml002
1652 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1653 * @tc.type: FUNC
1654 */
1655HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml002, TestSize.Level1)
1656{
1657    const char *helloWorld = "<p>Hello world</p>";
1658
1659    OH_UdmfData *data = OH_UdmfData_Create();
1660    OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1661    int result = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1662    EXPECT_EQ(result, UDMF_ERR);
1663
1664    OH_UdmfData *data2 = OH_UdmfData_Create();
1665    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1666    OH_UdsPlainText_SetContent(plainText, "Hello world");
1667    OH_UdmfRecord* record = OH_UdmfRecord_Create();
1668    OH_UdmfRecord_AddPlainText(record, plainText);
1669    OH_UdmfData_AddRecord(data2, record);
1670    int result2 = OH_UdmfData_GetPrimaryHtml(data2, htmlOutput);
1671    EXPECT_EQ(result2, UDMF_ERR);
1672
1673    OH_UdmfData *data3 = OH_UdmfData_Create();
1674    OH_UdsHtml *html = OH_UdsHtml_Create();
1675    OH_UdsHtml_SetContent(html, helloWorld);
1676    OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1677    OH_UdmfRecord_AddHtml(record2, html);
1678    OH_UdmfData_AddRecord(data3, record);
1679    OH_UdmfData_AddRecord(data3, record2);
1680    int result3 = OH_UdmfData_GetPrimaryHtml(data3, htmlOutput);
1681    ASSERT_EQ(result3, UDMF_E_OK);
1682    auto content = OH_UdsHtml_GetContent(htmlOutput);
1683    EXPECT_EQ(strcmp(content, helloWorld), 0);
1684
1685    OH_UdsHtml_Destroy(html);
1686    OH_UdsHtml_Destroy(htmlOutput);
1687    OH_UdsPlainText_Destroy(plainText);
1688    OH_UdmfRecord_Destroy(record);
1689    OH_UdmfRecord_Destroy(record2);
1690    OH_UdmfData_Destroy(data);
1691    OH_UdmfData_Destroy(data2);
1692    OH_UdmfData_Destroy(data3);
1693}
1694
1695/**
1696 * @tc.name: OH_UdmfData_GetPrimaryHtml003
1697 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1698 * @tc.type: FUNC
1699 */
1700HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml003, TestSize.Level1)
1701{
1702    const char *helloWorld = "<p>Hello world</p>";
1703    const char *helloWorld2 = "<p>Hello world2</p>";
1704
1705    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1706    OH_UdsPlainText_SetContent(plainText, "Hello world");
1707    OH_UdmfRecord* record = OH_UdmfRecord_Create();
1708    OH_UdmfRecord_AddPlainText(record, plainText);
1709
1710    OH_UdsHtml *html = OH_UdsHtml_Create();
1711    OH_UdsHtml_SetContent(html, helloWorld);
1712    OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1713    OH_UdmfRecord_AddHtml(record2, html);
1714
1715    OH_UdsHtml *html2 = OH_UdsHtml_Create();
1716    OH_UdsHtml_SetContent(html2, helloWorld2);
1717    OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1718    OH_UdmfRecord_AddHtml(record3, html2);
1719
1720    OH_UdmfData *data = OH_UdmfData_Create();
1721    OH_UdmfData_AddRecord(data, record3);
1722    OH_UdmfData_AddRecord(data, record2);
1723    OH_UdmfData_AddRecord(data, record);
1724    OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1725    int result4 = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1726    ASSERT_EQ(result4, UDMF_E_OK);
1727    auto content2 = OH_UdsHtml_GetContent(htmlOutput);
1728    EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1729
1730    OH_UdsHtml_Destroy(html);
1731    OH_UdsHtml_Destroy(html2);
1732    OH_UdsHtml_Destroy(htmlOutput);
1733    OH_UdsPlainText_Destroy(plainText);
1734    OH_UdmfRecord_Destroy(record);
1735    OH_UdmfRecord_Destroy(record2);
1736    OH_UdmfRecord_Destroy(record3);
1737    OH_UdmfData_Destroy(data);
1738}
1739
1740/**
1741 * @tc.name: OH_UdmfData_GetRecordCount001
1742 * @tc.desc: Normal testcase of OH_UdmfData_GetRecordCount
1743 * @tc.type: FUNC
1744 */
1745HWTEST_F(UDMFTest, OH_UdmfData_GetRecordCount001, TestSize.Level1)
1746{
1747    int result = OH_UdmfData_GetRecordCount(nullptr);
1748    EXPECT_EQ(result, 0);
1749
1750    OH_UdmfData data;
1751    int result2 = OH_UdmfData_GetRecordCount(&data);
1752    EXPECT_EQ(result2, 0);
1753
1754    OH_UdmfData *data2 = OH_UdmfData_Create();
1755    int result3 = OH_UdmfData_GetRecordCount(data2);
1756    EXPECT_EQ(result3, 0);
1757
1758    OH_UdmfData *data3 = OH_UdmfData_Create();
1759    OH_UdmfRecord *record = OH_UdmfRecord_Create();
1760    OH_UdmfData_AddRecord(data3, record);
1761    int result4 = OH_UdmfData_GetRecordCount(data3);
1762    EXPECT_EQ(result4, 1);
1763
1764    OH_UdmfData *data4 = OH_UdmfData_Create();
1765    OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1766    OH_UdmfData_AddRecord(data4, record);
1767    OH_UdmfData_AddRecord(data4, record2);
1768    int result5 = OH_UdmfData_GetRecordCount(data4);
1769    EXPECT_EQ(result5, 2);
1770
1771    OH_UdmfRecord_Destroy(record);
1772    OH_UdmfRecord_Destroy(record2);
1773    OH_UdmfData_Destroy(data2);
1774    OH_UdmfData_Destroy(data3);
1775    OH_UdmfData_Destroy(data4);
1776}
1777
1778/**
1779 * @tc.name: OH_UdmfData_GetRecord001
1780 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1781 * @tc.type: FUNC
1782 */
1783HWTEST_F(UDMFTest, OH_UdmfData_GetRecord001, TestSize.Level1)
1784{
1785    OH_UdmfRecord *result = OH_UdmfData_GetRecord(nullptr, -1);
1786    EXPECT_EQ(result, nullptr);
1787
1788    OH_UdmfData data;
1789    OH_UdmfRecord *result2 = OH_UdmfData_GetRecord(&data, -1);
1790    EXPECT_EQ(result2, nullptr);
1791
1792    OH_UdmfRecord *result3 = OH_UdmfData_GetRecord(&data, 0);
1793    EXPECT_EQ(result3, nullptr);
1794
1795    OH_UdmfData *data2 = OH_UdmfData_Create();
1796    OH_UdmfRecord *result4 = OH_UdmfData_GetRecord(data2, -1);
1797    EXPECT_EQ(result4, nullptr);
1798
1799    OH_UdmfRecord *result5 = OH_UdmfData_GetRecord(data2, 0);
1800    EXPECT_EQ(result5, nullptr);
1801
1802    OH_UdmfRecord *result6 = OH_UdmfData_GetRecord(data2, 1);
1803    EXPECT_EQ(result6, nullptr);
1804
1805    OH_UdmfData *data3 = OH_UdmfData_Create();
1806    OH_UdmfRecord* record = OH_UdmfRecord_Create();
1807    OH_UdmfData_AddRecord(data3, record);
1808    EXPECT_EQ(OH_UdmfData_GetRecordCount(data3), 1);
1809    OH_UdmfRecord *result7 = OH_UdmfData_GetRecord(data3, -1);
1810    EXPECT_EQ(result7, nullptr);
1811    OH_UdmfRecord *result8 = OH_UdmfData_GetRecord(data3, 1);
1812    EXPECT_EQ(result8, nullptr);
1813    OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1814    EXPECT_NE(result9, nullptr);
1815
1816    OH_UdmfRecord_Destroy(record);
1817    OH_UdmfData_Destroy(data2);
1818    OH_UdmfData_Destroy(data3);
1819}
1820
1821/**
1822 * @tc.name: OH_UdmfData_GetRecord002
1823 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1824 * @tc.type: FUNC
1825 */
1826HWTEST_F(UDMFTest, OH_UdmfData_GetRecord002, TestSize.Level1)
1827{
1828    const char *helloWorld = "Hello world";
1829    const char *helloWorld2 = "Hello world2";
1830
1831    OH_UdmfData *data3 = OH_UdmfData_Create();
1832    OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1833    OH_UdsPlainText_SetContent(plainText, helloWorld);
1834    OH_UdmfRecord* record = OH_UdmfRecord_Create();
1835    OH_UdmfRecord_AddPlainText(record, plainText);
1836    OH_UdmfData_AddRecord(data3, record);
1837    OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1838    EXPECT_NE(result9, nullptr);
1839    OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1840    OH_UdmfRecord_GetPlainText(result9, plainText2);
1841    auto content = OH_UdsPlainText_GetContent(plainText2);
1842    EXPECT_EQ(strcmp(content, helloWorld), 0);
1843
1844    OH_UdmfData *data4 = OH_UdmfData_Create();
1845    OH_UdsPlainText *plainText3 = OH_UdsPlainText_Create();
1846    OH_UdsPlainText_SetContent(plainText3, helloWorld2);
1847    OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1848    OH_UdmfRecord_AddPlainText(record2, plainText3);
1849    OH_UdmfData_AddRecord(data4, record);
1850    OH_UdmfData_AddRecord(data4, record2);
1851    OH_UdmfRecord *result10 = OH_UdmfData_GetRecord(data4, -1);
1852    EXPECT_EQ(result10, nullptr);
1853    OH_UdmfRecord *result11 = OH_UdmfData_GetRecord(data4, 2);
1854    EXPECT_EQ(result11, nullptr);
1855    OH_UdmfRecord *result12 = OH_UdmfData_GetRecord(data4, 0);
1856    ASSERT_NE(result12, nullptr);
1857    OH_UdsPlainText *plainText4 = OH_UdsPlainText_Create();
1858    OH_UdmfRecord_GetPlainText(result12, plainText4);
1859    auto content2 = OH_UdsPlainText_GetContent(plainText4);
1860    EXPECT_EQ(strcmp(content2, helloWorld), 0);
1861    OH_UdmfRecord *result13 = OH_UdmfData_GetRecord(data4, 1);
1862    ASSERT_NE(result13, nullptr);
1863    OH_UdsPlainText *plainText5 = OH_UdsPlainText_Create();
1864    OH_UdmfRecord_GetPlainText(result13, plainText5);
1865    auto content3 = OH_UdsPlainText_GetContent(plainText5);
1866    EXPECT_EQ(strcmp(content3, helloWorld2), 0);
1867
1868    OH_UdsPlainText_Destroy(plainText);
1869    OH_UdsPlainText_Destroy(plainText2);
1870    OH_UdmfRecord_Destroy(record);
1871    OH_UdmfRecord_Destroy(record2);
1872    OH_UdmfData_Destroy(data3);
1873    OH_UdmfData_Destroy(data4);
1874}
1875
1876/**
1877 * @tc.name: OH_UdmfData_IsLocal001
1878 * @tc.desc: Normal testcase of OH_UdmfData_IsLocal
1879 * @tc.type: FUNC
1880 */
1881HWTEST_F(UDMFTest, OH_UdmfData_IsLocal001, TestSize.Level1)
1882{
1883    bool result = OH_UdmfData_IsLocal(nullptr);
1884    EXPECT_EQ(result, true);
1885
1886    OH_UdmfData data;
1887    bool result2 = OH_UdmfData_IsLocal(&data);
1888    EXPECT_EQ(result2, true);
1889
1890    OH_UdmfData *data2 = OH_UdmfData_Create();
1891    bool result3 = OH_UdmfData_IsLocal(data2);
1892    EXPECT_EQ(result3, true);
1893
1894    OH_UdmfData_Destroy(data2);
1895}
1896
1897/**
1898 * @tc.name: FileUriTest001
1899 * @tc.desc: test fileUri between js and capi
1900 * @tc.type: FUNC
1901 */
1902HWTEST_F(UDMFTest, FileUriTest001, TestSize.Level1)
1903{
1904    std::string uri = "https://xxx/xx/xx.jpg";
1905    std::shared_ptr<Image> image = std::make_shared<Image>();
1906    image->SetUri(uri);
1907    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
1908    unifiedData->AddRecord(image);
1909    std::string key;
1910    CustomOption option = {
1911        .intention = UD_INTENTION_DRAG
1912    };
1913    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
1914    EXPECT_EQ(setRet, E_OK);
1915
1916    OH_UdmfData* udmfData = OH_UdmfData_Create();
1917    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
1918
1919    unsigned int dataTypeCount;
1920    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
1921    EXPECT_EQ(dataTypeCount, 2);
1922    EXPECT_NE(dataTypes, nullptr);
1923    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
1924    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1925
1926    unsigned int recordCount;
1927    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
1928    EXPECT_EQ(recordCount, 1);
1929    EXPECT_NE(records, nullptr);
1930
1931    for (unsigned int idx = 0; idx < recordCount; ++idx) {
1932        unsigned int recordTypeCount;
1933        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
1934        EXPECT_EQ(recordTypeCount, 2);
1935        EXPECT_NE(recordTypes, nullptr);
1936        EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_IMAGE), 0);
1937        EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1938        for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
1939            if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
1940                OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
1941                int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
1942                EXPECT_EQ(getFileUriRet, UDMF_E_OK);
1943                const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
1944                EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
1945            }
1946        }
1947    }
1948}
1949
1950/**
1951 * @tc.name: FileUriTest002
1952 * @tc.desc: test fileUri between js and capi
1953 * @tc.type: FUNC
1954 */
1955HWTEST_F(UDMFTest, FileUriTest002, TestSize.Level1)
1956{
1957    std::string uri = "https://xxx/xx/xx.jpg";
1958    std::string content = "content";
1959    std::shared_ptr<Image> image = std::make_shared<Image>();
1960    image->SetUri(uri);
1961    std::shared_ptr<PlainText> plaintext = std::make_shared<PlainText>();
1962    plaintext->SetContent(content);
1963    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
1964    unifiedData->AddRecord(image);
1965    unifiedData->AddRecord(plaintext);
1966    std::string key;
1967    CustomOption option = {
1968        .intention = UD_INTENTION_DRAG
1969    };
1970    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
1971    EXPECT_EQ(setRet, E_OK);
1972
1973    OH_UdmfData* udmfData = OH_UdmfData_Create();
1974    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
1975
1976    unsigned int dataTypeCount;
1977    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
1978    EXPECT_EQ(dataTypeCount, 3);
1979    EXPECT_NE(dataTypes, nullptr);
1980    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
1981    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_PLAIN_TEXT), 0);
1982    EXPECT_EQ(strcmp(dataTypes[2], UDMF_META_GENERAL_FILE_URI), 0);
1983
1984    unsigned int recordCount;
1985    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
1986    EXPECT_EQ(recordCount, 2);
1987    EXPECT_NE(records, nullptr);
1988
1989    for (unsigned int idx = 0; idx < recordCount; idx++) {
1990        unsigned int recordTypeCount;
1991        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
1992        EXPECT_NE(recordTypes, nullptr);
1993        if (recordTypeCount == 1) {
1994            EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_PLAIN_TEXT), 0);
1995            for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
1996                OH_UdsPlainText* text = OH_UdsPlainText_Create();
1997                int getPlaintextRet = OH_UdmfRecord_GetPlainText(records[idx], text);
1998                EXPECT_EQ(getPlaintextRet, UDMF_E_OK);
1999                const char* getContent = OH_UdsPlainText_GetContent(text);
2000                EXPECT_EQ(strcmp(getContent, content.c_str()), 0);
2001            }
2002        }
2003        if (recordTypeCount == 2) {
2004            EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_IMAGE), 0);
2005            EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2006            for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2007                if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2008                    OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2009                    int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2010                    EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2011                    const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2012                    EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2013                }
2014            }
2015        }
2016    }
2017}
2018
2019/**
2020 * @tc.name: FileUriTest003
2021 * @tc.desc: test fileUri between js and capi
2022 * @tc.type: FUNC
2023 */
2024HWTEST_F(UDMFTest, FileUriTest003, TestSize.Level1)
2025{
2026    std::string uri = "https://xxx/xx/xx.jpg";
2027    std::shared_ptr<Audio> audio = std::make_shared<Audio>();
2028    audio->SetUri(uri);
2029    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2030    unifiedData->AddRecord(audio);
2031    std::string key;
2032    CustomOption option = {
2033        .intention = UD_INTENTION_DRAG
2034    };
2035    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2036    EXPECT_EQ(setRet, E_OK);
2037
2038    OH_UdmfData* udmfData = OH_UdmfData_Create();
2039    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2040
2041    unsigned int dataTypeCount;
2042    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2043    EXPECT_EQ(dataTypeCount, 2);
2044    EXPECT_NE(dataTypes, nullptr);
2045    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_AUDIO), 0);
2046    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2047
2048    unsigned int recordCount;
2049    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2050    EXPECT_EQ(recordCount, 1);
2051    EXPECT_NE(records, nullptr);
2052
2053    for (unsigned int idx = 0; idx < recordCount; ++idx) {
2054        unsigned int recordTypeCount;
2055        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2056        EXPECT_EQ(recordTypeCount, 2);
2057        EXPECT_NE(recordTypes, nullptr);
2058        EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_AUDIO), 0);
2059        EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2060        for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2061            if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2062                OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2063                int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2064                EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2065                const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2066                EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2067            }
2068        }
2069    }
2070}
2071
2072/**
2073 * @tc.name: FileUriTest004
2074 * @tc.desc: test fileUri between js and capi
2075 * @tc.type: FUNC
2076 */
2077HWTEST_F(UDMFTest, FileUriTest004, TestSize.Level1)
2078{
2079    std::string uri = "https://xxx/xx/xx.jpg";
2080    std::shared_ptr<File> file = std::make_shared<File>();
2081    file->SetUri(uri);
2082    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2083    unifiedData->AddRecord(file);
2084    std::string key;
2085    CustomOption option = {
2086        .intention = UD_INTENTION_DRAG
2087    };
2088    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2089    EXPECT_EQ(setRet, E_OK);
2090
2091    OH_UdmfData* udmfData = OH_UdmfData_Create();
2092    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2093
2094    unsigned int dataTypeCount;
2095    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2096    EXPECT_EQ(dataTypeCount, 2);
2097    EXPECT_NE(dataTypes, nullptr);
2098    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_GENERAL_FILE), 0);
2099    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2100
2101    unsigned int recordCount;
2102    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2103    EXPECT_EQ(recordCount, 1);
2104    EXPECT_NE(records, nullptr);
2105
2106    for (unsigned int idx = 0; idx < recordCount; ++idx) {
2107        unsigned int recordTypeCount;
2108        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2109        EXPECT_EQ(recordTypeCount, 2);
2110        EXPECT_NE(recordTypes, nullptr);
2111        EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE), 0);
2112        EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2113        for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2114            if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2115                OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2116                int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2117                EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2118                const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2119                EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2120            }
2121        }
2122    }
2123}
2124
2125/**
2126 * @tc.name: FileUriTest005
2127 * @tc.desc: test fileUri between js and capi
2128 * @tc.type: FUNC
2129 */
2130HWTEST_F(UDMFTest, FileUriTest005, TestSize.Level1)
2131{
2132    std::string uri = "https://xxx/xx/xx.jpg";
2133    std::shared_ptr<Folder> folder = std::make_shared<Folder>();
2134    folder->SetUri(uri);
2135    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2136    unifiedData->AddRecord(folder);
2137    std::string key;
2138    CustomOption option = {
2139        .intention = UD_INTENTION_DRAG
2140    };
2141    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2142    EXPECT_EQ(setRet, E_OK);
2143
2144    OH_UdmfData* udmfData = OH_UdmfData_Create();
2145    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2146
2147    unsigned int dataTypeCount;
2148    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2149    EXPECT_EQ(dataTypeCount, 2);
2150    EXPECT_NE(dataTypes, nullptr);
2151    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_FOLDER), 0);
2152    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2153
2154    unsigned int recordCount;
2155    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2156    EXPECT_EQ(recordCount, 1);
2157    EXPECT_NE(records, nullptr);
2158
2159    for (unsigned int idx = 0; idx < recordCount; ++idx) {
2160        unsigned int recordTypeCount;
2161        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2162        EXPECT_EQ(recordTypeCount, 2);
2163        EXPECT_NE(recordTypes, nullptr);
2164        EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_FOLDER), 0);
2165        EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2166        for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2167            if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2168                OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2169                int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2170                EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2171                const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2172                EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2173            }
2174        }
2175    }
2176}
2177
2178/**
2179 * @tc.name: FileUriTest006
2180 * @tc.desc: test fileUri between js and capi
2181 * @tc.type: FUNC
2182 */
2183HWTEST_F(UDMFTest, FileUriTest006, TestSize.Level1)
2184{
2185    std::string uri = "https://xxx/xx/xx.jpg";
2186    std::shared_ptr<Video> video = std::make_shared<Video>();
2187    video->SetUri(uri);
2188    std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2189    unifiedData->AddRecord(video);
2190    std::string key;
2191    CustomOption option = {
2192        .intention = UD_INTENTION_DRAG
2193    };
2194    int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2195    EXPECT_EQ(setRet, E_OK);
2196
2197    OH_UdmfData* udmfData = OH_UdmfData_Create();
2198    OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2199
2200    unsigned int dataTypeCount;
2201    char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2202    EXPECT_EQ(dataTypeCount, 2);
2203    EXPECT_NE(dataTypes, nullptr);
2204    EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2205    EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2206
2207    unsigned int recordCount;
2208    OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2209    EXPECT_EQ(recordCount, 1);
2210    EXPECT_NE(records, nullptr);
2211
2212    for (unsigned int idx = 0; idx < recordCount; ++idx) {
2213        unsigned int recordTypeCount;
2214        char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2215        EXPECT_EQ(recordTypeCount, 2);
2216        EXPECT_NE(recordTypes, nullptr);
2217        EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_VIDEO), 0);
2218        EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2219        for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2220            if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2221                OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2222                int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2223                EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2224                const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2225                EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2226            }
2227        }
2228    }
2229}
2230
2231/**
2232 * @tc.name: OH_Udmf_SetAndGetUnifiedData003
2233 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2234 * @tc.type: FUNC
2235 * @tc.require: AROOOH5R5G
2236 */
2237HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData003, TestSize.Level1)
2238{
2239    std::string uri = "https://xxx/xx/xx.jpg";
2240    OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2241    OH_UdmfRecord *record = OH_UdmfRecord_Create();
2242    OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2243    OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2244    OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
2245    OH_UdmfRecord_AddFileUri(record, fileUri);
2246    OH_UdmfData_AddRecord(udmfUnifiedData, record);
2247    Udmf_Intention intention = UDMF_INTENTION_DRAG;
2248    char key[UDMF_KEY_BUFFER_LEN];
2249
2250    int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2251    EXPECT_EQ(setRes, UDMF_E_OK);
2252    EXPECT_NE(key[0], '\0');
2253    OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2254    int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2255    EXPECT_EQ(getRes, UDMF_E_OK);
2256    unsigned int count = 0;
2257    OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2258    EXPECT_EQ(count, 1);
2259    OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2260    OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2261    const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2262    EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2263
2264    OH_UdsFileUri_Destroy(fileUri);
2265    OH_UdmfRecord_Destroy(record);
2266    OH_UdmfData_Destroy(udmfUnifiedData);
2267
2268    OH_UdsFileUri_Destroy(getFileUri);
2269    OH_UdmfData_Destroy(readUnifiedData);
2270}
2271
2272/**
2273 * @tc.name: OH_Udmf_SetAndGetUnifiedData004
2274 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2275 * @tc.type: FUNC
2276 * @tc.require: AROOOH5R5G
2277 */
2278HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData004, TestSize.Level1)
2279{
2280    std::string uri = "https://xxx/xx/xx.jpg";
2281    OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2282    OH_UdmfRecord *record = OH_UdmfRecord_Create();
2283    OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2284    OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2285    OH_UdmfRecord_AddFileUri(record, fileUri);
2286    OH_UdmfData_AddRecord(udmfUnifiedData, record);
2287    Udmf_Intention intention = UDMF_INTENTION_DRAG;
2288    char key[UDMF_KEY_BUFFER_LEN];
2289
2290    int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2291    EXPECT_EQ(setRes, UDMF_E_OK);
2292    EXPECT_NE(key[0], '\0');
2293    OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2294    int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2295    EXPECT_EQ(getRes, UDMF_E_OK);
2296    unsigned int count = 0;
2297    OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2298    EXPECT_EQ(count, 1);
2299    OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2300    OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2301    const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2302    EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2303
2304    OH_UdsFileUri_Destroy(fileUri);
2305    OH_UdmfRecord_Destroy(record);
2306    OH_UdmfData_Destroy(udmfUnifiedData);
2307
2308    OH_UdsFileUri_Destroy(getFileUri);
2309    OH_UdmfData_Destroy(readUnifiedData);
2310}
2311
2312/**
2313 * @tc.name: OH_Udmf_SetAndGetUnifiedData005
2314 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2315 * @tc.type: FUNC
2316 * @tc.require: AROOOH5R5G
2317 */
2318HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData005, TestSize.Level1)
2319{
2320    std::string uri = "https://xxx/xx/xx.jpg";
2321    OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2322    OH_UdmfRecord *record = OH_UdmfRecord_Create();
2323    OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2324    OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2325    OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2326    OH_UdmfRecord_AddFileUri(record, fileUri);
2327    OH_UdmfData_AddRecord(udmfUnifiedData, record);
2328    Udmf_Intention intention = UDMF_INTENTION_DRAG;
2329    char key[UDMF_KEY_BUFFER_LEN];
2330
2331    int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2332    EXPECT_EQ(setRes, UDMF_E_OK);
2333    EXPECT_NE(key[0], '\0');
2334    OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2335    int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2336    EXPECT_EQ(getRes, UDMF_E_OK);
2337    unsigned int count = 0;
2338    OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2339    EXPECT_EQ(count, 1);
2340    OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2341    OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2342    const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2343    EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2344
2345    OH_UdsFileUri_Destroy(fileUri);
2346    OH_UdmfRecord_Destroy(record);
2347    OH_UdmfData_Destroy(udmfUnifiedData);
2348
2349    OH_UdsFileUri_Destroy(getFileUri);
2350    OH_UdmfData_Destroy(readUnifiedData);
2351}
2352
2353/**
2354 * @tc.name: OH_Udmf_SetAndGetUnifiedData006
2355 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2356 * @tc.type: FUNC
2357 */
2358HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData006, TestSize.Level1)
2359{
2360    OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2361    OH_UdmfRecord *record = OH_UdmfRecord_Create();
2362    OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
2363    unsigned char thumbData[] = {0, 1, 2, 3, 4};
2364    OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
2365    OH_UdsContentForm_SetDescription(contentForm, "description");
2366    OH_UdmfRecord_AddContentForm(record, contentForm);
2367    OH_UdmfData_AddRecord(udmfUnifiedData, record);
2368    Udmf_Intention intention = UDMF_INTENTION_DRAG;
2369    char key[UDMF_KEY_BUFFER_LEN];
2370
2371    int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2372    EXPECT_EQ(setRes, UDMF_E_OK);
2373    EXPECT_NE(key[0], '\0');
2374    OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2375    int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2376    EXPECT_EQ(getRes, UDMF_E_OK);
2377    unsigned int count = 0;
2378    OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2379    EXPECT_EQ(count, 1);
2380    OH_UdsContentForm *getContentForm = OH_UdsContentForm_Create();
2381    OH_UdmfRecord_GetContentForm(getRecords[0], getContentForm);
2382    EXPECT_EQ("description", std::string(OH_UdsContentForm_GetDescription(getContentForm)));
2383
2384    unsigned char *readThumbData;
2385    unsigned int thumbDataLen = 0;
2386    OH_UdsContentForm_GetThumbData(getContentForm, &readThumbData, &thumbDataLen);
2387    ASSERT_EQ(5, thumbDataLen);
2388    ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
2389
2390    OH_UdsContentForm_Destroy(contentForm);
2391    OH_UdmfRecord_Destroy(record);
2392    OH_UdmfData_Destroy(udmfUnifiedData);
2393
2394    OH_UdsContentForm_Destroy(getContentForm);
2395    OH_UdmfData_Destroy(readUnifiedData);
2396}
2397}
2398