1 /* 2 * Copyright (c) 2022-2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include <cstdio> 17 #include <cstdlib> 18 19 #include <dirent.h> 20 #include <fcntl.h> 21 22 #include <errors.h> 23 #include <file_ex.h> 24 #include <gtest/gtest.h> 25 26 #include "b_jsonutil/b_jsonutil.h" 27 #include "b_process/b_process.h" 28 #include "test_manager.h" 29 30 namespace OHOS::FileManagement::Backup { 31 using namespace std; 32 33 namespace { 34 constexpr uint32_t TEST_USER_ID = 100; 35 } // namespace 36 37 class BJsonUtilTest : public testing::Test { 38 public: SetUpTestCase(void)39 static void SetUpTestCase(void) {}; TearDownTestCase()40 static void TearDownTestCase() {}; SetUp()41 void SetUp() {}; TearDown()42 void TearDown() {}; 43 }; 44 45 /** 46 * @tc.number: b_jsonutil_ParseBundleNameIndexStr_0100 47 * @tc.name: b_jsonutil_ParseBundleNameIndexStr_0100 48 * @tc.desc: Test function of ParseBundleNameIndexStr interface for SUCCESS. 49 * @tc.size: MEDIUM 50 * @tc.type: FUNC 51 * @tc.level Level 0 52 * @tc.require: I6F3GV 53 */ 54 HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0100, testing::ext::TestSize.Level0) 55 { 56 GTEST_LOG_(INFO) << "BJsonUtilTest-begin b_dir_GetDirFiles_0100"; 57 try { 58 std::string bundleName = "com.hos.app01:1"; 59 BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); 60 EXPECT_EQ("com.hos.app01", detailInfo.bundleName); 61 } catch (...) { 62 EXPECT_TRUE(false); 63 GTEST_LOG_(INFO) << "BDirTest-an exception occurred."; 64 } 65 GTEST_LOG_(INFO) << "BDirTest-end b_dir_GetDirFiles_0100"; 66 } 67 68 /** 69 * @tc.number: b_jsonutil_ParseBundleNameIndexStr_0200 70 * @tc.name: b_jsonutil_ParseBundleNameIndexStr_0200 71 * @tc.desc: Test function of ParseBundleNameIndexStr interface for SUCCESS. 72 * @tc.size: MEDIUM 73 * @tc.type: FUNC 74 * @tc.level Level 0 75 * @tc.require: I6F3GV 76 */ 77 HWTEST_F(BJsonUtilTest, b_jsonutil_ParseBundleNameIndexStr_0200, testing::ext::TestSize.Level0) 78 { 79 GTEST_LOG_(INFO) << "BJsonUtilTest-begin ParseBundleNameIndexStr_0200"; 80 try { 81 std::string bundleName = "com.hos.app01"; 82 BJsonUtil::BundleDetailInfo detailInfo = BJsonUtil::ParseBundleNameIndexStr(bundleName); 83 EXPECT_EQ("com.hos.app01", detailInfo.bundleName); 84 } catch (...) { 85 EXPECT_TRUE(false); 86 GTEST_LOG_(INFO) << "BDirTest-an exception occurred."; 87 } 88 GTEST_LOG_(INFO) << "BDirTest-end ParseBundleNameIndexStr_0200"; 89 } 90 91 /** 92 * @tc.number: b_jsonutil_BuildBundleInfos_0100 93 * @tc.name: b_jsonutil_BuildBundleInfos_0100 94 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 95 * @tc.size: MEDIUM 96 * @tc.type: FUNC 97 * @tc.level Level 0 98 * @tc.require: I6F3GV 99 */ 100 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0100, testing::ext::TestSize.Level0) 101 { 102 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0100"; 103 try { 104 std::vector<std::string> bundleNames; 105 std::string bundleName = "com.hos.app01:1"; 106 bundleNames.push_back(bundleName); 107 std::vector<std::string> bundleInfos; 108 std::string bundleInfo = "info1"; 109 std::string bundleInfo2 = "info2"; 110 bundleInfos.push_back(bundleInfo); 111 bundleInfos.push_back(bundleInfo2); 112 int32_t userId = TEST_USER_ID; 113 std::vector<std::string> bundleNamesOnly; 114 std::map<std::string, bool> isClearDataFlags; 115 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 116 userId, isClearDataFlags); 117 EXPECT_TRUE(result.empty()); 118 } catch (...) { 119 EXPECT_TRUE(false); 120 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 121 } 122 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0100"; 123 } 124 125 /** 126 * @tc.number: b_jsonutil_BuildBundleInfos_0200 127 * @tc.name: b_jsonutil_BuildBundleInfos_0200 128 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 129 * @tc.size: MEDIUM 130 * @tc.type: FUNC 131 * @tc.level Level 0 132 * @tc.require: I6F3GV 133 */ 134 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0200, testing::ext::TestSize.Level0) 135 { 136 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0200"; 137 try { 138 std::vector<std::string> bundleNames; 139 std::string bundleName = "bundle"; 140 bundleNames.push_back(bundleName); 141 std::vector<std::string> bundleInfos; 142 std::string bundleInfo = "{\"infos\":\"infos\"}"; 143 bundleInfos.push_back(bundleInfo); 144 int32_t userId = TEST_USER_ID; 145 std::vector<std::string> bundleNamesOnly; 146 std::map<std::string, bool> isClearDataFlags; 147 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 148 userId, isClearDataFlags); 149 EXPECT_FALSE(result.empty()); 150 } catch (...) { 151 EXPECT_TRUE(false); 152 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 153 } 154 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0200"; 155 } 156 157 /** 158 * @tc.number: b_jsonutil_BuildBundleInfos_0300 159 * @tc.name: b_jsonutil_BuildBundleInfos_0300 160 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 161 * @tc.size: MEDIUM 162 * @tc.type: FUNC 163 * @tc.level Level 0 164 * @tc.require: I6F3GV 165 */ 166 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0300, testing::ext::TestSize.Level0) 167 { 168 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0300"; 169 try { 170 std::vector<std::string> bundleNames; 171 std::string bundleName = "bundle1:"; 172 bundleNames.push_back(bundleName); 173 std::vector<std::string> bundleInfos; 174 std::string bundleInfo = "info1"; 175 bundleInfos.push_back(bundleInfo); 176 int32_t userId = TEST_USER_ID; 177 std::vector<std::string> bundleNamesOnly; 178 std::map<std::string, bool> isClearDataFlags; 179 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 180 userId, isClearDataFlags); 181 EXPECT_TRUE(result.empty()); 182 } catch (...) { 183 EXPECT_TRUE(false); 184 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 185 } 186 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0300"; 187 } 188 189 /** 190 * @tc.number: b_jsonutil_BuildBundleInfos_0301 191 * @tc.name: b_jsonutil_BuildBundleInfos_0301 192 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 193 * @tc.size: MEDIUM 194 * @tc.type: FUNC 195 * @tc.level Level 0 196 * @tc.require: I6F3GV 197 */ 198 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0301, testing::ext::TestSize.Level0) 199 { 200 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0301"; 201 try { 202 std::vector<std::string> bundleNames; 203 std::string bundleName = ":bundle1"; 204 bundleNames.push_back(bundleName); 205 std::vector<std::string> bundleInfos; 206 std::string bundleInfo = "info1"; 207 bundleInfos.push_back(bundleInfo); 208 int32_t userId = TEST_USER_ID; 209 std::vector<std::string> bundleNamesOnly; 210 std::map<std::string, bool> isClearDataFlags; 211 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 212 userId, isClearDataFlags); 213 EXPECT_TRUE(result.empty()); 214 } catch (...) { 215 EXPECT_TRUE(false); 216 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 217 } 218 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0301"; 219 } 220 221 /** 222 * @tc.number: b_jsonutil_BuildBundleInfos_0400 223 * @tc.name: b_jsonutil_BuildBundleInfos_0400 224 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 225 * @tc.size: MEDIUM 226 * @tc.type: FUNC 227 * @tc.level Level 0 228 * @tc.require: I6F3GV 229 */ 230 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0400, testing::ext::TestSize.Level0) 231 { 232 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0400"; 233 try { 234 std::vector<std::string> bundleNames; 235 std::string bundleName = "bundle1"; 236 bundleNames.push_back(bundleName); 237 std::vector<std::string> bundleInfos; 238 std::string bundleInfo = { 239 "{\"infos\":[{\"type\":\"type1\",\"details\":\"details1\"}],\"clearBackupData\": \"false\"}" 240 }; 241 bundleInfos.push_back(bundleInfo); 242 int32_t userId = TEST_USER_ID; 243 std::vector<std::string> bundleNamesOnly; 244 std::map<std::string, bool> isClearDataFlags; 245 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 246 userId, isClearDataFlags); 247 EXPECT_EQ(isClearDataFlags[bundleName], false); 248 EXPECT_FALSE(result.empty()); 249 } catch (...) { 250 EXPECT_TRUE(false); 251 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 252 } 253 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0400"; 254 } 255 256 /** 257 * @tc.number: b_jsonutil_BuildBundleInfos_0500 258 * @tc.name: b_jsonutil_BuildBundleInfos_0500 259 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 260 * @tc.size: MEDIUM 261 * @tc.type: FUNC 262 * @tc.level Level 0 263 * @tc.require: I6F3GV 264 */ 265 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0500, testing::ext::TestSize.Level0) 266 { 267 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0500"; 268 try { 269 std::vector<std::string> bundleNames; 270 std::string bundleName = "bundle"; 271 bundleNames.push_back(bundleName); 272 std::vector<std::string> bundleInfos; 273 std::string bundleInfo = {"{\"infos\":[{\"type\":null}]}"}; 274 bundleInfos.push_back(bundleInfo); 275 int32_t userId = TEST_USER_ID; 276 std::vector<std::string> bundleNamesOnly; 277 std::map<std::string, bool> isClearDataFlags; 278 279 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 280 userId, isClearDataFlags); 281 EXPECT_EQ(isClearDataFlags[bundleName], true); 282 EXPECT_FALSE(result.empty()); 283 } catch (...) { 284 EXPECT_TRUE(false); 285 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 286 } 287 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0500"; 288 } 289 290 /** 291 * @tc.number: b_jsonutil_BuildBundleInfos_0600 292 * @tc.name: b_jsonutil_BuildBundleInfos_0600 293 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 294 * @tc.size: MEDIUM 295 * @tc.type: FUNC 296 * @tc.level Level 0 297 * @tc.require: I6F3GV 298 */ 299 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0600, testing::ext::TestSize.Level0) 300 { 301 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0600"; 302 try { 303 std::vector<std::string> bundleNames; 304 std::string bundleName = "bundle"; 305 bundleNames.push_back(bundleName); 306 std::vector<std::string> bundleInfos; 307 std::string bundleInfo = {"{\"infos\":[{\"type\":123}],\"clearBackupData\": \"true\"}"}; 308 bundleInfos.push_back(bundleInfo); 309 int32_t userId = TEST_USER_ID; 310 std::vector<std::string> bundleNamesOnly; 311 std::map<std::string, bool> isClearDataFlags; 312 313 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 314 userId, isClearDataFlags); 315 EXPECT_EQ(isClearDataFlags[bundleName], true); 316 EXPECT_FALSE(result.empty()); 317 } catch (...) { 318 EXPECT_TRUE(false); 319 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 320 } 321 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0600"; 322 } 323 324 /** 325 * @tc.number: b_jsonutil_BuildBundleInfos_0700 326 * @tc.name: b_jsonutil_BuildBundleInfos_0700 327 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 328 * @tc.size: MEDIUM 329 * @tc.type: FUNC 330 * @tc.level Level 0 331 * @tc.require: I6F3GV 332 */ 333 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0700, testing::ext::TestSize.Level0) 334 { 335 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0700"; 336 try { 337 std::vector<std::string> bundleNames; 338 std::string bundleName = "bundle"; 339 bundleNames.push_back(bundleName); 340 std::vector<std::string> bundleInfos; 341 std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":null}]}"}; 342 bundleInfos.push_back(bundleInfo); 343 int32_t userId = TEST_USER_ID; 344 std::vector<std::string> bundleNamesOnly; 345 std::map<std::string, bool> isClearDataFlags; 346 347 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 348 userId, isClearDataFlags); 349 EXPECT_FALSE(result.empty()); 350 } catch (...) { 351 EXPECT_TRUE(false); 352 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 353 } 354 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0700"; 355 } 356 357 /** 358 * @tc.number: b_jsonutil_BuildBundleInfos_0800 359 * @tc.name: b_jsonutil_BuildBundleInfos_0800 360 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 361 * @tc.size: MEDIUM 362 * @tc.type: FUNC 363 * @tc.level Level 0 364 * @tc.require: I6F3GV 365 */ 366 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0800, testing::ext::TestSize.Level0) 367 { 368 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0800"; 369 try { 370 std::vector<std::string> bundleNames; 371 std::string bundleName = "bundle"; 372 bundleNames.push_back(bundleName); 373 std::vector<std::string> bundleInfos; 374 std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[]}]}"}; 375 bundleInfos.push_back(bundleInfo); 376 int32_t userId = TEST_USER_ID; 377 std::vector<std::string> bundleNamesOnly; 378 std::map<std::string, bool> isClearDataFlags; 379 380 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 381 userId, isClearDataFlags); 382 EXPECT_FALSE(result.empty()); 383 } catch (...) { 384 EXPECT_TRUE(false); 385 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 386 } 387 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0800"; 388 } 389 390 /** 391 * @tc.number: b_jsonutil_BuildBundleInfos_0900 392 * @tc.name: b_jsonutil_BuildBundleInfos_0900 393 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 394 * @tc.size: MEDIUM 395 * @tc.type: FUNC 396 * @tc.level Level 0 397 * @tc.require: I6F3GV 398 */ 399 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_0900, testing::ext::TestSize.Level0) 400 { 401 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_0900"; 402 try { 403 std::vector<std::string> bundleNames; 404 std::string bundleName = "bundle"; 405 bundleNames.push_back(bundleName); 406 std::vector<std::string> bundleInfos; 407 std::string bundleInfo = {"{\"infos\":[{\"type\":\"testType\",\"details\":[\"detail\"]}]}"}; 408 bundleInfos.push_back(bundleInfo); 409 int32_t userId = TEST_USER_ID; 410 std::vector<std::string> bundleNamesOnly; 411 std::map<std::string, bool> isClearDataFlags; 412 413 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 414 userId, isClearDataFlags); 415 EXPECT_FALSE(result.empty()); 416 } catch (...) { 417 EXPECT_TRUE(false); 418 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 419 } 420 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_0900"; 421 } 422 423 /** 424 * @tc.number: b_jsonutil_BuildBundleInfos_1000 425 * @tc.name: b_jsonutil_BuildBundleInfos_1000 426 * @tc.desc: Test function of BuildBundleInfos interface for SUCCESS. 427 * @tc.size: MEDIUM 428 * @tc.type: FUNC 429 * @tc.level Level 0 430 * @tc.require: I6F3GV 431 */ 432 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildBundleInfos_1000, testing::ext::TestSize.Level0) 433 { 434 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildBundleInfos_1000"; 435 try { 436 std::vector<std::string> bundleNames; 437 std::string bundleName = "bundle"; 438 bundleNames.push_back(bundleName); 439 std::vector<std::string> bundleInfos; 440 std::string bundleInfo = {"{\"infos\":[\"infos\"]}"}; 441 bundleInfos.push_back(bundleInfo); 442 int32_t userId = TEST_USER_ID; 443 std::vector<std::string> bundleNamesOnly; 444 std::map<std::string, bool> isClearDataFlags; 445 446 auto result = BJsonUtil::BuildBundleInfos(bundleNames, bundleInfos, bundleNamesOnly, 447 userId, isClearDataFlags); 448 EXPECT_FALSE(result.empty()); 449 } catch (...) { 450 EXPECT_TRUE(false); 451 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 452 } 453 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildBundleInfos_1000"; 454 } 455 456 /** 457 * @tc.number: b_jsonutil_FindBundleInfoByName_0100 458 * @tc.name: b_jsonutil_FindBundleInfoByName_0100 459 * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. 460 * @tc.size: MEDIUM 461 * @tc.type: FUNC 462 * @tc.level Level 0 463 * @tc.require: I6F3GV 464 */ 465 HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0100, testing::ext::TestSize.Level0) 466 { 467 GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0100"; 468 try { 469 std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> bundleNameDetailsMap; 470 std::string bundleName = "bundle1"; 471 std::string jobType = "type"; 472 BJsonUtil::BundleDetailInfo bundleDetail; 473 474 bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); 475 EXPECT_EQ(false, result); 476 } catch (...) { 477 EXPECT_TRUE(false); 478 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 479 } 480 GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0100"; 481 } 482 483 /** 484 * @tc.number: b_jsonutil_FindBundleInfoByName_0200 485 * @tc.name: b_jsonutil_FindBundleInfoByName_0200 486 * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. 487 * @tc.size: MEDIUM 488 * @tc.type: FUNC 489 * @tc.level Level 0 490 * @tc.require: I6F3GV 491 */ 492 HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0200, testing::ext::TestSize.Level0) 493 { 494 GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0200"; 495 try { 496 std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> bundleNameDetailsMap; 497 std::string bundleName = "bundle1"; 498 std::string jobType = "type"; 499 BJsonUtil::BundleDetailInfo detailInfo; 500 detailInfo.bundleName = bundleName; 501 detailInfo.type = jobType; 502 bundleNameDetailsMap[bundleName] = {detailInfo}; 503 BJsonUtil::BundleDetailInfo bundleDetail; 504 505 bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType, bundleDetail); 506 EXPECT_EQ(true, result); 507 EXPECT_EQ(bundleDetail.type, detailInfo.type); 508 } catch (...) { 509 EXPECT_TRUE(false); 510 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 511 } 512 GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0200"; 513 } 514 515 /** 516 * @tc.number: b_jsonutil_FindBundleInfoByName_0300 517 * @tc.name: b_jsonutil_FindBundleInfoByName_0300 518 * @tc.desc: Test function of FindBundleInfoByName interface for SUCCESS. 519 * @tc.size: MEDIUM 520 * @tc.type: FUNC 521 * @tc.level Level 0 522 * @tc.require: I6F3GV 523 */ 524 HWTEST_F(BJsonUtilTest, b_jsonutil_FindBundleInfoByName_0300, testing::ext::TestSize.Level0) 525 { 526 GTEST_LOG_(INFO) << "BJsonUtilTest-begin FindBundleInfoByName_0300"; 527 try { 528 std::map<std::string, std::vector<BJsonUtil::BundleDetailInfo>> bundleNameDetailsMap; 529 std::string bundleName = "bundle1"; 530 std::string jobType = "type"; 531 std::string jobType1 = "type1"; 532 BJsonUtil::BundleDetailInfo detailInfo; 533 detailInfo.bundleName = bundleName; 534 detailInfo.type = jobType; 535 bundleNameDetailsMap[bundleName] = {detailInfo}; 536 BJsonUtil::BundleDetailInfo bundleDetail; 537 538 bool result = BJsonUtil::FindBundleInfoByName(bundleNameDetailsMap, bundleName, jobType1, bundleDetail); 539 EXPECT_EQ(false, result); 540 } catch (...) { 541 EXPECT_TRUE(false); 542 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 543 } 544 GTEST_LOG_(INFO) << "BJsonUtilTest-end FindBundleInfoByName_0300"; 545 } 546 547 /** 548 * @tc.number: b_jsonutil_BuildOnProcessRetInfo_0100 549 * @tc.name: b_jsonutil_BuildOnProcessRetInfo_0100 550 * @tc.desc: Test function of BuildOnProcessRetInfo interface for SUCCESS. 551 * @tc.size: MEDIUM 552 * @tc.type: FUNC 553 * @tc.level Level 0 554 * @tc.require: I6F3GV 555 */ 556 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildOnProcessRetInfo_0100, testing::ext::TestSize.Level0) 557 { 558 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildOnProcessRetInfo_0100"; 559 try { 560 std::string jsonStr; 561 std::string onProcessRet = "test result"; 562 563 bool result = BJsonUtil::BuildOnProcessRetInfo(jsonStr, onProcessRet); 564 EXPECT_EQ(true, result); 565 EXPECT_NE(jsonStr.find("timeInfo"), std::string::npos); 566 EXPECT_NE(jsonStr.find("resultInfo"), std::string::npos); 567 } catch (...) { 568 EXPECT_TRUE(false); 569 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 570 } 571 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildOnProcessRetInfo_0100"; 572 } 573 574 /** 575 * @tc.number: b_jsonutil_BuildExtensionErrInfo_0100 576 * @tc.name: b_jsonutil_BuildExtensionErrInfo_0100 577 * @tc.desc: Test function of BuildExtensionErrInfo interface for SUCCESS. 578 * @tc.size: MEDIUM 579 * @tc.type: FUNC 580 * @tc.level Level 0 581 * @tc.require: I6F3GV 582 */ 583 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0100, testing::ext::TestSize.Level0) 584 { 585 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0100"; 586 try { 587 std::string jsonStr; 588 int errCode = 1; 589 std::string errMsg = "error"; 590 591 bool result = BJsonUtil::BuildExtensionErrInfo(jsonStr, errCode, errMsg); 592 EXPECT_EQ(true, result); 593 EXPECT_NE(jsonStr.find("errorCode"), std::string::npos); 594 EXPECT_NE(jsonStr.find("errorInfo"), std::string::npos); 595 EXPECT_NE(jsonStr.find("type"), std::string::npos); 596 } catch (...) { 597 EXPECT_TRUE(false); 598 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 599 } 600 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildExtensionErrInfo_0100"; 601 } 602 603 /** 604 * @tc.number: b_jsonutil_BuildExtensionErrInfo_0200 605 * @tc.name: b_jsonutil_BuildExtensionErrInfo_0200 606 * @tc.desc: Test function of BuildExtensionErrInfo interface for SUCCESS. 607 * @tc.size: MEDIUM 608 * @tc.type: FUNC 609 * @tc.level Level 0 610 * @tc.require: I6F3GV 611 */ 612 HWTEST_F(BJsonUtilTest, b_jsonutil_BuildExtensionErrInfo_0200, testing::ext::TestSize.Level0) 613 { 614 GTEST_LOG_(INFO) << "BJsonUtilTest-begin BuildExtensionErrInfo_0200"; 615 try { 616 std::string jsonStr; 617 std::map<std::string, std::vector<int>> errFileInfo = {{"test", {1, 1}}}; 618 619 bool result = BJsonUtil::BuildExtensionErrInfo(jsonStr, errFileInfo); 620 EXPECT_EQ(true, result); 621 EXPECT_NE(jsonStr.find("errorCode"), std::string::npos); 622 EXPECT_NE(jsonStr.find("errorInfo"), std::string::npos); 623 EXPECT_NE(jsonStr.find("type"), std::string::npos); 624 } catch (...) { 625 EXPECT_TRUE(false); 626 GTEST_LOG_(INFO) << "BJsonUtilTest-an exception occurred."; 627 } 628 GTEST_LOG_(INFO) << "BJsonUtilTest-end BuildExtensionErrInfo_0200"; 629 } 630 } // namespace OHOS::FileManagement::Backup