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_Udmf_MultiStyleRecord002
1246 * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1247 * @tc.type: FUNC
1248 */
1249 HWTEST_F(UDMFTest, OH_Udmf_MultiStyleRecord002, TestSize.Level1)
1250 {
1251 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1252 UnifiedData data;
1253 std::string key;
1254 auto object = std::make_shared<Object>();
1255 object->value_[UNIFORM_DATA_TYPE] = UtdUtils::GetUtdIdFromUtdEnum(UDType::PLAIN_TEXT);
1256 object->value_[CONTENT] = "content_";
1257 object->value_[ABSTRACT] = "abstract_";
1258 auto record = std::make_shared<UnifiedRecord>(UDType::PLAIN_TEXT, object);
1259
1260 std::vector<uint8_t> raw = {1, 2, 3, 4, 5};
1261 std::shared_ptr<Object> obj = std::make_shared<Object>();
1262 obj->value_[UNIFORM_DATA_TYPE] = "general.content-form";
1263 obj->value_[THUMB_DATA] = raw;
1264 obj->value_[THUMB_DATA_LENGTH] = 5;
1265 obj->value_[DESCRIPTION] = "descritpion";
1266 obj->value_[TITLE] = "title";
1267 obj->value_[APP_ICON_LENGTH] = 5;
1268 obj->value_[APP_NAME] = "appName";
1269 obj->value_[LINK_URL] = "linkUri";
1270 auto contentForm = UnifiedRecord(CONTENT_FORM, obj);
1271 record->AddEntry(contentForm.GetUtdId(), contentForm.GetOriginValue());
1272
1273 data.AddRecord(record);
1274
1275 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1276 ASSERT_EQ(status, E_OK);
1277
1278 ASSERT_EQ(status, E_OK);
1279 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
1280 int getRes = OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, readUnifiedData);
1281 ASSERT_EQ(getRes, E_OK);
1282 unsigned int count = 0;
1283 OH_UdmfRecord** readRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
1284 ASSERT_EQ(count, 1);
1285 for (int i = 0; i < count; i++) {
1286 OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
1287 OH_UdmfRecord_GetContentForm(readRecords[i], contentForm);
1288 const char* desc = OH_UdsContentForm_GetDescription(contentForm);
1289 EXPECT_EQ(std::string(desc), "descritpion");
1290 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1291 OH_UdmfRecord_GetPlainText(readRecords[i], plainText);
1292 const char* text = OH_UdsPlainText_GetContent(plainText);
1293 EXPECT_EQ(std::string(text), "content_");
1294 }
1295 }
1296
1297 /**
1298 * @tc.name: OH_UdmfRecordProvider_Create001
1299 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Create
1300 * @tc.type: FUNC
1301 */
1302 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Create001, TestSize.Level1)
1303 {
1304 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1305 EXPECT_NE(provider, nullptr);
1306 OH_UdmfRecordProvider_Destroy(provider);
1307 }
1308
1309 /**
1310 * @tc.name: OH_UdmfRecordProvider_Destroy001
1311 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Destroy
1312 * @tc.type: FUNC
1313 */
1314 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy001, TestSize.Level1)
1315 {
1316 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1317 EXPECT_NE(provider, nullptr);
1318 int num = 1;
1319 void* context = #
1320 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1321 int res1 = OH_UdmfRecordProvider_Destroy(provider);
1322 EXPECT_EQ(res1, UDMF_E_OK);
1323 }
1324
1325 /**
1326 * @tc.name: OH_UdmfRecordProvider_Destroy002
1327 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_Destroy
1328 * @tc.type: FUNC
1329 */
1330 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy002, TestSize.Level1)
1331 {
1332 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1333 EXPECT_NE(provider, nullptr);
1334 int num = 1;
1335 void* context = #
1336 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1337 int res1 = OH_UdmfRecordProvider_Destroy(provider);
1338 EXPECT_EQ(res1, UDMF_E_OK);
1339 }
1340
1341 /**
1342 * @tc.name: OH_UdmfRecordProvider_SetData001
1343 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_SetData
1344 * @tc.type: FUNC
1345 */
1346 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData001, TestSize.Level1)
1347 {
1348 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1349 EXPECT_NE(provider, nullptr);
1350 int num = 1;
1351 void* context = #
1352 int res = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1353 EXPECT_NE(provider->context, nullptr);
1354 EXPECT_NE(provider->callback, nullptr);
1355 EXPECT_NE(provider->finalize, nullptr);
1356 EXPECT_EQ(res, UDMF_E_OK);
1357 OH_UdmfRecordProvider_Destroy(provider);
1358 }
1359
1360 /**
1361 * @tc.name: OH_UdmfRecordProvider_SetData002
1362 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_SetData
1363 * @tc.type: FUNC
1364 */
1365 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData002, TestSize.Level1)
1366 {
1367 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1368 EXPECT_NE(provider, nullptr);
1369 int num = 1;
1370 void* context = #
1371 int res1 = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1372 EXPECT_EQ(provider->context, nullptr);
1373 EXPECT_EQ(provider->finalize, nullptr);
1374 EXPECT_EQ(res1, UDMF_E_INVALID_PARAM);
1375
1376 int res2 = OH_UdmfRecordProvider_SetData(nullptr, context, GetDataCallbackFunc, nullptr);
1377 EXPECT_EQ(res2, UDMF_E_INVALID_PARAM);
1378
1379 int res3 = OH_UdmfRecordProvider_SetData(provider, context, nullptr, nullptr);
1380 EXPECT_EQ(res3, UDMF_E_INVALID_PARAM);
1381 OH_UdmfRecordProvider_Destroy(provider);
1382 }
1383
1384 /**
1385 * @tc.name: OH_UdmfRecord_SetProvider001
1386 * @tc.desc: Normal testcase of OH_UdmfRecord_SetProvider
1387 * @tc.type: FUNC
1388 */
1389 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider001, TestSize.Level1)
1390 {
1391 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1392 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1393 char content[] = "hello world";
1394 OH_UdsPlainText_SetContent(plainText, content);
1395 OH_UdmfRecord_AddPlainText(record, plainText);
1396 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1397 EXPECT_NE(provider, nullptr);
1398 int num = 1;
1399 void* context = #
1400 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1401 const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1402
1403 int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1404 EXPECT_EQ(res, UDMF_E_OK);
1405 OH_UdmfRecordProvider_Destroy(provider);
1406 }
1407
1408 /**
1409 * @tc.name: OH_UdmfRecord_SetProvider002
1410 * @tc.desc: invalid parameters testcase of OH_UdmfRecord_SetProvider
1411 * @tc.type: FUNC
1412 */
1413 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider002, TestSize.Level1)
1414 {
1415 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1416 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1417 char content[] = "hello world";
1418 OH_UdsPlainText_SetContent(plainText, content);
1419 OH_UdmfRecord_AddPlainText(record, plainText);
1420 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1421 EXPECT_NE(provider, nullptr);
1422 int num = 1;
1423 void* context = #
1424 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1425 const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1426
1427 int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1428 EXPECT_EQ(res, UDMF_E_OK);
1429 OH_UdmfRecordProvider_Destroy(provider);
1430 }
1431
1432 /**
1433 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001
1434 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1435 * @tc.type: FUNC
1436 */
1437 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001, TestSize.Level0)
1438 {
1439 int buildRes1 = OH_UdmfRecord_AddArrayBuffer(nullptr, nullptr, nullptr);
1440 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1441
1442 OH_UdmfRecord record1;
1443 int buildRes2 = OH_UdmfRecord_AddArrayBuffer(&record1, nullptr, nullptr);
1444 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1445
1446 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1447 int buildRes3 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, nullptr);
1448 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1449
1450 OH_UdsArrayBuffer buffer;
1451 int buildRes4 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, &buffer);
1452 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1453
1454 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1455 int buildRes5 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, buffer2);
1456 EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1457
1458 char type[] = "general.plain-text";
1459 int buildRes6 = OH_UdmfRecord_AddArrayBuffer(record2, type, buffer2);
1460 EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1461
1462 char type2[] = "ApplicationDefined-myType1";
1463 int buildRes7 = OH_UdmfRecord_AddArrayBuffer(record2, type2, buffer2);
1464 EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1465
1466 OH_UdmfRecord_Destroy(record2);
1467 OH_UdsArrayBuffer_Destroy(buffer2);
1468 }
1469
1470 /**
1471 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002
1472 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1473 * @tc.type: FUNC
1474 */
1475 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002, TestSize.Level0)
1476 {
1477 int buildRes1 = OH_UdmfRecord_GetArrayBuffer(nullptr, nullptr, nullptr);
1478 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1479
1480 OH_UdmfRecord record1;
1481 int buildRes2 = OH_UdmfRecord_GetArrayBuffer(&record1, nullptr, nullptr);
1482 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1483
1484 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1485 int buildRes3 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, nullptr);
1486 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1487
1488 OH_UdsArrayBuffer buffer;
1489 int buildRes4 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, &buffer);
1490 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1491
1492 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1493 int buildRes5 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, buffer2);
1494 EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1495
1496 char type[] = "general.plain-text";
1497 int buildRes6 = OH_UdmfRecord_GetArrayBuffer(record2, type, buffer2);
1498 EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1499
1500 char type2[] = "ApplicationDefined-myType1";
1501 int buildRes7 = OH_UdmfRecord_GetArrayBuffer(record2, type2, buffer2);
1502 EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1503
1504 OH_UdmfRecord_Destroy(record2);
1505 OH_UdsArrayBuffer_Destroy(buffer2);
1506 }
1507
1508 /**
1509 * @tc.name: OH_Udmf_GetArrayBufferFromRecord001
1510 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1511 * @tc.type: FUNC
1512 */
1513 HWTEST_F(UDMFTest, OH_Udmf_GetArrayBufferFromRecord001, TestSize.Level0)
1514 {
1515 unsigned char data1[] = "Hello world";
1516 unsigned int len1 = sizeof(data1);
1517 OH_UdsArrayBuffer *buffer1 = OH_UdsArrayBuffer_Create();
1518 OH_UdsArrayBuffer_SetData(buffer1, data1, len1);
1519
1520 char type1[] = "ApplicationDefined-myType1";
1521 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1522 int buildRes = OH_UdmfRecord_AddArrayBuffer(record1, type1, buffer1);
1523 ASSERT_EQ(buildRes, UDMF_E_OK);
1524
1525 char type2[] = "ApplicationDefined-myType2";
1526 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1527 int getRes = OH_UdmfRecord_GetArrayBuffer(record1, type2, buffer2);
1528 EXPECT_EQ(getRes, UDMF_E_INVALID_PARAM);
1529
1530 int getRes2 = OH_UdmfRecord_GetArrayBuffer(record1, type1, buffer2);
1531 ASSERT_EQ(getRes2, UDMF_E_OK);
1532
1533 unsigned int getLen = 0;
1534 unsigned char *getData;
1535 int getRes3 = OH_UdsArrayBuffer_GetData(buffer2, &getData, &getLen);
1536 ASSERT_EQ(getRes3, UDMF_E_OK);
1537 ASSERT_EQ(len1, getLen);
1538 ASSERT_TRUE(CheckUnsignedChar(data1, getData, getLen));
1539
1540 OH_UdmfRecord_Destroy(record1);
1541 OH_UdsArrayBuffer_Destroy(buffer1);
1542 OH_UdsArrayBuffer_Destroy(buffer2);
1543 }
1544
1545 /**
1546 * @tc.name: OH_UdmfData_GetPrimaryPlainText001
1547 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1548 * @tc.type: FUNC
1549 */
1550 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText001, TestSize.Level1)
1551 {
1552 int result = OH_UdmfData_GetPrimaryPlainText(nullptr, nullptr);
1553 EXPECT_EQ(result, UDMF_E_INVALID_PARAM);
1554
1555 OH_UdmfData data;
1556 int result2 = OH_UdmfData_GetPrimaryPlainText(&data, nullptr);
1557 EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1558
1559 OH_UdmfData *data2 = OH_UdmfData_Create();
1560 int result3 = OH_UdmfData_GetPrimaryPlainText(data2, nullptr);
1561 EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1562
1563 OH_UdsPlainText plainText;
1564 int result4 = OH_UdmfData_GetPrimaryPlainText(data2, &plainText);
1565 EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1566
1567 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1568 int result5 = OH_UdmfData_GetPrimaryPlainText(data2, plainText2);
1569 EXPECT_EQ(result5, UDMF_ERR);
1570
1571 OH_UdsPlainText_Destroy(plainText2);
1572 OH_UdmfData_Destroy(data2);
1573 }
1574
1575 /**
1576 * @tc.name: OH_UdmfData_GetPrimaryPlainText002
1577 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1578 * @tc.type: FUNC
1579 */
1580 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText002, TestSize.Level1)
1581 {
1582 const char *helloWorld = "Hello world";
1583
1584 OH_UdmfData *data = OH_UdmfData_Create();
1585 OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1586 int result = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1587 EXPECT_EQ(result, UDMF_ERR);
1588
1589 OH_UdmfData *data2 = OH_UdmfData_Create();
1590 OH_UdsHtml *html = OH_UdsHtml_Create();
1591 OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1592 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1593 OH_UdmfRecord_AddHtml(record, html);
1594 OH_UdmfData_AddRecord(data2, record);
1595 int result2 = OH_UdmfData_GetPrimaryPlainText(data2, plainTextOutput);
1596 EXPECT_EQ(result2, UDMF_ERR);
1597
1598 OH_UdmfData *data3 = OH_UdmfData_Create();
1599 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1600 OH_UdsPlainText_SetContent(plainText, helloWorld);
1601 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1602 OH_UdmfRecord_AddPlainText(record2, plainText);
1603 OH_UdmfData_AddRecord(data3, record);
1604 OH_UdmfData_AddRecord(data3, record2);
1605 int result3 = OH_UdmfData_GetPrimaryPlainText(data3, plainTextOutput);
1606 ASSERT_EQ(result3, UDMF_E_OK);
1607 auto *content = OH_UdsPlainText_GetContent(plainTextOutput);
1608 EXPECT_EQ(strcmp(content, helloWorld), 0);
1609
1610 OH_UdsHtml_Destroy(html);
1611 OH_UdsPlainText_Destroy(plainTextOutput);
1612 OH_UdsPlainText_Destroy(plainText);
1613 OH_UdmfRecord_Destroy(record);
1614 OH_UdmfRecord_Destroy(record2);
1615 OH_UdmfData_Destroy(data);
1616 OH_UdmfData_Destroy(data2);
1617 OH_UdmfData_Destroy(data3);
1618 }
1619
1620 /**
1621 * @tc.name: OH_UdmfData_GetPrimaryPlainText003
1622 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1623 * @tc.type: FUNC
1624 */
1625 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText003, TestSize.Level1)
1626 {
1627 const char *helloWorld = "Hello world";
1628 const char *helloWorld2 = "Hello world2";
1629
1630 OH_UdsHtml *html = OH_UdsHtml_Create();
1631 OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1632 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1633 OH_UdmfRecord_AddHtml(record, html);
1634
1635 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1636 OH_UdsPlainText_SetContent(plainText, helloWorld);
1637 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1638 OH_UdmfRecord_AddPlainText(record2, plainText);
1639
1640 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1641 OH_UdsPlainText_SetContent(plainText2, helloWorld2);
1642 OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1643 OH_UdmfRecord_AddPlainText(record3, plainText2);
1644
1645 OH_UdmfData *data = OH_UdmfData_Create();
1646 OH_UdmfData_AddRecord(data, record3);
1647 OH_UdmfData_AddRecord(data, record2);
1648 OH_UdmfData_AddRecord(data, record);
1649 OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1650 int result4 = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1651 ASSERT_EQ(result4, UDMF_E_OK);
1652 auto *content2 = OH_UdsPlainText_GetContent(plainTextOutput);
1653 EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1654
1655 OH_UdsHtml_Destroy(html);
1656 OH_UdsPlainText_Destroy(plainTextOutput);
1657 OH_UdsPlainText_Destroy(plainText);
1658 OH_UdsPlainText_Destroy(plainText2);
1659 OH_UdmfRecord_Destroy(record);
1660 OH_UdmfRecord_Destroy(record2);
1661 OH_UdmfRecord_Destroy(record3);
1662 OH_UdmfData_Destroy(data);
1663 }
1664
1665 /**
1666 * @tc.name: OH_UdmfData_GetPrimaryHtml001
1667 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1668 * @tc.type: FUNC
1669 */
1670 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml001, TestSize.Level1)
1671 {
1672 int result1 = OH_UdmfData_GetPrimaryHtml(nullptr, nullptr);
1673 EXPECT_EQ(result1, UDMF_E_INVALID_PARAM);
1674
1675 OH_UdmfData data;
1676 int result2 = OH_UdmfData_GetPrimaryHtml(&data, nullptr);
1677 EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1678
1679 OH_UdmfData *data2 = OH_UdmfData_Create();
1680 int result3 = OH_UdmfData_GetPrimaryHtml(data2, nullptr);
1681 EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1682
1683 OH_UdsHtml html;
1684 int result4 = OH_UdmfData_GetPrimaryHtml(data2, &html);
1685 EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1686
1687 OH_UdsHtml *html2 = OH_UdsHtml_Create();
1688 int result5 = OH_UdmfData_GetPrimaryHtml(data2, html2);
1689 EXPECT_EQ(result5, UDMF_ERR);
1690
1691 OH_UdsHtml_Destroy(html2);
1692 OH_UdmfData_Destroy(data2);
1693 }
1694
1695 /**
1696 * @tc.name: OH_UdmfData_GetPrimaryHtml002
1697 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1698 * @tc.type: FUNC
1699 */
1700 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml002, TestSize.Level1)
1701 {
1702 const char *helloWorld = "<p>Hello world</p>";
1703
1704 OH_UdmfData *data = OH_UdmfData_Create();
1705 OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1706 int result = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1707 EXPECT_EQ(result, UDMF_ERR);
1708
1709 OH_UdmfData *data2 = OH_UdmfData_Create();
1710 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1711 OH_UdsPlainText_SetContent(plainText, "Hello world");
1712 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1713 OH_UdmfRecord_AddPlainText(record, plainText);
1714 OH_UdmfData_AddRecord(data2, record);
1715 int result2 = OH_UdmfData_GetPrimaryHtml(data2, htmlOutput);
1716 EXPECT_EQ(result2, UDMF_ERR);
1717
1718 OH_UdmfData *data3 = OH_UdmfData_Create();
1719 OH_UdsHtml *html = OH_UdsHtml_Create();
1720 OH_UdsHtml_SetContent(html, helloWorld);
1721 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1722 OH_UdmfRecord_AddHtml(record2, html);
1723 OH_UdmfData_AddRecord(data3, record);
1724 OH_UdmfData_AddRecord(data3, record2);
1725 int result3 = OH_UdmfData_GetPrimaryHtml(data3, htmlOutput);
1726 ASSERT_EQ(result3, UDMF_E_OK);
1727 auto content = OH_UdsHtml_GetContent(htmlOutput);
1728 EXPECT_EQ(strcmp(content, helloWorld), 0);
1729
1730 OH_UdsHtml_Destroy(html);
1731 OH_UdsHtml_Destroy(htmlOutput);
1732 OH_UdsPlainText_Destroy(plainText);
1733 OH_UdmfRecord_Destroy(record);
1734 OH_UdmfRecord_Destroy(record2);
1735 OH_UdmfData_Destroy(data);
1736 OH_UdmfData_Destroy(data2);
1737 OH_UdmfData_Destroy(data3);
1738 }
1739
1740 /**
1741 * @tc.name: OH_UdmfData_GetPrimaryHtml003
1742 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1743 * @tc.type: FUNC
1744 */
1745 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml003, TestSize.Level1)
1746 {
1747 const char *helloWorld = "<p>Hello world</p>";
1748 const char *helloWorld2 = "<p>Hello world2</p>";
1749
1750 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1751 OH_UdsPlainText_SetContent(plainText, "Hello world");
1752 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1753 OH_UdmfRecord_AddPlainText(record, plainText);
1754
1755 OH_UdsHtml *html = OH_UdsHtml_Create();
1756 OH_UdsHtml_SetContent(html, helloWorld);
1757 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1758 OH_UdmfRecord_AddHtml(record2, html);
1759
1760 OH_UdsHtml *html2 = OH_UdsHtml_Create();
1761 OH_UdsHtml_SetContent(html2, helloWorld2);
1762 OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1763 OH_UdmfRecord_AddHtml(record3, html2);
1764
1765 OH_UdmfData *data = OH_UdmfData_Create();
1766 OH_UdmfData_AddRecord(data, record3);
1767 OH_UdmfData_AddRecord(data, record2);
1768 OH_UdmfData_AddRecord(data, record);
1769 OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1770 int result4 = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1771 ASSERT_EQ(result4, UDMF_E_OK);
1772 auto content2 = OH_UdsHtml_GetContent(htmlOutput);
1773 EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1774
1775 OH_UdsHtml_Destroy(html);
1776 OH_UdsHtml_Destroy(html2);
1777 OH_UdsHtml_Destroy(htmlOutput);
1778 OH_UdsPlainText_Destroy(plainText);
1779 OH_UdmfRecord_Destroy(record);
1780 OH_UdmfRecord_Destroy(record2);
1781 OH_UdmfRecord_Destroy(record3);
1782 OH_UdmfData_Destroy(data);
1783 }
1784
1785 /**
1786 * @tc.name: OH_UdmfData_GetRecordCount001
1787 * @tc.desc: Normal testcase of OH_UdmfData_GetRecordCount
1788 * @tc.type: FUNC
1789 */
1790 HWTEST_F(UDMFTest, OH_UdmfData_GetRecordCount001, TestSize.Level1)
1791 {
1792 int result = OH_UdmfData_GetRecordCount(nullptr);
1793 EXPECT_EQ(result, 0);
1794
1795 OH_UdmfData data;
1796 int result2 = OH_UdmfData_GetRecordCount(&data);
1797 EXPECT_EQ(result2, 0);
1798
1799 OH_UdmfData *data2 = OH_UdmfData_Create();
1800 int result3 = OH_UdmfData_GetRecordCount(data2);
1801 EXPECT_EQ(result3, 0);
1802
1803 OH_UdmfData *data3 = OH_UdmfData_Create();
1804 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1805 OH_UdmfData_AddRecord(data3, record);
1806 int result4 = OH_UdmfData_GetRecordCount(data3);
1807 EXPECT_EQ(result4, 1);
1808
1809 OH_UdmfData *data4 = OH_UdmfData_Create();
1810 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1811 OH_UdmfData_AddRecord(data4, record);
1812 OH_UdmfData_AddRecord(data4, record2);
1813 int result5 = OH_UdmfData_GetRecordCount(data4);
1814 EXPECT_EQ(result5, 2);
1815
1816 OH_UdmfRecord_Destroy(record);
1817 OH_UdmfRecord_Destroy(record2);
1818 OH_UdmfData_Destroy(data2);
1819 OH_UdmfData_Destroy(data3);
1820 OH_UdmfData_Destroy(data4);
1821 }
1822
1823 /**
1824 * @tc.name: OH_UdmfData_GetRecord001
1825 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1826 * @tc.type: FUNC
1827 */
1828 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord001, TestSize.Level1)
1829 {
1830 OH_UdmfRecord *result = OH_UdmfData_GetRecord(nullptr, -1);
1831 EXPECT_EQ(result, nullptr);
1832
1833 OH_UdmfData data;
1834 OH_UdmfRecord *result2 = OH_UdmfData_GetRecord(&data, -1);
1835 EXPECT_EQ(result2, nullptr);
1836
1837 OH_UdmfRecord *result3 = OH_UdmfData_GetRecord(&data, 0);
1838 EXPECT_EQ(result3, nullptr);
1839
1840 OH_UdmfData *data2 = OH_UdmfData_Create();
1841 OH_UdmfRecord *result4 = OH_UdmfData_GetRecord(data2, -1);
1842 EXPECT_EQ(result4, nullptr);
1843
1844 OH_UdmfRecord *result5 = OH_UdmfData_GetRecord(data2, 0);
1845 EXPECT_EQ(result5, nullptr);
1846
1847 OH_UdmfRecord *result6 = OH_UdmfData_GetRecord(data2, 1);
1848 EXPECT_EQ(result6, nullptr);
1849
1850 OH_UdmfData *data3 = OH_UdmfData_Create();
1851 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1852 OH_UdmfData_AddRecord(data3, record);
1853 EXPECT_EQ(OH_UdmfData_GetRecordCount(data3), 1);
1854 OH_UdmfRecord *result7 = OH_UdmfData_GetRecord(data3, -1);
1855 EXPECT_EQ(result7, nullptr);
1856 OH_UdmfRecord *result8 = OH_UdmfData_GetRecord(data3, 1);
1857 EXPECT_EQ(result8, nullptr);
1858 OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1859 EXPECT_NE(result9, nullptr);
1860
1861 OH_UdmfRecord_Destroy(record);
1862 OH_UdmfData_Destroy(data2);
1863 OH_UdmfData_Destroy(data3);
1864 }
1865
1866 /**
1867 * @tc.name: OH_UdmfData_GetRecord002
1868 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1869 * @tc.type: FUNC
1870 */
1871 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord002, TestSize.Level1)
1872 {
1873 const char *helloWorld = "Hello world";
1874 const char *helloWorld2 = "Hello world2";
1875
1876 OH_UdmfData *data3 = OH_UdmfData_Create();
1877 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1878 OH_UdsPlainText_SetContent(plainText, helloWorld);
1879 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1880 OH_UdmfRecord_AddPlainText(record, plainText);
1881 OH_UdmfData_AddRecord(data3, record);
1882 OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1883 EXPECT_NE(result9, nullptr);
1884
1885 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1886 OH_UdmfRecord_GetPlainText(result9, plainText2);
1887 auto content = OH_UdsPlainText_GetContent(plainText2);
1888 EXPECT_EQ(strcmp(content, helloWorld), 0);
1889
1890 OH_UdmfData *data4 = OH_UdmfData_Create();
1891 OH_UdsPlainText *plainText3 = OH_UdsPlainText_Create();
1892 OH_UdsPlainText_SetContent(plainText3, helloWorld2);
1893 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1894 OH_UdmfRecord_AddPlainText(record2, plainText3);
1895 OH_UdmfData_AddRecord(data4, record);
1896 OH_UdmfData_AddRecord(data4, record2);
1897 OH_UdmfRecord *result10 = OH_UdmfData_GetRecord(data4, -1);
1898 EXPECT_EQ(result10, nullptr);
1899 OH_UdmfRecord *result11 = OH_UdmfData_GetRecord(data4, 2);
1900 EXPECT_EQ(result11, nullptr);
1901 OH_UdmfRecord *result12 = OH_UdmfData_GetRecord(data4, 0);
1902 ASSERT_NE(result12, nullptr);
1903 OH_UdsPlainText *plainText4 = OH_UdsPlainText_Create();
1904 OH_UdmfRecord_GetPlainText(result12, plainText4);
1905 auto content2 = OH_UdsPlainText_GetContent(plainText4);
1906 EXPECT_EQ(strcmp(content2, helloWorld), 0);
1907 OH_UdmfRecord *result13 = OH_UdmfData_GetRecord(data4, 1);
1908 ASSERT_NE(result13, nullptr);
1909 OH_UdsPlainText *plainText5 = OH_UdsPlainText_Create();
1910 OH_UdmfRecord_GetPlainText(result13, plainText5);
1911 auto content3 = OH_UdsPlainText_GetContent(plainText5);
1912 EXPECT_EQ(strcmp(content3, helloWorld2), 0);
1913
1914 OH_UdsPlainText_Destroy(plainText);
1915 OH_UdsPlainText_Destroy(plainText2);
1916 OH_UdmfRecord_Destroy(record);
1917 OH_UdmfRecord_Destroy(record2);
1918 OH_UdmfData_Destroy(data3);
1919 OH_UdmfData_Destroy(data4);
1920 }
1921
1922 /**
1923 * @tc.name: OH_UdmfData_IsLocal001
1924 * @tc.desc: Normal testcase of OH_UdmfData_IsLocal
1925 * @tc.type: FUNC
1926 */
1927 HWTEST_F(UDMFTest, OH_UdmfData_IsLocal001, TestSize.Level1)
1928 {
1929 bool result = OH_UdmfData_IsLocal(nullptr);
1930 EXPECT_EQ(result, true);
1931
1932 OH_UdmfData data;
1933 bool result2 = OH_UdmfData_IsLocal(&data);
1934 EXPECT_EQ(result2, true);
1935
1936 OH_UdmfData *data2 = OH_UdmfData_Create();
1937 bool result3 = OH_UdmfData_IsLocal(data2);
1938 EXPECT_EQ(result3, true);
1939
1940 OH_UdmfData_Destroy(data2);
1941 }
1942
1943 /**
1944 * @tc.name: FileUriTest001
1945 * @tc.desc: test fileUri between js and capi
1946 * @tc.type: FUNC
1947 */
1948 HWTEST_F(UDMFTest, FileUriTest001, TestSize.Level1)
1949 {
1950 std::string uri = "https://xxx/xx/xx.jpg";
1951 std::shared_ptr<Image> image = std::make_shared<Image>();
1952 image->SetUri(uri);
1953 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
1954 unifiedData->AddRecord(image);
1955 std::string key;
1956 CustomOption option = {
1957 .intention = UD_INTENTION_DRAG
1958 };
1959 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
1960 EXPECT_EQ(setRet, E_OK);
1961
1962 OH_UdmfData* udmfData = OH_UdmfData_Create();
1963 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
1964
1965 unsigned int dataTypeCount;
1966 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
1967 EXPECT_EQ(dataTypeCount, 2);
1968 EXPECT_NE(dataTypes, nullptr);
1969 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
1970 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1971
1972 unsigned int recordCount;
1973 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
1974 EXPECT_EQ(recordCount, 1);
1975 EXPECT_NE(records, nullptr);
1976
1977 for (unsigned int idx = 0; idx < recordCount; ++idx) {
1978 unsigned int recordTypeCount;
1979 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
1980 EXPECT_EQ(recordTypeCount, 2);
1981 EXPECT_NE(recordTypes, nullptr);
1982 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_IMAGE), 0);
1983 EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1984 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
1985 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
1986 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
1987 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
1988 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
1989 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
1990 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
1991 }
1992 }
1993 }
1994 }
1995
1996 /**
1997 * @tc.name: FileUriTest007
1998 * @tc.desc: test fileUri between js and capi
1999 * @tc.type: FUNC
2000 */
2001 HWTEST_F(UDMFTest, FileUriTest007, TestSize.Level1)
2002 {
2003 std::string uri = "https://xxx/xx/xx.jpg";
2004
2005 std::shared_ptr<Object> obj = std::make_shared<Object>();
2006 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2007 obj->value_[FILE_URI_PARAM] = uri;
2008 obj->value_[FILE_TYPE] = "general.img";
2009 auto record = std::make_shared<UnifiedRecord>(UDType::VIDEO, obj);
2010 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2011 unifiedData->AddRecord(record);
2012 std::string key;
2013 CustomOption option = {
2014 .intention = UD_INTENTION_DRAG
2015 };
2016 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2017 EXPECT_EQ(setRet, E_OK);
2018
2019 OH_UdmfData* udmfData = OH_UdmfData_Create();
2020 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2021
2022 unsigned int dataTypeCount;
2023 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2024 EXPECT_EQ(dataTypeCount, 2);
2025 EXPECT_NE(dataTypes, nullptr);
2026 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2027 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2028
2029 unsigned int recordCount;
2030 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2031 EXPECT_EQ(recordCount, 1);
2032 EXPECT_NE(records, nullptr);
2033
2034 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2035 unsigned int recordTypeCount;
2036 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2037 EXPECT_EQ(recordTypeCount, 2);
2038 EXPECT_NE(recordTypes, nullptr);
2039 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_VIDEO), 0);
2040 EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2041 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2042 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2043 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2044 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2045 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2046 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2047 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2048 }
2049 }
2050 }
2051 }
2052
2053 /**
2054 * @tc.name: OH_Udmf_SetAndGetUnifiedData006
2055 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2056 * @tc.type: FUNC
2057 */
2058 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData006, TestSize.Level1)
2059 {
2060 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2061 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2062 OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
2063 unsigned char thumbData[] = {0, 1, 2, 3, 4};
2064 OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
2065 OH_UdsContentForm_SetDescription(contentForm, "description");
2066 OH_UdmfRecord_AddContentForm(record, contentForm);
2067 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2068 Udmf_Intention intention = UDMF_INTENTION_DRAG;
2069 char key[UDMF_KEY_BUFFER_LEN];
2070
2071 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2072 EXPECT_EQ(setRes, UDMF_E_OK);
2073 EXPECT_NE(key[0], '\0');
2074 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2075 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2076 EXPECT_EQ(getRes, UDMF_E_OK);
2077 unsigned int count = 0;
2078 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2079 EXPECT_EQ(count, 1);
2080 OH_UdsContentForm *getContentForm = OH_UdsContentForm_Create();
2081 OH_UdmfRecord_GetContentForm(getRecords[0], getContentForm);
2082 EXPECT_EQ("description", std::string(OH_UdsContentForm_GetDescription(getContentForm)));
2083
2084 unsigned char *readThumbData;
2085 unsigned int thumbDataLen = 0;
2086 OH_UdsContentForm_GetThumbData(getContentForm, &readThumbData, &thumbDataLen);
2087 ASSERT_EQ(5, thumbDataLen);
2088 ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
2089
2090 OH_UdsContentForm_Destroy(contentForm);
2091 OH_UdmfRecord_Destroy(record);
2092 OH_UdmfData_Destroy(udmfUnifiedData);
2093
2094 OH_UdsContentForm_Destroy(getContentForm);
2095 OH_UdmfData_Destroy(readUnifiedData);
2096 }
2097 }
2098