diff --git a/frameworks/js/napi/ability_manager/BUILD.gn b/frameworks/js/napi/ability_manager/BUILD.gn index 1a1643338c..352f58f0ff 100644 --- a/frameworks/js/napi/ability_manager/BUILD.gn +++ b/frameworks/js/napi/ability_manager/BUILD.gn @@ -45,6 +45,7 @@ template("abilitymanager") { "ability_runtime:ability_manager", "ability_runtime:abilitykit_native", "ability_runtime:runtime", + "access_token:libtokenid_sdk", "c_utils:utils", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", diff --git a/frameworks/js/napi/ability_manager/js_ability_manager.cpp b/frameworks/js/napi/ability_manager/js_ability_manager.cpp index ef57a22846..4afc489393 100644 --- a/frameworks/js/napi/ability_manager/js_ability_manager.cpp +++ b/frameworks/js/napi/ability_manager/js_ability_manager.cpp @@ -27,11 +27,13 @@ #include "js_runtime_utils.h" #include "napi/native_api.h" #include "if_system_ability_manager.h" +#include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" #include "js_ability_manager_utils.h" #include "event_runner.h" #include "napi_common_configuration.h" +#include "tokenid_kit.h" namespace OHOS { namespace AbilityRuntime { @@ -211,6 +213,14 @@ private: NativeValue* OnGetTopAbility(NativeEngine &engine, const NativeCallbackInfo &info) { HILOG_INFO("%{public}s is called", __FUNCTION__); +#ifdef ENABLE_ERRCODE + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } +#endif AsyncTask::CompleteCallback complete = [](NativeEngine &engine, AsyncTask &task, int32_t status) { AppExecFwk::ElementName elementName = AbilityManagerClient::GetInstance()->GetTopAbility(); diff --git a/frameworks/js/napi/app/js_app_manager/BUILD.gn b/frameworks/js/napi/app/js_app_manager/BUILD.gn index 5e6966d680..ad20610de2 100644 --- a/frameworks/js/napi/app/js_app_manager/BUILD.gn +++ b/frameworks/js/napi/app/js_app_manager/BUILD.gn @@ -32,6 +32,7 @@ ohos_shared_library("appmanager") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_services_path}/abilitymgr:abilityms", ] diff --git a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp index cf7431661b..ca74c78f43 100644 --- a/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp +++ b/frameworks/js/napi/app/js_app_manager/js_app_manager.cpp @@ -188,7 +188,6 @@ private: ThrowTooFewParametersError(engine); return engine.CreateUndefined(); } - if (!CheckOnOffType(engine, info)) { ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); @@ -198,8 +197,13 @@ private: napi_get_value_int64(reinterpret_cast(&engine), reinterpret_cast(info.argv[INDEX_ONE]), &observerId); std::lock_guard lock(g_observerMutex); + if (observer_ == nullptr) { + HILOG_ERROR("observer_ is nullpter, please register first"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); + return engine.CreateUndefined(); + } if (!observer_->FindObserverByObserverId(observerId)) { - HILOG_INFO("not find observer, observer:%{public}d", static_cast(observerId)); + HILOG_ERROR("not find observer, observer:%{public}d", static_cast(observerId)); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); } @@ -249,7 +253,7 @@ private: task.ResolveWithNoError(engine, CreateJsAppStateDataArray(engine, list)); } else { HILOG_ERROR("OnGetForegroundApplications failed error:%{public}d", ret); - task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED)); + task.Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(ret))); } }; @@ -275,7 +279,7 @@ private: if (ret == 0) { task.ResolveWithNoError(engine, CreateJsProcessRunningInfoArray(engine, infos)); } else { - task.Reject(engine, CreateJsError(engine, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED)); + task.Reject(engine, CreateJsError(engine, GetJsErrorCodeByNativeError(ret))); } }; diff --git a/frameworks/js/napi/js_mission_manager/BUILD.gn b/frameworks/js/napi/js_mission_manager/BUILD.gn index 84ffb6dd10..b95b569b12 100755 --- a/frameworks/js/napi/js_mission_manager/BUILD.gn +++ b/frameworks/js/napi/js_mission_manager/BUILD.gn @@ -28,6 +28,7 @@ ohos_shared_library("missionmanager") { deps = [ "${ability_runtime_napi_path}/inner/napi_common:napi_common", + "${ability_runtime_native_path}/ability/native:ability_business_error", "${ability_runtime_services_path}/abilitymgr:abilityms", ] diff --git a/frameworks/js/napi/js_mission_manager/mission_manager.cpp b/frameworks/js/napi/js_mission_manager/mission_manager.cpp index 8becaf3a69..369fb0bd8d 100755 --- a/frameworks/js/napi/js_mission_manager/mission_manager.cpp +++ b/frameworks/js/napi/js_mission_manager/mission_manager.cpp @@ -151,7 +151,7 @@ private: if (ret == CHECK_PERMISSION_FAILED) { ThrowNoPermissionError(engine, PermissionConstants::PERMISSION_MANAGE_MISSION); } else { - ThrowError(engine, AbilityErrorCode::ERROR_CODE_INNER); + ThrowError(engine, GetJsErrorCodeByNativeError(ret)); } return engine.CreateUndefined(); } @@ -172,7 +172,7 @@ private: } int32_t missionListenerId = -1; - if (!ConvertFromJsValue(engine, info.argv[0], missionListenerId)) { + if (!ConvertFromJsValue(engine, info.argv[ARGC_ONE], missionListenerId)) { HILOG_ERROR("Parse missionListenerId failed"); ThrowError(engine, AbilityErrorCode::ERROR_CODE_INVALID_PARAM); return engine.CreateUndefined(); diff --git a/frameworks/js/napi/wantagent/BUILD.gn b/frameworks/js/napi/wantagent/BUILD.gn index e8841bfc12..0a56342521 100644 --- a/frameworks/js/napi/wantagent/BUILD.gn +++ b/frameworks/js/napi/wantagent/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("wantagent") { "ability_runtime:abilitykit_native", "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", + "access_token:libtokenid_sdk", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/frameworks/js/napi/wantagent/ability_want_agent/BUILD.gn b/frameworks/js/napi/wantagent/ability_want_agent/BUILD.gn index c46f907de5..e487e631e7 100644 --- a/frameworks/js/napi/wantagent/ability_want_agent/BUILD.gn +++ b/frameworks/js/napi/wantagent/ability_want_agent/BUILD.gn @@ -41,6 +41,7 @@ ohos_shared_library("wantagent_napi") { "ability_runtime:abilitykit_native", "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", + "access_token:libtokenid_sdk", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/frameworks/js/napi/wantagent/napi_want_agent.cpp b/frameworks/js/napi/wantagent/napi_want_agent.cpp index e5d7ff62c6..16167b5112 100644 --- a/frameworks/js/napi/wantagent/napi_want_agent.cpp +++ b/frameworks/js/napi/wantagent/napi_want_agent.cpp @@ -22,9 +22,12 @@ #include "ability_runtime_error_util.h" #include "hilog_wrapper.h" +#include "ipc_skeleton.h" #include "js_runtime_utils.h" #include "napi_common.h" #include "want_agent_helper.h" +#include "tokenid_kit.h" + using namespace OHOS::AbilityRuntime; namespace OHOS { #define NAPI_ASSERT_RETURN_NULL(env, assertion, message) \ @@ -926,6 +929,12 @@ NativeValue* JsWantAgent::OnNapiGetWant(NativeEngine &engine, NativeCallbackInfo AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); return engine.CreateUndefined(); } + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } if (info.argv[0]->TypeOf() != NativeValueType::NATIVE_OBJECT) { HILOG_ERROR("Wrong argument type. Object expected."); diff --git a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp index aa313b9283..6a7c8e2661 100644 --- a/frameworks/native/ability/ability_runtime/ability_context_impl.cpp +++ b/frameworks/native/ability/ability_runtime/ability_context_impl.cpp @@ -243,23 +243,23 @@ void AbilityContextImpl::OnAbilityResult(int requestCode, int resultCode, const HILOG_INFO("%{public}s. End calling OnAbilityResult.", __func__); } -bool AbilityContextImpl::ConnectAbility(const AAFwk::Want& want, const sptr& connectCallback) +ErrCode AbilityContextImpl::ConnectAbility(const AAFwk::Want& want, const sptr& connectCallback) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("ConnectAbility begin, name:%{public}s.", abilityInfo_ == nullptr ? "" : abilityInfo_->name.c_str()); ErrCode ret = ConnectionManager::GetInstance().ConnectAbility(token_, want, connectCallback); HILOG_INFO("AbilityContextImpl::ConnectAbility ErrorCode = %{public}d", ret); - return ret == ERR_OK; + return ret; } -bool AbilityContextImpl::ConnectAbilityWithAccount(const AAFwk::Want& want, int accountId, +ErrCode AbilityContextImpl::ConnectAbilityWithAccount(const AAFwk::Want& want, int accountId, const sptr& connectCallback) { HILOG_DEBUG("%{public}s begin.", __func__); ErrCode ret = ConnectionManager::GetInstance().ConnectAbilityWithAccount(token_, want, accountId, connectCallback); HILOG_INFO("AbilityContextImpl::ConnectAbility ErrorCode = %{public}d", ret); - return ret == ERR_OK; + return ret; } void AbilityContextImpl::DisconnectAbility(const AAFwk::Want& want, diff --git a/frameworks/native/ability/native/BUILD.gn b/frameworks/native/ability/native/BUILD.gn index ad604f6b64..e80e576110 100644 --- a/frameworks/native/ability/native/BUILD.gn +++ b/frameworks/native/ability/native/BUILD.gn @@ -212,6 +212,7 @@ ohos_shared_library("abilitykit_native") { "ability_runtime:runtime", "ability_runtime:wantagent_innerkits", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", "hisysevent_native:libhisysevent", diff --git a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp index 3da507c6d3..ce6883d587 100755 --- a/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp +++ b/frameworks/native/ability/native/ability_business_error/ability_business_error.cpp @@ -26,33 +26,35 @@ namespace { constexpr const char* TAG_PERMISSION = " permission:"; constexpr const char* ERROR_MSG_OK = "OK."; constexpr const char* ERROR_MSG_PERMISSION_DENIED = "The application does not have permission to call the interface."; +constexpr const char* ERROR_MSG_NOT_SYSTEM_APP = "The application is not system-app, can not use system-api."; constexpr const char* ERROR_MSG_INVALID_PARAM = "Invalid input parameter."; constexpr const char* ERROR_MSG_SYSTEMCAP = "The specified SystemCapability name was not found."; -constexpr const char* ERROR_MSG_INNER = "Inner Error."; +constexpr const char* ERROR_MSG_INNER = "Internal error."; constexpr const char* ERROR_MSG_RESOLVE_ABILITY = "The specified ability does not exist."; -constexpr const char* ERROR_MSG_INVALID_ABILITY_TYPE = "Ability type error. The specified ability type is wrong"; -constexpr const char* ERROR_MSG_INVALID_ID = "The specified id does not exist."; +constexpr const char* ERROR_MSG_INVALID_ABILITY_TYPE = "Incorrect ability type."; +constexpr const char* ERROR_MSG_INVALID_ID = "Input error. The specified ID does not exist."; constexpr const char* ERROR_MSG_INVISIBLE = "Can not start invisible component."; constexpr const char* ERROR_MSG_STATIC_CFG_PERMISSION = "The specified process does not have the permission."; -constexpr const char* ERROR_MSG_CROSS_USER = "Can not cross user operations."; -constexpr const char* ERROR_MSG_CROWDTEST_EXPIRED = "Crowdtest App Expiration."; -constexpr const char* ERROR_MSG_WUKONG_MODE = "Cannot operate in wukong mode."; -constexpr const char* ERROR_MSG_CONTINUATION_FLAG = "StartAbility with continuation flags is not allowed!"; -constexpr const char* ERROR_MSG_INVALID_CONTEXT = "Context does not exist!"; -constexpr const char* ERROR_MSG_NETWORK_ABNORMAL = "Network error. The network is abnormal when free install."; -constexpr const char* ERROR_MSG_NOT_SUPPORT_FREE_INSTALL = "The Application does not support free install."; -constexpr const char* ERROR_MSG_NOT_TOP_ABILITY = "Not top ability, Can not free install ability."; +constexpr const char* ERROR_MSG_CROSS_USER = "Cross-user operations are not allowed."; +constexpr const char* ERROR_MSG_CROWDTEST_EXPIRED = "The crowdtesting application expires."; +constexpr const char* ERROR_MSG_WUKONG_MODE = "An ability cannot be started or stopped in Wukong mode."; +constexpr const char* ERROR_MSG_CONTINUATION_FLAG = "The call with the continuation flage is forbidden."; +constexpr const char* ERROR_MSG_INVALID_CONTEXT = "The context does not exist."; +constexpr const char* ERROR_MSG_NETWORK_ABNORMAL = "Network error."; +constexpr const char* ERROR_MSG_NOT_SUPPORT_FREE_INSTALL = "Installation-free is not supported."; +constexpr const char* ERROR_MSG_NOT_TOP_ABILITY = "The ability is not on the top of the UI."; constexpr const char* ERROR_MSG_FREE_INSTALL_TOO_BUSY = - "Free install busyness. There are concurrent tasks waiting for retry."; -constexpr const char* ERROR_MSG_FREE_INSTALL_TIMEOUT = "Free install timeout."; -constexpr const char* ERROR_MSG_FREE_INSTALL_OTHERS = "Can not free install other ability."; -constexpr const char* ERROR_MSG_INVALID_CALLER = "Caller released, The caller has been released."; -constexpr const char* ERROR_MSG_NO_MISSION_ID = "The specified mission id does not exist."; -constexpr const char* ERROR_MSG_NO_MISSION_LISTENER = "The specified mission listener does not exist."; + "The installation-free service is busy. Try again later."; +constexpr const char* ERROR_MSG_FREE_INSTALL_TIMEOUT = "Installation-free timed out."; +constexpr const char* ERROR_MSG_FREE_INSTALL_OTHERS = "Installation-free is not allowed for other applications."; +constexpr const char* ERROR_MSG_INVALID_CALLER = "The caller has been released."; +constexpr const char* ERROR_MSG_NO_MISSION_ID = "The specified mission does not exist."; +constexpr const char* ERROR_MSG_NO_MISSION_LISTENER = "Input error. The specified mission listener does not exist."; static std::unordered_map ERR_CODE_MAP = { { AbilityErrorCode::ERROR_OK, ERROR_MSG_OK }, { AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED, ERROR_MSG_PERMISSION_DENIED }, + { AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP, ERROR_MSG_NOT_SYSTEM_APP }, { AbilityErrorCode::ERROR_CODE_INVALID_PARAM, ERROR_MSG_INVALID_PARAM }, { AbilityErrorCode::ERROR_CODE_SYSTEMCAP, ERROR_MSG_SYSTEMCAP }, { AbilityErrorCode::ERROR_CODE_INNER, ERROR_MSG_INNER }, @@ -80,6 +82,8 @@ static std::unordered_map ERR_CODE_MAP = { static std::unordered_map INNER_TO_JS_ERROR_CODE_MAP { {0, AbilityErrorCode::ERROR_OK}, {CHECK_PERMISSION_FAILED, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED}, + {ERR_PERMISSION_DENIED, AbilityErrorCode::ERROR_CODE_PERMISSION_DENIED}, + {ERR_NOT_SYSTEM_APP, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP}, {RESOLVE_ABILITY_ERR, AbilityErrorCode::ERROR_CODE_RESOLVE_ABILITY}, {ERR_WRONG_INTERFACE_CALL, AbilityErrorCode::ERROR_CODE_INVALID_ABILITY_TYPE}, {TARGET_ABILITY_NOT_SERVICE, AbilityErrorCode::ERROR_CODE_INVALID_ABILITY_TYPE}, diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 63fb1a478c..905a61dd56 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -418,6 +418,7 @@ void JsAbility::OnForeground(const Want &want) void JsAbility::OnBackground() { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); + HILOG_DEBUG("OnBackground begin, ability is %{public}s.", GetAbilityName().c_str()); CallObjectMethod("onBackground"); Ability::OnBackground(); @@ -432,6 +433,7 @@ void JsAbility::OnBackground() if (applicationContext != nullptr) { applicationContext->DispatchOnAbilityBackground(jsAbilityObj_); } + HILOG_DEBUG("OnBackground end, ability is %{public}s.", GetAbilityName().c_str()); } std::unique_ptr JsAbility::CreateAppWindowStage() @@ -896,7 +898,16 @@ std::shared_ptr JsAbility::CreateADelegat { auto property = std::make_shared(); property->token_ = GetAbilityContext()->GetToken(); - property->name_ = GetAbilityName(); + if (GetApplicationInfo() == nullptr || GetApplicationInfo()->bundleName.empty()) { + property->name_ = GetAbilityName(); + } else { + std::string::size_type pos = GetAbilityName().find(GetApplicationInfo()->bundleName); + if (pos == std::string::npos || pos != 0) { + property->name_ = GetApplicationInfo()->bundleName + "." + GetAbilityName(); + } else { + property->name_ = GetAbilityName(); + } + } property->lifecycleState_ = GetState(); property->object_ = jsAbilityObj_; diff --git a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp index 5fd4c54bcd..1bf78fc20a 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability_context.cpp @@ -24,6 +24,7 @@ #include "js_error_utils.h" #include "js_runtime_utils.h" #include "ability_runtime/js_caller_complex.h" +#include "ipc_skeleton.h" #include "napi_common_ability.h" #include "napi_common_start_options.h" #include "napi_common_util.h" @@ -33,6 +34,7 @@ #include "want.h" #include "event_handler.h" #include "hitrace_meter.h" +#include "tokenid_kit.h" #ifdef SUPPORT_GRAPHICS #include "pixel_map_napi.h" @@ -45,7 +47,6 @@ constexpr size_t ARGC_ZERO = 0; constexpr size_t ARGC_ONE = 1; constexpr size_t ARGC_TWO = 2; constexpr size_t ARGC_THREE = 3; -constexpr int32_t ERROR_CODE_ONE = 1; class StartAbilityByCallParameters { public: @@ -69,6 +70,12 @@ NativeValue* JsAbilityContext::StartAbility(NativeEngine* engine, NativeCallback return (me != nullptr) ? me->OnStartAbility(*engine, *info) : nullptr; } +NativeValue* JsAbilityContext::StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info) +{ + JsAbilityContext* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnStartAbility(*engine, *info, true) : nullptr; +} + NativeValue* JsAbilityContext::StartAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info) { JsAbilityContext* me = CheckParamsAndGetThis(engine, info); @@ -167,7 +174,7 @@ NativeValue* JsAbilityContext::IsTerminating(NativeEngine* engine, NativeCallbac return (me != nullptr) ? me->OnIsTerminating(*engine, *info) : nullptr; } -NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info) +NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("OnStartAbility is called."); @@ -190,6 +197,12 @@ NativeValue* JsAbilityContext::OnStartAbility(NativeEngine& engine, NativeCallba reinterpret_cast(info.argv[1]), startOptions); unwrapArgc++; } + + if (isStartRecent) { + HILOG_INFO("OnStartRecentAbility is called"); + want.SetParam(Want::PARAM_RESV_START_RECENT, true); + } + AsyncTask::CompleteCallback complete = [weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) { auto context = weak.lock(); @@ -441,6 +454,12 @@ NativeValue* JsAbilityContext::OnStartAbilityForResult(NativeEngine& engine, Nat NativeValue* JsAbilityContext::OnStartAbilityForResultWithAccount(NativeEngine& engine, NativeCallbackInfo& info) { HILOG_INFO("OnStartAbilityForResultWithAccount is called"); + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + ThrowError(engine, AbilityErrorCode::ERROR_CODE_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } if (info.argc < ARGC_TWO) { HILOG_ERROR("Not enough params"); ThrowTooFewParametersError(engine); @@ -748,8 +767,11 @@ NativeValue* JsAbilityContext::OnConnectAbility(NativeEngine& engine, NativeCall task.Reject(engine, CreateJsError(engine, 1, "Context is released")); return; } - if (!context->ConnectAbility(want, connection)) { - connection->CallJsFailed(ERROR_CODE_ONE); + HILOG_INFO("ConnectAbility connection:%{public}d", static_cast(connectId)); + auto innerErrorCode = context->ConnectAbility(want, connection); + int32_t errcode = static_cast(AbilityRuntime::GetJsErrorCodeByNativeError(innerErrorCode)); + if (errcode) { + connection->CallJsFailed(errcode); } task.Resolve(engine, engine.CreateUndefined()); }; @@ -811,9 +833,11 @@ NativeValue* JsAbilityContext::OnConnectAbilityWithAccount(NativeEngine& engine, task.Reject(engine, CreateJsError(engine, 1, "Context is released")); return; } - HILOG_INFO("context->ConnectAbilityWithAccount connection:%{public}d", (int32_t)connectId); - if (!context->ConnectAbilityWithAccount(want, accountId, connection)) { - connection->CallJsFailed(ERROR_CODE_ONE); + HILOG_INFO("context->ConnectAbilityWithAccount connection:%{public}d", static_cast(connectId)); + auto innerErrorCode = context->ConnectAbilityWithAccount(want, accountId, connection); + int32_t errcode = static_cast(AbilityRuntime::GetJsErrorCodeByNativeError(innerErrorCode)); + if (errcode) { + connection->CallJsFailed(errcode); } task.Resolve(engine, engine.CreateUndefined()); }; @@ -1163,6 +1187,8 @@ NativeValue* CreateJsAbilityContext(NativeEngine& engine, std::shared_ptrOnStartAbility(*engine, *info) : nullptr; } + static NativeValue* StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info) + { + JsServiceExtensionContext* me = CheckParamsAndGetThis(engine, info); + return (me != nullptr) ? me->OnStartAbility(*engine, *info, true) : nullptr; + } + static NativeValue* StartAbilityByCall(NativeEngine* engine, NativeCallbackInfo* info) { JsServiceExtensionContext* me = CheckParamsAndGetThis(engine, info); @@ -134,7 +140,7 @@ public: private: std::weak_ptr context_; - NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info) + NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent = false) { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("OnStartAbility is called"); @@ -152,6 +158,11 @@ private: return engine.CreateUndefined(); } + if (isStartRecent) { + HILOG_INFO("OnStartRecentAbility is called"); + want.SetParam(Want::PARAM_RESV_START_RECENT, true); + } + AsyncTask::CompleteCallback complete = [weak = context_, want, startOptions, unwrapArgc](NativeEngine& engine, AsyncTask& task, int32_t status) { HILOG_INFO("startAbility begin"); @@ -872,6 +883,8 @@ NativeValue* CreateJsServiceExtensionContext(NativeEngine& engine, std::shared_p JsServiceExtensionContext::StopServiceExtensionAbility); BindNativeFunction(engine, *object, "stopServiceExtensionAbilityWithAccount", moduleName, JsServiceExtensionContext::StopServiceExtensionAbilityWithAccount); + BindNativeFunction(engine, *object, "startRecentAbility", moduleName, + JsServiceExtensionContext::StartRecentAbility); return objValue; } diff --git a/frameworks/native/appkit/BUILD.gn b/frameworks/native/appkit/BUILD.gn index 8786059f7a..7b3259a5a2 100644 --- a/frameworks/native/appkit/BUILD.gn +++ b/frameworks/native/appkit/BUILD.gn @@ -249,6 +249,7 @@ ohos_shared_library("app_context_utils") { external_deps = [ "ability_runtime:ability_runtime_error_util", "ability_runtime:runtime", + "access_token:libtokenid_sdk", "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", diff --git a/frameworks/native/appkit/ability_delegator/ability_delegator.cpp b/frameworks/native/appkit/ability_delegator/ability_delegator.cpp index 5ed9f036fd..39971ddedb 100644 --- a/frameworks/native/appkit/ability_delegator/ability_delegator.cpp +++ b/frameworks/native/appkit/ability_delegator/ability_delegator.cpp @@ -204,16 +204,25 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr AbilityDelegator::GetCurrentTopAbility() { - sptr topAbilityToken; - if (AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(topAbilityToken)) { + AppExecFwk::ElementName elementName = AAFwk::AbilityManagerClient::GetInstance()->GetTopAbility(); + std::string bundleName = elementName.GetBundleName(); + std::string abilityName = elementName.GetAbilityName(); + if (abilityName.empty()) { HILOG_ERROR("Failed to get top ability"); return {}; } + if (!bundleName.empty()) { + std::string::size_type pos = abilityName.find(bundleName); + if (pos == std::string::npos || pos != 0) { + abilityName = bundleName + "." + abilityName; + } + } + std::unique_lock lck(mutexAbilityProperties_); - auto existedProperty = FindPropertyByToken(topAbilityToken); + auto existedProperty = FindPropertyByName(abilityName); if (!existedProperty) { - HILOG_WARN("Unknown ability token"); + HILOG_WARN("Unknown ability name"); return {}; } @@ -654,7 +663,31 @@ std::shared_ptr AbilityDelegator::FindPropertyByToken } if (token == it->token_) { - HILOG_INFO("Porperty exists"); + HILOG_INFO("Property exists"); + return it; + } + } + + return {}; +} + +std::shared_ptr AbilityDelegator::FindPropertyByName(const std::string &name) +{ + HILOG_INFO("Enter"); + + if (name.empty()) { + HILOG_WARN("Invalid input parameter"); + return {}; + } + + for (const auto &it : abilityProperties_) { + if (!it) { + HILOG_WARN("Invalid ability property"); + continue; + } + + if (name == it->name_) { + HILOG_INFO("Property exists"); return it; } } diff --git a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp index 655ec710ed..2ef60d1739 100644 --- a/frameworks/native/appkit/ability_runtime/context/context_impl.cpp +++ b/frameworks/native/appkit/ability_runtime/context/context_impl.cpp @@ -490,7 +490,7 @@ void ContextImpl::InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleIn std::shared_ptr ContextImpl::GetHapModuleInfo() const { if (hapModuleInfo_ == nullptr) { - HILOG_ERROR("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty"); + HILOG_DEBUG("ContextImpl::GetHapModuleInfo, hapModuleInfo is empty"); } return hapModuleInfo_; } diff --git a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp index 5b67da9b37..d3477ec91d 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_application_context_utils.cpp @@ -20,11 +20,13 @@ #include "ability_runtime_error_util.h" #include "application_context.h" #include "hilog_wrapper.h" +#include "ipc_skeleton.h" #include "js_context_utils.h" #include "js_data_struct_converter.h" #include "js_hap_module_info_utils.h" #include "js_resource_manager_utils.h" #include "js_runtime_utils.h" +#include "tokenid_kit.h" namespace OHOS { namespace AbilityRuntime { @@ -101,6 +103,8 @@ private: NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetApplicationContext(NativeEngine& engine, NativeCallbackInfo& info); + bool CheckCallerIsSystemApp(); + std::shared_ptr keepApplicationContext_; std::shared_ptr callback_; std::shared_ptr envCallback_; @@ -115,6 +119,12 @@ NativeValue *JsApplicationContextUtils::CreateBundleContext(NativeEngine *engine NativeValue *JsApplicationContextUtils::OnCreateBundleContext(NativeEngine &engine, NativeCallbackInfo &info) { + if (!CheckCallerIsSystemApp()) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } + if (info.argc == 0) { HILOG_ERROR("Not enough params"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); @@ -223,6 +233,12 @@ NativeValue* JsApplicationContextUtils::CreateModuleContext(NativeEngine* engine NativeValue* JsApplicationContextUtils::OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info) { + if (!CheckCallerIsSystemApp()) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } + auto applicationContext = applicationContext_.lock(); if (!applicationContext) { HILOG_WARN("applicationContext is already released"); @@ -857,6 +873,15 @@ NativeValue* JsApplicationContextUtils::OnGetApplicationContext(NativeEngine& en nullptr); return contextObj; } + +bool JsApplicationContextUtils::CheckCallerIsSystemApp() +{ + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + return false; + } + return true; +} } // namespace NativeValue *CreateJsApplicationContext(NativeEngine &engine, std::shared_ptr applicationContext, diff --git a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp index 51b890ae45..df5243700d 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp @@ -17,11 +17,13 @@ #include "ability_runtime_error_util.h" #include "hilog_wrapper.h" +#include "ipc_skeleton.h" #include "js_application_context_utils.h" #include "js_data_struct_converter.h" #include "js_hap_module_info_utils.h" #include "js_resource_manager_utils.h" #include "js_runtime_utils.h" +#include "tokenid_kit.h" #include "application_context.h" namespace OHOS { @@ -71,6 +73,7 @@ private: NativeValue* OnSwitchArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnGetArea(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info); + bool CheckCallerIsSystemApp(); std::shared_ptr keepContext_; }; @@ -146,6 +149,12 @@ NativeValue* JsBaseContext::CreateModuleContext(NativeEngine* engine, NativeCall NativeValue* JsBaseContext::OnCreateModuleContext(NativeEngine& engine, NativeCallbackInfo& info) { + if (!CheckCallerIsSystemApp()) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } + auto context = context_.lock(); if (!context) { HILOG_WARN("context is already released"); @@ -200,7 +209,7 @@ NativeValue* JsBaseContext::OnCreateModuleContext(NativeEngine& engine, NativeCa nativeObj->SetNativePointer( workContext, [](NativeEngine *, void *data, void *) { - HILOG_INFO("Finalizer for weak_ptr module context is called"); + HILOG_DEBUG("Finalizer for weak_ptr module context is called"); delete static_cast *>(data); }, nullptr); @@ -353,6 +362,12 @@ NativeValue* JsBaseContext::OnGetBundleCodeDir(NativeEngine& engine, NativeCallb NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCallbackInfo& info) { + if (!CheckCallerIsSystemApp()) { + HILOG_ERROR("This application is not system-app, can not use system-api"); + AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP); + return engine.CreateUndefined(); + } + if (info.argc == 0) { HILOG_ERROR("Not enough params"); AbilityRuntimeErrorUtil::Throw(engine, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); @@ -399,7 +414,7 @@ NativeValue* JsBaseContext::OnCreateBundleContext(NativeEngine& engine, NativeCa nativeObj->SetNativePointer( workContext, [](NativeEngine *, void *data, void *) { - HILOG_INFO("Finalizer for weak_ptr bundle context is called"); + HILOG_DEBUG("Finalizer for weak_ptr bundle context is called"); delete static_cast *>(data); }, nullptr); @@ -442,12 +457,21 @@ NativeValue* JsBaseContext::OnGetApplicationContext(NativeEngine& engine, Native nativeObj->SetNativePointer( workContext, [](NativeEngine *, void *data, void *) { - HILOG_INFO("Finalizer for weak_ptr application context is called"); + HILOG_DEBUG("Finalizer for weak_ptr application context is called"); delete static_cast *>(data); }, nullptr); return contextObj; } + +bool JsBaseContext::CheckCallerIsSystemApp() +{ + auto selfToken = IPCSkeleton::GetSelfTokenID(); + if (!Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(selfToken)) { + return false; + } + return true; +} } // namespace NativeValue* AttachBaseContext(NativeEngine* engine, void* value, void* hint) @@ -478,7 +502,7 @@ NativeValue* AttachBaseContext(NativeEngine* engine, void* value, void* hint) auto workContext = new (std::nothrow) std::weak_ptr(ptr); nObject->SetNativePointer(workContext, [](NativeEngine *, void *data, void *) { - HILOG_INFO("Finalizer for weak_ptr base context is called"); + HILOG_DEBUG("Finalizer for weak_ptr base context is called"); delete static_cast *>(data); }, nullptr); return contextObj; diff --git a/frameworks/native/runtime/js_console_log.cpp b/frameworks/native/runtime/js_console_log.cpp index a22e8d9966..6460ed3385 100644 --- a/frameworks/native/runtime/js_console_log.cpp +++ b/frameworks/native/runtime/js_console_log.cpp @@ -45,7 +45,7 @@ std::string MakeLogContent(NativeCallbackInfo& info) size_t bufferLen = str->GetLength(); if (bufferLen >= JS_CONSOLE_LOG_MAX_LOG_LEN) { - HILOG_ERROR("Log length exceeds maximum"); + HILOG_DEBUG("Log length exceeds maximum"); return content; } diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h index 0cae3d06d5..eb43046143 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_errors.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_errors.h @@ -303,6 +303,11 @@ enum { * Result(2097208) for not granted for static permission. */ ERR_STATIC_CFG_PERMISSION, + + /** + * Result(2097209) for non-system-app use system-api. + */ + ERR_NOT_SYSTEM_APP, }; enum { diff --git a/interfaces/inner_api/app_manager/src/appmgr/component_interception_proxy.cpp b/interfaces/inner_api/app_manager/src/appmgr/component_interception_proxy.cpp index 1f9746099e..df7242b7fa 100755 --- a/interfaces/inner_api/app_manager/src/appmgr/component_interception_proxy.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/component_interception_proxy.cpp @@ -44,7 +44,14 @@ bool ComponentInterceptionProxy::AllowComponentStart(const Want &want, const spt return true; } data.WriteParcelable(&want); - data.WriteRemoteObject(callerToken); + + if (callerToken == nullptr) { + data.WriteBool(false); + } else { + data.WriteBool(true); + data.WriteRemoteObject(callerToken); + } + data.WriteInt32(requestCode); data.WriteInt32(componentStatus); sptr remote = Remote(); diff --git a/interfaces/inner_api/app_manager/src/appmgr/component_interception_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/component_interception_stub.cpp index 446c30f03e..c1e96c7da6 100755 --- a/interfaces/inner_api/app_manager/src/appmgr/component_interception_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/component_interception_stub.cpp @@ -68,7 +68,12 @@ int32_t ComponentInterceptionStub::HandleAllowComponentStart(MessageParcel &data HILOG_ERROR("ReadParcelable failed"); return ERR_APPEXECFWK_PARCEL_ERROR; } - sptr token = data.ReadRemoteObject(); + sptr token = nullptr; + bool hasRemoteToken = data.ReadBool(); + if (hasRemoteToken) { + token = data.ReadRemoteObject(); + } + int requestCode = data.ReadInt32(); int componentStatus = data.ReadInt32(); diff --git a/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h b/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h index 6df32e5fac..de97ca5767 100644 --- a/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h +++ b/interfaces/inner_api/error_utils/include/ability_runtime_error_util.h @@ -72,6 +72,7 @@ enum { ERR_ABILITY_RUNTIME_EXTERNAL_QUICK_FIX_INTERNAL_ERROR = 18500008, ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION = 201, + ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP = 202, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER = 401, ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP = 801, }; diff --git a/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp b/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp index 2d8db1778a..a0757e389a 100644 --- a/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp +++ b/interfaces/inner_api/error_utils/src/ability_runtime_error_util.cpp @@ -121,6 +121,8 @@ const std::map ERROR_MSG_MAP = { "Internal error." }, { ERR_ABILITY_RUNTIME_EXTERNAL_NO_ACCESS_PERMISSION, "The application does not have permission to call the interface." }, + { ERR_ABILITY_RUNTIME_NOT_SYSTEM_APP, + "The application is not system-app, can not use system-api." }, { ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER, "Invalid input parameter." }, { ERR_ABILITY_RUNTIME_EXTERNAL_NO_SUCH_SYSCAP, diff --git a/interfaces/inner_api/quick_fix/include/quick_fix_error_utils.h b/interfaces/inner_api/quick_fix/include/quick_fix_error_utils.h index 22f9c2ba59..bad2482b88 100644 --- a/interfaces/inner_api/quick_fix/include/quick_fix_error_utils.h +++ b/interfaces/inner_api/quick_fix/include/quick_fix_error_utils.h @@ -42,6 +42,7 @@ enum { QUICK_FIX_SET_INFO_FAILED = 17, QUICK_FIX_PROCESS_TIMEOUT = 18, QUICK_FIX_NOTIFY_UNLOAD_PATCH_FAILED = 19, + QUICK_FIX_NOT_SYSTEM_APP = 20, }; enum { @@ -51,6 +52,9 @@ enum { // The application does not have permission to call the interface. ERR_QUICKFIX_PERMISSION_DENIED = 201, + // non-system-app use system-api. + ERR_QUICKFIX_NOT_SYSTEM_APP = 202, + // Invalid input parameter. ERR_QUICKFIX_PARAM_INVALID = 401, diff --git a/interfaces/inner_api/quick_fix/src/quick_fix_error_utils.cpp b/interfaces/inner_api/quick_fix/src/quick_fix_error_utils.cpp index c76c02070e..6070c38d65 100644 --- a/interfaces/inner_api/quick_fix/src/quick_fix_error_utils.cpp +++ b/interfaces/inner_api/quick_fix/src/quick_fix_error_utils.cpp @@ -29,6 +29,7 @@ const std::map INTERNAL_ERR_CODE_MAP = { { QUICK_FIX_INVALID_PARAM, ERR_QUICKFIX_PARAM_INVALID }, { QUICK_FIX_CONNECT_FAILED, ERR_QUICKFIX_INTERNAL_ERROR }, { QUICK_FIX_VERIFY_PERMISSION_FAILED, ERR_QUICKFIX_PERMISSION_DENIED }, + { QUICK_FIX_NOT_SYSTEM_APP, ERR_QUICKFIX_NOT_SYSTEM_APP }, { QUICK_FIX_GET_BUNDLE_INFO_FAILED, ERR_QUICKFIX_BUNDLE_NAME_INVALID }, { QUICK_FIX_DEPLOY_FAILED, ERR_QUICKFIX_HQF_DEPLOY_FAILED }, { QUICK_FIX_SWICH_FAILED, ERR_QUICKFIX_HQF_SWITCH_FAILED }, @@ -59,6 +60,7 @@ const std::map INTERNAL_ERR_MSG_MAP = { const std::map EXTERNAL_ERR_MSG_MAP = { { ERR_OK, "Success." }, { ERR_QUICKFIX_PERMISSION_DENIED, "The application does not have permission to call the interface." }, + { ERR_QUICKFIX_NOT_SYSTEM_APP, "The application is not system-app, can not use system-api." }, { ERR_QUICKFIX_PARAM_INVALID, "Invalid input parameter." }, { ERR_QUICKFIX_BUNDLE_NAME_INVALID, "The specified bundleName is invalid." }, { ERR_QUICKFIX_HQF_INVALID, "The specified hqf is invalid. Hqf may not exist or inaccessible." }, diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context.h b/interfaces/kits/native/ability/ability_runtime/ability_context.h index 5411fc3eb6..78dd4099e5 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context.h @@ -134,7 +134,7 @@ public: * @param connectCallback Indicates the callback object when the target ability is connected. * @return True means success and false means failure */ - virtual bool ConnectAbility(const AAFwk::Want &want, const sptr &connectCallback) = 0; + virtual ErrCode ConnectAbility(const AAFwk::Want &want, const sptr &connectCallback) = 0; /** * @brief Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template. @@ -143,7 +143,7 @@ public: * @param connectCallback Indicates the callback object when the target ability is connected. * @return True means success and false means failure */ - virtual bool ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId, + virtual ErrCode ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId, const sptr &connectCallback) = 0; /** diff --git a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h index bee5a268f8..4b8467ebe6 100644 --- a/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h +++ b/interfaces/kits/native/ability/ability_runtime/ability_context_impl.h @@ -68,9 +68,9 @@ public: ErrCode StopServiceExtensionAbility(const Want& want, int32_t accountId = -1) override; ErrCode TerminateAbilityWithResult(const AAFwk::Want &want, int resultCode) override; void OnAbilityResult(int requestCode, int resultCode, const AAFwk::Want &resultData) override; - bool ConnectAbility(const AAFwk::Want &want, + ErrCode ConnectAbility(const AAFwk::Want &want, const sptr &connectCallback) override; - bool ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId, + ErrCode ConnectAbilityWithAccount(const AAFwk::Want &want, int accountId, const sptr &connectCallback) override; void DisconnectAbility(const AAFwk::Want &want, const sptr &connectCallback) override; diff --git a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h index 3ab89bc154..169a2089fa 100755 --- a/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h +++ b/interfaces/kits/native/ability/native/ability_business_error/ability_business_error.h @@ -27,6 +27,9 @@ enum class AbilityErrorCode { // no such permission. ERROR_CODE_PERMISSION_DENIED = 201, + // non-system-app use system-api. + ERROR_CODE_NOT_SYSTEM_APP = 202, + // invalid param. ERROR_CODE_INVALID_PARAM = 401, diff --git a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h index d5ec0d30f9..a54e935f64 100644 --- a/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h +++ b/interfaces/kits/native/ability/native/ability_runtime/js_ability_context.h @@ -39,6 +39,7 @@ public: static void Finalizer(NativeEngine* engine, void* data, void* hint); static NativeValue* StartAbility(NativeEngine* engine, NativeCallbackInfo* info); + static NativeValue* StartRecentAbility(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* StartAbilityWithAccount(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* StartAbilityByCall(NativeEngine* engine, NativeCallbackInfo* info); static NativeValue* StartAbilityForResult(NativeEngine* engine, NativeCallbackInfo* info); @@ -75,7 +76,7 @@ private: #endif private: - NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info); + NativeValue* OnStartAbility(NativeEngine& engine, NativeCallbackInfo& info, bool isStartRecent = false); NativeValue* OnStartAbilityWithAccount(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnStartAbilityByCall(NativeEngine& engine, NativeCallbackInfo& info); NativeValue* OnStartAbilityForResult(NativeEngine& engine, NativeCallbackInfo& info); diff --git a/interfaces/kits/native/ability/native/data_ability_helper_impl.h b/interfaces/kits/native/ability/native/data_ability_helper_impl.h index 4412ab6cf6..d130f99d83 100644 --- a/interfaces/kits/native/ability/native/data_ability_helper_impl.h +++ b/interfaces/kits/native/ability/native/data_ability_helper_impl.h @@ -20,7 +20,7 @@ #include #include -#include "context.h" +#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/app/context.h" #include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" #include "uri.h" diff --git a/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h b/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h index a0a5f4dedb..22f1a863b6 100644 --- a/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h +++ b/interfaces/kits/native/appkit/ability_delegator/ability_delegator.h @@ -328,7 +328,7 @@ private: void ProcessAbilityProperties(const std::shared_ptr &ability); void RemoveAbilityProperty(const std::shared_ptr &ability); std::shared_ptr FindPropertyByToken(const sptr &token); - + std::shared_ptr FindPropertyByName(const std::string &name); inline void CallClearFunc(const std::shared_ptr &ability); private: diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index e538e95ad9..d0b86c6f68 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -1174,6 +1174,10 @@ private: AAFWK::EventInfo BuildEventInfo(const Want &want, int32_t userId); + int CheckDlpForExtension( + const Want &want, const sptr &callerToken, + int32_t userId, AAFWK::EventInfo &eventInfo, const std::string &eventName); + void InitStartupFlag(); void UpdateAbilityRequestInfo(const sptr &want, AbilityRequest &request); diff --git a/services/abilitymgr/include/ability_record.h b/services/abilitymgr/include/ability_record.h index b146c10a90..25cfa4ad61 100644 --- a/services/abilitymgr/include/ability_record.h +++ b/services/abilitymgr/include/ability_record.h @@ -199,6 +199,7 @@ struct AbilityRequest { bool restart = false; int32_t restartCount = -1; int64_t restartTime = 0; + bool startRecent = false; // call ability int callerUid = -1; diff --git a/services/abilitymgr/include/mission.h b/services/abilitymgr/include/mission.h index eb75eca573..46050f1ca8 100644 --- a/services/abilitymgr/include/mission.h +++ b/services/abilitymgr/include/mission.h @@ -55,6 +55,13 @@ public: */ bool IsSpecifiedAbility() const; + /** + * check whether ability contains by this mission is standard. + * + * @return is ability contains by this mission is standard. + */ + bool IsStandardAbility() const; + /** * get owner mission list. * @@ -188,6 +195,16 @@ public: return needNotifyUpdateLabel_; } + inline void UpdateMissionTime(const std::string &missionTime) + { + missionTime_ = missionTime; + } + + inline std::string GetMissionTime() const + { + return missionTime_; + } + private: int32_t missionId_; int32_t startMethod_; @@ -200,6 +217,7 @@ private: bool isANRState_ = false; bool needNotify_ = true; bool needNotifyUpdateLabel_ = false; + std::string missionTime_ = "0"; }; } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/include/mission_info_mgr.h b/services/abilitymgr/include/mission_info_mgr.h index 1d5ed841fd..4d730d3dc1 100644 --- a/services/abilitymgr/include/mission_info_mgr.h +++ b/services/abilitymgr/include/mission_info_mgr.h @@ -97,10 +97,12 @@ public: * * @param missionName name of mission. * @param flag name of specified mission flag. + * @param isFindRecentStandard find recent standard mission. * @param info found mission info. * @return true if success. */ - bool FindReusedMissionInfo(const std::string &missionName, const std::string &flag, InnerMissionInfo &info); + bool FindReusedMissionInfo(const std::string &missionName, const std::string &flag, + bool isFindRecentStandard, InnerMissionInfo &info); /** * @brief Delete all the mission info. diff --git a/services/abilitymgr/include/mission_list.h b/services/abilitymgr/include/mission_list.h index d7d8e1a704..70f3c9430c 100644 --- a/services/abilitymgr/include/mission_list.h +++ b/services/abilitymgr/include/mission_list.h @@ -70,6 +70,14 @@ public: */ std::shared_ptr GetSpecifiedMission(const std::string& missionName, const std::string& flag) const; + /** + * Get recent standard mission by name. + * + * @param missionName target mission name. + * @return founded mission. + */ + std::shared_ptr GetRecentStandardMission(const std::string& missionName) const; + /** * Get top mission of this mission list. * diff --git a/services/abilitymgr/include/mission_list_manager.h b/services/abilitymgr/include/mission_list_manager.h index 4cf743558d..86d1fa8bff 100644 --- a/services/abilitymgr/include/mission_list_manager.h +++ b/services/abilitymgr/include/mission_list_manager.h @@ -392,11 +392,12 @@ private: const std::shared_ptr &callerAbility, const AbilityRequest &abilityRequest); std::shared_ptr GetReusedMission(const AbilityRequest &abilityRequest); std::shared_ptr GetReusedSpecifiedMission(const AbilityRequest &abilityRequest); + std::shared_ptr GetReusedStandardMission(const AbilityRequest &abilityRequest); void GetTargetMissionAndAbility(const AbilityRequest &abilityRequest, std::shared_ptr &targetMission, std::shared_ptr &targetRecord); bool HandleReusedMissionAndAbility(const AbilityRequest &abilityRequest, std::shared_ptr &targetMission, std::shared_ptr &targetRecord); - std::string GetMissionName(const AbilityRequest &abilityRequest, bool isStandard) const; + std::string GetMissionName(const AbilityRequest &abilityRequest) const; bool CreateOrReusedMissionInfo(const AbilityRequest &abilityRequest, InnerMissionInfo &info) const; void MoveMissionToTargetList(bool isCallFromLauncher, const std::shared_ptr &targetMissionList, diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 3efef2f6c2..fb1faec1fe 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -889,7 +889,8 @@ int AbilityManagerProxy::GetMissionSnapshot(const std::string& deviceId, int32_t std::unique_ptr info(reply.ReadParcelable()); if (!info) { HILOG_ERROR("readParcelableInfo failed."); - return ERR_UNKNOWN_OBJECT; + auto errorCode = reply.ReadInt32(); + return errorCode ? errorCode : ERR_UNKNOWN_OBJECT; } snapshot = *info; return reply.ReadInt32(); diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index efc6a130be..68511b08e5 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -51,6 +51,7 @@ #include "string_ex.h" #include "system_ability_definition.h" #include "os_account_manager_wrapper.h" +#include "permission_constants.h" #include "uri_permission_manager_client.h" #include "xcollie/watchdog.h" #include "hisysevent.h" @@ -79,6 +80,12 @@ using OHOS::Security::AccessToken::AccessTokenKit; namespace OHOS { namespace AAFwk { namespace { +#define CHECK_CALLER_IS_SYSTEM_APP \ + if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { \ + HILOG_ERROR("The caller is not system-app, can not use system-api"); \ + return ERR_NOT_SYSTEM_APP; \ + } + const std::string ARGS_USER_ID = "-u"; const std::string ARGS_CLIENT = "-c"; const std::string ILLEGAL_INFOMATION = "The arguments are illegal and you can enter '-h' for help."; @@ -283,6 +290,7 @@ const std::string DLP_INDEX = "ohos.dlp.params.index"; const std::string BOOTEVENT_APPFWK_READY = "bootevent.appfwk.ready"; const std::string BOOTEVENT_BOOT_COMPLETED = "bootevent.boot.completed"; const std::string BOOTEVENT_BOOT_ANIMATION_STARTED = "bootevent.bootanimation.started"; +const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; const int DEFAULT_DMS_MISSION_ID = -1; const std::map AbilityManagerService::dumpMap = { std::map::value_type("--all", KEY_DUMP_ALL), @@ -476,6 +484,9 @@ int AbilityManagerService::StartAbility(const Want &want, int32_t userId, int re { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_INFO("%{public}s coldStart:%{public}d", __func__, want.GetBoolParam("coldStart", false)); + if (userId != DEFAULT_INVAL_VALUE) { + CHECK_CALLER_IS_SYSTEM_APP; + } AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId); AAFWK::EventReport::SendAbilityEvent(AAFWK::START_ABILITY, HiSysEventType::BEHAVIOR, eventInfo); int32_t ret = StartAbilityInner(want, nullptr, requestCode, -1, userId); @@ -490,6 +501,9 @@ int AbilityManagerService::StartAbility(const Want &want, const sptr(extensionType); AAFWK::EventReport::SendExtensionEvent(AAFWK::START_SERVICE, HiSysEventType::BEHAVIOR, eventInfo); - if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || - VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || - !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { - HILOG_ERROR("%{public}s: Permission verification failed.", __func__); - eventInfo.errCode = CHECK_PERMISSION_FAILED; - AAFWK::EventReport::SendExtensionEvent(AAFWK::START_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); - return CHECK_PERMISSION_FAILED; + + auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::START_EXTENSION_ERROR); + if (result != ERR_OK) { + HILOG_ERROR("CheckDlpForExtension error."); + return result; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { @@ -1080,7 +1099,7 @@ int AbilityManagerService::StartExtensionAbility(const Want &want, const sptrDoProcess(want, 0, GetUserId(), false); if (result != ERR_OK) { return result; @@ -1151,16 +1170,15 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptr(extensionType); AAFWK::EventReport::SendExtensionEvent(AAFWK::STOP_SERVICE, HiSysEventType::BEHAVIOR, eventInfo); - if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || - VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || - !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { - HILOG_ERROR("%{public}s: Permission verification failed.", __func__); - eventInfo.errCode = CHECK_PERMISSION_FAILED; - AAFWK::EventReport::SendExtensionEvent(AAFWK::STOP_EXTENSION_ERROR, HiSysEventType::FAULT, eventInfo); - return CHECK_PERMISSION_FAILED; + + auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::STOP_EXTENSION_ERROR); + if (result != ERR_OK) { + HILOG_ERROR("CheckDlpForExtension error."); + return result; } if (callerToken != nullptr && !VerificationAllToken(callerToken)) { @@ -1178,7 +1196,7 @@ int AbilityManagerService::StopExtensionAbility(const Want &want, const sptrAsObject(), ERR_INVALID_VALUE); + if (extensionType == AppExecFwk::ExtensionAbilityType::SERVICE && userId != DEFAULT_INVAL_VALUE) { + CHECK_CALLER_IS_SYSTEM_APP; + } AAFWK::EventInfo eventInfo = BuildEventInfo(want, userId); AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE, HiSysEventType::BEHAVIOR, eventInfo); - if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || - VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || - !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { - HILOG_ERROR("%{public}s: Permission verification failed", __func__); - eventInfo.errCode = CHECK_PERMISSION_FAILED; - AAFWK::EventReport::SendExtensionEvent(AAFWK::CONNECT_SERVICE_ERROR, HiSysEventType::FAULT, eventInfo); - return CHECK_PERMISSION_FAILED; + auto result = CheckDlpForExtension(want, callerToken, userId, eventInfo, AAFWK::CONNECT_SERVICE_ERROR); + if (result != ERR_OK) { + HILOG_ERROR("CheckDlpForExtension error."); + return result; } - auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : + result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(want, 0, GetUserId(), false); if (result != ERR_OK) { return result; @@ -1634,6 +1652,14 @@ int AbilityManagerService::ConnectAbilityCommon( AppExecFwk::ExtensionAbilityInfo extensionInfo; auto bms = GetBundleManager(); CHECK_POINTER_AND_RETURN(bms, ERR_INVALID_VALUE); + + AbilityRequest abilityRequest; + abilityWant.SetParam("abilityConnectionObj", connect->AsObject()); + if (!IsComponentInterceptionStart(abilityWant, callerToken, 0, 0, abilityRequest)) { + return ERR_OK; + } + abilityWant.RemoveParam("abilityConnectionObj"); + bool queryResult = IN_PROCESS_CALL(bms->QueryExtensionAbilityInfoByUri(uri, validUserId, extensionInfo)); if (!queryResult || extensionInfo.name.empty() || extensionInfo.bundleName.empty()) { HILOG_ERROR("Invalid extension ability info."); @@ -1917,6 +1943,7 @@ int AbilityManagerService::GetDlpConnectionInfos(std::vector &listener) { + CHECK_CALLER_IS_SYSTEM_APP; std::string localDeviceId; if (!GetLocalDeviceId(localDeviceId) || localDeviceId == deviceId) { HILOG_ERROR("RegisterMissionListener: Check DeviceId failed"); @@ -1934,6 +1961,7 @@ int AbilityManagerService::RegisterMissionListener(const std::string &deviceId, int AbilityManagerService::UnRegisterMissionListener(const std::string &deviceId, const sptr &listener) { + CHECK_CALLER_IS_SYSTEM_APP; std::string localDeviceId; if (!GetLocalDeviceId(localDeviceId) || localDeviceId == deviceId) { HILOG_ERROR("RegisterMissionListener: Check DeviceId failed"); @@ -2132,6 +2160,7 @@ int AbilityManagerService::GetPendingRequestWant(const sptr &target CHECK_POINTER_AND_RETURN(pendingWantManager_, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(target, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(want, ERR_INVALID_VALUE); + CHECK_CALLER_IS_SYSTEM_APP; return pendingWantManager_->GetPendingRequestWant(target, want); } @@ -2139,6 +2168,7 @@ int AbilityManagerService::LockMissionForCleanup(int32_t missionId) { HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2151,6 +2181,7 @@ int AbilityManagerService::UnlockMissionForCleanup(int32_t missionId) { HILOG_INFO("request unlock mission for clean up all, id :%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2163,6 +2194,7 @@ int AbilityManagerService::RegisterMissionListener(const sptr { HILOG_INFO("request RegisterMissionListener "); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2175,6 +2207,7 @@ int AbilityManagerService::UnRegisterMissionListener(const sptrVerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2188,6 +2221,7 @@ int AbilityManagerService::GetMissionInfos(const std::string& deviceId, int32_t { HILOG_INFO("request GetMissionInfos."); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2219,6 +2253,7 @@ int AbilityManagerService::GetMissionInfo(const std::string& deviceId, int32_t m { HILOG_INFO("request GetMissionInfo, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2255,6 +2290,7 @@ int AbilityManagerService::CleanMission(int32_t missionId) { HILOG_INFO("request CleanMission, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2268,6 +2304,7 @@ int AbilityManagerService::CleanAllMissions() { HILOG_INFO("request CleanAllMissions "); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2288,6 +2325,7 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId) { HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2306,6 +2344,7 @@ int AbilityManagerService::MoveMissionToFront(int32_t missionId, const StartOpti { HILOG_INFO("request MoveMissionToFront, missionId:%{public}d", missionId); CHECK_POINTER_AND_RETURN(currentMissionListManager_, ERR_NO_INIT); + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -3141,6 +3180,10 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB HILOG_ERROR("Query highest priority ability failed."); return; } + AbilityRequest abilityRequest; + if (!IsComponentInterceptionStart(want, nullptr, 0, 0, abilityRequest)) { + return; + } usleep(REPOLL_TIME_MICRO_SECONDS); } @@ -3163,6 +3206,7 @@ void AbilityManagerService::StartHighestPriorityAbility(int32_t userId, bool isB } #ifdef SUPPORT_GRAPHICS + abilityWant.SetParam(NEED_STARTINGWINDOW, false); // wait BOOT_ANIMATION_STARTED to start LAUNCHER WaitParameter(BOOTEVENT_BOOT_ANIMATION_STARTED.c_str(), "true", amsConfigResolver_->GetBootAnimationTimeoutTime()); #endif @@ -3254,6 +3298,11 @@ int AbilityManagerService::GenerateAbilityRequest( HILOG_INFO("GenerateAbilityRequest, moduleName: %{public}s.", request.abilityInfo.moduleName.c_str()); request.want.SetModuleName(request.abilityInfo.moduleName); + if (want.GetBoolParam(Want::PARAM_RESV_START_RECENT, false) && + AAFwk::PermissionVerification::GetInstance()->VerifyMissionPermission()) { + request.startRecent = true; + } + return ERR_OK; } @@ -3434,6 +3483,7 @@ void AbilityManagerService::GetRestartIntervalTime(int &restartIntervalTime) int AbilityManagerService::KillProcess(const std::string &bundleName) { HILOG_DEBUG("Kill process, bundleName: %{public}s", bundleName.c_str()); + CHECK_CALLER_IS_SYSTEM_APP; auto bms = GetBundleManager(); CHECK_POINTER_AND_RETURN(bms, KILL_PROCESS_FAILED); int32_t userId = GetUserId(); @@ -3459,6 +3509,7 @@ int AbilityManagerService::KillProcess(const std::string &bundleName) int AbilityManagerService::ClearUpApplicationData(const std::string &bundleName) { HILOG_DEBUG("ClearUpApplicationData, bundleName: %{public}s", bundleName.c_str()); + CHECK_CALLER_IS_SYSTEM_APP; int ret = DelayedSingleton::GetInstance()->ClearUpApplicationData(bundleName); if (ret != ERR_OK) { return CLEAR_APPLICATION_DATA_FAIL; @@ -3948,6 +3999,7 @@ int AbilityManagerService::StartAbilityByCall( HILOG_INFO("call ability."); CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE); + CHECK_CALLER_IS_SYSTEM_APP; auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); if (abilityRecord && !JudgeSelfCalled(abilityRecord)) { @@ -4141,6 +4193,7 @@ void AbilityManagerService::OnStartSpecifiedAbilityTimeoutResponse(const AAFwk:: int AbilityManagerService::GetAbilityRunningInfos(std::vector &info) { HILOG_DEBUG("Get running ability infos."); + CHECK_CALLER_IS_SYSTEM_APP; auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); if (!currentMissionListManager_ || !connectManager_ || !dataAbilityManager_) { return ERR_INVALID_VALUE; @@ -4186,6 +4239,7 @@ void AbilityManagerService::UpdateFocusState(std::vector &in int AbilityManagerService::GetExtensionRunningInfos(int upperLimit, std::vector &info) { HILOG_DEBUG("Get extension infos, upperLimit : %{public}d", upperLimit); + CHECK_CALLER_IS_SYSTEM_APP; auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); if (!connectManager_) { return ERR_INVALID_VALUE; @@ -4236,6 +4290,7 @@ int AbilityManagerService::RegisterSnapshotHandler(const sptr& int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, int32_t missionId, MissionSnapshot& missionSnapshot, bool isLowResolution) { + CHECK_CALLER_IS_SYSTEM_APP; if (!PermissionVerification::GetInstance()->VerifyMissionPermission()) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); return CHECK_PERMISSION_FAILED; @@ -4773,6 +4828,7 @@ int AbilityManagerService::FinishUserTest( int AbilityManagerService::GetTopAbility(sptr &token) { #ifdef SUPPORT_GRAPHICS + CHECK_CALLER_IS_SYSTEM_APP; if (!wmsHandler_) { HILOG_ERROR("wmsHandler_ is nullptr."); return ERR_INVALID_VALUE; @@ -4973,7 +5029,8 @@ int AbilityManagerService::CheckStaticCfgPermission(AppExecFwk::AbilityInfo &abi } // verify permission if 'permission' is not empty - if (abilityInfo.permissions.empty()) { + if (abilityInfo.permissions.empty() || + AccessTokenKit::VerifyAccessToken(tokenId, PermissionConstants::PERMISSION_START_INVISIBLE_ABILITY)) { return AppExecFwk::Constants::PERMISSION_GRANTED; } @@ -5312,6 +5369,7 @@ int AbilityManagerService::SetMissionIcon(const sptr &token, const std::shared_ptr &icon) { HILOG_DEBUG("%{public}s", __func__); + CHECK_CALLER_IS_SYSTEM_APP; auto abilityRecord = Token::GetAbilityRecordByToken(token); if (!abilityRecord) { HILOG_ERROR("no such ability record"); @@ -5763,6 +5821,21 @@ int AbilityManagerService::AddStartControlParam(Want &want, const sptr &callerToken, + int32_t userId, AAFWK::EventInfo &eventInfo, const std::string &eventName) +{ + if (!DlpUtils::OtherAppsAccessDlpCheck(callerToken, want) || + VerifyAccountPermission(userId) == CHECK_PERMISSION_FAILED || + !DlpUtils::DlpAccessOtherAppsCheck(callerToken, want)) { + HILOG_ERROR("%{public}s: Permission verification failed", __func__); + eventInfo.errCode = CHECK_PERMISSION_FAILED; + AAFWK::EventReport::SendExtensionEvent(eventName, HiSysEventType::FAULT, eventInfo); + return CHECK_PERMISSION_FAILED; + } + return ERR_OK; +} + bool AbilityManagerService::JudgeSelfCalled(const std::shared_ptr &abilityRecord) { auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); diff --git a/services/abilitymgr/src/ability_record.cpp b/services/abilitymgr/src/ability_record.cpp index 02f4b4b336..256006ed4e 100644 --- a/services/abilitymgr/src/ability_record.cpp +++ b/services/abilitymgr/src/ability_record.cpp @@ -57,6 +57,7 @@ const std::string SHOW_ON_LOCK_SCREEN = "ShowOnLockScreen"; const std::string DLP_INDEX = "ohos.dlp.params.index"; const std::string DLP_BUNDLE_NAME = "com.ohos.dlpmanager"; const std::string COMPONENT_STARTUP_NEW_RULES = "component.startup.newRules"; +const std::string NEED_STARTINGWINDOW = "ohos.ability.NeedStartingWindow"; const uint32_t RELEASE_STARTING_BG_TIMEOUT = 15000; // release starting window resource timeout. int64_t AbilityRecord::abilityRecordId = 0; int64_t AbilityRecord::g_abilityRecordEventId_ = 0; @@ -499,9 +500,13 @@ void AbilityRecord::ProcessForegroundAbility(bool isRecent, const AbilityRequest } else { HILOG_INFO("SUPPORT_GRAPHICS: to load ability."); lifeCycleStateInfo_.sceneFlagBak = sceneFlag; - StartingWindowTask(isRecent, true, abilityRequest, startOptions); - AnimationTask(isRecent, abilityRequest, startOptions, callerAbility); - PostCancelStartingWindowColdTask(); + auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); + auto needStartingWindow = abilityRequest.want.GetBoolParam(NEED_STARTINGWINDOW, true); + if (!isSaCall || needStartingWindow) { + StartingWindowTask(isRecent, true, abilityRequest, startOptions); + AnimationTask(isRecent, abilityRequest, startOptions, callerAbility); + PostCancelStartingWindowColdTask(); + } LoadAbility(); } } diff --git a/services/abilitymgr/src/mission.cpp b/services/abilitymgr/src/mission.cpp index 7e889244ca..cc6bf611f3 100644 --- a/services/abilitymgr/src/mission.cpp +++ b/services/abilitymgr/src/mission.cpp @@ -68,6 +68,15 @@ bool Mission::IsSpecifiedAbility() const return false; } +bool Mission::IsStandardAbility() const +{ + if (abilityRecord_) { + return abilityRecord_->GetAbilityInfo().launchMode == AppExecFwk::LaunchMode::STANDARD; + } + + return false; +} + void Mission::SetSpecifiedFlag(const std::string &flag) { specifiedFlag_ = flag; diff --git a/services/abilitymgr/src/mission_info_mgr.cpp b/services/abilitymgr/src/mission_info_mgr.cpp index a84c2bad5d..16762bfc59 100644 --- a/services/abilitymgr/src/mission_info_mgr.cpp +++ b/services/abilitymgr/src/mission_info_mgr.cpp @@ -289,25 +289,32 @@ int MissionInfoMgr::GetInnerMissionInfoById(int32_t missionId, InnerMissionInfo } bool MissionInfoMgr::FindReusedMissionInfo(const std::string &missionName, - const std::string &flag, InnerMissionInfo &info) + const std::string &flag, bool isFindRecentStandard, InnerMissionInfo &info) { if (missionName.empty()) { return false; } + + std::lock_guard lock(mutex_); auto it = std::find_if(missionInfoList_.begin(), missionInfoList_.end(), - [&missionName, &flag](const InnerMissionInfo item) { - if (item.launchMode == static_cast(AppExecFwk::LaunchMode::STANDARD)) { + [&missionName, &flag, &isFindRecentStandard](const InnerMissionInfo item) { + if (missionName != item.missionName) { return false; } + // already sorted, return head of list + if (isFindRecentStandard && item.launchMode == static_cast(AppExecFwk::LaunchMode::STANDARD)) { + return true; + } + if (item.launchMode == static_cast(AppExecFwk::LaunchMode::SINGLETON)) { - return missionName == item.missionName; + return true; } if (item.launchMode == static_cast(AppExecFwk::LaunchMode::SPECIFIED)) { - return missionName == item.missionName && flag == item.specifiedFlag; + return flag == item.specifiedFlag; } return false; } diff --git a/services/abilitymgr/src/mission_list.cpp b/services/abilitymgr/src/mission_list.cpp index 781c4f70e0..0ab9c4d074 100644 --- a/services/abilitymgr/src/mission_list.cpp +++ b/services/abilitymgr/src/mission_list.cpp @@ -94,6 +94,25 @@ std::shared_ptr MissionList::GetSpecifiedMission( return nullptr; } +std::shared_ptr MissionList::GetRecentStandardMission(const std::string &missionName) const +{ + if (missionName.empty()) { + return nullptr; + } + + std::string missionTime = "0"; + std::shared_ptr result = nullptr; + for (auto& mission : missions_) { + if (mission && mission->IsStandardAbility() && mission->GetMissionName() == missionName && + mission->GetMissionTime() >= missionTime) { + result = mission; + missionTime = mission->GetMissionTime(); + } + } + + return result; +} + std::shared_ptr MissionList::GetAbilityRecordByToken(const sptr &token) const { for (auto mission : missions_) { diff --git a/services/abilitymgr/src/mission_list_manager.cpp b/services/abilitymgr/src/mission_list_manager.cpp index 803c831d35..75db0e2eac 100644 --- a/services/abilitymgr/src/mission_list_manager.cpp +++ b/services/abilitymgr/src/mission_list_manager.cpp @@ -384,30 +384,46 @@ bool MissionListManager::HandleReusedMissionAndAbility(const AbilityRequest &abi HILOG_DEBUG("mission exists. No update required"); return true; } - HILOG_DEBUG("mission exists. need to be updated"); - return false; + + auto missionId = targetMission->GetMissionId(); + HILOG_INFO("mission exists. need to be updated, missionId:%{public}d", missionId); + InnerMissionInfo info; + if (DelayedSingleton::GetInstance()->GetInnerMissionInfoById( + targetMission->GetMissionId(), info) == 0) { + info.missionInfo.time = GetCurrentTime(); + info.missionInfo.runningState = 0; + info.startMethod = CallType2StartMethod(abilityRequest.callType); + DelayedSingleton::GetInstance()->UpdateMissionInfo(info); + targetMission->UpdateMissionId(missionId, info.startMethod); + targetMission->UpdateMissionTime(info.missionInfo.time); + } + + return true; } -std::string MissionListManager::GetMissionName(const AbilityRequest &abilityRequest, bool isStandard) const +std::string MissionListManager::GetMissionName(const AbilityRequest &abilityRequest) const { int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0); - std::string missionName = isStandard ? abilityRequest.abilityInfo.bundleName : - AbilityUtil::ConvertBundleNameSingleton( - abilityRequest.abilityInfo.bundleName, abilityRequest.abilityInfo.name, - abilityRequest.abilityInfo.moduleName, appIndex); - - return missionName; + return AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName, + abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex); } bool MissionListManager::CreateOrReusedMissionInfo(const AbilityRequest &abilityRequest, InnerMissionInfo &info) const { // get mission name. bool reUsedMissionInfo = false; - bool isStandard = abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD; - std::string missionName = GetMissionName(abilityRequest, isStandard); + bool needFind = false; + bool isFindRecentStandard = abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD && + abilityRequest.startRecent; + if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::STANDARD || isFindRecentStandard) { + needFind = true; + } + + std::string missionName = GetMissionName(abilityRequest); auto mgr = DelayedSingleton::GetInstance(); - if (!isStandard && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp && mgr && - mgr->FindReusedMissionInfo(missionName, abilityRequest.specifiedFlag, info) && info.missionInfo.id > 0) { + if (needFind && !abilityRequest.abilityInfo.applicationInfo.isLauncherApp && mgr && + mgr->FindReusedMissionInfo(missionName, abilityRequest.specifiedFlag, isFindRecentStandard, info) + && info.missionInfo.id > 0) { reUsedMissionInfo = true; } HILOG_INFO("try find reused mission info. result:%{public}d", reUsedMissionInfo); @@ -439,27 +455,21 @@ void MissionListManager::GetTargetMissionAndAbility(const AbilityRequest &abilit targetMission = std::make_shared(info.missionInfo.id, targetRecord, info.missionName, info.startMethod); targetMission->SetLockedState(info.missionInfo.lockedState); + targetMission->UpdateMissionTime(info.missionInfo.time); targetRecord->SetMission(targetMission); targetRecord->SetOwnerMissionUserId(userId_); - } else { - HILOG_DEBUG("Update old mission data."); - auto state = targetMission->UpdateMissionId(info.missionInfo.id, info.startMethod); - if (!state) { - HILOG_INFO("targetMission UpdateMissionId(%{public}d, %{public}d) failed", info.missionInfo.id, - info.startMethod); + + // handle specified + if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) { + targetMission->SetSpecifiedFlag(abilityRequest.specifiedFlag); + targetRecord->SetSpecifiedFlag(abilityRequest.specifiedFlag); } - HILOG_DEBUG("Update MissionId (%{public}d, %{public}d) end", info.missionInfo.id, info.startMethod); } if (!findReusedMissionInfo && targetRecord) { info.missionInfo.label = targetRecord->GetLabel(); } - if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::SPECIFIED) { - targetMission->SetSpecifiedFlag(abilityRequest.specifiedFlag); - targetRecord->SetSpecifiedFlag(abilityRequest.specifiedFlag); - } - if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp || abilityRequest.abilityInfo.excludeFromMissions) { return; } @@ -572,14 +582,16 @@ std::shared_ptr MissionListManager::GetReusedMission(const AbilityReque return GetReusedSpecifiedMission(abilityRequest); } + if (abilityRequest.abilityInfo.launchMode == AppExecFwk::LaunchMode::STANDARD) { + return GetReusedStandardMission(abilityRequest); + } + if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::SINGLETON) { return nullptr; } std::shared_ptr reUsedMission = nullptr; - int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0); - std::string missionName = AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName, - abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex); + std::string missionName = GetMissionName(abilityRequest); // find launcher first. if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp) { @@ -611,9 +623,7 @@ std::shared_ptr MissionListManager::GetReusedSpecifiedMission(const Abi // specified mission name format is same as singleton. std::shared_ptr reUsedMission = nullptr; - int32_t appIndex = abilityRequest.want.GetIntParam(DLP_INDEX, 0); - std::string missionName = AbilityUtil::ConvertBundleNameSingleton(abilityRequest.abilityInfo.bundleName, - abilityRequest.abilityInfo.name, abilityRequest.abilityInfo.moduleName, appIndex); + std::string missionName = GetMissionName(abilityRequest); std::string flag = abilityRequest.specifiedFlag; // find launcher first. @@ -638,6 +648,49 @@ std::shared_ptr MissionListManager::GetReusedSpecifiedMission(const Abi return nullptr; } +std::shared_ptr MissionListManager::GetReusedStandardMission(const AbilityRequest &abilityRequest) +{ + if (abilityRequest.abilityInfo.launchMode != AppExecFwk::LaunchMode::STANDARD) { + return nullptr; + } + + if (!abilityRequest.startRecent) { + return nullptr; + } + + // all mission name format is same. + std::string missionName = GetMissionName(abilityRequest); + std::shared_ptr reUsedMission = nullptr; + + // find launcher first, if find it in launcher list, no need to find in other list. + if (abilityRequest.abilityInfo.applicationInfo.isLauncherApp) { + if ((reUsedMission = launcherList_->GetRecentStandardMission(missionName)) != nullptr) { + return reUsedMission; + } + } + + // try find it from current and default standard. + std::string missionTime = "0"; + for (const auto &missionList : currentMissionLists_) { + if (!missionList) { + continue; + } + + auto mission = missionList->GetRecentStandardMission(missionName); + if (mission && mission->GetMissionTime() >= missionTime) { + missionTime = mission->GetMissionTime(); + reUsedMission = mission; + } + } + + auto mission = defaultStandardList_->GetRecentStandardMission(missionName); + if (mission && mission->GetMissionTime() >= missionTime) { + reUsedMission = mission; + } + + return reUsedMission; +} + void MissionListManager::MoveMissionToTargetList(bool isCallFromLauncher, const std::shared_ptr &targetMissionList, const std::shared_ptr &mission) @@ -1031,10 +1084,12 @@ void MissionListManager::CompleteForegroundSuccess(const std::shared_ptrGetMission(); if (mission) { + auto currentTime = GetCurrentTime(); + mission->UpdateMissionTime(currentTime); InnerMissionInfo info; if (DelayedSingleton::GetInstance()->GetInnerMissionInfoById( mission->GetMissionId(), info) == 0) { - info.missionInfo.time = GetCurrentTime(); + info.missionInfo.time = currentTime; info.missionInfo.runningState = 0; DelayedSingleton::GetInstance()->UpdateMissionInfo(info); } diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 1f9ac3f17a..7bbf80ffb9 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -20,6 +20,7 @@ #include #include +#include "ability_manager_errors.h" #include "accesstoken_kit.h" #include "application_state_observer_stub.h" #include "datetime_ex.h" @@ -58,6 +59,12 @@ using namespace OHOS::Rosen; using namespace OHOS::Security; namespace { +#define CHECK_CALLER_IS_SYSTEM_APP \ + if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { \ + HILOG_ERROR("The caller is not system-app, can not use system-api"); \ + return AAFwk::ERR_NOT_SYSTEM_APP; \ + } + // NANOSECONDS mean 10^9 nano second constexpr int64_t NANOSECONDS = 1000000000; // MICROSECONDS mean 10^6 milli second @@ -375,7 +382,6 @@ void AppMgrServiceInner::ApplicationForegrounded(const int32_t recordId) appRecord->PopForegroundingAbilityTokens(); ApplicationState appState = appRecord->GetState(); if (appState == ApplicationState::APP_STATE_READY || appState == ApplicationState::APP_STATE_BACKGROUND) { - appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND); appRecord->SetState(ApplicationState::APP_STATE_FOREGROUND); bool needNotifyApp = appRunningManager_->IsApplicationFirstForeground(*appRecord); OnAppStateChanged(appRecord, ApplicationState::APP_STATE_FOREGROUND, needNotifyApp); @@ -582,9 +588,9 @@ int32_t AppMgrServiceInner::KillApplicationByUserId(const std::string &bundleNam HILOG_ERROR("appRunningManager_ is nullptr"); return ERR_NO_INIT; } - - if (VerifyAccountPermission(AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) == - ERR_PERMISSION_DENIED) { + CHECK_CALLER_IS_SYSTEM_APP; + if (VerifyAccountPermission( + AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES, userId) == ERR_PERMISSION_DENIED) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); return ERR_PERMISSION_DENIED; } @@ -1915,18 +1921,21 @@ void AppMgrServiceInner::NotifyAppStatusByCallerUid(const std::string &bundleNam int32_t AppMgrServiceInner::RegisterApplicationStateObserver( const sptr &observer, const std::vector &bundleNameList) { + CHECK_CALLER_IS_SYSTEM_APP; return DelayedSingleton::GetInstance()->RegisterApplicationStateObserver( observer, bundleNameList); } int32_t AppMgrServiceInner::UnregisterApplicationStateObserver(const sptr &observer) { + CHECK_CALLER_IS_SYSTEM_APP; return DelayedSingleton::GetInstance()->UnregisterApplicationStateObserver(observer); } int32_t AppMgrServiceInner::GetForegroundApplications(std::vector &list) { HILOG_INFO("%{public}s, begin.", __func__); + CHECK_CALLER_IS_SYSTEM_APP; auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyRunningInfoPerm(); if (!isPerm) { HILOG_ERROR("%{public}s: Permission verification failed", __func__); @@ -2256,6 +2265,7 @@ int32_t AppMgrServiceInner::UpdateConfiguration(const Configuration &config) HILOG_ERROR("appRunningManager_ is null"); return ERR_INVALID_VALUE; } + CHECK_CALLER_IS_SYSTEM_APP; auto ret = AAFwk::PermissionVerification::GetInstance()->VerifyUpdateConfigurationPerm(); if (ret != ERR_OK) { diff --git a/services/common/BUILD.gn b/services/common/BUILD.gn index 4fb36b7a18..62d853aad0 100644 --- a/services/common/BUILD.gn +++ b/services/common/BUILD.gn @@ -44,6 +44,7 @@ ohos_shared_library("perm_verification") { external_deps = [ "ability_base:want", "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index 1ad049bd5f..c5c586b6dc 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -79,6 +79,8 @@ struct VerificationInfo { int CheckStartByCallPermission(const VerificationInfo &verificationInfo) const; + bool JudgeCallerIsAllowedToUseSystemAPI() const; + private: DISALLOW_COPY_AND_MOVE(PermissionVerification); diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index ce90f42ac2..8d9d7f444b 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -19,6 +19,7 @@ #include "accesstoken_kit.h" #include "hilog_wrapper.h" #include "permission_constants.h" +#include "tokenid_kit.h" namespace OHOS { namespace AAFwk { @@ -357,5 +358,14 @@ int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo & return ERR_OK; } + +bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const +{ + if (IsSACall() || IsShellCall()) { + return true; + } + auto callerToken = IPCSkeleton::GetCallingFullTokenID(); + return Security::AccessToken::TokenIdKit::IsSystemAppByFullTokenID(callerToken); +} } // namespace AAFwk } // namespace OHOS diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/Application/AbilityStage.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/Application/AbilityStage.ts index 1821f62885..8f5ec9a9ec 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/Application/AbilityStage.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/Application/AbilityStage.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import AbilityStage from "@ohos.application.AbilityStage" +import AbilityStage from "@ohos.app.ability.AbilityStage" export default class DialogAbilityStage extends AbilityStage { onCreate() { diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts index b6d3ae971a..6fca20306e 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/SelectorServiceExtAbility.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import extension from '@ohos.application.ServiceExtensionAbility'; +import extension from '@ohos.app.ability.ServiceExtensionAbility'; import window from '@ohos.window'; import display from '@ohos.display'; diff --git a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts index 1728dd3596..ad5a5167a2 100644 --- a/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts +++ b/services/dialog_ui/ams_system_dialog/entry/src/main/ets/ServiceExtAbility/TipsServiceExtAbility.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -import extension from '@ohos.application.ServiceExtensionAbility'; +import extension from '@ohos.app.ability.ServiceExtensionAbility'; import window from '@ohos.window'; import display from '@ohos.display'; diff --git a/services/quickfixmgr/src/quick_fix_manager_service.cpp b/services/quickfixmgr/src/quick_fix_manager_service.cpp index 840775f652..b2cc415692 100644 --- a/services/quickfixmgr/src/quick_fix_manager_service.cpp +++ b/services/quickfixmgr/src/quick_fix_manager_service.cpp @@ -58,7 +58,10 @@ int32_t QuickFixManagerService::ApplyQuickFix(const std::vector &qu { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - + if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { + HILOG_ERROR("The caller is not system-app, can not use system-api"); + return QUICK_FIX_NOT_SYSTEM_APP; + } if (!AAFwk::PermissionVerification::GetInstance()->VerifyInstallBundlePermission()) { return QUICK_FIX_VERIFY_PERMISSION_FAILED; } @@ -88,7 +91,10 @@ int32_t QuickFixManagerService::GetApplyedQuickFixInfo(const std::string &bundle { HITRACE_METER_NAME(HITRACE_TAG_ABILITY_MANAGER, __PRETTY_FUNCTION__); HILOG_DEBUG("function called."); - + if (!AAFwk::PermissionVerification::GetInstance()->JudgeCallerIsAllowedToUseSystemAPI()) { + HILOG_ERROR("The caller is not system-app, can not use system-api"); + return QUICK_FIX_NOT_SYSTEM_APP; + } if (!AAFwk::PermissionVerification::GetInstance()->VerifyGetBundleInfoPrivilegedPermission()) { return QUICK_FIX_VERIFY_PERMISSION_FAILED; } diff --git a/test/fuzztest/missioninfomgrb_fuzzer/missioninfomgrb_fuzzer.cpp b/test/fuzztest/missioninfomgrb_fuzzer/missioninfomgrb_fuzzer.cpp index 38af64a3ad..e9eedd055f 100755 --- a/test/fuzztest/missioninfomgrb_fuzzer/missioninfomgrb_fuzzer.cpp +++ b/test/fuzztest/missioninfomgrb_fuzzer/missioninfomgrb_fuzzer.cpp @@ -31,6 +31,7 @@ namespace OHOS { namespace { constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; } uint32_t GetU32Data(const char* ptr) @@ -43,6 +44,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { int32_t int32Param = static_cast(GetU32Data(data)); std::string stringParam(data, size); + bool boolParam = *data % ENABLE; InnerMissionInfo innerMissionInfo; // fuzz for MissionInfoMgr @@ -52,7 +54,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) MissionInfo missionInfo; missionInfoMgr->GetMissionInfoById(int32Param, missionInfo); missionInfoMgr->GetInnerMissionInfoById(int32Param, innerMissionInfo); - missionInfoMgr->FindReusedMissionInfo(stringParam, stringParam, innerMissionInfo); + missionInfoMgr->FindReusedMissionInfo(stringParam, stringParam, boolParam, innerMissionInfo); return true; } @@ -90,4 +92,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ch = nullptr; return 0; } - diff --git a/test/fuzztest/missionlistmanagerfirst_fuzzer/missionlistmanagerfirst_fuzzer.cpp b/test/fuzztest/missionlistmanagerfirst_fuzzer/missionlistmanagerfirst_fuzzer.cpp index 299d3b2447..a43ec2cfc6 100755 --- a/test/fuzztest/missionlistmanagerfirst_fuzzer/missionlistmanagerfirst_fuzzer.cpp +++ b/test/fuzztest/missionlistmanagerfirst_fuzzer/missionlistmanagerfirst_fuzzer.cpp @@ -105,7 +105,7 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) missionListManager->StartAbilityLocked(abilityRecord, abilityRecord, abilityRequest); std::shared_ptr mission = std::make_shared(int32Param, abilityRecord); missionListManager->HandleReusedMissionAndAbility(abilityRequest, mission, abilityRecord); - missionListManager->GetMissionName(abilityRequest, boolParam); + missionListManager->GetMissionName(abilityRequest); InnerMissionInfo innerMissionInfo; missionListManager->CreateOrReusedMissionInfo(abilityRequest, innerMissionInfo); missionListManager->GetTargetMissionAndAbility(abilityRequest, mission, abilityRecord); @@ -165,4 +165,3 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) ch = nullptr; return 0; } - diff --git a/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_proxy.h b/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_proxy.h new file mode 100644 index 0000000000..120c7fb629 --- /dev/null +++ b/test/mock/frameworks_kits_ability_native_test/include/mock_form_mgr_proxy.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2022 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_FORM_FWK_MOCK_FORM_MGR_PROXY_H +#define OHOS_FORM_FWK_MOCK_FORM_MGR_PROXY_H + +#include +#include "gmock/gmock.h" +#include "form_mgr_proxy.h" +#include "form_provider_data.h" + +namespace OHOS { +namespace AppExecFwk { +class MockFormMgrProxy : public FormMgrProxy { +public: + MockFormMgrProxy(const sptr &impl) : FormMgrProxy(impl) {}; + MOCK_METHOD2(GetFormsInfo, int(const FormInfoFilter &filter, std::vector &formInfos)); + MOCK_METHOD0(IsRequestPublishFormSupported, bool()); + MOCK_METHOD2(StartAbility, int32_t(const Want &want, const sptr &callerToken)); + MOCK_METHOD2(UpdateForm, int32_t(int64_t formId, const FormProviderData &formBindingData)); + MOCK_METHOD3(RequestForm, int32_t(int64_t formId, const sptr &callerToken, const Want &want)); + MOCK_METHOD3(MessageEvent, int32_t(int64_t formId, const Want &want, const sptr &callerToken)); + MOCK_METHOD3(NotifyFormsPrivacyProtected, int(const std::vector &formIds, bool isProtected, + const sptr &callerToken)); + MOCK_METHOD1(DumpStorageFormInfos, int(std::string &formInfos)); + MOCK_METHOD2(DumpFormInfoByFormId, int(int64_t formId, std::string &formInfos)); + MOCK_METHOD2(DumpFormTimerByFormId, int(int64_t formId, std::string &isTimingService)); + MOCK_METHOD3(RouterEvent, int(const int64_t formId, Want &want, const sptr &callerToken)); + MOCK_METHOD3(NotifyFormsVisible, int(const std::vector &formIds, bool isProtected, + const sptr &callerToken)); + MOCK_METHOD3(DeleteInvalidForms, int(const std::vector &formIds, const sptr &callerToken, + int32_t &numFormsDeleted)); + MOCK_METHOD3(NotifyFormsEnableUpdate, int(const std::vector &formIds, bool isProtected, + const sptr &callerToken)); + MOCK_METHOD1(GetAllFormsInfo, int(std::vector &formInfos)); + MOCK_METHOD2(GetFormsInfoByApp, int(std::string &bundleName, std::vector &formInfos)); + MOCK_METHOD3(GetFormsInfoByModule, int(std::string &bundleName, std::string &moduleName, std::vector &formInfos)); + MOCK_METHOD2(DumpFormInfoByBundleName, int(const std::string &bundleName, std::string &formInfos)); + MOCK_METHOD3(AcquireFormState, int(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo)); + MOCK_METHOD0(CheckFMSReady, bool()); +}; +} +} +#endif // OHOS_FORM_FWK_MOCK_FORM_MGR_PROXY_H diff --git a/test/moduletest/ability_test/ability_context_test.cpp b/test/moduletest/ability_test/ability_context_test.cpp index da03185611..aad428a8c6 100644 --- a/test/moduletest/ability_test/ability_context_test.cpp +++ b/test/moduletest/ability_test/ability_context_test.cpp @@ -14,6 +14,8 @@ */ #include +#define private public +#define protected public #include "ability_thread.h" #include "ability_context.h" #include "ability_loader.h" @@ -23,6 +25,8 @@ #include "ohos_application.h" #include "system_ability_definition.h" #include "sys_mgr_client.h" +#undef protected +#undef private namespace OHOS { namespace AppExecFwk { @@ -251,5 +255,758 @@ HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0200, Function | EXPECT_TRUE(ret); usleep(AbilityContextTest::TEST_WAIT_TIME); } + +/** + * @tc.number: AaFwk_Ability_Context_GetCallingBundle_0100 + * @tc.name: SetCallingContext and GetCallingBundle + * @tc.desc: Verify that function SetCallingContext and GetCallingBundle. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCallingBundle_0100, Function | MediumTest | Level1) +{ + std::string deviceId = "deviceId"; + std::string bundleName = "bundleName"; + std::string abilityName = "abilityName"; + std::string moduleName = "moduleName"; + context_->SetCallingContext(deviceId, bundleName, abilityName, moduleName); + EXPECT_EQ(context_->GetCallingBundle(), "bundleName"); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetElementName_0100 + * @tc.name: GetElementName + * @tc.desc: Verify that function GetElementName. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetElementName_0100, Function | MediumTest | Level1) +{ + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + auto result = context_->GetElementName(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetElementName_0200 + * @tc.name: GetElementName + * @tc.desc: Verify that function GetElementName. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetElementName_0200, Function | MediumTest | Level1) +{ + auto result = context_->GetElementName(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetCallingAbility_0100 + * @tc.name: GetCallingAbility + * @tc.desc: Verify that function GetCallingAbility. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCallingAbility_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetCallingAbility(); + EXPECT_TRUE(result != nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_ConnectAbility_0200 + * @tc.name: ConnectAbility + * @tc.desc: Verify that function ConnectAbility. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0200, Function | MediumTest | Level1) +{ + Want want; + bool ret = context_->ConnectAbility(want, nullptr); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: AaFwk_Ability_Context_ConnectAbility_0300 + * @tc.name: ConnectAbility + * @tc.desc: Verify that function ConnectAbility. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_ConnectAbility_0300, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AppExecFwk::AbilityType::DATA; + abilityInfo->name = "DemoAbility"; + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + Want want; + bool ret = context_->ConnectAbility(want, nullptr); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: AaFwk_Ability_Context_StopService_0300 + * @tc.name: StopAbility + * @tc.desc: Verify that function StopAbility. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_StopService_0300, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AppExecFwk::AbilityType::DATA; + abilityInfo->name = "DemoAbility"; + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + + Want want; + bool ret = context_->StopAbility(want); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetApplicationInfo_0100 + * @tc.name: GetApplicationInfo + * @tc.desc: Verify that function GetApplicationInfo. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetApplicationInfo_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetApplicationInfo(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetCacheDir_0100 + * @tc.name: GetCacheDir + * @tc.desc: Verify that function GetCacheDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCacheDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetCacheDir(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetCodeCacheDir_0100 + * @tc.name: GetCodeCacheDir + * @tc.desc: Verify that function GetCodeCacheDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCodeCacheDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetCodeCacheDir(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetDatabaseDir_0100 + * @tc.name: GetDatabaseDir + * @tc.desc: Verify that function GetDatabaseDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDatabaseDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetDatabaseDir(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetDataDir_0100 + * @tc.name: GetDataDir + * @tc.desc: Verify that function GetDataDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDataDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetDataDir(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetBundleManager_0100 + * @tc.name: GetBundleManager + * @tc.desc: Verify that function GetBundleManager. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleManager_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetBundleManager(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetDir_0100 + * @tc.name: GetDir + * @tc.desc: Verify that function GetDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDir_0100, Function | MediumTest | Level1) +{ + std::string name = "name"; + int32_t mode = 1; + auto result = context_->GetDir(name, mode); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetBundleCodePath_0100 + * @tc.name: GetBundleCodePath + * @tc.desc: Verify that function GetBundleCodePath. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleCodePath_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetBundleCodePath(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetBundleName_0100 + * @tc.name: GetBundleName + * @tc.desc: Verify that function GetBundleName. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleName_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetBundleName(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetBundleResourcePath_0100 + * @tc.name: GetBundleResourcePath + * @tc.desc: Verify that function GetBundleResourcePath. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetBundleResourcePath_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetBundleResourcePath(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetApplicationContext_0100 + * @tc.name: GetApplicationContext + * @tc.desc: Verify that function GetApplicationContext. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetApplicationContext_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetApplicationContext(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetContext_0100 + * @tc.name: GetContext + * @tc.desc: Verify that function GetContext. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetContext_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetContext(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetAbilityManager_0100 + * @tc.name: GetAbilityManager + * @tc.desc: Verify that function GetAbilityManager. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityManager_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetAbilityManager(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetProcessInfo_0100 + * @tc.name: GetProcessInfo + * @tc.desc: Verify that function GetProcessInfo. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetProcessInfo_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetProcessInfo(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetAppType_0100 + * @tc.name: GetAppType + * @tc.desc: Verify that function GetAppType. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAppType_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetAppType(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetAbilityInfo_0100 + * @tc.name: GetAbilityInfo + * @tc.desc: Verify that function GetAbilityInfo. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfo_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetAbilityInfo(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetHapModuleInfo_0100 + * @tc.name: GetHapModuleInfo + * @tc.desc: Verify that function GetHapModuleInfo. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetHapModuleInfo_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetHapModuleInfo(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetHapModuleInfo_0100 + * @tc.name: GetAbilityInfoType + * @tc.desc: Verify that function GetAbilityInfoType. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfoType_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetAbilityInfoType(); + EXPECT_EQ(result, AppExecFwk::AbilityType::UNKNOWN); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetAbilityInfoType_0200 + * @tc.name: GetAbilityInfoType + * @tc.desc: Verify that function GetAbilityInfoType. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityInfoType_0200, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AppExecFwk::AbilityType::SERVICE; + abilityInfo->name = "DemoAbility"; + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + auto result = context_->GetAbilityInfoType(); + EXPECT_EQ(result, AppExecFwk::AbilityType::SERVICE); +} + +/** + * @tc.number: AaFwk_Ability_Context_CreateBundleContext_0100 + * @tc.name: CreateBundleContext + * @tc.desc: Verify that function CreateBundleContext. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_CreateBundleContext_0100, Function | MediumTest | Level1) +{ + std::string bundleName; + int32_t flag = 1; + int32_t accountId = 1; + auto result = context_->CreateBundleContext(bundleName, flag, accountId); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetResourceManager_0100 + * @tc.name: GetResourceManager + * @tc.desc: Verify that function GetResourceManager. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetResourceManager_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetResourceManager(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetResourceManager_0200 + * @tc.name: GetResourceManager + * @tc.desc: Verify that function GetResourceManager. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetResourceManager_0200, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AppExecFwk::AbilityType::SERVICE; + abilityInfo->name = "DemoAbility"; + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + auto result = context_->GetResourceManager(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_VerifyPermission_0100 + * @tc.name: VerifyPermission + * @tc.desc: Verify that function VerifyPermission. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0100, Function | MediumTest | Level1) +{ + std::string permission; + int32_t pid = 1; + int32_t uid = 1; + auto result = context_->VerifyPermission(permission, pid, uid); + EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED); +} + +/** + * @tc.number: AaFwk_Ability_Context_VerifyPermission_0200 + * @tc.name: VerifyPermission + * @tc.desc: Verify that function VerifyPermission. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0200, Function | MediumTest | Level1) +{ + std::string permission = "permission"; + int32_t pid = 1; + int32_t uid = 1; + auto result = context_->VerifyPermission(permission, pid, uid); + EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED); +} + +/** + * @tc.number: AaFwk_Ability_Context_VerifyPermission_0300 + * @tc.name: VerifyPermission + * @tc.desc: Verify that function VerifyPermission. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_VerifyPermission_0300, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = AppExecFwk::AbilityType::SERVICE; + abilityInfo->name = "DemoAbility"; + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + std::string permission = "permission"; + int32_t pid = 1; + int32_t uid = 1; + auto result = context_->VerifyPermission(permission, pid, uid); + EXPECT_EQ(result, AppExecFwk::Constants::PERMISSION_NOT_GRANTED); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetPermissionDes_0100 + * @tc.name: GetPermissionDes + * @tc.desc: Verify that function GetPermissionDes. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPermissionDes_0100, Function | MediumTest | Level1) +{ + std::string permissionName = "permissionName"; + std::string des = "des"; + context_->GetPermissionDes(permissionName, des); + EXPECT_TRUE(permissionName.length() != des.length()); +} + +/** + * @tc.number: AaFwk_Ability_Context_RequestPermissionsFromUser_0100 + * @tc.name: RequestPermissionsFromUser + * @tc.desc: Verify that function RequestPermissionsFromUser. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_RequestPermissionsFromUser_0100, Function | MediumTest | Level1) +{ + std::vector permissions; + std::vector permissionsState; + context_->RequestPermissionsFromUser(permissions, permissionsState, nullptr); + EXPECT_TRUE(permissions.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_RequestPermissionsFromUser_0200 + * @tc.name: RequestPermissionsFromUser + * @tc.desc: Verify that function RequestPermissionsFromUser. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_RequestPermissionsFromUser_0200, Function | MediumTest | Level1) +{ + std::vector permissions; + permissions.emplace_back("a"); + std::vector permissionsState; + context_->RequestPermissionsFromUser(permissions, permissionsState, nullptr); + EXPECT_TRUE(!permissions.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_DeleteFile_0100 + * @tc.name: DeleteFile + * @tc.desc: Verify that function DeleteFile. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_DeleteFile_0100, Function | MediumTest | Level1) +{ + std::string fileName; + auto result = context_->DeleteFile(fileName); + EXPECT_FALSE(result); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetCaller_0100 + * @tc.name: GetCaller + * @tc.desc: Verify that function GetCaller. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetCaller_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetCaller(); + EXPECT_EQ(result.GetScheme(), ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetExternalCacheDir_0100 + * @tc.name: GetExternalCacheDir + * @tc.desc: Verify that function GetExternalCacheDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetExternalCacheDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetExternalCacheDir(); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetExternalFilesDir_0100 + * @tc.name: GetExternalFilesDir + * @tc.desc: Verify that function GetExternalFilesDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetExternalFilesDir_0100, Function | MediumTest | Level1) +{ + std::string type; + auto result = context_->GetExternalFilesDir(type); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetFilesDir_0100 + * @tc.name: GetFilesDir + * @tc.desc: Verify that function GetFilesDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetFilesDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetFilesDir(); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetNoBackupFilesDir_0100 + * @tc.name: GetNoBackupFilesDir + * @tc.desc: Verify that function GetNoBackupFilesDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetNoBackupFilesDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetNoBackupFilesDir(); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetDistributedDir_0100 + * @tc.name: GetDistributedDir + * @tc.desc: Verify that function GetDistributedDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDistributedDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetDistributedDir(); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetAbilityPackageContext_0100 + * @tc.name: GetAbilityPackageContext + * @tc.desc: Verify that function GetAbilityPackageContext. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetAbilityPackageContext_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetAbilityPackageContext(); + EXPECT_TRUE(result == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetProcessName_0100 + * @tc.name: GetProcessName + * @tc.desc: Verify that function GetProcessName. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetProcessName_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetProcessName(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_InitResourceManager_0100 + * @tc.name: InitResourceManager + * @tc.desc: Verify that function InitResourceManager. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_InitResourceManager_0100, Function | MediumTest | Level1) +{ + BundleInfo bundleInfo; + std::shared_ptr deal = nullptr; + context_->InitResourceManager(bundleInfo, deal); + EXPECT_TRUE(deal == nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetString_0100 + * @tc.name: GetString + * @tc.desc: Verify that function GetString. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetString_0100, Function | MediumTest | Level1) +{ + int32_t resId = 1; + auto result = context_->GetString(resId); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetStringArray_0100 + * @tc.name: GetStringArray + * @tc.desc: Verify that function GetStringArray. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetStringArray_0100, Function | MediumTest | Level1) +{ + int32_t resId = 1; + auto result = context_->GetStringArray(resId); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetIntArray_0100 + * @tc.name: GetIntArray + * @tc.desc: Verify that function GetIntArray. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetIntArray_0100, Function | MediumTest | Level1) +{ + int32_t resId = 1; + auto result = context_->GetIntArray(resId); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetTheme_0100 + * @tc.name: GetTheme + * @tc.desc: Verify that function GetTheme. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetTheme_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetTheme(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetPattern_0100 + * @tc.name: GetPattern + * @tc.desc: Verify that function GetPattern. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPattern_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetPattern(); + EXPECT_TRUE(result.empty()); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetColor_0100 + * @tc.name: GetColor + * @tc.desc: Verify that function GetColor. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetColor_0100, Function | MediumTest | Level1) +{ + int32_t resId = 1; + auto result = context_->GetColor(resId); + EXPECT_EQ(result, INVALID_RESOURCE_VALUE); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetThemeId_0100 + * @tc.name: GetThemeId + * @tc.desc: Verify that function GetThemeId. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetThemeId_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetThemeId(); + EXPECT_EQ(result, -1); +} + +/** + * @tc.number: AaFwk_Ability_Context_TerminateAbilityResult_0100 + * @tc.name: TerminateAbilityResult + * @tc.desc: Verify that function TerminateAbilityResult. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_TerminateAbilityResult_0100, Function | MediumTest | Level1) +{ + int32_t startId = 1; + auto result = context_->TerminateAbilityResult(startId); + EXPECT_FALSE(result); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetDisplayOrientation_0100 + * @tc.name: GetDisplayOrientation + * @tc.desc: Verify that function GetDisplayOrientation. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetDisplayOrientation_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetDisplayOrientation(); + EXPECT_EQ(result, 0); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetPreferencesDir_0100 + * @tc.name: GetPreferencesDir + * @tc.desc: Verify that function GetPreferencesDir. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetPreferencesDir_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetPreferencesDir(); + EXPECT_EQ(result, ""); +} + +/** + * @tc.number: AaFwk_Ability_Context_SetColorMode_0100 + * @tc.name: SetColorMode and GetColorMode + * @tc.desc: Verify that function SetColorMode and GetColorMode. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_SetColorMode_0100, Function | MediumTest | Level1) +{ + std::shared_ptr application = std::make_shared(); + sptr abilityToken = sptr(new AbilityThread()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr abilityRecord = std::make_shared(abilityInfo, abilityToken); + AbilityThread::AbilityThreadMain(application, abilityRecord, nullptr); + std::shared_ptr deal = std::make_shared(); + deal->SetAbilityInfo(abilityInfo); + context_->AttachBaseContext(deal); + int32_t mode = 1; + context_->SetColorMode(mode); + auto result = context_->GetColorMode(); + EXPECT_EQ(result, 1); + EXPECT_TRUE(context_->baseContext_ != nullptr); +} + +/** + * @tc.number: AaFwk_Ability_Context_GetMissionId_0100 + * @tc.name: GetMissionId + * @tc.desc: Verify that function GetMissionId. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_GetMissionId_0100, Function | MediumTest | Level1) +{ + auto result = context_->GetMissionId(); + EXPECT_EQ(result, -1); +} + +/** + * @tc.number: AaFwk_Ability_Context_IsUpdatingConfigurations_0100 + * @tc.name: IsUpdatingConfigurations + * @tc.desc: Verify that function IsUpdatingConfigurations. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_IsUpdatingConfigurations_0100, Function | MediumTest | Level1) +{ + auto result = context_->IsUpdatingConfigurations(); + EXPECT_FALSE(result); +} + +/** + * @tc.number: AaFwk_Ability_Context_PrintDrawnCompleted_0100 + * @tc.name: PrintDrawnCompleted + * @tc.desc: Verify that function PrintDrawnCompleted. + */ +HWTEST_F(AbilityContextTest, AaFwk_Ability_Context_PrintDrawnCompleted_0100, Function | MediumTest | Level1) +{ + auto result = context_->PrintDrawnCompleted(); + EXPECT_FALSE(result); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 03631193d9..ed1cbd770d 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -327,6 +327,7 @@ group("unittest") { "app_spawn_socket_test:unittest", "app_state_observer_manager_test:unittest", "appkit:unittest", + "application_context_test:unittest", "atomic_service_status_callback_proxy_test:unittest", "atomic_service_status_callback_stub_test:unittest", "background_task_observer_test:unittest", @@ -385,6 +386,7 @@ group("unittest") { "start_options_test:unittest", "stop_user_callback_proxy_test:unittest", "stop_user_callback_stub_test:unittest", + "sys_mgr_client_test:unittest", "system_ability_token_callback_stub_test:unittest", "task_data_persistence_mgr_test:unittest", "trigger_Info_test:unittest", diff --git a/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp b/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp index 8be5b7ea1a..78bdeeed1e 100644 --- a/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp +++ b/test/unittest/ability_extension_context_test/ability_extension_context_test.cpp @@ -128,5 +128,44 @@ HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0100, TestSize.Level1) HILOG_INFO("SetAbilityInfo end"); } +/** + * @tc.number: SetAbilityInfo_0200 + * @tc.name: SetAbilityInfo + * @tc.desc: Set AbilityInfo Failed + */ +HWTEST_F(AbilityExtensionContextTest, SetAbilityInfo_0200, TestSize.Level1) +{ + HILOG_INFO("SetAbilityInfo start"); + + std::shared_ptr info = std::make_shared(); + info->name = "ExtensionContextTest"; + std::shared_ptr record = + std::make_shared(info, nullptr); + std::shared_ptr application = std::make_shared(); + std::shared_ptr handler = std::make_shared(nullptr); + sptr token = new AppExecFwk::MockAbilityToken(); + + std::shared_ptr contextImpl = std::make_shared(); + std::shared_ptr applicationContext = + std::make_shared(); + applicationContext->AttachContextImpl(contextImpl); + applicationContext->InitApplicationContext(); + application->SetApplicationContext(applicationContext); + + ExtensionBase extensionBase; + extensionBase.Init(record, application, handler, token); + std::shared_ptr context = extensionBase.GetContext(); + + std::shared_ptr abilityInfo = context->GetAbilityInfo(); + EXPECT_STREQ(abilityInfo->name.c_str(), "ExtensionContextTest"); + + info = nullptr; + context->SetAbilityInfo(info); + + abilityInfo = context->GetAbilityInfo(); + EXPECT_EQ(abilityInfo, nullptr); + + HILOG_INFO("SetAbilityInfo end"); +} } // namespace AbilityRuntime } // namespace OHOS diff --git a/test/unittest/ability_manager_service_test/BUILD.gn b/test/unittest/ability_manager_service_test/BUILD.gn index e0b201bd26..978bf021d1 100755 --- a/test/unittest/ability_manager_service_test/BUILD.gn +++ b/test/unittest/ability_manager_service_test/BUILD.gn @@ -58,6 +58,7 @@ ohos_unittest("ability_manager_service_test") { "${ability_runtime_innerkits_path}/connectionobs_manager:connection_obs_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/unittest:abilityms_test_source", @@ -69,12 +70,6 @@ ohos_unittest("ability_manager_service_test") { "ability_base:configuration", "ability_base:want", "ability_base:zuri", - "ability_runtime:ability_deps_wrapper", - "ability_runtime:ability_manager", - "ability_runtime:abilitykit_native", - "ability_runtime:app_manager", - "ability_runtime:connection_obs_manager", - "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_core", diff --git a/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h b/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h index 1846dbd485..945abcce82 100644 --- a/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h +++ b/test/unittest/ability_manager_service_test/mock/include/mock_permission_verification.h @@ -91,6 +91,8 @@ struct VerificationInfo { { return IPCSkeleton::GetCallingTokenID() == accessTokenId; } + + bool JudgeCallerIsAllowedToUseSystemAPI() const; }; } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp b/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp index ef7cd01eb6..1cad6c6c3d 100644 --- a/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp +++ b/test/unittest/ability_manager_service_test/mock/src/mock_permission_verification.cpp @@ -115,5 +115,9 @@ int PermissionVerification::JudgeInvisibleAndBackground(const VerificationInfo & { return MyFlag::flag_; } +bool PermissionVerification::JudgeCallerIsAllowedToUseSystemAPI() const +{ + return true; +} } // namespace AAFwk } // namespace OHOS \ No newline at end of file diff --git a/test/unittest/application_context_test/BUILD.gn b/test/unittest/application_context_test/BUILD.gn new file mode 100644 index 0000000000..570e5a4391 --- /dev/null +++ b/test/unittest/application_context_test/BUILD.gn @@ -0,0 +1,57 @@ +# Copyright (c) 2022 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("application_context_test") { + module_out_path = "ability_runtime/service_extension" + + include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ] + + sources = [ + "//foundation/ability/ability_runtime/test/unittest/application_context_test/mock_context_impl.cpp", + "application_context_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_native_path}/ability/native:service_extension", + "${ability_runtime_native_path}/appkit:app_context", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_runtime:ability_context_native", + "ability_runtime:abilitykit_native", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + +group("unittest") { + testonly = true + deps = [ ":application_context_test" ] +} diff --git a/test/unittest/application_context_test/application_context_test.cpp b/test/unittest/application_context_test/application_context_test.cpp new file mode 100644 index 0000000000..7addb06210 --- /dev/null +++ b/test/unittest/application_context_test/application_context_test.cpp @@ -0,0 +1,702 @@ +/* + * Copyright (c) 2022 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 +#define private public +#include "application_context.h" +#undef private +#include "mock_ability_token.h" +#include "mock_context_impl.h" +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { +class ApplicationContextTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; + std::shared_ptr context_ = nullptr; + std::shared_ptr mock_ = nullptr; +}; + +void ApplicationContextTest::SetUpTestCase(void) +{} + +void ApplicationContextTest::TearDownTestCase(void) +{} + +void ApplicationContextTest::SetUp() +{ + context_ = std::make_shared(); + mock_ = std::make_shared(); +} + +void ApplicationContextTest::TearDown() +{} + +/** + * @tc.number: RegisterAbilityLifecycleCallback_0100 + * @tc.name: RegisterAbilityLifecycleCallback + * @tc.desc: Register Ability Lifecycle Callback + */ +HWTEST_F(ApplicationContextTest, RegisterAbilityLifecycleCallback_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 start"; + context_->callbacks_.clear(); + std::shared_ptr abilityLifecycleCallback = nullptr; + context_->RegisterAbilityLifecycleCallback(abilityLifecycleCallback); + EXPECT_TRUE(context_->IsAbilityLifecycleCallbackEmpty()); + GTEST_LOG_(INFO) << "RegisterAbilityLifecycleCallback_0100 end"; +} + +/** + * @tc.number: RegisterEnvironmentCallback_0100 + * @tc.name: RegisterEnvironmentCallback + * @tc.desc: Register Environment Callback + */ +HWTEST_F(ApplicationContextTest, RegisterEnvironmentCallback_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 start"; + context_->envCallbacks_.clear(); + std::shared_ptr environmentCallback = nullptr; + context_->RegisterEnvironmentCallback(environmentCallback); + EXPECT_TRUE(context_->envCallbacks_.empty()); + GTEST_LOG_(INFO) << "RegisterEnvironmentCallback_0100 end"; +} + +/** + * @tc.number: GetBundleName_0100 + * @tc.name: GetBundleName + * @tc.desc: Get BundleName failed + */ +HWTEST_F(ApplicationContextTest, GetBundleName_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleName_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetBundleName(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetBundleName_0100 end"; +} + +/** + * @tc.number: GetBundleName_0200 + * @tc.name: GetBundleName + * @tc.desc: Get BundleName sucess + */ +HWTEST_F(ApplicationContextTest, GetBundleName_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleName_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetBundleName(); + EXPECT_EQ(ret, "com.test.bundleName"); + GTEST_LOG_(INFO) << "GetBundleName_0200 end"; +} + +/** + * @tc.number: CreateBundleContext_0100 + * @tc.name: CreateBundleContext + * @tc.desc: Create BundleContext failed + */ +HWTEST_F(ApplicationContextTest, CreateBundleContext_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateBundleContext_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateBundleContext(bundleName); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "CreateBundleContext_0100 end"; +} + +/** + * @tc.number: CreateBundleContext_0200 + * @tc.name: CreateBundleContext + * @tc.desc: Create BundleContext sucess + */ +HWTEST_F(ApplicationContextTest, CreateBundleContext_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateBundleContext_0200 start"; + context_->AttachContextImpl(mock_); + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateBundleContext(bundleName); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "CreateBundleContext_0200 end"; +} + +/** + * @tc.number: CreateModuleContext_0100 + * @tc.name: CreateModuleContext + * @tc.desc: Create ModuleContext failed + */ +HWTEST_F(ApplicationContextTest, CreateModuleContext_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateModuleContext_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + std::string moduleName = "moduleName"; + auto ret = context_->CreateModuleContext(moduleName); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "CreateModuleContext_0100 end"; +} + +/** + * @tc.number: CreateModuleContext_0200 + * @tc.name: CreateModuleContext + * @tc.desc: Create ModuleContext sucess + */ +HWTEST_F(ApplicationContextTest, CreateModuleContext_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateModuleContext_0200 start"; + context_->AttachContextImpl(mock_); + std::string moduleName = "moduleName"; + auto ret = context_->CreateModuleContext(moduleName); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "CreateModuleContext_0200 end"; +} + +/** + * @tc.number: CreateModuleContext_0300 + * @tc.name: CreateModuleContext + * @tc.desc: Create ModuleContext failed + */ +HWTEST_F(ApplicationContextTest, CreateModuleContext_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateModuleContext_0300 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + std::string moduleName = "moduleName"; + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateModuleContext(bundleName, moduleName); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "CreateModuleContext_0300 end"; +} + +/** + * @tc.number: CreateModuleContext_0400 + * @tc.name: CreateModuleContext + * @tc.desc: Create ModuleContext sucess + */ +HWTEST_F(ApplicationContextTest, CreateModuleContext_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateModuleContext_0400 start"; + context_->AttachContextImpl(mock_); + std::string moduleName = "moduleName"; + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateModuleContext(bundleName, moduleName); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "CreateModuleContext_0400 end"; +} + +/** + * @tc.number: GetApplicationInfo_0100 + * @tc.name: GetApplicationInfo + * @tc.desc: Get ApplicationInfo failed + */ +HWTEST_F(ApplicationContextTest, GetApplicationInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetApplicationInfo_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetApplicationInfo(); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "GetApplicationInfo_0100 end"; +} + +/** + * @tc.number: GetApplicationInfo_0200 + * @tc.name: GetApplicationInfo + * @tc.desc:Get ApplicationInfo sucess + */ +HWTEST_F(ApplicationContextTest, GetApplicationInfo_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetApplicationInfo_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetApplicationInfo(); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetApplicationInfo_0200 end"; +} + +/** + * @tc.number: GetResourceManager_0100 + * @tc.name: GetResourceManager + * @tc.desc: Get ResourceManager failed + */ +HWTEST_F(ApplicationContextTest, GetResourceManager_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetResourceManager_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetResourceManager(); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "GetResourceManager_0100 end"; +} + +/** + * @tc.number: GetApplicationInfo_0200 + * @tc.name: GetResourceManager + * @tc.desc:Get ResourceManager sucess + */ +HWTEST_F(ApplicationContextTest, GetResourceManager_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetResourceManager_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetResourceManager(); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetResourceManager_0200 end"; +} + +/** + * @tc.number: GetBundleCodePath_0100 + * @tc.name: GetBundleCodePath + * @tc.desc: Get BundleCode Path failed + */ +HWTEST_F(ApplicationContextTest, GetBundleCodePath_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleCodePath_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetBundleCodePath(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetBundleCodePath_0100 end"; +} + +/** + * @tc.number: GetBundleCodePath_0200 + * @tc.name: GetBundleCodePath + * @tc.desc:Get BundleCode Path sucess + */ +HWTEST_F(ApplicationContextTest, GetBundleCodePath_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleCodePath_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetBundleCodePath(); + EXPECT_EQ(ret, "codePath"); + GTEST_LOG_(INFO) << "GetBundleCodePath_0200 end"; +} + +/** + * @tc.number: GetHapModuleInfo_0100 + * @tc.name: GetHapModuleInfo + * @tc.desc: Get HapModuleInfo failed + */ +HWTEST_F(ApplicationContextTest, GetHapModuleInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 start"; + auto ret = context_->GetHapModuleInfo(); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "GetHapModuleInfo_0100 end"; +} + +/** + * @tc.number: GetBundleCodeDir_0100 + * @tc.name: GetBundleCodeDir + * @tc.desc: Get Bundle Code Dir failed + */ +HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetBundleCodeDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetBundleCodeDir_0100 end"; +} + +/** + * @tc.number: GetBundleCodeDir_0200 + * @tc.name: GetBundleCodeDir + * @tc.desc:Get Bundle Code Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetBundleCodeDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetBundleCodeDir(); + EXPECT_EQ(ret, "/code"); + GTEST_LOG_(INFO) << "GetBundleCodeDir_0200 end"; +} + +/** + * @tc.number: GetCacheDir_0100 + * @tc.name: GetCacheDir + * @tc.desc: Get Cache Dir failed + */ +HWTEST_F(ApplicationContextTest, GetCacheDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetCacheDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetCacheDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetCacheDir_0100 end"; +} + +/** + * @tc.number: GetCacheDir_0200 + * @tc.name: GetCacheDir + * @tc.desc:Get Cache Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetCacheDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetCacheDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetCacheDir(); + EXPECT_EQ(ret, "/cache"); + GTEST_LOG_(INFO) << "GetCacheDir_0200 end"; +} + +/** + * @tc.number: GetTempDir_0100 + * @tc.name: GetTempDir + * @tc.desc: Get Temp Dir failed + */ +HWTEST_F(ApplicationContextTest, GetTempDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetTempDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetTempDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetTempDir_0100 end"; +} + +/** + * @tc.number: GetTempDir_0200 + * @tc.name: GetTempDir + * @tc.desc:Get Temp Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetTempDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetTempDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetTempDir(); + EXPECT_EQ(ret, "/temp"); + GTEST_LOG_(INFO) << "GetTempDir_0200 end"; +} + +/** + * @tc.number: GetFilesDir_0100 + * @tc.name: GetFilesDir + * @tc.desc: Get Files Dir failed + */ +HWTEST_F(ApplicationContextTest, GetFilesDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetFilesDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetFilesDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetFilesDir_0100 end"; +} + +/** + * @tc.number: GetFilesDir_0200 + * @tc.name: GetFilesDir + * @tc.desc:Get Files Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetFilesDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetFilesDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetFilesDir(); + EXPECT_EQ(ret, "/files"); + GTEST_LOG_(INFO) << "GetFilesDir_0200 end"; +} + +/** + * @tc.number: IsUpdatingConfigurations_0100 + * @tc.name: IsUpdatingConfigurations + * @tc.desc: Is Updating Configurations failed + */ +HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->IsUpdatingConfigurations(); + EXPECT_EQ(ret, false); + GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0100 end"; +} + +/** + * @tc.number: IsUpdatingConfigurations_0200 + * @tc.name: IsUpdatingConfigurations + * @tc.desc:Is Updating Configurations sucess + */ +HWTEST_F(ApplicationContextTest, IsUpdatingConfigurations_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->IsUpdatingConfigurations(); + EXPECT_EQ(ret, true); + GTEST_LOG_(INFO) << "IsUpdatingConfigurations_0200 end"; +} + +/** + * @tc.number: PrintDrawnCompleted_0100 + * @tc.name: PrintDrawnCompleted + * @tc.desc: Print Drawn Completed failed + */ +HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->PrintDrawnCompleted(); + EXPECT_EQ(ret, false); + GTEST_LOG_(INFO) << "PrintDrawnCompleted_0100 end"; +} + +/** + * @tc.number: PrintDrawnCompleted_0200 + * @tc.name: PrintDrawnCompleted + * @tc.desc:Print Drawn Completed sucess + */ +HWTEST_F(ApplicationContextTest, PrintDrawnCompleted_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->PrintDrawnCompleted(); + EXPECT_EQ(ret, true); + GTEST_LOG_(INFO) << "PrintDrawnCompleted_0200 end"; +} + +/** + * @tc.number: GetDatabaseDir_0100 + * @tc.name: GetDatabaseDir + * @tc.desc: Get Data base Dir failed + */ +HWTEST_F(ApplicationContextTest, GetDatabaseDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDatabaseDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetDatabaseDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetDatabaseDir_0100 end"; +} + +/** + * @tc.number: GetDatabaseDir_0200 + * @tc.name: GetDatabaseDir + * @tc.desc:Get Data base Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetDatabaseDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDatabaseDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetDatabaseDir(); + EXPECT_EQ(ret, "/data/app/database"); + GTEST_LOG_(INFO) << "GetDatabaseDir_0200 end"; +} + +/** + * @tc.number: GetPreferencesDir_0100 + * @tc.name: GetPreferencesDir + * @tc.desc: Get Preferences Dir failed + */ +HWTEST_F(ApplicationContextTest, GetPreferencesDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPreferencesDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetPreferencesDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetPreferencesDir_0100 end"; +} + +/** + * @tc.number: GetPreferencesDir_0200 + * @tc.name: GetPreferencesDir + * @tc.desc:Get Preferences Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetPreferencesDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetPreferencesDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetPreferencesDir(); + EXPECT_EQ(ret, "/preferences"); + GTEST_LOG_(INFO) << "GetPreferencesDir_0200 end"; +} + +/** + * @tc.number: GetDistributedFilesDir_0100 + * @tc.name: GetDistributedFilesDir + * @tc.desc: Get Distributed Files Dir failed + */ +HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetDistributedFilesDir(); + EXPECT_EQ(ret, ""); + GTEST_LOG_(INFO) << "GetDistributedFilesDir_0100 end"; +} + +/** + * @tc.number: GetDistributedFilesDir_0200 + * @tc.name: GetDistributedFilesDir + * @tc.desc:Get Distributed Files Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetDistributedFilesDir_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetDistributedFilesDir(); + EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName"); + GTEST_LOG_(INFO) << "GetDistributedFilesDir_0200 end"; +} + +/** + * @tc.number: GetToken_0100 + * @tc.name: GetToken + * @tc.desc: Get Token failed + */ +HWTEST_F(ApplicationContextTest, GetToken_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetToken_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetToken(); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "GetToken_0100 end"; +} + +/** + * @tc.number: GetToken_0200 + * @tc.name: GetToken + * @tc.desc:Get Token sucess + */ +HWTEST_F(ApplicationContextTest, GetToken_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetToken_0200 start"; + std::shared_ptr contextImpl = std::make_shared(); + context_->AttachContextImpl(contextImpl); + sptr token = new OHOS::AppExecFwk::MockAbilityToken(); + context_->SetToken(token); + auto ret = context_->GetToken(); + EXPECT_EQ(ret, token); + GTEST_LOG_(INFO) << "GetToken_0200 end"; +} + +/** + * @tc.number: GetArea_0100 + * @tc.name: GetArea + * @tc.desc: Get Area failed + */ +HWTEST_F(ApplicationContextTest, GetArea_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetArea_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetArea(); + EXPECT_EQ(ret, 1); + GTEST_LOG_(INFO) << "GetArea_0100 end"; +} + +/** + * @tc.number: GetArea_0200 + * @tc.name: GetArea + * @tc.desc:Get Area sucess + */ +HWTEST_F(ApplicationContextTest, GetArea_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetArea_0200 start"; + std::shared_ptr contextImpl = std::make_shared(); + context_->AttachContextImpl(contextImpl); + int32_t mode = 1; + context_->SwitchArea(mode); + auto ret = context_->GetArea(); + EXPECT_EQ(ret, mode); + GTEST_LOG_(INFO) << "GetArea_0200 end"; +} + +/** + * @tc.number: GetConfiguration_0100 + * @tc.name: GetConfiguration + * @tc.desc: Get Configuration failed + */ +HWTEST_F(ApplicationContextTest, GetConfiguration_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetConfiguration_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetConfiguration(); + EXPECT_EQ(ret, nullptr); + GTEST_LOG_(INFO) << "GetConfiguration_0100 end"; +} + +/** + * @tc.number: GetConfiguration_0200 + * @tc.name: GetConfiguration + * @tc.desc:Get Configuration sucess + */ +HWTEST_F(ApplicationContextTest, GetConfiguration_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetConfiguration_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetConfiguration(); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetConfiguration_0200 end"; +} + +/** + * @tc.number: GetBaseDir_0100 + * @tc.name: GetBaseDir + * @tc.desc:Get Base Dir sucess + */ +HWTEST_F(ApplicationContextTest, GetBaseDir_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetBaseDir_0100 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetBaseDir(); + EXPECT_EQ(ret, "/data/app/base"); + GTEST_LOG_(INFO) << "GetBaseDir_0100 end"; +} + +/** + * @tc.number: GetDeviceType_0100 + * @tc.name: GetDeviceType + * @tc.desc: Get DeviceType failed + */ +HWTEST_F(ApplicationContextTest, GetDeviceType_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDeviceType_0100 start"; + std::shared_ptr contextImpl = nullptr; + context_->AttachContextImpl(contextImpl); + auto ret = context_->GetDeviceType(); + EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE); + GTEST_LOG_(INFO) << "GetDeviceType_0100 end"; +} + +/** + * @tc.number: GetDeviceType_0200 + * @tc.name: GetDeviceType + * @tc.desc:Get DeviceType sucess + */ +HWTEST_F(ApplicationContextTest, GetDeviceType_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetDeviceType_0200 start"; + context_->AttachContextImpl(mock_); + auto ret = context_->GetDeviceType(); + EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET); + GTEST_LOG_(INFO) << "GetDeviceType_0200 end"; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/application_context_test/mock_context_impl.cpp b/test/unittest/application_context_test/mock_context_impl.cpp new file mode 100644 index 0000000000..a072205b2e --- /dev/null +++ b/test/unittest/application_context_test/mock_context_impl.cpp @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2022 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 "mock_context_impl.h" +#include "sys_mgr_client.h" + +namespace OHOS { +namespace AbilityRuntime { + +std::string MockContextImpl::GetBundleName() const +{ + return "com.test.bundleName"; +} + +std::string MockContextImpl::GetBundleCodeDir() +{ + return "/code"; +} + +std::string MockContextImpl::GetCacheDir() +{ + return "/cache"; +} + +bool MockContextImpl::IsUpdatingConfigurations() +{ + return true; +} + +bool MockContextImpl::PrintDrawnCompleted() +{ + return true; +} + +std::string MockContextImpl::GetDatabaseDir() +{ + return "/data/app/database"; +} + +std::string MockContextImpl::GetPreferencesDir() +{ + return "/preferences"; +} + +std::string MockContextImpl::GetTempDir() +{ + return "/temp"; +} + +std::string MockContextImpl::GetFilesDir() +{ + return "/files"; +} + +std::string MockContextImpl::GetDistributedFilesDir() +{ + return "/mnt/hmdfs/device_view/local/data/bundleName"; +} + +std::shared_ptr MockContextImpl::CreateModuleContext(const std::string &moduleName) +{ + std::shared_ptr appContext = std::make_shared(); + return appContext; +} + +std::shared_ptr MockContextImpl::CreateModuleContext(const std::string &bundleName, const std::string &moduleName) +{ + std::shared_ptr appContext = std::make_shared(); + return appContext; +} + +int MockContextImpl::GetArea() +{ + return 1; +} + +std::string MockContextImpl::GetBaseDir() const +{ + return "/data/app/base"; +} + +std::shared_ptr MockContextImpl::CreateBundleContext(const std::string &bundleName) +{ + std::shared_ptr appContext = std::make_shared(); + return appContext; +} + +sptr MockContextImpl::GetBundleManager() const +{ + auto instance = OHOS::DelayedSingleton::GetInstance(); + if (instance == nullptr) { + return nullptr; + } + auto bundleObj = instance->GetSystemAbility(401); + if (bundleObj == nullptr) { + return nullptr; + } + sptr bms = iface_cast(bundleObj); + return bms; +} + +std::string MockContextImpl::GetBundleCodePath() const +{ + return "codePath"; +} + +void MockContextImpl::InitHapModuleInfo(const std::shared_ptr &abilityInfo) +{} + +Global::Resource::DeviceType MockContextImpl::GetDeviceType() const +{ + return Global::Resource::DeviceType::DEVICE_NOT_SET; +} + +std::shared_ptr MockContextImpl::GetApplicationInfo() const +{ + std::shared_ptr info = std::make_shared(); + info->name = "ContextTest"; + return info; +} + +std::shared_ptr MockContextImpl::GetResourceManager() const +{ + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + return resourceManager; +} + +std::shared_ptr MockContextImpl::GetConfiguration() const +{ + std::shared_ptr config = std::make_shared(); + return config; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/application_context_test/mock_context_impl.h b/test/unittest/application_context_test/mock_context_impl.h new file mode 100644 index 0000000000..2c1439ce2b --- /dev/null +++ b/test/unittest/application_context_test/mock_context_impl.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2022 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_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H +#define OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H + +#include "bundle_mgr_interface.h" +#include "context_impl.h" + +namespace OHOS { +namespace AbilityRuntime { +class MockContextImpl : public ContextImpl { +public: + MockContextImpl() = default; + virtual ~MockContextImpl() = default; + + std::string GetBundleName() const override; + + std::string GetBundleCodeDir() override; + + std::string GetCacheDir() override; + + bool IsUpdatingConfigurations() override; + + bool PrintDrawnCompleted() override; + + std::string GetTempDir() override; + + std::string GetFilesDir() override; + + std::string GetDatabaseDir() override; + + std::string GetPreferencesDir() override; + + std::string GetDistributedFilesDir() override; + + std::shared_ptr CreateModuleContext(const std::string &moduleName) override; + + std::shared_ptr CreateModuleContext(const std::string &bundleName, const std::string &moduleName) override; + + int GetArea() override; + + std::shared_ptr CreateBundleContext(const std::string &bundleName) override; + + sptr GetBundleManager() const; + + void SetApplicationInfo(const std::shared_ptr &info); + + + void SetParentContext(const std::shared_ptr &context); + + std::string GetBundleCodePath() const override; + + void InitHapModuleInfo(const std::shared_ptr &abilityInfo); + + std::string GetBaseDir() const override; + + Global::Resource::DeviceType GetDeviceType() const override; + + std::shared_ptr GetApplicationInfo() const override; + + std::shared_ptr GetResourceManager() const override; + + std::shared_ptr GetConfiguration() const override; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_IMPL_H \ No newline at end of file diff --git a/test/unittest/background_task_observer_test/BUILD.gn b/test/unittest/background_task_observer_test/BUILD.gn index 9058916fbe..c5d70173d4 100755 --- a/test/unittest/background_task_observer_test/BUILD.gn +++ b/test/unittest/background_task_observer_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("background_task_observer_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "background_task_observer_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("background_task_observer_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("background_task_observer_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/connection_observer_controller_test/BUILD.gn b/test/unittest/connection_observer_controller_test/BUILD.gn index 013657cddd..a8f7b274f3 100755 --- a/test/unittest/connection_observer_controller_test/BUILD.gn +++ b/test/unittest/connection_observer_controller_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("connection_observer_controller_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "connection_observer_controller_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("connection_observer_controller_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("connection_observer_controller_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/connection_state_item_test/BUILD.gn b/test/unittest/connection_state_item_test/BUILD.gn index dfd1e700e3..7518a76641 100755 --- a/test/unittest/connection_state_item_test/BUILD.gn +++ b/test/unittest/connection_state_item_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("connection_state_item_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "connection_state_item_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("connection_state_item_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("connection_state_item_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/connection_state_manager_test/BUILD.gn b/test/unittest/connection_state_manager_test/BUILD.gn index 41bfbaa00f..069edf8304 100755 --- a/test/unittest/connection_state_manager_test/BUILD.gn +++ b/test/unittest/connection_state_manager_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("connection_state_manager_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "connection_state_manager_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("connection_state_manager_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("connection_state_manager_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/form_extension_context_test/BUILD.gn b/test/unittest/form_extension_context_test/BUILD.gn index e59b5d94f3..899995438a 100644 --- a/test/unittest/form_extension_context_test/BUILD.gn +++ b/test/unittest/form_extension_context_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("form_extension_context_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "form_extension_context_test.cpp", # add mock file ] @@ -46,6 +45,7 @@ ohos_unittest("form_extension_context_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -60,7 +60,6 @@ ohos_unittest("form_extension_context_test") { "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "ability_runtime:runtime", - "access_token:libaccesstoken_sdk", "c_utils:utils", "eventhandler:libeventhandler", "hitrace_native:hitrace_meter", diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn index 03b9c3de98..30f6f6eac7 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/BUILD.gn @@ -25,12 +25,16 @@ config("module_private_config") { ohos_unittest("ability_context_impl_ut_test") { module_out_path = module_out_path - include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS" ] + include_dirs = [ + "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context/", + ] sources = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_ability_manager_client.cpp", "${ability_runtime_test_path}/mock/frameworks_kits_ability_ability_runtime_test/AMS/mock_serviceability_manager_service.cpp", "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/sys_mgr_client_mock.cpp", + "${ability_runtime_test_path}/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp", "ability_context_impl_ut_test.cpp", ] @@ -39,12 +43,15 @@ ohos_unittest("ability_context_impl_ut_test") { "${ability_runtime_native_path}/ability:ability_context_native", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] external_deps = [ + "ability_base:configuration", "ability_base:want", + "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", "hiviewdfx_hilog_native:libhilog", diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_ut_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_ut_test.cpp index ac4dc9ce51..b7f275f0eb 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_ut_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/ability_context_impl_ut_test.cpp @@ -20,6 +20,7 @@ #include "ability_loader.h" #include "ability_thread.h" #include "iability_callback.h" +#include "mock_context.h" #include "mock_serviceability_manager_service.h" #include "system_ability_definition.h" #include "sys_mgr_client.h" @@ -60,6 +61,7 @@ public: void TearDown(); public: std::unique_ptr context_ = nullptr; + std::shared_ptr mock_ = nullptr; }; void AbilityContextImplTest::SetUpTestCase(void) @@ -79,6 +81,7 @@ void AbilityContextImplTest::TearDownTestCase(void) void AbilityContextImplTest::SetUp(void) { context_ = std::make_unique(); + mock_ = std::make_shared(); } void AbilityContextImplTest::TearDown(void) @@ -236,5 +239,804 @@ HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetMissionIcon_0100, Funct context_->RegisterAbilityCallback(abilityCallback); AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; } + +/** + * @tc.number: Ability_Context_Impl_GetCurrentWindowMode_0100 + * @tc.name: GetCurrentWindowMode + * @tc.desc: Get Current Window Mode failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCurrentWindowMode_0100, Function | MediumTest | Level1) +{ + std::weak_ptr abilityCallback; + context_->RegisterAbilityCallback(abilityCallback); + auto ret = context_->GetCurrentWindowMode(); + EXPECT_EQ(ret, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); +} + +/** + * @tc.number: Ability_Context_Impl_GetCurrentWindowMode_0200 + * @tc.name: GetCurrentWindowMode + * @tc.desc: Get Current Window Mode sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCurrentWindowMode_0200, Function | MediumTest | Level1) +{ + auto abilityCallback = std::weak_ptr(); + context_->RegisterAbilityCallback(abilityCallback); + auto ret = context_->GetCurrentWindowMode(); + EXPECT_EQ(ret, AAFwk::AbilityWindowConfiguration::MULTI_WINDOW_DISPLAY_UNDEFINED); +} + +/** + * @tc.number: Ability_Context_Impl_ConnectAbility_0100 + * @tc.name: ConnectAbility + * @tc.desc: Connect Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_ConnectAbility_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + sptr connectCallback; + auto ret = context_->ConnectAbility(want, connectCallback); + EXPECT_EQ(ret, false); +} + +/** + * @tc.number: Ability_Context_Impl_ConnectAbilityWithAccount_0100 + * @tc.name: ConnectAbilityWithAccount + * @tc.desc: Connect Ability With Account + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_ConnectAbilityWithAccount_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + sptr connectCallback; + auto ret = context_->ConnectAbilityWithAccount(want, accountId, connectCallback); + EXPECT_EQ(ret, false); +} + +/** + * @tc.number: Ability_Context_Impl_TerminateSelf_0100 + * @tc.name: TerminateSelf + * @tc.desc: Terminate Self + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_TerminateSelf_0100, Function | MediumTest | Level1) +{ + auto ret = context_->TerminateSelf(); + EXPECT_EQ(ret, false); +} + +/** + * @tc.number: Ability_Context_Impl_SetAbilityInfo_0100 + * @tc.name: SetAbilityInfo + * @tc.desc: Set AbilityInfo + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetAbilityInfo_0100, Function | MediumTest | Level1) +{ + auto abilityInfo = std::make_shared(); + abilityInfo->name = "AbilityContextImplTest"; + context_->SetAbilityInfo(abilityInfo); + EXPECT_EQ(context_->GetAbilityInfo(), abilityInfo); +} + +/** + * @tc.number: Ability_Context_Impl_SetConfiguration_0100 + * @tc.name: SetConfiguration + * @tc.desc: Set Configuration + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SetConfiguration_0100, Function | MediumTest | Level1) +{ + auto config = std::make_shared(); + context_->SetConfiguration(config); + EXPECT_EQ(context_->GetConfiguration(), config); +} + +/** + * @tc.number: Ability_Context_Impl_CloseAbility_0100 + * @tc.name: CloseAbility + * @tc.desc: Close Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CloseAbility_0100, Function | MediumTest | Level1) +{ + auto ret = context_->CloseAbility(); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_TerminateAbilityWithResult_0100 + * @tc.name: TerminateAbilityWithResult + * @tc.desc: Terminate Ability With Result + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_TerminateAbilityWithResult_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t resultCode = 1; + auto ret = context_->TerminateAbilityWithResult(want, resultCode); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StopServiceExtensionAbility_0100 + * @tc.name: StopServiceExtensionAbility + * @tc.desc: Stop Service Extension Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StopServiceExtensionAbility_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + auto ret = context_->StopServiceExtensionAbility(want, accountId); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartServiceExtensionAbility_0100 + * @tc.name: StartServiceExtensionAbility + * @tc.desc: Start Service Extension Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartServiceExtensionAbility_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + auto ret = context_->StartServiceExtensionAbility(want, accountId); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityForResultWithAccount_0100 + * @tc.name: StartAbilityForResultWithAccount + * @tc.desc: Start Ability For Result With Account + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResultWithAccount_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResultWithAccount_0100 task called"; }; + auto ret = context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task)); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityForResult_0100 + * @tc.name: StartAbilityForResult + * @tc.desc: Start Ability For Result + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResult_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResult_0100 task called"; }; + auto ret = context_->StartAbilityForResult(want, startOptions, requestCode, std::move(task)); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityForResultWithAccount_0200 + * @tc.name: StartAbilityForResultWithAccount + * @tc.desc: Start Ability For Result With Account + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResultWithAccount_0200, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t requestCode = 1; + int32_t accountId = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResultWithAccount_0200 task called"; }; + auto ret = context_->StartAbilityForResultWithAccount(want, accountId, requestCode, std::move(task)); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityForResult_0200 + * @tc.name: StartAbilityForResult + * @tc.desc: Start Ability For Result + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityForResult_0200, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t requestCode = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_StartAbilityForResult_0200 task called"; }; + auto ret = context_->StartAbilityForResult(want, requestCode, std::move(task)); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityWithAccount_0100 + * @tc.name: StartAbilityWithAccount + * @tc.desc: Start Ability With Account + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityWithAccount_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + auto ret = context_->StartAbilityWithAccount(want, accountId, startOptions, requestCode); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbilityWithAccount_0200 + * @tc.name: StartAbilityWithAccount + * @tc.desc: Start Ability With Account + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbilityWithAccount_0200, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + int32_t requestCode = 1; + auto ret = context_->StartAbilityWithAccount(want, accountId, requestCode); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbility_0300 + * @tc.name: StartAbility + * @tc.desc: Start Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0300, Function | MediumTest | Level1) +{ + AAFwk::Want want; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + auto ret = context_->StartAbility(want, startOptions, requestCode); + EXPECT_NE(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_StartAbility_0400 + * @tc.name: StartAbility + * @tc.desc: Start Ability + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_StartAbility_0400, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t requestCode = 1; + auto ret = context_->StartAbility(want, requestCode); + EXPECT_EQ(ret, ERR_OK); +} + +/** + * @tc.number: Ability_Context_Impl_OnAbilityResult_0100 + * @tc.name: OnAbilityResult + * @tc.desc: On Ability Result + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_OnAbilityResult_0100, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_OnAbilityResult_0100 task called"; }; + context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task)); + int32_t count = context_->resultCallbacks_.size(); + EXPECT_EQ(count, 1); + + int32_t code = 2; + int32_t resultCode = 2; + AAFwk::Want resultData; + context_->OnAbilityResult(code, resultCode, resultData); + count = context_->resultCallbacks_.size(); + EXPECT_EQ(count, 1); +} + +/** + * @tc.number: Ability_Context_Impl_OnAbilityResult_0200 + * @tc.name: OnAbilityResult + * @tc.desc: On Ability Result + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_OnAbilityResult_0200, Function | MediumTest | Level1) +{ + AAFwk::Want want; + int32_t accountId = 1; + AAFwk::StartOptions startOptions; + int32_t requestCode = 1; + RuntimeTask task = [](const int32_t count, const Want& want) + { GTEST_LOG_(INFO) << "Ability_Context_Impl_OnAbilityResult_0200 task called"; }; + context_->StartAbilityForResultWithAccount(want, accountId, startOptions, requestCode, std::move(task)); + int32_t count = context_->resultCallbacks_.size(); + EXPECT_EQ(count, 1); + + int32_t code = 1; + int32_t resultCode = 1; + AAFwk::Want resultData; + context_->OnAbilityResult(code, resultCode, resultData); + count = context_->resultCallbacks_.size(); + EXPECT_EQ(count, 0); +} + +/** + * @tc.number: Ability_Context_Impl_GetDeviceType_0100 + * @tc.name: GetDeviceType + * @tc.desc: Get Device Type sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDeviceType_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetDeviceType(); + EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_NOT_SET); +} + +/** + * @tc.number: Ability_Context_Impl_GetDeviceType_0200 + * @tc.name: GetDeviceType + * @tc.desc: Get Device Type failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDeviceType_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetDeviceType(); + EXPECT_EQ(ret, Global::Resource::DeviceType::DEVICE_PHONE); +} + +/** + * @tc.number: Ability_Context_Impl_GetBaseDir_0100 + * @tc.name: GetBaseDir + * @tc.desc: Get Base Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBaseDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetBaseDir(); + EXPECT_EQ(ret, "/data/app/base"); +} + +/** + * @tc.number: Ability_Context_Impl_GetBaseDir_0200 + * @tc.name: GetBaseDir + * @tc.desc: Get Base Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBaseDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetBaseDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleCodeDir_0100 + * @tc.name: GetBundleCodeDir + * @tc.desc: Get Bundle Code Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodeDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetBundleCodeDir(); + EXPECT_EQ(ret, "/code"); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleCodeDir_0200 + * @tc.name: GetBundleCodeDir + * @tc.desc: Get Bundle Code Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodeDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetBundleCodeDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetCacheDir_0100 + * @tc.name: GetCacheDir + * @tc.desc: Get Cache Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCacheDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetCacheDir(); + EXPECT_EQ(ret, "/cache"); +} + +/** + * @tc.number: Ability_Context_Impl_GetCacheDir_0200 + * @tc.name: GetCacheDir + * @tc.desc: Get Cache Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetCacheDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetCacheDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetDatabaseDir_0100 + * @tc.name: GetDatabaseDir + * @tc.desc: Get Database Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDatabaseDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetDatabaseDir(); + EXPECT_EQ(ret, "/data/app/database"); +} + +/** + * @tc.number: Ability_Context_Impl_GetDatabaseDir_0200 + * @tc.name: GetDatabaseDir + * @tc.desc: Get Database Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDatabaseDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetDatabaseDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetPreferencesDir_0100 + * @tc.name: GetPreferencesDir + * @tc.desc: Get Preferences Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetPreferencesDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetPreferencesDir(); + EXPECT_EQ(ret, "/preferences"); +} + +/** + * @tc.number: Ability_Context_Impl_GetPreferencesDir_0200 + * @tc.name: GetPreferencesDir + * @tc.desc: Get Preferences Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetPreferencesDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetPreferencesDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetTempDir_0100 + * @tc.name: GetTempDir + * @tc.desc: Get Temp Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetTempDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetTempDir(); + EXPECT_EQ(ret, "/temp"); +} + +/** + * @tc.number: Ability_Context_Impl_GetTempDir_0200 + * @tc.name: GetTempDir + * @tc.desc: Get Temp Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetTempDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetTempDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetFilesDir_0100 + * @tc.name: GetFilesDir + * @tc.desc: Get Files Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetFilesDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetFilesDir(); + EXPECT_EQ(ret, "/files"); +} + +/** + * @tc.number: Ability_Context_Impl_GetFilesDir_0200 + * @tc.name: GetFilesDir + * @tc.desc: Get Files Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetFilesDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetFilesDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetDistributedFilesDir_0100 + * @tc.name: GetDistributedFilesDir + * @tc.desc: Get Distributed Files Dir sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDistributedFilesDir_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetDistributedFilesDir(); + EXPECT_EQ(ret, "/mnt/hmdfs/device_view/local/data/bundleName"); +} + +/** + * @tc.number: Ability_Context_Impl_GetDistributedFilesDir_0200 + * @tc.name: GetDistributedFilesDir + * @tc.desc: Get Distributed Files Dir failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetDistributedFilesDir_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetDistributedFilesDir(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_IsUpdatingConfigurations_0100 + * @tc.name: IsUpdatingConfigurations + * @tc.desc: Is Updating Configurations true + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_IsUpdatingConfigurations_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->IsUpdatingConfigurations(); + EXPECT_EQ(ret, true); +} + +/** + * @tc.number: Ability_Context_Impl_IsUpdatingConfigurations_0200 + * @tc.name: IsUpdatingConfigurations + * @tc.desc: Is Updating Configurations false + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_IsUpdatingConfigurations_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->IsUpdatingConfigurations(); + EXPECT_EQ(ret, false); +} + +/** + * @tc.number: Ability_Context_Impl_PrintDrawnCompleted_0100 + * @tc.name: PrintDrawnCompleted + * @tc.desc: Print Drawn Completed true + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_PrintDrawnCompleted_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->PrintDrawnCompleted(); + EXPECT_EQ(ret, true); +} + +/** + * @tc.number: Ability_Context_Impl_PrintDrawnCompleted_0200 + * @tc.name: PrintDrawnCompleted + * @tc.desc: Print Drawn Completed false + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_PrintDrawnCompleted_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->PrintDrawnCompleted(); + EXPECT_EQ(ret, false); +} + +/** + * @tc.number: Ability_Context_Impl_SwitchArea_0200 + * @tc.name: SwitchArea + * @tc.desc: Switch Area failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SwitchArea_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + int32_t mode = 2; + context_->SwitchArea(mode); + EXPECT_EQ(context_->GetArea(), 1); +} + +/** + * @tc.number: Ability_Context_Impl_SwitchArea_0100 + * @tc.name: SwitchArea + * @tc.desc: Switch Area sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_SwitchArea_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + int32_t mode = 2; + context_->SwitchArea(mode); + EXPECT_EQ(context_->GetArea(), mode); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleName_0100 + * @tc.name: GetBundleName + * @tc.desc: Get BundleName sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleName_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetBundleName(); + EXPECT_EQ(ret, "com.test.bundleName"); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleName_0200 + * @tc.name: GetBundleName + * @tc.desc: Get BundleName failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleName_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetBundleName(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetApplicationInfo_0100 + * @tc.name: GetApplicationInfo + * @tc.desc: Get ApplicationInfo sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetApplicationInfo_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetApplicationInfo(); + EXPECT_NE(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_GetApplicationInfo_0200 + * @tc.name: GetApplicationInfo + * @tc.desc: Get ApplicationInfo failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetApplicationInfo_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetApplicationInfo(); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleCodePath_0100 + * @tc.name: GetBundleCodePath + * @tc.desc: Get Bundle Code Path sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodePath_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetBundleCodePath(); + EXPECT_EQ(ret, "codePath"); +} + +/** + * @tc.number: Ability_Context_Impl_GetBundleCodePath_0200 + * @tc.name: GetBundleCodePath + * @tc.desc: Get Bundle Code Path failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetBundleCodePath_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetBundleCodePath(); + EXPECT_EQ(ret, ""); +} + +/** + * @tc.number: Ability_Context_Impl_GetHapModuleInfo_0100 + * @tc.name: GetHapModuleInfo + * @tc.desc: Get Hap Module Info sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetHapModuleInfo_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetHapModuleInfo(); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_GetHapModuleInfo_0200 + * @tc.name: GetHapModuleInfo + * @tc.desc: Get Hap Module Info failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetHapModuleInfo_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetHapModuleInfo(); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_GetResourceManager_0100 + * @tc.name: GetResourceManager + * @tc.desc: Get Resource Manager sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceManager_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + auto ret = context_->GetResourceManager(); + EXPECT_NE(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_GetResourceManager_0200 + * @tc.name: GetResourceManager + * @tc.desc: Get Resource Manager failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_GetResourceManager_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + auto ret = context_->GetResourceManager(); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateBundleContext_0100 + * @tc.name: CreateBundleContext + * @tc.desc: Create Bundle Context sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateBundleContext_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateBundleContext(bundleName); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateBundleContext_0200 + * @tc.name: CreateBundleContext + * @tc.desc: Create Bundle Context failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateBundleContext_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateBundleContext(bundleName); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateModuleContext_0100 + * @tc.name: CreateModuleContext + * @tc.desc: Create Module Context sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0100, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + std::string moduleName = "com.test.moduleName"; + auto ret = context_->CreateModuleContext(moduleName); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateModuleContext_0200 + * @tc.name: CreateModuleContext + * @tc.desc: Create Module Context failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0200, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + std::string moduleName = "com.test.moduleName"; + auto ret = context_->CreateModuleContext(moduleName); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateModuleContext_0300 + * @tc.name: CreateModuleContext + * @tc.desc: Create Module Context sucess + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0300, Function | MediumTest | Level1) +{ + context_->SetStageContext(mock_); + std::string moduleName = "com.test.moduleName"; + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateModuleContext(bundleName, moduleName); + EXPECT_EQ(ret, nullptr); +} + +/** + * @tc.number: Ability_Context_Impl_CreateModuleContext_0400 + * @tc.name: CreateModuleContext + * @tc.desc: Create Module Context failed + */ +HWTEST_F(AbilityContextImplTest, Ability_Context_Impl_CreateModuleContext_0400, Function | MediumTest | Level1) +{ + context_->SetStageContext(nullptr); + std::string moduleName = "com.test.moduleName"; + std::string bundleName = "com.test.bundleName"; + auto ret = context_->CreateModuleContext(bundleName, moduleName); + EXPECT_EQ(ret, nullptr); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp index 054d82e181..3afe362cc2 100644 --- a/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/local_call_container_ut_test.cpp @@ -411,5 +411,24 @@ HWTEST_F(LocalCallContainerTest, Local_Call_Container_GetCallLocalRecord_0200, F bool ret = localCallContainer.GetCallLocalRecord(elementName, localCallRecord); EXPECT_TRUE(ret == false); } + +/** + * @tc.number: Local_Call_Container_OnCallStubDied_0100 + * @tc.name: OnCallStubDied + * @tc.desc: Verify that function IsSameObject. + */ +HWTEST_F(LocalCallContainerTest, Local_Call_Container_OnCallStubDied_0100, Function | MediumTest | Level1) +{ + LocalCallContainer localCallContainer; + + AppExecFwk::ElementName elementName("DemoDeviceId", "DemoBundleName", "DemoAbilityName"); + std::shared_ptr localCallRecord = std::make_shared(elementName); + + sptr remoteObject = new (std::nothrow) MockServiceAbilityManagerService(); + wptr remote(remoteObject); + + localCallContainer.OnCallStubDied(remote); + EXPECT_TRUE(localCallContainer.callProxyRecords_.empty()); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp new file mode 100644 index 0000000000..5ec44018ab --- /dev/null +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2022 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 "connection_manager.h" +#include "mock_context.h" +#include "resource_manager.h" +#include "sys_mgr_client.h" + +namespace OHOS { +namespace AbilityRuntime { +const size_t Context::CONTEXT_TYPE_ID(std::hash {} ("Context")); +std::string MockContext::GetBundleName() const +{ + return "com.test.bundleName"; +} + +std::string MockContext::GetBundleCodeDir() +{ + return "/code"; +} + +std::string MockContext::GetCacheDir() +{ + return "/cache"; +} + +bool MockContext::IsUpdatingConfigurations() +{ + return true; +} + +bool MockContext::PrintDrawnCompleted() +{ + return true; +} + +std::string MockContext::GetDatabaseDir() +{ + return "/data/app/database"; +} + +std::string MockContext::GetPreferencesDir() +{ + return "/preferences"; +} + +std::string MockContext::GetTempDir() +{ + return "/temp"; +} + +std::string MockContext::GetFilesDir() +{ + return "/files"; +} + +std::string MockContext::GetDistributedFilesDir() +{ + return "/mnt/hmdfs/device_view/local/data/bundleName"; +} + +std::shared_ptr MockContext::CreateModuleContext(const std::string &moduleName) +{ + return nullptr; +} + +std::shared_ptr MockContext::CreateModuleContext(const std::string &bundleName, const std::string &moduleName) +{ + return nullptr; +} + +int MockContext::GetArea() +{ + return mode_; +} + +std::string MockContext::GetBaseDir() const +{ + return "/data/app/base"; +} + +std::shared_ptr MockContext::CreateBundleContext(const std::string &bundleName) +{ + return nullptr; +} + +sptr MockContext::GetBundleManager() const +{ + auto instance = OHOS::DelayedSingleton::GetInstance(); + if (instance == nullptr) { + return nullptr; + } + auto bundleObj = instance->GetSystemAbility(401); + if (bundleObj == nullptr) { + return nullptr; + } + sptr bms = iface_cast(bundleObj); + return bms; +} + +std::string MockContext::GetBundleCodePath() const +{ + return "codePath"; +} + +void MockContext::InitHapModuleInfo(const std::shared_ptr &abilityInfo) +{} + +Global::Resource::DeviceType MockContext::GetDeviceType() const +{ + return Global::Resource::DeviceType::DEVICE_NOT_SET; +} + +std::shared_ptr MockContext::GetApplicationInfo() const +{ + std::shared_ptr info = std::make_shared(); + info->name = "ContextTest"; + return info; +} + +std::shared_ptr MockContext::GetResourceManager() const +{ + std::shared_ptr resourceManager(Global::Resource::CreateResourceManager()); + return resourceManager; +} + +std::shared_ptr MockContext::GetConfiguration() const +{ + std::shared_ptr config = std::make_shared(); + return config; +} + +void MockContext::SetToken(const sptr &token) +{} + +sptr MockContext::GetToken() +{ + return nullptr; +} + +std::shared_ptr MockContext::GetHapModuleInfo() const +{ + return nullptr; +} + +void MockContext::SwitchArea(int mode) +{ + mode_ = mode; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h new file mode 100644 index 0000000000..a4f8e7a779 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_ability_runtime_test/mock_context.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2022 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_ABILITY_RUNTIME_MOCK_CONTEXT_H +#define OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_H + +#define protected public +#include "context.h" +#undef protected +#include "configuration.h" +#include "bundle_mgr_interface.h" + +namespace OHOS { +namespace AbilityRuntime { +class MockContext : public AbilityRuntime::Context{ +public: + MockContext() = default; + virtual ~MockContext() = default; + + std::string GetBundleName() const override; + + std::string GetBundleCodeDir() override; + + std::string GetCacheDir() override; + + bool IsUpdatingConfigurations() override; + + bool PrintDrawnCompleted() override; + + std::string GetTempDir() override; + + std::string GetFilesDir() override; + + std::string GetDatabaseDir() override; + + std::string GetPreferencesDir() override; + + std::string GetDistributedFilesDir() override; + + void SwitchArea(int mode) override; + + std::shared_ptr CreateModuleContext(const std::string &moduleName) override; + + std::shared_ptr CreateModuleContext(const std::string &bundleName, const std::string &moduleName) override; + + int GetArea() override; + + void SetResourceManager(const std::shared_ptr &resourceManager); + + std::shared_ptr GetResourceManager() const override; + + std::shared_ptr CreateBundleContext(const std::string &bundleName) override; + + sptr GetBundleManager() const; + + void SetApplicationInfo(const std::shared_ptr &info); + + std::shared_ptr GetApplicationInfo() const override; + + void SetParentContext(const std::shared_ptr &context); + + std::string GetBundleCodePath() const override; + + std::shared_ptr GetHapModuleInfo() const override; + + void InitHapModuleInfo(const std::shared_ptr &abilityInfo); + + void InitHapModuleInfo(const AppExecFwk::HapModuleInfo &hapModuleInfo); + + void SetToken(const sptr &token) override; + + sptr GetToken() override; + + void SetConfiguration(const std::shared_ptr &config); + + std::shared_ptr GetConfiguration() const override; + + std::string GetBaseDir() const override; + + Global::Resource::DeviceType GetDeviceType() const override; + + int32_t mode_ = 0; +}; +} // namespace AbilityRuntime +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_MOCK_CONTEXT_H \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn index d2bccc5401..f56820ad2a 100644 --- a/test/unittest/frameworks_kits_ability_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_ability_native_test/BUILD.gn @@ -16,6 +16,11 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") module_output_path = "ability_runtime/ability_test" +config("coverage_flags") { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] +} + ############################################################################### config("module_private_config") { visibility = [ ":*" ] @@ -352,17 +357,28 @@ ohos_unittest("scene_created_test") { ohos_unittest("data_ability_helper_test") { module_out_path = module_output_path - include_dirs = [ "${ability_runtime_services_path}/abilitymgr/include" ] + include_dirs = [ + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context", + ] - sources = [ "data_ability_helper_test.cpp" ] + sources = [ + "data_ability_helper_test.cpp", + "mock_ability_runtime_context.cpp", + ] - configs = [ ":module_ability_context_config" ] + configs = [ + ":module_ability_context_config", + ":coverage_flags", + ] deps = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager", "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/ability/native:data_ability_helper", "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_services_path}/abilitymgr:abilityms", "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -372,12 +388,16 @@ ohos_unittest("data_ability_helper_test") { "ability_base:want", "ability_base:zuri", "c_utils:utils", + "data_share:datashare_common", + "data_share:datashare_consumer", "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "relational_store:native_appdatafwk", "relational_store:native_dataability", "relational_store:native_rdb", + "relational_store:rdb_data_ability_adapter", ] if (ability_runtime_graphics) { @@ -1022,6 +1042,93 @@ ohos_unittest("data_uri_utils_test") { } } +ohos_unittest("extension_impl_test") { + module_out_path = module_output_path + include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ] + + sources = [ "extension_impl_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:form_extension", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "eventhandler:libeventhandler", + "form_fwk:form_manager", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "relational_store:native_appdatafwk", + "relational_store:native_dataability", + "relational_store:native_rdb", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +ohos_unittest("form_js_event_handler_test") { + module_out_path = module_output_path + include_dirs = [ "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include" ] + + sources = [ "form_js_event_handler_test.cpp" ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:form_extension", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:base", + "ability_base:configuration", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_deps_wrapper", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "eventhandler:libeventhandler", + "form_fwk:fmskit_native", + "form_fwk:form_manager", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "relational_store:native_appdatafwk", + "relational_store:native_dataability", + "relational_store:native_rdb", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + ohos_unittest("pac_map_test") { module_out_path = module_output_path sources = [ "pac_map_test.cpp" ] @@ -1205,6 +1312,7 @@ ohos_unittest("continuation_test") { "${ability_runtime_native_path}/appkit/app/app_context.cpp", "${ability_runtime_native_path}/appkit/app/app_loader.cpp", "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp", "continuation_test.cpp", ] @@ -1304,6 +1412,76 @@ ohos_unittest("new_ability_impl_test") { } } +ohos_unittest("reserse_continuation_scheduler_primary_stub_test") { + module_out_path = module_output_path + if (ability_runtime_graphics) { + sources = [ + "${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stub.cpp", + "reserse_continuation_scheduler_primary_stub_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "${multimodalinput_path}/frameworks/proxy:libmmi-common", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", + "ipc:ipc_core", + ] + } +} + +ohos_unittest("reserse_continuation_scheduler_primary_proxy_test") { + module_out_path = module_output_path + if (ability_runtime_graphics) { + sources = [ + "${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_proxy.cpp", + "${ability_runtime_native_path}/ability/native/continuation/distributed/reverse_continuation_scheduler_primary_stub.cpp", + "${ability_runtime_native_path}/ability/native/new_ability_impl.cpp", + "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_replace_ability_impl.cpp", + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit/src/mock_ability_connect_callback.cpp", + "reserse_continuation_scheduler_primary_proxy_test.cpp", + ] + + configs = [ ":module_private_config" ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "${global_path}/resource_management/frameworks/resmgr:global_resmgr", + "${multimodalinput_path}/frameworks/proxy:libmmi-common", + "//third_party/googletest:gmock_main", + ] + + external_deps = [ + "ability_base:want", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "input:libmmi-client", + "ipc:ipc_core", + ] + } +} + ohos_unittest("distributed_client_test") { module_out_path = module_output_path sources = [ @@ -1362,10 +1540,14 @@ group("unittest") { ":data_ability_result_test", ":data_uri_utils_test", ":distributed_client_test", + ":extension_impl_test", ":extension_test", ":form_extension_test", + ":form_js_event_handler_test", ":new_ability_impl_test", ":pac_map_test", + ":reserse_continuation_scheduler_primary_proxy_test", + ":reserse_continuation_scheduler_primary_stub_test", ":service_ability_impl_test", ":task_handler_client_test", ] diff --git a/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp index 47e52ff739..5653a95baa 100644 --- a/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/ability_impl_test.cpp @@ -15,8 +15,12 @@ #include -#include "ability_impl.h" #include "ability.h" +#define private public +#define protected public +#include "ability_impl.h" +#undef protected +#undef private #include "context_deal.h" #include "hilog_wrapper.h" #include "mock_ability_token.h" @@ -1526,5 +1530,1605 @@ HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndRestore_001, TestSize.Level1 } GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndRestore_001 end"; } + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0200 + * @tc.name: Init + * @tc.desc: application is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0200 start"; + std::shared_ptr application; + std::shared_ptr abilityInfo = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr contextDeal = std::make_shared(); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0300 + * @tc.name: Init + * @tc.desc: record is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0300 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr record; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr eventRunner = EventRunner::Create(""); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr contextDeal = std::make_shared(); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0400 + * @tc.name: Init + * @tc.desc: ability is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0400 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr ability; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr contextDeal = std::make_shared(); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0500 + * @tc.name: Init + * @tc.desc: handler is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0500 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr handler; + std::shared_ptr contextDeal = std::make_shared(); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0500 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0600 + * @tc.name: Init + * @tc.desc: token is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0600 start"; + std::shared_ptr application = std::make_shared(); + sptr token = nullptr; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr contextDeal = std::make_shared(); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0600 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Init_0700 + * @tc.name: Init + * @tc.desc: contextDeal is nullptr, Verify Init failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Init_0700, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0700 start"; + std::shared_ptr application = std::make_shared(); + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr contextDeal; + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + EXPECT_TRUE(AbilityImpl_->token_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Init_0700 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Start_0200 + * @tc.name: Start + * @tc.desc: Test the normal behavior of the AbilityImpl::Start + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0200 start"; + + std::shared_ptr mockAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "pageAbility"; + abilityInfo->type = AbilityType::DATA; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability; + MockPageAbility* pMocKPageAbility = new (std::nothrow) MockPageAbility(); + EXPECT_NE(pMocKPageAbility, nullptr); + if (pMocKPageAbility != nullptr) { + ability.reset(pMocKPageAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal); + Want want; + mockAbilityimpl->ImplStart(want); + EXPECT_EQ(AAFwk::ABILITY_STATE_ACTIVE, mockAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Start_0300 + * @tc.name: Start + * @tc.desc: Test the normal behavior of the AbilityImpl::Start + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0300 start"; + + std::shared_ptr mockAbilityimpl = std::make_shared(); + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "pageAbility"; + abilityInfo->type = AppExecFwk::AbilityType::PAGE; + abilityInfo->isStageBasedModel = true; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability; + MockPageAbility* pMocKPageAbility = new (std::nothrow) MockPageAbility(); + EXPECT_NE(pMocKPageAbility, nullptr); + if (pMocKPageAbility != nullptr) { + ability.reset(pMocKPageAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + mockAbilityimpl->Init(application, record, ability, handler, token, contextDeal); + Want want; + mockAbilityimpl->ImplStart(want); + EXPECT_EQ(AAFwk::ABILITY_STATE_STARTED_NEW, mockAbilityimpl->GetCurrentState()); + } + } + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Start_0400 + * @tc.name: Start + * @tc.desc: ability is nullptr, Verify Start failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0400 start"; + AbilityImpl_->ability_ = nullptr; + Want want; + AbilityImpl_->Start(want); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Start_0500 + * @tc.name: Start + * @tc.desc: abilityInfo is nullptr, Verify Start failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0500 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + Want want; + AbilityImpl_->Start(want); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0500 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Start_0600 + * @tc.name: Start + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Start failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Start_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0600 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + Want want; + AbilityImpl_->Start(want); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Start_0600 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0200 + * @tc.name: Stop + * @tc.desc: ability is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0200 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->Stop(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0300 + * @tc.name: Stop + * @tc.desc: abilityInfo is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0300 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + AbilityImpl_->Stop(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0400 + * @tc.name: Stop + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0400 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + AbilityImpl_->Stop(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0500 + * @tc.name: Stop + * @tc.desc: ability is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0500 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + AbilityImpl_->ability_ = nullptr; + bool isAsyncCallback = true; + AbilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0500 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0600 + * @tc.name: Stop + * @tc.desc: abilityInfo is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0600 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + bool isAsyncCallback = true; + AbilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0600 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0700 + * @tc.name: Stop + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0700, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0700 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + bool isAsyncCallback = true; + AbilityImpl_->Stop(isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0700 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Stop_0800 + * @tc.name: Stop + * @tc.desc: Verify Stop succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Stop_0800, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0800 start"; + std::shared_ptr application = std::make_shared(); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->name = "pageAbility"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + EXPECT_NE(token, nullptr); + if (token != nullptr) { + std::shared_ptr record = std::make_shared(abilityInfo, token); + std::shared_ptr eventRunner = EventRunner::Create(abilityInfo->name); + std::shared_ptr handler = std::make_shared(eventRunner); + std::shared_ptr ability; + MockPageAbility* pMocKPageAbility = new (std::nothrow) MockPageAbility(); + EXPECT_NE(pMocKPageAbility, nullptr); + if (pMocKPageAbility != nullptr) { + ability.reset(pMocKPageAbility); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->Init(application, record, ability, handler, token, contextDeal); + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + bool isAsyncCallback = false; + AbilityImpl_->Stop(isAsyncCallback); + + EXPECT_EQ(MockPageAbility::Event::ON_STOP, pMocKPageAbility->state_); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + } + } + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Stop_0800 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_StopCallback_0200 + * @tc.name: StopCallback + * @tc.desc: ability is nullptr, Verify StopCallback failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_StopCallback_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0200 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->StopCallback(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_StopCallback_0300 + * @tc.name: StopCallback + * @tc.desc: abilityInfo is nullptr, Verify StopCallback failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_StopCallback_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0300 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + AbilityImpl_->StopCallback(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_StopCallback_0400 + * @tc.name: Stop + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Stop failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_StopCallback_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0400 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + AbilityImpl_->StopCallback(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_StopCallback_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Active_0200 + * @tc.name: Active + * @tc.desc: ability is nullptr, Verify Active failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Active_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0200 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->Active(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Active_0300 + * @tc.name: Active + * @tc.desc: abilityInfo is nullptr, Verify Active failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Active_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0300 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + AbilityImpl_->Active(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Active_0400 + * @tc.name: Active + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Active failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Active_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0400 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + AbilityImpl_->Active(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Active_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Inactive_0200 + * @tc.name: Inactive + * @tc.desc: ability is nullptr, Verify Inactive failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Inactive_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0200 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->Inactive(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Inactive_0300 + * @tc.name: Inactive + * @tc.desc: abilityInfo is nullptr, Verify Inactive failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Inactive_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0300 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + AbilityImpl_->Inactive(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Inactive_0400 + * @tc.name: Inactive + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify Inactive failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Inactive_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0400 start"; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + AbilityImpl_->Inactive(); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Inactive_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_IsStageBasedModel_0100 + * @tc.name: IsStageBasedModel + * @tc.desc: Verify IsStageBasedModel succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_IsStageBasedModel_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_IsStageBasedModel_0100 start"; + EXPECT_FALSE(AbilityImpl_->IsStageBasedModel()); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_IsStageBasedModel_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DispatchSaveAbilityState_0100 + * @tc.name: DispatchSaveAbilityState + * @tc.desc: ability is nullptr, Verify DispatchSaveAbilityState failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchSaveAbilityState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchSaveAbilityState_0100 start"; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->DispatchSaveAbilityState(); + EXPECT_FALSE(AbilityImpl_->needSaveDate_); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchSaveAbilityState_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DispatchSaveAbilityState_0200 + * @tc.name: DispatchSaveAbilityState + * @tc.desc: abilityLifecycleCallbacks_ is nullptr, Verify DispatchSaveAbilityState failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchSaveAbilityState_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchSaveAbilityState_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + AbilityImpl_->abilityLifecycleCallbacks_ = nullptr; + AbilityImpl_->DispatchSaveAbilityState(); + EXPECT_FALSE(AbilityImpl_->needSaveDate_); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchSaveAbilityState_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DispatchRestoreAbilityState_0100 + * @tc.name: DispatchRestoreAbilityState + * @tc.desc: ability is nullptr, Verify DispatchRestoreAbilityState failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DispatchRestoreAbilityState_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchRestoreAbilityState_0100 start"; + AbilityImpl_->ability_ = nullptr; + PacMap inState; + AbilityImpl_->DispatchRestoreAbilityState(inState); + EXPECT_FALSE(AbilityImpl_->hasSaveData_); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DispatchRestoreAbilityState_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_HandleAbilityTransaction_0100 + * @tc.name: HandleAbilityTransaction + * @tc.desc: Verify HandleAbilityTransaction succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_HandleAbilityTransaction_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_HandleAbilityTransaction_0100 start"; + Want want; + AAFwk::LifeCycleStateInfo targetState; + AbilityImpl_->HandleAbilityTransaction(want, targetState); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_HandleAbilityTransaction_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AbilityTransactionCallback_0100 + * @tc.name: AbilityTransactionCallback + * @tc.desc: Verify AbilityTransactionCallback succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AbilityTransactionCallback_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AbilityTransactionCallback_0100 start"; + AAFwk::AbilityLifeCycleState state = AAFwk::ABILITY_STATE_INITIAL; + AbilityImpl_->AbilityTransactionCallback(state); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AbilityTransactionCallback_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ConnectAbility_0100 + * @tc.name: ConnectAbility + * @tc.desc: ability is nullptr, Verify ConnectAbility failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ConnectAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ConnectAbility_0100 start"; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + Want want; + AbilityImpl_->ConnectAbility(want); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ConnectAbility_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DisconnectAbility_0100 + * @tc.name: DisconnectAbility + * @tc.desc: ability is nullptr, Verify DisconnectAbility failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DisconnectAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DisconnectAbility_0100 start"; + AbilityImpl_->ability_ = nullptr; + Want want; + AbilityImpl_->DisconnectAbility(want); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DisconnectAbility_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DisconnectAbility_0200 + * @tc.name: DisconnectAbility + * @tc.desc: Verify DisconnectAbility succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DisconnectAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DisconnectAbility_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + Want want; + AbilityImpl_->DisconnectAbility(want); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DisconnectAbility_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CommandAbility_0100 + * @tc.name: CommandAbility + * @tc.desc: ability is nullptr, Verify CommandAbility failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CommandAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CommandAbility_0100 start"; + AbilityImpl_->ability_ = nullptr; + AbilityImpl_->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + Want want; + bool restart = false; + int32_t startId = 0; + AbilityImpl_->CommandAbility(want, restart, startId); + EXPECT_EQ(AbilityImpl_->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CommandAbility_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SendResult_0100 + * @tc.name: SendResult + * @tc.desc: ability is nullptr, Verify SendResult failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SendResult_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SendResult_0100 start"; + AbilityImpl_->ability_ = nullptr; + int32_t requestCode = 0; + int32_t resultCode = 0; + Want resultData; + AbilityImpl_->SendResult(requestCode, resultCode, resultData); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SendResult_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NewWant_0100 + * @tc.name: NewWant + * @tc.desc: ability is nullptr, Verify NewWant failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NewWant_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NewWant_0100 start"; + AbilityImpl_->ability_ = nullptr; + Want want; + AbilityImpl_->NewWant(want); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NewWant_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_OpenRawFile_0100 + * @tc.name: OpenRawFile + * @tc.desc: Verify OpenRawFile succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_OpenRawFile_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_OpenRawFile_0100 start"; + Uri uri(""); + std::string mode = ""; + auto result = AbilityImpl_->OpenRawFile(uri, mode); + EXPECT_EQ(result, -1); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_OpenRawFile_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Call_0100 + * @tc.name: Call + * @tc.desc: Verify Call succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Call_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Call_0100 start"; + Uri uri(""); + std::string mode = ""; + std::string arg = ""; + AppExecFwk::PacMap pacMap; + auto obj = AbilityImpl_->Call(uri, mode, arg, pacMap); + EXPECT_TRUE(obj == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Call_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_GetType_0100 + * @tc.name: GetType + * @tc.desc: Verify GetType succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_GetType_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_GetType_0100 start"; + Uri uri(""); + auto type = AbilityImpl_->GetType(uri); + EXPECT_STREQ(type.c_str(), ""); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_GetType_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_Reload_0100 + * @tc.name: Reload + * @tc.desc: Verify Reload succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_Reload_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Reload_0100 start"; + Uri uri(""); + PacMap extras; + auto result = AbilityImpl_->Reload(uri, extras); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_Reload_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_BatchInsert_0100 + * @tc.name: BatchInsert + * @tc.desc: Verify BatchInsert succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_BatchInsert_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_BatchInsert_0100 start"; + Uri uri(""); + std::vector values; + auto result = AbilityImpl_->BatchInsert(uri, values); + EXPECT_EQ(result, -1); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_BatchInsert_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SerUriString_0100 + * @tc.name: SerUriString + * @tc.desc: Verify SerUriString succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SerUriString_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SerUriString_0100 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->contextDeal_ = contextDeal; + + std::string uri = "abc"; + AbilityImpl_->SerUriString(uri); + auto getUri = AbilityImpl_->contextDeal_->GetCaller(); + EXPECT_STREQ(getUri.ToString().c_str(), "abc"); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SerUriString_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SerUriString_0200 + * @tc.name: SerUriString + * @tc.desc: contextDeal_ is nullptr, Verify SerUriString failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SerUriString_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SerUriString_0200 start"; + AbilityImpl_->contextDeal_ = nullptr; + std::string uri = "abc"; + AbilityImpl_->SerUriString(uri); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SerUriString_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SetLifeCycleStateInfo_0100 + * @tc.name: SetLifeCycleStateInfo + * @tc.desc: Verify SetLifeCycleStateInfo succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SetLifeCycleStateInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetLifeCycleStateInfo_0100 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->contextDeal_ = contextDeal; + + AAFwk::LifeCycleStateInfo info; + info.isNewWant = true; + AbilityImpl_->SetLifeCycleStateInfo(info); + auto state = AbilityImpl_->contextDeal_->GetLifeCycleStateInfo(); + EXPECT_TRUE(state.isNewWant); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetLifeCycleStateInfo_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SetLifeCycleStateInfo_0200 + * @tc.name: SetLifeCycleStateInfo + * @tc.desc: Verify SetLifeCycleStateInfo succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SetLifeCycleStateInfo_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetLifeCycleStateInfo_0200 start"; + AbilityImpl_->contextDeal_ = nullptr; + AAFwk::LifeCycleStateInfo info; + info.isNewWant = true; + AbilityImpl_->SetLifeCycleStateInfo(info); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetLifeCycleStateInfo_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CheckAndRestore_0100 + * @tc.name: CheckAndRestore + * @tc.desc: hasSaveData_ is false, Verify CheckAndRestore failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndRestore_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndRestore_0100 start"; + AbilityImpl_->hasSaveData_ = false; + auto result = AbilityImpl_->CheckAndRestore(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndRestore_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CheckAndRestore_0200 + * @tc.name: CheckAndRestore + * @tc.desc: ability is nullptr, Verify CheckAndRestore failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndRestore_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndRestore_0200 start"; + AbilityImpl_->hasSaveData_ = true; + AbilityImpl_->ability_ = nullptr; + auto result = AbilityImpl_->CheckAndRestore(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndRestore_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CheckAndSave_0100 + * @tc.name: CheckAndSave + * @tc.desc: needSaveDate_ is false, Verify CheckAndSave failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndSave_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndSave_0100 start"; + AbilityImpl_->needSaveDate_ = false; + auto result = AbilityImpl_->CheckAndSave(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndSave_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CheckAndSave_0200 + * @tc.name: CheckAndSave + * @tc.desc: ability is nullptr, Verify CheckAndSave failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CheckAndSave_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndSave_0200 start"; + AbilityImpl_->needSaveDate_ = true; + AbilityImpl_->ability_ = nullptr; + auto result = AbilityImpl_->CheckAndSave(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CheckAndSave_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_GetRestoreData_0100 + * @tc.name: GetRestoreData + * @tc.desc: Verify GetRestoreData succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_GetRestoreData_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_GetRestoreData_0100 start"; + PacMap pacMap; + std::string key = "key"; + pacMap.PutIntValue(key, 1); + AbilityImpl_->restoreData_ = pacMap; + auto result = AbilityImpl_->GetRestoreData(); + auto value = result.GetIntValue(key, 0); + EXPECT_EQ(value, 1); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_GetRestoreData_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_SetCallingContext_0100 + * @tc.name: SetCallingContext + * @tc.desc: Verify GetRestoreData succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_SetCallingContext_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetCallingContext_0100 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + std::string deviceId = "deviceId"; + std::string bundleName = "bundleName"; + std::string abilityName = "abilityName"; + std::string moduleName = "moduleName"; + AbilityImpl_->SetCallingContext(deviceId, bundleName, abilityName, moduleName); + + auto element = AbilityImpl_->ability_->GetCallingAbility(); + EXPECT_STREQ(element->GetDeviceID().c_str(), deviceId.c_str()); + EXPECT_STREQ(element->GetBundleName().c_str(), bundleName.c_str()); + EXPECT_STREQ(element->GetAbilityName().c_str(), abilityName.c_str()); + EXPECT_STREQ(element->GetModuleName().c_str(), moduleName.c_str()); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_SetCallingContext_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NormalizeUri_0100 + * @tc.name: NormalizeUri + * @tc.desc: Verify NormalizeUri succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NormalizeUri_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NormalizeUri_0100 start"; + Uri uri("abc"); + auto result = AbilityImpl_->NormalizeUri(uri); + EXPECT_STREQ(result.ToString().c_str(), "abc"); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NormalizeUri_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_DenormalizeUri_0100 + * @tc.name: DenormalizeUri + * @tc.desc: Verify DenormalizeUri succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_DenormalizeUri_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DenormalizeUri_0100 start"; + Uri uri("abc"); + auto result = AbilityImpl_->DenormalizeUri(uri); + EXPECT_STREQ(result.ToString().c_str(), "abc"); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_DenormalizeUri_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ScheduleUpdateConfiguration_0100 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: ability is nullptr, Verify ScheduleUpdateConfiguration failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ScheduleUpdateConfiguration_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ScheduleUpdateConfiguration_0100 start"; + AbilityImpl_->ability_ = nullptr; + Configuration config; + AbilityImpl_->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ScheduleUpdateConfiguration_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_CreatePostEventTimeouter_0100 + * @tc.name: CreatePostEventTimeouter + * @tc.desc: ability is nullptr, Verify CreatePostEventTimeouter failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_CreatePostEventTimeouter_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CreatePostEventTimeouter_0100 start"; + AbilityImpl_->ability_ = nullptr; + std::string taskstr = ""; + auto timeout = AbilityImpl_->CreatePostEventTimeouter(taskstr); + EXPECT_TRUE(timeout == nullptr); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_CreatePostEventTimeouter_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ExecuteBatch_0100 + * @tc.name: ExecuteBatch + * @tc.desc: Verify ExecuteBatch succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ExecuteBatch_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ExecuteBatch_0100 start"; + AbilityImpl_->ability_ = nullptr; + std::string taskstr = ""; + std::vector> operations; + auto result = AbilityImpl_->ExecuteBatch(operations); + EXPECT_EQ(static_cast(result.size()), 0); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ExecuteBatch_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ContinueAbility_0100 + * @tc.name: ContinueAbility + * @tc.desc: ability is nullptr, Verify ContinueAbility failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ContinueAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ContinueAbility_0100 start"; + AbilityImpl_->ability_ = nullptr; + std::string deviceId = "deviceId"; + uint32_t versionCode = 0; + AbilityImpl_->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ContinueAbility_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ContinueAbility_0200 + * @tc.name: ContinueAbility + * @tc.desc: Verify ContinueAbility succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ContinueAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ContinueAbility_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + std::string deviceId = "deviceId"; + uint32_t versionCode = 0; + AbilityImpl_->ContinueAbility(deviceId, versionCode); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ContinueAbility_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NotifyContinuationResult_0100 + * @tc.name: NotifyContinuationResult + * @tc.desc: ability is nullptr, Verify NotifyContinuationResult failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NotifyContinuationResult_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyContinuationResult_0100 start"; + AbilityImpl_->ability_ = nullptr; + int32_t result = 0; + AbilityImpl_->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyContinuationResult_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NotifyContinuationResult_0200 + * @tc.name: NotifyContinuationResult + * @tc.desc: Verify NotifyContinuationResult succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NotifyContinuationResult_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyContinuationResult_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + int32_t result = 0; + AbilityImpl_->NotifyContinuationResult(result); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyContinuationResult_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NotifyMemoryLevel_0100 + * @tc.name: NotifyMemoryLevel + * @tc.desc: ability is nullptr, Verify NotifyMemoryLevel failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NotifyMemoryLevel_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyMemoryLevel_0100 start"; + AbilityImpl_->ability_ = nullptr; + int32_t level = 0; + AbilityImpl_->NotifyMemoryLevel(level); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyMemoryLevel_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_NotifyMemoryLevel_0200 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Verify NotifyMemoryLevel succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_NotifyMemoryLevel_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyMemoryLevel_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + + int32_t level = 0; + AbilityImpl_->NotifyContinuationResult(level); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_NotifyMemoryLevel_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterUnFocused_0100 + * @tc.name: AfterUnFocused + * @tc.desc: Verify AfterUnFocused succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterUnFocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnFocused_0100 start"; + AbilityImpl_->AfterUnFocused(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnFocused_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocused_0100 + * @tc.name: AfterFocused + * @tc.desc: Verify AfterFocused succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocused_0100 start"; + AbilityImpl_->AfterFocused(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocused_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0100 + * @tc.name: AfterFocusedCommon + * @tc.desc: ability is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0100 start"; + AbilityImpl_->AfterFocusedCommon(true); + AbilityImpl_->AfterFocusedCommon(false); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0200 + * @tc.name: AfterFocusedCommon + * @tc.desc: abilityInfo is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0200 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + AbilityImpl_->ability_ = ability; + AbilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0300 + * @tc.name: AfterFocusedCommon + * @tc.desc: contextDeal_ is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0300 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0400 + * @tc.name: AfterFocusedCommon + * @tc.desc: handler_ is nullptr, Verify AfterFocusedCommon failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0400 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + auto abilityInfo = std::make_shared(); + auto contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->contextDeal_ = contextDeal; + + AbilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0400 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0500 + * @tc.name: AfterFocusedCommon + * @tc.desc: Verify AfterFocusedCommon succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0500, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0500 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + auto abilityInfo = std::make_shared(); + abilityInfo->isStageBasedModel = true; + auto contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->contextDeal_ = contextDeal; + + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + AbilityImpl_->handler_ = handler; + + AbilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0500 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterFocusedCommon_0600 + * @tc.name: AfterFocusedCommon + * @tc.desc: Verify AfterFocusedCommon succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterFocusedCommon_0600, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0600 start"; + std::shared_ptr pMocKPageAbility = std::make_shared(); + std::shared_ptr ability = pMocKPageAbility; + auto abilityInfo = std::make_shared(); + abilityInfo->isStageBasedModel = false; + auto contextDeal = std::make_shared(); + contextDeal->SetAbilityInfo(abilityInfo); + ability->AttachBaseContext(contextDeal); + AbilityImpl_->ability_ = ability; + AbilityImpl_->contextDeal_ = contextDeal; + + auto eventRunner = EventRunner::Create(abilityInfo->name); + auto handler = std::make_shared(eventRunner); + AbilityImpl_->handler_ = handler; + + AbilityImpl_->AfterFocusedCommon(true); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterFocusedCommon_0600 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterForeground_0100 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterForeground_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0100 start"; + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = true; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterForeground(); + EXPECT_FALSE(abilityImpl->notifyForegroundByAbility_); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterForeground_0200 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterForeground_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0200 start"; + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterForeground(); + EXPECT_TRUE(abilityImpl->notifyForegroundByWindow_); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterForeground_0300 + * @tc.name: AfterForeground + * @tc.desc: Verify AfterForeground failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterForeground_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0300 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->AfterForeground(); + + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl1 = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->AfterForeground(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterForeground_0300 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterBackground_0100 + * @tc.name: AfterBackground + * @tc.desc: Verify AfterBackground failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterBackground_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterBackground_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->AfterBackground(); + + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl1 = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->AfterBackground(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterBackground_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterBackground_0200 + * @tc.name: AfterBackground + * @tc.desc: Verify AfterBackground succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterBackground_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterBackground_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + abilityImpl->notifyForegroundByAbility_ = false; + abilityImpl->notifyForegroundByWindow_ = false; + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterBackground(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterBackground_0200 end"; +} + +/** + * @tc.number: AaFwk_WindowLifeCycleImpl_0100 + * @tc.name: AfterFocused + * @tc.desc: Verify AfterFocused succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_WindowLifeCycleImpl_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterFocused(); + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0100 end"; +} + +/** + * @tc.number: AaFwk_WindowLifeCycleImpl_0200 + * @tc.name: AfterFocused + * @tc.desc: abilityImpl is nullptr, Verify AfterFocused failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_WindowLifeCycleImpl_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->AfterFocused(); + GTEST_LOG_(INFO) << "AaFwk_WindowLifeCycleImpl_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterUnfocused_0100 + * @tc.name: AfterUnfocused + * @tc.desc: abilityImpl is nullptr, Verify AfterUnfocused failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterUnfocused_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnfocused_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->AfterUnfocused(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnfocused_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_AfterUnfocused_0200 + * @tc.name: AfterUnfocused + * @tc.desc: Verify AfterUnfocused succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_AfterUnfocused_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnfocused_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->AfterUnfocused(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_AfterUnfocused_0200 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ForegroundFailed_0100 + * @tc.name: ForegroundFailed + * @tc.desc: Verify ForegroundFailed succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ForegroundFailed_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundFailed_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->ForegroundFailed(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundFailed_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ForegroundInvalidMode_0100 + * @tc.name: ForegroundInvalidMode + * @tc.desc: Verify ForegroundFailed failed. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ForegroundInvalidMode_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundInvalidMode_0100 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, nullptr); + impl->ForegroundInvalidMode(); + + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = false; + sptr impl1 = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl1->ForegroundInvalidMode(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundInvalidMode_0100 end"; +} + +/** + * @tc.number: AaFwk_AbilityImpl_ForegroundInvalidMode_0200 + * @tc.name: ForegroundInvalidMode + * @tc.desc: Verify ForegroundFailed succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_AbilityImpl_ForegroundInvalidMode_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundInvalidMode_0200 start"; + sptr token = sptr(new (std::nothrow) MockAbilityToken()); + auto abilityImpl = std::make_shared(); + abilityImpl->isStageBasedModel_ = true; + sptr impl = + new (std::nothrow) AbilityImpl::WindowLifeCycleImpl(token, abilityImpl); + impl->ForegroundInvalidMode(); + GTEST_LOG_(INFO) << "AaFwk_AbilityImpl_ForegroundInvalidMode_0200 end"; +} + +/** + * @tc.number: AaFwk_InputEventConsumerImpl_0100 + * @tc.name: OnInputEvent + * @tc.desc: Verify OnInputEvent succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_InputEventConsumerImpl_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_InputEventConsumerImpl_0100 start"; + auto abilityImpl = std::make_shared(); + auto impl = std::make_shared(abilityImpl); + auto keyEvent = MMI::KeyEvent::Create(); + impl->OnInputEvent(keyEvent); + GTEST_LOG_(INFO) << "AaFwk_InputEventConsumerImpl_0100 end"; +} + +/** + * @tc.number: AaFwk_InputEventConsumerImpl_0200 + * @tc.name: OnInputEvent + * @tc.desc: Verify OnInputEvent succeeded. + */ +HWTEST_F(AbilityImplTest, AaFwk_InputEventConsumerImpl_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_InputEventConsumerImpl_0200 start"; + auto abilityImpl = std::make_shared(); + auto impl = std::make_shared(abilityImpl); + std::shared_ptr pointerEvent; + impl->OnInputEvent(pointerEvent); + GTEST_LOG_(INFO) << "AaFwk_InputEventConsumerImpl_0200 end"; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/continuation_test.cpp b/test/unittest/frameworks_kits_ability_native_test/continuation_test.cpp index 5884bc9283..6d8b708514 100644 --- a/test/unittest/frameworks_kits_ability_native_test/continuation_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/continuation_test.cpp @@ -26,7 +26,7 @@ #include "continuation_manager.h" #include "continuation_handler.h" #include "data_ability_predicates.h" -#include "mock_ability_impl.h" +#include "mock_ability_connect_callback.h" #include "mock_ability_lifecycle_callbacks.h" #include "mock_ability_token.h" #include "mock_continuation_ability.h" @@ -70,6 +70,25 @@ public: void TearDown(); }; +class MockReverseContinuationSchedulerPrimaryProxy : public IRemoteProxy { +public: + explicit MockReverseContinuationSchedulerPrimaryProxy(const sptr &remoteObject) : + IRemoteProxy(remoteObject) {} + virtual ~MockReverseContinuationSchedulerPrimaryProxy() = default; + MOCK_METHOD0(NotifyReplicaTerminated, void()); + MOCK_METHOD1(ContinuationBack, bool(const AAFwk::Want &want)); +}; + +class MockReverseContinuationSchedulerReplicaProxy : public IRemoteProxy { +public: + explicit MockReverseContinuationSchedulerReplicaProxy(const sptr &remoteObject) : + IRemoteProxy(remoteObject) {} + virtual ~MockReverseContinuationSchedulerReplicaProxy() = default; + MOCK_METHOD1(PassPrimary, void(const sptr &primary)); + MOCK_METHOD0(ReverseContinuation, bool()); + MOCK_METHOD1(NotifyReverseResult, void(int reverseResult)); +}; + void ContinuationTest::SetUpTestCase(void) {} @@ -373,6 +392,47 @@ HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuation_006, TestSiz GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuation_006 end"; } +/* + * @tc.number: continue_handler_HandleReceiveRemoteScheduler_001 + * @tc.name: HandleReceiveRemoteScheduler + * @tc.desc: call HandleReceiveRemoteScheduler with remoteReplica is null + */ +HWTEST_F(ContinuationTest, continue_handler_HandleReceiveRemoteScheduler_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_001 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->SetPrimaryStub(primary); + continuationHandler->HandleReceiveRemoteScheduler(nullptr); + EXPECT_TRUE(continuationHandler->remotePrimaryProxy_ == nullptr); + GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_001 end"; +} + +/* + * @tc.number: continue_handler_HandleReceiveRemoteScheduler_002 + * @tc.name: HandleReceiveRemoteScheduler + * @tc.desc: call HandleReceiveRemoteScheduler using remoteReplicaProxy_ and DeathRecipient_ in different situations. + */ +HWTEST_F(ContinuationTest, continue_handler_HandleReceiveRemoteScheduler_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_002 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr remoteReplica = + new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + EXPECT_CALL(*remoteReplica, PassPrimary(_)).Times(3); + continuationHandler->HandleReceiveRemoteScheduler(remoteReplica); + continuationHandler->HandleReceiveRemoteScheduler(remoteReplica); + continuationHandler->schedulerDeathRecipient_ = nullptr; + continuationHandler->HandleReceiveRemoteScheduler(remoteReplica); + GTEST_LOG_(INFO) << "continue_handler_HandleReceiveRemoteScheduler_002 end"; +} + /* * @tc.number: continue_handler_HandleCompleteContinuation_001 * @tc.name: HandleStartContinuation @@ -411,6 +471,172 @@ HWTEST_F(ContinuationTest, continue_handler_HandleCompleteContinuation_002, Test GTEST_LOG_(INFO) << "continue_handler_HandleCompleteContinuation_002 end"; } +/* + * @tc.number: continue_handler_PassPrimary_001 + * @tc.name: PassPrimary + * @tc.desc: call PassPrimary success + */ +HWTEST_F(ContinuationTest, continue_handler_PassPrimary_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_PassPrimary_001 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->PassPrimary(primary); + EXPECT_TRUE(continuationHandler->remotePrimaryProxy_ != nullptr); + GTEST_LOG_(INFO) << "continue_handler_PassPrimary_001 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_001 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with remotePrimaryProxy is null + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_001 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_002 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with abilityInfo_ is null + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_002 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->PassPrimary(primary); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_002 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_003 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with continuationManagerTmp is null + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_003 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + continuationManager.reset(); + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->PassPrimary(primary); + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_003 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_004 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with OnStartContinuation failed + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_004 start"; + EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(false)); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->PassPrimary(primary); + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_004 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_005 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with OnSaveData failed + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_005 start"; + EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(false)); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + sptr primary = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->PassPrimary(primary); + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_005 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_006 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with ContinuationBack failed + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_006, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_006 start"; + EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(true)); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject); + EXPECT_CALL(*primary, ContinuationBack(_)).Times(1).WillOnce(Return(true)); + continuationHandler->remotePrimaryProxy_ = primary; + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_006 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinuation_007 + * @tc.name: ReverseContinuation + * @tc.desc: call ReverseContinuation with success + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinuation_007, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_007 start"; + EXPECT_CALL(*mockAbility_, OnStartContinuation()).Times(1).WillOnce(Return(true)); + EXPECT_CALL(*mockAbility_, OnSaveData(_)).Times(1).WillOnce(Return(true)); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject); + EXPECT_CALL(*primary, ContinuationBack(_)).Times(1).WillOnce(Return(false)); + continuationHandler->remotePrimaryProxy_ = primary; + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationHandler->ReverseContinuation(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinuation_007 end"; +} + /* * @tc.number: continue_handler_NotifyReverseResult_001 * @tc.name: NotifyReverseResult @@ -463,6 +689,67 @@ HWTEST_F(ContinuationTest, continue_handler_NotifyReverseResult_003, TestSize.Le GTEST_LOG_(INFO) << "continue_handler_NotifyReverseResult_003 end"; } +/* + * @tc.number: continue_handler_ContinuationBack_001 + * @tc.name: ContinuationBack + * @tc.desc: call ContinuationBack with continuationManager is null + */ +HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + continuationManager.reset(); + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + Want want; + bool result = continuationHandler->ContinuationBack(want); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_001 end"; +} + +/* + * @tc.number: continue_handler_ContinuationBack_002 + * @tc.name: ContinuationBack + * @tc.desc: call ContinuationBack with RestoreFromRemote failed + */ +HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_002 start"; + EXPECT_CALL(*mockAbility_, OnRestoreData(_)).Times(1).WillOnce(Return(false)); + EXPECT_CALL(*mockAbility_, TerminateAbility()).Times(0); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + Want want; + sptr remoteReplica = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->remoteReplicaProxy_ = iface_cast(remoteReplica); + bool result = continuationHandler->ContinuationBack(want); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_002 end"; +} + +/* + * @tc.number: continue_handler_ContinuationBack_003 + * @tc.name: ContinuationBack + * @tc.desc: call ContinuationBack with RestoreFromRemote success + */ +HWTEST_F(ContinuationTest, continue_handler_ContinuationBack_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_003 start"; + EXPECT_CALL(*mockAbility_, OnRestoreData(_)).Times(1).WillOnce(Return(true)); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + Want want; + sptr remoteReplica = new (std::nothrow) MockReverseContinuationSchedulerReplicaStub(); + continuationHandler->remoteReplicaProxy_ = iface_cast(remoteReplica); + bool result = continuationHandler->ContinuationBack(want); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_handler_ContinuationBack_003 end"; +} + /* * @tc.number: continue_handler_NotifyReplicaTerminated_001 * @tc.name: NotifyReplicaTerminated @@ -481,6 +768,45 @@ HWTEST_F(ContinuationTest, continue_handler_NotifyReplicaTerminated_001, TestSiz GTEST_LOG_(INFO) << "continue_handler_NotifyReplicaTerminated_001 end"; } +/* + * @tc.number: continue_handler_NotifyTerminationToPrimary_001 + * @tc.name: NotifyTerminationToPrimary + * @tc.desc: call NotifyTerminationToPrimary with null remotePrimaryProxy_ + */ +HWTEST_F(ContinuationTest, continue_handler_NotifyTerminationToPrimary_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject); + EXPECT_CALL(*primary, NotifyReplicaTerminated()).Times(0); + continuationHandler->NotifyTerminationToPrimary(); + GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_001 end"; +} + +/* + * @tc.number: continue_handler_NotifyTerminationToPrimary_002 + * @tc.name: NotifyTerminationToPrimary + * @tc.desc: call NotifyTerminationToPrimary success + */ +HWTEST_F(ContinuationTest, continue_handler_NotifyTerminationToPrimary_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_002 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerPrimaryProxy(remoteObject); + EXPECT_CALL(*primary, NotifyReplicaTerminated()).Times(1); + continuationHandler->remotePrimaryProxy_ = primary; + continuationHandler->NotifyTerminationToPrimary(); + GTEST_LOG_(INFO) << "continue_handler_NotifyTerminationToPrimary_002 end"; +} + /* * @tc.number: continue_handler_SetReversible_001 * @tc.name: SetReversible @@ -533,6 +859,141 @@ HWTEST_F(ContinuationTest, continue_handler_SetPrimaryStub_001, TestSize.Level1) GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 end"; } +/* + * @tc.number: continue_handler_ReverseContinueAbility_001 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with null remoteReplicaProxy_ + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinueAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + auto result = continuationHandler->ReverseContinueAbility(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinueAbility_001 end"; +} + +/* + * @tc.number: continue_handler_ReverseContinueAbility_002 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility success + */ +HWTEST_F(ContinuationTest, continue_handler_ReverseContinueAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_SetPrimaryStub_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject); + EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(true)); + continuationHandler->remoteReplicaProxy_ = primary; + auto result = continuationHandler->ReverseContinueAbility(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_handler_ReverseContinueAbility_002 end"; +} + +/* + * @tc.number: continue_handler_HandleStartContinuationWithStack_001 + * @tc.name: HandleStartContinuationWithStack + * @tc.desc: call HandleStartContinuationWithStack with nullptr token + */ +HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + uint32_t versionCode = 0; + auto result = continuationHandler->HandleStartContinuationWithStack(nullptr, "deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_001 end"; +} + +/* + * @tc.number: continue_handler_HandleStartContinuationWithStack_002 + * @tc.name: HandleStartContinuationWithStack + * @tc.desc: call HandleStartContinuationWithStack with no abilityInfo_ + */ +HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_002 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + uint32_t versionCode = 0; + auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_002 end"; +} + +/* + * @tc.number: continue_handler_HandleStartContinuationWithStack_003 + * @tc.name: HandleStartContinuationWithStack + * @tc.desc: call HandleStartContinuationWithStack with null continuationManager + */ +HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_003 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + continuationManager.reset(); + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + uint32_t versionCode = 0; + continuationHandler->SetAbilityInfo(abilityInfo_); + auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_003 end"; +} + +/* + * @tc.number: continue_handler_HandleStartContinuationWithStack_004 + * @tc.name: HandleStartContinuationWithStack + * @tc.desc: call HandleStartContinuationWithStack with OnContinue failed + */ +HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_004 start"; + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(ability_, continueToken, abilityInfo_, continuationHandler); + uint32_t versionCode = 0; + continuationHandler->SetAbilityInfo(abilityInfo_); + auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_004 end"; +} + +/* + * @tc.number: continue_handler_HandleStartContinuationWithStack_005 + * @tc.name: HandleStartContinuationWithStack + * @tc.desc: call HandleStartContinuationWithStack success + */ +HWTEST_F(ContinuationTest, continue_handler_HandleStartContinuationWithStack_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_005 start"; + EXPECT_CALL(*mockAbility_, OnContinue(_)).Times(1).WillOnce(Return(ContinuationManager::OnContinueResult::AGREE)); + EXPECT_CALL(*mockAbility_, GetContentInfo()).Times(1).WillOnce(Return("ContentInfo")); + sptr continueToken = sptr(new (std::nothrow) MockAbilityToken()); + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + uint32_t versionCode = 0; + ability_->abilityInfo_->isStageBasedModel = true; + continuationHandler->SetAbilityInfo(abilityInfo_); + auto result = continuationHandler->HandleStartContinuationWithStack(continueToken, "deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_handler_HandleStartContinuationWithStack_005 end"; +} + /* * @tc.number: continue_manager_GetContinuationState_001 * @tc.name: GetContinuationState @@ -569,6 +1030,294 @@ HWTEST_F(ContinuationTest, continue_manager_GetOriginalDeviceId_001, TestSize.Le GTEST_LOG_(INFO) << "continue_manager_GetOriginalDeviceId_001 end"; } +/* + * @tc.number: continue_manager_ContinueAbilityWithStack_001 + * @tc.name: ContinueAbilityWithStack + * @tc.desc: call ContinueAbilityWithStack + */ +HWTEST_F(ContinuationTest, continue_manager_ContinueAbilityWithStack_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ContinueAbilityWithStack_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + uint32_t versionCode = 0; + mockAbility_->abilityInfo_->isStageBasedModel = true; + continuationHandler->SetAbilityInfo(abilityInfo_); + continuationManager_->ContinueAbilityWithStack("deviceId", versionCode); + EXPECT_TRUE(continuationManager_->mainHandler_ != nullptr); + GTEST_LOG_(INFO) << "continue_manager_ContinueAbilityWithStack_001 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbilityWithStack_001 + * @tc.name: HandleContinueAbilityWithStack + * @tc.desc: call HandleContinueAbilityWithStack with checkAbilityToken failed + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, nullptr, abilityInfo_, continuationHandler); + uint32_t versionCode = 0; + bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_001 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbilityWithStack_002 + * @tc.name: HandleContinueAbilityWithStack + * @tc.desc: call HandleContinueAbilityWithStack with null continuationHandler + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_002 start"; + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, nullptr); + uint32_t versionCode = 0; + bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_002 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbilityWithStack_003 + * @tc.name: HandleContinueAbilityWithStack + * @tc.desc: call HandleContinueAbilityWithStack success + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbilityWithStack_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_003 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + uint32_t versionCode = 0; + mockAbility_->abilityInfo_->isStageBasedModel = true; + continuationHandler->SetAbilityInfo(abilityInfo_); + bool result = continuationManager_->HandleContinueAbilityWithStack("deviceId", versionCode); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbilityWithStack_003 end"; +} + +/* + * @tc.number: continue_manager_ContinueAbility_001 + * @tc.name: ContinueAbility + * @tc.desc: call ContinueAbility with CheckContinuation Illegal + */ +HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState( + AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED); + bool reversible = false; + continuationManager_->ContinueAbility(reversible, "deviceId"); + EXPECT_TRUE(continuationManager_->CheckContinuationIllegal()); + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_001 end"; +} + +/* + * @tc.number: continue_manager_ContinueAbility_002 + * @tc.name: ContinueAbility + * @tc.desc: call ContinueAbility with progressState_ is IN_PROGRESS + */ +HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_002 start"; + bool reversible = false; + continuationManager_->progressState_ = ContinuationManager::ProgressState::IN_PROGRESS; + continuationManager_->ContinueAbility(reversible, "deviceId"); + EXPECT_NE(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_); + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_002 end"; +} + +/* + * @tc.number: continue_manager_ContinueAbility_003 + * @tc.name: ContinueAbility + * @tc.desc: call ContinueAbility with continuationState_ is REMOTE_RUNNING + */ +HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_003 start"; + bool reversible = false; + continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING; + continuationManager_->ContinueAbility(reversible, "deviceId"); + EXPECT_NE(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_); + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_003 end"; +} + +/* + * @tc.number: continue_manager_ContinueAbility_004 + * @tc.name: ContinueAbility + * @tc.desc: call ContinueAbility with HandleContinueAbility return true + */ +HWTEST_F(ContinuationTest, continue_manager_ContinueAbility_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_004 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + bool reversible = false; + continuationManager_->ContinueAbility(reversible, "deviceId"); + EXPECT_EQ(ContinuationManager::ProgressState::WAITING_SCHEDULE, continuationManager_->progressState_); + GTEST_LOG_(INFO) << "continue_manager_ContinueAbility_004 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbility_001 + * @tc.name: HandleContinueAbility + * @tc.desc: call HandleContinueAbility with CheckAbilityToken failed + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_001 start"; + bool reversible = false; + bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId"); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_001 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbility_002 + * @tc.name: HandleContinueAbility + * @tc.desc: call HandleContinueAbility with continuationHandler null + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_002 start"; + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, nullptr); + bool reversible = false; + bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId"); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_002 end"; +} + +/* + * @tc.number: continue_manager_HandleContinueAbility_003 + * @tc.name: HandleContinueAbility + * @tc.desc: call HandleContinueAbility success + */ +HWTEST_F(ContinuationTest, continue_manager_HandleContinueAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_003 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + bool reversible = false; + bool result = continuationManager_->HandleContinueAbility(reversible, "deviceId"); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_manager_HandleContinueAbility_003 end"; +} + +/* + * @tc.number: continue_manager_ReverseContinueAbility_001 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with wrong ProgressState_ + */ +HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler); + continuationManager_->progressState_ = ContinuationManager::ProgressState::WAITING_SCHEDULE; + continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING; + bool result = continuationManager_->ReverseContinueAbility(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_001 end"; +} + +/* + * @tc.number: continue_manager_ReverseContinueAbility_002 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with wrong continuationState_ + */ +HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_002 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = ability_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(ability_, continueToken_, abilityInfo_, continuationHandler); + continuationManager_->progressState_ = ContinuationManager::ProgressState::INITIAL; + continuationManager_->continuationState_ = ContinuationState::LOCAL_RUNNING; + bool result = continuationManager_->ReverseContinueAbility(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_002 end"; +} + +/* + * @tc.number: continue_manager_ReverseContinueAbility_003 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with null continuationHandler_ + */ +HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_003 start"; + continuationManager_->Init(ability_, continueToken_, abilityInfo_, nullptr); + continuationManager_->progressState_ = ContinuationManager::ProgressState::INITIAL; + continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING; + bool result = continuationManager_->ReverseContinueAbility(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_003 end"; +} + +/* + * @tc.number: continue_manager_ReverseContinueAbility_004 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with requestSuccess is true + */ +HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_004 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING; + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject); + EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(true)); + continuationHandler->remoteReplicaProxy_ = primary; + bool result = continuationManager_->ReverseContinueAbility(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_004 end"; +} + +/* + * @tc.number: continue_manager_ReverseContinueAbility_005 + * @tc.name: ReverseContinueAbility + * @tc.desc: call ReverseContinueAbility with requestSuccess is false + */ +HWTEST_F(ContinuationTest, continue_manager_ReverseContinueAbility_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_005 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + continuationManager_->continuationState_ = ContinuationState::REMOTE_RUNNING; + sptr remoteObject = new (std::nothrow) AAFwk::AbilityConnectCallback(); + sptr primary = + new (std::nothrow) MockReverseContinuationSchedulerReplicaProxy(remoteObject); + EXPECT_CALL(*primary, ReverseContinuation()).Times(1).WillOnce(Return(false)); + continuationHandler->remoteReplicaProxy_ = primary; + bool result = continuationManager_->ReverseContinueAbility(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_ReverseContinueAbility_005 end"; +} + /* * @tc.number: continue_manager_OnContinue_001 * @tc.name: OnContinue @@ -1088,5 +1837,83 @@ HWTEST_F(ContinuationTest, continue_manager_ChangeProcessStateToInit_002, TestSi EXPECT_EQ(ContinuationManager::ProgressState::INITIAL, continuationManager_->progressState_); GTEST_LOG_(INFO) << "continue_manager_ChangeProcessStateToInit_002 end"; } + +/* + * @tc.name: continue_manager_DoScheduleStartContinuation_001 + * @tc.name: DoScheduleStartContinuation + * @tc.desc: call DoScheduleStartContinuation with CheckContinuationIllegal failed + */ +HWTEST_F(ContinuationTest, continue_manager_DoScheduleStartContinuation_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_DoScheduleStartContinuation_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState( + AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED); + bool result = continuationManager_->DoScheduleStartContinuation(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_DoScheduleStartContinuation_001 end"; +} + +/* + * @tc.name: continue_manager_DoScheduleSaveData_001 + * @tc.name: DoScheduleSaveData + * @tc.desc: call DoScheduleSaveData with CheckContinuationIllegal failed + */ +HWTEST_F(ContinuationTest, continue_manager_DoScheduleSaveData_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState( + AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED); + WantParams saveData; + bool result = continuationManager_->DoScheduleSaveData(saveData); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 end"; +} + +/* + * @tc.name: continue_manager_DoScheduleRestoreData_001 + * @tc.name: DoScheduleRestoreData + * @tc.desc: call DoScheduleRestoreData with CheckContinuationIllegal failed + */ +HWTEST_F(ContinuationTest, continue_manager_DoScheduleRestoreData_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_001 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + mockAbility_->abilityLifecycleExecutor_->DispatchLifecycleState( + AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED); + WantParams restoreData; + bool result = continuationManager_->DoScheduleRestoreData(restoreData); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_DoScheduleSaveData_001 end"; +} + +/* + * @tc.name: continue_manager_DoScheduleRestoreData_002 + * @tc.name: DoScheduleRestoreData + * @tc.desc: call DoScheduleRestoreData with ability is null + */ +HWTEST_F(ContinuationTest, continue_manager_DoScheduleRestoreData_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_002 start"; + std::weak_ptr continuationManager = continuationManager_; + std::weak_ptr abilityTmp = mockAbility_; + auto continuationHandler = std::make_shared(continuationManager, abilityTmp); + continuationManager_->Init(mockAbility_, continueToken_, abilityInfo_, continuationHandler); + continuationManager_->ability_.reset(); + WantParams restoreData; + bool result = continuationManager_->DoScheduleRestoreData(restoreData); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "continue_manager_DoScheduleRestoreData_002 end"; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp index fb3176614e..651bf3a6a9 100644 --- a/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp +++ b/test/unittest/frameworks_kits_ability_native_test/data_ability_helper_test.cpp @@ -15,16 +15,24 @@ #include "gtest/gtest.h" +#define private public +#define protected public #include "mock_ability_manager_client_for_data_ability_observer.h" #include "mock_ability_scheduler_for_observer.h" #include "mock_ability_manager_client.h" #include "context.h" +#include "ability_connect_manager.h" #include "ability_context.h" #include "data_ability_helper.h" #include "abs_shared_result_set.h" #include "data_ability_predicates.h" #include "values_bucket.h" +#include "data_ability_observer_interface.h" +#include "datashare_helper.h" +#include "mock_ability_runtime_context.h" +#undef private +#undef protected namespace OHOS { namespace AppExecFwk { @@ -76,7 +84,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetFileTypes_ std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); std::string mimeTypeFilter("mimeTypeFiltertest"); // Test to AbilityThread interface - auto returnGetFileTypes = [&](const Uri& uri, const std::string& mimeTypeFilter) { + auto returnGetFileTypes = [&](const Uri &uri, const std::string &mimeTypeFilter) { std::vector matchedMIMEs; matchedMIMEs.push_back("test1"); matchedMIMEs.push_back("test2"); @@ -109,7 +117,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetFileTypes_ std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); std::string mimeTypeFilter("mimeTypeFiltertest"); // Test to AbilityThread interface - auto returnGetFileTypes = [&](const Uri& uri, const std::string& mimeTypeFilter) { + auto returnGetFileTypes = [&](const Uri &uri, const std::string &mimeTypeFilter) { std::vector matchedMIMEs; matchedMIMEs.push_back("test1"); matchedMIMEs.push_back("test2"); @@ -125,6 +133,64 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetFileTypes_ GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetFileTypes_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_GetFileTypes_0300 + * @tc.name: GetFileTypes + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetFileTypes_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetFileTypes_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string mimeTypeFilter("mimeTypeFiltertest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnGetFileTypes = [&](const Uri &uri, const std::string &mimeTypeFilter) { + std::vector matchedMIMEs; + matchedMIMEs.push_back("test1"); + matchedMIMEs.push_back("test2"); + matchedMIMEs.push_back("test3"); + return matchedMIMEs; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), GetFileTypes(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnGetFileTypes)); + + dataAbilityHelper->GetFileTypes(*uri, mimeTypeFilter); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetFileTypes_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_GetFileTypes_0400 + * @tc.name: GetFileTypes + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetFileTypes_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetFileTypes_0400 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string mimeTypeFilter("mimeTypeFiltertest"); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + auto ret = dataAbilityHelper->GetFileTypes(*uri, mimeTypeFilter); + EXPECT_TRUE(ret.empty()); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetFileTypes_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_OpenFile_0100 * @tc.name: OpenFile @@ -142,7 +208,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0100 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); std::string mode("modetest"); // Test to AbilityThread interface - auto returnOpenFile = [&](const Uri& uri, const std::string& mode) { + auto returnOpenFile = [&](const Uri &uri, const std::string &mode) { int fd = 1234; return fd; }; @@ -172,7 +238,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0200 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); std::string mode("modetest"); // Test to AbilityThread interface - auto returnOpenFile = [&](const Uri& uri, const std::string& mode) { + auto returnOpenFile = [&](const Uri &uri, const std::string &mode) { int fd = 1234; return fd; }; @@ -185,6 +251,96 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0200 GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_OpenFile_0300 + * @tc.name: OpenFile + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string mode("modetest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + dataAbilityHelper->callFromJs_ = true; + // Test to AbilityThread interface + auto returnOpenFile = [&](const Uri &uri, const std::string &mode) { + int fd = 1234; + return fd; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), OpenFile(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnOpenFile)); + + dataAbilityHelper->OpenFile(*uri, mode); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_OpenFile_0400 + * @tc.name: OpenFile + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0400 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string mode("modetest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + dataAbilityHelper->callFromJs_ = false; + // Test to AbilityThread interface + auto returnOpenFile = [&](const Uri &uri, const std::string &mode) { + int fd = 1234; + return fd; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), OpenFile(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnOpenFile)); + + dataAbilityHelper->OpenFile(*uri, mode); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_OpenFile_0500 + * @tc.name: OpenFile + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenFile_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0500 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string mode("modetest"); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + + EXPECT_EQ(dataAbilityHelper->OpenFile(*uri, mode), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenFile_0500 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_Insert_0100 * @tc.name: Insert @@ -203,7 +359,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Insert_0100, NativeRdb::ValuesBucket val; val.PutInt("valtest", 20); // Test to AbilityThread interface - auto returnInsert = [&](const Uri& uri, const NativeRdb::ValuesBucket& val) { + auto returnInsert = [&](const Uri &uri, const NativeRdb::ValuesBucket &val) { int index = 1234; return index; }; @@ -234,7 +390,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Insert_0200, NativeRdb::ValuesBucket val; val.PutInt("valtest", 20); // Test to AbilityThread interface - auto returnInsert = [&](const Uri& uri, const NativeRdb::ValuesBucket& val) { + auto returnInsert = [&](const Uri &uri, const NativeRdb::ValuesBucket &val) { int index = 1234; return index; }; @@ -247,6 +403,64 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Insert_0200, GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Insert_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_Insert_0300 + * @tc.name: Insert + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Insert_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Insert_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + NativeRdb::ValuesBucket val; + val.PutInt("valtest", 20); + // Test to AbilityThread interface + auto returnInsert = [&](const Uri &uri, const NativeRdb::ValuesBucket &val) { + int index = 1234; + return index; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Insert(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnInsert)); + + dataAbilityHelper->Insert(*uri, val); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Insert_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Insert_0400 + * @tc.name: Insert + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Insert_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Insert_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + NativeRdb::ValuesBucket val; + val.PutInt("valtest", 20); + + EXPECT_EQ(dataAbilityHelper->Insert(*uri, val), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Insert_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_Update_0100 * @tc.name: Update @@ -267,7 +481,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Update_0100, NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface auto returnUpdate = [&]( - const Uri& uri, const NativeRdb::ValuesBucket& val, const NativeRdb::DataAbilityPredicates& predicates) { + const Uri &uri, const NativeRdb::ValuesBucket &val, const NativeRdb::DataAbilityPredicates &predicates) { int index = 1234; return index; }; @@ -300,7 +514,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Update_0200, NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface auto returnUpdate = [&]( - const Uri& uri, const NativeRdb::ValuesBucket& val, const NativeRdb::DataAbilityPredicates& predicates) { + const Uri &uri, const NativeRdb::ValuesBucket &val, const NativeRdb::DataAbilityPredicates &predicates) { int index = 1234; return index; }; @@ -313,6 +527,66 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Update_0200, GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Update_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_Update_0300 + * @tc.name: Update + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Update_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Update_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + NativeRdb::ValuesBucket val; + val.PutInt("valtest", 20); + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnUpdate = [&]( + const Uri &uri, const NativeRdb::ValuesBucket &val, const NativeRdb::DataAbilityPredicates &predicates) { + int index = 1234; + return index; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Update(testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnUpdate)); + + dataAbilityHelper->Update(*uri, val, predicates); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Update_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Update_0400 + * @tc.name: Update + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Update_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Update_0400 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + NativeRdb::ValuesBucket val; + val.PutInt("valtest", 20); + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + + EXPECT_EQ(dataAbilityHelper->Update(*uri, val, predicates), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Update_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_Delete_0100 * @tc.name: Delete @@ -330,7 +604,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Delete_0100, std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface - auto returnDelete = [&](const Uri& uri, const NativeRdb::DataAbilityPredicates& predicates) { + auto returnDelete = [&](const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) { int index = 1234; return index; }; @@ -360,7 +634,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Delete_0200, std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface - auto returnDelete = [&](const Uri& uri, const NativeRdb::DataAbilityPredicates& predicates) { + auto returnDelete = [&](const Uri &uri, const NativeRdb::DataAbilityPredicates &predicates) { int index = 1234; return index; }; @@ -373,6 +647,53 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Delete_0200, GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Delete_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_Delete_0300 + * @tc.name: Delete + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Delete_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Delete_0300 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + + EXPECT_EQ(dataAbilityHelper->Delete(*uri, predicates), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Delete_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Delete_0400 + * @tc.name: Delete + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Delete_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Delete_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + + EXPECT_EQ(dataAbilityHelper->Delete(*uri, predicates), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Delete_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_Query_0100 * @tc.name: Query @@ -392,10 +713,9 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0100, F NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface auto returnQuery = - [&](const Uri& uri, const std::vector& columns, - const NativeRdb::DataAbilityPredicates& predicates) { - std::shared_ptr set = std::make_shared( - "resultset"); + [&](const Uri &uri, const std::vector &columns, + const NativeRdb::DataAbilityPredicates &predicates) { + std::shared_ptr set = nullptr; return set; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Query(testing::_, testing::_, testing::_)) @@ -426,10 +746,9 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0200, F NativeRdb::DataAbilityPredicates predicates("predicatestest"); // Test to AbilityThread interface auto returnQuery = - [&](const Uri& uri, const std::vector& columns, - const NativeRdb::DataAbilityPredicates& predicates) { - std::shared_ptr set = std::make_shared( - "resultset"); + [&](const Uri &uri, const std::vector &columns, + const NativeRdb::DataAbilityPredicates &predicates) { + std::shared_ptr set = nullptr; return set; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Query(testing::_, testing::_, testing::_)) @@ -441,6 +760,102 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0200, F GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_Query_0300 + * @tc.name: Query + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::vector columns; + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnQuery = + [&](const Uri &uri, const std::vector &columns, + const NativeRdb::DataAbilityPredicates &predicates) { + std::shared_ptr set = nullptr; + return set; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Query(testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnQuery)); + + dataAbilityHelper->Query(*uri, columns, predicates); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Query_0400 + * @tc.name: Query + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0400 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::vector columns; + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnQuery = + [&](const Uri &uri, const std::vector &columns, + const NativeRdb::DataAbilityPredicates &predicates) { + std::shared_ptr set = nullptr; + return set; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Query(testing::_, testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnQuery)); + + dataAbilityHelper->Query(*uri, columns, predicates); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Query_0500 + * @tc.name: Query + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Query_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0500 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::vector columns; + NativeRdb::DataAbilityPredicates predicates("predicatestest"); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + + EXPECT_TRUE(dataAbilityHelper->Query(*uri, columns, predicates) == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Query_0500 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_GetType_0100 * @tc.name: GetType @@ -457,7 +872,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetType_0100, std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface - auto returnGetType = [&](const Uri& uri) { + auto returnGetType = [&](const Uri &uri) { std::string type("Type1"); return type; }; @@ -486,7 +901,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetType_0200, std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface - auto returnGetType = [&](const Uri& uri) { + auto returnGetType = [&](const Uri &uri) { std::string type("Type1"); return type; }; @@ -499,6 +914,60 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetType_0200, GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetType_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_GetType_0300 + * @tc.name: GetType + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetType_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetType_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnGetType = [&](const Uri &uri) { + std::string type("Type1"); + return type; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), GetType(testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnGetType)); + + dataAbilityHelper->GetType(*uri); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetType_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_GetType_0400 + * @tc.name: GetType + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_GetType_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetType_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + + EXPECT_TRUE(dataAbilityHelper->GetType(*uri).empty()); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_GetType_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_OpenRawFile_0100 * @tc.name: OpenRawFile @@ -516,7 +985,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenRawFile_0 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface std::string mode("modetest"); - auto returnOpenRawFile = [&](const Uri& uri, const std::string& mode) { + auto returnOpenRawFile = [&](const Uri &uri, const std::string &mode) { int fd = 1234; return fd; }; @@ -546,7 +1015,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenRawFile_0 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface std::string mode("modetest"); - auto returnOpenRawFile = [&](const Uri& uri, const std::string& mode) { + auto returnOpenRawFile = [&](const Uri &uri, const std::string &mode) { int fd = 1234; return fd; }; @@ -559,6 +1028,61 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenRawFile_0 GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenRawFile_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_OpenRawFile_0300 + * @tc.name: OpenRawFile + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenRawFile_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenRawFile_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + std::string mode("modetest"); + auto returnOpenRawFile = [&](const Uri &uri, const std::string &mode) { + int fd = 1234; + return fd; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), OpenRawFile(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnOpenRawFile)); + + dataAbilityHelper->OpenRawFile(*uri, mode); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenRawFile_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_OpenRawFile_0400 + * @tc.name: OpenRawFile + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_OpenRawFile_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenRawFile_0400 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + std::string mode("modetest"); + + EXPECT_EQ(dataAbilityHelper->OpenRawFile(*uri, mode), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_OpenRawFile_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_Reload_0100 * @tc.name: Reload @@ -576,7 +1100,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Reload_0100, std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface PacMap extras; - auto returnReload = [&](const Uri& uri, const PacMap& extras) { return true; }; + auto returnReload = [&](const Uri &uri, const PacMap &extras) { return true; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Reload(testing::_, testing::_)) .Times(1) .WillOnce(testing::Invoke(returnReload)); @@ -603,7 +1127,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Reload_0200, std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface PacMap extras; - auto returnReload = [&](const Uri& uri, const PacMap& extras) { return true; }; + auto returnReload = [&](const Uri &uri, const PacMap &extras) { return true; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Reload(testing::_, testing::_)) .Times(1) .WillOnce(testing::Invoke(returnReload)); @@ -613,6 +1137,59 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Reload_0200, GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Reload_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_Reload_0300 + * @tc.name: Reload + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Reload_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Reload_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + PacMap extras; + auto returnReload = [&](const Uri &uri, const PacMap &extras) { return true; }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), Reload(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnReload)); + + dataAbilityHelper->Reload(*uri, extras); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Reload_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Reload_0400 + * @tc.name: Reload + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Reload_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Reload_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + PacMap extras; + + EXPECT_FALSE(dataAbilityHelper->Reload(*uri, extras)); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Reload_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_BatchInsert_0100 * @tc.name: BatchInsert @@ -630,7 +1207,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_BatchInsert_0 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface std::vector values; - auto returnBatchInsert = [&](const Uri& uri, const std::vector& values) { return true; }; + auto returnBatchInsert = [&](const Uri &uri, const std::vector &values) { return true; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), BatchInsert(testing::_, testing::_)) .Times(1) .WillOnce(testing::Invoke(returnBatchInsert)); @@ -657,7 +1234,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_BatchInsert_0 std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface std::vector values; - auto returnBatchInsert = [&](const Uri& uri, const std::vector& values) { return true; }; + auto returnBatchInsert = [&](const Uri &uri, const std::vector &values) { return true; }; EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), BatchInsert(testing::_, testing::_)) .Times(1) .WillOnce(testing::Invoke(returnBatchInsert)); @@ -667,6 +1244,69 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_BatchInsert_0 GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_BatchInsert_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_BatchInsert_0300 + * @tc.name: BatchInsert + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_BatchInsert_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_BatchInsert_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord);; + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + std::vector values; + NativeRdb::ValuesBucket value1; + value1.PutInt("value1", 1); + NativeRdb::ValuesBucket value2; + value2.PutInt("value2", 2); + NativeRdb::ValuesBucket value3; + value3.PutInt("value3", 3); + values.push_back(value1); + values.push_back(value2); + values.push_back(value3); + auto returnBatchInsert = [&](const Uri &uri, const std::vector &values) { return true; }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), BatchInsert(testing::_, testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnBatchInsert)); + + dataAbilityHelper->BatchInsert(*uri, values); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_BatchInsert_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_BatchInsert_0400 + * @tc.name: BatchInsert + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_BatchInsert_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_BatchInsert_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + // Test to AbilityThread interface + std::vector values; + + EXPECT_EQ(dataAbilityHelper->BatchInsert(*uri, values), -1); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_BatchInsert_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_NormalizeUri_0100 * @tc.name: NormalizeUri @@ -683,7 +1323,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NormalizeUri_ std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface - auto returnNormalizeUri = [&](const Uri& uri) { + auto returnNormalizeUri = [&](const Uri &uri) { Uri uriValue("dataability://device_id/com.domainname.dataability."); return uriValue; }; @@ -712,7 +1352,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NormalizeUri_ std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface - auto returnNormalizeUri = [&](const Uri& uri) { + auto returnNormalizeUri = [&](const Uri &uri) { Uri uriValue("dataability://device_id/com.domainname.dataability."); return uriValue; }; @@ -725,12 +1365,68 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NormalizeUri_ GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_NormalizeUri_0200 end"; } +/** + * @tc.number: AaFwk_DataAbilityHelper_NormalizeUri_0300 + * @tc.name: NormalizeUri + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NormalizeUri_0300, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_NormalizeUri_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnNormalizeUri = [&](const Uri &uri) { + Uri uriValue("dataability://device_id/com.domainname.dataability."); + return uriValue; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), NormalizeUri(testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnNormalizeUri)); + + dataAbilityHelper->NormalizeUri(*uri); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_NormalizeUri_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_NormalizeUri_0400 + * @tc.name: NormalizeUri + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NormalizeUri_0400, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_NormalizeUri_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + Uri urivalue(""); + + EXPECT_TRUE(urivalue.Equals(dataAbilityHelper->NormalizeUri(*uri))); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_NormalizeUri_0400 end"; +} + /** * @tc.number: AaFwk_DataAbilityHelper_DenormalizeUri_0100 * @tc.name: DenormalizeUri * @tc.desc: Simulate successful test cases */ -HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0100, Function | MediumTest | Level1) +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0100, Function | MediumTest | Level1) { GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0100 start"; @@ -741,7 +1437,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUr std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); // Test to AbilityThread interface - auto returnDenormalizeUri = [&](const Uri& uri) { + auto returnDenormalizeUri = [&](const Uri &uri) { Uri uriValue("dataability://device_id/com.domainname.dataability."); return uriValue; }; @@ -759,7 +1455,8 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUr * @tc.name: DenormalizeUri * @tc.desc: Simulate successful test cases */ -HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0200, Function | MediumTest | Level3) +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0200, Function | MediumTest | Level3) { GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0200 start"; @@ -770,7 +1467,7 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUr std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); // Test to AbilityThread interface - auto returnDenormalizeUri = [&](const Uri& uri) { + auto returnDenormalizeUri = [&](const Uri &uri) { Uri uriValue("dataability://device_id/com.domainname.dataability."); return uriValue; }; @@ -782,5 +1479,804 @@ HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUr GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0200 end"; } + +/** + * @tc.number: AaFwk_DataAbilityHelper_DenormalizeUri_0300 + * @tc.name: DenormalizeUri + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0300, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0300 start"; + + std::shared_ptr mockTools = MockAbilitySchedulerTools::GetInstance(); + mockTools->SetMockStatus(true); + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + // Test to AbilityThread interface + auto returnDenormalizeUri = [&](const Uri &uri) { + Uri uriValue("dataability://device_id/com.domainname.dataability."); + return uriValue; + }; + EXPECT_CALL(*mockTools->GetMockAbilityScheduler(), DenormalizeUri(testing::_)) + .Times(1) + .WillOnce(testing::Invoke(returnDenormalizeUri)); + + dataAbilityHelper->DenormalizeUri(*uri); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_DenormalizeUri_0400 + * @tc.name: DenormalizeUri + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DenormalizeUri_0400, Function | MediumTest | Level3) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0400 start"; + + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + Uri urivalue(""); + + EXPECT_TRUE(urivalue.Equals(dataAbilityHelper->DenormalizeUri(*uri))); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DenormalizeUri_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_SetCallFromJs_0100 + * @tc.name: SetCallFromJs + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_SetCallFromJs_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_SetCallFromJs_0100 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper->callFromJs_ == false); + dataAbilityHelper->SetCallFromJs(); + EXPECT_TRUE(dataAbilityHelper->callFromJs_ == true); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_SetCallFromJs_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Release_0100 + * @tc.name: Release + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Release_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0100 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + bool ret = false; + EXPECT_TRUE(!ret); + ret = dataAbilityHelper->Release(); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Release_0200 + * @tc.name: Release + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Release_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0200 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + bool ret = false; + EXPECT_TRUE(!ret); + ret = dataAbilityHelper->Release(); + EXPECT_TRUE(!ret); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Release_0300 + * @tc.name: Release + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Release_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0300 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + bool ret = false; + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ != nullptr); + EXPECT_TRUE(!ret); + ret = dataAbilityHelper->Release(); + EXPECT_TRUE(ret); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Release_0400 + * @tc.name: Release + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Release_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0400 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + bool ret = true; + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + EXPECT_TRUE(ret); + ret = dataAbilityHelper->Release(); + EXPECT_FALSE(ret); + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Release_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_RegisterObserver_0100 + * @tc.name: RegisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_RegisterObserver_0100, Function | MediumTest | Level1) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + std::string uriString; + Uri uri1(uriString); + const sptr dataObserver; + dataAbilityHelper->RegisterObserver(uri1, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_RegisterObserver_0200 + * @tc.name: RegisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_RegisterObserver_0200, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString; + Uri uri1(uriString); + const sptr dataObserver; + dataAbilityHelper->RegisterObserver(uri1, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_RegisterObserver_0300 + * @tc.name: RegisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_RegisterObserver_0300, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + const sptr dataObserver; + dataAbilityHelper->RegisterObserver(*uri, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ != nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_RegisterObserver_0400 + * @tc.name: RegisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_RegisterObserver_0400, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + const sptr dataObserver; + dataAbilityHelper->RegisterObserver(*uri, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataAbilityHelperImpl_ == nullptr); + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_UnregisterObserver_0100 + * @tc.name: UnregisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_UnregisterObserver_0100, Function | MediumTest | Level1) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + const sptr dataObserver; + std::string uriString; + Uri uri1(uriString); + dataAbilityHelper->UnregisterObserver(uri1, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_UnregisterObserver_0200 + * @tc.name: UnregisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_UnregisterObserver_0200, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + sptr dataObserver; + std::string uriString; + Uri uri1(uriString); + dataAbilityHelper->UnregisterObserver(uri1, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_UnregisterObserver_0300 + * @tc.name: UnregisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_UnregisterObserver_0300, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + sptr dataObserver; + dataAbilityHelper->UnregisterObserver(*uri, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ != nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_UnregisterObserver_0400 + * @tc.name: UnregisterObserver + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_UnregisterObserver_0400, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + sptr dataObserver; + dataAbilityHelper->UnregisterObserver(*uri, dataObserver); + + EXPECT_TRUE(dataAbilityHelper->dataAbilityHelperImpl_ == nullptr); + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_NotifyChange_0100 + * @tc.name: NotifyChange + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NotifyChange_0100, Function | MediumTest | Level1) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + std::string uriString; + Uri uri1(uriString); + dataAbilityHelper->NotifyChange(uri1); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_NotifyChange_0200 + * @tc.name: NotifyChange + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NotifyChange_0200, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString; + Uri uri1(uriString); + dataAbilityHelper->NotifyChange(uri1); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_NotifyChange_0300 + * @tc.name: NotifyChange + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NotifyChange_0300, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + dataAbilityHelper->NotifyChange(*uri); + + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ != nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_NotifyChange_0400 + * @tc.name: NotifyChange + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_NotifyChange_0400, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + dataAbilityHelper->NotifyChange(*uri); + + EXPECT_TRUE(dataAbilityHelper->dataAbilityHelperImpl_ == nullptr); + EXPECT_TRUE(dataAbilityHelper->dataShareHelper_ == nullptr); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_ExecuteBatch_0100 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_ExecuteBatch_0100, Function | MediumTest | Level1) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + std::string uriString; + Uri uri1(uriString); + std::vector> operations; + auto ret = dataAbilityHelper->ExecuteBatch(uri1, operations); + + EXPECT_TRUE(ret.empty()); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_ExecuteBatch_0200 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_ExecuteBatch_0200, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString; + Uri uri1(uriString); + std::vector> operations; + auto ret = dataAbilityHelper->ExecuteBatch(uri1, operations); + + EXPECT_TRUE(ret.empty()); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_ExecuteBatch_0300 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_ExecuteBatch_0300, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + std::string uriString; + Uri uri1(uriString); + std::vector> operations; + auto ret = dataAbilityHelper->ExecuteBatch(uri1, operations); + + EXPECT_TRUE(ret.empty()); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_ExecuteBatch_0400 + * @tc.name: ExecuteBatch + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_ExecuteBatch_0400, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + std::string uriString; + Uri uri1(uriString); + std::vector> operations; + auto ret = dataAbilityHelper->ExecuteBatch(uri1, operations); + + EXPECT_TRUE(ret.empty()); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_TransferScheme_0100 + * @tc.name: TransferScheme + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_TransferScheme_0100, Function | MediumTest | Level1) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + std::string uriString = "dataability"; + Uri uri1(uriString); + Uri dataShareUri(uriString); + bool ret = false; + ret = dataAbilityHelper->TransferScheme(uri1, dataShareUri); + EXPECT_TRUE(!ret); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_TransferScheme_0200 + * @tc.name: TransferScheme + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_TransferScheme_0200, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString = "datashare"; + Uri uri1(uriString); + Uri dataShareUri(uriString); + bool ret = false; + ret = dataAbilityHelper->TransferScheme(uri1, dataShareUri); + EXPECT_TRUE(!ret); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_TransferScheme_0300 + * @tc.name: TransferScheme + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_TransferScheme_0300, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString = "abc"; + Uri uri1(uriString); + Uri dataShareUri(uriString); + bool ret = false; + ret = dataAbilityHelper->TransferScheme(uri1, dataShareUri); + EXPECT_TRUE(!ret); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_TransferScheme_0400 + * @tc.name: TransferScheme + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_TransferScheme_0400, Function | MediumTest | Level3) +{ + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = + std::make_shared("datashare://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context); + std::string uriString = "abc"; + Uri dataShareUri(uriString); + bool ret = false; + ret = dataAbilityHelper->TransferScheme(*uri, dataShareUri); + EXPECT_TRUE(ret); +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0100 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0100 start"; + std::shared_ptr context = nullptr; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0200 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0200 start"; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr uri = nullptr; + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0200 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0300 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0300 start"; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper != nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0300 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0400 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0400 start"; + std::shared_ptr context = nullptr; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0400 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0500 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0500 start"; + std::shared_ptr context = std::make_shared(); + std::shared_ptr uri = nullptr; + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0500 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0600 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0600 start"; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + bool tryBind = false; + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri, tryBind); + EXPECT_TRUE(dataAbilityHelper != nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0600 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0700 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0700 start"; + sptr remote = nullptr; + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(remote); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0700 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0800 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0800 start"; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + sptr remote = nullptr; + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(remote, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0800 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_0900 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_0900, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0900 start"; + std::shared_ptr uri = nullptr; + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(remote, uri); + EXPECT_TRUE(dataAbilityHelper == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_0900 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Creator_1000 + * @tc.name: Creator + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Creator_1000, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_1000 start"; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(remote, uri); + EXPECT_TRUE(dataAbilityHelper != nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Creator_1000 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_DataAbilityHelper_0100 + * @tc.name: DataAbilityHelper + * @tc.desc: Simulate successful test cases + */ +HWTEST_F( + DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_DataAbilityHelper_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DataAbilityHelper_0100 start"; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + auto dataShareHelper = std::make_shared(remote, *uri); + auto result = std::make_shared(dataShareHelper); + EXPECT_TRUE(result != nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_DataAbilityHelper_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Call_0100 + * @tc.name: Call + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Call_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Call_0100 start"; + std::shared_ptr context = std::make_shared();; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper != nullptr); + std::weak_ptr abilityRecord; + sptr remote = new OHOS::AAFwk::Token(abilityRecord); + dataAbilityHelper->dataShareHelper_ = std::make_shared(remote, *uri); + + const std::string method; + const std::string arg; + AppExecFwk::PacMap pacMap; + + EXPECT_TRUE(dataAbilityHelper->Call(*uri, method, arg, pacMap) == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Call_0100 end"; +} + +/** + * @tc.number: AaFwk_DataAbilityHelper_Call_0200 + * @tc.name: Call + * @tc.desc: Simulate successful test cases + */ +HWTEST_F(DataAbilityHelperForObserverTest, AaFwk_DataAbilityHelper_Call_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Call_0200 start"; + std::shared_ptr context = std::make_shared();; + std::shared_ptr uri = + std::make_shared("dataability://device_id/com.domainname.dataability.persondata/person/10"); + std::shared_ptr dataAbilityHelper = DataAbilityHelper::Creator(context, uri); + EXPECT_TRUE(dataAbilityHelper != nullptr); + dataAbilityHelper->dataAbilityHelperImpl_ = nullptr; + dataAbilityHelper->dataShareHelper_ = nullptr; + const std::string method; + const std::string arg; + AppExecFwk::PacMap pacMap; + + EXPECT_TRUE(dataAbilityHelper->Call(*uri, method, arg, pacMap) == nullptr); + + GTEST_LOG_(INFO) << "AaFwk_DataAbilityHelper_Call_0200 end"; +} } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp b/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp new file mode 100644 index 0000000000..a1f06492fc --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/extension_impl_test.cpp @@ -0,0 +1,637 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#define protected public +#include "ability_handler.h" +#include "ability_info.h" +#include "ability_local_record.h" +#include "extension_impl.h" +#undef private +#undef protected +#include "event_runner.h" +#include "mock_ability_token.h" +#include "ohos_application.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; + +class ExtensionImplTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ExtensionImplTest::SetUpTestCase(void) +{ +} + +void ExtensionImplTest::TearDownTestCase(void) +{ +} + +void ExtensionImplTest::SetUp(void) +{ +} + +void ExtensionImplTest::TearDown(void) +{ +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0100 + * @tc.name: Init + * @tc.desc: params is nullptr, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0100 start"; + std::shared_ptr application; + std::shared_ptr record; + std::shared_ptr extension; + std::shared_ptr handler; + sptr token = nullptr; + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0100 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0200 + * @tc.name: Init + * @tc.desc: application is not null, others is null, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0200 start"; + auto application = std::make_shared(); + std::shared_ptr record; + std::shared_ptr extension; + std::shared_ptr handler; + sptr token = nullptr; + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0200 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0300 + * @tc.name: Init + * @tc.desc: record is not null, others is null, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0300 start"; + std::shared_ptr application; + + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + + std::shared_ptr extension; + std::shared_ptr handler; + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0300 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0400 + * @tc.name: Init + * @tc.desc: token is not null, others is null, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0400 start"; + std::shared_ptr application; + sptr token = new AppExecFwk::MockAbilityToken(); + std::shared_ptr record; + std::shared_ptr extension; + std::shared_ptr handler; + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0400 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0500 + * @tc.name: Init + * @tc.desc: handler is not null, others is null, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0500 start"; + std::shared_ptr application; + sptr token = nullptr; + std::shared_ptr record; + std::shared_ptr extension; + + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0500 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0600 + * @tc.name: Init + * @tc.desc: extension is not null, others is null, Validation initialization failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0600 start"; + std::shared_ptr application; + sptr token = nullptr; + std::shared_ptr record; + auto extension = std::make_shared(); + std::shared_ptr handler; + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ == nullptr); + EXPECT_TRUE(impl->extension_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0600 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0700 + * @tc.name: Init + * @tc.desc: extension is not null, others is null, Validation initialization succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0700 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ != nullptr); + EXPECT_TRUE(impl->extension_ != nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0700 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0800 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Validation NotifyMemoryLevel succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0800 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + EXPECT_TRUE(impl->token_ != nullptr); + EXPECT_TRUE(impl->extension_ != nullptr); + + impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + int32_t level = 0; + impl->NotifyMemoryLevel(level); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0800 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_0900 + * @tc.name: NotifyMemoryLevel + * @tc.desc: Validation NotifyMemoryLevel succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_0900, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0900 start"; + auto impl = std::make_shared(); + int32_t level = 0; + impl->NotifyMemoryLevel(level); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_0900 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1000 + * @tc.name: Start + * @tc.desc: extension is nullptr, Validation Start failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1000, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1000 start"; + auto impl = std::make_shared(); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + Want want; + impl->Start(want); + EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1000 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1100 + * @tc.name: Start + * @tc.desc: extension is not nullptr, Validation Start succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1100 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + + Want want; + impl->Start(want); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1100 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1200 + * @tc.name: Stop + * @tc.desc: extension is not nullptr, Validation Stop succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1200 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + impl->Stop(); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1200 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1300 + * @tc.name: Stop + * @tc.desc: extension is nullptr, Validation Stop failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1300 start"; + auto impl = std::make_shared(); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + impl->Stop(); + EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1300 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1400 + * @tc.name: ConnectExtension + * @tc.desc: extension is nullptr, Validation ConnectExtension failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1400 start"; + auto impl = std::make_shared(); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + Want want; + auto object = impl->ConnectExtension(want); + EXPECT_NE(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + EXPECT_TRUE(object == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1400 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1500 + * @tc.name: ConnectExtension + * @tc.desc: extension is not nullptr, Validation ConnectExtension succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1500 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + Want want; + auto object = impl->ConnectExtension(want); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + EXPECT_TRUE(object == nullptr); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1500 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1600 + * @tc.name: DisconnectExtension + * @tc.desc: extension is not nullptr, Validation DisconnectExtension succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1600 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + Want want; + impl->DisconnectExtension(want); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1600 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1700 + * @tc.name: DisconnectExtension + * @tc.desc: extension is not nullptr, Validation DisconnectExtension failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1700 start"; + auto impl = std::make_shared(); + Want want; + impl->DisconnectExtension(want); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1700 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1800 + * @tc.name: DisconnectExtension + * @tc.desc: extension is nullptr, Validation DisconnectExtension failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1800 start"; + auto impl = std::make_shared(); + Want want; + bool isAsyncCallback = true; + impl->DisconnectExtension(want, isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1800 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_1900 + * @tc.name: DisconnectExtension + * @tc.desc: extension is nullptr, Validation DisconnectExtension failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_1900, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1900 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + + Want want; + bool isAsyncCallback = true; + impl->DisconnectExtension(want, isAsyncCallback); + EXPECT_FALSE(isAsyncCallback); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_1900 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2000 + * @tc.name: DisconnectExtensionCallback + * @tc.desc: Validation DisconnectExtensionCallback succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2000, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2000 start"; + auto impl = std::make_shared(); + impl->DisconnectExtensionCallback(); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2000 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2100 + * @tc.name: CommandExtension + * @tc.desc: extension is nullptr, Validation CommandExtension failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2100 start"; + auto impl = std::make_shared(); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + Want want; + bool restart = false; + int32_t startId = 0; + impl->CommandExtension(want, restart, startId); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2100 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2200 + * @tc.name: CommandExtension + * @tc.desc: extension is not nullptr, Validation CommandExtension succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2200 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INACTIVE; + Want want; + bool restart = false; + int32_t startId = 0; + impl->CommandExtension(want, restart, startId); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2200 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2300 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: extension is not nullptr, Validation ScheduleUpdateConfiguration succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2300 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + AppExecFwk::Configuration config; + impl->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2300 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2400 + * @tc.name: ScheduleUpdateConfiguration + * @tc.desc: extension is not nullptr, Validation ScheduleUpdateConfiguration failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2400 start"; + auto impl = std::make_shared(); + AppExecFwk::Configuration config; + impl->ScheduleUpdateConfiguration(config); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2400 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2600 + * @tc.name: HandleExtensionTransaction + * @tc.desc: current state is init, target state is inactive, Validation HandleExtensionTransaction succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2600 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + + impl->lifecycleState_ = AAFwk::ABILITY_STATE_INITIAL; + AAFwk::LifeCycleStateInfo targetState; + targetState.state = AAFwk::ABILITY_STATE_INITIAL; + Want want; + impl->HandleExtensionTransaction(want, targetState); + + targetState.state = AAFwk::ABILITY_STATE_INACTIVE; + impl->HandleExtensionTransaction(want, targetState); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2600 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2700 + * @tc.name: HandleExtensionTransaction + * @tc.desc: current state is active, target state is init, Validation HandleExtensionTransaction succeeded. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2700 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + Want want; + AAFwk::LifeCycleStateInfo targetState; + targetState.state = AAFwk::ABILITY_STATE_INITIAL; + impl->HandleExtensionTransaction(want, targetState); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_INITIAL); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2700 end"; +} + +/** + * @tc.number: AaFwk_ExtensionImpl_2800 + * @tc.name: HandleExtensionTransaction + * @tc.desc: current state is active, target state is inactive, Validation HandleExtensionTransaction failed. + */ +HWTEST_F(ExtensionImplTest, AaFwk_ExtensionImpl_2800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2800 start"; + auto application = std::make_shared(); + std::shared_ptr info = std::make_shared(); + sptr token = new AppExecFwk::MockAbilityToken(); + auto record = std::make_shared(info, token); + auto extension = std::make_shared(); + std::shared_ptr runner; + auto handler = std::make_shared(runner); + + auto impl = std::make_shared(); + impl->Init(application, record, extension, handler, token); + impl->lifecycleState_ = AAFwk::ABILITY_STATE_ACTIVE; + Want want; + AAFwk::LifeCycleStateInfo targetState; + targetState.state = AAFwk::ABILITY_STATE_INACTIVE; + impl->HandleExtensionTransaction(want, targetState); + EXPECT_EQ(impl->lifecycleState_, AAFwk::ABILITY_STATE_ACTIVE); + GTEST_LOG_(INFO) << "AaFwk_ExtensionImpl_2800 end"; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/frameworks_kits_ability_native_test/form_js_event_handler_test.cpp b/test/unittest/frameworks_kits_ability_native_test/form_js_event_handler_test.cpp new file mode 100644 index 0000000000..aef9a83562 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/form_js_event_handler_test.cpp @@ -0,0 +1,271 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#define protected public +#include "form_js_event_handler.h" +#include "form_mgr.h" +#include "inner_event.h" +#undef private +#undef protected +#include "mock_form_mgr_proxy.h" +#include "mock_service_ability.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; +using testing::_; + +class FormJsEventHandlerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void FormJsEventHandlerTest::SetUpTestCase(void) +{ +} + +void FormJsEventHandlerTest::TearDownTestCase(void) +{ +} + +void FormJsEventHandlerTest::SetUp(void) +{ +} + +void FormJsEventHandlerTest::TearDown(void) +{ +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0100 + * @tc.name: Create + * @tc.desc: Constructor method + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0100 start"; + std::shared_ptr runner; + std::shared_ptr ability; + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + EXPECT_TRUE(eventHandler->ability_ == nullptr); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0100 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0200 + * @tc.name: Create + * @tc.desc: Constructor method + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0200 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + EXPECT_TRUE(eventHandler->ability_ != nullptr); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0200 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0300 + * @tc.name: IsSystemApp + * @tc.desc: Validation IsSystemApp succeeded. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0300 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + auto result = eventHandler->IsSystemApp(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0300 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0400 + * @tc.name: ProcessEvent + * @tc.desc: event is nullptr, Verify that the ProcessEvent succeeded. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0400, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0400 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + InnerEvent::Pointer event = InnerEvent::Pointer(nullptr, nullptr); + eventHandler->ProcessEvent(event); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0400 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0500 + * @tc.name: ProcessEvent + * @tc.desc: empty event, Verify that the ProcessEvent succeeded. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0500, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0500 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + InnerEvent::Pointer event = InnerEvent::Get(); + eventHandler->ProcessEvent(event); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0500 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0600 + * @tc.name: ProcessRouterEvent + * @tc.desc: Validation ProcessRouterEvent succeeded. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0600, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0600 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + formJsInfo.bundleName = "bundleName"; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + eventHandler->ProcessRouterEvent(want); + std::string abilityName = "formAbility"; + want.SetParam(Constants::PARAM_FORM_ABILITY_NAME_KEY, abilityName); + eventHandler->ProcessRouterEvent(want); + auto bundleName = want.GetElement().GetBundleName(); + EXPECT_STREQ(bundleName.c_str(), "bundleName"); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0600 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0700 + * @tc.name: ProcessMessageEvent + * @tc.desc: Validation ProcessMessageEvent succeeded. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0700, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0700 start"; + sptr impl = nullptr; + sptr mockProxy = new (std::nothrow) MockFormMgrProxy(impl); + FormMgr::GetInstance().SetFormMgrService(mockProxy); + + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + std::string formId = "1"; + want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId); + std::string message = "message"; + want.SetParam(Constants::PARAM_MESSAGE_KEY, message); + + EXPECT_CALL(*mockProxy, MessageEvent(_, _, _)).Times(1); + eventHandler->ProcessMessageEvent(want); + testing::Mock::AllowLeak(mockProxy); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0700 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0800 + * @tc.name: ProcessMessageEvent + * @tc.desc: There is no formId in want, Validation ProcessMessageEvent failed. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0800, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0800 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + eventHandler->ProcessMessageEvent(want); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0800 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_0900 + * @tc.name: ProcessMessageEvent + * @tc.desc: form id is equal to 0, Validation ProcessMessageEvent failed. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_0900, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0900 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + std::string formId = "0"; + want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId); + eventHandler->ProcessMessageEvent(want); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_0900 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_1000 + * @tc.name: ProcessMessageEvent + * @tc.desc: There is no PARAM_MESSAGE_KEY in want, Validation ProcessMessageEvent failed. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_1000, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1000 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + std::string formId = "1"; + want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId); + eventHandler->ProcessMessageEvent(want); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1000 end"; +} + +/** + * @tc.number: AaFwk_FormJsEventHandler_1100 + * @tc.name: ProcessMessageEvent + * @tc.desc: Form mgr set IN_RECOVERING, Validation ProcessMessageEvent failed. + */ +HWTEST_F(FormJsEventHandlerTest, AaFwk_FormJsEventHandler_1100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1100 start"; + std::shared_ptr runner; + std::shared_ptr ability = std::make_shared(); + FormJsInfo formJsInfo; + auto eventHandler = std::make_shared(runner, ability, formJsInfo); + Want want; + std::string formId = "1"; + want.SetParam(Constants::PARAM_FORM_IDENTITY_KEY, formId); + std::string message = "message"; + want.SetParam(Constants::PARAM_MESSAGE_KEY, message); + + FormMgr::GetInstance().SetRecoverStatus(Constants::IN_RECOVERING); + eventHandler->ProcessMessageEvent(want); + GTEST_LOG_(INFO) << "AaFwk_FormJsEventHandler_1100 end"; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp new file mode 100644 index 0000000000..dec3ef1d6b --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2021-2022 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 "gtest/gtest.h" + +#define private public +#define protected public +#include "context.h" +#include "mock_ability_runtime_context.h" +#undef private +#undef protected + +namespace OHOS { +namespace AbilityRuntime { +MockAbilityRuntimeContext::MockAbilityRuntimeContext() +{}; + +std::string MockAbilityRuntimeContext::GetBundleName() const +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::CreateBundleContext(const std::string &bundleName) +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::GetApplicationInfo() const +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::GetResourceManager() const +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetBundleCodePath() const +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::GetHapModuleInfo() const +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetBundleCodeDir() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetCacheDir() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetTempDir() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetFilesDir() +{ + return {}; +}; + +bool MockAbilityRuntimeContext::IsUpdatingConfigurations() +{ + return {}; +}; + +bool MockAbilityRuntimeContext::PrintDrawnCompleted() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetDatabaseDir() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetPreferencesDir() +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetDistributedFilesDir() +{ + return {}; +}; + +sptr MockAbilityRuntimeContext::GetToken() +{ + return {}; +}; + +void MockAbilityRuntimeContext::SetToken(const sptr &token) +{}; + +void MockAbilityRuntimeContext::SwitchArea(int mode) +{}; + +std::shared_ptr MockAbilityRuntimeContext::CreateModuleContext(const std::string &moduleName) +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::CreateModuleContext( + const std::string &bundleName, const std::string &moduleName) +{ + return {}; +}; + +int MockAbilityRuntimeContext::GetArea() +{ + return {}; +}; + +std::shared_ptr MockAbilityRuntimeContext::GetConfiguration() const +{ + return {}; +}; + +std::string MockAbilityRuntimeContext::GetBaseDir() const +{ + return {}; +}; + +Global::Resource::DeviceType MockAbilityRuntimeContext::GetDeviceType() const +{ + return {}; +}; +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h new file mode 100644 index 0000000000..ce6a837756 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/mock_ability_runtime_context.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2021-2022 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 "gtest/gtest.h" + +#define private public +#define protected public +#include "foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context/context.h" +#undef private +#undef protected + +namespace OHOS { +namespace AbilityRuntime { +class MockAbilityRuntimeContext : public OHOS::AbilityRuntime::Context { +public: + MockAbilityRuntimeContext(); + virtual ~MockAbilityRuntimeContext() = default; + + std::string GetBundleName() const override; + std::shared_ptr CreateBundleContext(const std::string &bundleName) override; + std::shared_ptr GetApplicationInfo() const override; + std::shared_ptr GetResourceManager() const override; + std::string GetBundleCodePath() const override; + std::shared_ptr GetHapModuleInfo() const override; + std::string GetBundleCodeDir() override; + std::string GetCacheDir() override; + std::string GetTempDir() override; + std::string GetFilesDir() override; + bool IsUpdatingConfigurations() override; + bool PrintDrawnCompleted() override; + std::string GetDatabaseDir() override; + std::string GetPreferencesDir() override; + std::string GetDistributedFilesDir() override; + sptr GetToken() override; + void SetToken(const sptr &token) override; + void SwitchArea(int mode) override; + std::shared_ptr CreateModuleContext(const std::string &moduleName) override; + std::shared_ptr CreateModuleContext( + const std::string &bundleName, const std::string &moduleName) override; + int GetArea() override; + std::shared_ptr GetConfiguration() const override; + std::string GetBaseDir() const override; + Global::Resource::DeviceType GetDeviceType() const override; +}; +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_proxy_test.cpp b/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_proxy_test.cpp new file mode 100644 index 0000000000..349c3972f2 --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_proxy_test.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (c) 2022 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 "gmock/gmock.h" +#define private public +#define protected public +#include "message_parcel.h" +#include "mock_ability_connect_callback.h" +#include "peer_holder.h" +#include "reverse_continuation_scheduler_primary.h" +#include "reverse_continuation_scheduler_primary_proxy.h" +#include "reverse_continuation_scheduler_primary_stub.h" +#undef private +#undef protected +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using ::testing::_; +using namespace OHOS; +using namespace OHOS::AppExecFwk; +class MockContinuationSchedulerPrimaryStub : public ReverseContinuationSchedulerPrimaryStub { +public: + MOCK_METHOD4(OnRemoteRequest, int(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)); + MOCK_METHOD0(NotifyReplicaTerminated, void()); + MOCK_METHOD1(ContinuationBack, bool(const AAFwk::Want& want)); +}; + +class ReverseContinuationSchedulerPrimaryProxyTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ReverseContinuationSchedulerPrimaryProxyTest::SetUpTestCase(void) {} +void ReverseContinuationSchedulerPrimaryProxyTest::TearDownTestCase(void) {} +void ReverseContinuationSchedulerPrimaryProxyTest::SetUp(void) {} +void ReverseContinuationSchedulerPrimaryProxyTest::TearDown(void) {} + +/** + * @tc.number: ContinuationBack_0100 + * @tc.name: ContinuationBack + * @tc.desc: Verify that function ContinuationBack. + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, ContinuationBack_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ContinuationBack_0100 start"; + auto remoteObject = new (std::nothrow) MockContinuationSchedulerPrimaryStub(); + auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject->AsObject()); + AAFwk::Want want; + EXPECT_CALL(*remoteObject, OnRemoteRequest(_, _, _, _)) + .Times(::testing::AtLeast(1)).WillOnce(::testing::Return(2)); + auto result = primaryProxy_->ContinuationBack(want); + EXPECT_TRUE(result); + testing::Mock::AllowLeak(remoteObject); + GTEST_LOG_(INFO) << "ContinuationBack_0100 end"; +} + +/** + * @tc.number: ContinuationBack_0200 + * @tc.name: ContinuationBack + * @tc.desc: Verify that function ContinuationBack. + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, ContinuationBack_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ContinuationBack_0100 start"; + sptr remoteObject = nullptr; + auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject); + AAFwk::Want want; + auto result = primaryProxy_->ContinuationBack(want); + EXPECT_TRUE(!result); + GTEST_LOG_(INFO) << "ContinuationBack_0100 end"; +} + +/** + * @tc.number: NotifyReplicaTerminated_0100 + * @tc.name: NotifyReplicaTerminated + * @tc.desc: Verify that function NotifyReplicaTerminated. + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryProxyTest, NotifyReplicaTerminated_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "NotifyReplicaTerminated_0100 start"; + sptr remoteObject = nullptr; + auto primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(remoteObject); + primaryProxy_->NotifyReplicaTerminated(); + + auto Object = new (std::nothrow) MockContinuationSchedulerPrimaryStub(); + primaryProxy_ = new (std::nothrow) ReverseContinuationSchedulerPrimaryProxy(Object->AsObject()); + EXPECT_CALL(*Object, OnRemoteRequest(_, _, _, _)) + .Times(::testing::AtLeast(1)).WillOnce(::testing::Return(2)); + primaryProxy_->NotifyReplicaTerminated(); + testing::Mock::AllowLeak(Object); + GTEST_LOG_(INFO) << "NotifyReplicaTerminated_0100 end"; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_stub_test.cpp b/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_stub_test.cpp new file mode 100644 index 0000000000..3161552a3e --- /dev/null +++ b/test/unittest/frameworks_kits_ability_native_test/reserse_continuation_scheduler_primary_stub_test.cpp @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2022 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 +#define private public +#define protected public +#include "event_handler.h" +#include "message_parcel.h" +#include "parcel.h" +#include "reverse_continuation_scheduler_primary.h" +#include "reverse_continuation_scheduler_primary_stub.h" +#undef protected +#undef private +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AAFwk; +class MockReverseContinuationSchedulerPrimaryStub : public ReverseContinuationSchedulerPrimaryStub { +public: + MockReverseContinuationSchedulerPrimaryStub() = default; + virtual ~MockReverseContinuationSchedulerPrimaryStub() {} + bool ContinuationBack(const AAFwk::Want& want) override + { + return true; + } + void NotifyReplicaTerminated() override {} +}; +class ReverseContinuationSchedulerPrimaryStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + sptr primaryStub_; +}; +void ReverseContinuationSchedulerPrimaryStubTest::SetUpTestCase(void) {} +void ReverseContinuationSchedulerPrimaryStubTest::TearDownTestCase(void) {} +void ReverseContinuationSchedulerPrimaryStubTest::SetUp(void) +{ + primaryStub_ = new (std::nothrow) MockReverseContinuationSchedulerPrimaryStub(); +} +void ReverseContinuationSchedulerPrimaryStubTest::TearDown(void) +{ + primaryStub_ = nullptr; +} + +/** + * @tc.number: OnRemoteRequest_0100 + * @tc.name: OnRemoteRequest + * @tc.desc: Verify that function OnRemoteRequest + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "OnRemoteRequest_0100 start"; + uint32_t code = 1; + MessageParcel data; + MessageParcel reply; + MessageOption option; + auto result = primaryStub_->OnRemoteRequest(code, data, reply, option); + + EXPECT_EQ(result, INVALID_FD); + GTEST_LOG_(INFO) << "OnRemoteRequest_0100 end"; +} + +/** + * @tc.number: OnRemoteRequest_0200 + * @tc.name: OnRemoteRequest + * @tc.desc: Verify that function OnRemoteRequest + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "OnRemoteRequest_0200 start"; + uint32_t code = 1; + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::u16string name = u"ohos.abilityshell.ReverseContinuationSchedulerMaster"; + data.WriteInterfaceToken(name); + auto result = primaryStub_->OnRemoteRequest(code, data, reply, option); + + EXPECT_EQ(result, ERR_NONE); + GTEST_LOG_(INFO) << "OnRemoteRequest_0200 end"; +} + +/** + * @tc.number: OnRemoteRequest_0300 + * @tc.name: OnRemoteRequest + * @tc.desc: Verify that function OnRemoteRequest + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, OnRemoteRequest_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "OnRemoteRequest_0300 start"; + uint32_t code = 3; + MessageParcel data; + MessageParcel reply; + MessageOption option; + std::u16string name = u"ohos.abilityshell.ReverseContinuationSchedulerMaster"; + data.WriteInterfaceToken(name); + primaryStub_->requestFuncMap_[3] = nullptr; + auto result = primaryStub_->OnRemoteRequest(code, data, reply, option); + + EXPECT_EQ(result, IPC_STUB_UNKNOW_TRANS_ERR); + GTEST_LOG_(INFO) << "OnRemoteRequest_0300 end"; +} + +/** + * @tc.number: NotifyReplicaTerminatedInner_0100 + * @tc.name: NotifyReplicaTerminatedInner + * @tc.desc: Verify that function NotifyReplicaTerminatedInner + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, NotifyReplicaTerminatedInner_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "NotifyReplicaTerminatedInner_0100 start"; + MessageParcel data; + MessageParcel reply; + auto result = primaryStub_->NotifyReplicaTerminatedInner(data, reply); + + EXPECT_EQ(result, ERR_NONE); + GTEST_LOG_(INFO) << "NotifyReplicaTerminatedInner_0100 end"; +} + +/** + * @tc.number: ContinuationBackInner_0100 + * @tc.name: ContinuationBackInner + * @tc.desc: Verify that function ContinuationBackInner + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0100, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ContinuationBackInner_0100 start"; + MessageParcel data; + MessageParcel reply; + data.WriteInt32(0); + auto result = primaryStub_->ContinuationBackInner(data, reply); + + EXPECT_EQ(result, -1); + GTEST_LOG_(INFO) << "ContinuationBackInner_0100 end"; +} + +/** + * @tc.number: ContinuationBackInner_0200 + * @tc.name: ContinuationBackInner + * @tc.desc: Verify that function ContinuationBackInner + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0200, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ContinuationBackInner_0200 start"; + MessageParcel data; + MessageParcel reply; + auto result = primaryStub_->ContinuationBackInner(data, reply); + + EXPECT_EQ(result, -1); + GTEST_LOG_(INFO) << "ContinuationBackInner_0200 end"; +} + +/** + * @tc.number: ContinuationBackInner_0300 + * @tc.name: ContinuationBackInner + * @tc.desc: Verify that function ContinuationBackInner + */ +HWTEST_F(ReverseContinuationSchedulerPrimaryStubTest, ContinuationBackInner_0300, Function | MediumTest | Level1) +{ + GTEST_LOG_(INFO) << "ContinuationBackInner_0300 start"; + MessageParcel data; + MessageParcel reply; + data.WriteInt32(1); + auto result = primaryStub_->ContinuationBackInner(data, reply); + + EXPECT_EQ(result, -1); + GTEST_LOG_(INFO) << "ContinuationBackInner_0300 end"; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn index 7e933abb50..785b5533e3 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn +++ b/test/unittest/frameworks_kits_appkit_native_test/BUILD.gn @@ -86,6 +86,10 @@ ohos_unittest("context_deal_interface_test") { ohos_unittest("application_test") { module_out_path = module_output_path + + include_dirs = + [ "//base/global/resource_management/frameworks/resmgr/include" ] + sources = [ "${ability_runtime_native_path}/appkit/app/app_context.cpp", "${ability_runtime_native_path}/appkit/app/app_loader.cpp", @@ -370,6 +374,39 @@ ohos_unittest("ability_stage_test") { ] } +ohos_unittest("form_extension_context_test") { + module_out_path = module_output_path + + sources = [ + "${ability_runtime_native_path}/appkit/app/app_loader.cpp", + "${ability_runtime_native_path}/appkit/app/ohos_application.cpp", + "form_extension_context_test.cpp", + ] + + configs = [ ":module_context_config" ] + + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/ability/native:form_extension", + "${ability_runtime_native_path}/appkit:app_context", + "${ability_runtime_native_path}/appkit:appkit_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:configuration", + "ability_base:want", + "ability_runtime:runtime", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "form_fwk:fmskit_native", + "form_fwk:form_manager", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] +} + ############################################################################### group("unittest") { @@ -383,6 +420,7 @@ group("unittest") { ":application_test", ":context_container_test", ":context_deal_test", + ":form_extension_context_test", ":mix_stack_dumper_test", ":watchdog_test", ] diff --git a/test/unittest/frameworks_kits_appkit_native_test/context_container_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/context_container_test.cpp index b197d1eedb..1a58ad1971 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/context_container_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/context_container_test.cpp @@ -1259,5 +1259,758 @@ HWTEST_F(ContextContainerTest, PrintDrawnCompleted_0200, Function | MediumTest | context_->AttachBaseContext(nullptr); EXPECT_FALSE(context_->PrintDrawnCompleted()); } + +/** + * @tc.number: AppExecFwk_ContextContainer_DeleteFile_0100 + * @tc.name: Delete File + * @tc.desc: Test Delete File When baseContext is not null, + * and verify whether the return value of DeleteFile is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_DeleteFile_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_TRUE(context_->DeleteFile("test")); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_DeleteFile_0200 + * @tc.name: Delete File + * @tc.desc: Test Delete File When baseContext is null. + * and verify whether the return value of DeleteFile is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_DeleteFile_0200, Function | MediumTest | Level3) +{ + EXPECT_FALSE(context_->DeleteFile("test")); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetExternalCacheDir_0100 + * @tc.name: Get External Cache Dir + * @tc.desc: Test Get External Cache Dir When baseContext is not null, + * and verify whether the return value of Get External Cache Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalCacheDir_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetExternalCacheDir(), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetExternalCacheDir_0200 + * @tc.name: Get External Cache Dir + * @tc.desc: Test Get External Cache Dir When baseContext is null. + * and verify whether the return value of Get External Cache Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalCacheDir_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetExternalCacheDir(), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetExternalFilesDir_0100 + * @tc.name: Get External Files Dir + * @tc.desc: Test Get External Files Dir When baseContext is not null, + * and verify whether the return value of Get External Files Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalFilesDir_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + std::string type = "type"; + EXPECT_EQ(context_->GetExternalFilesDir(type), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetExternalFilesDir_0200 + * @tc.name: Get External FilesDir + * @tc.desc: Test Get External Files Dir When baseContext is null. + * and verify whether the return value of Get External Files Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetExternalFilesDir_0200, Function | MediumTest | Level3) +{ + std::string type = "type"; + EXPECT_EQ(context_->GetExternalFilesDir(type), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetNoBackupFilesDir_0100 + * @tc.name: Get No Backup Files Dir + * @tc.desc: Test Get No Backup Files Dir When baseContext is not null, + * and verify whether the return value of Get No Backup Files Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetNoBackupFilesDir_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetNoBackupFilesDir(), "/data/storage/el2/base/data/no_backup"); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetNoBackupFilesDir_0200 + * @tc.name: Get No Backup FilesDir + * @tc.desc: Test Get No Backup Files Dir When baseContext is null. + * and verify whether the return value of Get No Backup Files Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetNoBackupFilesDir_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetNoBackupFilesDir(), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_VerifySelfPermission_0100 + * @tc.name: Verify Self Permission + * @tc.desc: Test Verify Self Permission When baseContext is not null, + * and verify whether the return value of Verify Self Permission is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_VerifySelfPermission_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->VerifySelfPermission("permission"), AppExecFwk::Constants::PERMISSION_GRANTED); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_VerifySelfPermission_0200 + * @tc.name: Verify Self Permission + * @tc.desc: Test Verify Self Permission When baseContext is null. + * and verify whether the return value of Verify Self Permission is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_VerifySelfPermission_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->VerifySelfPermission("permission"), AppExecFwk::Constants::PERMISSION_NOT_GRANTED); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_UnauthUriPermission_0100 + * @tc.name: Unauth Uri Permission + * @tc.desc: Test Unauth Uri Permission When baseContext is not null + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_UnauthUriPermission_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + Uri urivalue(""); + context_->UnauthUriPermission("permission", urivalue, 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_UnauthUriPermission_0200 + * @tc.name: Unauth Uri Permission + * @tc.desc: TestUnauth Uri Permission When baseContext is null. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_UnauthUriPermission_0200, Function | MediumTest | Level3) +{ + Uri urivalue(""); + context_->UnauthUriPermission("permission", urivalue, 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetDistributedDir_0100 + * @tc.name: Get Distributed Dir + * @tc.desc: Test Get Distributed Dir When baseContext is not null, + * and verify whether the return value of Get Distributed Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDistributedDir_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetDistributedDir(), "/data/storage/el2/distributedfiles"); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetDistributedDir_0200 + * @tc.name: Get Distributed Dir + * @tc.desc: Test Get Distributed Dir When baseContext is null. + * and verify whether the return value of Get Distributed Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDistributedDir_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetDistributedDir(), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetAbilityPackageContext_0100 + * @tc.name: Get Ability Package Context + * @tc.desc: Test Get Ability Package Context When baseContext is not null, + * and verify whether the return value of Get Ability Package Context is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetAbilityPackageContext_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetAbilityPackageContext(), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetAbilityPackageContext_0200 + * @tc.name: Get Ability Package Context + * @tc.desc: Test Get Ability Package Context When baseContext is null. + * and verify whether the return value of Get Ability Package Context is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetAbilityPackageContext_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetAbilityPackageContext(), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetHapModuleInfo_0100 + * @tc.name: Get Hap Module Info + * @tc.desc: Test Get Hap Module Info When baseContext is not null, + * and verify whether the return value of Get Hap Module Info is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetHapModuleInfo_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + contextDeal_->hapModuleInfoLocal_ = std::make_shared(); + context_->AttachBaseContext(contextDeal_); + + EXPECT_NE(context_->GetHapModuleInfo(), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetHapModuleInfo_0200 + * @tc.name: Get Hap Module Info + * @tc.desc: Test Get Hap Module Info When baseContext is null. + * and verify whether the return value of Get Hap Module Info is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetHapModuleInfo_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetHapModuleInfo(), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetCaller_0100 + * @tc.name: Get Caller + * @tc.desc: Test Get Caller When baseContext is not null, + * and verify whether the return value of Get Caller is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetCaller_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + contextDeal_->SerUriString("test"); + context_->AttachBaseContext(contextDeal_); + + Uri uri("test"); + EXPECT_EQ(context_->GetCaller(), uri); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetCaller_0200 + * @tc.name: Request Permissions From User + * @tc.desc: Test Get Caller When baseContext is null. + * and verify whether the return value of Get Caller is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetCaller_0200, Function | MediumTest | Level3) +{ + Uri uri(""); + EXPECT_EQ(context_->GetCaller(), uri); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetString_0100 + * @tc.name: Get String + * @tc.desc: Test Get String When baseContext is not null, + * and verify whether the return value of Get String is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetString_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetString(0), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetString_0200 + * @tc.name: Get String + * @tc.desc: Test Get String When baseContext is null. + * and verify whether the return value of Get String is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetString_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetString(0), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetStringArray_0100 + * @tc.name: Get String Array + * @tc.desc: Test Get String Array When baseContext is not null, + * and verify whether the return value of Get String Array is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetStringArray_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + std::vector ret = context_->GetStringArray(0); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetStringArray_0200 + * @tc.name: Get String Array + * @tc.desc: Test Get String Array When baseContext is null. + * and verify whether the return value of Get String Array is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetStringArray_0200, Function | MediumTest | Level3) +{ + std::vector ret = context_->GetStringArray(0); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetIntArray_0100 + * @tc.name: Get Int Array + * @tc.desc: Test Get Int Array When baseContext is not null, + * and verify whether the return value of Get Int Array is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetIntArray_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + std::vector ret = context_->GetIntArray(0); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetIntArray_0200 + * @tc.name: Get Int Array + * @tc.desc: Test Get Int Array When baseContext is null. + * and verify whether the return value of Get Int Array is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetIntArray_0200, Function | MediumTest | Level3) +{ + std::vector ret = context_->GetIntArray(0); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetTheme_0100 + * @tc.name: Get Theme + * @tc.desc: Test Get Theme When baseContext is not null, + * and verify whether the return value of Get Theme is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetTheme_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + std::map ret = context_->GetTheme(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetTheme_0200 + * @tc.name: Get Theme + * @tc.desc: Test Get Theme When baseContext is null. + * and verify whether the return value of Get Theme is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetTheme_0200, Function | MediumTest | Level3) +{ + std::map ret = context_->GetTheme(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_SetTheme_0100 + * @tc.name: Set Theme + * @tc.desc: Test Set Theme When baseContext is not null, + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetTheme_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + context_->SetTheme(0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_SetTheme_0200 + * @tc.name: Set Theme + * @tc.desc: Test Set Theme When baseContext is null. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetTheme_0200, Function | MediumTest | Level3) +{ + context_->SetTheme(0); +} + +/** + * @tc.number: AppExecFwk_ContextContainerGetPattern_0100 + * @tc.name: Get Pattern + * @tc.desc: Test Get Pattern When baseContext is not null, + * and verify whether the return value of Get Pattern is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPattern_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + std::map ret = context_->GetPattern(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetPattern_0200 + * @tc.name: Get Pattern + * @tc.desc: Test Get Pattern When baseContext is null. + * and verify whether the return value of Get Pattern is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPattern_0200, Function | MediumTest | Level3) +{ + std::map ret = context_->GetPattern(); + EXPECT_EQ(ret.size(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainerSetPattern_0100 + * @tc.name: Set Pattern + * @tc.desc: Test Get Pattern When baseContext is not null, + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetPattern_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + context_->SetPattern(0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_SetPattern_0200 + * @tc.name: Set Pattern + * @tc.desc: Test Set Pattern When baseContext is null. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_SetPattern_0200, Function | MediumTest | Level3) +{ + context_->SetPattern(0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetColor_0100 + * @tc.name: Get Color + * @tc.desc: Test Get Color When baseContext is not null, + * and verify whether the return value of Get Color is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColor_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetColor(0), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetColor_0200 + * @tc.name: Get Color + * @tc.desc: Test Get Color When baseContext is null. + * and verify whether the return value of Get Color is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColor_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetColor(0), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetThemeId_0100 + * @tc.name: Get Theme Id + * @tc.desc: Test Get Theme Id When baseContext is not null, + * and verify whether the return value of Get Theme Id is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetThemeId_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetThemeId(), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetThemeId_0200 + * @tc.name: Get Theme Id + * @tc.desc: Test Get Theme Id When baseContext is null. + * and verify whether the return value of Get Theme Id is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetThemeId_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetThemeId(), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetDisplayOrientation_0100 + * @tc.name: Get Display Orientation + * @tc.desc: Test Get Display Orientation When baseContext is not null, + * and verify whether the return value of Get Display Orientation is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDisplayOrientation_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + contextDeal_-> abilityInfo_ = std::make_shared(); + contextDeal_->abilityInfo_->orientation = DisplayOrientation::LANDSCAPE; + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetDisplayOrientation(), 1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetDisplayOrientation_0200 + * @tc.name: Get Display Orientation + * @tc.desc: Test Get Display Orientation When baseContext is null. + * and verify whether the return value of Get Display Orientation is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetDisplayOrientation_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetDisplayOrientation(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetPreferencesDir_0100 + * @tc.name: Get Preferences Dir + * @tc.desc: Test Get Preferences Dir When baseContext is not null, + * and verify whether the return value of Get Preferences Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPreferencesDire_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetPreferencesDir(), "/data/storage/el2/base/preferences"); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetPreferencesDir_0200 + * @tc.name: Get Preferences Dir + * @tc.desc: Test Get Preferences Dir When baseContext is null. + * and verify whether the return value of Get Preferences Dir is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetPreferencesDir_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetPreferencesDir(), ""); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetColorMode_0100 + * @tc.name: Get Color Mode + * @tc.desc: Test Get Color Mode When baseContext is not null, + * and verify whether the return value of Get Color Mode is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColorMode_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + contextDeal_->hapModuleInfoLocal_ = std::make_shared(); + context_->AttachBaseContext(contextDeal_); + + context_->SetColorMode(static_cast(ModuleColorMode::DARK)); + EXPECT_EQ(context_->GetColorMode(), static_cast(ModuleColorMode::DARK)); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetColorMode_0200 + * @tc.name: Get Color Mode + * @tc.desc: Test Get Color Mode When baseContext is null. + * and verify whether the return value of Get Color Mode is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetColorMode_0200, Function | MediumTest | Level3) +{ + context_->SetColorMode(-1); + EXPECT_EQ(context_->GetColorMode(), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetMissionId_0100 + * @tc.name: Get Mission Id + * @tc.desc: Test Get Mission Id When baseContext is not null, + * and verify whether the return value of Get Mission Id is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetMissionId_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + + AAFwk::LifeCycleStateInfo lifeCycleStateInfo; + lifeCycleStateInfo.missionId = 0; + contextDeal_->SetLifeCycleStateInfo(lifeCycleStateInfo); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->GetMissionId(), 0); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_GetMissionId_0200 + * @tc.name: Get Mission Id + * @tc.desc: Test Get Mission Id When baseContext is null. + * and verify whether the return value of Get Mission Id is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_GetMissionId_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->GetMissionId(), -1); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_IsUpdatingConfigurations_0100 + * @tc.name: Is Updating Configurations + * @tc.desc: Test Is Updating Configurations When baseContext is not null, + * and verify whether the return value of Is Updating Configurations is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_IsUpdatingConfigurations_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->IsUpdatingConfigurations(), false); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_IsUpdatingConfigurations_0200 + * @tc.name: Is Updating Configurations + * @tc.desc: Test Is Updating Configurations When baseContext is null. + * and verify whether the return value of Is Updating Configurations is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_IsUpdatingConfigurations_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->IsUpdatingConfigurations(), false); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_PrintDrawnCompleted_0100 + * @tc.name: Print Drawn Completed + * @tc.desc: Test Print Drawn Completed When baseContext is not null, + * and verify whether the return value of Print Drawn Completed is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_PrintDrawnCompleted_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->PrintDrawnCompleted(), false); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_PrintDrawnCompleted_0200 + * @tc.name: Print Drawn Completed + * @tc.desc: Test Print Drawn Completed When baseContext is null. + * and verify whether the return value of Print Drawn Completed is correct. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_PrintDrawnCompleted_0200, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->PrintDrawnCompleted(), false); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0100 +* @tc.name: Create Bundle Context + * @tc.desc: Test Create Bundle Context return is not null. + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0100, Function | MediumTest | Level1) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + std::shared_ptr info = std::make_shared(); + std::string bundleName = "BundleName"; + info->bundleName = bundleName; + contextDeal_->SetContext(context); + contextDeal_->SetApplicationInfo(info); + contextDeal_->SetApplicationContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_NE(context_->CreateBundleContext("BundleName", 0, 0), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0200 + * @tc.name: Create Bundle Context + * @tc.desc: Test Create Bundle Context return is null because bundle info is error account id is not DEFAULT_ACCOUNT_ID + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0200, Function | MediumTest | Level3) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->CreateBundleContext("bundlename", 0, 0), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0300 + * @tc.name: Create Bundle Context + * @tc.desc: Test Create Bundle Context return is null because bundle info is error account id is DEFAULT_ACCOUNT_ID + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0300, Function | MediumTest | Level3) +{ + std::shared_ptr ability = std::make_shared(); + std::shared_ptr context(ability); + contextDeal_->SetContext(context); + context_->AttachBaseContext(contextDeal_); + + EXPECT_EQ(context_->CreateBundleContext("bundlename", 0, DEFAULT_ACCOUNT_ID), nullptr); +} + +/** + * @tc.number: AppExecFwk_ContextContainer_CreateBundleContext_0400 + * @tc.name: Create Bundle Context + * @tc.desc: Test Create Bundle Context return is null because bundle name is empty + */ +HWTEST_F(ContextContainerTest, AppExecFwk_ContextContainer_CreateBundleContext_0400, Function | MediumTest | Level3) +{ + EXPECT_EQ(context_->CreateBundleContext("", 0, 0), nullptr); +} + } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp index 990c0baf22..c50c95c79f 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/context_impl_test.cpp @@ -29,6 +29,7 @@ #include "iremote_object.h" #include "mock_ability_token.h" #include "mock_bundle_manager.h" +#include "mock_resource_manager.h" #include "system_ability_definition.h" #include "sys_mgr_client.h" @@ -945,5 +946,125 @@ HWTEST_F(ContextImplTest, GetDeviceType_0100, TestSize.Level1) HILOG_INFO("%{public}s end.", __func__); } + +/** + * @tc.number: GetCacheDir_0100 + * @tc.name: GetCacheDir_0100 + * @tc.desc: Get cache dir test. + */ +HWTEST_F(ContextImplTest, GetCacheDir_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + + auto cacheDir = contextImpl->GetCacheDir(); + EXPECT_EQ(cacheDir, "/data/storage/el2/base/cache"); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: GetConfiguration_0100 + * @tc.name: GetConfiguration_0100 + * @tc.desc: Get configuration test. + */ +HWTEST_F(ContextImplTest, GetConfiguration_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + auto configRet = contextImpl->GetConfiguration(); + EXPECT_EQ(configRet, nullptr); + + // construct configuration + auto config = std::make_shared(); + EXPECT_NE(config, nullptr); + config->AddItem(AAFwk::GlobalConfigurationKey::DEVICE_TYPE, "phone"); + contextImpl->SetConfiguration(config); + + configRet = contextImpl->GetConfiguration(); + EXPECT_NE(configRet, nullptr); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: IsCreateBySystemApp_0100 + * @tc.name: IsCreateBySystemApp_0100 + * @tc.desc: Is create by system app test. + */ +HWTEST_F(ContextImplTest, IsCreateBySystemApp_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + auto isSystemApp = contextImpl->IsCreateBySystemApp(); + EXPECT_EQ(isSystemApp, false); + + contextImpl->flags_ = CONTEXT_CREATE_BY_SYSTEM_APP; + isSystemApp = contextImpl->IsCreateBySystemApp(); + EXPECT_EQ(isSystemApp, true); + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: SetResourceManager_0100 + * @tc.name: SetResourceManager_0100 + * @tc.desc: Set Resource Manager test. + */ +HWTEST_F(ContextImplTest, SetResourceManager_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + EXPECT_EQ(contextImpl->GetResourceManager(), nullptr); + + auto resourceManager = std::make_shared(); + EXPECT_NE(resourceManager, nullptr); + + contextImpl->SetResourceManager(resourceManager); + EXPECT_NE(contextImpl->GetResourceManager(), nullptr); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: GetResourceManager_0100 + * @tc.name: GetResourceManager_0100 + * @tc.desc: Get Resource Manager test. + */ +HWTEST_F(ContextImplTest, GetResourceManager_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + EXPECT_EQ(contextImpl->GetResourceManager(), nullptr); + + auto parentContext = std::make_shared(); + EXPECT_NE(parentContext, nullptr); + contextImpl->SetParentContext(parentContext); + auto resourceManager = std::make_shared(); + EXPECT_NE(resourceManager, nullptr); + + parentContext->SetResourceManager(resourceManager); + EXPECT_NE(contextImpl->GetResourceManager(), nullptr); + + HILOG_INFO("%{public}s end.", __func__); +} + +/** + * @tc.number: GetBundleManager_0100 + * @tc.name: GetBundleManager_0100 + * @tc.desc: Get Bundle Manager test. + */ +HWTEST_F(ContextImplTest, GetBundleManager_0100, TestSize.Level1) +{ + HILOG_INFO("%{public}s start.", __func__); + auto contextImpl = std::make_shared(); + EXPECT_NE(contextImpl, nullptr); + EXPECT_NE(contextImpl->GetBundleManager(), nullptr); + HILOG_INFO("%{public}s end.", __func__); +} } // namespace AppExecFwk } diff --git a/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h new file mode 100644 index 0000000000..3eed1bbcf2 --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_mock_test.h @@ -0,0 +1,193 @@ +/* + * Copyright (c) 2022 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 MOCK_OHOS_ABILITY_FORM_MOCK_EXTENSION_H +#define MOCK_OHOS_ABILITY_FORM_MOCK_EXTENSION_H + +#include "form_mgr.h" +#include "form_mgr_interface.h" +#include +#include +#include + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; + +constexpr int32_t STARTABILITYVALUE = 0; + +class MockIFormMgr : public IRemoteStub { +public: + MockIFormMgr() = default; + ~MockIFormMgr() = default; + int32_t StartAbility(const Want &want, const sptr &callerToken) override + { + return STARTABILITYVALUE; + } + + int AddForm( + const int64_t formId, const Want &want, const sptr &callerToken, FormJsInfo &formInfo) override + { + return 0; + } + + int DeleteForm(const int64_t formId, const sptr &callerToken) override + { + return 0; + } + + int ReleaseForm(const int64_t formId, const sptr &callerToken, const bool delCache) override + { + return 0; + } + + int UpdateForm(const int64_t formId, const FormProviderData &formProviderData) override + { + return 0; + } + + int SetNextRefreshTime(const int64_t formId, const int64_t nextTime) override + { + return 0; + } + + ErrCode RequestPublishForm(Want &want, bool withFormBindingData, std::unique_ptr &formBindingData, + int64_t &formId) override + { + return 0; + } + + int LifecycleUpdate( + const std::vector &formIds, const sptr &callerToken, bool updateType) override + { + return 0; + } + + int RequestForm(const int64_t formId, const sptr &callerToken, const Want &want) override + { + return 0; + } + + int NotifyWhetherVisibleForms(const std::vector &formIds, const sptr &callerToken, + const int32_t formVisibleType) override + { + return 0; + } + + int CastTempForm(const int64_t formId, const sptr &callerToken) override + { + return 0; + } + + int DumpStorageFormInfos(std::string &formInfos) override + { + return 0; + } + + int DumpFormInfoByBundleName(const std::string &bundleName, std::string &formInfos) override + { + return 0; + } + + int DumpFormInfoByFormId(const std::int64_t formId, std::string &formInfo) override + { + return 0; + } + + int DumpFormTimerByFormId(const std::int64_t formId, std::string &isTimingService) override + { + return 0; + } + + int MessageEvent(const int64_t formId, const Want &want, const sptr &callerToken) override + { + return 0; + } + + int RouterEvent(const int64_t formId, Want &want, const sptr &callerToken) override + { + return 0; + } + + int DeleteInvalidForms( + const std::vector &formIds, const sptr &callerToken, int32_t &numFormsDeleted) override + { + return 0; + } + + int AcquireFormState(const Want &want, const sptr &callerToken, FormStateInfo &stateInfo) override + { + return 0; + } + + int NotifyFormsVisible( + const std::vector &formIds, bool isVisible, const sptr &callerToken) override + { + return 0; + } + + int NotifyFormsPrivacyProtected( + const std::vector &formIds, bool isProtected, const sptr &callerToken) override + { + return 0; + } + + int NotifyFormsEnableUpdate( + const std::vector &formIds, bool isEnableUpdate, const sptr &callerToken) override + { + return 0; + } + + int GetAllFormsInfo(std::vector &formInfos) override + { + return 0; + } + + int GetFormsInfoByApp(std::string &bundleName, std::vector &formInfos) override + { + return 0; + } + + int GetFormsInfoByModule( + std::string &bundleName, std::string &moduleName, std::vector &formInfos) override + { + return 0; + } + + int32_t GetFormsInfo(const FormInfoFilter &filter, std::vector &formInfos) override + { + return 0; + } + + bool IsRequestPublishFormSupported() override + { + return 0; + } + + int32_t ShareForm(int64_t formId, const std::string &deviceId, const sptr &callerToken, + int64_t requestCode) override + { + return 0; + } + + int32_t RecvFormShareInfoFromRemote(const FormShareInfo &info) override + { + return 0; + } +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_FORM_MOCK_EXTENSION_H \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_test.cpp new file mode 100644 index 0000000000..e51a4b00ac --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/form_extension_context_test.cpp @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2022 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 + +#define private public +#include "form_extension_context.h" +#undef private + +#include "form_extension_context_mock_test.h" +#include "form_mgr_errors.h" + +namespace OHOS { +namespace AppExecFwk { +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AppExecFwk; + +class FormExtensionContextTest : public testing::Test { +public: + std::shared_ptr formextension_ = nullptr; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void FormExtensionContextTest::SetUpTestCase(void) +{} + +void FormExtensionContextTest::TearDownTestCase(void) +{} + +void FormExtensionContextTest::SetUp(void) +{ + formextension_ = std::make_shared(); +} + +void FormExtensionContextTest::TearDown(void) +{} + +/** + * @tc.number: formExtensionContext_UpdateForm_0100 + * @tc.name: UpdateForm + * @tc.desc: Verify whether UpdateForm is called normally (formID is less than 0). + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0100 start"; + FormProviderData formProviderData; + std::string inputTestJsonStr = "{" + " \"deviceType\": \"PHONE\", " + " \"fontScale\": 1.0 , " + " \"fontScalse\": 1.0 " + "}"; + formProviderData.SetDataString(inputTestJsonStr); + int32_t formId = -1; + auto result = formextension_->UpdateForm(formId, formProviderData); + EXPECT_EQ(ERR_APPEXECFWK_FORM_INVALID_PARAM, result); + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0100 end"; +} + +/** + * @tc.number: formExtensionContext_UpdateForm_0200 + * @tc.name: UpdateForm + * @tc.desc: Verify whether UpdateForm is called normally (the formProviderData parameter is not set). + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0200 start"; + FormProviderData formProviderData; + int32_t formId = 200; + auto result = formextension_->UpdateForm(formId, formProviderData); + EXPECT_EQ(ERR_APPEXECFWK_FORM_INVALID_PARAM, result); + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0200 end"; +} + +/** + * @tc.number: formExtensionContext_UpdateForm_0300 + * @tc.name: UpdateForm + * @tc.desc: Verify that the setting status is IN_ RECOVERING returned result execution exception. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0300, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0300 start"; + FormMgr::SetRecoverStatus(AppExecFwk::Constants::IN_RECOVERING); + FormProviderData formProviderData; + std::string inputTestJsonStr = "{" + " \"deviceType\": \"PHONE\", " + " \"fontScale\": 1.0 , " + " \"fontScalse\": 1.0 " + "}"; + formProviderData.SetDataString(inputTestJsonStr); + int32_t formId = 200; + auto result = formextension_->UpdateForm(formId, formProviderData); + EXPECT_EQ(ERR_APPEXECFWK_FORM_IN_RECOVER, result); + FormMgr::SetRecoverStatus(Constants::NOT_IN_RECOVERY); + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0300 end"; +} + +/** + * @tc.number: formExtensionContext_UpdateForm_0400 + * @tc.name: UpdateForm + * @tc.desc: Verify whether calling UpdateForm normally will trigger a mock (parameters are normal). + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_UpdateForm_0400, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0400 start"; + FormProviderData formProviderData; + std::string inputTestJsonStr = "{" + " \"deviceType\": \"PHONE\", " + " \"fontScale\": 1.0 , " + " \"fontScalse\": 1.0 " + "}"; + formProviderData.SetDataString(inputTestJsonStr); + int32_t formId = 200; + sptr mockIFormMgr = new (std::nothrow) MockIFormMgr(); + OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(mockIFormMgr); + auto result = formextension_->UpdateForm(formId, formProviderData); + EXPECT_EQ(ERR_OK, result); + OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(nullptr); + GTEST_LOG_(INFO) << "formExtensionContext_UpdateForm_0400 end"; +} + +/** + * @tc.number: formExtensionContext_GetAbilityInfo_0100 + * @tc.name: SetAbilityInfo/GetAbilityInfo + * @tc.desc: Verify whether the SetAbilityInfo setting content and GetAbilityInformation get. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0100 start"; + std::shared_ptr abilityInfo = std::make_shared(); + EXPECT_EQ(formextension_->GetAbilityInfo(), nullptr); + abilityInfo->name = "Ability"; + formextension_->SetAbilityInfo(abilityInfo); + abilityInfo = formextension_->GetAbilityInfo(); + EXPECT_STREQ(abilityInfo->name.c_str(), "Ability"); + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0100 end"; +} + +/** + * @tc.number: formExtensionContext_GetAbilityInfo_0200 + * @tc.name: SetAbilityInfo/GetAbilityInfo + * @tc.desc: Verify that SetAbilityInfo is set to null and GetAbilityInformation gets. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfo_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0200 start"; + std::shared_ptr abilityInfo = std::make_shared(); + EXPECT_EQ(formextension_->GetAbilityInfo(), nullptr); + abilityInfo->name = ""; + formextension_->SetAbilityInfo(abilityInfo); + abilityInfo = formextension_->GetAbilityInfo(); + EXPECT_STREQ(abilityInfo->name.c_str(), ""); + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfo_0200 end"; +} + +/** + * @tc.number: formExtensionContext_SetAbilityInfo_0100 + * @tc.name: SetAbilityInfo + * @tc.desc: Verify that the SetAbilityInfo parameter is null and exit without exception. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_SetAbilityInfo_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_SetAbilityInfo_0100 start"; + std::shared_ptr abilityInfo = nullptr; + formextension_->SetAbilityInfo(abilityInfo); + EXPECT_EQ(abilityInfo, nullptr); + GTEST_LOG_(INFO) << "formExtensionContext_SetAbilityInfo_0100 end"; +} + +/** + * @tc.number: formExtensionContext_StartAbility_0100 + * @tc.name: StartAbility + * @tc.desc: Verify that StartAbility return is not equal to ERR_OK. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_StartAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0100 start"; + AAFwk::Want want; + ElementName element("device", "ohos.samples", "form_extension_context_test"); + want.SetElement(element); + EXPECT_TRUE(formextension_->StartAbility(want) != ERR_OK); + GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0100 end"; +} + +/** + * @tc.number: formExtensionContext_StartAbility_0200 + * @tc.name: StartAbility + * @tc.desc: Verify that StartAbility returns equal to ERR_OK. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_StartAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0200 start"; + AAFwk::Want want; + sptr mockIFormMgr = new (std::nothrow) MockIFormMgr(); + OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(mockIFormMgr); + ElementName element("device", "ohos.samples", "form_extension_context_test"); + want.SetElement(element); + EXPECT_TRUE(formextension_->StartAbility(want) == ERR_OK); + OHOS::AppExecFwk::FormMgr::GetInstance().SetFormMgrService(nullptr); + GTEST_LOG_(INFO) << "formExtensionContext_StartAbility_0200 end"; +} + +/** + * @tc.number: formExtensionContext_GetAbilityInfoType_0100 + * @tc.name: GetAbilityInfoType + * @tc.desc: Verify whether GetAbilityInfoType gets the unset information. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfoType_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0100 start"; + EXPECT_EQ(OHOS::AppExecFwk::AbilityType::UNKNOWN, formextension_->GetAbilityInfoType()); + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0100 end"; +} + +/** + * @tc.number: formExtensionContext_GetAbilityInfoType_0200 + * @tc.name: GetAbilityInfoType + * @tc.desc: Verify whether the setting information GetAbilityInfoType gets. + */ +HWTEST_F(FormExtensionContextTest, formExtensionContext_GetAbilityInfoType_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0200 start"; + EXPECT_EQ(OHOS::AppExecFwk::AbilityType::UNKNOWN, formextension_->GetAbilityInfoType()); + std::shared_ptr abilityInfo = std::make_shared(); + abilityInfo->type = OHOS::AppExecFwk::AbilityType::SERVICE; + formextension_->SetAbilityInfo(abilityInfo); + EXPECT_EQ(abilityInfo->type, formextension_->GetAbilityInfoType()); + GTEST_LOG_(INFO) << "formExtensionContext_GetAbilityInfoType_0200 end"; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/mock_resource_manager.h b/test/unittest/frameworks_kits_appkit_native_test/mock_resource_manager.h new file mode 100644 index 0000000000..79911232a4 --- /dev/null +++ b/test/unittest/frameworks_kits_appkit_native_test/mock_resource_manager.h @@ -0,0 +1,305 @@ +/* + * Copyright (c) 2022 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 "resource_manager.h" + +namespace OHOS { +namespace Global { +namespace Resource { +class MockResourceManager : public ResourceManager { +public: +MockResourceManager *CreateMockResourceManager() +{ + MockResourceManager *impl = new (std::nothrow) MockResourceManager; + return impl; +} + +~MockResourceManager() {} + +bool AddResource(const char *path) +{ + return true; +} + +bool AddResource(const std::string &path, const std::vector &overlayPaths) +{ + return true; +} + +RState UpdateResConfig(ResConfig &resConfig) +{ + return SUCCESS; +} + +void GetResConfig(ResConfig &resConfig) {} + +RState GetStringById(uint32_t id, std::string &outValue) +{ + outValue = "ENTRY"; + return SUCCESS; +} + +RState GetStringByName(const char *name, std::string &outValue) +{ + outValue = "bgmode_test"; + return SUCCESS; +} + +RState GetStringFormatById(std::string &outValue, uint32_t id, ...) +{ + return SUCCESS; +} + +RState GetStringFormatByName(std::string &outValue, const char *name, ...) +{ + return SUCCESS; +} + +RState GetStringArrayById(uint32_t id, std::vector &outValue) +{ + return SUCCESS; +} + +RState GetStringArrayByName(const char *name, std::vector &outValue) +{ + return SUCCESS; +} + +RState GetPatternById(uint32_t id, std::map &outValue) +{ + return SUCCESS; +} + +RState GetPatternByName(const char *name, std::map &outValue) +{ + return SUCCESS; +} + +RState GetPluralStringById(uint32_t id, int32_t quantity, std::string &outValue) +{ + return SUCCESS; +} + +RState GetPluralStringByName(const char *name, int32_t quantity, std::string &outValue) +{ + return SUCCESS; +} + +RState GetPluralStringByIdFormat(std::string &outValue, uint32_t id, int32_t quantity, ...) +{ + return SUCCESS; +} + +RState GetPluralStringByNameFormat(std::string &outValue, const char *name, int32_t quantity, ...) +{ + return SUCCESS; +} + +RState GetThemeById(uint32_t id, std::map &outValue) +{ + return SUCCESS; +} + +RState GetThemeByName(const char *name, std::map &outValue) +{ + return SUCCESS; +} + +RState GetBooleanById(uint32_t id, bool &outValue) +{ + return SUCCESS; +} + +RState GetBooleanByName(const char *name, bool &outValue) +{ + return SUCCESS; +} + +RState GetIntegerById(uint32_t id, int32_t &outValue) +{ + return SUCCESS; +} + +RState GetIntegerByName(const char *name, int32_t &outValue) +{ + return SUCCESS; +} + +RState GetFloatById(uint32_t id, float &outValue) +{ + return SUCCESS; +} + +RState GetFloatById(uint32_t id, float &outValue, std::string &unit) +{ + return SUCCESS; +} + +RState GetFloatByName(const char *name, float &outValue) +{ + return SUCCESS; +} + +RState GetFloatByName(const char *name, float &outValue, std::string &unit) +{ + return SUCCESS; +} + +RState GetIntArrayById(uint32_t id, std::vector &outValue) +{ + return SUCCESS; +} + +RState GetIntArrayByName(const char *name, std::vector &outValue) +{ + return SUCCESS; +} + +RState GetColorById(uint32_t id, uint32_t &outValue) +{ + return SUCCESS; +} + +RState GetColorByName(const char *name, uint32_t &outValue) +{ + return SUCCESS; +} + +RState GetProfileById(uint32_t id, std::string &outValue) +{ + return SUCCESS; +} + +RState GetProfileByName(const char *name, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaById(uint32_t id, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaById(uint32_t id, uint32_t density, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaByName(const char *name, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaByName(const char *name, uint32_t density, std::string &outValue) +{ + return SUCCESS; +} + +RState GetRawFilePathByName(const std::string &name, std::string &outValue) +{ + return SUCCESS; +} + +RState GetRawFileDescriptor(const std::string &name, RawFileDescriptor &descriptor) +{ + return SUCCESS; +} + +RState CloseRawFileDescriptor(const std::string &name) +{ + return SUCCESS; +} + +RState GetMediaBase64ByIdData(uint32_t id, uint32_t density, std::string &base64Data) +{ + return SUCCESS; +} + +RState GetMediaBase64ByNameData(const char *name, uint32_t density, std::string &base64Data) +{ + return SUCCESS; +} + +RState GetMediaDataById(uint32_t id, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetMediaDataByName(const char *name, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetMediaDataById(uint32_t id, uint32_t density, size_t &len, + std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetMediaDataByName(const char *name, uint32_t density, size_t &len, + std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetMediaBase64DataById(uint32_t id, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaBase64DataByName(const char *name, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaBase64DataById(uint32_t id, uint32_t density, std::string &outValue) +{ + return SUCCESS; +} + +RState GetMediaBase64DataByName(const char *name, uint32_t density, std::string &outValue) +{ + return SUCCESS; +} + +RState GetProfileDataById(uint32_t id, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetProfileDataByName(const char *name, size_t &len, std::unique_ptr &outValue) +{ + return SUCCESS; +} + +RState GetRawFileFromHap(const std::string& rawFileName, size_t& len, + std::unique_ptr& outValue) +{ + return SUCCESS; +} + +RState GetRawFileDescriptorFromHap(const std::string &rawFileName, RawFileDescriptor &descriptor) +{ + return SUCCESS; +} + +RState IsLoadHap(std::string& hapPath) +{ + return SUCCESS; +} +}; +} // namespace Resource +} // namespace Global +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp index b297d2054c..8da84a0f25 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/watchdog_test.cpp @@ -41,6 +41,7 @@ public: std::shared_ptr mockHandler_ = nullptr; std::shared_ptr runner_ = nullptr; std::shared_ptr watchdog_ = nullptr; + std::shared_ptr mainHandlerDumper_; static void SetUpTestCase(void); static void TearDownTestCase(void); void SetUp(); @@ -60,32 +61,34 @@ void WatchdogTest::SetUp(void) watchdog_ = std::make_shared(); watchdog_->Init(mockHandler_); + mainHandlerDumper_ = std::make_shared(); } void WatchdogTest::TearDown(void) { watchdog_->Stop(); + mainHandlerDumper_ = nullptr; } /** - * @tc.number: AppExecFwk_Watchdog_IsReportEvent_0001 + * @tc.number: AppExecFwk_watchdog_IsReportEvent_0001 * @tc.name: IsReportEvent * @tc.desc: Test the abnormal state of IsReportEvent. * @tc.require: issueI5MGFU */ -HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0001, Function | MediumTest | Level3) +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0001, Function | MediumTest | Level3) { bool ret = watchdog_->IsReportEvent(); EXPECT_TRUE(ret); } /** - * @tc.number: AppExecFwk_Watchdog_IsReportEvent_0002 + * @tc.number: AppExecFwk_watchdog_IsReportEvent_0002 * @tc.name: IsReportEvent * @tc.desc: Test the change state of IsReportEvent. * @tc.require: issueI5MGFU */ -HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0002, Function | MediumTest | Level3) +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_IsReportEvent_0002, Function | MediumTest | Level3) { watchdog_->SetAppMainThreadState(true); watchdog_->AllowReportEvent(); @@ -94,12 +97,12 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_IsReportEvent_0002, Function | Medium } /** - * @tc.number: AppExecFwk_Watchdog_ReportEvent_0001 + * @tc.number: AppExecFwk_watchdog_ReportEvent_0001 * @tc.name: ReportEvent * @tc.desc: Test ReportEvent. * @tc.require: I5UL6H */ -HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0001, Function | MediumTest | Level3) +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0001, Function | MediumTest | Level3) { // be ready for ReportEvent watchdog_->lastWatchTime_ = std::chrono::duration_cast(std::chrono:: @@ -115,12 +118,12 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0001, Function | MediumTe } /** - * @tc.number: AppExecFwk_Watchdog_ReportEvent_0002 + * @tc.number: AppExecFwk_watchdog_ReportEvent_0002 * @tc.name: ReportEvent * @tc.desc: Test ReportEvent. * @tc.require: I5UL6H */ -HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0002, Function | MediumTest | Level3) +HWTEST_F(WatchdogTest, AppExecFwk_watchdog_ReportEvent_0002, Function | MediumTest | Level3) { // be ready for ReportEvent watchdog_->lastWatchTime_ = std::chrono::duration_cast(std::chrono:: @@ -134,5 +137,341 @@ HWTEST_F(WatchdogTest, AppExecFwk_Watchdog_ReportEvent_0002, Function | MediumTe watchdog_->ReportEvent(); EXPECT_TRUE(1); } + +/** + * @tc.number: WatchdogTest_Init_001 + * @tc.name: Init + * @tc.desc: Verify that function Init. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Init_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Init_001 start"; + std::shared_ptr eventHandler = std::make_shared(); + watchdog_->Init(eventHandler); + EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr); + GTEST_LOG_(INFO) << "WatchdogTest_Init_001 end"; +} + +/** + * @tc.number: WatchdogTest_Init_002 + * @tc.name: Init + * @tc.desc: Verify that function Init. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Init_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Init_002 start"; + std::shared_ptr eventHandler = nullptr; + watchdog_->lastWatchTime_ = 2; + watchdog_->Init(eventHandler); + EXPECT_EQ(watchdog_->lastWatchTime_, 0); + GTEST_LOG_(INFO) << "WatchdogTest_Init_002 end"; +} + +/** + * @tc.number: WatchdogTest_Stop_001 + * @tc.name: Stop + * @tc.desc: Verify that function Init. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Stop_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 start"; + std::shared_ptr eventHandler = std::make_shared(); + watchdog_->Init(eventHandler); + EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr); + watchdog_->Stop(); + EXPECT_TRUE(watchdog_->appMainHandler_ == nullptr); + GTEST_LOG_(INFO) << "WatchdogTest_Stop_001 end"; +} + +/** + * @tc.number: WatchdogTest_Stop_002 + * @tc.name: Stop + * @tc.desc: Verify that function Stop. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Stop_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 start"; + std::shared_ptr eventHandler = nullptr; + watchdog_->Stop(); + EXPECT_TRUE(watchdog_->stopWatchdog_); + GTEST_LOG_(INFO) << "WatchdogTest_Stop_002 end"; +} + +/** + * @tc.number: WatchdogTest_SetApplicationInfo_001 + * @tc.name: SetApplicationInfo + * @tc.desc: Verify that function SetApplicationInfo. + */ +HWTEST_F(WatchdogTest, WatchdogTest_SetApplicationInfo_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_SetApplicationInfo_001 start"; + std::shared_ptr applicationInfo = std::make_shared(); + EXPECT_TRUE(watchdog_->applicationInfo_ == nullptr); + watchdog_->SetApplicationInfo(applicationInfo); + EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr); + GTEST_LOG_(INFO) << "WatchdogTest_SetApplicationInfo_001 end"; +} + +/** + * @tc.number: WatchdogTest_SetAppMainThreadState_001 + * @tc.name: SetAppMainThreadState + * @tc.desc: Verify that function SetAppMainThreadState. + */ +HWTEST_F(WatchdogTest, WatchdogTest_SetAppMainThreadState_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 start"; + bool appMainThreadState = true; + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + watchdog_->SetAppMainThreadState(appMainThreadState); + EXPECT_TRUE(watchdog_->appMainThreadIsAlive_); + GTEST_LOG_(INFO) << "WatchdogTest_SetAppMainThreadState_001 end"; +} + +/** + * @tc.number: WatchdogTest_SetBackgroundStatus_001 + * @tc.name: SetBackgroundStatus + * @tc.desc: Verify that function SetBackgroundStatus. + */ +HWTEST_F(WatchdogTest, WatchdogTest_SetBackgroundStatus_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 start"; + bool isInBackground = true; + EXPECT_FALSE(watchdog_->isInBackground_); + watchdog_->SetBackgroundStatus(isInBackground); + EXPECT_TRUE(watchdog_->isInBackground_); + GTEST_LOG_(INFO) << "WatchdogTest_SetBackgroundStatus_001 end"; +} + +/** + * @tc.number: WatchdogTest_AllowReportEvent_001 + * @tc.name: AllowReportEvent + * @tc.desc: Verify that function AllowReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_AllowReportEvent_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 start"; + watchdog_->needReport_ = false; + watchdog_->AllowReportEvent(); + EXPECT_TRUE(watchdog_->needReport_); + GTEST_LOG_(INFO) << "WatchdogTest_AllowReportEvent_001 end"; +} + +/** + * @tc.number: WatchdogTest_IsReportEvent_001 + * @tc.name: IsReportEvent + * @tc.desc: Verify that function IsReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_001 start"; + auto result = watchdog_->IsReportEvent(); + EXPECT_TRUE(result); + GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_001 end"; +} + +/** + * @tc.number: WatchdogTest_IsReportEvent_002 + * @tc.name: IsReportEvent + * @tc.desc: Verify that function IsReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_IsReportEvent_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_002 start"; + bool appMainThreadState = true; + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + watchdog_->SetAppMainThreadState(appMainThreadState); + auto result = watchdog_->IsReportEvent(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "WatchdogTest_IsReportEvent_002 end"; +} + +/** + * @tc.number: WatchdogTest_IsStopwatchdog_001 + * @tc.name: IsStopWatchdog + * @tc.desc: Verify that function IsStopWatchdog. + */ +HWTEST_F(WatchdogTest, WatchdogTest_IsStopwatchdog_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 start"; + auto result = watchdog_->IsStopWatchdog(); + EXPECT_FALSE(result); + GTEST_LOG_(INFO) << "WatchdogTest_IsStopwatchdog_001 end"; +} + +/** + * @tc.number: WatchdogTest_Timer_001 + * @tc.name: Timer + * @tc.desc: Verify that function Timer. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Timer_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 start"; + watchdog_->needReport_ = false; + watchdog_->Timer(); + EXPECT_TRUE(!watchdog_->needReport_); + GTEST_LOG_(INFO) << "WatchdogTest_Timer_001 end"; +} + +/** + * @tc.number: WatchdogTest_Timer_002 + * @tc.name: Timer + * @tc.desc: Verify that function Timer. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Timer_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 start"; + bool isInBackground = true; + EXPECT_FALSE(watchdog_->isInBackground_); + watchdog_->SetBackgroundStatus(isInBackground); + watchdog_->Timer(); + EXPECT_TRUE(watchdog_->appMainThreadIsAlive_); + GTEST_LOG_(INFO) << "WatchdogTest_Timer_002 end"; +} + +/** + * @tc.number: WatchdogTest_Timer_003 + * @tc.name: Timer + * @tc.desc: Verify that function Timer. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Timer_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 start"; + bool appMainThreadState = true; + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + watchdog_->SetAppMainThreadState(appMainThreadState); + watchdog_->Timer(); + EXPECT_TRUE(watchdog_->needReport_); + EXPECT_FALSE(watchdog_->isInBackground_); + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + GTEST_LOG_(INFO) << "WatchdogTest_Timer_003 end"; +} + +/** + * @tc.number: WatchdogTest_Timer_004 + * @tc.name: Timer + * @tc.desc: Verify that function Timer. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Timer_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 start"; + bool appMainThreadState = true; + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + watchdog_->SetAppMainThreadState(appMainThreadState); + watchdog_->appMainHandler_ = std::make_shared(); + watchdog_->Timer(); + EXPECT_TRUE(watchdog_->needReport_); + EXPECT_FALSE(watchdog_->isInBackground_); + EXPECT_FALSE(watchdog_->appMainThreadIsAlive_); + EXPECT_TRUE(watchdog_->appMainHandler_ != nullptr); + GTEST_LOG_(INFO) << "WatchdogTest_Timer_004 end"; +} + +/** + * @tc.number: WatchdogTest_ReportEvent_003 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_001 start"; + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->lastWatchTime_ != 0); + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_001 end"; +} + +/** + * @tc.number: WatchdogTest_ReportEvent_004 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 start"; + watchdog_->lastWatchTime_ = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->applicationInfo_ == nullptr); + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_002 end"; +} + +/** + * @tc.number: WatchdogTest_ReportEvent_005 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 start"; + watchdog_->lastWatchTime_ = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + watchdog_->applicationInfo_ = std::make_shared(); + watchdog_->needReport_ = false; + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr); + EXPECT_TRUE(watchdog_->needReport_ == false); + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_003 end"; +} + +/** + * @tc.number: WatchdogTest_ReportEvent_006 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_006, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_004 start"; + watchdog_->lastWatchTime_ = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + watchdog_->applicationInfo_ = std::make_shared(); + watchdog_->isSixSecondEvent_ = true; + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr); + EXPECT_TRUE(watchdog_->needReport_ == false); + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_004 end"; +} + +/** + * @tc.number: WatchdogTest_ReportEvent_007 + * @tc.name: ReportEvent + * @tc.desc: Verify that function ReportEvent. + */ +HWTEST_F(WatchdogTest, WatchdogTest_ReportEvent_007, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 start"; + watchdog_->lastWatchTime_ = + std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + watchdog_->applicationInfo_ = std::make_shared(); + watchdog_->ReportEvent(); + EXPECT_TRUE(watchdog_->applicationInfo_ != nullptr); + EXPECT_TRUE(watchdog_->isSixSecondEvent_ == true); + GTEST_LOG_(INFO) << "WatchdogTest_ReportEvent_005 end"; +} + +/** + * @tc.number: WatchdogTest_Dump_001 + * @tc.name: Dump + * @tc.desc: Verify that function Dump. + */ +HWTEST_F(WatchdogTest, WatchdogTest_Dump_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_Dump_001 start"; + std::string message = "message"; + mainHandlerDumper_->dumpInfo = "dump"; + mainHandlerDumper_->Dump(message); + EXPECT_EQ(mainHandlerDumper_->GetDumpInfo(), "dumpmessage"); + GTEST_LOG_(INFO) << "WatchdogTest_Dump_001 end"; +} + +/** + * @tc.number: WatchdogTest_GetTag_001 + * @tc.name: GetTag + * @tc.desc: Verify that function GetTag. + */ +HWTEST_F(WatchdogTest, WatchdogTest_GetTag_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "WatchdogTest_GetTag_001 start"; + EXPECT_EQ(mainHandlerDumper_->GetTag(), ""); + GTEST_LOG_(INFO) << "WatchdogTest_GetTag_001 end"; +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/mission_data_storage_test/BUILD.gn b/test/unittest/mission_data_storage_test/BUILD.gn index a7761ad97b..514f7f4fd0 100755 --- a/test/unittest/mission_data_storage_test/BUILD.gn +++ b/test/unittest/mission_data_storage_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("mission_data_storage_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "mission_data_storage_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("mission_data_storage_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("mission_data_storage_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/mission_info_mgr_test/BUILD.gn b/test/unittest/mission_info_mgr_test/BUILD.gn index bc0238069d..658121198e 100755 --- a/test/unittest/mission_info_mgr_test/BUILD.gn +++ b/test/unittest/mission_info_mgr_test/BUILD.gn @@ -26,7 +26,6 @@ ohos_unittest("mission_info_mgr_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "mission_info_mgr_test.cpp", # add mock file ] @@ -42,6 +41,7 @@ ohos_unittest("mission_info_mgr_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +52,6 @@ ohos_unittest("mission_info_mgr_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "bundle_framework:appexecfwk_base", "c_utils:utils", "common_event_service:cesfwk_innerkits", diff --git a/test/unittest/mission_info_mgr_test/mission_info_mgr_test.cpp b/test/unittest/mission_info_mgr_test/mission_info_mgr_test.cpp index 1e03fd589a..e76806d7a6 100755 --- a/test/unittest/mission_info_mgr_test/mission_info_mgr_test.cpp +++ b/test/unittest/mission_info_mgr_test/mission_info_mgr_test.cpp @@ -388,44 +388,50 @@ HWTEST_F(MissionInfoMgrTest, FindReusedMissionInfo_001, TestSize.Level1) int userId = 0; missionInfoMgr->Init(userId); InnerMissionInfo missionInfo; - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("", "", missionInfo)); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("", "", false, missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfo.missionInfo.id = 1; missionInfo.launchMode = static_cast(AppExecFwk::LaunchMode::STANDARD); missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.launchMode = static_cast(AppExecFwk::LaunchMode::SINGLETON); missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.missionName = "test"; missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.launchMode = static_cast(AppExecFwk::LaunchMode::SPECIFIED); missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.missionName = "test1"; missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.missionName = "test"; missionInfo.specifiedFlag = "flag"; missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); missionInfoMgr->missionInfoList_.clear(); missionInfo.specifiedFlag = ""; missionInfo.launchMode = 1000; missionInfoMgr->missionInfoList_.push_back(missionInfo); - EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", missionInfo)); + EXPECT_FALSE(missionInfoMgr->FindReusedMissionInfo("test", "", false, missionInfo)); + + missionInfoMgr->missionInfoList_.clear(); + missionInfo.missionName = "test"; + missionInfo.launchMode = static_cast(AppExecFwk::LaunchMode::STANDARD); + missionInfoMgr->missionInfoList_.push_back(missionInfo); + EXPECT_TRUE(missionInfoMgr->FindReusedMissionInfo("test", "", true, missionInfo)); } /* diff --git a/test/unittest/mission_list_manager_test/BUILD.gn b/test/unittest/mission_list_manager_test/BUILD.gn index 67c32e2ede..17c5456080 100644 --- a/test/unittest/mission_list_manager_test/BUILD.gn +++ b/test/unittest/mission_list_manager_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("mission_list_manager_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "mission_list_manager_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("mission_list_manager_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("mission_list_manager_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/mission_listener_proxy_test/BUILD.gn b/test/unittest/mission_listener_proxy_test/BUILD.gn index 53a2e90888..e042c78034 100755 --- a/test/unittest/mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/mission_listener_proxy_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("mission_listener_proxy_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "mission_listener_proxy_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("mission_listener_proxy_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +52,6 @@ ohos_unittest("mission_listener_proxy_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn index 459c9a4b8f..2afd4c6b7e 100755 --- a/test/unittest/remote_mission_listener_proxy_test/BUILD.gn +++ b/test/unittest/remote_mission_listener_proxy_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("remote_mission_listener_proxy_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "remote_mission_listener_proxy_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("remote_mission_listener_proxy_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +52,6 @@ ohos_unittest("remote_mission_listener_proxy_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/service_extension_context_test/BUILD.gn b/test/unittest/service_extension_context_test/BUILD.gn index cbf8646fa1..0fa3a18e29 100644 --- a/test/unittest/service_extension_context_test/BUILD.gn +++ b/test/unittest/service_extension_context_test/BUILD.gn @@ -27,7 +27,6 @@ ohos_unittest("service_extension_context_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "service_extension_context_test.cpp", # add mock file ] @@ -46,11 +45,13 @@ ohos_unittest("service_extension_context_test") { "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_native_path}/appkit:app_context", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", "${ability_runtime_test_path}/unittest:abilityms_test_source", "//foundation/ability/ability_runtime/frameworks/native/ability/native:service_extension", + "//third_party/googletest:gmock_main", "//third_party/googletest:gtest_main", ] @@ -60,7 +61,6 @@ ohos_unittest("service_extension_context_test") { "ability_runtime:ability_context_native", "ability_runtime:ability_manager", "ability_runtime:runtime", - "access_token:libaccesstoken_sdk", "c_utils:utils", "eventhandler:libeventhandler", "hitrace_native:hitrace_meter", diff --git a/test/unittest/service_extension_context_test/ability_manager_stub_mock.h b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h new file mode 100644 index 0000000000..a3c10dd35a --- /dev/null +++ b/test/unittest/service_extension_context_test/ability_manager_stub_mock.h @@ -0,0 +1,363 @@ +/* + * Copyright (c) 2022 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 UNITTEST_OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_STUB_MOCK_TEST_H +#define UNITTEST_OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_STUB_MOCK_TEST_H +#include +#include +#include +#include "ability_manager_interface.h" + +namespace OHOS { +namespace AAFwk { +class AbilityManagerStubTestMock : public IRemoteStub { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"IAbilityManagerMock"); + + AbilityManagerStubTestMock() : code_(0) + {} + virtual ~AbilityManagerStubTestMock() + {} + + MOCK_METHOD4(SendRequest, int(uint32_t, MessageParcel&, MessageParcel&, MessageOption&)); + + int InvokeSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + { + code_ = code; + + return 0; + } + + int InvokeErrorSendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + { + code_ = code; + return UNKNOWN_ERROR; + } + + int code_ = 0; + + virtual int StartAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) + { + return 0; + } + + virtual int StartAbility(const Want& want, + const AbilityStartSetting& abilityStartSetting, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE, + int requestCode = DEFAULT_INVAL_VALUE) + { + return 0; + } + + virtual int StartAbility( + const Want& want, + const StartOptions& startOptions, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE, + int requestCode = DEFAULT_INVAL_VALUE) + { + return 0; + } + + virtual int TerminateAbility(const sptr& token, int resultCode, const Want* resultWant = nullptr) + { + return 0; + } + int CloseAbility(const sptr& token, int resultCode = DEFAULT_INVAL_VALUE, + const Want* resultWant = nullptr) override + { + return 0; + } + int MinimizeAbility(const sptr& token, bool fromUser) override + { + return 0; + } + + virtual int ConnectAbility( + const Want& want, + const sptr& connect, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE) + { + return 0; + } + + sptr AcquireDataAbility( + const Uri& uri, bool tryBind, const sptr& callerToken) override + { + return nullptr; + } + + virtual int ReleaseDataAbility(sptr dataAbilityScheduler, const sptr& callerToken) + { + return 0; + } + + virtual int DisconnectAbility(const sptr& connect) + { + return 0; + } + + virtual int AttachAbilityThread(const sptr& scheduler, const sptr& token) + { + return 0; + } + + virtual int AbilityTransitionDone(const sptr& token, int state, const PacMap& saveData) + { + return 0; + } + + virtual int ScheduleConnectAbilityDone(const sptr& token, const sptr& remoteObject) + { + return 0; + } + + virtual int ScheduleDisconnectAbilityDone(const sptr& token) + { + return 0; + } + + virtual int ScheduleCommandAbilityDone(const sptr& token) + { + return 0; + } + + virtual void DumpState(const std::string& args, std::vector& state) + {} + + virtual void DumpSysState( + const std::string& args, std::vector& info, bool isClient, bool isUserID, int UserID) + {} + + virtual int TerminateAbilityResult(const sptr& token, int startId) + { + return 0; + } + + virtual int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE) + { + return 0; + } + + virtual int KillProcess(const std::string& bundleName) + { + return 0; + } + + virtual int UninstallApp(const std::string& bundleName, int32_t uid) + { + return 0; + } + + int32_t GetMissionIdByToken(const sptr& token) override + { + return 0; + } + + int ClearUpApplicationData(const std::string& bundleName) override + { + return 0; + } + + int StartUser(int userId) override + { + return 0; + } + + int StopUser(int userId, const sptr& callback) override + { + return 0; + } + int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } + int RegisterMissionListener(const std::string& deviceId, + const sptr& listener) override + { + return 0; + } + int UnRegisterMissionListener(const std::string& deviceId, + const sptr& listener) override + { + return 0; + } + int ReleaseCall(const sptr& connect, + const AppExecFwk::ElementName& element) override + { + return 0; + } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, + MissionSnapshot& snapshot, bool isLowResolution) + { + return 0; + } + + virtual void UpdateMissionSnapShot(const sptr& token) + { + return; + } + + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } + + int RegisterWindowManagerServiceHandler(const sptr& handler) override + { + return 0; + } + + void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} + + int SetAbilityController(const sptr& abilityController, + bool imAStabilityTest) override + { + return 0; + } + + bool IsRunningInStabilityTest() override + { + return true; + } + + int SendANRProcessID(int pid) override + { + return 0; + } + + int SetMissionIcon(const sptr& token, + const std::shared_ptr& icon) override + { + if (!token || !icon) { + return -1; + } + + return 0; + } + + MOCK_METHOD2(TerminateAbilityByCaller, int(const sptr& callerToken, int requestCode)); + MOCK_METHOD4(StartAbility, int(const Want& want, const sptr& callerToken, + int32_t userId, int requestCode)); + MOCK_METHOD2( + GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); + MOCK_METHOD2(SendWantSender, int(const sptr& target, const SenderInfo& senderInfo)); + MOCK_METHOD1(CancelWantSender, void(const sptr& sender)); + MOCK_METHOD1(GetPendingWantUid, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantUserId, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantBundleName, std::string(const sptr& target)); + MOCK_METHOD1(GetPendingWantCode, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantType, int(const sptr& target)); + MOCK_METHOD2(RegisterCancelListener, void(const sptr& sender, const sptr& receiver)); + MOCK_METHOD2(UnregisterCancelListener, void(const sptr& sender, const sptr& receiver)); + MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); + MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callBack, AAFwk::WantParams& wantParams)); + MOCK_METHOD3(ContinueAbility, int(const std::string& deviceId, int32_t missionId, uint32_t versionCode)); + MOCK_METHOD3(NotifyCompleteContinuation, void(const std::string& deviceId, int32_t sessionId, bool isSuccess)); + + MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); + MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId)); + MOCK_METHOD1(RegisterMissionListener, int(const sptr& listener)); + MOCK_METHOD1(UnRegisterMissionListener, int(const sptr& listener)); + MOCK_METHOD3( + GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector& missionInfos)); + MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo& missionInfo)); + MOCK_METHOD1(CleanMission, int(int32_t missionId)); + MOCK_METHOD0(CleanAllMissions, int()); + MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); + MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions)); + MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); + MOCK_METHOD2(GetWantSenderInfo, int(const sptr& target, std::shared_ptr& info)); + MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); + MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); + MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); +#ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + MOCK_METHOD0(BlockAmsService, int()); + MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); +#endif + + int SendResultToAbility(int requestCode, int resultCode, Want& resultWant) override + { + return 0; + } + + int StartAbilityByCall( + const Want& want, const sptr& connect, const sptr& callerToken) override + { + return 0; + } + + void CallRequestDone(const sptr &token, const sptr &callStub) override + { + return; + } + + int StartUserTest(const Want &want, const sptr &observer) override + { + return 0; + } + + int FinishUserTest( + const std::string& msg, const int64_t& resultCode, const std::string& bundleName) override + { + return 0; + } + + int GetTopAbility(sptr& token) override + { + return 0; + } + + int DelegatorDoAbilityForeground(const sptr& token) override + { + return 0; + } + + int DelegatorDoAbilityBackground(const sptr& token) override + { + return 0; + } + + int DoAbilityForeground(const sptr& token, uint32_t flag) override + { + return 0; + } + + int DoAbilityBackground(const sptr& token, uint32_t flag) override + { + return 0; + } + +#ifdef ABILITY_COMMAND_FOR_TEST + int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override + { + return 0; + } +#endif +}; +} // namespace AAFwk +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/test/unittest/service_extension_context_test/service_extension_context_test.cpp b/test/unittest/service_extension_context_test/service_extension_context_test.cpp index 0a1a17f15d..dd32f32d00 100644 --- a/test/unittest/service_extension_context_test/service_extension_context_test.cpp +++ b/test/unittest/service_extension_context_test/service_extension_context_test.cpp @@ -16,11 +16,12 @@ #include #define private public +#include "ability_manager_client.h" #include "service_extension_context.h" #undef private #include "ability_connection.h" -#include "ability_manager_client.h" +#include "ability_manager_stub_mock.h" using namespace testing::ext; using namespace OHOS::AppExecFwk; @@ -255,5 +256,113 @@ HWTEST_F(ServiceExtensionContextTest, service_extension_context_GetAbilityInfoTy ServiceExtensionContext serviceExtensionContextTest; EXPECT_EQ(AppExecFwk::AbilityType::UNKNOWN, serviceExtensionContextTest.GetAbilityInfoType()); } + +/** + * @tc.number: service_extension_context_startAbility_003 + * @tc.name: StartAbility + * @tc.desc: Start ability success + */ +HWTEST_F(ServiceExtensionContextTest, service_extension_context_startAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "service_extension_context_startAbility_003 start"; + ServiceExtensionContext serviceExtensionContextTest; + sptr mock = new AAFwk::AbilityManagerStubTestMock(); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock; + + AAFwk::Want want; + AppExecFwk::ElementName element("device", "com.ix.hiMusic", "MusicAbility"); + want.SetElement(element); + auto ret = serviceExtensionContextTest.StartAbility(want); + EXPECT_EQ(ret, ERR_OK); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; + GTEST_LOG_(INFO) << "service_extension_context_startAbility_003 end"; +} + +/** + * @tc.number: service_extension_context_StartAbilityWithAccount_003 + * @tc.name: StartAbility + * @tc.desc: Start ability with Account success + */ +HWTEST_F(ServiceExtensionContextTest, service_extension_context_StartAbilityWithAccount_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "service_extension_context_StartAbilityWithAccount_003 start"; + ServiceExtensionContext serviceExtensionContextTest; + sptr mock = new AAFwk::AbilityManagerStubTestMock(); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock; + + AAFwk::Want want; + AppExecFwk::ElementName element("device", "com.ix.hiMusic", "MusicAbility"); + want.SetElement(element); + int32_t accountId = 1; + + auto ret = serviceExtensionContextTest.StartAbilityWithAccount(want, accountId); + EXPECT_EQ(ret, ERR_OK); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; + GTEST_LOG_(INFO) << "service_extension_context_StartAbilityWithAccount_003 end"; +} + +/** + * @tc.number: service_extension_context_StartServiceExtensionAbility_002 + * @tc.name: StartAbility + * @tc.desc: Start service extension ability success + */ +HWTEST_F(ServiceExtensionContextTest, service_extension_context_StartServiceExtensionAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "service_extension_context_StartServiceExtensionAbility_002 start"; + ServiceExtensionContext serviceExtensionContextTest; + sptr mock = new AAFwk::AbilityManagerStubTestMock(); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock; + + AAFwk::Want want; + AppExecFwk::ElementName element("device", "com.ix.hiMusic", "MusicAbility"); + want.SetElement(element); + int32_t accountId = 1; + + auto ret = serviceExtensionContextTest.StartServiceExtensionAbility(want, accountId); + EXPECT_EQ(ret, ERR_OK); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; + GTEST_LOG_(INFO) << "service_extension_context_StartServiceExtensionAbility_002 end"; +} + +/** + * @tc.number: service_extension_context_StopServiceExtensionAbility_002 + * @tc.name: StopServiceExtensionAbility + * @tc.desc: Stop service extension ability success + */ +HWTEST_F(ServiceExtensionContextTest, service_extension_context_StopServiceExtensionAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "service_extension_context_StopServiceExtensionAbility_002 start"; + ServiceExtensionContext serviceExtensionContextTest; + sptr mock = new AAFwk::AbilityManagerStubTestMock(); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock; + + AAFwk::Want want; + AppExecFwk::ElementName element("device", "com.ix.hiMusic", "MusicAbility"); + want.SetElement(element); + int32_t accountId = 1; + + auto ret = serviceExtensionContextTest.StopServiceExtensionAbility(want, accountId); + EXPECT_EQ(ret, ERR_OK); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; + GTEST_LOG_(INFO) << "service_extension_context_StopServiceExtensionAbility_002 end"; +} + +/** + * @tc.number: service_extension_context_TerminateAbility_002 + * @tc.name: TerminateAbility + * @tc.desc: Terminate ability success + */ +HWTEST_F(ServiceExtensionContextTest, service_extension_context_TerminateAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "service_extension_context_TerminateAbility_002 start"; + ServiceExtensionContext serviceExtensionContextTest; + sptr mock = new AAFwk::AbilityManagerStubTestMock(); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = mock; + + auto ret = serviceExtensionContextTest.TerminateAbility(); + EXPECT_EQ(ret, ERR_OK); + AAFwk::AbilityManagerClient::GetInstance()->proxy_ = nullptr; + GTEST_LOG_(INFO) << "service_extension_context_TerminateAbility_002 end"; +} } } \ No newline at end of file diff --git a/test/unittest/specified_mission_list_test/BUILD.gn b/test/unittest/specified_mission_list_test/BUILD.gn index e6dc07a47d..c7a279543f 100644 --- a/test/unittest/specified_mission_list_test/BUILD.gn +++ b/test/unittest/specified_mission_list_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("specified_mission_list_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "specified_mission_list_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("specified_mission_list_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("specified_mission_list_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", diff --git a/test/unittest/stop_user_callback_proxy_test/BUILD.gn b/test/unittest/stop_user_callback_proxy_test/BUILD.gn index 1942a58166..2f69523c25 100755 --- a/test/unittest/stop_user_callback_proxy_test/BUILD.gn +++ b/test/unittest/stop_user_callback_proxy_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("stop_user_callback_proxy_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "stop_user_callback_proxy_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("stop_user_callback_proxy_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -52,7 +52,6 @@ ohos_unittest("stop_user_callback_proxy_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/sys_mgr_client_test/BUILD.gn b/test/unittest/sys_mgr_client_test/BUILD.gn new file mode 100644 index 0000000000..040b1eaf6e --- /dev/null +++ b/test/unittest/sys_mgr_client_test/BUILD.gn @@ -0,0 +1,58 @@ +# Copyright (c) 2022 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("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +ohos_unittest("sys_mgr_client_test") { + module_out_path = "ability_runtime/sys_mgr_client_test" + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_path}/interfaces/inner_api/connectionobs_manager/include", + ] + + sources = [ + "mock_ability_manager_service.cpp", + "sys_mgr_client_test.cpp", + ] + + configs = [ "${ability_runtime_services_path}/common:common_config" ] + + cflags = [] + + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "ability_runtime:runtime", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +group("unittest") { + testonly = true + deps = [ ":sys_mgr_client_test" ] +} diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.cpp b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.cpp new file mode 100644 index 0000000000..a40c12a210 --- /dev/null +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2022 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 "mock_ability_manager_service.h" +#include + +#include +#include +#include +#include + +using OHOS::AppExecFwk::ElementName; + +namespace OHOS { +namespace AAFwk { +MockAbilityManagerService::MockAbilityManagerService() : abilityScheduler_(nullptr) +{ + abilityScheduler_ = nullptr; +} + +MockAbilityManagerService::~MockAbilityManagerService() +{} + +int MockAbilityManagerService::StartAbility(const Want& want, int32_t userId, int requestCode) +{ + GTEST_LOG_(INFO) << "MockAbilityManagerService::StartAbility called"; + curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + switch (requestCode) { + case AbilityLifeCycleState::ABILITY_STATE_INITIAL: + curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + break; + case AbilityLifeCycleState::ABILITY_STATE_INACTIVE: + curstate_ = AbilityLifeCycleState::ABILITY_STATE_INACTIVE; + break; + case AbilityLifeCycleState::ABILITY_STATE_ACTIVE: + curstate_ = AbilityLifeCycleState::ABILITY_STATE_ACTIVE; + break; + case AbilityLifeCycleState::ABILITY_STATE_BACKGROUND: + curstate_ = AbilityLifeCycleState::ABILITY_STATE_BACKGROUND; + break; + default: + break; + } + + if (abilityScheduler_ != nullptr) { + want_ = want; + want_.SetElementName("BundleName", "abilityName"); + LifeCycleStateInfo stateInfo; + stateInfo.state = curstate_; + abilityScheduler_->ScheduleAbilityTransaction(want_, stateInfo); + } + + return 0; +} + +int MockAbilityManagerService::StartAbility(const Want& want, const sptr& callerToken, + int32_t userId, int requestCode) +{ + return 0; +} + +int MockAbilityManagerService::TerminateAbility( + const sptr& token, int resultCode, const Want* resultWant) +{ + GTEST_LOG_(INFO) << "MockAbilityManagerService::TerminateAbility"; + + if (abilityScheduler_ != nullptr) { + LifeCycleStateInfo stateInfo; + stateInfo.state = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + abilityScheduler_->ScheduleAbilityTransaction(want_, stateInfo); + + int ceode = 250; + abilityScheduler_->SendResult(ceode, resultCode, *resultWant); + } + return 0; +} + +int MockAbilityManagerService::ConnectAbility( + const Want& want, const sptr& connect, const sptr& callerToken, int32_t userId) +{ + if (abilityScheduler_ != nullptr) { + PacMap inState; + abilityScheduler_->ScheduleSaveAbilityState(); + abilityScheduler_->ScheduleRestoreAbilityState(inState); + } + return 0; +} + +int MockAbilityManagerService::DisconnectAbility(const sptr& connect) +{ + GTEST_LOG_(INFO) << "MockAbilityManagerService::DisconnectAbility"; + AbilityLifeCycleState lifeState = AbilityLifeCycleState::ABILITY_STATE_ACTIVE; + + if (abilityScheduler_ != nullptr) { + LifeCycleStateInfo stateInfo; + stateInfo.state = lifeState; + stateInfo.isNewWant = true; + want_.SetElementName("BundleName", "abilityName"); + curstate_ = AbilityLifeCycleState::ABILITY_STATE_ACTIVE; + abilityScheduler_->ScheduleAbilityTransaction(want_, stateInfo); + } + return 0; +} + +int MockAbilityManagerService::AttachAbilityThread( + const sptr& scheduler, const sptr& token) +{ + abilityScheduler_ = scheduler; + EXPECT_NE(nullptr, token); + return 0; +} + +void MockAbilityManagerService::DumpState(const std::string& args, std::vector& info) +{} + +void MockAbilityManagerService::DumpSysState( + const std::string& args, std::vector& state, bool isClient, bool isUserID, int UserID) +{} + +int MockAbilityManagerService::AbilityTransitionDone( + const sptr& token, int state, const PacMap& saveData) +{ + GTEST_LOG_(INFO) << "MockAbilityManagerService::AbilityTransitionDone called"; + return 0; +} + +int MockAbilityManagerService::ScheduleConnectAbilityDone( + const sptr& token, const sptr& remoteObject) +{ + return 0; +} + +int MockAbilityManagerService::ScheduleDisconnectAbilityDone(const sptr& token) +{ + return 0; +} + +int MockAbilityManagerService::ScheduleCommandAbilityDone(const sptr& token) +{ + return 0; +} + +int MockAbilityManagerService::TerminateAbilityByCaller(const sptr& callerToken, int requestCode) +{ + return 0; +} + +int MockAbilityManagerService::TerminateAbilityResult(const sptr& token, int startId) +{ + return 0; +} + +int MockAbilityManagerService::StopServiceAbility(const Want& want, int32_t userId) +{ + return 0; +} + +sptr MockAbilityManagerService::AcquireDataAbility( + const Uri& uri, bool tryBind, const sptr& callerToken) +{ + if (abilityScheduler_ != nullptr) { + return abilityScheduler_; + } + return nullptr; +} + +ErrCode MockAbilityManagerService::ReleaseDataAbility( + sptr dataAbilityScheduler, const sptr& callerToken) +{ + if (abilityScheduler_ != nullptr) { + abilityScheduler_ = nullptr; + return 0; + } + return -1; +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h new file mode 100644 index 0000000000..7ee98ab1f5 --- /dev/null +++ b/test/unittest/sys_mgr_client_test/mock_ability_manager_service.h @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2022 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 MOCK_OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H +#define MOCK_OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H + +#include +#include +#include +#include + +#include "ability_manager_stub.h" +#include "iremote_object.h" + +#include "gmock/gmock.h" + +namespace OHOS { +namespace AAFwk { +enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; + +class MockAbilityManagerService : public AbilityManagerStub, + public std::enable_shared_from_this { +public: + MockAbilityManagerService(); + ~MockAbilityManagerService(); + int StartAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE, int requestCode = -1) override; + int StartAbility(const Want& want, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE, + int requestCode = -1) override; + int StartAbility( + const Want& want, + const StartOptions& startOptions, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE, + int requestCode = DEFAULT_INVAL_VALUE) override + { + return 0; + } + int TerminateAbility( + const sptr& token, int resultCode = -1, const Want* resultWant = nullptr) override; + int CloseAbility(const sptr& token, int resultCode = DEFAULT_INVAL_VALUE, + const Want* resultWant = nullptr) override + { + return 0; + } + int MinimizeAbility(const sptr& token, bool fromUser) override + { + return 0; + } + int ConnectAbility( + const Want& want, + const sptr& connect, + const sptr& callerToken, + int32_t userId = DEFAULT_INVAL_VALUE) override; + int DisconnectAbility(const sptr& connect) override; + + sptr AcquireDataAbility(const Uri& uri, bool tryBind, const sptr& callerToken); + + ErrCode ReleaseDataAbility(sptr dataAbilityScheduler, const sptr& callerToken); + + int AttachAbilityThread(const sptr& scheduler, const sptr& token) override; + + int AbilityTransitionDone(const sptr& token, int state, const PacMap& saveData) override; + int ScheduleConnectAbilityDone(const sptr& token, const sptr& remoteObject) override; + int ScheduleDisconnectAbilityDone(const sptr& token) override; + int ScheduleCommandAbilityDone(const sptr& token) override; + + void DumpState(const std::string& args, std::vector& info) override; + void DumpSysState( + const std::string& args, std::vector& state, bool isClient, bool isUserID, int UserID) override; + int TerminateAbilityByCaller(const sptr& callerToken, int requestCode) override; + int TerminateAbilityResult(const sptr& token, int startId) override; + int StopServiceAbility(const Want& want, int32_t userId = DEFAULT_INVAL_VALUE) override; + + MOCK_METHOD1(KillProcess, int(const std::string& bundleName)); + MOCK_METHOD2(UninstallApp, int(const std::string& bundleName, int32_t uid)); + MOCK_METHOD2( + GetWantSender, sptr(const WantSenderInfo& wantSenderInfo, const sptr& callerToken)); + MOCK_METHOD2(SendWantSender, int(const sptr& target, const SenderInfo& senderInfo)); + MOCK_METHOD1(CancelWantSender, void(const sptr& sender)); + MOCK_METHOD1(GetPendingWantUid, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantUserId, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantBundleName, std::string(const sptr& target)); + MOCK_METHOD1(GetPendingWantCode, int(const sptr& target)); + MOCK_METHOD1(GetPendingWantType, int(const sptr& target)); + MOCK_METHOD2(RegisterCancelListener, void(const sptr& sender, const sptr& receiver)); + MOCK_METHOD2(UnregisterCancelListener, void(const sptr& sender, const sptr& receiver)); + MOCK_METHOD2(GetPendingRequestWant, int(const sptr& target, std::shared_ptr& want)); + MOCK_METHOD5(StartAbility, int(const Want& want, const AbilityStartSetting& abilityStartSetting, + const sptr& callerToken, int32_t userId, int requestCode)); + MOCK_METHOD1(GetPendinTerminateAbilityTestgRequestWant, void(int id)); + MOCK_METHOD3(StartContinuation, int(const Want& want, const sptr& abilityToken, int32_t status)); + MOCK_METHOD2(NotifyContinuationResult, int(int32_t missionId, int32_t result)); + MOCK_METHOD5(ContinueMission, int(const std::string& srcDeviceId, const std::string& dstDeviceId, + int32_t missionId, const sptr& callBack, AAFwk::WantParams& wantParams)); + MOCK_METHOD3(ContinueAbility, int(const std::string& deviceId, int32_t missionId, uint32_t versionCode)); + MOCK_METHOD3(NotifyCompleteContinuation, void(const std::string& deviceId, int32_t sessionId, bool isSuccess)); + + MOCK_METHOD1(LockMissionForCleanup, int(int32_t missionId)); + MOCK_METHOD1(UnlockMissionForCleanup, int(int32_t missionId)); + MOCK_METHOD1(RegisterMissionListener, int(const sptr& listener)); + MOCK_METHOD1(UnRegisterMissionListener, int(const sptr& listener)); + MOCK_METHOD3( + GetMissionInfos, int(const std::string& deviceId, int32_t numMax, std::vector& missionInfos)); + MOCK_METHOD3(GetMissionInfo, int(const std::string& deviceId, int32_t missionId, MissionInfo& missionInfo)); + MOCK_METHOD1(CleanMission, int(int32_t missionId)); + MOCK_METHOD0(CleanAllMissions, int()); + MOCK_METHOD1(MoveMissionToFront, int(int32_t missionId)); + MOCK_METHOD2(MoveMissionToFront, int(int32_t missionId, const StartOptions& startOptions)); + MOCK_METHOD2(SetMissionLabel, int(const sptr& token, const std::string& label)); + MOCK_METHOD2(SetMissionIcon, int(const sptr& token, + const std::shared_ptr& icon)); + MOCK_METHOD2(GetWantSenderInfo, int(const sptr& target, std::shared_ptr& info)); + MOCK_METHOD1(GetAbilityRunningInfos, int(std::vector& info)); + MOCK_METHOD2(GetExtensionRunningInfos, int(int upperLimit, std::vector& info)); + MOCK_METHOD1(GetProcessRunningInfos, int(std::vector& info)); + MOCK_METHOD3(StartAbilityByCall, int(const Want&, const sptr&, const sptr&)); + MOCK_METHOD1(GetMissionIdByToken, int32_t(const sptr& token)); +#ifdef ABILITY_COMMAND_FOR_TEST + MOCK_METHOD0(BlockAppService, int()); + MOCK_METHOD0(BlockAmsService, int()); + MOCK_METHOD1(BlockAbility, int(int32_t abilityRecordId)); +#endif + + int ClearUpApplicationData(const std::string& bundleName) override + { + return 0; + } + + int StartUser(int userId) override + { + return 0; + } + + int StopUser(int userId, const sptr& callback) override + { + return 0; + } + + int StartSyncRemoteMissions(const std::string& devId, bool fixConflict, int64_t tag) override + { + return 0; + } + + int StopSyncRemoteMissions(const std::string& devId) override + { + return 0; + } + int RegisterMissionListener(const std::string& deviceId, + const sptr& listener) override + { + return 0; + } + int UnRegisterMissionListener(const std::string& deviceId, + const sptr& listener) override + { + return 0; + } + + int ReleaseCall(const sptr& connect, + const AppExecFwk::ElementName& element) override + { + return 0; + } + virtual int GetMissionSnapshot(const std::string& deviceId, int32_t missionId, + MissionSnapshot& snapshot, bool isLowResolution) + { + return 0; + } + virtual void UpdateMissionSnapShot(const sptr& token) + { + return; + } + virtual int RegisterSnapshotHandler(const sptr& handler) + { + return 0; + } + int SetAbilityController(const sptr& abilityController, + bool imAStabilityTest) override + { + return 0; + } + + bool IsRunningInStabilityTest() override + { + return true; + } + + int SendANRProcessID(int pid) override + { + return 0; + } + + int StartUserTest(const Want& want, const sptr& observer) override + { + return 0; + } + + int FinishUserTest( + const std::string& msg, const int64_t& resultCode, const std::string& bundleName) override + { + return 0; + } + + int GetTopAbility(sptr& token) override + { + return 0; + } + + int DelegatorDoAbilityForeground(const sptr& token) override + { + return 0; + } + + int DelegatorDoAbilityBackground(const sptr& token) override + { + return 0; + } + + int RegisterWindowManagerServiceHandler(const sptr& handler) override + { + return 0; + } + + void CompleteFirstFrameDrawing(const sptr& abilityToken) override {} + + void CallRequestDone(const sptr &token, const sptr &callStub) override {} + +#ifdef ABILITY_COMMAND_FOR_TEST + int ForceTimeoutForTest(const std::string& abilityName, const std::string& state) override + { + return 0; + } +#endif + + AbilityLifeCycleState curstate_ = AbilityLifeCycleState::ABILITY_STATE_INITIAL; + sptr abilityScheduler_; // kit interface used to schedule ability life + Want want_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // MOCK_OHOS_ABILITY_RUNTIME_ABILITY_MANAGER_SERVICE_H \ No newline at end of file diff --git a/test/unittest/sys_mgr_client_test/sys_mgr_client_test.cpp b/test/unittest/sys_mgr_client_test/sys_mgr_client_test.cpp new file mode 100644 index 0000000000..068af3f2c8 --- /dev/null +++ b/test/unittest/sys_mgr_client_test/sys_mgr_client_test.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2022 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 "iservice_registry.h" +#include "mock_ability_manager_service.h" +#include "system_ability_definition.h" +#define private public +#define protected public +#include "sys_mgr_client.h" +#undef private +#undef protected + +using namespace testing::ext; + +namespace OHOS { +namespace AbilityRuntime { +int32_t REGISTER_FLAG = 0; +int32_t UN_REGISTER_FLAG = 0; + +class SysMgrClient : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp() override; + void TearDown() override; +}; + +void SysMgrClient::SetUpTestCase(void) +{} + +void SysMgrClient::TearDownTestCase(void) +{} + +void SysMgrClient::SetUp() +{} + +void SysMgrClient::TearDown() +{} + +/** + * @tc.number: GetSystemAbility_0100 + * @tc.name: GetSystemAbility + * @tc.desc: Get System Ability Success When abilityManager_ is null. + */ +HWTEST_F(SysMgrClient, GetSystemAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetSystemAbility_0100 start"; + auto sysMgr = DelayedSingleton::GetInstance(); + EXPECT_NE(sysMgr, nullptr); + + EXPECT_EQ(sysMgr-> abilityManager_, nullptr); + + auto ret = sysMgr->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetSystemAbility_0100 end"; +} + +/** + * @tc.number: GetSystemAbility_0200 + * @tc.name: GetSystemAbility + * @tc.desc: Get System Ability Success When abilityManager_ is not null. + */ +HWTEST_F(SysMgrClient, GetSystemAbility_0200, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "GetSystemAbility_0200 start"; + auto sysMgr = DelayedSingleton::GetInstance(); + EXPECT_NE(sysMgr, nullptr); + + sysMgr-> abilityManager_ = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + EXPECT_NE(sysMgr-> abilityManager_, nullptr); + + auto ret = sysMgr->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + EXPECT_NE(ret, nullptr); + GTEST_LOG_(INFO) << "GetSystemAbility_0200 end"; +} + +/** + * @tc.number: RegisterSystemAbility_0100 + * @tc.name: Register System Ability + * @tc.desc: Register System Ability Success. + */ +HWTEST_F(SysMgrClient, RegisterSystemAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RegisterSystemAbility_0100 start"; + auto sysMgr = DelayedSingleton::GetInstance(); + EXPECT_NE(sysMgr, nullptr); + + OHOS::sptr object = new AAFwk::MockAbilityManagerService(); + + sysMgr->RegisterSystemAbility( OHOS::ABILITY_MGR_SERVICE_ID, object); + GTEST_LOG_(INFO) << "RegisterSystemAbility_0100 end"; +} + +/** + * @tc.number: UnregisterSystemAbility_0100 + * @tc.name: UnRegister System Ability + * @tc.desc: Un Register System Ability Success. + */ +HWTEST_F(SysMgrClient, UnregisterSystemAbility_0100, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UnregisterSystemAbility_0100 start"; + auto sysMgr = DelayedSingleton::GetInstance(); + EXPECT_NE(sysMgr, nullptr); + sysMgr->UnregisterSystemAbility(OHOS::ABILITY_MGR_SERVICE_ID); + GTEST_LOG_(INFO) << "UnregisterSystemAbility_0100 end"; +} +} // namespace AbilityRuntime +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/task_data_persistence_mgr_test/BUILD.gn b/test/unittest/task_data_persistence_mgr_test/BUILD.gn index daf42e3985..a2e6a9c62c 100755 --- a/test/unittest/task_data_persistence_mgr_test/BUILD.gn +++ b/test/unittest/task_data_persistence_mgr_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("task_data_persistence_mgr_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "task_data_persistence_mgr_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("task_data_persistence_mgr_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("task_data_persistence_mgr_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/test/unittest/user_event_handler_test/BUILD.gn b/test/unittest/user_event_handler_test/BUILD.gn index a9dd06eed7..4fcb3063a1 100755 --- a/test/unittest/user_event_handler_test/BUILD.gn +++ b/test/unittest/user_event_handler_test/BUILD.gn @@ -25,7 +25,6 @@ ohos_unittest("user_event_handler_test") { ] sources = [ - "${ability_runtime_services_path}/common/src/permission_verification.cpp", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core/src/appmgr/mock_app_scheduler.cpp", "user_event_handler_test.cpp", # add mock file ] @@ -41,6 +40,7 @@ ohos_unittest("user_event_handler_test") { deps = [ "${ability_runtime_native_path}/ability/native:abilitykit_native", "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:perm_verification", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/aakit:aakit_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_appmgr_mock", "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/appexecfwk_core:appexecfwk_bundlemgr_mock", @@ -51,7 +51,6 @@ ohos_unittest("user_event_handler_test") { external_deps = [ "ability_base:want", "ability_base:zuri", - "access_token:libaccesstoken_sdk", "c_utils:utils", "common_event_service:cesfwk_innerkits", "eventhandler:libeventhandler", diff --git a/tools/aa/BUILD.gn b/tools/aa/BUILD.gn index eb8425a990..30abb17ff0 100644 --- a/tools/aa/BUILD.gn +++ b/tools/aa/BUILD.gn @@ -30,6 +30,7 @@ ohos_source_set("tools_aa_source_set") { "src/ability_command.cpp", "src/ability_tool_command.cpp", "src/shell_command.cpp", + "src/shell_command_config_loader.cpp", "src/shell_command_executor.cpp", "src/shell_command_result.cpp", "src/system_time.cpp", @@ -119,6 +120,15 @@ ohos_executable("aa") { part_name = "ability_tools" } -group("tools_aa") { - deps = [ ":aa" ] +ohos_prebuilt_etc("shell_command_excutor_config.json") { + source = "resource/shell_command_excutor_config.json" + subsystem_name = "ability" + part_name = "ability_tools" +} + +group("tools_aa") { + deps = [ + ":aa", + ":shell_command_excutor_config.json", + ] } diff --git a/tools/aa/include/shell_command_config_loader.h b/tools/aa/include/shell_command_config_loader.h new file mode 100644 index 0000000000..66b11e5e73 --- /dev/null +++ b/tools/aa/include/shell_command_config_loader.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2022 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_ABILITY_RUNTIME_SHELL_COMMAND_CONFIG_LOADER_H +#define OHOS_ABILITY_RUNTIME_SHELL_COMMAND_CONFIG_LOADER_H + +#include +#include + +namespace OHOS { +namespace AAFwk { +class ShellCommandConfigLoder final +{ +public: + ShellCommandConfigLoder() = default; + ~ShellCommandConfigLoder() = default; + + /** + * @brief Read configuration file. + * + * @param filePath Configuration directory. + * @return true Read successfully. + * @return false Read failed. + */ + bool ReadConfig(const std::string &filePath); + + /** + * @brief Read the configuration file only once, + * true indicates that the config has been read. + * Otherwise, it has not been read. + */ + static bool configState_; + + static std::set commands_; +private: + std::mutex mtxRead_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif \ No newline at end of file diff --git a/tools/aa/include/shell_command_executor.h b/tools/aa/include/shell_command_executor.h index b307486666..07b0411f77 100644 --- a/tools/aa/include/shell_command_executor.h +++ b/tools/aa/include/shell_command_executor.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "event_handler.h" #include "shell_command_result.h" @@ -48,7 +49,7 @@ public: private: bool DoWork(); - + bool CheckCommand(); private: std::string cmd_; int64_t timeoutSec_{ 0 }; diff --git a/tools/aa/resource/shell_command_excutor_config.json b/tools/aa/resource/shell_command_excutor_config.json new file mode 100644 index 0000000000..7bf4554e9f --- /dev/null +++ b/tools/aa/resource/shell_command_excutor_config.json @@ -0,0 +1,3 @@ +{ + "command_list":["aa", "bm", "cp", "mkdir", "rm", "uinput", "hilog", "ppwd", "echo"] +} diff --git a/tools/aa/src/shell_command_config_loader.cpp b/tools/aa/src/shell_command_config_loader.cpp new file mode 100644 index 0000000000..2bf3a6f8ac --- /dev/null +++ b/tools/aa/src/shell_command_config_loader.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 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 "shell_command_config_loader.h" +#include +#include +#include +#include "hilog_wrapper.h" + +using json = nlohmann::json; +namespace OHOS { +namespace AAFwk { +namespace { + constexpr const char* AA_TOOL_COMMAND_LIST = "command_list"; + constexpr static int COMMANDS_MAX_SIZE = 100; +} + +bool ShellCommandConfigLoder::configState_ = false; +std::set ShellCommandConfigLoder::commands_ = {}; + +bool ShellCommandConfigLoder::ReadConfig(const std::string &filePath) +{ + HILOG_INFO("%{public}s", __func__); + if(configState_) { + HILOG_INFO("config has been read"); + return true; + } + + std::ifstream inFile; + inFile.open(filePath, std::ios::in); + if (!inFile.is_open()) { + HILOG_INFO("read aa config error"); + return false; + } + + json aaJson; + inFile >> aaJson; + inFile.close(); + if (aaJson.is_discarded()) { + HILOG_INFO("json discarded error"); + return false; + } + + if (aaJson.is_null() || aaJson.empty()) { + HILOG_INFO("invalid jsonObj"); + return false; + } + + if(!aaJson.contains(AA_TOOL_COMMAND_LIST)) { + HILOG_INFO("json config not contains the key"); + return false; + } + + if (aaJson[AA_TOOL_COMMAND_LIST].is_null() || !aaJson[AA_TOOL_COMMAND_LIST].is_array() + || aaJson[AA_TOOL_COMMAND_LIST].empty()) { + HILOG_INFO("invalid command obj size"); + return false; + } + + if(aaJson[AA_TOOL_COMMAND_LIST].size() > COMMANDS_MAX_SIZE) { + HILOG_INFO("command obj size overflow"); + return false; + } + + std::lock_guard lock(mtxRead_); + for(int i = 0; i < aaJson[AA_TOOL_COMMAND_LIST].size(); i++) { + if(aaJson[AA_TOOL_COMMAND_LIST][i].is_null() || !aaJson[AA_TOOL_COMMAND_LIST][i].is_string()) { + continue; + } + commands_.emplace(aaJson[AA_TOOL_COMMAND_LIST][i]); + } + + aaJson.clear(); + HILOG_INFO("read config success"); + configState_ = true; + return true; +} + +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/tools/aa/src/shell_command_executor.cpp b/tools/aa/src/shell_command_executor.cpp index 7084b2390c..e81856d80d 100644 --- a/tools/aa/src/shell_command_executor.cpp +++ b/tools/aa/src/shell_command_executor.cpp @@ -18,8 +18,10 @@ #include #include #include +#include #include "hilog_wrapper.h" +#include "shell_command_config_loader.h" using namespace std::chrono_literals; namespace OHOS { @@ -77,6 +79,11 @@ bool ShellCommandExecutor::DoWork() HILOG_ERROR("Invalid event handler"); return false; } + + if(!CheckCommand()) { + HILOG_ERROR("Invalid command"); + return false; + } auto self(shared_from_this()); handler_->PostTask([this, self]() { @@ -117,5 +124,16 @@ bool ShellCommandExecutor::DoWork() return true; } + +bool ShellCommandExecutor::CheckCommand() +{ + std::istringstream iss(cmd_); + std::string firstCommand = ""; + iss >> firstCommand; + if(ShellCommandConfigLoder::commands_.find(firstCommand) != ShellCommandConfigLoder::commands_.end()) { + return true; + } + return false; +} } // namespace AAFwk } // namespace OHOS diff --git a/tools/aa/src/test_observer.cpp b/tools/aa/src/test_observer.cpp index 5afd1da84a..53dd024bc0 100644 --- a/tools/aa/src/test_observer.cpp +++ b/tools/aa/src/test_observer.cpp @@ -20,6 +20,7 @@ #include #include "hilog_wrapper.h" +#include "shell_command_config_loader.h" #include "shell_command_executor.h" #include "system_time.h" @@ -27,6 +28,10 @@ using namespace std::chrono_literals; namespace OHOS { namespace AAFwk { +namespace { + constexpr const char* AA_TOOL_COMMAND_CONFIG = "/system/etc/shell_command_excutor_config.json"; +} + TestObserver::TestObserver() : isFinished_(false) {} @@ -58,6 +63,11 @@ ShellCommandResult TestObserver::ExecuteShellCommand(const std::string& cmd, con return {}; } + if(!std::make_shared()->ReadConfig(AA_TOOL_COMMAND_CONFIG)) { + HILOG_ERROR("Failed to read config"); + return {}; + } + return cmdExecutor->WaitWorkDone(); } diff --git a/tools/test/BUILD.gn b/tools/test/BUILD.gn index 402bb19e56..a107981e13 100644 --- a/tools/test/BUILD.gn +++ b/tools/test/BUILD.gn @@ -32,4 +32,5 @@ group("unittest") { deps = [ "unittest/aa:unittest" ] deps += [ "unittest/ability_delegator:unittest" ] deps += [ "unittest/ability_tool:unittest" ] + deps += [ "unittest/system_time:unittest" ] } diff --git a/tools/test/moduletest/ability_delegator/test_observer_module_test.cpp b/tools/test/moduletest/ability_delegator/test_observer_module_test.cpp index 7ed20ef69b..6f727ccae6 100644 --- a/tools/test/moduletest/ability_delegator/test_observer_module_test.cpp +++ b/tools/test/moduletest/ability_delegator/test_observer_module_test.cpp @@ -77,6 +77,6 @@ HWTEST_F(TestObserverModuleTest, Test_Observer_Module_Test_0100, Function | Medi HWTEST_F(TestObserverModuleTest, Test_Observer_Module_Test_0200, Function | MediumTest | Level1) { TestObserver observer; - EXPECT_NE(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0); + EXPECT_EQ(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0); } diff --git a/tools/test/unittest/ability_delegator/test_observer_test.cpp b/tools/test/unittest/ability_delegator/test_observer_test.cpp index 813e22cb25..963b06ef9f 100644 --- a/tools/test/unittest/ability_delegator/test_observer_test.cpp +++ b/tools/test/unittest/ability_delegator/test_observer_test.cpp @@ -93,7 +93,7 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0200, Function | MediumTest | Leve { HILOG_INFO("Test_Observer_Test_0200 is called"); TestObserver observer; - EXPECT_NE(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0); + EXPECT_EQ(observer.ExecuteShellCommand(CMD.c_str(), TIMEOUT).stdResult.size(), 0); } /** @@ -110,3 +110,29 @@ HWTEST_F(TestObserverTest, Test_Observer_Test_0300, Function | MediumTest | Leve th.join(); EXPECT_TRUE(ret); } + +/** + * @tc.number: Test_Observer_Test_0400 + * @tc.name: WaitForFinish + * @tc.desc: Verify the WaitForFinish return false. + */ +HWTEST_F(TestObserverTest, Test_Observer_Test_0400, Function | MediumTest | Level1) +{ + HILOG_INFO("Test_Observer_Test_0400 is called"); + TestObserver observer; + observer.isFinished_ = false; + bool ret = observer.WaitForFinish(1); + EXPECT_FALSE(ret); +} + +/** + * @tc.number: Test_Observer_Test_0500 + * @tc.name: TestStatus + * @tc.desc: Verify the TestStatus. + */ +HWTEST_F(TestObserverTest, Test_Observer_Test_0500, Function | MediumTest | Level1) +{ + HILOG_INFO("Test_Observer_Test_0500 is called"); + TestObserver observer; + observer.TestStatus(MSG.c_str(), RESULT_CODE); +} diff --git a/tools/test/unittest/system_time/BUILD.gn b/tools/test/unittest/system_time/BUILD.gn new file mode 100644 index 0000000000..65da0871fd --- /dev/null +++ b/tools/test/unittest/system_time/BUILD.gn @@ -0,0 +1,39 @@ +# Copyright (c) 2022 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/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_tools/tools" + +ohos_unittest("system_time_test") { + module_out_path = module_output_path + + sources = [ "system_time_test.cpp" ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + + deps = [ + "${ability_runtime_path}/tools/aa:tools_aa_source_set", + "//third_party/googletest:gtest_main", + ] +} + +group("unittest") { + testonly = true + + deps = [ ":system_time_test" ] +} diff --git a/tools/test/unittest/system_time/system_time_test.cpp b/tools/test/unittest/system_time/system_time_test.cpp new file mode 100644 index 0000000000..5f43821971 --- /dev/null +++ b/tools/test/unittest/system_time/system_time_test.cpp @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 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 "system_time.h" + +using namespace testing::ext; +using namespace OHOS; +using namespace OHOS::AAFwk; + +namespace OHOS { +namespace AAFwk { +namespace { +} // namespace + +class SystemTimeTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SystemTimeTest::SetUpTestCase() +{} + +void SystemTimeTest::TearDownTestCase() +{} + +void SystemTimeTest::SetUp() +{} + +void SystemTimeTest::TearDown() +{} + +/** + * @tc.name: System_Time_Get_Now_System_0100 + * @tc.desc: "Get System Time" test. + * @tc.type: FUNC + */ +HWTEST_F(SystemTimeTest, System_Time_Get_Now_System_0100, TestSize.Level1) +{ + SystemTime systemTime; + EXPECT_GT(systemTime.GetNowSysTime(), 0); +} +} // namespace AAFwk +} // namespace OHOS