1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #define LOG_TAG "UDMFTEST"
17 #include <gtest/gtest.h>
18 #include "token_setproc.h"
19 #include "accesstoken_kit.h"
20 #include "directory_ex.h"
21 #include "nativetoken_kit.h"
22 #include <unistd.h>
23 #include <memory>
24 #include "udmf.h"
25 #include "uds.h"
26 #include "udmf_err_code.h"
27 #include "unified_data.h"
28 #include "unified_record.h"
29 #include "udmf_capi_common.h"
30 #include "udmf_client.h"
31 #include "plain_text.h"
32 #include "udmf_meta.h"
33 #include "data_provider_impl.h"
34 #include "image.h"
35 #include "audio.h"
36 #include "file.h"
37 #include "folder.h"
38 #include "video.h"
39 #include "logger.h"
40
41 using namespace testing::ext;
42 using namespace OHOS::Security::AccessToken;
43 using namespace OHOS::UDMF;
44
45 namespace OHOS::Test {
46 static constexpr uint64_t MAX_TYPES_COUNT = 10 * 1024;
47 class UDMFTest : public testing::Test {
48 public:
49 static void SetUpTestCase(void);
50 static void TearDownTestCase(void);
51 void SetUp();
52 void TearDown();
53 static void AllocHapToken1();
54 static void AllocHapToken2();
55 void SetHapToken1();
56 void SetHapToken2();
57 bool CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size);
58 static void FinalizeFunc(void* context);
59 static void* GetDataCallbackFunc(void* context, const char* type);
60 static constexpr int USER_ID = 100;
61 static constexpr int INST_INDEX = 0;
62 int64_t CountTime();
63 };
64
SetUpTestCase()65 void UDMFTest::SetUpTestCase()
66 {
67 AllocHapToken1();
68 AllocHapToken2();
69 }
70
TearDownTestCase()71 void UDMFTest::TearDownTestCase()
72 {
73 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
74 AccessTokenKit::DeleteToken(tokenId);
75 tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
76 AccessTokenKit::DeleteToken(tokenId);
77 }
78
SetUp()79 void UDMFTest::SetUp()
80 {
81 SetHapToken1();
82 }
83
TearDown()84 void UDMFTest::TearDown()
85 {
86 }
87
AllocHapToken1()88 void UDMFTest::AllocHapToken1()
89 {
90 HapInfoParams info = {
91 .userID = USER_ID,
92 .bundleName = "ohos.test.demo1",
93 .instIndex = INST_INDEX,
94 .appIDDesc = "ohos.test.demo1"
95 };
96
97 HapPolicyParams policy = {
98 .apl = APL_NORMAL,
99 .domain = "test.domain",
100 .permList = {
101 {
102 .permissionName = "ohos.permission.test",
103 .bundleName = "ohos.test.demo1",
104 .grantMode = 1,
105 .availableLevel = APL_NORMAL,
106 .label = "label",
107 .labelId = 1,
108 .description = "test1",
109 .descriptionId = 1
110 }
111 },
112 .permStateList = {
113 {
114 .permissionName = "ohos.permission.test",
115 .isGeneral = true,
116 .resDeviceID = { "local" },
117 .grantStatus = { PermissionState::PERMISSION_GRANTED },
118 .grantFlags = { 1 }
119 }
120 }
121 };
122 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
123 SetSelfTokenID(tokenID.tokenIDEx);
124 }
125
AllocHapToken2()126 void UDMFTest::AllocHapToken2()
127 {
128 HapInfoParams info = {
129 .userID = USER_ID,
130 .bundleName = "ohos.test.demo2",
131 .instIndex = INST_INDEX,
132 .appIDDesc = "ohos.test.demo2"
133 };
134
135 HapPolicyParams policy = {
136 .apl = APL_NORMAL,
137 .domain = "test.domain",
138 .permList = {
139 {
140 .permissionName = "ohos.permission.test",
141 .bundleName = "ohos.test.demo2",
142 .grantMode = 1,
143 .availableLevel = APL_NORMAL,
144 .label = "label",
145 .labelId = 1,
146 .description = "test2",
147 .descriptionId = 1
148 }
149 },
150 .permStateList = {
151 {
152 .permissionName = "ohos.permission.test",
153 .isGeneral = true,
154 .resDeviceID = { "local" },
155 .grantStatus = { PermissionState::PERMISSION_GRANTED },
156 .grantFlags = { 1 }
157 }
158 }
159 };
160 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
161 SetSelfTokenID(tokenID.tokenIDEx);
162 }
163
SetHapToken1()164 void UDMFTest::SetHapToken1()
165 {
166 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
167 SetSelfTokenID(tokenId);
168 }
169
SetHapToken2()170 void UDMFTest::SetHapToken2()
171 {
172 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
173 SetSelfTokenID(tokenId);
174 }
175
CheckUnsignedChar(unsigned char * dst,unsigned char * src,int size)176 bool UDMFTest::CheckUnsignedChar(unsigned char* dst, unsigned char* src, int size)
177 {
178 EXPECT_NE(dst, nullptr);
179 EXPECT_NE(src, nullptr);
180 for (int i = 0; i < size; ++i) {
181 if (dst[i] != src[i]) {
182 return false;
183 }
184 }
185 return true;
186 }
187
FinalizeFunc(void * context)188 void UDMFTest::FinalizeFunc(void* context) {}
189
GetDataCallbackFunc(void * context,const char * type)190 void* UDMFTest::GetDataCallbackFunc(void* context, const char* type)
191 {
192 auto plainText = OH_UdsPlainText_Create();
193 OH_UdsPlainText_SetAbstract(plainText, "doing something");
194 OH_UdsPlainText_SetContent(plainText, "doing something");
195 return plainText;
196 }
197
CountTime()198 int64_t UDMFTest::CountTime()
199 {
200 return std::chrono::duration_cast<std::chrono::milliseconds>(
201 std::chrono::system_clock::now().time_since_epoch()).count();
202 }
203
204 /**
205 * @tc.name: OH_Udmf_CreateUnifiedData001
206 * @tc.desc: test OH_UdmfData_Create
207 * @tc.type: FUNC
208 */
209 HWTEST_F(UDMFTest, OH_Udmf_CreateUnifiedData001, TestSize.Level0)
210 {
211 OH_UdmfData *unifiedData = OH_UdmfData_Create();
212 EXPECT_NE(unifiedData, nullptr);
213 EXPECT_NE(unifiedData->unifiedData_, nullptr);
214 OH_UdmfData_Destroy(unifiedData);
215 }
216
217 /**
218 * @tc.name: OH_Udmf_AddRecordToUnifiedData001
219 * @tc.desc: OH_UdmfData_AddRecord with return UDMF_E_INVALID_PARAM
220 * @tc.type: FUNC
221 */
222 HWTEST_F(UDMFTest, OH_Udmf_AddRecordToUnifiedData001, TestSize.Level0)
223 {
224 OH_UdmfRecord *record = OH_UdmfRecord_Create();
225 OH_UdmfData *unifiedData = OH_UdmfData_Create();
226
227 int invalidRes1 = OH_UdmfData_AddRecord(nullptr, record);
228 EXPECT_EQ(invalidRes1, UDMF_E_INVALID_PARAM);
229
230 OH_UdmfData unifiedData1;
231 int invalidRes2 = OH_UdmfData_AddRecord(&unifiedData1, record);
232 EXPECT_EQ(invalidRes2, UDMF_E_INVALID_PARAM);
233
234 int invalidRes3 = OH_UdmfData_AddRecord(unifiedData, nullptr);
235 EXPECT_EQ(invalidRes3, UDMF_E_INVALID_PARAM);
236
237 OH_UdmfRecord unifiedRecord1;
238 int invalidRes4 = OH_UdmfData_AddRecord(unifiedData, nullptr);
239 EXPECT_EQ(invalidRes4, UDMF_E_INVALID_PARAM);
240 OH_UdmfRecord_Destroy(record);
241 OH_UdmfData_Destroy(unifiedData);
242 }
243
244 /**
245 * @tc.name: OH_Udmf_AddRecordToUnifiedData002
246 * @tc.desc: OH_UdmfData_AddRecord with return UDMF_E_OK
247 * @tc.type: FUNC
248 */
249 HWTEST_F(UDMFTest, OH_Udmf_AddRecordToUnifiedData002, TestSize.Level0)
250 {
251 OH_UdmfRecord *record = OH_UdmfRecord_Create();
252 OH_UdmfData *unifiedData = OH_UdmfData_Create();
253 int status = OH_UdmfData_AddRecord(unifiedData, record);
254 EXPECT_EQ(status, UDMF_E_OK);
255
256 OH_UdmfRecord_Destroy(record);
257 OH_UdmfData_Destroy(unifiedData);
258 }
259
260 /**
261 * @tc.name: OH_Udmf_HasUnifiedDataType001
262 * @tc.desc: OH_UdmfData_HasType with return UDMF_E_INVALID_PARAM
263 * @tc.type: FUNC
264 */
265 HWTEST_F(UDMFTest, OH_Udmf_HasUnifiedDataType001, TestSize.Level0)
266 {
267 OH_UdmfData *unifiedData = OH_UdmfData_Create();
268 char type[] = "general.plain-text";
269
270 bool status1 = OH_UdmfData_HasType(nullptr, type);
271 EXPECT_FALSE(status1);
272
273 bool status2 = OH_UdmfData_HasType(unifiedData, nullptr);
274 EXPECT_FALSE(status2);
275
276 OH_UdmfData unifiedData1;
277 bool status3 = OH_UdmfData_HasType(&unifiedData1, nullptr);
278 EXPECT_FALSE(status3);
279
280 bool status4 = OH_UdmfData_HasType(nullptr, nullptr);
281 EXPECT_FALSE(status4);
282
283 OH_UdmfData_Destroy(unifiedData);
284 }
285
286 /**
287 * @tc.name: OH_Udmf_HasUnifiedDataType002
288 * @tc.desc: OH_UdmfData_HasType with return whether has type, number 1 represent true, number 0 represent false
289 * @tc.type: FUNC
290 */
291 HWTEST_F(UDMFTest, OH_Udmf_HasUnifiedDataType002, TestSize.Level0)
292 {
293 OH_UdmfData *unifiedData = OH_UdmfData_Create();
294 OH_UdmfRecord *record = OH_UdmfRecord_Create();
295 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
296 OH_UdmfRecord_AddPlainText(record, plainText);
297 OH_UdmfData_AddRecord(unifiedData, record);
298
299 char type1[] = "general.plain-text";
300 int hasType1 = OH_UdmfData_HasType(unifiedData, type1);
301 EXPECT_EQ(hasType1, 1);
302
303 char type2[] = "general.html";
304 int hasType2 = OH_UdmfData_HasType(unifiedData, type2);
305 EXPECT_EQ(hasType2, 0);
306
307 OH_UdsPlainText_Destroy(plainText);
308 OH_UdmfRecord_Destroy(record);
309 OH_UdmfData_Destroy(unifiedData);
310 }
311
312 /**
313 * @tc.name: OH_Udmf_GetUnifiedDataTypes001
314 * @tc.desc: OH_UdmfData_GetTypes with invalid params
315 * @tc.type: FUNC
316 */
317 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataTypes001, TestSize.Level0)
318 {
319 OH_UdmfData *unifiedData = OH_UdmfData_Create();
320
321 unsigned int count1 = 0;
322 char **types1 = OH_UdmfData_GetTypes(nullptr, &count1);
323 EXPECT_EQ(types1, nullptr);
324
325 OH_UdmfData data;
326 char **types2 = OH_UdmfData_GetTypes(&data, &count1);
327 EXPECT_EQ(types2, nullptr);
328
329 char **types3 = OH_UdmfData_GetTypes(unifiedData, nullptr);
330 EXPECT_EQ(types3, nullptr);
331
332 OH_UdmfData_Destroy(unifiedData);
333 }
334
335 /**
336 * @tc.name: OH_Udmf_GetUnifiedDataTypes002
337 * @tc.desc: OH_UdmfData_GetTypes with valid params
338 * @tc.type: FUNC
339 */
340 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataTypes002, TestSize.Level0)
341 {
342 OH_UdmfData *unifiedData = OH_UdmfData_Create();
343 OH_UdmfRecord *record = OH_UdmfRecord_Create();
344 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
345 OH_UdmfRecord_AddPlainText(record, plainText);
346 OH_UdmfData_AddRecord(unifiedData, record);
347 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
348 OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
349 OH_UdmfRecord_AddHyperlink(record1, hyperlink);
350 OH_UdmfData_AddRecord(unifiedData, record1);
351
352 unsigned int count1 = 0;
353 char **types1 = OH_UdmfData_GetTypes(unifiedData, &count1);
354 EXPECT_NE(types1, nullptr);
355 EXPECT_EQ(count1, 2);
356
357 char **types2 = OH_UdmfData_GetTypes(unifiedData, &count1);
358 EXPECT_EQ(types1, types2);
359
360 OH_UdsPlainText_Destroy(plainText);
361 OH_UdsHyperlink_Destroy(hyperlink);
362 OH_UdmfRecord_Destroy(record);
363 OH_UdmfData_Destroy(unifiedData);
364 }
365
366 /**
367 * @tc.name: OH_Udmf_GetUnifiedRecordTypes001
368 * @tc.desc: OH_UdmfRecord_GetTypes with invalid params
369 * @tc.type: FUNC
370 */
371 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedRecordTypes001, TestSize.Level0)
372 {
373 OH_UdmfRecord *record = OH_UdmfRecord_Create();
374 unsigned int count = 0;
375 char **types1 = OH_UdmfRecord_GetTypes(nullptr, &count);
376 EXPECT_EQ(types1, nullptr);
377
378 char **types2 = OH_UdmfRecord_GetTypes(record, nullptr);
379 EXPECT_EQ(types2, nullptr);
380
381 OH_UdmfRecord recordCp;
382 char **types3 = OH_UdmfRecord_GetTypes(&recordCp, nullptr);
383 EXPECT_EQ(types3, nullptr);
384
385 OH_UdmfRecord_Destroy(record);
386 }
387
388 /**
389 * @tc.name: OH_Udmf_GetUnifiedRecordTypes002
390 * @tc.desc: OH_UdmfRecord_GetTypes with valid params
391 * @tc.type: FUNC
392 */
393 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedRecordTypes002, TestSize.Level0)
394 {
395 OH_UdmfRecord *record = OH_UdmfRecord_Create();
396 OH_UdsPlainText *plaintext = OH_UdsPlainText_Create();
397 OH_UdmfRecord_AddPlainText(record, plaintext);
398 unsigned int count = 0;
399 char **types1 = OH_UdmfRecord_GetTypes(record, &count);
400 EXPECT_NE(types1, nullptr);
401 EXPECT_EQ(count, 1);
402
403 char **types2 = OH_UdmfRecord_GetTypes(record, &count);
404 EXPECT_NE(types2, nullptr);
405 EXPECT_EQ(count, 1);
406 EXPECT_EQ(types2, types1);
407
408 OH_UdsPlainText_Destroy(plaintext);
409 OH_UdmfRecord_Destroy(record);
410 }
411
412 /**
413 * @tc.name: OH_Udmf_GetRecords001
414 * @tc.desc: OH_UdmfRecord_GetTypes with invalid params
415 * @tc.type: FUNC
416 */
417 HWTEST_F(UDMFTest, OH_Udmf_GetRecords001, TestSize.Level0)
418 {
419 OH_UdmfData *unifiedData = OH_UdmfData_Create();
420
421 unsigned int count1 = 0;
422 OH_UdmfRecord **records1 = OH_UdmfData_GetRecords(nullptr, &count1);
423 EXPECT_EQ(records1, nullptr);
424
425 OH_UdmfData data;
426 OH_UdmfRecord **records2 = OH_UdmfData_GetRecords(&data, &count1);
427 EXPECT_EQ(records2, nullptr);
428
429 OH_UdmfRecord **records3 = OH_UdmfData_GetRecords(unifiedData, nullptr);
430 EXPECT_EQ(records3, nullptr);
431
432 OH_UdmfData_Destroy(unifiedData);
433 }
434
435 /**
436 * @tc.name: OH_Udmf_GetRecords002
437 * @tc.desc: OH_UdmfRecord_GetTypes with valid params
438 * @tc.type: FUNC
439 */
440 HWTEST_F(UDMFTest, OH_Udmf_GetRecords002, TestSize.Level0)
441 {
442 OH_UdmfData *unifiedData = OH_UdmfData_Create();
443 OH_UdmfRecord *record = OH_UdmfRecord_Create();
444 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
445 OH_UdmfRecord_AddPlainText(record, plainText);
446 OH_UdmfData_AddRecord(unifiedData, record);
447 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
448 OH_UdsHyperlink *hyperlink = OH_UdsHyperlink_Create();
449 OH_UdmfRecord_AddHyperlink(record1, hyperlink);
450 OH_UdmfData_AddRecord(unifiedData, record1);
451
452 unsigned int count = 0;
453 OH_UdmfRecord **records1 = OH_UdmfData_GetRecords(unifiedData, &count);
454 EXPECT_EQ(count, 2);
455 EXPECT_NE(records1, nullptr);
456
457 OH_UdmfRecord **records2 = OH_UdmfData_GetRecords(unifiedData, &count);
458 EXPECT_EQ(count, 2);
459 EXPECT_NE(records2, nullptr);
460 EXPECT_EQ(records2, records1);
461
462 OH_UdsPlainText_Destroy(plainText);
463 OH_UdsHyperlink_Destroy(hyperlink);
464 OH_UdmfRecord_Destroy(record);
465 OH_UdmfRecord_Destroy(record1);
466 OH_UdmfData_Destroy(unifiedData);
467 }
468
469 /**
470 * @tc.name: OH_Udmf_SetUnifiedData001
471 * @tc.desc: OH_Udmf_SetUnifiedData with invalid param
472 * @tc.type: FUNC
473 */
474 HWTEST_F(UDMFTest, UdmfTest006, TestSize.Level0)
475 {
476 Udmf_Intention intention = UDMF_INTENTION_DRAG;
477 int setRes1 = OH_Udmf_SetUnifiedData(intention, nullptr, nullptr, 0);
478 EXPECT_EQ(setRes1, UDMF_E_INVALID_PARAM);
479
480 OH_UdmfData unifiedData;
481 int setRes2 = OH_Udmf_SetUnifiedData(intention, &unifiedData, nullptr, 0);
482 EXPECT_EQ(setRes2, UDMF_E_INVALID_PARAM);
483
484 OH_UdmfData *unifiedData1 = OH_UdmfData_Create();
485 int setRes3 = OH_Udmf_SetUnifiedData(intention, unifiedData1, nullptr, 0);
486 EXPECT_EQ(setRes3, UDMF_E_INVALID_PARAM);
487
488 char key[] = "key";
489 int setRes4 = OH_Udmf_SetUnifiedData(intention, unifiedData1, key, 0);
490 EXPECT_EQ(setRes4, UDMF_E_INVALID_PARAM);
491
492 intention = static_cast<Udmf_Intention>(10);
493 int setRes5 = OH_Udmf_SetUnifiedData(intention, unifiedData1, key, UDMF_KEY_BUFFER_LEN);
494 EXPECT_EQ(setRes5, UDMF_E_INVALID_PARAM);
495
496 OH_UdmfData_Destroy(unifiedData1);
497 }
498
499 /**
500 * @tc.name: OH_Udmf_GetUnifiedData001
501 * @tc.desc: OH_Udmf_GetUnifiedData with invalid param
502 * @tc.type: FUNC
503 */
504 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedData001, TestSize.Level0)
505 {
506 Udmf_Intention intention = UDMF_INTENTION_DRAG;
507 int getRes1 = OH_Udmf_GetUnifiedData(nullptr, intention, nullptr);
508 EXPECT_EQ(getRes1, UDMF_E_INVALID_PARAM);
509
510 OH_UdmfData unifiedData;
511 int getRes2 = OH_Udmf_GetUnifiedData(nullptr, intention, &unifiedData);
512 EXPECT_EQ(getRes2, UDMF_E_INVALID_PARAM);
513
514 OH_UdmfData *unifiedData1 = OH_UdmfData_Create();
515 int getRes3 = OH_Udmf_GetUnifiedData(nullptr, intention, unifiedData1);
516 EXPECT_EQ(getRes3, UDMF_E_INVALID_PARAM);
517
518 int getRes4 = OH_Udmf_GetUnifiedData("KEY", UDMF_INTENTION_PASTEBOARD, unifiedData1);
519 EXPECT_EQ(getRes4, UDMF_E_INVALID_PARAM);
520
521 OH_UdmfData_Destroy(unifiedData1);
522 }
523
524 /**
525 * @tc.name: OH_Udmf_SetAndGetUnifiedData001
526 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with valid param
527 * @tc.type: FUNC
528 */
529 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData001, TestSize.Level0)
530 {
531 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
532 OH_UdmfRecord *record = OH_UdmfRecord_Create();
533 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
534 char content[] = "hello world";
535 OH_UdsPlainText_SetContent(plainText, content);
536 OH_UdmfRecord_AddPlainText(record, plainText);
537 OH_UdmfData_AddRecord(udmfUnifiedData, record);
538 Udmf_Intention intention = UDMF_INTENTION_DRAG;
539 char key[UDMF_KEY_BUFFER_LEN];
540
541 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
542 EXPECT_EQ(setRes, UDMF_E_OK);
543 EXPECT_NE(key[0], '\0');
544 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
545 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
546 EXPECT_EQ(getRes, UDMF_E_OK);
547 unsigned int count = 0;
548 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
549 EXPECT_EQ(count, 1);
550 OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
551 OH_UdmfRecord_GetPlainText(getRecords[0], getPlainText);
552 const char *getContent = OH_UdsPlainText_GetContent(getPlainText);
553 EXPECT_EQ(strcmp(getContent, content), 0);
554
555 OH_UdsPlainText_Destroy(plainText);
556 OH_UdmfRecord_Destroy(record);
557 OH_UdmfData_Destroy(udmfUnifiedData);
558
559 OH_UdsPlainText_Destroy(getPlainText);
560 OH_UdmfData_Destroy(readUnifiedData);
561 }
562
563 /**
564 * @tc.name: OH_Udmf_SetAndGetUnifiedData002
565 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with valid param
566 * @tc.type: FUNC
567 */
568 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData002, TestSize.Level0)
569 {
570 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
571 char typeId[] = "ApplicationDefined-myType";
572 unsigned char entry[] = "CreateGeneralRecord";
573 unsigned int count = sizeof(entry);
574 OH_UdmfRecord *record = OH_UdmfRecord_Create();
575 int setRes = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
576 EXPECT_EQ(setRes, UDMF_E_OK);
577 setRes = OH_UdmfData_AddRecord(udmfUnifiedData, record);
578 EXPECT_EQ(setRes, UDMF_E_OK);
579 Udmf_Intention intention = UDMF_INTENTION_DRAG;
580 char key[UDMF_KEY_BUFFER_LEN];
581
582 setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
583 EXPECT_EQ(setRes, UDMF_E_OK);
584 EXPECT_NE(key[0], '\0');
585 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
586 int getUnifiedDataRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
587 EXPECT_EQ(getUnifiedDataRes, UDMF_E_OK);
588 unsigned int getRecordsCount = 0;
589 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &getRecordsCount);
590 EXPECT_EQ(getRecordsCount, 1);
591 EXPECT_NE(getRecords, nullptr);
592
593 OH_UdmfRecord_Destroy(record);
594 OH_UdmfData_Destroy(readUnifiedData);
595 OH_UdmfData_Destroy(udmfUnifiedData);
596 }
597
598 /**
599 * @tc.name: OH_Udmf_CreateUnifiedRecord001
600 * @tc.desc: OH_Udmf_CreateUnifiedRecord001
601 * @tc.type: FUNC
602 */
603 HWTEST_F(UDMFTest, OH_Udmf_CreateUnifiedRecord001, TestSize.Level0)
604 {
605 OH_UdmfRecord *record = OH_UdmfRecord_Create();
606 EXPECT_NE(record, nullptr);
607 EXPECT_NE(record->record_, nullptr);
608 OH_UdmfRecord_Destroy(record);
609 }
610
611 /**
612 * @tc.name: OH_Udmf_AddGeneralEntry001
613 * @tc.desc: test OH_UdmfRecord_AddGeneralEntry with invalid param
614 * @tc.type: FUNC
615 */
616 HWTEST_F(UDMFTest, OH_Udmf_AddGeneralEntry001, TestSize.Level0)
617 {
618 int addRes1 = OH_UdmfRecord_AddGeneralEntry(nullptr, nullptr, nullptr, 0);
619 EXPECT_EQ(addRes1, UDMF_E_INVALID_PARAM);
620
621 OH_UdmfRecord record1;
622 int addRes2 = OH_UdmfRecord_AddGeneralEntry(&record1, nullptr, nullptr, 0);
623 EXPECT_EQ(addRes2, UDMF_E_INVALID_PARAM);
624
625 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
626 int addRes3 = OH_UdmfRecord_AddGeneralEntry(record2, nullptr, nullptr, 0);
627 EXPECT_EQ(addRes3, UDMF_E_INVALID_PARAM);
628
629 char typeId[] = "general.plain-text";
630 int addRes4 = OH_UdmfRecord_AddGeneralEntry(record2, typeId, nullptr, 0);
631 EXPECT_EQ(addRes4, UDMF_E_INVALID_PARAM);
632
633 OH_UdmfRecord_Destroy(record2);
634 }
635
636 /**
637 * @tc.name: OH_Udmf_GetGeneralEntry001
638 * @tc.desc: test OH_UdmfRecord_GetGeneralEntry with invalid param
639 * @tc.type: FUNC
640 */
641 HWTEST_F(UDMFTest, OH_Udmf_GetGeneralEntry001, TestSize.Level0)
642 {
643 int addRes1 = OH_UdmfRecord_GetGeneralEntry(nullptr, nullptr, nullptr, 0);
644 EXPECT_EQ(addRes1, UDMF_E_INVALID_PARAM);
645
646 OH_UdmfRecord record1;
647 int addRes2 = OH_UdmfRecord_GetGeneralEntry(&record1, nullptr, nullptr, 0);
648 EXPECT_EQ(addRes2, UDMF_E_INVALID_PARAM);
649
650 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
651 int addRes3 = OH_UdmfRecord_GetGeneralEntry(record2, nullptr, nullptr, 0);
652 EXPECT_EQ(addRes3, UDMF_E_INVALID_PARAM);
653
654 char typeId[] = "general.plain-text";
655 int addRes4 = OH_UdmfRecord_GetGeneralEntry(record2, typeId, nullptr, 0);
656 EXPECT_EQ(addRes4, UDMF_E_INVALID_PARAM);
657 OH_UdmfRecord_Destroy(record2);
658 }
659
660 /**
661 * @tc.name: OH_Udmf_AddAndGetGeneralEntry002
662 * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with valid param
663 * @tc.type: FUNC
664 */
665 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry002, TestSize.Level0)
666 {
667 char typeId[] = "general.plain-text-1";
668 unsigned char entry[] = "CreateGeneralRecord";
669 unsigned int count = sizeof(entry);
670 OH_UdmfRecord *record = OH_UdmfRecord_Create();
671 int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
672 EXPECT_EQ(addRes1, UDMF_E_OK);
673 }
674
675 /**
676 * @tc.name: OH_Udmf_AddAndGetGeneralEntry003
677 * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with appdefined type
678 * @tc.type: FUNC
679 * @tc.require:
680 */
681 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry003, TestSize.Level0)
682 {
683 char typeId[] = "ApplicationDefined-myType";
684 unsigned char entry[] = "CreateGeneralRecord1";
685 unsigned int count = sizeof(entry);
686 OH_UdmfRecord *record = OH_UdmfRecord_Create();
687 int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId, entry, count);
688 EXPECT_EQ(addRes1, UDMF_E_OK);
689
690 unsigned int getCount = 0;
691 unsigned char *getEntry;
692 int getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId, &getEntry, &getCount);
693 EXPECT_EQ(getRes, UDMF_E_OK);
694 EXPECT_EQ(getCount, count);
695 ASSERT_TRUE(CheckUnsignedChar(entry, getEntry, getCount));
696 OH_UdmfRecord_Destroy(record);
697 }
698
699 /**
700 * @tc.name: OH_Udmf_AddAndGetGeneralEntry004
701 * @tc.desc: test OH_UdmfRecord_AddGeneralEntry and OH_UdmfRecord_GetGeneralEntry with appdefined diff types
702 * @tc.type: FUNC
703 * @tc.require:
704 */
705 HWTEST_F(UDMFTest, OH_Udmf_AddAndGetGeneralEntry004, TestSize.Level0)
706 {
707 char typeId1[] = "ApplicationDefined-myType1";
708 unsigned char entry1[] = "CreateGeneralRecord1";
709 unsigned int count1 = sizeof(entry1);
710 char typeId2[] = "ApplicationDefined-myType2";
711 unsigned char entry2[] = "CreateGeneralRecord2";
712 unsigned int count2 = sizeof(entry2);
713 OH_UdmfRecord *record = OH_UdmfRecord_Create();
714 int addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId1, entry1, count1);
715 EXPECT_EQ(addRes1, UDMF_E_OK);
716 addRes1 = OH_UdmfRecord_AddGeneralEntry(record, typeId2, entry2, count2);
717 EXPECT_EQ(addRes1, UDMF_E_OK);
718
719 unsigned int getCount1 = 0;
720 unsigned char *getEntry1;
721 int getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId1, &getEntry1, &getCount1);
722 EXPECT_EQ(getRes, UDMF_E_OK);
723 EXPECT_EQ(getCount1, count1);
724 ASSERT_TRUE(CheckUnsignedChar(entry1, getEntry1, getCount1));
725
726 unsigned int getCount2 = 0;
727 unsigned char *getEntry2;
728 getRes = OH_UdmfRecord_GetGeneralEntry(record, typeId2, &getEntry2, &getCount2);
729 EXPECT_EQ(getRes, UDMF_E_OK);
730 EXPECT_EQ(getCount2, count2);
731 ASSERT_TRUE(CheckUnsignedChar(entry2, getEntry2, getCount2));
732
733 OH_UdmfRecord_Destroy(record);
734 }
735
736 /**
737 * @tc.name: OH_Udmf_BuildRecordByPlainText001
738 * @tc.desc: test OH_UdmfRecord_AddPlainText with invalid param
739 * @tc.type: FUNC
740 */
741 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByPlainText001, TestSize.Level0)
742 {
743 int buildRes1 = OH_UdmfRecord_AddPlainText(nullptr, nullptr);
744 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
745
746 OH_UdmfRecord record1;
747 int buildRes2 = OH_UdmfRecord_AddPlainText(&record1, nullptr);
748 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
749
750 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
751 int buildRes3 = OH_UdmfRecord_AddPlainText(record2, nullptr);
752 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
753
754 OH_UdsPlainText plainText;
755 int buildRes4 = OH_UdmfRecord_AddPlainText(record2, &plainText);
756 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
757
758 OH_UdmfRecord_Destroy(record2);
759 }
760
761 /**
762 * @tc.name: OH_Udmf_GetPlainTextFromRecord001
763 * @tc.desc: test OH_UdmfRecord_GetPlainText with invalid param
764 * @tc.type: FUNC
765 */
766 HWTEST_F(UDMFTest, OH_Udmf_GetPlainTextFromRecord001, TestSize.Level0)
767 {
768 int buildRes1 = OH_UdmfRecord_GetPlainText(nullptr, nullptr);
769 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
770
771 OH_UdmfRecord record1;
772 int buildRes2 = OH_UdmfRecord_GetPlainText(&record1, nullptr);
773 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
774
775 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
776 int buildRes3 = OH_UdmfRecord_GetPlainText(record2, nullptr);
777 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
778
779 OH_UdsPlainText plainText;
780 int buildRes4 = OH_UdmfRecord_GetPlainText(record2, &plainText);
781 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
782
783 OH_UdmfRecord_Destroy(record2);
784 }
785
786 /**
787 * @tc.name: OH_Udmf_BuildAndGetPlainTextFromRecord001
788 * @tc.desc: test OH_UdmfRecord_GetPlainText and OH_Udmf_BuildPlainTextFromRecord with invalid param
789 * @tc.type: FUNC
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 */
817 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByHyperlink001, TestSize.Level0)
818 {
819 int buildRes1 = OH_UdmfRecord_AddHyperlink(nullptr, nullptr);
820 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
821
822 OH_UdmfRecord record1;
823 int buildRes2 = OH_UdmfRecord_AddHyperlink(&record1, nullptr);
824 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
825
826 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
827 int buildRes3 = OH_UdmfRecord_AddHyperlink(record2, nullptr);
828 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
829
830 OH_UdsHyperlink hyperlink;
831 int buildRes4 = OH_UdmfRecord_AddHyperlink(record2, &hyperlink);
832 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
833
834 OH_UdmfRecord_Destroy(record2);
835 }
836
837 /**
838 * @tc.name: OH_Udmf_GetHyperlinkFromRecord001
839 * @tc.desc: test OH_UdmfRecord_GetHyperlink with invalid param
840 * @tc.type: FUNC
841 */
842 HWTEST_F(UDMFTest, OH_Udmf_GetHyperlinkFromRecord001, TestSize.Level0)
843 {
844 int buildRes1 = OH_UdmfRecord_GetHyperlink(nullptr, nullptr);
845 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
846
847 OH_UdmfRecord record1;
848 int buildRes2 = OH_UdmfRecord_GetHyperlink(&record1, nullptr);
849 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
850
851 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
852 int buildRes3 = OH_UdmfRecord_GetHyperlink(record2, nullptr);
853 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
854
855 OH_UdsHyperlink hyperlink;
856 int buildRes4 = OH_UdmfRecord_GetHyperlink(record2, &hyperlink);
857 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
858
859 OH_UdmfRecord_Destroy(record2);
860 }
861
862 /**
863 * @tc.name: OH_Udmf_BuildAndGetHyperlinkFromRecord001
864 * @tc.desc: test OH_Udmf_BuildAndGetHyperlinkFromRecord with invalid param
865 * @tc.type: FUNC
866 */
867 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetHyperlinkFromRecord001, TestSize.Level0)
868 {
869 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
870 OH_UdsHyperlink *hyperlink1 = OH_UdsHyperlink_Create();
871 char url[] = "https://gitee.com/openharmony/distributeddatamgr_udmf/members";
872 OH_UdsHyperlink_SetUrl(hyperlink1, url);
873 int buildRes = OH_UdmfRecord_AddHyperlink(record1, hyperlink1);
874 EXPECT_EQ(buildRes, UDMF_E_OK);
875
876 OH_UdsHyperlink *hyperlink2 = OH_UdsHyperlink_Create();
877 int getRes = OH_UdmfRecord_GetHyperlink(record1, hyperlink2);
878 EXPECT_EQ(getRes, UDMF_E_OK);
879
880 const char *getUrl = OH_UdsHyperlink_GetUrl(hyperlink2);
881 EXPECT_EQ(strcmp(url, getUrl), 0);
882
883 OH_UdmfRecord_Destroy(record1);
884 OH_UdsHyperlink_Destroy(hyperlink1);
885 OH_UdsHyperlink_Destroy(hyperlink2);
886 }
887
888 /**
889 * @tc.name: OH_Udmf_BuildRecordByHtml001
890 * @tc.desc: test OH_UdmfRecord_AddHtml with invalid param
891 * @tc.type: FUNC
892 */
893 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByHtml001, TestSize.Level0)
894 {
895 int buildRes1 = OH_UdmfRecord_AddHtml(nullptr, nullptr);
896 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
897
898 OH_UdmfRecord record1;
899 int buildRes2 = OH_UdmfRecord_AddHtml(&record1, nullptr);
900 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
901
902 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
903 int buildRes3 = OH_UdmfRecord_AddHtml(record2, nullptr);
904 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
905
906 OH_UdsHtml html;
907 int buildRes4 = OH_UdmfRecord_AddHtml(record2, &html);
908 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
909
910 OH_UdmfRecord_Destroy(record2);
911 }
912
913 /**
914 * @tc.name: OH_Udmf_GetHtmlFromRecord001
915 * @tc.desc: test OH_UdmfRecord_GetHtml with invalid param
916 * @tc.type: FUNC
917 */
918 HWTEST_F(UDMFTest, OH_Udmf_GetHtmlFromRecord001, TestSize.Level0)
919 {
920 int buildRes1 = OH_UdmfRecord_GetHtml(nullptr, nullptr);
921 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
922
923 OH_UdmfRecord record1;
924 int buildRes2 = OH_UdmfRecord_GetHtml(&record1, nullptr);
925 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
926
927 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
928 int buildRes3 = OH_UdmfRecord_GetHtml(record2, nullptr);
929 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
930
931 OH_UdsHtml html;
932 int buildRes4 = OH_UdmfRecord_GetHtml(record2, &html);
933 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
934
935 OH_UdmfRecord_Destroy(record2);
936 }
937
938 /**
939 * @tc.name: OH_Udmf_BuildAndGetHtmlFromRecord001
940 * @tc.desc: test OH_Udmf_BuildAndGetHtmlFromRecord with invalid param
941 * @tc.type: FUNC
942 */
943 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetHtmlFromRecord001, TestSize.Level0)
944 {
945 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
946 OH_UdsHtml *html1 = OH_UdsHtml_Create();
947 char content[] = "hello world";
948 OH_UdsHtml_SetContent(html1, content);
949 int buildRes = OH_UdmfRecord_AddHtml(record1, html1);
950 EXPECT_EQ(buildRes, UDMF_E_OK);
951
952 OH_UdsHtml *html2 = OH_UdsHtml_Create();
953 int getRes = OH_UdmfRecord_GetHtml(record1, html2);
954 EXPECT_EQ(getRes, UDMF_E_OK);
955
956 const char *getContent = OH_UdsHtml_GetContent(html2);
957 EXPECT_EQ(strcmp(content, getContent), 0);
958
959 OH_UdmfRecord_Destroy(record1);
960 OH_UdsHtml_Destroy(html1);
961 OH_UdsHtml_Destroy(html2);
962 }
963
964 /**
965 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyAppItem001
966 * @tc.desc: test OH_UdmfRecord_AddAppItem with invalid param
967 * @tc.type: FUNC
968 */
969 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyAppItem001, TestSize.Level0)
970 {
971 int buildRes1 = OH_UdmfRecord_AddAppItem(nullptr, nullptr);
972 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
973
974 OH_UdmfRecord record1;
975 int buildRes2 = OH_UdmfRecord_AddAppItem(&record1, nullptr);
976 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
977
978 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
979 int buildRes3 = OH_UdmfRecord_AddAppItem(record2, nullptr);
980 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
981
982 OH_UdsAppItem appItem;
983 int buildRes4 = OH_UdmfRecord_AddAppItem(record2, &appItem);
984 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
985
986 OH_UdmfRecord_Destroy(record2);
987 }
988
989 /**
990 * @tc.name: OH_Udmf_GetOpenHarmonyAppItemFromRecord001
991 * @tc.desc: test OH_UdmfRecord_GetAppItem with invalid param
992 * @tc.type: FUNC
993 */
994 HWTEST_F(UDMFTest, OH_Udmf_GetOpenHarmonyAppItemFromRecord001, TestSize.Level0)
995 {
996 int buildRes1 = OH_UdmfRecord_GetAppItem(nullptr, nullptr);
997 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
998
999 OH_UdmfRecord record1;
1000 int buildRes2 = OH_UdmfRecord_GetAppItem(&record1, nullptr);
1001 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1002
1003 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1004 int buildRes3 = OH_UdmfRecord_GetAppItem(record2, nullptr);
1005 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1006
1007 OH_UdsAppItem appItem;
1008 int buildRes4 = OH_UdmfRecord_GetAppItem(record2, &appItem);
1009 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1010
1011 OH_UdmfRecord_Destroy(record2);
1012 }
1013
1014 /**
1015 * @tc.name: OH_Udmf_BuildAndGetAppItemFromRecord001
1016 * @tc.desc: test OH_Udmf_BuildAndGetAppItemFromRecord with invalid param
1017 * @tc.type: FUNC
1018 */
1019 HWTEST_F(UDMFTest, OH_Udmf_BuildAndGetAppItemFromRecord001, TestSize.Level0)
1020 {
1021 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1022 OH_UdsAppItem *appItem1 = OH_UdsAppItem_Create();
1023 char name[] = "appItem";
1024 OH_UdsAppItem_SetName(appItem1, name);
1025 int buildRes = OH_UdmfRecord_AddAppItem(record1, appItem1);
1026 EXPECT_EQ(buildRes, UDMF_E_OK);
1027
1028 OH_UdsAppItem *appItem2 = OH_UdsAppItem_Create();
1029 int getRes = OH_UdmfRecord_GetAppItem(record1, appItem2);
1030 EXPECT_EQ(getRes, UDMF_E_OK);
1031
1032 const char *getName = OH_UdsAppItem_GetName(appItem2);
1033 EXPECT_EQ(strcmp(name, getName), 0);
1034
1035 OH_UdmfRecord_Destroy(record1);
1036 OH_UdsAppItem_Destroy(appItem1);
1037 OH_UdsAppItem_Destroy(appItem2);
1038 }
1039
1040 /**
1041 * @tc.name: OH_Udmf_CreatePropertiesFromUnifiedData001
1042 * @tc.desc: Normal testcase of OH_UdmfProperty_Create
1043 * @tc.type: FUNC
1044 */
1045 HWTEST_F(UDMFTest, OH_Udmf_CreatePropertiesFromUnifiedData001, TestSize.Level1)
1046 {
1047 OH_UdmfData *data = OH_UdmfData_Create();
1048 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1049 auto duration = std::chrono::system_clock::now().time_since_epoch();
1050 EXPECT_LE(properties->properties_->timestamp,
1051 std::chrono::duration_cast<std::chrono::milliseconds>(duration).count());
1052 OH_UdmfData_Destroy(data);
1053 OH_UdmfProperty_Destroy(properties);
1054 }
1055
1056 /**
1057 * @tc.name: OH_Udmf_SetPropertiesTag001
1058 * @tc.desc: Normal testcase of OH_Udmf_SetPropertiesTag001
1059 * @tc.type: FUNC
1060 */
1061 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesTag001, TestSize.Level1)
1062 {
1063 OH_UdmfData *data = OH_UdmfData_Create();
1064 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1065 std::string tag("tag");
1066 int result = OH_UdmfProperty_SetTag(properties, tag.c_str());
1067 EXPECT_EQ(UDMF_E_OK, result);
1068 EXPECT_EQ(tag, OH_UdmfProperty_GetTag(properties));
1069 OH_UdmfProperty_Destroy(properties);
1070 OH_UdmfData_Destroy(data);
1071 }
1072
1073 /**
1074 * @tc.name: OH_Udmf_SetPropertiesShareOption001
1075 * @tc.desc: set properties IN_APP
1076 * @tc.type: FUNC
1077 */
1078 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption001, TestSize.Level1)
1079 {
1080 OH_UdmfData *data = OH_UdmfData_Create();
1081 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1082 int result = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_IN_APP);
1083 EXPECT_EQ(UDMF_E_OK, result);
1084 EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_IN_APP, OH_UdmfProperty_GetShareOption(properties));
1085 OH_UdmfData_Destroy(data);
1086 OH_UdmfProperty_Destroy(properties);
1087 }
1088
1089 /**
1090 * @tc.name: OH_Udmf_SetPropertiesShareOption002
1091 * @tc.desc: set properties CROSS_APP
1092 * @tc.type: FUNC
1093 */
1094 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption002, TestSize.Level1)
1095 {
1096 OH_UdmfData *data = OH_UdmfData_Create();
1097 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1098 int result = OH_UdmfProperty_SetShareOption(properties, Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP);
1099 EXPECT_EQ(UDMF_E_OK, result);
1100 EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_CROSS_APP, OH_UdmfProperty_GetShareOption(properties));
1101 OH_UdmfData_Destroy(data);
1102 OH_UdmfProperty_Destroy(properties);
1103 }
1104
1105 /**
1106 * @tc.name: OH_Udmf_SetPropertiesShareOption003
1107 * @tc.desc: set invalid properties
1108 * @tc.type: FUNC
1109 */
1110 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesShareOption003, TestSize.Level1)
1111 {
1112 OH_UdmfProperty *property = nullptr;
1113 EXPECT_EQ(Udmf_ShareOption::SHARE_OPTIONS_INVALID, OH_UdmfProperty_GetShareOption(property));
1114 }
1115
1116 /**
1117 * @tc.name: OH_Udmf_SetPropertiesExtrasIntParam001
1118 * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasIntParam
1119 * @tc.type: FUNC
1120 */
1121 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesExtrasIntParam001, TestSize.Level1)
1122 {
1123 OH_UdmfData *data = OH_UdmfData_Create();
1124 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1125 int result = OH_UdmfProperty_SetExtrasIntParam(properties, "keyInt", 0);
1126 EXPECT_EQ(UDMF_E_OK, result);
1127 EXPECT_EQ(0, OH_UdmfProperty_GetExtrasIntParam(properties, "keyInt", -1));
1128 OH_UdmfData_Destroy(data);
1129 OH_UdmfProperty_Destroy(properties);
1130 }
1131
1132 /**
1133 * @tc.name: OH_Udmf_SetPropertiesExtrasStringParam001
1134 * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1135 * @tc.type: FUNC
1136 */
1137 HWTEST_F(UDMFTest, OH_Udmf_SetPropertiesExtrasStringParam001, TestSize.Level1)
1138 {
1139 OH_UdmfData *data = OH_UdmfData_Create();
1140 OH_UdmfProperty *properties = OH_UdmfProperty_Create(data);
1141 std::string str("str");
1142 int result = OH_UdmfProperty_SetExtrasStringParam(properties, "keyStr", str.c_str());
1143 EXPECT_EQ(UDMF_E_OK, result);
1144 std::string actualStr(OH_UdmfProperty_GetExtrasStringParam(properties, "keyStr"));
1145 EXPECT_EQ(str, actualStr);
1146 OH_UdmfData_Destroy(data);
1147 OH_UdmfProperty_Destroy(properties);
1148 }
1149
1150 /**
1151 * @tc.name: OH_Udmf_MultiStyleRecord001
1152 * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1153 * @tc.type: FUNC
1154 */
1155 HWTEST_F(UDMFTest, OH_Udmf_MultiStyleRecord001, TestSize.Level1)
1156 {
1157 OH_UdsPlainText* plainText = OH_UdsPlainText_Create();
1158 char plainTextContent[] = "plain text";
1159 OH_UdsPlainText_SetContent(plainText, plainTextContent);
1160
1161 OH_UdsHyperlink* hyperlink = OH_UdsHyperlink_Create();
1162 char url[] = "hyper link";
1163 OH_UdsHyperlink_SetUrl(hyperlink, url);
1164
1165 OH_UdsHtml* html = OH_UdsHtml_Create();
1166 char htmlContent[] = "html";
1167 OH_UdsHtml_SetContent(html, htmlContent);
1168
1169 OH_UdsAppItem* appItem = OH_UdsAppItem_Create();
1170 char name[] = "appItem";
1171 OH_UdsAppItem_SetName(appItem, name);
1172
1173 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1174
1175 OH_UdmfRecord_AddPlainText(record, plainText);
1176 OH_UdmfRecord_AddHyperlink(record, hyperlink);
1177 OH_UdmfRecord_AddHtml(record, html);
1178 OH_UdmfRecord_AddAppItem(record, appItem);
1179
1180 unsigned int count = 0;
1181 char** types = OH_UdmfRecord_GetTypes(record, &count);
1182 EXPECT_NE(types, nullptr);
1183 EXPECT_EQ(count, 4);
1184
1185 OH_UdsPlainText *getPlainText = OH_UdsPlainText_Create();
1186 OH_UdmfRecord_GetPlainText(record, getPlainText);
1187 const char *getPlainTextContent = OH_UdsPlainText_GetContent(getPlainText);
1188 EXPECT_EQ(strcmp(getPlainTextContent, plainTextContent), 0);
1189
1190 OH_UdsHyperlink *getHyperLink = OH_UdsHyperlink_Create();
1191 OH_UdmfRecord_GetHyperlink(record, getHyperLink);
1192 const char *getUrl = OH_UdsHyperlink_GetUrl(getHyperLink);
1193 EXPECT_EQ(strcmp(getUrl, url), 0);
1194
1195 OH_UdsHtml *getHtml = OH_UdsHtml_Create();
1196 OH_UdmfRecord_GetHtml(record, getHtml);
1197 const char *getHtmlContent = OH_UdsHtml_GetContent(getHtml);
1198 EXPECT_EQ(strcmp(getHtmlContent, htmlContent), 0);
1199
1200 OH_UdsAppItem *getAppItem = OH_UdsAppItem_Create();
1201 OH_UdmfRecord_GetAppItem(record, getAppItem);
1202 const char *getName = OH_UdsAppItem_GetName(getAppItem);
1203 EXPECT_EQ(strcmp(getName, name), 0);
1204
1205 OH_UdmfData* data = OH_UdmfData_Create();
1206 OH_UdmfData_AddRecord(data, record);
1207
1208 unsigned int count2 = 0;
1209 char** types2 = OH_UdmfData_GetTypes(data, &count2);
1210 EXPECT_NE(types2, nullptr);
1211 EXPECT_EQ(count2, 4);
1212
1213 char plianTextType[] = "general.plain-text";
1214 char hyperLinkType[] = "general.hyperlink";
1215 char htmlType[] = "general.html";
1216 char appItemType[] = "openharmony.app-item";
1217
1218 EXPECT_TRUE(OH_UdmfData_HasType(data, plianTextType));
1219 EXPECT_TRUE(OH_UdmfData_HasType(data, hyperLinkType));
1220 EXPECT_TRUE(OH_UdmfData_HasType(data, htmlType));
1221 EXPECT_TRUE(OH_UdmfData_HasType(data, appItemType));
1222
1223 OH_UdsPlainText_Destroy(plainText);
1224 OH_UdsPlainText_Destroy(getPlainText);
1225 OH_UdsHyperlink_Destroy(hyperlink);
1226 OH_UdsHyperlink_Destroy(getHyperLink);
1227 OH_UdsHtml_Destroy(html);
1228 OH_UdsHtml_Destroy(getHtml);
1229 OH_UdsAppItem_Destroy(appItem);
1230 OH_UdsAppItem_Destroy(getAppItem);
1231 OH_UdmfRecord_Destroy(record);
1232 OH_UdmfData_Destroy(data);
1233 }
1234
1235 /**
1236 * @tc.name: OH_Udmf_MultiStyleRecord002
1237 * @tc.desc: Normal testcase of OH_UdmfProperty_SetExtrasStringParam
1238 * @tc.type: FUNC
1239 */
1240 HWTEST_F(UDMFTest, OH_Udmf_MultiStyleRecord002, TestSize.Level1)
1241 {
1242 LOG_INFO(UDMF_TEST, "GetSummary005 begin.");
1243
1244 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1245 UnifiedData data;
1246 std::string key;
1247 auto object = std::make_shared<Object>();
1248 object->value_[UNIFORM_DATA_TYPE] = UtdUtils::GetUtdIdFromUtdEnum(UDType::PLAIN_TEXT);
1249 object->value_[CONTENT] = "content_";
1250 object->value_[ABSTRACT] = "abstract_";
1251 auto record = std::make_shared<UnifiedRecord>(UDType::PLAIN_TEXT, object);
1252
1253 std::vector<uint8_t> raw = {1, 2, 3, 4, 5};
1254 std::shared_ptr<Object> obj = std::make_shared<Object>();
1255 obj->value_[UNIFORM_DATA_TYPE] = "general.content-form";
1256 obj->value_[THUMB_DATA] = raw;
1257 obj->value_[THUMB_DATA_LENGTH] = 5;
1258 obj->value_[DESCRIPTION] = "descritpion";
1259 obj->value_[TITLE] = "title";
1260 obj->value_[APP_ICON_LENGTH] = 5;
1261 obj->value_[APP_NAME] = "appName";
1262 obj->value_[LINK_URL] = "linkUri";
1263 auto contentForm = UnifiedRecord(CONTENT_FORM, obj);
1264 record->AddEntry(contentForm.GetUtdId(), contentForm.GetOriginValue());
1265
1266 data.AddRecord(record);
1267
1268 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1269 ASSERT_EQ(status, E_OK);
1270
1271 ASSERT_EQ(status, E_OK);
1272 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
1273 int getRes = OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, readUnifiedData);
1274 ASSERT_EQ(getRes, E_OK);
1275 unsigned int count = 0;
1276 OH_UdmfRecord** readRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
1277 ASSERT_EQ(count, 1);
1278 for (int i = 0; i < count; i++) {
1279 OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
1280 OH_UdmfRecord_GetContentForm(readRecords[i], contentForm);
1281 const char* desc = OH_UdsContentForm_GetDescription(contentForm);
1282 EXPECT_EQ(std::string(desc), "descritpion");
1283 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1284 OH_UdmfRecord_GetPlainText(readRecords[i], plainText);
1285 const char* text = OH_UdsPlainText_GetContent(plainText);
1286 EXPECT_EQ(std::string(text), "content_");
1287 }
1288 }
1289
1290 /**
1291 * @tc.name: OH_UdmfRecordProvider_Create001
1292 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Create
1293 * @tc.type: FUNC
1294 */
1295 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Create001, TestSize.Level1)
1296 {
1297 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1298 EXPECT_NE(provider, nullptr);
1299 OH_UdmfRecordProvider_Destroy(provider);
1300 }
1301
1302 /**
1303 * @tc.name: OH_UdmfRecordProvider_Destroy001
1304 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_Destroy
1305 * @tc.type: FUNC
1306 */
1307 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy001, TestSize.Level1)
1308 {
1309 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1310 EXPECT_NE(provider, nullptr);
1311 int num = 1;
1312 void* context = #
1313 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1314 int res1 = OH_UdmfRecordProvider_Destroy(provider);
1315 EXPECT_EQ(res1, UDMF_E_OK);
1316 }
1317
1318 /**
1319 * @tc.name: OH_UdmfRecordProvider_Destroy002
1320 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_Destroy
1321 * @tc.type: FUNC
1322 */
1323 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_Destroy002, TestSize.Level1)
1324 {
1325 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1326 EXPECT_NE(provider, nullptr);
1327 int num = 1;
1328 void* context = #
1329 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1330 int res1 = OH_UdmfRecordProvider_Destroy(provider);
1331 EXPECT_EQ(res1, UDMF_E_OK);
1332 }
1333
1334 /**
1335 * @tc.name: OH_UdmfRecordProvider_SetData001
1336 * @tc.desc: Normal testcase of OH_UdmfRecordProvider_SetData
1337 * @tc.type: FUNC
1338 */
1339 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData001, TestSize.Level1)
1340 {
1341 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1342 EXPECT_NE(provider, nullptr);
1343 int num = 1;
1344 void* context = #
1345 int res = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1346 EXPECT_NE(provider->context, nullptr);
1347 EXPECT_NE(provider->callback, nullptr);
1348 EXPECT_NE(provider->finalize, nullptr);
1349 EXPECT_EQ(res, UDMF_E_OK);
1350 OH_UdmfRecordProvider_Destroy(provider);
1351 }
1352
1353 /**
1354 * @tc.name: OH_UdmfRecordProvider_SetData002
1355 * @tc.desc: invalid parameters testcase of OH_UdmfRecordProvider_SetData
1356 * @tc.type: FUNC
1357 */
1358 HWTEST_F(UDMFTest, OH_UdmfRecordProvider_SetData002, TestSize.Level1)
1359 {
1360 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1361 EXPECT_NE(provider, nullptr);
1362 int num = 1;
1363 void* context = #
1364 int res1 = OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, nullptr);
1365 EXPECT_EQ(provider->context, nullptr);
1366 EXPECT_EQ(provider->finalize, nullptr);
1367 EXPECT_EQ(res1, UDMF_E_INVALID_PARAM);
1368
1369 int res2 = OH_UdmfRecordProvider_SetData(nullptr, context, GetDataCallbackFunc, nullptr);
1370 EXPECT_EQ(res2, UDMF_E_INVALID_PARAM);
1371
1372 int res3 = OH_UdmfRecordProvider_SetData(provider, context, nullptr, nullptr);
1373 EXPECT_EQ(res3, UDMF_E_INVALID_PARAM);
1374 OH_UdmfRecordProvider_Destroy(provider);
1375 }
1376
1377 /**
1378 * @tc.name: OH_UdmfRecord_SetProvider001
1379 * @tc.desc: Normal testcase of OH_UdmfRecord_SetProvider
1380 * @tc.type: FUNC
1381 */
1382 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider001, TestSize.Level1)
1383 {
1384 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1385 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1386 char content[] = "hello world";
1387 OH_UdsPlainText_SetContent(plainText, content);
1388 OH_UdmfRecord_AddPlainText(record, plainText);
1389 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1390 EXPECT_NE(provider, nullptr);
1391 int num = 1;
1392 void* context = #
1393 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1394 const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1395
1396 int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1397 EXPECT_EQ(res, UDMF_E_OK);
1398 OH_UdmfRecordProvider_Destroy(provider);
1399 }
1400
1401 /**
1402 * @tc.name: OH_UdmfRecord_SetProvider002
1403 * @tc.desc: valid parameters testcase of OH_UdmfRecord_SetProvider
1404 * @tc.type: FUNC
1405 */
1406 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider002, TestSize.Level1)
1407 {
1408 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1409 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1410 char content[] = "hello world";
1411 OH_UdsPlainText_SetContent(plainText, content);
1412 OH_UdmfRecord_AddPlainText(record, plainText);
1413 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1414 EXPECT_NE(provider, nullptr);
1415 int num = 1;
1416 void* context = #
1417 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1418 const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1419
1420 int res = OH_UdmfRecord_SetProvider(record, types, 3, provider);
1421 EXPECT_EQ(res, UDMF_E_OK);
1422 OH_UdmfRecordProvider_Destroy(provider);
1423 }
1424
1425 /**
1426 * @tc.name: OH_UdmfRecord_SetProvider003
1427 * @tc.desc: invalid parameters testcase of OH_UdmfRecord_SetProvider
1428 * @tc.type: FUNC
1429 */
1430 HWTEST_F(UDMFTest, OH_UdmfRecord_SetProvider003, TestSize.Level1)
1431 {
1432 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1433 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1434 char content[] = "hello world";
1435 OH_UdsPlainText_SetContent(plainText, content);
1436 OH_UdmfRecord_AddPlainText(record, plainText);
1437 OH_UdmfRecordProvider* provider = OH_UdmfRecordProvider_Create();
1438 EXPECT_NE(provider, nullptr);
1439 int num = 1;
1440 void* context = #
1441 OH_UdmfRecordProvider_SetData(provider, context, GetDataCallbackFunc, FinalizeFunc);
1442 const char* types[3] = { "general.plain-text", "general.hyperlink", "general.html" };
1443
1444 int res = OH_UdmfRecord_SetProvider(record, types, MAX_TYPES_COUNT + 1, provider);
1445 EXPECT_EQ(res, UDMF_E_INVALID_PARAM);
1446
1447 res = OH_UdmfRecord_SetProvider(record, types, 0, provider);
1448 EXPECT_EQ(res, UDMF_E_INVALID_PARAM);
1449
1450 res = OH_UdmfRecord_SetProvider(record, nullptr, MAX_TYPES_COUNT + 1, provider);
1451 EXPECT_EQ(res, UDMF_E_INVALID_PARAM);
1452
1453 res = OH_UdmfRecord_SetProvider(record, types, 3, nullptr);
1454 EXPECT_EQ(res, UDMF_E_INVALID_PARAM);
1455 OH_UdmfRecordProvider_Destroy(provider);
1456 }
1457
1458 /**
1459 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001
1460 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1461 * @tc.type: FUNC
1462 */
1463 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer001, TestSize.Level0)
1464 {
1465 int buildRes1 = OH_UdmfRecord_AddArrayBuffer(nullptr, nullptr, nullptr);
1466 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1467
1468 OH_UdmfRecord record1;
1469 int buildRes2 = OH_UdmfRecord_AddArrayBuffer(&record1, nullptr, nullptr);
1470 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1471
1472 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1473 int buildRes3 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, nullptr);
1474 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1475
1476 OH_UdsArrayBuffer buffer;
1477 int buildRes4 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, &buffer);
1478 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1479
1480 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1481 int buildRes5 = OH_UdmfRecord_AddArrayBuffer(record2, nullptr, buffer2);
1482 EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1483
1484 char type[] = "general.plain-text";
1485 int buildRes6 = OH_UdmfRecord_AddArrayBuffer(record2, type, buffer2);
1486 EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1487
1488 char type2[] = "ApplicationDefined-myType1";
1489 int buildRes7 = OH_UdmfRecord_AddArrayBuffer(record2, type2, buffer2);
1490 EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1491
1492 OH_UdmfRecord_Destroy(record2);
1493 OH_UdsArrayBuffer_Destroy(buffer2);
1494 }
1495
1496 /**
1497 * @tc.name: OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002
1498 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1499 * @tc.type: FUNC
1500 */
1501 HWTEST_F(UDMFTest, OH_Udmf_BuildRecordByOpenHarmonyArrayBuffer002, TestSize.Level0)
1502 {
1503 int buildRes1 = OH_UdmfRecord_GetArrayBuffer(nullptr, nullptr, nullptr);
1504 EXPECT_EQ(buildRes1, UDMF_E_INVALID_PARAM);
1505
1506 OH_UdmfRecord record1;
1507 int buildRes2 = OH_UdmfRecord_GetArrayBuffer(&record1, nullptr, nullptr);
1508 EXPECT_EQ(buildRes2, UDMF_E_INVALID_PARAM);
1509
1510 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1511 int buildRes3 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, nullptr);
1512 EXPECT_EQ(buildRes3, UDMF_E_INVALID_PARAM);
1513
1514 OH_UdsArrayBuffer buffer;
1515 int buildRes4 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, &buffer);
1516 EXPECT_EQ(buildRes4, UDMF_E_INVALID_PARAM);
1517
1518 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1519 int buildRes5 = OH_UdmfRecord_GetArrayBuffer(record2, nullptr, buffer2);
1520 EXPECT_EQ(buildRes5, UDMF_E_INVALID_PARAM);
1521
1522 char type[] = "general.plain-text";
1523 int buildRes6 = OH_UdmfRecord_GetArrayBuffer(record2, type, buffer2);
1524 EXPECT_EQ(buildRes6, UDMF_E_INVALID_PARAM);
1525
1526 char type2[] = "ApplicationDefined-myType1";
1527 int buildRes7 = OH_UdmfRecord_GetArrayBuffer(record2, type2, buffer2);
1528 EXPECT_EQ(buildRes7, UDMF_E_INVALID_PARAM);
1529
1530 OH_UdmfRecord_Destroy(record2);
1531 OH_UdsArrayBuffer_Destroy(buffer2);
1532 }
1533
1534 /**
1535 * @tc.name: OH_Udmf_GetArrayBufferFromRecord001
1536 * @tc.desc: test OH_UdmfRecord_AddArrayBuffer with invalid param
1537 * @tc.type: FUNC
1538 */
1539 HWTEST_F(UDMFTest, OH_Udmf_GetArrayBufferFromRecord001, TestSize.Level0)
1540 {
1541 unsigned char data1[] = "Hello world";
1542 unsigned int len1 = sizeof(data1);
1543 OH_UdsArrayBuffer *buffer1 = OH_UdsArrayBuffer_Create();
1544 OH_UdsArrayBuffer_SetData(buffer1, data1, len1);
1545
1546 char type1[] = "ApplicationDefined-myType1";
1547 OH_UdmfRecord *record1 = OH_UdmfRecord_Create();
1548 int buildRes = OH_UdmfRecord_AddArrayBuffer(record1, type1, buffer1);
1549 ASSERT_EQ(buildRes, UDMF_E_OK);
1550
1551 char type2[] = "ApplicationDefined-myType2";
1552 OH_UdsArrayBuffer *buffer2 = OH_UdsArrayBuffer_Create();
1553 int getRes = OH_UdmfRecord_GetArrayBuffer(record1, type2, buffer2);
1554 EXPECT_EQ(getRes, UDMF_E_INVALID_PARAM);
1555
1556 int getRes2 = OH_UdmfRecord_GetArrayBuffer(record1, type1, buffer2);
1557 ASSERT_EQ(getRes2, UDMF_E_OK);
1558
1559 unsigned int getLen = 0;
1560 unsigned char *getData;
1561 int getRes3 = OH_UdsArrayBuffer_GetData(buffer2, &getData, &getLen);
1562 ASSERT_EQ(getRes3, UDMF_E_OK);
1563 ASSERT_EQ(len1, getLen);
1564 ASSERT_TRUE(CheckUnsignedChar(data1, getData, getLen));
1565
1566 OH_UdmfRecord_Destroy(record1);
1567 OH_UdsArrayBuffer_Destroy(buffer1);
1568 OH_UdsArrayBuffer_Destroy(buffer2);
1569 }
1570
1571 /**
1572 * @tc.name: OH_UdmfData_GetPrimaryPlainText001
1573 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1574 * @tc.type: FUNC
1575 */
1576 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText001, TestSize.Level1)
1577 {
1578 int result = OH_UdmfData_GetPrimaryPlainText(nullptr, nullptr);
1579 EXPECT_EQ(result, UDMF_E_INVALID_PARAM);
1580
1581 OH_UdmfData data;
1582 int result2 = OH_UdmfData_GetPrimaryPlainText(&data, nullptr);
1583 EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1584
1585 OH_UdmfData *data2 = OH_UdmfData_Create();
1586 int result3 = OH_UdmfData_GetPrimaryPlainText(data2, nullptr);
1587 EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1588
1589 OH_UdsPlainText plainText;
1590 int result4 = OH_UdmfData_GetPrimaryPlainText(data2, &plainText);
1591 EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1592
1593 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1594 int result5 = OH_UdmfData_GetPrimaryPlainText(data2, plainText2);
1595 EXPECT_EQ(result5, UDMF_ERR);
1596
1597 OH_UdsPlainText_Destroy(plainText2);
1598 OH_UdmfData_Destroy(data2);
1599 }
1600
1601 /**
1602 * @tc.name: OH_UdmfData_GetPrimaryPlainText002
1603 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1604 * @tc.type: FUNC
1605 */
1606 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText002, TestSize.Level1)
1607 {
1608 const char *helloWorld = "Hello world";
1609
1610 OH_UdmfData *data = OH_UdmfData_Create();
1611 OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1612 int result = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1613 EXPECT_EQ(result, UDMF_ERR);
1614
1615 OH_UdmfData *data2 = OH_UdmfData_Create();
1616 OH_UdsHtml *html = OH_UdsHtml_Create();
1617 OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1618 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1619 OH_UdmfRecord_AddHtml(record, html);
1620 OH_UdmfData_AddRecord(data2, record);
1621 int result2 = OH_UdmfData_GetPrimaryPlainText(data2, plainTextOutput);
1622 EXPECT_EQ(result2, UDMF_ERR);
1623
1624 OH_UdmfData *data3 = OH_UdmfData_Create();
1625 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1626 OH_UdsPlainText_SetContent(plainText, helloWorld);
1627 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1628 OH_UdmfRecord_AddPlainText(record2, plainText);
1629 OH_UdmfData_AddRecord(data3, record);
1630 OH_UdmfData_AddRecord(data3, record2);
1631 int result3 = OH_UdmfData_GetPrimaryPlainText(data3, plainTextOutput);
1632 ASSERT_EQ(result3, UDMF_E_OK);
1633 auto *content = OH_UdsPlainText_GetContent(plainTextOutput);
1634 EXPECT_EQ(strcmp(content, helloWorld), 0);
1635
1636 OH_UdsHtml_Destroy(html);
1637 OH_UdsPlainText_Destroy(plainTextOutput);
1638 OH_UdsPlainText_Destroy(plainText);
1639 OH_UdmfRecord_Destroy(record);
1640 OH_UdmfRecord_Destroy(record2);
1641 OH_UdmfData_Destroy(data);
1642 OH_UdmfData_Destroy(data2);
1643 OH_UdmfData_Destroy(data3);
1644 }
1645
1646 /**
1647 * @tc.name: OH_UdmfData_GetPrimaryPlainText003
1648 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryPlainText
1649 * @tc.type: FUNC
1650 */
1651 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryPlainText003, TestSize.Level1)
1652 {
1653 const char *helloWorld = "Hello world";
1654 const char *helloWorld2 = "Hello world2";
1655
1656 OH_UdsHtml *html = OH_UdsHtml_Create();
1657 OH_UdsHtml_SetContent(html, "<p>Hello world</p>");
1658 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1659 OH_UdmfRecord_AddHtml(record, html);
1660
1661 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1662 OH_UdsPlainText_SetContent(plainText, helloWorld);
1663 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1664 OH_UdmfRecord_AddPlainText(record2, plainText);
1665
1666 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1667 OH_UdsPlainText_SetContent(plainText2, helloWorld2);
1668 OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1669 OH_UdmfRecord_AddPlainText(record3, plainText2);
1670
1671 OH_UdmfData *data = OH_UdmfData_Create();
1672 OH_UdmfData_AddRecord(data, record3);
1673 OH_UdmfData_AddRecord(data, record2);
1674 OH_UdmfData_AddRecord(data, record);
1675 OH_UdsPlainText *plainTextOutput = OH_UdsPlainText_Create();
1676 int result4 = OH_UdmfData_GetPrimaryPlainText(data, plainTextOutput);
1677 ASSERT_EQ(result4, UDMF_E_OK);
1678 auto *content2 = OH_UdsPlainText_GetContent(plainTextOutput);
1679 EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1680
1681 OH_UdsHtml_Destroy(html);
1682 OH_UdsPlainText_Destroy(plainTextOutput);
1683 OH_UdsPlainText_Destroy(plainText);
1684 OH_UdsPlainText_Destroy(plainText2);
1685 OH_UdmfRecord_Destroy(record);
1686 OH_UdmfRecord_Destroy(record2);
1687 OH_UdmfRecord_Destroy(record3);
1688 OH_UdmfData_Destroy(data);
1689 }
1690
1691 /**
1692 * @tc.name: OH_UdmfData_GetPrimaryHtml001
1693 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1694 * @tc.type: FUNC
1695 */
1696 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml001, TestSize.Level1)
1697 {
1698 int result1 = OH_UdmfData_GetPrimaryHtml(nullptr, nullptr);
1699 EXPECT_EQ(result1, UDMF_E_INVALID_PARAM);
1700
1701 OH_UdmfData data;
1702 int result2 = OH_UdmfData_GetPrimaryHtml(&data, nullptr);
1703 EXPECT_EQ(result2, UDMF_E_INVALID_PARAM);
1704
1705 OH_UdmfData *data2 = OH_UdmfData_Create();
1706 int result3 = OH_UdmfData_GetPrimaryHtml(data2, nullptr);
1707 EXPECT_EQ(result3, UDMF_E_INVALID_PARAM);
1708
1709 OH_UdsHtml html;
1710 int result4 = OH_UdmfData_GetPrimaryHtml(data2, &html);
1711 EXPECT_EQ(result4, UDMF_E_INVALID_PARAM);
1712
1713 OH_UdsHtml *html2 = OH_UdsHtml_Create();
1714 int result5 = OH_UdmfData_GetPrimaryHtml(data2, html2);
1715 EXPECT_EQ(result5, UDMF_ERR);
1716
1717 OH_UdsHtml_Destroy(html2);
1718 OH_UdmfData_Destroy(data2);
1719 }
1720
1721 /**
1722 * @tc.name: OH_UdmfData_GetPrimaryHtml002
1723 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1724 * @tc.type: FUNC
1725 */
1726 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml002, TestSize.Level1)
1727 {
1728 const char *helloWorld = "<p>Hello world</p>";
1729
1730 OH_UdmfData *data = OH_UdmfData_Create();
1731 OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1732 int result = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1733 EXPECT_EQ(result, UDMF_ERR);
1734
1735 OH_UdmfData *data2 = OH_UdmfData_Create();
1736 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1737 OH_UdsPlainText_SetContent(plainText, "Hello world");
1738 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1739 OH_UdmfRecord_AddPlainText(record, plainText);
1740 OH_UdmfData_AddRecord(data2, record);
1741 int result2 = OH_UdmfData_GetPrimaryHtml(data2, htmlOutput);
1742 EXPECT_EQ(result2, UDMF_ERR);
1743
1744 OH_UdmfData *data3 = OH_UdmfData_Create();
1745 OH_UdsHtml *html = OH_UdsHtml_Create();
1746 OH_UdsHtml_SetContent(html, helloWorld);
1747 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1748 OH_UdmfRecord_AddHtml(record2, html);
1749 OH_UdmfData_AddRecord(data3, record);
1750 OH_UdmfData_AddRecord(data3, record2);
1751 int result3 = OH_UdmfData_GetPrimaryHtml(data3, htmlOutput);
1752 ASSERT_EQ(result3, UDMF_E_OK);
1753 auto content = OH_UdsHtml_GetContent(htmlOutput);
1754 EXPECT_EQ(strcmp(content, helloWorld), 0);
1755
1756 OH_UdsHtml_Destroy(html);
1757 OH_UdsHtml_Destroy(htmlOutput);
1758 OH_UdsPlainText_Destroy(plainText);
1759 OH_UdmfRecord_Destroy(record);
1760 OH_UdmfRecord_Destroy(record2);
1761 OH_UdmfData_Destroy(data);
1762 OH_UdmfData_Destroy(data2);
1763 OH_UdmfData_Destroy(data3);
1764 }
1765
1766 /**
1767 * @tc.name: OH_UdmfData_GetPrimaryHtml003
1768 * @tc.desc: Normal testcase of OH_UdmfData_GetPrimaryHtml
1769 * @tc.type: FUNC
1770 */
1771 HWTEST_F(UDMFTest, OH_UdmfData_GetPrimaryHtml003, TestSize.Level1)
1772 {
1773 const char *helloWorld = "<p>Hello world</p>";
1774 const char *helloWorld2 = "<p>Hello world2</p>";
1775
1776 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1777 OH_UdsPlainText_SetContent(plainText, "Hello world");
1778 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1779 OH_UdmfRecord_AddPlainText(record, plainText);
1780
1781 OH_UdsHtml *html = OH_UdsHtml_Create();
1782 OH_UdsHtml_SetContent(html, helloWorld);
1783 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1784 OH_UdmfRecord_AddHtml(record2, html);
1785
1786 OH_UdsHtml *html2 = OH_UdsHtml_Create();
1787 OH_UdsHtml_SetContent(html2, helloWorld2);
1788 OH_UdmfRecord* record3 = OH_UdmfRecord_Create();
1789 OH_UdmfRecord_AddHtml(record3, html2);
1790
1791 OH_UdmfData *data = OH_UdmfData_Create();
1792 OH_UdmfData_AddRecord(data, record3);
1793 OH_UdmfData_AddRecord(data, record2);
1794 OH_UdmfData_AddRecord(data, record);
1795 OH_UdsHtml *htmlOutput = OH_UdsHtml_Create();
1796 int result4 = OH_UdmfData_GetPrimaryHtml(data, htmlOutput);
1797 ASSERT_EQ(result4, UDMF_E_OK);
1798 auto content2 = OH_UdsHtml_GetContent(htmlOutput);
1799 EXPECT_EQ(strcmp(content2, helloWorld2), 0);
1800
1801 OH_UdsHtml_Destroy(html);
1802 OH_UdsHtml_Destroy(html2);
1803 OH_UdsHtml_Destroy(htmlOutput);
1804 OH_UdsPlainText_Destroy(plainText);
1805 OH_UdmfRecord_Destroy(record);
1806 OH_UdmfRecord_Destroy(record2);
1807 OH_UdmfRecord_Destroy(record3);
1808 OH_UdmfData_Destroy(data);
1809 }
1810
1811 /**
1812 * @tc.name: OH_UdmfData_GetRecordCount001
1813 * @tc.desc: Normal testcase of OH_UdmfData_GetRecordCount
1814 * @tc.type: FUNC
1815 */
1816 HWTEST_F(UDMFTest, OH_UdmfData_GetRecordCount001, TestSize.Level1)
1817 {
1818 int result = OH_UdmfData_GetRecordCount(nullptr);
1819 EXPECT_EQ(result, 0);
1820
1821 OH_UdmfData data;
1822 int result2 = OH_UdmfData_GetRecordCount(&data);
1823 EXPECT_EQ(result2, 0);
1824
1825 OH_UdmfData *data2 = OH_UdmfData_Create();
1826 int result3 = OH_UdmfData_GetRecordCount(data2);
1827 EXPECT_EQ(result3, 0);
1828
1829 OH_UdmfData *data3 = OH_UdmfData_Create();
1830 OH_UdmfRecord *record = OH_UdmfRecord_Create();
1831 OH_UdmfData_AddRecord(data3, record);
1832 int result4 = OH_UdmfData_GetRecordCount(data3);
1833 EXPECT_EQ(result4, 1);
1834
1835 OH_UdmfData *data4 = OH_UdmfData_Create();
1836 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
1837 OH_UdmfData_AddRecord(data4, record);
1838 OH_UdmfData_AddRecord(data4, record2);
1839 int result5 = OH_UdmfData_GetRecordCount(data4);
1840 EXPECT_EQ(result5, 2);
1841
1842 OH_UdmfRecord_Destroy(record);
1843 OH_UdmfRecord_Destroy(record2);
1844 OH_UdmfData_Destroy(data2);
1845 OH_UdmfData_Destroy(data3);
1846 OH_UdmfData_Destroy(data4);
1847 }
1848
1849 /**
1850 * @tc.name: OH_UdmfData_GetRecord001
1851 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1852 * @tc.type: FUNC
1853 */
1854 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord001, TestSize.Level1)
1855 {
1856 OH_UdmfRecord *result = OH_UdmfData_GetRecord(nullptr, -1);
1857 EXPECT_EQ(result, nullptr);
1858
1859 OH_UdmfData data;
1860 OH_UdmfRecord *result2 = OH_UdmfData_GetRecord(&data, -1);
1861 EXPECT_EQ(result2, nullptr);
1862
1863 OH_UdmfRecord *result3 = OH_UdmfData_GetRecord(&data, 0);
1864 EXPECT_EQ(result3, nullptr);
1865
1866 OH_UdmfData *data2 = OH_UdmfData_Create();
1867 OH_UdmfRecord *result4 = OH_UdmfData_GetRecord(data2, -1);
1868 EXPECT_EQ(result4, nullptr);
1869
1870 OH_UdmfRecord *result5 = OH_UdmfData_GetRecord(data2, 0);
1871 EXPECT_EQ(result5, nullptr);
1872
1873 OH_UdmfRecord *result6 = OH_UdmfData_GetRecord(data2, 1);
1874 EXPECT_EQ(result6, nullptr);
1875
1876 OH_UdmfData *data3 = OH_UdmfData_Create();
1877 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1878 OH_UdmfData_AddRecord(data3, record);
1879 EXPECT_EQ(OH_UdmfData_GetRecordCount(data3), 1);
1880 OH_UdmfRecord *result7 = OH_UdmfData_GetRecord(data3, -1);
1881 EXPECT_EQ(result7, nullptr);
1882 OH_UdmfRecord *result8 = OH_UdmfData_GetRecord(data3, 1);
1883 EXPECT_EQ(result8, nullptr);
1884 OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1885 EXPECT_NE(result9, nullptr);
1886
1887 OH_UdmfRecord_Destroy(record);
1888 OH_UdmfData_Destroy(data2);
1889 OH_UdmfData_Destroy(data3);
1890 }
1891
1892 /**
1893 * @tc.name: OH_UdmfData_GetRecord002
1894 * @tc.desc: Normal testcase of OH_UdmfData_GetRecord
1895 * @tc.type: FUNC
1896 */
1897 HWTEST_F(UDMFTest, OH_UdmfData_GetRecord002, TestSize.Level1)
1898 {
1899 const char *helloWorld = "Hello world";
1900 const char *helloWorld2 = "Hello world2";
1901
1902 OH_UdmfData *data3 = OH_UdmfData_Create();
1903 OH_UdsPlainText *plainText = OH_UdsPlainText_Create();
1904 OH_UdsPlainText_SetContent(plainText, helloWorld);
1905 OH_UdmfRecord* record = OH_UdmfRecord_Create();
1906 OH_UdmfRecord_AddPlainText(record, plainText);
1907 OH_UdmfData_AddRecord(data3, record);
1908 OH_UdmfRecord *result9 = OH_UdmfData_GetRecord(data3, 0);
1909 EXPECT_NE(result9, nullptr);
1910
1911 OH_UdsPlainText *plainText2 = OH_UdsPlainText_Create();
1912 OH_UdmfRecord_GetPlainText(result9, plainText2);
1913 auto content = OH_UdsPlainText_GetContent(plainText2);
1914 EXPECT_EQ(strcmp(content, helloWorld), 0);
1915
1916 OH_UdmfData *data4 = OH_UdmfData_Create();
1917 OH_UdsPlainText *plainText3 = OH_UdsPlainText_Create();
1918 OH_UdsPlainText_SetContent(plainText3, helloWorld2);
1919 OH_UdmfRecord* record2 = OH_UdmfRecord_Create();
1920 OH_UdmfRecord_AddPlainText(record2, plainText3);
1921 OH_UdmfData_AddRecord(data4, record);
1922 OH_UdmfData_AddRecord(data4, record2);
1923 OH_UdmfRecord *result10 = OH_UdmfData_GetRecord(data4, -1);
1924 EXPECT_EQ(result10, nullptr);
1925 OH_UdmfRecord *result11 = OH_UdmfData_GetRecord(data4, 2);
1926 EXPECT_EQ(result11, nullptr);
1927 OH_UdmfRecord *result12 = OH_UdmfData_GetRecord(data4, 0);
1928 ASSERT_NE(result12, nullptr);
1929 OH_UdsPlainText *plainText4 = OH_UdsPlainText_Create();
1930 OH_UdmfRecord_GetPlainText(result12, plainText4);
1931 auto content2 = OH_UdsPlainText_GetContent(plainText4);
1932 EXPECT_EQ(strcmp(content2, helloWorld), 0);
1933 OH_UdmfRecord *result13 = OH_UdmfData_GetRecord(data4, 1);
1934 ASSERT_NE(result13, nullptr);
1935 OH_UdsPlainText *plainText5 = OH_UdsPlainText_Create();
1936 OH_UdmfRecord_GetPlainText(result13, plainText5);
1937 auto content3 = OH_UdsPlainText_GetContent(plainText5);
1938 EXPECT_EQ(strcmp(content3, helloWorld2), 0);
1939
1940 OH_UdsPlainText_Destroy(plainText);
1941 OH_UdsPlainText_Destroy(plainText2);
1942 OH_UdmfRecord_Destroy(record);
1943 OH_UdmfRecord_Destroy(record2);
1944 OH_UdmfData_Destroy(data3);
1945 OH_UdmfData_Destroy(data4);
1946 }
1947
1948 /**
1949 * @tc.name: OH_UdmfData_IsLocal001
1950 * @tc.desc: Normal testcase of OH_UdmfData_IsLocal
1951 * @tc.type: FUNC
1952 */
1953 HWTEST_F(UDMFTest, OH_UdmfData_IsLocal001, TestSize.Level1)
1954 {
1955 bool result = OH_UdmfData_IsLocal(nullptr);
1956 EXPECT_EQ(result, true);
1957
1958 OH_UdmfData data;
1959 bool result2 = OH_UdmfData_IsLocal(&data);
1960 EXPECT_EQ(result2, true);
1961
1962 OH_UdmfData *data2 = OH_UdmfData_Create();
1963 bool result3 = OH_UdmfData_IsLocal(data2);
1964 EXPECT_EQ(result3, true);
1965
1966 OH_UdmfData_Destroy(data2);
1967 }
1968
1969 /**
1970 * @tc.name: FileUriTest001
1971 * @tc.desc: test fileUri between js and capi
1972 * @tc.type: FUNC
1973 */
1974 HWTEST_F(UDMFTest, FileUriTest001, TestSize.Level1)
1975 {
1976 std::string uri = "https://xxx/xx/xx.jpg";
1977 std::shared_ptr<Image> image = std::make_shared<Image>();
1978 image->SetUri(uri);
1979 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
1980 unifiedData->AddRecord(image);
1981 std::string key;
1982 CustomOption option = {
1983 .intention = UD_INTENTION_DRAG
1984 };
1985 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
1986 EXPECT_EQ(setRet, E_OK);
1987
1988 OH_UdmfData* udmfData = OH_UdmfData_Create();
1989 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
1990
1991 unsigned int dataTypeCount;
1992 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
1993 EXPECT_EQ(dataTypeCount, 2);
1994 EXPECT_NE(dataTypes, nullptr);
1995 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
1996 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
1997
1998 unsigned int recordCount;
1999 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2000 EXPECT_EQ(recordCount, 1);
2001 EXPECT_NE(records, nullptr);
2002
2003 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2004 unsigned int recordTypeCount;
2005 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2006 EXPECT_EQ(recordTypeCount, 1);
2007 EXPECT_NE(recordTypes, nullptr);
2008 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2009 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2010 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2011 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2012 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2013 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2014 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2015 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2016 }
2017 }
2018 }
2019 }
2020
2021 /**
2022 * @tc.name: FileUriTest002
2023 * @tc.desc: test fileUri between js and capi
2024 * @tc.type: FUNC
2025 */
2026 HWTEST_F(UDMFTest, FileUriTest002, TestSize.Level1)
2027 {
2028 std::string uri = "https://xxx/xx/xx.jpg";
2029 std::string content = "content";
2030 std::shared_ptr<Image> image = std::make_shared<Image>();
2031 image->SetUri(uri);
2032 std::shared_ptr<PlainText> plaintext = std::make_shared<PlainText>();
2033 plaintext->SetContent(content);
2034 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2035 unifiedData->AddRecord(image);
2036 unifiedData->AddRecord(plaintext);
2037 std::string key;
2038 CustomOption option = {
2039 .intention = UD_INTENTION_DRAG
2040 };
2041 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2042 EXPECT_EQ(setRet, E_OK);
2043
2044 OH_UdmfData* udmfData = OH_UdmfData_Create();
2045 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2046
2047 unsigned int dataTypeCount;
2048 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2049 EXPECT_EQ(dataTypeCount, 3);
2050 EXPECT_NE(dataTypes, nullptr);
2051 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_IMAGE), 0);
2052 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_PLAIN_TEXT), 0);
2053 EXPECT_EQ(strcmp(dataTypes[2], UDMF_META_GENERAL_FILE_URI), 0);
2054
2055 unsigned int recordCount;
2056 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2057 EXPECT_EQ(recordCount, 2);
2058 EXPECT_NE(records, nullptr);
2059
2060 unsigned int recordTypeCount;
2061 char** recordTypes = OH_UdmfRecord_GetTypes(records[0], &recordTypeCount);
2062 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2063 EXPECT_EQ(recordTypeCount, 1);
2064 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2065 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[0], fileUri);
2066 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2067 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2068 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2069
2070 recordTypes = OH_UdmfRecord_GetTypes(records[1], &recordTypeCount);
2071 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_PLAIN_TEXT), 0);
2072 EXPECT_EQ(recordTypeCount, 1);
2073 OH_UdsPlainText* text = OH_UdsPlainText_Create();
2074 int getPlaintextRet = OH_UdmfRecord_GetPlainText(records[1], text);
2075 EXPECT_EQ(getPlaintextRet, UDMF_E_OK);
2076 const char* getContent = OH_UdsPlainText_GetContent(text);
2077 EXPECT_EQ(strcmp(getContent, content.c_str()), 0);
2078 }
2079
2080 /**
2081 * @tc.name: FileUriTest003
2082 * @tc.desc: test fileUri between js and capi
2083 * @tc.type: FUNC
2084 */
2085 HWTEST_F(UDMFTest, FileUriTest003, TestSize.Level1)
2086 {
2087 std::string uri = "https://xxx/xx/xx.jpg";
2088 std::shared_ptr<Audio> audio = std::make_shared<Audio>();
2089 audio->SetUri(uri);
2090 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2091 unifiedData->AddRecord(audio);
2092 std::string key;
2093 CustomOption option = {
2094 .intention = UD_INTENTION_DRAG
2095 };
2096 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2097 EXPECT_EQ(setRet, E_OK);
2098
2099 OH_UdmfData* udmfData = OH_UdmfData_Create();
2100 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2101
2102 unsigned int dataTypeCount;
2103 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2104 EXPECT_EQ(dataTypeCount, 2);
2105 EXPECT_NE(dataTypes, nullptr);
2106 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_AUDIO), 0);
2107 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2108
2109 unsigned int recordCount;
2110 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2111 EXPECT_EQ(recordCount, 1);
2112 EXPECT_NE(records, nullptr);
2113
2114 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2115 unsigned int recordTypeCount;
2116 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2117 EXPECT_EQ(recordTypeCount, 1);
2118 EXPECT_NE(recordTypes, nullptr);
2119 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2120 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2121 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2122 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2123 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2124 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2125 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2126 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2127 }
2128 }
2129 }
2130 }
2131
2132 /**
2133 * @tc.name: FileUriTest004
2134 * @tc.desc: test fileUri between js and capi
2135 * @tc.type: FUNC
2136 */
2137 HWTEST_F(UDMFTest, FileUriTest004, TestSize.Level1)
2138 {
2139 std::string uri = "https://xxx/xx/xx.jpg";
2140 std::shared_ptr<File> file = std::make_shared<File>();
2141 file->SetUri(uri);
2142 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2143 unifiedData->AddRecord(file);
2144 std::string key;
2145 CustomOption option = {
2146 .intention = UD_INTENTION_DRAG
2147 };
2148 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2149 EXPECT_EQ(setRet, E_OK);
2150
2151 OH_UdmfData* udmfData = OH_UdmfData_Create();
2152 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2153
2154 unsigned int dataTypeCount;
2155 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2156 EXPECT_EQ(dataTypeCount, 2);
2157 EXPECT_NE(dataTypes, nullptr);
2158 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_GENERAL_FILE), 0);
2159 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2160
2161 unsigned int recordCount;
2162 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2163 EXPECT_EQ(recordCount, 1);
2164 EXPECT_NE(records, nullptr);
2165
2166 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2167 unsigned int recordTypeCount;
2168 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2169 EXPECT_EQ(recordTypeCount, 1);
2170 EXPECT_NE(recordTypes, nullptr);
2171 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2172 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2173 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2174 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2175 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2176 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2177 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2178 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2179 }
2180 }
2181 }
2182 }
2183
2184 /**
2185 * @tc.name: FileUriTest005
2186 * @tc.desc: test fileUri between js and capi
2187 * @tc.type: FUNC
2188 */
2189 HWTEST_F(UDMFTest, FileUriTest005, TestSize.Level1)
2190 {
2191 std::string uri = "https://xxx/xx/xx.jpg";
2192 std::shared_ptr<Object> obj = std::make_shared<Object>();
2193 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2194 obj->value_[FILE_URI_PARAM] = uri;
2195 obj->value_[FILE_TYPE] = "general.img";
2196 auto record = std::make_shared<UnifiedRecord>(UDType::FOLDER, obj);
2197 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2198 unifiedData->AddRecord(record);
2199 std::string key;
2200 CustomOption option = {
2201 .intention = UD_INTENTION_DRAG
2202 };
2203 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2204 EXPECT_EQ(setRet, E_OK);
2205
2206 OH_UdmfData* udmfData = OH_UdmfData_Create();
2207 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2208
2209 unsigned int dataTypeCount;
2210 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2211 EXPECT_EQ(dataTypeCount, 2);
2212 EXPECT_NE(dataTypes, nullptr);
2213 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_FOLDER), 0);
2214 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2215
2216 unsigned int recordCount;
2217 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2218 EXPECT_EQ(recordCount, 1);
2219 EXPECT_NE(records, nullptr);
2220
2221 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2222 unsigned int recordTypeCount;
2223 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2224 EXPECT_EQ(recordTypeCount, 2);
2225 EXPECT_NE(recordTypes, nullptr);
2226 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_FOLDER), 0);
2227 EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2228 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2229 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2230 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2231 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2232 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2233 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2234 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2235 }
2236 }
2237 }
2238 }
2239
2240 /**
2241 * @tc.name: FileUriTest006
2242 * @tc.desc: test fileUri between js and capi
2243 * @tc.type: FUNC
2244 */
2245 HWTEST_F(UDMFTest, FileUriTest006, TestSize.Level1)
2246 {
2247 std::string uri = "https://xxx/xx/xx.jpg";
2248 std::shared_ptr<Video> video = std::make_shared<Video>();
2249 video->SetUri(uri);
2250 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2251 unifiedData->AddRecord(video);
2252 std::string key;
2253 CustomOption option = {
2254 .intention = UD_INTENTION_DRAG
2255 };
2256 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2257 EXPECT_EQ(setRet, E_OK);
2258
2259 OH_UdmfData* udmfData = OH_UdmfData_Create();
2260 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2261
2262 unsigned int dataTypeCount;
2263 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2264 EXPECT_EQ(dataTypeCount, 2);
2265 EXPECT_NE(dataTypes, nullptr);
2266 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2267 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2268
2269 unsigned int recordCount;
2270 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2271 EXPECT_EQ(recordCount, 1);
2272 EXPECT_NE(records, nullptr);
2273
2274 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2275 unsigned int recordTypeCount;
2276 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2277 EXPECT_EQ(recordTypeCount, 1);
2278 EXPECT_NE(recordTypes, nullptr);
2279 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_GENERAL_FILE_URI), 0);
2280 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2281 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2282 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2283 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2284 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2285 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2286 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2287 }
2288 }
2289 }
2290 }
2291
2292 /**
2293 * @tc.name: FileUriTest007
2294 * @tc.desc: test fileUri between js and capi
2295 * @tc.type: FUNC
2296 */
2297 HWTEST_F(UDMFTest, FileUriTest007, TestSize.Level1)
2298 {
2299 std::string uri = "https://xxx/xx/xx.jpg";
2300
2301 std::shared_ptr<Object> obj = std::make_shared<Object>();
2302 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2303 obj->value_[FILE_URI_PARAM] = uri;
2304 obj->value_[FILE_TYPE] = "general.img";
2305 auto record = std::make_shared<UnifiedRecord>(UDType::VIDEO, obj);
2306 std::shared_ptr<UnifiedData> unifiedData = std::make_shared<UnifiedData>();
2307 unifiedData->AddRecord(record);
2308 std::string key;
2309 CustomOption option = {
2310 .intention = UD_INTENTION_DRAG
2311 };
2312 int setRet = UdmfClient::GetInstance().SetData(option, *unifiedData, key);
2313 EXPECT_EQ(setRet, E_OK);
2314
2315 OH_UdmfData* udmfData = OH_UdmfData_Create();
2316 OH_Udmf_GetUnifiedData(key.c_str(), UDMF_INTENTION_DRAG, udmfData);
2317
2318 unsigned int dataTypeCount;
2319 char** dataTypes = OH_UdmfData_GetTypes(udmfData, &dataTypeCount);
2320 EXPECT_EQ(dataTypeCount, 2);
2321 EXPECT_NE(dataTypes, nullptr);
2322 EXPECT_EQ(strcmp(dataTypes[0], UDMF_META_VIDEO), 0);
2323 EXPECT_EQ(strcmp(dataTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2324
2325 unsigned int recordCount;
2326 OH_UdmfRecord** records = OH_UdmfData_GetRecords(udmfData, &recordCount);
2327 EXPECT_EQ(recordCount, 1);
2328 EXPECT_NE(records, nullptr);
2329
2330 for (unsigned int idx = 0; idx < recordCount; ++idx) {
2331 unsigned int recordTypeCount;
2332 char** recordTypes = OH_UdmfRecord_GetTypes(records[idx], &recordTypeCount);
2333 EXPECT_EQ(recordTypeCount, 2);
2334 EXPECT_NE(recordTypes, nullptr);
2335 EXPECT_EQ(strcmp(recordTypes[0], UDMF_META_VIDEO), 0);
2336 EXPECT_EQ(strcmp(recordTypes[1], UDMF_META_GENERAL_FILE_URI), 0);
2337 for (unsigned int recordIdx = 0; recordIdx < recordTypeCount; ++recordIdx) {
2338 if (strcmp(recordTypes[recordIdx], UDMF_META_GENERAL_FILE_URI) == 0) {
2339 OH_UdsFileUri* fileUri = OH_UdsFileUri_Create();
2340 int getFileUriRet = OH_UdmfRecord_GetFileUri(records[idx], fileUri);
2341 EXPECT_EQ(getFileUriRet, UDMF_E_OK);
2342 const char* getFileUri = OH_UdsFileUri_GetFileUri(fileUri);
2343 EXPECT_EQ(strcmp(getFileUri, uri.c_str()), 0);
2344 }
2345 }
2346 }
2347 }
2348
2349 /**
2350 * @tc.name: OH_Udmf_SetAndGetUnifiedData003
2351 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2352 * @tc.type: FUNC
2353 */
2354 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData003, TestSize.Level1)
2355 {
2356 std::string uri = "https://xxx/xx/xx.jpg";
2357 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2358 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2359 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2360 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2361 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
2362 OH_UdmfRecord_AddFileUri(record, fileUri);
2363 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2364 Udmf_Intention intention = UDMF_INTENTION_DRAG;
2365 char key[UDMF_KEY_BUFFER_LEN];
2366
2367 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2368 EXPECT_EQ(setRes, UDMF_E_OK);
2369 EXPECT_NE(key[0], '\0');
2370 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2371 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2372 EXPECT_EQ(getRes, UDMF_E_OK);
2373 unsigned int count = 0;
2374 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2375 EXPECT_EQ(count, 1);
2376 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2377 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2378 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2379 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2380
2381 OH_UdsFileUri_Destroy(fileUri);
2382 OH_UdmfRecord_Destroy(record);
2383 OH_UdmfData_Destroy(udmfUnifiedData);
2384
2385 OH_UdsFileUri_Destroy(getFileUri);
2386 OH_UdmfData_Destroy(readUnifiedData);
2387 }
2388
2389 /**
2390 * @tc.name: OH_Udmf_SetAndGetUnifiedData004
2391 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2392 * @tc.type: FUNC
2393 */
2394 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData004, TestSize.Level1)
2395 {
2396 std::string uri = "https://xxx/xx/xx.jpg";
2397 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2398 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2399 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2400 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2401 OH_UdmfRecord_AddFileUri(record, fileUri);
2402 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2403 Udmf_Intention intention = UDMF_INTENTION_DRAG;
2404 char key[UDMF_KEY_BUFFER_LEN];
2405
2406 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2407 EXPECT_EQ(setRes, UDMF_E_OK);
2408 EXPECT_NE(key[0], '\0');
2409 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2410 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2411 EXPECT_EQ(getRes, UDMF_E_OK);
2412 unsigned int count = 0;
2413 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2414 EXPECT_EQ(count, 1);
2415 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2416 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2417 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2418 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2419
2420 OH_UdsFileUri_Destroy(fileUri);
2421 OH_UdmfRecord_Destroy(record);
2422 OH_UdmfData_Destroy(udmfUnifiedData);
2423
2424 OH_UdsFileUri_Destroy(getFileUri);
2425 OH_UdmfData_Destroy(readUnifiedData);
2426 }
2427
2428 /**
2429 * @tc.name: OH_Udmf_SetAndGetUnifiedData005
2430 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2431 * @tc.type: FUNC
2432 */
2433 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData005, TestSize.Level1)
2434 {
2435 std::string uri = "https://xxx/xx/xx.jpg";
2436 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2437 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2438 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2439 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2440 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2441 OH_UdmfRecord_AddFileUri(record, fileUri);
2442 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2443 Udmf_Intention intention = UDMF_INTENTION_DRAG;
2444 char key[UDMF_KEY_BUFFER_LEN];
2445
2446 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2447 EXPECT_EQ(setRes, UDMF_E_OK);
2448 EXPECT_NE(key[0], '\0');
2449 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2450 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2451 EXPECT_EQ(getRes, UDMF_E_OK);
2452 unsigned int count = 0;
2453 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2454 EXPECT_EQ(count, 1);
2455 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
2456 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
2457 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
2458 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
2459
2460 OH_UdsFileUri_Destroy(fileUri);
2461 OH_UdmfRecord_Destroy(record);
2462 OH_UdmfData_Destroy(udmfUnifiedData);
2463
2464 OH_UdsFileUri_Destroy(getFileUri);
2465 OH_UdmfData_Destroy(readUnifiedData);
2466 }
2467
2468 /**
2469 * @tc.name: OH_Udmf_SetAndGetUnifiedData006
2470 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2471 * @tc.type: FUNC
2472 */
2473 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData006, TestSize.Level1)
2474 {
2475 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2476 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2477 OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
2478 unsigned char thumbData[] = {0, 1, 2, 3, 4};
2479 OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
2480 OH_UdsContentForm_SetDescription(contentForm, "description");
2481 OH_UdmfRecord_AddContentForm(record, contentForm);
2482 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2483 Udmf_Intention intention = UDMF_INTENTION_DRAG;
2484 char key[UDMF_KEY_BUFFER_LEN];
2485
2486 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2487 EXPECT_EQ(setRes, UDMF_E_OK);
2488 EXPECT_NE(key[0], '\0');
2489 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2490 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2491 EXPECT_EQ(getRes, UDMF_E_OK);
2492 unsigned int count = 0;
2493 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(readUnifiedData, &count);
2494 EXPECT_EQ(count, 1);
2495 OH_UdsContentForm *getContentForm = OH_UdsContentForm_Create();
2496 OH_UdmfRecord_GetContentForm(getRecords[0], getContentForm);
2497 EXPECT_EQ("description", std::string(OH_UdsContentForm_GetDescription(getContentForm)));
2498
2499 unsigned char *readThumbData;
2500 unsigned int thumbDataLen = 0;
2501 OH_UdsContentForm_GetThumbData(getContentForm, &readThumbData, &thumbDataLen);
2502 ASSERT_EQ(5, thumbDataLen);
2503 ASSERT_TRUE(CheckUnsignedChar(thumbData, readThumbData, thumbDataLen));
2504
2505 OH_UdsContentForm_Destroy(contentForm);
2506 OH_UdmfRecord_Destroy(record);
2507 OH_UdmfData_Destroy(udmfUnifiedData);
2508
2509 OH_UdsContentForm_Destroy(getContentForm);
2510 OH_UdmfData_Destroy(readUnifiedData);
2511 }
2512
2513 /**
2514 * @tc.name: OH_Udmf_SetAndGetUnifiedData007
2515 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with invlid params
2516 * @tc.type: FUNC
2517 */
2518 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData007, TestSize.Level1)
2519 {
2520 std::string uri = "file://file_010.txt";
2521 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2522 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2523 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2524 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2525 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2526 OH_UdmfRecord_AddFileUri(record, fileUri);
2527 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2528 Udmf_Intention intention = UDMF_INTENTION_MENU;
2529 char key[UDMF_KEY_BUFFER_LEN];
2530
2531 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2532 EXPECT_EQ(setRes, UDMF_E_OK);
2533 EXPECT_NE(key[0], '\0');
2534 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2535 Udmf_Intention intention1 = UDMF_INTENTION_SYSTEM_SHARE;
2536 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2537 EXPECT_EQ(getRes, UDMF_ERR);
2538 char key1[UDMF_KEY_BUFFER_LEN];
2539 getRes = OH_Udmf_GetUnifiedData(key1, intention1, readUnifiedData);
2540 EXPECT_EQ(getRes, UDMF_ERR);
2541 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2542 EXPECT_EQ(getRes, UDMF_ERR);
2543 OH_UdmfRecord_Destroy(record);
2544 OH_UdmfData_Destroy(udmfUnifiedData);
2545 OH_UdmfData_Destroy(readUnifiedData);
2546 }
2547
2548 /**
2549 * @tc.name: OH_Udmf_SetAndGetUnifiedData008
2550 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with invlid params
2551 * @tc.type: FUNC
2552 */
2553 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData008, TestSize.Level1)
2554 {
2555 std::string uri = "file://file_011.txt";
2556 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2557 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2558 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2559 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2560 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2561 OH_UdmfRecord_AddFileUri(record, fileUri);
2562 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2563 Udmf_Intention intention = UDMF_INTENTION_SYSTEM_SHARE;
2564 char key[UDMF_KEY_BUFFER_LEN];
2565
2566 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2567 EXPECT_EQ(setRes, UDMF_E_OK);
2568 EXPECT_NE(key[0], '\0');
2569 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2570 Udmf_Intention intention1 = UDMF_INTENTION_MENU;
2571 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2572 EXPECT_EQ(getRes, UDMF_ERR);
2573 char key1[UDMF_KEY_BUFFER_LEN];
2574 getRes = OH_Udmf_GetUnifiedData(key1, intention1, readUnifiedData);
2575 EXPECT_EQ(getRes, UDMF_ERR);
2576 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2577 EXPECT_EQ(getRes, UDMF_ERR);
2578
2579 OH_UdmfRecord_Destroy(record);
2580 OH_UdmfData_Destroy(udmfUnifiedData);
2581 OH_UdmfData_Destroy(readUnifiedData);
2582 }
2583
2584 /**
2585 * @tc.name: OH_Udmf_SetAndGetUnifiedData009
2586 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with UDMF_ERR
2587 * @tc.type: FUNC
2588 */
2589 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData009, TestSize.Level1)
2590 {
2591 std::string uri = "file://file_009.txt";
2592 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2593 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2594 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2595 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2596 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2597 OH_UdmfRecord_AddFileUri(record, fileUri);
2598 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2599 Udmf_Intention intention = UDMF_INTENTION_PICKER;
2600 char key[UDMF_KEY_BUFFER_LEN];
2601
2602 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2603 EXPECT_EQ(setRes, UDMF_E_OK);
2604 EXPECT_NE(key[0], '\0');
2605 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2606 Udmf_Intention intention1 = UDMF_INTENTION_MENU;
2607 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2608 EXPECT_EQ(getRes, UDMF_ERR);
2609 char key1[UDMF_KEY_BUFFER_LEN];
2610 getRes = OH_Udmf_GetUnifiedData(key1, intention1, readUnifiedData);
2611 EXPECT_EQ(getRes, UDMF_ERR);
2612 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2613 EXPECT_EQ(getRes, UDMF_ERR);
2614
2615 OH_UdmfRecord_Destroy(record);
2616 OH_UdmfData_Destroy(udmfUnifiedData);
2617 OH_UdmfData_Destroy(readUnifiedData);
2618 }
2619
2620 /**
2621 * @tc.name: OH_Udmf_SetAndGetUnifiedData010
2622 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2623 * @tc.type: FUNC
2624 */
2625 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData010, TestSize.Level1)
2626 {
2627 std::string uri = "file://file_010.txt";
2628 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2629 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2630 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2631 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2632 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2633 OH_UdmfRecord_AddFileUri(record, fileUri);
2634 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2635 Udmf_Intention intention = UDMF_INTENTION_PICKER;
2636 char key[UDMF_KEY_BUFFER_LEN];
2637 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2638 EXPECT_EQ(setRes, UDMF_E_OK);
2639 EXPECT_NE(key[0], '\0');
2640 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2641 SetHapToken2();
2642 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2643 EXPECT_EQ(getRes, UDMF_ERR);
2644 }
2645
2646 /**
2647 * @tc.name: OH_Udmf_SetAndGetUnifiedData011
2648 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2649 * @tc.type: FUNC
2650 */
2651 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData011, TestSize.Level1)
2652 {
2653 std::string uri = "file://file_011.txt";
2654 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2655 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2656 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2657 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2658 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2659 OH_UdmfRecord_AddFileUri(record, fileUri);
2660 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2661 Udmf_Intention intention = UDMF_INTENTION_MENU;
2662 char key[UDMF_KEY_BUFFER_LEN];
2663 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2664 EXPECT_EQ(setRes, UDMF_E_OK);
2665 EXPECT_NE(key[0], '\0');
2666 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2667 SetHapToken2();
2668 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2669 EXPECT_EQ(getRes, UDMF_ERR);
2670 }
2671
2672 /**
2673 * @tc.name: OH_Udmf_SetAndGetUnifiedData012
2674 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with file uri
2675 * @tc.type: FUNC
2676 */
2677 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData012, TestSize.Level1)
2678 {
2679 std::string uri = "file://file_012.txt";
2680 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2681 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2682 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2683 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2684 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2685 OH_UdmfRecord_AddFileUri(record, fileUri);
2686 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2687 Udmf_Intention intention = UDMF_INTENTION_SYSTEM_SHARE;
2688 char key[UDMF_KEY_BUFFER_LEN];
2689 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2690 EXPECT_EQ(setRes, UDMF_E_OK);
2691 EXPECT_NE(key[0], '\0');
2692 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2693 SetHapToken2();
2694 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2695 EXPECT_EQ(getRes, UDMF_ERR);
2696 }
2697
2698 /**
2699 * @tc.name: OH_Udmf_SetAndGetUnifiedData013
2700 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData
2701 * @tc.type: FUNC
2702 */
2703 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData013, TestSize.Level1)
2704 {
2705 std::string uri = "file://file_007.txt";
2706 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2707 OH_UdsContentForm *contentForm = OH_UdsContentForm_Create();
2708 unsigned char thumbData[] = {0, 1, 2, 3, 4};
2709 OH_UdsContentForm_SetThumbData(contentForm, thumbData, 5);
2710 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2711 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2712 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2713 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2714 OH_UdmfRecord_AddFileUri(record, fileUri);
2715 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2716 Udmf_Intention intention = UDMF_INTENTION_SYSTEM_SHARE;
2717 char key[UDMF_KEY_BUFFER_LEN];
2718
2719 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2720 EXPECT_EQ(setRes, UDMF_E_OK);
2721 EXPECT_NE(key[0], '\0');
2722 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2723 Udmf_Intention intention1 = UDMF_INTENTION_PICKER;
2724 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2725 EXPECT_EQ(getRes, UDMF_ERR);
2726 char key1[UDMF_KEY_BUFFER_LEN] = "udmf://aaabbbccc/com.hmos.photos/CSl;cdcGFcmdkasaccCSCAAScscdc";
2727 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2728 EXPECT_EQ(getRes, UDMF_ERR);
2729 getRes = OH_Udmf_GetUnifiedData(key1, intention1, readUnifiedData);
2730 EXPECT_EQ(getRes, UDMF_ERR);
2731
2732 OH_UdmfRecord_Destroy(record);
2733 OH_UdmfData_Destroy(udmfUnifiedData);
2734 OH_UdmfData_Destroy(readUnifiedData);
2735 }
2736
2737 /**
2738 * @tc.name: OH_Udmf_SetAndGetUnifiedData014
2739 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with
2740 * @tc.type: FUNC
2741 */
2742 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData014, TestSize.Level1)
2743 {
2744 std::string uri = "file://file_008.txt";
2745 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2746 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2747 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2748 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2749 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2750 OH_UdmfRecord_AddFileUri(record, fileUri);
2751 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2752 Udmf_Intention intention = UDMF_INTENTION_PICKER;
2753 char key[UDMF_KEY_BUFFER_LEN];
2754
2755 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2756 EXPECT_EQ(setRes, UDMF_E_OK);
2757 EXPECT_NE(key[0], '\0');
2758 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2759 Udmf_Intention intention1 = UDMF_INTENTION_SYSTEM_SHARE;
2760 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2761 EXPECT_EQ(getRes, UDMF_ERR);
2762 char key1[UDMF_KEY_BUFFER_LEN] = "udmf://aaabbbccc/com.hmos.photos/CSl;cdcGFcmdkasaccCSCAAScscdc";
2763 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2764 EXPECT_EQ(getRes, UDMF_ERR);
2765 getRes = OH_Udmf_GetUnifiedData(key1, intention1, readUnifiedData);
2766 EXPECT_EQ(getRes, UDMF_ERR);
2767
2768 OH_UdmfRecord_Destroy(record);
2769 OH_UdmfData_Destroy(udmfUnifiedData);
2770 OH_UdmfData_Destroy(readUnifiedData);
2771 }
2772
2773 /**
2774 * @tc.name: OH_Udmf_SetAndGetUnifiedData015
2775 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2776 * @tc.type: FUNC
2777 */
2778 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData015, TestSize.Level1)
2779 {
2780 std::string uri = "file://file_009.txt";
2781 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2782 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2783 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2784 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2785 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2786 OH_UdmfRecord_AddFileUri(record, fileUri);
2787 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2788 Udmf_Intention intention = UDMF_INTENTION_MENU;
2789 char key[UDMF_KEY_BUFFER_LEN];
2790
2791 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2792 EXPECT_EQ(setRes, UDMF_E_OK);
2793 EXPECT_NE(key[0], '\0');
2794 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2795 Udmf_Intention intention1 = UDMF_INTENTION_SYSTEM_SHARE;
2796 int getRes = OH_Udmf_GetUnifiedData(key, intention1, readUnifiedData);
2797 EXPECT_EQ(getRes, UDMF_ERR);
2798 char key1[UDMF_KEY_BUFFER_LEN] = "udmf://aaabbbccc/com.hmos.photos/CSl;cdcGFcmdkasaccCSCAAScscdc";
2799 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2800 EXPECT_EQ(getRes, UDMF_ERR);
2801 intention = UDMF_INTENTION_MENU;
2802 getRes = OH_Udmf_GetUnifiedData(key1, intention, readUnifiedData);
2803 EXPECT_EQ(getRes, UDMF_ERR);
2804
2805 OH_UdmfRecord_Destroy(record);
2806 OH_UdmfData_Destroy(udmfUnifiedData);
2807 OH_UdmfData_Destroy(readUnifiedData);
2808 }
2809
2810 /**
2811 * @tc.name: OH_Udmf_SetAndGetUnifiedData016
2812 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData
2813 * @tc.type: FUNC
2814 */
2815 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData016, TestSize.Level1)
2816 {
2817 std::string uri = "file://file_010.txt";
2818 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2819 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2820 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2821 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2822 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2823 for (int32_t i = 0; i < 1000; i++) {
2824 OH_UdmfRecord_AddFileUri(record, fileUri);
2825 }
2826 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2827 Udmf_Intention intention = UDMF_INTENTION_SYSTEM_SHARE;
2828 char key[UDMF_KEY_BUFFER_LEN];
2829 int64_t start = CountTime();
2830 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2831 int64_t end = CountTime();
2832 LOG_INFO(UDMF_TEST, "systemshare setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2833 EXPECT_EQ(setRes, UDMF_E_OK);
2834 EXPECT_NE(key[0], '\0');
2835 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2836 start = CountTime();
2837 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2838 end = CountTime();
2839 LOG_INFO(UDMF_TEST, "systemshare setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2840 EXPECT_EQ(getRes, UDMF_E_OK);
2841
2842 OH_UdsFileUri_Destroy(fileUri);
2843 OH_UdmfRecord_Destroy(record);
2844 OH_UdmfData_Destroy(udmfUnifiedData);
2845 OH_UdmfData_Destroy(readUnifiedData);
2846 }
2847
2848 /**
2849 * @tc.name: OH_Udmf_SetAndGetUnifiedData017
2850 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2851 * @tc.type: FUNC
2852 */
2853 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData017, TestSize.Level1)
2854 {
2855 std::string uri = "file://file_008.txt";
2856 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2857 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2858 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2859 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2860 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2861 for (int32_t i = 0; i < 1000; i++) {
2862 OH_UdmfRecord_AddFileUri(record, fileUri);
2863 }
2864 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2865 Udmf_Intention intention = UDMF_INTENTION_PICKER;
2866 char key[UDMF_KEY_BUFFER_LEN];
2867
2868 int64_t start = CountTime();
2869 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2870 int64_t end = CountTime();
2871 LOG_INFO(UDMF_TEST, "picker setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2872 EXPECT_EQ(setRes, UDMF_E_OK);
2873 EXPECT_NE(key[0], '\0');
2874 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2875 start = CountTime();
2876 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2877 end = CountTime();
2878 LOG_INFO(UDMF_TEST, "picker setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2879 EXPECT_EQ(getRes, UDMF_E_OK);
2880
2881 OH_UdsFileUri_Destroy(fileUri);
2882 OH_UdmfRecord_Destroy(record);
2883 OH_UdmfData_Destroy(udmfUnifiedData);
2884 OH_UdmfData_Destroy(readUnifiedData);
2885 }
2886
2887 /**
2888 * @tc.name: OH_Udmf_SetAndGetUnifiedData018
2889 * @tc.desc: OH_Udmf_SetUnifiedData and OH_Udmf_GetUnifiedData with content form
2890 * @tc.type: FUNC
2891 */
2892 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedData018, TestSize.Level1)
2893 {
2894 std::string uri = "file://file_010.txt";
2895 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2896 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2897 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2898 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2899 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_FOLDER);
2900 for (int32_t i = 0; i < 1000; i++) {
2901 OH_UdmfRecord_AddFileUri(record, fileUri);
2902 }
2903 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2904 Udmf_Intention intention = UDMF_INTENTION_MENU;
2905 char key[UDMF_KEY_BUFFER_LEN];
2906 int64_t start = CountTime();
2907 int setRes = OH_Udmf_SetUnifiedData(intention, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
2908 int64_t end = CountTime();
2909 LOG_INFO(UDMF_TEST, "menu setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2910 EXPECT_EQ(setRes, UDMF_E_OK);
2911 EXPECT_NE(key[0], '\0');
2912 OH_UdmfData *readUnifiedData = OH_UdmfData_Create();
2913 start = CountTime();
2914 int getRes = OH_Udmf_GetUnifiedData(key, intention, readUnifiedData);
2915 end = CountTime();
2916 LOG_INFO(UDMF_TEST, "menu setdata 1000 cost timet:%{public}" PRIi64, (end - start));
2917 EXPECT_EQ(getRes, UDMF_E_OK);
2918
2919 OH_UdsFileUri_Destroy(fileUri);
2920 OH_UdmfRecord_Destroy(record);
2921 OH_UdmfData_Destroy(udmfUnifiedData);
2922 OH_UdmfData_Destroy(readUnifiedData);
2923 }
2924
CreateImageDataWithFileUri(const std::string & uriStr)2925 static OH_UdmfData* CreateImageDataWithFileUri(const std::string& uriStr)
2926 {
2927 std::string uri = uriStr;
2928 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2929 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2930 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2931 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2932 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
2933 OH_UdmfRecord_AddFileUri(record, fileUri);
2934 OH_UdmfData_AddRecord(udmfUnifiedData, record);
2935 return udmfUnifiedData;
2936 }
2937
2938 /**
2939 * @tc.name: OH_UdmfOptions001
2940 * @tc.desc: OH_UdmfOptions with content form
2941 * @tc.type: FUNC
2942 */
2943 HWTEST_F(UDMFTest, OH_UdmfOptions001, TestSize.Level1)
2944 {
2945 OH_UdmfOptions* options = OH_UdmfOptions_Create();
2946 ASSERT_TRUE(options != nullptr);
2947 const char* testKey = "testKey";
2948 int result = OH_UdmfOptions_SetKey(options, testKey);
2949 EXPECT_EQ(result, UDMF_E_OK);
2950 const char* getKey = OH_UdmfOptions_GetKey(options);
2951 EXPECT_STREQ(getKey, testKey);
2952 Udmf_Intention testIntention = UDMF_INTENTION_DRAG;
2953 int setResult = OH_UdmfOptions_SetIntention(options, testIntention);
2954 EXPECT_EQ(setResult, UDMF_E_OK);
2955 Udmf_Intention getIntention = OH_UdmfOptions_GetIntention(options);
2956 EXPECT_EQ(getIntention, testIntention);
2957 int resetResult = OH_UdmfOptions_Reset(options);
2958 EXPECT_EQ(resetResult, UDMF_E_OK);
2959 EXPECT_EQ(options->key.empty(), true);
2960 EXPECT_EQ(options->intention, Udmf_Intention {});
2961 OH_UdmfOptions_Destroy(options);
2962 }
2963
2964 /**
2965 * @tc.name: OH_UdmfOptions002
2966 * @tc.desc: OH_UdmfOptions with content form
2967 * @tc.type: FUNC
2968 */
2969 HWTEST_F(UDMFTest, OH_UdmfOptions002, TestSize.Level1)
2970 {
2971 OH_UdmfOptions* options1 = nullptr;
2972 const char * key = nullptr;
2973 int setRes = OH_UdmfOptions_SetKey(options1, key);
2974 EXPECT_EQ(setRes, UDMF_E_INVALID_PARAM);
2975 const char* getRes = OH_UdmfOptions_GetKey(options1);
2976 EXPECT_EQ(getRes, nullptr);
2977 Udmf_Intention testIntention = UDMF_INTENTION_DRAG;
2978 OH_UdmfOptions_GetIntention(options1);
2979 int setIntention = OH_UdmfOptions_SetIntention(options1, testIntention);
2980 EXPECT_EQ(setIntention, UDMF_E_INVALID_PARAM);
2981 int reSet = OH_UdmfOptions_Reset(options1);
2982 EXPECT_EQ(reSet, UDMF_E_INVALID_PARAM);
2983 OH_UdmfOptions_Destroy(options1);
2984 }
2985
2986 /**
2987 * @tc.name: OH_Udmf_SetUnifiedDataByOptions001
2988 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions with content form
2989 * @tc.type: FUNC
2990 */
2991 HWTEST_F(UDMFTest, OH_Udmf_SetUnifiedDataByOptions001, TestSize.Level1)
2992 {
2993 std::string uri = "https://xxx/xx/xx.jpg";
2994 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
2995 OH_UdmfRecord *record = OH_UdmfRecord_Create();
2996 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
2997 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
2998 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
2999 OH_UdmfRecord_AddFileUri(record, fileUri);
3000 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3001 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3002 options->intention = UDMF_INTENTION_DRAG;
3003 char key[UDMF_KEY_BUFFER_LEN];
3004
3005 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3006 EXPECT_EQ(setRes, UDMF_E_INVALID_PARAM);
3007
3008 OH_UdmfOptions_Destroy(options);
3009 OH_UdsFileUri_Destroy(fileUri);
3010 OH_UdmfRecord_Destroy(record);
3011 OH_UdmfData_Destroy(udmfUnifiedData);
3012 }
3013
3014 /**
3015 * @tc.name: OH_Udmf_SetAndGetUnifiedDataByOptions001
3016 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions and OH_Udmf_GetUnifiedDataByOptions with content form
3017 * @tc.type: FUNC
3018 */
3019 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedDataByOptions001, TestSize.Level1)
3020 {
3021 std::string uri = "https://xxx/xx/xx.jpg";
3022 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3023 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3024 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3025 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3026 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3027 OH_UdmfRecord_AddFileUri(record, fileUri);
3028 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3029 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3030 options->intention = UDMF_INTENTION_DATA_HUB;
3031 char key[UDMF_KEY_BUFFER_LEN];
3032
3033 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3034 EXPECT_EQ(setRes, UDMF_E_OK);
3035 std::string uri2 = "https://new/uri/path.jpg";
3036 OH_UdmfData *udmfUnifiedData2 = OH_UdmfData_Create();
3037 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
3038 OH_UdsFileUri *fileUri2 = OH_UdsFileUri_Create();
3039 OH_UdsFileUri_SetFileUri(fileUri2, uri2.c_str());
3040 OH_UdsFileUri_SetFileType(fileUri2, UDMF_META_IMAGE);
3041 OH_UdmfRecord_AddFileUri(record2, fileUri2);
3042 OH_UdmfData_AddRecord(udmfUnifiedData2, record2);
3043 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3044 options2->intention = UDMF_INTENTION_DATA_HUB;
3045 char key2[UDMF_KEY_BUFFER_LEN];
3046 int setRes2 = OH_Udmf_SetUnifiedDataByOptions(options2, udmfUnifiedData2, key2, UDMF_KEY_BUFFER_LEN);
3047 EXPECT_EQ(setRes2, UDMF_E_OK);
3048 EXPECT_NE(key[0], '\0');
3049 unsigned int dataSize = 0;
3050 OH_UdmfData* dataArray = nullptr;
3051 int getRes = OH_Udmf_GetUnifiedDataByOptions(options, &dataArray, &dataSize);
3052 EXPECT_EQ(getRes, UDMF_E_OK);
3053 EXPECT_NE(dataArray, nullptr);
3054 unsigned int dataSize2 = 0;
3055 OH_UdmfData* dataArray2 = nullptr;
3056 int deleteRes = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3057 EXPECT_EQ(deleteRes, UDMF_E_OK);
3058 EXPECT_NE(dataArray2, nullptr);
3059 EXPECT_EQ(dataSize2, 2);
3060 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3061 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3062 OH_UdmfOptions_Destroy(options);
3063 OH_UdmfOptions_Destroy(options2);
3064 OH_UdsFileUri_Destroy(fileUri);
3065 OH_UdsFileUri_Destroy(fileUri2);
3066 OH_UdmfRecord_Destroy(record);
3067 OH_UdmfRecord_Destroy(record2);
3068 OH_UdmfData_Destroy(udmfUnifiedData);
3069 OH_UdmfData_Destroy(udmfUnifiedData2);
3070 }
3071
3072 /**
3073 * @tc.name: OH_Udmf_UpdateUnifiedData001
3074 * @tc.desc: OH_Udmf_UpdateUnifiedData001 with content form
3075 * @tc.type: FUNC
3076 */
3077 HWTEST_F(UDMFTest, OH_Udmf_UpdateUnifiedData001, TestSize.Level1)
3078 {
3079 std::string uri = "https://xxx/xx/xx.jpg";
3080 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3081 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3082 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3083 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3084 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3085 OH_UdmfRecord_AddFileUri(record, fileUri);
3086 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3087 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3088 options->intention = UDMF_INTENTION_DATA_HUB;
3089 char key[UDMF_KEY_BUFFER_LEN];
3090 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3091 EXPECT_EQ(setRes, UDMF_E_OK);
3092 EXPECT_NE(key[0], '\0');
3093
3094 std::string uri2 = "https://new/uri/path.jpg";
3095 OH_UdmfData *udmfUnifiedData2 = OH_UdmfData_Create();
3096 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
3097 OH_UdsFileUri *fileUri2 = OH_UdsFileUri_Create();
3098 OH_UdsFileUri_SetFileUri(fileUri2, uri2.c_str());
3099 OH_UdsFileUri_SetFileType(fileUri2, UDMF_META_IMAGE);
3100 OH_UdmfRecord_AddFileUri(record2, fileUri2);
3101 OH_UdmfData_AddRecord(udmfUnifiedData2, record2);
3102 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3103 options2->intention = UDMF_INTENTION_DATA_HUB;
3104 options2->key = key;
3105 int updataRes = OH_Udmf_UpdateUnifiedData(options2, udmfUnifiedData2);
3106 EXPECT_EQ(updataRes, UDMF_E_OK);
3107
3108 unsigned int dataSize2 = 0;
3109 OH_UdmfData* dataArray2 = nullptr;
3110 int deleteRes = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3111 EXPECT_EQ(deleteRes, UDMF_E_OK);
3112 EXPECT_NE(dataArray2, nullptr);
3113 EXPECT_EQ(dataSize2, 1);
3114 OH_UdmfOptions_Destroy(options);
3115 OH_UdmfOptions_Destroy(options2);
3116
3117 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3118
3119 OH_UdsFileUri_Destroy(fileUri);
3120 OH_UdsFileUri_Destroy(fileUri2);
3121 OH_UdmfRecord_Destroy(record);
3122 OH_UdmfRecord_Destroy(record2);
3123 OH_UdmfData_Destroy(udmfUnifiedData);
3124 OH_UdmfData_Destroy(udmfUnifiedData2);
3125 }
3126
3127 /**
3128 * @tc.name: OH_Udmf_GetUnifiedDataByOptions001
3129 * @tc.desc: OH_Udmf_GetUnifiedDataByOptions with content form
3130 * @tc.type: FUNC
3131 */
3132 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataByOptions001, TestSize.Level1)
3133 {
3134 std::string uri = "https://xxx/xx/xx.jpg";
3135 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3136 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3137 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3138 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3139 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3140 OH_UdmfRecord_AddFileUri(record, fileUri);
3141 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3142 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3143 options->intention = UDMF_INTENTION_PICKER;
3144 char key[UDMF_KEY_BUFFER_LEN];
3145
3146 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3147 EXPECT_EQ(setRes, UDMF_E_OK);
3148 EXPECT_NE(key[0], '\0');
3149
3150 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3151 options1->intention = UDMF_INTENTION_PICKER;
3152 options1->key = key;
3153 unsigned dataSize1 = 0;
3154 OH_UdmfData* dataArray1 = nullptr;
3155 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray1, &dataSize1);
3156 EXPECT_EQ(getRes, UDMF_E_OK);
3157 unsigned int recordCount = 0;
3158 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray1[0], &recordCount);
3159 EXPECT_EQ(recordCount, 1);
3160 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3161 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3162 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3163 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3164 OH_Udmf_DestroyDataArray(&dataArray1, dataSize1);
3165 OH_UdmfOptions_Destroy(options);
3166 OH_UdmfOptions_Destroy(options1);
3167
3168 OH_UdsFileUri_Destroy(fileUri);
3169 OH_UdsFileUri_Destroy(getFileUri);
3170 OH_UdmfRecord_Destroy(record);
3171 OH_UdmfData_Destroy(udmfUnifiedData);
3172 }
3173
3174 /**
3175 * @tc.name: OH_Udmf_GetUnifiedDataByOptions002
3176 * @tc.desc: OH_Udmf_GetUnifiedDataByOptions with content form
3177 * @tc.type: FUNC
3178 */
3179 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataByOptions002, TestSize.Level1)
3180 {
3181 std::string uri = "https://xxx/xx/xx.jpg";
3182 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3183 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3184 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3185 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3186 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3187 OH_UdmfRecord_AddFileUri(record, fileUri);
3188 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3189 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3190 options->intention = UDMF_INTENTION_MENU;
3191 char key[UDMF_KEY_BUFFER_LEN];
3192
3193 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3194 EXPECT_EQ(setRes, UDMF_E_OK);
3195 EXPECT_NE(key[0], '\0');
3196
3197 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3198 options1->intention = UDMF_INTENTION_MENU;
3199 options1->key = key;
3200 unsigned dataSize1 = 0;
3201 OH_UdmfData* dataArray1 = nullptr;
3202 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray1, &dataSize1);
3203 EXPECT_EQ(getRes, UDMF_E_OK);
3204 unsigned int recordCount = 0;
3205 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray1[0], &recordCount);
3206 EXPECT_EQ(recordCount, 1);
3207 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3208 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3209 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3210 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3211 OH_Udmf_DestroyDataArray(&dataArray1, dataSize1);
3212
3213 OH_UdmfOptions_Destroy(options);
3214 OH_UdmfOptions_Destroy(options1);
3215
3216 OH_UdsFileUri_Destroy(fileUri);
3217 OH_UdsFileUri_Destroy(getFileUri);
3218 OH_UdmfRecord_Destroy(record);
3219 OH_UdmfData_Destroy(udmfUnifiedData);
3220 }
3221
3222 /**
3223 * @tc.name: OH_Udmf_DeleteUnifiedData001
3224 * @tc.desc: OH_Udmf_DeleteUnifiedData with content form
3225 * @tc.type: FUNC
3226 */
3227 HWTEST_F(UDMFTest, OH_Udmf_DeleteUnifiedData001, TestSize.Level1)
3228 {
3229 std::string uri = "https://xxx/xx/xx.jpg";
3230 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3231 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3232 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3233 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3234 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3235 OH_UdmfRecord_AddFileUri(record, fileUri);
3236 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3237 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3238 options->intention = UDMF_INTENTION_DATA_HUB;
3239 char key[UDMF_KEY_BUFFER_LEN];
3240
3241 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3242 EXPECT_EQ(setRes, UDMF_E_OK);
3243 EXPECT_NE(key[0], '\0');
3244
3245 unsigned int dataSize = 0;
3246 OH_UdmfData* dataArray = nullptr;
3247 int dateleRes = OH_Udmf_DeleteUnifiedData(options, &dataArray, &dataSize);
3248 EXPECT_EQ(dateleRes, UDMF_E_OK);
3249 EXPECT_NE(dataArray, nullptr);
3250 unsigned int recordCount = 0;
3251 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray[0], &recordCount);
3252 EXPECT_EQ(recordCount, 1);
3253 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3254 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3255 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3256 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3257 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3258
3259 OH_UdmfOptions_Destroy(options);
3260 OH_UdsFileUri_Destroy(fileUri);
3261 OH_UdsFileUri_Destroy(getFileUri);
3262 OH_UdmfRecord_Destroy(record);
3263 OH_UdmfData_Destroy(udmfUnifiedData);
3264 }
3265
3266 /**
3267 * @tc.name: OH_Udmf_DeleteUnifiedData002
3268 * @tc.desc: OH_Udmf_DeleteUnifiedData with content form
3269 * @tc.type: FUNC
3270 */
3271 HWTEST_F(UDMFTest, OH_Udmf_DeleteUnifiedData002, TestSize.Level1)
3272 {
3273 std::string uri = "https://xxx/xx/xx.jpg";
3274 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3275 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3276 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3277 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3278 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3279 OH_UdmfRecord_AddFileUri(record, fileUri);
3280 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3281 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3282 options->intention = UDMF_INTENTION_SYSTEM_SHARE;
3283 char key[UDMF_KEY_BUFFER_LEN];
3284
3285 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3286 EXPECT_EQ(setRes, UDMF_E_OK);
3287 EXPECT_NE(key[0], '\0');
3288
3289 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3290 options1->intention = UDMF_INTENTION_SYSTEM_SHARE;
3291 options1->key = key;
3292 unsigned int dataSize1 = 0;
3293 OH_UdmfData* dataArray1 = nullptr;
3294 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray1, &dataSize1);
3295 EXPECT_EQ(getRes, UDMF_E_OK);
3296 unsigned int recordCount = 0;
3297 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray1[0], &recordCount);
3298 EXPECT_EQ(recordCount, 1);
3299 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3300 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3301 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3302 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3303 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3304 options2->intention = UDMF_INTENTION_SYSTEM_SHARE;
3305 options2->key = key;
3306 unsigned int dataSize2 = 0;
3307 OH_UdmfData* dataArray2 = nullptr;
3308 int deleteRes = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3309 EXPECT_EQ(deleteRes, UDMF_E_OK);
3310
3311 OH_Udmf_DestroyDataArray(&dataArray1, dataSize1);
3312 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3313
3314 OH_UdmfOptions_Destroy(options);
3315 OH_UdmfOptions_Destroy(options1);
3316 OH_UdmfOptions_Destroy(options2);
3317 OH_UdsFileUri_Destroy(fileUri);
3318 OH_UdsFileUri_Destroy(getFileUri);
3319 OH_UdmfRecord_Destroy(record);
3320 OH_UdmfData_Destroy(udmfUnifiedData);
3321 }
3322
3323 /**
3324 * @tc.name: OH_Udmf_DeleteUnifiedData003
3325 * @tc.desc: OH_Udmf_DeleteUnifiedData with content form
3326 * @tc.type: FUNC
3327 */
3328 HWTEST_F(UDMFTest, OH_Udmf_DeleteUnifiedData003, TestSize.Level1)
3329 {
3330 std::string uri = "https://xxx/xx/xx.jpg";
3331 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3332 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3333 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3334 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3335 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3336 OH_UdmfRecord_AddFileUri(record, fileUri);
3337 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3338 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3339 options->intention = UDMF_INTENTION_PICKER;
3340 char key[UDMF_KEY_BUFFER_LEN];
3341
3342 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3343 EXPECT_EQ(setRes, UDMF_E_OK);
3344 EXPECT_NE(key[0], '\0');
3345
3346 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3347 options2->intention = UDMF_INTENTION_PICKER;
3348 options2->key = key;
3349 unsigned int dataSize2 = 0;
3350 OH_UdmfData* dataArray2 = nullptr;
3351 int deleteRes = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3352 EXPECT_EQ(deleteRes, UDMF_E_OK);
3353 EXPECT_NE(dataArray2, nullptr);
3354 unsigned int recordCount = 0;
3355 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray2[0], &recordCount);
3356 EXPECT_EQ(recordCount, 1);
3357 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3358 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3359 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3360 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3361 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3362
3363 OH_UdmfOptions_Destroy(options);
3364 OH_UdmfOptions_Destroy(options2);
3365 OH_UdsFileUri_Destroy(fileUri);
3366 OH_UdsFileUri_Destroy(getFileUri);
3367 OH_UdmfRecord_Destroy(record);
3368 OH_UdmfData_Destroy(udmfUnifiedData);
3369 }
3370
3371 /**
3372 * @tc.name: OH_Udmf_DeleteUnifiedData004
3373 * @tc.desc: OH_Udmf_DeleteUnifiedData with content form
3374 * @tc.type: FUNC
3375 */
3376 HWTEST_F(UDMFTest, OH_Udmf_DeleteUnifiedData004, TestSize.Level1)
3377 {
3378 std::string uri = "https://xxx/xx/xx.jpg";
3379 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3380 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3381 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3382 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3383 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3384 OH_UdmfRecord_AddFileUri(record, fileUri);
3385 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3386 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3387 options->intention = UDMF_INTENTION_MENU;
3388 char key[UDMF_KEY_BUFFER_LEN];
3389
3390 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3391 EXPECT_EQ(setRes, UDMF_E_OK);
3392 EXPECT_NE(key[0], '\0');
3393
3394 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3395 options2->intention = UDMF_INTENTION_MENU;
3396 options2->key = key;
3397 unsigned int dataSize2 = 0;
3398 OH_UdmfData* dataArray2 = nullptr;
3399 int deleteRes = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3400 EXPECT_EQ(deleteRes, UDMF_E_OK);
3401 EXPECT_NE(dataArray2, nullptr);
3402 unsigned int recordCount = 0;
3403 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray2[0], &recordCount);
3404 EXPECT_EQ(recordCount, 1);
3405 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3406 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3407 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3408 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3409 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3410
3411 OH_UdmfOptions_Destroy(options);
3412 OH_UdmfOptions_Destroy(options2);
3413 OH_UdsFileUri_Destroy(fileUri);
3414 OH_UdsFileUri_Destroy(getFileUri);
3415 OH_UdmfRecord_Destroy(record);
3416 OH_UdmfData_Destroy(udmfUnifiedData);
3417 }
3418
3419 /**
3420 * @tc.name: OH_Udmf_GetUnifiedDataByOptions003
3421 * @tc.desc: OH_Udmf_GetUnifiedDataByOptions with content form
3422 * @tc.type: FUNC
3423 */
3424 HWTEST_F(UDMFTest, OH_Udmf_GetUnifiedDataByOptions003, TestSize.Level1)
3425 {
3426 std::string uri = "https://xxx/xx/xx.jpg";
3427 OH_UdmfData *udmfUnifiedData = OH_UdmfData_Create();
3428 OH_UdmfRecord *record = OH_UdmfRecord_Create();
3429 OH_UdsFileUri *fileUri = OH_UdsFileUri_Create();
3430 OH_UdsFileUri_SetFileUri(fileUri, uri.c_str());
3431 OH_UdsFileUri_SetFileType(fileUri, UDMF_META_IMAGE);
3432 OH_UdmfRecord_AddFileUri(record, fileUri);
3433 OH_UdmfData_AddRecord(udmfUnifiedData, record);
3434 OH_UdmfOptions* options = nullptr;
3435 unsigned int dataSize = 0;
3436 OH_UdmfData* dataArray = nullptr;
3437 int getRes = OH_Udmf_GetUnifiedDataByOptions(options, &dataArray, &dataSize);
3438 EXPECT_EQ(getRes, UDMF_E_INVALID_PARAM);
3439
3440 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3441 options1->intention = UDMF_INTENTION_DRAG;
3442 unsigned int dataSize1 = 0;
3443 OH_UdmfData* dataArray1 = nullptr;
3444 int getRes1 = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray1, &dataSize1);
3445 EXPECT_EQ(getRes1, UDMF_E_INVALID_PARAM);
3446
3447 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3448 options2->intention = UDMF_INTENTION_MENU;
3449 unsigned int dataSize2 = 0;
3450 OH_UdmfData* dataArray2 = nullptr;
3451 int getRes2 = OH_Udmf_GetUnifiedDataByOptions(options2, &dataArray2, &dataSize2);
3452 EXPECT_EQ(getRes2, UDMF_ERR);
3453
3454 OH_UdmfOptions_Destroy(options1);
3455 OH_UdmfOptions_Destroy(options2);
3456 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3457 OH_Udmf_DestroyDataArray(&dataArray1, dataSize1);
3458 OH_UdsFileUri_Destroy(fileUri);
3459 OH_UdmfRecord_Destroy(record);
3460 OH_UdmfData_Destroy(udmfUnifiedData);
3461 }
3462
3463 /**
3464 * @tc.name: OH_Udmf_UpdateUnifiedData002
3465 * @tc.desc: OH_Udmf_UpdateUnifiedData001 with content form
3466 * @tc.type: FUNC
3467 */
3468 HWTEST_F(UDMFTest, OH_Udmf_UpdateUnifiedData002, TestSize.Level1)
3469 {
3470 OH_UdmfData *udmfUnifiedData = nullptr;
3471 OH_UdmfOptions* options = nullptr;
3472 int updataRes = OH_Udmf_UpdateUnifiedData(options, udmfUnifiedData);
3473 EXPECT_EQ(updataRes, UDMF_E_INVALID_PARAM);
3474
3475 std::string uri2 = "https://new/uri/path.jpg";
3476 OH_UdmfData *udmfUnifiedData2 = OH_UdmfData_Create();
3477 OH_UdmfRecord *record2 = OH_UdmfRecord_Create();
3478 OH_UdsFileUri *fileUri2 = OH_UdsFileUri_Create();
3479 OH_UdsFileUri_SetFileUri(fileUri2, uri2.c_str());
3480 OH_UdsFileUri_SetFileType(fileUri2, UDMF_META_IMAGE);
3481 OH_UdmfRecord_AddFileUri(record2, fileUri2);
3482 OH_UdmfData_AddRecord(udmfUnifiedData2, record2);
3483 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3484 options2->intention = UDMF_INTENTION_DRAG;
3485 options2->key = "testKey";
3486 int updataRes1 = OH_Udmf_UpdateUnifiedData(options2, udmfUnifiedData2);
3487 EXPECT_EQ(updataRes1, UDMF_E_INVALID_PARAM);
3488
3489 OH_UdmfOptions_Destroy(options2);
3490 OH_UdsFileUri_Destroy(fileUri2);
3491 OH_UdmfRecord_Destroy(record2);
3492 OH_UdmfData_Destroy(udmfUnifiedData2);
3493 }
3494
3495 /**
3496 * @tc.name: OH_Udmf_UpdateUnifiedData003
3497 * @tc.desc: OH_Udmf_UpdateUnifiedData with content form
3498 * @tc.type: FUNC
3499 */
3500 HWTEST_F(UDMFTest, OH_Udmf_UpdateUnifiedData003, TestSize.Level1)
3501 {
3502 std::string uri = "https://xxx/xx/xx4.jpg";
3503 OH_UdmfData *udmfUnifiedData = CreateImageDataWithFileUri(uri);
3504 OH_UdmfOptions* options = nullptr;
3505 int upDataRes = OH_Udmf_UpdateUnifiedData(options, udmfUnifiedData);
3506 EXPECT_EQ(upDataRes, UDMF_E_INVALID_PARAM);
3507 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3508 upDataRes = OH_Udmf_UpdateUnifiedData(options, udmfUnifiedData);
3509 EXPECT_EQ(upDataRes, UDMF_E_INVALID_PARAM);
3510 OH_UdmfOptions_Destroy(options2);
3511 }
3512
3513 /**
3514 * @tc.name: OH_Udmf_DeleteUnifiedData005
3515 * @tc.desc: OH_Udmf_DeleteUnifiedData with content form
3516 * @tc.type: FUNC
3517 */
3518 HWTEST_F(UDMFTest, OH_Udmf_DeleteUnifiedData005, TestSize.Level1)
3519 {
3520 unsigned int* dataSize = nullptr;
3521 OH_UdmfData* dataArray = nullptr;
3522 OH_UdmfOptions* options = nullptr;
3523 int deleteRes = OH_Udmf_DeleteUnifiedData(options, &dataArray, dataSize);
3524 EXPECT_EQ(deleteRes, UDMF_E_INVALID_PARAM);
3525
3526 unsigned int dataSize2 = 0 ;
3527 OH_UdmfData* dataArray2 = nullptr;
3528 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3529 options2->intention = UDMF_INTENTION_DRAG;
3530 options2->key = "testKey";
3531 int deleteRes2 = OH_Udmf_DeleteUnifiedData(options2, &dataArray2, &dataSize2);
3532 EXPECT_EQ(deleteRes2, UDMF_E_INVALID_PARAM);
3533
3534 OH_UdmfOptions_Destroy(options2);
3535 OH_UdmfData* dataArray1 = nullptr;
3536 OH_Udmf_DestroyDataArray(&dataArray1, dataSize2);
3537 }
3538
3539 /**
3540 * @tc.name: OH_UdmfOptions_GetVisibility001
3541 * @tc.desc: OH_UdmfOptions_GetVisibility with content form
3542 * @tc.type: FUNC
3543 */
3544 HWTEST_F(UDMFTest, OH_UdmfOptions_GetVisibility001, TestSize.Level1)
3545 {
3546 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3547 options->visibility = UDMF_OWN_PROCESS;
3548 Udmf_Visibility getVisibility = OH_UdmfOptions_GetVisibility(options);
3549 EXPECT_EQ(getVisibility, UDMF_OWN_PROCESS);
3550 OH_UdmfOptions_Destroy(options);
3551 }
3552
3553 /**
3554 * @tc.name: OH_UdmfOptions_GetVisibility002
3555 * @tc.desc: OH_UdmfOptions_GetVisibility with content form
3556 * @tc.type: FUNC
3557 */
3558 HWTEST_F(UDMFTest, OH_UdmfOptions_GetVisibility002, TestSize.Level1)
3559 {
3560 OH_UdmfOptions* options = nullptr;
3561 Udmf_Visibility getVisibility = OH_UdmfOptions_GetVisibility(options);
3562 EXPECT_EQ(getVisibility, UDMF_ALL);
3563 }
3564
3565 /**
3566 * @tc.name: OH_UdmfOptions_SetVisibility001
3567 * @tc.desc: OH_UdmfOptions_SetVisibility with content form
3568 * @tc.type: FUNCF
3569 */
3570 HWTEST_F(UDMFTest, OH_UdmfOptions_SetVisibility001, TestSize.Level1)
3571 {
3572 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3573 Udmf_Visibility testVisibility = UDMF_ALL;
3574 int setRes = OH_UdmfOptions_SetVisibility(options, testVisibility);
3575 EXPECT_EQ(setRes, UDMF_E_OK);
3576 OH_UdmfOptions_Destroy(options);
3577 }
3578
3579 /**
3580 * @tc.name: OH_UdmfOptions_SetVisibility002
3581 * @tc.desc: OH_UdmfOptions_SetVisibility with content form
3582 * @tc.type: FUNC
3583 */
3584 HWTEST_F(UDMFTest, OH_UdmfOptions_SetVisibility002, TestSize.Level1)
3585 {
3586 Udmf_Visibility testVisibility = UDMF_ALL;
3587 OH_UdmfOptions* options = nullptr;
3588 int setRes2 = OH_UdmfOptions_SetVisibility(options, testVisibility);
3589 EXPECT_EQ(setRes2, UDMF_E_INVALID_PARAM);
3590 }
3591
3592 /**
3593 * @tc.name: SetVisibilityAndGetVisibility001
3594 * @tc.desc: OH_UdmfOptions_SetVisibility and OH_UdmfOptions_GetVisibility with content form
3595 * @tc.type: FUNC
3596 */
3597 HWTEST_F(UDMFTest, SetVisibilityAndGetVisibility001, TestSize.Level1)
3598 {
3599 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3600 Udmf_Visibility testVisibility = UDMF_ALL;
3601 int setRes = OH_UdmfOptions_SetVisibility(options, testVisibility);
3602 EXPECT_EQ(setRes, UDMF_E_OK);
3603 Udmf_Visibility getVisibility = OH_UdmfOptions_GetVisibility(options);
3604 EXPECT_EQ(getVisibility, testVisibility);
3605 OH_UdmfOptions_Destroy(options);
3606 }
3607
3608 /**
3609 * @tc.name: SetVisibilityAndGetVisibility002
3610 * @tc.desc: OH_UdmfOptions_SetVisibility and OH_UdmfOptions_GetVisibility with content form
3611 * @tc.type: FUNC
3612 */
3613 HWTEST_F(UDMFTest, SetVisibilityAndGetVisibility002, TestSize.Level1)
3614 {
3615 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3616 Udmf_Visibility testVisibility = Udmf_Visibility::UDMF_OWN_PROCESS;
3617 int setRes = OH_UdmfOptions_SetVisibility(options, testVisibility);
3618 EXPECT_EQ(setRes, UDMF_E_OK);
3619 Udmf_Visibility getVisibility = OH_UdmfOptions_GetVisibility(options);
3620 EXPECT_EQ(getVisibility, testVisibility);
3621 OH_UdmfOptions_Destroy(options);
3622 }
3623
3624 /**
3625 * @tc.name: OH_Udmf_SetAndGetUnifiedDataByOptions002
3626 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions and OH_Udmf_GetUnifiedDataByOptions with content form
3627 * @tc.type: FUNC
3628 */
3629 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedDataByOptions002, TestSize.Level1)
3630 {
3631 std::string uri = "https://xxx/xx/xx2.jpg";
3632 OH_UdmfData *udmfUnifiedData = CreateImageDataWithFileUri(uri);
3633 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3634 options->intention = UDMF_INTENTION_DATA_HUB;
3635 options->visibility = UDMF_OWN_PROCESS;
3636 char key[UDMF_KEY_BUFFER_LEN];
3637 unsigned int dataSize3 = 0;
3638 OH_UdmfData* dataArray3 = nullptr;
3639 OH_Udmf_DeleteUnifiedData(options, &dataArray3, &dataSize3);
3640
3641 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3642 EXPECT_EQ(setRes, UDMF_E_OK);
3643 EXPECT_NE(key[0], '\0');
3644
3645 OH_UdmfOptions* options2 = OH_UdmfOptions_Create();
3646 options2->intention = UDMF_INTENTION_DATA_HUB;
3647 options2->key = key;
3648 unsigned int dataSize = 0;
3649 OH_UdmfData* dataArray = nullptr;
3650 int getRes = OH_Udmf_GetUnifiedDataByOptions(options2, &dataArray, &dataSize);
3651 EXPECT_EQ(getRes, UDMF_E_OK);
3652 EXPECT_NE(dataArray, nullptr);
3653
3654 unsigned int recordCount = 0;
3655 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray[0], &recordCount);
3656 EXPECT_EQ(recordCount, 1);
3657 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3658 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3659 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3660 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3661
3662 unsigned int dataSize2 = 0;
3663 OH_UdmfData* dataArray2 = nullptr;
3664 int deleteRes = OH_Udmf_DeleteUnifiedData(options, &dataArray2, &dataSize2);
3665 EXPECT_EQ(deleteRes, UDMF_E_OK);
3666 EXPECT_NE(dataArray2, nullptr);
3667
3668 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3669 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3670 OH_Udmf_DestroyDataArray(&dataArray3, dataSize3);
3671 OH_UdsFileUri_Destroy(getFileUri);
3672 OH_UdmfOptions_Destroy(options);
3673 OH_UdmfData_Destroy(udmfUnifiedData);
3674 }
3675
3676 /**
3677 * @tc.name: OH_Udmf_SetAndGetUnifiedDataByOptions003
3678 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions and OH_Udmf_GetUnifiedDataByOptions with content form
3679 * @tc.type: FUNC
3680 */
3681 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedDataByOptions003, TestSize.Level1)
3682 {
3683 SetHapToken1();
3684 std::string uri = "https://xxx/xx/xx3.jpg";
3685 OH_UdmfData *udmfUnifiedData = CreateImageDataWithFileUri(uri);
3686 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3687 options->intention = UDMF_INTENTION_DATA_HUB;
3688 options->visibility = UDMF_OWN_PROCESS;
3689 char key[UDMF_KEY_BUFFER_LEN];
3690 unsigned int dataSize3 = 0;
3691 OH_UdmfData* dataArray3 = nullptr;
3692 OH_Udmf_DeleteUnifiedData(options, &dataArray3, &dataSize3);
3693 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3694 EXPECT_EQ(setRes, UDMF_E_OK);
3695 EXPECT_NE(key[0], '\0');
3696
3697 SetHapToken2();
3698 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3699 options1->intention = UDMF_INTENTION_DATA_HUB;
3700 options1->key = key;
3701 unsigned int dataSize = 0;
3702 OH_UdmfData* dataArray = nullptr;
3703 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray, &dataSize);
3704 EXPECT_EQ(getRes, UDMF_E_OK);
3705 EXPECT_EQ(dataArray, nullptr);
3706
3707 unsigned int dataSize2 = 0;
3708 OH_UdmfData* dataArray2 = nullptr;
3709 int deleteRes = OH_Udmf_DeleteUnifiedData(options, &dataArray2, &dataSize2);
3710 EXPECT_EQ(deleteRes, UDMF_E_OK);
3711 EXPECT_NE(dataArray2, nullptr);
3712
3713 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3714 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3715 OH_Udmf_DestroyDataArray(&dataArray3, dataSize3);
3716 OH_UdmfOptions_Destroy(options);
3717 OH_UdmfOptions_Destroy(options1);
3718 OH_UdmfData_Destroy(udmfUnifiedData);
3719 }
3720
3721 /**
3722 * @tc.name: OH_Udmf_SetAndGetUnifiedDataByOptions004
3723 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions and OH_Udmf_GetUnifiedDataByOptions with content form
3724 * @tc.type: FUNC
3725 */
3726 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedDataByOptions004, TestSize.Level1)
3727 {
3728 SetHapToken1();
3729 std::string uri = "https://xxx/xx/xx4.jpg";
3730 OH_UdmfData *udmfUnifiedData = CreateImageDataWithFileUri(uri);
3731 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3732 options->intention = UDMF_INTENTION_DATA_HUB;
3733 options->visibility = UDMF_ALL;
3734 char key[UDMF_KEY_BUFFER_LEN];
3735
3736 unsigned int dataSize3 = 0;
3737 OH_UdmfData* dataArray3 = nullptr;
3738 OH_Udmf_DeleteUnifiedData(options, &dataArray3, &dataSize3);
3739 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3740 EXPECT_EQ(setRes, UDMF_E_OK);
3741 EXPECT_NE(key[0], '\0');
3742
3743 SetHapToken2();
3744 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3745 options1->intention = UDMF_INTENTION_DATA_HUB;
3746 options1->key = key;
3747 unsigned int dataSize = 0;
3748 OH_UdmfData* dataArray = nullptr;
3749 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray, &dataSize);
3750 EXPECT_EQ(getRes, UDMF_E_OK);
3751 EXPECT_NE(dataArray, nullptr);
3752
3753 unsigned int recordCount = 0;
3754 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray[0], &recordCount);
3755 EXPECT_EQ(recordCount, 1);
3756 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3757 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3758 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3759 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3760
3761 unsigned int dataSize2 = 0;
3762 OH_UdmfData* dataArray2 = nullptr;
3763 int deleteRes = OH_Udmf_DeleteUnifiedData(options, &dataArray2, &dataSize2);
3764 EXPECT_EQ(deleteRes, UDMF_E_OK);
3765 EXPECT_NE(dataArray2, nullptr);
3766
3767 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3768 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3769 OH_Udmf_DestroyDataArray(&dataArray3, dataSize3);
3770 OH_UdsFileUri_Destroy(getFileUri);
3771 OH_UdmfOptions_Destroy(options);
3772 OH_UdmfOptions_Destroy(options1);
3773 OH_UdmfData_Destroy(udmfUnifiedData);
3774 }
3775
3776 /**
3777 * @tc.name: OH_Udmf_SetAndGetUnifiedDataByOptions005
3778 * @tc.desc: OH_Udmf_SetUnifiedDataByOptions and OH_Udmf_GetUnifiedDataByOptions with content form
3779 * @tc.type: FUNC
3780 */
3781 HWTEST_F(UDMFTest, OH_Udmf_SetAndGetUnifiedDataByOptions005, TestSize.Level1)
3782 {
3783 std::string uri = "https://xxx/xx/xx5.jpg";
3784 OH_UdmfData *udmfUnifiedData = CreateImageDataWithFileUri(uri);
3785 OH_UdmfOptions* options = OH_UdmfOptions_Create();
3786 options->intention = UDMF_INTENTION_DATA_HUB;
3787 options->visibility = UDMF_ALL;
3788 char key[UDMF_KEY_BUFFER_LEN];
3789
3790 unsigned int dataSize3 = 0;
3791 OH_UdmfData* dataArray3 = nullptr;
3792 OH_Udmf_DeleteUnifiedData(options, &dataArray3, &dataSize3);
3793 int setRes = OH_Udmf_SetUnifiedDataByOptions(options, udmfUnifiedData, key, UDMF_KEY_BUFFER_LEN);
3794 EXPECT_EQ(setRes, UDMF_E_OK);
3795 EXPECT_NE(key[0], '\0');
3796
3797 OH_UdmfOptions* options1 = OH_UdmfOptions_Create();
3798 options1->intention = UDMF_INTENTION_DATA_HUB;
3799 options1->key = key;
3800 unsigned int dataSize = 0;
3801 OH_UdmfData* dataArray = nullptr;
3802 int getRes = OH_Udmf_GetUnifiedDataByOptions(options1, &dataArray, &dataSize);
3803 EXPECT_EQ(getRes, UDMF_E_OK);
3804 EXPECT_NE(dataArray, nullptr);
3805
3806 unsigned int recordCount = 0;
3807 OH_UdmfRecord** getRecords = OH_UdmfData_GetRecords(&dataArray[0], &recordCount);
3808 EXPECT_EQ(recordCount, 1);
3809 OH_UdsFileUri *getFileUri = OH_UdsFileUri_Create();
3810 OH_UdmfRecord_GetFileUri(getRecords[0], getFileUri);
3811 const char *getUri = OH_UdsFileUri_GetFileUri(getFileUri);
3812 EXPECT_EQ(strcmp(getUri, uri.c_str()), 0);
3813
3814 unsigned int dataSize2 = 0;
3815 OH_UdmfData* dataArray2 = nullptr;
3816 int deleteRes = OH_Udmf_DeleteUnifiedData(options, &dataArray2, &dataSize2);
3817 EXPECT_EQ(deleteRes, UDMF_E_OK);
3818 EXPECT_NE(dataArray2, nullptr);
3819
3820 OH_Udmf_DestroyDataArray(&dataArray, dataSize);
3821 OH_Udmf_DestroyDataArray(&dataArray2, dataSize2);
3822 OH_Udmf_DestroyDataArray(&dataArray3, dataSize3);
3823 OH_UdsFileUri_Destroy(getFileUri);
3824 OH_UdmfOptions_Destroy(options);
3825 OH_UdmfOptions_Destroy(options1);
3826 OH_UdmfData_Destroy(udmfUnifiedData);
3827 }
3828
3829 /**
3830 * @tc.name: DestroyUnifiedRecordArray001
3831 * @tc.desc: test DestroyUnifiedRecordArray
3832 * @tc.type: FUNC
3833 */
3834 HWTEST_F(UDMFTest, DestroyUnifiedRecordArray001, TestSize.Level1)
3835 {
3836 OH_UdmfData *unifiedData = OH_UdmfData_Create();
3837 EXPECT_NE(unifiedData, nullptr);
3838 std::shared_ptr<Object> object = std::make_shared<Object>();
3839 std::map<std::string, ValueType> map;
3840 map["uniformDataType"] = UtdUtils::GetUtdIdFromUtdEnum(UDType::PLAIN_TEXT);
3841 map["textContent"] = "content";
3842 map["abstract"] = "abstract";
3843 object->value_ = map;
3844 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(PLAIN_TEXT, object);
3845 std::vector<std::shared_ptr<UnifiedRecord>> recordVec = { record };
3846 unifiedData->records = nullptr;
3847 unifiedData->unifiedData_->SetRecords(recordVec);
3848 unsigned int recordCount = 0;
3849 OH_UdmfRecord **getRecords = OH_UdmfData_GetRecords(unifiedData, &recordCount);
3850 EXPECT_EQ(recordCount, 1);
3851 EXPECT_EQ(unifiedData->recordsCount, 1);
3852 EXPECT_NE(getRecords[0], nullptr);
3853 getRecords[0]->recordDataLen = 1;
3854 getRecords[0]->recordData = new (std::nothrow) unsigned char[getRecords[0]->recordDataLen];
3855 unifiedData->records = getRecords;
3856 OH_UdmfData_Destroy(unifiedData);
3857 EXPECT_EQ(unifiedData->recordsCount, 0);
3858 }
3859 }
3860