1 /*
2 * Copyright (c) 2025 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 "UdmfClientFileMangerTest"
16 #include <gtest/gtest.h>
17 #include <unistd.h>
18 #include <thread>
19 #include <chrono>
20
21 #include "token_setproc.h"
22 #include "accesstoken_kit.h"
23 #include "directory_ex.h"
24 #include "nativetoken_kit.h"
25
26 #include "logger.h"
27 #include "udmf_client.h"
28 #include "application_defined_record.h"
29 #include "audio.h"
30 #include "file.h"
31 #include "folder.h"
32 #include "html.h"
33 #include "image.h"
34 #include "link.h"
35 #include "plain_text.h"
36 #include "system_defined_appitem.h"
37 #include "system_defined_form.h"
38 #include "system_defined_pixelmap.h"
39 #include "system_defined_record.h"
40 #include "text.h"
41 #include "unified_data_helper.h"
42 #include "unified_html_record_process.h"
43 #include "video.h"
44
45 using namespace testing::ext;
46 using namespace OHOS::Security::AccessToken;
47 using namespace OHOS::UDMF;
48 using namespace OHOS;
49 namespace OHOS::Test {
50 class UdmfClientFileMangerTest : public testing::Test {
51 public:
52 static void SetUpTestCase();
53 static void TearDownTestCase();
54 void SetUp() override;
55 void TearDown() override;
56
57 void SetNativeToken(const std::string &processName);
58 static void AllocHapToken1();
59 static void AllocHapToken2();
60 void SetHapToken1();
61 void SetHapToken2();
62
63 void AddPrivilege(QueryOption &option);
64 void AddPrivilege1(QueryOption &option);
65 int64_t CountTime();
66
67 static constexpr int userId = 100;
68 static constexpr int instIndex = 0;
69 };
70
SetUpTestCase()71 void UdmfClientFileMangerTest::SetUpTestCase()
72 {
73 AllocHapToken1();
74 AllocHapToken2();
75 }
76
TearDownTestCase()77 void UdmfClientFileMangerTest::TearDownTestCase()
78 {
79 auto tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo1", instIndex);
80 AccessTokenKit::DeleteToken(tokenId);
81 tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
82 AccessTokenKit::DeleteToken(tokenId);
83 }
84
SetUp()85 void UdmfClientFileMangerTest::SetUp()
86 {
87 SetHapToken1();
88 }
89
TearDown()90 void UdmfClientFileMangerTest::TearDown()
91 {
92 QueryOption query = { .intention = Intention::UD_INTENTION_PICKER };
93 std::vector<UnifiedData> unifiedDataSet;
94 UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
95 query = { .intention = Intention::UD_INTENTION_MENU };
96 UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
97 query = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
98 UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
99 }
100
SetNativeToken(const std::string & processName)101 void UdmfClientFileMangerTest::SetNativeToken(const std::string &processName)
102 {
103 auto tokenId = AccessTokenKit::GetNativeTokenId(processName);
104 SetSelfTokenID(tokenId);
105 }
106
AllocHapToken1()107 void UdmfClientFileMangerTest::AllocHapToken1()
108 {
109 HapInfoParams info = {
110 .userID = userId,
111 .bundleName = "ohos.file.manger.test.demo1",
112 .instIndex = instIndex,
113 .appIDDesc = "ohos.file.manger.test.demo1"
114 };
115
116 HapPolicyParams policy = {
117 .apl = APL_NORMAL,
118 .domain = "test.domain",
119 .permList = {
120 {
121 .permissionName = "ohos.permission.test",
122 .bundleName = "ohos.file.manger.test.demo1",
123 .grantMode = 1,
124 .availableLevel = APL_NORMAL,
125 .label = "label",
126 .labelId = 1,
127 .description = "test1",
128 .descriptionId = 1
129 }
130 },
131 .permStateList = {
132 {
133 .permissionName = "ohos.permission.test",
134 .isGeneral = true,
135 .resDeviceID = { "local" },
136 .grantStatus = { PermissionState::PERMISSION_GRANTED },
137 .grantFlags = { 1 }
138 }
139 }
140 };
141 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
142 SetSelfTokenID(tokenID.tokenIDEx);
143 }
144
AllocHapToken2()145 void UdmfClientFileMangerTest::AllocHapToken2()
146 {
147 HapInfoParams info = {
148 .userID = userId,
149 .bundleName = "ohos.file.manger.test.demo2",
150 .instIndex = instIndex,
151 .appIDDesc = "ohos.file.manger.test.demo2"
152 };
153
154 HapPolicyParams policy = {
155 .apl = APL_NORMAL,
156 .domain = "test.domain",
157 .permList = {
158 {
159 .permissionName = "ohos.permission.test",
160 .bundleName = "ohos.file.manger.test.demo2",
161 .grantMode = 1,
162 .availableLevel = APL_NORMAL,
163 .label = "label",
164 .labelId = 1,
165 .description = "test2",
166 .descriptionId = 1
167 }
168 },
169 .permStateList = {
170 {
171 .permissionName = "ohos.permission.test",
172 .isGeneral = true,
173 .resDeviceID = { "local" },
174 .grantStatus = { PermissionState::PERMISSION_GRANTED },
175 .grantFlags = { 1 }
176 }
177 }
178 };
179 auto tokenID = AccessTokenKit::AllocHapToken(info, policy);
180 SetSelfTokenID(tokenID.tokenIDEx);
181 }
182
SetHapToken1()183 void UdmfClientFileMangerTest::SetHapToken1()
184 {
185 auto tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo1", instIndex);
186 SetSelfTokenID(tokenId);
187 }
188
SetHapToken2()189 void UdmfClientFileMangerTest::SetHapToken2()
190 {
191 auto tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
192 SetSelfTokenID(tokenId);
193 }
194
AddPrivilege(QueryOption & option)195 void UdmfClientFileMangerTest::AddPrivilege(QueryOption &option)
196 {
197 Privilege privilege;
198 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
199 privilege.readPermission = "readAndKeep";
200 privilege.writePermission = "writePermission";
201 SetNativeToken("foundation");
202
203 auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
204 ASSERT_EQ(status, E_OK);
205 }
206
AddPrivilege1(QueryOption & option)207 void UdmfClientFileMangerTest::AddPrivilege1(QueryOption &option)
208 {
209 Privilege privilege;
210 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo1", instIndex);
211 privilege.readPermission = "readpermission";
212 privilege.writePermission = "writePermission";
213 SetNativeToken("foundation");
214 auto status = UdmfClient::GetInstance().AddPrivilege(option, privilege);
215 ASSERT_EQ(status, E_OK);
216 }
217
CountTime()218 int64_t UdmfClientFileMangerTest::CountTime()
219 {
220 return std::chrono::duration_cast<std::chrono::milliseconds>(
221 std::chrono::system_clock::now().time_since_epoch()).count();
222 }
223
224 /**
225 * @tc.name: SetData001
226 * @tc.desc: Set data with invalid params
227 * @tc.type: FUNC
228 */
229 HWTEST_F(UdmfClientFileMangerTest, SetData001, TestSize.Level1)
230 {
231 LOG_INFO(UDMF_TEST, "SetData001 begin.");
232
233 CustomOption option = { .intention = Intention::UD_INTENTION_PICKER };
234 UnifiedData data;
235 std::string key;
236 auto status = UdmfClient::GetInstance().SetData(option, data, key);
237 EXPECT_EQ(status, E_INVALID_PARAMETERS);
238
239 option = {};
240 status = UdmfClient::GetInstance().SetData(option, data, key);
241 EXPECT_EQ(status, E_INVALID_PARAMETERS);
242
243 option = { .intention = Intention::UD_INTENTION_BASE };
244 status = UdmfClient::GetInstance().SetData(option, data, key);
245 EXPECT_EQ(status, E_INVALID_PARAMETERS);
246 LOG_INFO(UDMF_TEST, "SetData001 end.");
247 }
248
249 /**
250 * @tc.name: SetData002
251 * @tc.desc: Set data with valid params UD_INTENTION_PICKER
252 * @tc.type: FUNC
253 */
254 HWTEST_F(UdmfClientFileMangerTest, SetData002, TestSize.Level1)
255 {
256 LOG_INFO(UDMF_TEST, "SetData002 begin.");
257 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
258 UnifiedData inputData;
259 std::string keyTest;
260 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
261
262 std::string uri = "file://file_11.txt";
263 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
264 inputData.SetRecords(inputRecords);
265 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
266 ASSERT_EQ(status, E_OK);
267
268 QueryOption query = { .key = keyTest };
269 std::vector<UnifiedData> unifiedDataSet;
270 SetHapToken2();
271 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
272 EXPECT_EQ(status, E_NO_PERMISSION);
273
274 AddPrivilege(query);
275 SetHapToken2();
276 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
277 EXPECT_EQ(status, E_OK);
278 query.intention = Intention::UD_INTENTION_PICKER;
279 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
280 EXPECT_EQ(status, E_OK);
281 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
282 ASSERT_EQ(status, E_OK);
283 LOG_INFO(UDMF_TEST, "SetData002 end.");
284 }
285
286 /**
287 * @tc.name: SetData003
288 * @tc.desc: Set data with invalid params UD_INTENTION_PICKER
289 * @tc.type: FUNC
290 */
291 HWTEST_F(UdmfClientFileMangerTest, SetData003, TestSize.Level1)
292 {
293 LOG_INFO(UDMF_TEST, "SetData003 begin.");
294 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
295 UnifiedData inputData;
296 std::string keyTest;
297 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
298 std::string uri = "file://file_11.txt";
299 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
300 inputData.SetRecords(inputRecords);
301 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
302 ASSERT_EQ(status, E_OK);
303
304 QueryOption query = { .key = keyTest };
305 std::vector<UnifiedData> unifiedDataSet;
306 SetHapToken2();
307 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
308 EXPECT_EQ(status, E_NO_PERMISSION);
309 AddPrivilege(query);
310 SetHapToken2();
311 query.intention = Intention::UD_INTENTION_DATA_HUB;
312 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
313 ASSERT_EQ(status, E_INVALID_PARAMETERS);
314
315 QueryOption query1;
316 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
317 ASSERT_EQ(status, E_INVALID_PARAMETERS);
318 query1.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
319 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
320 ASSERT_EQ(status, E_INVALID_PARAMETERS);
321 query1.intention = Intention::UD_INTENTION_PICKER;
322 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
323 ASSERT_EQ(status, E_INVALID_PARAMETERS);
324
325 query.intention = Intention::UD_INTENTION_PICKER;
326 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
327 ASSERT_EQ(status, E_OK);
328 LOG_INFO(UDMF_TEST, "SetData003 end.");
329 }
330
331 /**
332 * @tc.name: SetData004
333 * @tc.desc: Set data with invalid params UD_INTENTION_PICKER
334 * @tc.type: FUNC
335 */
336 HWTEST_F(UdmfClientFileMangerTest, SetData004, TestSize.Level1)
337 {
338 LOG_INFO(UDMF_TEST, "SetData004 begin.");
339 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
340 UnifiedData inputData;
341 std::string keyTest;
342 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
343 std::string uri = "file://file_11.txt";
344 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
345 inputData.SetRecords(inputRecords);
346 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
347 ASSERT_EQ(status, E_OK);
348
349 QueryOption query = { .key = keyTest };
350 std::vector<UnifiedData> unifiedDataSet;
351 SetHapToken2();
352 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
353 EXPECT_EQ(status, E_NO_PERMISSION);
354 AddPrivilege(query);
355 SetHapToken2();
356
357 QueryOption query1;
358 query1.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
359 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
360 ASSERT_EQ(status, E_INVALID_PARAMETERS);
361 query1.intention = Intention::UD_INTENTION_DATA_HUB;
362 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
363 ASSERT_EQ(status, E_INVALID_PARAMETERS);
364 query1.intention = Intention::UD_INTENTION_PICKER;
365 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
366 ASSERT_EQ(status, E_INVALID_PARAMETERS);
367
368 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
369 ASSERT_EQ(status, E_OK);
370 LOG_INFO(UDMF_TEST, "SetData003 end.");
371 }
372
373 /**
374 * @tc.name: SetData005
375 * @tc.desc: one over 2MB record UD_INTENTION_PICKER
376 * @tc.type: FUNC
377 */
378 HWTEST_F(UdmfClientFileMangerTest, SetData005, TestSize.Level1)
379 {
380 LOG_INFO(UDMF_TEST, "SetData005 begin.");
381 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
382 UnifiedData inputData;
383 std::string key;
384 UDDetails details;
385 std::string value;
386 int64_t maxSize = 512 * 1024;
387 for (int64_t i = 0; i < maxSize; ++i) {
388 value += "11";
389 }
390 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
391 std::string fileName = "file_" + value + ".txt";
392 std::string uri = "file://" + fileName;
393 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
394 inputData.SetRecords(inputRecords);
395 int64_t start = CountTime();
396 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
397 int64_t end = CountTime();
398 LOG_INFO(UDMF_TEST, "picker setdata 1000 cost timet:%{public}" PRIi64, (end - start));
399 ASSERT_EQ(status, E_OK);
400
401 QueryOption query = { .key = key };
402 std::vector<UnifiedData> unifiedDataSet;
403 SetHapToken2();
404 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
405 EXPECT_EQ(status, E_NO_PERMISSION);
406
407 AddPrivilege(query);
408 SetHapToken2();
409 start = CountTime();
410 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
411 end = CountTime();
412 LOG_INFO(UDMF_TEST, "picker getdata 2MB record cost timet:%{public}" PRIi64, (end - start));
413 ASSERT_EQ(status, E_OK);
414 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
415 ASSERT_EQ(status, E_OK);
416 LOG_INFO(UDMF_TEST, "SetData005 end.");
417 }
418
419 /**
420 * @tc.name: SetData006
421 * @tc.desc: two 2MB record UD_INTENTION_PICKER
422 * @tc.type: FUNC
423 */
424 HWTEST_F(UdmfClientFileMangerTest, SetData006, TestSize.Level1)
425 {
426 LOG_INFO(UDMF_TEST, "SetData006 begin.");
427
428 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
429 std::string key;
430 std::string value;
431 UnifiedData inputData;
432 int64_t maxSize = 512 * 1024;
433 for (int64_t i = 0; i < maxSize; ++i) {
434 value += "11";
435 }
436 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
437 std::string uri = "file://file_" + value + ".txt";
438 for (int i = 0; i < 2; ++i) {
439 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
440 }
441 inputData.SetRecords(inputRecords);
442
443 int64_t start = CountTime();
444 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
445 int64_t end = CountTime();
446 LOG_INFO(UDMF_TEST, "picker setdata two 2MB record cost timet:%{public}" PRIi64, (end - start));
447 ASSERT_EQ(status, E_OK);
448
449 QueryOption query = { .key = key };
450 std::vector<UnifiedData> unifiedDataSet;
451 SetHapToken2();
452 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
453 EXPECT_EQ(status, E_NO_PERMISSION);
454
455 AddPrivilege(query);
456 SetHapToken2();
457 start = CountTime();
458 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
459 end = CountTime();
460 LOG_INFO(UDMF_TEST, "picker getdata two 2MB record cost timet:%{public}" PRIi64, (end - start));
461 ASSERT_EQ(status, E_OK);
462 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
463 ASSERT_EQ(status, E_OK);
464 LOG_INFO(UDMF_TEST, "SetData006 end.");
465 }
466
467 /**
468 * @tc.name: SetData007
469 * @tc.desc: Set multiple record with valid params and get data
470 * @tc.type: FUNC
471 */
472 HWTEST_F(UdmfClientFileMangerTest, SetData007, TestSize.Level1)
473 {
474 LOG_INFO(UDMF_TEST, "SetData007 begin.");
475
476 CustomOption customOption = {.intention = Intention::UD_INTENTION_PICKER};
477 std::string key;
478 UnifiedData inputData;
479 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords = {
480 std::make_shared<Text>(),
481 std::make_shared<PlainText>(),
482 std::make_shared<File>(),
483 std::make_shared<Image>(),
484 std::make_shared<SystemDefinedRecord>(),
485 std::make_shared<SystemDefinedForm>(),
486 std::make_shared<ApplicationDefinedRecord>()
487 };
488 inputData.SetRecords(inputRecords);
489
490 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
491 ASSERT_EQ(status, E_OK);
492
493 QueryOption query = { .key = key };
494 std::vector<UnifiedData> unifiedDataSet;
495 SetHapToken2();
496 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
497 EXPECT_EQ(status, E_NO_PERMISSION);
498
499 AddPrivilege(query);
500 SetHapToken2();
501
502 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
503 ASSERT_EQ(status, E_OK);
504 auto outputRecords = unifiedDataSet[0].GetRecords();
505 ASSERT_EQ(inputRecords.size(), outputRecords.size());
506 for (size_t i = 0; i < outputRecords.size(); ++i) {
507 ASSERT_EQ(outputRecords[i]->GetType(), inputRecords[i]->GetType());
508 }
509 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
510 ASSERT_EQ(status, E_OK);
511 LOG_INFO(UDMF_TEST, "SetData007 end.");
512 }
513
514 /**
515 * @tc.name: SetData008
516 * @tc.desc: Set data with invalid params
517 * @tc.type: FUNC
518 */
519 HWTEST_F(UdmfClientFileMangerTest, SetData008, TestSize.Level1)
520 {
521 LOG_INFO(UDMF_TEST, "SetData008 begin.");
522 CustomOption option = { .intention = Intention::UD_INTENTION_MENU };
523 UnifiedData data;
524 std::string key;
525 auto status = UdmfClient::GetInstance().SetData(option, data, key);
526 EXPECT_EQ(status, E_INVALID_PARAMETERS);
527
528 option = {};
529 status = UdmfClient::GetInstance().SetData(option, data, key);
530 EXPECT_EQ(status, E_INVALID_PARAMETERS);
531
532 option = { .intention = Intention::UD_INTENTION_BASE };
533 status = UdmfClient::GetInstance().SetData(option, data, key);
534 EXPECT_EQ(status, E_INVALID_PARAMETERS);
535 LOG_INFO(UDMF_TEST, "SetData008 end.");
536 }
537
538 /**
539 * @tc.name: SetData009
540 * @tc.desc: Set data with valid params UD_INTENTION_MENU
541 * @tc.type: FUNC
542 */
543 HWTEST_F(UdmfClientFileMangerTest, SetData009, TestSize.Level1)
544 {
545 LOG_INFO(UDMF_TEST, "SetData009 begin.");
546 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
547 UnifiedData inputData;
548 std::string keyTest;
549 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
550
551 std::string uri = "file://file_11.txt";
552 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
553 inputData.SetRecords(inputRecords);
554 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
555 ASSERT_EQ(status, E_OK);
556
557 QueryOption query = { .key = keyTest };
558 std::vector<UnifiedData> unifiedDataSet;
559 SetHapToken2();
560 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
561 EXPECT_EQ(status, E_NO_PERMISSION);
562
563 AddPrivilege(query);
564 SetHapToken2();
565
566 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
567 EXPECT_EQ(status, E_OK);
568
569 query.intention = Intention::UD_INTENTION_MENU;
570 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
571 EXPECT_EQ(status, E_OK);
572 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
573 ASSERT_EQ(status, E_OK);
574 LOG_INFO(UDMF_TEST, "SetData009 end.");
575 }
576
577 /**
578 * @tc.name: SetData010
579 * @tc.desc: Set data with invalid params UD_INTENTION_MENU
580 * @tc.type: FUNC
581 */
582 HWTEST_F(UdmfClientFileMangerTest, SetData010, TestSize.Level1)
583 {
584 LOG_INFO(UDMF_TEST, "SetData010 begin.");
585 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
586 UnifiedData inputData;
587 std::string keyTest;
588 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
589 std::string uri = "file://file_11.txt";
590 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
591 inputData.SetRecords(inputRecords);
592 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
593 ASSERT_EQ(status, E_OK);
594
595 QueryOption query = { .key = keyTest };
596 std::vector<UnifiedData> unifiedDataSet;
597 SetHapToken2();
598 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
599 EXPECT_EQ(status, E_NO_PERMISSION);
600 AddPrivilege(query);
601 SetHapToken2();
602 query.intention = Intention::UD_INTENTION_DATA_HUB;
603 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
604 ASSERT_EQ(status, E_INVALID_PARAMETERS);
605
606 QueryOption query1;
607 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
608 ASSERT_EQ(status, E_INVALID_PARAMETERS);
609 query1.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
610 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
611 ASSERT_EQ(status, E_INVALID_PARAMETERS);
612 query1.intention = Intention::UD_INTENTION_MENU;
613 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
614 ASSERT_EQ(status, E_INVALID_PARAMETERS);
615
616 query.intention = Intention::UD_INTENTION_MENU;
617 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
618 ASSERT_EQ(status, E_OK);
619 LOG_INFO(UDMF_TEST, "SetData010 end.");
620 }
621
622 /**
623 * @tc.name: SetData011
624 * @tc.desc: Set data with invalid params UD_INTENTION_MENU
625 * @tc.type: FUNC
626 */
627 HWTEST_F(UdmfClientFileMangerTest, SetData011, TestSize.Level1)
628 {
629 LOG_INFO(UDMF_TEST, "SetData011 begin.");
630 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
631 UnifiedData inputData;
632 std::string keyTest;
633 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
634 std::string uri = "file://file_11.txt";
635 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
636 inputData.SetRecords(inputRecords);
637 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
638 ASSERT_EQ(status, E_OK);
639
640 QueryOption query = { .key = keyTest };
641 std::vector<UnifiedData> unifiedDataSet;
642 SetHapToken2();
643 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
644 EXPECT_EQ(status, E_NO_PERMISSION);
645 AddPrivilege(query);
646 SetHapToken2();
647
648 QueryOption query1;
649 query1.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
650 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
651 ASSERT_EQ(status, E_INVALID_PARAMETERS);
652 query1.intention = Intention::UD_INTENTION_DATA_HUB;
653 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
654 ASSERT_EQ(status, E_INVALID_PARAMETERS);
655 query1.intention = Intention::UD_INTENTION_MENU;
656 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
657 ASSERT_EQ(status, E_INVALID_PARAMETERS);
658
659 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
660 ASSERT_EQ(status, E_OK);
661 LOG_INFO(UDMF_TEST, "SetData011 end.");
662 }
663
664 /**
665 * @tc.name: SetData012
666 * @tc.desc: one over 2MB record UD_INTENTION_MENU
667 * @tc.type: FUNC
668 */
669 HWTEST_F(UdmfClientFileMangerTest, SetData012, TestSize.Level1)
670 {
671 LOG_INFO(UDMF_TEST, "SetData012 begin.");
672
673 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
674 UnifiedData inputData;
675 std::string key;
676 UDDetails details;
677 std::string value;
678 int64_t maxSize = 512 * 1024;
679 for (int64_t i = 0; i < maxSize; ++i) {
680 value += "11";
681 }
682 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
683 std::string fileName = "file_" + value + ".txt";
684 std::string uri = "file://" + fileName;
685 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
686 inputData.SetRecords(inputRecords);
687
688 int64_t start = CountTime();
689 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
690 int64_t end = CountTime();
691 LOG_INFO(UDMF_TEST, "rightclick setdata 2MB record cost timet:%{public}" PRIi64, (end - start));
692 ASSERT_EQ(status, E_OK);
693
694 QueryOption query = { .key = key };
695 std::vector<UnifiedData> unifiedDataSet;
696 SetHapToken2();
697 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
698 EXPECT_EQ(status, E_NO_PERMISSION);
699
700 AddPrivilege(query);
701 SetHapToken2();
702
703 start = CountTime();
704 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
705 end = CountTime();
706 LOG_INFO(UDMF_TEST, "rightclick getdata 2MB record cost timet:%{public}" PRIi64, (end - start));
707 ASSERT_EQ(status, E_OK);
708 UnifiedDataHelper::SetRootPath("");
709 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
710 ASSERT_EQ(status, E_OK);
711 LOG_INFO(UDMF_TEST, "SetData012 end.");
712 }
713
714 /**
715 * @tc.name: SetData013
716 * @tc.desc: two 2MB record UD_INTENTION_MENU
717 * @tc.type: FUNC
718 */
719 HWTEST_F(UdmfClientFileMangerTest, SetData013, TestSize.Level1)
720 {
721 LOG_INFO(UDMF_TEST, "SetData013 begin.");
722
723 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
724 UnifiedData inputData;
725 std::string key;
726 UDDetails details;
727 std::string value;
728 int64_t maxSize = 512 * 1024;
729 for (int64_t i = 0; i < maxSize; ++i) {
730 value += "11";
731 }
732 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
733 std::string uri = "file://file_" + value + ".txt";
734 for (int i = 0; i < 2; ++i) {
735 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
736 }
737 inputData.SetRecords(inputRecords);
738
739 int64_t start = CountTime();
740 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
741 int64_t end = CountTime();
742 LOG_INFO(UDMF_TEST, "setdata 4MB cost timet:%{public}" PRIi64, (end - start));
743 ASSERT_EQ(status, E_OK);
744
745 QueryOption query = { .key = key };
746 std::vector<UnifiedData> unifiedDataSet;
747 SetHapToken2();
748 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
749 EXPECT_EQ(status, E_NO_PERMISSION);
750
751 AddPrivilege(query);
752 SetHapToken2();
753
754 start = CountTime();
755 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
756 end = CountTime();
757 LOG_INFO(UDMF_TEST, "getdata 4MB cost timet:%{public}" PRIi64, (end - start));
758 ASSERT_EQ(status, E_OK);
759 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
760 ASSERT_EQ(status, E_OK);
761 LOG_INFO(UDMF_TEST, "SetData013 end.");
762 }
763
764 /**
765 * @tc.name: SetData014
766 * @tc.desc: Set multiple record with valid params and get data
767 * @tc.type: FUNC
768 */
769 HWTEST_F(UdmfClientFileMangerTest, SetData014, TestSize.Level1)
770 {
771 LOG_INFO(UDMF_TEST, "SetData014 begin.");
772
773 CustomOption customOption = {.intention = Intention::UD_INTENTION_MENU};
774 std::string key;
775 UnifiedData inputData;
776 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords = {
777 std::make_shared<Text>(),
778 std::make_shared<PlainText>(),
779 std::make_shared<File>(),
780 std::make_shared<Image>(),
781 std::make_shared<SystemDefinedRecord>(),
782 std::make_shared<SystemDefinedForm>(),
783 std::make_shared<ApplicationDefinedRecord>()
784 };
785 inputData.SetRecords(inputRecords);
786
787 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
788 ASSERT_EQ(status, E_OK);
789
790 QueryOption query = { .key = key };
791 std::vector<UnifiedData> unifiedDataSet;
792 SetHapToken2();
793 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
794 EXPECT_EQ(status, E_NO_PERMISSION);
795
796 AddPrivilege(query);
797 SetHapToken2();
798
799 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
800 ASSERT_EQ(status, E_OK);
801 auto outputRecords = unifiedDataSet[0].GetRecords();
802 ASSERT_EQ(inputRecords.size(), outputRecords.size());
803 for (size_t i = 0; i < outputRecords.size(); ++i) {
804 ASSERT_EQ(outputRecords[i]->GetType(), inputRecords[i]->GetType());
805 }
806 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
807 ASSERT_EQ(status, E_OK);
808 LOG_INFO(UDMF_TEST, "SetData014 end.");
809 }
810
811 /**
812 * @tc.name: SetData015
813 * @tc.desc: Set data with invalid params
814 * @tc.type: FUNC
815 */
816 HWTEST_F(UdmfClientFileMangerTest, SetData015, TestSize.Level1)
817 {
818 LOG_INFO(UDMF_TEST, "SetData015 begin.");
819
820 CustomOption option = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
821 UnifiedData data;
822 std::string key;
823 auto status = UdmfClient::GetInstance().SetData(option, data, key);
824 EXPECT_EQ(status, E_INVALID_PARAMETERS);
825
826 option = {};
827 status = UdmfClient::GetInstance().SetData(option, data, key);
828 EXPECT_EQ(status, E_INVALID_PARAMETERS);
829
830 option = { .intention = Intention::UD_INTENTION_BASE };
831 status = UdmfClient::GetInstance().SetData(option, data, key);
832 EXPECT_EQ(status, E_INVALID_PARAMETERS);
833 LOG_INFO(UDMF_TEST, "SetData015 end.");
834 }
835
836 /**
837 * @tc.name: SetData016
838 * @tc.desc: Set data with valid params UD_INTENTION_SYSTEM_SHARE
839 * @tc.type: FUNC
840 */
841 HWTEST_F(UdmfClientFileMangerTest, SetData016, TestSize.Level1)
842 {
843 LOG_INFO(UDMF_TEST, "SetData016 begin.");
844 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
845 UnifiedData inputData;
846 std::string keyTest;
847 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
848
849 std::string uri = "file://file_11.txt";
850 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
851 inputData.SetRecords(inputRecords);
852 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
853 ASSERT_EQ(status, E_OK);
854
855 QueryOption query = { .key = keyTest };
856 std::vector<UnifiedData> unifiedDataSet;
857 SetHapToken2();
858 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
859 EXPECT_EQ(status, E_NO_PERMISSION);
860
861 AddPrivilege(query);
862 SetHapToken2();
863
864 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
865 EXPECT_EQ(status, E_OK);
866
867 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
868 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
869 EXPECT_EQ(status, E_OK);
870 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
871 ASSERT_EQ(status, E_OK);
872 LOG_INFO(UDMF_TEST, "SetData016 end.");
873 }
874
875 /**
876 * @tc.name: SetData017
877 * @tc.desc: Set data with invalid params UD_INTENTION_SYSTEM_SHARE
878 * @tc.type: FUNC
879 */
880 HWTEST_F(UdmfClientFileMangerTest, SetData017, TestSize.Level1)
881 {
882 LOG_INFO(UDMF_TEST, "SetData017 begin.");
883 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
884 UnifiedData inputData;
885 std::string keyTest;
886 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
887 std::string uri = "file://file_11.txt";
888 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
889 inputData.SetRecords(inputRecords);
890 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
891 ASSERT_EQ(status, E_OK);
892
893 QueryOption query = { .key = keyTest };
894 std::vector<UnifiedData> unifiedDataSet;
895 SetHapToken2();
896 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
897 EXPECT_EQ(status, E_NO_PERMISSION);
898 AddPrivilege(query);
899 SetHapToken2();
900 query.intention = Intention::UD_INTENTION_DATA_HUB;
901 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
902 ASSERT_EQ(status, E_INVALID_PARAMETERS);
903
904 QueryOption query1;
905 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
906 ASSERT_EQ(status, E_INVALID_PARAMETERS);
907 query1.intention = Intention::UD_INTENTION_MENU;
908 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
909 ASSERT_EQ(status, E_INVALID_PARAMETERS);
910 query1.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
911 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
912 ASSERT_EQ(status, E_INVALID_PARAMETERS);
913
914 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
915 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
916 ASSERT_EQ(status, E_OK);
917 LOG_INFO(UDMF_TEST, "SetData017 end.");
918 }
919
920 /**
921 * @tc.name: SetData018
922 * @tc.desc: Set data with invalid params UD_INTENTION_SYSTEM_SHARE
923 * @tc.type: FUNC
924 */
925 HWTEST_F(UdmfClientFileMangerTest, SetData018, TestSize.Level1)
926 {
927 LOG_INFO(UDMF_TEST, "SetData018 begin.");
928 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
929 UnifiedData inputData;
930 std::string keyTest;
931 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
932 std::string uri = "file://file_11.txt";
933 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
934 inputData.SetRecords(inputRecords);
935 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, keyTest);
936 ASSERT_EQ(status, E_OK);
937
938 QueryOption query = { .key = keyTest };
939 std::vector<UnifiedData> unifiedDataSet;
940 SetHapToken2();
941 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
942 EXPECT_EQ(status, E_NO_PERMISSION);
943 AddPrivilege(query);
944 SetHapToken2();
945
946 QueryOption query1;
947 query1.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
948 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
949 ASSERT_EQ(status, E_INVALID_PARAMETERS);
950 query1.intention = Intention::UD_INTENTION_DATA_HUB;
951 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
952 ASSERT_EQ(status, E_INVALID_PARAMETERS);
953 query1.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
954 status = UdmfClient::GetInstance().GetBatchData(query1, unifiedDataSet);
955 ASSERT_EQ(status, E_INVALID_PARAMETERS);
956 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
957 ASSERT_EQ(status, E_OK);
958 LOG_INFO(UDMF_TEST, "SetData018 end.");
959 }
960
961 /**
962 * @tc.name: SetData019
963 * @tc.desc: one over 2MB record UD_INTENTION_SYSTEM_SHARE
964 * @tc.type: FUNC
965 */
966 HWTEST_F(UdmfClientFileMangerTest, SetData019, TestSize.Level1)
967 {
968 LOG_INFO(UDMF_TEST, "SetData019 begin.");
969
970 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
971 UnifiedData inputData;
972 std::string key;
973 UDDetails details;
974 std::string value;
975 int64_t maxSize = 512 * 1024;
976 for (int64_t i = 0; i < maxSize; ++i) {
977 value += "11";
978 }
979 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
980 std::string fileName = "file_" + value + ".txt";
981 std::string uri = "file://" + fileName;
982 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
983 inputData.SetRecords(inputRecords);
984
985 int64_t start = CountTime();
986 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
987 int64_t end = CountTime();
988 LOG_INFO(UDMF_TEST, "systemshare setdata one over 2MB record cost timet:%{public}" PRIi64, (end - start));
989 ASSERT_EQ(status, E_OK);
990
991 QueryOption query = { .key = key };
992 std::vector<UnifiedData> unifiedDataSet;
993 SetHapToken2();
994 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
995 EXPECT_EQ(status, E_NO_PERMISSION);
996
997 AddPrivilege(query);
998 SetHapToken2();
999
1000 start = CountTime();
1001 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1002 end = CountTime();
1003 LOG_INFO(UDMF_TEST, "systemshare getdata one over 2MB record cost timet:%{public}" PRIi64, (end - start));
1004 ASSERT_EQ(status, E_OK);
1005 UnifiedDataHelper::SetRootPath("");
1006 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1007 ASSERT_EQ(status, E_OK);
1008 LOG_INFO(UDMF_TEST, "SetData019 end.");
1009 }
1010
1011 /**
1012 * @tc.name: SetData020
1013 * @tc.desc: two 2MB record UD_INTENTION_SYSTEM_SHARE
1014 * @tc.type: FUNC
1015 */
1016 HWTEST_F(UdmfClientFileMangerTest, SetData020, TestSize.Level1)
1017 {
1018 LOG_INFO(UDMF_TEST, "SetData020 begin.");
1019
1020 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1021 UnifiedData inputData;
1022 std::string key;
1023 UDDetails details;
1024 std::string value;
1025 int64_t maxSize = 512 * 1024;
1026 for (int64_t i = 0; i < maxSize; ++i) {
1027 value += "11";
1028 }
1029 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords;
1030 std::string uri = "file://file_" + value + ".txt";
1031 for (int i = 0; i < 2; ++i) {
1032 inputRecords.emplace_back(std::make_shared<File>(UDType::FILE, "this is a oriUri"+uri));
1033 }
1034 inputData.SetRecords(inputRecords);
1035
1036 int64_t start = CountTime();
1037 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1038 int64_t end = CountTime();
1039 LOG_INFO(UDMF_TEST, "getdata 1 cost timet:%{public}" PRIi64, (end - start));
1040 ASSERT_EQ(status, E_OK);
1041
1042 QueryOption query = { .key = key };
1043 std::vector<UnifiedData> unifiedDataSet;
1044 SetHapToken2();
1045 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1046 EXPECT_EQ(status, E_NO_PERMISSION);
1047
1048 AddPrivilege(query);
1049 SetHapToken2();
1050
1051 start = CountTime();
1052 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1053 end = CountTime();
1054 LOG_INFO(UDMF_TEST, "getdata 1 cost timet:%{public}" PRIi64, (end - start));
1055 ASSERT_EQ(status, E_OK);
1056 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1057 ASSERT_EQ(status, E_OK);
1058
1059 LOG_INFO(UDMF_TEST, "SetData020 end.");
1060 }
1061
1062 /**
1063 * @tc.name: SetData021
1064 * @tc.desc: Set multiple record with valid params and get data
1065 * @tc.type: FUNC
1066 */
1067 HWTEST_F(UdmfClientFileMangerTest, SetData021, TestSize.Level1)
1068 {
1069 LOG_INFO(UDMF_TEST, "SetData021 begin.");
1070
1071 CustomOption customOption = {.intention = Intention::UD_INTENTION_SYSTEM_SHARE};
1072 std::string key;
1073 UnifiedData inputData;
1074 std::vector<std::shared_ptr<UnifiedRecord>> inputRecords = {
1075 std::make_shared<Text>(),
1076 std::make_shared<PlainText>(),
1077 std::make_shared<File>(),
1078 std::make_shared<Image>(),
1079 std::make_shared<SystemDefinedRecord>(),
1080 std::make_shared<SystemDefinedForm>(),
1081 std::make_shared<ApplicationDefinedRecord>()
1082 };
1083 inputData.SetRecords(inputRecords);
1084
1085 auto status = UdmfClient::GetInstance().SetData(customOption, inputData, key);
1086 ASSERT_EQ(status, E_OK);
1087
1088 QueryOption query = { .key = key };
1089 std::vector<UnifiedData> unifiedDataSet;
1090 SetHapToken2();
1091 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1092 EXPECT_EQ(status, E_NO_PERMISSION);
1093
1094 AddPrivilege(query);
1095 SetHapToken2();
1096
1097 status = UdmfClient::GetInstance().GetBatchData(query, unifiedDataSet);
1098 ASSERT_EQ(status, E_OK);
1099 auto outputRecords = unifiedDataSet[0].GetRecords();
1100 ASSERT_EQ(inputRecords.size(), outputRecords.size());
1101 for (size_t i = 0; i < outputRecords.size(); ++i) {
1102 ASSERT_EQ(outputRecords[i]->GetType(), inputRecords[i]->GetType());
1103 }
1104 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1105 ASSERT_EQ(status, E_OK);
1106 LOG_INFO(UDMF_TEST, "SetData018 end.");
1107 }
1108
1109 /**
1110 * @tc.name: AddPrivilege001
1111 * @tc.desc: Add privilege with valid params
1112 * @tc.type: FUNC
1113 */
1114 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege001, TestSize.Level1)
1115 {
1116 LOG_INFO(UDMF_TEST, "AddPrivilege001 begin.");
1117 CustomOption option1 = { .intention = Intention::UD_INTENTION_PICKER };
1118 UnifiedData data;
1119 auto text = std::make_shared<Text>();
1120 UDDetails details;
1121 details.insert({ "udmf_key", "udmf_value" });
1122 text->SetDetails(details);
1123 data.AddRecord(text);
1124 std::string key;
1125 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1126 ASSERT_EQ(status, E_OK);
1127
1128 QueryOption query = { .key = key };
1129 Privilege privilege;
1130 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1131 privilege.readPermission = "readandkeep";
1132 privilege.writePermission = "writePermission";
1133 SetNativeToken("foundation");
1134 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1135 ASSERT_EQ(status, E_OK);
1136 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1137 SetNativeToken("foundation");
1138 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1139 ASSERT_EQ(status, E_NO_PERMISSION);
1140 privilege.readPermission = "readpermission";
1141 query.intention = Intention::UD_INTENTION_PICKER;
1142 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1143 ASSERT_EQ(status, E_OK);
1144 LOG_INFO(UDMF_TEST, "AddPrivilege001 end.");
1145 }
1146
1147 /**
1148 * @tc.name: AddPrivilege002
1149 * @tc.desc: Add privilege with valid params
1150 * @tc.type: FUNC
1151 */
1152 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege002, TestSize.Level1)
1153 {
1154 LOG_INFO(UDMF_TEST, "AddPrivilege002 begin.");
1155 CustomOption option1 = { .intention = Intention::UD_INTENTION_MENU };
1156 UnifiedData data;
1157 auto text = std::make_shared<Text>();
1158 UDDetails details;
1159 details.insert({ "udmf_key", "udmf_value" });
1160 text->SetDetails(details);
1161 data.AddRecord(text);
1162 std::string key;
1163 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1164 ASSERT_EQ(status, E_OK);
1165
1166 QueryOption query = { .key = key };
1167 Privilege privilege;
1168 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1169 privilege.readPermission = "readandkeep";
1170 privilege.writePermission = "writePermission";
1171 SetNativeToken("foundation");
1172
1173 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1174 ASSERT_EQ(status, E_OK);
1175 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1176 SetNativeToken("foundation");
1177 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1178 ASSERT_EQ(status, E_NO_PERMISSION);
1179 privilege.readPermission = "readpermission";
1180 query.intention = Intention::UD_INTENTION_MENU;
1181 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1182 ASSERT_EQ(status, E_OK);
1183 LOG_INFO(UDMF_TEST, "AddPrivilege002 end.");
1184 }
1185
1186 /**
1187 * @tc.name: AddPrivilege003
1188 * @tc.desc: Add privilege with valid params
1189 * @tc.type: FUNC
1190 */
1191 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege003, TestSize.Level1)
1192 {
1193 LOG_INFO(UDMF_TEST, "AddPrivilege003 begin.");
1194
1195 CustomOption option1 = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1196 UnifiedData data;
1197 auto text = std::make_shared<Text>();
1198 UDDetails details;
1199 details.insert({ "udmf_key", "udmf_value" });
1200 text->SetDetails(details);
1201 data.AddRecord(text);
1202 std::string key;
1203 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1204 ASSERT_EQ(status, E_OK);
1205
1206 QueryOption query = { .key = key };
1207 Privilege privilege;
1208 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1209 privilege.readPermission = "readandkeep";
1210 privilege.writePermission = "writePermission";
1211 SetNativeToken("foundation");
1212 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1213 ASSERT_EQ(status, E_OK);
1214 query.intention = Intention::UD_INTENTION_MENU;
1215 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1216 ASSERT_EQ(status, E_NO_PERMISSION);
1217 privilege.readPermission = "readpermission";
1218 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1219 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1220 ASSERT_EQ(status, E_OK);
1221 LOG_INFO(UDMF_TEST, "AddPrivilege003 end.");
1222 }
1223
1224 /**
1225 * @tc.name: AddPrivilege004
1226 * @tc.desc: Add privilege with invalid params
1227 * @tc.type: FUNC
1228 */
1229 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege004, TestSize.Level1)
1230 {
1231 LOG_INFO(UDMF_TEST, "AddPrivilege004 begin.");
1232
1233 CustomOption option1 = { .intention = Intention::UD_INTENTION_PICKER };
1234 UnifiedData data;
1235 auto text = std::make_shared<Text>();
1236 UDDetails details;
1237 details.insert({ "udmf_key", "udmf_value" });
1238 text->SetDetails(details);
1239 data.AddRecord(text);
1240 std::string key;
1241 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1242 ASSERT_EQ(status, E_OK);
1243
1244 QueryOption query;
1245 Privilege privilege;
1246 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1247 privilege.readPermission = "readandkeep";
1248 privilege.writePermission = "writePermission";
1249 SetNativeToken("foundation");
1250
1251 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1252 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1253 query.intention = Intention::UD_INTENTION_MENU;
1254 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1255 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1256 query.intention = Intention::UD_INTENTION_PICKER;
1257 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1258 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1259
1260 query.key = key;
1261 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1262 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1263 ASSERT_EQ(status, E_NO_PERMISSION);
1264 query.intention = Intention::UD_INTENTION_PICKER;
1265 std::vector<UnifiedData> unifiedDataSet;
1266 SetHapToken2();
1267 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1268 ASSERT_EQ(status, E_OK);
1269 LOG_INFO(UDMF_TEST, "AddPrivilege004 end.");
1270 }
1271
1272 /**
1273 * @tc.name: AddPrivilege005
1274 * @tc.desc: Add privilege with invalid params
1275 * @tc.type: FUNC
1276 */
1277 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege005, TestSize.Level1)
1278 {
1279 LOG_INFO(UDMF_TEST, "AddPrivilege005 begin.");
1280
1281 CustomOption option1 = { .intention = Intention::UD_INTENTION_MENU };
1282 UnifiedData data;
1283 auto text = std::make_shared<Text>();
1284 UDDetails details;
1285 details.insert({ "udmf_key", "udmf_value" });
1286 text->SetDetails(details);
1287 data.AddRecord(text);
1288 std::string key;
1289 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1290 ASSERT_EQ(status, E_OK);
1291
1292 QueryOption query;
1293 Privilege privilege;
1294 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1295 privilege.readPermission = "readandkeep";
1296 privilege.writePermission = "writePermission";
1297 SetNativeToken("foundation");
1298 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1299 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1300 query.intention = Intention::UD_INTENTION_PICKER;
1301 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1302 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1303 query.intention = Intention::UD_INTENTION_MENU;
1304 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1305 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1306 query.key = key;
1307 query.intention = Intention::UD_INTENTION_PICKER;
1308 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1309 ASSERT_EQ(status, E_NO_PERMISSION);
1310 query.intention = Intention::UD_INTENTION_MENU;
1311 std::vector<UnifiedData> unifiedDataSet;
1312 SetHapToken2();
1313 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1314 ASSERT_EQ(status, E_OK);
1315 LOG_INFO(UDMF_TEST, "AddPrivilege005 end.");
1316 }
1317
1318 /**
1319 * @tc.name: AddPrivilege006
1320 * @tc.desc: Add privilege with invalid params
1321 * @tc.type: FUNC
1322 */
1323 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege006, TestSize.Level1)
1324 {
1325 LOG_INFO(UDMF_TEST, "AddPrivilege006 begin.");
1326
1327 CustomOption option1 = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1328 UnifiedData data;
1329 auto text = std::make_shared<Text>();
1330 UDDetails details;
1331 details.insert({ "udmf_key", "udmf_value" });
1332 text->SetDetails(details);
1333 data.AddRecord(text);
1334 std::string key;
1335 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1336 ASSERT_EQ(status, E_OK);
1337
1338 QueryOption query;
1339 Privilege privilege;
1340 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1341 privilege.readPermission = "readandkeep";
1342 privilege.writePermission = "writePermission";
1343 SetNativeToken("foundation");
1344 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1345 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1346 query.intention = Intention::UD_INTENTION_MENU;
1347 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1348 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1349 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1350 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1351 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1352 query.key = key;
1353 query.intention = Intention::UD_INTENTION_MENU;
1354 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1355 ASSERT_EQ(status, E_NO_PERMISSION);
1356 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1357 std::vector<UnifiedData> unifiedDataSet;
1358 SetHapToken2();
1359 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1360 ASSERT_EQ(status, E_OK);
1361 LOG_INFO(UDMF_TEST, "AddPrivilege006 end.");
1362 }
1363
1364 /**
1365 * @tc.name: AddPrivilege007
1366 * @tc.desc: Add privilege with invalid params
1367 * @tc.type: FUNC
1368 */
1369 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege007, TestSize.Level1)
1370 {
1371 LOG_INFO(UDMF_TEST, "AddPrivilege007 begin.");
1372
1373 CustomOption option1 = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1374 UnifiedData data;
1375 auto text = std::make_shared<Text>();
1376 UDDetails details;
1377 details.insert({ "udmf_key", "udmf_value" });
1378 text->SetDetails(details);
1379 data.AddRecord(text);
1380 std::string key;
1381 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1382 ASSERT_EQ(status, E_OK);
1383
1384 QueryOption query;
1385 Privilege privilege;
1386 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1387 privilege.readPermission = "readandkeep";
1388 privilege.writePermission = "writePermission";
1389 SetNativeToken("foundation");
1390
1391 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1392 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1393 ASSERT_EQ(status, E_NO_PERMISSION);
1394 query.intention = Intention::UD_INTENTION_MENU;
1395 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1396 ASSERT_EQ(status, E_NO_PERMISSION);
1397 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1398 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1399 ASSERT_EQ(status, E_NO_PERMISSION);
1400 LOG_INFO(UDMF_TEST, "AddPrivilege007 end.");
1401 }
1402
1403 /**
1404 * @tc.name: AddPrivilege008
1405 * @tc.desc: Add privilege with invalid params
1406 * @tc.type: FUNC
1407 */
1408 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege008, TestSize.Level1)
1409 {
1410 LOG_INFO(UDMF_TEST, "AddPrivilege008 begin.");
1411
1412 CustomOption option1 = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1413 UnifiedData data;
1414 auto text = std::make_shared<Text>();
1415 UDDetails details;
1416 details.insert({ "udmf_key", "udmf_value" });
1417 text->SetDetails(details);
1418 data.AddRecord(text);
1419 std::string key;
1420 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1421 ASSERT_EQ(status, E_OK);
1422
1423 QueryOption query;
1424 Privilege privilege;
1425 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1426 privilege.readPermission = "readandkeep";
1427 privilege.writePermission = "writePermission";
1428 SetNativeToken("foundation");
1429 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1430 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1431 ASSERT_EQ(status, E_NO_PERMISSION);
1432 query.intention = Intention::UD_INTENTION_MENU;
1433 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1434 ASSERT_EQ(status, E_NO_PERMISSION);
1435 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1436 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1437 ASSERT_EQ(status, E_NO_PERMISSION);
1438 LOG_INFO(UDMF_TEST, "AddPrivilege008 end.");
1439 }
1440
1441 /**
1442 * @tc.name: AddPrivilege009
1443 * @tc.desc: Add privilege with invalid params
1444 * @tc.type: FUNC
1445 */
1446 HWTEST_F(UdmfClientFileMangerTest, AddPrivilege009, TestSize.Level1)
1447 {
1448 LOG_INFO(UDMF_TEST, "AddPrivilege009 begin.");
1449
1450 CustomOption option1 = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1451 UnifiedData data;
1452 auto text = std::make_shared<Text>();
1453 UDDetails details;
1454 details.insert({ "udmf_key", "udmf_value" });
1455 text->SetDetails(details);
1456 data.AddRecord(text);
1457 std::string key;
1458 auto status = UdmfClient::GetInstance().SetData(option1, data, key);
1459 ASSERT_EQ(status, E_OK);
1460
1461 QueryOption query;
1462 Privilege privilege;
1463 privilege.tokenId = AccessTokenKit::GetHapTokenID(userId, "ohos.file.manger.test.demo2", instIndex);
1464 privilege.readPermission = "readandkeep";
1465 privilege.writePermission = "writePermission";
1466 SetNativeToken("foundation");
1467 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1468 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1469 ASSERT_EQ(status, E_NO_PERMISSION);
1470 query.intention = Intention::UD_INTENTION_MENU;
1471 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1472 ASSERT_EQ(status, E_NO_PERMISSION);
1473 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1474 status = UdmfClient::GetInstance().AddPrivilege(query, privilege);
1475 ASSERT_EQ(status, E_NO_PERMISSION);
1476 LOG_INFO(UDMF_TEST, "AddPrivilege009 end.");
1477 }
1478
1479 /**
1480 * @tc.name: DeleteData001
1481 * @tc.desc: Delete data with UD_INTENTION_PICKER
1482 * @tc.type: FUNC
1483 */
1484 HWTEST_F(UdmfClientFileMangerTest, DeleteData001, TestSize.Level1)
1485 {
1486 LOG_INFO(UDMF_TEST, "DeleteData001 begin.");
1487 CustomOption customOption = { .intention = UD_INTENTION_PICKER };
1488 UnifiedData data;
1489 auto plainText = std::make_shared<PlainText>();
1490 plainText->SetContent("content1");
1491 data.AddRecord(plainText);
1492 std::string key;
1493 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1494 ASSERT_EQ(status, E_OK);
1495
1496 QueryOption queryOption;
1497 std::vector<UnifiedData> unifiedDataSet;
1498 queryOption.key = key;
1499 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1500 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1501 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1502 queryOption.intention = UD_INTENTION_PICKER;
1503 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1504 ASSERT_EQ(status, E_OK);
1505 LOG_INFO(UDMF_TEST, "DeleteData001 end.");
1506 }
1507
1508 /**
1509 * @tc.name: DeleteData002
1510 * @tc.desc: Delete data with UD_INTENTION_PICKER
1511 * @tc.type: FUNC
1512 */
1513 HWTEST_F(UdmfClientFileMangerTest, DeleteData002, TestSize.Level1)
1514 {
1515 LOG_INFO(UDMF_TEST, "DeleteData002 begin.");
1516 CustomOption customOption = { .intention = UD_INTENTION_PICKER };
1517 UnifiedData data;
1518 auto plainText = std::make_shared<PlainText>();
1519 plainText->SetContent("content1");
1520 data.AddRecord(plainText);
1521 std::string key;
1522 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1523 ASSERT_EQ(status, E_OK);
1524
1525 QueryOption queryOption;
1526 std::vector<UnifiedData> unifiedDataSet;
1527 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1528 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1529 queryOption.intention = UD_INTENTION_PICKER;
1530 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1531 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1532 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1533 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1534 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1535
1536 QueryOption queryOption1 = { .key = key };
1537 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1538 ASSERT_EQ(status, E_OK);
1539 LOG_INFO(UDMF_TEST, "DeleteData002 end.");
1540 }
1541
1542 /**
1543 * @tc.name: DeleteData003
1544 * @tc.desc: Delete data with UD_INTENTION_PICKER
1545 * @tc.type: FUNC
1546 */
1547 HWTEST_F(UdmfClientFileMangerTest, DeleteData003, TestSize.Level1)
1548 {
1549 LOG_INFO(UDMF_TEST, "DeleteData003 begin.");
1550 CustomOption customOption = { .intention = UD_INTENTION_PICKER };
1551 UnifiedData data;
1552 auto plainText = std::make_shared<PlainText>();
1553 plainText->SetContent("content1");
1554 data.AddRecord(plainText);
1555 std::string key;
1556 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1557 ASSERT_EQ(status, E_OK);
1558
1559 QueryOption queryOption;
1560 std::vector<UnifiedData> unifiedDataSet;
1561 queryOption.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1562 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1563 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1564 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1565 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1566 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1567 queryOption.intention = UD_INTENTION_PICKER;
1568 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1569 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1570
1571 QueryOption queryOption1 = { .key = key };
1572 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1573 ASSERT_EQ(status, E_OK);
1574 LOG_INFO(UDMF_TEST, "DeleteData003 end.");
1575 }
1576
1577 /**
1578 * @tc.name: DeleteData004
1579 * @tc.desc: Delete data with UD_INTENTION_SYSTEM_SHARE
1580 * @tc.type: FUNC
1581 */
1582 HWTEST_F(UdmfClientFileMangerTest, DeleteData004, TestSize.Level1)
1583 {
1584 LOG_INFO(UDMF_TEST, "DeleteData004 begin.");
1585 CustomOption customOption = { .intention = UD_INTENTION_SYSTEM_SHARE };
1586 UnifiedData data;
1587 auto plainText = std::make_shared<PlainText>();
1588 plainText->SetContent("content1");
1589 data.AddRecord(plainText);
1590 std::string key;
1591 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1592 ASSERT_EQ(status, E_OK);
1593
1594 QueryOption queryOption;
1595 std::vector<UnifiedData> unifiedDataSet;
1596 queryOption.key = key;
1597 queryOption.intention = UD_INTENTION_PICKER;
1598 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1599 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1600 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1601 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1602 ASSERT_EQ(status, E_OK);
1603 LOG_INFO(UDMF_TEST, "DeleteData004 end.");
1604 }
1605
1606 /**
1607 * @tc.name: DeleteData005
1608 * @tc.desc: Delete data with UD_INTENTION_SYSTEM_SHARE
1609 * @tc.type: FUNC
1610 */
1611 HWTEST_F(UdmfClientFileMangerTest, DeleteData005, TestSize.Level1)
1612 {
1613 LOG_INFO(UDMF_TEST, "DeleteData005 begin.");
1614 CustomOption customOption = { .intention = UD_INTENTION_SYSTEM_SHARE };
1615 UnifiedData data;
1616 auto plainText = std::make_shared<PlainText>();
1617 plainText->SetContent("content1");
1618 data.AddRecord(plainText);
1619 std::string key;
1620 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1621 ASSERT_EQ(status, E_OK);
1622
1623 QueryOption queryOption;
1624 std::vector<UnifiedData> unifiedDataSet;
1625 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1626 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1627 queryOption.intention = UD_INTENTION_PICKER;
1628 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1629 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1630 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1631 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1632 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1633
1634 QueryOption queryOption1 = { .key = key };
1635 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1636 ASSERT_EQ(status, E_OK);
1637 LOG_INFO(UDMF_TEST, "DeleteData005 end.");
1638 }
1639
1640 /**
1641 * @tc.name: DeleteData006
1642 * @tc.desc: Delete data with UD_INTENTION_SYSTEM_SHARE
1643 * @tc.type: FUNC
1644 */
1645 HWTEST_F(UdmfClientFileMangerTest, DeleteData006, TestSize.Level1)
1646 {
1647 LOG_INFO(UDMF_TEST, "DeleteData006 begin.");
1648 CustomOption customOption = { .intention = UD_INTENTION_SYSTEM_SHARE };
1649 UnifiedData data;
1650 auto plainText = std::make_shared<PlainText>();
1651 plainText->SetContent("content1");
1652 data.AddRecord(plainText);
1653 std::string key;
1654 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1655 ASSERT_EQ(status, E_OK);
1656
1657 QueryOption queryOption;
1658 std::vector<UnifiedData> unifiedDataSet;
1659 queryOption.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1660 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1661 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1662 queryOption.intention = UD_INTENTION_PICKER;
1663 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1664 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1665 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1666 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1667 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1668
1669 QueryOption queryOption1 = { .key = key };
1670 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1671 ASSERT_EQ(status, E_OK);
1672 LOG_INFO(UDMF_TEST, "DeleteData006 end.");
1673 }
1674
1675 /**
1676 * @tc.name: DeleteData007
1677 * @tc.desc: Delete data with UD_INTENTION_MENU
1678 * @tc.type: FUNC
1679 */
1680 HWTEST_F(UdmfClientFileMangerTest, DeleteData007, TestSize.Level1)
1681 {
1682 LOG_INFO(UDMF_TEST, "DeleteData007 begin.");
1683 CustomOption customOption = { .intention = UD_INTENTION_MENU };
1684 UnifiedData data;
1685 auto plainText = std::make_shared<PlainText>();
1686 plainText->SetContent("content1");
1687 data.AddRecord(plainText);
1688 std::string key;
1689 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1690 ASSERT_EQ(status, E_OK);
1691
1692 QueryOption queryOption;
1693 std::vector<UnifiedData> unifiedDataSet;
1694 queryOption.key = key;
1695 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1696 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1697 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1698 queryOption.intention = UD_INTENTION_MENU;
1699 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1700 ASSERT_EQ(status, E_OK);
1701 LOG_INFO(UDMF_TEST, "DeleteData007 end.");
1702 }
1703
1704 /**
1705 * @tc.name: DeleteData008
1706 * @tc.desc: Delete data with UD_INTENTION_MENU
1707 * @tc.type: FUNC
1708 */
1709 HWTEST_F(UdmfClientFileMangerTest, DeleteData008, TestSize.Level1)
1710 {
1711 LOG_INFO(UDMF_TEST, "DeleteData008 begin.");
1712 CustomOption customOption = { .intention = UD_INTENTION_MENU };
1713 UnifiedData data;
1714 auto plainText = std::make_shared<PlainText>();
1715 plainText->SetContent("content1");
1716 data.AddRecord(plainText);
1717 std::string key;
1718 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1719 ASSERT_EQ(status, E_OK);
1720
1721 QueryOption queryOption;
1722 std::vector<UnifiedData> unifiedDataSet;
1723 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1724 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1725 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1726 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1727 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1728 queryOption.intention = UD_INTENTION_MENU;
1729 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1730 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1731
1732 QueryOption queryOption1 = { .key = key };
1733 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1734 ASSERT_EQ(status, E_OK);
1735 LOG_INFO(UDMF_TEST, "DeleteData008 end.");
1736 }
1737
1738 /**
1739 * @tc.name: DeleteData009
1740 * @tc.desc: Delete data with UD_INTENTION_MENU
1741 * @tc.type: FUNC
1742 */
1743 HWTEST_F(UdmfClientFileMangerTest, DeleteData009, TestSize.Level1)
1744 {
1745 LOG_INFO(UDMF_TEST, "DeleteData009 begin.");
1746 CustomOption customOption = { .intention = UD_INTENTION_MENU };
1747 UnifiedData data;
1748 auto plainText = std::make_shared<PlainText>();
1749 plainText->SetContent("content1");
1750 data.AddRecord(plainText);
1751 std::string key;
1752 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1753 ASSERT_EQ(status, E_OK);
1754
1755 QueryOption queryOption;
1756 std::vector<UnifiedData> unifiedDataSet;
1757 queryOption.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1758 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1759 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1760 queryOption.intention = UD_INTENTION_SYSTEM_SHARE;
1761 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1762 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1763 queryOption.intention = UD_INTENTION_MENU;
1764 status = UdmfClient::GetInstance().DeleteData(queryOption, unifiedDataSet);
1765 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1766
1767 QueryOption queryOption1 = { .key = key };
1768 status = UdmfClient::GetInstance().DeleteData(queryOption1, unifiedDataSet);
1769 ASSERT_EQ(status, E_OK);
1770 LOG_INFO(UDMF_TEST, "DeleteData009 end.");
1771 }
1772
1773 /**
1774 * @tc.name: UpdateData001
1775 * @tc.desc: test picker update data
1776 * @tc.type: FUNC
1777 */
1778 HWTEST_F(UdmfClientFileMangerTest, UpdateData001, TestSize.Level1)
1779 {
1780 LOG_INFO(UDMF_TEST, "UpdateData001 begin.");
1781 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
1782 UnifiedData data;
1783 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1784 data.AddRecord(record);
1785 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1786 std::string tag = "this is a tag of test UpdateData001";
1787 properties->tag = tag;
1788 data.SetProperties(std::move(properties));
1789 std::string key;
1790 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1791 ASSERT_EQ(status, E_OK);
1792
1793 QueryOption query;
1794 std::vector<UnifiedData> unifiedDataSet;
1795 status = UdmfClient::GetInstance().UpdateData(query, data);
1796 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1797 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1798 status = UdmfClient::GetInstance().UpdateData(query, data);
1799 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1800 query.intention = Intention::UD_INTENTION_PICKER;
1801 status = UdmfClient::GetInstance().UpdateData(query, data);
1802 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1803
1804 query.key = key;
1805 status = UdmfClient::GetInstance().UpdateData(query, data);
1806 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1807 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1808 ASSERT_EQ(status, E_OK);
1809 LOG_INFO(UDMF_TEST, "UpdateData001 end.");
1810 }
1811
1812 /**
1813 * @tc.name: UpdateData002
1814 * @tc.desc: test picker update data
1815 * @tc.type: FUNC
1816 */
1817 HWTEST_F(UdmfClientFileMangerTest, UpdateData002, TestSize.Level1)
1818 {
1819 LOG_INFO(UDMF_TEST, "UpdateData002 begin.");
1820 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
1821 UnifiedData data;
1822 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1823 data.AddRecord(record);
1824 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1825 std::string tag = "this is a tag of test UpdateData001";
1826 properties->tag = tag;
1827 data.SetProperties(std::move(properties));
1828 std::string key;
1829 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1830 ASSERT_EQ(status, E_OK);
1831
1832 QueryOption query;
1833 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
1834 std::vector<UnifiedData> unifiedDataSet;
1835 status = UdmfClient::GetInstance().UpdateData(query, data);
1836 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1837 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1838 status = UdmfClient::GetInstance().UpdateData(query, data);
1839 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1840 query.intention = Intention::UD_INTENTION_PICKER;
1841 status = UdmfClient::GetInstance().UpdateData(query, data);
1842 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1843
1844 query.key = key;
1845 status = UdmfClient::GetInstance().UpdateData(query, data);
1846 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1847 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1848 ASSERT_EQ(status, E_OK);
1849 LOG_INFO(UDMF_TEST, "UpdateData002 end.");
1850 }
1851
1852 /**
1853 * @tc.name: UpdateData003
1854 * @tc.desc: test picker update data
1855 * @tc.type: FUNC
1856 */
1857 HWTEST_F(UdmfClientFileMangerTest, UpdateData003, TestSize.Level1)
1858 {
1859 LOG_INFO(UDMF_TEST, "UpdateData003 begin.");
1860 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
1861 UnifiedData data;
1862 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1863 data.AddRecord(record);
1864 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1865 std::string tag = "this is a tag of test UpdateData001";
1866 properties->tag = tag;
1867 data.SetProperties(std::move(properties));
1868 std::string key;
1869 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1870 ASSERT_EQ(status, E_OK);
1871
1872 QueryOption query;
1873 query.key = key;
1874 std::vector<UnifiedData> unifiedDataSet;
1875 status = UdmfClient::GetInstance().UpdateData(query, data);
1876 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1877 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1878 status = UdmfClient::GetInstance().UpdateData(query, data);
1879 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1880 query.intention = Intention::UD_INTENTION_PICKER;
1881 status = UdmfClient::GetInstance().UpdateData(query, data);
1882 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1883
1884 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1885 ASSERT_EQ(status, E_OK);
1886 LOG_INFO(UDMF_TEST, "UpdateData003 end.");
1887 }
1888
1889 /**
1890 * @tc.name: UpdateData004
1891 * @tc.desc: test picker update data
1892 * @tc.type: FUNC
1893 */
1894 HWTEST_F(UdmfClientFileMangerTest, UpdateData004, TestSize.Level1)
1895 {
1896 LOG_INFO(UDMF_TEST, "UpdateData004 begin.");
1897 CustomOption customOption = { .intention = Intention::UD_INTENTION_PICKER };
1898 UnifiedData data;
1899 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1900 data.AddRecord(record);
1901 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1902 std::string tag = "this is a tag of test UpdateData001";
1903 properties->tag = tag;
1904 data.SetProperties(std::move(properties));
1905 std::string key;
1906 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1907 ASSERT_EQ(status, E_OK);
1908
1909 QueryOption query;
1910 std::vector<UnifiedData> unifiedDataSet;
1911 status = UdmfClient::GetInstance().UpdateData(query, data);
1912 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1913 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1914 status = UdmfClient::GetInstance().UpdateData(query, data);
1915 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1916 query.intention = Intention::UD_INTENTION_PICKER;
1917 status = UdmfClient::GetInstance().UpdateData(query, data);
1918 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1919
1920 query.key = key;
1921 status = UdmfClient::GetInstance().UpdateData(query, data);
1922 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1923 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1924 ASSERT_EQ(status, E_OK);
1925 LOG_INFO(UDMF_TEST, "UpdateData004 end.");
1926 }
1927
1928 /**
1929 * @tc.name: UpdateData005
1930 * @tc.desc: test picker update data
1931 * @tc.type: FUNC
1932 */
1933 HWTEST_F(UdmfClientFileMangerTest, UpdateData005, TestSize.Level1)
1934 {
1935 LOG_INFO(UDMF_TEST, "UpdateData005 begin.");
1936 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1937 UnifiedData data;
1938 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1939 data.AddRecord(record);
1940 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1941 std::string tag = "this is a tag of test UpdateData001";
1942 properties->tag = tag;
1943 data.SetProperties(std::move(properties));
1944 std::string key;
1945 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1946 ASSERT_EQ(status, E_OK);
1947
1948 QueryOption query;
1949 query.key = key;
1950 std::vector<UnifiedData> unifiedDataSet;
1951 status = UdmfClient::GetInstance().UpdateData(query, data);
1952 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1953 query.intention = Intention::UD_INTENTION_PICKER;
1954 status = UdmfClient::GetInstance().UpdateData(query, data);
1955 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1956 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1957 status = UdmfClient::GetInstance().UpdateData(query, data);
1958 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1959
1960 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
1961 ASSERT_EQ(status, E_OK);
1962 LOG_INFO(UDMF_TEST, "UpdateData005 end.");
1963 }
1964
1965 /**
1966 * @tc.name: UpdateData006
1967 * @tc.desc: test systemshare update data
1968 * @tc.type: FUNC
1969 */
1970 HWTEST_F(UdmfClientFileMangerTest, UpdateData006, TestSize.Level1)
1971 {
1972 LOG_INFO(UDMF_TEST, "UpdateData006 begin.");
1973 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
1974 UnifiedData data;
1975 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
1976 data.AddRecord(record);
1977 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
1978 std::string tag = "this is a tag of test UpdateData001";
1979 properties->tag = tag;
1980 data.SetProperties(std::move(properties));
1981 std::string key;
1982 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
1983 ASSERT_EQ(status, E_OK);
1984
1985 QueryOption query;
1986 std::vector<UnifiedData> unifiedDataSet;
1987 status = UdmfClient::GetInstance().UpdateData(query, data);
1988 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1989 query.intention = Intention::UD_INTENTION_PICKER;
1990 status = UdmfClient::GetInstance().UpdateData(query, data);
1991 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1992 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
1993 status = UdmfClient::GetInstance().UpdateData(query, data);
1994 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1995
1996 query.key = key;
1997 status = UdmfClient::GetInstance().UpdateData(query, data);
1998 ASSERT_EQ(status, E_INVALID_PARAMETERS);
1999 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2000 ASSERT_EQ(status, E_OK);
2001 LOG_INFO(UDMF_TEST, "UpdateData006 end.");
2002 }
2003
2004 /**
2005 * @tc.name: UpdateData007
2006 * @tc.desc: test systemshare update data
2007 * @tc.type: FUNC
2008 */
2009 HWTEST_F(UdmfClientFileMangerTest, UpdateData007, TestSize.Level1)
2010 {
2011 LOG_INFO(UDMF_TEST, "UpdateData007 begin.");
2012 CustomOption customOption = { .intention = Intention::UD_INTENTION_SYSTEM_SHARE };
2013 UnifiedData data;
2014 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
2015 data.AddRecord(record);
2016 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
2017 std::string tag = "this is a tag of test UpdateData001";
2018 properties->tag = tag;
2019 data.SetProperties(std::move(properties));
2020 std::string key;
2021 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
2022 ASSERT_EQ(status, E_OK);
2023
2024 QueryOption query;
2025 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
2026 std::vector<UnifiedData> unifiedDataSet;
2027 status = UdmfClient::GetInstance().UpdateData(query, data);
2028 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2029 query.intention = Intention::UD_INTENTION_PICKER;
2030 status = UdmfClient::GetInstance().UpdateData(query, data);
2031 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2032 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
2033 status = UdmfClient::GetInstance().UpdateData(query, data);
2034 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2035
2036 query.key = key;
2037 status = UdmfClient::GetInstance().UpdateData(query, data);
2038 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2039 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2040 ASSERT_EQ(status, E_OK);
2041 LOG_INFO(UDMF_TEST, "UpdateData007 end.");
2042 }
2043
2044 /**
2045 * @tc.name: UpdateData008
2046 * @tc.desc: test menu update data
2047 * @tc.type: FUNC
2048 */
2049 HWTEST_F(UdmfClientFileMangerTest, UpdateData008, TestSize.Level1)
2050 {
2051 LOG_INFO(UDMF_TEST, "UpdateData008 begin.");
2052 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
2053 UnifiedData data;
2054 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
2055 data.AddRecord(record);
2056 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
2057 std::string tag = "this is a tag of test UpdateData001";
2058 properties->tag = tag;
2059 data.SetProperties(std::move(properties));
2060 std::string key;
2061 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
2062 ASSERT_EQ(status, E_OK);
2063
2064 QueryOption query;
2065 std::vector<UnifiedData> unifiedDataSet;
2066 status = UdmfClient::GetInstance().UpdateData(query, data);
2067 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2068 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
2069 status = UdmfClient::GetInstance().UpdateData(query, data);
2070 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2071 query.intention = Intention::UD_INTENTION_MENU;
2072 status = UdmfClient::GetInstance().UpdateData(query, data);
2073 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2074
2075 query.key = key;
2076 status = UdmfClient::GetInstance().UpdateData(query, data);
2077 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2078 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2079 ASSERT_EQ(status, E_OK);
2080 LOG_INFO(UDMF_TEST, "UpdateData008 end.");
2081 }
2082
2083 /**
2084 * @tc.name: UpdateData011
2085 * @tc.desc: test menu update data
2086 * @tc.type: FUNC
2087 */
2088 HWTEST_F(UdmfClientFileMangerTest, UpdateData011, TestSize.Level1)
2089 {
2090 LOG_INFO(UDMF_TEST, "UpdateData011 begin.");
2091 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
2092 UnifiedData data;
2093 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
2094 data.AddRecord(record);
2095 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
2096 std::string tag = "this is a tag of test UpdateData001";
2097 properties->tag = tag;
2098 data.SetProperties(std::move(properties));
2099 std::string key;
2100 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
2101 ASSERT_EQ(status, E_OK);
2102
2103 QueryOption query;
2104 query.key = "udmf://aaabbbccc/com.hmos.test/CSl;cdcGFcmdkasaccCSCAAScscdc";
2105 std::vector<UnifiedData> unifiedDataSet;
2106 status = UdmfClient::GetInstance().UpdateData(query, data);
2107 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2108 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
2109 status = UdmfClient::GetInstance().UpdateData(query, data);
2110 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2111 query.intention = Intention::UD_INTENTION_MENU;
2112 status = UdmfClient::GetInstance().UpdateData(query, data);
2113 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2114
2115 query.key = key;
2116 status = UdmfClient::GetInstance().UpdateData(query, data);
2117 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2118 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2119 ASSERT_EQ(status, E_OK);
2120 LOG_INFO(UDMF_TEST, "UpdateData011 end.");
2121 }
2122
2123 /**
2124 * @tc.name: UpdateData012
2125 * @tc.desc: test menu update data
2126 * @tc.type: FUNC
2127 */
2128 HWTEST_F(UdmfClientFileMangerTest, UpdateData012, TestSize.Level1)
2129 {
2130 LOG_INFO(UDMF_TEST, "UpdateData012 begin.");
2131 CustomOption customOption = { .intention = Intention::UD_INTENTION_MENU };
2132 UnifiedData data;
2133 std::shared_ptr<UnifiedRecord> record = std::make_shared<PlainText>(UDType::PLAIN_TEXT, "plainTextContent");
2134 data.AddRecord(record);
2135 std::shared_ptr<UnifiedDataProperties> properties = std::make_shared<UnifiedDataProperties>();
2136 std::string tag = "this is a tag of test UpdateData001";
2137 properties->tag = tag;
2138 data.SetProperties(std::move(properties));
2139 std::string key;
2140 auto status = UdmfClient::GetInstance().SetData(customOption, data, key);
2141 ASSERT_EQ(status, E_OK);
2142
2143 QueryOption query;
2144 query.key = key;
2145 std::vector<UnifiedData> unifiedDataSet;
2146 status = UdmfClient::GetInstance().UpdateData(query, data);
2147 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2148 query.intention = Intention::UD_INTENTION_SYSTEM_SHARE;
2149 status = UdmfClient::GetInstance().UpdateData(query, data);
2150 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2151 query.intention = Intention::UD_INTENTION_MENU;
2152 status = UdmfClient::GetInstance().UpdateData(query, data);
2153 ASSERT_EQ(status, E_INVALID_PARAMETERS);
2154
2155 status = UdmfClient::GetInstance().DeleteData(query, unifiedDataSet);
2156 ASSERT_EQ(status, E_OK);
2157 LOG_INFO(UDMF_TEST, "UpdateData012 end.");
2158 }
2159 }
2160