1 /*
2 * Copyright (c) 2023 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 #define LOG_TAG "UdmfClientTest"
16 #include <gtest/gtest.h>
17
18 #include <unistd.h>
19 #include <thread>
20 #include <chrono>
21
22 #include "token_setproc.h"
23 #include "accesstoken_kit.h"
24 #include "directory_ex.h"
25 #include "nativetoken_kit.h"
26
27 #include "logger.h"
28 #include "udmf_client.h"
29 #include "application_defined_record.h"
30 #include "audio.h"
31 #include "file.h"
32 #include "folder.h"
33 #include "html.h"
34 #include "image.h"
35 #include "link.h"
36 #include "plain_text.h"
37 #include "system_defined_appitem.h"
38 #include "system_defined_form.h"
39 #include "system_defined_pixelmap.h"
40 #include "system_defined_record.h"
41 #include "text.h"
42 #include "unified_data_helper.h"
43 #include "unified_html_record_process.h"
44 #include "video.h"
45
46 using namespace testing::ext;
47 using namespace OHOS::Security::AccessToken;
48 using namespace OHOS::UDMF;
49 using namespace OHOS;
50 namespace OHOS::Test {
51 constexpr int SLEEP_TIME = 50; // 50 ms
52 class UdmfClientTest : public testing::Test {
53 public:
54 static void SetUpTestCase();
55 static void TearDownTestCase();
56 void SetUp() override;
57 void TearDown() override;
58
59 void SetNativeToken(const std::string &processName);
60 static void AllocHapToken1();
61 static void AllocHapToken2();
62 void SetHapToken1();
63 void SetHapToken2();
64
65 void AddPrivilege(QueryOption &option);
66 void AddPrivilege1(QueryOption &option);
67 void CompareDetails(const UDDetails &details);
68 void GetEmptyData(QueryOption &option);
69 void GetFileUriUnifiedData(UnifiedData &data);
70
71 static constexpr int USER_ID = 100;
72 static constexpr int INST_INDEX = 0;
73 };
74
SetUpTestCase()75 void UdmfClientTest::SetUpTestCase()
76 {
77 AllocHapToken1();
78 AllocHapToken2();
79 }
80
TearDownTestCase()81 void UdmfClientTest::TearDownTestCase()
82 {
83 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
84 AccessTokenKit::DeleteToken(tokenId);
85 tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
86 AccessTokenKit::DeleteToken(tokenId);
87 }
88
SetUp()89 void UdmfClientTest::SetUp()
90 {
91 SetHapToken1();
92 }
93
TearDown()94 void UdmfClientTest::TearDown()
95 {
96 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
97 std::vector<UnifiedData> unifiedDataSet;
98 UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
99 query = { .intention = Intention::UD_INTENTION_DRAG };
100 UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
101 }
102
SetNativeToken(const std::string & processName)103 void UdmfClientTest::SetNativeToken(const std::string &processName)
104 {
105 auto tokenId = AccessTokenKit::GetNativeTokenId(processName);
106 SetSelfTokenID(tokenId);
107 }
108
AllocHapToken1()109 void UdmfClientTest::AllocHapToken1()
110 {
111 HapInfoParams info = {
112 .userID = USER_ID,
113 .bundleName = "ohos.test.demo1",
114 .instIndex = INST_INDEX,
115 .appIDDesc = "ohos.test.demo1"
116 };
117
118 HapPolicyParams policy = {
119 .apl = APL_NORMAL,
120 .domain = "test.domain",
121 .permList = {
122 {
123 .permissionName = "ohos.permission.test",
124 .bundleName = "ohos.test.demo1",
125 .grantMode = 1,
126 .availableLevel = APL_NORMAL,
127 .label = "label",
128 .labelId = 1,
129 .description = "test1",
130 .descriptionId = 1
131 }
132 },
133 .permStateList = {
134 {
135 .permissionName = "ohos.permission.test",
136 .isGeneral = true,
137 .resDeviceID = { "local" },
138 .grantStatus = { PermissionState::PERMISSION_GRANTED },
139 .grantFlags = { 1 }
140 }
141 }
142 };
143 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
144 SetSelfTokenID(tokenID.tokenIDEx);
145 }
146
AllocHapToken2()147 void UdmfClientTest::AllocHapToken2()
148 {
149 HapInfoParams info = {
150 .userID = USER_ID,
151 .bundleName = "ohos.test.demo2",
152 .instIndex = INST_INDEX,
153 .appIDDesc = "ohos.test.demo2"
154 };
155
156 HapPolicyParams policy = {
157 .apl = APL_NORMAL,
158 .domain = "test.domain",
159 .permList = {
160 {
161 .permissionName = "ohos.permission.test",
162 .bundleName = "ohos.test.demo2",
163 .grantMode = 1,
164 .availableLevel = APL_NORMAL,
165 .label = "label",
166 .labelId = 1,
167 .description = "test2",
168 .descriptionId = 1
169 }
170 },
171 .permStateList = {
172 {
173 .permissionName = "ohos.permission.test",
174 .isGeneral = true,
175 .resDeviceID = { "local" },
176 .grantStatus = { PermissionState::PERMISSION_GRANTED },
177 .grantFlags = { 1 }
178 }
179 }
180 };
181 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
182 SetSelfTokenID(tokenID.tokenIDEx);
183 }
184
SetHapToken1()185 void UdmfClientTest::SetHapToken1()
186 {
187 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
188 SetSelfTokenID(tokenId);
189 }
190
SetHapToken2()191 void UdmfClientTest::SetHapToken2()
192 {
193 auto tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
194 SetSelfTokenID(tokenId);
195 }
196
AddPrivilege(QueryOption & option)197 void UdmfClientTest::AddPrivilege(QueryOption &option)
198 {
199 Privilege privilege;
200 privilege.tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo2", INST_INDEX);
201 privilege.readPermission = "readPermission";
202 privilege.writePermission = "writePermission";
203 SetNativeToken("msdp_sa");
204 auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
205 ASSERT_EQ(status, E_OK);
206 }
207
AddPrivilege1(QueryOption & option)208 void UdmfClientTest::AddPrivilege1(QueryOption &option)
209 {
210 Privilege privilege;
211 privilege.tokenId = AccessTokenKit::GetHapTokenID(USER_ID, "ohos.test.demo1", INST_INDEX);
212 privilege.readPermission = "readPermission";
213 privilege.writePermission = "writePermission";
214 SetNativeToken("msdp_sa");
215 auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
216 ASSERT_EQ(status, E_OK);
217 }
218
CompareDetails(const UDDetails & details)219 void UdmfClientTest::CompareDetails(const UDDetails &details)
220 {
221 for (const auto &detail : details) {
222 auto key = detail.first;
223 EXPECT_EQ(key, "udmf_key");
224 auto value = detail.second;
225 auto str = std::get<std::string>(value);
226 EXPECT_EQ(str, "udmf_value");
227 }
228 }
229
GetEmptyData(QueryOption & option)230 void UdmfClientTest::GetEmptyData(QueryOption &option)
231 {
232 UnifiedData data;
233 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
234 auto status = UdmfClient::GetInstance().GetData(option, data);
235 EXPECT_EQ(status, E_NOT_FOUND);
236 }
237
GetFileUriUnifiedData(UnifiedData & data)238 void UdmfClientTest::GetFileUriUnifiedData(UnifiedData &data)
239 {
240 std::shared_ptr<Object> obj = std::make_shared<Object>();
241 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
242 obj->value_[FILE_URI_PARAM] = "http://demo.com";
243 obj->value_[FILE_TYPE] = "abcdefg";
244 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
245
246 std::shared_ptr<Object> obj1 = std::make_shared<Object>();
247 obj1->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
248 obj1->value_[FILE_URI_PARAM] = "http://demo.com";
249 obj1->value_[FILE_TYPE] = "general.image";
250 auto record1 = std::make_shared<UnifiedRecord>(FILE_URI, obj1);
251
252 std::shared_ptr<Object> obj2 = std::make_shared<Object>();
253 obj2->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
254 obj2->value_[FILE_URI_PARAM] = "http://demo.com";
255 obj2->value_[FILE_TYPE] = "general.audio";
256 auto record2 = std::make_shared<UnifiedRecord>(FILE_URI, obj2);
257 data.AddRecord(record);
258 data.AddRecord(record1);
259 data.AddRecord(record2);
260 }
261
262 /**
263 * @tc.name: SetData001
264 * @tc.desc: Set data with invalid params
265 * @tc.type: FUNC
266 */
267 HWTEST_F(UdmfClientTest, SetData001, TestSize.Level1)
268 {
269 LOG_INFO(UDMF_TEST, "SetData001 begin.");
270
271 CustomOption option = { .intention = Intention::UD_INTENTION_DRAG };
272 UnifiedData data;
273 std::string key;
274 auto status = UdmfClient::GetInstance().SetData(option, data, key);
275 EXPECT_EQ(status, E_INVALID_PARAMETERS);
276
277 option = { .intention = Intention::UD_INTENTION_BUTT };
278 auto text = std::make_shared<Text>();
279 UDDetails details;
280 details.insert({ "udmf_key", "udmf_value" });
281 text->SetDetails(details);
282 data.AddRecord(text);
283 status = UdmfClient::GetInstance().SetData(option, data, key);
284 EXPECT_EQ(status, E_INVALID_PARAMETERS);
285
286 option = {};
287 status = UdmfClient::GetInstance().SetData(option, data, key);
288 EXPECT_EQ(status, E_INVALID_PARAMETERS);
289
290 option = { .intention = Intention::UD_INTENTION_BASE };
291 status = UdmfClient::GetInstance().SetData(option, data, key);
292 EXPECT_EQ(status, E_INVALID_PARAMETERS);
293 LOG_INFO(UDMF_TEST, "SetData001 end.");
294 }
295
296 /**
297 * @tc.name: SetData002
298 * @tc.desc: Set Text record with valid params and get data
299 * @tc.type: FUNC
300 */
301 HWTEST_F(UdmfClientTest, SetData002, TestSize.Level1)
302 {
303 LOG_INFO(UDMF_TEST, "SetData002 begin.");
304
305 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
306 UnifiedData data1;
307 auto text1 = std::make_shared<Text>();
308 UDDetails details1;
309 details1.insert({ "udmf_key", "udmf_value" });
310 text1->SetDetails(details1);
311 data1.AddRecord(text1);
312 std::string key;
313 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
314 ASSERT_EQ(status, E_OK);
315
316 QueryOption option2 = { .key = key };
317 AddPrivilege(option2);
318 SetHapToken2();
319 UnifiedData data2;
320 status = UdmfClient::GetInstance().GetData(option2, data2);
321 ASSERT_EQ(status, E_OK);
322
323 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
324 ASSERT_NE(record2, nullptr);
325 auto type = record2->GetType();
326 EXPECT_EQ(type, UDType::TEXT);
327
328 auto text2 = static_cast<Text *>(record2.get());
329 ASSERT_NE(text2, nullptr);
330 CompareDetails(text2->GetDetails());
331
332 GetEmptyData(option2);
333
334 LOG_INFO(UDMF_TEST, "SetData002 end.");
335 }
336
337 /**
338 * @tc.name: SetData003
339 * @tc.desc: Set PlainText record with valid params and get data
340 * @tc.type: FUNC
341 */
342 HWTEST_F(UdmfClientTest, SetData003, TestSize.Level1)
343 {
344 LOG_INFO(UDMF_TEST, "SetData003 begin.");
345
346 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
347 UnifiedData data1;
348 auto plainText1 = std::make_shared<PlainText>();
349 UDDetails details1;
350 details1.insert({ "udmf_key", "udmf_value" });
351 plainText1->SetDetails(details1);
352 plainText1->SetContent("content");
353 plainText1->SetAbstract("abstract");
354 data1.AddRecord(plainText1);
355 std::string key;
356 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
357 ASSERT_EQ(status, E_OK);
358
359 QueryOption option2 = { .key = key };
360 AddPrivilege(option2);
361 SetHapToken2();
362 UnifiedData data2;
363 status = UdmfClient::GetInstance().GetData(option2, data2);
364 ASSERT_EQ(status, E_OK);
365
366 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
367 ASSERT_NE(record2, nullptr);
368 auto type = record2->GetType();
369 ASSERT_EQ(type, UDType::PLAIN_TEXT);
370
371 auto text2 = static_cast<Text *>(record2.get());
372 ASSERT_NE(text2, nullptr);
373 CompareDetails(text2->GetDetails());
374
375 auto plainText2 = static_cast<PlainText *>(record2.get());
376 ASSERT_NE(plainText2, nullptr);
377 EXPECT_EQ(plainText1->GetContent(), plainText2->GetContent());
378 EXPECT_EQ(plainText1->GetAbstract(), plainText2->GetAbstract());
379
380 GetEmptyData(option2);
381
382 LOG_INFO(UDMF_TEST, "SetData003 end.");
383 }
384
385 /**
386 * @tc.name: SetData004
387 * @tc.desc: Set Html record with valid params and get data
388 * @tc.type: FUNC
389 */
390 HWTEST_F(UdmfClientTest, SetData004, TestSize.Level1)
391 {
392 LOG_INFO(UDMF_TEST, "SetData004 begin.");
393
394 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
395 UnifiedData data1;
396 std::string key;
397 auto html1 = std::make_shared<Html>();
398 UDDetails details1;
399 details1.insert({ "udmf_key", "udmf_value" });
400 html1->SetDetails(details1);
401 html1->SetHtmlContent("htmlcontent");
402 html1->SetPlainContent("plainContent");
403 data1.AddRecord(html1);
404 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
405 ASSERT_EQ(status, E_OK);
406
407 QueryOption option2 = { .key = key };
408 AddPrivilege(option2);
409 SetHapToken2();
410 UnifiedData data2;
411 status = UdmfClient::GetInstance().GetData(option2, data2);
412 ASSERT_EQ(status, E_OK);
413
414 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
415 ASSERT_NE(record2, nullptr);
416 auto type = record2->GetType();
417 ASSERT_EQ(type, UDType::HTML);
418
419 auto text2 = static_cast<Text *>(record2.get());
420 ASSERT_NE(text2, nullptr);
421 CompareDetails(text2->GetDetails());
422
423 auto html2 = static_cast<Html *>(record2.get());
424 ASSERT_NE(html2, nullptr);
425 EXPECT_EQ(html1->GetHtmlContent(), html2->GetHtmlContent());
426 EXPECT_EQ(html1->GetPlainContent(), html2->GetPlainContent());
427
428 GetEmptyData(option2);
429
430 LOG_INFO(UDMF_TEST, "SetData004 end.");
431 }
432
433 /**
434 * @tc.name: SetData005
435 * @tc.desc: Set Link record with valid params and get data
436 * @tc.type: FUNC
437 */
438 HWTEST_F(UdmfClientTest, SetData005, TestSize.Level1)
439 {
440 LOG_INFO(UDMF_TEST, "SetData005 begin.");
441
442 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
443 UnifiedData data1;
444 std::string key;
445 auto link1 = std::make_shared<Link>();
446 UDDetails details1;
447 details1.insert({ "udmf_key", "udmf_value" });
448 link1->SetDetails(details1);
449 link1->SetUrl("url");
450 link1->SetDescription("description");
451 data1.AddRecord(link1);
452 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
453 ASSERT_EQ(status, E_OK);
454
455 QueryOption option2 = { .key = key };
456 AddPrivilege(option2);
457 SetHapToken2();
458 UnifiedData data2;
459 status = UdmfClient::GetInstance().GetData(option2, data2);
460 ASSERT_EQ(status, E_OK);
461
462 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
463 ASSERT_NE(record2, nullptr);
464 auto type = record2->GetType();
465 ASSERT_EQ(type, UDType::HYPERLINK);
466
467 auto text2 = static_cast<Text *>(record2.get());
468 ASSERT_NE(text2, nullptr);
469 CompareDetails(text2->GetDetails());
470
471 auto link2 = static_cast<Link *>(record2.get());
472 ASSERT_NE(link2, nullptr);
473 EXPECT_EQ(link1->GetUrl(), link2->GetUrl());
474 EXPECT_EQ(link1->GetDescription(), link2->GetDescription());
475
476 GetEmptyData(option2);
477
478 LOG_INFO(UDMF_TEST, "SetData005 end.");
479 }
480
481 /**
482 * @tc.name: SetData006
483 * @tc.desc: Set File record with valid params and get data
484 * @tc.type: FUNC
485 */
486 HWTEST_F(UdmfClientTest, SetData006, TestSize.Level1)
487 {
488 LOG_INFO(UDMF_TEST, "SetData006 begin.");
489
490 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
491 UnifiedData data1;
492 std::string key;
493 auto file1 = std::make_shared<File>();
494 file1->SetRemoteUri("remoteUri");
495 UDDetails details1;
496 details1.insert({ "udmf_key", "udmf_value" });
497 file1->SetDetails(details1);
498 data1.AddRecord(file1);
499 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
500 ASSERT_EQ(status, E_OK);
501
502 QueryOption option2 = { .key = key };
503 AddPrivilege(option2);
504 SetHapToken2();
505 UnifiedData data2;
506 status = UdmfClient::GetInstance().GetData(option2, data2);
507 ASSERT_EQ(status, E_OK);
508
509 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
510 ASSERT_NE(record2, nullptr);
511 auto type = record2->GetType();
512 ASSERT_EQ(type, UDType::FILE);
513
514 auto file2 = static_cast<File *>(record2.get());
515 ASSERT_NE(file2, nullptr);
516 EXPECT_EQ(file1->GetRemoteUri(), file2->GetRemoteUri());
517 CompareDetails(file2->GetDetails());
518
519 GetEmptyData(option2);
520
521 LOG_INFO(UDMF_TEST, "SetData006 end.");
522 }
523
524 /**
525 * @tc.name: SetData007
526 * @tc.desc: Set Image record with valid params and get data
527 * @tc.type: FUNC
528 */
529 HWTEST_F(UdmfClientTest, SetData007, TestSize.Level1)
530 {
531 LOG_INFO(UDMF_TEST, "SetData007 begin.");
532
533 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
534 UnifiedData data1;
535 std::string key;
536 auto image1 = std::make_shared<Image>();
537 UDDetails details1;
538 details1.insert({ "udmf_key", "udmf_value" });
539 image1->SetDetails(details1);
540 image1->SetRemoteUri("remoteUri");
541 data1.AddRecord(image1);
542 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
543 ASSERT_EQ(status, E_OK);
544
545 QueryOption option2 = { .key = key };
546 AddPrivilege(option2);
547 SetHapToken2();
548 UnifiedData data2;
549 status = UdmfClient::GetInstance().GetData(option2, data2);
550 ASSERT_EQ(status, E_OK);
551
552 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
553 ASSERT_NE(record2, nullptr);
554 auto type = record2->GetType();
555 ASSERT_EQ(type, UDType::IMAGE);
556
557 auto file2 = static_cast<File *>(record2.get());
558 ASSERT_NE(file2, nullptr);
559 CompareDetails(file2->GetDetails());
560
561 auto image2 = static_cast<Image *>(record2.get());
562 ASSERT_NE(image2, nullptr);
563 EXPECT_EQ(image1->GetRemoteUri(), image2->GetRemoteUri());
564
565 GetEmptyData(option2);
566
567 LOG_INFO(UDMF_TEST, "SetData007 end.");
568 }
569
570 /**
571 * @tc.name: SetData008
572 * @tc.desc: Set Video record with valid params and get data
573 * @tc.type: FUNC
574 */
575 HWTEST_F(UdmfClientTest, SetData008, TestSize.Level1)
576 {
577 LOG_INFO(UDMF_TEST, "SetData008 begin.");
578
579 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
580 UnifiedData data1;
581 std::string key;
582 auto video1 = std::make_shared<Video>();
583 UDDetails details1;
584 details1.insert({ "udmf_key", "udmf_value" });
585 video1->SetDetails(details1);
586 video1->SetRemoteUri("remoteUri");
587 data1.AddRecord(video1);
588 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
589 ASSERT_EQ(status, E_OK);
590
591 QueryOption option2 = { .key = key };
592 AddPrivilege(option2);
593 SetHapToken2();
594 UnifiedData data2;
595 status = UdmfClient::GetInstance().GetData(option2, data2);
596 ASSERT_EQ(status, E_OK);
597
598 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
599 ASSERT_NE(record2, nullptr);
600 auto type = record2->GetType();
601 EXPECT_EQ(type, UDType::VIDEO);
602
603 auto file2 = static_cast<File *>(record2.get());
604 ASSERT_NE(file2, nullptr);
605 CompareDetails(file2->GetDetails());
606
607 auto video2 = static_cast<Video *>(record2.get());
608 ASSERT_NE(video2, nullptr);
609 EXPECT_EQ(video1->GetRemoteUri(), video2->GetRemoteUri());
610
611 GetEmptyData(option2);
612
613 LOG_INFO(UDMF_TEST, "SetData008 end.");
614 }
615
616 /**
617 * @tc.name: SetData009
618 * @tc.desc: Set Audio record with valid params and get data
619 * @tc.type: FUNC
620 */
621 HWTEST_F(UdmfClientTest, SetData009, TestSize.Level1)
622 {
623 LOG_INFO(UDMF_TEST, "SetData009 begin.");
624
625 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
626 UnifiedData data1;
627 std::string key;
628 auto audio1 = std::make_shared<Audio>();
629 UDDetails details1;
630 details1.insert({ "udmf_key", "udmf_value" });
631 audio1->SetDetails(details1);
632 audio1->SetRemoteUri("remoteUri");
633 data1.AddRecord(audio1);
634 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
635 ASSERT_EQ(status, E_OK);
636
637 QueryOption option2 = { .key = key };
638 AddPrivilege(option2);
639 SetHapToken2();
640 UnifiedData data2;
641 status = UdmfClient::GetInstance().GetData(option2, data2);
642 ASSERT_EQ(status, E_OK);
643
644 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
645 ASSERT_NE(record2, nullptr);
646 auto type = record2->GetType();
647 EXPECT_EQ(type, UDType::AUDIO);
648
649 auto file2 = static_cast<File *>(record2.get());
650 ASSERT_NE(file2, nullptr);
651 CompareDetails(file2->GetDetails());
652
653 auto audio2 = static_cast<Audio *>(record2.get());
654 ASSERT_NE(audio2, nullptr);
655 EXPECT_EQ(audio1->GetRemoteUri(), audio2->GetRemoteUri());
656
657 GetEmptyData(option2);
658
659 LOG_INFO(UDMF_TEST, "SetData009 end.");
660 }
661
662 /**
663 * @tc.name: SetData010
664 * @tc.desc: Set Folder record with valid params and get data
665 * @tc.type: FUNC
666 */
667 HWTEST_F(UdmfClientTest, SetData010, TestSize.Level1)
668 {
669 LOG_INFO(UDMF_TEST, "SetData010 begin.");
670
671 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
672 UnifiedData data1;
673 std::string key;
674 auto folder1 = std::make_shared<Folder>();
675 UDDetails details1;
676 details1.insert({ "udmf_key", "udmf_value" });
677 folder1->SetDetails(details1);
678 folder1->SetRemoteUri("remoteUri");
679 data1.AddRecord(folder1);
680 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
681 ASSERT_EQ(status, E_OK);
682
683 QueryOption option2 = { .key = key };
684 AddPrivilege(option2);
685 SetHapToken2();
686 UnifiedData data2;
687 status = UdmfClient::GetInstance().GetData(option2, data2);
688 ASSERT_EQ(status, E_OK);
689
690 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
691 ASSERT_NE(record2, nullptr);
692 auto type = record2->GetType();
693 EXPECT_EQ(type, UDType::FOLDER);
694
695 auto file2 = static_cast<File *>(record2.get());
696 ASSERT_NE(file2, nullptr);
697 CompareDetails(file2->GetDetails());
698
699 auto folder2 = static_cast<Folder *>(record2.get());
700 ASSERT_NE(folder2, nullptr);
701 EXPECT_EQ(folder1->GetRemoteUri(), folder2->GetRemoteUri());
702
703 GetEmptyData(option2);
704
705 LOG_INFO(UDMF_TEST, "SetData010 end.");
706 }
707
708 /**
709 * @tc.name: SetData011
710 * @tc.desc: Set SystemDefined record with valid params and get data
711 * @tc.type: FUNC
712 */
713 HWTEST_F(UdmfClientTest, SetData011, TestSize.Level1)
714 {
715 LOG_INFO(UDMF_TEST, "SetData011 begin.");
716
717 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
718 UnifiedData data1;
719 std::string key;
720 auto systemDefinedRecord1 = std::make_shared<SystemDefinedRecord>();
721 UDDetails details1;
722 details1.insert({ "udmf_key", "udmf_value" });
723 systemDefinedRecord1->SetDetails(details1);
724 data1.AddRecord(systemDefinedRecord1);
725 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
726 ASSERT_EQ(status, E_OK);
727
728 QueryOption option2 = { .key = key };
729 AddPrivilege(option2);
730 SetHapToken2();
731 UnifiedData data2;
732 status = UdmfClient::GetInstance().GetData(option2, data2);
733 ASSERT_EQ(status, E_OK);
734
735 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
736 ASSERT_NE(record2, nullptr);
737 auto type = record2->GetType();
738 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_RECORD);
739
740 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record2.get());
741 ASSERT_NE(systemDefinedRecord2, nullptr);
742 CompareDetails(systemDefinedRecord2->GetDetails());
743
744 GetEmptyData(option2);
745
746 LOG_INFO(UDMF_TEST, "SetData011 end.");
747 }
748
749 /**
750 * @tc.name: SetData012
751 * @tc.desc: Set Form record with valid params and get data
752 * @tc.type: FUNC
753 */
754 HWTEST_F(UdmfClientTest, SetData012, TestSize.Level1)
755 {
756 LOG_INFO(UDMF_TEST, "SetData012 begin.");
757
758 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
759 UnifiedData data1;
760 std::string key;
761 auto systemDefinedForm1 = std::make_shared<SystemDefinedForm>();
762 UDDetails details1;
763 details1.insert({ "udmf_key", "udmf_value" });
764 systemDefinedForm1->SetDetails(details1);
765 systemDefinedForm1->SetFormId(123);
766 systemDefinedForm1->SetFormName("formName");
767 systemDefinedForm1->SetModule("module");
768 systemDefinedForm1->SetAbilityName("abilityName");
769 systemDefinedForm1->SetBundleName("bundleName");
770 data1.AddRecord(systemDefinedForm1);
771 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
772 ASSERT_EQ(status, E_OK);
773
774 QueryOption option2 = { .key = key };
775 AddPrivilege(option2);
776 SetHapToken2();
777 UnifiedData data2;
778 status = UdmfClient::GetInstance().GetData(option2, data2);
779 ASSERT_EQ(status, E_OK);
780
781 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
782 ASSERT_NE(record2, nullptr);
783 auto type = record2->GetType();
784 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_FORM);
785
786 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record2.get());
787 ASSERT_NE(systemDefinedRecord2, nullptr);
788 CompareDetails(systemDefinedRecord2->GetDetails());
789
790 auto systemDefinedForm2 = static_cast<SystemDefinedForm *>(record2.get());
791 ASSERT_NE(systemDefinedForm2, nullptr);
792 EXPECT_EQ(systemDefinedForm1->GetFormId(), systemDefinedForm2->GetFormId());
793 EXPECT_EQ(systemDefinedForm1->GetFormName(), systemDefinedForm2->GetFormName());
794 EXPECT_EQ(systemDefinedForm1->GetBundleName(), systemDefinedForm2->GetBundleName());
795 EXPECT_EQ(systemDefinedForm1->GetAbilityName(), systemDefinedForm2->GetAbilityName());
796 EXPECT_EQ(systemDefinedForm1->GetModule(), systemDefinedForm2->GetModule());
797
798 GetEmptyData(option2);
799
800 LOG_INFO(UDMF_TEST, "SetData012 end.");
801 }
802
803 /**
804 * @tc.name: SetData013
805 * @tc.desc: Set AppItem record with valid params and get data
806 * @tc.type: FUNC
807 */
808 HWTEST_F(UdmfClientTest, SetData013, TestSize.Level1)
809 {
810 LOG_INFO(UDMF_TEST, "SetData013 begin.");
811
812 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
813 UnifiedData data1;
814 std::string key;
815 auto systemDefinedAppItem1 = std::make_shared<SystemDefinedAppItem>();
816 UDDetails details1;
817 details1.insert({ "udmf_key", "udmf_value" });
818 systemDefinedAppItem1->SetDetails(details1);
819 systemDefinedAppItem1->SetAppId("appId");
820 systemDefinedAppItem1->SetAppName("appName");
821 systemDefinedAppItem1->SetAppIconId("appIconId");
822 systemDefinedAppItem1->SetAppLabelId("appLabelId");
823 systemDefinedAppItem1->SetBundleName("bundleName");
824 systemDefinedAppItem1->SetAbilityName("abilityName");
825 data1.AddRecord(systemDefinedAppItem1);
826 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
827 ASSERT_EQ(status, E_OK);
828
829 QueryOption option2 = { .key = key };
830 AddPrivilege(option2);
831 SetHapToken2();
832 UnifiedData data2;
833 status = UdmfClient::GetInstance().GetData(option2, data2);
834 ASSERT_EQ(status, E_OK);
835
836 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
837 ASSERT_NE(record2, nullptr);
838 auto type = record2->GetType();
839 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_APP_ITEM);
840
841 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record2.get());
842 ASSERT_NE(systemDefinedRecord2, nullptr);
843 CompareDetails(systemDefinedRecord2->GetDetails());
844
845 auto systemDefinedAppItem2 = static_cast<SystemDefinedAppItem *>(record2.get());
846 ASSERT_NE(systemDefinedAppItem2, nullptr);
847 EXPECT_EQ(systemDefinedAppItem1->GetAppId(), systemDefinedAppItem2->GetAppId());
848 EXPECT_EQ(systemDefinedAppItem1->GetAppName(), systemDefinedAppItem2->GetAppName());
849 EXPECT_EQ(systemDefinedAppItem1->GetBundleName(), systemDefinedAppItem2->GetBundleName());
850 EXPECT_EQ(systemDefinedAppItem1->GetAbilityName(), systemDefinedAppItem2->GetAbilityName());
851 EXPECT_EQ(systemDefinedAppItem1->GetAppIconId(), systemDefinedAppItem2->GetAppIconId());
852 EXPECT_EQ(systemDefinedAppItem1->GetAppLabelId(), systemDefinedAppItem2->GetAppLabelId());
853
854 GetEmptyData(option2);
855
856 LOG_INFO(UDMF_TEST, "SetData013 end.");
857 }
858
859 /**
860 * @tc.name: SetData014
861 * @tc.desc: Set PixelMap record with valid params and get data
862 * @tc.type: FUNC
863 */
864 HWTEST_F(UdmfClientTest, SetData014, TestSize.Level1)
865 {
866 LOG_INFO(UDMF_TEST, "SetData014 begin.");
867
868 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
869 UnifiedData data1;
870 std::string key;
871 auto systemDefinedPixelMap1 = std::make_shared<SystemDefinedPixelMap>();
872 UDDetails details1;
873 details1.insert({ "udmf_key", "udmf_value" });
874 systemDefinedPixelMap1->SetDetails(details1);
875 std::vector<uint8_t> rawData1;
876
877 uint32_t color[100] = { 3, 7, 9, 9, 7, 6 };
878 OHOS::Media::InitializationOptions opts = { { 5, 7 },
879 Media::PixelFormat::ARGB_8888,
880 Media::PixelFormat::ARGB_8888 };
881 std::unique_ptr<OHOS::Media::PixelMap> pixelMap =
882 OHOS::Media::PixelMap::Create(color, sizeof(color) / sizeof(color[0]), opts);
883 std::shared_ptr<OHOS::Media::PixelMap> pixelMapIn = move(pixelMap);
884 pixelMapIn->EncodeTlv(rawData1);
885
886 systemDefinedPixelMap1->SetRawData(rawData1);
887 data1.AddRecord(systemDefinedPixelMap1);
888 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
889 ASSERT_EQ(status, E_OK);
890
891 QueryOption option2 = { .key = key };
892 AddPrivilege(option2);
893 SetHapToken2();
894 UnifiedData data2;
895 status = UdmfClient::GetInstance().GetData(option2, data2);
896 ASSERT_EQ(status, E_OK);
897
898 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
899 ASSERT_NE(record2, nullptr);
900 auto type = record2->GetType();
901 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_PIXEL_MAP);
902
903 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record2.get());
904 ASSERT_NE(systemDefinedRecord2, nullptr);
905 CompareDetails(systemDefinedRecord2->GetDetails());
906
907 auto systemDefinedPixelMap2 = static_cast<SystemDefinedPixelMap *>(record2.get());
908 ASSERT_NE(systemDefinedPixelMap2, nullptr);
909 auto rawData2 = systemDefinedPixelMap2->GetRawData();
910 EXPECT_EQ(rawData1.size(), rawData2.size());
911 for (uint32_t i = 0; i < rawData1.size(); ++i) {
912 EXPECT_EQ(rawData1[i], rawData2[i]);
913 }
914
915 GetEmptyData(option2);
916
917 LOG_INFO(UDMF_TEST, "SetData014 end.");
918 }
919
920 /**
921 * @tc.name: SetData015
922 * @tc.desc: Set Application Defined record with valid params and get data
923 * @tc.type: FUNC
924 */
925 HWTEST_F(UdmfClientTest, SetData015, TestSize.Level1)
926 {
927 LOG_INFO(UDMF_TEST, "SetData015 begin.");
928
929 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
930 UnifiedData data1;
931 std::string key;
932 auto applicationDefinedRecord1 = std::make_shared<ApplicationDefinedRecord>();
933 applicationDefinedRecord1->SetApplicationDefinedType("applicationDefinedType");
934 std::vector<uint8_t> rawData1 = { 1, 2, 3, 4, 5 };
935 applicationDefinedRecord1->SetRawData(rawData1);
936 data1.AddRecord(applicationDefinedRecord1);
937 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
938 ASSERT_EQ(status, E_OK);
939
940 QueryOption option2 = { .key = key };
941 AddPrivilege(option2);
942 SetHapToken2();
943 UnifiedData data2;
944 status = UdmfClient::GetInstance().GetData(option2, data2);
945 ASSERT_EQ(status, E_OK);
946
947 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
948 ASSERT_NE(record2, nullptr);
949 auto type = record2->GetType();
950 ASSERT_EQ(type, UDType::APPLICATION_DEFINED_RECORD);
951
952 auto applicationDefinedRecord2 = static_cast<ApplicationDefinedRecord *>(record2.get());
953 ASSERT_NE(applicationDefinedRecord2, nullptr);
954 EXPECT_EQ(applicationDefinedRecord1->GetApplicationDefinedType(),
955 applicationDefinedRecord2->GetApplicationDefinedType());
956 auto rawData2 = applicationDefinedRecord2->GetRawData();
957 EXPECT_EQ(rawData1.size(), rawData2.size());
958 for (uint32_t i = 0; i < rawData1.size(); ++i) {
959 EXPECT_EQ(rawData1[i], rawData2[i]);
960 }
961
962 GetEmptyData(option2);
963
964 LOG_INFO(UDMF_TEST, "SetData015 end.");
965 }
966
967 /**
968 * @tc.name: SetData016
969 * @tc.desc: Set multiple record with valid params and get data
970 * @tc.type: FUNC
971 */
972 HWTEST_F(UdmfClientTest, SetData016, TestSize.Level1)
973 {
974 LOG_INFO(UDMF_TEST, "SetData016 begin.");
975
976 CustomOption customOption = {.intention = Intention::UD_INTENTION_DRAG};
977 std::string key;
978 UnifiedData inputData;
979 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords = {
980 std::make_shared<Text>(),
981 std::make_shared<PlainText>(),
982 std::make_shared<File>(),
983 std::make_shared<Image>(),
984 std::make_shared<SystemDefinedRecord>(),
985 std::make_shared<SystemDefinedForm>(),
986 std::make_shared<ApplicationDefinedRecord>()
987 };
988 inputData.SetRecords(inputRecords);
989
990 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
991 ASSERT_EQ(status, E_OK);
992
993 QueryOption queryOption = { .key = key };
994 UnifiedData outputData;
995 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
996 ASSERT_EQ(status, E_OK);
997 auto outputRecords = outputData.GetRecords();
998 ASSERT_EQ(inputRecords.size(), outputRecords.size());
999 for (size_t i = 0; i < outputRecords.size(); ++i) {
1000 ASSERT_EQ(outputRecords[i]->GetType(), inputRecords[i]->GetType());
1001 }
1002
1003 LOG_INFO(UDMF_TEST, "SetData016 end.");
1004 }
1005
1006 /**
1007 * @tc.name: SetData017
1008 * @tc.desc: Set 512 records with valid params and get data
1009 * @tc.type: FUNC
1010 */
1011 HWTEST_F(UdmfClientTest, SetData017, TestSize.Level1)
1012 {
1013 LOG_INFO(UDMF_TEST, "SetData017 begin.");
1014
1015 CustomOption customOption = {.intention = Intention::UD_INTENTION_DRAG};
1016 std::string key;
1017 UnifiedData inputData;
1018 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
1019 for (int32_t i = 0; i < 512; ++i) {
1020 inputRecords.emplace_back(std::make_shared<Text>());
1021 }
1022 inputData.SetRecords(inputRecords);
1023
1024 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1025 ASSERT_EQ(status, E_OK);
1026
1027 QueryOption queryOption = { .key = key };
1028 UnifiedData outputData;
1029 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1030 ASSERT_EQ(status, E_OK);
1031 auto outputRecords = outputData.GetRecords();
1032 ASSERT_EQ(inputRecords.size(), outputRecords.size());
1033
1034 LOG_INFO(UDMF_TEST, "SetData017 end.");
1035 }
1036
1037 /**
1038 * @tc.name: SetData018
1039 * @tc.desc: Set one 2MB record of data with valid params and get data
1040 * @tc.type: FUNC
1041 */
1042 HWTEST_F(UdmfClientTest, SetData018, TestSize.Level1)
1043 {
1044 LOG_INFO(UDMF_TEST, "SetData018 begin.");
1045
1046 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
1047 UnifiedData inputData;
1048 std::string key;
1049 UDDetails details;
1050 std::string value;
1051 int64_t maxSize = 512 * 1024;
1052 for (int64_t i = 0; i < maxSize; ++i) {
1053 value += "11";
1054 }
1055 details.insert({ value, value });
1056 auto text = std::make_shared<Text>();
1057 text->SetDetails(details);
1058 inputData.AddRecord(text);
1059
1060 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1061 ASSERT_EQ(status, E_OK);
1062
1063 QueryOption queryOption = { .key = key };
1064 UnifiedData outputData;
1065 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1066 ASSERT_EQ(status, E_OK);
1067
1068 LOG_INFO(UDMF_TEST, "SetData018 end.");
1069 }
1070
1071 /**
1072 * @tc.name: SetData019
1073 * @tc.desc: Set one over 2MB record of data with valid params and get data
1074 * @tc.type: FUNC
1075 */
1076 HWTEST_F(UdmfClientTest, SetData019, TestSize.Level1)
1077 {
1078 LOG_INFO(UDMF_TEST, "SetData019 begin.");
1079
1080 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
1081 UnifiedData inputData;
1082 std::string key;
1083 UDDetails details;
1084 std::string value;
1085 int64_t maxSize = 512 * 1024;
1086 for (int64_t i = 0; i < maxSize; ++i) {
1087 value += "11";
1088 }
1089 details.insert({ value, value });
1090 details.insert({ "udmf_key", "udmf_value" });
1091 auto text = std::make_shared<Text>();
1092 text->SetDetails(details);
1093 inputData.AddRecord(text);
1094
1095 UnifiedDataHelper::SetRootPath("/data/udmf_test/");
1096 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1097 ASSERT_EQ(status, E_OK);
1098
1099 QueryOption queryOption = { .key = key };
1100 UnifiedData outputData;
1101 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1102 ASSERT_EQ(status, E_OK);
1103 UnifiedDataHelper::SetRootPath("");
1104
1105 LOG_INFO(UDMF_TEST, "SetData019 end.");
1106 }
1107
1108 /**
1109 * @tc.name: SetData020
1110 * @tc.desc: Set two 2MB record of data with valid params and get data
1111 * @tc.type: FUNC
1112 */
1113 HWTEST_F(UdmfClientTest, SetData020, TestSize.Level1)
1114 {
1115 LOG_INFO(UDMF_TEST, "SetData020 begin.");
1116
1117 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
1118 UnifiedData inputData;
1119 std::string key;
1120 UDDetails details;
1121 std::string value;
1122 int64_t maxSize = 512 * 1024;
1123 for (int64_t i = 0; i < maxSize; ++i) {
1124 value += "11";
1125 }
1126 details.insert({ value, value });
1127 auto text = std::make_shared<Text>();
1128 text->SetDetails(details);
1129 for (int i = 0; i < 2; ++i) {
1130 inputData.AddRecord(text);
1131 }
1132 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1133 ASSERT_EQ(status, E_OK);
1134
1135 QueryOption queryOption = { .key = key };
1136 UnifiedData outputData;
1137 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1138 ASSERT_EQ(status, E_OK);
1139
1140 LOG_INFO(UDMF_TEST, "SetData020 end.");
1141 }
1142
1143 /**
1144 * @tc.name: GetData001
1145 * @tc.desc: Get data with invalid key
1146 * @tc.type: FUNC
1147 */
1148 HWTEST_F(UdmfClientTest, GetData001, TestSize.Level1)
1149 {
1150 LOG_INFO(UDMF_TEST, "GetData001 begin.");
1151
1152 QueryOption option;
1153 UnifiedData data;
1154 auto status = UdmfClient::GetInstance().GetData(option, data);
1155 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1156
1157 option.key = "udmf";
1158 status = UdmfClient::GetInstance().GetData(option, data);
1159 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1160
1161 option.key = "odmf://";
1162 status = UdmfClient::GetInstance().GetData(option, data);
1163 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1164
1165 option.key = "udmf://drag";
1166 status = UdmfClient::GetInstance().GetData(option, data);
1167 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1168
1169 option.key = "udmf://123/bundle/group";
1170 status = UdmfClient::GetInstance().GetData(option, data);
1171 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1172
1173 option.key = "udmf://drag/bundle";
1174 status = UdmfClient::GetInstance().GetData(option, data);
1175 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1176
1177 option.key = "udmf://drag/bundle***/group";
1178 status = UdmfClient::GetInstance().GetData(option, data);
1179 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1180
1181 option.key = "udmf://drag/bundle/";
1182 status = UdmfClient::GetInstance().GetData(option, data);
1183 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1184
1185 option.key = "udmf://drag/bundle/group###";
1186 status = UdmfClient::GetInstance().GetData(option, data);
1187 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1188
1189 LOG_INFO(UDMF_TEST, "GetData001 end.");
1190 }
1191
1192 /**
1193 * @tc.name: GetSummary001
1194 * @tc.desc: Get summary data
1195 * @tc.type: FUNC
1196 */
1197 HWTEST_F(UdmfClientTest, GetSummary001, TestSize.Level1)
1198 {
1199 LOG_INFO(UDMF_TEST, "GetSummary001 begin.");
1200
1201 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1202 UnifiedData data;
1203 std::string key;
1204
1205 UDDetails details;
1206 details.insert({ "udmf_key", "udmf_value" });
1207
1208 auto text = std::make_shared<Text>();
1209 text->SetDetails(details);
1210 data.AddRecord(text);
1211
1212 auto plainText = std::make_shared<PlainText>();
1213 plainText->SetDetails(details);
1214 plainText->SetContent("content");
1215 plainText->SetAbstract("abstract");
1216 data.AddRecord(plainText);
1217
1218 auto file = std::make_shared<File>();
1219 file->SetDetails(details);
1220 file->SetUri("uri");
1221 file->SetRemoteUri("remoteUri");
1222 data.AddRecord(file);
1223
1224 auto image = std::make_shared<Image>();
1225 file->SetDetails(details);
1226 image->SetUri("uri");
1227 image->SetRemoteUri("remoteUri");
1228 data.AddRecord(image);
1229
1230 auto systemDefinedRecord = std::make_shared<SystemDefinedRecord>();
1231 systemDefinedRecord->SetDetails(details);
1232 data.AddRecord(systemDefinedRecord);
1233
1234 auto systemDefinedForm = std::make_shared<SystemDefinedForm>();
1235 systemDefinedForm->SetDetails(details);
1236 systemDefinedForm->SetFormId(123);
1237 systemDefinedForm->SetFormName("formName");
1238 systemDefinedForm->SetModule("module");
1239 systemDefinedForm->SetAbilityName("abilityName");
1240 systemDefinedForm->SetBundleName("bundleName");
1241 data.AddRecord(systemDefinedForm);
1242
1243 auto applicationDefinedRecord = std::make_shared<ApplicationDefinedRecord>();
1244 applicationDefinedRecord->SetApplicationDefinedType("applicationDefinedType");
1245 std::vector<uint8_t> rawData = { 1, 2, 3, 4, 5 };
1246 applicationDefinedRecord->SetRawData(rawData);
1247 data.AddRecord(applicationDefinedRecord);
1248
1249 std::shared_ptr<Object> obj = std::make_shared<Object>();
1250 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
1251 obj->value_[FILE_URI_PARAM] = "http://demo.com";
1252 obj->value_[FILE_TYPE] = "abcdefg";
1253 auto record8 = std::make_shared<UnifiedRecord>(FILE_URI, obj);
1254 data.AddRecord(record8);
1255
1256 auto record9 = std::make_shared<UnifiedRecord>(PNG, "http://demo.com");
1257 data.AddRecord(record9);
1258
1259 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1260 ASSERT_EQ(status, E_OK);
1261
1262 QueryOption option2 = { .key = key };
1263 Summary summary;
1264 status = UdmfClient::GetInstance().GetSummary(option2, summary);
1265
1266 auto size = text->GetSize();
1267 size += plainText->GetSize();
1268 size += file->GetSize();
1269 size += image->GetSize();
1270 size += systemDefinedRecord->GetSize();
1271 size += systemDefinedForm->GetSize();
1272 size += applicationDefinedRecord->GetSize();
1273 size += record8->GetSize();
1274 size += record9->GetSize();
1275
1276 EXPECT_EQ(status, E_OK);
1277 EXPECT_EQ(summary.totalSize, size);
1278 EXPECT_EQ(summary.summary["general.text"], text->GetSize());
1279 EXPECT_EQ(summary.summary["general.plain-text"], plainText->GetSize());
1280 EXPECT_EQ(summary.summary["general.file"], file->GetSize());
1281 EXPECT_EQ(summary.summary["general.image"], image->GetSize());
1282 EXPECT_EQ(summary.summary["SystemDefinedType"], systemDefinedRecord->GetSize());
1283 EXPECT_EQ(summary.summary["openharmony.form"], systemDefinedForm->GetSize());
1284 EXPECT_EQ(summary.summary["ApplicationDefinedType"], applicationDefinedRecord->GetSize());
1285 EXPECT_EQ(summary.summary["abcdefg"], record8->GetSize());
1286 EXPECT_EQ(summary.summary["general.png"], record9->GetSize());
1287
1288 LOG_INFO(UDMF_TEST, "GetSummary001 end.");
1289 }
1290
1291
1292 /**
1293 * @tc.name: GetSummary002
1294 * @tc.desc: Get summary with invalid key
1295 * @tc.type: FUNC
1296 */
1297 HWTEST_F(UdmfClientTest, GetSummary002, TestSize.Level1)
1298 {
1299 LOG_INFO(UDMF_FRAMEWORK, "GetSummary002 begin.");
1300
1301 QueryOption option;
1302 Summary summary;
1303 auto status = UdmfClient::GetInstance().GetSummary(option, summary);
1304 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1305
1306 option.key = "udmf";
1307 status = UdmfClient::GetInstance().GetSummary(option, summary);
1308 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1309
1310 option.key = "odmf://";
1311 status = UdmfClient::GetInstance().GetSummary(option, summary);
1312 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1313
1314 option.key = "udmf://drag";
1315 status = UdmfClient::GetInstance().GetSummary(option, summary);
1316 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1317
1318 option.key = "udmf://123/bundle/group";
1319 status = UdmfClient::GetInstance().GetSummary(option, summary);
1320 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1321
1322 option.key = "udmf://drag/bundle";
1323 status = UdmfClient::GetInstance().GetSummary(option, summary);
1324 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1325
1326 option.key = "udmf://drag/bundle***/group";
1327 status = UdmfClient::GetInstance().GetSummary(option, summary);
1328 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1329
1330 option.key = "udmf://drag/bundle/";
1331 status = UdmfClient::GetInstance().GetSummary(option, summary);
1332 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1333
1334 option.key = "udmf://drag/bundle/group###";
1335 status = UdmfClient::GetInstance().GetSummary(option, summary);
1336 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1337
1338 LOG_INFO(UDMF_FRAMEWORK, "GetSummary002 end.");
1339 }
1340
1341 /**
1342 * @tc.name: AddPrivilege001
1343 * @tc.desc: Add privilege with valid params
1344 * @tc.type: FUNC
1345 */
1346 HWTEST_F(UdmfClientTest, AddPrivilege001, TestSize.Level1)
1347 {
1348 LOG_INFO(UDMF_TEST, "AddPrivilege001 begin.");
1349
1350 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1351 UnifiedData data;
1352 auto text = std::make_shared<Text>();
1353 UDDetails details;
1354 details.insert({ "udmf_key", "udmf_value" });
1355 text->SetDetails(details);
1356 data.AddRecord(text);
1357 std::string key;
1358 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1359 ASSERT_EQ(status, E_OK);
1360
1361 QueryOption option2 = { .key = key };
1362 Privilege privilege;
1363 SetHapToken2();
1364 privilege.tokenId = AccessTokenKit::GetHapTokenID(100, "ohos.test.demo2", 0);
1365 privilege.readPermission = "readPermission";
1366 privilege.writePermission = "writePermission";
1367 SetNativeToken("msdp_sa");
1368 status = UdmfClient::GetInstance().AddPrivilege(option2, privilege);
1369 ASSERT_EQ(status, E_OK);
1370
1371 LOG_INFO(UDMF_TEST, "AddPrivilege001 end.");
1372 }
1373
1374 /**
1375 * @tc.name: AddPrivilege002
1376 * @tc.desc: Add Privilege with invalid params
1377 * @tc.type: FUNC
1378 */
1379 HWTEST_F(UdmfClientTest, AddPrivilege002, TestSize.Level1)
1380 {
1381 LOG_INFO(UDMF_FRAMEWORK, "AddPrivilege002 begin.");
1382
1383 QueryOption option;
1384 Privilege privilege;
1385 auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1386 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1387
1388 option.key = "udmf";
1389 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1390 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1391
1392 option.key = "odmf://";
1393 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1394 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1395
1396 option.key = "udmf://drag";
1397 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1398 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1399
1400 option.key = "udmf://123/bundle/group";
1401 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1402 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1403
1404 option.key = "udmf://drag/bundle";
1405 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1406 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1407
1408 option.key = "udmf://drag/bundle***/group";
1409 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1410 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1411
1412 option.key = "udmf://drag/bundle/";
1413 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1414 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1415
1416 option.key = "udmf://drag/bundle/group###";
1417 status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
1418 EXPECT_EQ(status, E_INVALID_PARAMETERS);
1419
1420 LOG_INFO(UDMF_FRAMEWORK, "AddPrivilege002 end.");
1421 }
1422
1423 /**
1424 * @tc.name: AddPrivilege003
1425 * @tc.desc: Add privilege with invalid intention
1426 * @tc.type: FUNC
1427 */
1428 HWTEST_F(UdmfClientTest, AddPrivilege003, TestSize.Level1)
1429 {
1430 LOG_INFO(UDMF_TEST, "AddPrivilege003 begin.");
1431
1432 CustomOption option1 = { .intention = Intention::UD_INTENTION_DATA_HUB };
1433 UnifiedData data;
1434 auto text = std::make_shared<Text>();
1435 UDDetails details;
1436 details.insert({ "udmf_key", "udmf_value" });
1437 text->SetDetails(details);
1438 data.AddRecord(text);
1439 std::string key;
1440 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1441 ASSERT_EQ(status, E_OK);
1442
1443 QueryOption option2 = { .key = key };
1444 Privilege privilege;
1445 SetHapToken2();
1446 privilege.tokenId = AccessTokenKit::GetHapTokenID(100, "ohos.test.demo2", 0);
1447 privilege.readPermission = "readPermission";
1448 privilege.writePermission = "writePermission";
1449 SetNativeToken("msdp_sa");
1450 status = UdmfClient::GetInstance().AddPrivilege(option2, privilege);
1451 ASSERT_EQ(status, E_NO_PERMISSION);
1452 LOG_INFO(UDMF_TEST, "AddPrivilege003 end.");
1453 }
1454
1455 /**
1456 * @tc.name: AddPrivilege004
1457 * @tc.desc: Add privilege for unauthorized process with valid params
1458 * @tc.type: FUNC
1459 */
1460 HWTEST_F(UdmfClientTest, AddPrivilege004, TestSize.Level1)
1461 {
1462 LOG_INFO(UDMF_TEST, "AddPrivilege004 begin.");
1463
1464 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1465 UnifiedData data;
1466 auto text = std::make_shared<Text>();
1467 UDDetails details;
1468 details.insert({ "udmf_key", "udmf_value" });
1469 text->SetDetails(details);
1470 data.AddRecord(text);
1471 std::string key;
1472 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1473 ASSERT_EQ(status, E_OK);
1474
1475 QueryOption option2 = { .key = key };
1476 Privilege privilege;
1477 SetHapToken2();
1478 privilege.tokenId = AccessTokenKit::GetHapTokenID(100, "ohos.test.demo2", 0);
1479 privilege.readPermission = "readPermission";
1480 privilege.writePermission = "writePermission";
1481 SetNativeToken("foundation");
1482 status = UdmfClient::GetInstance().AddPrivilege(option2, privilege);
1483 ASSERT_EQ(status, E_NO_PERMISSION);
1484 LOG_INFO(UDMF_TEST, "AddPrivilege004 end.");
1485 }
1486
1487 /**
1488 * @tc.name: AddPrivilege005
1489 * @tc.desc: Add privilege with valid params
1490 * @tc.type: FUNC
1491 */
1492 HWTEST_F(UdmfClientTest, AddPrivilege005, TestSize.Level1)
1493 {
1494 LOG_INFO(UDMF_TEST, "AddPrivilege005 begin.");
1495
1496 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1497 UnifiedData data;
1498 auto text = std::make_shared<Text>();
1499 UDDetails details;
1500 details.insert({ "udmf_key", "udmf_value" });
1501 text->SetDetails(details);
1502 data.AddRecord(text);
1503 std::string key;
1504 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1505 ASSERT_EQ(status, E_OK);
1506
1507 QueryOption option2 = { .key = key };
1508 Privilege privilege;
1509 SetHapToken2();
1510 privilege.tokenId = AccessTokenKit::GetHapTokenID(100, "ohos.test.demo2", 0);
1511 privilege.readPermission = "readAndKeep";
1512 privilege.writePermission = "writePermission";
1513 SetNativeToken("msdp_sa");
1514 status = UdmfClient::GetInstance().AddPrivilege(option2, privilege);
1515 ASSERT_EQ(status, E_OK);
1516
1517 SetHapToken2();
1518 UnifiedData data1;
1519 status = UdmfClient::GetInstance().GetData(option2, data1);
1520 ASSERT_EQ(status, E_OK);
1521
1522 std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME));
1523 UnifiedData data2;
1524 status = UdmfClient::GetInstance().GetData(option2, data2);
1525 ASSERT_EQ(status, E_OK);
1526 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
1527 ASSERT_NE(record2, nullptr);
1528 auto type = record2->GetType();
1529 ASSERT_EQ(type, UDType::TEXT);
1530 auto text2 = static_cast<Text *>(record2.get());
1531 ASSERT_NE(text2, nullptr);
1532 CompareDetails(text2->GetDetails()); // Can be read repeatedly.
1533 LOG_INFO(UDMF_TEST, "AddPrivilege005 end.");
1534 }
1535
1536 /**
1537 * @tc.name: GetSelfData001
1538 * @tc.desc: Set File record with valid params and no add privilege and get data by self
1539 * @tc.type: FUNC
1540 */
1541 HWTEST_F(UdmfClientTest, GetSelfData001, TestSize.Level1)
1542 {
1543 LOG_INFO(UDMF_TEST, "GetSelfData001 begin.");
1544
1545 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1546 UnifiedData data1;
1547 std::string key;
1548 auto file1 = std::make_shared<File>();
1549 file1->SetRemoteUri("remoteUri");
1550 UDDetails details1;
1551 details1.insert({ "udmf_key", "udmf_value" });
1552 file1->SetDetails(details1);
1553 data1.AddRecord(file1);
1554 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
1555 ASSERT_EQ(status, E_OK);
1556
1557 QueryOption option2 = { .key = key };
1558 UnifiedData data2;
1559 status = UdmfClient::GetInstance().GetData(option2, data2);
1560 ASSERT_EQ(status, E_OK);
1561
1562 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
1563 ASSERT_NE(record2, nullptr);
1564 auto type = record2->GetType();
1565 ASSERT_EQ(type, UDType::FILE);
1566
1567 auto file2 = static_cast<File *>(record2.get());
1568 ASSERT_NE(file2, nullptr);
1569 EXPECT_EQ(file1->GetRemoteUri(), file2->GetRemoteUri());
1570 CompareDetails(file2->GetDetails());
1571
1572 GetEmptyData(option2);
1573
1574 LOG_INFO(UDMF_TEST, "GetSelfData001 end.");
1575 }
1576
1577 /**
1578 * @tc.name: GetSelfData002
1579 * @tc.desc: Set File record with valid params and add privilege and get data by self
1580 * @tc.type: FUNC
1581 */
1582 HWTEST_F(UdmfClientTest, GetSelfData002, TestSize.Level1)
1583 {
1584 LOG_INFO(UDMF_TEST, "GetSelfData002 begin.");
1585
1586 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
1587 UnifiedData data1;
1588 std::string key;
1589 auto file1 = std::make_shared<File>();
1590 file1->SetRemoteUri("remoteUri");
1591 UDDetails details1;
1592 details1.insert({ "udmf_key", "udmf_value" });
1593 file1->SetDetails(details1);
1594 data1.AddRecord(file1);
1595 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
1596 ASSERT_EQ(status, E_OK);
1597
1598 QueryOption option2 = { .key = key };
1599 AddPrivilege(option2);
1600 SetHapToken1();
1601 UnifiedData data2;
1602 status = UdmfClient::GetInstance().GetData(option2, data2);
1603 ASSERT_EQ(status, E_OK);
1604
1605 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
1606 ASSERT_NE(record2, nullptr);
1607 auto type = record2->GetType();
1608 ASSERT_EQ(type, UDType::FILE);
1609
1610 auto file2 = static_cast<File *>(record2.get());
1611 ASSERT_NE(file2, nullptr);
1612 EXPECT_EQ(file1->GetRemoteUri(), file2->GetRemoteUri());
1613 CompareDetails(file2->GetDetails());
1614
1615 GetEmptyData(option2);
1616
1617 LOG_INFO(UDMF_TEST, "GetSelfData002 end.");
1618 }
1619
1620 /**
1621 * @tc.name: SetData021
1622 * @tc.desc: Set datas with intention ${UD_INTENTION_DATA_HUB} and manually check db is cleared before set or not
1623 * @tc.type: FUNC
1624 */
1625 HWTEST_F(UdmfClientTest, SetData021, TestSize.Level1)
1626 {
1627 LOG_INFO(UDMF_TEST, "SetData021 begin.");
1628 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
1629 std::vector<UnifiedData> unifiedDataSet;
1630 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1631 ASSERT_EQ(status, E_OK);
1632 unifiedDataSet.clear();
1633 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1634 ASSERT_EQ(status, E_OK);
1635 ASSERT_TRUE(unifiedDataSet.empty());
1636
1637 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
1638 UnifiedData data1;
1639 auto plainText1 = std::make_shared<PlainText>();
1640 plainText1->SetContent("content1");
1641 data1.AddRecord(plainText1);
1642 std::string key;
1643 status = UdmfClient::GetInstance().SetData(customOption, data1, key);
1644 ASSERT_EQ(status, E_OK);
1645 UnifiedData data2;
1646 plainText1->SetContent("content2");
1647 data2.AddRecord(plainText1);
1648 status = UdmfClient::GetInstance().SetData(customOption, data2, key);
1649 ASSERT_EQ(status, E_OK);
1650
1651 SetHapToken2();
1652 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1653 ASSERT_EQ(status, E_OK);
1654 auto size = static_cast<int32_t>(unifiedDataSet.size());
1655 ASSERT_EQ(size, 2);
1656 LOG_INFO(UDMF_TEST, "SetData021 end.");
1657 }
1658
1659 /**
1660 * @tc.name: UpdateData001
1661 * @tc.desc: Update data with invalid params
1662 * @tc.type: FUNC
1663 */
1664 HWTEST_F(UdmfClientTest, UpdateData001, TestSize.Level1)
1665 {
1666 LOG_INFO(UDMF_TEST, "UpdateData001 begin.");
1667
1668 UnifiedData data;
1669 QueryOption queryOption = { .key = "" };
1670 auto status = UdmfClient::GetInstance().UpdateData(queryOption, data);
1671 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1672
1673 queryOption = { .key = "udmf://drag/ohos.test.demo1/abcde" };
1674 status = UdmfClient::GetInstance().UpdateData(queryOption, data);
1675 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1676
1677 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
1678 UnifiedData data1;
1679 auto plainText1 = std::make_shared<PlainText>();
1680 plainText1->SetContent("content1");
1681 data1.AddRecord(plainText1);
1682 std::string key;
1683 status = UdmfClient::GetInstance().SetData(customOption, data1, key);
1684 ASSERT_EQ(status, E_OK);
1685
1686 queryOption = { .key = key };
1687 SetHapToken2();
1688 status = UdmfClient::GetInstance().UpdateData(queryOption, data);
1689 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1690 LOG_INFO(UDMF_TEST, "UpdateData001 end.");
1691 }
1692
1693 /**
1694 * @tc.name: UpdateData002
1695 * @tc.desc: Update data with valid params
1696 * @tc.type: FUNC
1697 */
1698 HWTEST_F(UdmfClientTest, UpdateData002, TestSize.Level1)
1699 {
1700 LOG_INFO(UDMF_TEST, "UpdateData002 begin.");
1701
1702 UnifiedData data;
1703 auto plainText = std::make_shared<PlainText>();
1704 plainText->SetContent("content");
1705 data.AddRecord(plainText);
1706
1707 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
1708 UnifiedData data1;
1709 auto plainText1 = std::make_shared<PlainText>();
1710 plainText1->SetContent("content1");
1711 data1.AddRecord(plainText1);
1712 std::string key;
1713 auto status = UdmfClient::GetInstance().SetData(customOption, data1, key);
1714
1715 ASSERT_EQ(status, E_OK);
1716 QueryOption queryOption = { .key = key };
1717 SetHapToken2();
1718 status = UdmfClient::GetInstance().UpdateData(queryOption, data);
1719 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1720
1721 SetHapToken1();
1722 status = UdmfClient::GetInstance().UpdateData(queryOption, data);
1723 ASSERT_EQ(status, E_OK);
1724
1725 std::vector<UnifiedData> dataSet;
1726 status = UdmfClient::GetInstance().GetBatchData(queryOption, dataSet);
1727 std::shared_ptr<UnifiedRecord> record2 = dataSet[0].GetRecordAt(0);
1728 ASSERT_NE(record2, nullptr);
1729 auto type = record2->GetType();
1730 ASSERT_EQ(type, UDType::PLAIN_TEXT);
1731 auto plainText2 = static_cast<PlainText *>(record2.get());
1732 ASSERT_EQ(plainText2->GetContent(), "content");
1733
1734 LOG_INFO(UDMF_TEST, "UpdateData002 end.");
1735 }
1736
1737 /**
1738 * @tc.name: QueryData001
1739 * @tc.desc: Query data with invalid params
1740 * @tc.type: FUNC
1741 */
1742 HWTEST_F(UdmfClientTest, QueryData001, TestSize.Level1)
1743 {
1744 LOG_INFO(UDMF_TEST, "QueryData001 begin.");
1745 std::vector<UnifiedData> unifiedDataSet;
1746 QueryOption queryOption = {};
1747 auto status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1748 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1749
1750 queryOption = { .key = "udmf://drag/ohos.test.demo1/abcde" };
1751 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1752 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1753
1754 queryOption = { .intention = UD_INTENTION_DRAG };
1755 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1756 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1757
1758 queryOption = { .key = "udmf://DataHub/ohos.test.demo1/abcde", .intention = UD_INTENTION_DRAG };
1759 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1760 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1761
1762 queryOption = { .key = "udmf://drag/ohos.test.demo1/abcde", .intention = UD_INTENTION_DATA_HUB };
1763 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1764 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1765 LOG_INFO(UDMF_TEST, "QueryData001 end.");
1766 }
1767
1768 /**
1769 * @tc.name: QueryData002
1770 * @tc.desc: Query data with valid params
1771 * @tc.type: FUNC
1772 */
1773 HWTEST_F(UdmfClientTest, QueryData002, TestSize.Level1)
1774 {
1775 LOG_INFO(UDMF_TEST, "QueryData002 begin.");
1776
1777 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
1778 std::vector<UnifiedData> unifiedDataSet;
1779 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1780 ASSERT_EQ(status, E_OK);
1781 unifiedDataSet.clear();
1782 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1783 ASSERT_EQ(status, E_OK);
1784 ASSERT_TRUE(unifiedDataSet.empty());
1785
1786 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
1787 UnifiedData data;
1788 auto plainText = std::make_shared<PlainText>();
1789 plainText->SetContent("content1");
1790 data.AddRecord(plainText);
1791 std::string key;
1792 status = UdmfClient::GetInstance().SetData(customOption, data, key);
1793 ASSERT_EQ(status, E_OK);
1794
1795 query = { .key = key };
1796 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1797 ASSERT_EQ(status, E_OK);
1798 auto size = static_cast<int32_t>(unifiedDataSet.size());
1799 ASSERT_EQ(size, 1);
1800 std::shared_ptr<UnifiedRecord> record2 = unifiedDataSet[0].GetRecordAt(0);
1801 ASSERT_NE(record2, nullptr);
1802 auto type = record2->GetType();
1803 ASSERT_EQ(type, UDType::PLAIN_TEXT);
1804 auto plainText2 = static_cast<PlainText *>(record2.get());
1805 ASSERT_EQ(plainText2->GetContent(), "content1");
1806
1807 UnifiedData data2;
1808 plainText = std::make_shared<PlainText>();
1809 plainText->SetContent("content2");
1810 data2.AddRecord(plainText);
1811 status = UdmfClient::GetInstance().SetData(customOption, data2, key);
1812 ASSERT_EQ(status, E_OK);
1813
1814 unifiedDataSet.clear();
1815 query = { .key = key, .intention = UD_INTENTION_DATA_HUB };
1816 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1817 ASSERT_EQ(status, E_OK);
1818 size = static_cast<int32_t>(unifiedDataSet.size());
1819 ASSERT_EQ(size, 1);
1820 record2 = unifiedDataSet[0].GetRecordAt(0);
1821 ASSERT_NE(record2, nullptr);
1822 type = record2->GetType();
1823 ASSERT_EQ(type, UDType::PLAIN_TEXT);
1824 plainText2 = static_cast<PlainText *>(record2.get());
1825 ASSERT_EQ(plainText2->GetContent(), "content2");
1826
1827 unifiedDataSet.clear();
1828 query = { .intention = UD_INTENTION_DATA_HUB };
1829 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1830 ASSERT_EQ(status, E_OK);
1831 size = static_cast<int32_t>(unifiedDataSet.size());
1832 ASSERT_EQ(size, 2);
1833
1834 LOG_INFO(UDMF_TEST, "QueryData002 end.");
1835 }
1836
1837 /**
1838 * @tc.name: DeleteData001
1839 * @tc.desc: Delete data with invalid params
1840 * @tc.type: FUNC
1841 */
1842 HWTEST_F(UdmfClientTest, DeleteData001, TestSize.Level1)
1843 {
1844 LOG_INFO(UDMF_TEST, "DeleteData001 begin.");
1845 std::vector<UnifiedData> unifiedDataSet;
1846 QueryOption queryOption = {};
1847 auto status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1848 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1849
1850 queryOption = { .key = "udmf://drag/ohos.test.demo1/abcde" };
1851 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1852 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1853
1854 queryOption = { .intention = UD_INTENTION_DRAG };
1855 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1856 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1857
1858 queryOption = { .key = "udmf://DataHub/ohos.test.demo1/abcde", .intention = UD_INTENTION_DRAG };
1859 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1860 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1861
1862 queryOption = { .key = "udmf://drag/ohos.test.demo1/abcde", .intention = UD_INTENTION_DATA_HUB };
1863 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1864 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1865 LOG_INFO(UDMF_TEST, "DeleteData001 end.");
1866 }
1867
1868 /**
1869 * @tc.name: DeleteData002
1870 * @tc.desc: Delete data with valid params
1871 * @tc.type: FUNC
1872 */
1873 HWTEST_F(UdmfClientTest, DeleteData002, TestSize.Level1)
1874 {
1875 LOG_INFO(UDMF_TEST, "DeleteData002 begin.");
1876
1877 CustomOption customOption = { .intention = UD_INTENTION_DATA_HUB };
1878 UnifiedData data;
1879 auto plainText = std::make_shared<PlainText>();
1880 plainText->SetContent("content1");
1881 data.AddRecord(plainText);
1882 std::string key;
1883 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1884 ASSERT_EQ(status, E_OK);
1885 status = UdmfClient::GetInstance().SetData(customOption, data, key);
1886 ASSERT_EQ(status, E_OK);
1887 status = UdmfClient::GetInstance().SetData(customOption, data, key);
1888 ASSERT_EQ(status, E_OK);
1889
1890 QueryOption queryOption = { .key = key };
1891 SetHapToken2();
1892
1893 std::vector<UnifiedData> unifiedDataSet;
1894 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1895 ASSERT_EQ(status, E_OK);
1896 ASSERT_EQ(0, unifiedDataSet.size());
1897
1898 SetHapToken1();
1899 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1900 ASSERT_EQ(status, E_OK);
1901 ASSERT_EQ(1, unifiedDataSet.size());
1902
1903 unifiedDataSet.clear();
1904 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1905 ASSERT_TRUE(unifiedDataSet.empty());
1906
1907 queryOption = { .intention = UD_INTENTION_DATA_HUB };
1908 unifiedDataSet.clear();
1909 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1910 ASSERT_TRUE(!unifiedDataSet.empty());
1911
1912 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1913 ASSERT_EQ(status, E_OK);
1914
1915 unifiedDataSet.clear();
1916 status = UdmfClient::GetInstance().GetBatchData(queryOption, unifiedDataSet);
1917 ASSERT_TRUE(unifiedDataSet.empty());
1918 LOG_INFO(UDMF_TEST, "DeleteData002 end.");
1919 }
1920
1921 /**
1922 * @tc.name: SetData022
1923 * @tc.desc: Set two over 2MB record of data with valid params and get data
1924 * @tc.type: FUNC
1925 */
1926 HWTEST_F(UdmfClientTest, SetData022, TestSize.Level1)
1927 {
1928 LOG_INFO(UDMF_TEST, "SetData022 begin.");
1929
1930 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
1931 UnifiedData inputData;
1932 std::string key;
1933 UDDetails details;
1934 std::string value;
1935 int64_t maxSize = 512 * 1024;
1936 for (int64_t i = 0; i < maxSize; ++i) {
1937 value += "11";
1938 }
1939 details.insert({ value, value });
1940 details.insert({ "udmf_key", "udmf_value" });
1941 auto text = std::make_shared<Text>();
1942 text->SetDetails(details);
1943 for (int i = 0; i < 2; ++i) {
1944 inputData.AddRecord(text);
1945 }
1946 UnifiedDataHelper::SetRootPath("/data/udmf_test/");
1947 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1948 ASSERT_EQ(status, E_OK);
1949
1950 QueryOption queryOption = { .key = key };
1951 UnifiedData outputData;
1952 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1953 ASSERT_EQ(status, E_OK);
1954 UnifiedDataHelper::SetRootPath("");
1955
1956 LOG_INFO(UDMF_TEST, "SetData022 end.");
1957 }
1958
1959 /**
1960 * @tc.name: SetData023
1961 * @tc.desc: Set 200MB record of data with valid params and get data
1962 * @tc.type: FUNC
1963 */
1964 HWTEST_F(UdmfClientTest, SetData023, TestSize.Level1)
1965 {
1966 LOG_INFO(UDMF_TEST, "SetData023 begin.");
1967
1968 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
1969 UnifiedData inputData;
1970 std::string key;
1971 UDDetails details;
1972 std::string value;
1973 int64_t maxSize = 512 * 1024;
1974 for (int64_t i = 0; i < maxSize; ++i) {
1975 value += "11";
1976 }
1977 details.insert({ value, value });
1978 Text text;
1979 text.SetDetails(details);
1980 for (int64_t i = 0; i < 100; ++i) {
1981 auto record = std::make_shared<Text>();
1982 inputData.AddRecord(record);
1983 }
1984 auto records = inputData.GetRecords();
1985 LOG_INFO(UDMF_TEST, "SetData023 inputData.size() = %{public}zu", records.size());
1986 UnifiedDataHelper::SetRootPath("/data/udmf_test/");
1987 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1988 ASSERT_EQ(status, E_OK);
1989
1990 QueryOption queryOption = { .key = key };
1991 UnifiedData outputData;
1992 status = UdmfClient::GetInstance().GetData(queryOption, outputData);
1993 ASSERT_EQ(status, E_OK);
1994 UnifiedDataHelper::SetRootPath("");
1995
1996 LOG_INFO(UDMF_TEST, "SetData023 end.");
1997 }
1998
1999 /**
2000 * @tc.name: SetData024
2001 * @tc.desc: Set over 200MB record of data with valid params and get data
2002 * @tc.type: FUNC
2003 */
2004 HWTEST_F(UdmfClientTest, SetData024, TestSize.Level1)
2005 {
2006 LOG_INFO(UDMF_TEST, "SetData024 begin.");
2007
2008 CustomOption customOption = { .intention = Intention::UD_INTENTION_DRAG };
2009 UnifiedData inputData;
2010 std::string key;
2011 UDDetails details;
2012 std::string value;
2013 int64_t maxSize = 512 * 1024;
2014 for (int64_t i = 0; i < maxSize; ++i) {
2015 value += "11";
2016 }
2017 details.insert({ value, value });
2018 auto text = std::make_shared<Text>();
2019 text->SetDetails(details);
2020 for (int64_t i = 0; i < 101; ++i) {
2021 inputData.AddRecord(text);
2022 }
2023 auto records = inputData.GetRecords();
2024 LOG_INFO(UDMF_TEST, "SetData024 inputData.size() = %{public}zu", records.size());
2025
2026 UnifiedDataHelper::SetRootPath("/data/udmf_test/");
2027 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
2028 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2029 UnifiedDataHelper::SetRootPath("");
2030
2031 LOG_INFO(UDMF_TEST, "SetData024 end.");
2032 }
2033
2034 /**
2035 * @tc.name: SetData025
2036 * @tc.desc: Set PixelMap record with valid params and get data
2037 * @tc.type: FUNC
2038 */
2039 HWTEST_F(UdmfClientTest, SetData025, TestSize.Level1)
2040 {
2041 LOG_INFO(UDMF_TEST, "SetData025 begin.");
2042
2043 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2044 UnifiedData data1;
2045 std::string key;
2046 auto systemDefinedPixelMap1 = std::make_shared<SystemDefinedPixelMap>();
2047 UDDetails details1;
2048 details1.insert({ "udmf_key", "udmf_value" });
2049 systemDefinedPixelMap1->SetDetails(details1);
2050 std::vector<uint8_t> rawData1 = { 1, 2, 3, 4, 5 };
2051
2052 systemDefinedPixelMap1->SetRawData(rawData1);
2053 data1.AddRecord(systemDefinedPixelMap1);
2054 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
2055 ASSERT_EQ(status, E_OK);
2056
2057 QueryOption option2 = { .key = key };
2058 AddPrivilege(option2);
2059 SetHapToken2();
2060 UnifiedData data2;
2061 status = UdmfClient::GetInstance().GetData(option2, data2);
2062 ASSERT_EQ(status, E_OK);
2063
2064 std::shared_ptr<UnifiedRecord> record2 = data2.GetRecordAt(0);
2065 ASSERT_NE(record2, nullptr);
2066 auto type = record2->GetType();
2067 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_PIXEL_MAP);
2068
2069 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record2.get());
2070 ASSERT_NE(systemDefinedRecord2, nullptr);
2071 CompareDetails(systemDefinedRecord2->GetDetails());
2072
2073 auto systemDefinedPixelMap2 = static_cast<SystemDefinedPixelMap *>(record2.get());
2074 ASSERT_NE(systemDefinedPixelMap2, nullptr);
2075 auto rawData2 = systemDefinedPixelMap2->GetRawData();
2076 EXPECT_EQ(rawData1.size(), rawData2.size());
2077 for (uint32_t i = 0; i < rawData1.size(); ++i) {
2078 EXPECT_EQ(rawData1[i], rawData2[i]);
2079 }
2080
2081 LOG_INFO(UDMF_TEST, "SetData025 end.");
2082 }
2083
2084 /**
2085 * @tc.name: SetData026
2086 * @tc.desc: Set more record with valid params and get data
2087 * @tc.type: FUNC
2088 */
2089 HWTEST_F(UdmfClientTest, SetData026, TestSize.Level1)
2090 {
2091 LOG_INFO(UDMF_TEST, "SetData026 begin.");
2092
2093 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2094 UnifiedData data1;
2095 std::string key;
2096 auto systemDefinedPixelMap1 = std::make_shared<SystemDefinedPixelMap>();
2097 UDDetails details1;
2098 details1.insert({ "udmf_key", "udmf_value" });
2099 systemDefinedPixelMap1->SetDetails(details1);
2100 std::vector<uint8_t> rawData1 = { 1, 2, 3, 4, 5 };
2101
2102 systemDefinedPixelMap1->SetRawData(rawData1);
2103 std::shared_ptr<UnifiedRecord> record2 = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "this is a content");
2104 data1.AddRecord(systemDefinedPixelMap1);
2105 data1.AddRecord(record2);
2106 auto status = UdmfClient::GetInstance().SetData(option1, data1, key);
2107 ASSERT_EQ(status, E_OK);
2108
2109 QueryOption option2 = { .key = key };
2110 AddPrivilege(option2);
2111 SetHapToken2();
2112 UnifiedData data2;
2113 status = UdmfClient::GetInstance().GetData(option2, data2);
2114 ASSERT_EQ(status, E_OK);
2115
2116 std::shared_ptr<UnifiedRecord> record3 = data2.GetRecordAt(0);
2117 ASSERT_NE(record3, nullptr);
2118 auto type = record3->GetType();
2119 ASSERT_EQ(type, UDType::SYSTEM_DEFINED_PIXEL_MAP);
2120
2121 auto systemDefinedRecord2 = static_cast<SystemDefinedRecord *>(record3.get());
2122 ASSERT_NE(systemDefinedRecord2, nullptr);
2123 CompareDetails(systemDefinedRecord2->GetDetails());
2124
2125 auto systemDefinedPixelMap2 = static_cast<SystemDefinedPixelMap *>(record3.get());
2126 ASSERT_NE(systemDefinedPixelMap2, nullptr);
2127 auto rawData2 = systemDefinedPixelMap2->GetRawData();
2128 EXPECT_EQ(rawData1.size(), rawData2.size());
2129 for (uint32_t i = 0; i < rawData1.size(); ++i) {
2130 EXPECT_EQ(rawData1[i], rawData2[i]);
2131 }
2132
2133 std::shared_ptr<UnifiedRecord> record4 = data2.GetRecordAt(1);
2134 auto plainText = static_cast<PlainText *>(record4.get());
2135 ASSERT_EQ(UDType::PLAIN_TEXT, plainText->GetType());
2136 ASSERT_EQ("this is a content", plainText->GetContent());
2137
2138 LOG_INFO(UDMF_TEST, "SetData026 end.");
2139 }
2140
2141 /**
2142 * @tc.name: SetData027
2143 * @tc.desc: Set Html record value is null str and get uris data
2144 * @tc.type: FUNC
2145 */
2146 HWTEST_F(UdmfClientTest, SetData027, TestSize.Level1)
2147 {
2148 LOG_INFO(UDMF_TEST, "SetData027 begin.");
2149
2150 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2151 UnifiedData data;
2152 std::string key;
2153 std::string html = "";
2154 auto obj = std::make_shared<Object>();
2155 obj->value_["uniformDataType"] = "general.html";
2156 obj->value_["htmlContent"] = html;
2157 obj->value_["plainContent"] = "htmlPlainContent";
2158 auto obj2 = std::make_shared<Object>();
2159 obj2->value_["detail1"] = "detail1";
2160 obj2->value_["detail2"] = "detail2";
2161 obj->value_["details"] = obj2;
2162 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2163 data.AddRecord(htmlRecord);
2164 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2165 ASSERT_EQ(status, E_OK);
2166
2167 QueryOption option2 = { .key = key };
2168 AddPrivilege1(option2);
2169 SetHapToken1();
2170 UnifiedData readData;
2171 status = UdmfClient::GetInstance().GetData(option2, readData);
2172 ASSERT_EQ(status, E_OK);
2173
2174 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2175 ASSERT_NE(readRecord, nullptr);
2176 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2177 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), html);
2178 auto uris = readRecord->GetUris();
2179 EXPECT_EQ(uris.size(), 0);
2180
2181 LOG_INFO(UDMF_TEST, "SetData027 end.");
2182 }
2183
2184 /**
2185 * @tc.name: SetData028
2186 * @tc.desc: Set Html record include invalid value and get uris data
2187 * @tc.type: FUNC
2188 */
2189 HWTEST_F(UdmfClientTest, SetData028, TestSize.Level1)
2190 {
2191 LOG_INFO(UDMF_TEST, "SetData028 begin.");
2192
2193 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2194 UnifiedData data;
2195 std::string key;
2196 std::string html = "<img data-ohos='clipboard' src=>"
2197 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/102.png'>"
2198 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/103.png'>"
2199 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/104.png'>";
2200 auto obj = std::make_shared<Object>();
2201 obj->value_["uniformDataType"] = "general.html";
2202 obj->value_["htmlContent"] = html;
2203 obj->value_["plainContent"] = "htmlPlainContent";
2204 auto obj2 = std::make_shared<Object>();
2205 obj2->value_["detail1"] = "detail1";
2206 obj2->value_["detail2"] = "detail2";
2207 obj->value_["details"] = obj2;
2208 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2209 data.AddRecord(htmlRecord);
2210 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2211 ASSERT_EQ(status, E_OK);
2212
2213 QueryOption option2 = { .key = key };
2214 AddPrivilege1(option2);
2215 SetHapToken1();
2216 UnifiedData readData;
2217 status = UdmfClient::GetInstance().GetData(option2, readData);
2218 ASSERT_EQ(status, E_OK);
2219
2220 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2221 ASSERT_NE(readRecord, nullptr);
2222 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2223 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), html);
2224 auto uris = readRecord->GetUris();
2225 EXPECT_EQ(uris.size(), 0);
2226
2227 LOG_INFO(UDMF_TEST, "SetData028 end.");
2228 }
2229
2230 /**
2231 * @tc.name: SetData029
2232 * @tc.desc: Set Html record include valid value and get uris data
2233 * @tc.type: FUNC
2234 */
2235 HWTEST_F(UdmfClientTest, SetData029, TestSize.Level1)
2236 {
2237 LOG_INFO(UDMF_TEST, "SetData029 begin.");
2238
2239 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2240 UnifiedData data;
2241 std::string key;
2242 std::string html = "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/temp.png'><img "
2243 "data-ohos='clipboard' "
2244 "src=\"file:///data/storage/el2/distributedfiles/temp.png\"><img data-ohos='clipboard' "
2245 "src='https://data/storage/el2/distributedfiles/202305301.png'>";
2246 auto obj = std::make_shared<Object>();
2247 obj->value_["uniformDataType"] = "general.html";
2248 obj->value_["htmlContent"] = html;
2249 obj->value_["plainContent"] = "htmlPlainContent";
2250 auto obj2 = std::make_shared<Object>();
2251 obj2->value_["detail1"] = "detail1";
2252 obj2->value_["detail2"] = "detail2";
2253 obj->value_["details"] = obj2;
2254 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2255 data.AddRecord(htmlRecord);
2256 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2257 ASSERT_EQ(status, E_OK);
2258
2259 QueryOption option2 = { .key = key };
2260 AddPrivilege1(option2);
2261 SetHapToken1();
2262 UnifiedData readData;
2263 status = UdmfClient::GetInstance().GetData(option2, readData);
2264 ASSERT_EQ(status, E_OK);
2265
2266 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2267 ASSERT_NE(readRecord, nullptr);
2268 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2269 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), html);
2270 auto uris = readRecord->GetUris();
2271 EXPECT_EQ(uris.size(), 2);
2272
2273 LOG_INFO(UDMF_TEST, "SetData029 end.");
2274 }
2275
2276 /**
2277 * @tc.name: SetData030
2278 * @tc.desc: Set Html record include valid value and get uris data
2279 * @tc.type: FUNC
2280 */
2281 HWTEST_F(UdmfClientTest, SetData030, TestSize.Level1)
2282 {
2283 LOG_INFO(UDMF_TEST, "SetData030 begin.");
2284
2285 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2286 UnifiedData data;
2287 std::string key;
2288 std::string html = "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/101.png'>"
2289 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/102.png'>"
2290 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/103.png'>";
2291 std::string uriSrc = "file:///data/storage/el2/distributedfiles/101.png";
2292 auto obj = std::make_shared<Object>();
2293 obj->value_["uniformDataType"] = "general.html";
2294 obj->value_["htmlContent"] = html;
2295 obj->value_["plainContent"] = "htmlPlainContent";
2296 auto obj2 = std::make_shared<Object>();
2297 obj2->value_["detail1"] = "detail1";
2298 obj2->value_["detail2"] = "detail2";
2299 obj->value_["details"] = obj2;
2300 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2301 data.AddRecord(htmlRecord);
2302 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2303 ASSERT_EQ(status, E_OK);
2304
2305 QueryOption option2 = { .key = key };
2306 AddPrivilege1(option2);
2307 SetHapToken1();
2308 UnifiedData readData;
2309 status = UdmfClient::GetInstance().GetData(option2, readData);
2310 ASSERT_EQ(status, E_OK);
2311
2312 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2313 ASSERT_NE(readRecord, nullptr);
2314 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2315 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), html);
2316 auto uris = readRecord->GetUris();
2317 EXPECT_EQ(uris.size(), 1);
2318 EXPECT_EQ(uris[0].oriUri, uriSrc);
2319 EXPECT_TRUE(uris[0].dfsUri.empty());
2320
2321 LOG_INFO(UDMF_TEST, "SetData030 end.");
2322 }
2323
2324 /**
2325 * @tc.name: SetData031
2326 * @tc.desc: Set Html record add dfsUri and get uris data
2327 * @tc.type: FUNC
2328 */
2329 HWTEST_F(UdmfClientTest, SetData031, TestSize.Level1)
2330 {
2331 LOG_INFO(UDMF_TEST, "SetData031 begin.");
2332
2333 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2334 UnifiedData data;
2335 std::string key;
2336 std::string html = "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/101.png'>"
2337 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/101.png'>"
2338 "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/102.png'>"
2339 "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/101.png'>";
2340 std::string uriSrc1 = "file:///data/storage/el2/distributedfiles/101.png";
2341 std::string uriSrc2 = "file:///data/storage/el2/distributedfiles/102.png";
2342 auto obj = std::make_shared<Object>();
2343 obj->value_["uniformDataType"] = "general.html";
2344 obj->value_["htmlContent"] = html;
2345 obj->value_["plainContent"] = "htmlPlainContent";
2346 auto obj2 = std::make_shared<Object>();
2347 obj2->value_["detail1"] = "detail1";
2348 obj2->value_["detail2"] = "detail2";
2349 obj->value_["details"] = obj2;
2350 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2351 data.AddRecord(htmlRecord);
2352 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2353 ASSERT_EQ(status, E_OK);
2354
2355 QueryOption option2 = { .key = key };
2356 AddPrivilege1(option2);
2357 SetHapToken1();
2358 UnifiedData readData;
2359 status = UdmfClient::GetInstance().GetData(option2, readData);
2360 ASSERT_EQ(status, E_OK);
2361
2362 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2363 ASSERT_NE(readRecord, nullptr);
2364 auto uris = readRecord->GetUris();
2365 EXPECT_EQ(uris.size(), 3);
2366 EXPECT_EQ(uris[0].oriUri, uriSrc1);
2367 EXPECT_EQ(uris[1].oriUri, uriSrc2);
2368 EXPECT_EQ(uris[2].oriUri, uriSrc1);
2369 std::string strUri1 = "file:///data/1.png";
2370 std::string strUri2 = "file:///data/2.png";
2371 std::unordered_map<std::string, std::string> dfsUris;
2372 dfsUris.insert(std::make_pair(uriSrc1, strUri1));
2373 dfsUris.insert(std::make_pair(uriSrc2, strUri2));
__anonf182d9e90102(UriInfo &uriInfo) 2374 readRecord->ComputeUris([&dfsUris] (UriInfo &uriInfo) {
2375 auto iter = dfsUris.find(uriInfo.oriUri);
2376 if (iter != dfsUris.end()) {
2377 uriInfo.dfsUri = iter->second;
2378 }
2379 return true;
2380 });
2381 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2382 std::string htmlResult = "<img data-ohos='clipboard' src='file:///data/1.png'>"
2383 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/101.png'>"
2384 "<img data-ohos='clipboard' src='file:///data/2.png'>"
2385 "<img data-ohos='clipboard' src='file:///data/1.png'>";
2386 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2387 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), htmlResult);
2388 auto uris1 = readRecord->GetUris();
2389 EXPECT_EQ(uris1[0].dfsUri, strUri1);
2390 EXPECT_EQ(uris1[1].dfsUri, strUri2);
2391 EXPECT_EQ(uris1[2].dfsUri, strUri1);
2392
2393 LOG_INFO(UDMF_TEST, "SetData031 end.");
2394 }
2395
2396 /**
2397 * @tc.name: SetData032
2398 * @tc.desc: Set Html entry is null str and get uris data
2399 * @tc.type: FUNC
2400 */
2401 HWTEST_F(UdmfClientTest, SetData032, TestSize.Level1)
2402 {
2403 LOG_INFO(UDMF_TEST, "SetData032 begin.");
2404
2405 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2406 UnifiedData data;
2407 std::string key;
2408 std::shared_ptr<Object> obj = std::make_shared<Object>();
2409 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2410 obj->value_[FILE_URI_PARAM] = "http://demo.com";
2411 obj->value_[FILE_TYPE] = "abcdefg";
2412 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
2413 std::string html = "";
2414 auto htmlRecord = Html(html, "abstract");
2415 htmlRecord.InitObject();
2416 record->AddEntry(htmlRecord.GetUtdId(), htmlRecord.GetOriginValue());
2417 data.AddRecord(record);
2418 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2419 ASSERT_EQ(status, E_OK);
2420
2421 QueryOption option2 = { .key = key };
2422 AddPrivilege1(option2);
2423 SetHapToken1();
2424 UnifiedData readData;
2425 status = UdmfClient::GetInstance().GetData(option2, readData);
2426 ASSERT_EQ(status, E_OK);
2427
2428 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2429 ASSERT_NE(readRecord, nullptr);
2430 auto entryValue = readRecord->GetEntry(UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML));
2431 auto object = std::get<std::shared_ptr<Object>>(entryValue);
2432 ASSERT_NE(object, nullptr);
2433 auto iter = object->value_.find(HTML_CONTENT);
2434 ASSERT_TRUE(iter != object->value_.end());
2435 EXPECT_TRUE(std::holds_alternative<std::string>(iter->second));
2436 auto content = std::get<std::string>(iter->second);
2437 EXPECT_EQ(content, html);
2438 auto uris = readRecord->GetUris();
2439 EXPECT_EQ(uris.size(), 0);
2440
2441 LOG_INFO(UDMF_TEST, "SetData032 end.");
2442 }
2443
2444 /**
2445 * @tc.name: SetData033
2446 * @tc.desc: Set Html entry include invalid value and get uris data
2447 * @tc.type: FUNC
2448 */
2449 HWTEST_F(UdmfClientTest, SetData033, TestSize.Level1)
2450 {
2451 LOG_INFO(UDMF_TEST, "SetData033 begin.");
2452
2453 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2454 UnifiedData data;
2455 std::string key;
2456 std::shared_ptr<Object> obj = std::make_shared<Object>();
2457 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2458 obj->value_[FILE_URI_PARAM] = "http://demo.com";
2459 obj->value_[FILE_TYPE] = "abcdefg";
2460 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
2461 std::string html = "<img data-ohos='clipboard' src=>"
2462 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/102.png'>"
2463 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/103.png'>"
2464 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/104.png'>";
2465 auto htmlRecord = Html(html, "abstract");
2466 htmlRecord.InitObject();
2467 record->AddEntry(htmlRecord.GetUtdId(), htmlRecord.GetOriginValue());
2468 data.AddRecord(record);
2469 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2470 ASSERT_EQ(status, E_OK);
2471
2472 QueryOption option2 = { .key = key };
2473 AddPrivilege1(option2);
2474 SetHapToken1();
2475 UnifiedData readData;
2476 status = UdmfClient::GetInstance().GetData(option2, readData);
2477 ASSERT_EQ(status, E_OK);
2478
2479 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2480 ASSERT_NE(readRecord, nullptr);
2481 auto entryValue = readRecord->GetEntry(UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML));
2482 auto object = std::get<std::shared_ptr<Object>>(entryValue);
2483 ASSERT_NE(object, nullptr);
2484 auto iter = object->value_.find(HTML_CONTENT);
2485 ASSERT_TRUE(iter != object->value_.end());
2486 EXPECT_TRUE(std::holds_alternative<std::string>(iter->second));
2487 auto content = std::get<std::string>(iter->second);
2488 EXPECT_EQ(content, html);
2489 auto uris = readRecord->GetUris();
2490 EXPECT_EQ(uris.size(), 0);
2491
2492 LOG_INFO(UDMF_TEST, "SetData033 end.");
2493 }
2494
2495 /**
2496 * @tc.name: SetData034
2497 * @tc.desc: Set Html entry include valid value and get uris data
2498 * @tc.type: FUNC
2499 */
2500 HWTEST_F(UdmfClientTest, SetData034, TestSize.Level1)
2501 {
2502 LOG_INFO(UDMF_TEST, "SetData034 begin.");
2503
2504 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2505 UnifiedData data;
2506 std::string key;
2507 std::shared_ptr<Object> obj = std::make_shared<Object>();
2508 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2509 obj->value_[FILE_URI_PARAM] = "http://demo.com";
2510 obj->value_[FILE_TYPE] = "abcdefg";
2511 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
2512 std::string html = "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/101.png'>"
2513 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/102.png'>"
2514 "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/103.png'>";
2515 std::string uriSrc = "file:///data/storage/el2/distributedfiles/103.png";
2516 auto htmlRecord = Html(html, "abstract");
2517 htmlRecord.InitObject();
2518 record->AddEntry(htmlRecord.GetUtdId(), htmlRecord.GetOriginValue());
2519 data.AddRecord(record);
2520 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2521 ASSERT_EQ(status, E_OK);
2522
2523 QueryOption option2 = { .key = key };
2524 AddPrivilege1(option2);
2525 SetHapToken1();
2526 UnifiedData readData;
2527 status = UdmfClient::GetInstance().GetData(option2, readData);
2528 ASSERT_EQ(status, E_OK);
2529
2530 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2531 ASSERT_NE(readRecord, nullptr);
2532 auto entryValue = readRecord->GetEntry(UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML));
2533 auto object = std::get<std::shared_ptr<Object>>(entryValue);
2534 ASSERT_NE(object, nullptr);
2535 auto iter = object->value_.find(HTML_CONTENT);
2536 ASSERT_TRUE(iter != object->value_.end());
2537 EXPECT_TRUE(std::holds_alternative<std::string>(iter->second));
2538 auto content = std::get<std::string>(iter->second);
2539 EXPECT_EQ(content, html);
2540 auto uris = readRecord->GetUris();
2541 EXPECT_EQ(uris.size(), 1);
2542 EXPECT_EQ(uris[0].oriUri, uriSrc);
2543 EXPECT_TRUE(uris[0].dfsUri.empty());
2544
2545 LOG_INFO(UDMF_TEST, "SetData034 end.");
2546 }
2547
2548 /**
2549 * @tc.name: SetData035
2550 * @tc.desc: Set Html entry add dfsUri and get uris data
2551 * @tc.type: FUNC
2552 */
2553 HWTEST_F(UdmfClientTest, SetData035, TestSize.Level1)
2554 {
2555 LOG_INFO(UDMF_TEST, "SetData035 begin.");
2556
2557 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2558 UnifiedData data;
2559 std::string key;
2560 std::shared_ptr<Object> obj = std::make_shared<Object>();
2561 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2562 obj->value_[FILE_URI_PARAM] = "http://demo.com";
2563 obj->value_[FILE_TYPE] = "abcdefg";
2564 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
2565 std::string html = "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/101.png'>"
2566 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/202305301.png'>"
2567 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/202305301.png'>"
2568 "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/102.png'>"
2569 "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/103.png'>";
2570 std::string uriSrc1 = "file:///data/storage/el2/distributedfiles/101.png";
2571 std::string uriSrc2 = "file:///data/storage/el2/distributedfiles/102.png";
2572 std::string uriSrc3 = "file:///data/storage/el2/distributedfiles/103.png";
2573 auto htmlRecord = Html(html, "abstract");
2574 htmlRecord.InitObject();
2575 record->AddEntry(htmlRecord.GetUtdId(), htmlRecord.GetOriginValue());
2576 data.AddRecord(record);
2577 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2578 ASSERT_EQ(status, E_OK);
2579
2580 QueryOption option2 = { .key = key };
2581 AddPrivilege1(option2);
2582 SetHapToken1();
2583 UnifiedData readData;
2584 status = UdmfClient::GetInstance().GetData(option2, readData);
2585 ASSERT_EQ(status, E_OK);
2586
2587 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2588 ASSERT_NE(readRecord, nullptr);
2589 auto uris = readRecord->GetUris();
2590 EXPECT_EQ(uris.size(), 3);
2591 EXPECT_EQ(uris[0].oriUri, uriSrc1);
2592 EXPECT_EQ(uris[1].oriUri, uriSrc2);
2593 EXPECT_EQ(uris[2].oriUri, uriSrc3);
2594 std::string strUri1 = "file:///data/201.png";
2595 std::string strUri2 = "file:///data/202.png";
2596 std::string strUri3 = "file:///data/203.png";
2597 std::unordered_map<std::string, std::string> dfsUris;
2598 dfsUris.insert(std::make_pair(uriSrc1, strUri1));
2599 dfsUris.insert(std::make_pair(uriSrc2, strUri2));
2600 dfsUris.insert(std::make_pair(uriSrc3, strUri3));
__anonf182d9e90202(UriInfo &uriInfo) 2601 readRecord->ComputeUris([&dfsUris] (UriInfo &uriInfo) {
2602 auto iter = dfsUris.find(uriInfo.oriUri);
2603 if (iter != dfsUris.end()) {
2604 uriInfo.dfsUri = iter->second;
2605 }
2606 return true;
2607 });
2608 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2609 std::shared_ptr<UnifiedRecord> rebuildRecord = readData.GetRecordAt(0);
2610 std::string htmlResult = "<img data-ohos='clipboard' src='file:///data/201.png'>"
2611 "<img data-ohos='clipboard' src='https://data/storage/el2/distributedfiles/202305301.png'>"
2612 "<img data-ohos='clipboard' src='file://data/storage/el2/distributedfiles/202305301.png'>"
2613 "<img data-ohos='clipboard' src='file:///data/202.png'>"
2614 "<img data-ohos='clipboard' src='file:///data/203.png'>";
2615 auto entryValue = rebuildRecord->GetEntry(UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML));
2616 auto object = std::get<std::shared_ptr<Object>>(entryValue);
2617 ASSERT_NE(object, nullptr);
2618 auto iter = object->value_.find(HTML_CONTENT);
2619 ASSERT_TRUE(iter != object->value_.end());
2620 EXPECT_TRUE(std::holds_alternative<std::string>(iter->second));
2621 auto content = std::get<std::string>(iter->second);
2622 EXPECT_EQ(content, htmlResult);
2623
2624 LOG_INFO(UDMF_TEST, "SetData035 end.");
2625 }
2626
2627 /**
2628 * @tc.name: SetData036
2629 * @tc.desc: split and rebuild html value performance test
2630 * @tc.type: FUNC
2631 */
2632 HWTEST_F(UdmfClientTest, SetData036, TestSize.Level1)
2633 {
2634 LOG_INFO(UDMF_TEST, "SetData036 begin.");
2635
2636 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2637 UnifiedData data;
2638 std::string key;
2639 uint32_t kNumImages = 1000;
2640 std::string html = "";
2641 for (uint32_t i = 0; i < kNumImages; i++) {
2642 html += "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/101.png'>";
2643 }
2644 auto obj = std::make_shared<Object>();
2645 obj->value_["uniformDataType"] = "general.html";
2646 obj->value_["htmlContent"] = html;
2647 obj->value_["plainContent"] = "htmlPlainContent";
2648 auto obj2 = std::make_shared<Object>();
2649 obj2->value_["detail1"] = "detail1";
2650 obj2->value_["detail2"] = "detail2";
2651 obj->value_["details"] = obj2;
2652 auto htmlRecord = std::make_shared<Html>(UDType::HTML, obj);
2653 data.AddRecord(htmlRecord);
2654 auto start = std::chrono::high_resolution_clock::now();
2655 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2656 ASSERT_EQ(status, E_OK);
2657
2658 QueryOption option2 = { .key = key };
2659 AddPrivilege1(option2);
2660 SetHapToken1();
2661 UnifiedData readData;
2662 status = UdmfClient::GetInstance().GetData(option2, readData);
2663 ASSERT_EQ(status, E_OK);
2664
2665 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2666 ASSERT_NE(readRecord, nullptr);
2667 auto uris = readRecord->GetUris();
2668 EXPECT_EQ(uris.size(), kNumImages);
2669 std::string strUri = "file:///data/1.png";
__anonf182d9e90302(UriInfo &uriInfo) 2670 readRecord->ComputeUris([&strUri] (UriInfo &uriInfo) {
2671 uriInfo.dfsUri = strUri;
2672 return true;
2673 });
2674 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2675 auto end = std::chrono::high_resolution_clock::now();
2676 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
2677 LOG_INFO(UDMF_TEST, "SetData036 count duration=%{public}lld", duration.count());
2678 std::string htmlResult = "";
2679 for (uint32_t i = 0; i < kNumImages; i++) {
2680 htmlResult += "<img data-ohos='clipboard' src='file:///data/1.png'>";
2681 }
2682 auto readHtmlRecord = std::static_pointer_cast<Html>(readRecord);
2683 EXPECT_EQ(readHtmlRecord->GetHtmlContent(), htmlResult);
2684
2685 LOG_INFO(UDMF_TEST, "SetData036 end.");
2686 }
2687
2688 /**
2689 * @tc.name: SetData037
2690 * @tc.desc: test html record process
2691 * @tc.type: FUNC
2692 */
2693 HWTEST_F(UdmfClientTest, SetData037, TestSize.Level1)
2694 {
2695 LOG_INFO(UDMF_TEST, "SetData037 begin.");
2696
2697 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2698 UnifiedData data1;
2699 std::shared_ptr<UnifiedRecord> record = std::make_shared<UnifiedRecord>();
2700 data1.AddRecord(record);
2701 std::string key;
2702 UnifiedHtmlRecordProcess::RebuildHtmlRecord(data1);
2703 UnifiedHtmlRecordProcess::GetUriFromHtmlRecord(data1);
2704 UnifiedData data;
2705 auto plainText = std::make_shared<PlainText>();
2706 plainText->SetContent("plainContent");
2707 data.AddRecord(plainText);
2708 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2709 ASSERT_EQ(status, E_OK);
2710 std::shared_ptr<UnifiedRecord> record1 = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "this is a content");
2711 record1->ClearUris();
2712 data.AddRecord(record1);
2713 auto file = std::make_shared<File>();
2714 file->SetRemoteUri("remoteUri");
2715 UDDetails details;
2716 details.insert({ "udmf_key", "udmf_value" });
2717 file->SetDetails(details);
2718 data.AddRecord(file);
2719 UnifiedHtmlRecordProcess::RebuildHtmlRecord(data);
2720
2721 QueryOption option2 = { .key = key };
2722 AddPrivilege1(option2);
2723 SetHapToken1();
2724 UnifiedData readData;
2725 status = UdmfClient::GetInstance().GetData(option2, readData);
2726 ASSERT_EQ(status, E_OK);
2727
2728 LOG_INFO(UDMF_TEST, "SetData037 end.");
2729 }
2730
2731 /**
2732 * @tc.name: SetData038
2733 * @tc.desc: test html record process
2734 * @tc.type: FUNC
2735 */
2736 HWTEST_F(UdmfClientTest, SetData038, TestSize.Level1)
2737 {
2738 LOG_INFO(UDMF_TEST, "SetData038 begin.");
2739
2740 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2741 UnifiedData data;
2742 std::string key;
2743 std::shared_ptr<Object> fileObj = std::make_shared<Object>();
2744 fileObj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
2745 fileObj->value_[FILE_URI_PARAM] = "http://demo.com";
2746 auto record = std::make_shared<UnifiedRecord>(FILE_URI, fileObj);
2747 std::string html = "<img data-ohos='clipboard' src='file:///data/storage/el2/distributedfiles/103.png'>";
2748 auto htmlRecord = Html(html, "abstract");
2749 htmlRecord.InitObject();
2750 record->AddEntry(htmlRecord.GetUtdId(), htmlRecord.GetOriginValue());
2751 data.AddRecord(record);
2752 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2753 ASSERT_EQ(status, E_OK);
2754
2755 QueryOption option2 = { .key = key };
2756 AddPrivilege1(option2);
2757 SetHapToken1();
2758 UnifiedData readData;
2759 status = UdmfClient::GetInstance().GetData(option2, readData);
2760 ASSERT_EQ(status, E_OK);
2761
2762 std::shared_ptr<UnifiedRecord> readRecord = readData.GetRecordAt(0);
2763 ASSERT_NE(readRecord, nullptr);
2764 std::shared_ptr<std::map<std::string, ValueType>> entries = std::make_shared<std::map<std::string, ValueType>>();
2765 std::string utd = "general.html";
2766 ValueType value = "htmlContent";
2767 std::shared_ptr<Object> obj = std::make_shared<Object>();
2768 obj->value_[HTML_CONTENT] = 10;
2769 std::shared_ptr<Object> obj1 = std::make_shared<Object>();
2770 obj1->value_[HTML_CONTENT] = "file:///data/storage/el2/distributedfiles/103.png";
2771 readRecord->SetInnerEntries(entries);
2772 readRecord->SetType(UDType::HTML);
2773 entries->insert_or_assign(std::move(utd), std::move(value));
2774 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2775 entries->insert_or_assign(std::move(utd), std::move(obj));
2776 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2777 entries->insert_or_assign(std::move(utd), std::move(obj1));
2778 UnifiedHtmlRecordProcess::RebuildHtmlRecord(readData);
2779
2780 LOG_INFO(UDMF_TEST, "SetData038 end.");
2781 }
2782
2783 /**
2784 * @tc.name: SetData039
2785 * @tc.desc: test html record process
2786 * @tc.type: FUNC
2787 */
2788 HWTEST_F(UdmfClientTest, SetData039, TestSize.Level1)
2789 {
2790 LOG_INFO(UDMF_TEST, "SetData039 begin.");
2791
2792 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2793 UnifiedData data;
2794 auto text = std::make_shared<Text>();
2795 data.AddRecord(text);
2796 auto plainText = std::make_shared<PlainText>();
2797 plainText->SetContent("plainContent");
2798 data.AddRecord(plainText);
2799 auto html = std::make_shared<Html>();
2800 html->SetPlainContent("htmlContent");
2801 data.AddRecord(html);
2802 std::string key;
2803 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2804 ASSERT_EQ(status, E_OK);
2805
2806 UnifiedData data1;
2807 std::shared_ptr<Object> obj = std::make_shared<Object>();
2808 obj->value_[PLAIN_CONTENT] = "http://demo.com";
2809 obj->value_[HTML_CONTENT] = 10;
2810 plainText->AddEntry("general.html", obj);
2811 data1.AddRecord(plainText);
2812 UnifiedHtmlRecordProcess::GetUriFromHtmlRecord(data1);
2813 UnifiedHtmlRecordProcess::RebuildHtmlRecord(data1);
2814 UnifiedData data2;
2815 text->AddEntry("general.html", "");
2816 data2.AddRecord(text);
2817 UnifiedHtmlRecordProcess::GetUriFromHtmlRecord(data2);
2818 UnifiedHtmlRecordProcess::RebuildHtmlRecord(data2);
2819 QueryOption option2 = { .key = key };
2820 AddPrivilege1(option2);
2821 SetHapToken1();
2822 UnifiedData readData;
2823 status = UdmfClient::GetInstance().GetData(option2, readData);
2824 ASSERT_EQ(status, E_OK);
2825
2826 LOG_INFO(UDMF_TEST, "SetData039 end.");
2827 }
2828
2829 /**
2830 * @tc.name: GetSummary003
2831 * @tc.desc: Get summary data
2832 * @tc.type: FUNC
2833 */
2834 HWTEST_F(UdmfClientTest, GetSummary003, TestSize.Level1)
2835 {
2836 LOG_INFO(UDMF_TEST, "GetSummary003 begin.");
2837
2838 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2839 UnifiedData data;
2840 std::string key;
2841
2842 UDDetails details;
2843 details.insert({ "udmf_key", "udmf_value" });
2844 std::string value;
2845 int64_t maxSize = 512 * 1024;
2846 for (int64_t i = 0; i < maxSize; ++i) {
2847 value += "11";
2848 }
2849 details.insert({ value, value });
2850
2851 auto text = std::make_shared<Text>();
2852 text->SetDetails(details);
2853 data.AddRecord(text);
2854
2855 auto plainText = std::make_shared<PlainText>();
2856 plainText->SetDetails(details);
2857 plainText->SetContent("content");
2858 plainText->SetAbstract("abstract");
2859 data.AddRecord(plainText);
2860
2861 UnifiedDataHelper::SetRootPath("/data/udmf_test/");
2862 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2863 ASSERT_EQ(status, E_OK);
2864 UnifiedDataHelper::SetRootPath("");
2865
2866 QueryOption option2 = { .key = key };
2867 Summary summary;
2868 status = UdmfClient::GetInstance().GetSummary(option2, summary);
2869
2870 auto size = text->GetSize();
2871 size += plainText->GetSize();
2872
2873 ASSERT_EQ(status, E_OK);
2874 ASSERT_EQ(summary.totalSize, size);
2875 ASSERT_EQ(summary.summary["general.text"], text->GetSize());
2876 ASSERT_EQ(summary.summary["general.plain-text"], plainText->GetSize());
2877
2878 LOG_INFO(UDMF_TEST, "GetSummary003 end.");
2879 }
2880
2881 /**
2882 * @tc.name: IsRemoteData
2883 * @tc.desc: is remote data, result false: not remote data, true: remote data.
2884 * @tc.type: FUNC
2885 */
2886 HWTEST_F(UdmfClientTest, IsRemoteData001, TestSize.Level1)
2887 {
2888 LOG_INFO(UDMF_TEST, "IsRemoteData001 begin.");
2889
2890 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
2891 UnifiedData data;
2892 std::string key;
2893
2894 UDDetails details;
2895 details.insert({ "udmf_key", "udmf_value" });
2896
2897 auto text = std::make_shared<Text>();
2898 text->SetDetails(details);
2899 data.AddRecord(text);
2900
2901 auto plainText = std::make_shared<PlainText>();
2902 plainText->SetDetails(details);
2903 plainText->SetContent("content");
2904 plainText->SetAbstract("abstract");
2905 data.AddRecord(plainText);
2906
2907 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
2908 ASSERT_EQ(status, E_OK);
2909
2910 QueryOption option2 = { .key = key };
2911 bool result = true;
2912 status = UdmfClient::GetInstance().IsRemoteData(option2, result);
2913
2914 ASSERT_EQ(status, E_OK);
2915 ASSERT_EQ(result, false);
2916
2917 LOG_INFO(UDMF_TEST, "IsRemoteData001 end.");
2918 }
2919
2920 /**
2921 * @tc.name: GetTypesLabels001
2922 * @tc.desc: test GetTypesLabels
2923 * @tc.type: FUNC
2924 */
2925 HWTEST_F(UdmfClientTest, GetTypesLabels001, TestSize.Level1)
2926 {
2927 LOG_INFO(UDMF_TEST, "GetTypesLabels001 begin.");
2928 UnifiedData data;
2929 UDDetails details;
2930 details.insert({ "udmf_key", "udmf_value" });
2931 auto text = std::make_shared<Text>();
2932 text->SetDetails(details);
2933 auto plainText = std::make_shared<PlainText>();
2934 plainText->SetDetails(details);
2935 std::vector<std::shared_ptr<UnifiedRecord>> records = {text, plainText};
2936 data.AddRecords(records);
2937
2938 std::vector<std::string> types = {"general.text", "general.plain-text"};
2939 ASSERT_EQ(data.GetTypesLabels(), types);
2940 ASSERT_EQ(data.HasType("general.text"), true);
2941 ASSERT_EQ(data.HasType("general.plain-text"), true);
2942 ASSERT_EQ(data.HasType("general.html"), false);
2943 }
2944
2945 /**
2946 * @tc.name: QueryUDSData001
2947 * @tc.desc: QueryUDSData001
2948 * @tc.type: FUNC
2949 */
2950 HWTEST_F(UdmfClientTest, QueryUDSData001, TestSize.Level1)
2951 {
2952 LOG_INFO(UDMF_TEST, "QueryUDSData001 begin.");
2953
2954 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
2955 std::vector<UnifiedData> unifiedDataSet;
2956 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2957 ASSERT_EQ(status, E_OK);
2958 unifiedDataSet.clear();
2959 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
2960 ASSERT_EQ(status, E_OK);
2961 ASSERT_TRUE(unifiedDataSet.empty());
2962
2963 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
2964 UnifiedData data;
2965 std::shared_ptr<UnifiedRecord> record1 = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
2966 data.AddRecord(record1);
2967 std::string key;
2968 status = UdmfClient::GetInstance().SetData(customOption, data, key);
2969 ASSERT_EQ(status, E_OK);
2970
2971 query = { .key = key };
2972 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
2973 ASSERT_EQ(status, E_OK);
2974 ASSERT_EQ(unifiedDataSet.size(), 1);
2975 std::shared_ptr<UnifiedRecord> record2 = unifiedDataSet[0].GetRecordAt(0);
2976 ASSERT_NE(record2, nullptr);
2977 ASSERT_EQ(record2->GetType(), UDType::PLAIN_TEXT);
2978 ValueType value = record2->GetValue();
2979 ASSERT_NE(std::get_if<std::string>(&value), nullptr);
2980 ASSERT_EQ(std::get<std::string>(value), "plainTextContent");
2981 LOG_INFO(UDMF_TEST, "QueryUDSData001 end.");
2982 }
2983
2984 /**
2985 * @tc.name: QueryUDSData002
2986 * @tc.desc: QueryUDSData002
2987 * @tc.type: FUNC
2988 */
2989 HWTEST_F(UdmfClientTest, QueryUDSData002, TestSize.Level1)
2990 {
2991 LOG_INFO(UDMF_TEST, "QueryUDSData002 begin.");
2992
2993 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
2994 std::vector<UnifiedData> unifiedDataSet;
2995 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2996 ASSERT_EQ(status, E_OK);
2997 unifiedDataSet.clear();
2998 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
2999 ASSERT_EQ(status, E_OK);
3000 ASSERT_TRUE(unifiedDataSet.empty());
3001
3002 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
3003 UnifiedData data;
3004 auto obj = std::make_shared<Object>();
3005 obj->value_["uniformDataType"] = "general.plain-text";
3006 obj->value_["textContent"] = "plainTextContent";
3007 obj->value_["abstract"] = "plainTextAbstract";
3008 auto obj2 = std::make_shared<Object>();
3009 obj2->value_["detail1"] = "detail1";
3010 obj2->value_["detail2"] = "detail2";
3011 obj->value_["details"] = obj2;
3012 auto record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, obj);
3013 data.AddRecord(record);
3014 std::string key;
3015 status = UdmfClient::GetInstance().SetData(customOption, data, key);
3016 ASSERT_EQ(status, E_OK);
3017
3018 unifiedDataSet.clear();
3019 query = { .key = key, .intention = UD_INTENTION_DATA_HUB };
3020 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3021 ASSERT_EQ(status, E_OK);
3022 ASSERT_EQ(unifiedDataSet.size(), 1);
3023 auto record2 = unifiedDataSet[0].GetRecordAt(0);
3024 ASSERT_NE(record2, nullptr);
3025 ASSERT_EQ(record2->GetType(), UDType::PLAIN_TEXT);
3026 auto value = record2->GetValue();
3027
3028 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&value), nullptr);
3029 obj = std::get<std::shared_ptr<Object>>(value);
3030
3031 ASSERT_NE(std::get_if<std::string>(&obj->value_["uniformDataType"]), nullptr);
3032 ASSERT_EQ(std::get<std::string>(obj->value_["uniformDataType"]), "general.plain-text");
3033 ASSERT_NE(std::get_if<std::string>(&obj->value_["textContent"]), nullptr);
3034 ASSERT_EQ(std::get<std::string>(obj->value_["textContent"]), "plainTextContent");
3035 ASSERT_NE(std::get_if<std::string>(&obj->value_["abstract"]), nullptr);
3036 ASSERT_EQ(std::get<std::string>(obj->value_["abstract"]), "plainTextAbstract");
3037
3038 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&obj->value_["details"]), nullptr);
3039 obj2 = std::get<std::shared_ptr<Object>>(obj->value_["details"]);
3040
3041 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail1"]), nullptr);
3042 ASSERT_EQ(std::get<std::string>(obj2->value_["detail1"]), "detail1");
3043 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail2"]), nullptr);
3044 ASSERT_EQ(std::get<std::string>(obj2->value_["detail2"]), "detail2");
3045 LOG_INFO(UDMF_TEST, "QueryUDSData002 end.");
3046 }
3047
3048 /**
3049 * @tc.name: QueryUDSData003
3050 * @tc.desc: QueryUDSData003
3051 * @tc.type: FUNC
3052 */
3053 HWTEST_F(UdmfClientTest, QueryUDSData003, TestSize.Level1)
3054 {
3055 LOG_INFO(UDMF_TEST, "QueryUDSData003 begin.");
3056
3057 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
3058 std::vector<UnifiedData> unifiedDataSet;
3059 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
3060 ASSERT_EQ(status, E_OK);
3061 unifiedDataSet.clear();
3062 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3063 ASSERT_EQ(status, E_OK);
3064 ASSERT_TRUE(unifiedDataSet.empty());
3065
3066 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
3067 UnifiedData data;
3068 auto obj = std::make_shared<Object>();
3069 obj->value_["uniformDataType"] = "general.hyperlink";
3070 obj->value_["url"] = "www.xxx";
3071 obj->value_["description"] = "hyperlinkDescription";
3072 auto obj2 = std::make_shared<Object>();
3073 obj2->value_["detail1"] = "detail1";
3074 obj2->value_["detail2"] = "detail2";
3075 obj->value_["details"] = obj2;
3076 auto record = std::make_shared<Link>(UDType::HYPERLINK, obj);
3077 data.AddRecord(record);
3078 std::string key;
3079 status = UdmfClient::GetInstance().SetData(customOption, data, key);
3080 ASSERT_EQ(status, E_OK);
3081
3082 unifiedDataSet.clear();
3083 query = { .key = key, .intention = UD_INTENTION_DATA_HUB };
3084 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3085 ASSERT_EQ(status, E_OK);
3086 ASSERT_EQ(unifiedDataSet.size(), 1);
3087 auto record2 = unifiedDataSet[0].GetRecordAt(0);
3088 ASSERT_NE(record2, nullptr);
3089 ASSERT_EQ(record2->GetType(), UDType::HYPERLINK);
3090 auto value = record2->GetValue();
3091
3092 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&value), nullptr);
3093 obj = std::get<std::shared_ptr<Object>>(value);
3094
3095 ASSERT_NE(std::get_if<std::string>(&obj->value_["uniformDataType"]), nullptr);
3096 ASSERT_EQ(std::get<std::string>(obj->value_["uniformDataType"]), "general.hyperlink");
3097 ASSERT_NE(std::get_if<std::string>(&obj->value_["url"]), nullptr);
3098 ASSERT_EQ(std::get<std::string>(obj->value_["url"]), "www.xxx");
3099 ASSERT_NE(std::get_if<std::string>(&obj->value_["description"]), nullptr);
3100 ASSERT_EQ(std::get<std::string>(obj->value_["description"]), "hyperlinkDescription");
3101
3102 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&obj->value_["details"]), nullptr);
3103 obj2 = std::get<std::shared_ptr<Object>>(obj->value_["details"]);
3104
3105 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail1"]), nullptr);
3106 ASSERT_EQ(std::get<std::string>(obj2->value_["detail1"]), "detail1");
3107 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail2"]), nullptr);
3108 ASSERT_EQ(std::get<std::string>(obj2->value_["detail2"]), "detail2");
3109 LOG_INFO(UDMF_TEST, "QueryUDSData003 end.");
3110 }
3111
3112 /**
3113 * @tc.name: QueryUDSData004
3114 * @tc.desc: QueryUDSData004
3115 * @tc.type: FUNC
3116 */
3117 HWTEST_F(UdmfClientTest, QueryUDSData004, TestSize.Level1)
3118 {
3119 LOG_INFO(UDMF_TEST, "QueryUDSData004 begin.");
3120
3121 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
3122 std::vector<UnifiedData> unifiedDataSet;
3123 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
3124 ASSERT_EQ(status, E_OK);
3125 unifiedDataSet.clear();
3126 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3127 ASSERT_EQ(status, E_OK);
3128 ASSERT_TRUE(unifiedDataSet.empty());
3129
3130 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
3131 UnifiedData data;
3132 auto obj = std::make_shared<Object>();
3133 obj->value_["uniformDataType"] = "general.html";
3134 obj->value_["htmlContent"] = "www.xxx";
3135 obj->value_["plainContent"] = "htmlPlainContent";
3136 auto obj2 = std::make_shared<Object>();
3137 obj2->value_["detail1"] = "detail1";
3138 obj2->value_["detail2"] = "detail2";
3139 obj->value_["details"] = obj2;
3140 auto record = std::make_shared<Html>(UDType::HTML, obj);
3141 data.AddRecord(record);
3142 std::string key;
3143 status = UdmfClient::GetInstance().SetData(customOption, data, key);
3144 ASSERT_EQ(status, E_OK);
3145
3146 unifiedDataSet.clear();
3147 query = { .key = key, .intention = UD_INTENTION_DATA_HUB };
3148 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3149 ASSERT_EQ(status, E_OK);
3150 ASSERT_EQ(unifiedDataSet.size(), 1);
3151 auto record2 = unifiedDataSet[0].GetRecordAt(0);
3152 ASSERT_NE(record2, nullptr);
3153 ASSERT_EQ(record2->GetType(), UDType::HTML);
3154 auto value = record2->GetValue();
3155
3156 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&value), nullptr);
3157 obj = std::get<std::shared_ptr<Object>>(value);
3158
3159 ASSERT_NE(std::get_if<std::string>(&obj->value_["uniformDataType"]), nullptr);
3160 ASSERT_EQ(std::get<std::string>(obj->value_["uniformDataType"]), "general.html");
3161 ASSERT_NE(std::get_if<std::string>(&obj->value_["htmlContent"]), nullptr);
3162 ASSERT_EQ(std::get<std::string>(obj->value_["htmlContent"]), "www.xxx");
3163 ASSERT_NE(std::get_if<std::string>(&obj->value_["plainContent"]), nullptr);
3164 ASSERT_EQ(std::get<std::string>(obj->value_["plainContent"]), "htmlPlainContent");
3165
3166 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&obj->value_["details"]), nullptr);
3167 obj2 = std::get<std::shared_ptr<Object>>(obj->value_["details"]);
3168
3169 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail1"]), nullptr);
3170 ASSERT_EQ(std::get<std::string>(obj2->value_["detail1"]), "detail1");
3171 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail2"]), nullptr);
3172 ASSERT_EQ(std::get<std::string>(obj2->value_["detail2"]), "detail2");
3173 LOG_INFO(UDMF_TEST, "QueryUDSData004 end.");
3174 }
3175
3176 /**
3177 * @tc.name: QueryUDSData005
3178 * @tc.desc: QueryUDSData005
3179 * @tc.type: FUNC
3180 */
3181 HWTEST_F(UdmfClientTest, QueryUDSData005, TestSize.Level1)
3182 {
3183 LOG_INFO(UDMF_TEST, "QueryUDSData005 begin.");
3184
3185 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
3186 std::vector<UnifiedData> unifiedDataSet;
3187 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
3188 ASSERT_EQ(status, E_OK);
3189 unifiedDataSet.clear();
3190 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3191 ASSERT_EQ(status, E_OK);
3192 ASSERT_TRUE(unifiedDataSet.empty());
3193
3194 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
3195 UnifiedData data;
3196 auto obj = std::make_shared<Object>();
3197 obj->value_["uniformDataType"] = "openharmony.app-item";
3198 obj->value_["appId"] = "app-itemAppId";
3199 obj->value_["appName"] = "app-itemAppName";
3200 obj->value_["appIconId"] = "app-itemAppIconId";
3201 obj->value_["appLabelId"] = "app-itemAppLabelId";
3202 obj->value_["bundleName"] = "app-itemBundleName";
3203 obj->value_["abilityName"] = "app-itemAbilityName";
3204 auto obj2 = std::make_shared<Object>();
3205 obj2->value_["detail1"] = "detail1";
3206 obj2->value_["detail2"] = 1234;
3207 obj->value_["details"] = obj2;
3208 auto record = std::make_shared<SystemDefinedAppItem>(UDType::SYSTEM_DEFINED_APP_ITEM, obj);
3209 data.AddRecord(record);
3210 std::string key;
3211 status = UdmfClient::GetInstance().SetData(customOption, data, key);
3212 ASSERT_EQ(status, E_OK);
3213
3214 unifiedDataSet.clear();
3215 query = { .key = key, .intention = UD_INTENTION_DATA_HUB };
3216 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3217 ASSERT_EQ(status, E_OK);
3218 ASSERT_EQ(unifiedDataSet.size(), 1);
3219 auto record2 = unifiedDataSet[0].GetRecordAt(0);
3220 ASSERT_NE(record2, nullptr);
3221 ASSERT_EQ(record2->GetType(), UDType::SYSTEM_DEFINED_APP_ITEM);
3222 auto value = record2->GetValue();
3223
3224 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&value), nullptr);
3225 obj = std::get<std::shared_ptr<Object>>(value);
3226
3227 ASSERT_NE(std::get_if<std::string>(&obj->value_["uniformDataType"]), nullptr);
3228 ASSERT_EQ(std::get<std::string>(obj->value_["uniformDataType"]), "openharmony.app-item");
3229 ASSERT_NE(std::get_if<std::string>(&obj->value_["appId"]), nullptr);
3230 ASSERT_EQ(std::get<std::string>(obj->value_["appId"]), "app-itemAppId");
3231 ASSERT_NE(std::get_if<std::string>(&obj->value_["appName"]), nullptr);
3232 ASSERT_EQ(std::get<std::string>(obj->value_["appName"]), "app-itemAppName");
3233 ASSERT_NE(std::get_if<std::string>(&obj->value_["appIconId"]), nullptr);
3234 ASSERT_EQ(std::get<std::string>(obj->value_["appIconId"]), "app-itemAppIconId");
3235 ASSERT_NE(std::get_if<std::string>(&obj->value_["appLabelId"]), nullptr);
3236 ASSERT_EQ(std::get<std::string>(obj->value_["appLabelId"]), "app-itemAppLabelId");
3237 ASSERT_NE(std::get_if<std::string>(&obj->value_["bundleName"]), nullptr);
3238 ASSERT_EQ(std::get<std::string>(obj->value_["bundleName"]), "app-itemBundleName");
3239 ASSERT_NE(std::get_if<std::string>(&obj->value_["abilityName"]), nullptr);
3240 ASSERT_EQ(std::get<std::string>(obj->value_["abilityName"]), "app-itemAbilityName");
3241
3242 ASSERT_NE(std::get_if<std::shared_ptr<Object>>(&obj->value_["details"]), nullptr);
3243 obj2 = std::get<std::shared_ptr<Object>>(obj->value_["details"]);
3244
3245 ASSERT_NE(std::get_if<std::string>(&obj2->value_["detail1"]), nullptr);
3246 ASSERT_EQ(std::get<std::string>(obj2->value_["detail1"]), "detail1");
3247 ASSERT_NE(std::get_if<int32_t>(&obj2->value_["detail2"]), nullptr);
3248 ASSERT_EQ(std::get<int32_t>(obj2->value_["detail2"]), 1234);
3249 LOG_INFO(UDMF_TEST, "QueryUDSData005 end.");
3250 }
3251
3252 /**
3253 * @tc.name: GetSelfBundleName001
3254 * @tc.desc: Nrmal testcase of GetSelfBundleName
3255 * @tc.type: FUNC
3256 */
3257 HWTEST_F(UdmfClientTest, GetSelfBundleName001, TestSize.Level1)
3258 {
3259 LOG_INFO(UDMF_TEST, "GetSelfBundleName001 begin.");
3260 UdmfClient udmfClient;
3261 std::string ret = udmfClient.GetSelfBundleName();
3262 EXPECT_NE(ret, "");
3263 LOG_INFO(UDMF_TEST, "GetSelfBundleName001 end.");
3264 }
3265
3266 /**
3267 * @tc.name: GetSummary004
3268 * @tc.desc: Get summary data for entries
3269 * @tc.type: FUNC
3270 */
3271 HWTEST_F(UdmfClientTest, GetSummary004, TestSize.Level1)
3272 {
3273 LOG_INFO(UDMF_TEST, "GetSummary004 begin.");
3274 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
3275 UnifiedData data;
3276 std::string key;
3277 UDDetails details;
3278 details.insert({ "udmf_key", "udmf_value" });
3279 std::shared_ptr<Object> obj = std::make_shared<Object>();
3280 obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri";
3281 obj->value_[FILE_URI_PARAM] = "http://demo.com";
3282 obj->value_[FILE_TYPE] = "abcdefg";
3283 auto record = std::make_shared<UnifiedRecord>(FILE_URI, obj);
3284 auto plainText = PlainText("content", "abstract");
3285 auto size1 = plainText.GetSize();
3286 plainText.InitObject();
3287 record->AddEntry(plainText.GetUtdId2(), plainText.GetOriginValue());
3288 auto image = Image("uri");
3289 image.SetDetails(details);
3290 auto size2 = image.GetSize();
3291 image.InitObject();
3292 record->AddEntry(image.GetUtdId2(), image.GetOriginValue());
3293 std::vector<uint8_t> raw = {1, 2, 3, 4, 5};
3294 SystemDefinedPixelMap pixelMap = SystemDefinedPixelMap(raw);
3295 pixelMap.SetDetails(details);
3296 auto size3 = pixelMap.GetSize();
3297 pixelMap.InitObject();
3298 record->AddEntry(pixelMap.GetUtdId2(), pixelMap.GetOriginValue());
3299 raw = {1, 2, 3, 4, 5};
3300 auto applicationDefinedRecord = ApplicationDefinedRecord("my.type", raw);
3301 auto size4 = applicationDefinedRecord.GetSize();
3302 applicationDefinedRecord.InitObject();
3303 record->AddEntry(applicationDefinedRecord.GetUtdId2(), applicationDefinedRecord.GetOriginValue());
3304 data.AddRecord(record);
3305 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
3306 ASSERT_EQ(status, E_OK);
3307 QueryOption option2 = { .key = key };
3308 Summary summary;
3309 status = UdmfClient::GetInstance().GetSummary(option2, summary);
3310 ASSERT_EQ(status, E_OK);
3311 EXPECT_EQ(summary.summary["general.plain-text"], size1);
3312 EXPECT_EQ(summary.summary["general.image"], size2);
3313 EXPECT_EQ(summary.summary["openharmony.pixel-map"], size3);
3314 EXPECT_EQ(summary.summary["ApplicationDefinedType"], size4);
3315 EXPECT_EQ(summary.totalSize, record->GetSize());
3316 UnifiedData readData;
3317 status = UdmfClient::GetInstance().GetData(option2, readData);
3318 ASSERT_EQ(E_OK, status);
3319 ASSERT_EQ(1, readData.GetRecords().size());
3320 auto readRecord = readData.GetRecordAt(0);
3321 auto entries = readRecord->GetEntries();
3322 ASSERT_EQ(4, entries->size());
3323 auto readFileUri = std::get<std::shared_ptr<Object>>(entries->at("general.file-uri"));
3324 EXPECT_EQ("general.image", std::get<std::string>(readFileUri->value_[FILE_TYPE]));
3325 EXPECT_EQ("uri", std::get<std::string>(readFileUri->value_[ORI_URI]));
3326 auto readPlainText = std::get<std::shared_ptr<Object>>(entries->at("general.plain-text"));
3327 EXPECT_EQ("abstract", std::get<std::string>(readPlainText->value_[ABSTRACT]));
3328 auto readPixelMap = std::get<std::shared_ptr<Object>>(entries->at("openharmony.pixel-map"));
3329 EXPECT_EQ(5, std::get<std::vector<uint8_t>>(readPixelMap->value_[PIXEL_MAP]).size());
3330 auto readDefinedRecord = std::get<std::shared_ptr<Object>>(entries->at("my.type"));
3331 EXPECT_EQ(5, std::get<std::vector<uint8_t>>(readDefinedRecord->value_[ARRAY_BUFFER]).size());
3332 auto valueType = readRecord->GetValue();
3333 EXPECT_TRUE(std::holds_alternative<std::monostate>(readRecord->GetValue()));
3334 LOG_INFO(UDMF_TEST, "GetSummary004 end.");
3335 }
3336
3337 /**
3338 * @tc.name: GetSummary005
3339 * @tc.desc: Get summary data for entries
3340 * @tc.type: FUNC
3341 */
3342 HWTEST_F(UdmfClientTest, GetSummary005, TestSize.Level1)
3343 {
3344 LOG_INFO(UDMF_TEST, "GetSummary005 begin.");
3345
3346 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
3347 UnifiedData data;
3348 std::string key;
3349
3350 UDDetails details;
3351 details.insert({ "udmf_key", "udmf_value" });
3352
3353 auto record = std::make_shared<Html>("content1", "content2");
3354 auto size0 = record->GetSize();
3355
3356 auto link = Link("url", "descritpion");
3357 auto size1 = link.GetSize();
3358 link.InitObject();
3359 record->AddEntry(link.GetUtdId2(), link.GetOriginValue());
3360
3361 auto folder = Folder("uri");
3362 folder.SetDetails(details);
3363 auto size2 = folder.GetSize();
3364 folder.InitObject();
3365 record->AddEntry(folder.GetUtdId2(), folder.GetOriginValue());
3366
3367 std::vector<uint8_t> raw = {1, 2, 3, 4, 5};
3368 auto applicationDefinedRecord1 = ApplicationDefinedRecord("your.type", raw);
3369 auto size3 = applicationDefinedRecord1.GetSize();
3370 applicationDefinedRecord1.InitObject();
3371 record->AddEntry(applicationDefinedRecord1.GetUtdId2(), applicationDefinedRecord1.GetOriginValue());
3372
3373 raw = {1, 2, 3, 4, 5};
3374 auto applicationDefinedRecord2 = ApplicationDefinedRecord("my.type", raw);
3375 auto size4 = applicationDefinedRecord2.GetSize();
3376 applicationDefinedRecord2.InitObject();
3377 record->AddEntry(applicationDefinedRecord2.GetUtdId2(), applicationDefinedRecord2.GetOriginValue());
3378
3379 auto form = SystemDefinedForm();
3380 form.SetDetails(details);
3381 form.SetDetails(details);
3382 form.SetFormId(123);
3383 form.SetFormName("formName");
3384 form.SetModule("module");
3385 form.SetAbilityName("abilityName");
3386 form.SetBundleName("bundleName");
3387 auto size5 = form.GetSize();
3388 form.InitObject();
3389 record->AddEntry(form.GetUtdId2(), form.GetOriginValue());
3390
3391 raw = {1, 2, 3, 4, 5};
3392 std::shared_ptr<Object> obj = std::make_shared<Object>();
3393 obj->value_[UNIFORM_DATA_TYPE] = "general.content-form";
3394 obj->value_[THUMB_DATA] = raw;
3395 obj->value_[THUMB_DATA_LENGTH] = 5;
3396 obj->value_[DESCRIPTION] = "descritpion";
3397 obj->value_[TITLE] = "title";
3398 obj->value_[APP_ICON] = raw;
3399 obj->value_[APP_ICON_LENGTH] = 5;
3400 obj->value_[APP_NAME] = "appName";
3401 obj->value_[LINK_URL] = "linkUri";
3402 auto contentForm = UnifiedRecord(CONTENT_FORM, obj);
3403 auto size6 = contentForm.GetSize();
3404 record->AddEntry(contentForm.GetUtdId(), contentForm.GetOriginValue());
3405
3406 data.AddRecord(record);
3407
3408 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
3409 ASSERT_EQ(status, E_OK);
3410
3411 QueryOption option2 = { .key = key };
3412 Summary summary;
3413 status = UdmfClient::GetInstance().GetSummary(option2, summary);
3414
3415 LOG_INFO(UDMF_TEST, "GetSummary005 GetSummary.");
3416
3417 ASSERT_EQ(status, E_OK);
3418 EXPECT_EQ(summary.summary["general.html"], size0);
3419 EXPECT_EQ(summary.summary["general.hyperlink"], size1);
3420 EXPECT_EQ(summary.summary["general.folder"], size2);
3421 EXPECT_EQ(summary.summary["ApplicationDefinedType"], size3 + size4);
3422 EXPECT_EQ(summary.summary["openharmony.form"], size5);
3423 EXPECT_EQ(summary.summary["general.content-form"], size6);
3424
3425 EXPECT_EQ(summary.totalSize, record->GetSize());
3426
3427 UnifiedData readData;
3428 status = UdmfClient::GetInstance().GetData(option2, readData);
3429 LOG_INFO(UDMF_TEST, "GetSummary005 GetSummary1.");
3430 ASSERT_EQ(E_OK, status);
3431 ASSERT_EQ(1, readData.GetRecords().size());
3432 auto readRecord = readData.GetRecordAt(0);
3433 ValueType recordVal = readRecord->GetValue();
3434 auto entries = readRecord->GetEntries();
3435 ASSERT_EQ(7, entries->size());
3436 auto readHtml = std::get<std::shared_ptr<Object>>(entries->at("general.html"));
3437 EXPECT_EQ("content1", std::get<std::string>(readHtml->value_[HTML_CONTENT]));
3438 auto readHyperlink = std::get<std::shared_ptr<Object>>(entries->at("general.hyperlink"));
3439 EXPECT_EQ("descritpion", std::get<std::string>(readHyperlink->value_[DESCRIPTION]));
3440 auto readFolder = std::get<std::shared_ptr<Object>>(entries->at("general.file-uri"));
3441 EXPECT_EQ("uri", std::get<std::string>(readFolder->value_[ORI_URI]));
3442 auto readDefinedRecord = std::get<std::shared_ptr<Object>>(entries->at("your.type"));
3443 EXPECT_EQ(5, std::get<std::vector<uint8_t>>(readDefinedRecord->value_[ARRAY_BUFFER]).size());
3444 auto readDefinedRecord2 = std::get<std::shared_ptr<Object>>(entries->at("my.type"));
3445 EXPECT_EQ(5, std::get<std::vector<uint8_t>>(readDefinedRecord2->value_[ARRAY_BUFFER]).size());
3446 auto readForm = std::get<std::shared_ptr<Object>>(entries->at("openharmony.form"));
3447 EXPECT_EQ("module", std::get<std::string>(readForm->value_[MODULE]));
3448 auto readCotentForm = std::get<std::shared_ptr<Object>>(entries->at("general.content-form"));
3449 EXPECT_EQ("title", std::get<std::string>(readCotentForm->value_[TITLE]));
3450 LOG_INFO(UDMF_TEST, "GetSummary005 end.");
3451 }
3452
3453
3454 /**
3455 * @tc.name: FileUriCastTest001
3456 * @tc.desc: Cast file uri type record to verify works well
3457 * @tc.type: FUNC
3458 */
3459 HWTEST_F(UdmfClientTest, FileUriCastTest001, TestSize.Level1)
3460 {
3461 LOG_INFO(UDMF_TEST, "FileUriCastTest001 begin.");
3462 UnifiedData data;
3463 GetFileUriUnifiedData(data);
3464 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
3465 std::string key;
3466 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
3467 ASSERT_EQ(status, E_OK);
3468 QueryOption option2 = { .key = key };
3469 UnifiedData readData;
3470 status = UdmfClient::GetInstance().GetData(option2, readData);
3471 auto record0 = readData.GetRecordAt(0);
3472 auto fileValue = record0->GetValue();
3473 std::shared_ptr<Object> fileObj = std::get<std::shared_ptr<Object>>(fileValue);
3474 EXPECT_EQ(std::get<std::string>(fileObj->value_[FILE_URI_PARAM]), "http://demo.com");
3475 EXPECT_EQ(std::get<std::string>(fileObj->value_[FILE_TYPE]), "abcdefg");
3476 File *file = reinterpret_cast<File *>(record0.get());
3477 EXPECT_EQ(file->GetUri(), "http://demo.com");
3478 auto record1 = readData.GetRecordAt(1);
3479 auto imageValue = record1->GetValue();
3480 std::shared_ptr<Object> imageObj = std::get<std::shared_ptr<Object>>(imageValue);
3481 EXPECT_EQ(std::get<std::string>(imageObj->value_[FILE_URI_PARAM]), "http://demo.com");
3482 EXPECT_EQ(std::get<std::string>(imageObj->value_[FILE_TYPE]), "general.image");
3483 File *image = reinterpret_cast<Image *>(record1.get());
3484 EXPECT_EQ(image->GetUri(), "http://demo.com");
3485 auto record2 = readData.GetRecordAt(2);
3486 File *audio = reinterpret_cast<Audio *>(record2.get());
3487 EXPECT_EQ(audio->GetUri(), "http://demo.com");
3488 LOG_INFO(UDMF_TEST, "FileUriCastTest001 end.");
3489 }
3490
3491 /**
3492 * @tc.name: GetData002
3493 * @tc.desc: test Marshalling and Unmarshalling properties drag
3494 * @tc.type: FUNC
3495 */
3496 HWTEST_F(UdmfClientTest, GetData002, TestSize.Level1)
3497 {
3498 LOG_INFO(UDMF_TEST, "GetData002 begin.");
3499
3500 CustomOption option1 = { .intention = Intention::UD_INTENTION_DRAG };
3501 UnifiedData data;
3502 std::string key;
3503 auto record = std::make_shared<Html>("htmlContent", "plainContent");
3504 auto link = Link("url", "descritpion");
3505 link.InitObject();
3506 record->AddEntry(link.GetUtdId(), link.GetOriginValue());
3507 data.AddRecord(record);
3508 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
3509 std::string tag = "this is a tag of test GetData002";
3510 properties->tag = tag;
3511 properties->shareOptions = CROSS_APP;
3512 data.SetProperties(std::move(properties));
3513 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
3514 ASSERT_EQ(status, E_OK);
3515
3516 QueryOption option2 = { .key = key };
3517 UnifiedData readData;
3518 status = UdmfClient::GetInstance().GetData(option2, readData);
3519 ASSERT_EQ(status, E_OK);
3520 ASSERT_EQ(readData.GetRecords().size(), 1);
3521 auto readRecord = readData.GetRecordAt(0);
3522 ASSERT_NE(readRecord, nullptr);
3523 auto entries = readRecord->GetEntries();
3524 auto readHtml = std::get<std::shared_ptr<Object>>(entries->at("general.html"));
3525 EXPECT_EQ("htmlContent", std::get<std::string>(readHtml->value_[HTML_CONTENT]));
3526 auto readHyperlink = std::get<std::shared_ptr<Object>>(entries->at("general.hyperlink"));
3527 EXPECT_EQ("descritpion", std::get<std::string>(readHyperlink->value_[DESCRIPTION]));
3528 auto readProperties = readData.GetProperties();
3529 ASSERT_NE(readProperties, nullptr);
3530 EXPECT_EQ(readProperties->tag, tag);
3531 EXPECT_EQ(readProperties->shareOptions, CROSS_APP);
3532
3533 LOG_INFO(UDMF_TEST, "GetData002 end.");
3534 }
3535
3536 /**
3537 * @tc.name: GetBatchData001
3538 * @tc.desc: test Marshalling and Unmarshalling properties datahub
3539 * @tc.type: FUNC
3540 */
3541 HWTEST_F(UdmfClientTest, GetBatchData001, TestSize.Level1)
3542 {
3543 LOG_INFO(UDMF_TEST, "GetBatchData001 begin.");
3544
3545 QueryOption query = { .intention = Intention::UD_INTENTION_DATA_HUB };
3546 std::vector<UnifiedData> unifiedDataSet;
3547 auto status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
3548 ASSERT_EQ(status, E_OK);
3549 unifiedDataSet.clear();
3550 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3551 ASSERT_EQ(status, E_OK);
3552 ASSERT_TRUE(unifiedDataSet.empty());
3553
3554 CustomOption customOption = { .intention = Intention::UD_INTENTION_DATA_HUB };
3555 UnifiedData data;
3556 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
3557 data.AddRecord(record);
3558 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
3559 std::string tag = "this is a tag of test GetBatchData001";
3560 properties->tag = tag;
3561 properties->shareOptions = CROSS_APP;
3562 data.SetProperties(std::move(properties));
3563 std::string key;
3564 status = UdmfClient::GetInstance().SetData(customOption, data, key);
3565 ASSERT_EQ(status, E_OK);
3566 query = { .key = key, .intention = Intention::UD_INTENTION_DATA_HUB };
3567 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
3568 ASSERT_EQ(status, E_OK);
3569 ASSERT_EQ(unifiedDataSet.size(), 1);
3570 auto record2 = unifiedDataSet[0].GetRecordAt(0);
3571 ValueType value = record2->GetValue();
3572 ASSERT_NE(std::get_if<std::string>(&value), nullptr);
3573 EXPECT_EQ(std::get<std::string>(value), "plainTextContent");
3574 auto readProperties = unifiedDataSet[0].GetProperties();
3575 ASSERT_NE(readProperties, nullptr);
3576 EXPECT_EQ(readProperties->tag, tag);
3577 EXPECT_EQ(readProperties->shareOptions, CROSS_APP);
3578
3579 LOG_INFO(UDMF_TEST, "GetBatchData001 end.");
3580 }
3581 } // OHOS::Test