1 /* 2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #include <gtest/gtest.h> 16 #include <memory> 17 #include "form_caller_mgr.h" 18 #define private public 19 #define protected public 20 #include "form_mgr.h" 21 #include "form_errors.h" 22 #include "iservice_registry.h" 23 #undef private 24 #undef protected 25 #include "form_mgr_errors.h" 26 #include "mock_form_provider_client.h" 27 #include "gmock/gmock.h" 28 #include "mock_form_mgr_proxy.h" 29 #include "mock_form_token.h" 30 #include "if_system_ability_manager.h" 31 #include "mock_system_ability_manager.h" 32 #include "mock_i_remote_object.h" 33 #include "fms_log_wrapper.h" 34 35 using namespace testing::ext; 36 using namespace OHOS; 37 using namespace OHOS::AppExecFwk; 38 39 using ::testing::Return; 40 using ::testing::SetArgReferee; 41 using ::testing::ContainerEq; 42 using ::testing::_; 43 using ::testing::DoAll; 44 45 // overload operator for ContainerEq 46 namespace OHOS::AppExecFwk { operator ==(const FormInfo & lhs,const FormInfo & rhs)47 bool operator==(const FormInfo& lhs, const FormInfo& rhs) 48 { 49 if (lhs.bundleName != rhs.bundleName) { 50 return false; 51 } 52 if (lhs.moduleName != rhs.moduleName) { 53 return false; 54 } 55 if (lhs.name != rhs.name) { 56 return false; 57 } 58 // to be continued... 59 return true; 60 } 61 } 62 63 namespace { 64 const std::int32_t ERROR_NUM = 2293778; 65 const std::int32_t ERROR_NUMS = 8388610; 66 const std::int32_t NEGATIVE_NUM = -1; 67 const std::int32_t POSITIVE_NUM = 1; 68 class FormMgrTest : public testing::Test { 69 public: 70 // TestSuite setup has to be static SetUpTestCase()71 static void SetUpTestCase() 72 { 73 if (mockProxy == nullptr) { 74 GTEST_LOG_(INFO) << "SetUpTestCase"; 75 sptr<IRemoteObject> impl = nullptr; 76 mockProxy = new (std::nothrow) MockFormMgrProxy(impl); 77 FormMgr::GetInstance().SetFormMgrService(mockProxy); 78 } 79 } 80 // TearDown is unnecessary. 81 // TestSuite setup has to be static 82 static sptr<MockFormMgrProxy> mockProxy; 83 }; 84 // initialize static variable. 85 sptr<MockFormMgrProxy> FormMgrTest::mockProxy = nullptr; 86 87 /** 88 * @tc.name: FormMgrTest_0001 89 * @tc.desc: Verify GetFormsInfo 90 * @tc.type: FUNC 91 * @tc.require: #I59O23 92 */ 93 HWTEST_F(FormMgrTest, FormMgrTest_0001, TestSize.Level1) { 94 GTEST_LOG_(INFO) << "FormMgrTest_0001 starts"; 95 // initialize input parameters. 96 FormInfoFilter filter; 97 filter.moduleName = ""; 98 std::vector<FormInfo> formInfos; 99 // setup expectations. 100 std::vector<FormInfo> expectFormInfos; 101 FormInfo formInfo = {}; 102 formInfo.bundleName = "ohos.samples.FormApplication"; 103 expectFormInfos.push_back(formInfo); 104 EXPECT_CALL(*mockProxy, GetFormsInfo(_, _)) 105 .Times(1) 106 .WillOnce(DoAll(SetArgReferee<1>(expectFormInfos), Return(ERR_OK))); 107 // test. 108 FormMgr::GetInstance().GetFormsInfo(filter, formInfos); 109 // expect result. 110 EXPECT_THAT(formInfos, ContainerEq(expectFormInfos)); 111 // FormMgr is a singleton, therefore, deleteing it will cause segfault for other invocations. 112 testing::Mock::AllowLeak(mockProxy); 113 GTEST_LOG_(INFO) << "FormMgrTest_0001 test ends"; 114 } 115 116 /** 117 * @tc.name: FormMgrTest_0002 118 * @tc.desc: Verify GetFormsInfo 119 * @tc.type: FUNC 120 * @tc.require: #I59O23 121 */ 122 HWTEST_F(FormMgrTest, FormMgrTest_0002, TestSize.Level1) { 123 GTEST_LOG_(INFO) << "FormMgrTest_0002 starts"; 124 // initialize input parameters. 125 FormInfoFilter filter; 126 filter.moduleName = "empty"; 127 std::vector<FormInfo> formInfos; 128 // setup expectations. 129 std::vector<FormInfo> expectFormInfos; 130 FormInfo formInfo = {}; 131 formInfo.bundleName = "ohos.samples.FormApplication"; 132 formInfo.moduleName = "entry"; 133 expectFormInfos.push_back(formInfo); 134 EXPECT_CALL(*mockProxy, GetFormsInfo(_, _)) 135 .Times(1) 136 .WillOnce(Return(ERR_OK)); 137 // test. 138 FormMgr::GetInstance().GetFormsInfo(filter, formInfos); 139 // expect result. 140 EXPECT_EQ(formInfos.size(), 0); 141 testing::Mock::AllowLeak(mockProxy); 142 GTEST_LOG_(INFO) << "FormMgrTest_0002 test ends"; 143 } 144 145 /** 146 * @tc.name: FormMgrTest_0003 147 * @tc.desc: Verify IsRequestPublishFormSupported 148 * @tc.type: FUNC 149 * @tc.require: #I58Y0A 150 */ 151 HWTEST_F(FormMgrTest, FormMgrTest_0003, TestSize.Level1) { 152 GTEST_LOG_(INFO) << "FormMgrTest_0003 starts"; 153 EXPECT_CALL(*mockProxy, IsRequestPublishFormSupported()) 154 .Times(1) 155 .WillOnce(Return(false)); 156 bool result = FormMgr::GetInstance().IsRequestPublishFormSupported(); 157 EXPECT_EQ(result, false); 158 GTEST_LOG_(INFO) << "FormMgrTest_0003 test ends"; 159 } 160 161 /** 162 * @tc.name: FormMgrTest_0004 163 * @tc.desc: Verify StartAbility 164 * @tc.type: FUNC 165 * @tc.require: #I5EFDX 166 */ 167 HWTEST_F(FormMgrTest, FormMgrTest_0004, TestSize.Level1) { 168 GTEST_LOG_(INFO) << "FormMgrTest_0004 starts"; 169 EXPECT_CALL(*mockProxy, StartAbility(_, _)) 170 .Times(1) 171 .WillOnce(Return(0)); 172 Want want; 173 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 174 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 175 int32_t result = FormMgr::GetInstance().StartAbility(want, token); 176 EXPECT_EQ(result, 0); 177 GTEST_LOG_(INFO) << "FormMgrTest_0004 test ends"; 178 } 179 180 /** 181 * @tc.name: FormMgrTest_0005 182 * @tc.desc: Verify UpdateForm 183 * @tc.type: FUNC 184 * @tc.require: issueI5PFT9 185 */ 186 HWTEST_F(FormMgrTest, FormMgrTest_0005, TestSize.Level1) { 187 GTEST_LOG_(INFO) << "FormMgrTest_0005 starts"; 188 EXPECT_CALL(*mockProxy, UpdateForm(_, _)) 189 .Times(1) 190 .WillOnce(Return(0)); 191 FormJsInfo formJsInfo; 192 formJsInfo.formId = 1; 193 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 194 sptr<IRemoteObject> providerToken = new (std::nothrow) MockFormProviderClient(); 195 FormCallerMgr::GetInstance().AddFormHostCaller(formJsInfo, providerToken); 196 FormProviderData formProviderData = FormProviderData(std::string("{\"city\": \"beijing001\"}")); 197 int32_t result = FormMgr::GetInstance().UpdateForm(formJsInfo.formId, formProviderData); 198 EXPECT_EQ(result, 0); 199 GTEST_LOG_(INFO) << "FormMgrTest_0005 test ends"; 200 } 201 202 /** 203 * @tc.name: FormMgrTest_0006 204 * @tc.desc: Verify RequestForm 205 * @tc.type: FUNC 206 * @tc.require: issueI5Q8IU 207 */ 208 HWTEST_F(FormMgrTest, FormMgrTest_0006, TestSize.Level1) { 209 GTEST_LOG_(INFO) << "FormMgrTest_0006 starts"; 210 EXPECT_CALL(*mockProxy, RequestForm(_, _, _)) 211 .Times(1) 212 .WillOnce(Return(0)); 213 Want want; 214 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 215 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 216 FormJsInfo formJsInfo; 217 formJsInfo.formId = 1; 218 sptr<IRemoteObject> providerToken = new (std::nothrow) MockFormProviderClient(); 219 FormCallerMgr::GetInstance().AddFormHostCaller(formJsInfo, providerToken); 220 int32_t result = FormMgr::GetInstance().RequestForm(formJsInfo.formId, token, want); 221 EXPECT_EQ(result, 0); 222 GTEST_LOG_(INFO) << "FormMgrTest_0006 test ends"; 223 } 224 225 /** 226 * @tc.name: FormMgrTest_0007 227 * @tc.desc: Verify MessageEvent 228 * @tc.type: FUNC 229 * @tc.require: issueI5QGMS 230 */ 231 HWTEST_F(FormMgrTest, FormMgrTest_0007, TestSize.Level1) { 232 GTEST_LOG_(INFO) << "FormMgrTest_0007 starts"; 233 EXPECT_CALL(*mockProxy, MessageEvent(_, _, _)) 234 .Times(1) 235 .WillOnce(Return(0)); 236 Want want; 237 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 238 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 239 FormJsInfo formJsInfo; 240 sptr<IRemoteObject> providerToken = new (std::nothrow) MockFormProviderClient(); 241 FormCallerMgr::GetInstance().AddFormHostCaller(formJsInfo, providerToken); 242 int32_t result = FormMgr::GetInstance().MessageEvent(formJsInfo.formId, want, token); 243 EXPECT_EQ(result, 0); 244 GTEST_LOG_(INFO) << "FormMgrTest_0007 test ends"; 245 } 246 247 /** 248 * @tc.name: FormMgrTest_0005 249 * @tc.desc: Verify NotifyFormsPrivacyProtected 250 * @tc.type: FUNC 251 * @tc.require: I5ST27 252 */ 253 HWTEST_F(FormMgrTest, FormMgrTest_0008, TestSize.Level1) { 254 GTEST_LOG_(INFO) << "FormMgrTest_0008 starts"; 255 EXPECT_CALL(*mockProxy, NotifyFormsPrivacyProtected(_, _, _)) 256 .Times(1) 257 .WillOnce(Return(0)); 258 // initialize input parameters. 259 int64_t formId = 1; 260 std::vector<int64_t> formIds; 261 formIds.push_back(formId); 262 bool isProtected = false; 263 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 264 int32_t result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 265 // expect result. 266 EXPECT_EQ(result, 0); 267 GTEST_LOG_(INFO) << "FormMgrTest_0008 test ends"; 268 } 269 270 /** 271 * @tc.name: FormMgrTest_0006 272 * @tc.desc: Verify NotifyFormsPrivacyProtected 273 * @tc.type: FUNC 274 * @tc.require: I5ST27 275 */ 276 HWTEST_F(FormMgrTest, FormMgrTest_0009, TestSize.Level1) { 277 GTEST_LOG_(INFO) << "FormMgrTest_0009 starts"; 278 EXPECT_CALL(*mockProxy, NotifyFormsPrivacyProtected(_, _, _)) 279 .Times(1) 280 .WillOnce(Return(0)); 281 // initialize input parameters. 282 int64_t formId = 2; 283 std::vector<int64_t> formIds; 284 formIds.push_back(formId); 285 bool isProtected = true; 286 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 287 int32_t result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 288 // expect result. 289 EXPECT_EQ(result, 0); 290 GTEST_LOG_(INFO) << "FormMgrTest_0009 test ends"; 291 } 292 293 /** 294 * @tc.name: FormMgrTest_0007 295 * @tc.desc: Verify NotifyFormsPrivacyProtected 296 * @tc.type: FUNC 297 * @tc.require: I5ST27 298 */ 299 HWTEST_F(FormMgrTest, FormMgrTest_0010, TestSize.Level1) { 300 GTEST_LOG_(INFO) << "FormMgrTest_0010 starts"; 301 EXPECT_CALL(*mockProxy, NotifyFormsPrivacyProtected(_, _, _)) 302 .Times(1) 303 .WillOnce(Return(0)); 304 // initialize input parameters. 305 int64_t formId1 = 3; 306 int64_t formId2 = 4; 307 std::vector<int64_t> formIds; 308 formIds.push_back(formId1); 309 formIds.push_back(formId2); 310 bool isProtected = false; 311 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 312 int32_t result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 313 // expect result. 314 EXPECT_EQ(result, 0); 315 GTEST_LOG_(INFO) << "FormMgrTest_0010 test ends"; 316 } 317 318 /** 319 * @tc.name: FormMgrTest_0011 320 * @tc.desc: Verify NotifyFormsPrivacyProtected 321 * @tc.type: FUNC 322 * @tc.require: I5ST27 323 */ 324 HWTEST_F(FormMgrTest, FormMgrTest_0011, TestSize.Level1) { 325 GTEST_LOG_(INFO) << "FormMgrTest_0008 starts"; 326 EXPECT_CALL(*mockProxy, NotifyFormsPrivacyProtected(_, _, _)) 327 .Times(1) 328 .WillOnce(Return(0)); 329 // initialize input parameters. 330 int64_t formId1 = 5; 331 int64_t formId2 = 6; 332 std::vector<int64_t> formIds; 333 formIds.push_back(formId1); 334 formIds.push_back(formId2); 335 bool isProtected = true; 336 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 337 int32_t result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 338 // expect result. 339 EXPECT_EQ(result, 0); 340 GTEST_LOG_(INFO) << "FormMgrTest_0011 test ends"; 341 } 342 343 /** 344 * @tc.name: FormMgrTest_0012 345 * @tc.desc: Verify GetErrorMsg 346 * @tc.type: FUNC 347 */ 348 HWTEST_F(FormMgrTest, FormMgrTest_0012, TestSize.Level1) { 349 GTEST_LOG_(INFO) << "FormMgrTest_0012 starts"; 350 int errorCode = 0; 351 auto result = FormMgr::GetInstance().GetErrorMsg(errorCode); 352 353 EXPECT_EQ(result, "unknown error"); 354 GTEST_LOG_(INFO) << "FormMgrTest_0012 test ends"; 355 } 356 357 /** 358 * @tc.name: FormMgrTest_0013 359 * @tc.desc: Verify DumpStorageFormInfos 360 * @tc.type: FUNC 361 */ 362 HWTEST_F(FormMgrTest, FormMgrTest_0013, TestSize.Level1) { 363 GTEST_LOG_(INFO) << "FormMgrTest_0013 starts"; 364 EXPECT_CALL(*mockProxy, DumpStorageFormInfos(_)) 365 .Times(1) 366 .WillOnce(Return(0)); 367 std::string formInfos = "a"; 368 auto result = FormMgr::GetInstance().DumpStorageFormInfos(formInfos); 369 370 EXPECT_EQ(result, 0); 371 GTEST_LOG_(INFO) << "FormMgrTest_0013 test ends"; 372 } 373 374 /** 375 * @tc.name: FormMgrTest_0014 376 * @tc.desc: Verify DumpFormInfoByFormId 377 * @tc.type: FUNC 378 */ 379 HWTEST_F(FormMgrTest, FormMgrTest_0014, TestSize.Level1) { 380 GTEST_LOG_(INFO) << "FormMgrTest_0014 starts"; 381 EXPECT_CALL(*mockProxy, DumpFormInfoByFormId(_, _)) 382 .Times(1) 383 .WillOnce(Return(0)); 384 std::string formInfos = "a"; 385 std::int64_t formId = 3; 386 auto result = FormMgr::GetInstance().DumpFormInfoByFormId(formId, formInfos); 387 388 EXPECT_EQ(result, 0); 389 GTEST_LOG_(INFO) << "FormMgrTest_0014 test ends"; 390 } 391 392 /** 393 * @tc.name: FormMgrTest_0015 394 * @tc.desc: Verify DumpFormTimerByFormId 395 * @tc.type: FUNC 396 */ 397 HWTEST_F(FormMgrTest, FormMgrTest_0015, TestSize.Level1) { 398 GTEST_LOG_(INFO) << "FormMgrTest_0015 starts"; 399 EXPECT_CALL(*mockProxy, DumpFormTimerByFormId(_, _)) 400 .Times(1) 401 .WillOnce(Return(0)); 402 std::string isTimingService = "b"; 403 std::int64_t formId = 3; 404 auto result = FormMgr::GetInstance().DumpFormTimerByFormId(formId, isTimingService); 405 406 EXPECT_EQ(result, 0); 407 GTEST_LOG_(INFO) << "FormMgrTest_0015 test ends"; 408 } 409 410 /** 411 * @tc.name: FormMgrTest_0016 412 * @tc.desc: Verify RouterEvent 413 * @tc.type: FUNC 414 */ 415 HWTEST_F(FormMgrTest, FormMgrTest_0016, TestSize.Level1) { 416 GTEST_LOG_(INFO) << "FormMgrTest_0016 starts"; 417 EXPECT_CALL(*mockProxy, RouterEvent(_, _, _)) 418 .Times(1) 419 .WillOnce(Return(0)); 420 Want want; 421 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 422 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 423 FormJsInfo formJsInfo; 424 sptr<IRemoteObject> providerToken = new (std::nothrow) MockFormProviderClient(); 425 FormCallerMgr::GetInstance().AddFormHostCaller(formJsInfo, providerToken); 426 int32_t result = FormMgr::GetInstance().RouterEvent(formJsInfo.formId, want, token); 427 428 EXPECT_EQ(result, 0); 429 GTEST_LOG_(INFO) << "FormMgrTest_0016 test ends"; 430 } 431 432 /** 433 * @tc.name: FormMgrTest_0017 434 * @tc.desc: Verify SetNextRefreshTime 435 * @tc.type: FUNC 436 */ 437 HWTEST_F(FormMgrTest, FormMgrTest_0017, TestSize.Level1) { 438 GTEST_LOG_(INFO) << "FormMgrTest_0017 starts"; 439 int64_t formId = 1; 440 int64_t nextTime = 2; 441 auto result = FormMgr::GetInstance().SetNextRefreshTime(formId, nextTime); 442 443 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_REFRESH_TIME); 444 GTEST_LOG_(INFO) << "FormMgrTest_0017 test ends"; 445 } 446 447 /** 448 * @tc.name: FormMgrTest_0018 449 * @tc.desc: Verify GetErrorMessage 450 * @tc.type: FUNC 451 */ 452 HWTEST_F(FormMgrTest, FormMgrTest_0018, TestSize.Level1) { 453 GTEST_LOG_(INFO) << "FormMgrTest_0018 starts"; 454 FormErrors::GetInstance().InitErrorMessageMap(); 455 int errCode = ERR_APPEXECFWK_FORM_PERMISSION_DENY; 456 auto result = FormMgr::GetInstance().GetErrorMessage(errCode); 457 458 EXPECT_EQ(result, "check permission deny, need to request ohos.permission.REQUIRE_FORM " 459 "or ohos.permission.INTERACT_ACROSS_LOCAL_ACCOUNTS."); 460 GTEST_LOG_(INFO) << "FormMgrTest_0018 test ends"; 461 } 462 463 /** 464 * @tc.name: FormMgrTest_0019 465 * @tc.desc: Verify DeleteInvalidForms 466 * @tc.type: FUNC 467 */ 468 HWTEST_F(FormMgrTest, FormMgrTest_0019, TestSize.Level1) { 469 GTEST_LOG_(INFO) << "FormMgrTest_0019 starts"; 470 EXPECT_CALL(*mockProxy, DeleteInvalidForms(_, _, _)) 471 .Times(1) 472 .WillOnce(Return(0)); 473 std::vector<int64_t> formInfos; 474 formInfos.push_back(1); 475 formInfos.push_back(2); 476 FormJsInfo formJsInfo; 477 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 478 int32_t numFormsDeleted = 2; 479 auto result = FormMgr::GetInstance().DeleteInvalidForms(formInfos, token, numFormsDeleted); 480 481 EXPECT_EQ(result, 0); 482 GTEST_LOG_(INFO) << "FormMgrTest_0019 test ends"; 483 } 484 485 /** 486 * @tc.name: FormMgrTest_0020 487 * @tc.desc: Verify DumpStorageFormInfos 488 * @tc.type: FUNC 489 */ 490 HWTEST_F(FormMgrTest, FormMgrTest_0020, TestSize.Level1) { 491 GTEST_LOG_(INFO) << "FormMgrTest_0020 starts"; 492 EXPECT_CALL(*mockProxy, NotifyFormsVisible(_, _, _)) 493 .Times(1) 494 .WillOnce(Return(0)); 495 int64_t formId1 = 5; 496 int64_t formId2 = 6; 497 std::vector<int64_t> formIds; 498 formIds.push_back(formId1); 499 formIds.push_back(formId2); 500 bool isProtected = true; 501 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 502 int32_t result = FormMgr::GetInstance().NotifyFormsVisible(formIds, isProtected, token); 503 504 EXPECT_EQ(result, 0); 505 GTEST_LOG_(INFO) << "FormMgrTest_0020 test ends"; 506 } 507 508 /** 509 * @tc.name: FormMgrTest_0021 510 * @tc.desc: Verify NotifyFormsEnableUpdate 511 * @tc.type: FUNC 512 */ 513 HWTEST_F(FormMgrTest, FormMgrTest_0021, TestSize.Level1) { 514 GTEST_LOG_(INFO) << "FormMgrTest_0021 starts"; 515 EXPECT_CALL(*mockProxy, NotifyFormsEnableUpdate(_, _, _)) 516 .Times(1) 517 .WillOnce(Return(0)); 518 int64_t formId1 = 3; 519 int64_t formId2 = 4; 520 std::vector<int64_t> formIds; 521 formIds.push_back(formId1); 522 formIds.push_back(formId2); 523 bool isProtected = true; 524 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 525 int32_t result = FormMgr::GetInstance().NotifyFormsEnableUpdate(formIds, isProtected, token); 526 527 EXPECT_EQ(result, 0); 528 GTEST_LOG_(INFO) << "FormMgrTest_0021 test ends"; 529 } 530 531 /** 532 * @tc.name: FormMgrTest_0022 533 * @tc.desc: Verify GetAllFormsInfo 534 * @tc.type: FUNC 535 */ 536 HWTEST_F(FormMgrTest, FormMgrTest_0022, TestSize.Level1) { 537 GTEST_LOG_(INFO) << "FormMgrTest_0022 starts"; 538 EXPECT_CALL(*mockProxy, GetAllFormsInfo(_)) 539 .Times(1) 540 .WillOnce(Return(0)); 541 std::vector<FormInfo> formInfos; 542 std::vector<FormInfo> expectFormInfos; 543 FormInfo formInfo = {}; 544 formInfo.bundleName = "ohos.samples.FormApplication"; 545 formInfo.moduleName = "entry"; 546 expectFormInfos.push_back(formInfo); 547 auto result = FormMgr::GetInstance().GetAllFormsInfo(formInfos); 548 549 EXPECT_EQ(result, 0); 550 GTEST_LOG_(INFO) << "FormMgrTest_0022 test ends"; 551 } 552 553 /** 554 * @tc.name: FormMgrTest_0023 555 * @tc.desc: Verify GetFormsInfoByApp 556 * @tc.type: FUNC 557 */ 558 HWTEST_F(FormMgrTest, FormMgrTest_0023, TestSize.Level1) { 559 GTEST_LOG_(INFO) << "FormMgrTest_0023 starts"; 560 EXPECT_CALL(*mockProxy, GetFormsInfoByApp(_, _)) 561 .Times(1) 562 .WillOnce(Return(0)); 563 std::vector<FormInfo> formInfos; 564 std::vector<FormInfo> expectFormInfos; 565 FormInfo formInfo = {}; 566 formInfo.bundleName = "ohos.samples.FormApplication"; 567 formInfo.moduleName = "entry"; 568 expectFormInfos.push_back(formInfo); 569 std::string bundleName = "a"; 570 auto result = FormMgr::GetInstance().GetFormsInfoByApp(bundleName, formInfos); 571 572 EXPECT_EQ(result, 0); 573 GTEST_LOG_(INFO) << "FormMgrTest_0023 test ends"; 574 } 575 576 /** 577 * @tc.name: FormMgrTest_0024 578 * @tc.desc: Verify GetFormsInfoByModule 579 * @tc.type: FUNC 580 */ 581 HWTEST_F(FormMgrTest, FormMgrTest_0024, TestSize.Level1) { 582 GTEST_LOG_(INFO) << "FormMgrTest_0024 starts"; 583 EXPECT_CALL(*mockProxy, GetFormsInfoByModule(_, _, _)) 584 .Times(1) 585 .WillOnce(Return(0)); 586 std::vector<FormInfo> formInfos; 587 std::vector<FormInfo> expectFormInfos; 588 FormInfo formInfo = {}; 589 formInfo.bundleName = "ohos.samples.FormApplication"; 590 formInfo.moduleName = "entry"; 591 expectFormInfos.push_back(formInfo); 592 std::string bundleName = "a"; 593 std::string moduleName = "A"; 594 auto result = FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); 595 596 EXPECT_EQ(result, 0); 597 GTEST_LOG_(INFO) << "FormMgrTest_0024 test ends"; 598 } 599 600 /** 601 * @tc.name: FormMgrTest_0025 602 * @tc.desc: Verify CheckFMSReady 603 * @tc.type: FUNC 604 */ 605 HWTEST_F(FormMgrTest, FormMgrTest_0025, TestSize.Level1) { 606 GTEST_LOG_(INFO) << "FormMgrTest_0025 starts"; 607 EXPECT_CALL(*mockProxy, CheckFMSReady()) 608 .Times(2) 609 .WillOnce(Return(true)); 610 611 auto result = FormMgr::GetInstance().CheckFMSReady(); 612 EXPECT_TRUE(result); 613 GTEST_LOG_(INFO) << "FormMgrTest_0025 test ends"; 614 } 615 616 /** 617 * @tc.name: FormMgrTest_0026 618 * @tc.desc: Verify DumpFormInfoByBundleName 619 * @tc.type: FUNC 620 */ 621 HWTEST_F(FormMgrTest, FormMgrTest_0026, TestSize.Level1) { 622 GTEST_LOG_(INFO) << "FormMgrTest_0026 starts"; 623 EXPECT_CALL(*mockProxy, DumpFormInfoByBundleName(_, _)) 624 .Times(1) 625 .WillOnce(Return(0)); 626 std::string bundleName = "b"; 627 std::string formInfos = "a"; 628 auto result = FormMgr::GetInstance().DumpFormInfoByBundleName(bundleName, formInfos); 629 630 EXPECT_EQ(result, 0); 631 GTEST_LOG_(INFO) << "FormMgrTest_0026 test ends"; 632 } 633 634 /** 635 * @tc.name: FormMgrTest_0027 636 * @tc.desc: Verify AcquireFormState 637 * @tc.type: FUNC 638 */ 639 HWTEST_F(FormMgrTest, FormMgrTest_0027, TestSize.Level1) { 640 GTEST_LOG_(INFO) << "FormMgrTest_0027 starts"; 641 EXPECT_CALL(*mockProxy, AcquireFormState(_, _, _)) 642 .Times(1) 643 .WillOnce(Return(0)); 644 Want want; 645 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 646 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 647 FormStateInfo stateInfo; 648 auto result = FormMgr::GetInstance().AcquireFormState(want, token, stateInfo); 649 650 EXPECT_EQ(result, 0); 651 GTEST_LOG_(INFO) << "FormMgrTest_0027 test ends"; 652 } 653 654 /** 655 * @tc.name: FormMgrTest_0028 656 * @tc.desc: Verify DeleteForm 657 * @tc.type: FUNC 658 * @tc.require: issueI63OQL 659 */ 660 HWTEST_F(FormMgrTest, FormMgrTest_0028, TestSize.Level1) { 661 GTEST_LOG_(INFO) << "FormMgrTest_0028 starts"; 662 int64_t formId = 1; 663 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 664 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 665 int result = FormMgr::GetInstance().DeleteForm(formId, token); 666 667 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 668 GTEST_LOG_(INFO) << "FormMgrTest_0028 test ends"; 669 } 670 671 /** 672 * @tc.name: FormMgrTest_0029 673 * @tc.desc: Verify ReleaseForm 674 * @tc.type: FUNC 675 * @tc.require: issueI63OQL 676 */ 677 HWTEST_F(FormMgrTest, FormMgrTest_0029, TestSize.Level1) { 678 GTEST_LOG_(INFO) << "FormMgrTest_0029 starts"; 679 int64_t formId = 1; 680 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 681 bool delCache = true; 682 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 683 int result = FormMgr::GetInstance().ReleaseForm(formId, token, delCache); 684 685 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 686 GTEST_LOG_(INFO) << "FormMgrTest_0029 test ends"; 687 } 688 689 /** 690 * @tc.name: FormMgrTest_0030 691 * @tc.desc: Verify ReleaseForm 692 * @tc.type: FUNC 693 * @tc.require: issueI63OQL 694 */ 695 HWTEST_F(FormMgrTest, FormMgrTest_0030, TestSize.Level1) { 696 GTEST_LOG_(INFO) << "FormMgrTest_0030 starts"; 697 int64_t formId = -1; 698 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 699 bool delCache = true; 700 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 701 int result = FormMgr::GetInstance().ReleaseForm(formId, token, delCache); 702 703 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 704 GTEST_LOG_(INFO) << "FormMgrTest_0030 test ends"; 705 } 706 707 /** 708 * @tc.name: FormMgrTest_0031 709 * @tc.desc: Verify UpdateForm 710 * @tc.type: FUNC 711 * @tc.require: issueI63OQL 712 */ 713 HWTEST_F(FormMgrTest, FormMgrTest_0031, TestSize.Level1) { 714 GTEST_LOG_(INFO) << "FormMgrTest_0031 starts"; 715 int64_t formId = 1; 716 FormProviderData formBindingData; 717 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 718 int result = FormMgr::GetInstance().UpdateForm(formId, formBindingData); 719 720 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 721 GTEST_LOG_(INFO) << "FormMgrTest_0031 test ends"; 722 } 723 724 /** 725 * @tc.name: FormMgrTest_0032 726 * @tc.desc: Verify UpdateForm 727 * @tc.type: FUNC 728 * @tc.require: issueI63OQL 729 */ 730 HWTEST_F(FormMgrTest, FormMgrTest_0032, TestSize.Level1) { 731 GTEST_LOG_(INFO) << "FormMgrTest_0032 starts"; 732 int64_t formId = -1; 733 FormProviderData formBindingData; 734 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 735 int result = FormMgr::GetInstance().UpdateForm(formId, formBindingData); 736 737 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 738 GTEST_LOG_(INFO) << "FormMgrTest_0032 test ends"; 739 } 740 741 /** 742 * @tc.name: FormMgrTest_0033 743 * @tc.desc: Verify UpdateForm 744 * @tc.type: FUNC 745 * @tc.require: issueI63OQL 746 */ 747 HWTEST_F(FormMgrTest, FormMgrTest_0033, TestSize.Level1) { 748 GTEST_LOG_(INFO) << "FormMgrTest_0033 starts"; 749 int64_t formId = 1; 750 FormProviderData formBindingData; 751 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 752 int result = FormMgr::GetInstance().UpdateForm(formId, formBindingData); 753 754 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_PROVIDER_DATA_EMPTY); 755 GTEST_LOG_(INFO) << "FormMgrTest_0033 test ends"; 756 } 757 758 /** 759 * @tc.name: FormMgrTest_0034 760 * @tc.desc: Verify RequestForm 761 * @tc.type: FUNC 762 * @tc.require: issueI63OQL 763 */ 764 HWTEST_F(FormMgrTest, FormMgrTest_0034, TestSize.Level1) { 765 GTEST_LOG_(INFO) << "FormMgrTest_0034 starts"; 766 int64_t formId = 1; 767 Want want; 768 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 769 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 770 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 771 int result = FormMgr::GetInstance().RequestForm(formId, token, want); 772 773 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 774 GTEST_LOG_(INFO) << "FormMgrTest_0034 test ends"; 775 } 776 777 /** 778 * @tc.name: FormMgrTest_0035 779 * @tc.desc: Verify RequestForm 780 * @tc.type: FUNC 781 * @tc.require: issueI63OQL 782 */ 783 HWTEST_F(FormMgrTest, FormMgrTest_0035, TestSize.Level1) { 784 GTEST_LOG_(INFO) << "FormMgrTest_0035 starts"; 785 int64_t formId = -1; 786 Want want; 787 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 788 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 789 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 790 int result = FormMgr::GetInstance().RequestForm(formId, token, want); 791 792 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 793 GTEST_LOG_(INFO) << "FormMgrTest_0035 test ends"; 794 } 795 796 /** 797 * @tc.name: FormMgrTest_0036 798 * @tc.desc: Verify NotifyWhetherVisibleForms 799 * @tc.type: FUNC 800 * @tc.require: issueI63OQL 801 */ 802 HWTEST_F(FormMgrTest, FormMgrTest_0036, TestSize.Level1) { 803 GTEST_LOG_(INFO) << "FormMgrTest_0036 starts"; 804 std::vector<int64_t> formIds; 805 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 806 int32_t formVisibleType = 1; 807 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 808 int result = FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, token, formVisibleType); 809 810 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 811 GTEST_LOG_(INFO) << "FormMgrTest_0036 test ends"; 812 } 813 814 /** 815 * @tc.name: FormMgrTest_0037 816 * @tc.desc: Verify NotifyWhetherVisibleForms 817 * @tc.type: FUNC 818 * @tc.require: issueI63OQL 819 */ 820 HWTEST_F(FormMgrTest, FormMgrTest_0037, TestSize.Level1) { 821 GTEST_LOG_(INFO) << "FormMgrTest_0037 starts"; 822 std::vector<int64_t> formIds; 823 int64_t formId = 1; 824 formIds.emplace_back(formId); 825 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 826 int32_t formVisibleType = 1; 827 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 828 int result = FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, token, formVisibleType); 829 830 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 831 GTEST_LOG_(INFO) << "FormMgrTest_0037 test ends"; 832 } 833 834 /** 835 * @tc.name: FormMgrTest_0038 836 * @tc.desc: Verify SetNextRefreshTime 837 * @tc.type: FUNC 838 * @tc.require: issueI63OQL 839 */ 840 HWTEST_F(FormMgrTest, FormMgrTest_0038, TestSize.Level1) { 841 GTEST_LOG_(INFO) << "FormMgrTest_0038 starts"; 842 int64_t formId = 10; 843 int64_t nextTime = 50; 844 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 845 int result = FormMgr::GetInstance().SetNextRefreshTime(formId, nextTime); 846 847 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 848 GTEST_LOG_(INFO) << "FormMgrTest_0038 test ends"; 849 } 850 851 /** 852 * @tc.name: FormMgrTest_0039 853 * @tc.desc: Verify LifecycleUpdate 854 * @tc.type: FUNC 855 * @tc.require: issueI63OQL 856 */ 857 HWTEST_F(FormMgrTest, FormMgrTest_0039, TestSize.Level1) { 858 GTEST_LOG_(INFO) << "FormMgrTest_0039 starts"; 859 std::vector<int64_t> formIds; 860 int64_t formId = 1; 861 formIds.emplace_back(formId); 862 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 863 bool updateType = true; 864 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 865 int result = FormMgr::GetInstance().LifecycleUpdate(formIds, token, updateType); 866 867 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 868 GTEST_LOG_(INFO) << "FormMgrTest_0039 test ends"; 869 } 870 871 /** 872 * @tc.name: FormMgrTest_0040 873 * @tc.desc: Verify RegisterDeathCallback 874 * @tc.type: FUNC 875 * @tc.require: issueI63OQL 876 */ 877 HWTEST_F(FormMgrTest, FormMgrTest_0040, TestSize.Level1) { 878 GTEST_LOG_(INFO) << "FormMgrTest_0040 starts"; 879 std::shared_ptr<FormMgr> formMgr = std::make_shared<FormMgr>(); 880 ASSERT_NE(nullptr, formMgr); 881 formMgr->RegisterDeathCallback(nullptr); 882 formMgr->UnRegisterDeathCallback(nullptr); 883 formMgr->SetRecoverStatus(Constants::IN_RECOVERING); 884 GTEST_LOG_(INFO) << "FormMgrTest_0040 test ends"; 885 } 886 887 /** 888 * @tc.name: FormMgrTest_0041 889 * @tc.desc: Verify DeleteInvalidForms 890 * @tc.type: FUNC 891 * @tc.require: issueI63OQL 892 */ 893 HWTEST_F(FormMgrTest, FormMgrTest_0041, TestSize.Level1) { 894 GTEST_LOG_(INFO) << "FormMgrTest_0041 starts"; 895 std::vector<int64_t> formIds; 896 int64_t formId = 1; 897 formIds.emplace_back(formId); 898 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 899 int32_t numFormsDeleted = 2; 900 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 901 int result = FormMgr::GetInstance().DeleteInvalidForms(formIds, token, numFormsDeleted); 902 903 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 904 GTEST_LOG_(INFO) << "FormMgrTest_0041 test ends"; 905 } 906 907 /** 908 * @tc.name: FormMgrTest_0042 909 * @tc.desc: Verify AcquireFormState 910 * @tc.type: FUNC 911 * @tc.require: issueI63OQL 912 */ 913 HWTEST_F(FormMgrTest, FormMgrTest_0042, TestSize.Level1) { 914 GTEST_LOG_(INFO) << "FormMgrTest_0042 starts"; 915 Want want; 916 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 917 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 918 FormStateInfo stateInfo; 919 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 920 int result = FormMgr::GetInstance().AcquireFormState(want, token, stateInfo); 921 922 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 923 GTEST_LOG_(INFO) << "FormMgrTest_0042 test ends"; 924 } 925 926 /** 927 * @tc.name: FormMgrTest_0043 928 * @tc.desc: Verify NotifyFormsVisible 929 * @tc.type: FUNC 930 * @tc.require: issueI63OQL 931 */ 932 HWTEST_F(FormMgrTest, FormMgrTest_0043, TestSize.Level1) { 933 GTEST_LOG_(INFO) << "FormMgrTest_0043 starts"; 934 std::vector<int64_t> formIds; 935 int64_t formId = 1; 936 formIds.emplace_back(formId); 937 bool isVisible = true; 938 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 939 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 940 int result = FormMgr::GetInstance().NotifyFormsVisible(formIds, isVisible, token); 941 942 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 943 GTEST_LOG_(INFO) << "FormMgrTest_0043 test ends"; 944 } 945 946 /** 947 * @tc.name: FormMgrTest_0044 948 * @tc.desc: Verify NotifyFormsPrivacyProtected 949 * @tc.type: FUNC 950 * @tc.require: issueI63OQL 951 */ 952 HWTEST_F(FormMgrTest, FormMgrTest_0044, TestSize.Level1) { 953 GTEST_LOG_(INFO) << "FormMgrTest_0044 starts"; 954 std::vector<int64_t> formIds; 955 int64_t formId = 1; 956 formIds.emplace_back(formId); 957 bool isProtected = true; 958 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 959 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 960 int result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 961 962 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 963 GTEST_LOG_(INFO) << "FormMgrTest_0044 test ends"; 964 } 965 966 /** 967 * @tc.name: FormMgrTest_0045 968 * @tc.desc: Verify NotifyFormsEnableUpdate 969 * @tc.type: FUNC 970 * @tc.require: issueI63OQL 971 */ 972 HWTEST_F(FormMgrTest, FormMgrTest_0045, TestSize.Level1) { 973 GTEST_LOG_(INFO) << "FormMgrTest_0045 starts"; 974 std::vector<int64_t> formIds; 975 int64_t formId = 1; 976 formIds.emplace_back(formId); 977 bool isEnableUpdate = true; 978 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 979 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 980 int result = FormMgr::GetInstance().NotifyFormsEnableUpdate(formIds, isEnableUpdate, token); 981 982 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 983 GTEST_LOG_(INFO) << "FormMgrTest_0045 test ends"; 984 } 985 986 /** 987 * @tc.name: FormMgrTest_0046 988 * @tc.desc: Verify GetAllFormsInfo 989 * @tc.type: FUNC 990 * @tc.require: issueI63OQL 991 */ 992 HWTEST_F(FormMgrTest, FormMgrTest_0046, TestSize.Level1) { 993 GTEST_LOG_(INFO) << "FormMgrTest_0046 starts"; 994 std::vector<FormInfo> formInfos; 995 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 996 int result = FormMgr::GetInstance().GetAllFormsInfo(formInfos); 997 998 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 999 GTEST_LOG_(INFO) << "FormMgrTest_0046 test ends"; 1000 } 1001 1002 /** 1003 * @tc.name: FormMgrTest_0047 1004 * @tc.desc: Verify GetFormsInfoByApp 1005 * @tc.type: FUNC 1006 * @tc.require: issueI63OQL 1007 */ 1008 HWTEST_F(FormMgrTest, FormMgrTest_0047, TestSize.Level1) { 1009 GTEST_LOG_(INFO) << "FormMgrTest_0047 starts"; 1010 std::string bundleName = "this is bundleName"; 1011 std::vector<FormInfo> formInfos; 1012 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1013 int result = FormMgr::GetInstance().GetFormsInfoByApp(bundleName, formInfos); 1014 1015 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1016 GTEST_LOG_(INFO) << "FormMgrTest_0047 test ends"; 1017 } 1018 1019 /** 1020 * @tc.name: FormMgrTest_0048 1021 * @tc.desc: Verify GetFormsInfoByApp 1022 * @tc.type: FUNC 1023 * @tc.require: issueI63OQL 1024 */ 1025 HWTEST_F(FormMgrTest, FormMgrTest_0048, TestSize.Level1) { 1026 GTEST_LOG_(INFO) << "FormMgrTest_0048 starts"; 1027 std::string bundleName = ""; 1028 std::vector<FormInfo> formInfos; 1029 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1030 int result = FormMgr::GetInstance().GetFormsInfoByApp(bundleName, formInfos); 1031 1032 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_BUNDLENAME); 1033 GTEST_LOG_(INFO) << "FormMgrTest_0048 test ends"; 1034 } 1035 1036 /** 1037 * @tc.name: FormMgrTest_0050 1038 * @tc.desc: Verify GetFormsInfoByModule 1039 * @tc.type: FUNC 1040 * @tc.require: issueI63OQL 1041 */ 1042 HWTEST_F(FormMgrTest, FormMgrTest_0050, TestSize.Level1) { 1043 GTEST_LOG_(INFO) << "FormMgrTest_0050 starts"; 1044 std::string bundleName = ""; 1045 std::string moduleName = "this is moduleName"; 1046 std::vector<FormInfo> formInfos; 1047 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1048 int result = FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); 1049 1050 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_BUNDLENAME); 1051 GTEST_LOG_(INFO) << "FormMgrTest_0050 test ends"; 1052 } 1053 1054 /** 1055 * @tc.name: FormMgrTest_0051 1056 * @tc.desc: Verify GetFormsInfoByModule 1057 * @tc.type: FUNC 1058 * @tc.require: issueI63OQL 1059 */ 1060 HWTEST_F(FormMgrTest, FormMgrTest_0051, TestSize.Level1) { 1061 GTEST_LOG_(INFO) << "FormMgrTest_0051 starts"; 1062 std::string bundleName = "this is bundleName"; 1063 std::string moduleName = ""; 1064 std::vector<FormInfo> formInfos; 1065 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1066 int result = FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); 1067 1068 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_MODULENAME); 1069 GTEST_LOG_(INFO) << "FormMgrTest_0051 test ends"; 1070 } 1071 1072 /** 1073 * @tc.name: FormMgrTest_0052 1074 * @tc.desc: Verify GetFormsInfoByModule 1075 * @tc.type: FUNC 1076 * @tc.require: issueI63OQL 1077 */ 1078 HWTEST_F(FormMgrTest, FormMgrTest_0052, TestSize.Level1) { 1079 GTEST_LOG_(INFO) << "FormMgrTest_0052 starts"; 1080 std::string bundleName = "this is bundleName"; 1081 std::string moduleName = "this is moduleName"; 1082 std::vector<FormInfo> formInfos; 1083 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1084 int result = FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); 1085 1086 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1087 GTEST_LOG_(INFO) << "FormMgrTest_0052 test ends"; 1088 } 1089 1090 /** 1091 * @tc.name: FormMgrTest_0053 1092 * @tc.desc: Verify GetErrorMessage 1093 * @tc.type: FUNC 1094 * @tc.require: issueI63Y7Y 1095 */ 1096 HWTEST_F(FormMgrTest, FormMgrTest_0053, TestSize.Level1) { 1097 GTEST_LOG_(INFO) << "FormMgrTest_0053 starts"; 1098 FormErrors::GetInstance().InitErrorMessageMap(); 1099 int errCode = ERR_APPEXECFWK_FORM_COMMON_CODE; 1100 auto result = FormMgr::GetInstance().GetErrorMessage(errCode); 1101 1102 EXPECT_EQ(result, "some internal server error occurs."); 1103 GTEST_LOG_(INFO) << "FormMgrTest_0053 test ends"; 1104 } 1105 1106 /** 1107 * @tc.name: FormMgrTest_0054 1108 * @tc.desc: Verify AddForm 1109 * @tc.type: FUNC 1110 * @tc.require: issueI63Y7Y 1111 */ 1112 HWTEST_F(FormMgrTest, FormMgrTest_0054, TestSize.Level1) 1113 { 1114 GTEST_LOG_(INFO) << "FormMgrTest_0054 starts"; 1115 int64_t formId = 10; 1116 Want want; 1117 FormJsInfo formInfo; 1118 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1119 auto data = FormMgr::GetInstance().AddForm(formId, want, token, formInfo); 1120 EXPECT_EQ(data, ERROR_NUMS); 1121 GTEST_LOG_(INFO) << "FormMgrTest_0054 test ends"; 1122 } 1123 1124 /** 1125 * @tc.name: FormMgrTest_0055 1126 * @tc.desc: Verify DeleteForm (ID <= 0) 1127 * @tc.type: FUNC 1128 * @tc.require: issueI63Y7Y 1129 */ 1130 HWTEST_F(FormMgrTest, FormMgrTest_0055, TestSize.Level1) 1131 { 1132 GTEST_LOG_(INFO) << "FormMgrTest_0055 starts"; 1133 int64_t formId = -1; 1134 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1135 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1136 int result = FormMgr::GetInstance().DeleteForm(formId, token); 1137 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 1138 GTEST_LOG_(INFO) << "FormMgrTest_0055 test ends"; 1139 } 1140 1141 /** 1142 * @tc.name: FormMgrTest_0056 1143 * @tc.desc: Verify DeleteForm (Parameters are normal.) 1144 * @tc.type: FUNC 1145 * @tc.require: issueI63Y7Y 1146 */ 1147 HWTEST_F(FormMgrTest, FormMgrTest_0056, TestSize.Level1) 1148 { 1149 GTEST_LOG_(INFO) << "FormMgrTest_0056 starts"; 1150 EXPECT_CALL(*mockProxy, DeleteForm(_, _)) 1151 .Times(1) 1152 .WillOnce(Return(OHOS::ERR_OK)); 1153 int64_t formId = 1; 1154 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1155 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1156 int result = FormMgr::GetInstance().DeleteForm(formId, token); 1157 EXPECT_EQ(result, OHOS::ERR_OK); 1158 GTEST_LOG_(INFO) << "FormMgrTest_0056 test ends"; 1159 } 1160 1161 /** 1162 * @tc.name: FormMgrTest_0057 1163 * @tc.desc: Verify ReleaseForm (Parameters are normal.) 1164 * @tc.type: FUNC 1165 * @tc.require: issueI63Y7Y 1166 */ 1167 HWTEST_F(FormMgrTest, FormMgrTest_0057, TestSize.Level1) 1168 { 1169 GTEST_LOG_(INFO) << "FormMgrTest_0057 starts"; 1170 EXPECT_CALL(*mockProxy, ReleaseForm(_, _, _)) 1171 .Times(1) 1172 .WillOnce(Return(OHOS::ERR_OK)); 1173 int64_t formId = 1; 1174 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1175 bool delCache = true; 1176 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1177 int result = FormMgr::GetInstance().ReleaseForm(formId, token, delCache); 1178 EXPECT_EQ(result, OHOS::ERR_OK); 1179 GTEST_LOG_(INFO) << "FormMgrTest_0057 test ends"; 1180 } 1181 1182 /** 1183 * @tc.name: FormMgrTest_0058 1184 * @tc.desc: Verify UpdateForm (Parameter formId exception) 1185 * @tc.type: FUNC 1186 * @tc.require: issueI63Y7Y 1187 */ 1188 HWTEST_F(FormMgrTest, FormMgrTest_0058, TestSize.Level1) { 1189 GTEST_LOG_(INFO) << "FormMgrTest_0058 starts"; 1190 EXPECT_CALL(*mockProxy, UpdateForm(_, _)) 1191 .Times(1) 1192 .WillOnce(Return(NEGATIVE_NUM)); 1193 FormJsInfo formJsInfo; 1194 formJsInfo.formId = 0x00000008fffffffL; 1195 FormProviderData formProviderData = FormProviderData(std::string("{\"city\": \"beijing001\"}")); 1196 int32_t result = FormMgr::GetInstance().UpdateForm(formJsInfo.formId, formProviderData); 1197 EXPECT_EQ(result, NEGATIVE_NUM); 1198 GTEST_LOG_(INFO) << "FormMgrTest_0058 test ends"; 1199 } 1200 1201 /** 1202 * @tc.name: FormMgrTest_0059 1203 * @tc.desc: Verify RequestForm (Parameter formId exception) 1204 * @tc.type: FUNC 1205 * @tc.require: issueI63Y7Y 1206 */ 1207 HWTEST_F(FormMgrTest, FormMgrTest_0059, TestSize.Level1) { 1208 GTEST_LOG_(INFO) << "FormMgrTest_0059 starts"; 1209 EXPECT_CALL(*mockProxy, RequestForm(_, _, _)) 1210 .Times(1) 1211 .WillOnce(Return(NEGATIVE_NUM)); 1212 Want want; 1213 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 1214 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1215 FormJsInfo formJsInfo; 1216 formJsInfo.formId = 0x00000008fffffffL; 1217 int32_t result = FormMgr::GetInstance().RequestForm(formJsInfo.formId, token, want); 1218 EXPECT_EQ(result, NEGATIVE_NUM); 1219 GTEST_LOG_(INFO) << "FormMgrTest_0059 test ends"; 1220 } 1221 1222 /** 1223 * @tc.name: FormMgrTest_0060 1224 * @tc.desc: Verify NotifyWhetherVisibleForms (Parameters are normal, the return value of mock function is 0) 1225 * @tc.type: FUNC 1226 * @tc.require: issueI63Y7Y 1227 */ 1228 HWTEST_F(FormMgrTest, FormMgrTest_0060, TestSize.Level1) { 1229 GTEST_LOG_(INFO) << "FormMgrTest_0060 starts"; 1230 EXPECT_CALL(*mockProxy, NotifyWhetherVisibleForms(_, _, _)) 1231 .Times(1) 1232 .WillOnce(Return(OHOS::ERR_OK)); 1233 std::vector<int64_t> formIds; 1234 int64_t formId = 1; 1235 formIds.emplace_back(formId); 1236 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1237 int32_t formVisibleType = 1; 1238 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1239 int result = FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, token, formVisibleType); 1240 EXPECT_EQ(result, OHOS::ERR_OK); 1241 GTEST_LOG_(INFO) << "FormMgrTest_0060 test ends"; 1242 } 1243 1244 /** 1245 * @tc.name: FormMgrTest_0061 1246 * @tc.desc: Verify NotifyWhetherVisibleForms (Parameters are normal, the return value of mock function is not 0) 1247 * @tc.type: FUNC 1248 * @tc.require: issueI63Y7Y 1249 */ 1250 HWTEST_F(FormMgrTest, FormMgrTest_0061, TestSize.Level1) { 1251 GTEST_LOG_(INFO) << "FormMgrTest_0061 starts"; 1252 EXPECT_CALL(*mockProxy, NotifyWhetherVisibleForms(_, _, _)) 1253 .Times(1) 1254 .WillOnce(Return(POSITIVE_NUM)); 1255 std::vector<int64_t> formIds; 1256 int64_t formId = 1; 1257 formIds.emplace_back(formId); 1258 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1259 int32_t formVisibleType = 1; 1260 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1261 int result = FormMgr::GetInstance().NotifyWhetherVisibleForms(formIds, token, formVisibleType); 1262 EXPECT_EQ(result, POSITIVE_NUM); 1263 GTEST_LOG_(INFO) << "FormMgrTest_0061 test ends"; 1264 } 1265 1266 /** 1267 * @tc.name: FormMgrTest_0062 1268 * @tc.desc: Verify CastTempForm (Parameters are normal, the return value of mock function is 0) 1269 * @tc.type: FUNC 1270 * @tc.require: issueI63Y7Y 1271 */ 1272 HWTEST_F(FormMgrTest, FormMgrTest_0062, TestSize.Level1) { 1273 GTEST_LOG_(INFO) << "FormMgrTest_0062 starts"; 1274 EXPECT_CALL(*mockProxy, CastTempForm(_, _)) 1275 .Times(1) 1276 .WillOnce(Return(OHOS::ERR_OK)); 1277 int64_t formId = 1; 1278 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1279 int result = FormMgr::GetInstance().CastTempForm(formId, token); 1280 EXPECT_EQ(result, OHOS::ERR_OK); 1281 GTEST_LOG_(INFO) << "FormMgrTest_0062 test ends"; 1282 } 1283 1284 /** 1285 * @tc.name: FormMgrTest_0063 1286 * @tc.desc: Verify CastTempForm (Parameters are normal, the return value of mock function is not 0) 1287 * @tc.type: FUNC 1288 * @tc.require: issueI63Y7Y 1289 */ 1290 HWTEST_F(FormMgrTest, FormMgrTest_0063, TestSize.Level1) { 1291 GTEST_LOG_(INFO) << "FormMgrTest_0063 starts"; 1292 EXPECT_CALL(*mockProxy, CastTempForm(_, _)) 1293 .Times(1) 1294 .WillOnce(Return(POSITIVE_NUM)); 1295 int64_t formId = 1; 1296 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1297 int result = FormMgr::GetInstance().CastTempForm(formId, token); 1298 EXPECT_EQ(result, POSITIVE_NUM); 1299 GTEST_LOG_(INFO) << "FormMgrTest_0063 test ends"; 1300 } 1301 1302 /** 1303 * @tc.name: FormMgrTest_0064 1304 * @tc.desc: Verify CastTempForm (formId <= 0) 1305 * @tc.type: FUNC 1306 * @tc.require: issueI63Y7Y 1307 */ 1308 HWTEST_F(FormMgrTest, FormMgrTest_0064, TestSize.Level1) { 1309 GTEST_LOG_(INFO) << "FormMgrTest_0064 starts"; 1310 EXPECT_CALL(*mockProxy, CastTempForm(_, _)) 1311 .Times(1) 1312 .WillOnce(Return(OHOS::ERR_OK)); 1313 int64_t formId = -1; 1314 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1315 int result = FormMgr::GetInstance().CastTempForm(formId, token); 1316 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 1317 GTEST_LOG_(INFO) << "FormMgrTest_0064 test ends"; 1318 } 1319 1320 /** 1321 * @tc.name: FormMgrTest_0065 1322 * @tc.desc: Verify RegisterDeathCallback (Parameter is not nullptr) 1323 * @tc.type: FUNC 1324 * @tc.require: issueI63Y7Y 1325 */ 1326 HWTEST_F(FormMgrTest, FormMgrTest_0065, TestSize.Level1) { 1327 GTEST_LOG_(INFO) << "FormMgrTest_0065 starts"; 1328 std::shared_ptr<FormMgr> formMgr = std::make_shared<FormMgr>(); 1329 ASSERT_NE(nullptr, formMgr); 1330 std::shared_ptr<FormInterfaceCallbackTest> callback = std::make_shared<FormInterfaceCallbackTest>(); 1331 std::shared_ptr<FormInterfaceCallbackTest> callback_first = std::make_shared<FormInterfaceCallbackTest>(); 1332 formMgr->formDeathCallbacks_.emplace_back(callback); 1333 formMgr->formDeathCallbacks_.emplace_back(callback_first); 1334 formMgr->RegisterDeathCallback(callback); 1335 GTEST_LOG_(INFO) << "FormMgrTest_0065 test ends"; 1336 } 1337 1338 /** 1339 * @tc.name: FormMgrTest_0066 1340 * @tc.desc: Verify UnRegisterDeathCallback (Parameter is not nullptr) 1341 * @tc.type: FUNC 1342 * @tc.require: issueI63Y7Y 1343 */ 1344 HWTEST_F(FormMgrTest, FormMgrTest_0066, TestSize.Level1) { 1345 GTEST_LOG_(INFO) << "FormMgrTest_0066 starts"; 1346 std::shared_ptr<FormMgr> formMgr = std::make_shared<FormMgr>(); 1347 ASSERT_NE(nullptr, formMgr); 1348 std::shared_ptr<FormInterfaceCallbackTest> callback = std::make_shared<FormInterfaceCallbackTest>(); 1349 std::shared_ptr<FormInterfaceCallbackTest> callback_first = std::make_shared<FormInterfaceCallbackTest>(); 1350 formMgr->formDeathCallbacks_.emplace_back(callback); 1351 formMgr->formDeathCallbacks_.emplace_back(callback_first); 1352 formMgr->UnRegisterDeathCallback(callback); 1353 GTEST_LOG_(INFO) << "FormMgrTest_0066 test ends"; 1354 } 1355 1356 /** 1357 * @tc.name: FormMgrTest_0067 1358 * @tc.desc: Verify GetDeathRecipient 1359 * @tc.type: FUNC 1360 * @tc.require: issueI63Y7Y 1361 */ 1362 HWTEST_F(FormMgrTest, FormMgrTest_0067, TestSize.Level1) 1363 { 1364 GTEST_LOG_(INFO) << "FormMgrTest_0067 starts"; 1365 auto data = FormMgr::GetInstance().GetDeathRecipient(); 1366 EXPECT_TRUE(data == FormMgr::GetInstance().deathRecipient_); 1367 GTEST_LOG_(INFO) << "FormMgrTest_0067 test ends"; 1368 } 1369 1370 /** 1371 * @tc.name: FormMgrTest_0068 1372 * @tc.desc: Verify CheckIsDeathCallbackRegistered (Parameter is nullptr) 1373 * @tc.type: FUNC 1374 * @tc.require: issueI63Y7Y 1375 */ 1376 HWTEST_F(FormMgrTest, FormMgrTest_0068, TestSize.Level1) { 1377 GTEST_LOG_(INFO) << "FormMgrTest_0068 starts"; 1378 bool data = FormMgr::GetInstance().CheckIsDeathCallbackRegistered(nullptr); 1379 EXPECT_TRUE(data == false); 1380 GTEST_LOG_(INFO) << "FormMgrTest_0068 test ends"; 1381 } 1382 1383 /** 1384 * @tc.name: FormMgrTest_0069 1385 * @tc.desc: Verify CheckIsDeathCallbackRegistered (Parameter is not nullptr) 1386 * @tc.type: FUNC 1387 * @tc.require: issueI63Y7Y 1388 */ 1389 HWTEST_F(FormMgrTest, FormMgrTest_0069, TestSize.Level1) { 1390 GTEST_LOG_(INFO) << "FormMgrTest_0069 starts"; 1391 std::shared_ptr<FormInterfaceCallbackTest> callback = std::make_shared<FormInterfaceCallbackTest>(); 1392 std::shared_ptr<FormInterfaceCallbackTest> callback_first = std::make_shared<FormInterfaceCallbackTest>(); 1393 std::shared_ptr<FormInterfaceCallbackTest> callback_second = std::make_shared<FormInterfaceCallbackTest>(); 1394 bool result = FormMgr::GetInstance().CheckIsDeathCallbackRegistered(callback_first); 1395 EXPECT_TRUE(result == false); 1396 FormMgr::GetInstance().formDeathCallbacks_.emplace_back(callback_first); 1397 FormMgr::GetInstance().formDeathCallbacks_.emplace_back(callback_second); 1398 bool data = FormMgr::GetInstance().CheckIsDeathCallbackRegistered(callback_first); 1399 EXPECT_TRUE(data); 1400 GTEST_LOG_(INFO) << "FormMgrTest_0069 test ends"; 1401 } 1402 1403 /** 1404 * @tc.name: FormMgrTest_0070 1405 * @tc.desc: Verify CheckIsDeathCallbackRegistered (Parameter exception) 1406 * @tc.type: FUNC 1407 * @tc.require: issueI63Y7Y 1408 */ 1409 HWTEST_F(FormMgrTest, FormMgrTest_0070, TestSize.Level1) { 1410 GTEST_LOG_(INFO) << "FormMgrTest_0070 starts"; 1411 std::shared_ptr<FormInterfaceCallbackTest> callback = std::make_shared<FormInterfaceCallbackTest>(); 1412 std::shared_ptr<FormInterfaceCallbackTest> callback_first = std::make_shared<FormInterfaceCallbackTest>(); 1413 std::shared_ptr<FormInterfaceCallbackTest> callback_second = std::make_shared<FormInterfaceCallbackTest>(); 1414 FormMgr::GetInstance().formDeathCallbacks_.emplace_back(callback_first); 1415 FormMgr::GetInstance().formDeathCallbacks_.emplace_back(callback_second); 1416 bool data = FormMgr::GetInstance().CheckIsDeathCallbackRegistered(callback); 1417 EXPECT_TRUE(data == false); 1418 GTEST_LOG_(INFO) << "FormMgrTest_0070 test ends"; 1419 } 1420 1421 /** 1422 * @tc.name: FormMgrTest_0071 1423 * @tc.desc: Verify OnRemoteDied 1424 * @tc.type: FUNC 1425 * @tc.require: issueI63Y7Y 1426 */ 1427 HWTEST_F(FormMgrTest, FormMgrTest_0071, TestSize.Level1) { 1428 GTEST_LOG_(INFO) << "FormMgrTest_0071 starts"; 1429 sptr<IRemoteObject> mockFormProviderClient = new (std::nothrow) MockFormProviderClient(); 1430 sptr<FormMgr::FormMgrDeathRecipient> formMgrDeath = new (std::nothrow) FormMgr::FormMgrDeathRecipient(); 1431 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1432 formMgrDeath->OnRemoteDied(mockFormProviderClient); 1433 EXPECT_TRUE(FormMgr::GetInstance().GetRecoverStatus() == Constants::IN_RECOVERING); 1434 GTEST_LOG_(INFO) << "FormMgrTest_0071 test ends"; 1435 } 1436 1437 /** 1438 * @tc.name: FormMgrTest_0072 1439 * @tc.desc: Verify OnRemoteDied (Parameter is nullptr) 1440 * @tc.type: FUNC 1441 * @tc.require: issueI63Y7Y 1442 */ 1443 HWTEST_F(FormMgrTest, FormMgrTest_0072, TestSize.Level1) { 1444 GTEST_LOG_(INFO) << "FormMgrTest_0072 starts"; 1445 sptr<FormMgr::FormMgrDeathRecipient> formMgrDeath = new (std::nothrow) FormMgr::FormMgrDeathRecipient(); 1446 formMgrDeath->OnRemoteDied(nullptr); 1447 GTEST_LOG_(INFO) << "FormMgrTest_0072 test ends"; 1448 } 1449 1450 /** 1451 * @tc.name: FormMgrTest_0073 1452 * @tc.desc: Verify Reconnect 1453 * @tc.type: FUNC 1454 * @tc.require: issueI63Y7Y 1455 */ 1456 HWTEST_F(FormMgrTest, FormMgrTest_0073, TestSize.Level1) { 1457 GTEST_LOG_(INFO) << "FormMgrTest_0073 starts"; 1458 bool data = FormMgr::GetInstance().Reconnect(); 1459 EXPECT_EQ(data, true); 1460 GTEST_LOG_(INFO) << "FormMgrTest_0073 test ends"; 1461 } 1462 1463 /** 1464 * @tc.name: FormMgrTest_0074 1465 * @tc.desc: Verify ResetProxy (Parameter is nullptr) 1466 * @tc.type: FUNC 1467 * @tc.require: issueI63Y7Y 1468 */ 1469 HWTEST_F(FormMgrTest, FormMgrTest_0074, TestSize.Level1) { 1470 GTEST_LOG_(INFO) << "FormMgrTest_0074 starts"; 1471 std::shared_ptr<FormMgr> formMgr = std::make_shared<FormMgr>(); 1472 ASSERT_NE(nullptr, formMgr); 1473 formMgr->ResetProxy(nullptr); 1474 formMgr->SetFormMgrService(mockProxy); 1475 GTEST_LOG_(INFO) << "FormMgrTest_0074 test ends"; 1476 } 1477 1478 /** 1479 * @tc.name: FormMgrTest_0075 1480 * @tc.desc: Verify ResetProxy 1481 * @tc.type: FUNC 1482 * @tc.require: issueI63Y7Y 1483 */ 1484 HWTEST_F(FormMgrTest, FormMgrTest_0075, TestSize.Level1) { 1485 GTEST_LOG_(INFO) << "FormMgrTest_0075 starts"; 1486 sptr<IRemoteObject> remote = new (std::nothrow) MockFormProviderClient(); 1487 FormMgr::GetInstance().ResetProxy(remote); 1488 EXPECT_TRUE(FormMgr::GetInstance().GetRecoverStatus() == Constants::IN_RECOVERING); 1489 FormMgr::GetInstance().SetFormMgrService(mockProxy); 1490 GTEST_LOG_(INFO) << "FormMgrTest_0075 test ends"; 1491 } 1492 1493 /** 1494 * @tc.name: FormMgrTest_0076 1495 * @tc.desc: Verify DeleteInvalidForms (The return value of mock function is not 0) 1496 * @tc.type: FUNC 1497 * @tc.require: issueI63Y7Y 1498 */ 1499 HWTEST_F(FormMgrTest, FormMgrTest_0076, TestSize.Level1) { 1500 GTEST_LOG_(INFO) << "FormMgrTest_0076 starts"; 1501 EXPECT_CALL(*mockProxy, DeleteInvalidForms(_, _, _)) 1502 .Times(1) 1503 .WillOnce(Return(POSITIVE_NUM)); 1504 std::vector<int64_t> formInfos; 1505 formInfos.push_back(1); 1506 formInfos.push_back(2); 1507 FormJsInfo formJsInfo; 1508 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1509 int32_t numFormsDeleted = 2; 1510 auto result = FormMgr::GetInstance().DeleteInvalidForms(formInfos, token, numFormsDeleted); 1511 EXPECT_EQ(result, ERROR_NUM); 1512 GTEST_LOG_(INFO) << "FormMgrTest_0076 test ends"; 1513 } 1514 1515 /** 1516 * @tc.name: FormMgrTest_0077 1517 * @tc.desc: Verify AcquireFormState (The return value of mock function is not 0) 1518 * @tc.type: FUNC 1519 * @tc.require: issueI63Y7Y 1520 */ 1521 HWTEST_F(FormMgrTest, FormMgrTest_0077, TestSize.Level1) { 1522 GTEST_LOG_(INFO) << "FormMgrTest_0077 starts"; 1523 EXPECT_CALL(*mockProxy, AcquireFormState(_, _, _)) 1524 .Times(1) 1525 .WillOnce(Return(POSITIVE_NUM)); 1526 Want want; 1527 want = want.SetElementName("", "com.example.FormAbility", "MainAbility"); 1528 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1529 FormStateInfo stateInfo; 1530 auto result = FormMgr::GetInstance().AcquireFormState(want, token, stateInfo); 1531 EXPECT_EQ(result, ERROR_NUM); 1532 GTEST_LOG_(INFO) << "FormMgrTest_0077 test ends"; 1533 } 1534 1535 /** 1536 * @tc.name: FormMgrTest_0078 1537 * @tc.desc: Verify NotifyFormsVisible (The return value of mock function is not 0) 1538 * @tc.type: FUNC 1539 * @tc.require: issueI63Y7Y 1540 */ 1541 HWTEST_F(FormMgrTest, FormMgrTest_0078, TestSize.Level1) { 1542 GTEST_LOG_(INFO) << "FormMgrTest_0078 starts"; 1543 EXPECT_CALL(*mockProxy, NotifyFormsVisible(_, _, _)) 1544 .Times(1) 1545 .WillOnce(Return(POSITIVE_NUM)); 1546 int64_t formId1 = 5; 1547 int64_t formId2 = 6; 1548 std::vector<int64_t> formIds; 1549 formIds.push_back(formId1); 1550 formIds.push_back(formId2); 1551 bool isProtected = true; 1552 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1553 int32_t result = FormMgr::GetInstance().NotifyFormsVisible(formIds, isProtected, token); 1554 EXPECT_EQ(result, ERROR_NUM); 1555 GTEST_LOG_(INFO) << "FormMgrTest_0078 test ends"; 1556 } 1557 1558 /** 1559 * @tc.name: FormMgrTest_0079 1560 * @tc.desc: Verify NotifyFormsPrivacyProtected (The return value of mock function is not 0) 1561 * @tc.type: FUNC 1562 * @tc.require: issueI63Y7Y 1563 */ 1564 HWTEST_F(FormMgrTest, FormMgrTest_0079, TestSize.Level1) { 1565 GTEST_LOG_(INFO) << "FormMgrTest_0079 starts"; 1566 EXPECT_CALL(*mockProxy, NotifyFormsPrivacyProtected(_, _, _)) 1567 .Times(1) 1568 .WillOnce(Return(POSITIVE_NUM)); 1569 int64_t formId = 1; 1570 std::vector<int64_t> formIds; 1571 formIds.push_back(formId); 1572 bool isProtected = false; 1573 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1574 int32_t result = FormMgr::GetInstance().NotifyFormsPrivacyProtected(formIds, isProtected, token); 1575 EXPECT_EQ(result, ERROR_NUM); 1576 GTEST_LOG_(INFO) << "FormMgrTest_0079 test ends"; 1577 } 1578 1579 /** 1580 * @tc.name: FormMgrTest_0080 1581 * @tc.desc: Verify NotifyFormsEnableUpdate (The return value of mock function is not 0) 1582 * @tc.type: FUNC 1583 * @tc.require: issueI63Y7Y 1584 */ 1585 HWTEST_F(FormMgrTest, FormMgrTest_0080, TestSize.Level1) { 1586 GTEST_LOG_(INFO) << "FormMgrTest_0080 starts"; 1587 EXPECT_CALL(*mockProxy, NotifyFormsEnableUpdate(_, _, _)) 1588 .Times(1) 1589 .WillOnce(Return(POSITIVE_NUM)); 1590 int64_t formId1 = 3; 1591 int64_t formId2 = 4; 1592 std::vector<int64_t> formIds; 1593 formIds.push_back(formId1); 1594 formIds.push_back(formId2); 1595 bool isProtected = true; 1596 sptr<MockFormToken> token = new (std::nothrow) MockFormToken(); 1597 int32_t result = FormMgr::GetInstance().NotifyFormsEnableUpdate(formIds, isProtected, token); 1598 EXPECT_EQ(result, ERROR_NUM); 1599 GTEST_LOG_(INFO) << "FormMgrTest_0080 test ends"; 1600 } 1601 1602 /** 1603 * @tc.name: FormMgrTest_0081 1604 * @tc.desc: Verify GetAllFormsInfo (The return value of mock function is not 0) 1605 * @tc.type: FUNC 1606 * @tc.require: issueI63Y7Y 1607 */ 1608 HWTEST_F(FormMgrTest, FormMgrTest_0081, TestSize.Level1) { 1609 GTEST_LOG_(INFO) << "FormMgrTest_0081 starts"; 1610 EXPECT_CALL(*mockProxy, GetAllFormsInfo(_)) 1611 .Times(1) 1612 .WillOnce(Return(POSITIVE_NUM)); 1613 std::vector<FormInfo> formInfos; 1614 std::vector<FormInfo> expectFormInfos; 1615 FormInfo formInfo = {}; 1616 formInfo.bundleName = "ohos.samples.FormApplication"; 1617 formInfo.moduleName = "entry"; 1618 expectFormInfos.push_back(formInfo); 1619 auto result = FormMgr::GetInstance().GetAllFormsInfo(formInfos); 1620 EXPECT_EQ(result, ERROR_NUM); 1621 GTEST_LOG_(INFO) << "FormMgrTest_0081 test ends"; 1622 } 1623 1624 /** 1625 * @tc.name: FormMgrTest_0082 1626 * @tc.desc: Verify GetFormsInfoByApp (The return value of mock function is not 0) 1627 * @tc.type: FUNC 1628 * @tc.require: issueI63Y7Y 1629 */ 1630 HWTEST_F(FormMgrTest, FormMgrTest_0082, TestSize.Level1) { 1631 GTEST_LOG_(INFO) << "FormMgrTest_0082 starts"; 1632 EXPECT_CALL(*mockProxy, GetFormsInfoByApp(_, _)) 1633 .Times(1) 1634 .WillOnce(Return(POSITIVE_NUM)); 1635 std::vector<FormInfo> formInfos; 1636 std::vector<FormInfo> expectFormInfos; 1637 FormInfo formInfo = {}; 1638 formInfo.bundleName = "ohos.samples.FormApplication"; 1639 formInfo.moduleName = "entry"; 1640 expectFormInfos.push_back(formInfo); 1641 std::string bundleName = "a"; 1642 auto result = FormMgr::GetInstance().GetFormsInfoByApp(bundleName, formInfos); 1643 EXPECT_EQ(result, ERROR_NUM); 1644 GTEST_LOG_(INFO) << "FormMgrTest_0082 test ends"; 1645 } 1646 1647 /** 1648 * @tc.name: FormMgrTest_0083 1649 * @tc.desc: Verify GetFormsInfoByModule (The return value of mock function is not 0) 1650 * @tc.type: FUNC 1651 * @tc.require: issueI63Y7Y 1652 */ 1653 HWTEST_F(FormMgrTest, FormMgrTest_0083, TestSize.Level1) { 1654 GTEST_LOG_(INFO) << "FormMgrTest_0083 starts"; 1655 EXPECT_CALL(*mockProxy, GetFormsInfoByModule(_, _, _)) 1656 .Times(1) 1657 .WillOnce(Return(POSITIVE_NUM)); 1658 std::vector<FormInfo> formInfos; 1659 std::vector<FormInfo> expectFormInfos; 1660 FormInfo formInfo = {}; 1661 formInfo.bundleName = "ohos.samples.FormApplication"; 1662 formInfo.moduleName = "entry"; 1663 expectFormInfos.push_back(formInfo); 1664 std::string bundleName = "a"; 1665 std::string moduleName = "A"; 1666 auto result = FormMgr::GetInstance().GetFormsInfoByModule(bundleName, moduleName, formInfos); 1667 EXPECT_EQ(result, ERROR_NUM); 1668 GTEST_LOG_(INFO) << "FormMgrTest_0083 test ends"; 1669 } 1670 1671 /** 1672 * @tc.name: FormMgrTest_0084 1673 * @tc.desc: Verify CheckFMSReady (mock function returns nullptr) 1674 * @tc.type: FUNC 1675 * @tc.require: issueI63Y7Y 1676 */ 1677 HWTEST_F(FormMgrTest, FormMgrTest_0084, TestSize.Level1) { 1678 GTEST_LOG_(INFO) << "FormMgrTest_0084 starts"; 1679 sptr<MockSystemAbilityManager> mockSamgr = new (std::nothrow) MockSystemAbilityManager(); 1680 sptr<ISystemAbilityManager> backupSamgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); 1681 SystemAbilityManagerClient::GetInstance().systemAbilityManager_ = mockSamgr; 1682 std::shared_ptr<bool> dummyVal = std::make_shared<bool>(true); 1683 mockSamgr->weakGetSystemAbility_ = dummyVal; 1684 auto result = FormMgr::GetInstance().CheckFMSReady(); 1685 EXPECT_TRUE(result == false); 1686 GTEST_LOG_(INFO) << "FormMgrTest_0084 test ends"; 1687 } 1688 1689 /** 1690 * @tc.name: FormMgrTest_0085 1691 * @tc.desc: Verify ShareForm (The return value of mock function is 0) 1692 * @tc.type: FUNC 1693 * @tc.require: issueI63Y7Y 1694 */ 1695 HWTEST_F(FormMgrTest, FormMgrTest_0085, TestSize.Level1) { 1696 GTEST_LOG_(INFO) << "FormMgrTest_0085 starts"; 1697 EXPECT_CALL(*mockProxy, ShareForm(_, _, _, _)) 1698 .Times(1) 1699 .WillOnce(Return(OHOS::ERR_OK)); 1700 int64_t formId = 0; 1701 std::string deviceId = "aa"; 1702 int64_t requestCode = 1; 1703 sptr<IRemoteObject> Token = new (std::nothrow) MockFormProviderClient(); 1704 auto result = FormMgr::GetInstance().ShareForm(formId, deviceId, Token, requestCode); 1705 EXPECT_EQ(result, OHOS::ERR_OK); 1706 GTEST_LOG_(INFO) << "FormMgrTest_0085 test ends"; 1707 } 1708 1709 /** 1710 * @tc.name: FormMgrTest_0086 1711 * @tc.desc: Verify GetFormsCount 1712 * @tc.type: FUNC 1713 * @tc.require: issueI63OQL 1714 */ 1715 HWTEST_F(FormMgrTest, FormMgrTest_0086, TestSize.Level1) { 1716 GTEST_LOG_(INFO) << "FormMgrTest_0086 starts"; 1717 bool isTempFormFlag = true; 1718 int32_t formCount = 0; 1719 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1720 int result = FormMgr::GetInstance().GetFormsCount(isTempFormFlag, formCount); 1721 1722 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1723 GTEST_LOG_(INFO) << "FormMgrTest_0086 test ends"; 1724 } 1725 1726 /** 1727 * @tc.name: FormMgrTest_0087 1728 * @tc.desc: Verify GetFormsCount 1729 * @tc.type: FUNC 1730 * @tc.require: issueI63OQL 1731 */ 1732 HWTEST_F(FormMgrTest, FormMgrTest_0087, TestSize.Level1) { 1733 GTEST_LOG_(INFO) << "FormMgrTest_0087 starts"; 1734 bool isTempFormFlag = true; 1735 int32_t formCount = 0; 1736 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1737 int result = FormMgr::GetInstance().GetFormsCount(isTempFormFlag, formCount); 1738 1739 EXPECT_EQ(result, 0); 1740 GTEST_LOG_(INFO) << "FormMgrTest_0087 test ends"; 1741 } 1742 1743 /** 1744 * @tc.name: FormMgrTest_0088 1745 * @tc.desc: Verify GetHostFormsCount 1746 * @tc.type: FUNC 1747 * @tc.require: issueI63OQL 1748 */ 1749 HWTEST_F(FormMgrTest, FormMgrTest_0088, TestSize.Level1) { 1750 GTEST_LOG_(INFO) << "FormMgrTest_0088 starts"; 1751 std::string bundleName = "this is bundleName"; 1752 int32_t formCount = 0; 1753 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1754 int result = FormMgr::GetInstance().GetHostFormsCount(bundleName, formCount); 1755 1756 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1757 GTEST_LOG_(INFO) << "FormMgrTest_0088 test ends"; 1758 } 1759 1760 /** 1761 * @tc.name: FormMgrTest_0089 1762 * @tc.desc: Verify GetHostFormsCount 1763 * @tc.type: FUNC 1764 * @tc.require: issueI63OQL 1765 */ 1766 HWTEST_F(FormMgrTest, FormMgrTest_0089, TestSize.Level1) { 1767 GTEST_LOG_(INFO) << "FormMgrTest_0089 starts"; 1768 std::string bundleName = ""; 1769 int32_t formCount = 0; 1770 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1771 int result = FormMgr::GetInstance().GetHostFormsCount(bundleName, formCount); 1772 1773 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_BUNDLENAME); 1774 GTEST_LOG_(INFO) << "FormMgrTest_0089 test ends"; 1775 } 1776 1777 /** 1778 * @tc.name: FormMgrTest_0090 1779 * @tc.desc: Verify GetHostFormsCount 1780 * @tc.type: FUNC 1781 * @tc.require: issueI63OQL 1782 */ 1783 HWTEST_F(FormMgrTest, FormMgrTest_0090, TestSize.Level1) { 1784 GTEST_LOG_(INFO) << "FormMgrTest_0090 starts"; 1785 std::string bundleName = "this is bundleName"; 1786 int32_t formCount = 0; 1787 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1788 int result = FormMgr::GetInstance().GetHostFormsCount(bundleName, formCount); 1789 1790 EXPECT_EQ(result, 0); 1791 GTEST_LOG_(INFO) << "FormMgrTest_0090 test ends"; 1792 } 1793 1794 /** 1795 * @tc.name: FormMgrTest_0091 1796 * @tc.desc: Verify AcquireFormData (The return value of mock function is 0) 1797 * @tc.type: FUNC 1798 * @tc.require: issueI63Y7Y 1799 */ 1800 HWTEST_F(FormMgrTest, FormMgrTest_0091, TestSize.Level1) { 1801 GTEST_LOG_(INFO) << "FormMgrTest_0091 starts"; 1802 EXPECT_CALL(*mockProxy, AcquireFormData(_, _, _, _)) 1803 .Times(1) 1804 .WillOnce(Return(OHOS::ERR_OK)); 1805 int64_t formId = 0; 1806 int64_t requestCode = 1; 1807 AAFwk::WantParams formData; 1808 sptr<IRemoteObject> Token = new (std::nothrow) MockFormProviderClient(); 1809 auto result = FormMgr::GetInstance().AcquireFormData(formId, requestCode, Token, formData); 1810 EXPECT_EQ(result, OHOS::ERR_OK); 1811 GTEST_LOG_(INFO) << "FormMgrTest_0091 test ends"; 1812 } 1813 1814 /** 1815 * @tc.name: FormMgrTest_0092 1816 * @tc.desc: Verify GetRunningFormInfos 1817 * @tc.type: FUNC 1818 * @tc.require: issueI63OQL 1819 */ 1820 HWTEST_F(FormMgrTest, FormMgrTest_0092, TestSize.Level1) { 1821 GTEST_LOG_(INFO) << "FormMgrTest_0092 starts"; 1822 EXPECT_CALL(*mockProxy, GetRunningFormInfos(_, _)) 1823 .Times(1) 1824 .WillOnce(Return(OHOS::ERR_OK)); 1825 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1826 1827 std::vector<RunningFormInfo> runningFormInfos; 1828 bool isUnusedInclude = false; 1829 int result = FormMgr::GetInstance().GetRunningFormInfos(isUnusedInclude, runningFormInfos); 1830 1831 EXPECT_EQ(result, 0); 1832 GTEST_LOG_(INFO) << "FormMgrTest_0092 test ends"; 1833 } 1834 1835 /** 1836 * @tc.name: FormMgrTest_0093 1837 * @tc.desc: Verify GetRunningFormInfos 1838 * @tc.type: FUNC 1839 * @tc.require: issueI63OQL 1840 */ 1841 HWTEST_F(FormMgrTest, FormMgrTest_0093, TestSize.Level1) { 1842 GTEST_LOG_(INFO) << "FormMgrTest_0093 starts"; 1843 EXPECT_CALL(*mockProxy, GetRunningFormInfos(_, _)) 1844 .Times(1) 1845 .WillOnce(Return(OHOS::ERR_OK)); 1846 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1847 1848 std::vector<RunningFormInfo> runningFormInfos; 1849 bool isUnusedInclude = false; 1850 int result = FormMgr::GetInstance().GetRunningFormInfos(isUnusedInclude, runningFormInfos); 1851 1852 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1853 GTEST_LOG_(INFO) << "FormMgrTest_0093 test ends"; 1854 } 1855 1856 /** 1857 * @tc.name: FormMgrTest_0094 1858 * @tc.desc: Verify GetRunningFormInfos 1859 * @tc.type: FUNC 1860 * @tc.require: issueI63OQL 1861 */ 1862 HWTEST_F(FormMgrTest, FormMgrTest_0094, TestSize.Level1) { 1863 GTEST_LOG_(INFO) << "FormMgrTest_0094 starts"; 1864 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1865 EXPECT_CALL(*mockProxy, GetRunningFormInfos(_, _)) 1866 .Times(1) 1867 .WillOnce(Return(ERROR_NUM)); 1868 std::vector<RunningFormInfo> runningFormInfos; 1869 bool isUnusedInclude = false; 1870 int result = FormMgr::GetInstance().GetRunningFormInfos(isUnusedInclude, runningFormInfos); 1871 1872 EXPECT_EQ(result, ERROR_NUM); 1873 GTEST_LOG_(INFO) << "FormMgrTest_0094 test ends"; 1874 } 1875 1876 /** 1877 * @tc.name: FormMgrTest_0095 1878 * @tc.desc: Verify GetRunningFormInfos 1879 * @tc.type: FUNC 1880 * @tc.require: issueI63OQL 1881 */ 1882 HWTEST_F(FormMgrTest, FormMgrTest_0095, TestSize.Level1) { 1883 GTEST_LOG_(INFO) << "FormMgrTest_0095 starts"; 1884 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1885 EXPECT_CALL(*mockProxy, GetRunningFormInfos(_, _)) 1886 .Times(1) 1887 .WillOnce(Return(NEGATIVE_NUM)); 1888 std::vector<RunningFormInfo> runningFormInfos; 1889 bool isUnusedInclude = false; 1890 int result = FormMgr::GetInstance().GetRunningFormInfos(isUnusedInclude, runningFormInfos); 1891 1892 EXPECT_EQ(result, NEGATIVE_NUM); 1893 GTEST_LOG_(INFO) << "FormMgrTest_0095 test ends"; 1894 } 1895 1896 /** 1897 * @tc.name: FormMgrTest_0096 1898 * @tc.desc: Verify GetRunningFormInfos 1899 * @tc.type: FUNC 1900 * @tc.require: issueI63OQL 1901 */ 1902 HWTEST_F(FormMgrTest, FormMgrTest_0096, TestSize.Level1) { 1903 GTEST_LOG_(INFO) << "FormMgrTest_0096 starts"; 1904 EXPECT_CALL(*mockProxy, GetRunningFormInfosByBundleName(_, _, _)) 1905 .Times(1) 1906 .WillOnce(Return(OHOS::ERR_OK)); 1907 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1908 1909 std::string bundleName = "a"; 1910 bool isUnusedInclude = false; 1911 std::vector<RunningFormInfo> runningFormInfos; 1912 int result = FormMgr::GetInstance().GetRunningFormInfosByBundleName(bundleName, isUnusedInclude, runningFormInfos); 1913 1914 EXPECT_EQ(result, 0); 1915 GTEST_LOG_(INFO) << "FormMgrTest_0096 test ends"; 1916 } 1917 1918 /** 1919 * @tc.name: FormMgrTest_0097 1920 * @tc.desc: Verify GetRunningFormInfosByBundleName 1921 * @tc.type: FUNC 1922 * @tc.require: issueI63OQL 1923 */ 1924 HWTEST_F(FormMgrTest, FormMgrTest_0097, TestSize.Level1) { 1925 GTEST_LOG_(INFO) << "FormMgrTest_0097 starts"; 1926 EXPECT_CALL(*mockProxy, GetRunningFormInfosByBundleName(_, _, _)) 1927 .Times(1) 1928 .WillOnce(Return(OHOS::ERR_OK)); 1929 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1930 std::string bundleName = "a"; 1931 bool isUnusedInclude = false; 1932 std::vector<RunningFormInfo> runningFormInfos; 1933 int result = FormMgr::GetInstance().GetRunningFormInfosByBundleName(bundleName, isUnusedInclude, runningFormInfos); 1934 1935 EXPECT_EQ(result, 0); 1936 GTEST_LOG_(INFO) << "FormMgrTest_0097 test ends"; 1937 } 1938 1939 /** 1940 * @tc.name: FormMgrTest_0098 1941 * @tc.desc: Verify GetRunningFormInfosByBundleName 1942 * @tc.type: FUNC 1943 * @tc.require: issueI63OQL 1944 */ 1945 HWTEST_F(FormMgrTest, FormMgrTest_0098, TestSize.Level1) { 1946 GTEST_LOG_(INFO) << "FormMgrTest_0098 starts"; 1947 EXPECT_CALL(*mockProxy, GetRunningFormInfosByBundleName(_, _, _)) 1948 .Times(1) 1949 .WillOnce(Return(OHOS::ERR_OK)); 1950 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 1951 std::string bundleName = "a"; 1952 bool isUnusedInclude = false; 1953 std::vector<RunningFormInfo> runningFormInfos; 1954 int result = FormMgr::GetInstance().GetRunningFormInfosByBundleName(bundleName, isUnusedInclude, runningFormInfos); 1955 1956 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 1957 GTEST_LOG_(INFO) << "FormMgrTest_0098 test ends"; 1958 } 1959 1960 /** 1961 * @tc.name: FormMgrTest_0099 1962 * @tc.desc: Verify GetRunningFormInfosByBundleName 1963 * @tc.type: FUNC 1964 * @tc.require: issueI63OQL 1965 */ 1966 HWTEST_F(FormMgrTest, FormMgrTest_0099, TestSize.Level1) { 1967 GTEST_LOG_(INFO) << "FormMgrTest_0099 starts"; 1968 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1969 EXPECT_CALL(*mockProxy, GetRunningFormInfosByBundleName(_, _, _)) 1970 .Times(1) 1971 .WillOnce(Return(ERROR_NUM)); 1972 std::string bundleName = "a"; 1973 bool isUnusedInclude = false; 1974 std::vector<RunningFormInfo> runningFormInfos; 1975 int result = FormMgr::GetInstance().GetRunningFormInfosByBundleName(bundleName, isUnusedInclude, runningFormInfos); 1976 1977 EXPECT_EQ(result, ERROR_NUM); 1978 GTEST_LOG_(INFO) << "FormMgrTest_0099 test ends"; 1979 } 1980 1981 /** 1982 * @tc.name: FormMgrTest_0100 1983 * @tc.desc: Verify RegisterFormAddObserverByBundle 1984 * @tc.type: FUNC 1985 * @tc.require: issueI63OQL 1986 */ 1987 HWTEST_F(FormMgrTest, FormMgrTest_0100, TestSize.Level1) { 1988 GTEST_LOG_(INFO) << "FormMgrTest_0100 starts"; 1989 EXPECT_CALL(*mockProxy, RegisterFormAddObserverByBundle(_, _)) 1990 .Times(1) 1991 .WillOnce(Return(OHOS::ERR_OK)); 1992 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 1993 std::string bundleName = "a"; 1994 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 1995 int result = FormMgr::GetInstance().RegisterFormAddObserverByBundle(bundleName, callerToken); 1996 1997 EXPECT_EQ(result, 0); 1998 GTEST_LOG_(INFO) << "FormMgrTest_0100 test ends"; 1999 } 2000 2001 /** 2002 * @tc.name: FormMgrTest_0101 2003 * @tc.desc: Verify RegisterFormAddObserverByBundle 2004 * @tc.type: FUNC 2005 * @tc.require: issueI63OQL 2006 */ 2007 HWTEST_F(FormMgrTest, FormMgrTest_0101, TestSize.Level1) { 2008 GTEST_LOG_(INFO) << "FormMgrTest_0101 starts"; 2009 EXPECT_CALL(*mockProxy, RegisterFormAddObserverByBundle(_, _)) 2010 .Times(1) 2011 .WillOnce(Return(OHOS::ERR_OK)); 2012 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2013 std::string bundleName = "a"; 2014 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2015 int result = FormMgr::GetInstance().RegisterFormAddObserverByBundle(bundleName, callerToken); 2016 2017 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 2018 GTEST_LOG_(INFO) << "FormMgrTest_0101 test ends"; 2019 } 2020 2021 /** 2022 * @tc.name: FormMgrTest_0102 2023 * @tc.desc: Verify RegisterFormAddObserverByBundle 2024 * @tc.type: FUNC 2025 * @tc.require: issueI63OQL 2026 */ 2027 HWTEST_F(FormMgrTest, FormMgrTest_0102, TestSize.Level1) { 2028 GTEST_LOG_(INFO) << "FormMgrTest_0102 starts"; 2029 EXPECT_CALL(*mockProxy, RegisterFormAddObserverByBundle(_, _)) 2030 .Times(1) 2031 .WillOnce(Return(ERROR_NUM)); 2032 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 2033 std::string bundleName = "a"; 2034 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2035 int result = FormMgr::GetInstance().RegisterFormAddObserverByBundle(bundleName, callerToken); 2036 2037 EXPECT_EQ(result, ERROR_NUM); 2038 GTEST_LOG_(INFO) << "FormMgrTest_0102 test ends"; 2039 } 2040 2041 /** 2042 * @tc.name: FormMgrTest_0103 2043 * @tc.desc: Verify RegisterFormRemoveObserverByBundle 2044 * @tc.type: FUNC 2045 * @tc.require: issueI63OQL 2046 */ 2047 HWTEST_F(FormMgrTest, FormMgrTest_0103, TestSize.Level1) { 2048 GTEST_LOG_(INFO) << "FormMgrTest_0103 starts"; 2049 EXPECT_CALL(*mockProxy, RegisterFormRemoveObserverByBundle(_, _)) 2050 .Times(1) 2051 .WillOnce(Return(OHOS::ERR_OK)); 2052 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 2053 std::string bundleName = "a"; 2054 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2055 int result = FormMgr::GetInstance().RegisterFormRemoveObserverByBundle(bundleName, callerToken); 2056 2057 EXPECT_EQ(result, 0); 2058 GTEST_LOG_(INFO) << "FormMgrTest_0103 test ends"; 2059 } 2060 2061 /** 2062 * @tc.name: FormMgrTest_0104 2063 * @tc.desc: Verify RegisterFormRemoveObserverByBundle 2064 * @tc.type: FUNC 2065 * @tc.require: issueI63OQL 2066 */ 2067 HWTEST_F(FormMgrTest, FormMgrTest_0104, TestSize.Level1) { 2068 GTEST_LOG_(INFO) << "FormMgrTest_0104 starts"; 2069 EXPECT_CALL(*mockProxy, RegisterFormRemoveObserverByBundle(_, _)) 2070 .Times(1) 2071 .WillOnce(Return(OHOS::ERR_OK)); 2072 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2073 std::string bundleName = "a"; 2074 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2075 int result = FormMgr::GetInstance().RegisterFormRemoveObserverByBundle(bundleName, callerToken); 2076 2077 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_SERVER_STATUS_ERR); 2078 GTEST_LOG_(INFO) << "FormMgrTest_0104 test ends"; 2079 } 2080 2081 /** 2082 * @tc.name: FormMgrTest_0105 2083 * @tc.desc: Verify RegisterFormRemoveObserverByBundle 2084 * @tc.type: FUNC 2085 * @tc.require: issueI63OQL 2086 */ 2087 HWTEST_F(FormMgrTest, FormMgrTest_0105, TestSize.Level1) { 2088 GTEST_LOG_(INFO) << "FormMgrTest_0105 starts"; 2089 EXPECT_CALL(*mockProxy, RegisterFormRemoveObserverByBundle(_, _)) 2090 .Times(1) 2091 .WillOnce(Return(ERROR_NUM)); 2092 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 2093 std::string bundleName = "a"; 2094 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2095 int result = FormMgr::GetInstance().RegisterFormRemoveObserverByBundle(bundleName, callerToken); 2096 2097 EXPECT_EQ(result, ERROR_NUM); 2098 GTEST_LOG_(INFO) << "FormMgrTest_0105 test ends"; 2099 } 2100 2101 /** 2102 * @tc.name: FormMgrTest_0106 2103 * @tc.desc: Verify UpdateForm (include data proxies) 2104 * @tc.type: FUNC 2105 * @tc.require: issueI7CGTP 2106 */ 2107 HWTEST_F(FormMgrTest, FormMgrTest_0106, TestSize.Level1) { 2108 GTEST_LOG_(INFO) << "FormMgrTest_0106 starts"; 2109 EXPECT_CALL(*mockProxy, UpdateProxyForm(_, _, _)) 2110 .Times(1) 2111 .WillOnce(Return(NEGATIVE_NUM)); 2112 FormJsInfo formJsInfo; 2113 formJsInfo.formId = 0x00000008fffffffL; 2114 FormProviderData formProviderData = FormProviderData(std::string("{\"city\": \"beijing001\"}")); 2115 std::vector<FormDataProxy> formDataProxies; 2116 FormDataProxy formDataProxy("city", ""); 2117 formDataProxies.push_back(formDataProxy); 2118 int32_t result = FormMgr::GetInstance().UpdateForm(formJsInfo.formId, formProviderData, formDataProxies); 2119 EXPECT_EQ(result, NEGATIVE_NUM); 2120 GTEST_LOG_(INFO) << "FormMgrTest_0106 test ends"; 2121 } 2122 2123 /** 2124 * @tc.name: FormMgrTest_0107 2125 * @tc.desc: Verify RequestPublishForm (include data proxies) 2126 * @tc.type: FUNC 2127 * @tc.require: issueI7CGTP 2128 */ 2129 HWTEST_F(FormMgrTest, FormMgrTest_0107, TestSize.Level1) { 2130 GTEST_LOG_(INFO) << "FormMgrTest_0107 starts"; 2131 EXPECT_CALL(*mockProxy, RequestPublishProxyForm(_, _, _, _, _)) 2132 .Times(1) 2133 .WillOnce(Return(NEGATIVE_NUM)); 2134 Want want; 2135 int64_t formId = 0x00000008fffffffL; 2136 std::unique_ptr<FormProviderData> formProviderData; 2137 std::vector<FormDataProxy> formDataProxies; 2138 FormDataProxy formDataProxy("city", ""); 2139 formDataProxies.push_back(formDataProxy); 2140 int32_t result = FormMgr::GetInstance().RequestPublishForm(want, true, formProviderData, formId, formDataProxies); 2141 EXPECT_EQ(result, NEGATIVE_NUM); 2142 GTEST_LOG_(INFO) << "FormMgrTest_0107 test ends"; 2143 } 2144 2145 /** 2146 * @tc.name: FormMgrTest_0108 2147 * @tc.desc: Verify StopRenderingForm 2148 * @tc.type: FUNC 2149 * @tc.require: issueI7HGZ2 2150 */ 2151 HWTEST_F(FormMgrTest, FormMgrTest_0108, TestSize.Level1) { 2152 GTEST_LOG_(INFO) << "FormMgrTest_0108 starts"; 2153 int64_t formId = 0; 2154 std::string compId = "this is compId"; 2155 int result = FormMgr::GetInstance().StopRenderingForm(formId, compId); 2156 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 2157 GTEST_LOG_(INFO) << "FormMgrTest_0108 test ends"; 2158 } 2159 2160 /** 2161 * @tc.name: FormMgrTest_0109 2162 * @tc.desc: Verify ReleaseRenderer 2163 * @tc.type: FUNC 2164 * @tc.require: issueI7HGZ2 2165 */ 2166 HWTEST_F(FormMgrTest, FormMgrTest_0109, TestSize.Level1) { 2167 GTEST_LOG_(INFO) << "FormMgrTest_0109 starts"; 2168 int64_t formId = 0; 2169 std::string compId = "this is compId"; 2170 int result = FormMgr::GetInstance().ReleaseRenderer(formId, compId); 2171 EXPECT_EQ(result, ERR_APPEXECFWK_FORM_INVALID_FORM_ID); 2172 GTEST_LOG_(INFO) << "FormMgrTest_0109 test ends"; 2173 } 2174 2175 /** 2176 * @tc.name: FormMgrTest_0111 2177 * @tc.desc: Verify GetErrorMsgByExternalErrorCode 2178 * @tc.type: FUNC 2179 * @tc.require: issueI7HGZ2 2180 */ 2181 HWTEST_F(FormMgrTest, FormMgrTest_0111, TestSize.Level1) { 2182 GTEST_LOG_(INFO) << "FormMgrTest_0111 starts"; 2183 int32_t innerErrorCode = 0; 2184 int32_t externalErrorCode = 0; 2185 std::string errorMsg = "this is errorMsg"; 2186 FormMgr::GetInstance().GetExternalError(innerErrorCode, externalErrorCode, errorMsg); 2187 2188 std::string result = FormMgr::GetInstance().GetErrorMsgByExternalErrorCode(externalErrorCode); 2189 EXPECT_EQ(result, "success"); 2190 GTEST_LOG_(INFO) << "FormMgrTest_0111 test ends"; 2191 } 2192 2193 /** 2194 * @tc.name: FormMgrTest_0112 2195 * @tc.desc: Verify GetFormInstancesByFilter 2196 * @tc.type: FUNC 2197 * @tc.require: issueI7HGZ2 2198 */ 2199 HWTEST_F(FormMgrTest, FormMgrTest_0112, TestSize.Level1) { 2200 GTEST_LOG_(INFO) << "FormMgrTest_0112 starts"; 2201 FormInstancesFilter filter; 2202 std::vector<FormInstance> formInstances; 2203 ErrCode result = FormMgr::GetInstance().GetFormInstancesByFilter(filter, formInstances); 2204 int code = 8388610; 2205 EXPECT_EQ(result, code); 2206 2207 int64_t formId = 1; 2208 FormInstance formInstance; 2209 ErrCode result1 = FormMgr::GetInstance().GetFormInstanceById(formId, formInstance); 2210 EXPECT_EQ(result1, code); 2211 GTEST_LOG_(INFO) << "FormMgrTest_0112 test ends"; 2212 } 2213 2214 /** 2215 * @tc.name: FormMgrTest_0113 2216 * @tc.desc: Verify BackgroundEvent 2217 * @tc.type: FUNC 2218 * @tc.require: IssueI7X4L4 2219 */ 2220 HWTEST_F(FormMgrTest, FormMgrTest_0113, TestSize.Level1) { 2221 GTEST_LOG_(INFO) << "FormMgrTest_0113 starts"; 2222 EXPECT_CALL(*mockProxy, BackgroundEvent(_, _, _)) 2223 .Times(1) 2224 .WillOnce(Return(ERROR_NUM)); 2225 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2226 Want want; 2227 int64_t formId = 1; 2228 std::string bundleName = "a"; 2229 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2230 int result = FormMgr::GetInstance().BackgroundEvent(formId, want, callerToken); 2231 2232 EXPECT_EQ(result, ERROR_NUM); 2233 GTEST_LOG_(INFO) << "FormMgrTest_0113 test ends"; 2234 } 2235 2236 /** 2237 * @tc.name: FormMgrTest_0114 2238 * @tc.desc: Verify RegisterPublishFormInterceptor 2239 * @tc.type: FUNC 2240 * @tc.require: IssueI7X4L4 2241 */ 2242 HWTEST_F(FormMgrTest, FormMgrTest_0114, TestSize.Level1) { 2243 GTEST_LOG_(INFO) << "FormMgrTest_0114 starts"; 2244 EXPECT_CALL(*mockProxy, RegisterPublishFormInterceptor(_)) 2245 .Times(1) 2246 .WillOnce(Return(ERR_OK)); 2247 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2248 sptr<IRemoteObject> interceptorCallback; 2249 2250 int32_t result = FormMgr::GetInstance().RegisterPublishFormInterceptor(interceptorCallback); 2251 2252 EXPECT_EQ(result, 0); 2253 GTEST_LOG_(INFO) << "FormMgrTest_0114 test ends"; 2254 } 2255 2256 /** 2257 * @tc.name: FormMgrTest_0115 2258 * @tc.desc: Verify UnregisterPublishFormInterceptor 2259 * @tc.type: FUNC 2260 * @tc.require: IssueI7X4L4 2261 */ 2262 HWTEST_F(FormMgrTest, FormMgrTest_0115, TestSize.Level1) { 2263 GTEST_LOG_(INFO) << "FormMgrTest_0115 starts"; 2264 FormMgr::GetInstance().SetRecoverStatus(Constants::NOT_IN_RECOVERY); 2265 EXPECT_CALL(*mockProxy, UnregisterPublishFormInterceptor(_)) 2266 .Times(1) 2267 .WillOnce(Return(ERROR_NUMS)); 2268 sptr<IRemoteObject> interceptorCallback; 2269 2270 int32_t result = FormMgr::GetInstance().UnregisterPublishFormInterceptor(interceptorCallback); 2271 EXPECT_EQ(result, 8388610); 2272 GTEST_LOG_(INFO) << "FormMgrTest_0115 test ends"; 2273 } 2274 2275 /** 2276 * @tc.name: FormMgrTest_0117 2277 * @tc.desc: Verify RegisterAddObserver 2278 * @tc.type: FUNC 2279 * @tc.require: IssueI7X4L4 2280 */ 2281 HWTEST_F(FormMgrTest, FormMgrTest_0117, TestSize.Level1) { 2282 GTEST_LOG_(INFO) << "FormMgrTest_0117 starts"; 2283 EXPECT_CALL(*mockProxy, RegisterAddObserver(_, _)) 2284 .Times(1) 2285 .WillOnce(Return(ERROR_NUMS)); 2286 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2287 std::string bundleName = "this is a bundleName"; 2288 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2289 2290 ErrCode result = FormMgr::GetInstance().RegisterAddObserver(bundleName, callerToken); 2291 EXPECT_EQ(result, ERROR_NUM); 2292 GTEST_LOG_(INFO) << "FormMgrTest_0117 test ends"; 2293 } 2294 2295 /** 2296 * @tc.name: FormMgrTest_0118 2297 * @tc.desc: Verify RegisterRemoveObserver 2298 * @tc.type: FUNC 2299 * @tc.require: IssueI7X4L4 2300 */ 2301 HWTEST_F(FormMgrTest, FormMgrTest_0118, TestSize.Level1) { 2302 GTEST_LOG_(INFO) << "FormMgrTest_0118 starts"; 2303 EXPECT_CALL(*mockProxy, RegisterRemoveObserver(_, _)) 2304 .Times(1) 2305 .WillOnce(Return(OHOS::ERR_OK)); 2306 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2307 std::string bundleName = "a"; 2308 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2309 2310 ErrCode result = FormMgr::GetInstance().RegisterRemoveObserver(bundleName, callerToken); 2311 EXPECT_EQ(result, ERROR_NUM); 2312 GTEST_LOG_(INFO) << "FormMgrTest_0118 test ends"; 2313 } 2314 2315 /** 2316 * @tc.name: FormMgrTest_0119 2317 * @tc.desc: Verify RegisterFormRouterProxy 2318 * @tc.type: FUNC 2319 * @tc.require: IssueI8H9R5 2320 */ 2321 HWTEST_F(FormMgrTest, FormMgrTest_0119, TestSize.Level1) { 2322 GTEST_LOG_(INFO) << "FormMgrTest_0119 starts"; 2323 EXPECT_CALL(*mockProxy, RegisterFormRouterProxy(_, _)) 2324 .Times(1) 2325 .WillOnce(Return(OHOS::ERR_OK)); 2326 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2327 std::vector<int64_t> formIds; 2328 formIds.push_back(0); 2329 sptr<IRemoteObject> callerToken = new (std::nothrow) MockFormProviderClient(); 2330 2331 ErrCode result = FormMgr::GetInstance().RegisterFormRouterProxy(formIds, callerToken); 2332 EXPECT_EQ(result, ERROR_NUM); 2333 GTEST_LOG_(INFO) << "FormMgrTest_0119 test ends"; 2334 } 2335 2336 /** 2337 * @tc.name: FormMgrTest_0120 2338 * @tc.desc: Verify UnregisterFormRouterProxy 2339 * @tc.type: FUNC 2340 * @tc.require: IssueI8H9R5 2341 */ 2342 HWTEST_F(FormMgrTest, FormMgrTest_0120, TestSize.Level1) { 2343 GTEST_LOG_(INFO) << "FormMgrTest_0120 starts"; 2344 EXPECT_CALL(*mockProxy, UnregisterFormRouterProxy(_)) 2345 .Times(1) 2346 .WillOnce(Return(OHOS::ERR_OK)); 2347 FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); 2348 std::vector<int64_t> formIds; 2349 formIds.push_back(0); 2350 2351 ErrCode result = FormMgr::GetInstance().UnregisterFormRouterProxy(formIds); 2352 EXPECT_EQ(result, ERROR_NUM); 2353 GTEST_LOG_(INFO) << "FormMgrTest_0120 test ends"; 2354 } 2355 } // namespace 2356