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