diff --git a/interfaces/innerkits/appexecfwk_base/include/form_constants.h b/interfaces/innerkits/appexecfwk_base/include/form_constants.h index 0819e3111dcf3211965f4f845fecf4f921fc050e..cfd1fc11dc5f2d93b6702908938a84e6e4f96e9c 100644 --- a/interfaces/innerkits/appexecfwk_base/include/form_constants.h +++ b/interfaces/innerkits/appexecfwk_base/include/form_constants.h @@ -101,6 +101,8 @@ namespace Constants { // the delimiter between bundleName and abilityName const std::string NAME_DELIMITER = "::"; + const std::string PARAM_FORM_ADD_COUNT = "form.add.count"; + const size_t MAX_LAYOUT = 8; const std::map DIMENSION_MAP = { {1, "1*2"}, diff --git a/interfaces/innerkits/appexecfwk_base/include/form_js_info.h b/interfaces/innerkits/appexecfwk_base/include/form_js_info.h index 69fe4a021719e38faa95ac9154e7ac1929348bd5..ac079d6bde1ece99ebc292976a1f31f548c74e6e 100644 --- a/interfaces/innerkits/appexecfwk_base/include/form_js_info.h +++ b/interfaces/innerkits/appexecfwk_base/include/form_js_info.h @@ -1,51 +1,51 @@ -/* - * 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 FOUNDATION_APPEXECFWK_OHOS_FORM_JS_INFO_H -#define FOUNDATION_APPEXECFWK_OHOS_FORM_JS_INFO_H - - -#include -#include "parcel.h" -#include "form_provider_data.h" - -namespace OHOS { -namespace AppExecFwk { -/** - * @struct FormJsInfo - * Defines form js info. - */ -struct FormJsInfo : public Parcelable { - int64_t formId; - std::string formName; - std::string bundleName; - std::string abilityName; - bool formTempFlg = false; - std::string jsFormCodePath; - std::string formData; - FormProviderData formProviderData; - - std::string htmlPath; - std::string cssPath; - std::string jsPath; - std::string fileReousePath; - - bool ReadFromParcel(Parcel &parcel); - virtual bool Marshalling(Parcel &parcel) const override; - static FormJsInfo *Unmarshalling(Parcel &parcel); -}; -} // namespace AppExecFwk -} // namespace OHOS +/* + * 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 FOUNDATION_APPEXECFWK_OHOS_FORM_JS_INFO_H +#define FOUNDATION_APPEXECFWK_OHOS_FORM_JS_INFO_H + + +#include +#include "form_provider_data.h" +#include "parcel.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @struct FormJsInfo + * Defines form js info. + */ +struct FormJsInfo : public Parcelable { + int64_t formId; + std::string formName; + std::string bundleName; + std::string abilityName; + bool formTempFlg = false; + std::string jsFormCodePath; + std::string formData; + FormProviderData formProviderData; + + std::string htmlPath; + std::string cssPath; + std::string jsPath; + std::string fileReousePath; + + bool ReadFromParcel(Parcel &parcel); + virtual bool Marshalling(Parcel &parcel) const override; + static FormJsInfo *Unmarshalling(Parcel &parcel); +}; +} // namespace AppExecFwk +} // namespace OHOS #endif // FOUNDATION_APPEXECFWK_OHOS_FORM_JS_INFO_H \ No newline at end of file diff --git a/interfaces/innerkits/appexecfwk_base/src/form_info.cpp b/interfaces/innerkits/appexecfwk_base/src/form_info.cpp index 9e589c283d149557e8d2057d85149b45ba129780..75d5a22d8ca06da8d2537acaed4f15e1c4fbc07c 100644 --- a/interfaces/innerkits/appexecfwk_base/src/form_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/form_info.cpp @@ -120,13 +120,12 @@ bool FormInfo::ReadFromParcel(Parcel &parcel) FormInfo *FormInfo::Unmarshalling(Parcel &parcel) { - FormInfo *info = new FormInfo(); - if (!info->ReadFromParcel(parcel)) { + std::unique_ptr info = std::make_unique(); + if (info && !info->ReadFromParcel(parcel)) { APP_LOGW("read from parcel failed"); - delete info; info = nullptr; } - return info; + return info.release(); } bool FormInfo::Marshalling(Parcel &parcel) const @@ -182,7 +181,7 @@ bool FormInfo::Marshalling(Parcel &parcel) const void to_json(nlohmann::json &jsonObject, const FormCustomizeData &customizeDatas) { jsonObject = nlohmann::json{ - {JSON_KEY_NAME, customizeDatas.name}, + {JSON_KEY_NAME, customizeDatas.name}, {JSON_KEY_VALUE, customizeDatas.value} }; } diff --git a/interfaces/innerkits/appexecfwk_base/src/form_js_info.cpp b/interfaces/innerkits/appexecfwk_base/src/form_js_info.cpp index 46df890569dc09901279438a3fc3cd5c46acf57d..823e1f172569ab52d88205ac32d6b032c1219a1b 100644 --- a/interfaces/innerkits/appexecfwk_base/src/form_js_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/form_js_info.cpp @@ -30,21 +30,20 @@ bool FormJsInfo::ReadFromParcel(Parcel &parcel) formData = Str16ToStr8(parcel.ReadString16()); auto bindingData = parcel.ReadParcelable(); + formProviderData = *bindingData; if (nullptr == bindingData){ return false; } - formProviderData = *bindingData; return true; } FormJsInfo *FormJsInfo::Unmarshalling(Parcel &parcel) { - FormJsInfo *formJsInfo = new (std::nothrow) FormJsInfo(); + std::unique_ptr formJsInfo = std::make_unique(); if (formJsInfo && !formJsInfo->ReadFromParcel(parcel)) { - delete formJsInfo; formJsInfo = nullptr; } - return formJsInfo; + return formJsInfo.release(); } bool FormJsInfo::Marshalling(Parcel &parcel) const diff --git a/interfaces/innerkits/appexecfwk_base/src/form_provider_data.cpp b/interfaces/innerkits/appexecfwk_base/src/form_provider_data.cpp index 918a832f4048055e3191ddb7def4be7bb65e4648..c929b6ec8ea138f393be3c6c7d3f553a197bfbbc 100644 --- a/interfaces/innerkits/appexecfwk_base/src/form_provider_data.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/form_provider_data.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ +#include #include #include -#include #include "app_log_wrapper.h" #include "form_provider_data.h" @@ -269,14 +269,11 @@ bool FormProviderData::Marshalling(Parcel &parcel) const */ FormProviderData* FormProviderData::Unmarshalling(Parcel &parcel) { - FormProviderData *formProviderData = new (std::nothrow) FormProviderData(); + std::unique_ptr formProviderData = std::make_unique(); if (formProviderData && !formProviderData->ReadFromParcel(parcel)) { - delete formProviderData; formProviderData = nullptr; } - std::string str = formProviderData->GetDataString(); - APP_LOGI("%{public}s, , provider data length: %{public}zu, provider data: %{public}s", __func__, str.length(), str.c_str()); - return formProviderData; + return formProviderData.release(); } /** diff --git a/interfaces/innerkits/appexecfwk_base/src/form_provider_info.cpp b/interfaces/innerkits/appexecfwk_base/src/form_provider_info.cpp index d6b83c82a9d2ba74296b33b3f7f157e93523eec5..e7824e24f3c8d001fe8d4ccc837e773369252fa6 100644 --- a/interfaces/innerkits/appexecfwk_base/src/form_provider_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/form_provider_info.cpp @@ -27,12 +27,11 @@ bool FormProviderInfo::ReadFromParcel(Parcel &parcel) FormProviderInfo *FormProviderInfo::Unmarshalling(Parcel &parcel) { - FormProviderInfo *formProviderInfo = new (std::nothrow) FormProviderInfo(); + std::unique_ptr formProviderInfo = std::make_unique(); if (formProviderInfo && !formProviderInfo->ReadFromParcel(parcel)) { - delete formProviderInfo; formProviderInfo = nullptr; } - return formProviderInfo; + return formProviderInfo.release(); } bool FormProviderInfo::Marshalling(Parcel &parcel) const diff --git a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_interface.h b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_interface.h index 19b3d58e7d6b966a77fa02961a22dded1c91c706..59e40281fe59d81613b7ce5eb3b8f2d06e63738f 100644 --- a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_interface.h +++ b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_interface.h @@ -139,6 +139,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) = 0; + /** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form timer. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) = 0; /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -148,6 +155,18 @@ public: */ virtual int MessageEvent(const int64_t formId, const Want &want, const sptr &callerToken) = 0; + /** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int BatchAddFormRecords(const Want &want) = 0; + /** + * @brief Clear form records for st limit value test. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int ClearFormRecords() = 0; + enum class Message { // ipc id 1-1000 for kit // ipc id 1001-2000 for DMS @@ -170,7 +189,10 @@ public: FORM_MGR_STORAGE_FORM_INFOS, FORM_MGR_FORM_INFOS_BY_NAME, FORM_MGR_FORM_INFOS_BY_ID, + FORM_MGR_FORM_TIMER_INFO_BY_ID, FORM_MGR_MESSAGE_EVENT, + FORM_MGR_BATCH_ADD_FORM_RECORDS_ST, + FORM_MGR_CLEAR_FORM_RECORDS_ST, }; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_proxy.h b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_proxy.h index 576f077c005f0b1975faf508cb74e8a1b91a0668..934b53dd48ccf297b8bee8388806476f719ae45f 100644 --- a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_proxy.h +++ b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_proxy.h @@ -132,6 +132,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ virtual int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override; + /** + * @brief Dump timer info by form id. + * @param formId The id of the form. + * @param formInfo Form timer info. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override; /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -140,6 +147,18 @@ public: * @return Returns true if execute success, false otherwise. */ virtual int MessageEvent(const int64_t formId, const Want &want, const sptr &callerToken) override; + + /** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int BatchAddFormRecords(const Want &want) override; + /** + * @brief Clear form records for st limit value test. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int ClearFormRecords() override; private: template int GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos); diff --git a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_stub.h b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_stub.h index 95467215c8c891b8c921b8a8428a9c4c495f724d..c0bf23d71f8070303737bcd213b268a4bebf436a 100644 --- a/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_stub.h +++ b/interfaces/innerkits/appexecfwk_core/include/formmgr/form_mgr_stub.h @@ -128,6 +128,13 @@ private: * @return Returns ERR_OK on success, others on failure. */ int32_t HandleDumpFormInfoByFormId(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle DumpFormTimerByFormId message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleDumpFormTimerByFormId(MessageParcel &data, MessageParcel &reply); /** * @brief Handle DumpFormInfoByFormId message. * @param data input param. @@ -136,6 +143,21 @@ private: */ int32_t HandleMessageEvent(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle BatchAddFormRecords message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleBatchAddFormRecords(MessageParcel &data, MessageParcel &reply); + /** + * @brief Handle ClearFormRecords message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ + int32_t HandleClearFormRecords(MessageParcel &data, MessageParcel &reply); + private: using FormMgrFunc = int32_t (FormMgrStub::*)(MessageParcel &data, MessageParcel &reply); std::map memberFuncMap_; diff --git a/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_proxy.cpp b/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_proxy.cpp index ea52dc1d756f13e2840e59ccb0368c9f596a5c3d..2eb8efd1c25fa2e3dc0b3f6a1ba02764fe3458b6 100644 --- a/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_proxy.cpp +++ b/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_proxy.cpp @@ -460,6 +460,31 @@ int FormMgrProxy::DumpFormInfoByFormId(const std::int64_t formId, std::string &f return error; } +/** + * @brief Dump timer info by form id. + * @param formId The id of the form. + * @param formInfo Form timer info. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrProxy::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) +{ + MessageParcel data; + if (!WriteInterfaceToken(data)) { + APP_LOGE("%{public}s, failed to write interface token", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteInt64(formId)) { + APP_LOGE("%{public}s, failed to write formId", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int error = GetStringInfo(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID, data, isTimingService); + if (error != ERR_OK) { + APP_LOGE("%{public}s, failed to GetStringInfo: %{public}d", __func__, error); + } + + return error; +} /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -502,6 +527,26 @@ int FormMgrProxy::MessageEvent(const int64_t formId, const Want &want, const spt return reply.ReadInt32(); } +/** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrProxy::BatchAddFormRecords(const Want &want) +{ + // must not implement, just for st + return ERR_OK; +} +/** + * @brief Clear form records for st limit value test. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrProxy::ClearFormRecords() +{ + // must not implement, just for st + return ERR_OK; +} + template int FormMgrProxy::GetParcelableInfos(MessageParcel &reply, std::vector &parcelableInfos) { diff --git a/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_stub.cpp b/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_stub.cpp index 42c11f891676683a566f69fb89c235ec015955ff..97b6f35620d5a4660fc01ee5d0d1b17950e8f08c 100644 --- a/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_stub.cpp +++ b/interfaces/innerkits/appexecfwk_core/src/formmgr/form_mgr_stub.cpp @@ -59,12 +59,18 @@ FormMgrStub::FormMgrStub() &FormMgrStub::HandleDumpFormInfoByBundleName; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_FORM_INFOS_BY_ID)] = &FormMgrStub::HandleDumpFormInfoByFormId; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID)] = + &FormMgrStub::HandleDumpFormTimerByFormId; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_SET_NEXT_REFRESH_TIME)] = &FormMgrStub::HandleSetNextRefreshTime; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_LIFECYCLE_UPDATE)] = &FormMgrStub::HandleLifecycleUpdate; memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_MESSAGE_EVENT)] = &FormMgrStub::HandleMessageEvent; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_BATCH_ADD_FORM_RECORDS_ST)] = + &FormMgrStub::HandleBatchAddFormRecords; + memberFuncMap_[static_cast(IFormMgr::Message::FORM_MGR_CLEAR_FORM_RECORDS_ST)] = + &FormMgrStub::HandleClearFormRecords; } FormMgrStub::~FormMgrStub() @@ -353,6 +359,29 @@ int32_t FormMgrStub::HandleDumpFormInfoByFormId(MessageParcel &data, MessageParc } return result; } +/** + * @brief Handle DumpFormTimerByFormId message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleDumpFormTimerByFormId(MessageParcel &data, MessageParcel &reply) +{ + int64_t formId = data.ReadInt64(); + std::string isTimingService; + int32_t result = DumpFormTimerByFormId(formId, isTimingService); + reply.WriteInt32(result); + if (result == ERR_OK) { + std::vector dumpInfos; + SplitString(isTimingService, dumpInfos); + if (!reply.WriteStringVector(dumpInfos)) { + APP_LOGE("%{public}s, failed to WriteStringVector", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + } + return result; +} + /** * @brief Handle DumpFormInfoByFormId message. * @param data input param. @@ -381,5 +410,39 @@ int32_t FormMgrStub::HandleMessageEvent(MessageParcel &data, MessageParcel &repl reply.WriteInt32(result); return result; } + +/** + * @brief Handle BatchAddFormRecords message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleBatchAddFormRecords(MessageParcel &data, MessageParcel &reply) +{ + APP_LOGI("%{public}s called.", __func__); + + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + APP_LOGE("%{public}s, failed to ReadParcelable", __func__); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + int32_t result = BatchAddFormRecords(*want); + reply.WriteInt32(result); + return result; +} +/** + * @brief Handle BatchDeleteFormRecords message. + * @param data input param. + * @param reply output param. + * @return Returns ERR_OK on success, others on failure. + */ +int32_t FormMgrStub::HandleClearFormRecords(MessageParcel &data, MessageParcel &reply) +{ + APP_LOGI("%{public}s called.", __func__); + int32_t result = ClearFormRecords(); + reply.WriteInt32(result); + return result; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/interfaces/innerkits/fmskit/native/include/form_mgr.h b/interfaces/innerkits/fmskit/native/include/form_mgr.h index ec455552e483cf19ee8f2772804020bc57c676fb..c4f52f20dfffb7388e23cd86a48fb502658e49d6 100644 --- a/interfaces/innerkits/fmskit/native/include/form_mgr.h +++ b/interfaces/innerkits/fmskit/native/include/form_mgr.h @@ -51,8 +51,8 @@ public: * @param formInfo Form info. * @return Returns ERR_OK on success, others on failure. */ - int AddForm(const int64_t formId, const Want &want, const sptr &callerToken, - FormJsInfo &formInfo); + int AddForm(const int64_t formId, const Want &want, const sptr &callerToken, + FormJsInfo &formInfo); /** * @brief Delete forms with formIds, send formIds to form manager service. @@ -130,6 +130,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo); + /** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form timer. + * @return Returns ERR_OK on success, others on failure. + */ + int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService); /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -160,6 +167,13 @@ public: */ void UnRegisterDeathCallback(const std::shared_ptr &formDeathCallback); + /** + * @brief Set the next refresh time + * + * @param formId The id of the form. + * @param nextTime Next refresh time + * @return Returns ERR_OK on success, others on failure. + */ int SetNextRefreshTime(const int64_t formId, const int64_t nextTime); /** diff --git a/interfaces/innerkits/fmskit/native/src/form_mgr.cpp b/interfaces/innerkits/fmskit/native/src/form_mgr.cpp index b728408bb40fcda1279f829295e011411675cc1c..6504649191592dbc041b47c573366229935bfafa 100644 --- a/interfaces/innerkits/fmskit/native/src/form_mgr.cpp +++ b/interfaces/innerkits/fmskit/native/src/form_mgr.cpp @@ -221,6 +221,21 @@ int FormMgr::DumpFormInfoByFormId(const std::int64_t formId, std::string &formIn return remoteProxy_->DumpFormInfoByFormId(formId, formInfo); } +/** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form timer. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgr::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) +{ + int errCode = Connect(); + if (errCode != ERR_OK) { + return errCode; + } + + return remoteProxy_->DumpFormTimerByFormId(formId, isTimingService); +} /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -239,9 +254,8 @@ int FormMgr::MessageEvent(const int64_t formId, const Want &want, const sptr &remoteObject); + + /** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns forms count to add. + */ + int BatchAddFormRecords(const Want &want); + /** + * @brief Clear form records for st limit value test. + * @return Returns forms count to delete. + */ + int ClearFormRecords(); private: /** * @brief Get form configure info. @@ -302,10 +321,11 @@ private: * @param record Form data. * @param formId The form id. * @param wantParams WantParams of the request. + * @param formInfo Form info for form host. * @return Returns ERR_OK on success, others on failure. */ ErrCode AddExistFormRecord(const FormItemInfo &info, const sptr &callerToken, - const FormRecord &record, const int64_t formId, const WantParams &wantParams); + const FormRecord &record, const int64_t formId, const WantParams &wantParams, FormJsInfo &formInfo); /** * @brief Add new form record. @@ -393,6 +413,37 @@ private: * @return Returns true on success, others on failure. */ bool GetBundleName(std::string &bundleName); + + /** + * @brief Update provider info to host + * + * @param matchedFormId The Id of the form + * @param callerToken Caller ability token. + * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. + * @param formRecord Form storage information + * @return Returns true on success, false on failure. + */ + bool UpdateProviderInfoToHost(const int64_t matchedFormId, const sptr &callerToken, + const int32_t formVisibleType, FormRecord &formRecord); + + /** + * @brief If the form provider is system app and the config item 'formVisibleNotify' is true, + * notify the form provider that the current form is visible. + * + * @param bundleName BundleName + * @return Returns true if the form provider is system app, false if not. + */ + bool CheckIsSystemAppByBundleName(const sptr &iBundleMgr, const std::string &bundleName); + /** + * @brief Create eventMaps for event notify. + * + * @param matchedFormId The Id of the form + * @param formRecord Form storage information + * @param eventMaps eventMaps for event notify + * @return Returns true on success, false on failure. + */ + bool CreateHandleEventMap(const int64_t matchedFormId, const FormRecord &formRecord, + std::map> &eventMaps); }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/include/form_mgr_service.h b/services/formmgr/include/form_mgr_service.h index ac10b21ae6a2a392f596c3e16d6dca6550335edc..c0cef5623d9044a58c6bb3e63cc09dbc795f09c3 100644 --- a/services/formmgr/include/form_mgr_service.h +++ b/services/formmgr/include/form_mgr_service.h @@ -26,6 +26,7 @@ #include "event_handler.h" #include "form_mgr_stub.h" #include "form_provider_data.h" +#include "form_sys_event_receiver.h" #include "iremote_object.h" namespace OHOS { @@ -153,7 +154,13 @@ public: * @return Returns ERR_OK on success, others on failure. */ int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override; - + /** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form info. + * @return Returns ERR_OK on success, others on failure. + */ + int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override; /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -163,6 +170,18 @@ public: */ int MessageEvent(const int64_t formId, const Want &want, const sptr &callerToken) override; + /** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns ERR_OK on success, others on failure. + */ + int BatchAddFormRecords(const Want &want) override; + /** + * @brief Clear form records for st limit value test. + * @return Returns ERR_OK on success, others on failure. + */ + int ClearFormRecords() override; + /** * @brief Check whether if the form manager service is ready. * @return Returns true if the form manager service is ready; returns false otherwise. @@ -193,7 +212,8 @@ private: std::shared_ptr runner_ = nullptr; std::shared_ptr handler_ = nullptr; - + std::shared_ptr formSysEventReceiver_ = nullptr; + bool resetFlag = false; mutable std::mutex instanceMutex_; diff --git a/services/formmgr/include/form_record.h b/services/formmgr/include/form_record.h index 2bc6bc1f64e6a2931ad32afe14e1a73ce2eef636..78a00aea70e8658ac59f93beb4dc5c612ce32164 100644 --- a/services/formmgr/include/form_record.h +++ b/services/formmgr/include/form_record.h @@ -50,6 +50,7 @@ public: std::vector formUserUids; bool formVisibleNotify = false; int formVisibleNotifyState = 0; + int userId = 0; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/include/form_timer_mgr.h b/services/formmgr/include/form_timer_mgr.h index 1ff69380079bdb562a21b9d0e7305aad3ef7901c..8668c09f4d9417a84ad620385931a40929d6152d 100644 --- a/services/formmgr/include/form_timer_mgr.h +++ b/services/formmgr/include/form_timer_mgr.h @@ -134,7 +134,24 @@ public: * @return Returns true on success, false on failure. */ bool OnDynamicTimeTrigger(long updateTime); - + /** + * @brief Get interval timer task. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ + bool GetIntervalTimer(const int64_t formId, FormTimer &formTimer); + /** + * @brief Get update at timer. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ + bool GetUpdateAtTimer(const int64_t formId, UpdateAtItem &updateAtItem); + /** + * @brief Get dynamic refresh item. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ + bool GetDynamicItem(const int64_t formId, DynamicRefreshItem &dynamicItem); private: /** * @brief Add update at timer. @@ -157,7 +174,6 @@ private: * @brief interval timer task timeout. */ void OnIntervalTimeOut(); - /** * @brief Get remind tasks. * @param remindTasks Remind tasks. @@ -312,7 +328,6 @@ private: std::map intervalTimerTasks_; std::list updateAtTimerTasks_; std::vector dynamicRefreshTasks_; - std::shared_ptr timerReceiver_ = nullptr; OHOS::ThreadPool* taskExecutor_ = nullptr; @@ -320,9 +335,6 @@ private: uint64_t updateAtTimerId_ = 0L; uint64_t dynamicAlarmTimerId_ = 0L; uint64_t limiterTimerId_= 0L; - - - }; } // namespace AppExecFwk diff --git a/services/formmgr/src/form_ams_helper.cpp b/services/formmgr/src/form_ams_helper.cpp index 7588442f149637b44f0a691b6096a44980cc19b6..f519ea91eae7a081515e53782fe9be6b8b09b760 100644 --- a/services/formmgr/src/form_ams_helper.cpp +++ b/services/formmgr/src/form_ams_helper.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace AppExecFwk { -const int FORM_DISCONNECT_DELAY_TIME = 100; // ms +const int FORM_DISCONNECT_DELAY_TIME = 5000; // ms FormAmsHelper::FormAmsHelper(){} FormAmsHelper::~FormAmsHelper(){} diff --git a/services/formmgr/src/form_data_mgr.cpp b/services/formmgr/src/form_data_mgr.cpp index 94b4e638b69dee256edce65ec772551d606876ab..5e6210a7b816e3201d90832e1c4112a3060efc06 100644 --- a/services/formmgr/src/form_data_mgr.cpp +++ b/services/formmgr/src/form_data_mgr.cpp @@ -1084,6 +1084,7 @@ void FormDataMgr::ParseIntervalConfig(FormRecord &record, const int configDurati } APP_LOGI("%{public}s end", __func__); } + /** * @brief Parse at time config. * @param record The form record. @@ -1131,5 +1132,20 @@ bool FormDataMgr::IsFormCached(const FormRecord record) } return FormCacheMgr::GetInstance().IsExist(record.formId); } + +/** + * @brief Clear form records for st limit value test. + */ +void FormDataMgr::ClearFormRecords() +{ + { + std::lock_guard lock(formRecordMutex_); + formRecords_.clear(); + } + { + std::lock_guard lock(formTempMutex_); + tempForms_.clear(); + } +} } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/src/form_mgr_adapter.cpp b/services/formmgr/src/form_mgr_adapter.cpp index db4a108f3ac7dd2fe67221dd0045b118eb9578e2..7a065d01b67eca51604355265756ee6840967f2c 100644 --- a/services/formmgr/src/form_mgr_adapter.cpp +++ b/services/formmgr/src/form_mgr_adapter.cpp @@ -219,8 +219,7 @@ ErrCode FormMgrAdapter::HandleDeleteForm(const int64_t formId, const sptr &fo } matchedFormId = FormDataMgr::GetInstance().FindMatchedFormId(formId); FormRecord formRecord; - if (!FormDataMgr::GetInstance().GetFormRecord(matchedFormId, formRecord)) { - APP_LOGW("%{public}s fail, not exist such form, formId:%{public}" PRId64 ".", __func__, matchedFormId); + // Update provider info to host + if (!UpdateProviderInfoToHost(matchedFormId, callerToken, formVisibleType, formRecord)) { continue; } - FormHostRecord formHostRecord; - bool hasFormHostRecord = FormDataMgr::GetInstance().GetMatchedHostClient(callerToken, formHostRecord); - if (!(hasFormHostRecord && formHostRecord.Contains(matchedFormId))) { - APP_LOGW("%{public}s fail, form is not belong to self, formId:%{public}" PRId64 ".", __func__, matchedFormId); + // Check if the form provider is system app + if (!CheckIsSystemAppByBundleName(iBundleMgr, formRecord.bundleName)) { continue; } - formRecord.formVisibleNotifyState = formVisibleType; - if (!FormDataMgr::GetInstance().UpdateFormRecord(matchedFormId, formRecord)) { - APP_LOGW("%{public}s fail, set formVisibleNotifyState error, formId:%{public}" PRId64 ".", - __func__, matchedFormId); + // Create eventMaps + if (!CreateHandleEventMap(matchedFormId, formRecord, eventMaps)) { continue; } - - // If the form need refrsh flag is true and form visibleType is FORM_VISIBLE, refresh the form host. - if (formRecord.needRefresh && formVisibleType == Constants::FORM_VISIBLE) { - std::string cacheData; - // If the form has business cache, refresh the form host. - if (FormCacheMgr::GetInstance().GetData(matchedFormId, cacheData)) { - formRecord.formProviderInfo.SetFormDataString(cacheData); - formHostRecord.OnUpdate(matchedFormId, formRecord); - } - } - - // If the form provider is system app and the config item 'formVisibleNotify' is true, - // notify the form provider that the current form is visible. - BundleInfo bundleInfo; - if (iBundleMgr->GetBundleInfo(formRecord.bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo)) { - APP_LOGD("%{public}s, get bundle uid success", __func__); - if (!iBundleMgr->CheckIsSystemAppByUid(bundleInfo.uid)) { - APP_LOGW("%{public}s fail, form provider is not system app, formId:%{public}" PRId64 ".", - __func__, matchedFormId); - continue; - } - } else { - APP_LOGW("%{public}s fail, can not get bundleInfo's uid", __func__); - continue; - } - if (!formRecord.formVisibleNotify) { - APP_LOGW("%{public}s fail, the config item 'formVisibleNotify' is false, formId:%{public}" PRId64 ".", - __func__, matchedFormId); - continue; - } - - std::string providerKey = formRecord.bundleName + Constants::NAME_DELIMITER + formRecord.abilityName; - auto iter = eventMaps.find(providerKey); - if (iter == eventMaps.end()) { - std::vector formEventsByProvider {matchedFormId}; - eventMaps.insert(std::make_pair(providerKey, formEventsByProvider)); - } else { - iter->second.emplace_back(matchedFormId); - } } for (auto iter = eventMaps.begin(); iter != eventMaps.end(); iter++) { @@ -568,7 +524,7 @@ int FormMgrAdapter::CastTempForm(const int64_t formId, const sptr } FormHostRecord record; - bool hasHostRec = FormDataMgr::GetInstance().GetFormHostRecord(matchedFormId, record); + bool hasHostRec = FormDataMgr::GetInstance().GetMatchedHostClient(callerToken, record); if (!hasHostRec || !record.Contains(matchedFormId)) { APP_LOGE("%{public}s, not self form:%{public}" PRId64 "", __func__, matchedFormId); return ERR_APPEXECFWK_FORM_OPERATION_NOT_SELF; @@ -701,6 +657,30 @@ int FormMgrAdapter::DumpFormInfoByFormId(const std::int64_t formId, std::string return reply; } +/** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form timer. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrAdapter::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) const +{ + APP_LOGI("%{public}s called.", __func__); + FormTimer formTimer; + UpdateAtItem updateAtItem; + DynamicRefreshItem dynamicItem; + bool result_inter = FormTimerMgr::GetInstance().GetIntervalTimer(formId, formTimer); + bool result_update = FormTimerMgr::GetInstance().GetUpdateAtTimer(formId, updateAtItem); + bool result_dynamic = FormTimerMgr::GetInstance().GetDynamicItem(formId, dynamicItem); + APP_LOGI("%{public}s result_inter:%{public}d,result_update:%{public}d,result_dynamic:%{public}d", + __func__, result_inter, result_update, result_dynamic); + if (result_inter || result_update || result_dynamic) { + isTimingService = "true"; + } else { + isTimingService = "false"; + } + return ERR_OK; +} /** * @brief Get form configure info. * @param want The want of the request. @@ -755,18 +735,20 @@ ErrCode FormMgrAdapter::AllotFormById(const FormItemInfo &info, return ERR_APPEXECFWK_FORM_COMMON_CODE; } - if (hasRecord && FormDataMgr::GetInstance().IsCallingUidValid(record.formUserUids)) { + if (hasRecord && (record.userId == DEFAULT_USER_ID + || FormDataMgr::GetInstance().IsCallingUidValid(record.formUserUids))) { if (!info.IsMatch(record)) { APP_LOGE("%{public}s, formId and item info not match:%{public}" PRId64 "", __func__, formId); return ERR_APPEXECFWK_FORM_CFG_NOT_MATCH_ID; } - return AddExistFormRecord(info, callerToken, record, formId, wantParams); + return AddExistFormRecord(info, callerToken, record, formId, wantParams, formInfo); } // find in db but not in cache FormRecord dbRecord; ErrCode getDbRet = FormDbCache::GetInstance().GetDBRecord(formId, dbRecord); - if (getDbRet == ERR_OK && FormDataMgr::GetInstance().IsCallingUidValid(dbRecord.formUserUids)) { + if (getDbRet == ERR_OK && (record.userId == DEFAULT_USER_ID + || FormDataMgr::GetInstance().IsCallingUidValid(dbRecord.formUserUids))) { return AddNewFormRecord(info, formId, callerToken, wantParams, formInfo); } @@ -794,7 +776,8 @@ int64_t FormMgrAdapter::PaddingUDIDHash(const int64_t formId) const return formId; } ErrCode FormMgrAdapter::AddExistFormRecord(const FormItemInfo &info, const sptr &callerToken, - const FormRecord &record, const int64_t formId, const WantParams &wantParams) + const FormRecord &record, const int64_t formId, const WantParams &wantParams, + FormJsInfo &formInfo) { APP_LOGI("%{public}s call, formId:%{public}" PRId64 "", __func__, formId); // allot form host record @@ -820,11 +803,18 @@ ErrCode FormMgrAdapter::AddExistFormRecord(const FormItemInfo &info, const sptr< // Add new form user uid. FormDataMgr::GetInstance().AddFormUserUid(formId, callingUid); - if (std::find(newRecord.formUserUids.begin(), newRecord.formUserUids.end(), callingUid) == + if (std::find(newRecord.formUserUids.begin(), newRecord.formUserUids.end(), callingUid) == newRecord.formUserUids.end()) { newRecord.formUserUids.emplace_back(callingUid); } + // create form info for js + std::string cacheData; + if (FormCacheMgr::GetInstance().GetData(formId, cacheData)) { + formInfo.formData = cacheData; + } + FormDataMgr::GetInstance().CreateFormInfo(formId, record, formInfo); + // start update timer if (ErrCode errorCode = AddFormTimer(newRecord); errorCode != ERR_OK) { return errorCode; @@ -1030,7 +1020,8 @@ ErrCode FormMgrAdapter::GetBundleInfo(const AAFwk::Want &want, BundleInfo &bundl } for (const auto &abilityInfo : bundleInfo.abilityInfos) { - if (abilityInfo.bundleName == bundleName && abilityInfo.moduleName == moduleName ) { + if (abilityInfo.bundleName == bundleName && abilityInfo.moduleName == moduleName + && abilityInfo.name == abilityName) { packageName = bundleName + moduleName; break; } @@ -1451,5 +1442,165 @@ void FormMgrAdapter::NotifyFormDelete(const int64_t formId, const Want &want, co APP_LOGE("%{public}s fail, Failed to get acquire provider form info", __func__); } } + +/** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns forms count to add. + */ +int FormMgrAdapter::BatchAddFormRecords(const Want &want) +{ + APP_LOGI("%{public}s called.", __func__); + ElementName elementName = want.GetElement(); + std::string bundleName = elementName.GetBundleName(); + std::string abilityName = elementName.GetAbilityName(); + int formCount = want.GetIntParam(Constants::PARAM_FORM_ADD_COUNT, 0); + APP_LOGI("%{public}s, batch add form, bundleName: %{public}s, abilityName: %{public}s, count: %{public}d.", + __func__, + bundleName.c_str(), + abilityName.c_str(), + formCount); + + for (int count = 0; count < formCount; count++) { + // get from comfig info + FormItemInfo formItemInfo; + int32_t errCode = GetFormConfigInfo(want, formItemInfo); + if (errCode != ERR_OK) { + APP_LOGE("%{public}s fail, get form config info failed.", __func__); + return errCode; + } + if (!formItemInfo.IsValidItem()) { + APP_LOGE("%{public}s fail, input param itemInfo is invalid", __func__); + return ERR_APPEXECFWK_FORM_GET_INFO_FAILED; + } + if (!FormDataMgr::GetInstance().GenerateUdidHash()) { + APP_LOGE("%{public}s fail, generate udid hash failed", __func__); + return ERR_APPEXECFWK_FORM_COMMON_CODE; + } + + // generate formId + int64_t newFormId = FormDataMgr::GetInstance().GenerateFormId(); + if (newFormId < 0) { + APP_LOGE("%{public}s fail, generateFormId no invalid formId", __func__); + return ERR_APPEXECFWK_FORM_COMMON_CODE; + } + + formItemInfo.SetFormId(newFormId); + // allot form host record + int callingUid = IPCSkeleton::GetCallingUid(); + // allot form record + FormRecord formRecord = FormDataMgr::GetInstance().AllotFormRecord(formItemInfo, callingUid); + APP_LOGI("%{public}s, batch add form, formId:" "%{public}" PRId64 ".", __func__, formRecord.formId); + + APP_LOGI("%{public}s, count: %{public}d", __func__, count + 1); + } + APP_LOGI("%{public}s end.", __func__); + return ERR_OK; +} +/** + * @brief Clear form records for st limit value test. + * @return Returns forms count to delete. + */ +int FormMgrAdapter::ClearFormRecords() +{ + APP_LOGI("%{public}s called.", __func__); + FormDataMgr::GetInstance().ClearFormRecords(); + APP_LOGI("%{public}s end.", __func__); + return ERR_OK; +} +/** + * @brief Create eventMaps for event notify. + * + * @param matchedFormId The Id of the form + * @param formRecord Form storage information + * @param eventMaps eventMaps for event notify + * @return Returns true on success, false on failure. + */ +bool FormMgrAdapter::CreateHandleEventMap(const int64_t matchedFormId, const FormRecord &formRecord, + std::map> &eventMaps) +{ + if (!formRecord.formVisibleNotify) { + APP_LOGW("%{public}s fail, the config item 'formVisibleNotify' is false, formId:%{public}" PRId64 ".", + __func__, matchedFormId); + return false; + } + + std::string providerKey = formRecord.bundleName + Constants::NAME_DELIMITER + formRecord.abilityName; + auto iter = eventMaps.find(providerKey); + if (iter == eventMaps.end()) { + std::vector formEventsByProvider {matchedFormId}; + eventMaps.insert(std::make_pair(providerKey, formEventsByProvider)); + } else { + iter->second.emplace_back(matchedFormId); + } + return true; +} +/** + * @brief Update provider info to host + * + * @param matchedFormId The Id of the form + * @param callerToken Caller ability token. + * @param formVisibleType The form visible type, including FORM_VISIBLE and FORM_INVISIBLE. + * @param formRecord Form storage information + * @return Returns true on success, false on failure. + */ +bool FormMgrAdapter::UpdateProviderInfoToHost(const int64_t matchedFormId, const sptr &callerToken, + const int32_t formVisibleType, FormRecord &formRecord) +{ + if (!FormDataMgr::GetInstance().GetFormRecord(matchedFormId, formRecord)) { + APP_LOGW("%{public}s fail, not exist such form, formId:%{public}" PRId64 ".", __func__, matchedFormId); + return false; + } + + FormHostRecord formHostRecord; + bool hasFormHostRecord = FormDataMgr::GetInstance().GetMatchedHostClient(callerToken, formHostRecord); + if (!(hasFormHostRecord && formHostRecord.Contains(matchedFormId))) { + APP_LOGW("%{public}s fail, form is not belong to self, formId:%{public}" PRId64 ".", __func__, matchedFormId); + return false; + } + + formRecord.formVisibleNotifyState = formVisibleType; + if (!FormDataMgr::GetInstance().UpdateFormRecord(matchedFormId, formRecord)) { + APP_LOGW("%{public}s fail, set formVisibleNotifyState error, formId:%{public}" PRId64 ".", + __func__, matchedFormId); + return false; + } + + // If the form need refrsh flag is true and form visibleType is FORM_VISIBLE, refresh the form host. + if (formRecord.needRefresh && formVisibleType == Constants::FORM_VISIBLE) { + std::string cacheData; + // If the form has business cache, refresh the form host. + if (FormCacheMgr::GetInstance().GetData(matchedFormId, cacheData)) { + formRecord.formProviderInfo.SetFormDataString(cacheData); + formHostRecord.OnUpdate(matchedFormId, formRecord); + } + } + return true; +} +/** + * @brief If the form provider is system app and the config item 'formVisibleNotify' is true, + * notify the form provider that the current form is visible. + * + * @param bundleName BundleName + * @return Returns true if the form provider is system app, false if not. + */ +bool FormMgrAdapter::CheckIsSystemAppByBundleName(const sptr &iBundleMgr, const std::string &bundleName) +{ + BundleInfo bundleInfo; + if (iBundleMgr->GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo)) { + APP_LOGD("%{public}s, get bundle uid success", __func__); + if (!iBundleMgr->CheckIsSystemAppByUid(bundleInfo.uid)) { + APP_LOGW("%{public}s fail, form provider is not system app, bundleName: %{public}s", + __func__, bundleName.c_str()); + return false; + } + } else { + APP_LOGW("%{public}s fail, can not get bundleInfo's uid", __func__); + return false; + } + + return true; +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/services/formmgr/src/form_mgr_service.cpp b/services/formmgr/src/form_mgr_service.cpp index 8f25249579aa31e8c31de74365c615b143db74da..948c33d0d8b810c1408f5ee7cb5e518200e9d614 100644 --- a/services/formmgr/src/form_mgr_service.cpp +++ b/services/formmgr/src/form_mgr_service.cpp @@ -19,6 +19,8 @@ #include "appexecfwk_errors.h" #include "app_log_wrapper.h" +#include "common_event_manager.h" +#include "common_event_support.h" #include "form_ams_helper.h" #include "form_bms_helper.h" #include "form_constants.h" @@ -55,7 +57,10 @@ FormMgrService::FormMgrService() } FormMgrService::~FormMgrService() -{} +{ + EventFwk::CommonEventManager::UnSubscribeCommonEvent(formSysEventReceiver_); + formSysEventReceiver_ = nullptr; +} bool FormMgrService::IsReady() const { @@ -258,6 +263,16 @@ int FormMgrService::DumpFormInfoByFormId(const std::int64_t formId, std::string { return FormMgrAdapter::GetInstance().DumpFormInfoByFormId(formId, formInfo); } +/** + * @brief Dump form timer by form id. + * @param formId The id of the form. + * @param formInfo Form info. + * @return Returns ERR_OK on success, others on failure. + */ +int FormMgrService::DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) +{ + return FormMgrAdapter::GetInstance().DumpFormTimerByFormId(formId, isTimingService); +} /** * @brief Process js message event. * @param formId Indicates the unique id of form. @@ -276,6 +291,24 @@ int FormMgrService::MessageEvent(const int64_t formId, const Want &want, const s return FormMgrAdapter::GetInstance().MessageEvent(formId, want, callerToken); } + +/** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns forms count to add. + */ +int FormMgrService::BatchAddFormRecords(const Want &want) +{ + return FormMgrAdapter::GetInstance().BatchAddFormRecords(want); +} +/** + * @brief Clear form records for st limit value test. + * @return Returns forms count to delete. + */ +int FormMgrService::ClearFormRecords() +{ + return FormMgrAdapter::GetInstance().ClearFormRecords(); +} /** * @brief Start envent for the form manager service. */ @@ -339,6 +372,17 @@ ErrCode FormMgrService::Init() return ERR_INVALID_OPERATION; } + if (formSysEventReceiver_ == nullptr) { + EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED); + matchingSkills.AddEvent(EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_DATA_CLEARED); + + // init TimerReceiver + EventFwk::CommonEventSubscribeInfo subscribeInfo(matchingSkills); + formSysEventReceiver_ = std::make_shared(subscribeInfo); + EventFwk::CommonEventManager::SubscribeCommonEvent(formSysEventReceiver_); + } FormDbCache::GetInstance().Start(); APP_LOGI("init success"); @@ -351,7 +395,26 @@ ErrCode FormMgrService::Init() */ bool FormMgrService::CheckFormPermission() { - return true; + sptr iBundleMgr = FormBmsHelper::GetInstance().GetBundleMgr(); + if (iBundleMgr == nullptr) { + APP_LOGE("%{public}s, failed to get IBundleMgr.", __func__); + return false; + } + + int32_t uid = IPCSkeleton::GetCallingUid(); + if (!iBundleMgr->CheckIsSystemAppByUid(uid)) { + APP_LOGE("%{public}s fail, form is not system app. uid:%{public}d", __func__, uid); + return false; + } + + std::string bundleName; + bool result = iBundleMgr->GetBundleNameForUid(uid, bundleName); + if (!result || bundleName.empty()) { + APP_LOGE("%{public}s failed, cannot get bundle name by uid:%{public}d", __func__, uid); + return false; + } + + return CheckFormPermission(bundleName); } bool FormMgrService::CheckFormPermission(const std::string &bundleName) const diff --git a/services/formmgr/src/form_refresh_limiter.cpp b/services/formmgr/src/form_refresh_limiter.cpp index b0c814350119063a76fae588206a1c44fc4b5cff..4b5fb292853ac9a24663cabd7b90bc3b88e2f104 100644 --- a/services/formmgr/src/form_refresh_limiter.cpp +++ b/services/formmgr/src/form_refresh_limiter.cpp @@ -26,14 +26,14 @@ namespace AppExecFwk { * @param formId The id of the form. * @return Returns true on success, false on failure. */ -bool FormRefreshLimiter::AddItem(const int64_t formId) +bool FormRefreshLimiter::AddItem(const int64_t formId) { APP_LOGI("%{public}s start", __func__); std::lock_guard lock(limiterMutex_); auto info = limiterMap_.find(formId); if (info == limiterMap_.end()) { LimitInfo limitInfo; - std::pair::iterator, bool> retVal = + std::pair::iterator, bool> retVal = limiterMap_.emplace(formId, limitInfo); APP_LOGI("%{public}s end", __func__); return retVal.second; @@ -46,7 +46,7 @@ bool FormRefreshLimiter::AddItem(const int64_t formId) * @brief Delete form limit info by formId. * @param formId The form id. */ -void FormRefreshLimiter::DeleteItem(const int64_t formId) +void FormRefreshLimiter::DeleteItem(const int64_t formId) { APP_LOGI("%{public}s start", __func__); std::lock_guard lock(limiterMutex_); @@ -121,7 +121,7 @@ void FormRefreshLimiter::Increase(const int64_t formId) APP_LOGI("%{public}s start", __func__); std::lock_guard lock(limiterMutex_); auto info = limiterMap_.find(formId); - if (info != limiterMap_.end()) { + if (info != limiterMap_.end()) { info->second.refreshCount++; APP_LOGI("increase,formId:%{public}" PRId64 ", count:%{public}d", formId, info->second.refreshCount); if (info->second.refreshCount == Constants::LIMIT_COUNT && !info->second.isReported) { @@ -140,7 +140,7 @@ void FormRefreshLimiter::MarkRemind(const int64_t formId) APP_LOGI("%{public}s start", __func__); std::lock_guard lock(limiterMutex_); auto info = limiterMap_.find(formId); - if (info != limiterMap_.end()) { + if (info != limiterMap_.end()) { if (info->second.refreshCount >= Constants::LIMIT_COUNT) { info->second.remindFlag = true; } diff --git a/services/formmgr/src/form_sys_event_receiver.cpp b/services/formmgr/src/form_sys_event_receiver.cpp index 3279d6019effd8ebb6a9f877fb781b521c27a547..0311b315356caa5c19cfcdfe19bc1baa1bc2dd92 100644 --- a/services/formmgr/src/form_sys_event_receiver.cpp +++ b/services/formmgr/src/form_sys_event_receiver.cpp @@ -35,7 +35,6 @@ namespace OHOS { namespace AppExecFwk { const std::string KEY_UID = "uid"; -const std::string KEY_BUNDLE_NAME = "bundleName"; /** * @brief Receiver Constructor. * @param subscriberInfo Subscriber info. @@ -51,14 +50,14 @@ void FormSysEventReceiver::OnReceiveEvent(const EventFwk::CommonEventData &event { AAFwk::Want want = eventData.GetWant(); std::string action = want.GetAction(); - std::string bundleName = want.GetStringParam(KEY_BUNDLE_NAME); + std::string bundleName = want.GetElement().GetBundleName(); if (action.empty() || bundleName.empty()) { APP_LOGE("%{public}s failed, invalid param, action: %{public}s, bundleName: %{public}s", __func__, action.c_str(), bundleName.c_str()); return; } APP_LOGI("%{public}s, action:%{public}s.", __func__, action.c_str()); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_ABILITY_REMOVED) { + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { APP_LOGI("%{public}s, bundle removed, bundleName: %{public}s", __func__, bundleName.c_str()); HandleProviderRemoved(bundleName); } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_ABILITY_UPDATED) { diff --git a/services/formmgr/src/form_timer_mgr.cpp b/services/formmgr/src/form_timer_mgr.cpp index 886cef74cc4f0a5dc65a47ca46c3e5052316a599..73b4380a60b8e8a54e47c0f3e1a74d3ab4b54bd5 100644 --- a/services/formmgr/src/form_timer_mgr.cpp +++ b/services/formmgr/src/form_timer_mgr.cpp @@ -616,6 +616,68 @@ void FormTimerMgr::SetIntervalEnableFlag(int64_t formId, bool flag) return; } } +/** + * @brief Get interval timer task. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ +bool FormTimerMgr::GetIntervalTimer(const int64_t formId, FormTimer &formTimer) +{ + APP_LOGI("%{public}s start", __func__); + std::lock_guard lock(intervalMutex_); + auto intervalTask = intervalTimerTasks_.find(formId); + if (intervalTask == intervalTimerTasks_.end()) { + APP_LOGI("%{public}s, interval timer not find", __func__); + return false; + } + formTimer = intervalTask->second; + APP_LOGI("%{public}s, get interval timer successfully", __func__); + return true; +} +/** + * @brief Get update at timer. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ +bool FormTimerMgr::GetUpdateAtTimer(const int64_t formId, UpdateAtItem &updateAtItem) +{ + APP_LOGI("%{public}s start", __func__); + { + std::lock_guard lock(updateAtMutex_); + std::list::iterator itItem; + for (itItem = updateAtTimerTasks_.begin(); itItem != updateAtTimerTasks_.end(); itItem++) { + if (itItem->refreshTask.formId == formId) { + updateAtItem.refreshTask = itItem->refreshTask; + updateAtItem.updateAtTime = itItem->updateAtTime; + APP_LOGI("%{public}s, get update at timer successfully", __func__); + return true; + } + } + } + APP_LOGI("%{public}s, update at timer not find", __func__); + return false; +} +/** + * @brief Get dynamic refresh item. + * @param formId The Id of the form. + * @return Returns true on success, false on failure. + */ +bool FormTimerMgr::GetDynamicItem(const int64_t formId, DynamicRefreshItem &dynamicItem) +{ + APP_LOGI("%{public}s start", __func__); + std::lock_guard lock(dynamicMutex_); + std::vector::iterator itItem; + for (itItem = dynamicRefreshTasks_.begin(); itItem != dynamicRefreshTasks_.end();) { + if (itItem->formId == formId) { + dynamicItem.formId = itItem->formId; + dynamicItem.settedTime = itItem->settedTime; + APP_LOGI("%{public}s, get dynamic item successfully", __func__); + return true; + } + } + APP_LOGI("%{public}s, dynamic item not find", __func__); + return false; +} /** * @brief Delete interval timer task. * @param formId The Id of the form. @@ -731,7 +793,7 @@ bool FormTimerMgr::UpdateAtTimerAlarm() /** * @brief Clear update at timer resource. - */ + */ void FormTimerMgr::ClearUpdateAtTimerResource() { APP_LOGI("%{public}s start", __func__); diff --git a/services/formmgr/test/mock/include/mock_bundle_manager.h b/services/formmgr/test/mock/include/mock_bundle_manager.h index 5a3ec17f10924d8bff5648c05244d6d8e29e46c3..e64a1dbfc27bf01dcff884abd353ad9f0f38c290 100644 --- a/services/formmgr/test/mock/include/mock_bundle_manager.h +++ b/services/formmgr/test/mock/include/mock_bundle_manager.h @@ -195,67 +195,7 @@ public: virtual bool GetShortcutInfos(const std::string &bundleName,std::vector &shortcut) override{ return true; } - // /** - // * @brief Starts a shortcut based on the given shortcut ID and bundle name. - // * @param bundleName BundleName Indicates the bundle name of the application to which the shortcut belongs. - // * @param shortcutId Starts a shortcut based on the given shortcut ID and bundle name. - // * @return Returns true if StartShortcut get success - // */ - // virtual bool StartShortcut(const std::string &shortcutId, const std::string &bundleName) override{ - // return true; - // } - /** - * @brief Disables specified home-screen shortcuts that are no longer used. - * @param shortcutIds Indicates the list of shortcut IDs to be disabled. - * @return Returns true if disableHomeShortcuts get success - */ - // virtual bool DisableHomeShortcuts(std::vector &shortcutIds) override{ - // return true; - // } - // /** - // * @brief Enables specified home-screen shortcuts. - // * @param shortcutIds Indicates the list of shortcut IDs to be enabled. - // * @return Returns true if enableHomeShortcuts? get success - // */ - // virtual bool EnableHomeShortcuts(std::vector &shortcutIds) override{ - // return true; - // } - // /** - // * @brief Checks whether a shortcut can be added to the home screen where the application is located. - // * @return Returns true if a shortcut can be added to the home screen; returns false otherwise. - // */ - // virtual bool IsHomeShortcutSupportes() override{ - // return true; - // } - // /** - // * @brief Adds a home-screen shortcut that will be fixed on the home screen. - // * @param shortcutInfo Indicates the ShortcutInfo object containing information about the home-screen - // * shortcut to add. The id, label, and intent attributes of this parameter must be specified. - // * @return Returns true if the shortcut is successfully added; returns false otherwise. - // */ - // virtual bool AddHomeShortcut(ShortcutInfo &shortcutInfo) override{ - // return true; - // } - // /** - // * @brief Updates information about specified home-screen shortcuts that have been added. - // * @param shortcutInfos Updates information about specified home-screen shortcuts that have been added. - // * @return Returns true if the operation is successful; returns false otherwise. - // */ - // virtual bool UpdateShortcuts(std::vector &shortcutInfos) override{ - // return true; - // } - // /** - // * @brief Checks whether a specified shortcut is available. - // * @param shortcutId Indicates the ID of the shortcut to check. - // * @param flag Indicates the type of the shortcut to check. Currently, only the home-screen shortcut - // * IBundleManager#QUERY_SHORTCUT_HOME is available. - // * @return Returns IBundleManager#SHORTCUT_EXISTENCE_EXISTS if the specified shortcut is available; returns - // * IBundleManager#SHORTCUT_EXISTENCE_NOT_EXISTS if it is not available; - // * returns IBundleManager.SHORTCUT_EXISTENCE_UNKNOW if an error occurs. - // */ - // virtual int IsShortcutExist(const std::string &shortcutId, const int &flag) override{ - // return 0; - // } + /** * @brief Obtain the HAP module info of a specific ability. * @param abilityInfo Indicates the ability. @@ -451,67 +391,6 @@ public: virtual bool GetShortcutInfos(const std::string &bundleName,std::vector &shortcut) override{ return true; } - // /** - // * @brief Starts a shortcut based on the given shortcut ID and bundle name. - // * @param bundleName BundleName Indicates the bundle name of the application to which the shortcut belongs. - // * @param shortcutId Starts a shortcut based on the given shortcut ID and bundle name. - // * @return Returns true if StartShortcut get success - // */ - // virtual bool StartShortcut(const std::string &shortcutId, const std::string &bundleName) override{ - // return true; - // } - // /** - // * @brief Disables specified home-screen shortcuts that are no longer used. - // * @param shortcutIds Indicates the list of shortcut IDs to be disabled. - // * @return Returns true if disableHomeShortcuts get success - // */ - // virtual bool DisableHomeShortcuts(std::vector &shortcutIds) override{ - // return true; - // } - // /** - // * @brief Enables specified home-screen shortcuts. - // * @param shortcutIds Indicates the list of shortcut IDs to be enabled. - // * @return Returns true if enableHomeShortcuts? get success - // */ - // virtual bool EnableHomeShortcuts(std::vector &shortcutIds) override{ - // return true; - // } - /** - * @brief Checks whether a shortcut can be added to the home screen where the application is located. - * @return Returns true if a shortcut can be added to the home screen; returns false otherwise. - */ - // virtual bool IsHomeShortcutSupportes() override{ - // return true; - // } - // /** - // * @brief Adds a home-screen shortcut that will be fixed on the home screen. - // * @param shortcutInfo Indicates the ShortcutInfo object containing information about the home-screen shortcut - // * to add. The id, label, and intent attributes of this parameter must be specified. - // * @return Returns true if the shortcut is successfully added; returns false otherwise. - // */ - // virtual bool AddHomeShortcut(ShortcutInfo &shortcutInfo) override{ - // return true; - // } - // /** - // * @brief Updates information about specified home-screen shortcuts that have been added. - // * @param shortcutInfos Updates information about specified home-screen shortcuts that have been added. - // * @return Returns true if the operation is successful; returns false otherwise. - // */ - // virtual bool UpdateShortcuts(std::vector &shortcutInfos) override{ - // return true; - // } - // /** - // * @brief Checks whether a specified shortcut is available. - // * @param shortcutId Indicates the ID of the shortcut to check. - // * @param flag Indicates the type of the shortcut to check. Currently, only the home-screen shortcut - // * IBundleManager#QUERY_SHORTCUT_HOME is available. - // * @return Returns IBundleManager#SHORTCUT_EXISTENCE_EXISTS if the specified shortcut is available; returns - // * IBundleManager#SHORTCUT_EXISTENCE_NOT_EXISTS if it is not available; returns - // * IBundleManager.SHORTCUT_EXISTENCE_UNKNOW if an error occurs. - // */ - // virtual int IsShortcutExist(const std::string &shortcutId, const int &flag) override{ - // return 0; - // } virtual bool GetAllFormsInfo(std::vector &formInfo) override; virtual bool GetFormsInfoByApp(const std::string &bundleName, std::vector &formInfo) override; diff --git a/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/BUILD.gn index 3ea0a927c2a0ba6914c8f62602cacbf04e05004e..d6023948b196ce48f0bb78219569ba5848e25dfc 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_mgr_lifecycle_update_test/BUILD.gn @@ -74,6 +74,7 @@ ohos_unittest("FmsFormMgrLifecycleUpdateTest") { ] external_deps = [ + "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] diff --git a/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/BUILD.gn index f35b3b3e96868aafd6601ebfcf1f75e7c236e25d..a0ae851003daac710e75709ecad9b25f35ad91d9 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_mgr_notify_invisible_forms_test/BUILD.gn @@ -74,6 +74,7 @@ ohos_unittest("FmsFormMgrNotifyInvisibleFormsTest") { ] external_deps = [ + "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] diff --git a/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/BUILD.gn b/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/BUILD.gn index 82f7bb282004eaa3a193daf38e66f8edf8725efc..59395c434faba73074fb9141a552d747a414db77 100644 --- a/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/BUILD.gn +++ b/services/formmgr/test/unittest/fms_form_mgr_notify_visible_forms_test/BUILD.gn @@ -74,6 +74,7 @@ ohos_unittest("FmsFormMgrNotifyVisibleFormsTest") { ] external_deps = [ + "ces_standard:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonA-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonA-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..7366fbf7c2e442eb9a0e69c5f98fe1d2753df135 Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonA-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonB-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonB-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..dec57d49f67a8acce1f7b1b340e28c3b14a15238 Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostCommonB-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNoPerm-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNoPerm-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..af2b3aa0076b116cc8a6bddf80a8229f40cb69ba Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNoPerm-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormal-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormal-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..d33264218d22cfe8adead95fb17f7d1a179b9ab3 Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormal-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalB-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalB-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..1aae96bdca4b315127cd11b7783f7cfdac667fe5 Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalB-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalC-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalC-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..dd698b11e995049eb75251121ab1625dea566cd1 Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNormalC-signed.hap differ diff --git a/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNotSys-signed.hap b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNotSys-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..66631e8bdda3a03806b481fbde8aef285702125a Binary files /dev/null and b/test/resource/fms/fms_host_ability_bundle/native/fmsSystemTestHostNotSys-signed.hap differ diff --git a/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceA-signed.hap b/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceA-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..a3844af47d7af173bdff35ae5283fb3bc758cd7e Binary files /dev/null and b/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceA-signed.hap differ diff --git a/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceB-signed.hap b/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceB-signed.hap new file mode 100644 index 0000000000000000000000000000000000000000..9ed696779567fcb639fc0e074142788840dd5840 Binary files /dev/null and b/test/resource/fms/fms_provider_ability_bundle/native/formSystemTestServiceB-signed.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..6400fd7419717874242452134fc5ed217a33a1ea 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..a28de7950d6edcd31877260c6560179b6d40e1ff 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..0105b328bb2e18a4e1a8b2eafbfdeab09b3990bd 100644 --- a/test/resource/formsystemtestability/BUILD.gn +++ b/test/resource/formsystemtestability/BUILD.gn @@ -12,5 +12,20 @@ # limitations under the License. group("fms_system_test_app") { - deps = [ "formSystemTestServiceA:formSystemTestServiceA" ] + deps = [ + "fmsSystemTestHostCommonA:fmsSystemTestHostCommonA", + "fmsSystemTestHostCommonB:fmsSystemTestHostCommonB", + "fmsSystemTestHostNoPerm:fmsSystemTestHostNoPerm", + "fmsSystemTestHostNormal:fmsSystemTestHostNormal", + "fmsSystemTestHostNormalB:fmsSystemTestHostNormalB", + "fmsSystemTestHostNormalC:fmsSystemTestHostNormalC", + "fmsSystemTestHostNotSys:fmsSystemTestHostNotSys", + "fmsSystemTestSelfStarting/selfStartingTestHostA:selfStartingTestHostA", + "fmsSystemTestSelfStarting/selfStartingTestHostB:selfStartingTestHostB", + "formSystemTestServiceA:formSystemTestServiceA", + "formSystemTestServiceB:formSystemTestServiceB", + "formSystemTestServiceC:formSystemTestServiceC", + "formSystemTestServiceD:formSystemTestServiceD", + "formSystemTestServiceE:formSystemTestServiceE", + ] } diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d68dd6133bc1d736966a79a63fa48e265256579e --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/BUILD.gn @@ -0,0 +1,80 @@ +# 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", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostCommonA") { + 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", + "../tool/src/form_test_utils.cpp", + "src/form_ability_commona.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ + ":fmsSystemTestHostCommonAConfig", + "${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", + "${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 = [ + "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", + ] + 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..89ae25797a8519d67509d0860d9832ea2a9a887b --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/include/form_ability_commona.h @@ -0,0 +1,78 @@ +/* + * 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 FMS_deleteForm(std::string data); + void FMS_acquireForm_batch(std::string data); + void FMS_deleteFormBatch(std::string data); + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback() + { + } + 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; + }; +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::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..401b391d0da4f05d8a717ec874ef315ad4e29403 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonA/src/form_ability_commona.cpp @@ -0,0 +1,219 @@ +/* + * 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" +#include "system_test_form_util.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_ONE_NORMAL_FORM, + FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, + FORM_EVENT_REQ_CLEAR_FORM_BATCH +}; +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(); + // 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); + 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, ""); + } +} +void FormAbilityCommonA::FMS_deleteForm(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, "false"); + } +} +void FormAbilityCommonA::FMS_acquireForm_batch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} +void FormAbilityCommonA::FMS_deleteFormBatch(std::string strFormId) +{ + APP_LOGI("%{public}s called", __func__); + int result = STtools::SystemTestFormUtil::ClearFormRecords(); + if (result == ERR_OK) { + APP_LOGI("Clear form records end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "true"); + } else { + APP_LOGE("Clear form records error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); + } +} +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; + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL] = &FormAbilityCommonA::FMS_deleteForm; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityCommonA::FMS_acquireForm_batch; + memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityCommonA::FMS_deleteFormBatch; + SubscribeEvent(); +} + +void FormAbilityCommonA::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 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()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + if (eventName == FORM_EVENT_REQ_ONE_NORMAL_FORM && data.GetCode() == EVENT_CODE_100) { + return; + } + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +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/fmsSystemTestHostCommonB/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2d93b79c14a583942493e3a70f37e9f84e2dcd10 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/BUILD.gn @@ -0,0 +1,80 @@ +# 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("fmsSystemTestHostCommonBConfig") { + 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", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostCommonB") { + 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", + "../tool/src/form_test_utils.cpp", + "src/form_ability_commonb.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ + ":fmsSystemTestHostCommonBConfig", + "${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", + "${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 = [ + "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", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonB/config.json b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/config.json new file mode 100644 index 0000000000000000000000000000000000000000..052634ce88b35d009ce76b28ee08b91fddeebb44 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.commonb", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.commonb.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbility", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityCommonB", + "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/fmsSystemTestHostCommonB/include/form_ability_commonb.h b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/include/form_ability_commonb.h new file mode 100644 index 0000000000000000000000000000000000000000..fcce3fb32c2b08b5b713291d9a74e970b629386d --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/include/form_ability_commonb.h @@ -0,0 +1,78 @@ +/* + * 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_COMMONB_H_ +#define _FORM_ABILITY_COMMONB_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriberForCommonB; +class FormAbilityCommonB : public Ability { +public: + ~FormAbilityCommonB(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + void FMS_acquireForm(std::string data); + void FMS_deleteForm(std::string data); + void FMS_acquireForm_batch(std::string data); + void FMS_deleteFormBatch(std::string data); + std::shared_ptr subscriber_; + + class AcquireFormCallback : public FormCallback { + public: + AcquireFormCallback() + { + } + 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; + }; +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 (FormAbilityCommonB::*)(std::string data); + std::map memberFuncMap_; + std::shared_ptr callback_; +}; + +class FormEventSubscriberForCommonB : public EventFwk::CommonEventSubscriber { +public: + FormEventSubscriberForCommonB(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) + { + ability_ = nullptr; + } + ~FormEventSubscriberForCommonB() + { + ability_ = nullptr; + } + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + void KitTerminateAbility(); + + FormAbilityCommonB *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_COMMONB_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8add0eef427b284519aad229b43a92f5a42df13 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostCommonB/src/form_ability_commonb.cpp @@ -0,0 +1,216 @@ +/* + * 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_commonb.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" +#include "system_test_form_util.h" + +namespace { +using namespace OHOS::AAFwk; +using namespace OHOS::EventFwk; +} + +namespace OHOS { +namespace AppExecFwk { +std::vector eventList = { + FORM_EVENT_REQ_ONE_NORMAL_FORM_B, + FORM_EVENT_REQ_ONE_NORMAL_FORM_B_DEL, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, + FORM_EVENT_REQ_CLEAR_FORM_BATCH +}; +void FormAbilityCommonB::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 FormAbilityCommonB::AcquireFormCallback::OnUpdate(const int32_t result, const FormJsInfo &formJsInfo) const +{ + APP_LOGI("%{public}s called", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B, EVENT_CODE_100, std::to_string(formJsInfo.formId)); +} + +void FormAbilityCommonB::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} + +// Create one form(temp/normal) +void FormAbilityCommonB::FMS_acquireForm(std::string data) +{ + APP_LOGI("%{public}s called, data: %{public}s", __func__, data.c_str()); + std::shared_ptr callback = std::make_shared(); + // 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); + 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_commonB]AcquireForm end"); + } else { + APP_LOGE("[form_ability_commonB]AcquireForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B, EVENT_CODE_100, ""); + } +} +void FormAbilityCommonB::FMS_acquireForm_batch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} +void FormAbilityCommonB::FMS_deleteFormBatch(std::string strFormId) +{ + APP_LOGI("%{public}s called", __func__); + int result = STtools::SystemTestFormUtil::ClearFormRecords(); + if (result == ERR_OK) { + APP_LOGI("Clear form records end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "true"); + } else { + APP_LOGE("Clear form records error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); + } +} +void FormAbilityCommonB::FMS_deleteForm(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, EVENT_CODE_101, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, EVENT_CODE_101, "false"); + } +} +FormAbilityCommonB::~FormAbilityCommonB() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilityCommonB::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityCommonB::onStart"); + Ability::OnStart(want); +} +void FormAbilityCommonB::OnActive() +{ + APP_LOGI("FormAbilityCommonB::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityCommonB::OnStop() +{ + APP_LOGI("FormAbilityCommonB::OnStop"); + + Ability::OnStop(); +} +void FormAbilityCommonB::OnInactive() +{ + APP_LOGI("FormAbilityCommonB::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityCommonB::OnBackground() +{ + APP_LOGI("FormAbilityCommonB::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityCommonB::SubscribeEvent() +{ + APP_LOGI("FormAbilityCommonB::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 FormAbilityCommonB::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityCommonB::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_B] = &FormAbilityCommonB::FMS_acquireForm; + memberFuncMap_[FORM_EVENT_REQ_ONE_NORMAL_FORM_B_DEL] = &FormAbilityCommonB::FMS_deleteForm; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityCommonB::FMS_acquireForm_batch; + memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityCommonB::FMS_deleteFormBatch; + SubscribeEvent(); +} + +void FormAbilityCommonB::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 FormEventSubscriberForCommonB::OnReceiveEvent(const CommonEventData &data) +{ + APP_LOGI("FormEventSubscriberForCommonB::OnReceiveEvent:event=%{public}s", data.GetWant().GetAction().c_str()); + APP_LOGI("KitTestEventSubscriber::OnReceiveEvent:data=%{public}s", data.GetData().c_str()); + APP_LOGI("FormEventSubscriberForCommonB::OnReceiveEvent:code=%{public}d", data.GetCode()); + auto eventName = data.GetWant().GetAction(); + ability_->handleEvent(eventName, data.GetData()); + CommonEventManager::UnSubscribeCommonEvent(ability_->subscriber_); +} + +void FormEventSubscriberForCommonB::KitTerminateAbility() +{ + if (ability_ != nullptr) { + ability_->TerminateAbility(); + } +} + +REGISTER_AA(FormAbilityCommonB) +} // 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..97f7b4d47527d3b4c88b33aaa794542a90576914 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/BUILD.gn @@ -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. +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", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNormal") { + 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", + "../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", + "${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", + "${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 = [ + "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", + ] + 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..bb63b78c256d89c587711c50deb4851853b93fab --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_a.h @@ -0,0 +1,119 @@ +/* + * 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_2900_1(std::string data); + void FMS_acquireForm_3000(std::string data); + void FMS_acquireForm_3100(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); + void FMS_acquireFormBatch(std::string data); + void FMS_acquireFormBatchB(std::string data); + void FMS_acquireFormTempBatch(std::string data); + void FMS_deleteFormBatch(std::string strFormId); + 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..9af88ac6a13eec2f82e19aa71c69f4dd00e522e5 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_deleteform.h @@ -0,0 +1,119 @@ +/* + * 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); + 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_1201(std::string data); + void FMS_deleteForm_1400(std::string data); + void FMS_deleteForm_1401(std::string data); + void FMS_deleteForm_1500(std::string data); + void FMS_deleteForm_1501(std::string data); + void FMS_deleteForm_1502(std::string data); + void FMS_deleteForm_1600(std::string data); + void FMS_deleteForm_1601(std::string data); + void FMS_deleteForm_1602(std::string data); + void FMS_deleteForm_1700(std::string data); + void FMS_deleteForm_1701(std::string data); + void FMS_deleteForm_1702(std::string data); + void FMS_acquire_tempForm_batch(std::string data); + void FMS_acquireForm_batch(std::string data); + void FMS_deleteFormBatch(std::string data); + + 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; + FormAbilityDeleteForm *ability_; + 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(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); + 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); + void DeleteForm_1200(int64_t form_id); + void DeleteForm_1400(int64_t form_id); + void DeleteForm_1500(int64_t form_id); + void DeleteForm_1501(int64_t form_id); + void DeleteForm_1600(int64_t form_id); + void DeleteForm_1601(int64_t form_id); + void DeleteForm_1700(int64_t form_id); + void DeleteForm_1701(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..a596482858c1fbc775e55918d2b30b32cf1e475d --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/include/form_ability_releaseform.h @@ -0,0 +1,104 @@ +/* + * 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); + void FMS_releaseForm_common_del(std::string data); + void Clear(std::string case_id, int64_t form_id); + + 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 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); + void ReleaseForm_0800(int64_t form_id); + void ReleaseForm_0900(int64_t form_id); + void ReleaseForm_1000(int64_t form_id); + void ReleaseForm_1100(int64_t form_id); + 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..344a14cf92aa96bb183f4b9441c321d10799b473 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_a.cpp @@ -0,0 +1,904 @@ +/* + * 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" +#include "system_test_form_util.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_TEMP, + 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_2800, FORM_EVENT_REQ_ACQUIRE_FORM_2900, + FORM_EVENT_REQ_ACQUIRE_FORM_2900_1, FORM_EVENT_REQ_ACQUIRE_FORM_3000, FORM_EVENT_REQ_ACQUIRE_FORM_3100, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, FORM_EVENT_REQ_CLEAR_FORM_BATCH, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B, +}; +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()); + if (strFormId.empty()) { + APP_LOGE("DeleteForm error, formId is 0"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + return; + } + 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"); + } 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"); + } 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) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800); + + // Set Want info end + int64_t formId = std::stoll(data); + bool bResult = CastTempForm(formId); + if (bResult) { + APP_LOGI("CastTempForm end"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800, "false"); + } + + FMS_deleteFormCommon(data); +} +void FormAbilityA::FMS_acquireForm_2900(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2900); + 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_2900, EVENT_CODE_2900, ""); + } +} + +void FormAbilityA::FMS_acquireForm_2900_1(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2910); + 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_2900_1, EVENT_CODE_2910, ""); + } +} +void FormAbilityA::FMS_acquireForm_3000(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000); + // 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_3000, EVENT_CODE_3000, "false"); + } +} +void FormAbilityA::FMS_acquireForm_3100(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100); + 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_3100, EVENT_CODE_3100, ""); + } +} + +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, ""); + } +} +void FormAbilityA::FMS_acquireFormBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} + +void FormAbilityA::FMS_acquireFormBatchB(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B, "false"); + } +} +void FormAbilityA::FMS_acquireFormTempBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add temp form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "true"); + } else { + APP_LOGE("Batch add temp form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); + } +} +void FormAbilityA::FMS_deleteFormBatch(std::string strFormId) +{ + APP_LOGI("%{public}s called", __func__); + int result = STtools::SystemTestFormUtil::ClearFormRecords(); + if (result == ERR_OK) { + APP_LOGI("Clear form records end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "true"); + } else { + APP_LOGE("Clear form records error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); + } +} +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_ACQUIRE_FORM_2800] = &FormAbilityA::FMS_acquireForm_2800; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2900] = &FormAbilityA::FMS_acquireForm_2900; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_2900_1] = &FormAbilityA::FMS_acquireForm_2900_1; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3000] = &FormAbilityA::FMS_acquireForm_3000; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3100] = &FormAbilityA::FMS_acquireForm_3100; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_COMMON] = &FormAbilityA::FMS_deleteFormCommon; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_TEMP] = &FormAbilityA::FMS_acquireForm_tempForm; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityA::FMS_acquireFormBatch; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B] = &FormAbilityA::FMS_acquireFormBatchB; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH] = &FormAbilityA::FMS_acquireFormTempBatch; + memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityA::FMS_deleteFormBatch; + 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..f50e5b4f7beab31ec5ff6fd7a7954f74d15af978 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_deleteform.cpp @@ -0,0 +1,905 @@ +/* + * 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" +#include "system_test_form_util.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(formJsInfo.formId, this->caseName_); + } +} +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 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1200 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1400 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1500 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1501 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1600 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1601 || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1700 + || this->caseName_ == FORM_EVENT_RECV_DELETE_FORM_1701) { + ability_->FMS_deleteForm_common(formJsInfo.formId, this->caseName_); + } +} + +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) +{ + APP_LOGI("%{public}s called, formId: %{public}s, caseName:%{public}s", + __func__, std::to_string(formId).c_str(), caseName.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); + } 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); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1200) { + DeleteForm_1200(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1400) { + DeleteForm_1400(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1500) { + DeleteForm_1500(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1501) { + DeleteForm_1501(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1600) { + DeleteForm_1600(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1601) { + DeleteForm_1601(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1700) { + DeleteForm_1700(formId); + } else if (caseName == FORM_EVENT_RECV_DELETE_FORM_1701) { + DeleteForm_1701(formId); + } else { + return; + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0300(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0300); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0500(std::string data) +{ + APP_LOGI("%{public}s start[%{public}s]", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500, "true"); + } else { + APP_LOGE("%{public}s error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0500, EVENT_CODE_500, "false"); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_0600(std::string data) +{ + APP_LOGI("%{public}s start[%{public}s]", __func__, data.c_str()); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_0600); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1200(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_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_NAME1); + want.SetParam(Constants::PARAM_MODULE_NAME_KEY, PARAM_PROVIDER_MODULE_NAME1); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1200, EVENT_CODE_1200, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1201(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1201, EVENT_CODE_1201, "false"); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1400(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1400); + 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); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400, ""); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1401(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1401, EVENT_CODE_1401, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1401, EVENT_CODE_1401, "false"); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1500(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_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_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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1501(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1501); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510, "acquireError"); + } + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510, "deleteError"); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1502(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1502, EVENT_CODE_1511, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1502, EVENT_CODE_1511, "false"); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1600(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600, ""); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1601(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1601); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610, "acquireError"); + } + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610, "deleteError"); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1602(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1602, EVENT_CODE_1611, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1602, EVENT_CODE_1611, "false"); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1700(std::string data) +{ + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1700); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700, ""); + } +} + +void FormAbilityDeleteForm::FMS_deleteForm_1701(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_DELETE_FORM_1701); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701, "acquireError"); + } + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701, "deleteError"); + } +} +void FormAbilityDeleteForm::FMS_deleteForm_1702(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702, "false"); + } +} +void FormAbilityDeleteForm::FMS_acquire_tempForm_batch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); + } +} +void FormAbilityDeleteForm::FMS_acquireForm_batch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} +void FormAbilityDeleteForm::FMS_deleteFormBatch(std::string strFormId) +{ + APP_LOGI("%{public}s called", __func__); + int result = STtools::SystemTestFormUtil::ClearFormRecords(); + if (result == ERR_OK) { + APP_LOGI("Clear form records end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "true"); + } else { + APP_LOGE("Clear form records error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0300(int64_t form_id) +{ + bool bResult = DeleteForm(-1); + Clear("FMS_deleteForm_0300", form_id); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0300, EVENT_CODE_300, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + 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("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0400, EVENT_CODE_400, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + 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("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600, "false"); + } +} + +void FormAbilityDeleteForm::DeleteForm_0700(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + 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("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0800, EVENT_CODE_800, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + 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) { + APP_LOGI("%{public}s DeleteForm1 end", __func__); + bool realResult = DeleteForm(form_id); + if (realResult) { + APP_LOGI("%{public}s DeleteForm2 end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, "true"); + } else { + APP_LOGE("%{public}s DeleteForm2 error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_0900, EVENT_CODE_900, "false"); + } + } else { + APP_LOGE("%{public}s DeleteForm1 error", __func__); + 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) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + bool realResult = DeleteForm(form_id); + if (realResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, "false"); + } + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1000, EVENT_CODE_1000, ""); + } +} +void FormAbilityDeleteForm::DeleteForm_1100(int64_t form_id) +{ + bool bResult = DeleteForm(form_id); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100, "false"); + } +} +void FormAbilityDeleteForm::DeleteForm_1200(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1200, EVENT_CODE_1200, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1400(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1500(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1501(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1600(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1601(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1700(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700, std::to_string(form_id)); +} +void FormAbilityDeleteForm::DeleteForm_1701(int64_t form_id) +{ + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701, std::to_string(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_1201, + FORM_EVENT_REQ_DELETE_FORM_1400, + FORM_EVENT_REQ_DELETE_FORM_1401, + FORM_EVENT_REQ_DELETE_FORM_1500, + FORM_EVENT_REQ_DELETE_FORM_1501, + FORM_EVENT_REQ_DELETE_FORM_1502, + FORM_EVENT_REQ_DELETE_FORM_1600, + FORM_EVENT_REQ_DELETE_FORM_1601, + FORM_EVENT_REQ_DELETE_FORM_1602, + FORM_EVENT_REQ_DELETE_FORM_1700, + FORM_EVENT_REQ_DELETE_FORM_1701, + FORM_EVENT_REQ_DELETE_FORM_1702, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, + FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, + FORM_EVENT_REQ_CLEAR_FORM_BATCH + }; + 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_1201] = &FormAbilityDeleteForm::FMS_deleteForm_1201; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1400] = &FormAbilityDeleteForm::FMS_deleteForm_1400; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1401] = &FormAbilityDeleteForm::FMS_deleteForm_1401; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1500] = &FormAbilityDeleteForm::FMS_deleteForm_1500; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1501] = &FormAbilityDeleteForm::FMS_deleteForm_1501; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1502] = &FormAbilityDeleteForm::FMS_deleteForm_1502; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1600] = &FormAbilityDeleteForm::FMS_deleteForm_1600; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1601] = &FormAbilityDeleteForm::FMS_deleteForm_1601; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1602] = &FormAbilityDeleteForm::FMS_deleteForm_1602; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1700] = &FormAbilityDeleteForm::FMS_deleteForm_1700; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1701] = &FormAbilityDeleteForm::FMS_deleteForm_1701; + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_1702] = &FormAbilityDeleteForm::FMS_deleteForm_1702; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityDeleteForm::FMS_acquireForm_batch; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH] = &FormAbilityDeleteForm::FMS_acquire_tempForm_batch; + memberFuncMap_[FORM_EVENT_REQ_CLEAR_FORM_BATCH] = &FormAbilityDeleteForm::FMS_deleteFormBatch; +} + +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..1d2cdb7044b5a946cb38ef19363954b39ac0dd6e --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormal/src/form_ability_releaseform.cpp @@ -0,0 +1,636 @@ +/* + * 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(formJsInfo.formId, 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); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0800) { + ReleaseForm_0800(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_0900) { + ReleaseForm_0900(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1000) { + ReleaseForm_1000(formId); + } else if (caseName == FORM_EVENT_RECV_RELEASE_FORM_1100) { + ReleaseForm_1100(formId); + } 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400, ""); + } +} + +void FormAbilityReleaseForm::FMS_releaseForm_0500(std::string data) +{ + APP_LOGI("%{public}s start[%{public}s]", __func__, data.c_str()); + bool bResult = ReleaseForm(atoll(data.c_str()), true); + if (bResult) { + APP_LOGI("%{public}s end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0500, EVENT_CODE_500, "true"); + } else { + APP_LOGE("%{public}s error", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + 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("%{public}s AcquireForm ok.", __func__); + } else { + APP_LOGE("%{public}s AcquireForm error.", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, ""); + } +} +void FormAbilityReleaseForm::FMS_releaseForm_common_del(std::string data) +{ + APP_LOGI("%{public}s formId: %{public}s", __func__, data.c_str()); + bool bResult = DeleteForm(atoll(data.c_str())); + if (bResult) { + APP_LOGI("%{public}s DeleteForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, "true"); + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, "false"); + } +} + +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("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0300, EVENT_CODE_300, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0400, EVENT_CODE_400, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, "false"); + } + } else { + APP_LOGE("%{public}s DeleteForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0600, EVENT_CODE_600, ""); + } +} + +void FormAbilityReleaseForm::ReleaseForm_0700(int64_t form_id) +{ + bool isReleaseCache = false; + bool bResult = ReleaseForm(form_id, isReleaseCache); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_0800(int64_t form_id) +{ + bool isReleaseCache = false; + bool bResult = ReleaseForm(form_id, isReleaseCache); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_0900, EVENT_CODE_900, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1000(int64_t form_id) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000, "false"); + } +} +void FormAbilityReleaseForm::ReleaseForm_1100(int64_t form_id) +{ + bool isReleaseCache = true; + bool bResult = ReleaseForm(form_id, isReleaseCache); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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); + if (bResult) { + APP_LOGI("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1200, EVENT_CODE_1200, std::to_string(form_id)); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1300, EVENT_CODE_1300, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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("%{public}s ReleaseForm end", __func__); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_RELEASE_FORM_1400, EVENT_CODE_1400, "true"); + } else { + APP_LOGE("%{public}s ReleaseForm error", __func__); + 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, + FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL + }; + 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; + memberFuncMap_[FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL] = &FormAbilityReleaseForm::FMS_releaseForm_common_del; +} + +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() == "") || + eventName == FORM_EVENT_REQ_RELEASE_FORM_0700 || eventName == FORM_EVENT_REQ_RELEASE_FORM_0800 || + eventName == FORM_EVENT_REQ_RELEASE_FORM_0900 || eventName == FORM_EVENT_REQ_RELEASE_FORM_1000 || + eventName == FORM_EVENT_REQ_RELEASE_FORM_1100 || eventName == FORM_EVENT_REQ_RELEASE_FORM_1200) { + 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..30e6a8c55b892e6bb447ef1b066d703252b75b06 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/BUILD.gn @@ -0,0 +1,80 @@ +# 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", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNormalB") { + 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", + "../tool/src/form_test_utils.cpp", + "src/form_ability_b.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ + ":fmsSystemTestHostNormalBConfig", + "${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", + "${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 = [ + "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", + ] + 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..d5e5c7a6368673f9f55e98589b36d59002c87f41 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/include/form_ability_b.h @@ -0,0 +1,94 @@ +/* + * 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(std::string strFormId); + + 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); + void FMS_acquireForm_3100(std::string data); + void FMS_acquireForm_tempForm(std::string data); + void FMS_acquireFormBatch(std::string data); + void FMS_acquireFormTempBatch(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..437923559ae01683daf2901af227fc309b4ef3f1 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalB/src/form_ability_b.cpp @@ -0,0 +1,392 @@ +/* + * 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" +#include "system_test_form_util.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_TEMP, 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, FORM_EVENT_REQ_ACQUIRE_FORM_3100, FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, + FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, +}; +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) { + 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 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) { + 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 FormAbilityB::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityB::FMS_deleteFormCommon(std::string strFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); + if (strFormId.empty()) { + APP_LOGE("DeleteForm error, formId is 0"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + return; + } + 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 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"); + } else { + APP_LOGE("CastTempForm error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_2400_1, EVENT_CODE_2410, "false"); + } +} +void FormAbilityB::FMS_acquireForm_3100(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100); + 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_3100, EVENT_CODE_3100, ""); + } +} +void FormAbilityB::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, ""); + } +} + +void FormAbilityB::FMS_acquireFormBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} + +void FormAbilityB::FMS_acquireFormTempBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add temp form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "true"); + } else { + APP_LOGE("Batch add temp form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "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_DELETE_FORM_COMMON] = &FormAbilityB::FMS_deleteFormCommon; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_TEMP] = &FormAbilityB::FMS_acquireForm_tempForm; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityB::FMS_acquireFormBatch; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH] = &FormAbilityB::FMS_acquireFormTempBatch; + 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; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3100] = &FormAbilityB::FMS_acquireForm_3100; + 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/fmsSystemTestHostNormalC/BUILD.gn b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..5630620e87c5afffaffa7d38ec576ec2cc7fb923 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/BUILD.gn @@ -0,0 +1,80 @@ +# 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("fmsSystemTestHostNormalCConfig") { + 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", + "//foundation/distributedschedule/safwk/services/safwk/include", + ] + defines = [ + "APP_LOG_TAG = \"formManagerSystemTest\"", + "LOG_DOMAIN = 0xD002666", + ] +} +ohos_shared_library("fmsSystemTestHostNormalC") { + 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", + "../tool/src/form_test_utils.cpp", + "src/form_ability_c.cpp", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + configs = [ + ":fmsSystemTestHostNormalCConfig", + "${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", + "${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 = [ + "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", + ] + subsystem_name = "formsystemtestability" +} diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalC/config.json b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/config.json new file mode 100644 index 0000000000000000000000000000000000000000..c3bb05c974b474173c781e56841c0ce49e0d539a --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/config.json @@ -0,0 +1,80 @@ +{ + "app":{ + "bundleName": "com.ohos.form.manager.normalc", + "vendor": "ix", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 3, + "target": 3 + } + }, + "deviceConfig": { + "default": { + } + }, + "module": { + "package":"com.ohos.form.manager.normalc.FormAbility", + "name":"FormAbility", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "FormAbilityC", + "moduleType": "entry" + }, + "abilities": [{ + "name": "FormAbilityC", + "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/fmsSystemTestHostNormalC/include/form_ability_c.h b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/include/form_ability_c.h new file mode 100644 index 0000000000000000000000000000000000000000..5b13e2e4c39bf645b9dfc55438e3dc1755add0a1 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/include/form_ability_c.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_C_H_ +#define _FORM_ABILITY_C_H_ +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" + +namespace OHOS { +namespace AppExecFwk { +class FormEventSubscriber; +class FormAbilityC : public Ability { +public: + ~FormAbilityC(); + void SubscribeEvent(); + void handleEvent(std::string action, std::string data); + + void FMS_deleteFormCommon(std::string strFormId); + + void FMS_acquireForm_3100(std::string data); + void FMS_acquireForm_3200(std::string data); + + void FMS_acquireFormBatch(std::string data); + void FMS_acquireFormTempBatch(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; + FormAbilityC *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 (FormAbilityC::*)(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(); + + FormAbilityC *ability_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // _FORM_ABILITY_C_H_ \ No newline at end of file diff --git a/test/resource/formsystemtestability/fmsSystemTestHostNormalC/src/form_ability_c.cpp b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/src/form_ability_c.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dad17b4b4b0facf359e444f27dd8498b1b4d3003 --- /dev/null +++ b/test/resource/formsystemtestability/fmsSystemTestHostNormalC/src/form_ability_c.cpp @@ -0,0 +1,267 @@ +/* + * 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_c.h" +#include "app_log_wrapper.h" +#include "form_st_common_info.h" +#include "form_test_utils.h" +#include "system_test_form_util.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_3100, FORM_EVENT_REQ_ACQUIRE_FORM_3200, + FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, +}; +void FormAbilityC::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 FormAbilityC::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); +} + +void FormAbilityC::AcquireFormCallback::OnFormUninstall(const int64_t formId) const +{ + APP_LOGI("%{public}s called", __func__); +} +void FormAbilityC::FMS_deleteFormCommon(std::string strFormId) +{ + APP_LOGI("%{public}s called, formId: %{public}s", __func__, strFormId.c_str()); + if (strFormId.empty()) { + APP_LOGE("DeleteForm error, formId is 0"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_DELETE_FORM_COMMON, EVENT_CODE_999, "false"); + return; + } + 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 FormAbilityC::FMS_acquireForm_3100(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100); + 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_3100, EVENT_CODE_3100, ""); + } +} + +void FormAbilityC::FMS_acquireForm_3200(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + std::shared_ptr callback = + std::make_shared(FORM_EVENT_RECV_ACQUIRE_FORM_3200, EVENT_CODE_3200); + 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_3200, EVENT_CODE_3200, "false"); + } +} +void FormAbilityC::FMS_acquireFormBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "true"); + } else { + APP_LOGE("Batch add form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, "false"); + } +} + +void FormAbilityC::FMS_acquireFormTempBatch(std::string data) +{ + APP_LOGI("%{public}s called", __func__); + // 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.SetParam(Constants::PARAM_FORM_TEMPORARY_KEY, FORM_TEMP_FORM_FLAG_TRUE); + want.SetElementName(FORM_TEST_DEVICEID, FORM_PROVIDER_BUNDLE_NAME1, FORM_PROVIDER_ABILITY_NAME1); + + int formCount = std::stoi(data); + APP_LOGI("%{public}s, formCount: %{public}d", __func__, formCount); + want.SetParam(Constants::PARAM_FORM_ADD_COUNT, formCount); + // Set Want info end + int result = STtools::SystemTestFormUtil::BatchAddFormRecords(want); + if (result == ERR_OK) { + APP_LOGI("Batch add temp form end"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "true"); + } else { + APP_LOGE("Batch add temp form error"); + FormTestUtils::PublishEvent(FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, "false"); + } +} +FormAbilityC::~FormAbilityC() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} +void FormAbilityC::OnStart(const Want &want) +{ + APP_LOGI("FormAbilityC::onStart"); + Ability::OnStart(want); +} +void FormAbilityC::OnActive() +{ + APP_LOGI("FormAbilityC::OnActive"); + Ability::OnActive(); + std::string eventData = GetAbilityName() + FORM_ABILITY_STATE_ONACTIVE; + FormTestUtils::PublishEvent(FORM_EVENT_ABILITY_ONACTIVED, 0, eventData); +} + +void FormAbilityC::OnStop() +{ + APP_LOGI("FormAbilityC::OnStop"); + + Ability::OnStop(); +} +void FormAbilityC::OnInactive() +{ + APP_LOGI("FormAbilityC::OnInactive"); + + Ability::OnInactive(); +} +void FormAbilityC::OnBackground() +{ + APP_LOGI("FormAbilityC::OnBackground"); + + Ability::OnBackground(); +} +void FormAbilityC::SubscribeEvent() +{ + APP_LOGI("FormAbilityC::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 FormAbilityC::Init(const std::shared_ptr &abilityInfo, + const std::shared_ptr &application, std::shared_ptr &handler, + const sptr &token) +{ + APP_LOGI("FormAbilityC::Init"); + Ability::Init(abilityInfo, application, handler, token); + memberFuncMap_[FORM_EVENT_REQ_DELETE_FORM_COMMON] = &FormAbilityC::FMS_deleteFormCommon; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_BATCH] = &FormAbilityC::FMS_acquireFormBatch; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH] = &FormAbilityC::FMS_acquireFormTempBatch; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3100] = &FormAbilityC::FMS_acquireForm_3100; + memberFuncMap_[FORM_EVENT_REQ_ACQUIRE_FORM_3200] = &FormAbilityC::FMS_acquireForm_3200; + + SubscribeEvent(); +} + +void FormAbilityC::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 FormAbilityC::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(FormAbilityC) +} // 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/formSystemTestServiceA/config.json b/test/resource/formsystemtestability/formSystemTestServiceA/config.json index c7baafed52bb0c88b550f74f77a16c0b154ad98f..9c9e18be8de173747cce400ef545cd31a943fec6 100644 --- a/test/resource/formsystemtestability/formSystemTestServiceA/config.json +++ b/test/resource/formsystemtestability/formSystemTestServiceA/config.json @@ -1,56 +1,61 @@ { "app": { - "bundleName": "com.provider.bundleName1", - "vendor": "ohos", + "bundleName": "com.form.formsystemtestservicea", + "vendor": "neusoft", "version": { "code": 1, "name": "1.0" }, "apiVersion": { - "compatible": 3, - "target": 3 - } - }, - "deviceConfig": { - "default": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" } }, + "deviceConfig": {}, "module": { - "package": "com.provider.FormSystemTestServiceA.src", - "name": "moduleName11", + "package": "com.form.formsystemtestservicea", + "name": ".MyApplication", "deviceType": [ "phone" ], "distro": { "deliveryWithInstall": true, - "moduleName": "moduleName11", + "moduleName": "formmodule001", "moduleType": "entry" }, "abilities": [ { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, "name": "FormStServiceAbilityA", - "icon": "$media:snowball", - "label": "FormStServiceAbilityA Ability", - "launchType": "standard", - "orientation": "unspecified", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", "type": "service", - "visible": true, + "launchType": "standard", "formsEnabled": true, + "srcLanguage": "c++", "forms": [ { - "name": "formName111", + "name": "Form_Js001", "description": "form_description", "isDefault": true, "type": "JS", "colorMode": "auto", "supportDimensions":[ "1*2", "2*2" ], "defaultDimension": "1*2", - "landscapeLayouts": [""], - "portraitLayouts": [""], "updateEnabled": true, - "scheduledUpateTime": "0:0", - "updateDuration": 1, - "deepLink": "", + "scheduledUpdateTime": "10:30", "jsComponentName": "card", "formVisibleNotify" : true, "metaData": { @@ -63,19 +68,15 @@ } }, { - "name": "formName112", + "name": "Form_Js002", "description": "form_description", "isDefault": true, "type": "JS", "colorMode": "auto", "supportDimensions":[ "1*2", "2*2" ], "defaultDimension": "1*2", - "landscapeLayouts": [""], - "portraitLayouts": [""], "updateEnabled": true, - "scheduledUpateTime": "10:30", - "updateDuration": 0, - "deepLink": "", + "updateDuration": 1, "jsComponentName": "card", "formVisibleNotify" : true, "metaData": { @@ -90,23 +91,17 @@ ] } ], - "defPermissions": [ - { - "name": "com.permission.CAMERA", - "grantMode": "system_grant", - "availableScope": ["signature"], - "label": "CAMERA permission", - "description": "CAMERA permission in detail" - } - ], "js": [ { - "name": "card", "pages": [ "pages/index/index" ], - "type": "form" + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } } ] } -} +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_A.h b/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_A.h index 610caccc59c7c13bdcf5f2be0a3eabe5ea456860..9d54dda7e96811cab208e70637a4a514987da769 100755 --- a/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_A.h +++ b/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_A.h @@ -31,6 +31,7 @@ using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; const std::string APP_A_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_a"; const std::string APP_A_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_a"; const std::string COMMON_EVENT_TEST_ACTION1 = "usual.event.test1"; +const std::string COMMON_EVENT_ON_DELETE = "usual.event.ondelete"; /** * Form event trigger result */ diff --git a/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_A.cpp b/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_A.cpp index e229ca09f08fa93e2f8f9cd9d08d5ca851d76f52..393563683ed7630c6f7eb04f92bb04cc188c3288 100755 --- a/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_A.cpp +++ b/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_A.cpp @@ -314,7 +314,8 @@ void FormStServiceAbilityA::OnUpdate(const int64_t formId) long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnUpdate"); - APP_LOGI("%{public}s end, formId: %{public}lld, current time: %{public}ld", __func__, formId, currentTime); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); } void FormStServiceAbilityA::OnTriggerEvent(const int64_t formId, const std::string &message) @@ -326,7 +327,8 @@ void FormStServiceAbilityA::OnTriggerEvent(const int64_t formId, const std::stri long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnTriggerEvent"); - APP_LOGI("%{public}s end, formId: %{public}lld, message: %{public}s, current time: %{public}ld", __func__, formId, message.c_str(), currentTime); + APP_LOGI("%{public}s end, formId: %{public}s, message: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), message.c_str(), currentTime); } void FormStServiceAbilityA::OnDelete(const int64_t formId) @@ -337,8 +339,10 @@ void FormStServiceAbilityA::OnDelete(const int64_t formId) clock_gettime(CLOCK_REALTIME, &ts); long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; - PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnDelete"); - APP_LOGI("%{public}s end, formId: %{public}lld, current time: %{public}ld", __func__, formId, currentTime); + PublishEvent(COMMON_EVENT_ON_DELETE, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + std::to_string(formId)); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); } void FormStServiceAbilityA::OnCastTemptoNormal(const int64_t formId) @@ -350,7 +354,8 @@ void FormStServiceAbilityA::OnCastTemptoNormal(const int64_t formId) long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnCastTemptoNormal"); - APP_LOGI("%{public}s end, formId: %{public}lld, current time: %{public}ld", __func__, formId, currentTime); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); } void FormStServiceAbilityA::OnVisibilityChanged(const std::map &formEventsMap) diff --git a/test/resource/formsystemtestability/formSystemTestServiceB/BUILD.gn b/test/resource/formsystemtestability/formSystemTestServiceB/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a85feccfd2aa735ea79117980fb8b0e33c596003 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceB/BUILD.gn @@ -0,0 +1,58 @@ +# 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") +subdemosystem_path = "${appexecfwk_path}/test/resource/formsystemtestability/formSystemTestServiceB" +config("formSystemTestBConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${subdemosystem_path}/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/services/bundlemgr/include", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "//foundation/distributedschedule/services/dtbschedmgr/include", + "${even_path}/cesfwk/innerkits/include", + "${even_path}/cesfwk/kits/native/include", + ] + defines = [ + "APP_LOG_TAG = \"formSystemTestServiceB\"", + "LOG_DOMAIN = 0xD002200", + ] +} +ohos_shared_library("formSystemTestServiceB") { + sources = [ "${subdemosystem_path}/src/form_st_service_ability_B.cpp" ] + configs = [ ":formSystemTestBConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/want:want", + "${aafwk_path}/services/abilitymgr:abilityms", + "${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", + "//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/formSystemTestServiceB/config.json b/test/resource/formsystemtestability/formSystemTestServiceB/config.json new file mode 100644 index 0000000000000000000000000000000000000000..baf8da59ed63e02ee4ec549e459d5efee9fb069f --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceB/config.json @@ -0,0 +1,107 @@ +{ + "app": { + "bundleName": "com.form.formsystemtestserviceb", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.form.formsystemtestserviceb", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "formmodule001", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "name": "FormStServiceAbilityB", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "service", + "launchType": "standard", + "formsEnabled": true, + "srcLanguage": "c++", + "forms": [ + { + "name": "Form_Js001", + "description": "form_description", + "isDefault": true, + "type": "JS", + "colorMode": "auto", + "supportDimensions":[ "1*2", "2*2" ], + "defaultDimension": "1*2", + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "jsComponentName": "card", + "formVisibleNotify" : true, + "metaData": { + "customizeData": [ + { + "name": "originWidgetName", + "value": "myTest" + } + ] + } + }, + { + "name": "Form_Js002", + "description": "form_description", + "isDefault": true, + "type": "JS", + "colorMode": "auto", + "supportDimensions":[ "1*2", "2*2" ], + "defaultDimension": "1*2", + "updateEnabled": true, + "updateDuration": 1, + "jsComponentName": "card", + "formVisibleNotify" : true, + "metaData": { + "customizeData": [ + { + "name": "originWidgetName", + "value": "myTest" + } + ] + } + } + ] + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_a1.h b/test/resource/formsystemtestability/formSystemTestServiceB/include/form_st_service_ability_B.h old mode 100755 new mode 100644 similarity index 76% rename from test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_a1.h rename to test/resource/formsystemtestability/formSystemTestServiceB/include/form_st_service_ability_B.h index e5e30429343af0cdfe4aca95ac07ec9d7d07fd75..090627c0bd4a4444d91efea7bb185e081f98f08a --- a/test/resource/formsystemtestability/formSystemTestServiceA/include/form_st_service_ability_a1.h +++ b/test/resource/formsystemtestability/formSystemTestServiceB/include/form_st_service_ability_B.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FORM_ST_SERVICE_ABILITY_A1_ -#define FORM_ST_SERVICE_ABILITY_A1_ +#ifndef FORM_ST_SERVICE_ABILITY_B_ +#define FORM_ST_SERVICE_ABILITY_B_ #include #include #include "ability_connect_callback_stub.h" @@ -22,19 +22,26 @@ #include "ability_loader.h" #include "common_event.h" #include "common_event_manager.h" - #include "form_provider_info.h" namespace OHOS { namespace AppExecFwk { using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; -const std::string APP_A1_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_a1"; -const std::string APP_A1_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_a1"; +const std::string APP_A_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_b"; +const std::string APP_A_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_b"; +const std::string COMMON_EVENT_TEST_ACTION1 = "usual.event.test1"; +/** + * Form event trigger result + */ +typedef enum { + FORM_EVENT_TRIGGER_RESULT_NG = 0, + FORM_EVENT_TRIGGER_RESULT_OK = 1, +} FORM_EVENT_TRIGGER_RESULT; -class FormStServiceAbilityA1 : public Ability { +class FormStServiceAbilityB : public Ability { public: - ~FormStServiceAbilityA1(); + ~FormStServiceAbilityB(); protected: virtual void OnStart(const Want &want) override; @@ -47,6 +54,11 @@ protected: virtual sptr OnConnect(const Want &want) override; virtual void OnDisconnect(const Want &want) override; virtual FormProviderInfo OnCreate(const Want &want) override; + virtual void OnUpdate(const int64_t formId) override; + virtual void OnTriggerEvent(const int64_t formId, const std::string &message) override; + virtual void OnDelete(const int64_t formId) override; + virtual void OnCastTemptoNormal(const int64_t formId) override; + virtual void OnVisibilityChanged(const std::map &formEventsMap) override; private: void Clear(); @@ -70,7 +82,7 @@ private: std::string nextTargetAbilityConn_ = {}; std::string zombie_ = {}; - typedef void (FormStServiceAbilityA1::*func)(); + typedef void (FormStServiceAbilityB::*func)(); static std::map funcMap_; class AbilityConnectCallback; sptr stub_ = {}; @@ -96,7 +108,7 @@ private: { if (resultCode == 0) { onAbilityConnectDoneCount++; - PublishEvent(APP_A1_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityConnectDone"); + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityConnectDone"); } } @@ -110,7 +122,7 @@ private: { if (resultCode == 0) { onAbilityConnectDoneCount--; - PublishEvent(APP_A1_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityDisconnectDone"); + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityDisconnectDone"); } } @@ -118,13 +130,13 @@ private: }; class AppEventSubscriber : public EventFwk::CommonEventSubscriber { public: - AppEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp){}; + AppEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; ~AppEventSubscriber() = default; virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; - FormStServiceAbilityA1 *mainAbility_ = nullptr; + FormStServiceAbilityB *mainAbility_ = nullptr; }; }; } // namespace AppExecFwk } // namespace OHOS -#endif // FORM_ST_SERVICE_ABILITY_A1_ +#endif // FORM_ST_SERVICE_ABILITY_B_ diff --git a/test/resource/formsystemtestability/formSystemTestServiceB/src/form_st_service_ability_B.cpp b/test/resource/formsystemtestability/formSystemTestServiceB/src/form_st_service_ability_B.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a59b6ad4499ae16e62d31bb76c8b180b1877eeae --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceB/src/form_st_service_ability_B.cpp @@ -0,0 +1,379 @@ +/* + * 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_st_service_ability_B.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_client.h" + +using namespace OHOS::EventFwk; + +namespace OHOS { +namespace AppExecFwk { +constexpr int64_t SEC_TO_MILLISEC = 1000; +constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; + +int FormStServiceAbilityB::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +std::map FormStServiceAbilityB::funcMap_ = { + {"StartOtherAbility", &FormStServiceAbilityB::StartOtherAbility}, + {"ConnectOtherAbility", &FormStServiceAbilityB::ConnectOtherAbility}, + {"DisConnectOtherAbility", &FormStServiceAbilityB::DisConnectOtherAbility}, + {"StopSelfAbility", &FormStServiceAbilityB::StopSelfAbility}, +}; + +FormStServiceAbilityB::~FormStServiceAbilityB() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +std::vector FormStServiceAbilityB::Split(std::string str, const std::string &token) +{ + APP_LOGI("FormStServiceAbilityB::Split"); + + std::vector splitString; + while (str.size()) { + size_t index = str.find(token); + if (index != std::string::npos) { + splitString.push_back(str.substr(0, index)); + str = str.substr(index + token.size()); + if (str.size() == 0) { + splitString.push_back(str); + } + } else { + splitString.push_back(str); + str = ""; + } + } + return splitString; +} +void FormStServiceAbilityB::StartOtherAbility() +{ + APP_LOGI("FormStServiceAbilityB::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", + targetBundle_.c_str(), + targetAbility_.c_str()); + APP_LOGI("FormStServiceAbilityB::StartOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + if (!targetBundle_.empty() && !targetAbility_.empty()) { + std::vector strtargetBundles = Split(targetBundle_, ","); + std::vector strTargetAbilitys = Split(targetAbility_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + StartAbility(want); + sleep(1); + } + } +} +void FormStServiceAbilityB::ConnectOtherAbility() +{ + APP_LOGI( + "FormStServiceAbilityB::ConnectOtherAbility begin targetBundleConn=%{public}s, targetAbilityConn=%{public}s", + targetBundleConn_.c_str(), + targetAbilityConn_.c_str()); + APP_LOGI("FormStServiceAbilityB::ConnectOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + // connect service ability + if (!targetBundleConn_.empty() && !targetAbilityConn_.empty()) { + std::vector strtargetBundles = Split(targetBundleConn_, ","); + std::vector strTargetAbilitys = Split(targetAbilityConn_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + APP_LOGI("FormStServiceAbilityB::ConnectOtherAbility->ConnectAbility"); + bool ret = ConnectAbility(want, connCallback_); + sleep(1); + if (!ret) { + APP_LOGE("FormStServiceAbilityB::ConnectAbility failed!"); + } + } + } +} +void FormStServiceAbilityB::DisConnectOtherAbility() +{ + APP_LOGI("FormStServiceAbilityB::DisConnectOtherAbility begin"); + if (connCallback_ != nullptr) { + DisconnectAbility(connCallback_); + sleep(1); + } + APP_LOGI("FormStServiceAbilityB::DisConnectOtherAbility end"); +} + +void FormStServiceAbilityB::StopSelfAbility() +{ + APP_LOGI("FormStServiceAbilityB::StopSelfAbility"); + + TerminateAbility(); +} + +void FormStServiceAbilityB::OnStart(const Want &want) +{ + APP_LOGI("FormStServiceAbilityB::OnStart"); + + GetWantInfo(want); + Ability::OnStart(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); + SubscribeEvent(); + + // make exception for test + if (!zombie_.empty()) { + std::unique_ptr pWant = nullptr; + pWant->GetScheme(); + } +} +void FormStServiceAbilityB::OnCommand(const AAFwk::Want &want, bool restart, int startId) +{ + APP_LOGI("FormStServiceAbilityB::OnCommand"); + + GetWantInfo(want); + Ability::OnCommand(want, restart, startId); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); +} +void FormStServiceAbilityB::OnNewWant(const Want &want) +{ + APP_LOGI("FormStServiceAbilityB::OnNewWant"); + + GetWantInfo(want); + Ability::OnNewWant(want); +} +void FormStServiceAbilityB::OnStop() +{ + APP_LOGI("FormStServiceAbilityB::OnStop"); + + Ability::OnStop(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); +} +void FormStServiceAbilityB::OnActive() +{ + APP_LOGI("FormStServiceAbilityB::OnActive"); + + Ability::OnActive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); +} +void FormStServiceAbilityB::OnInactive() +{ + APP_LOGI("FormStServiceAbilityB::OnInactive"); + + Ability::OnInactive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); +} +void FormStServiceAbilityB::OnBackground() +{ + APP_LOGI("FormStServiceAbilityB::OnBackground"); + + Ability::OnBackground(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); +} + +void FormStServiceAbilityB::Clear() +{ + shouldReturn_ = ""; + targetBundle_ = ""; + targetAbility_ = ""; + targetBundleConn_ = ""; + targetAbilityConn_ = ""; + nextTargetBundle_ = ""; + nextTargetAbility_ = ""; + nextTargetBundleConn_ = ""; + nextTargetAbilityConn_ = ""; +} +void FormStServiceAbilityB::GetWantInfo(const Want &want) +{ + Want mWant(want); + shouldReturn_ = mWant.GetStringParam("shouldReturn"); + targetBundle_ = mWant.GetStringParam("targetBundle"); + targetAbility_ = mWant.GetStringParam("targetAbility"); + targetBundleConn_ = mWant.GetStringParam("targetBundleConn"); + targetAbilityConn_ = mWant.GetStringParam("targetAbilityConn"); + nextTargetBundle_ = mWant.GetStringParam("nextTargetBundle"); + nextTargetAbility_ = mWant.GetStringParam("nextTargetAbility"); + nextTargetBundleConn_ = mWant.GetStringParam("nextTargetBundleConn"); + nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); + zombie_ = mWant.GetStringParam("zombie"); + FormStServiceAbilityB::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +} +bool FormStServiceAbilityB::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + APP_LOGI("FormStServiceAbilityB::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + code, + data.c_str()); + + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} +sptr FormStServiceAbilityB::OnConnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityB::OnConnect"); + + sptr formProviderClient = new (std::nothrow) FormProviderClient(); + std::shared_ptr thisAbility = this->shared_from_this(); + formProviderClient->SetOwner(thisAbility); + + return formProviderClient; +} +void FormStServiceAbilityB::OnDisconnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityB::OnDisconnect"); + + Ability::OnDisconnect(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); +} +bool FormStServiceAbilityB::SubscribeEvent() +{ + MatchingSkills matchingSkills; + matchingSkills.AddEvent(APP_A_REQ_EVENT_NAME); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->mainAbility_ = this; + return CommonEventManager::SubscribeCommonEvent(subscriber_); +} +void FormStServiceAbilityB::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + auto eventName = data.GetWant().GetAction(); + auto dataContent = data.GetData(); + APP_LOGI("FormStServiceAbilityB::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + if (APP_A_REQ_EVENT_NAME.compare(eventName) == 0) { + if (funcMap_.find(dataContent) == funcMap_.end()) { + APP_LOGI( + "FormStServiceAbilityB::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + } else { + if (mainAbility_ != nullptr) { + (mainAbility_->*funcMap_[dataContent])(); + } + } + } +} + +FormProviderInfo FormStServiceAbilityB::OnCreate(const Want &want) +{ + APP_LOGI("%{public}s start", __func__); + FormProviderInfo formProviderInfo; + if (!want.HasParameter(Constants::PARAM_FORM_IDENTITY_KEY)) { + APP_LOGE("%{public}s, formId not exist", __func__); + return formProviderInfo; + } + std::string formId = want.GetStringParam(Constants::PARAM_FORM_IDENTITY_KEY); + std::string jsonData = std::string(""); + int count = 200; + for (int i = 0; i < count; i = i + 1) { + jsonData = jsonData + std::string("beijingB" + std::to_string(i)); + } + std::string formData = std::string("{\"city\":\"") + jsonData + std::string("\"}"); + FormProviderData formProviderData = FormProviderData(formData); + formProviderInfo.SetFormData(formProviderData); + APP_LOGI("%{public}s end, formId: %{public}s", __func__, formId.c_str()); + return formProviderInfo; +} + +void FormStServiceAbilityB::OnUpdate(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnUpdate"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityB::OnTriggerEvent(const int64_t formId, const std::string &message) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnTriggerEvent"); + APP_LOGI("%{public}s end, formId: %{public}s, message: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), message.c_str(), currentTime); +} + +void FormStServiceAbilityB::OnDelete(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnDelete"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityB::OnCastTemptoNormal(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnCastTemptoNormal"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityB::OnVisibilityChanged(const std::map &formEventsMap) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnVisibilityChanged"); + APP_LOGI("%{public}s end, current time: %{public}ld", __func__, currentTime); +} + +REGISTER_AA(FormStServiceAbilityB); +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/resource/formsystemtestability/formSystemTestServiceC/BUILD.gn b/test/resource/formsystemtestability/formSystemTestServiceC/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f08c7721fa5da74582fd9158895a8f14cbd3e8be --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceC/BUILD.gn @@ -0,0 +1,58 @@ +# 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") +subdemosystem_path = "${appexecfwk_path}/test/resource/formsystemtestability/formSystemTestServiceC" +config("formSystemTestCConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${subdemosystem_path}/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/services/bundlemgr/include", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "//foundation/distributedschedule/services/dtbschedmgr/include", + "${even_path}/cesfwk/innerkits/include", + "${even_path}/cesfwk/kits/native/include", + ] + defines = [ + "APP_LOG_TAG = \"formSystemTestServiceC\"", + "LOG_DOMAIN = 0xD002200", + ] +} +ohos_shared_library("formSystemTestServiceC") { + sources = [ "${subdemosystem_path}/src/form_st_service_ability_C.cpp" ] + configs = [ ":formSystemTestCConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/want:want", + "${aafwk_path}/services/abilitymgr:abilityms", + "${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", + "//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/formSystemTestServiceC/config.json b/test/resource/formsystemtestability/formSystemTestServiceC/config.json new file mode 100644 index 0000000000000000000000000000000000000000..81c2839e9faad4ca4617a561ffd6b2cb123df40f --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceC/config.json @@ -0,0 +1,87 @@ +{ + "app": { + "bundleName": "com.form.formsystemtestservicec", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.form.formsystemtestservicec", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "formmodule001", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "name": "FormStServiceAbilityC", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "service", + "launchType": "standard", + "formsEnabled": true, + "srcLanguage": "c++", + "forms": [ + { + "name": "Form_Js001", + "description": "form_description", + "isDefault": true, + "type": "JS", + "colorMode": "auto", + "supportDimensions":[ "1*2", "2*2" ], + "defaultDimension": "1*2", + "updateEnabled": false, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "jsComponentName": "card", + "formVisibleNotify" : true, + "metaData": { + "customizeData": [ + { + "name": "originWidgetName", + "value": "myTest" + } + ] + } + } + ] + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/formSystemTestServiceC/include/form_st_service_ability_C.h b/test/resource/formsystemtestability/formSystemTestServiceC/include/form_st_service_ability_C.h new file mode 100644 index 0000000000000000000000000000000000000000..2b0c9929994520eb203cb49aae9515916559a8e0 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceC/include/form_st_service_ability_C.h @@ -0,0 +1,142 @@ +/* + * 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_SERVICE_ABILITY_C_ +#define FORM_ST_SERVICE_ABILITY_C_ +#include +#include +#include "ability_connect_callback_stub.h" +#include "ability_connect_callback_proxy.h" +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_info.h" + +namespace OHOS { +namespace AppExecFwk { +using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; +const std::string APP_A_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_b"; +const std::string APP_A_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_b"; +const std::string COMMON_EVENT_TEST_ACTION1 = "usual.event.test1"; +/** + * Form event trigger result + */ +typedef enum { + FORM_EVENT_TRIGGER_RESULT_NG = 0, + FORM_EVENT_TRIGGER_RESULT_OK = 1, +} FORM_EVENT_TRIGGER_RESULT; + +class FormStServiceAbilityC : public Ability { +public: + ~FormStServiceAbilityC(); + +protected: + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + virtual void OnNewWant(const Want &want) override; + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; + virtual sptr OnConnect(const Want &want) override; + virtual void OnDisconnect(const Want &want) override; + virtual FormProviderInfo OnCreate(const Want &want) override; + virtual void OnUpdate(const int64_t formId) override; + virtual void OnTriggerEvent(const int64_t formId, const std::string &message) override; + virtual void OnDelete(const int64_t formId) override; + virtual void OnCastTemptoNormal(const int64_t formId) override; + virtual void OnVisibilityChanged(const std::map &formEventsMap) override; + +private: + void Clear(); + void GetWantInfo(const Want &want); + std::vector Split(std::string str, const std::string &token); + bool SubscribeEvent(); + static bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + void StartOtherAbility(); + void ConnectOtherAbility(); + void DisConnectOtherAbility(); + void StopSelfAbility(); + + std::string shouldReturn_ = {}; + std::string targetBundle_ = {}; + std::string targetAbility_ = {}; + std::string nextTargetBundle_ = {}; + std::string nextTargetAbility_ = {}; + std::string targetBundleConn_ = {}; + std::string targetAbilityConn_ = {}; + std::string nextTargetBundleConn_ = {}; + std::string nextTargetAbilityConn_ = {}; + std::string zombie_ = {}; + + typedef void (FormStServiceAbilityC::*func)(); + static std::map funcMap_; + class AbilityConnectCallback; + sptr stub_ = {}; + sptr connCallback_ = {}; + class AppEventSubscriber; + std::shared_ptr subscriber_ = {}; + + class AbilityConnectCallback : public AbilityConnectionStub { + public: + sptr AsObject() override + { + return nullptr; + } + /** + * OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element,.service ability's ElementName. + * @param remoteObject,.the session proxy of service ability. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount++; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityConnectDone"); + } + } + + /** + * OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect. + * + * @param element,.service ability's ElementName. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount--; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityDisconnectDone"); + } + } + + static int onAbilityConnectDoneCount; + }; + class AppEventSubscriber : public EventFwk::CommonEventSubscriber { + public: + AppEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + ~AppEventSubscriber() = default; + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + + FormStServiceAbilityC *mainAbility_ = nullptr; + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FORM_ST_SERVICE_ABILITY_C_ diff --git a/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_a1.cpp b/test/resource/formsystemtestability/formSystemTestServiceC/src/form_st_service_ability_C.cpp old mode 100755 new mode 100644 similarity index 49% rename from test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_a1.cpp rename to test/resource/formsystemtestability/formSystemTestServiceC/src/form_st_service_ability_C.cpp index 8a3d6e97ff72f23d2984f4ebc23169c90fef389e..82ad5b1d65486f6aff328b326a1af57bee785f53 --- a/test/resource/formsystemtestability/formSystemTestServiceA/src/form_st_service_ability_a1.cpp +++ b/test/resource/formsystemtestability/formSystemTestServiceC/src/form_st_service_ability_C.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "form_st_service_ability_a1.h" +#include "form_st_service_ability_C.h" #include "app_log_wrapper.h" #include "common_event.h" #include "common_event_manager.h" @@ -23,24 +23,26 @@ using namespace OHOS::EventFwk; namespace OHOS { namespace AppExecFwk { +constexpr int64_t SEC_TO_MILLISEC = 1000; +constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; -int FormStServiceAbilityA1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; -std::map FormStServiceAbilityA1::funcMap_ = { - {"StartOtherAbility", &FormStServiceAbilityA1::StartOtherAbility}, - {"ConnectOtherAbility", &FormStServiceAbilityA1::ConnectOtherAbility}, - {"DisConnectOtherAbility", &FormStServiceAbilityA1::DisConnectOtherAbility}, - {"StopSelfAbility", &FormStServiceAbilityA1::StopSelfAbility}, +int FormStServiceAbilityC::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +std::map FormStServiceAbilityC::funcMap_ = { + {"StartOtherAbility", &FormStServiceAbilityC::StartOtherAbility}, + {"ConnectOtherAbility", &FormStServiceAbilityC::ConnectOtherAbility}, + {"DisConnectOtherAbility", &FormStServiceAbilityC::DisConnectOtherAbility}, + {"StopSelfAbility", &FormStServiceAbilityC::StopSelfAbility}, }; -FormStServiceAbilityA1::~FormStServiceAbilityA1() +FormStServiceAbilityC::~FormStServiceAbilityC() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); } -std::vector FormStServiceAbilityA1::Split(std::string str, const std::string &token) +std::vector FormStServiceAbilityC::Split(std::string str, const std::string &token) { - APP_LOGI("FormStServiceAbilityA1::Split"); + APP_LOGI("FormStServiceAbilityC::Split"); std::vector splitString; while (str.size()) { @@ -58,12 +60,12 @@ std::vector FormStServiceAbilityA1::Split(std::string str, const st } return splitString; } -void FormStServiceAbilityA1::StartOtherAbility() +void FormStServiceAbilityC::StartOtherAbility() { - APP_LOGI("FormStServiceAbilityA1::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", + APP_LOGI("FormStServiceAbilityC::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", targetBundle_.c_str(), targetAbility_.c_str()); - APP_LOGI("FormStServiceAbilityA1::StartOtherAbility begin nextTargetBundleConn=%{public}s, " + APP_LOGI("FormStServiceAbilityC::StartOtherAbility begin nextTargetBundleConn=%{public}s, " "nextTargetAbilityConn=%{public}s", nextTargetBundleConn_.c_str(), nextTargetAbilityConn_.c_str()); @@ -84,13 +86,13 @@ void FormStServiceAbilityA1::StartOtherAbility() } } } -void FormStServiceAbilityA1::ConnectOtherAbility() +void FormStServiceAbilityC::ConnectOtherAbility() { APP_LOGI( - "FormStServiceAbilityA1::ConnectOtherAbility begin targetBundleConn=%{public}s, targetAbilityConn=%{public}s", + "FormStServiceAbilityC::ConnectOtherAbility begin targetBundleConn=%{public}s, targetAbilityConn=%{public}s", targetBundleConn_.c_str(), targetAbilityConn_.c_str()); - APP_LOGI("FormStServiceAbilityA1::ConnectOtherAbility begin nextTargetBundleConn=%{public}s, " + APP_LOGI("FormStServiceAbilityC::ConnectOtherAbility begin nextTargetBundleConn=%{public}s, " "nextTargetAbilityConn=%{public}s", nextTargetBundleConn_.c_str(), nextTargetAbilityConn_.c_str()); @@ -109,39 +111,39 @@ void FormStServiceAbilityA1::ConnectOtherAbility() want.SetParam("targetAbilityConn", nextTargetAbilityConn_); stub_ = new (std::nothrow) AbilityConnectCallback(); connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - APP_LOGI("FormStServiceAbilityA1::ConnectOtherAbility->ConnectAbility"); + APP_LOGI("FormStServiceAbilityC::ConnectOtherAbility->ConnectAbility"); bool ret = ConnectAbility(want, connCallback_); sleep(1); if (!ret) { - APP_LOGE("FormStServiceAbilityA1::ConnectAbility failed!"); + APP_LOGE("FormStServiceAbilityC::ConnectAbility failed!"); } } } } -void FormStServiceAbilityA1::DisConnectOtherAbility() +void FormStServiceAbilityC::DisConnectOtherAbility() { - APP_LOGI("FormStServiceAbilityA1::DisConnectOtherAbility begin"); + APP_LOGI("FormStServiceAbilityC::DisConnectOtherAbility begin"); if (connCallback_ != nullptr) { DisconnectAbility(connCallback_); sleep(1); } - APP_LOGI("FormStServiceAbilityA1::DisConnectOtherAbility end"); + APP_LOGI("FormStServiceAbilityC::DisConnectOtherAbility end"); } -void FormStServiceAbilityA1::StopSelfAbility() +void FormStServiceAbilityC::StopSelfAbility() { - APP_LOGI("FormStServiceAbilityA1::StopSelfAbility"); + APP_LOGI("FormStServiceAbilityC::StopSelfAbility"); TerminateAbility(); } -void FormStServiceAbilityA1::OnStart(const Want &want) +void FormStServiceAbilityC::OnStart(const Want &want) { - APP_LOGI("FormStServiceAbilityA1::OnStart"); + APP_LOGI("FormStServiceAbilityC::OnStart"); GetWantInfo(want); Ability::OnStart(want); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); SubscribeEvent(); // make exception for test @@ -150,51 +152,51 @@ void FormStServiceAbilityA1::OnStart(const Want &want) pWant->GetScheme(); } } -void FormStServiceAbilityA1::OnCommand(const AAFwk::Want &want, bool restart, int startId) +void FormStServiceAbilityC::OnCommand(const AAFwk::Want &want, bool restart, int startId) { - APP_LOGI("FormStServiceAbilityA1::OnCommand"); + APP_LOGI("FormStServiceAbilityC::OnCommand"); GetWantInfo(want); Ability::OnCommand(want, restart, startId); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); } -void FormStServiceAbilityA1::OnNewWant(const Want &want) +void FormStServiceAbilityC::OnNewWant(const Want &want) { - APP_LOGI("FormStServiceAbilityA1::OnNewWant"); + APP_LOGI("FormStServiceAbilityC::OnNewWant"); GetWantInfo(want); Ability::OnNewWant(want); } -void FormStServiceAbilityA1::OnStop() +void FormStServiceAbilityC::OnStop() { - APP_LOGI("FormStServiceAbilityA1::OnStop"); + APP_LOGI("FormStServiceAbilityC::OnStop"); Ability::OnStop(); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); } -void FormStServiceAbilityA1::OnActive() +void FormStServiceAbilityC::OnActive() { - APP_LOGI("FormStServiceAbilityA1::OnActive"); + APP_LOGI("FormStServiceAbilityC::OnActive"); Ability::OnActive(); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); } -void FormStServiceAbilityA1::OnInactive() +void FormStServiceAbilityC::OnInactive() { - APP_LOGI("FormStServiceAbilityA1::OnInactive"); + APP_LOGI("FormStServiceAbilityC::OnInactive"); Ability::OnInactive(); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); } -void FormStServiceAbilityA1::OnBackground() +void FormStServiceAbilityC::OnBackground() { - APP_LOGI("FormStServiceAbilityA1::OnBackground"); + APP_LOGI("FormStServiceAbilityC::OnBackground"); Ability::OnBackground(); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); } -void FormStServiceAbilityA1::Clear() +void FormStServiceAbilityC::Clear() { shouldReturn_ = ""; targetBundle_ = ""; @@ -206,7 +208,7 @@ void FormStServiceAbilityA1::Clear() nextTargetBundleConn_ = ""; nextTargetAbilityConn_ = ""; } -void FormStServiceAbilityA1::GetWantInfo(const Want &want) +void FormStServiceAbilityC::GetWantInfo(const Want &want) { Want mWant(want); shouldReturn_ = mWant.GetStringParam("shouldReturn"); @@ -219,11 +221,11 @@ void FormStServiceAbilityA1::GetWantInfo(const Want &want) nextTargetBundleConn_ = mWant.GetStringParam("nextTargetBundleConn"); nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); zombie_ = mWant.GetStringParam("zombie"); - FormStServiceAbilityA1::AbilityConnectCallback::onAbilityConnectDoneCount = 0; + FormStServiceAbilityC::AbilityConnectCallback::onAbilityConnectDoneCount = 0; } -bool FormStServiceAbilityA1::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +bool FormStServiceAbilityC::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { - APP_LOGI("FormStServiceAbilityA1::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + APP_LOGI("FormStServiceAbilityC::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", eventName.c_str(), code, data.c_str()); @@ -236,46 +238,45 @@ bool FormStServiceAbilityA1::PublishEvent(const std::string &eventName, const in commonData.SetData(data); return CommonEventManager::PublishCommonEvent(commonData); } -sptr FormStServiceAbilityA1::OnConnect(const Want &want) +sptr FormStServiceAbilityC::OnConnect(const Want &want) { - APP_LOGI("FormStServiceAbilityA1::OnConnect"); - + APP_LOGI("FormStServiceAbilityC::OnConnect"); + sptr formProviderClient = new (std::nothrow) FormProviderClient(); - formProviderClient->SetOwner(std::make_shared(*this)); std::shared_ptr thisAbility = this->shared_from_this(); formProviderClient->SetOwner(thisAbility); return formProviderClient; } -void FormStServiceAbilityA1::OnDisconnect(const Want &want) +void FormStServiceAbilityC::OnDisconnect(const Want &want) { - APP_LOGI("FormStServiceAbilityA1::OnDisconnect"); + APP_LOGI("FormStServiceAbilityC::OnDisconnect"); Ability::OnDisconnect(want); - PublishEvent(APP_A1_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } -bool FormStServiceAbilityA1::SubscribeEvent() +bool FormStServiceAbilityC::SubscribeEvent() { MatchingSkills matchingSkills; - matchingSkills.AddEvent(APP_A1_REQ_EVENT_NAME); + matchingSkills.AddEvent(APP_A_REQ_EVENT_NAME); CommonEventSubscribeInfo subscribeInfo(matchingSkills); subscribeInfo.SetPriority(1); subscriber_ = std::make_shared(subscribeInfo); subscriber_->mainAbility_ = this; return CommonEventManager::SubscribeCommonEvent(subscriber_); } -void FormStServiceAbilityA1::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) +void FormStServiceAbilityC::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) { auto eventName = data.GetWant().GetAction(); auto dataContent = data.GetData(); - APP_LOGI("FormStServiceAbilityA1::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + APP_LOGI("FormStServiceAbilityC::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", eventName.c_str(), data.GetCode(), dataContent.c_str()); - if (APP_A1_REQ_EVENT_NAME.compare(eventName) == 0) { + if (APP_A_REQ_EVENT_NAME.compare(eventName) == 0) { if (funcMap_.find(dataContent) == funcMap_.end()) { APP_LOGI( - "FormStServiceAbilityA1::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + "FormStServiceAbilityC::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", eventName.c_str(), data.GetCode(), dataContent.c_str()); @@ -287,7 +288,7 @@ void FormStServiceAbilityA1::AppEventSubscriber::OnReceiveEvent(const CommonEven } } -FormProviderInfo FormStServiceAbilityA1::OnCreate(const Want &want) +FormProviderInfo FormStServiceAbilityC::OnCreate(const Want &want) { APP_LOGI("%{public}s start", __func__); FormProviderInfo formProviderInfo; @@ -296,11 +297,79 @@ FormProviderInfo FormStServiceAbilityA1::OnCreate(const Want &want) return formProviderInfo; } std::string formId = want.GetStringParam(Constants::PARAM_FORM_IDENTITY_KEY); - formProviderInfo.SetFormData(FormProviderData(std::string("{\"city\": \"beijingA\", \"formId\": " + formId + "}"))); + std::string jsonData = std::string("{\"city\":\"beijingC\"}"); + FormProviderData formProviderData = FormProviderData(jsonData); + formProviderInfo.SetFormData(formProviderData); + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnCreate"); APP_LOGI("%{public}s end, formId: %{public}s", __func__, formId.c_str()); return formProviderInfo; } -REGISTER_AA(FormStServiceAbilityA1); +void FormStServiceAbilityC::OnUpdate(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnUpdate"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityC::OnTriggerEvent(const int64_t formId, const std::string &message) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnTriggerEvent"); + APP_LOGI("%{public}s end, formId: %{public}s, message: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), message.c_str(), currentTime); +} + +void FormStServiceAbilityC::OnDelete(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnDelete"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityC::OnCastTemptoNormal(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnCastTemptoNormal"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityC::OnVisibilityChanged(const std::map &formEventsMap) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnVisibilityChanged"); + APP_LOGI("%{public}s end, current time: %{public}ld", __func__, currentTime); +} + +REGISTER_AA(FormStServiceAbilityC); } // namespace AppExecFwk } // namespace OHOS diff --git a/test/resource/formsystemtestability/formSystemTestServiceD/BUILD.gn b/test/resource/formsystemtestability/formSystemTestServiceD/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..56303e43cbf8c1f8f876451ecba25bb74d5a6596 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceD/BUILD.gn @@ -0,0 +1,58 @@ +# 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") +subdemosystem_path = "${appexecfwk_path}/test/resource/formsystemtestability/formSystemTestServiceD" +config("formSystemTestDConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${subdemosystem_path}/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/services/bundlemgr/include", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "//foundation/distributedschedule/services/dtbschedmgr/include", + "${even_path}/cesfwk/innerkits/include", + "${even_path}/cesfwk/kits/native/include", + ] + defines = [ + "APP_LOG_TAG = \"formSystemTestServiceD\"", + "LOG_DOMAIN = 0xD002200", + ] +} +ohos_shared_library("formSystemTestServiceD") { + sources = [ "${subdemosystem_path}/src/form_st_service_ability_D.cpp" ] + configs = [ ":formSystemTestDConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/want:want", + "${aafwk_path}/services/abilitymgr:abilityms", + "${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", + "//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/formSystemTestServiceD/config.json b/test/resource/formsystemtestability/formSystemTestServiceD/config.json new file mode 100644 index 0000000000000000000000000000000000000000..bda4f9975f4d45c22e027a8c7f17e81d6d327e7c --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceD/config.json @@ -0,0 +1,87 @@ +{ + "app": { + "bundleName": "com.form.formsystemtestserviced", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.form.formsystemtestserviced", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "formmodule001", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "name": "FormStServiceAbilityD", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "service", + "launchType": "standard", + "formsEnabled": true, + "srcLanguage": "c++", + "forms": [ + { + "name": "Form_Js001", + "description": "form_description", + "isDefault": true, + "type": "JS", + "colorMode": "auto", + "supportDimensions":[ "1*2", "2*2" ], + "defaultDimension": "1*2", + "updateEnabled": true, + "scheduledUpdateTime": "10:30", + "updateDuration": 1, + "jsComponentName": "card", + "formVisibleNotify" : false, + "metaData": { + "customizeData": [ + { + "name": "originWidgetName", + "value": "myTest" + } + ] + } + } + ] + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/formSystemTestServiceD/include/form_st_service_ability_D.h b/test/resource/formsystemtestability/formSystemTestServiceD/include/form_st_service_ability_D.h new file mode 100644 index 0000000000000000000000000000000000000000..a0d8e46a9f110ffc466f7ad3b2a95b6b0110e345 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceD/include/form_st_service_ability_D.h @@ -0,0 +1,142 @@ +/* + * 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_SERVICE_ABILITY_D_ +#define FORM_ST_SERVICE_ABILITY_D_ +#include +#include +#include "ability_connect_callback_stub.h" +#include "ability_connect_callback_proxy.h" +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_info.h" + +namespace OHOS { +namespace AppExecFwk { +using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; +const std::string APP_A_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_b"; +const std::string APP_A_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_b"; +const std::string COMMON_EVENT_TEST_ACTION1 = "usual.event.test1"; +/** + * Form event trigger result + */ +typedef enum { + FORM_EVENT_TRIGGER_RESULT_NG = 0, + FORM_EVENT_TRIGGER_RESULT_OK = 1, +} FORM_EVENT_TRIGGER_RESULT; + +class FormStServiceAbilityD : public Ability { +public: + ~FormStServiceAbilityD(); + +protected: + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + virtual void OnNewWant(const Want &want) override; + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; + virtual sptr OnConnect(const Want &want) override; + virtual void OnDisconnect(const Want &want) override; + virtual FormProviderInfo OnCreate(const Want &want) override; + virtual void OnUpdate(const int64_t formId) override; + virtual void OnTriggerEvent(const int64_t formId, const std::string &message) override; + virtual void OnDelete(const int64_t formId) override; + virtual void OnCastTemptoNormal(const int64_t formId) override; + virtual void OnVisibilityChanged(const std::map &formEventsMap) override; + +private: + void Clear(); + void GetWantInfo(const Want &want); + std::vector Split(std::string str, const std::string &token); + bool SubscribeEvent(); + static bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + void StartOtherAbility(); + void ConnectOtherAbility(); + void DisConnectOtherAbility(); + void StopSelfAbility(); + + std::string shouldReturn_ = {}; + std::string targetBundle_ = {}; + std::string targetAbility_ = {}; + std::string nextTargetBundle_ = {}; + std::string nextTargetAbility_ = {}; + std::string targetBundleConn_ = {}; + std::string targetAbilityConn_ = {}; + std::string nextTargetBundleConn_ = {}; + std::string nextTargetAbilityConn_ = {}; + std::string zombie_ = {}; + + typedef void (FormStServiceAbilityD::*func)(); + static std::map funcMap_; + class AbilityConnectCallback; + sptr stub_ = {}; + sptr connCallback_ = {}; + class AppEventSubscriber; + std::shared_ptr subscriber_ = {}; + + class AbilityConnectCallback : public AbilityConnectionStub { + public: + sptr AsObject() override + { + return nullptr; + } + /** + * OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element,.service ability's ElementName. + * @param remoteObject,.the session proxy of service ability. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount++; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityConnectDone"); + } + } + + /** + * OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect. + * + * @param element,.service ability's ElementName. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount--; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityDisconnectDone"); + } + } + + static int onAbilityConnectDoneCount; + }; + class AppEventSubscriber : public EventFwk::CommonEventSubscriber { + public: + AppEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + ~AppEventSubscriber() = default; + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + + FormStServiceAbilityD *mainAbility_ = nullptr; + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FORM_ST_SERVICE_ABILITY_D_ diff --git a/test/resource/formsystemtestability/formSystemTestServiceD/src/form_st_service_ability_D.cpp b/test/resource/formsystemtestability/formSystemTestServiceD/src/form_st_service_ability_D.cpp new file mode 100644 index 0000000000000000000000000000000000000000..564a083f8f5070eaeb4dbbb13ba3da6f104057b7 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceD/src/form_st_service_ability_D.cpp @@ -0,0 +1,375 @@ +/* + * 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_st_service_ability_D.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_client.h" + +using namespace OHOS::EventFwk; + +namespace OHOS { +namespace AppExecFwk { +constexpr int64_t SEC_TO_MILLISEC = 1000; +constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; + +int FormStServiceAbilityD::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +std::map FormStServiceAbilityD::funcMap_ = { + {"StartOtherAbility", &FormStServiceAbilityD::StartOtherAbility}, + {"ConnectOtherAbility", &FormStServiceAbilityD::ConnectOtherAbility}, + {"DisConnectOtherAbility", &FormStServiceAbilityD::DisConnectOtherAbility}, + {"StopSelfAbility", &FormStServiceAbilityD::StopSelfAbility}, +}; + +FormStServiceAbilityD::~FormStServiceAbilityD() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +std::vector FormStServiceAbilityD::Split(std::string str, const std::string &token) +{ + APP_LOGI("FormStServiceAbilityD::Split"); + + std::vector splitString; + while (str.size()) { + size_t index = str.find(token); + if (index != std::string::npos) { + splitString.push_back(str.substr(0, index)); + str = str.substr(index + token.size()); + if (str.size() == 0) { + splitString.push_back(str); + } + } else { + splitString.push_back(str); + str = ""; + } + } + return splitString; +} +void FormStServiceAbilityD::StartOtherAbility() +{ + APP_LOGI("FormStServiceAbilityD::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", + targetBundle_.c_str(), + targetAbility_.c_str()); + APP_LOGI("FormStServiceAbilityD::StartOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + if (!targetBundle_.empty() && !targetAbility_.empty()) { + std::vector strtargetBundles = Split(targetBundle_, ","); + std::vector strTargetAbilitys = Split(targetAbility_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + StartAbility(want); + sleep(1); + } + } +} +void FormStServiceAbilityD::ConnectOtherAbility() +{ + APP_LOGI( + "FormStServiceAbilityD::ConnectOtherAbility begin targetBundleConn=%{public}s, targetAbilityConn=%{public}s", + targetBundleConn_.c_str(), + targetAbilityConn_.c_str()); + APP_LOGI("FormStServiceAbilityD::ConnectOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + // connect service ability + if (!targetBundleConn_.empty() && !targetAbilityConn_.empty()) { + std::vector strtargetBundles = Split(targetBundleConn_, ","); + std::vector strTargetAbilitys = Split(targetAbilityConn_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + APP_LOGI("FormStServiceAbilityD::ConnectOtherAbility->ConnectAbility"); + bool ret = ConnectAbility(want, connCallback_); + sleep(1); + if (!ret) { + APP_LOGE("FormStServiceAbilityD::ConnectAbility failed!"); + } + } + } +} +void FormStServiceAbilityD::DisConnectOtherAbility() +{ + APP_LOGI("FormStServiceAbilityD::DisConnectOtherAbility begin"); + if (connCallback_ != nullptr) { + DisconnectAbility(connCallback_); + sleep(1); + } + APP_LOGI("FormStServiceAbilityD::DisConnectOtherAbility end"); +} + +void FormStServiceAbilityD::StopSelfAbility() +{ + APP_LOGI("FormStServiceAbilityD::StopSelfAbility"); + + TerminateAbility(); +} + +void FormStServiceAbilityD::OnStart(const Want &want) +{ + APP_LOGI("FormStServiceAbilityD::OnStart"); + + GetWantInfo(want); + Ability::OnStart(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); + SubscribeEvent(); + + // make exception for test + if (!zombie_.empty()) { + std::unique_ptr pWant = nullptr; + pWant->GetScheme(); + } +} +void FormStServiceAbilityD::OnCommand(const AAFwk::Want &want, bool restart, int startId) +{ + APP_LOGI("FormStServiceAbilityD::OnCommand"); + + GetWantInfo(want); + Ability::OnCommand(want, restart, startId); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); +} +void FormStServiceAbilityD::OnNewWant(const Want &want) +{ + APP_LOGI("FormStServiceAbilityD::OnNewWant"); + + GetWantInfo(want); + Ability::OnNewWant(want); +} +void FormStServiceAbilityD::OnStop() +{ + APP_LOGI("FormStServiceAbilityD::OnStop"); + + Ability::OnStop(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); +} +void FormStServiceAbilityD::OnActive() +{ + APP_LOGI("FormStServiceAbilityD::OnActive"); + + Ability::OnActive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); +} +void FormStServiceAbilityD::OnInactive() +{ + APP_LOGI("FormStServiceAbilityD::OnInactive"); + + Ability::OnInactive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); +} +void FormStServiceAbilityD::OnBackground() +{ + APP_LOGI("FormStServiceAbilityD::OnBackground"); + + Ability::OnBackground(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); +} + +void FormStServiceAbilityD::Clear() +{ + shouldReturn_ = ""; + targetBundle_ = ""; + targetAbility_ = ""; + targetBundleConn_ = ""; + targetAbilityConn_ = ""; + nextTargetBundle_ = ""; + nextTargetAbility_ = ""; + nextTargetBundleConn_ = ""; + nextTargetAbilityConn_ = ""; +} +void FormStServiceAbilityD::GetWantInfo(const Want &want) +{ + Want mWant(want); + shouldReturn_ = mWant.GetStringParam("shouldReturn"); + targetBundle_ = mWant.GetStringParam("targetBundle"); + targetAbility_ = mWant.GetStringParam("targetAbility"); + targetBundleConn_ = mWant.GetStringParam("targetBundleConn"); + targetAbilityConn_ = mWant.GetStringParam("targetAbilityConn"); + nextTargetBundle_ = mWant.GetStringParam("nextTargetBundle"); + nextTargetAbility_ = mWant.GetStringParam("nextTargetAbility"); + nextTargetBundleConn_ = mWant.GetStringParam("nextTargetBundleConn"); + nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); + zombie_ = mWant.GetStringParam("zombie"); + FormStServiceAbilityD::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +} +bool FormStServiceAbilityD::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + APP_LOGI("FormStServiceAbilityD::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + code, + data.c_str()); + + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} +sptr FormStServiceAbilityD::OnConnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityD::OnConnect"); + + sptr formProviderClient = new (std::nothrow) FormProviderClient(); + std::shared_ptr thisAbility = this->shared_from_this(); + formProviderClient->SetOwner(thisAbility); + + return formProviderClient; +} +void FormStServiceAbilityD::OnDisconnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityD::OnDisconnect"); + + Ability::OnDisconnect(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); +} +bool FormStServiceAbilityD::SubscribeEvent() +{ + MatchingSkills matchingSkills; + matchingSkills.AddEvent(APP_A_REQ_EVENT_NAME); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->mainAbility_ = this; + return CommonEventManager::SubscribeCommonEvent(subscriber_); +} +void FormStServiceAbilityD::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + auto eventName = data.GetWant().GetAction(); + auto dataContent = data.GetData(); + APP_LOGI("FormStServiceAbilityD::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + if (APP_A_REQ_EVENT_NAME.compare(eventName) == 0) { + if (funcMap_.find(dataContent) == funcMap_.end()) { + APP_LOGI( + "FormStServiceAbilityD::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + } else { + if (mainAbility_ != nullptr) { + (mainAbility_->*funcMap_[dataContent])(); + } + } + } +} + +FormProviderInfo FormStServiceAbilityD::OnCreate(const Want &want) +{ + APP_LOGI("%{public}s start", __func__); + FormProviderInfo formProviderInfo; + if (!want.HasParameter(Constants::PARAM_FORM_IDENTITY_KEY)) { + APP_LOGE("%{public}s, formId not exist", __func__); + return formProviderInfo; + } + std::string formId = want.GetStringParam(Constants::PARAM_FORM_IDENTITY_KEY); + std::string jsonData = std::string("{\"city\":\"beijingD\"}"); + FormProviderData formProviderData = FormProviderData(jsonData); + formProviderInfo.SetFormData(formProviderData); + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnCreate"); + APP_LOGI("%{public}s end, formId: %{public}s", __func__, formId.c_str()); + return formProviderInfo; +} + +void FormStServiceAbilityD::OnUpdate(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnUpdate"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityD::OnTriggerEvent(const int64_t formId, const std::string &message) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnTriggerEvent"); + APP_LOGI("%{public}s end, formId: %{public}s, message: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), message.c_str(), currentTime); +} + +void FormStServiceAbilityD::OnDelete(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnDelete"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityD::OnCastTemptoNormal(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnCastTemptoNormal"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityD::OnVisibilityChanged(const std::map &formEventsMap) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnVisibilityChanged"); + APP_LOGI("%{public}s end, current time: %{public}ld", __func__, currentTime); +} + +REGISTER_AA(FormStServiceAbilityD); +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/resource/formsystemtestability/formSystemTestServiceE/BUILD.gn b/test/resource/formsystemtestability/formSystemTestServiceE/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dc9ee0a621153717d10009dbd8e5a91ec8a98f6a --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceE/BUILD.gn @@ -0,0 +1,58 @@ +# 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") +subdemosystem_path = "${appexecfwk_path}/test/resource/formsystemtestability/formSystemTestServiceE" +config("formSystemTestEConfig") { + visibility = [ ":*" ] + include_dirs = [ + "${subdemosystem_path}/include", + "${appexecfwk_path}/kits/appkit/native/app", + "${aafwk_path}/interfaces/innerkits/want/include/ohos/aafwk/content", + "${aafwk_path}/interfaces/innerkits/ability_manager/include", + "${appexecfwk_path}/interfaces/innerkits/libeventhandler/include", + "${appexecfwk_path}/services/bundlemgr/include", + "${aafwk_path}/services/abilitymgr/include", + "${appexecfwk_path}/common/log/include", + "//foundation/distributedschedule/services/dtbschedmgr/include", + "${even_path}/cesfwk/innerkits/include", + "${even_path}/cesfwk/kits/native/include", + ] + defines = [ + "APP_LOG_TAG = \"formSystemTestServiceE\"", + "LOG_DOMAIN = 0xD002200", + ] +} +ohos_shared_library("formSystemTestServiceE") { + sources = [ "${subdemosystem_path}/src/form_st_service_ability_E.cpp" ] + configs = [ ":formSystemTestEConfig" ] + deps = [ + "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native", + "${aafwk_path}/interfaces/innerkits/want:want", + "${aafwk_path}/services/abilitymgr:abilityms", + "${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", + "//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/formSystemTestServiceE/config.json b/test/resource/formsystemtestability/formSystemTestServiceE/config.json new file mode 100644 index 0000000000000000000000000000000000000000..9bf48e647281548ed8d7250fa78ab0c17d689586 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceE/config.json @@ -0,0 +1,87 @@ +{ + "app": { + "bundleName": "com.form.formsystemtestservicee", + "vendor": "ohos", + "version": { + "code": 1, + "name": "1.0" + }, + "apiVersion": { + "compatible": 5, + "target": 5, + "releaseType": "Beta1" + } + }, + "deviceConfig": {}, + "module": { + "package": "com.form.formsystemtestservicee", + "name": ".MyApplication", + "deviceType": [ + "phone" + ], + "distro": { + "deliveryWithInstall": true, + "moduleName": "formmodule001", + "moduleType": "entry" + }, + "abilities": [ + { + "skills": [ + { + "entities": [ + "entity.system.home" + ], + "actions": [ + "action.system.home" + ] + } + ], + "visible": true, + "name": "FormStServiceAbilityE", + "icon": "$media:icon", + "description": "$string:mainability_description", + "label": "$string:entry_MainAbility", + "type": "service", + "launchType": "standard", + "formsEnabled": true, + "srcLanguage": "c++", + "forms": [ + { + "name": "Form_Js001", + "description": "form_description", + "isDefault": true, + "type": "JS", + "colorMode": "auto", + "supportDimensions":[ "1*2", "2*2" ], + "defaultDimension": "1*2", + "updateEnabled": true, + "scheduledUpdateTime": "0:0", + "updateDuration": 1, + "jsComponentName": "card", + "formVisibleNotify" : true, + "metaData": { + "customizeData": [ + { + "name": "originWidgetName", + "value": "myTest" + } + ] + } + } + ] + } + ], + "js": [ + { + "pages": [ + "pages/index/index" + ], + "name": "default", + "window": { + "designWidth": 720, + "autoDesignWidth": true + } + } + ] + } +} \ No newline at end of file diff --git a/test/resource/formsystemtestability/formSystemTestServiceE/include/form_st_service_ability_E.h b/test/resource/formsystemtestability/formSystemTestServiceE/include/form_st_service_ability_E.h new file mode 100644 index 0000000000000000000000000000000000000000..a84bc3862a5e4581a1e4ce728eadc30c049da7b7 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceE/include/form_st_service_ability_E.h @@ -0,0 +1,142 @@ +/* + * 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_SERVICE_ABILITY_E_ +#define FORM_ST_SERVICE_ABILITY_E_ +#include +#include +#include "ability_connect_callback_stub.h" +#include "ability_connect_callback_proxy.h" +#include "ability_loader.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_info.h" + +namespace OHOS { +namespace AppExecFwk { +using AbilityConnectionStub = OHOS::AAFwk::AbilityConnectionStub; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; +const std::string APP_A_RESP_EVENT_NAME = "resp_com_ohos_formst_service_app_b"; +const std::string APP_A_REQ_EVENT_NAME = "req_com_ohos_formst_service_app_b"; +const std::string COMMON_EVENT_TEST_ACTION1 = "usual.event.test1"; +/** + * Form event trigger result + */ +typedef enum { + FORM_EVENT_TRIGGER_RESULT_NG = 0, + FORM_EVENT_TRIGGER_RESULT_OK = 1, +} FORM_EVENT_TRIGGER_RESULT; + +class FormStServiceAbilityE : public Ability { +public: + ~FormStServiceAbilityE(); + +protected: + virtual void OnStart(const Want &want) override; + virtual void OnStop() override; + virtual void OnActive() override; + virtual void OnInactive() override; + virtual void OnBackground() override; + virtual void OnNewWant(const Want &want) override; + virtual void OnCommand(const AAFwk::Want &want, bool restart, int startId) override; + virtual sptr OnConnect(const Want &want) override; + virtual void OnDisconnect(const Want &want) override; + virtual FormProviderInfo OnCreate(const Want &want) override; + virtual void OnUpdate(const int64_t formId) override; + virtual void OnTriggerEvent(const int64_t formId, const std::string &message) override; + virtual void OnDelete(const int64_t formId) override; + virtual void OnCastTemptoNormal(const int64_t formId) override; + virtual void OnVisibilityChanged(const std::map &formEventsMap) override; + +private: + void Clear(); + void GetWantInfo(const Want &want); + std::vector Split(std::string str, const std::string &token); + bool SubscribeEvent(); + static bool PublishEvent(const std::string &eventName, const int &code, const std::string &data); + void StartOtherAbility(); + void ConnectOtherAbility(); + void DisConnectOtherAbility(); + void StopSelfAbility(); + + std::string shouldReturn_ = {}; + std::string targetBundle_ = {}; + std::string targetAbility_ = {}; + std::string nextTargetBundle_ = {}; + std::string nextTargetAbility_ = {}; + std::string targetBundleConn_ = {}; + std::string targetAbilityConn_ = {}; + std::string nextTargetBundleConn_ = {}; + std::string nextTargetAbilityConn_ = {}; + std::string zombie_ = {}; + + typedef void (FormStServiceAbilityE::*func)(); + static std::map funcMap_; + class AbilityConnectCallback; + sptr stub_ = {}; + sptr connCallback_ = {}; + class AppEventSubscriber; + std::shared_ptr subscriber_ = {}; + + class AbilityConnectCallback : public AbilityConnectionStub { + public: + sptr AsObject() override + { + return nullptr; + } + /** + * OnAbilityConnectDone, AbilityMs notify caller ability the result of connect. + * + * @param element,.service ability's ElementName. + * @param remoteObject,.the session proxy of service ability. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityConnectDone( + const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount++; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityConnectDone"); + } + } + + /** + * OnAbilityDisconnectDone, AbilityMs notify caller ability the result of disconnect. + * + * @param element,.service ability's ElementName. + * @param resultCode, ERR_OK on success, others on failure. + */ + void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override + { + if (resultCode == 0) { + onAbilityConnectDoneCount--; + PublishEvent(APP_A_RESP_EVENT_NAME, onAbilityConnectDoneCount, "OnAbilityDisconnectDone"); + } + } + + static int onAbilityConnectDoneCount; + }; + class AppEventSubscriber : public EventFwk::CommonEventSubscriber { + public: + AppEventSubscriber(const EventFwk::CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp) {}; + ~AppEventSubscriber() = default; + virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; + + FormStServiceAbilityE *mainAbility_ = nullptr; + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // FORM_ST_SERVICE_ABILITY_E_ diff --git a/test/resource/formsystemtestability/formSystemTestServiceE/src/form_st_service_ability_E.cpp b/test/resource/formsystemtestability/formSystemTestServiceE/src/form_st_service_ability_E.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6dcbaeb598586a5f04a2c8f68da65046ae14b990 --- /dev/null +++ b/test/resource/formsystemtestability/formSystemTestServiceE/src/form_st_service_ability_E.cpp @@ -0,0 +1,375 @@ +/* + * 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_st_service_ability_E.h" +#include "app_log_wrapper.h" +#include "common_event.h" +#include "common_event_manager.h" +#include "form_provider_client.h" + +using namespace OHOS::EventFwk; + +namespace OHOS { +namespace AppExecFwk { +constexpr int64_t SEC_TO_MILLISEC = 1000; +constexpr int64_t MILLISEC_TO_NANOSEC = 1000000; +using AbilityConnectionProxy = OHOS::AAFwk::AbilityConnectionProxy; + +int FormStServiceAbilityE::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +std::map FormStServiceAbilityE::funcMap_ = { + {"StartOtherAbility", &FormStServiceAbilityE::StartOtherAbility}, + {"ConnectOtherAbility", &FormStServiceAbilityE::ConnectOtherAbility}, + {"DisConnectOtherAbility", &FormStServiceAbilityE::DisConnectOtherAbility}, + {"StopSelfAbility", &FormStServiceAbilityE::StopSelfAbility}, +}; + +FormStServiceAbilityE::~FormStServiceAbilityE() +{ + CommonEventManager::UnSubscribeCommonEvent(subscriber_); +} + +std::vector FormStServiceAbilityE::Split(std::string str, const std::string &token) +{ + APP_LOGI("FormStServiceAbilityE::Split"); + + std::vector splitString; + while (str.size()) { + size_t index = str.find(token); + if (index != std::string::npos) { + splitString.push_back(str.substr(0, index)); + str = str.substr(index + token.size()); + if (str.size() == 0) { + splitString.push_back(str); + } + } else { + splitString.push_back(str); + str = ""; + } + } + return splitString; +} +void FormStServiceAbilityE::StartOtherAbility() +{ + APP_LOGI("FormStServiceAbilityE::StartOtherAbility begin targetBundle=%{public}s, targetAbility=%{public}s", + targetBundle_.c_str(), + targetAbility_.c_str()); + APP_LOGI("FormStServiceAbilityE::StartOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + if (!targetBundle_.empty() && !targetAbility_.empty()) { + std::vector strtargetBundles = Split(targetBundle_, ","); + std::vector strTargetAbilitys = Split(targetAbility_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + StartAbility(want); + sleep(1); + } + } +} +void FormStServiceAbilityE::ConnectOtherAbility() +{ + APP_LOGI( + "FormStServiceAbilityE::ConnectOtherAbility begin targetBundleConn=%{public}s, targetAbilityConn=%{public}s", + targetBundleConn_.c_str(), + targetAbilityConn_.c_str()); + APP_LOGI("FormStServiceAbilityE::ConnectOtherAbility begin nextTargetBundleConn=%{public}s, " + "nextTargetAbilityConn=%{public}s", + nextTargetBundleConn_.c_str(), + nextTargetAbilityConn_.c_str()); + + // connect service ability + if (!targetBundleConn_.empty() && !targetAbilityConn_.empty()) { + std::vector strtargetBundles = Split(targetBundleConn_, ","); + std::vector strTargetAbilitys = Split(targetAbilityConn_, ","); + for (size_t i = 0; i < strtargetBundles.size() && i < strTargetAbilitys.size(); i++) { + Want want; + want.SetElementName(strtargetBundles[i], strTargetAbilitys[i]); + want.SetParam("shouldReturn", shouldReturn_); + want.SetParam("targetBundle", nextTargetBundle_); + want.SetParam("targetAbility", nextTargetAbility_); + want.SetParam("targetBundleConn", nextTargetBundleConn_); + want.SetParam("targetAbilityConn", nextTargetAbilityConn_); + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + APP_LOGI("FormStServiceAbilityE::ConnectOtherAbility->ConnectAbility"); + bool ret = ConnectAbility(want, connCallback_); + sleep(1); + if (!ret) { + APP_LOGE("FormStServiceAbilityE::ConnectAbility failed!"); + } + } + } +} +void FormStServiceAbilityE::DisConnectOtherAbility() +{ + APP_LOGI("FormStServiceAbilityE::DisConnectOtherAbility begin"); + if (connCallback_ != nullptr) { + DisconnectAbility(connCallback_); + sleep(1); + } + APP_LOGI("FormStServiceAbilityE::DisConnectOtherAbility end"); +} + +void FormStServiceAbilityE::StopSelfAbility() +{ + APP_LOGI("FormStServiceAbilityE::StopSelfAbility"); + + TerminateAbility(); +} + +void FormStServiceAbilityE::OnStart(const Want &want) +{ + APP_LOGI("FormStServiceAbilityE::OnStart"); + + GetWantInfo(want); + Ability::OnStart(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnStart"); + SubscribeEvent(); + + // make exception for test + if (!zombie_.empty()) { + std::unique_ptr pWant = nullptr; + pWant->GetScheme(); + } +} +void FormStServiceAbilityE::OnCommand(const AAFwk::Want &want, bool restart, int startId) +{ + APP_LOGI("FormStServiceAbilityE::OnCommand"); + + GetWantInfo(want); + Ability::OnCommand(want, restart, startId); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnCommand"); +} +void FormStServiceAbilityE::OnNewWant(const Want &want) +{ + APP_LOGI("FormStServiceAbilityE::OnNewWant"); + + GetWantInfo(want); + Ability::OnNewWant(want); +} +void FormStServiceAbilityE::OnStop() +{ + APP_LOGI("FormStServiceAbilityE::OnStop"); + + Ability::OnStop(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INITIAL, "OnStop"); +} +void FormStServiceAbilityE::OnActive() +{ + APP_LOGI("FormStServiceAbilityE::OnActive"); + + Ability::OnActive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::ACTIVE, "OnActive"); +} +void FormStServiceAbilityE::OnInactive() +{ + APP_LOGI("FormStServiceAbilityE::OnInactive"); + + Ability::OnInactive(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::INACTIVE, "OnInactive"); +} +void FormStServiceAbilityE::OnBackground() +{ + APP_LOGI("FormStServiceAbilityE::OnBackground"); + + Ability::OnBackground(); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnBackground"); +} + +void FormStServiceAbilityE::Clear() +{ + shouldReturn_ = ""; + targetBundle_ = ""; + targetAbility_ = ""; + targetBundleConn_ = ""; + targetAbilityConn_ = ""; + nextTargetBundle_ = ""; + nextTargetAbility_ = ""; + nextTargetBundleConn_ = ""; + nextTargetAbilityConn_ = ""; +} +void FormStServiceAbilityE::GetWantInfo(const Want &want) +{ + Want mWant(want); + shouldReturn_ = mWant.GetStringParam("shouldReturn"); + targetBundle_ = mWant.GetStringParam("targetBundle"); + targetAbility_ = mWant.GetStringParam("targetAbility"); + targetBundleConn_ = mWant.GetStringParam("targetBundleConn"); + targetAbilityConn_ = mWant.GetStringParam("targetAbilityConn"); + nextTargetBundle_ = mWant.GetStringParam("nextTargetBundle"); + nextTargetAbility_ = mWant.GetStringParam("nextTargetAbility"); + nextTargetBundleConn_ = mWant.GetStringParam("nextTargetBundleConn"); + nextTargetAbilityConn_ = mWant.GetStringParam("nextTargetAbilityConn"); + zombie_ = mWant.GetStringParam("zombie"); + FormStServiceAbilityE::AbilityConnectCallback::onAbilityConnectDoneCount = 0; +} +bool FormStServiceAbilityE::PublishEvent(const std::string &eventName, const int &code, const std::string &data) +{ + APP_LOGI("FormStServiceAbilityE::PublishEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + code, + data.c_str()); + + Want want; + want.SetAction(eventName); + CommonEventData commonData; + commonData.SetWant(want); + commonData.SetCode(code); + commonData.SetData(data); + return CommonEventManager::PublishCommonEvent(commonData); +} +sptr FormStServiceAbilityE::OnConnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityE::OnConnect"); + + sptr formProviderClient = new (std::nothrow) FormProviderClient(); + std::shared_ptr thisAbility = this->shared_from_this(); + formProviderClient->SetOwner(thisAbility); + + return formProviderClient; +} +void FormStServiceAbilityE::OnDisconnect(const Want &want) +{ + APP_LOGI("FormStServiceAbilityE::OnDisconnect"); + + Ability::OnDisconnect(want); + PublishEvent(APP_A_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); +} +bool FormStServiceAbilityE::SubscribeEvent() +{ + MatchingSkills matchingSkills; + matchingSkills.AddEvent(APP_A_REQ_EVENT_NAME); + CommonEventSubscribeInfo subscribeInfo(matchingSkills); + subscribeInfo.SetPriority(1); + subscriber_ = std::make_shared(subscribeInfo); + subscriber_->mainAbility_ = this; + return CommonEventManager::SubscribeCommonEvent(subscriber_); +} +void FormStServiceAbilityE::AppEventSubscriber::OnReceiveEvent(const CommonEventData &data) +{ + auto eventName = data.GetWant().GetAction(); + auto dataContent = data.GetData(); + APP_LOGI("FormStServiceAbilityE::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + if (APP_A_REQ_EVENT_NAME.compare(eventName) == 0) { + if (funcMap_.find(dataContent) == funcMap_.end()) { + APP_LOGI( + "FormStServiceAbilityE::OnReceiveEvent eventName = %{public}s, code = %{public}d, data = %{public}s", + eventName.c_str(), + data.GetCode(), + dataContent.c_str()); + } else { + if (mainAbility_ != nullptr) { + (mainAbility_->*funcMap_[dataContent])(); + } + } + } +} + +FormProviderInfo FormStServiceAbilityE::OnCreate(const Want &want) +{ + APP_LOGI("%{public}s start", __func__); + FormProviderInfo formProviderInfo; + if (!want.HasParameter(Constants::PARAM_FORM_IDENTITY_KEY)) { + APP_LOGE("%{public}s, formId not exist", __func__); + return formProviderInfo; + } + std::string formId = want.GetStringParam(Constants::PARAM_FORM_IDENTITY_KEY); + std::string jsonData = std::string("{\"city\":\"beijingE\"}"); + FormProviderData formProviderData = FormProviderData(jsonData); + formProviderInfo.SetFormData(formProviderData); + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnCreate"); + APP_LOGI("%{public}s end, formId: %{public}s", __func__, formId.c_str()); + return formProviderInfo; +} + +void FormStServiceAbilityE::OnUpdate(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnUpdate"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityE::OnTriggerEvent(const int64_t formId, const std::string &message) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnTriggerEvent"); + APP_LOGI("%{public}s end, formId: %{public}s, message: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), message.c_str(), currentTime); +} + +void FormStServiceAbilityE::OnDelete(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, "OnDelete"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityE::OnCastTemptoNormal(const int64_t formId) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnCastTemptoNormal"); + APP_LOGI("%{public}s end, formId: %{public}s, current time: %{public}ld", __func__, + std::to_string(formId).c_str(), currentTime); +} + +void FormStServiceAbilityE::OnVisibilityChanged(const std::map &formEventsMap) +{ + APP_LOGI("%{public}s start", __func__); + + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + long currentTime = ts.tv_sec * SEC_TO_MILLISEC + ts.tv_nsec / MILLISEC_TO_NANOSEC; + + PublishEvent(COMMON_EVENT_TEST_ACTION1, FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK, + "OnVisibilityChanged"); + APP_LOGI("%{public}s end, current time: %{public}ld", __func__, currentTime); +} + +REGISTER_AA(FormStServiceAbilityE); +} // namespace AppExecFwk +} // namespace OHOS 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..abd18104282787ed1da6b56fd14b127fd0601180 --- /dev/null +++ b/test/systemtest/common/fms/BUILD.gn @@ -0,0 +1,41 @@ +# 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_acquire_form_test_max: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..703f29eae9abf04bc4c5543432eb556a654da877 --- /dev/null +++ b/test/systemtest/common/fms/common/include/form_st_common_info.h @@ -0,0 +1,428 @@ +/* + * 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 = "FormStServiceAbilityA"; +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 = "FormStServiceAbilityB"; +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"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2800 = "fms_req_acquireForm_2800"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2800 = "fms_recv_acquireForm_2800"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2900 = "fms_req_acquireForm_2900"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2900 = "fms_recv_acquireForm_2900"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_2900_1 = "fms_req_acquireForm_2900_1"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_2900_1 = "fms_recv_acquireForm_2900_1"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3000 = "fms_req_acquireForm_3000"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3000 = "fms_recv_acquireForm_3000"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3100 = "fms_req_acquireForm_3100"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3100 = "fms_recv_acquireForm_3100"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3200 = "fms_req_acquireForm_3200"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3200 = "fms_recv_acquireForm_3200"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_3300 = "fms_req_acquireForm_3300"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_3300 = "fms_recv_acquireForm_3300"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_BATCH = "fms_req_acquireForm_batch"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_BATCH = "fms_recv_acquireForm_batch"; +const std::string FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B = "fms_req_acquireForm_batch_b"; +const std::string FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B = "fms_recv_acquireForm_batch_b"; +const std::string FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH = "fms_req_acquireFormTemp_batch"; +const std::string FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH = "fms_recv_acquireFormTemp_batch"; +const std::string FORM_EVENT_REQ_CLEAR_FORM_BATCH = "fms_req_clearForm_batch"; +const std::string FORM_EVENT_RECV_CLEAR_FORM_BATCH = "fms_recv_clearForm_batch"; + + +// 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_1201 = "fms_req_deleteForm_1201"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1201 = "fms_recv_deleteForm_1201"; +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_1401 = "fms_req_deleteForm_1401"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1401 = "fms_recv_deleteForm_1401"; +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_1501 = "fms_req_deleteForm_1501"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1501 = "fms_recv_deleteForm_1501"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1502 = "fms_req_deleteForm_1502"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1502 = "fms_recv_deleteForm_1502"; +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_1601 = "fms_req_deleteForm_1601"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1601 = "fms_recv_deleteForm_1601"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1602 = "fms_req_deleteForm_1602"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1602 = "fms_recv_deleteForm_1602"; +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"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1701 = "fms_req_deleteForm_1701"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1701 = "fms_recv_deleteForm_1701"; +const std::string FORM_EVENT_REQ_DELETE_FORM_1702 = "fms_req_deleteForm_1702"; +const std::string FORM_EVENT_RECV_DELETE_FORM_1702 = "fms_recv_deleteForm_1702"; +// OnDelete +const std::string COMMON_EVENT_ON_DELETE = "usual.event.ondelete"; +typedef enum { + FORM_EVENT_TRIGGER_RESULT_NG = 0, + FORM_EVENT_TRIGGER_RESULT_OK = 1, +} FORM_EVENT_TRIGGER_RESULT; + +// 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"; +const std::string FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL = "fms_req_releaseForm_common_del"; +const std::string FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL = "fms_recv_releaseForm_common_del"; + +// 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"; +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL = "fms_req_one_normal_form_del"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL = "fms_recv_one_normal_form_del"; + +// CommonB(acquire one normal form) +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_B = "fms_req_one_normal_form_b"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_B = "fms_recv_one_normal_form_b"; +const std::string FORM_EVENT_REQ_ONE_NORMAL_FORM_B_DEL = "fms_req_one_normal_form_b_del"; +const std::string FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL = "fms_recv_one_normal_form_b_del"; + +// 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"; + +// Uninstall App Test +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0100 = "fms_req_uninstallTest_0100"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0100 = "fms_recv_uninstallTest_0100"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0200 = "fms_req_uninstallTest_0200"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0200 = "fms_recv_uninstallTest_0200"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0300 = "fms_req_uninstallTest_0300"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0300 = "fms_recv_uninstallTest_0300"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0400 = "fms_req_uninstallTest_0400"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0400 = "fms_recv_uninstallTest_0400"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0500 = "fms_req_uninstallTest_0500"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0500 = "fms_recv_uninstallTest_0500"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0600 = "fms_req_uninstallTest_0600"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0600 = "fms_recv_uninstallTest_0600"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0700 = "fms_req_uninstallTest_0700"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0700 = "fms_recv_uninstallTest_0700"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0800 = "fms_req_uninstallTest_0800"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0800 = "fms_recv_uninstallTest_0800"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_0900 = "fms_req_uninstallTest_0900"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_0900 = "fms_recv_uninstallTest_0900"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1000 = "fms_req_uninstallTest_1000"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1000 = "fms_recv_uninstallTest_1000"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1100 = "fms_req_uninstallTest_1100"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1100 = "fms_recv_uninstallTest_1100"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1200 = "fms_req_uninstallTest_1200"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1200 = "fms_recv_uninstallTest_1200"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1300 = "fms_req_uninstallTest_1300"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1300 = "fms_recv_uninstallTest_1300"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1400 = "fms_req_uninstallTest_1400"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1400 = "fms_recv_uninstallTest_1400"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1500 = "fms_req_uninstallTest_1500"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1500 = "fms_recv_uninstallTest_1500"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1600 = "fms_req_uninstallTest_1600"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1600 = "fms_recv_uninstallTest_1600"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1700 = "fms_req_uninstallTest_1700"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1700 = "fms_recv_uninstallTest_1700"; +const std::string FORM_EVENT_REQ_UNINSTALL_TEST_1800 = "fms_req_uninstallTest_1800"; +const std::string FORM_EVENT_RECV_UNINSTALL_TEST_1800 = "fms_recv_uninstallTest_1800"; + +// common event data code +const int EVENT_CODE_100 = 100; +const int EVENT_CODE_101 = 101; +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_1401 = 1401; +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_1701 = 1701; +const int EVENT_CODE_1702 = 1702; +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_2800 = 2800; +const int EVENT_CODE_2900 = 2900; +const int EVENT_CODE_2901 = 2901; +const int EVENT_CODE_2910 = 2910; +const int EVENT_CODE_2911 = 2911; +const int EVENT_CODE_3000 = 3000; +const int EVENT_CODE_3100 = 3100; +const int EVENT_CODE_3101 = 3101; +const int EVENT_CODE_3200 = 3200; +const int EVENT_CODE_3300 = 3300; +const int EVENT_CODE_3301 = 3301; + +const int EVENT_CODE_BATCH = 9000; +const int EVENT_CODE_BATCH_B = 9010; +const int EVENT_CODE_TEMP_BATCH = 9020; +const int EVENT_CODE_CLEAR_BATCH = 9030; + +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..2e4f801581eb130a7a32053550d293d204accfe5 --- /dev/null +++ b/test/systemtest/common/fms/common/include/system_test_form_util.h @@ -0,0 +1,350 @@ +/* + * 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); + /** + * @brief Query form timer service by form id. + * @param formId The id of the form. + * @return Returns form timer service. + */ + static std::string QueryFormTimerByFormId(const std::int64_t formId); + + /** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns forms count to add. + */ + static int BatchAddFormRecords(const AAFwk::Want &want); + /** + * @brief Clear form records for st limit value test. + * @return Returns forms count to delete. + */ + static int ClearFormRecords(); +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..126817d6d1088d4ed916c721c4a886ec3d6aca3f --- /dev/null +++ b/test/systemtest/common/fms/common/src/system_test_form_util.cpp @@ -0,0 +1,686 @@ +/* + * 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; +} +/** + * @brief Query form timer service by form id. + * @param formId The id of the form. + * @return Returns form timer service. + */ +std::string SystemTestFormUtil::QueryFormTimerByFormId(const std::int64_t formId) +{ + std::cout << "QueryFormTimerByFormId called." << std::endl; + + std::string isTimingService; + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "QueryFormTimerByFormId, failed to write interface token." << std::endl; + return "QueryFormTimerByFormId, failed to write interface token."; + } + if (!data.WriteInt64(formId)) { + std::cout << "QueryFormTimerByFormId, failed to write formId." << std::endl; + return "QueryFormTimerByFormId, failed to write formId."; + } + + int result = GetStringInfo(AppExecFwk::IFormMgr::Message::FORM_MGR_FORM_TIMER_INFO_BY_ID, data, isTimingService); + if (result != ERR_OK) { + std::cout << "QueryFormTimerByFormId, failed to query timer info." << std::endl; + } + + std::cout << "QueryFormTimerByFormId end." << std::endl; + + return isTimingService; +} + +/** + * @brief Batch add forms to form records for st limit value test. + * @param want The want of the form to add. + * @return Returns forms count to add. + */ +int SystemTestFormUtil::BatchAddFormRecords(const AAFwk::Want &want) +{ + sptr remoteObject = GetFmsService(); + if (!remoteObject) { + std::cout << "SendTransactCmd, failed to get remote object." << std::endl; + return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED; + } + + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "BatchAddFormRecords, failed to write interface token." << std::endl; + return ERR_APPEXECFWK_PARCEL_ERROR; + } + if (!data.WriteParcelable(&want)) { + std::cout << "BatchAddFormRecords, failed to write want." << std::endl; + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = remoteObject->SendRequest( + static_cast(IFormMgr::Message::FORM_MGR_BATCH_ADD_FORM_RECORDS_ST), + data, + reply, + option); + if (error != ERR_OK) { + std::cout << "BatchAddFormRecords, failed to SendRequest." << std::endl; + return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; + } + return reply.ReadInt32(); +} + +/** + * @brief Clear form records for st limit value test. + * @return Returns forms count to delete. + */ +int SystemTestFormUtil::ClearFormRecords() +{ + sptr remoteObject = GetFmsService(); + if (!remoteObject) { + std::cout << "SendTransactCmd, failed to get remote object." << std::endl; + return ERR_APPEXECFWK_SERVICE_NOT_CONNECTED; + } + + MessageParcel data; + if (!WriteInterfaceToken(data)) { + std::cout << "BatchAddFormRecords, failed to write interface token." << std::endl; + return ERR_APPEXECFWK_PARCEL_ERROR; + } + + MessageParcel reply; + MessageOption option; + int error = remoteObject->SendRequest( + static_cast(IFormMgr::Message::FORM_MGR_CLEAR_FORM_RECORDS_ST), + data, + reply, + option); + if (error != ERR_OK) { + std::cout << "ClearFormRecords, failed to SendRequest." << std::endl; + return ERR_APPEXECFWK_FORM_SEND_FMS_MSG; + } + return reply.ReadInt32(); +} +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..3fa5bababd4bc678cb1e5f57f8521891c9df4d36 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test/BUILD.gn @@ -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. + +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", + "multimodalinput_base:libmmi-client", + "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..a623fd2547b82551f966ce229ac90cb9effdbc88 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test/fms_acquire_form_test.cpp @@ -0,0 +1,1199 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.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.form.formsystemtestservicea", + "com.form.formsystemtestserviceb", +}; +std::vector hapNameList = { + "fmsSystemTestHostNotSys-signed", + "formSystemTestServiceA-signed", + "formSystemTestServiceB-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() +{ + 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(1); + 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); + + sleep(1); + FmsAcquireFormDeleteA(strFormId); + std::cout << "END FMS_acquireForm_1500" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_1600 + * @tc.name: A single form host (using a single thread) continuously creates 2 normal and 2 temporary forms. + * @tc.desc: Verify that a single host (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 hosts create one normal form and one temporary form respectively. + * @tc.desc: Verify that multiple hosts 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 host 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 host 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 host is not a system application + * @tc.desc: Failed to create form when verifying that the form host 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 host does not have permission to use the form + * @tc.desc: Failed to create a form when verifying that the form host 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_acquire_form_test_max/BUILD.gn b/test/systemtest/common/fms/fms_acquire_form_test_max/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2a567af5bd5b1094a2b35bb7d016a9474e406e4f --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test_max/BUILD.gn @@ -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. + +import("//build/test.gni") +import("//foundation/appexecfwk/standard/appexecfwk.gni") + +module_output_path = "appexecfwk_standard/formmanagerst" + +ohos_systemtest("FmsAcquireFormTestMax") { + 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_batch.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 = \"FMSAcquireFormTestMax\"" ] + + 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", + "multimodalinput_base:libmmi-client", + "safwk:system_ability_fwk", + "samgr_L2:samgr_proxy", + ] +} + +group("systemtest") { + testonly = true + + deps = [ ":FmsAcquireFormTestMax" ] +} diff --git a/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e8a711b4558cff4e471dadbac116f04c8616f29 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_batch.cpp @@ -0,0 +1,813 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +const int FORM_COUNT_200 = 200; +const int FORM_COUNT_111 = 111; +const int FORM_COUNT_112 = 112; +const int TEMP_FORM_COUNT_256 = 256; +const int TEMP_FORM_COUNT_128 = 128; + +std::vector bundleNameList = { + "com.form.formsystemtestservicea", + "com.form.formsystemtestserviceb", +}; +std::vector hapNameList = { + "formSystemTestServiceA-signed", + "formSystemTestServiceB-signed", +}; + +std::vector normalFormsMaxA; +std::vector normalFormsMaxB; +std::vector normalFormsMaxC; + +std::vector tempFormsMaxA; +std::vector tempFormsMaxB; +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsAcquireFormTestBatch : 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 FmsAcquireForm2700(std::string strFormId); + std::string FmsAcquireForm2900A(); + std::string FmsAcquireForm2900B(); + void FmsAcquireForm3000(); + std::string FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName); + void FmsAcquireForm2800(std::string strFormId); + void FmsAcquireForm3200(); + + void FmsAcquireFormDeleteA(const std::string &strFormId); + void FmsAcquireFormDeleteB(const std::string &strFormId); + void FmsAcquireFormDeleteC(const std::string &strFormId); + std::string FmsAcquireFormTemp(const std::string &bundleName, const std::string &abilityName); + bool FmsAcquireFormTempForFailed(const std::string &bundleName, const std::string &abilityName); + + void FMS_acquireFormBatchA(const std::string &bundleName, const std::string &abilityName, const int count); + void FMS_acquireFormBatchB(const std::string &bundleName, const std::string &abilityName, const int count); + + void FMS_acquireTempFormBatch(const std::string &bundleName, const std::string &abilityName, const int count); + void FMS_deleteFormBatch(); +}; +std::vector FmsAcquireFormTestBatch::eventList = { + FORM_EVENT_RECV_DELETE_FORM_COMMON, FORM_EVENT_ABILITY_ONACTIVED, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, + FORM_EVENT_RECV_ACQUIRE_FORM_2700, FORM_EVENT_RECV_ACQUIRE_FORM_2800, FORM_EVENT_RECV_ACQUIRE_FORM_2900, + FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, FORM_EVENT_RECV_ACQUIRE_FORM_3000, FORM_EVENT_RECV_ACQUIRE_FORM_3100, + FORM_EVENT_RECV_ACQUIRE_FORM_3200, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, + FORM_EVENT_RECV_CLEAR_FORM_BATCH, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, +}; + + +FormEvent FmsAcquireFormTestBatch::event = FormEvent(); +sptr FmsAcquireFormTestBatch::abilityMs = nullptr; +std::shared_ptr FmsAcquireFormTestBatch::subscriber = nullptr; +void FmsAcquireFormTestBatch::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 FmsAcquireFormTestBatch::SetUpTestCase() +{ + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsAcquireFormTestBatch::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "UnSubscribeCommonEvent calld"; + CommonEventManager::UnSubscribeCommonEvent(subscriber); +} + +void FmsAcquireFormTestBatch::SetUp() +{ +} + +void FmsAcquireFormTestBatch::TearDown() +{ + GTEST_LOG_(INFO) << "CleanMsg calld"; + SystemTestFormUtil::CleanMsg(event); +} +bool FmsAcquireFormTestBatch::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_2900 + * @tc.name: A single host creates 256 different provider forms. + * @tc.desc: The single host can successfully create 256 different provider forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_2900, Function | MediumTest | Level1) +{ + std::cout << "START FMS_acquireForm_2900" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityA"; + int countA = Constants::MAX_RECORD_PER_APP/2; + int countB = Constants::MAX_RECORD_PER_APP/2 - 1; + sleep(1); + FMS_acquireFormBatchA(bundleName, abilityName, countA); + sleep(1); + FMS_acquireFormBatchB(bundleName, abilityName, countB); + int count = Constants::MAX_RECORD_PER_APP - 1; + std::cout << "FMS_acquireForm_2900, form size of the host A:" << count << std::endl; + + sleep(1); + std::string strFormId = FmsAcquireForm2900A(); + normalFormsMaxA.emplace_back(strFormId); + std::cout << "END FMS_acquireForm_2900" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3000 + * @tc.name: Create limit value verification using single party form. + * @tc.desc: Failed to create the 257th host form. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3000, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3000" << std::endl; + std::cout << "FMS_acquireForm_3000, form size of the host A:" << normalFormsMaxA.size() << std::endl; + FmsAcquireForm3000(); + std::cout << "END FMS_acquireForm_3000" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2700 + * @tc.name: When the normal form reaches the maximum value (256) created by the host, + * the temporary form is transferred to the normal form. + * @tc.desc: Verify that when the normal form reaches the maximum value (256) created by the single host, + * the conversion of the temporary form to the normal form fails. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_2700, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2700" << std::endl; + std::cout << "FMS_acquireForm_2700, form size of the host A:" << normalFormsMaxA.size() << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + + sleep(1); + FmsAcquireForm2700(strFormId); + std::cout << "END FMS_acquireForm_2700" << std::endl; + + std::cout << "the host A, delete form start" << std::endl; + if (normalFormsMaxA.size() > 0) { + for (int count = 0; count < normalFormsMaxA.size(); count++) { + FmsAcquireFormDeleteA(normalFormsMaxA[count]); + } + } + sleep(1); + FMS_deleteFormBatch(); + std::cout << "the host A, delete form end" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3100 + * @tc.name: Multiple hosts create 512 forms respectively. + * @tc.desc: Verify that multiple hosts can create 512 forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3100, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3100" << std::endl; + + std::cout << "START add form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireFormBatchA(bundleNameA, abilityNameA, FORM_COUNT_200); + std::cout << "count:" << FORM_COUNT_200 << std::endl; + std::cout << "END add form to the host A" << std::endl; + + sleep(1); + std::cout << "START add form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireFormBatchA(bundleNameB, abilityNameB, FORM_COUNT_200); + std::cout << "count:" << FORM_COUNT_200 << std::endl; + std::cout << "END add form to the host B" << std::endl; + + sleep(1); + std::cout << "START add form to the host C" << std::endl; + std::string bundleNameC = "com.ohos.form.manager.normalc"; + std::string abilityNameC = "FormAbilityC"; + std::cout << "bundleName: " << bundleNameC << std::endl; + std::cout << "abilityName: " << abilityNameC << std::endl; + FMS_acquireFormBatchA(bundleNameC, abilityNameC, FORM_COUNT_111); + std::cout << "count:" << FORM_COUNT_111 << std::endl; + std::cout << "END add form to the host C" << std::endl; + + sleep(1); + std::string formId = FmsAcquireForm3100(bundleNameC, abilityNameC); + normalFormsMaxC.emplace_back(formId); + std::cout << "END FMS_acquireForm_3100" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2800 + * @tc.name: When the normal form reaches the maximum value (512) of the form created by FMS, + * the temporary form will be transferred to the normal form. + * @tc.desc: When the normal form reaches the maximum value (512) created by FMS, + * the conversion of temporary form to normal form fails. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_2800, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_2800" << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host A:" << FORM_COUNT_200 << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host B:" << FORM_COUNT_200 << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host C:" << FORM_COUNT_112 << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + + sleep(1); + FmsAcquireForm2800(strFormId); + + std::cout << "END FMS_acquireForm_2800" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3200 + * @tc.name: FMS create form limit value (512) verification. + * @tc.desc: Verify that 512 forms can be successfully created by creating forms with different users + * (the number of single user forms is less than 256), and the 513rd form fails to be created. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3200, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3200" << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host A:" << FORM_COUNT_200 << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host B:" << FORM_COUNT_200 << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host C:" << FORM_COUNT_112 << std::endl; + FmsAcquireForm3200(); + std::cout << "END FMS_acquireForm_3200" << std::endl; + + std::cout << "dlete form start" << std::endl; + if (normalFormsMaxC.size() > 0) { + for (int count = 0; count < normalFormsMaxC.size(); count++) { + sleep(1); + FmsAcquireFormDeleteC(normalFormsMaxC[count]); + } + } + sleep(1); + FMS_deleteFormBatch(); + std::cout << "dlete form end" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3300 + * @tc.name: A single host can create 256 temporary forms. + * @tc.desc: The host of the verification form can successfully create 256 temporary forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3300, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3300" << std::endl; + + std::cout << "START add temp form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireTempFormBatch(bundleNameA, abilityNameA, TEMP_FORM_COUNT_256 - 1); + std::cout << "FMS_acquireForm_3300, temp form size of the host A:" << (TEMP_FORM_COUNT_256 - 1)<< std::endl; + + sleep(1); + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + std::cout << "FMS_acquireForm_3300, temp form size of the host A:" << TEMP_FORM_COUNT_256 << std::endl; + std::cout << "END add temp form to the host A" << std::endl; + std::cout << "END FMS_acquireForm_3300" << std::endl; + + sleep(1); + std::cout << "the host A, dlete temp form start" << std::endl; + FmsAcquireFormDeleteA(strFormId); + sleep(1); + FMS_deleteFormBatch(); + std::cout << "the host A, dlete temp form end" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3400 + * @tc.name: 256 temporary forms can be created by multiple hosts. + * @tc.desc: Verify that multiple hosts can successfully create 256 temporary forms. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3400, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3400" << std::endl; + + std::cout << "START add temp form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireTempFormBatch(bundleNameA, abilityNameA, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3400, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + std::cout << "END add temp form to the host A" << std::endl; + + sleep(1); + std::cout << "START add temp form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireTempFormBatch(bundleNameB, abilityNameB, TEMP_FORM_COUNT_128 - 1); + std::cout << "FMS_acquireForm_3400, temp form size:" << (TEMP_FORM_COUNT_128 - 1) << std::endl; + sleep(1); + std::string strFormId = FmsAcquireFormTemp(bundleNameB, abilityNameB); + std::cout << "FMS_acquireForm_3400, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + std::cout << "END add temp form to the host B" << std::endl; + + sleep(1); + std::cout << "FMS_acquireForm_3400, dlete temp form start" << std::endl; + FmsAcquireFormDeleteB(strFormId); + sleep(1); + FMS_deleteFormBatch(); + std::cout << "FMS_acquireForm_3400, dlete temp form end" << std::endl; + + std::cout << "END FMS_acquireForm_3400" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3500 + * @tc.name: Create temporary form limit value (256) verification. + * @tc.desc: Failed to create the 257th temporary form for multiple users. + */ +HWTEST_F(FmsAcquireFormTestBatch, FMS_acquireForm_3500, Function | MediumTest | Level1) +{ + sleep(1); + std::cout << "START FMS_acquireForm_3500" << std::endl; + std::cout << "START add temp form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + FMS_acquireTempFormBatch(bundleNameA, abilityNameA, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3500, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + std::cout << "END add temp form to the host A" << std::endl; + sleep(1); + std::cout << "START add temp form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + FMS_acquireTempFormBatch(bundleNameB, abilityNameB, TEMP_FORM_COUNT_128); + std::cout << "FMS_acquireForm_3500, temp form size:" << TEMP_FORM_COUNT_128 << std::endl; + std::cout << "END add temp form to the host B" << std::endl; + sleep(1); + bool result = FmsAcquireFormTempForFailed(bundleNameB, abilityNameB); + EXPECT_TRUE(result); + if (result) { + std::cout << "END add temp form to the host B, Failed to create the 257th temporary form." << std::endl; + } + sleep(1); + std::cout << "FMS_acquireForm_3500, dlete temp form start" << std::endl; + FMS_deleteFormBatch(); + std::cout << "FMS_acquireForm_3500, dlete temp form end" << std::endl; + + std::cout << "END FMS_acquireForm_3500" << std::endl; +} + +std::string FmsAcquireFormTestBatch::FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName) +{ + 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_3100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3100, EVENT_CODE_3100, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireForm3100, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireForm3100, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3101)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3101); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + GTEST_LOG_(INFO) << "FmsAcquireForm3100, result:" << result2; + + return strFormId; +} + +void FmsAcquireFormTestBatch::FmsAcquireForm2700(std::string strFormId) +{ + std::cout << "START FmsAcquireForm2700, cast temp form" << 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 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2700, EVENT_CODE_2700, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700); + bool result3 = data3 == "false"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FmsAcquireForm2700, 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) << "FmsAcquireForm2700, delete form, result:" << result4; + std::cout << "END FmsAcquireForm2700, cast temp form" << std::endl; +} +void FmsAcquireFormTestBatch::FmsAcquireForm3200() +{ + std::cout << "START FmsAcquireForm3200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normalc"; + std::string abilityName = "FormAbilityC"; + 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_3200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3200, EVENT_CODE_3200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3200, EVENT_CODE_3200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3200, EVENT_CODE_3200); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireForm3200, result:" << result; + + std::cout << "END FmsAcquireForm3200" << std::endl; +} +void FmsAcquireFormTestBatch::FmsAcquireForm2800(std::string strFormId) +{ + std::cout << "START FmsAcquireForm2800, cast temp form" << 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 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2800, EVENT_CODE_2800, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800); + bool result3 = data3 == "false"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FmsAcquireForm2800, 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) << "FmsAcquireForm2800, delete form, result:" << result4; + std::cout << "END FmsAcquireForm2800, cast temp form" << std::endl; +} + +std::string FmsAcquireFormTestBatch::FmsAcquireForm2900A() +{ + std::cout << "START FmsAcquireForm2900A, Provider A" << 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_2900; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2900, EVENT_CODE_2900, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2900)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2900); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2901)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2901); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, result:" << result2; + + std::cout << "END FmsAcquireForm2900A, Provider A" << std::endl; + return strFormId; +} +void FmsAcquireFormTestBatch::FmsAcquireForm3000() +{ + std::cout << "START FmsAcquireForm3000" << 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_3000; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3000, EVENT_CODE_3000, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireForm3000, result:" << result; + + std::cout << "END FmsAcquireForm3000" << std::endl; +} + +void FmsAcquireFormTestBatch::FMS_acquireFormBatchA(const std::string &bundleName, const std::string &abilityName, + const int count) +{ + std::cout << "START FMS_acquireFormBatchA" << 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 = std::to_string(count); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + if (result) { + GTEST_LOG_(INFO) << "FMS_acquireFormBatchA, for provider A, count: " << eventData; + } else { + GTEST_LOG_(INFO) << "FMS_acquireFormBatchA, result:" << result; + } + std::cout << "END FMS_acquireFormBatchA" << std::endl; +} + +void FmsAcquireFormTestBatch::FMS_acquireFormBatchB(const std::string &bundleName, const std::string &abilityName, + const int count) +{ + std::cout << "START FMS_acquireFormBatchB" << 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 = std::to_string(count); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH_B, EVENT_CODE_BATCH_B); + bool result = data == "true"; + EXPECT_TRUE(result); + if (result) { + GTEST_LOG_(INFO) << "FMS_acquireFormBatchB, for provider B, count: " << eventData; + } else { + GTEST_LOG_(INFO) << "FMS_acquireFormBatchB, result:" << result; + } + + std::cout << "END FMS_acquireFormBatchB" << std::endl; +} +void FmsAcquireFormTestBatch::FMS_acquireTempFormBatch(const std::string &bundleName, const std::string &abilityName, + const int count) +{ + std::cout << "START FMS_acquireTempFormBatch" << 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 = std::to_string(count); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + EVENT_CODE_TEMP_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + EVENT_CODE_TEMP_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + if (result) { + GTEST_LOG_(INFO) << "FMS_acquireTempFormBatch, count: " << eventData; + } else { + GTEST_LOG_(INFO) << "FMS_acquireTempFormBatch, result:" << result; + } + + std::cout << "END FMS_acquireTempFormBatch" << std::endl; +} + +std::string FmsAcquireFormTestBatch::FmsAcquireFormTemp(const std::string &bundleName, const std::string &abilityName) +{ + std::cout << "START FmsAcquireFormTemp, add temp form" << 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_TEMP; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, formId:" << strFormId; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP_1)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP_1); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, formData:" << data2; + } + std::cout << "END FmsAcquireFormTemp, add temp form" << std::endl; + + return strFormId; +} +bool FmsAcquireFormTestBatch::FmsAcquireFormTempForFailed(const std::string &bundleName, const std::string &abilityName) +{ + std::cout << "START FmsAcquireFormTempForFailed, add temp form" << 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_TEMP; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP); + bool result = strFormId.empty(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireFormTempForFailed, result:" << result; + + std::cout << "END FmsAcquireFormTempForFailed, add temp form" << std::endl; + + return result; +} + +void FmsAcquireFormTestBatch::FmsAcquireFormDeleteA(const 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; +} + +void FmsAcquireFormTestBatch::FmsAcquireFormDeleteB(const std::string &strFormId) +{ + std::cout << "START FmsAcquireFormDeleteB, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + std::cout << "START FmsAcquireFormDeleteB, bundleName: " << bundleName << std::endl; + std::cout << "START FmsAcquireFormDeleteB, 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) << "FmsAcquireFormDeleteB, delete form, result:" << result; + + std::cout << "END FmsAcquireFormDeleteB end" << std::endl; +} +void FmsAcquireFormTestBatch::FmsAcquireFormDeleteC(const std::string &strFormId) +{ + std::cout << "START FmsAcquireFormDeleteC, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalc"; + std::string abilityName = "FormAbilityC"; + std::cout << "START FmsAcquireFormDeleteC, bundleName: " << bundleName << std::endl; + std::cout << "START FmsAcquireFormDeleteC, 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) << "FmsAcquireFormDeleteC, delete form, result:" << result; + + std::cout << "END FmsAcquireFormDeleteC end" << std::endl; +} + +void FmsAcquireFormTestBatch::FMS_deleteFormBatch() +{ + std::cout << "START FMS_deleteFormBatch, delete forms" << 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_CLEAR_FORM_BATCH; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_CLEAR_FORM_BATCH, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_deleteFormBatch, result:" << result; + + std::cout << "END FMS_deleteFormBatch, delete forms" << std::endl; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_max.cpp b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_max.cpp new file mode 100644 index 0000000000000000000000000000000000000000..340d8d8c9c06398aa863a0fa2d11b0c4615c77c5 --- /dev/null +++ b/test/systemtest/common/fms/fms_acquire_form_test_max/fms_acquire_form_test_max.cpp @@ -0,0 +1,763 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +namespace { +const int FORM_COUNT_200 = 200; +const int FORM_COUNT_112 = 112; +const int TEMP_FORM_COUNT_256 = 256; +const int TEMP_FORM_COUNT_128 = 128; + +std::vector bundleNameList = { + "com.form.formsystemtestservicea", + "com.form.formsystemtestserviceb", +}; +std::vector hapNameList = { + "formSystemTestServiceA-signed", + "formSystemTestServiceB-signed", +}; + +std::vector normalFormsMaxA; +std::vector normalFormsMaxB; +std::vector normalFormsMaxC; + +std::vector tempFormsMaxA; +std::vector tempFormsMaxB; +} // namespace + +namespace OHOS { +namespace AppExecFwk { +class FmsAcquireFormTestMax : 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 FmsAcquireForm2700(std::string strFormId); + std::string FmsAcquireForm2900A(); + std::string FmsAcquireForm2900B(); + void FmsAcquireForm3000(); + std::string FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName); + void FmsAcquireForm2800(std::string strFormId); + void FmsAcquireForm3200(); + + void FmsAcquireFormDeleteA(const std::string &strFormId); + void FmsAcquireFormDeleteB(const std::string &strFormId); + void FmsAcquireFormDeleteC(const std::string &strFormId); + std::string FmsAcquireFormTemp(const std::string &bundleName, const std::string &abilityName); + bool FmsAcquireFormTempForFailed(const std::string &bundleName, const std::string &abilityName); +}; +std::vector FmsAcquireFormTestMax::eventList = { + FORM_EVENT_RECV_DELETE_FORM_COMMON, FORM_EVENT_ABILITY_ONACTIVED, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, + FORM_EVENT_RECV_ACQUIRE_FORM_2700, FORM_EVENT_RECV_ACQUIRE_FORM_2800, FORM_EVENT_RECV_ACQUIRE_FORM_2900, + FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, FORM_EVENT_RECV_ACQUIRE_FORM_3000, FORM_EVENT_RECV_ACQUIRE_FORM_3100, + FORM_EVENT_RECV_ACQUIRE_FORM_3200, +}; + + +FormEvent FmsAcquireFormTestMax::event = FormEvent(); +sptr FmsAcquireFormTestMax::abilityMs = nullptr; +std::shared_ptr FmsAcquireFormTestMax::subscriber = nullptr; +void FmsAcquireFormTestMax::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 FmsAcquireFormTestMax::SetUpTestCase() +{ + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsAcquireFormTestMax::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "UnSubscribeCommonEvent calld"; + CommonEventManager::UnSubscribeCommonEvent(subscriber); +} + +void FmsAcquireFormTestMax::SetUp() +{ +} + +void FmsAcquireFormTestMax::TearDown() +{ + GTEST_LOG_(INFO) << "CleanMsg calld"; + SystemTestFormUtil::CleanMsg(event); +} +bool FmsAcquireFormTestMax::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_2900 + * @tc.name: A single host creates 256 different provider forms. + * @tc.desc: The single host can successfully create 256 different provider forms. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_2900, Function | MediumTest | Level1) +{ + std::cout << "START FMS_acquireForm_2900" << std::endl; + for (int count = 0; count < Constants::MAX_RECORD_PER_APP/2; count++) { + sleep(7); + std::string strFormId1 = FmsAcquireForm2900A(); + normalFormsMaxA.emplace_back(strFormId1); + std::cout << "FMS_acquireForm_2900, form size of the host A:" << normalFormsMaxA.size() << std::endl; + sleep(7); + std::string strFormId2 = FmsAcquireForm2900B(); + normalFormsMaxA.emplace_back(strFormId2); + std::cout << "FMS_acquireForm_2900, form size of the host A:" << normalFormsMaxA.size() << std::endl; + } + + std::cout << "END FMS_acquireForm_2900" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3000 + * @tc.name: Create limit value verification using single party form. + * @tc.desc: Failed to create the 257th host form. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3000, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3000" << std::endl; + std::cout << "FMS_acquireForm_3000, form size of the host A:" << normalFormsMaxA.size() << std::endl; + FmsAcquireForm3000(); + std::cout << "END FMS_acquireForm_3000" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2700 + * @tc.name: When the normal form reaches the maximum value (256) created by the host, + * the temporary form is transferred to the normal form. + * @tc.desc: Verify that when the normal form reaches the maximum value (256) created by the single host, + * the conversion of the temporary form to the normal form fails. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_2700, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_2700" << std::endl; + std::cout << "FMS_acquireForm_2700, form size of the host A:" << normalFormsMaxA.size() << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + + sleep(7); + FmsAcquireForm2700(strFormId); + std::cout << "END FMS_acquireForm_2700" << std::endl; + + std::cout << "the host A, dlete form start" << std::endl; + for (int count = 0; count < normalFormsMaxA.size(); count++) { + sleep(7); + FmsAcquireFormDeleteA(normalFormsMaxA[count]); + std::cout << "delete form count:" << count + 1 << std::endl; + } + normalFormsMaxA.clear(); + std::cout << "the host A, dlete form end" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3100 + * @tc.name: Multiple hosts create 512 forms respectively. + * @tc.desc: Verify that multiple hosts can create 512 forms. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3100, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3100" << std::endl; + + std::cout << "START add form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + for (int count = 0; count < FORM_COUNT_200; count++) { + sleep(7); + std::string strFormId = FmsAcquireForm3100(bundleNameA, abilityNameA); + normalFormsMaxA.emplace_back(strFormId); + std::cout << "add form count:" << count + 1 << std::endl; + } + std::cout << "END add form to the host A" << std::endl; + + std::cout << "START add form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + for (int count = 0; count < FORM_COUNT_200; count++) { + sleep(7); + std::string strFormId = FmsAcquireForm3100(bundleNameB, abilityNameB); + normalFormsMaxB.emplace_back(strFormId); + std::cout << "add form count:" << count + 1 << std::endl; + } + std::cout << "END add form to the host B" << std::endl; + + std::cout << "START add form to the host C" << std::endl; + std::string bundleNameC = "com.ohos.form.manager.normalc"; + std::string abilityNameC = "FormAbilityC"; + std::cout << "bundleName: " << bundleNameC << std::endl; + std::cout << "abilityName: " << abilityNameC << std::endl; + for (int count = 0; count < FORM_COUNT_112; count++) { + sleep(7); + std::string strFormId = FmsAcquireForm3100(bundleNameC, abilityNameC); + normalFormsMaxC.emplace_back(strFormId); + std::cout << "add form count:" << count + 1 << std::endl; + } + std::cout << "END add form to the host C" << std::endl; + + std::cout << "END FMS_acquireForm_3100" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2800 + * @tc.name: When the normal form reaches the maximum value (512) of the form created by FMS, + * the temporary form will be transferred to the normal form. + * @tc.desc: When the normal form reaches the maximum value (512) created by FMS, + * the conversion of temporary form to normal form fails. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_2800, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_2800" << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host A:" << normalFormsMaxA.size() << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host B:" << normalFormsMaxB.size() << std::endl; + std::cout << "FMS_acquireForm_2800, form size of the host C:" << normalFormsMaxC.size() << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + + sleep(7); + FmsAcquireForm2800(strFormId); + std::cout << "END FMS_acquireForm_2800" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_2800 + * @tc.name: When the normal form reaches the maximum value (512) of the form created by FMS, + * the temporary form will be transferred to the normal form. + * @tc.desc: When the normal form reaches the maximum value (512) created by FMS, + * the conversion of temporary form to normal form fails. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3200, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3200" << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host A:" << normalFormsMaxA.size() << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host B:" << normalFormsMaxB.size() << std::endl; + std::cout << "FMS_acquireForm_3200, form size of the host C:" << normalFormsMaxC.size() << std::endl; + FmsAcquireForm3200(); + std::cout << "END FMS_acquireForm_3200" << std::endl; + + std::cout << "the host A, dlete form start" << std::endl; + for (int count = 0; count < normalFormsMaxA.size(); count++) { + sleep(7); + FmsAcquireFormDeleteA(normalFormsMaxA[count]); + std::cout << "delete form count:" << count + 1 << std::endl; + } + normalFormsMaxA.clear(); + std::cout << "the host A, dlete form end" << std::endl; + + std::cout << "the host B, dlete form start" << std::endl; + for (int count = 0; count < normalFormsMaxB.size(); count++) { + sleep(7); + FmsAcquireFormDeleteB(normalFormsMaxB[count]); + std::cout << "delete form count:" << count + 1 << std::endl; + } + normalFormsMaxB.clear(); + std::cout << "the host B, dlete form end" << std::endl; + + std::cout << "the host C, dlete form start" << std::endl; + for (int count = 0; count < normalFormsMaxC.size(); count++) { + sleep(7); + FmsAcquireFormDeleteC(normalFormsMaxC[count]); + std::cout << "delete form count:" << count + 1 << std::endl; + } + normalFormsMaxC.clear(); + std::cout << "the host C, dlete form end" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3300 + * @tc.name: A single host can create 256 temporary forms. + * @tc.desc: The host of the verification form can successfully create 256 temporary forms. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3300, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3300" << std::endl; + + std::cout << "START add temp form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + for (int count = 0; count < TEMP_FORM_COUNT_256; count++) { + sleep(7); + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + tempFormsMaxA.emplace_back(strFormId); + std::cout << "FMS_acquireForm_3300, form size of the host A:" << tempFormsMaxA.size() << std::endl; + } + std::cout << "END add temp form to the host A" << std::endl; + + std::cout << "END FMS_acquireForm_3300" << std::endl; + + std::cout << "the host A, dlete temp form start" << std::endl; + for (int count = 0; count < tempFormsMaxA.size(); count++) { + sleep(7); + FmsAcquireFormDeleteA(tempFormsMaxA[count]); + std::cout << "delete temp form count:" << count + 1 << std::endl; + } + tempFormsMaxA.clear(); + std::cout << "the host A, dlete temp form end" << std::endl; +} +/** + * @tc.number: FMS_acquireForm_3400 + * @tc.name: 256 temporary forms can be created by multiple hosts. + * @tc.desc: Verify that multiple hosts can successfully create 256 temporary forms. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3400, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3400" << std::endl; + + std::cout << "START add temp form to the host A" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.normal"; + std::string abilityNameA = "FormAbilityA"; + std::cout << "bundleName: " << bundleNameA << std::endl; + std::cout << "abilityName: " << abilityNameA << std::endl; + for (int count = 0; count < TEMP_FORM_COUNT_128; count++) { + sleep(7); + std::string strFormId = FmsAcquireFormTemp(bundleNameA, abilityNameA); + tempFormsMaxA.emplace_back(strFormId); + std::cout << "FMS_acquireForm_3400, temp form size of the host A:" << tempFormsMaxA.size() << std::endl; + } + std::cout << "END add temp form to the host A" << std::endl; + + std::cout << "START add temp form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + for (int count = 0; count < TEMP_FORM_COUNT_128; count++) { + sleep(7); + std::string strFormId = FmsAcquireFormTemp(bundleNameB, abilityNameB); + tempFormsMaxB.emplace_back(strFormId); + std::cout << "FMS_acquireForm_3400, temp form size of the host B:" << tempFormsMaxB.size() << std::endl; + } + std::cout << "END add temp form to the host B" << std::endl; + + std::cout << "END FMS_acquireForm_3400" << std::endl; +} + +/** + * @tc.number: FMS_acquireForm_3500 + * @tc.name: Create temporary form limit value (256) verification. + * @tc.desc: Failed to create the 257th temporary form for multiple users. + */ +HWTEST_F(FmsAcquireFormTestMax, FMS_acquireForm_3500, Function | MediumTest | Level1) +{ + sleep(7); + std::cout << "START FMS_acquireForm_3500" << std::endl; + + std::cout << "START add temp form to the host B" << std::endl; + std::string bundleNameB = "com.ohos.form.manager.normalb"; + std::string abilityNameB = "FormAbilityB"; + std::cout << "bundleName: " << bundleNameB << std::endl; + std::cout << "abilityName: " << abilityNameB << std::endl; + + bool result = FmsAcquireFormTempForFailed(bundleNameB, abilityNameB); + EXPECT_TRUE(result); + if (result) { + std::cout << "END add temp form to the host B, Failed to create the 257th temporary form." << std::endl; + } + std::cout << "END FMS_acquireForm_3500" << std::endl; + + std::cout << "the host A, dlete temp form start" << std::endl; + for (int count = 0; count < tempFormsMaxA.size(); count++) { + sleep(7); + FmsAcquireFormDeleteA(tempFormsMaxA[count]); + std::cout << "delete temp form count:" << count + 1 << std::endl; + } + tempFormsMaxA.clear(); + std::cout << "the host A, dlete temp form end" << std::endl; + + std::cout << "the host B, dlete temp form start" << std::endl; + for (int count = 0; count < tempFormsMaxB.size(); count++) { + sleep(7); + FmsAcquireFormDeleteB(tempFormsMaxB[count]); + std::cout << "delete temp form count:" << count + 1 << std::endl; + } + tempFormsMaxB.clear(); + std::cout << "the host B, dlete temp form end" << std::endl; +} + +std::string FmsAcquireFormTestMax::FmsAcquireForm3100(const std::string &bundleName, const std::string &abilityName) +{ + 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_3100; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3100, EVENT_CODE_3100, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3100); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireForm3100, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireForm3100, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3101)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3100, EVENT_CODE_3101); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + GTEST_LOG_(INFO) << "FmsAcquireForm3100, result:" << result2; + + return strFormId; +} + +void FmsAcquireFormTestMax::FmsAcquireForm2700(std::string strFormId) +{ + std::cout << "START FmsAcquireForm2700, cast temp form" << 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 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2700, EVENT_CODE_2700, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2700, EVENT_CODE_2700); + bool result3 = data3 == "false"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FmsAcquireForm2700, 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) << "FmsAcquireForm2700, delete form, result:" << result4; + std::cout << "END FmsAcquireForm2700, cast temp form" << std::endl; +} +void FmsAcquireFormTestMax::FmsAcquireForm3200() +{ + std::cout << "START FmsAcquireForm3200" << std::endl; + + std::string bundleName = "com.ohos.form.manager.normalc"; + std::string abilityName = "FormAbilityC"; + 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_3200; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3200, EVENT_CODE_3200, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3200, EVENT_CODE_3200)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3200, EVENT_CODE_3200); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireForm3200, result:" << result; + + std::cout << "END FmsAcquireForm3200" << std::endl; +} +void FmsAcquireFormTestMax::FmsAcquireForm2800(std::string strFormId) +{ + std::cout << "START FmsAcquireForm2800, cast temp form" << 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 = strFormId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2800, EVENT_CODE_2800, eventData1); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800)); + std::string data3 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2800, EVENT_CODE_2800); + bool result3 = data3 == "false"; + EXPECT_TRUE(result3); + GTEST_LOG_(INFO) << "FmsAcquireForm2800, 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) << "FmsAcquireForm2800, delete form, result:" << result4; + std::cout << "END FmsAcquireForm2800, cast temp form" << std::endl; +} + +std::string FmsAcquireFormTestMax::FmsAcquireForm2900A() +{ + std::cout << "START FmsAcquireForm2900A, Provider A" << 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_2900; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2900, EVENT_CODE_2900, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2900)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2900); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2901)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900, EVENT_CODE_2901); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + GTEST_LOG_(INFO) << "FmsAcquireForm2900A, result:" << result2; + + std::cout << "END FmsAcquireForm2900A, Provider A" << std::endl; + return strFormId; +} +std::string FmsAcquireFormTestMax::FmsAcquireForm2900B() +{ + std::cout << "START FmsAcquireForm2900B, Provider B" << 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_2900_1; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_2900_1, EVENT_CODE_2910, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2910)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2910); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireForm2900B, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireForm2900B, formId:" << strFormId; + } + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2911)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_2900_1, EVENT_CODE_2911); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + GTEST_LOG_(INFO) << "FmsAcquireForm2900B, result:" << result2; + + std::cout << "END FmsAcquireForm2900B, Provider B" << std::endl; + return strFormId; +} +void FmsAcquireFormTestMax::FmsAcquireForm3000() +{ + std::cout << "START FmsAcquireForm3000" << 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_3000; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_3000, EVENT_CODE_3000, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_3000, EVENT_CODE_3000); + bool result = data == "false"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireForm3000, result:" << result; + + std::cout << "END FmsAcquireForm3000" << std::endl; +} +std::string FmsAcquireFormTestMax::FmsAcquireFormTemp(const std::string &bundleName, const std::string &abilityName) +{ + std::cout << "START FmsAcquireFormTemp, add temp form" << 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_TEMP; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP); + bool result = !strFormId.empty(); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, result:" << result; + } else { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, formId:" << strFormId; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP_1)); + std::string data2 = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP_1); + bool result2 = !data2.empty(); + EXPECT_TRUE(result2); + if (!result2) { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, result:" << result2; + } else { + GTEST_LOG_(INFO) << "FmsAcquireFormTemp, formData:" << data2; + } + std::cout << "END FmsAcquireFormTemp, add temp form" << std::endl; + + return strFormId; +} + +bool FmsAcquireFormTestMax::FmsAcquireFormTempForFailed(const std::string &bundleName, const std::string &abilityName) +{ + std::cout << "START FmsAcquireFormTempForFailed, add temp form" << 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_TEMP; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP)); + std::string strFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_TEMP, EVENT_CODE_TEMP); + bool result = strFormId.empty(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FmsAcquireFormTempForFailed, result:" << result; + + std::cout << "END FmsAcquireFormTempForFailed, add temp form" << std::endl; + + return result; +} + +void FmsAcquireFormTestMax::FmsAcquireFormDeleteA(const 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; +} + +void FmsAcquireFormTestMax::FmsAcquireFormDeleteB(const std::string &strFormId) +{ + std::cout << "START FmsAcquireFormDeleteB, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalb"; + std::string abilityName = "FormAbilityB"; + std::cout << "START FmsAcquireFormDeleteB, bundleName: " << bundleName << std::endl; + std::cout << "START FmsAcquireFormDeleteB, 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) << "FmsAcquireFormDeleteB, delete form, result:" << result; + + std::cout << "END FmsAcquireFormDeleteB end" << std::endl; +} +void FmsAcquireFormTestMax::FmsAcquireFormDeleteC(const std::string &strFormId) +{ + std::cout << "START FmsAcquireFormDeleteC, start." << std::endl; + std::string bundleName = "com.ohos.form.manager.normalc"; + std::string abilityName = "FormAbilityC"; + std::cout << "START FmsAcquireFormDeleteC, bundleName: " << bundleName << std::endl; + std::cout << "START FmsAcquireFormDeleteC, 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) << "FmsAcquireFormDeleteC, delete form, result:" << result; + + std::cout << "END FmsAcquireFormDeleteC 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..1cbfbc5b1a604a3a72e1572ade90535bb4619568 --- /dev/null +++ b/test/systemtest/common/fms/fms_delete_form_test/BUILD.gn @@ -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. + +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", + "multimodalinput_base:libmmi-client", + "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..4aae43bb0d63ec86c0847bb0e0f81733f715db1c --- /dev/null +++ b/test/systemtest/common/fms/fms_delete_form_test/fms_delete_form_test.cpp @@ -0,0 +1,1204 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +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; + bool FmsGetCacheInfoByFormId(std::int64_t formId); + bool FmsGetHostInfoByFormId(std::int64_t formId, std::string hostBundleName); + bool FmsGetStorageFormInfos(std::int64_t formId); + bool FmsGetFormTimerTask(std::int64_t formId); + void FMS_deleteForm_1400_A(); + void FMS_deleteForm_1400_B(); + void FMS_deleteForm_1500_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1500_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1500_Create_Delete(std::string delFormId, std::string &createFormId); + void FMS_deleteForm_1600_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1600_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1600_Delete_Create(std::string delFormId, std::string &createFormId); + void FMS_deleteForm_1700_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1700_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId); + void FMS_deleteForm_1700_Delete_Create(std::string delFormId, std::string &createFormId); + void FMS_acquireTempFormBatch(const std::string &bundleName, const std::string &abilityName, + const int count); + void FMS_acquireNormalFormBatch(const std::string &bundleName, const std::string &abilityName, + const int count); + void FMS_deleteFormBatch(const std::string &bundleName, const std::string &abilityName); +}; + +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_1201, + FORM_EVENT_RECV_DELETE_FORM_1400, + FORM_EVENT_RECV_DELETE_FORM_1401, + FORM_EVENT_RECV_DELETE_FORM_1500, + FORM_EVENT_RECV_DELETE_FORM_1501, + FORM_EVENT_RECV_DELETE_FORM_1502, + FORM_EVENT_RECV_DELETE_FORM_1600, + FORM_EVENT_RECV_DELETE_FORM_1601, + FORM_EVENT_RECV_DELETE_FORM_1602, + FORM_EVENT_RECV_DELETE_FORM_1700, + FORM_EVENT_RECV_DELETE_FORM_1701, + FORM_EVENT_RECV_DELETE_FORM_1702, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, + FORM_EVENT_RECV_ONE_NORMAL_FORM_B, + FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, + COMMON_EVENT_ON_DELETE, + FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, + FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + FORM_EVENT_RECV_CLEAR_FORM_BATCH +}; + +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(); + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsDeleteFormTest::SetUpTestCase() +{ + std::cout << "START Install============" << std::endl; + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsDeleteFormTest::TearDownTestCase() +{ + std::cout << "START Uninstall============" << std::endl; + 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_1201, + FORM_EVENT_RECV_DELETE_FORM_1400, + FORM_EVENT_RECV_DELETE_FORM_1401, + FORM_EVENT_RECV_DELETE_FORM_1500, + FORM_EVENT_RECV_DELETE_FORM_1501, + FORM_EVENT_RECV_DELETE_FORM_1502, + FORM_EVENT_RECV_DELETE_FORM_1600, + FORM_EVENT_RECV_DELETE_FORM_1601, + FORM_EVENT_RECV_DELETE_FORM_1602, + FORM_EVENT_RECV_DELETE_FORM_1700, + FORM_EVENT_RECV_DELETE_FORM_1701, + FORM_EVENT_RECV_DELETE_FORM_1702, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, + FORM_EVENT_RECV_ONE_NORMAL_FORM_B, + FORM_EVENT_RECV_ONE_NORMAL_FORM_B_DEL, + COMMON_EVENT_ON_DELETE, + FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, + FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + FORM_EVENT_RECV_CLEAR_FORM_BATCH + }; + 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) +{ + 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) +{ + 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) +{ + 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; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + 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) +{ + 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; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + 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) +{ + 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::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, data); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } + 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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_deleteForm_0600, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0600, EVENT_CODE_600); + bool result = formTwo == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0600, result:" << result; + } + // can't receive onDelete + EXPECT_EQ(-1, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + bool hostRes = FmsGetHostInfoByFormId(atoll(formOne.c_str()), "com.ohos.form.manager.normal"); + bool storageRes = FmsGetStorageFormInfos(atoll(formOne.c_str())); + EXPECT_TRUE(cacheRes); + EXPECT_FALSE(hostRes); + EXPECT_TRUE(storageRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } + 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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700, formOne:[" << formOne << "]" << std::endl; + EXPECT_TRUE(formOne != ""); + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_0700, EVENT_CODE_700); + GTEST_LOG_(INFO) << "FMS_deleteForm_0700, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0700, result:" << result; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + std::string onDeleteData = SystemTestFormUtil::GetData(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK); + EXPECT_TRUE(onDeleteData == formTwo); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formTwo.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formTwo.c_str())); + bool timerRes = FmsGetFormTimerTask(atoll(formTwo.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); + EXPECT_FALSE(timerRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } + 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) +{ + 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 != "false" && data != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_0800, result:" << result; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + std::string onDeleteData = SystemTestFormUtil::GetData(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK); + EXPECT_TRUE(onDeleteData == data); + bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); + bool timerRes = FmsGetFormTimerTask(atoll(data.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(storageRes); + EXPECT_FALSE(timerRes); + 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) +{ + 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; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + 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) +{ + 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; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + 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) +{ + 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, EVENT_CODE_100, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + std::string formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_deleteForm_1100, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1100, EVENT_CODE_1100); + GTEST_LOG_(INFO) << "FMS_deleteForm_1100, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1100, result:" << result; + } + // can receive onDelete + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + std::string onDeleteData = SystemTestFormUtil::GetData(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK); + GTEST_LOG_(INFO) << "00000, onDeleteData:[" << onDeleteData << "]" << std::endl; + EXPECT_TRUE(onDeleteData == formTwo); + + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formTwo.c_str())); + EXPECT_FALSE(cacheRes); + bool cacheRes2 = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + EXPECT_TRUE(cacheRes2); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } + 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) +{ + int createFormCount = 10; + std::string formIds[10] = {""}; + std::cout << "============START FMS_deleteForm_1200" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + + for (int i=0; i>index:" << i; + bool result = (formIds[i] != "false" && formIds[i] != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1200, result:" << result; + } + } + for (int i=0; i>index:" << i; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1201, result:" << result; + } + } + SystemTestFormUtil::CleanMsg(event); + 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) +{ + std::cout << "============START FMS_deleteForm_1400" << std::endl; + FMS_deleteForm_1400_A(); + FMS_deleteForm_1400_B(); + SystemTestFormUtil::CleanMsg(event); + 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) +{ + std::cout << "============START FMS_deleteForm_1500" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + int count = Constants::MAX_RECORD_PER_APP - 1; + FMS_acquireTempFormBatch(bundleName, abilityName, count); + std::string formId = ""; + FMS_deleteForm_1500_acquireForm(bundleName, abilityName, formId); + FMS_deleteForm_1500_clearForm(bundleName, abilityName, formId); + SystemTestFormUtil::CleanMsg(event); + 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) +{ + std::cout << "============START FMS_deleteForm_1600" << std::endl; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + int count = Constants::MAX_RECORD_PER_APP - 1; + FMS_acquireNormalFormBatch(bundleName, abilityName, count); + std::string formId = ""; + FMS_deleteForm_1600_acquireForm(bundleName, abilityName, formId); + FMS_deleteForm_1600_clearForm(bundleName, abilityName, formId); + SystemTestFormUtil::CleanMsg(event); + 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) +{ + std::cout << "============START FMS_deleteForm_1700" << std::endl; + std::string bundleNameA = "com.ohos.form.manager.commona"; + std::string abilityNameA = "FormAbilityCommonA"; + int countA = 200; + FMS_acquireNormalFormBatch(bundleNameA, abilityNameA, countA); + + std::string bundleNameB = "com.ohos.form.manager.commonb"; + std::string abilityNameB = "FormAbilityCommonB"; + int countB = 200; + FMS_acquireNormalFormBatch(bundleNameB, abilityNameB, countB); + + std::string bundleNameC = "com.ohos.form.manager.normal"; + std::string abilityNameC = "FormAbilityDeleteForm"; + int countC = 111; + FMS_acquireNormalFormBatch(bundleNameC, abilityNameC, countC); + + std::string formId = ""; + FMS_deleteForm_1700_acquireForm(bundleNameC, abilityNameC, formId); + FMS_deleteForm_1700_clearForm(bundleNameC, abilityNameC, formId); + FMS_deleteFormBatch(bundleNameA, abilityNameA); + FMS_deleteFormBatch(bundleNameB, abilityNameB); + FMS_deleteFormBatch(bundleNameC, abilityNameC); + SystemTestFormUtil::CleanMsg(event); + std::cout << "============END FMS_deleteForm_1700" << std::endl; +} + +bool FmsDeleteFormTest::FmsGetCacheInfoByFormId(std::int64_t formId) +{ + std::string cachedData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + bool cacheRes = false; + std::string formIdStr = std::to_string(formId); + std::string::size_type pos = cachedData.find(formIdStr); + if (pos != cachedData.npos) { + std::cout << "######### formId is found in cache" << std::endl; + cacheRes = true; + } else { + std::cout << "######### Can't find formId in cache!" << std::endl; + cacheRes = false; + } + return cacheRes; +} +bool FmsDeleteFormTest::FmsGetHostInfoByFormId(std::int64_t formId, std::string hostBundleName) +{ + std::string hostData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + bool hostRes = false; + std::string::size_type pos = hostData.find(hostBundleName); + if (pos != hostData.npos) { + std::cout << "######### hostBundleName is found in cache" << std::endl; + hostRes = true; + } else { + std::cout << "######### Can't find hostBundleName in cache!" << std::endl; + hostRes = false; + } + return hostRes; +} +bool FmsDeleteFormTest::FmsGetStorageFormInfos(std::int64_t formId) +{ + std::string storageData = SystemTestFormUtil::QueryStorageFormInfos(); + bool storageRes = false; + std::string formIdStr = std::to_string(formId); + std::string::size_type pos = storageData.find(formIdStr); + if (pos != storageData.npos) { + std::cout << "######### formId is found in storage" << std::endl; + storageRes = true; + } else { + std::cout << "######### Can't find formId in storage!" << std::endl; + storageRes = false; + } + return storageRes; +} +bool FmsDeleteFormTest::FmsGetFormTimerTask(std::int64_t formId) +{ + std::string timerRes = SystemTestFormUtil::QueryFormTimerByFormId(formId); + if (timerRes == "true") { + std::cout << "######### formId is found in TimerTask" << std::endl; + return true; + } else { + std::cout << "######### Can't find formId in TimerTask!" << std::endl; + return false; + } +} +void FmsDeleteFormTest::FMS_deleteForm_1400_A() +{ + int createFormCount = 10; + std::string formIds[10] = {""}; + std::string bundleName = "com.ohos.form.manager.commona"; + std::string abilityName = "FormAbilityCommonA"; + MAP_STR_STR params; + + for (int i = 0; i < createFormCount; i++) { + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + int tmp = 5; + std::string eventData = ((i / tmp == 1) ? "true" : "false"); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM, EVENT_CODE_1400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100)); + formIds[i] = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1400[A][#Create#]formId:[" << formIds[i] << "]======>>index:" << i; + bool result = (formIds[i] != "false" && formIds[i] != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1400[A], result:" << result; + } + } + for (int i = 0; i < createFormCount; i++) { + 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 = formIds[i]; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_1400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1400[A][#Delete#]formId:[" << formIds[i] << "]======>>index:" << i; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1401[A], result:" << result; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } +} +void FmsDeleteFormTest::FMS_deleteForm_1400_B() +{ + int createFormCount = 10; + std::string formIds[10] = {""}; + std::string bundleName = "com.ohos.form.manager.normal"; + std::string abilityName = "FormAbilityDeleteForm"; + MAP_STR_STR params; + + for (int i = 0; i < createFormCount; i++) { + Want want = SystemTestFormUtil::MakeWant("device", abilityName, bundleName, params); + SystemTestFormUtil::StartAbility(want, abilityManager); + EXPECT_EQ(SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_ABILITY_ONACTIVED, 0), 0); + int tmp = 5; + std::string eventData = ((i / tmp == 1) ? "true" : "false"); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1400, EVENT_CODE_1400, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400)); + formIds[i] = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1400, EVENT_CODE_1400); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1400[B][#Create#]formId:[" << formIds[i] << "]======>>index:" << i; + bool result = (formIds[i] != "false" && formIds[i] != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1400[B], result:" << result; + } + } + for (int i = 0; i < createFormCount; i++) { + 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 = formIds[i]; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1401, EVENT_CODE_1401, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1401, EVENT_CODE_1401)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1401, EVENT_CODE_1401); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1400[B][#Delete#]formId:[" << formIds[i] << "]======>>index:" << i; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1401[B], result:" << result; + } + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, COMMON_EVENT_ON_DELETE, + FORM_EVENT_TRIGGER_RESULT::FORM_EVENT_TRIGGER_RESULT_OK)); + } +} +void FmsDeleteFormTest::FMS_deleteForm_1500_Create_Delete(std::string delFormId, std::string &createFormId) +{ + 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); + + // delete one and create one + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1501, EVENT_CODE_1510, delFormId); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510)); + createFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1501, EVENT_CODE_1510); + bool result = (createFormId != "deleteError" && createFormId != "acquireError" && createFormId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1501, result:" << result; + } +} +void FmsDeleteFormTest::FMS_deleteForm_1600_Delete_Create(std::string delFormId, std::string &createFormId) +{ + 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); + + // delete one and create one + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1601, EVENT_CODE_1610, delFormId); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610)); + createFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1601, EVENT_CODE_1610); + bool result = (createFormId != "deleteError" && createFormId != "acquireError" && createFormId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1601, result:" << result; + } +} +void FmsDeleteFormTest::FMS_deleteForm_1700_Delete_Create(std::string delFormId, std::string &createFormId) +{ + 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); + + // delete one and create one + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1701, EVENT_CODE_1701, delFormId); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701)); + createFormId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1701, EVENT_CODE_1701); + bool result = (createFormId != "deleteError" && createFormId != "acquireError" && createFormId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1701, result:" << result; + } +} +void FmsDeleteFormTest::FMS_deleteForm_1500_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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_1500; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1500, EVENT_CODE_1500, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500)); + std::string formId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1500, EVENT_CODE_1500); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1500 [#Create#]formId:[" << formId << "]"; + bool result = (formId != "false" && formId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1500, result:" << result; + } + FMS_deleteForm_1500_Create_Delete(formId, outformId); +} +void FmsDeleteFormTest::FMS_deleteForm_1500_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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 = outformId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1502, EVENT_CODE_1511, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1502, EVENT_CODE_1511)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1502, EVENT_CODE_1511); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1500_clearForm [#Delete#]formId:[" << outformId << "]"; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1500_clearForm, result:" << result; + } + FMS_deleteFormBatch(bundleName, abilityName); +} +void FmsDeleteFormTest::FMS_deleteForm_1600_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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_1600; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1600, EVENT_CODE_1600, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600)); + std::string formId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1600, EVENT_CODE_1600); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1600 [#Create#]formId:[" << formId << "]"; + bool result = (formId != "false" && formId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1600, result:" << result; + } + FMS_deleteForm_1600_Delete_Create(formId, outformId); +} +void FmsDeleteFormTest::FMS_deleteForm_1600_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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 = outformId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1602, EVENT_CODE_1611, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1602, EVENT_CODE_1611)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1602, EVENT_CODE_1611); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1600 [#Delete#]formId:[" << outformId << "]"; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1600, result:" << result; + } + FMS_deleteFormBatch(bundleName, abilityName); +} +void FmsDeleteFormTest::FMS_deleteForm_1700_acquireForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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_1700; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1700, EVENT_CODE_1700, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700)); + std::string formId = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1700, EVENT_CODE_1700); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1700 [#Create#]formId:[" << formId << "]"; + bool result = (formId != "false" && formId != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1700, result:" << result; + } + FMS_deleteForm_1700_Delete_Create(formId, outformId); +} +void FmsDeleteFormTest::FMS_deleteForm_1700_clearForm(const std::string &bundleName, const std::string &abilityName, + std::string &outformId) +{ + 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 = outformId; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_DELETE_FORM_1702, EVENT_CODE_1702, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_DELETE_FORM_1702, EVENT_CODE_1702); + GTEST_LOG_(INFO) << "========FMS_deleteForm_1700 [#Delete#]formId:[" << outformId << "]"; + bool result = data == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_deleteForm_1700, result:" << result; + } +} +void FmsDeleteFormTest::FMS_acquireTempFormBatch(const std::string &bundleName, const std::string &abilityName, + const int count) +{ + std::cout << "START FMS_acquireTempFormBatch" << std::endl; + 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 = std::to_string(count); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_TEMP_FORM_BATCH, EVENT_CODE_TEMP_BATCH, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + EVENT_CODE_TEMP_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_TEMP_FORM_BATCH, + EVENT_CODE_TEMP_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + if (result) { + GTEST_LOG_(INFO) << "FMS_acquireTempFormBatch, count: " << eventData; + } else { + GTEST_LOG_(INFO) << "FMS_acquireTempFormBatch, result:" << result; + } + std::cout << "END FMS_acquireTempFormBatch" << std::endl; +} +void FmsDeleteFormTest::FMS_acquireNormalFormBatch(const std::string &bundleName, const std::string &abilityName, + const int count) +{ + std::cout << "START FMS_acquireNormalFormBatch" << std::endl; + 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 = std::to_string(count); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH, eventData); + + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ACQUIRE_FORM_BATCH, EVENT_CODE_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + if (result) { + GTEST_LOG_(INFO) << "FMS_acquireNormalFormBatch, count: " << eventData; + } else { + GTEST_LOG_(INFO) << "FMS_acquireNormalFormBatch, result:" << result; + } + std::cout << "END FMS_acquireNormalFormBatch" << std::endl; +} +void FmsDeleteFormTest::FMS_deleteFormBatch(const std::string &bundleName, const std::string &abilityName) +{ + std::cout << "START FMS_deleteFormBatch, delete forms" << std::endl; + 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_CLEAR_FORM_BATCH; + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_CLEAR_FORM_BATCH, EVENT_CODE_TEMP, eventData); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH)); + std::string data = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_CLEAR_FORM_BATCH, EVENT_CODE_CLEAR_BATCH); + bool result = data == "true"; + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "FMS_deleteFormBatch, result:" << result; + std::cout << "END FMS_deleteFormBatch, delete forms" << 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..3212f211b097c031abb7f3f8bc273a7f5c4ac46c --- /dev/null +++ b/test/systemtest/common/fms/fms_release_form_test/BUILD.gn @@ -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. + +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", + "multimodalinput_base:libmmi-client", + "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..57b6502c0670f66946eaf313464b7aff3a60d27a --- /dev/null +++ b/test/systemtest/common/fms/fms_release_form_test/fms_release_form_test.cpp @@ -0,0 +1,789 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +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; + bool FmsGetCacheInfoByFormId(std::int64_t formId); + bool FmsGetHostInfoByFormId(std::int64_t formId, std::string hostBundleName); + bool FmsGetStorageFormInfos(std::int64_t formId); + bool FmsGetFormTimerTask(std::int64_t formId); +}; + +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_RELEASE_FORM_COMMON_DEL, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL +}; + +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(); + SystemTestFormUtil::Completed(event, data.GetWant().GetAction(), data.GetCode(), data.GetData()); +} + +void FmsReleaseFormTest::SetUpTestCase() +{ + std::cout << "START Install============" << std::endl; + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsReleaseFormTest::TearDownTestCase() +{ + std::cout << "START Uninstall============" << std::endl; + 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_RELEASE_FORM_COMMON_DEL, + FORM_EVENT_RECV_ONE_NORMAL_FORM, + FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL + }; + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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) +{ + 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::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, data); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + } + 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) +{ + 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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_releaseForm_0700, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0700, EVENT_CODE_700); + bool result = formTwo == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0700, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + bool hostRes = FmsGetHostInfoByFormId(atoll(formOne.c_str()), "com.ohos.form.manager.normal"); + bool storageRes = FmsGetStorageFormInfos(atoll(formOne.c_str())); + EXPECT_TRUE(cacheRes); + EXPECT_FALSE(hostRes); + EXPECT_TRUE(storageRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + } + 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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_releaseForm_0800, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_0800, EVENT_CODE_800); + GTEST_LOG_(INFO) << "FMS_releaseForm_0800, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0800, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formTwo.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formTwo.c_str())); + bool timerRes = FmsGetFormTimerTask(atoll(formTwo.c_str())); + EXPECT_TRUE(cacheRes); + EXPECT_TRUE(storageRes); + EXPECT_FALSE(timerRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, formTwo); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + } + 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) +{ + 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); + GTEST_LOG_(INFO) << "FMS_releaseForm_0900, data:[" << data << "]" << std::endl; + bool result = (data != "false" && data != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_0900, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool hostRes = FmsGetHostInfoByFormId(atoll(data.c_str()), "com.ohos.form.manager.normal"); + bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); + EXPECT_TRUE(cacheRes); + EXPECT_FALSE(hostRes); + EXPECT_TRUE(storageRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, data); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_0900" << 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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + GTEST_LOG_(INFO) << "FMS_releaseForm_1100, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1100, EVENT_CODE_1100); + GTEST_LOG_(INFO) << "FMS_releaseForm_1100, formTwo:[" << formTwo << "]" << std::endl; + bool result = (formTwo != "false" && formTwo != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1100, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formTwo.c_str())); + bool storageRes = FmsGetStorageFormInfos(atoll(formTwo.c_str())); + bool timerRes = FmsGetFormTimerTask(atoll(formTwo.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_TRUE(storageRes); + EXPECT_FALSE(timerRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, formTwo); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + } + 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) +{ + 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); + GTEST_LOG_(INFO) << "FMS_releaseForm_1200, data:[" << data << "]" << std::endl; + bool result = (data != "false" && data != ""); + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1200, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(data.c_str())); + bool hostRes = FmsGetHostInfoByFormId(atoll(data.c_str()), "com.ohos.form.manager.normal"); + bool storageRes = FmsGetStorageFormInfos(atoll(data.c_str())); + EXPECT_FALSE(cacheRes); + EXPECT_FALSE(hostRes); + EXPECT_TRUE(storageRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, data); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + 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) +{ + 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) +{ + 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; +} +/** + * @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) +{ + 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 formOne = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_ONE_NORMAL_FORM, EVENT_CODE_100); + + GTEST_LOG_(INFO) << "FMS_releaseForm_1000, formOne:[" << formOne << "]" << std::endl; + if (formOne != "") { + 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 = formOne; + 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 formTwo = SystemTestFormUtil::GetData(event, FORM_EVENT_RECV_RELEASE_FORM_1000, EVENT_CODE_1000); + bool result = formTwo == "true"; + EXPECT_TRUE(result); + if (!result) { + GTEST_LOG_(INFO) << "FMS_releaseForm_1000, result:" << result; + } + bool cacheRes = FmsGetCacheInfoByFormId(atoll(formOne.c_str())); + bool hostRes = FmsGetHostInfoByFormId(atoll(formOne.c_str()), "com.ohos.form.manager.normal"); + bool storageRes = FmsGetStorageFormInfos(atoll(formOne.c_str())); + EXPECT_TRUE(cacheRes); + EXPECT_FALSE(hostRes); + EXPECT_TRUE(storageRes); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_ONE_NORMAL_FORM_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_ONE_NORMAL_FORM_DEL, EVENT_CODE_101)); + SystemTestFormUtil::PublishEvent(FORM_EVENT_REQ_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101, formOne); + EXPECT_EQ(0, SystemTestFormUtil::WaitCompleted(event, FORM_EVENT_RECV_RELEASE_FORM_COMMON_DEL, EVENT_CODE_101)); + } + SystemTestFormUtil::CleanMsg(event); + + std::cout << "============END FMS_releaseForm_1000" << std::endl; +} +bool FmsReleaseFormTest::FmsGetCacheInfoByFormId(std::int64_t formId) +{ + std::string cachedData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + bool cacheRes = false; + std::string formIdStr = std::to_string(formId); + std::string::size_type pos = cachedData.find(formIdStr); + if (pos != cachedData.npos) { + std::cout << "######### formId is found in cache" << std::endl; + cacheRes = true; + } else { + std::cout << "######### Can't find formId in cache!" << std::endl; + cacheRes = false; + } + return cacheRes; +} +bool FmsReleaseFormTest::FmsGetHostInfoByFormId(std::int64_t formId, std::string hostBundleName) +{ + std::string hostData = SystemTestFormUtil::QueryFormInfoByFormId(formId); + bool hostRes = false; + std::string::size_type pos = hostData.find(hostBundleName); + if (pos != hostData.npos) { + std::cout << "######### hostBundleName is found in cache" << std::endl; + hostRes = true; + } else { + std::cout << "######### Can't find hostBundleName in cache!" << std::endl; + hostRes = false; + } + return hostRes; +} +bool FmsReleaseFormTest::FmsGetStorageFormInfos(std::int64_t formId) +{ + std::string storageData = SystemTestFormUtil::QueryStorageFormInfos(); + bool storageRes = false; + std::string formIdStr = std::to_string(formId); + std::string::size_type pos = storageData.find(formIdStr); + if (pos != storageData.npos) { + std::cout << "######### formId is found in storage" << std::endl; + storageRes = true; + } else { + std::cout << "######### Can't find formId in storage!" << std::endl; + storageRes = false; + } + return storageRes; +} +bool FmsReleaseFormTest::FmsGetFormTimerTask(std::int64_t formId) +{ + std::string timerRes = SystemTestFormUtil::QueryFormTimerByFormId(formId); + if (timerRes == "true") { + std::cout << "######### formId is found in TimerTask" << std::endl; + return true; + } else { + std::cout << "######### Can't find formId in TimerTask!" << std::endl; + return false; + } +} +} // 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..0b98eeb563de6c16223f0db11abeeb6bff587f84 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/BUILD.gn @@ -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. + +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", + "multimodalinput_base:libmmi-client", + "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..3e71c7655ebe4ced726e040587371d4b8eff0db0 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_acquire_forms_and_self_starting.sh @@ -0,0 +1,48 @@ +# 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 "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..af60e3b9144a523aa76db80d814b60cb71572fd2 --- /dev/null +++ b/test/systemtest/common/fms/fms_self_starting_test/fms_self_starting_test.cpp @@ -0,0 +1,204 @@ +/* + * 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 "iservice_registry.h" +#include "nlohmann/json.hpp" +#include "system_ability_definition.h" +#include "system_test_form_util.h" + +using OHOS::AAFwk::Want; +using namespace testing::ext; +using namespace std::chrono_literals; +using namespace OHOS::STtools; + +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() +{ + if (!SubscribeEvent()) { + GTEST_LOG_(INFO) << "SubscribeEvent error"; + } +} + +void FmsSelfStartingTest::TearDownTestCase() +{ + GTEST_LOG_(INFO) << "UnSubscribeCommonEvent calld"; + 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 diff --git a/tools/fm/src/fms_command.cpp b/tools/fm/src/fms_command.cpp index 462165df9a8f3367e9b8f15e57fb03010cec9ca0..bcc3b184ed542d129cb925926ff765e1489e6afc 100755 --- a/tools/fm/src/fms_command.cpp +++ b/tools/fm/src/fms_command.cpp @@ -445,7 +445,7 @@ int FormMgrShellCommand::GetStringInfo(IFormMgr::Message code, MessageParcel &da std::vector stringInfoList; if (!reply.ReadStringVector(&stringInfoList)) { APP_LOGE("%{public}s, failed to read string vector from reply", __func__); - return false; + return ERR_APPEXECFWK_PARCEL_ERROR; } if (stringInfoList.empty()) { APP_LOGI("%{public}s, No string info", __func__);