diff --git a/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceA.hap b/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceA.hap new file mode 100644 index 0000000000000000000000000000000000000000..b2fdf9c2d257585d8ce5254fc9edf977127e7d61 Binary files /dev/null and b/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceA.hap differ diff --git a/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceB.hap b/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceB.hap new file mode 100644 index 0000000000000000000000000000000000000000..dbc971a82f5e1532619d4b37435625268a844bdf Binary files /dev/null and b/test/resource/fms/fms_provider_ability_bundle/FormSystemTestServiceB.hap differ diff --git a/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingA-signed.hap b/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingA-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..5db324f6ca4f93d51561260376e64a4cfdf3be3a Binary files /dev/null and b/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingA-signed.hap differ diff --git a/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingB-signed.hap b/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingB-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..f224d6eaa8708d188aaf8a7b0e60fb57e88fb5a8 Binary files /dev/null and b/test/resource/fms/fms_self_starting_host_bundle/fmsSystemTestSelfStartingB-signed.hap differ diff --git a/test/resource/formsystemtestability/BUILD.gn b/test/resource/formsystemtestability/BUILD.gn index 48b23fa1259b5527045b8fbe2c27bde38f716951..ce7c6a3168b0971d9a7226a721665fe66b65714d 100644 --- a/test/resource/formsystemtestability/BUILD.gn +++ b/test/resource/formsystemtestability/BUILD.gn @@ -12,5 +12,13 @@ # limitations under the License. group("fms_system_test_app") { - deps = [ "formSystemTestServiceA:formSystemTestServiceA" ] + deps = [ + "fmsSystemTestHostCommonA:fmsSystemTestHostCommonA", + "fmsSystemTestHostNoPerm:fmsSystemTestHostNoPerm", + "fmsSystemTestHostNormal:fmsSystemTestHostNormal", + "fmsSystemTestHostNormalB:fmsSystemTestHostNormalB", + "fmsSystemTestHostNotSys:fmsSystemTestHostNotSys", + "fmsSystemTestSelfStarting/selfStartingTestHostA:selfStartingTestHostA", + "fmsSystemTestSelfStarting/selfStartingTestHostB:selfStartingTestHostB", + ] } diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dd65e46f37941921e26183634894b90fcc0299b5 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("fmsSystemTestHostCommonAConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostCommonA") { + sources = [ + "../tool/src/form_test_utils.cpp", + "src/form_ability_commona.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":fmsSystemTestHostCommonAConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/config.json b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/config.json new file mode 100644 index 0000000000000000000000000000000000000000..81bf59d215595e0f8ac116c53ee2bdc7689b0d9e --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.commona", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.commona.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityCommonA", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h new file mode 100644 index 0000000000000000000000000000000000000000..b33c725775930d63b4fd4338cd7c333cda3ba764 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_COMMONA_H_ +#define _FORM_ABILITY_COMMONA_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriberForCommonA; +class FormAbilityCommonA : public Ability { +public: + ~FormAbilityCommonA(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_acquireForm(std::string data); + void Clear(std::string data); + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name, int code):caseName_(name), code_(code) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_ = ""; + int code_ = 0; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + + using FormFunc = void (FormAbilityCommonA::*)(std::string data); + std::map memberFuncMap_; + std::map calledFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriberForCommonA : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriberForCommonA(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriberForCommonA() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityCommonA *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_COMMONA_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b0336138586cd0284b63c5d096494c0ffe4fe8af --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_commona.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_ONE_NORMAL_FORM, +}; +void FormAbilityCommonA::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called[%{public}s]", __func__, std::to_string(formJsInfo.formId).c_str()); +} +void FormAbilityCommonA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100, std::to_string(formJsInfo.formId)); +} + +void FormAbilityCommonA::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +// Create one form(temp/normal) +void FormAbilityCommonA::FMS_acquireForm(std::string data) +{ + APP_LOGI("%{public}s called, data: %{public}s", __func__, data.c_str()); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + if (data == "true") { + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + } else { + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + } + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[form_ability_commonA]AcquireForm end"); + } else { + APP_LOGE("[form_ability_commonA]AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100, ""); + } +} + +FormAbilityCommonA::~FormAbilityCommonA() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilityCommonA::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityCommonA::onStart"); + Ability::OnStart(want); +} +void FormAbilityCommonA::OnActive() +{ + APP_LOGI("FormAbilityCommonA::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityCommonA::OnStop() +{ + APP_LOGI("FormAbilityCommonA::OnStop"); + + Ability::OnStop(); +} +void FormAbilityCommonA::OnInactive() +{ + APP_LOGI("FormAbilityCommonA::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityCommonA::OnBackground() +{ + APP_LOGI("FormAbilityCommonA::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityCommonA::SubscribeEvent() +{ + APP_LOGI("FormAbilityCommonA::SubscribeEvent"); + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityCommonA::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityCommonA::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM] = &FormAbilityCommonA::FMS_acquireForm; + SubscribeEvent(); +} + +void FormAbilityCommonA::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilityCommonA::Clear(std::string data) +{ + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("[FormAbilityCommonA] Clear end"); + } else { + APP_LOGE("[FormAbilityCommonA] Clear error"); + } +} + +void FormEventSubscriberForCommonA::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriberForCommonA::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriberForCommonA::OnReceiveEvent:code=%{public}d", data.GetCode()); + // clear + if (data.GetCode() == EVENT_CODE_110) { + ability_->Clear(data.GetData()); + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); + } else { + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + } +} + +void FormEventSubscriberForCommonA::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityCommonA) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..bc1f36c5a3d34359c9f89d7f8a9a3e599aa0e4a8 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("fmsSystemTestHostNoPermConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNoPerm") { + sources = [ + "../tool/src/form_test_utils.cpp", + "src/form_ability_no_perm.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":fmsSystemTestHostNoPermConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/config.json b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/config.json new file mode 100644 index 0000000000000000000000000000000000000000..662ab9e31ab7d97cb406562c00d676ce6a37229d --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/config.json @@ -0,0 +1,60 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.nopermission", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.nopermission.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityNoPerm", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/include/form_ability_no_perm.h b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/include/form_ability_no_perm.h new file mode 100644 index 0000000000000000000000000000000000000000..4e4fc48d4ba99c98f022733fd659fb47513026a1 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/include/form_ability_no_perm.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_NO_PERM_H_ +#define _FORM_ABILITY_NO_PERM_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilityNoPerm : public Ability { +public: + void SubscribeEvent(const std::vector &eventList); + void handleEvent(std::string action); + + void FMS_acquireForm_0200(); + void FMS_deleteForm_0200(); + void FMS_releaseForm_0200(); + + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name):caseName_(name) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilityNoPerm::*)(); + std::map memberFuncMap_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityNoPerm *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_NO_PERM_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0bab3eab502c8f0f49b1e7f9eed6c9962b89dde --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNoPerm/src/form_ability_no_perm.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_no_perm.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +void FormAbilityNoPerm::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityNoPerm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityNoPerm::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +void FormAbilityNoPerm::FMS_acquireForm_0200() +{ + std::shared_ptr callback = std::make_shared("FMS_acquireForm_0200"); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0200, EVENT_CODE_200, "false"); + } +} + +void FormAbilityNoPerm::FMS_deleteForm_0200() +{ + int64_t formId = 1; + bool bResult = DeleteForm(formId); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0200] end"); + } else { + APP_LOGE("[FMS_deleteForm_0200] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0200, EVENT_CODE_200, "false"); + } +} + +void FormAbilityNoPerm::FMS_releaseForm_0200() +{ + int64_t formId = 1; + bool isReleaseCache = true; + bool bResult = ReleaseForm(formId, isReleaseCache); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0200] end"); + } else { + APP_LOGE("[FMS_releaseForm_0200] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0200, EVENT_CODE_200, "false"); + } +} + + +void FormAbilityNoPerm::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityNoPerm::onStart"); + Ability::OnStart(want); + + std::vector eventList = { + FORM_EVENT_REQ_ACQUIRE_FORM_0200, + FORM_EVENT_REQ_DELETE_FORM_0200, + FORM_EVENT_REQ_RELEASE_FORM_0200, + }; + SubscribeEvent(eventList); +} +void FormAbilityNoPerm::OnActive() +{ + APP_LOGI("FormAbilityNoPerm::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityNoPerm::OnStop() +{ + APP_LOGI("FormAbilityNoPerm::OnStop"); + + Ability::OnStop(); +} +void FormAbilityNoPerm::OnInactive() +{ + APP_LOGI("FormAbilityNoPerm::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityNoPerm::OnBackground() +{ + APP_LOGI("FormAbilityNoPerm::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityNoPerm::SubscribeEvent(const std::vector &eventList) +{ + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityNoPerm::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityNoPerm::Init"); + Ability::Init(abilityInfo, application, handler, token); + + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0200] = &FormAbilityNoPerm::FMS_acquireForm_0200; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0200] = &FormAbilityNoPerm::FMS_deleteForm_0200; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0200] = &FormAbilityNoPerm::FMS_releaseForm_0200; +} + +void FormAbilityNoPerm::handleEvent(std::string action) +{ + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(); + } + } +} + +void FormAbilityNoPerm::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityNoPerm) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..869b06e2be28d79666903a5dbd4e08d2a17a8d7b --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("fmsSystemTestHostNormalConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNormal") { + sources = [ + "../tool/src/form_test_utils.cpp", + "src/form_ability_a.cpp", + "src/form_ability_deleteform.cpp", + "src/form_ability_releaseform.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":fmsSystemTestHostNormalConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/config.json b/test/resource/formsystemtestability/fmsSystemTestHostNormal/config.json new file mode 100644 index 0000000000000000000000000000000000000000..e3ec3c806ab171beda5cf2c4bc5bfdfe62792c54 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/config.json @@ -0,0 +1,122 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.normal", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.normal.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityA", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }, + { + "name": "FormAbilityDeleteForm", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }, + { + "name": "FormAbilityReleaseForm", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h new file mode 100644 index 0000000000000000000000000000000000000000..3496d85a47a86ee933ea08f97a56653dc1c9a11b --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_A_H_ +#define _FORM_ABILITY_A_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilityA : public Ability { +public: + ~FormAbilityA(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_deleteFormCommon(std::string strFormId); + + void FMS_acquireForm_0300(std::string data); + void FMS_acquireForm_0400(std::string data); + void FMS_acquireForm_0500(std::string data); + void FMS_acquireForm_0600(std::string data); + void FMS_acquireForm_0700(std::string data); + void FMS_acquireForm_1000(std::string data); + void FMS_acquireForm_1100(std::string data); + void FMS_acquireForm_1200(std::string data); + void FMS_acquireForm_1500_1(std::string data); + void FMS_acquireForm_1600(std::string data); + void FMS_acquireForm_1600_1(std::string data); + void FMS_acquireForm_1800(std::string data); + void FMS_acquireForm_1800_1(std::string data); + void FMS_acquireForm_1900(std::string data); + void FMS_acquireForm_2100(std::string data); + void FMS_acquireForm_2200(std::string data); + void FMS_acquireForm_2300(std::string data); + void FMS_acquireForm_2400(std::string data); + void FMS_acquireForm_2500(std::string data); + void FMS_acquireForm_2600(std::string data); + void FMS_acquireForm_2600_1(std::string data); + void FMS_acquireForm_2700(std::string data); + void FMS_acquireForm_2800(std::string data); + void FMS_acquireForm_2900(std::string data); + void FMS_acquireForm_3000(std::string data); + void FMS_acquireForm_3100(std::string data); + void FMS_acquireForm_3200(std::string data); + void FMS_acquireForm_3300(std::string data); + void FMS_acquireForm_3400(std::string data); + void FMS_acquireForm_3500(std::string data); + void FMS_acquireForm_tempForm(std::string data); + + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name, int code):caseName_(name), code_(code) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_ = ""; + int code_ = 0; + FormAbilityA *ability_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilityA::*)(std::string data); + std::map memberFuncMap_; + std::map calledFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityA *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_A_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h new file mode 100644 index 0000000000000000000000000000000000000000..c0292b7fe830f3e3df90c9358090faa50db3ae32 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_DELETEFORM_H_ +#define _FORM_ABILITY_DELETEFORM_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriberForDeleteForm; +class FormAbilityDeleteForm : public Ability { +public: + void SubscribeEvent(const std::vector &eventList); + void handleEvent(std::string action, std::string data); + void FMS_deleteForm_common(int64_t formId, std::string caseName, std::string lastFormId); + void FMS_deleteForm_0300(std::string data); + void FMS_deleteForm_0400(std::string data); + void FMS_deleteForm_0500(std::string data); + void FMS_deleteForm_0600(std::string data); + void FMS_deleteForm_0700(std::string data); + void FMS_deleteForm_0800(std::string data); + void FMS_deleteForm_0900(std::string data); + void FMS_deleteForm_1000(std::string data); + void FMS_deleteForm_1100(std::string data); + void FMS_deleteForm_1200(std::string data); + void FMS_deleteForm_1400(std::string data); + void FMS_deleteForm_1500(std::string data); + void FMS_deleteForm_1600(std::string data); + void FMS_deleteForm_1700(std::string data); + + std::shared_ptr subscriber_; + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name, std::string id):caseName_(name), lastformId_(id) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + FormAbilityDeleteForm *ability_; + std::string caseName_; + std::string lastformId_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(std::string case_id, int64_t form_id); + void DeleteForm_0300(int64_t form_id); + void DeleteForm_0400(int64_t form_id); + void DeleteForm_0500(int64_t form_id); + void DeleteForm_0600(int64_t form_id); + void DeleteForm_0700(int64_t form_id, std::string lastFormId); + void DeleteForm_0800(int64_t form_id); + void DeleteForm_0900(int64_t form_id); + void DeleteForm_1000(int64_t form_id); + void DeleteForm_1100(int64_t form_id, std::string lastFormId); + void DeleteForm_1200(int64_t form_id); + void DeleteForm_1400(int64_t form_id); + void DeleteForm_1500(int64_t form_id); + void DeleteForm_1600(int64_t form_id); + void DeleteForm_1700(int64_t form_id); + + using FormFunc = void (FormAbilityDeleteForm::*)(std::string data); + std::map memberFuncMap_; + std::shared_ptr callback_; +}; +class FormEventSubscriberForDeleteForm : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriberForDeleteForm(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriberForDeleteForm() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityDeleteForm *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_DELETEFORM_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_releaseform.h b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_releaseform.h new file mode 100644 index 0000000000000000000000000000000000000000..ede79f60ff86e1297acb87905a0c0a0aaca5070a --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_releaseform.h @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_RELEASEFORM_H_ +#define _FORM_ABILITY_RELEASEFORM_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriberForReleaseForm; +class FormAbilityReleaseForm : public Ability { +public: + void SubscribeEvent(const std::vector &eventList); + void handleEvent(std::string action, std::string data); + void FMS_releaseForm_common(int64_t formId, std::string caseName, std::string lastFormId); + void FMS_releaseForm_0300(std::string data); + void FMS_releaseForm_0400(std::string data); + void FMS_releaseForm_0500(std::string data); + void FMS_releaseForm_0600(std::string data); + void FMS_releaseForm_0700(std::string data); + void FMS_releaseForm_0800(std::string data); + void FMS_releaseForm_0900(std::string data); + void FMS_releaseForm_1000(std::string data); + void FMS_releaseForm_1100(std::string data); + void FMS_releaseForm_1200(std::string data); + void FMS_releaseForm_1300(std::string data); + void FMS_releaseForm_1400(std::string data); + + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name, std::string id):caseName_(name), lastformId_(id) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + FormAbilityReleaseForm *ability_; + std::string caseName_; + std::string lastformId_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(std::string case_id, int64_t form_id); + void ReleaseForm_0300(int64_t form_id); + void ReleaseForm_0400(int64_t form_id); + void ReleaseForm_0500(int64_t form_id); + void ReleaseForm_0600(int64_t form_id); + void ReleaseForm_0700(int64_t form_id, std::string lastFormId); + void ReleaseForm_0800(int64_t form_id, std::string lastFormId); + void ReleaseForm_0900(int64_t form_id); + void ReleaseForm_1000(int64_t form_id, std::string lastFormId); + void ReleaseForm_1100(int64_t form_id, std::string lastFormId); + void ReleaseForm_1200(int64_t form_id); + void ReleaseForm_1300(int64_t form_id, std::string lastFormId); + void ReleaseForm_1400(int64_t form_id); + + using FormFunc = void (FormAbilityReleaseForm::*)(std::string data); + std::map memberFuncMap_; + std::shared_ptr callback_; +}; +class FormEventSubscriberForReleaseForm : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriberForReleaseForm(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriberForReleaseForm() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityReleaseForm *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_RELEASEFORM_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..083b3006d26f8cc15abf4e26cacfe7a5619788f4 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp @@ -0,0 +1,711 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_a.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_DELETE_FORM_COMMON, + FORM_EVENT_REQ_ACQUIRE_FORM_0300, FORM_EVENT_REQ_ACQUIRE_FORM_0400, FORM_EVENT_REQ_ACQUIRE_FORM_0500, + FORM_EVENT_REQ_ACQUIRE_FORM_0600, FORM_EVENT_REQ_ACQUIRE_FORM_0700, FORM_EVENT_REQ_ACQUIRE_FORM_1000, + FORM_EVENT_REQ_ACQUIRE_FORM_1100, FORM_EVENT_REQ_ACQUIRE_FORM_1200, FORM_EVENT_REQ_ACQUIRE_FORM_1500_1, + FORM_EVENT_REQ_ACQUIRE_FORM_1600, FORM_EVENT_REQ_ACQUIRE_FORM_1600_1, FORM_EVENT_REQ_ACQUIRE_FORM_1800, + FORM_EVENT_REQ_ACQUIRE_FORM_1800_1, FORM_EVENT_REQ_ACQUIRE_FORM_1900, FORM_EVENT_REQ_ACQUIRE_FORM_2400, + FORM_EVENT_REQ_ACQUIRE_FORM_2100, FORM_EVENT_REQ_ACQUIRE_FORM_2200, FORM_EVENT_REQ_ACQUIRE_FORM_2300, + FORM_EVENT_REQ_ACQUIRE_FORM_2500, FORM_EVENT_REQ_ACQUIRE_FORM_2600, FORM_EVENT_REQ_ACQUIRE_FORM_2600_1, + FORM_EVENT_REQ_ACQUIRE_FORM_2700, FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, +}; +void FormAbilityA::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(this->caseName_, this->code_, std::to_string(formJsInfo.formId)); +} +void FormAbilityA::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(this->caseName_, this->code_ + 1, formJsInfo.formData); + + if (this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1200 + || this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1600 + || this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1600_1 + || this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1800 + || this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1800_1 + || this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1900) { + std::string strFormId = std::to_string(formJsInfo.formId); + APP_LOGI("%{public}s, delete form, formId: %{public}s", __func__, strFormId.c_str()); + ability_->FMS_deleteFormCommon(strFormId); + } +} + +void FormAbilityA::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityA::FMS_deleteFormCommon(std::string strFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); + int64_t formId = std::stoll(strFormId); + sleep(1); + bool bResult = DeleteForm(formId); + sleep(1); + if (bResult) { + APP_LOGI("DeleteForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "true"); + } else { + APP_LOGE("DeleteForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + } +} + +void FormAbilityA::FMS_acquireForm_0300(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(-1, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300, "false"); + } +} +void FormAbilityA::FMS_acquireForm_0400(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0400, EVENT_CODE_400); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, "com.form.bundlename99", FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0400, EVENT_CODE_400, "false"); + } +} +void FormAbilityA::FMS_acquireForm_0500(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0500, EVENT_CODE_500); + // Set Want info begin + std::string moduleName = "moduleName99"; + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, moduleName); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0500, EVENT_CODE_500, "false"); + } +} +void FormAbilityA::FMS_acquireForm_0600(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0600, EVENT_CODE_600); + // Set Want info begin + std::string formName = "formName999"; + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, formName); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0600, EVENT_CODE_600, "false"); + } +} +void FormAbilityA::FMS_acquireForm_0700(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_0700, EVENT_CODE_700); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, "abilityName9"); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0700, EVENT_CODE_700, "false"); + } +} +void FormAbilityA::FMS_acquireForm_1000(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1000, EVENT_CODE_1000); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, 0); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1000, EVENT_CODE_1000, "false"); + } +} +void FormAbilityA::FMS_acquireForm_1100(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1100); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1100, ""); + } +} +void FormAbilityA::FMS_acquireForm_1200(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1200); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME2); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME2); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME2, FORM_PROVIDER_ABILITY_NAME2); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1200, ""); + } +} + +void FormAbilityA::FMS_acquireForm_1500_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1510); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1510, ""); + } +} + +void FormAbilityA::FMS_acquireForm_1600(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1600); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1600, ""); + } +} +void FormAbilityA::FMS_acquireForm_1600_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1610); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1610, ""); + } +} +void FormAbilityA::FMS_acquireForm_1800(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1800); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1800, ""); + } +} +void FormAbilityA::FMS_acquireForm_1800_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1810); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1810, ""); + } +} +void FormAbilityA::FMS_acquireForm_1900(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1900); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1900, ""); + } +} +void FormAbilityA::FMS_acquireForm_2100(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2100, EVENT_CODE_2100); + callback->ability_ = this; + // Set Want info begin + int64_t formId = std::stoll(data); + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(formId, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2100, EVENT_CODE_2100, "false"); + } +} +void FormAbilityA::FMS_acquireForm_2200(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2200, EVENT_CODE_2200); + + // Set Want info end + bool bResult = CastTempForm(-1); + if (bResult) { + APP_LOGI("CastTempForm end"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2200, EVENT_CODE_2200, "false"); + } +} +void FormAbilityA::FMS_acquireForm_2300(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2300, EVENT_CODE_2300); + + // Set Want info end + bool bResult = CastTempForm(0); + if (bResult) { + APP_LOGI("CastTempForm end"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2300, EVENT_CODE_2300, "false"); + } +} +void FormAbilityA::FMS_acquireForm_2400(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2400); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2400, ""); + } +} + +void FormAbilityA::FMS_acquireForm_2500(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500); + + // Set Want info end + bool bResult = CastTempForm(EVENT_CODE_1234); + if (bResult) { + APP_LOGI("CastTempForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500, "true"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500, "false"); + } +} +void FormAbilityA::FMS_acquireForm_2600_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2610); + + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2610, ""); + } +} + +void FormAbilityA::FMS_acquireForm_2600(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2600, EVENT_CODE_2600); + callback->ability_ = this; + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = CastTempForm(formId); + if (bResult) { + APP_LOGI("CastTempForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2600, EVENT_CODE_2600, "true"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2600, EVENT_CODE_2600, "false"); + } + + FMS_deleteFormCommon(data); +} + +void FormAbilityA::FMS_acquireForm_2700(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700); + + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = CastTempForm(formId); + if (bResult) { + APP_LOGI("CastTempForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700, "true"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700, "false"); + } + + FMS_deleteFormCommon(data); +} +void FormAbilityA::FMS_acquireForm_2800(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_2900(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3000(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3100(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3200(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3300(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3400(std::string data) +{ +} +void FormAbilityA::FMS_acquireForm_3500(std::string data) +{ +} + +void FormAbilityA::FMS_acquireForm_tempForm(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP); + + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, ""); + } +} + +FormAbilityA::~FormAbilityA() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilityA::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityA::onStart"); + Ability::OnStart(want); +} +void FormAbilityA::OnActive() +{ + APP_LOGI("FormAbilityA::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityA::OnStop() +{ + APP_LOGI("FormAbilityA::OnStop"); + + Ability::OnStop(); +} +void FormAbilityA::OnInactive() +{ + APP_LOGI("FormAbilityA::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityA::OnBackground() +{ + APP_LOGI("FormAbilityA::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityA::SubscribeEvent() +{ + APP_LOGI("FormAbilityA::SubscribeEvent"); + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityA::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityA::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0300] = &FormAbilityA::FMS_acquireForm_0300; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0400] = &FormAbilityA::FMS_acquireForm_0400; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0500] = &FormAbilityA::FMS_acquireForm_0500; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0600] = &FormAbilityA::FMS_acquireForm_0600; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0700] = &FormAbilityA::FMS_acquireForm_0700; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1000] = &FormAbilityA::FMS_acquireForm_1000; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1100] = &FormAbilityA::FMS_acquireForm_1100; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1200] = &FormAbilityA::FMS_acquireForm_1200; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1500_1] = &FormAbilityA::FMS_acquireForm_1500_1; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1600] = &FormAbilityA::FMS_acquireForm_1600; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1600_1] = &FormAbilityA::FMS_acquireForm_1600_1; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1800] = &FormAbilityA::FMS_acquireForm_1800; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1800_1] = &FormAbilityA::FMS_acquireForm_1800_1; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1900] = &FormAbilityA::FMS_acquireForm_1900; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2100] = &FormAbilityA::FMS_acquireForm_2100; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2200] = &FormAbilityA::FMS_acquireForm_2200; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2300] = &FormAbilityA::FMS_acquireForm_2300; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2400] = &FormAbilityA::FMS_acquireForm_2400; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2500] = &FormAbilityA::FMS_acquireForm_2500; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2600] = &FormAbilityA::FMS_acquireForm_2600; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2600_1] = &FormAbilityA::FMS_acquireForm_2600_1; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2700] = &FormAbilityA::FMS_acquireForm_2700; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_COMMON] = &FormAbilityA::FMS_deleteFormCommon; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_TEMP] = &FormAbilityA::FMS_acquireForm_tempForm; + SubscribeEvent(); +} + +void FormAbilityA::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilityA::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityA) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf6e17eafe6cf963fc9913a6033d2ee3082d45fb --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp @@ -0,0 +1,534 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_deleteform.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +void FormAbilityDeleteForm::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s receive formId:%{public}s", __func__, std::to_string(formJsInfo.formId).c_str()); + if (this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0600) { + ability_->FMS_deleteForm_common(atoll(this->lastformId_.c_str()), this->caseName_, this->lastformId_); + } +} +void FormAbilityDeleteForm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s receive formData:%{public}s", __func__, formJsInfo.formData.c_str()); + if (this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0300 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0400 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0700 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0800 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_0900 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1000 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1100) { + ability_->FMS_deleteForm_common(formJsInfo.formId, this->caseName_, this->lastformId_); + } +} + +void FormAbilityDeleteForm::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +void FormAbilityDeleteForm::FMS_deleteForm_common(int64_t formId, std::string caseName, std::string lastFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s, caseName:%{public}s, lastFormId:%{public}s", + __func__, std::to_string(formId).c_str(), caseName.c_str(), lastFormId.c_str()); + if (caseName == FORM_EVENT_RECV_DELETE_FORM_0300) { + DeleteForm_0300(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0400) { + DeleteForm_0400(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0600) { + DeleteForm_0600(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0700) { + DeleteForm_0700(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0800) { + DeleteForm_0800(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_0900) { + DeleteForm_0900(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1000) { + DeleteForm_1000(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1100) { + DeleteForm_1100(formId, lastFormId); + } else { + return; + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0300(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0300, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0300] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0300] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300, ""); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_0400(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0400, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0400] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0400] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0500(std::string data) +{ + APP_LOGI("[FMS_deleteForm_0500] start[%{public}s]", data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, data); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0500] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0500] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500, "false"); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0600(std::string data) +{ + APP_LOGI("[FMS_deleteForm_0600] start[%{public}s]", data.c_str()); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0600, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(atoll(data.c_str()), want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0600] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0600] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0700(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0700, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0700] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0700] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0800(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0800, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0800] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0800] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800, ""); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_0900(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0900, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0900] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_0900] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1000(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1000, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_1000] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_1000] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1100(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1100, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_deleteForm_1100] AcquireForm ok."); + } else { + APP_LOGE("[FMS_deleteForm_1100] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1200(std::string data) +{} + +void FormAbilityDeleteForm::FMS_deleteForm_1400(std::string data) +{} + +void FormAbilityDeleteForm::FMS_deleteForm_1500(std::string data) +{} + +void FormAbilityDeleteForm::FMS_deleteForm_1600(std::string data) +{} + +void FormAbilityDeleteForm::FMS_deleteForm_1700(std::string data) +{} + + +void FormAbilityDeleteForm::DeleteForm_0300(int64_t form_id) +{ + bool bResult = DeleteForm(-1); + Clear("FMS_deleteForm_0300", form_id); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0300] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0300] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0400(int64_t form_id) +{ + bool bResult = DeleteForm(0); + Clear("FMS_deleteForm_0400", form_id); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0400] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0400] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0500(int64_t form_id) +{} + +void FormAbilityDeleteForm::DeleteForm_0600(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0600] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0600] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0700(int64_t form_id, std::string lastFormId) +{ + bool bResult = DeleteForm(form_id); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0700] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0700] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0800(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0800] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0800] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0900(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + bool realResult = DeleteForm(form_id); + if (realResult) { + APP_LOGI("[FMS_deleteForm_0900] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, "true"); + } else { + APP_LOGE("[FMS_deleteForm_0900] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, "false"); + } + } else { + APP_LOGE("[FMS_deleteForm_0900] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, ""); + } +} + +void FormAbilityDeleteForm::DeleteForm_1000(int64_t form_id) +{ + bool bResult = ReleaseForm(form_id); + if (bResult) { + bool realResult = DeleteForm(form_id); + if (realResult) { + APP_LOGI("[FMS_deleteForm_1000] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "true"); + } else { + APP_LOGE("[FMS_deleteForm_1000] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "false"); + } + } else { + APP_LOGE("[FMS_deleteForm_1000] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, ""); + } +} +void FormAbilityDeleteForm::DeleteForm_1100(int64_t form_id, std::string lastFormId) +{ + bool bResult = DeleteForm(form_id); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + if (bResult) { + APP_LOGI("[FMS_deleteForm_1100] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, "true"); + } else { + APP_LOGE("[FMS_deleteForm_1100] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, "false"); + } +} +void FormAbilityDeleteForm::DeleteForm_1200(int64_t form_id) +{} +void FormAbilityDeleteForm::DeleteForm_1400(int64_t form_id) +{} +void FormAbilityDeleteForm::DeleteForm_1500(int64_t form_id) +{} +void FormAbilityDeleteForm::DeleteForm_1600(int64_t form_id) +{} +void FormAbilityDeleteForm::DeleteForm_1700(int64_t form_id) +{} + +void FormAbilityDeleteForm::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityDeleteForm::onStart"); + Ability::OnStart(want); + + std::vector eventList = { + FORM_EVENT_REQ_DELETE_FORM_0300, + FORM_EVENT_REQ_DELETE_FORM_0400, + FORM_EVENT_REQ_DELETE_FORM_0500, + FORM_EVENT_REQ_DELETE_FORM_0600, + FORM_EVENT_REQ_DELETE_FORM_0700, + FORM_EVENT_REQ_DELETE_FORM_0800, + FORM_EVENT_REQ_DELETE_FORM_0900, + FORM_EVENT_REQ_DELETE_FORM_1000, + FORM_EVENT_REQ_DELETE_FORM_1100, + FORM_EVENT_REQ_DELETE_FORM_1200, + FORM_EVENT_REQ_DELETE_FORM_1400, + FORM_EVENT_REQ_DELETE_FORM_1500, + FORM_EVENT_REQ_DELETE_FORM_1600, + FORM_EVENT_REQ_DELETE_FORM_1700 + }; + SubscribeEvent(eventList); +} +void FormAbilityDeleteForm::OnActive() +{ + APP_LOGI("FormAbilityDeleteForm::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityDeleteForm::OnStop() +{ + APP_LOGI("FormAbilityDeleteForm::OnStop"); + + Ability::OnStop(); +} +void FormAbilityDeleteForm::OnInactive() +{ + APP_LOGI("FormAbilityDeleteForm::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityDeleteForm::OnBackground() +{ + APP_LOGI("FormAbilityDeleteForm::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityDeleteForm::SubscribeEvent(const std::vector &eventList) +{ + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityDeleteForm::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityDeleteForm::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0300] = &FormAbilityDeleteForm::FMS_deleteForm_0300; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0400] = &FormAbilityDeleteForm::FMS_deleteForm_0400; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0500] = &FormAbilityDeleteForm::FMS_deleteForm_0500; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0600] = &FormAbilityDeleteForm::FMS_deleteForm_0600; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0700] = &FormAbilityDeleteForm::FMS_deleteForm_0700; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0800] = &FormAbilityDeleteForm::FMS_deleteForm_0800; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0900] = &FormAbilityDeleteForm::FMS_deleteForm_0900; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1000] = &FormAbilityDeleteForm::FMS_deleteForm_1000; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1100] = &FormAbilityDeleteForm::FMS_deleteForm_1100; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1200] = &FormAbilityDeleteForm::FMS_deleteForm_1200; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1400] = &FormAbilityDeleteForm::FMS_deleteForm_1400; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1500] = &FormAbilityDeleteForm::FMS_deleteForm_1500; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1600] = &FormAbilityDeleteForm::FMS_deleteForm_1600; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1700] = &FormAbilityDeleteForm::FMS_deleteForm_1700; +} + +void FormAbilityDeleteForm::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilityDeleteForm::Clear(std::string case_id, int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("[%{public}s] clear ok", case_id.c_str()); + } else { + APP_LOGE("[%{public}s] clear error", case_id.c_str()); + } +} + +void FormEventSubscriberForDeleteForm::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriberForDeleteForm::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("FormEventSubscriberForDeleteForm::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriberForDeleteForm::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityDeleteForm) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ca469fd0786ff3e69fc4fb73632728a3738fc9e --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp @@ -0,0 +1,635 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_releaseform.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +void FormAbilityReleaseForm::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s receive formId:%{public}s", __func__, std::to_string(formJsInfo.formId).c_str()); + if (this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0700 || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_1000) { + ability_->FMS_releaseForm_common(atoll(this->lastformId_.c_str()), this->caseName_, this->lastformId_); + } +} +void FormAbilityReleaseForm::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s receive formData:%{public}s", __func__, formJsInfo.formData.c_str()); + if (this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0300 || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0400 + || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0600 || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0800 + || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_0900 || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_1100 + || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_1200 || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_1300 + || this->caseName_ == FORM_EVENT_RECV_RELEASE_FORM_1400) { + ability_->FMS_releaseForm_common(formJsInfo.formId, this->caseName_, this->lastformId_); + } +} + +void FormAbilityReleaseForm::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +void FormAbilityReleaseForm::FMS_releaseForm_common(int64_t formId, std::string caseName, std::string lastFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s, caseName:%{public}s, lastFormId:%{public}s", + __func__, std::to_string(formId).c_str(), caseName.c_str(), lastFormId.c_str()); + if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0300) { + ReleaseForm_0300(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0400) { + ReleaseForm_0400(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0600) { + ReleaseForm_0600(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0700) { + ReleaseForm_0700(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0800) { + ReleaseForm_0800(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0900) { + ReleaseForm_0900(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1000) { + ReleaseForm_1000(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1100) { + ReleaseForm_1100(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1200) { + ReleaseForm_1200(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1300) { + ReleaseForm_1300(formId, lastFormId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1400) { + ReleaseForm_1400(formId); + } else { + return; + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0300(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0300, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0300] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0300] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300, ""); + } +} +void FormAbilityReleaseForm::FMS_releaseForm_0400(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0400, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0400] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0400] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0500(std::string data) +{ + APP_LOGI("[FMS_releaseForm_0500] start[%{public}s]", data.c_str()); + bool bResult = ReleaseForm(atoll(data.c_str()), true); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, data); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0500] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0500, EVENT_CODE_500, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0500] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0500, EVENT_CODE_500, "false"); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0600(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0600, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0600] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0600] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0700(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0700, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(atoll(data.c_str()), want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0700] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0700] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0800(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0800, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0800] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0800] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, ""); + } +} +void FormAbilityReleaseForm::FMS_releaseForm_0900(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_0900, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0900] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_0900] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_1000(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_1000, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(atoll(data.c_str()), want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1000] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_1000] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_1100(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_1100, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1100] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_1100] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_1200(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_1200, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1200] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_1200] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_1300(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_1300, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1300] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_1300] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_1400(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_RELEASE_FORM_1400, data); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1400] AcquireForm ok."); + } else { + APP_LOGE("[FMS_releaseForm_1400] AcquireForm error."); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, ""); + } +} + +void FormAbilityReleaseForm::ReleaseForm_0300(int64_t form_id) +{ + int64_t formId = -1; + bool isReleaseCache = true; + bool bResult = ReleaseForm(formId, isReleaseCache); + Clear("FMS_releaseForm_0300", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0300] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0300] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300, "false"); + } +} + +void FormAbilityReleaseForm::ReleaseForm_0400(int64_t form_id) +{ + int64_t formId = 0; + bool isReleaseCache = true; + bool bResult = ReleaseForm(formId, isReleaseCache); + Clear("FMS_releaseForm_0400", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0400] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0400] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400, "false"); + } +} + +void FormAbilityReleaseForm::ReleaseForm_0500(int64_t form_id) +{} + +void FormAbilityReleaseForm::ReleaseForm_0600(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + bool isReleaseCache = true; + bool realResult = ReleaseForm(form_id, isReleaseCache); + if (realResult) { + APP_LOGI("[FMS_releaseForm_0600] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0600] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, "false"); + } + } else { + APP_LOGE("[FMS_releaseForm_0600] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, ""); + } +} + +void FormAbilityReleaseForm::ReleaseForm_0700(int64_t form_id, std::string lastFormId) +{ + bool isReleaseCache = false; + bool bResult = ReleaseForm(form_id, isReleaseCache); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + Clear("FMS_releaseForm_0700", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0700] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0700] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_0800(int64_t form_id, std::string lastFormId) +{ + bool isReleaseCache = false; + bool bResult = ReleaseForm(form_id, isReleaseCache); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + Clear("FMS_releaseForm_0800", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0800] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0800] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_0900(int64_t form_id) +{ + bool isReleaseCache = false; + bool bResult = ReleaseForm(form_id, isReleaseCache); + Clear("FMS_releaseForm_0900", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0900] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, "true"); + } else { + APP_LOGE("[FMS_releaseForm_0900] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1000(int64_t form_id, std::string lastFormId) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + Clear("FMS_releaseForm_1000", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1000] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, "true"); + } else { + APP_LOGE("[FMS_releaseForm_1000] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1100(int64_t form_id, std::string lastFormId) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + // Clear + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_110, lastFormId); + Clear("FMS_releaseForm_1100", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1100] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100, "true"); + } else { + APP_LOGE("[FMS_releaseForm_1100] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1200(int64_t form_id) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + Clear("FMS_releaseForm_1200", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1200] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200, "true"); + } else { + APP_LOGE("[FMS_releaseForm_1200] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1300(int64_t form_id, std::string lastFormId) +{ + if (lastFormId == "") { + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300, std::to_string(form_id)); + } else { + bool isReleaseCache = true; + bool bResult1 = ReleaseForm(form_id, isReleaseCache); + bool bResult2 = ReleaseForm(atoll(lastFormId.c_str()), isReleaseCache); + Clear("FMS_releaseForm_1300", form_id); + Clear("FMS_releaseForm_1300", atoll(lastFormId.c_str())); + if (bResult1 && bResult2) { + APP_LOGI("[FMS_releaseForm_1300] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300, "true"); + } else { + APP_LOGE("[FMS_releaseForm_1300] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300, "false"); + } + } +} +void FormAbilityReleaseForm::ReleaseForm_1400(int64_t form_id) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + Clear("FMS_releaseForm_1400", form_id); + if (bResult) { + APP_LOGI("[FMS_releaseForm_1400] end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, "true"); + } else { + APP_LOGE("[FMS_releaseForm_1400] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, "false"); + } +} + +void FormAbilityReleaseForm::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityReleaseForm::onStart"); + Ability::OnStart(want); + + std::vector eventList = { + FORM_EVENT_REQ_RELEASE_FORM_0300, + FORM_EVENT_REQ_RELEASE_FORM_0400, + FORM_EVENT_REQ_RELEASE_FORM_0500, + FORM_EVENT_REQ_RELEASE_FORM_0600, + FORM_EVENT_REQ_RELEASE_FORM_0700, + FORM_EVENT_REQ_RELEASE_FORM_0800, + FORM_EVENT_REQ_RELEASE_FORM_0900, + FORM_EVENT_REQ_RELEASE_FORM_1000, + FORM_EVENT_REQ_RELEASE_FORM_1100, + FORM_EVENT_REQ_RELEASE_FORM_1200, + FORM_EVENT_REQ_RELEASE_FORM_1300, + FORM_EVENT_REQ_RELEASE_FORM_1400, + }; + SubscribeEvent(eventList); +} +void FormAbilityReleaseForm::OnActive() +{ + APP_LOGI("FormAbilityReleaseForm::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityReleaseForm::OnStop() +{ + APP_LOGI("FormAbilityReleaseForm::OnStop"); + + Ability::OnStop(); +} +void FormAbilityReleaseForm::OnInactive() +{ + APP_LOGI("FormAbilityReleaseForm::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityReleaseForm::OnBackground() +{ + APP_LOGI("FormAbilityReleaseForm::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityReleaseForm::SubscribeEvent(const std::vector &eventList) +{ + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityReleaseForm::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityReleaseForm::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0300] = &FormAbilityReleaseForm::FMS_releaseForm_0300; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0400] = &FormAbilityReleaseForm::FMS_releaseForm_0400; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0500] = &FormAbilityReleaseForm::FMS_releaseForm_0500; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0600] = &FormAbilityReleaseForm::FMS_releaseForm_0600; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0700] = &FormAbilityReleaseForm::FMS_releaseForm_0700; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0800] = &FormAbilityReleaseForm::FMS_releaseForm_0800; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0900] = &FormAbilityReleaseForm::FMS_releaseForm_0900; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_1000] = &FormAbilityReleaseForm::FMS_releaseForm_1000; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_1100] = &FormAbilityReleaseForm::FMS_releaseForm_1100; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_1200] = &FormAbilityReleaseForm::FMS_releaseForm_1200; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_1300] = &FormAbilityReleaseForm::FMS_releaseForm_1300; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_1400] = &FormAbilityReleaseForm::FMS_releaseForm_1400; +} + +void FormAbilityReleaseForm::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilityReleaseForm::Clear(std::string case_id, int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("[%{public}s] clear ok", case_id.c_str()); + } else { + APP_LOGE("[%{public}s] clear error", case_id.c_str()); + } +} + +void FormEventSubscriberForReleaseForm::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriberForReleaseForm::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("FormEventSubscriberForReleaseForm::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + if (data.GetCode() == EVENT_CODE_1300 && data.GetData() == "") { + return; + } else { + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); + } +} + +void FormEventSubscriberForReleaseForm::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityReleaseForm) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..3f206845487cca0bcd59efa473f733be9a66ffe1 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("fmsSystemTestHostNormalBConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNormalB") { + sources = [ + "../tool/src/form_test_utils.cpp", + "src/form_ability_b.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":fmsSystemTestHostNormalBConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/config.json b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/config.json new file mode 100644 index 0000000000000000000000000000000000000000..5102f274b673e399a14ce84448f37fbf0c07b28d --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.normalb", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.normalb.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbilityB", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityB", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability B", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/include/form_ability_b.h b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/include/form_ability_b.h new file mode 100644 index 0000000000000000000000000000000000000000..ebf2b64fca21f9eb9c226b03e03a265a3803745d --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/include/form_ability_b.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_B_H_ +#define _FORM_ABILITY_B_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilityB : public Ability { +public: + ~FormAbilityB(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_deleteFormCommon(int64_t formId); + + void FMS_acquireForm_1400(std::string data); + void FMS_acquireForm_1500(std::string data); + void FMS_acquireForm_1800_2(std::string data); + void FMS_acquireForm_1800_3(std::string data); + void FMS_acquireForm_2400_1(std::string data); + + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name, int code):caseName_(name), code_(code) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_ = ""; + int code_ = 0; + FormAbilityB *ability_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilityB::*)(std::string data); + std::map memberFuncMap_; + std::map calledFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityB *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_B_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6bdfa341b8e0742908b8da37e3c38bae5644ecb8 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp @@ -0,0 +1,285 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_b.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_ACQUIRE_FORM_1400, FORM_EVENT_REQ_ACQUIRE_FORM_1500, + FORM_EVENT_REQ_ACQUIRE_FORM_1800_2, FORM_EVENT_REQ_ACQUIRE_FORM_1800_3, + FORM_EVENT_REQ_ACQUIRE_FORM_2400_1, +}; +void FormAbilityB::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(this->caseName_, this->code_, std::to_string(formJsInfo.formId)); + if (this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1500) { + APP_LOGI("%{public}s, delete form", __func__); + ability_->FMS_deleteFormCommon(formJsInfo.formId); + } +} +void FormAbilityB::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(this->caseName_, this->code_ + 1, formJsInfo.formData); + if (this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1800_2 || + this->caseName_ == FORM_EVENT_RECV_ACQUIRE_FORM_1800_3) { + APP_LOGI("%{public}s, delete form", __func__); + ability_->FMS_deleteFormCommon(formJsInfo.formId); + } +} + +void FormAbilityB::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityB::FMS_deleteFormCommon(int64_t formId) +{ + sleep(1); + APP_LOGI("%{public}s called, formId: %{public}lld", __func__, formId); + bool bResult = DeleteForm(formId); + sleep(1); + if (bResult) { + APP_LOGI("DeleteForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "true"); + } else { + APP_LOGE("DeleteForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + } +} + +void FormAbilityB::FMS_acquireForm_1400(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1400, EVENT_CODE_1400); + // Set Want info begin + std::string formName = "formName999"; + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, formName); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = AcquireForm(formId, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1400, EVENT_CODE_1400, "false"); + } +} +void FormAbilityB::FMS_acquireForm_1500(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1500, EVENT_CODE_1500); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = AcquireForm(formId, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1500, EVENT_CODE_1500, ""); + } +} + +void FormAbilityB::FMS_acquireForm_1800_2(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1820); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1820, ""); + } +} +void FormAbilityB::FMS_acquireForm_1800_3(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1830); + callback->ability_ = this; + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1830, ""); + } +} + +void FormAbilityB::FMS_acquireForm_2400_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410); + callback->ability_ = this; + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = CastTempForm(formId); + if (bResult) { + APP_LOGI("CastTempForm end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410, "true"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410, "false"); + } +} + +FormAbilityB::~FormAbilityB() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilityB::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityB::onStart"); + Ability::OnStart(want); +} +void FormAbilityB::OnActive() +{ + APP_LOGI("FormAbilityB::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityB::OnStop() +{ + APP_LOGI("FormAbilityB::OnStop"); + + Ability::OnStop(); +} +void FormAbilityB::OnInactive() +{ + APP_LOGI("FormAbilityB::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityB::OnBackground() +{ + APP_LOGI("FormAbilityB::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityB::SubscribeEvent() +{ + APP_LOGI("FormAbilityB::SubscribeEvent"); + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityB::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityB::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1400] = &FormAbilityB::FMS_acquireForm_1400; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1500] = &FormAbilityB::FMS_acquireForm_1500; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1800_2] = &FormAbilityB::FMS_acquireForm_1800_2; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_1800_3] = &FormAbilityB::FMS_acquireForm_1800_3; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2400_1] = &FormAbilityB::FMS_acquireForm_2400_1; + + SubscribeEvent(); +} + +void FormAbilityB::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilityB::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityB) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNotSys/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..6c67d9f296d8b974ade168af35de57f38c9f2735 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("fmsSystemTestHostNotSysConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNotSys") { + sources = [ + "../tool/src/form_test_utils.cpp", + "src/form_ability_not_sys.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":fmsSystemTestHostNotSysConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNotSys/config.json b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bf7d51772e727006301204c4d986e69077cb6d74 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.notsystemapp", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.notsystemapp.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityNotSys", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNotSys/include/form_ability_not_sys.h b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/include/form_ability_not_sys.h new file mode 100644 index 0000000000000000000000000000000000000000..8e5eb6467e0b8af8f9e857d083b91a35409810e5 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/include/form_ability_not_sys.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_NOT_SYS_H_ +#define _FORM_ABILITY_NOT_SYS_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilityNotSys : public Ability { +public: + void SubscribeEvent(const std::vector &eventList); + void handleEvent(std::string action); + + void FMS_acquireForm_0100(); + void FMS_deleteForm_0100(); + void FMS_releaseForm_0100(); + + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback(std::string name):caseName_(name) + { + } + virtual ~AcquireFormCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilityNotSys::*)(); + std::map memberFuncMap_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityNotSys *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_NOT_SYS_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNotSys/src/form_ability_not_sys.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/src/form_ability_not_sys.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef06ae7609054797765bc020b5a48d460a2bdea4 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNotSys/src/form_ability_not_sys.cpp @@ -0,0 +1,180 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_not_sys.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +void FormAbilityNotSys::AcquireFormCallback::OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityNotSys::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityNotSys::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityNotSys::FMS_acquireForm_0100() +{ + std::shared_ptr callback = std::make_shared("FMS_acquireForm_0100"); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_0100, EVENT_CODE_100, "false"); + } +} + +void FormAbilityNotSys::FMS_deleteForm_0100() +{ + int64_t formId = 1; + bool bResult = DeleteForm(formId); + if (bResult) { + APP_LOGI("[FMS_deleteForm_0100] end"); + } else { + APP_LOGE("[FMS_deleteForm_0100] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0100, EVENT_CODE_100, "false"); + } +} + +void FormAbilityNotSys::FMS_releaseForm_0100() +{ + int64_t formId = 1; + bool isReleaseCache = true; + bool bResult = ReleaseForm(formId, isReleaseCache); + if (bResult) { + APP_LOGI("[FMS_releaseForm_0100] end"); + } else { + APP_LOGE("[FMS_releaseForm_0100] error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0100, EVENT_CODE_100, "false"); + } +} + +void FormAbilityNotSys::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityNotSys::onStart"); + Ability::OnStart(want); + + std::vector eventList = { + FORM_EVENT_REQ_ACQUIRE_FORM_0100, + FORM_EVENT_REQ_DELETE_FORM_0100, + FORM_EVENT_REQ_RELEASE_FORM_0100, + }; + SubscribeEvent(eventList); +} +void FormAbilityNotSys::OnActive() +{ + APP_LOGI("FormAbilityNotSys::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityNotSys::OnStop() +{ + APP_LOGI("FormAbilityNotSys::OnStop"); + + Ability::OnStop(); +} +void FormAbilityNotSys::OnInactive() +{ + APP_LOGI("FormAbilityNotSys::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityNotSys::OnBackground() +{ + APP_LOGI("FormAbilityNotSys::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityNotSys::SubscribeEvent(const std::vector &eventList) +{ + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilityNotSys::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityNotSys::Init"); + Ability::Init(abilityInfo, application, handler, token); + + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_0100] = &FormAbilityNotSys::FMS_acquireForm_0100; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_0100] = &FormAbilityNotSys::FMS_deleteForm_0100; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_0100] = &FormAbilityNotSys::FMS_releaseForm_0100; +} + +void FormAbilityNotSys::handleEvent(std::string action) +{ + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(); + } + } +} + +void FormAbilityNotSys::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityNotSys) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..1d86964e7300c3247d1a03d1560e237d16109001 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("selfStartingTestHostAConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("selfStartingTestHostA") { + sources = [ + "../../tool/src/form_test_utils.cpp", + "src/form_ability_self_starting_a.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":selfStartingTestHostAConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/config.json b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/config.json new file mode 100644 index 0000000000000000000000000000000000000000..8a8d3824734573e4a60bd138c68ae070c5952a03 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.selfStartingA", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.selfStartingA.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilitySelfStartingA", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability Self Starting A", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/include/form_ability_self_starting_a.h b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/include/form_ability_self_starting_a.h new file mode 100644 index 0000000000000000000000000000000000000000..78e8f9a3af7ecfe31b9eb7bd6c4a4cd8e86d756f --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/include/form_ability_self_starting_a.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_SELF_STARTING_A_H_ +#define _FORM_ABILITY_SELF_STARTING_A_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilitySelfStartingA : public Ability { +public: + ~FormAbilitySelfStartingA(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_Start_0300_01(std::string data); + + std::shared_ptr subscriber_; + + class SelfStartingCallback : public FormCallback { + public: + SelfStartingCallback(std::string name, int code):caseName_(name), code_(code) {} + virtual ~SelfStartingCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_ = ""; + int code_ = 0; + FormAbilitySelfStartingA *ability_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilitySelfStartingA::*)(std::string data); + std::map memberFuncMap_; + std::map calledFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilitySelfStartingA *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_SELF_STARTING_A_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/src/form_ability_self_starting_a.cpp b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/src/form_ability_self_starting_a.cpp new file mode 100644 index 0000000000000000000000000000000000000000..63fab6895159552fb14f33c02938260649128f52 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostA/src/form_ability_self_starting_a.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "form_ability_self_starting_a.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_SELF_STARTING_TEST_0100, +}; +void FormAbilitySelfStartingA::SelfStartingCallback::OnAcquired(const int32_t result, + const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilitySelfStartingA::SelfStartingCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s called, caseName_: %{public}s, code_: %{public}d", __func__, this->caseName_.c_str(), + this->code_); + FormTestUtils::PublishEvent(this->caseName_, this->code_, "true"); +} + +void FormAbilitySelfStartingA::SelfStartingCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +void FormAbilitySelfStartingA::FMS_Start_0300_01(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_SELF_STARTING_TEST_0100, EVENT_CODE_100); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_SELF_STARTING_TEST_0100, EVENT_CODE_100, "false"); + } +} + +FormAbilitySelfStartingA::~FormAbilitySelfStartingA() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +void FormAbilitySelfStartingA::OnStart(const Want &want) +{ + APP_LOGI("FormAbilitySelfStartingA::onStart"); + Ability::OnStart(want); +} +void FormAbilitySelfStartingA::OnActive() +{ + APP_LOGI("FormAbilitySelfStartingA::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilitySelfStartingA::OnStop() +{ + APP_LOGI("FormAbilitySelfStartingA::OnStop"); + + Ability::OnStop(); +} +void FormAbilitySelfStartingA::OnInactive() +{ + APP_LOGI("FormAbilitySelfStartingA::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilitySelfStartingA::OnBackground() +{ + APP_LOGI("FormAbilitySelfStartingA::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilitySelfStartingA::SubscribeEvent() +{ + APP_LOGI("FormAbilitySelfStartingA::SubscribeEvent"); + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilitySelfStartingA::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilitySelfStartingA::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_SELF_STARTING_TEST_0100] = &FormAbilitySelfStartingA::FMS_Start_0300_01; + + SubscribeEvent(); +} + +void FormAbilitySelfStartingA::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilitySelfStartingA::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilitySelfStartingA) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..512d087459702b442833f1e4300a8378c67eefc0 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/BUILD.gn @@ -0,0 +1,70 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("selfStartingTestHostBConfig") { + visibility = [ ":*" ] + include_dirs = [ + "include", + "../../tool/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${appexecfwk_path}/services/bundlemgr/include", + "//foundation/distributedschedule/dmsfwk/services/dtbschedmgr/include", + "//utils/system/safwk/native/include", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/appmgr", + "//third_party/jsoncpp/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("selfStartingTestHostB") { + sources = [ + "../../tool/src/form_test_utils.cpp", + "src/form_ability_self_starting_b.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ ":selfStartingTestHostBConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/base:base", + "${aafwk_path}/interfaces/innerkits/want:want", + "${appexecfwk_path}/common:libappexecfwk_common", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core:appexecfwk_core", + "${appexecfwk_path}/kits:appkit_native", + "${appexecfwk_path}/services/bundlemgr:libbms", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", + "//third_party/jsoncpp:jsoncpp", + "//utils/native/base:utilsbase", + ] + external_deps = [ + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/config.json b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9306f37ea37c2017c4269cde83c97357240760b4 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.selfStartingB", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.selfStartingA.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilitySelfStartingB", + "icon": "$media:snowball", + "srcLanguage": "c++", + "label": "Form Ability Self Starting B", + "launchType": "standard", + "orientation": "unspecified", + "type": "page", + "visible": true, + "skills": [ + { + "actions": [ + "ohos.aafwk.content.Want.ACTION_HOME" + ], + "entities": [ + "ohos.aafwk.content.Want.ENTITY_HOME" + ], + "attributes": [] + } + ] + }], + "defPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "grantMode": "system_grant", + "label": "$string:entry_MainAbility", + "description": "REQUIRE_FORM permission in detail" + } + ], + "reqPermissions": [ + { + "name": "ohos.permission.REQUIRE_FORM", + "reason": "fmsStressTest100", + "usedScene": { + "ability": [ + ".MainAbility" + ], + "when": "always" + } + } + ], + "js": [ + { + "name": "formDemo", + "pages": [ + "pages/index/index" + ], + "type": "form" + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/include/form_ability_self_starting_b.h b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/include/form_ability_self_starting_b.h new file mode 100644 index 0000000000000000000000000000000000000000..e56fe20afbced325dd305512e4a33b0b28b45c2e --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/include/form_ability_self_starting_b.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _FORM_ABILITY_SELF_STARTING_B_H_ +#define _FORM_ABILITY_SELF_STARTING_B_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilitySelfStartingB : public Ability { +public: + ~FormAbilitySelfStartingB(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_Start_0300_02(std::string data); + void FMS_Start_0300_03(std::string data); + + std::shared_ptr subscriber_; + + class SelfStartingCallback : public FormCallback { + public: + SelfStartingCallback(std::string name, int code):caseName_(name), code_(code) {} + virtual ~SelfStartingCallback() = default; + void OnAcquired(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const override; + void OnFormUninstall(const int64_t formId) const override; + + std::string caseName_ = ""; + int code_ = 0; + FormAbilitySelfStartingB *ability_; + }; +protected: + virtual void Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) override; + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; +private: + void Clear(); + + using FormFunc = void (FormAbilitySelfStartingB::*)(std::string data); + std::map memberFuncMap_; + std::map calledFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriber : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriber() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilitySelfStartingB *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_SELF_STARTING_B_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/src/form_ability_self_starting_b.cpp b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/src/form_ability_self_starting_b.cpp new file mode 100644 index 0000000000000000000000000000000000000000..28f419e5dff723e6b22a19dc8982e60d70e75488 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestSelfStarting/selfStartingTestHostB/src/form_ability_self_starting_b.cpp @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_ability_self_starting_b.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_SELF_STARTING_TEST_0200, FORM_EVENT_REQ_SELF_STARTING_TEST_0300, +}; +void FormAbilitySelfStartingB::SelfStartingCallback::OnAcquired(const int32_t result, + const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilitySelfStartingB::SelfStartingCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + APP_LOGI("%{public}s called, caseName_: %{public}s, code_: %{public}d", __func__, this->caseName_.c_str(), + this->code_); + FormTestUtils::PublishEvent(this->caseName_, this->code_, "true"); +} + +void FormAbilitySelfStartingB::SelfStartingCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +void FormAbilitySelfStartingB::FMS_Start_0300_02(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_SELF_STARTING_TEST_0200, EVENT_CODE_200); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_SELF_STARTING_TEST_0200, EVENT_CODE_200, "false"); + } +} + +void FormAbilitySelfStartingB::FMS_Start_0300_03(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_SELF_STARTING_TEST_0300, EVENT_CODE_300); + // Set Want info begin + Want want; + want.SetParam(Constants::PARAM_FORM_DIMENSION_KEY, FORM_DIMENSION_1); + want.SetParam(Constants::PARAM_FORM_NAME_KEY, PARAM_FORM_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + want.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_FALSE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + // Set Want info end + bool bResult = AcquireForm(0, want, callback); + if (bResult) { + APP_LOGI("AcquireForm end"); + } else { + APP_LOGE("AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_SELF_STARTING_TEST_0300, EVENT_CODE_300, "false"); + } +} + +FormAbilitySelfStartingB::~FormAbilitySelfStartingB() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilitySelfStartingB::OnStart(const Want &want) +{ + APP_LOGI("FormAbilitySelfStartingB::onStart"); + Ability::OnStart(want); +} +void FormAbilitySelfStartingB::OnActive() +{ + APP_LOGI("FormAbilitySelfStartingB::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilitySelfStartingB::OnStop() +{ + APP_LOGI("FormAbilitySelfStartingB::OnStop"); + + Ability::OnStop(); +} +void FormAbilitySelfStartingB::OnInactive() +{ + APP_LOGI("FormAbilitySelfStartingB::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilitySelfStartingB::OnBackground() +{ + APP_LOGI("FormAbilitySelfStartingB::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilitySelfStartingB::SubscribeEvent() +{ + APP_LOGI("FormAbilitySelfStartingB::SubscribeEvent"); + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->ability_ = this; + CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +// KitTest End +void FormAbilitySelfStartingB::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilitySelfStartingB::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_SELF_STARTING_TEST_0200] = &FormAbilitySelfStartingB::FMS_Start_0300_02; + memberFuncMap_[FORM_EVENT_REQ_SELF_STARTING_TEST_0300] = &FormAbilitySelfStartingB::FMS_Start_0300_03; + + SubscribeEvent(); +} + +void FormAbilitySelfStartingB::handleEvent(std::string action, std::string data) +{ + APP_LOGI("%{public}s called", __func__); + if (calledFuncMap_.find(action) != calledFuncMap_.end()) { + return; + } + calledFuncMap_.emplace(action, 0); + auto itFunc = memberFuncMap_.find(action); + if (itFunc != memberFuncMap_.end()) { + auto memberFunc = itFunc->second; + if (memberFunc != nullptr) { + return (this->*memberFunc)(data); + } + } +} + +void FormAbilitySelfStartingB::Clear() +{ +} + +void FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriber::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriber::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriber::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilitySelfStartingB) +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/resource/formsystemtestability/tool/include/form_test_utils.h b/test/resource/formsystemtestability/tool/include/form_test_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..73daabb2d082cb47b2dd8e2781d59d0400df270c --- /dev/null +++ b/test/resource/formsystemtestability/tool/include/form_test_utils.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef _FORM_TEST_UTILS_H_ +#define _FORM_TEST_UTILS_H_ +#include "ability_info.h" +#include "ability_lifecycle.h" +#include "application_info.h" +#include "process_info.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +const int OnStateChangedEventWant = LifeCycle::Event::UNDEFINED; +const int OnStateChangedEvent = (int)LifeCycle::Event::UNDEFINED + 1; +const int requestCodeForTerminate = 10; +const int requestCodeForResult = 20; + +class FormTestUtils { +public: + FormTestUtils() = default; + virtual ~FormTestUtils() = default; + static bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + static Want MakeWant(std::string deviceId, std::string abilityName, std::string bundleName, + std::map params); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_TEST_UTILS_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/tool/src/form_test_utils.cpp b/test/resource/formsystemtestability/tool/src/form_test_utils.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4ba7d976ce7513f6a69c5a5c58ee2ad8cda606af --- /dev/null +++ b/test/resource/formsystemtestability/tool/src/form_test_utils.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_test_utils.h" +#include "common_event_data.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace OHOS::EventFwk; +bool FormTestUtils::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} + +Want FormTestUtils::MakeWant( + std::string deviceId, std::string abilityName, std::string bundleName, std::map params) +{ + ElementName element(deviceId, bundleName, abilityName); + Want want; + want.SetElement(element); + for (const auto ¶m : params) { + want.SetParam(param.first, param.second); + } + return want; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/BUILD.gn b/test/systemtest/BUILD.gn index 9865e4bf44664eea59989a2fce7e120083f7fe8a..ad067232979d97ee5bbbc05d2403a9c6645c4824 100755 --- a/test/systemtest/BUILD.gn +++ b/test/systemtest/BUILD.gn @@ -26,6 +26,7 @@ group("systemtest") { "common/ams:systemtest", "common/bms:systemtest_bms", "common/ems:systemtest_ems", + "common/fms:systemtest", "common/task_dispatcher:systemtest_task", ] } diff --git a/test/systemtest/common/fms/BUILD.gn b/test/systemtest/common/fms/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..7640ae6b28f6cfa2be785212a0169ede3ace6105 --- /dev/null +++ b/test/systemtest/common/fms/BUILD.gn @@ -0,0 +1,40 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/ohos.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +config("form_manager_test_config") { + defines = [ + "APP_LOG_TAG = \"FormManagerTest\"", + "LOG_DOMAIN = 0xD00666F", + ] + + configs = [ + "${aafwk_path}/frameworks/kits/ability/native:ability_config", + "${appexecfwk_path}/interfaces/innerkits/appexecfwk_base:appexecfwk_base_sdk_config", + ] +} + +public_configs = [ ":form_manager_test_config" ] + +group("systemtest") { + testonly = true + + deps = [ + "fms_acquire_form_test:systemtest", + "fms_delete_form_test:systemtest", + "fms_release_form_test:systemtest", + "fms_self_starting_test:systemtest", + ] +} diff --git a/test/systemtest/common/fms/common/include/form_event.h b/test/systemtest/common/fms/common/include/form_event.h new file mode 100644 index 0000000000000000000000000000000000000000..56091491156754ec890e8d4c8240a620e8e59b55 --- /dev/null +++ b/test/systemtest/common/fms/common/include/form_event.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_SYSTEM_TEST_FMS_STEVENT_H +#define OHOS_SYSTEM_TEST_FMS_STEVENT_H + +#include +#include +#include +#include +#include +#include +#include "hilog_wrapper.h" +namespace OHOS { +namespace STtools { +class FormEvent { +public: + FormEvent(); + ~FormEvent(); + bool Compare(); + int WaitingMessage(const std::string &message, int timeout_ms, bool locked); + void CompleteMessage(const std::string &message); + void Clean(); + std::string GetData(const std::string &message); + void CompleteMessage(const std::string &message, const std::string &data); + +private: + std::mutex mutex_; + std::condition_variable cv_; + std::string waiting_message_; + std::vector complete_message_; + std::unordered_map message_data_; +}; +} // namespace STtools +} // namespace OHOS +#endif // OHOS_SYSTEM_TEST_FMS_STEVENT_H \ No newline at end of file diff --git a/test/systemtest/common/fms/common/include/form_st_common_info.h b/test/systemtest/common/fms/common/include/form_st_common_info.h new file mode 100644 index 0000000000000000000000000000000000000000..690d6d8ca18ffa9be32ac724d9cc8218b482d571 --- /dev/null +++ b/test/systemtest/common/fms/common/include/form_st_common_info.h @@ -0,0 +1,316 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FORM_ST_COMMON_INFO_H +#define FORM_ST_COMMON_INFO_H + +namespace OHOS { +namespace AppExecFwk { +const std::string PERMISSION_NAME_REQUIRE_FORM = "ohos.permission.REQUIRE_FORM"; +const std::string FORM_TEST_DEVICEID = "0"; + +const std::string FORM_ABILITY_STATE_ONACTIVE = ":OnActive"; +const std::string FORM_EVENT_ABILITY_ONACTIVED = "fms_req_acquireForm_ability_actived"; + +const int FORM_DIMENSION_1 = 1; +const bool FORM_TEMP_FORM_FLAG_FALSE = false; +const bool FORM_TEMP_FORM_FLAG_TRUE = true; + +// provider ability +const std::string FORM_PROVIDER_BUNDLE_NAME1 = "com.form.formsystemtestservicea"; +const std::string PARAM_PROVIDER_MODULE_NAME1 = "formmodule001"; +const std::string FORM_PROVIDER_ABILITY_NAME1 = "com.form.formmodule001.FormAbility001"; +const std::string PARAM_FORM_NAME1 = "Form_Js001"; + +const std::string FORM_PROVIDER_BUNDLE_NAME2 = "com.form.formsystemtestserviceb"; +const std::string PARAM_PROVIDER_MODULE_NAME2 = "formmodule001"; +const std::string FORM_PROVIDER_ABILITY_NAME2 = "com.form.formmodule001.FormAbility001"; +const std::string PARAM_FORM_NAME2 = "Form_Js001"; + + +// add Form +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_TEMP = "fms_req_acquireForm_temp"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_TEMP = "fms_recv_acquireForm_temp"; +const std::string FORM_EVENT_REQ_DELETE_FORM_COMMON = "fms_req_deleteForm_common"; +const std::string FORM_EVENT_RECV_DELETE_FORM_COMMON = "fms_recv_deleteForm_common"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0100 = "fms_req_acquireForm_0100"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0100 = "fms_recv_acquireForm_0100"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0200 = "fms_req_acquireForm_0200"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0200 = "fms_recv_acquireForm_0200"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0300 = "fms_req_acquireForm_0300"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0300 = "fms_recv_acquireForm_0300"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0400 = "fms_req_acquireForm_0400"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0400 = "fms_recv_acquireForm_0400"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0500 = "fms_req_acquireForm_0500"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0500 = "fms_recv_acquireForm_0500"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0600 = "fms_req_acquireForm_0600"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0600 = "fms_recv_acquireForm_0600"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_0700 = "fms_req_acquireForm_0700"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_0700 = "fms_recv_acquireForm_0700"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1000 = "fms_req_acquireForm_1000"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1000 = "fms_recv_acquireForm_1000"; + +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1100 = "fms_req_acquireForm_1100"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1100 = "fms_recv_acquireForm_1100"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1200 = "fms_req_acquireForm_1200"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1200 = "fms_recv_acquireForm_1200"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1400 = "fms_req_acquireForm_1400"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1400 = "fms_recv_acquireForm_1400"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1400_1 = "fms_req_acquireForm_1400_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1400_1 = "fms_recv_acquireForm_1400_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1500 = "fms_req_acquireForm_1500"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1500 = "fms_recv_acquireForm_1500"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1500_1 = "fms_req_acquireForm_1500_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1500_1 = "fms_recv_acquireForm_1500_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1600 = "fms_req_acquireForm_1600"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1600 = "fms_recv_acquireForm_1600"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1600_1 = "fms_req_acquireForm_1600_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1600_1 = "fms_recv_acquireForm_1600_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1800 = "fms_req_acquireForm_1800"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1800 = "fms_recv_acquireForm_1800"; + + +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1800_1 = "fms_req_acquireForm_1800_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1800_1 = "fms_recv_acquireForm_1800_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1800_2 = "fms_req_acquireForm_1800_2"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1800_2 = "fms_recv_acquireForm_1800_2"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1800_3 = "fms_req_acquireForm_1800_3"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1800_3 = "fms_recv_acquireForm_1800_3"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_1900 = "fms_req_acquireForm_1900"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_1900 = "fms_recv_acquireForm_1900"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2100 = "fms_req_acquireForm_2100"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2100 = "fms_recv_acquireForm_2100"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2100_1 = "fms_req_acquireForm_2100_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2100_1 = "fms_recv_acquireForm_2100_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2200 = "fms_req_acquireForm_2200"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2200 = "fms_recv_acquireForm_2200"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2300 = "fms_req_acquireForm_2300"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2300 = "fms_recv_acquireForm_2300"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2400 = "fms_req_acquireForm_2400"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2400 = "fms_recv_acquireForm_2400"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2400_1 = "fms_req_acquireForm_2400_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2400_1 = "fms_recv_acquireForm_2400_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2500 = "fms_req_acquireForm_2500"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2500 = "fms_recv_acquireForm_2500"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2600 = "fms_req_acquireForm_2600"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2600 = "fms_recv_acquireForm_2600"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2600_1 = "fms_req_acquireForm_2600_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2600_1 = "fms_recv_acquireForm_2600_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2700 = "fms_req_acquireForm_2700"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2700 = "fms_recv_acquireForm_2700"; + +// Delete Form +const std::string FORM_EVENT_REQ_DELETE_FORM_0100 = "fms_req_deleteForm_0100"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0100 = "fms_recv_deleteForm_0100"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0200 = "fms_req_deleteForm_0200"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0200 = "fms_recv_deleteForm_0200"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0300 = "fms_req_deleteForm_0300"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0300 = "fms_recv_deleteForm_0300"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0400 = "fms_req_deleteForm_0400"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0400 = "fms_recv_deleteForm_0400"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0500 = "fms_req_deleteForm_0500"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0500 = "fms_recv_deleteForm_0500"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0600 = "fms_req_deleteForm_0600"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0600 = "fms_recv_deleteForm_0600"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0700 = "fms_req_deleteForm_0700"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0700 = "fms_recv_deleteForm_0700"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0800 = "fms_req_deleteForm_0800"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0800 = "fms_recv_deleteForm_0800"; +const std::string FORM_EVENT_REQ_DELETE_FORM_0900 = "fms_req_deleteForm_0900"; +const std::string FORM_EVENT_RECV_DELETE_FORM_0900 = "fms_recv_deleteForm_0900"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1000 = "fms_req_deleteForm_1000"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1000 = "fms_recv_deleteForm_1000"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1100 = "fms_req_deleteForm_1100"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1100 = "fms_recv_deleteForm_1100"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1200 = "fms_req_deleteForm_1200"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1200 = "fms_recv_deleteForm_1200"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1400 = "fms_req_deleteForm_1400"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1400 = "fms_recv_deleteForm_1400"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1500 = "fms_req_deleteForm_1500"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1500 = "fms_recv_deleteForm_1500"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1600 = "fms_req_deleteForm_1600"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1600 = "fms_recv_deleteForm_1600"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1700 = "fms_req_deleteForm_1700"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1700 = "fms_recv_deleteForm_1700"; + +// Release Form +const std::string FORM_EVENT_REQ_RELEASE_FORM_0100 = "fms_req_releaseForm_0100"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0100 = "fms_recv_releaseForm_0100"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0200 = "fms_req_releaseForm_0200"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0200 = "fms_recv_releaseForm_0200"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0300 = "fms_req_releaseForm_0300"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0300 = "fms_recv_releaseForm_0300"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0400 = "fms_req_releaseForm_0400"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0400 = "fms_recv_releaseForm_0400"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0500 = "fms_req_releaseForm_0500"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0500 = "fms_recv_releaseForm_0500"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0600 = "fms_req_releaseForm_0600"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0600 = "fms_recv_releaseForm_0600"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0700 = "fms_req_releaseForm_0700"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0700 = "fms_recv_releaseForm_0700"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0800 = "fms_req_releaseForm_0800"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0800 = "fms_recv_releaseForm_0800"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_0900 = "fms_req_releaseForm_0900"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_0900 = "fms_recv_releaseForm_0900"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_1000 = "fms_req_releaseForm_1000"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_1000 = "fms_recv_releaseForm_1000"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_1100 = "fms_req_releaseForm_1100"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_1100 = "fms_recv_releaseForm_1100"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_1200 = "fms_req_releaseForm_1200"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_1200 = "fms_recv_releaseForm_1200"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_1300 = "fms_req_releaseForm_1300"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_1300 = "fms_recv_releaseForm_1300"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_1400 = "fms_req_releaseForm_1400"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_1400 = "fms_recv_releaseForm_1400"; + +// Stress Test +const std::string FORM_EVENT_REQ_STRESS_TEST_0100 = "fms_req_stressTest_0100"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0100 = "fms_recv_stressTest_0100"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0100_01 = "fms_req_stressTest_0100_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0100_01 = "fms_recv_stressTest_0100_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0200 = "fms_req_stressTest_0200"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0200 = "fms_recv_stressTest_0200"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0200_01 = "fms_req_stressTest_0200_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0200_01 = "fms_recv_stressTest_0200_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0200_02 = "fms_req_stressTest_0200_02"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0200_02 = "fms_recv_stressTest_0200_02"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0200_03 = "fms_req_stressTest_0200_03"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0200_03 = "fms_recv_stressTest_0200_03"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0300 = "fms_req_stressTest_0300"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0300 = "fms_recv_stressTest_0300"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0300_01 = "fms_req_stressTest_0300_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0300_01 = "fms_recv_stressTest_0300_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0300_02 = "fms_req_stressTest_0300_02"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0300_02 = "fms_recv_stressTest_0300_02"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0400 = "fms_req_stressTest_0400"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0400 = "fms_recv_stressTest_0400"; +const std::string FORM_EVENT_REQ_STRESS_TEST_0500 = "fms_req_stressTest_0500"; +const std::string FORM_EVENT_RECV_STRESS_TEST_0500 = "fms_recv_stressTest_0500"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1100 = "fms_req_stressTest_1100"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1100 = "fms_recv_stressTest_1100"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1100_01 = "fms_req_stressTest_1100_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1100_01 = "fms_recv_stressTest_1100_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1100_02 = "fms_req_stressTest_1100_02"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1100_02 = "fms_recv_stressTest_1100_02"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1100_03 = "fms_req_stressTest_1100_03"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1100_03 = "fms_recv_stressTest_1100_03"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1300 = "fms_req_stressTest_1300"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1300 = "fms_recv_stressTest_1300"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1300_01 = "fms_req_stressTest_1300_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1300_01 = "fms_recv_stressTest_1300_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1300_02 = "fms_req_stressTest_1300_02"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1300_02 = "fms_recv_stressTest_1300_02"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1300_03 = "fms_req_stressTest_1300_03"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1300_03 = "fms_recv_stressTest_1300_03"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1700 = "fms_req_stressTest_1700"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1700 = "fms_recv_stressTest_1700"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1700_01 = "fms_req_stressTest_1700_01"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1700_01 = "fms_recv_stressTest_1700_01"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1700_02 = "fms_req_stressTest_1700_02"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1700_02 = "fms_recv_stressTest_1700_02"; +const std::string FORM_EVENT_REQ_STRESS_TEST_1800 = "fms_req_stressTest_1800"; +const std::string FORM_EVENT_RECV_STRESS_TEST_1800 = "fms_recv_stressTest_1800"; + +// CommonA(acquire one normal form) +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM = "fms_req_one_normal_form"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM = "fms_recv_one_normal_form"; + +// Performance Test +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0100 = "fms_req_performanceTest_0100"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0100 = "fms_recv_performanceTest_0100"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0200 = "fms_req_performanceTest_0200"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0200 = "fms_recv_performanceTest_0200"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0300 = "fms_req_performanceTest_0300"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0300 = "fms_recv_performanceTest_0300"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0400 = "fms_req_performanceTest_0400"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0400 = "fms_recv_performanceTest_0400"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0500 = "fms_req_performanceTest_0500"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0500 = "fms_recv_performanceTest_0500"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0600 = "fms_req_performanceTest_0600"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0600 = "fms_recv_performanceTest_0600"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_0700 = "fms_req_performanceTest_0700"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_0700 = "fms_recv_performanceTest_0700"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_1300 = "fms_req_performanceTest_1300"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_1300 = "fms_recv_performanceTest_1300"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_1400 = "fms_req_performanceTest_1400"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_1400 = "fms_recv_performanceTest_1400"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_1500 = "fms_req_performanceTest_1500"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_1500 = "fms_recv_performanceTest_1500"; +const std::string FORM_EVENT_REQ_PERFORMANCE_TEST_1600 = "fms_req_performanceTest_1600"; +const std::string FORM_EVENT_RECV_PERFORMANCE_TEST_1600 = "fms_recv_performanceTest_1600"; + +// Self-Starting Test +const std::string FORM_EVENT_REQ_SELF_STARTING_TEST_0100 = "fms_req_selfStartingTest_0100"; +const std::string FORM_EVENT_RECV_SELF_STARTING_TEST_0100 = "fms_recv_selfStartingTest_0100"; +const std::string FORM_EVENT_REQ_SELF_STARTING_TEST_0200 = "fms_req_selfStartingTest_0200"; +const std::string FORM_EVENT_RECV_SELF_STARTING_TEST_0200 = "fms_recv_selfStartingTest_0200"; +const std::string FORM_EVENT_REQ_SELF_STARTING_TEST_0300 = "fms_req_selfStartingTest_0300"; +const std::string FORM_EVENT_RECV_SELF_STARTING_TEST_0300 = "fms_recv_selfStartingTest_0300"; + +// common event data code +const int EVENT_CODE_100 = 100; +const int EVENT_CODE_110 = 110; +const int EVENT_CODE_200 = 200; +const int EVENT_CODE_300 = 300; +const int EVENT_CODE_400 = 400; +const int EVENT_CODE_500 = 500; +const int EVENT_CODE_600 = 600; +const int EVENT_CODE_700 = 700; +const int EVENT_CODE_800 = 800; +const int EVENT_CODE_900 = 900; +const int EVENT_CODE_999 = 999; +const int EVENT_CODE_1000 = 1000; +const int EVENT_CODE_1100 = 1100; +const int EVENT_CODE_1101 = 1101; +const int EVENT_CODE_1200 = 1200; +const int EVENT_CODE_1201 = 1201; +const int EVENT_CODE_1234 = 1234; +const int EVENT_CODE_1300 = 1300; +const int EVENT_CODE_1400 = 1400; +const int EVENT_CODE_1500 = 1500; +const int EVENT_CODE_1510 = 1510; +const int EVENT_CODE_1511 = 1511; +const int EVENT_CODE_1600 = 1600; +const int EVENT_CODE_1601 = 1601; +const int EVENT_CODE_1610 = 1610; +const int EVENT_CODE_1611 = 1611; +const int EVENT_CODE_1700 = 1700; +const int EVENT_CODE_1800 = 1800; +const int EVENT_CODE_1801 = 1801; +const int EVENT_CODE_1810 = 1810; +const int EVENT_CODE_1811 = 1811; +const int EVENT_CODE_1820 = 1820; +const int EVENT_CODE_1821 = 1821; +const int EVENT_CODE_1830 = 1830; +const int EVENT_CODE_1831 = 1831; +const int EVENT_CODE_1900 = 1900; +const int EVENT_CODE_1901 = 1901; +const int EVENT_CODE_2000 = 2000; +const int EVENT_CODE_2100 = 2100; +const int EVENT_CODE_2200 = 2200; +const int EVENT_CODE_2300 = 2300; +const int EVENT_CODE_2400 = 2400; +const int EVENT_CODE_2401 = 2401; +const int EVENT_CODE_2410 = 2410; +const int EVENT_CODE_2500 = 2500; +const int EVENT_CODE_2600 = 2600; +const int EVENT_CODE_2610 = 2610; +const int EVENT_CODE_2611 = 2611; +const int EVENT_CODE_2700 = 2700; +const int EVENT_CODE_TEMP = 9900; +const int EVENT_CODE_TEMP_1 = 9901; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FORM_ST_COMMON_INFO_H \ No newline at end of file diff --git a/test/systemtest/common/fms/common/include/install_tool_status_receiver.h b/test/systemtest/common/fms/common/include/install_tool_status_receiver.h new file mode 100644 index 0000000000000000000000000000000000000000..549613b3d6ece3e7ed8bed23b822c016cc990b8c --- /dev/null +++ b/test/systemtest/common/fms/common/include/install_tool_status_receiver.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INSTALL_TOOL_STATUS_RECEIVER_H +#define INSTALL_TOOL_STATUS_RECEIVER_H + +#include "form_event.h" + +namespace OHOS { +namespace STtools { +using namespace OHOS::AppExecFwk; +class InstallToolStatusReceiver : public StatusReceiverHost { +public: + InstallToolStatusReceiver(); + virtual ~InstallToolStatusReceiver() override; + virtual void OnStatusNotify(const int progress) override; + virtual void OnFinished(const int32_t resultCode, const std::string &resultMsg) override; + static int TestWaitCompleted(FormEvent &event, const std::string eventName, const int code, const int timeout = 10); + static void TestCompleted(FormEvent &event, const std::string &eventName, const int code); + FormEvent event_ = STtools::FormEvent(); + +private: + int iProgress_ = 0; + DISALLOW_COPY_AND_MOVE(InstallToolStatusReceiver); +}; +InstallToolStatusReceiver::InstallToolStatusReceiver() +{ + std::cout << "create status receiver instance" << std::endl; +} + +InstallToolStatusReceiver::~InstallToolStatusReceiver() +{ + std::cout << "destroy status receiver instance" << std::endl; +} + +void InstallToolStatusReceiver::OnStatusNotify(const int progress) +{ + iProgress_ = progress; + std::cout << "destroy status receiver instance" << progress << std::endl; +} + +void InstallToolStatusReceiver::OnFinished(const int32_t resultCode, const std::string &resultMsg) +{ + std::cout << "on finished result is " << resultCode << " " << resultMsg << std::endl; + TestCompleted(event_, resultMsg, resultCode); +} + +int InstallToolStatusReceiver::TestWaitCompleted( + FormEvent &event, const std::string eventName, const int code, const int timeout) +{ + std::cout << "TestWaitCompleted " << eventName << std::endl; + return SystemTestFormUtil::WaitCompleted(event, eventName, code, timeout); +} +void InstallToolStatusReceiver::TestCompleted(FormEvent &event, const std::string &eventName, const int code) +{ + std::cout << "TestCompleted " << eventName << std::endl; + SystemTestFormUtil::Completed(event, eventName, code); + return; +} +} // namespace AppExecFwk +} // namespace OHOS +#endif // INSTALL_TOOL_STATUS_RECEIVER_H \ No newline at end of file diff --git a/test/systemtest/common/fms/common/include/system_test_form_util.h b/test/systemtest/common/fms/common/include/system_test_form_util.h new file mode 100644 index 0000000000000000000000000000000000000000..42486ce03c1ab68889e7426a38d76cdb61f5519d --- /dev/null +++ b/test/systemtest/common/fms/common/include/system_test_form_util.h @@ -0,0 +1,332 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSTEM_TEST_FORM_UTIL_H +#define SYSTEM_TEST_FORM_UTIL_H + +#include +#include +#include +#include + +#include "ability_manager_service.h" +#include "ability_manager_errors.h" +#include "app_mgr_service.h" +#include "bundle_installer_interface.h" +#include "bundle_mgr_interface.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_event.h" +#include "form_mgr_interface.h" +#include "hilog_wrapper.h" +#include "iremote_proxy.h" +#include "sa_mgr_client.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace STtools { +namespace { +using vector_str = std::vector; +using MAP_STR_STR = std::map; +} // namespace +class SystemTestFormUtil { +public: + SystemTestFormUtil() = default; + ~SystemTestFormUtil() = default; + + static std::shared_ptr GetInstance(); + static void DestroyInstance(); + + /** + * + * @param {string} eventName : Sent FormEvent Name + * @param {int} code : Sent Code + * @param {string} data : Sent Data + * @Introduction: Sent FormEvent + */ + static bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + + /** + * + * @param {vector} hapNames : container containing multiple hap names + * @Introduction: use bm install multiple hap + */ + static void InstallHaps(vector_str &hapNames); + + /** + * + * @param {vector} bundleNames : container containing multiple bundle names + * @Introduction: use bm install multiple bundle + */ + static void UninstallBundle(vector_str &bundleNames); + + /** + * + * @param {string} serviceName : process name + * @Introduction: kill process + */ + static void KillService(const std::string &serviceName); + + /** + * + * @param {string} serviceName : executable file name + * @param {time_t} delay : Waiting time for executable to start(milliseconds) + * @Introduction: start executable file + */ + static void StartService(const std::string &serviceName, const time_t &delay = 0); + + /** + * + * @param {vector} bundleNames : Container Containing Multiple Bundle Names + * @Introduction: start executable file + */ + static void KillBundleProcess(vector_str &bundleNames); + + /** + * + * @Introduction: Get Ability manager Service. + */ + static sptr GetAbilityManagerService(); + + /** + * + * @Introduction: Get App manager Service. + */ + static sptr GetAppMgrService(); + + /** + * + * @param {Want} want : The want of the ability to start. + * @param {sptr} abilityMs : Ability Manager Service ptr + * @param {time_t} delay : Waiting time for ability to start (milliseconds) + * @Introduction: start ability + */ + static ErrCode StartAbility( + const AAFwk::Want &want, sptr &abilityMs, const time_t &delay = 0); + + /** + * + * @param {string} eventName : Sent FormEvent Name + * @param {int} code : Sent Code + * @param {string} data : Sent Data + * @Introduction: Sent FormEvent to terminate app + */ + static bool StopAbility(const std::string &eventName, const int &code, const std::string &data); + /** + * + * @param {string} deviceId : Device ID + * @param {string} abilityName : Ability Name + * @param {string} bundleName : Bundle Name + * @param {MAP_STR_STR} params : Params (SetParam) + * @Introduction: Great Want + */ + static AAFwk::Want MakeWant( + std::string deviceId, std::string abilityName, std::string bundleName, MAP_STR_STR params = {}); + + /** + * + * @param {string} deviceId : Device ID + * @param {string} abilityName : Ability Name + * @param {string} bundleName : Bundle Name + * @param {vector_str} params : Params (SetParam) + * @Introduction: Great Want + */ + static AAFwk::Want MakeWant( + std::string deviceId, std::string abilityName, std::string bundleName, vector_str params = {}); + + /** + * + * @param {int64_t} id : Ability Record ID + * @param {sptr} abilityMs : Ability Manager Service ptr + * @Introduction: Get Top AbilityRecord ID + */ + static ErrCode GetTopAbilityRecordId(int64_t &id, sptr &abilityMs); + + /** + * + * @param {shared_ptr} runningProcessInfo : Process Info + * @param {sptr} appMs : App Manager ptr + * @param {time_t} delay : Waiting time for ability to Get Process Info (milliseconds) + * @Introduction: Get Top AbilityRecord ID + */ + static ErrCode GetRunningProcessInfo(std::vector &runningProcessInfo, + sptr &appMs, const time_t &delay = 0); + + /** + * + * @param {string} appName : app Name + * @param {sptr} appMs : App Manager ptr + * @param {time_t} delay : Waiting time for ability to KillApplication (milliseconds) + * @Introduction: Get Top AbilityRecord ID + */ + static ErrCode KillApplication( + const std::string &appName, sptr &appMs, const time_t &delay = 0); + + /** + * + * @param {string} processName : processName + * @param {sptr} appMs : App Manager ptr + * @param {time_t} delay : Waiting time for ability to GetAppProcessInfo (milliseconds) + * @Introduction: Get Top AbilityRecord ID + */ + static AppExecFwk::RunningProcessInfo GetAppProcessInfoByName( + const std::string &processName, sptr &appMs, const time_t &delay = 0); + + /** + * + * @param {FormEvent} event : FormEvent Class Object + * @param {string} eventName : The name of the event to wait for. + * @param {int} code : The code of the event to wait for. + * @param {int} timeout : Time of wait (seconds) + * @Introduction: Judge whether the event is received in the event queue, if not, wait + */ + static int WaitCompleted( + STtools::FormEvent &event, const std::string &eventName, const int code, const int timeout = 15); + + /** + * + * @param {FormEvent} event : FormEvent Class Object + * @param {string} eventName : The name of the event to wait for. + * @param {int} code : The code of the event to wait for. + * @Introduction: Compare the received events, if not, join the event queue. + */ + static void Completed(STtools::FormEvent &event, const std::string &eventName, const int code); + + /** + * + * @param {FormEvent} event : FormEvent Class Object + * @param {string} eventName : The name of the event to wait for. + * @param {int} code : The code of the event to wait for. + * @param {string} data : The data of the event to wait for. + * @Introduction: Compare the received events, if not, join the event queue. + */ + static void Completed(STtools::FormEvent &event, const std::string &eventName, const int code, + const std::string &data); + + /** + * + * @param {FormEvent} event : FormEvent Class Object + * @Introduction: Clean wait event. + */ + static void CleanMsg(STtools::FormEvent &event); + + /** + * + * @param {FormEvent} event : FormEvent Class Object + * @param {string} eventName : The name of the event to wait for. + * @param {int} code : The code of the event to wait for. + * @Introduction: get the event data. + */ + static std::string GetData(STtools::FormEvent &event, const std::string &eventName, const int code); + + /** + * + * @param {Want} want : The want of the ability to start. + * @param {sptr} connect : Callback + * @param {time_t} delay : Waiting time for ability to start (milliseconds) + * @Introduction: connect ability + */ + static ErrCode ConnectAbility(const AAFwk::Want &want, const sptr &connect, + const sptr &callerToken, unsigned int usec = 0); + + /** + * + * @param {Want} want : The want of the ability to start. + * @param {sptr} connect : Callback + * @param {time_t} delay : Waiting time for ability to start (milliseconds) + * @Introduction: disconnect ability + */ + static ErrCode DisconnectAbility(const sptr &connect, unsigned int usec = 0); + + /** + * + * @param {Want} want : The want of the ability to start. + * @param {time_t} delay : Waiting time for ability to start (milliseconds) + * @Introduction: stop service ability + */ + static ErrCode StopServiceAbility(const AAFwk::Want &want, unsigned int usec = 0); + + /** + * Remove the specified mission stack by stack id + * + * @param id. + * @param {sptr} abilityMs : Ability Manager Service ptr + * @param {time_t} delay : Waiting time for ability to GetAppProcessInfo (milliseconds) + * @return Returns ERR_OK on success, others on failure. + */ + static int RemoveStack(int id, sptr &abilityMs, const time_t &backHmoeDelay = 0, + const time_t &removeDelay = 0); + + /** + * + * @param {string} bundleFilePath : Hap File Name + * @param {AppExecFwk::InstallFlag} installFlag : install flag + * @Introduction: use bms install + */ + static void Install( + const std::string &bundleFilePath, const AppExecFwk::InstallFlag installFlag = AppExecFwk::InstallFlag::NORMAL); + + /** + * + * @param {string} bundleName : bundleName + * @Introduction: use bm uninstall bundleName + */ + static void Uninstall(const std::string &bundleName); + + /** + * @brief Query all of form storage infos. + * @return Returns all of form storage infos. + */ + static std::string QueryStorageFormInfos(); + /** + * @brief Query form infos by bundleName. + * @param bundleName BundleName. + * @return Returns form infos. + */ + static std::string QueryFormInfoByBundleName(const std::string& bundleName); + /** + * @brief Query form infos by form id. + * @param formId The id of the form. + * @return form infos. + */ + static std::string QueryFormInfoByFormId(const std::int64_t formId); +private: + /** + * + * @Introduction: get bundleManger object + */ + static sptr GetBundleMgrProxy(); + + /** + * + * @Introduction: get bundleInstaller object + */ + static sptr GetInstallerProxy(); + + /** + * @brief Get form manager service. + * @return Returns form manager servic remoteObject. + */ + static sptr GetFmsService(); + + static bool WriteInterfaceToken(MessageParcel &data); + static int GetStringInfo(AppExecFwk::IFormMgr::Message code, MessageParcel &data, std::string &stringInfo); + static int SendTransactCmd(AppExecFwk::IFormMgr::Message code, MessageParcel &data, MessageParcel &reply); + + static std::shared_ptr instance_; +}; +} // namespace STtools +} // namespace OHOS +#endif // SYSTEM_TEST_FORM_UTIL_H diff --git a/test/systemtest/common/fms/common/src/form_event.cpp b/test/systemtest/common/fms/common/src/form_event.cpp new file mode 100644 index 0000000000000000000000000000000000000000..082058567e050079e709fb7567c17129ad6fb667 --- /dev/null +++ b/test/systemtest/common/fms/common/src/form_event.cpp @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "form_event.h" + +namespace OHOS { +namespace STtools { +FormEvent::FormEvent() +{ + waiting_message_ = ""; + complete_message_.clear(); +} + +FormEvent::~FormEvent() +{ + waiting_message_ = ""; + std::vector tmp_vector; + tmp_vector.swap(complete_message_); + complete_message_.clear(); +} + +bool FormEvent::Compare() +{ + if (!waiting_message_.empty()) { + for (size_t i = 0; i < complete_message_.size(); i++) { + if (waiting_message_.compare(complete_message_.at(i)) == 0) { + complete_message_.erase(std::begin(complete_message_) + i, std::begin(complete_message_) + i + 1); + waiting_message_ = ""; + return true; + } + } + } + return false; +} + +int FormEvent::WaitingMessage(const std::string &message, int timeout_ms, bool locked) +{ + std::unique_lock lock(mutex_); + HILOG_INFO(" WaitingMessage: [%{public}s]", message.c_str()); + waiting_message_ = message; + if (Compare()) { + HILOG_INFO(" WaitingMessage: unlock [%{public}s]", message.c_str()); + return 0; + } + + if (locked) { + HILOG_INFO(" WaitingMessage: locked [%{public}s]", message.c_str()); + cv_.wait(lock); + return 0; + } + + if (cv_.wait_for(lock, std::chrono::seconds(timeout_ms)) == std::cv_status::timeout) { + HILOG_INFO("[%{public}s] waiting timeout", waiting_message_.c_str()); + waiting_message_ = ""; + return -1; + } + return 0; +} + +void FormEvent::CompleteMessage(const std::string &message) +{ + std::unique_lock lock(mutex_); + HILOG_INFO("CompleteMessage [%{public}s]", message.c_str()); + if (waiting_message_.compare(message) == 0) { + HILOG_INFO("Completed unlocked: [%{public}s]", message.c_str()); + waiting_message_ = ""; + cv_.notify_all(); + return; + } + HILOG_INFO("completed message: [%{public}s] does not equal waiting message", message.c_str()); + + complete_message_.push_back(message); + return; +} + +void FormEvent::CompleteMessage(const std::string &message, const std::string &data) +{ + std::unique_lock lock(mutex_); + HILOG_INFO("CompleteMessage [%{public}s]", message.c_str()); + message_data_[message] = data; + if (waiting_message_.compare(message) == 0) { + HILOG_INFO("Completed unlocked: [%{public}s]", message.c_str()); + waiting_message_ = ""; + cv_.notify_all(); + return; + } + HILOG_INFO("completed message: [%{public}s] does not equal waiting message", message.c_str()); + + complete_message_.push_back(message); + return; +} + +std::string FormEvent::GetData(const std::string &message) +{ + std::string data; + std::unique_lock lock(mutex_); + if (message_data_.find(message) != message_data_.end()) { + data = message_data_.at(message); + message_data_.erase(message); + } + return data; +} + +void FormEvent::Clean() +{ + HILOG_INFO("FormEvent::Clean()"); + std::unique_lock lock(mutex_); + waiting_message_ = ""; + complete_message_.clear(); + message_data_.clear(); +} +} // namespace STtools +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/common/src/system_test_form_util.cpp b/test/systemtest/common/fms/common/src/system_test_form_util.cpp new file mode 100644 index 0000000000000000000000000000000000000000..baad03bcd385e5ce851ca4b5ac14ab8c3eb11675 --- /dev/null +++ b/test/systemtest/common/fms/common/src/system_test_form_util.cpp @@ -0,0 +1,588 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "system_test_form_util.h" +#include "iservice_registry.h" +#include "status_receiver_host.h" +#include "install_tool_status_receiver.h" + +namespace OHOS { +namespace STtools { +using namespace OHOS; +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::EventFwk; + +std::shared_ptr SystemTestFormUtil::instance_ = nullptr; + +bool SystemTestFormUtil::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} + +void SystemTestFormUtil::InstallHaps(vector_str &hapNames) +{ + for (auto hapName : hapNames) { + Install(hapName); + } +} + +void SystemTestFormUtil::UninstallBundle(vector_str &bundleNames) +{ + for (auto bundleName : bundleNames) { + Uninstall(bundleName); + } +} + +void SystemTestFormUtil::KillService(const std::string &serviceName) +{ + system(("kill -9 $(pidof " + serviceName + ") > /dev/null 2>&1").c_str()); +} + +void SystemTestFormUtil::StartService(const std::string &serviceName, const time_t &delay) +{ + system(("/system/bin/" + serviceName + "& > /dev/null 2>&1").c_str()); + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); +} + +void SystemTestFormUtil::KillBundleProcess(vector_str &bundleNames) +{ + for (std::string bundleName : bundleNames) { + KillService(bundleName); + } +} + +sptr SystemTestFormUtil::GetAbilityManagerService() +{ + sptr abilityMsObj = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (abilityMsObj == nullptr) { + HILOG_ERROR("failed to get ability manager service"); + return nullptr; + } + return iface_cast(abilityMsObj); +} + +sptr SystemTestFormUtil::GetAppMgrService() +{ + sptr appMsObj = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(APP_MGR_SERVICE_ID); + if (appMsObj == nullptr) { + HILOG_ERROR("failed to get app manager service"); + return nullptr; + } + return iface_cast(appMsObj); +} + +ErrCode SystemTestFormUtil::StartAbility(const Want &want, sptr &abilityMs, const time_t &delay) +{ + ErrCode result = OHOS::ERR_OK; + abilityMs = GetAbilityManagerService(); + if (abilityMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get ability manager service"); + return result; + } + + result = abilityMs->StartAbility(want); + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); + if (result == OHOS::ERR_OK) { + HILOG_INFO("start ability successfully."); + } else { + HILOG_INFO("failed to start ability."); + } + + return result; +} + +bool SystemTestFormUtil::StopAbility(const std::string &eventName, const int &code, const std::string &data) +{ + return PublishEvent(eventName, code, data); +} + +ErrCode SystemTestFormUtil::StopServiceAbility(const Want &want, unsigned int usec) +{ + ErrCode result = OHOS::ERR_OK; + + sptr abilityMs = GetAbilityManagerService(); + if (abilityMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get ability manager service"); + return result; + } + + result = abilityMs->StopServiceAbility(want); + if (result == OHOS::ERR_OK) { + HILOG_INFO("stop service ability successfully."); + } else { + HILOG_INFO("failed to stop service ability."); + } + + return result; +} + +ErrCode SystemTestFormUtil::ConnectAbility(const Want &want, const sptr &connect, + const sptr &callerToken, unsigned int usec) +{ + ErrCode result = OHOS::ERR_OK; + + sptr abilityMs = GetAbilityManagerService(); + if (abilityMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get ability manager service"); + return result; + } + + result = abilityMs->ConnectAbility(want, connect, callerToken); + if (result == OHOS::ERR_OK) { + HILOG_INFO("connect ability successfully."); + } else { + HILOG_INFO("failed to connect ability."); + } + + return result; +} + +ErrCode SystemTestFormUtil::DisconnectAbility(const sptr &connect, unsigned int usec) +{ + ErrCode result = OHOS::ERR_OK; + + sptr abilityMs = GetAbilityManagerService(); + if (abilityMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get ability manager service"); + return result; + } + + result = abilityMs->DisconnectAbility(connect); + if (result == OHOS::ERR_OK) { + HILOG_INFO("StopServiceAbility successfully."); + } else { + HILOG_INFO("failed to StopServiceAbility."); + } + + return result; +} + +Want SystemTestFormUtil::MakeWant(std::string deviceId, std::string abilityName, std::string bundleName, + MAP_STR_STR params) +{ + ElementName element(deviceId, bundleName, abilityName); + Want want; + want.SetElement(element); + for (const auto ¶m : params) { + want.SetParam(param.first, param.second); + } + return want; +} + +Want SystemTestFormUtil::MakeWant(std::string deviceId, std::string abilityName, std::string bundleName, + vector_str params) +{ + ElementName element(deviceId, bundleName, abilityName); + Want want; + want.SetElement(element); + want.SetParam("operator", params); + return want; +} + +ErrCode SystemTestFormUtil::GetTopAbilityRecordId(int64_t &id, sptr &abilityMs) +{ + ErrCode result = OHOS::ERR_OK; + id = -1; + abilityMs = GetAbilityManagerService(); + if (abilityMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get ability manager service"); + return result; + } + StackInfo stackInfo; + abilityMs->GetAllStackInfo(stackInfo); + MissionStackInfo defaultMissionStack; + for (const auto &stackInfo : stackInfo.missionStackInfos) { + if (stackInfo.id == 1) { // DEFAULT_MISSION_STACK_ID = 1 + defaultMissionStack = stackInfo; + break; + } + } + if (!defaultMissionStack.missionRecords.empty() && + !defaultMissionStack.missionRecords.begin()->abilityRecordInfos.empty()) { + id = defaultMissionStack.missionRecords.begin()->abilityRecordInfos.begin()->id; + } + return result; +} + +ErrCode SystemTestFormUtil::GetRunningProcessInfo( + std::vector &runningProcessInfo, sptr &appMs, const time_t &delay) +{ + ErrCode result = ERR_OK; + appMs = GetAppMgrService(); + if (appMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get app manager service"); + return result; + } + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); + result = appMs->GetAllRunningProcesses(runningProcessInfo); + if (result == ERR_OK) { + HILOG_INFO("get running process info successfully."); + } else { + HILOG_INFO("failed to get running process info."); + } + return result; +} + +ErrCode SystemTestFormUtil::KillApplication(const std::string &appName, sptr &appMs, const time_t &delay) +{ + ErrCode result = ERR_OK; + appMs = GetAppMgrService(); + if (appMs == nullptr) { + result = OHOS::ERR_INVALID_VALUE; + HILOG_ERROR("failed to get app manager service"); + return result; + } + result = appMs->GetAmsMgr()->KillApplication(appName); + std::this_thread::sleep_for(std::chrono::milliseconds(delay)); + if (result == ERR_OK) { + HILOG_INFO("kill application:%{public}s successfully.", appName.c_str()); + } else { + HILOG_INFO("failed to kill application:%{public}s.", appName.c_str()); + } + return result; +} + +RunningProcessInfo SystemTestFormUtil::GetAppProcessInfoByName( + const std::string &processName, sptr &appMs, const time_t &delay) +{ + RunningProcessInfo appProcessInfo; + appProcessInfo.pid_ = 0; + std::vector runningProcessInfo; + if (ERR_OK == GetRunningProcessInfo(runningProcessInfo, appMs, delay)) { + for (const auto &info : runningProcessInfo) { + if (processName == info.processName_) { + appProcessInfo = info; + } + } + } + return appProcessInfo; +} + +int SystemTestFormUtil::WaitCompleted(FormEvent &event, const std::string &eventName, const int code, const int timeout) +{ + HILOG_INFO("WaitCompleted"); + return event.WaitingMessage(std::to_string(code) + eventName, timeout, false); +} + +void SystemTestFormUtil::Completed(FormEvent &event, const std::string &eventName, const int code) +{ + HILOG_INFO("Completed"); + return event.CompleteMessage(std::to_string(code) + eventName); +} + +void SystemTestFormUtil::Completed(FormEvent &event, const std::string &eventName, const int code, + const std::string &data) +{ + HILOG_INFO("SystemTestFormUtil::Completed"); + return event.CompleteMessage(std::to_string(code) + eventName, data); +} + +std::string SystemTestFormUtil::GetData(FormEvent &event, const std::string &eventName, const int code) +{ + HILOG_INFO("SystemTestFormUtil::GetData"); + return event.GetData(std::to_string(code) + eventName); +} + +void SystemTestFormUtil::CleanMsg(FormEvent &event) +{ + HILOG_INFO("CleanMsg"); + return event.Clean(); +} + +int SystemTestFormUtil::RemoveStack( + int id, sptr &abilityMs, const time_t &backHmoeDelay, const time_t &removeDelay) +{ + Want wantEntity; + wantEntity.AddEntity(Want::FLAG_HOME_INTENT_FROM_SYSTEM); + StartAbility(wantEntity, abilityMs); + std::this_thread::sleep_for(std::chrono::milliseconds(backHmoeDelay)); + if (!abilityMs) { + HILOG_INFO("RemoveStack abilityMs nullptr"); + return OHOS::ERR_INVALID_VALUE; + } + int result = abilityMs->RemoveStack(id); + std::this_thread::sleep_for(std::chrono::milliseconds(removeDelay)); + return result; +} + +const std::string MSG_SUCCESS = "[SUCCESS]"; +void SystemTestFormUtil::Install(const std::string &bundleFilePath, const InstallFlag installFlag) +{ + std::string bundlePath = "/system/vendor/" + bundleFilePath + ".hap"; + std::string installMsg = ""; + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + std::cout << "get bundle installer Failure." << std::endl; + installMsg = "Failure"; + return; + } + + InstallParam installParam; + installParam.installFlag = installFlag; + sptr statusReceiver(new (std::nothrow) InstallToolStatusReceiver()); + if (statusReceiver == nullptr) { + std::cout << "get statusReceiver Failure." << std::endl; + return; + } + bool installResult = installerProxy->Install(bundlePath, installParam, statusReceiver); + if (!installResult) { + installMsg = "Failure"; + return; + } + if (InstallToolStatusReceiver::TestWaitCompleted(statusReceiver->event_, MSG_SUCCESS, 0) == 0) { + installMsg = "Success"; + } else { + installMsg = "Failure"; + } +} + +void SystemTestFormUtil::Uninstall(const std::string &bundleName) +{ + std::string uninstallMsg = ""; + sptr installerProxy = GetInstallerProxy(); + if (!installerProxy) { + std::cout << "get bundle installer Failure." << std::endl; + uninstallMsg = "Failure"; + return; + } + if (bundleName.empty()) { + std::cout << "bundelname is null." << std::endl; + uninstallMsg = "Failure"; + } else { + sptr statusReceiver(new (std::nothrow) InstallToolStatusReceiver()); + if (statusReceiver == nullptr) { + std::cout << "get statusReceiver Failure." << std::endl; + uninstallMsg = "Failure"; + return; + } + InstallParam installParam; + bool uninstallResult = installerProxy->Uninstall(bundleName, installParam, statusReceiver); + if (!uninstallResult) { + std::cout << "Uninstall Failure." << std::endl; + uninstallMsg = "Failure"; + return; + } + if (InstallToolStatusReceiver::TestWaitCompleted(statusReceiver->event_, MSG_SUCCESS, 0) == 0) { + uninstallMsg = "Success"; + } else { + uninstallMsg = "Failure"; + } + } +} + +sptr SystemTestFormUtil::GetInstallerProxy() +{ + sptr bundleMgrProxy = GetBundleMgrProxy(); + if (!bundleMgrProxy) { + std::cout << "bundle mgr proxy is nullptr." << std::endl; + return nullptr; + } + + sptr installerProxy = bundleMgrProxy->GetBundleInstaller(); + if (!installerProxy) { + std::cout << "fail to get bundle installer proxy" << std::endl; + return nullptr; + } + std::cout << "get bundle installer proxy success." << std::endl; + return installerProxy; +} + +sptr SystemTestFormUtil::GetBundleMgrProxy() +{ + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + std::cout << "fail to get system ability mgr." << std::endl; + return nullptr; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (!remoteObject) { + std::cout << "fail to get bundle manager proxy." << std::endl; + return nullptr; + } + + std::cout << "get bundle manager proxy success." << std::endl; + return iface_cast(remoteObject); +} + +/** + * @brief Query all of form storage infos. + * @return Returns all of form storage infos. + */ +std::string SystemTestFormUtil::QueryStorageFormInfos() +{ + std::cout << "QueryStorageFormInfos called." << std::endl; + + std::string formInfos = ""; + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "QueryStorageFormInfos, failed to write interface token." << std::endl; + return "QueryStorageFormInfos, failed to write interface token."; + } + + int result = GetStringInfo(AppExecFwk::IFormMgr::Message::FORM_MGR_STORAGE_FORM_INFOS, data, formInfos); + if (result != ERR_OK) { + std::cout << "QueryStorageFormInfos, failed to query form info." << std::endl; + } + + std::cout << "QueryStorageFormInfos end." << std::endl; + + return formInfos; +} +/** + * @brief Query form infos by bundleName. + * @param bundleName BundleName. + * @return Returns form infos. + */ +std::string SystemTestFormUtil::QueryFormInfoByBundleName(const std::string& bundleName) +{ + std::cout << "QueryFormInfoByBundleName called." << std::endl; + + std::string formInfos = ""; + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "QueryFormInfoByBundleName, failed to write interface token." << std::endl; + return "QueryFormInfoByBundleName, failed to write interface token."; + } + + if (!data.WriteString(bundleName)) { + std::cout << "QueryFormInfoByBundleName, failed to write bundleName." << std::endl; + return "QueryFormInfoByBundleName, failed to write bundleName."; + } + + int result = GetStringInfo(AppExecFwk::IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_NAME, data, formInfos); + if (result != ERR_OK) { + std::cout << "QueryFormInfoByBundleName, failed to query form info." << std::endl; + } + + std::cout << "QueryFormInfoByBundleName end." << std::endl; + + return formInfos; +} +/** + * @brief Query form infos by form id. + * @param formId The id of the form. + * @return Returns form infos. + */ +std::string SystemTestFormUtil::QueryFormInfoByFormId(const std::int64_t formId) +{ + std::cout << "QueryFormInfoByFormId called." << std::endl; + + std::string formInfo = ""; + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "QueryFormInfoByFormId, failed to write interface token." << std::endl; + return "QueryFormInfoByFormId, failed to write interface token."; + } + if (!data.WriteInt64(formId)) { + std::cout << "QueryFormInfoByFormId, failed to write formId." << std::endl; + return "QueryFormInfoByFormId, failed to write formId."; + } + + int result = GetStringInfo(AppExecFwk::IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID, data, formInfo); + if (result != ERR_OK) { + std::cout << "QueryFormInfoByFormId, failed to query form info." << std::endl; + } + + std::cout << "QueryFormInfoByFormId end." << std::endl; + + return formInfo; +} +bool SystemTestFormUtil::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(AppExecFwk::IFormMgr::GetDescriptor())) { + std::cout << "WriteInterfaceToken, failed to write interface token." << std::endl; + return false; + } + return true; +} +int SystemTestFormUtil::GetStringInfo(AppExecFwk::IFormMgr::Message code, MessageParcel &data, std::string &stringInfo) +{ + int error; + MessageParcel reply; + error = SendTransactCmd(code, data, reply); + if (error != ERR_OK) { + return error; + } + + error = reply.ReadInt32(); + if (error != ERR_OK) { + std::cout << "GetStringInfo, failed to read reply result." << std::endl; + return error; + } + std::vector stringInfoList; + if (!reply.ReadStringVector(&stringInfoList)) { + std::cout << "GetStringInfo, failed to read string vector from reply." << std::endl; + return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + } + if (stringInfoList.empty()) { + std::cout << "GetStringInfo, No string info." << std::endl; + return ERR_APPEXECFWK_FORM_NOT_EXIST_ID; + } + for (auto &info : stringInfoList) { + stringInfo += info; + } + std::cout << "GetStringInfo end." << std::endl; + return ERR_OK; +} +int SystemTestFormUtil::SendTransactCmd(AppExecFwk::IFormMgr::Message code, MessageParcel &data, MessageParcel &reply) +{ + sptr remoteObject = GetFmsService(); + if (!remoteObject) { + std::cout << "SendTransactCmd, failed to get remote object." << std::endl; + return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED; + } + + MessageOption option(MessageOption::TF_SYNC); + int32_t result = remoteObject->SendRequest(static_cast(code), data, reply, option); + if (result != ERR_OK) { + std::cout << "SendTransactCmd, failed to SendRequest." << std::endl; + return result; + } + return ERR_OK; +} +/** + * @brief Get form manager service. + * @return Returns form manager servic remoteObject. + */ +sptr SystemTestFormUtil::GetFmsService() +{ + sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemManager == nullptr) { + std::cout << "SendTransactCmd, failed to get system ability manager." << std::endl; + return nullptr; + } + sptr remoteObject = systemManager->GetSystemAbility(FORM_MGR_SERVICE_ID); + + std::cout << "SendTransactCmd end." << std::endl; + return remoteObject; +} +} // namespace STtools +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn b/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9a529de62f4f12918a62a11867491bc976b5db49 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "appexecfwk_standard/formmanagerst" + +ohos_systemtest("FmsAcquireFormTest") { + module_out_path = module_output_path + include_dirs = [ + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "//base/notification/ces_standard/test/systemtest/common/resource", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + + sources = [ + "${appexecfwk_path}/test/systemtest/common/fms/common/src/form_event.cpp", + "${appexecfwk_path}/test/systemtest/common/fms/common/src/system_test_form_util.cpp", + "fms_acquire_form_test.cpp", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + configs = [ + "${aafwk_path}/services/abilitymgr:abilityms_config", + "${appexecfwk_path}/services/appmgr:appmgr_config", + ] + + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/services/abilitymgr:abilityms", + "${appexecfwk_path}/common:libappexecfwk_common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//third_party/googletest:gtest_main", + ] + + defines = [ "APP_LOG_TAG = \"FMSAcquireFormTest\"" ] + + external_deps = [ + "aafwk_standard:base", + "aafwk_standard:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] +} + +group("systemtest") { + testonly = true + + deps = [ ":FmsAcquireFormTest" ] +} diff --git a/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp b/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7fb6f33e529a13023b99d227b649d8bbd6498f41 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp @@ -0,0 +1,1196 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "ability_handler.h" +#include "ability_info.h" +#include "ability_local_record.h" +#include "ability_start_setting.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "context_deal.h" +#include "form_event.h" +#include "form_st_common_info.h" +#include "system_test_form_util.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +std::vector bundleNameList = { + "com.ohos.form.manager.notsystemapp", + "com.ohos.form.manager.nopermission", +}; +std::vector hapNameList = { + "fmsSystemTestHostNotSys-signed", + "fmsSystemTestHostNoPerm-signed", +}; + +std::string catchFormId; // FormId when creating a cached form +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsAcquireFormTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + static bool SubscribeEvent(); + + void SetUp(); + void TearDown(); + + void StartAbilityKitTest(const std::string &abilityName, const std::string &bundleName); + void TerminateAbility(const std::string &eventName, const std::string &abilityName); + + class FormEventSubscriber : public CommonEventSubscriber { + public: + explicit FormEventSubscriber(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + virtual void OnReceiveEvent(const CommonEventData &data) override; + ~FormEventSubscriber() = default; + }; + + static sptr abilityMs; + static FormEvent event; + static std::vector eventList; + static std::shared_ptr subscriber; + + void FmsAcquireFormCatched1500(std::string strFormId); + void FmsAcquireForm1600(); + void FmsAcquireForm1600A(); + void FmsAcquireForm1800(); + void FmsAcquireForm1800A(); + void FmsAcquireForm1800B(); + void FmsAcquireForm1800C(); + std::string FmsAcquireForm2400(); + void FmsAcquireForm2400_1(std::string strFormId); + void FmsAcquireFormDeleteA(std::string strFormId); +}; + +std::vector FmsAcquireFormTest::eventList = { + FORM_EVENT_RECV_DELETE_FORM_COMMON, + FORM_EVENT_ABILITY_ONACTIVED, FORM_EVENT_RECV_ACQUIRE_FORM_0100, FORM_EVENT_RECV_ACQUIRE_FORM_0200, + FORM_EVENT_RECV_ACQUIRE_FORM_0300, FORM_EVENT_RECV_ACQUIRE_FORM_0400, FORM_EVENT_RECV_ACQUIRE_FORM_0500, + FORM_EVENT_RECV_ACQUIRE_FORM_0600, FORM_EVENT_RECV_ACQUIRE_FORM_0700, FORM_EVENT_RECV_ACQUIRE_FORM_1000, + FORM_EVENT_RECV_ACQUIRE_FORM_1100, FORM_EVENT_RECV_ACQUIRE_FORM_1200, FORM_EVENT_RECV_ACQUIRE_FORM_1400, + FORM_EVENT_RECV_ACQUIRE_FORM_1500, FORM_EVENT_RECV_ACQUIRE_FORM_1600, FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, + FORM_EVENT_RECV_ACQUIRE_FORM_1800, FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, + FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, FORM_EVENT_RECV_ACQUIRE_FORM_1900, FORM_EVENT_RECV_ACQUIRE_FORM_2100, + FORM_EVENT_RECV_ACQUIRE_FORM_2200, FORM_EVENT_RECV_ACQUIRE_FORM_2300, FORM_EVENT_RECV_ACQUIRE_FORM_2500, + FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, FORM_EVENT_RECV_ACQUIRE_FORM_2600, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, + FORM_EVENT_RECV_ACQUIRE_FORM_2400, FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, +}; + + +FormEvent FmsAcquireFormTest::event = FormEvent(); +sptr FmsAcquireFormTest::abilityMs = nullptr; +std::shared_ptr FmsAcquireFormTest::subscriber = nullptr; +void FmsAcquireFormTest::FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + GTEST_LOG_(INFO) << "OnReceiveEvent: event=" << data.GetWant().GetAction(); + GTEST_LOG_(INFO) << "OnReceiveEvent: data=" << data.GetData(); + GTEST_LOG_(INFO) << "OnReceiveEvent: code=" << data.GetCode(); + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsAcquireFormTest::SetUpTestCase() +{ + SystemTestFormUtil::InstallHaps(hapNameList); + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsAcquireFormTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "UnSubscribeCommonEvent calld"; + CommonEventManager::UnSubscribeCommonEvent(subscriber); +} + +void FmsAcquireFormTest::SetUp() +{ +} + +void FmsAcquireFormTest::TearDown() +{ + GTEST_LOG_(INFO) << "CleanMsg calld"; + SystemTestFormUtil::CleanMsg(event); +} +bool FmsAcquireFormTest::SubscribeEvent() +{ + GTEST_LOG_(INFO) << "SubscribeEvent calld"; + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber = std::make_shared(subscribeInfo); + return CommonEventManager::SubscribeCommonEvent(subscriber); +} + +/** + * @tc.number: FMS_acquireForm_1100 + * @tc.name: When the formId is set to 0, a non cached form is added. + * @tc.desc: Verify that the non cache form can be successfully created. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1100, Function | MediumTest | Level1) +{ + sleep(2); + std::cout << "START FMS_acquireForm_1100" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1100, EVENT_CODE_1100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1100)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1100); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1100, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1100, formId:" << strFormId; + } + + catchFormId = strFormId; + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1101)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1100, EVENT_CODE_1101); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1100, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1100, formData:" << data2; + } + int64_t formId = std::stoll(strFormId); + std::string cachedData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + GTEST_LOG_(INFO) << "FMS_acquireForm_1100, cachedData:" << cachedData; + + std::cout << "END FMS_acquireForm_1100" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_1200 + * @tc.name: When the formId is set to 0, a non cached form is added. + * @tc.desc: Verify that the non cache form can be successfully created. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1200, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_1200" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1200, EVENT_CODE_1200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1200)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1200); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1201)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1200, EVENT_CODE_1201); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, formData:" << data2; + } + + int64_t formId = std::stoll(strFormId); + std::string cachedData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, cachedData:" << cachedData; + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FMS_acquireForm_1200, delete form, result:" << result3; + + std::cout << "END FMS_acquireForm_1200" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_1500 + * @tc.name: Add a cached form. + * @tc.desc: Verify that the cached form can be successfully created. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1500, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_1500" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, add no catch form start"; + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1500_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1500_1, EVENT_CODE_1510, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1510)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1510); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, formId:" << strFormId; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1511)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500_1, EVENT_CODE_1511); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, formData:" << data2; + } + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, add no catch form end"; + + sleep(1); + FmsAcquireFormCatched1500(strFormId); + + std::cout << "END FMS_acquireForm_1500" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_1600 + * @tc.name: A single form user (using a single thread) continuously creates 2 normal and 2 temporary forms. + * @tc.desc: Verify that a single user (using a single thread) can successfully create multiple normal + * and temporary forms continuously. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1600, Function | MediumTest | Level1) +{ + sleep(1); + int normalCount = 0; + int tempCount = 0; + for (int iCount = 0; iCount < 2; iCount++) { + sleep(1); + FmsAcquireForm1600(); + normalCount++; + std::cout << "END FMS_acquireForm_1600, normal form end, count:" << normalCount << std::endl; + sleep(1); + FmsAcquireForm1600A(); + tempCount++; + std::cout << "END FMS_acquireForm_1600_1, temp form end, count:" << tempCount << std::endl; + } +} + +/** + * @tc.number: FMS_acquireForm_1800 + * @tc.name: Multiple form users create one normal form and one temporary form respectively. + * @tc.desc: Verify that multiple users can successfully create multiple normal and temporary forms respectively. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1800, Function | MediumTest | Level1) +{ + sleep(1); + FmsAcquireForm1800(); + sleep(1); + FmsAcquireForm1800A(); + sleep(1); + FmsAcquireForm1800B(); + sleep(1); + FmsAcquireForm1800C(); +} + +/** + * @tc.number: FMS_acquireForm_1900 + * @tc.name: Add a temporary form when the formId is set to 0. + * @tc.desc: When the verification formId is set to 0, the temporary form is created successfully. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1900, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_1900" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1900; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1900, EVENT_CODE_1900, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1900)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1900); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1900, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1900, normal, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1901)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1900, EVENT_CODE_1901); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1900, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1900, normal, formData:" << data2; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + if (!result3) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1900, delete form, result:" << result3; + } + + std::cout << "END FMS_acquireForm_1900" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2400 + * @tc.name: FormId does not match other parameters when adding a cached form. + * @tc.desc: Failed to create a cached form when verifying that FormId does not match other parameters. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2400, Function | MediumTest | Level1) +{ + sleep(1); + std::string strFormId = FmsAcquireForm2400(); + sleep(1); + FmsAcquireForm2400_1(strFormId); + sleep(1); + FmsAcquireFormDeleteA(strFormId); +} + +/** + * @tc.number: FMS_acquireForm_2600 + * @tc.name: When the normal form does not reach the maximum value created by the form + * (the single user is 256 and the FMS is 512), the temporary form changes to the normal form. + * @tc.desc: Verify that when the normal form does not reach the maximum value created by the form. + * (the single user is 256 and the FMS is 512), the temporary form can be successfully + * casted to the normal form. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2600, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2600" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_2600_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2600_1, EVENT_CODE_2610, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2610)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2610); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, formId:" << strFormId; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2611)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600_1, EVENT_CODE_2611); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, formData:" << data2; + } + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData1 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2600, EVENT_CODE_2600, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600, EVENT_CODE_2600)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2600, EVENT_CODE_2600); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, result:" << result3; + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data4 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result4 = data4 == "true"; + EXPECT_TRUE(result4); + GTEST_LOG_(INFO) << "FMS_acquireForm_2600, delete form, result:" << result4; + std::cout << "END FMS_acquireForm_2600" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0100 + * @tc.name: Form user is not a system application + * @tc.desc: Failed to create form when verifying that the form user is not a system application. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0100, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0100" << std::endl; + + std::string bundleName = "com.ohos.form.manager.notsystemapp"; + std::string abilityName = "FormAbilityNotSys"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0100, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0100, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0100, EVENT_CODE_100); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0100, result:" << result; + + std::cout << "END FMS_acquireForm_0100" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0200 + * @tc.name: The form user does not have permission to use the form + * @tc.desc: Failed to create a form when verifying that the form user does not have form permission. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0200, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.nopermission"; + std::string abilityName = "FormAbilityNoPerm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0200, EVENT_CODE_200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0200, EVENT_CODE_200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0200, EVENT_CODE_200); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0200, result:" << result; + + std::cout << "END FMS_acquireForm_0200" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0300 + * @tc.name: Failed to add form when parameter formId is wrong. + * @tc.desc: Failed to create form when verifying that the parameter (formId) of creating form is wrong. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0300, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0300" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0300; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0300, EVENT_CODE_300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0300, EVENT_CODE_300); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0300, result:" << result; + std::cout << "END FMS_acquireForm_0300" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0400 + * @tc.name: Failed to add form when parameter bundlename is wrong. + * @tc.desc: Form creation failed when verifying the wrong parameter (bundlename) of form creation. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0400, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0400" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0400; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0400, EVENT_CODE_400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0400, EVENT_CODE_400)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0400, EVENT_CODE_400); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0400, result:" << result; + std::cout << "END FMS_acquireForm_0400" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0500 + * @tc.name: Failed to add form when parameter moduleName is wrong. + * @tc.desc: Form creation failed when verifying the wrong parameter (moduleName) of form creation. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0500, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0500" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0500; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0500, EVENT_CODE_500, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0500, EVENT_CODE_500)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0500, EVENT_CODE_500); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0500, result:" << result; + std::cout << "END FMS_acquireForm_0500" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0600 + * @tc.name: Failed to add form when parameter formName is wrong. + * @tc.desc: Form creation failed when verifying the wrong parameter (formName) of form creation. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0600, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0600" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0600; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0600, EVENT_CODE_600, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0600, EVENT_CODE_600)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0600, EVENT_CODE_600); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_0600, result:" << result; + + std::cout << "END FMS_acquireForm_0600" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_0700 + * @tc.name: Failed to add form when parameter abilityName is wrong. + * @tc.desc: Form creation failed when verifying the wrong parameter (abilityName) of form creation. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_0700, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_0700" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_0700; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_0700, EVENT_CODE_700, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_0700, EVENT_CODE_700)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_0700, EVENT_CODE_700); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_0700, result:" << result; + } + std::cout << "END FMS_acquireForm_0700" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_1000 + * @tc.name: Failed to add form when parameter form dimension is wrong. + * @tc.desc: Form creation failed when verifying the wrong parameter (form dimension) of form creation. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1000, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_1000" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1000; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1000, EVENT_CODE_1000, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1000, EVENT_CODE_1000)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1000, EVENT_CODE_1000); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_1000, result:" << result; + + std::cout << "END FMS_acquireForm_1000" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_1400 + * @tc.name: FormId does not match other parameters when adding a cached form. + * @tc.desc: Failed to create a cached form when verifying that FormId does not match other parameters. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_1400, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_1400" << std::endl; + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = catchFormId; + GTEST_LOG_(INFO) << "FMS_acquireForm_1400, formId:" << eventData; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1400, EVENT_CODE_1400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1400, EVENT_CODE_1400)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1400, EVENT_CODE_1400); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_1400, result:" << result; + + std::cout << "END FMS_acquireForm_1400" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2100 + * @tc.name: When creating a temporary form, the formId is specified as the created normal formId. + * @tc.desc: Failed to create a temporary form when verifying that the formId is set to create a normal formId. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2100, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2100" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = catchFormId; + GTEST_LOG_(INFO) << "FMS_acquireForm_2100, formId:" << eventData; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2100, EVENT_CODE_2100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2100, EVENT_CODE_2100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2100, EVENT_CODE_2100); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_2100, result:" << result; + sleep(1); + FmsAcquireFormDeleteA(catchFormId); + std::cout << "END FMS_acquireForm_2100" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2200 + * @tc.name: Cast to normal form when the temporary formId is set to negative. + * @tc.desc: Failed to Cast to normal form when the temporary formId is set to negative + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2200, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2200" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_2200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2200, EVENT_CODE_2200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2200, EVENT_CODE_2200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2200, EVENT_CODE_2200); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_2200, result:" << result; + + std::cout << "END FMS_acquireForm_2200" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2300 + * @tc.name: Cast to normal form when the temporary formIdis set to 0. + * @tc.desc: Failed to convert to normal form when verifying that the temporary formIdis set to 0 + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2300, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2300" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_2300; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2300, EVENT_CODE_2300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2300, EVENT_CODE_2300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2300, EVENT_CODE_2300); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_2300, result:" << result; + + std::cout << "END FMS_acquireForm_2300" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2500 + * @tc.name: cast non-existent temporary formId to normal form. + * @tc.desc: Failed to verify that the temporary formId that does not exist is casted to normal form. + */ +HWTEST_F(FmsAcquireFormTest, FMS_acquireForm_2500, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2500" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_2500; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2500, EVENT_CODE_2500, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2500, EVENT_CODE_2500); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_acquireForm_2500, result:" << result; + + std::cout << "END FMS_acquireForm_2500" << std::endl; +} + +void FmsAcquireFormTest::FmsAcquireFormCatched1500(std::string strFormId) +{ + std::string bundleName1 = "com.ohos.form.manager.normalb"; + std::string abilityName1 = "FormAbilityB"; + MAP_STR_STR params1; + Want want1 = SystemTestFormUtil::MakeWant("device", abilityName1, bundleName1, params1); + SystemTestFormUtil::StartAbility(want1, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, add catched form start"; + std::string eventData2 = strFormId; + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, formId:" << eventData2; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1500, EVENT_CODE_1500, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500, EVENT_CODE_1500)); + std::string strFormId2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1500, EVENT_CODE_1500); + bool result3 = !strFormId2.empty(); + EXPECT_TRUE(result3); + if (!result3) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, result:" << result3; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, formId:" << strFormId2; + } + + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, add catched form end"; + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data5 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result5 = data5 == "true"; + EXPECT_TRUE(result5); + GTEST_LOG_(INFO) << "FMS_acquireForm_1500, delete form, result:" << result5; +} + +void FmsAcquireFormTest::FmsAcquireForm1600() +{ + std::cout << "START FMS_acquireForm_1600, normal form start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1600; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1600, EVENT_CODE_1600, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1600)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1600); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1601)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600, EVENT_CODE_1601); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600, formData:" << data2; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FMS_acquireForm_1600, delete form, result:" << result3; +} + +void FmsAcquireFormTest::FmsAcquireForm1600A() +{ + std::cout << "START FMS_acquireForm_1600_1, temp form start." << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData1 = FORM_EVENT_REQ_ACQUIRE_FORM_1600_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1600_1, EVENT_CODE_1610, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1610)); + std::string strFormId1 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1610); + bool result4 = !strFormId1.empty(); + EXPECT_TRUE(result4); + if (!result4) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600_1, result:" << result4; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600_1 formId:" << strFormId1; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1611)); + std::string data4 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1600_1, EVENT_CODE_1611); + bool result5 = !data4.empty(); + EXPECT_TRUE(result5); + if (!result5) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600_1, result:" << result5; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1600_1, formData:" << data4; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data5 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result6 = data5 == "true"; + EXPECT_TRUE(result6); + GTEST_LOG_(INFO) << "FMS_acquireForm_1600_1, delete form, result:" << result6; +} +void FmsAcquireFormTest::FmsAcquireForm1800() +{ + int normalCount = 0; + std::cout << "START FMS_acquireForm_1800, normal form start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + std::cout << "START FMS_acquireForm_1800, bundleName: "<< bundleName << std::endl; + std::cout << "START FMS_acquireForm_1800, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1800; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1800, EVENT_CODE_1800, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1800)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1800); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1801)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800, EVENT_CODE_1801); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800, formData:" << data2; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FMS_acquireForm_1800, delete form, result:" << result3; + + normalCount++; + std::cout << "END FMS_acquireForm_1800, normal form end, count:" << normalCount << std::endl; +} +void FmsAcquireFormTest::FmsAcquireForm1800A() +{ + int tempCount = 0; + std::cout << "START FMS_acquireForm_1800_1, temp form start." << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + std::cout << "START FMS_acquireForm_1800_1, bundleName: "<< bundleName << std::endl; + std::cout << "START FMS_acquireForm_1800_1, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData1 = FORM_EVENT_REQ_ACQUIRE_FORM_1800_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1800_1, EVENT_CODE_1810, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1810)); + std::string strFormId1 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1810); + bool result4 = !strFormId1.empty(); + EXPECT_TRUE(result4); + if (!result4) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_1, result:" << result4; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_1 formId:" << strFormId1; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1811)); + std::string data4 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_1, EVENT_CODE_1811); + bool result5 = !data4.empty(); + EXPECT_TRUE(result5); + if (!result5) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_1, result:" << result5; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_1, formData:" << data4; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data5 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result6 = data5 == "true"; + EXPECT_TRUE(result6); + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_1, delete form, result:" << result6; + + tempCount++; + std::cout << "END FMS_acquireForm_1800_1, temp form end, count:" << tempCount << std::endl; +} +void FmsAcquireFormTest::FmsAcquireForm1800B() +{ + int normalCount = 0; + std::cout << "START FMS_acquireForm_1800_2, normal form start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + std::cout << "START FMS_acquireForm_1800_2, bundleName: "<< bundleName << std::endl; + std::cout << "START FMS_acquireForm_1800_2, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_1800_2; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1800_2, EVENT_CODE_1820, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1820)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1820); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_2, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_2, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1821)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_2, EVENT_CODE_1821); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_2, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_2, formData:" << data2; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result3 = data3 == "true"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_2, delete form, result:" << result3; + + normalCount++; + std::cout << "END FMS_acquireForm_1800_2, normal form end, count:" << normalCount << std::endl; +} +void FmsAcquireFormTest::FmsAcquireForm1800C() +{ + int tempCount = 0; + std::cout << "START FMS_acquireForm_1800_3, temp form start." << std::endl; + + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + std::cout << "START FMS_acquireForm_1800_3, bundleName: "<< bundleName << std::endl; + std::cout << "START FMS_acquireForm_1800_3, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData1 = FORM_EVENT_REQ_ACQUIRE_FORM_1800_3; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_1800_3, EVENT_CODE_1830, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1830)); + std::string strFormId1 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1830); + bool result4 = !strFormId1.empty(); + EXPECT_TRUE(result4); + if (!result4) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_3, result:" << result4; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_3 formId:" << strFormId1; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1831)); + std::string data4 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_1800_3, EVENT_CODE_1831); + bool result5 = !data4.empty(); + EXPECT_TRUE(result5); + if (!result5) { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_3, result:" << result5; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_3, formData:" << data4; + } + + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data5 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result6 = data5 == "true"; + EXPECT_TRUE(result6); + GTEST_LOG_(INFO) << "FMS_acquireForm_1800_3, delete form, result:" << result6; + + tempCount++; + std::cout << "END FMS_acquireForm_1800_3, temp form end, count:" << tempCount << std::endl; +} + +std::string FmsAcquireFormTest::FmsAcquireForm2400() +{ + int normalCount = 0; + std::cout << "START FMS_acquireForm_2400, temp form start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + std::cout << "START FMS_acquireForm_2400, bundleName: "<< bundleName << std::endl; + std::cout << "START FMS_acquireForm_2400, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_ACQUIRE_FORM_2400; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2400, EVENT_CODE_2400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2400)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2400); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_acquireForm_2400, result:" << result; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_2400, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2401)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400, EVENT_CODE_2401); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_acquireForm_2400, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FMS_acquireForm_2400, formData:" << data2; + } + + normalCount++; + std::cout << "END FMS_acquireForm_2400, temp form end, count:" << normalCount << std::endl; + + return strFormId; +} + +void FmsAcquireFormTest::FmsAcquireForm2400_1(std::string strFormId) +{ + std::cout << "START FMS_acquireForm_2400_1, cast temp start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + std::cout << "START FmsAcquireForm2400_1, bundleName: "<< bundleName << std::endl; + std::cout << "START FmsAcquireForm2400_1, abilityName: "<< abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData1 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2400_1, EVENT_CODE_2410, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410); + bool result3 = data3 == "false"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FmsAcquireForm2400_1, result:" << result3; + + std::cout << "END FmsAcquireForm2400_1 cast temp end" << std::endl; +} + +void FmsAcquireFormTest::FmsAcquireFormDeleteA(std::string strFormId) +{ + std::cout << "START FmsAcquireFormDeleteA, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + std::cout << "START FmsAcquireFormDeleteA, bundleName: " << bundleName << std::endl; + std::cout << "START FmsAcquireFormDeleteA, abilityName: " << abilityName << std::endl; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + std::string eventData = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_COMMON, EVENT_CODE_999, eventData); + // wait delete form + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999); + bool result = data == "true"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireFormDeleteA, delete form, result:" << result; + + std::cout << "END FmsAcquireFormDeleteA end" << std::endl; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_delete_form_test/BUILD.gn b/test/systemtest/common/fms/fms_delete_form_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..08ed2ad2d404b0cff773d3651d7ca79ff3d6da87 --- /dev/null +++ b/test/systemtest/common/fms/fms_delete_form_test/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "appexecfwk_standard/formmanagerst" + +ohos_systemtest("FormDeleteFormTest") { + module_out_path = module_output_path + include_dirs = [ + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "//base/notification/ces_standard/test/systemtest/common/resource", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + + sources = [ + "${appexecfwk_path}/test/systemtest/common/fms/common/src/form_event.cpp", + "${appexecfwk_path}/test/systemtest/common/fms/common/src/system_test_form_util.cpp", + "fms_delete_form_test.cpp", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + configs = [ + "${aafwk_path}/services/abilitymgr:abilityms_config", + "${appexecfwk_path}/services/appmgr:appmgr_config", + ] + + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/services/abilitymgr:abilityms", + "${appexecfwk_path}/common:libappexecfwk_common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//third_party/googletest:gtest_main", + ] + + defines = [ "APP_LOG_TAG = \"FMSDeleteFormTest\"" ] + + external_deps = [ + "aafwk_standard:base", + "aafwk_standard:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] +} + +group("systemtest") { + testonly = true + + deps = [ ":FormDeleteFormTest" ] +} diff --git a/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp b/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..befe90cfe82f55dd82baed01b045bd2d7f309edd --- /dev/null +++ b/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp @@ -0,0 +1,652 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "ability_handler.h" +#include "ability_info.h" +#include "ability_local_record.h" +#include "ability_start_setting.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "context_deal.h" +#include "form_event.h" +#include "form_st_common_info.h" +#include "system_test_form_util.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +std::vector bundleNameList = { + "com.ohos.form.manager.notsystemapp", +}; +std::vector hapNameList = { + "fmsSystemTestHostNotSys-signed", +}; +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsDeleteFormTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + static bool SubscribeEvent(); + + void SetUp(); + void TearDown(); + + void StartAbilityKitTest(const std::string &abilityName, const std::string &bundleName); + void TerminateAbility(const std::string &eventName, const std::string &abilityName); + + class FormEventSubscriber : public CommonEventSubscriber { + public: + explicit FormEventSubscriber(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + virtual void OnReceiveEvent(const CommonEventData &data) override; + ~FormEventSubscriber() = default; + }; + + static sptr abilityManager; + static FormEvent event; + static std::vector eventList; + static std::shared_ptr subscriber; +}; + +std::vector FmsDeleteFormTest::eventList = { + FORM_EVENT_ABILITY_ONACTIVED, + FORM_EVENT_RECV_DELETE_FORM_0100, + FORM_EVENT_RECV_DELETE_FORM_0200, + FORM_EVENT_RECV_DELETE_FORM_0300, + FORM_EVENT_RECV_DELETE_FORM_0400, + FORM_EVENT_RECV_DELETE_FORM_0500, + FORM_EVENT_RECV_DELETE_FORM_0600, + FORM_EVENT_RECV_DELETE_FORM_0700, + FORM_EVENT_RECV_DELETE_FORM_0800, + FORM_EVENT_RECV_DELETE_FORM_0900, + FORM_EVENT_RECV_DELETE_FORM_1000, + FORM_EVENT_RECV_DELETE_FORM_1100, + FORM_EVENT_RECV_DELETE_FORM_1200, + FORM_EVENT_RECV_DELETE_FORM_1400, + FORM_EVENT_RECV_DELETE_FORM_1500, + FORM_EVENT_RECV_DELETE_FORM_1600, + FORM_EVENT_RECV_DELETE_FORM_1700, + FORM_EVENT_RECV_ONE_NORMAL_FORM, +}; + +FormEvent FmsDeleteFormTest::event = FormEvent(); +sptr FmsDeleteFormTest::abilityManager = nullptr; +std::shared_ptr FmsDeleteFormTest::subscriber = nullptr; +void FmsDeleteFormTest::FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + GTEST_LOG_(INFO) << "OnReceiveEvent: event=" << data.GetWant().GetAction(); + GTEST_LOG_(INFO) << "OnReceiveEvent: data=" << data.GetData(); + GTEST_LOG_(INFO) << "OnReceiveEvent: code=" << data.GetCode(); + if (data.GetCode() == EVENT_CODE_110) { + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_110, data.GetData()); + } + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsDeleteFormTest::SetUpTestCase() +{ + std::cout << "START Install============" << std::endl; + SystemTestFormUtil::InstallHaps(hapNameList); + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsDeleteFormTest::TearDownTestCase() +{ + std::cout << "START Uninstall============" << std::endl; + SystemTestFormUtil::UninstallBundle(bundleNameList); + CommonEventManager::UnSubscribeCommonEvent(subscriber); +} + +void FmsDeleteFormTest::SetUp() +{ +} + +void FmsDeleteFormTest::TearDown() +{ + SystemTestFormUtil::CleanMsg(event); +} +bool FmsDeleteFormTest::SubscribeEvent() +{ + std::vector eventList = { + FORM_EVENT_ABILITY_ONACTIVED, + FORM_EVENT_RECV_DELETE_FORM_0100, + FORM_EVENT_RECV_DELETE_FORM_0200, + FORM_EVENT_RECV_DELETE_FORM_0300, + FORM_EVENT_RECV_DELETE_FORM_0400, + FORM_EVENT_RECV_DELETE_FORM_0500, + FORM_EVENT_RECV_DELETE_FORM_0600, + FORM_EVENT_RECV_DELETE_FORM_0700, + FORM_EVENT_RECV_DELETE_FORM_0800, + FORM_EVENT_RECV_DELETE_FORM_0900, + FORM_EVENT_RECV_DELETE_FORM_1000, + FORM_EVENT_RECV_DELETE_FORM_1100, + FORM_EVENT_RECV_DELETE_FORM_1200, + FORM_EVENT_RECV_DELETE_FORM_1400, + FORM_EVENT_RECV_DELETE_FORM_1500, + FORM_EVENT_RECV_DELETE_FORM_1600, + FORM_EVENT_RECV_DELETE_FORM_1700, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + }; + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber = std::make_shared(subscribeInfo); + return CommonEventManager::SubscribeCommonEvent(subscriber); +} + +/** + * @tc.number: FMS_deleteForm_0100 + * @tc.name: host is not a system app + * @tc.desc: 1.delete the form that formID is 1 + * 2.Verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0100, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0100" << std::endl; + + std::string bundleName = "com.ohos.form.manager.notsystemapp"; + std::string abilityName = "FormAbilityNotSys"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0100, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0100, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0100, EVENT_CODE_100); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0100, result:" << result; + } + + std::cout << "============END FMS_deleteForm_0100" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0200 + * @tc.name: host does not have permission + * @tc.desc: 1.delete the form that formID is 1 + * 2.Verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0200, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.nopermission"; + std::string abilityName = "FormAbilityNoPerm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0200, EVENT_CODE_200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0200, EVENT_CODE_200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0200, EVENT_CODE_200); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0200, result:" << result; + } + + std::cout << "============END FMS_deleteForm_0200" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0300 + * @tc.name: formID id is error(formID < 0) + * @tc.desc: 1.delete the form + * 2.Verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0300, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0300" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0300; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0300, EVENT_CODE_300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0300, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_deleteForm_0300" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0400 + * @tc.name: formID id is error(formID = 0) + * @tc.desc: 1.delete the form + * 2.Verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0400, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0400" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0400; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0400, EVENT_CODE_400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0400, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_deleteForm_0400" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0500 + * @tc.name: formID id is error because formId is not self + * @tc.desc: 1.host A create a formA + * 2.host B delete the formA + * 2.Verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0500, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0500" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_deleteForm_0500, data:[" << data << "]" << std::endl; + bool result1 = data != ""; + EXPECT_TRUE(result1); + + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0500, EVENT_CODE_500, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500); + bool result2 = data2 == "false"; + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0500, result2:" << result2; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_0500" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0600 + * @tc.name: Delete a normal form and the form reference is not 0 after deletion + * @tc.desc: 1.host A create a normal formA + * 2.host B create a form with formA's ID + * 3.delete formA, and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0600, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0600" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_deleteForm_0600, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0600, EVENT_CODE_600, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0600, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_0600" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0700 + * @tc.name: After deleting a normal form, the form reference is 0. + * After deleting a form, there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0700, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0700" << std::endl; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_deleteForm_0700, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0700, EVENT_CODE_700, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0700, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_0700" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0800 + * @tc.name: After deleting a normal form, there is no created normal form in FMS. + * @tc.desc: 1.host create one normal card + * 2.host delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0800, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0800" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0800; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0800, EVENT_CODE_800, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0800, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_0800" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_0900 + * @tc.name: Form ID error (FormID does not exist) + * @tc.desc: 1.host create one normal card + * 2.host delete the form + * 3.host delete the form again and verify the result is false + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_0900, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_0900" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_0900; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_0900, EVENT_CODE_900, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0900, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_0900" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1000 + * @tc.name: You can delete a card after releasing it + * @tc.desc: 1.host create one normal card + * 2.host release the form + * 3.host delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1000, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1000" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_DELETE_FORM_1000; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1000, EVENT_CODE_1000, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1000, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_1000" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1100 + * @tc.name: When deleting a temporary form, cache data is deleted. + * @tc.desc: 1.host a and b create one temporary card respectively + * 2.host a delete the form and verify the result is true + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1100, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1100" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "true"; // temp form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, 100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, 100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, 100); + + GTEST_LOG_(INFO) << "FMS_deleteForm_1100, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityDeleteForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1100, EVENT_CODE_1100, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1100, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_deleteForm_1100" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1200 + * @tc.name: single host (using a single thread) continuously deletes multiple normal and temporary forms + * @tc.desc: 1.There are 5 normal forms and 5 temporary forms created by the single host + * 2.single host (using a single thread) deletes 10 deletes successfully + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1200, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1200" << std::endl; + std::cout << "============END FMS_deleteForm_1200" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1400 + * @tc.name: Multiple hosts delete normal and temporary forms respectively + * @tc.desc: 1.host A and B have 5 normal forms and 5 temporary forms respectively. + * 2.host A and B delete their forms successively. + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1400, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1400" << std::endl; + std::cout << "============END FMS_deleteForm_1400" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1500 + * @tc.name: create 256 temporary forms and delete one + * @tc.desc: 1.create 256 temporary forms and delete one + * 2.create one temporary form successfully . + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1500, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1500" << std::endl; + std::cout << "============END FMS_deleteForm_1500" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1600 + * @tc.name: create 256 normal forms and delete one + * @tc.desc: 1.create 256 normal forms and delete one + * 2.create one normal form successfully . + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1600, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1600" << std::endl; + std::cout << "============END FMS_deleteForm_1600" << std::endl; +} + +/** + * @tc.number: FMS_deleteForm_1700 + * @tc.name: When the number of normal forms of multiple hosts reaches 512, + * you can delete forms and create forms + * @tc.desc: 1.host A create 200 normal forms + * 2.host B create 200 normal forms + * 3.host C create 112 normal forms + * 4.host C delete one normal form and create one normal form successfully . + */ +HWTEST_F(FmsDeleteFormTest, FMS_deleteForm_1700, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_deleteForm_1700" << std::endl; + std::cout << "============END FMS_deleteForm_1700" << std::endl; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_release_form_test/BUILD.gn b/test/systemtest/common/fms/fms_release_form_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1bc7de01d765b63018a2cd102f2fbc0cd0add9f0 --- /dev/null +++ b/test/systemtest/common/fms/fms_release_form_test/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "appexecfwk_standard/formmanagerst" + +ohos_systemtest("FormReleaseFormTest") { + module_out_path = module_output_path + include_dirs = [ + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "//base/notification/ces_standard/test/systemtest/common/resource", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + + sources = [ + "${appexecfwk_path}/test/systemtest/common/fms/common/src/form_event.cpp", + "${appexecfwk_path}/test/systemtest/common/fms/common/src/system_test_form_util.cpp", + "fms_release_form_test.cpp", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + configs = [ + "${aafwk_path}/services/abilitymgr:abilityms_config", + "${appexecfwk_path}/services/appmgr:appmgr_config", + ] + + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/services/abilitymgr:abilityms", + "${appexecfwk_path}/common:libappexecfwk_common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//third_party/googletest:gtest_main", + ] + + defines = [ "APP_LOG_TAG = \"FMSReleaseFormTest\"" ] + + external_deps = [ + "aafwk_standard:base", + "aafwk_standard:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] +} + +group("systemtest") { + testonly = true + + deps = [ ":FormReleaseFormTest" ] +} diff --git a/test/systemtest/common/fms/fms_release_form_test/fms_release_form_test.cpp b/test/systemtest/common/fms/fms_release_form_test/fms_release_form_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9292240ea44285fbaab43951bbd75afe01ca8789 --- /dev/null +++ b/test/systemtest/common/fms/fms_release_form_test/fms_release_form_test.cpp @@ -0,0 +1,700 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "ability_handler.h" +#include "ability_info.h" +#include "ability_local_record.h" +#include "ability_start_setting.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "context_deal.h" +#include "form_event.h" +#include "form_st_common_info.h" +#include "system_test_form_util.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +std::vector bundleNameList = { + "com.ohos.form.manager.notsystemapp", +}; +std::vector hapNameList = { + "fmsSystemTestHostNotSys-signed", +}; +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsReleaseFormTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + static bool SubscribeEvent(); + + void SetUp(); + void TearDown(); + + void StartAbilityKitTest(const std::string &abilityName, const std::string &bundleName); + void TerminateAbility(const std::string &eventName, const std::string &abilityName); + + class FormEventSubscriber : public CommonEventSubscriber { + public: + explicit FormEventSubscriber(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + virtual void OnReceiveEvent(const CommonEventData &data) override; + ~FormEventSubscriber() = default; + }; + + static sptr abilityManager; + static FormEvent event; + static std::vector eventList; + static std::shared_ptr subscriber; +}; + +std::vector FmsReleaseFormTest::eventList = { + FORM_EVENT_ABILITY_ONACTIVED, + FORM_EVENT_RECV_RELEASE_FORM_0100, + FORM_EVENT_RECV_RELEASE_FORM_0200, + FORM_EVENT_RECV_RELEASE_FORM_0300, + FORM_EVENT_RECV_RELEASE_FORM_0400, + FORM_EVENT_RECV_RELEASE_FORM_0500, + FORM_EVENT_RECV_RELEASE_FORM_0600, + FORM_EVENT_RECV_RELEASE_FORM_0700, + FORM_EVENT_RECV_RELEASE_FORM_0800, + FORM_EVENT_RECV_RELEASE_FORM_0900, + FORM_EVENT_RECV_RELEASE_FORM_1000, + FORM_EVENT_RECV_RELEASE_FORM_1100, + FORM_EVENT_RECV_RELEASE_FORM_1200, + FORM_EVENT_RECV_RELEASE_FORM_1300, + FORM_EVENT_RECV_RELEASE_FORM_1400, + FORM_EVENT_RECV_ONE_NORMAL_FORM, +}; + +FormEvent FmsReleaseFormTest::event = FormEvent(); +sptr FmsReleaseFormTest::abilityManager = nullptr; +std::shared_ptr FmsReleaseFormTest::subscriber = nullptr; +void FmsReleaseFormTest::FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + GTEST_LOG_(INFO) << "OnReceiveEvent: event=" << data.GetWant().GetAction(); + GTEST_LOG_(INFO) << "OnReceiveEvent: data=" << data.GetData(); + GTEST_LOG_(INFO) << "OnReceiveEvent: code=" << data.GetCode(); + + if (data.GetCode() == EVENT_CODE_110) { + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_110, data.GetData()); + } + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsReleaseFormTest::SetUpTestCase() +{ + std::cout << "START Install============" << std::endl; + SystemTestFormUtil::InstallHaps(hapNameList); + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsReleaseFormTest::TearDownTestCase() +{ + std::cout << "START Uninstall============" << std::endl; + SystemTestFormUtil::UninstallBundle(bundleNameList); + CommonEventManager::UnSubscribeCommonEvent(subscriber); +} + +void FmsReleaseFormTest::SetUp() +{ +} + +void FmsReleaseFormTest::TearDown() +{ + SystemTestFormUtil::CleanMsg(event); +} +bool FmsReleaseFormTest::SubscribeEvent() +{ + std::vector eventList = { + FORM_EVENT_ABILITY_ONACTIVED, + FORM_EVENT_RECV_RELEASE_FORM_0100, + FORM_EVENT_RECV_RELEASE_FORM_0200, + FORM_EVENT_RECV_RELEASE_FORM_0300, + FORM_EVENT_RECV_RELEASE_FORM_0400, + FORM_EVENT_RECV_RELEASE_FORM_0500, + FORM_EVENT_RECV_RELEASE_FORM_0600, + FORM_EVENT_RECV_RELEASE_FORM_0700, + FORM_EVENT_RECV_RELEASE_FORM_0800, + FORM_EVENT_RECV_RELEASE_FORM_0900, + FORM_EVENT_RECV_RELEASE_FORM_1000, + FORM_EVENT_RECV_RELEASE_FORM_1100, + FORM_EVENT_RECV_RELEASE_FORM_1200, + FORM_EVENT_RECV_RELEASE_FORM_1300, + FORM_EVENT_RECV_RELEASE_FORM_1400, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + }; + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber = std::make_shared(subscribeInfo); + return CommonEventManager::SubscribeCommonEvent(subscriber); +} + +/** + * @tc.number: FMS_releaseForm_0100 + * @tc.name: host is not a system app + * @tc.desc: 1.release the form that formID is 1 + * 2.Verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0100, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0100" << std::endl; + + std::string bundleName = "com.ohos.form.manager.notsystemapp"; + std::string abilityName = "FormAbilityNotSys"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0100, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0100, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0100, EVENT_CODE_100); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0100, result:" << result; + } + + std::cout << "============END FMS_releaseForm_0100" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0200 + * @tc.name: host does not have permission + * @tc.desc: 1.release the form that formID is 1 + * 2.Verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0200, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.nopermission"; + std::string abilityName = "FormAbilityNoPerm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0200, EVENT_CODE_200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0200, EVENT_CODE_200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0200, EVENT_CODE_200); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0200, result:" << result; + } + + std::cout << "============END FMS_releaseForm_0200" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0300 + * @tc.name: formID id is error(formID < 0) + * @tc.desc: 1.release the form + * 2.Verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0300, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0300" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0300; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0300, EVENT_CODE_300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0300, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_releaseForm_0300" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0400 + * @tc.name: formID id is error(formID = 0) + * @tc.desc: 1.release the form + * 2.Verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0400, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0400" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0400; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0400, EVENT_CODE_400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0400, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_releaseForm_0400" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0500 + * @tc.name: formID id is error because formId is not self + * @tc.desc: 1.host A create a formA + * 2.host B release the formA + * 2.Verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0500, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0500" << std::endl; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_0500, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityReleaseForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0500, EVENT_CODE_500, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0500, EVENT_CODE_500)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0500, EVENT_CODE_500); + bool result = data2 == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0500, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_releaseForm_0500" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0600 + * @tc.name: Form ID error (FormID does not exist) + * @tc.desc: 1.host create one normal card + * 2.host delete the form + * 3.host release the form and verify the result is false + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0600, Function | MediumTest | Level0) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0600" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0600; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0600, EVENT_CODE_600, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600); + bool result = data == "false"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0600, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_0600" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0700 + * @tc.name: form reference is not 0 after release form(isReleaseCache:false) + * @tc.desc: 1.host A create a normal formA + * 2.host B create a form with formA's ID + * 3.release formA(isReleaseCache is false), and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0700, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0700" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_0700, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityReleaseForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0700, EVENT_CODE_700, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0700, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_0700" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0800 + * @tc.name: After releasing a normal form, the form reference is 0.(isReleaseCache:false) + * there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal card respectively + * 2.host A release the form and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0800, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0800" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_0800, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityReleaseForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0800, EVENT_CODE_800, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0800, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_releaseForm_0800" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_0900 + * @tc.name: After releasing a normal form, there is no created normal form in FMS.(isReleaseCache:false) + * @tc.desc: 1.host create one normal card + * 2.host release the form and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_0900, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_0900" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_0900; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_0900, EVENT_CODE_900, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0900, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_0900" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_1000 + * @tc.name: form reference is not 0 after release form(isReleaseCache:true) + * @tc.desc: 1.host A create a normal formA + * 2.host B create a form with formA's ID + * 3.release formA(isReleaseCache:true), and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_1000, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_1000" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_1000, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityReleaseForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1000, EVENT_CODE_1000, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1000, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1000" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_1100 + * @tc.name: After releasing a normal form, the form reference is 0.(isReleaseCache:true) + * there are still created normal forms in FMS. + * @tc.desc: 1.host A an host B create one normal form respectively + * 2.host A release the form and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_1100, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_1100" << std::endl; + + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = "false"; // normal form + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_1100, data:[" << data << "]" << std::endl; + if (data != "") { + std::string bundleName2 = "com.ohos.form.manager.normal"; + std::string abilityName2 = "FormAbilityReleaseForm"; + MAP_STR_STR params2; + Want want2 = SystemTestFormUtil::MakeWant("device", abilityName2, bundleName2, params2); + SystemTestFormUtil::StartAbility(want2, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1100, EVENT_CODE_1100, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100); + bool result = data2 == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1100, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1100" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_1200 + * @tc.name: After releasing a normal form, there is no created normal form in FMS.(isReleaseCache:true) + * @tc.desc: 1.host create one normal card + * 2.host release the form and verify the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_1200, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_1200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_1200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1200, EVENT_CODE_1200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1200, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1200" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_1300 + * @tc.name: single host continuously release forms + * @tc.desc: 1.There are 2 forms created by the single host + * 2.single host release 2 forms successfully + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_1300, Function | MediumTest | Level2) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_1300" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = ""; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1300, EVENT_CODE_1300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300); + bool result = data != ""; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1300, result:" << result; + } + GTEST_LOG_(INFO) << "FMS_releaseForm_1300, data:[" << data << "]" << std::endl; + if (data != "") { + std::string eventData2 = data; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1300, EVENT_CODE_1300, eventData2); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300); + bool result2 = data2 == "true"; + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1300, result2:" << result2; + } + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1300" << std::endl; +} + +/** + * @tc.number: FMS_releaseForm_1400 + * @tc.name: release temp form + * @tc.desc: 1.host create one temp form + * 2.release the form and judge the result is true + */ +HWTEST_F(FmsReleaseFormTest, FMS_releaseForm_1400, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "============START FMS_releaseForm_1400" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityReleaseForm"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_RELEASE_FORM_1400; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_1400, EVENT_CODE_1400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1400, result:" << result; + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1400" << std::endl; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_self_starting_test/BUILD.gn b/test/systemtest/common/fms/fms_self_starting_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3e85f1586cc3251e374f8dd78547344cc5a6b3c7 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/BUILD.gn @@ -0,0 +1,73 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "appexecfwk_standard/formmanagerst" + +ohos_systemtest("FmsSelfStartingTest") { + module_out_path = module_output_path + include_dirs = [ + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/test/systemtest/common/fms/common/include", + "//base/notification/ces_standard/test/systemtest/common/resource", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + + sources = [ + "${appexecfwk_path}/test/systemtest/common/fms/common/src/form_event.cpp", + "${appexecfwk_path}/test/systemtest/common/fms/common/src/system_test_form_util.cpp", + "fms_self_starting_test.cpp", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + configs = [ + "${aafwk_path}/services/abilitymgr:abilityms_config", + "${appexecfwk_path}/services/appmgr:appmgr_config", + ] + + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/services/abilitymgr:abilityms", + "${appexecfwk_path}/common:libappexecfwk_common", + "//foundation/aafwk/standard/interfaces/innerkits/ability_manager:ability_manager", + "//foundation/appexecfwk/standard/interfaces/innerkits/libeventhandler:libeventhandler", + "//third_party/googletest:gtest_main", + ] + + defines = [ "APP_LOG_TAG = \"FmsSelfStartingTest\"" ] + + external_deps = [ + "aafwk_standard:base", + "aafwk_standard:want", + "appexecfwk_standard:appexecfwk_base", + "appexecfwk_standard:appexecfwk_core", + "ces_standard:cesfwk_core", + "ces_standard:cesfwk_innerkits", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] +} + +group("systemtest") { + testonly = true + + deps = [ ":FmsSelfStartingTest" ] +} diff --git a/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh b/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh new file mode 100644 index 0000000000000000000000000000000000000000..6ca84e72f3a152ae9863f382f6da95817d83e1ab --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh @@ -0,0 +1,56 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +sleepSeconds=20 + +echo "Install hap begin" +chmod 644 /system/app/fmsSystemTestSelfStartingA-signed.hap +bm install -p /system/app/fmsSystemTestSelfStartingA-signed.hap +sleep 1 +chmod 644 /system/app/fmsSystemTestSelfStartingB-signed.hap +bm install -p /system/app/fmsSystemTestSelfStartingB-signed.hap +sleep 1 +echo "Install hap end" +echo "acquire forms" +./FmsSelfStartingTest + +if [ $? -eq 0 ]; then + sleep 10 + echo "acquire forms succeed" +else + echo "acquire forms failed" + exit +fi + +formStorage=`fm query -s` +echo "get form storage:" +echo "${formStorage}" + +sleep 2 +echo "kill foundation" +pgrep foundation | xargs kill -9 + +echo "sleep ${sleepSeconds} seconds" +sleep ${sleepSeconds} + +newFormStorage=`fm query -s` +echo "get form storage after FMS restart:" +echo "${newFormStorage}" + +if [ "${formStorage}" == "${newFormStorage}" ]; then + echo "same form storage" +else + echo "not same form storage" +fi + +exit \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_self_starting_test/fms_check_self_starting.sh b/test/systemtest/common/fms/fms_self_starting_test/fms_check_self_starting.sh new file mode 100644 index 0000000000000000000000000000000000000000..1ec86d113818b381b8b17e8612bb8d8e15525584 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_check_self_starting.sh @@ -0,0 +1,47 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +abilityName=$1 +bundleName=$2 +sleepSeconds=20 +MaxlinesInOneLoop=22000 +linesInOnLoop=5000 +loop=1 +if [ -n "$3" ]; then + loopKey=$3 + loop=$((10#${loopKey})) +fi +echo "loop times: ${loop}" +for i in $(seq 1 ${loop}) +do + echo "==========loop: ${i} start==========" + echo "kill foundation" + pgrep foundation | xargs kill -9 + + echo "sleep ${sleepSeconds} seconds" + sleep ${sleepSeconds} + + echo "check whether the FMS restart" + /system/bin/aa start -d aa -a ${abilityName} -b ${bundleName};hilog -a ${MaxlinesInOneLoop} | tail -n ${linesInOnLoop}>>log_loop${loop}.txt + + if [ $? -eq 0 ]; then + echo "loop ${i}: FMS restart succeed" + echo "clean host" + killall -9 ${bundleName} + else + echo "loop ${i}: FMS restart failed" + exit + fi +done + +exit diff --git a/test/systemtest/common/fms/fms_self_starting_test/fms_self_starting_test.cpp b/test/systemtest/common/fms/fms_self_starting_test/fms_self_starting_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c3e375c2540877aa9b714301a3fa7175234132a1 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_self_starting_test.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "ability_handler.h" +#include "ability_info.h" +#include "ability_local_record.h" +#include "ability_start_setting.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "context_deal.h" +#include "form_event.h" +#include "form_st_common_info.h" +#include "system_test_form_util.h" +#include "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +std::vector bundleNameList = { + "com.ohos.form.manager.selfStartingA", + "com.ohos.form.manager.selfStartingB", +}; +std::vector hapNameList = { + "fmsSystemTestSelfStartingA-signed", + "fmsSystemTestSelfStartingB-signed", +}; +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsSelfStartingTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + + static bool SubscribeEvent(); + + void SetUp(); + void TearDown(); + + void StartAbilityKitTest(const std::string &abilityName, const std::string &bundleName); + void TerminateAbility(const std::string &eventName, const std::string &abilityName); + + class FormEventSubscriber : public CommonEventSubscriber { + public: + explicit FormEventSubscriber(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + virtual void OnReceiveEvent(const CommonEventData &data) override; + ~FormEventSubscriber() = default; + }; + + static sptr abilityMs; + static FormEvent event; + static std::vector eventList; + static std::shared_ptr subscriber_; +}; + +std::vector FmsSelfStartingTest::eventList = { + FORM_EVENT_ABILITY_ONACTIVED, FORM_EVENT_RECV_SELF_STARTING_TEST_0100, FORM_EVENT_RECV_SELF_STARTING_TEST_0200, + FORM_EVENT_RECV_SELF_STARTING_TEST_0300 +}; + +FormEvent FmsSelfStartingTest::event = FormEvent(); +sptr FmsSelfStartingTest::abilityMs = nullptr; +std::shared_ptr FmsSelfStartingTest::subscriber_ = nullptr; +void FmsSelfStartingTest::FormEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + GTEST_LOG_(INFO) << "OnReceiveEvent: event=" << data.GetWant().GetAction(); + GTEST_LOG_(INFO) << "OnReceiveEvent: data=" << data.GetData(); + GTEST_LOG_(INFO) << "OnReceiveEvent: code=" << data.GetCode(); + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsSelfStartingTest::SetUpTestCase() +{ + SystemTestFormUtil::InstallHaps(hapNameList); + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsSelfStartingTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "UnSubscribeCommonEvent calld"; + SystemTestFormUtil::UninstallBundle(bundleNameList); + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +void FmsSelfStartingTest::SetUp() +{ +} + +void FmsSelfStartingTest::TearDown() +{ + GTEST_LOG_(INFO) << "CleanMsg calld"; + SystemTestFormUtil::CleanMsg(event); +} +bool FmsSelfStartingTest::SubscribeEvent() +{ + GTEST_LOG_(INFO) << "SubscribeEvent calld"; + MatchingSkills matchingSkills; + for (const auto &e : eventList) { + matchingSkills.AddEvent(e); + } + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + return CommonEventManager::SubscribeCommonEvent(subscriber_); +} + +/** + * @tc.number: FMS_Start_0300_01 + * @tc.name: Host A add one form + * @tc.desc: + */ +HWTEST_F(FmsSelfStartingTest, FMS_Start_0300_01, Function | MediumTest | Level1) +{ + std::cout << "START FMS_Start_0300_01" << std::endl; + + std::string bundleName = "com.ohos.form.manager.selfStartingA"; + std::string abilityName = "FormAbilitySelfStartingA"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_SELF_STARTING_TEST_0100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_SELF_STARTING_TEST_0100, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0100, EVENT_CODE_100)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0100, EVENT_CODE_100); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_Start_0300_01, result:" << result; + } + std::cout << "END FMS_Start_0300_01" << std::endl; +} + +/** + * @tc.number: FMS_Start_0300_02 + * @tc.name: Host B add form one + * @tc.desc: + */ +HWTEST_F(FmsSelfStartingTest, FMS_Start_0300_02, Function | MediumTest | Level1) +{ + std::cout << "START FMS_Start_0300_02" << std::endl; + std::string bundleName = "com.ohos.form.manager.selfStartingB"; + std::string abilityName = "FormAbilitySelfStartingB"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_SELF_STARTING_TEST_0200; + GTEST_LOG_(INFO) << "FMS_Start_0300_02, eventData:" << eventData; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_SELF_STARTING_TEST_0200, EVENT_CODE_200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0200, EVENT_CODE_200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0200, EVENT_CODE_200); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_Start_0300_02, result:" << result; + } + + std::cout << "END FMS_Start_0300_02" << std::endl; +} + +/** + * @tc.number: FMS_Start_0300_03 + * @tc.name: Host B add form two + * @tc.desc: + */ +HWTEST_F(FmsSelfStartingTest, FMS_Start_0300_03, Function | MediumTest | Level1) +{ + std::cout << "START FMS_Start_0300_03" << std::endl; + std::string bundleName = "com.ohos.form.manager.selfStartingB"; + std::string abilityName = "FormAbilitySelfStartingB"; + MAP_STR_STR params; + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityMs); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + + std::string eventData = FORM_EVENT_REQ_SELF_STARTING_TEST_0300; + GTEST_LOG_(INFO) << "FMS_Start_0300_03, eventData:" << eventData; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_SELF_STARTING_TEST_0300, EVENT_CODE_300, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0300, EVENT_CODE_300)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_SELF_STARTING_TEST_0300, EVENT_CODE_300); + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_Start_0300_03, result:" << result; + } +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file