1 /* 2 * Copyright (c) 2022 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 "json_serializer.h" 17 18 #include <benchmark/benchmark.h> 19 20 using namespace std; 21 using namespace OHOS; 22 using namespace OHOS::AppExecFwk; 23 24 namespace { 25 constexpr int32_t BENCHMARK_TIMES = 1000; 26 27 /** 28 * @tc.name: BenchmarkTestForCustomizeDataToJson 29 * @tc.desc: Testcase for testing 'to_json' function. 30 * @tc.type: FUNC 31 * @tc.require: Issue Number 32 */ BenchmarkTestForCustomizeDataToJson(benchmark::State & state)33 static void BenchmarkTestForCustomizeDataToJson(benchmark::State &state) 34 { 35 nlohmann::json jsonObject; 36 CustomizeData customizeData; 37 customizeData.name = "ohos.global.systemres"; 38 customizeData.value = "1"; 39 customizeData.extra = "/data/accounts/account_0/applications/ohos.global.systemres"; 40 for (auto _ : state) { 41 /* @tc.steps: step1.call to_json in loop */ 42 to_json(jsonObject, customizeData); 43 } 44 } 45 46 /** 47 * @tc.name: BenchmarkTestForCustomizeDataFromJson 48 * @tc.desc: Testcase for testing 'from_json' function. 49 * @tc.type: FUNC 50 * @tc.require: Issue Number 51 */ BenchmarkTestForCustomizeDataFromJson(benchmark::State & state)52 static void BenchmarkTestForCustomizeDataFromJson(benchmark::State &state) 53 { 54 nlohmann::json jsonObject; 55 jsonObject["name"] = "ohos.global.systemres"; 56 jsonObject["value"] = "1"; 57 jsonObject["extra"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 58 CustomizeData customizeData; 59 for (auto _ : state) { 60 /* @tc.steps: step1.call from_json in loop */ 61 from_json(jsonObject, customizeData); 62 } 63 } 64 65 /** 66 * @tc.name: BenchmarkTestForMetaDataToJson 67 * @tc.desc: Testcase for testing 'to_json' function. 68 * @tc.type: FUNC 69 * @tc.require: Issue Number 70 */ BenchmarkTestForMetadataToJson(benchmark::State & state)71 static void BenchmarkTestForMetadataToJson(benchmark::State &state) 72 { 73 nlohmann::json jsonObject; 74 Metadata metadata; 75 metadata.name = "ohos.global.systemres"; 76 metadata.value = "1"; 77 metadata.resource = "/data/accounts/account_0/applications/ohos.global.systemres"; 78 for (auto _ : state) { 79 /* @tc.steps: step1.call to_json in loop */ 80 to_json(jsonObject, metadata); 81 } 82 } 83 84 /** 85 * @tc.name: BenchmarkTestForMetaDataFromJson 86 * @tc.desc: Testcase for testing 'from_json' function. 87 * @tc.type: FUNC 88 * @tc.require: Issue Number 89 */ BenchmarkTestForMetadataFromJson(benchmark::State & state)90 static void BenchmarkTestForMetadataFromJson(benchmark::State &state) 91 { 92 nlohmann::json jsonObject; 93 jsonObject["name"] = "ohos.global.systemres"; 94 jsonObject["value"] = "1"; 95 jsonObject["resource"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 96 Metadata metadata; 97 for (auto _ : state) { 98 /* @tc.steps: step1.call from_json in loop */ 99 from_json(jsonObject, metadata); 100 } 101 } 102 103 /** 104 * @tc.name: BenchmarkTestForAbilityInfoToJson 105 * @tc.desc: Testcase for testing 'to_json' function. 106 * @tc.type: FUNC 107 * @tc.require: Issue Number 108 */ BenchmarkTestForAbilityInfoToJson(benchmark::State & state)109 static void BenchmarkTestForAbilityInfoToJson(benchmark::State &state) 110 { 111 nlohmann::json jsonObject; 112 AbilityInfo abilityInfo; 113 abilityInfo.name = "ohos.global.systemres"; 114 abilityInfo.label = "1"; 115 abilityInfo.description = "/data/accounts/account_0/applications/ohos.global.systemres"; 116 for (auto _ : state) { 117 /* @tc.steps: step1.call to_json in loop */ 118 to_json(jsonObject, abilityInfo); 119 } 120 } 121 122 /** 123 * @tc.name: BenchmarkTestForAbilityInfoFromJson 124 * @tc.desc: Testcase for testing 'from_json' function. 125 * @tc.type: FUNC 126 * @tc.require: Issue Number 127 */ BenchmarkTestForAbilityInfoFromJson(benchmark::State & state)128 static void BenchmarkTestForAbilityInfoFromJson(benchmark::State &state) 129 { 130 nlohmann::json jsonObject; 131 jsonObject["name"] = "ohos.global.systemres"; 132 jsonObject["label"] = "1"; 133 jsonObject["description"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 134 AbilityInfo abilityInfo; 135 for (auto _ : state) { 136 /* @tc.steps: step1.call from_json in loop */ 137 from_json(jsonObject, abilityInfo); 138 } 139 } 140 141 /** 142 * @tc.name: BenchmarkTestForExtensionAbilityInfoToJson 143 * @tc.desc: Testcase for testing 'to_json' function. 144 * @tc.type: FUNC 145 * @tc.require: Issue Number 146 */ BenchmarkTestForExtensionAbilityInfoToJson(benchmark::State & state)147 static void BenchmarkTestForExtensionAbilityInfoToJson(benchmark::State &state) 148 { 149 nlohmann::json jsonObject; 150 ExtensionAbilityInfo extensionInfo; 151 extensionInfo.name = "ohos.global.systemres"; 152 extensionInfo.icon = "1"; 153 extensionInfo.description = "/data/accounts/account_0/applications/ohos.global.systemres"; 154 for (auto _ : state) { 155 /* @tc.steps: step1.call to_json in loop */ 156 to_json(jsonObject, extensionInfo); 157 } 158 } 159 160 /** 161 * @tc.name: BenchmarkTestForExtensionAbilityInfoFromJson 162 * @tc.desc: Testcase for testing 'from_json' function. 163 * @tc.type: FUNC 164 * @tc.require: Issue Number 165 */ BenchmarkTestForExtensionAbilityInfoFromJson(benchmark::State & state)166 static void BenchmarkTestForExtensionAbilityInfoFromJson(benchmark::State &state) 167 { 168 nlohmann::json jsonObject; 169 jsonObject["name"] = "ohos.global.systemres"; 170 jsonObject["icon"] = "1"; 171 jsonObject["description"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 172 ExtensionAbilityInfo extensionInfo; 173 for (auto _ : state) { 174 /* @tc.steps: step1.call from_json in loop */ 175 from_json(jsonObject, extensionInfo); 176 } 177 } 178 179 /** 180 * @tc.name: BenchmarkTestForApplicationInfoToJson 181 * @tc.desc: Testcase for testing 'to_json' function. 182 * @tc.type: FUNC 183 * @tc.require: Issue Number 184 */ BenchmarkTestForApplicationInfoToJson(benchmark::State & state)185 static void BenchmarkTestForApplicationInfoToJson(benchmark::State &state) 186 { 187 nlohmann::json jsonObject; 188 ApplicationInfo applicationInfo; 189 applicationInfo.name = "ohos.global.systemres"; 190 applicationInfo.label = "1"; 191 applicationInfo.iconPath = "/data/accounts/account_0/applications/ohos.global.systemres"; 192 for (auto _ : state) { 193 /* @tc.steps: step1.call to_json in loop */ 194 to_json(jsonObject, applicationInfo); 195 } 196 } 197 198 /** 199 * @tc.name: BenchmarkTestForApplicationInfoFromJson 200 * @tc.desc: Testcase for testing 'from_json' function. 201 * @tc.type: FUNC 202 * @tc.require: Issue Number 203 */ BenchmarkTestForApplicationInfoFromJson(benchmark::State & state)204 static void BenchmarkTestForApplicationInfoFromJson(benchmark::State &state) 205 { 206 nlohmann::json jsonObject; 207 jsonObject["name"] = "ohos.global.systemres"; 208 jsonObject["label"] = "1"; 209 jsonObject["iconPath"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 210 ApplicationInfo applicationInfo; 211 for (auto _ : state) { 212 /* @tc.steps: step1.call from_json in loop */ 213 from_json(jsonObject, applicationInfo); 214 } 215 } 216 217 /** 218 * @tc.name: BenchmarkTestForBundleInfoToJson 219 * @tc.desc: Testcase for testing 'to_json' function. 220 * @tc.type: FUNC 221 * @tc.require: Issue Number 222 */ BenchmarkTestForBundleInfoToJson(benchmark::State & state)223 static void BenchmarkTestForBundleInfoToJson(benchmark::State &state) 224 { 225 nlohmann::json jsonObject; 226 BundleInfo bundleInfo; 227 bundleInfo.name = "ohos.global.systemres"; 228 bundleInfo.appId = "1"; 229 bundleInfo.entryModuleName = "ohos.global.systemres.MainAbility"; 230 for (auto _ : state) { 231 /* @tc.steps: step1.call to_json in loop */ 232 to_json(jsonObject, bundleInfo); 233 } 234 } 235 236 /** 237 * @tc.name: BenchmarkTestForApplicationInfoFromJson 238 * @tc.desc: Testcase for testing 'from_json' function. 239 * @tc.type: FUNC 240 * @tc.require: Issue Number 241 */ BenchmarkTestForBundleInfoFromJson(benchmark::State & state)242 static void BenchmarkTestForBundleInfoFromJson(benchmark::State &state) 243 { 244 nlohmann::json jsonObject; 245 jsonObject["name"] = "ohos.global.systemres"; 246 jsonObject["appId"] = "1"; 247 jsonObject["entryModuleName"] = "ohos.global.systemres.MainAbility"; 248 BundleInfo bundleInfo; 249 for (auto _ : state) { 250 /* @tc.steps: step1.call from_json in loop */ 251 from_json(jsonObject, bundleInfo); 252 } 253 } 254 255 /** 256 * @tc.name: BenchmarkTestForModuleInfoToJson 257 * @tc.desc: Testcase for testing 'to_json' function. 258 * @tc.type: FUNC 259 * @tc.require: Issue Number 260 */ BenchmarkTestForModuleInfoToJson(benchmark::State & state)261 static void BenchmarkTestForModuleInfoToJson(benchmark::State &state) 262 { 263 nlohmann::json jsonObject; 264 ModuleInfo moduleInfo; 265 moduleInfo.moduleName = "ohos.global.systemres"; 266 moduleInfo.moduleSourceDir = "/data/accounts/account_0/applications/ohos.global.systemres"; 267 for (auto _ : state) { 268 /* @tc.steps: step1.call to_json in loop */ 269 to_json(jsonObject, moduleInfo); 270 } 271 } 272 273 /** 274 * @tc.name: BenchmarkTestForModuleInfoFromJson 275 * @tc.desc: Testcase for testing 'from_json' function. 276 * @tc.type: FUNC 277 * @tc.require: Issue Number 278 */ BenchmarkTestForModuleInfoFromJson(benchmark::State & state)279 static void BenchmarkTestForModuleInfoFromJson(benchmark::State &state) 280 { 281 nlohmann::json jsonObject; 282 jsonObject["moduleName"] = "ohos.global.systemres"; 283 jsonObject["moduleSourceDir"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 284 ModuleInfo moduleInfo; 285 for (auto _ : state) { 286 /* @tc.steps: step1.call from_json in loop */ 287 from_json(jsonObject, moduleInfo); 288 } 289 } 290 291 /** 292 * @tc.name: BenchmarkTestForFormInfoToJson 293 * @tc.desc: Testcase for testing 'to_json' function. 294 * @tc.type: FUNC 295 * @tc.require: Issue Number 296 */ BenchmarkTestForFormInfoToJson(benchmark::State & state)297 static void BenchmarkTestForFormInfoToJson(benchmark::State &state) 298 { 299 nlohmann::json jsonObject; 300 FormInfo formInfo; 301 formInfo.name = "ohos.global.systemres"; 302 formInfo.description = "1"; 303 formInfo.src = "/data/accounts/account_0/applications/ohos.global.systemres"; 304 for (auto _ : state) { 305 /* @tc.steps: step1.call to_json in loop */ 306 to_json(jsonObject, formInfo); 307 } 308 } 309 310 /** 311 * @tc.name: BenchmarkTestForFormInfoFromJson 312 * @tc.desc: Testcase for testing 'from_json' function. 313 * @tc.type: FUNC 314 * @tc.require: Issue Number 315 */ BenchmarkTestForFormInfoFromJson(benchmark::State & state)316 static void BenchmarkTestForFormInfoFromJson(benchmark::State &state) 317 { 318 nlohmann::json jsonObject; 319 FormInfo formInfo; 320 formInfo.name = "ohos.global.systemres"; 321 formInfo.description = "1"; 322 formInfo.src = "/data/accounts/account_0/applications/ohos.global.systemres"; 323 to_json(jsonObject, formInfo); 324 FormInfo formInfoTest; 325 326 for (auto _ : state) { 327 /* @tc.steps: step1.call from_json in loop */ 328 from_json(jsonObject, formInfoTest); 329 } 330 } 331 332 /** 333 * @tc.name: BenchmarkTestForShortcutInfoToJson 334 * @tc.desc: Testcase for testing 'to_json' function. 335 * @tc.type: FUNC 336 * @tc.require: Issue Number 337 */ BenchmarkTestForShortcutInfoToJson(benchmark::State & state)338 static void BenchmarkTestForShortcutInfoToJson(benchmark::State &state) 339 { 340 nlohmann::json jsonObject; 341 ShortcutInfo shortcutInfo; 342 shortcutInfo.bundleName = "ohos_global_systemres"; 343 shortcutInfo.id = "1"; 344 shortcutInfo.disableMessage = "/data/accounts/account_0/applications/ohos.global.systemres"; 345 for (auto _ : state) { 346 /* @tc.steps: step1.call to_json in loop */ 347 to_json(jsonObject, shortcutInfo); 348 } 349 } 350 351 /** 352 * @tc.name: BenchmarkTestForShortcutInfoFromJson 353 * @tc.desc: Testcase for testing 'from_json' function. 354 * @tc.type: FUNC 355 * @tc.require: Issue Number 356 */ BenchmarkTestForShortcutInfoFromJson(benchmark::State & state)357 static void BenchmarkTestForShortcutInfoFromJson(benchmark::State &state) 358 { 359 nlohmann::json jsonObject; 360 jsonObject["bundleName"] = "ohos_global_systemres"; 361 jsonObject["id"] = "1"; 362 jsonObject["disableMessage"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 363 ShortcutInfo shortcutInfo; 364 for (auto _ : state) { 365 /* @tc.steps: step1.call from_json in loop */ 366 from_json(jsonObject, shortcutInfo); 367 } 368 } 369 370 /** 371 * @tc.name: BenchmarkTestForCommonEventInfoToJson 372 * @tc.desc: Testcase for testing 'to_json' function. 373 * @tc.type: FUNC 374 * @tc.require: Issue Number 375 */ BenchmarkTestForCommonEventInfoToJson(benchmark::State & state)376 static void BenchmarkTestForCommonEventInfoToJson(benchmark::State &state) 377 { 378 nlohmann::json jsonObject; 379 CommonEventInfo commonEvent; 380 commonEvent.name = "ohos.global.systemres"; 381 commonEvent.permission = "1"; 382 commonEvent.bundleName = "ohos_global_systemres"; 383 for (auto _ : state) { 384 /* @tc.steps: step1.call to_json in loop */ 385 to_json(jsonObject, commonEvent); 386 } 387 } 388 389 /** 390 * @tc.name: BenchmarkTestForCommonEventInfoFromJson 391 * @tc.desc: Testcase for testing 'from_json' function. 392 * @tc.type: FUNC 393 * @tc.require: Issue Number 394 */ BenchmarkTestForCommonEventInfoFromJson(benchmark::State & state)395 static void BenchmarkTestForCommonEventInfoFromJson(benchmark::State &state) 396 { 397 nlohmann::json jsonObject; 398 std::vector<std::string> data; 399 std::vector<std::string> type; 400 std::vector<std::string> events; 401 jsonObject["name"] = "ohos.global.systemres"; 402 jsonObject["permission"] = "1"; 403 jsonObject["bundleName"] = "ohos_global_systemres"; 404 jsonObject["uid"] = -1; 405 jsonObject["data"] = data; 406 jsonObject["type"] = type; 407 jsonObject["events"] = events; 408 CommonEventInfo commonEvent; 409 for (auto _ : state) { 410 /* @tc.steps: step1.call from_json in loop */ 411 from_json(jsonObject, commonEvent); 412 } 413 } 414 415 /** 416 * @tc.name: BenchmarkTestForHapModuleInfoToJson 417 * @tc.desc: Testcase for testing 'to_json' function. 418 * @tc.type: FUNC 419 * @tc.require: Issue Number 420 */ BenchmarkTestForHapModuleInfoToJson(benchmark::State & state)421 static void BenchmarkTestForHapModuleInfoToJson(benchmark::State &state) 422 { 423 nlohmann::json jsonObject; 424 HapModuleInfo hapModuleInfo; 425 hapModuleInfo.name = "ohos.global.systemres"; 426 hapModuleInfo.label = "1"; 427 hapModuleInfo.srcPath = "/data/accounts/account_0/applications/ohos.global.systemres"; 428 for (auto _ : state) { 429 /* @tc.steps: step1.call to_json in loop */ 430 to_json(jsonObject, hapModuleInfo); 431 } 432 } 433 434 /** 435 * @tc.name: BenchmarkTestForHapModuleInfoFromJson 436 * @tc.desc: Testcase for testing 'from_json' function. 437 * @tc.type: FUNC 438 * @tc.require: Issue Number 439 */ BenchmarkTestForHapModuleInfoFromJson(benchmark::State & state)440 static void BenchmarkTestForHapModuleInfoFromJson(benchmark::State &state) 441 { 442 nlohmann::json jsonObject; 443 jsonObject["name"] = "ohos.global.systemres"; 444 jsonObject["label"] = "1"; 445 jsonObject["srcPath"] = "/data/accounts/account_0/applications/ohos.global.systemres"; 446 HapModuleInfo hapModuleInfo; 447 for (auto _ : state) { 448 /* @tc.steps: step1.call from_json in loop */ 449 from_json(jsonObject, hapModuleInfo); 450 } 451 } 452 453 /** 454 * @tc.name: BenchmarkTestForBundleUserInfoToJson 455 * @tc.desc: Testcase for testing 'to_json' function. 456 * @tc.type: FUNC 457 * @tc.require: Issue Number 458 */ BenchmarkTestForBundleUserInfoToJson(benchmark::State & state)459 static void BenchmarkTestForBundleUserInfoToJson(benchmark::State &state) 460 { 461 nlohmann::json jsonObject; 462 BundleUserInfo bundleUserInfo; 463 bundleUserInfo.disabledAbilities = {"ohos.global.systemres.MainAbility"}; 464 for (auto _ : state) { 465 /* @tc.steps: step1.call to_json in loop */ 466 to_json(jsonObject, bundleUserInfo); 467 } 468 } 469 470 /** 471 * @tc.name: BenchmarkTestForBundleUserInfoFromJson 472 * @tc.desc: Testcase for testing 'from_json' function. 473 * @tc.type: FUNC 474 * @tc.require: Issue Number 475 */ BenchmarkTestForBundleUserInfoFromJson(benchmark::State & state)476 static void BenchmarkTestForBundleUserInfoFromJson(benchmark::State &state) 477 { 478 nlohmann::json jsonObject; 479 jsonObject["abilities"] = {"ohos.global.systemres.MainAbility"}; 480 jsonObject["disabledAbilities"] = {"ohos.global.systemres.MainAbility"}; 481 BundleUserInfo bundleUserInfo; 482 for (auto _ : state) { 483 /* @tc.steps: step1.call from_json in loop */ 484 from_json(jsonObject, bundleUserInfo); 485 } 486 } 487 488 /** 489 * @tc.name: BenchmarkTestForShortcutWantFromJson 490 * @tc.desc: Testcase for testing 'from_json' function. 491 * @tc.type: FUNC 492 * @tc.require: Issue Number 493 */ BenchmarkTestForShortcutWantFromJson(benchmark::State & state)494 static void BenchmarkTestForShortcutWantFromJson(benchmark::State &state) 495 { 496 nlohmann::json jsonObject; 497 jsonObject["bundleName"] = "ohos_global_systemres"; 498 jsonObject["abilityName"] = "ohos.global.systemres.MainAbility"; 499 ShortcutWant shortcutWant; 500 for (auto _ : state) { 501 /* @tc.steps: step1.call from_json in loop */ 502 from_json(jsonObject, shortcutWant); 503 } 504 } 505 506 /** 507 * @tc.name: BenchmarkTestForShortcutFromJson 508 * @tc.desc: Testcase for testing 'from_json' function. 509 * @tc.type: FUNC 510 * @tc.require: Issue Number 511 */ BenchmarkTestForShortcutFromJson(benchmark::State & state)512 static void BenchmarkTestForShortcutFromJson(benchmark::State &state) 513 { 514 nlohmann::json jsonObject; 515 jsonObject["shortcutId"] = "1"; 516 jsonObject["label"] = "1"; 517 jsonObject["icon"] = "1"; 518 Shortcut shortcut; 519 for (auto _ : state) { 520 /* @tc.steps: step1.call from_json in loop */ 521 from_json(jsonObject, shortcut); 522 } 523 } 524 525 /** 526 * @tc.name: BenchmarkTestForShortcutJsonFromJson 527 * @tc.desc: Testcase for testing 'from_json' function. 528 * @tc.type: FUNC 529 * @tc.require: Issue Number 530 */ BenchmarkTestForShortcutJsonFromJson(benchmark::State & state)531 static void BenchmarkTestForShortcutJsonFromJson(benchmark::State &state) 532 { 533 nlohmann::json jsonObject; 534 jsonObject["shortcuts"] = {"ohos_global_systemres"}; 535 ShortcutJson shortcutJson; 536 for (auto _ : state) { 537 /* @tc.steps: step1.call from_json in loop */ 538 from_json(jsonObject, shortcutJson); 539 } 540 } 541 542 /** 543 * @tc.name: BenchmarkTestForReqPermissionUsedSceToJson 544 * @tc.desc: Testcase for testing 'to_json' function. 545 * @tc.type: FUNC 546 * @tc.require: Issue Number 547 */ BenchmarkTestForReqPermissionUsedSceToJson(benchmark::State & state)548 static void BenchmarkTestForReqPermissionUsedSceToJson(benchmark::State &state) 549 { 550 nlohmann::json jsonObject; 551 RequestPermissionUsedScene usedScene; 552 usedScene.abilities = {"ohos.global.systemres.MainAbility"}; 553 usedScene.when = "1"; 554 for (auto _ : state) { 555 /* @tc.steps: step1.call to_json in loop */ 556 to_json(jsonObject, usedScene); 557 } 558 } 559 560 /** 561 * @tc.name: BenchmarkTestForReqPermissionUsedSceFromJson 562 * @tc.desc: Testcase for testing 'from_json' function. 563 * @tc.type: FUNC 564 * @tc.require: Issue Number 565 */ BenchmarkTestForReqPermissionUsedSceFromJson(benchmark::State & state)566 static void BenchmarkTestForReqPermissionUsedSceFromJson(benchmark::State &state) 567 { 568 nlohmann::json jsonObject; 569 jsonObject["abilities"] = {"ohos.global.systemres.MainAbility"}; 570 jsonObject["when"] = "1"; 571 RequestPermissionUsedScene usedScene; 572 for (auto _ : state) { 573 /* @tc.steps: step1.call from_json in loop */ 574 from_json(jsonObject, usedScene); 575 } 576 } 577 578 /** 579 * @tc.name: BenchmarkTestForRequestPermissionToJson 580 * @tc.desc: Testcase for testing 'to_json' function. 581 * @tc.type: FUNC 582 * @tc.require: Issue Number 583 */ BenchmarkTestForRequestPermissionToJson(benchmark::State & state)584 static void BenchmarkTestForRequestPermissionToJson(benchmark::State &state) 585 { 586 nlohmann::json jsonObject; 587 RequestPermission requestPermission; 588 requestPermission.name = "ohos.global.systemres"; 589 requestPermission.reason = "1"; 590 for (auto _ : state) { 591 /* @tc.steps: step1.call to_json in loop */ 592 to_json(jsonObject, requestPermission); 593 } 594 } 595 596 /** 597 * @tc.name: BenchmarkTestForRequestPermissionFromJson 598 * @tc.desc: Testcase for testing 'from_json' function. 599 * @tc.type: FUNC 600 * @tc.require: Issue Number 601 */ BenchmarkTestForRequestPermissionFromJson(benchmark::State & state)602 static void BenchmarkTestForRequestPermissionFromJson(benchmark::State &state) 603 { 604 nlohmann::json jsonObject; 605 jsonObject["name"] = "ohos.global.systemres"; 606 jsonObject["reason"] = "1"; 607 RequestPermission requestPermission; 608 for (auto _ : state) { 609 /* @tc.steps: step1.call from_json in loop */ 610 from_json(jsonObject, requestPermission); 611 } 612 } 613 614 BENCHMARK(BenchmarkTestForCustomizeDataToJson)->Iterations(BENCHMARK_TIMES); 615 BENCHMARK(BenchmarkTestForCustomizeDataFromJson)->Iterations(BENCHMARK_TIMES); 616 BENCHMARK(BenchmarkTestForMetadataToJson)->Iterations(BENCHMARK_TIMES); 617 BENCHMARK(BenchmarkTestForMetadataFromJson)->Iterations(BENCHMARK_TIMES); 618 BENCHMARK(BenchmarkTestForAbilityInfoToJson)->Iterations(BENCHMARK_TIMES); 619 BENCHMARK(BenchmarkTestForAbilityInfoFromJson)->Iterations(BENCHMARK_TIMES); 620 BENCHMARK(BenchmarkTestForExtensionAbilityInfoToJson)->Iterations(BENCHMARK_TIMES); 621 BENCHMARK(BenchmarkTestForExtensionAbilityInfoFromJson)->Iterations(BENCHMARK_TIMES); 622 BENCHMARK(BenchmarkTestForApplicationInfoToJson)->Iterations(BENCHMARK_TIMES); 623 BENCHMARK(BenchmarkTestForApplicationInfoFromJson)->Iterations(BENCHMARK_TIMES); 624 BENCHMARK(BenchmarkTestForBundleInfoToJson)->Iterations(BENCHMARK_TIMES); 625 BENCHMARK(BenchmarkTestForBundleInfoFromJson)->Iterations(BENCHMARK_TIMES); 626 BENCHMARK(BenchmarkTestForModuleInfoToJson)->Iterations(BENCHMARK_TIMES); 627 BENCHMARK(BenchmarkTestForModuleInfoFromJson)->Iterations(BENCHMARK_TIMES); 628 BENCHMARK(BenchmarkTestForFormInfoToJson)->Iterations(BENCHMARK_TIMES); 629 BENCHMARK(BenchmarkTestForFormInfoFromJson)->Iterations(BENCHMARK_TIMES); 630 BENCHMARK(BenchmarkTestForShortcutInfoToJson)->Iterations(BENCHMARK_TIMES); 631 BENCHMARK(BenchmarkTestForShortcutInfoFromJson)->Iterations(BENCHMARK_TIMES); 632 BENCHMARK(BenchmarkTestForCommonEventInfoToJson)->Iterations(BENCHMARK_TIMES); 633 BENCHMARK(BenchmarkTestForCommonEventInfoFromJson)->Iterations(BENCHMARK_TIMES); 634 BENCHMARK(BenchmarkTestForHapModuleInfoToJson)->Iterations(BENCHMARK_TIMES); 635 BENCHMARK(BenchmarkTestForHapModuleInfoFromJson)->Iterations(BENCHMARK_TIMES); 636 BENCHMARK(BenchmarkTestForBundleUserInfoToJson)->Iterations(BENCHMARK_TIMES); 637 BENCHMARK(BenchmarkTestForBundleUserInfoFromJson)->Iterations(BENCHMARK_TIMES); 638 BENCHMARK(BenchmarkTestForShortcutWantFromJson)->Iterations(BENCHMARK_TIMES); 639 BENCHMARK(BenchmarkTestForShortcutFromJson)->Iterations(BENCHMARK_TIMES); 640 BENCHMARK(BenchmarkTestForShortcutJsonFromJson)->Iterations(BENCHMARK_TIMES); 641 BENCHMARK(BenchmarkTestForReqPermissionUsedSceToJson)->Iterations(BENCHMARK_TIMES); 642 BENCHMARK(BenchmarkTestForReqPermissionUsedSceFromJson)->Iterations(BENCHMARK_TIMES); 643 BENCHMARK(BenchmarkTestForRequestPermissionToJson)->Iterations(BENCHMARK_TIMES); 644 BENCHMARK(BenchmarkTestForRequestPermissionFromJson)->Iterations(BENCHMARK_TIMES); 645 } 646 647 BENCHMARK_MAIN();