diff --git a/frameworks/native/ability/native/ability_runtime/js_ability.cpp b/frameworks/native/ability/native/ability_runtime/js_ability.cpp index 1b47d597b525876e97b0a9c4e369c703ed0bfa1d..63fb1a478c3cf526d363717d04aa6f597a844d92 100644 --- a/frameworks/native/ability/native/ability_runtime/js_ability.cpp +++ b/frameworks/native/ability/native/ability_runtime/js_ability.cpp @@ -832,7 +832,7 @@ NativeValue *JsAbility::CallObjectMethod(const char *name, NativeValue *const *a return nullptr; } - HandleScope handleScope(jsRuntime_); + HandleEscape handleEscape(jsRuntime_); auto &nativeEngine = jsRuntime_.GetNativeEngine(); NativeValue *value = jsAbilityObj_->Get(); @@ -848,7 +848,7 @@ NativeValue *JsAbility::CallObjectMethod(const char *name, NativeValue *const *a return nullptr; } if (withResult) { - return handleScope.Escape(nativeEngine.CallFunction(value, methodOnCreate, argv, argc)); + return handleEscape.Escape(nativeEngine.CallFunction(value, methodOnCreate, argv, argc)); } nativeEngine.CallFunction(value, methodOnCreate, argv, argc); return nullptr; diff --git a/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp b/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp index ea403af0acca8db7ab13a8dc9461d5463a4a3809..3f70e3bdc18dacf7b777bdf243226828b76a7b62 100644 --- a/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp +++ b/frameworks/native/ability/native/continuation/remote_register_service/connect_callback_proxy.cpp @@ -31,7 +31,7 @@ void ConnectCallbackProxy::Connect(const string &deviceId, const string &deviceT HILOG_INFO("%{public}s called begin", __func__); MessageParcel data; if (!data.WriteInterfaceToken(IConnectCallback::GetDescriptor()) || !data.WriteString(deviceId) || - data.WriteString(deviceType)) { + !data.WriteString(deviceType)) { HILOG_ERROR("%{public}s params is wrong", __func__); return; } diff --git a/frameworks/native/ability/native/form_runtime/js_form_extension.cpp b/frameworks/native/ability/native/form_runtime/js_form_extension.cpp index a2a5ad65957e5bc18fd6b54b65cc82afaa372fa0..0d8b792903ba4967cb9b7557df858d4e0ed75c4a 100644 --- a/frameworks/native/ability/native/form_runtime/js_form_extension.cpp +++ b/frameworks/native/ability/native/form_runtime/js_form_extension.cpp @@ -285,7 +285,7 @@ NativeValue* JsFormExtension::CallObjectMethod(const char* name, const char *bak return nullptr; } - HandleScope handleScope(jsRuntime_); + HandleEscape handleEscape(jsRuntime_); auto& nativeEngine = jsRuntime_.GetNativeEngine(); NativeValue* value = jsObj_->Get(); @@ -308,7 +308,7 @@ NativeValue* JsFormExtension::CallObjectMethod(const char* name, const char *bak } } HILOG_INFO("JsFormExtension::CallFunction(%{public}s), success", name); - return handleScope.Escape(nativeEngine.CallFunction(value, method, argv, argc)); + return handleEscape.Escape(nativeEngine.CallFunction(value, method, argv, argc)); } void JsFormExtension::GetSrcPath(std::string &srcPath) diff --git a/frameworks/native/ability/native/js_service_extension.cpp b/frameworks/native/ability/native/js_service_extension.cpp index fe1d6e3c4a88f1b37f5460df28c15d2aa5a6c8ad..addfac857027e9f34e7a66b6cd40259d0c4c7988 100644 --- a/frameworks/native/ability/native/js_service_extension.cpp +++ b/frameworks/native/ability/native/js_service_extension.cpp @@ -332,7 +332,7 @@ void JsServiceExtension::GetSrcPath(std::string &srcPath) NativeValue *JsServiceExtension::CallOnDisconnect(const AAFwk::Want &want, bool withResult) { - HandleScope handleScope(jsRuntime_); + HandleEscape handleEscape(jsRuntime_); NativeEngine *nativeEngine = &jsRuntime_.GetNativeEngine(); napi_value napiWant = OHOS::AppExecFwk::WrapWant(reinterpret_cast(nativeEngine), want); NativeValue *nativeWant = reinterpret_cast(napiWant); @@ -356,7 +356,7 @@ NativeValue *JsServiceExtension::CallOnDisconnect(const AAFwk::Want &want, bool } if (withResult) { - return handleScope.Escape(nativeEngine->CallFunction(value, method, argv, ARGC_ONE)); + return handleEscape.Escape(nativeEngine->CallFunction(value, method, argv, ARGC_ONE)); } else { nativeEngine->CallFunction(value, method, argv, ARGC_ONE); return nullptr; 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 fab7e24761d69b35a46ae2a1ea6322e9aa9f25d4..51b890ae45c0c69559a711340a513274f375a372 100644 --- a/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp +++ b/frameworks/native/appkit/ability_runtime/context/js_context_utils.cpp @@ -77,7 +77,7 @@ private: void JsBaseContext::Finalizer(NativeEngine* engine, void* data, void* hint) { - HILOG_INFO("JsBaseContext::Finalizer is called"); + HILOG_DEBUG("JsBaseContext::Finalizer is called"); std::unique_ptr(static_cast(data)); } @@ -512,7 +512,7 @@ NativeValue* AttachApplicationContext(NativeEngine* engine, void* value, void* h auto workContext = new (std::nothrow) std::weak_ptr(ptr); nObject->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; diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index e11b86d27584f494a15d39cc62fade4b6bf6c591..0c099795c286c59dd8bb93605af46501c2368b0e 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -175,6 +175,10 @@ MainThread::MainThread() MainThread::~MainThread() { HILOG_INFO("MainThread::MainThread call destructor."); + if (watchdog_ != nullptr && !watchdog_->IsStopWatchdog()) { + watchdog_->Stop(); + watchdog_ = nullptr; + } #ifdef ABILITY_LIBRARY_LOADER CloseAbilityLibrary(); #endif // ABILITY_LIBRARY_LOADER @@ -695,8 +699,9 @@ void MainThread::HandleTerminateApplicationLocal() return; } - if (watchdog_ != nullptr) { + if (watchdog_ != nullptr && !watchdog_->IsStopWatchdog()) { watchdog_->Stop(); + watchdog_ = nullptr; } int ret = runner->Stop(); @@ -1281,7 +1286,7 @@ void MainThread::LoadAllExtensions(const std::string &filePath, std::weak_ptrsecond; extensionTypeMap.insert(std::pair(type, extensionName)); - HILOG_INFO("Success load extension type: %{public}d, name:%{public}s", type, extensionName.c_str()); + HILOG_DEBUG("Success load extension type: %{public}d, name:%{public}s", type, extensionName.c_str()); AbilityLoader::GetInstance().RegisterExtension(extensionName, [wpApplication, file]() -> AbilityRuntime::Extension* { auto app = wpApplication.lock(); @@ -1573,8 +1578,9 @@ void MainThread::HandleTerminateApplication() return; } - if (watchdog_ != nullptr) { + if (watchdog_ != nullptr && !watchdog_->IsStopWatchdog()) { watchdog_->Stop(); + watchdog_ = nullptr; } int ret = runner->Stop(); diff --git a/frameworks/native/appkit/app/watchdog.cpp b/frameworks/native/appkit/app/watchdog.cpp index de17496d956c5368eaf7cfa7b2795b50356a61de..a8fd27c5504db386a5ac92be23296a2fa12f049e 100644 --- a/frameworks/native/appkit/app/watchdog.cpp +++ b/frameworks/native/appkit/app/watchdog.cpp @@ -53,6 +53,11 @@ void Watchdog::Init(const std::shared_ptr mainHandler) void Watchdog::Stop() { HILOG_DEBUG("Watchdog is stop !"); + std::unique_lock lock(cvMutex_); + if (stopWatchdog_) { + HILOG_ERROR("Watchdog has stoped."); + return; + } stopWatchdog_.store(true); cvWatchdog_.notify_all(); OHOS::HiviewDFX::Watchdog::GetInstance().StopWatchdog(); @@ -99,20 +104,9 @@ bool Watchdog::IsStopWatchdog() return stopWatchdog_; } -bool Watchdog::WaitForDuration(uint32_t duration) -{ - std::unique_lock lock(cvMutex_); - auto condition = [this] { - return this->IsStopWatchdog(); - }; - if (cvWatchdog_.wait_for(lock, std::chrono::milliseconds(duration), condition)) { - return true; - } - return false; -} - void Watchdog::Timer() { + std::unique_lock lock(cvMutex_); if (!needReport_) { HILOG_ERROR("Watchdog timeout, wait for the handler to recover, and do not send event."); return; diff --git a/frameworks/native/runtime/js_runtime.cpp b/frameworks/native/runtime/js_runtime.cpp index 8e365284ef57fecc6dc1744a2dd460109de6a939..7a90324c862da7b43bf6d4a49152c34aa8593451 100644 --- a/frameworks/native/runtime/js_runtime.cpp +++ b/frameworks/native/runtime/js_runtime.cpp @@ -136,6 +136,8 @@ public: } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(hapPath, runtimeExtractor)); + ExtractorUtil::AddExtractor(hapPath, runtimeExtractor); + panda::JSNApi::LoadAotFile(vm_, hapPath); } else { runtimeExtractor = runtimeExtractorMap_.at(hapPath); } @@ -344,8 +346,10 @@ private: } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(options.hapPath, runtimeExtractor)); + ExtractorUtil::AddExtractor(options.hapPath, runtimeExtractor); panda::JSNApi::SetHostResolveBufferTracker( vm_, JsModuleReader(options.bundleName, options.hapPath, runtimeExtractor)); + panda::JSNApi::LoadAotFile(vm_, options.hapPath); } isBundle_ = options.isBundle; panda::JSNApi::SetBundle(vm_, options.isBundle); @@ -486,7 +490,7 @@ std::unique_ptr JsRuntime::Create(const Runtime::Options& options) std::unique_ptr JsRuntime::LoadSystemModuleByEngine(NativeEngine* engine, const std::string& moduleName, NativeValue* const* argv, size_t argc) { - HILOG_INFO("JsRuntime::LoadSystemModule(%{public}s)", moduleName.c_str()); + HILOG_DEBUG("JsRuntime::LoadSystemModule(%{public}s)", moduleName.c_str()); if (engine == nullptr) { HILOG_INFO("JsRuntime::LoadSystemModule: invalid engine."); return std::unique_ptr(); @@ -706,6 +710,7 @@ bool JsRuntime::RunScript(const std::string& srcPath, const std::string& hapPath } runtimeExtractor->SetRuntimeFlag(true); runtimeExtractorMap_.insert(make_pair(hapPath, runtimeExtractor)); + ExtractorUtil::AddExtractor(hapPath, runtimeExtractor); } else { runtimeExtractor = runtimeExtractorMap_.at(hapPath); } diff --git a/frameworks/native/runtime/js_runtime_utils.cpp b/frameworks/native/runtime/js_runtime_utils.cpp index dce4384f39f8bbdaa8d458afbfad33288f19389e..d4af3efc0801a8c160e13d6c593f9ea14afdf2fc 100644 --- a/frameworks/native/runtime/js_runtime_utils.cpp +++ b/frameworks/native/runtime/js_runtime_utils.cpp @@ -100,7 +100,7 @@ HandleScope::HandleScope(JsRuntime& jsRuntime) { scopeManager_ = jsRuntime.GetNativeEngine().GetScopeManager(); if (scopeManager_ != nullptr) { - nativeScope_ = scopeManager_->OpenEscape(); + nativeScope_ = scopeManager_->Open(); } } @@ -108,11 +108,37 @@ HandleScope::HandleScope(NativeEngine& engine) { scopeManager_ = engine.GetScopeManager(); if (scopeManager_ != nullptr) { - nativeScope_ = scopeManager_->OpenEscape(); + nativeScope_ = scopeManager_->Open(); } } HandleScope::~HandleScope() +{ + if (nativeScope_ != nullptr) { + scopeManager_->Close(nativeScope_); + nativeScope_ = nullptr; + } + scopeManager_ = nullptr; +} + +// Handle Escape +HandleEscape::HandleEscape(JsRuntime& jsRuntime) +{ + scopeManager_ = jsRuntime.GetNativeEngine().GetScopeManager(); + if (scopeManager_ != nullptr) { + nativeScope_ = scopeManager_->OpenEscape(); + } +} + +HandleEscape::HandleEscape(NativeEngine& engine) +{ + scopeManager_ = engine.GetScopeManager(); + if (scopeManager_ != nullptr) { + nativeScope_ = scopeManager_->OpenEscape(); + } +} + +HandleEscape::~HandleEscape() { if (nativeScope_ != nullptr) { scopeManager_->CloseEscape(nativeScope_); @@ -121,7 +147,7 @@ HandleScope::~HandleScope() scopeManager_ = nullptr; } -NativeValue* HandleScope::Escape(NativeValue* value) +NativeValue* HandleEscape::Escape(NativeValue* value) { if (nativeScope_ != nullptr) { scopeManager_->Escape(nativeScope_, value); diff --git a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h index 9b9f80197ca697eada99a965c6908cba00741440..d8e3e08e3ab2b5893f91179792a5f1440f35b37d 100644 --- a/interfaces/inner_api/ability_manager/include/ability_manager_interface.h +++ b/interfaces/inner_api/ability_manager/include/ability_manager_interface.h @@ -27,6 +27,7 @@ #include "ability_start_setting.h" #include "extension_running_info.h" #include "iability_controller.h" +#include "icomponent_interception.h" #include "mission_listener_interface.h" #include "mission_info.h" #include "mission_snapshot.h" @@ -551,6 +552,17 @@ public: virtual int SetAbilityController(const sptr &abilityController, bool imAStabilityTest) = 0; + /** + * Set component interception. + * + * @param componentInterception, component interception. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int SetComponentInterception(const sptr &componentInterception) + { + return 0; + } + /** * Is user a stability test. * @@ -860,6 +872,8 @@ public: // stop extension ability (61) STOP_EXTENSION_ABILITY, + SET_COMPONENT_INTERCEPTION, + // ipc id 1001-2000 for DMS // ipc id for starting ability (1001) START_ABILITY = 1001, diff --git a/interfaces/inner_api/ability_manager/include/container_manager_client.h b/interfaces/inner_api/ability_manager/include/container_manager_client.h new file mode 100755 index 0000000000000000000000000000000000000000..f555ae85fa31988504114288e565e09589d0db74 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/container_manager_client.h @@ -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. + */ + +#ifndef OHOS_CONTAINER_MANAGER_CLIENT_H +#define OHOS_CONTAINER_MANAGER_CLIENT_H + +#include + +#include "icontainer_manager.h" + +#include "iremote_object.h" +#include "system_memory_attr.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class ContainerManagerClient + * ContainerManagerClient is used to access container manager services. + */ +class ContainerManagerClient { +public: + ContainerManagerClient(); + virtual ~ContainerManagerClient(); + static std::shared_ptr GetInstance(); + + /** + * Notify the state of boot + * + * @param state, state of boot. + * @return Returns ERR_OK on success, others on failure. + */ + ErrCode NotifyBootComplete(int state); +private: + /** + * Connect ability manager service. + * + * @return Returns ERR_Ok on success, others on failure. + */ + ErrCode Connect(); + + static std::mutex mutex_; + static std::shared_ptr instance_; + sptr remoteObject_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_CONTAINER_MANAGER_CLIENT_H \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/include/container_manager_proxy.h b/interfaces/inner_api/ability_manager/include/container_manager_proxy.h new file mode 100755 index 0000000000000000000000000000000000000000..4ba88be8005ac03047e8945f647042ca5835e817 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/container_manager_proxy.h @@ -0,0 +1,53 @@ +/* + * 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_CONTAINER_MANAGER_PROXY_H +#define OHOS_CONTAINER_MANAGER_PROXY_H + +#include "icontainer_manager.h" +#include "hilog_wrapper.h" +#include "iremote_proxy.h" + +namespace OHOS { +namespace AAFwk { +/** + * @class ContainerManagerProxy + * ContainerManagerProxy. + */ +class ContainerManagerProxy : public IRemoteProxy { +public: + explicit ContainerManagerProxy(const sptr &impl) : IRemoteProxy(impl) + {} + + virtual ~ContainerManagerProxy() + {} + + /** + * Notify the state of boot. + * + * @param state, state of boot. + * @return Return ERR_OK on success, others on failure. + */ + virtual int NotifyBootComplete(int32_t state = 0) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + +private: + static inline BrokerDelegator delegator_; +}; +} // namespace AAFwk +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/inner_api/ability_manager/include/icontainer_manager.h b/interfaces/inner_api/ability_manager/include/icontainer_manager.h new file mode 100755 index 0000000000000000000000000000000000000000..006d97a6e92ae02d4a0ab354ec74efc8d1d40fa9 --- /dev/null +++ b/interfaces/inner_api/ability_manager/include/icontainer_manager.h @@ -0,0 +1,53 @@ +/* + * 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_CONTAINER_MANAGER_H +#define OHOS_CONTAINER_MANAGER_H + +#include +#include + +namespace OHOS { +namespace AAFwk { +const std::string CONTAINER_MANAGER_ABILITY_NAME = "ContainerManagerAbility"; +/** + * @class IContainerManager + * IContainerManager interface is used to access container manager services. + */ +class IContainerManager : public OHOS::IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.IContainerManager") + + enum : int32_t { + ERROR_DEF = -1, + }; + + /** + * Notify the state of boot. + * + * @param state, state of boot. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int NotifyBootComplete(int32_t state = 0) = 0; + + enum { + // ipc id 1-1000 for kit + // ipc id for notify boot complete (1) + NOTIFY_BOOT_COMPLETE = 1, + }; +}; +} // namespace AAFwk +} // namespace OHOS +#endif // OHOS_CONTAINER_MANAGER_H \ No newline at end of file diff --git a/interfaces/inner_api/app_manager/BUILD.gn b/interfaces/inner_api/app_manager/BUILD.gn index 99694ee87f60b50c2c4a4e2666580ab141a2135b..43ea33c7cc78138ec50db6562cebf0ddcaa9f773 100644 --- a/interfaces/inner_api/app_manager/BUILD.gn +++ b/interfaces/inner_api/app_manager/BUILD.gn @@ -69,6 +69,8 @@ ohos_shared_library("app_manager") { "src/appmgr/app_task_info.cpp", "src/appmgr/application_state_observer_proxy.cpp", "src/appmgr/application_state_observer_stub.cpp", + "src/appmgr/component_interception_proxy.cpp", + "src/appmgr/component_interception_stub.cpp", "src/appmgr/configuration_observer_proxy.cpp", "src/appmgr/configuration_observer_stub.cpp", "src/appmgr/priority_object.cpp", diff --git a/interfaces/inner_api/app_manager/include/appmgr/component_interception_proxy.h b/interfaces/inner_api/app_manager/include/appmgr/component_interception_proxy.h new file mode 100755 index 0000000000000000000000000000000000000000..06b9ec3104cceeea25bd117f8f56f5ec324824ab --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/component_interception_proxy.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_COMPONENT_INTERCEPTION_PROXY_H +#define OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_PROXY_H + +#include "iremote_proxy.h" +#include "icomponent_interception.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @brief Interface to monitor what is happening in component manager. + */ +class ComponentInterceptionProxy : public IRemoteProxy { +public: + explicit ComponentInterceptionProxy(const sptr &impl); + virtual ~ComponentInterceptionProxy() = default; + + /** + * The system is trying to start an component. + * + * @param want The want of component to start. + * @param callerToken Caller component token. + * @param requestCode the requestCode of the component to start. + * @param componentStatus the status of component. + * @param extraParam The extra param of component to start. + * @return Return true to allow component to start, or false to reject. + */ + virtual bool AllowComponentStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, sptr &extraParam) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + void SetExtraParam(const sptr &want, sptr &extraParam); + static inline BrokerDelegator delegator_; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif diff --git a/interfaces/inner_api/app_manager/include/appmgr/component_interception_stub.h b/interfaces/inner_api/app_manager/include/appmgr/component_interception_stub.h new file mode 100755 index 0000000000000000000000000000000000000000..b0f9db225adffa9604db91d9fce6f277afcdffd2 --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/component_interception_stub.h @@ -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. + */ + +#ifndef OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_STUB_H +#define OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_STUB_H + +#include "iremote_stub.h" +#include "icomponent_interception.h" + +namespace OHOS { +namespace AppExecFwk { +/** + * @brief Interface to monitor what is happening in component manager. + */ +class ComponentInterceptionStub : public IRemoteStub { +public: + ComponentInterceptionStub(); + virtual ~ComponentInterceptionStub(); + + virtual int OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + /** + * The system is trying to start an component. + * + * @param want The want of component to start. + * @param callerToken Caller component token. + * @param requestCode the requestCode of the component to start. + * @param componentStatus the status of component. + * @param extraParam The extra param of component to start. + * @return Return true to allow component to start, or false to reject. + */ + virtual bool AllowComponentStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, sptr &extraParam) override; + +private: + using ComponentInterceptionFunc = int32_t (ComponentInterceptionStub::*) + (MessageParcel &data, MessageParcel &reply); + std::map requestFuncMap_; + int32_t HandleAllowComponentStart(MessageParcel &data, MessageParcel &reply); + + DISALLOW_COPY_AND_MOVE(ComponentInterceptionStub); +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_STUB_H diff --git a/interfaces/inner_api/app_manager/include/appmgr/icomponent_interception.h b/interfaces/inner_api/app_manager/include/appmgr/icomponent_interception.h new file mode 100755 index 0000000000000000000000000000000000000000..3d746b8e1851cf596bbeec372485d1ab1f7e0e61 --- /dev/null +++ b/interfaces/inner_api/app_manager/include/appmgr/icomponent_interception.h @@ -0,0 +1,53 @@ +/* + * 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_COMPONENT_INTERCEPTION_H +#define OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_H + +#include "iremote_broker.h" +#include "iremote_object.h" +#include "want.h" + +namespace OHOS { +namespace AppExecFwk { +using OHOS::AAFwk::Want; + +/** + * @brief Interface to monitor what is happening in component manager. + */ +class IComponentInterception : public IRemoteBroker { +public: + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.appexecfwk.IComponentInterception"); + + /** + * The system is trying to start an component. + * + * @param want The want of component to start. + * @param callerToken Caller component token. + * @param requestCode the requestCode of the component to start. + * @param componentStatus the status of component. + * @param extraParam The extra param of component to start. + * @return Return true to allow component to start, or false to reject. + */ + virtual bool AllowComponentStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, sptr &extraParam) = 0; + + enum class Message { + TRANSACT_ON_ALLOW_COMPONENT_START = 1, + }; +}; +} // namespace AppExecFwk +} // namespace OHOS +#endif // OHOS_ABILITY_RUNTIME_COMPONENT_INTERCEPTION_H diff --git a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp index 12cb334058755bc4af5aa02ca22073046dbaa02d..20095585063937560d79f28d146cdddc5e974243 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/application_state_observer_stub.cpp @@ -59,7 +59,7 @@ ApplicationStateObserverStub::~ApplicationStateObserverStub() int ApplicationStateObserverStub::OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { - HILOG_INFO("ApplicationStateObserverStub::OnReceived, code = %{public}u, flags= %{public}d.", + HILOG_DEBUG("ApplicationStateObserverStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); std::u16string descriptor = ApplicationStateObserverStub::GetDescriptor(); std::u16string remoteDescriptor = data.ReadInterfaceToken(); 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 new file mode 100755 index 0000000000000000000000000000000000000000..1f9746099e561f5452c0374b33a4a07e99721aab --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/component_interception_proxy.cpp @@ -0,0 +1,86 @@ +/* + * 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 "component_interception_proxy.h" + +#include "hilog_wrapper.h" +#include "ipc_types.h" + + +namespace OHOS { +namespace AppExecFwk { +ComponentInterceptionProxy::ComponentInterceptionProxy( + const sptr &impl) : IRemoteProxy(impl) +{} + +bool ComponentInterceptionProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(ComponentInterceptionProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed"); + return false; + } + return true; +} + +bool ComponentInterceptionProxy::AllowComponentStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, sptr &extraParam) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option(MessageOption::TF_SYNC); + if (!WriteInterfaceToken(data)) { + return true; + } + data.WriteParcelable(&want); + data.WriteRemoteObject(callerToken); + data.WriteInt32(requestCode); + data.WriteInt32(componentStatus); + sptr remote = Remote(); + if (remote == nullptr) { + HILOG_ERROR("Remote() is NULL"); + return true; + } + int32_t ret = remote->SendRequest( + static_cast(IComponentInterception::Message::TRANSACT_ON_ALLOW_COMPONENT_START), + data, reply, option); + if (ret != NO_ERROR) { + HILOG_WARN("SendRequest is failed, error code: %{public}d", ret); + return true; + } + + bool hasExtraParam = reply.ReadBool(); + if (hasExtraParam) { + sptr tempWant = reply.ReadParcelable(); + if (tempWant != nullptr) { + SetExtraParam(tempWant, extraParam); + } + } + return reply.ReadBool(); +} + +void ComponentInterceptionProxy::SetExtraParam(const sptr &want, sptr &extraParam) +{ + sptr tempCallBack = want->GetRemoteObject(Want::PARAM_RESV_ABILITY_INFO_CALLBACK); + if (tempCallBack == nullptr) { + return; + } + extraParam->SetParam(Want::PARAM_RESV_REQUEST_PROC_CODE, + want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); + extraParam->SetParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, + want->GetIntParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, 0)); + extraParam->SetParam(Want::PARAM_RESV_ABILITY_INFO_CALLBACK, tempCallBack); +} +} // namespace AppExecFwk +} // namespace OHOS 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 new file mode 100755 index 0000000000000000000000000000000000000000..446c30f03e44b7a1594bb58127e479b2f726dd12 --- /dev/null +++ b/interfaces/inner_api/app_manager/src/appmgr/component_interception_stub.cpp @@ -0,0 +1,87 @@ +/* + * 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 "component_interception_stub.h" +#include "appexecfwk_errors.h" +#include "hilog_wrapper.h" +#include "ipc_types.h" +#include "iremote_object.h" + +namespace OHOS { +namespace AppExecFwk { +ComponentInterceptionStub::ComponentInterceptionStub() +{ + requestFuncMap_[static_cast( + IComponentInterception::Message::TRANSACT_ON_ALLOW_COMPONENT_START)] = + &ComponentInterceptionStub::HandleAllowComponentStart; +} + +ComponentInterceptionStub::~ComponentInterceptionStub() +{ + requestFuncMap_.clear(); +} + +int ComponentInterceptionStub::OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) +{ + HILOG_INFO("ComponentInterceptionStub::OnReceived, code = %{public}u, flags= %{public}d.", code, option.GetFlags()); + std::u16string descriptor = ComponentInterceptionStub::GetDescriptor(); + std::u16string remoteDescriptor = data.ReadInterfaceToken(); + if (descriptor != remoteDescriptor) { + HILOG_ERROR("local descriptor is not equal to remote"); + return ERR_INVALID_STATE; + } + + auto itFunc = requestFuncMap_.find(code); + if (itFunc != requestFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +bool ComponentInterceptionStub::AllowComponentStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, sptr &extraParam) +{ + return true; +} + +int32_t ComponentInterceptionStub::HandleAllowComponentStart(MessageParcel &data, MessageParcel &reply) +{ + HILOG_INFO("HandleAllowComponentStart"); + std::unique_ptr want(data.ReadParcelable()); + if (!want) { + HILOG_ERROR("ReadParcelable failed"); + return ERR_APPEXECFWK_PARCEL_ERROR; + } + sptr token = data.ReadRemoteObject(); + int requestCode = data.ReadInt32(); + int componentStatus = data.ReadInt32(); + + sptr extraParam = new (std::nothrow) Want(); + bool result = AllowComponentStart(*want, token, requestCode, componentStatus, extraParam); + if (want->GetRemoteObject(Want::PARAM_RESV_ABILITY_INFO_CALLBACK)) { + reply.WriteBool(true); + reply.WriteParcelable(extraParam); + } else { + reply.WriteBool(false); + } + reply.WriteBool(result); + return NO_ERROR; +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp index d7baaa3fbd1af3315b861503fd27f005954aa3ce..92dd371697ca78e37d72dfcc861b962c7e56846a 100644 --- a/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp +++ b/interfaces/inner_api/deps_wrapper/src/os_account_manager_wrapper.cpp @@ -33,11 +33,11 @@ const int32_t UID_TRANSFORM_DIVISOR = 200000; ErrCode OsAccountManagerWrapper::QueryActiveOsAccountIds(std::vector& ids) { #ifndef OS_ACCOUNT_PART_ENABLED - HILOG_INFO("execute %{public}s without os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s without os account subsystem.", __func__); ids.emplace_back(DEFAULT_OS_ACCOUNT_ID); return ERR_OK; #else - HILOG_INFO("execute %{public}s with os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s with os account subsystem.", __func__); return AccountSA::OsAccountManager::QueryActiveOsAccountIds(ids); #endif // OS_ACCOUNT_PART_ENABLED } @@ -45,11 +45,11 @@ ErrCode OsAccountManagerWrapper::QueryActiveOsAccountIds(std::vector& i ErrCode OsAccountManagerWrapper::GetOsAccountLocalIdFromUid(const int32_t uid, int32_t &id) { #ifndef OS_ACCOUNT_PART_ENABLED - HILOG_INFO("execute %{public}s without os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s without os account subsystem.", __func__); id = uid / UID_TRANSFORM_DIVISOR; return ERR_OK; #else - HILOG_INFO("execute %{public}s with os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s with os account subsystem.", __func__); return AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(uid, id); #endif // OS_ACCOUNT_PART_ENABLED } @@ -57,11 +57,11 @@ ErrCode OsAccountManagerWrapper::GetOsAccountLocalIdFromUid(const int32_t uid, i ErrCode OsAccountManagerWrapper::GetOsAccountLocalIdFromProcess(int &id) { #ifndef OS_ACCOUNT_PART_ENABLED - HILOG_INFO("execute %{public}s without os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s without os account subsystem.", __func__); id = DEFAULT_OS_ACCOUNT_ID; return ERR_OK; #else - HILOG_INFO("execute %{public}s with os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s with os account subsystem.", __func__); return AccountSA::OsAccountManager::GetOsAccountLocalIdFromProcess(id); #endif // OS_ACCOUNT_PART_ENABLED } @@ -69,11 +69,11 @@ ErrCode OsAccountManagerWrapper::GetOsAccountLocalIdFromProcess(int &id) ErrCode OsAccountManagerWrapper::IsOsAccountExists(const int id, bool &isOsAccountExists) { #ifndef OS_ACCOUNT_PART_ENABLED - HILOG_INFO("execute %{public}s without os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s without os account subsystem.", __func__); isOsAccountExists = (id == DEFAULT_OS_ACCOUNT_ID); return ERR_OK; #else // OS_ACCOUNT_PART_ENABLED - HILOG_INFO("execute %{public}s with os account subsystem.", __func__); + HILOG_DEBUG("execute %{public}s with os account subsystem.", __func__); return AccountSA::OsAccountManager::IsOsAccountExists(id, isOsAccountExists); #endif // OS_ACCOUNT_PART_ENABLED } diff --git a/interfaces/inner_api/runtime/include/js_runtime_utils.h b/interfaces/inner_api/runtime/include/js_runtime_utils.h index dc73d7b1a6cbfff0246ee88cd3718e119a2ab280..297445001b619724c26b80cd063c51a6df79bf34 100644 --- a/interfaces/inner_api/runtime/include/js_runtime_utils.h +++ b/interfaces/inner_api/runtime/include/js_runtime_utils.h @@ -134,8 +134,6 @@ public: explicit HandleScope(NativeEngine& engine); ~HandleScope(); - NativeValue* Escape(NativeValue* value); - HandleScope(const HandleScope&) = delete; HandleScope(HandleScope&&) = delete; HandleScope& operator=(const HandleScope&) = delete; @@ -146,6 +144,24 @@ private: NativeScope* nativeScope_ = nullptr; }; +class HandleEscape final { +public: + explicit HandleEscape(JsRuntime& jsRuntime); + explicit HandleEscape(NativeEngine& engine); + ~HandleEscape(); + + NativeValue* Escape(NativeValue* value); + + HandleEscape(const HandleEscape&) = delete; + HandleEscape(HandleEscape&&) = delete; + HandleEscape& operator=(const HandleEscape&) = delete; + HandleEscape& operator=(HandleEscape&&) = delete; + +private: + NativeScopeManager* scopeManager_ = nullptr; + NativeScope* nativeScope_ = nullptr; +}; + class AsyncTask final { public: using ExecuteCallback = std::function; diff --git a/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h b/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h index 3b40f9f150a92a611cecffacb803eb8745f8f8a6..9a5da62aa8bc1b66ac56be35263d2cf393d41dbc 100644 --- a/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h +++ b/interfaces/kits/native/ability/native/continuation/remote_register_service/connect_callback_proxy.h @@ -28,6 +28,8 @@ namespace AppExecFwk { */ class ConnectCallbackProxy : public IRemoteProxy { public: + ConnectCallbackProxy(const sptr &object) : IRemoteProxy(object) {}; + virtual ~ConnectCallbackProxy() = default; /** * @brief Remote device sends connection request. * @param deviceId indicators id of connection device. diff --git a/interfaces/kits/native/appkit/app/watchdog.h b/interfaces/kits/native/appkit/app/watchdog.h index c7a1a8f0350f729dceec1c6c3bc78517b59222d9..7d9369aa5aa6061a4b8047fefbe7d92205f91997 100644 --- a/interfaces/kits/native/appkit/app/watchdog.h +++ b/interfaces/kits/native/appkit/app/watchdog.h @@ -102,7 +102,6 @@ public: private: void Timer(); - bool WaitForDuration(uint32_t duration); void ReportEvent(); std::atomic_bool appMainThreadIsAlive_ = false; diff --git a/services/abilitymgr/abilitymgr.gni b/services/abilitymgr/abilitymgr.gni index c8622d77648e4fecffd7e7956b955785b4f2ec12..a9286ac30180c03bcff266e3cec9695cfc4a9644 100644 --- a/services/abilitymgr/abilitymgr.gni +++ b/services/abilitymgr/abilitymgr.gni @@ -22,6 +22,8 @@ abilityms_files = [ "src/ability_manager_service.cpp", "src/ability_manager_stub.cpp", "src/ability_manager_proxy.cpp", + "src/container_manager_proxy.cpp", + "src/container_manager_client.cpp", "src/ability_record.cpp", "src/ability_scheduler_stub.cpp", "src/ability_scheduler_proxy.cpp", diff --git a/services/abilitymgr/include/ability_manager_proxy.h b/services/abilitymgr/include/ability_manager_proxy.h index b8d3ff48286f4c13aa10139019cc4fcc1902ded8..5fd932a555f206fc6ab5d6d113246e2c4da598fe 100644 --- a/services/abilitymgr/include/ability_manager_proxy.h +++ b/services/abilitymgr/include/ability_manager_proxy.h @@ -475,6 +475,9 @@ public: virtual int SetAbilityController(const sptr &abilityController, bool imAStabilityTest) override; + virtual int SetComponentInterception( + const sptr &componentInterception) override; + /** * Is user a stability test. * diff --git a/services/abilitymgr/include/ability_manager_service.h b/services/abilitymgr/include/ability_manager_service.h index 564b4bcb9b5b9b56d8c4926058bddf4c744c10f4..555059eace1cb46c715f168c6bf86e69c5608036 100644 --- a/services/abilitymgr/include/ability_manager_service.h +++ b/services/abilitymgr/include/ability_manager_service.h @@ -713,6 +713,15 @@ public: */ virtual int DoAbilityBackground(const sptr &token, uint32_t flag) override; + /** + * Set component interception. + * + * @param componentInterception, component interception. + * @return Returns ERR_OK on success, others on failure. + */ + virtual int SetComponentInterception( + const sptr &componentInterception) override; + bool IsAbilityControllerStart(const Want &want, const std::string &bundleName); bool IsAbilityControllerForeground(const std::string &bundleName); @@ -721,6 +730,9 @@ public: void GrantUriPermission(const Want &want, int32_t validUserId, uint32_t targetTokenId); + bool IsComponentInterceptionStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, AbilityRequest &request); + /** * Send not response process ID to ability manager service. * @param pid The not response process ID. @@ -1164,6 +1176,8 @@ private: void InitStartupFlag(); + void UpdateAbilityRequestInfo(const sptr &want, AbilityRequest &request); + constexpr static int REPOLL_TIME_MICRO_SECONDS = 1000000; constexpr static int WAITING_BOOT_ANIMATION_TIMER = 5; @@ -1193,6 +1207,7 @@ private: bool controllerIsAStabilityTest_ = false; std::recursive_mutex globalLock_; std::shared_mutex managersMutex_; + sptr componentInterception_ = nullptr; std::multimap timeoutMap_; diff --git a/services/abilitymgr/include/ability_manager_stub.h b/services/abilitymgr/include/ability_manager_stub.h index 1c9ff1666a7769c4b0bc079da3e6e3fd797d93a1..c46c54b7eda61d3de27185ca674397d745300111 100644 --- a/services/abilitymgr/include/ability_manager_stub.h +++ b/services/abilitymgr/include/ability_manager_stub.h @@ -150,6 +150,7 @@ private: int SendANRProcessIDInner(MessageParcel &data, MessageParcel &reply); int SetAbilityControllerInner(MessageParcel &data, MessageParcel &reply); + int SetComponentInterceptionInner(MessageParcel &data, MessageParcel &reply); int StartUserTestInner(MessageParcel &data, MessageParcel &reply); int FinishUserTestInner(MessageParcel &data, MessageParcel &reply); diff --git a/services/abilitymgr/src/ability_manager_proxy.cpp b/services/abilitymgr/src/ability_manager_proxy.cpp index 1ac3ca199f9536148b30149c093a2ed55ca0ccb7..3efef2f6c2fe46b93a6d48a9e955c2c08453cac4 100644 --- a/services/abilitymgr/src/ability_manager_proxy.cpp +++ b/services/abilitymgr/src/ability_manager_proxy.cpp @@ -2294,6 +2294,30 @@ int AbilityManagerProxy::SetAbilityController(const sptr &componentInterception) +{ + if (!componentInterception) { + HILOG_ERROR("componentInterception nullptr"); + return ERR_INVALID_VALUE; + } + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!WriteInterfaceToken(data)) { + return INNER_ERR; + } + if (!data.WriteRemoteObject(componentInterception->AsObject())) { + HILOG_ERROR("componentInterception write failed."); + return ERR_INVALID_VALUE; + } + auto error = Remote()->SendRequest(IAbilityManager::SET_COMPONENT_INTERCEPTION, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} + bool AbilityManagerProxy::IsRunningInStabilityTest() { MessageParcel data; diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 351da0a6f5bea75419a79769e3dfb727d545f368..fb7898aaca0680d806ec7dcd3d78036b14f51d80 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -579,6 +579,10 @@ int AbilityManagerService::StartAbilityInner(const Want &want, const sptrGetApplicationInfo().uid / BASE_USER_RANGE; auto abilityInfo = abilityRecord->GetAbilityInfo(); @@ -2861,6 +2868,10 @@ int AbilityManagerService::AbilityTransitionDone(const sptr &toke } auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN_LOG(abilityRecord, ERR_INVALID_VALUE, "Ability record is nullptr."); + if (!JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } + auto abilityInfo = abilityRecord->GetAbilityInfo(); HILOG_DEBUG("Ability transition done come, state:%{public}d, name:%{public}s", state, abilityInfo.name.c_str()); auto type = abilityInfo.type; @@ -2912,6 +2923,9 @@ int AbilityManagerService::ScheduleConnectAbilityDone( auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + if (!JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } auto type = abilityRecord->GetAbilityInfo().type; if (type != AppExecFwk::AbilityType::SERVICE && type != AppExecFwk::AbilityType::EXTENSION) { @@ -2937,6 +2951,9 @@ int AbilityManagerService::ScheduleDisconnectAbilityDone(const sptrGetAbilityInfo().type; if (type != AppExecFwk::AbilityType::SERVICE && type != AppExecFwk::AbilityType::EXTENSION) { @@ -2962,6 +2979,9 @@ int AbilityManagerService::ScheduleCommandAbilityDone(const sptr auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + if (!JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } // force timeout ability for test if (IsNeedTimeoutForTest(abilityRecord->GetAbilityInfo().name, std::string("COMMAND"))) { HILOG_WARN("force timeout ability for test, state:COMMAND, ability: %{public}s", @@ -3140,10 +3160,10 @@ int AbilityManagerService::GenerateAbilityRequest( request.callerToken = callerToken; request.startSetting = nullptr; - auto isPerm = AAFwk::PermissionVerification::GetInstance()->VerifyMissionPermission(); - if (isPerm) { - sptr abilityInfoCallback = want.GetRemoteObject("abilityInfoCallback"); - if (abilityInfoCallback != nullptr) { + sptr abilityInfoCallback = want.GetRemoteObject(Want::PARAM_RESV_ABILITY_INFO_CALLBACK); + if (abilityInfoCallback != nullptr) { + auto isPerm = AAFwk::PermissionVerification::GetInstance()->IsGatewayCall(); + if (isPerm) { request.abilityInfoCallback = abilityInfoCallback; } } @@ -3733,6 +3753,13 @@ void AbilityManagerService::StartResidentApps() HILOG_DEBUG("%{public}s", __func__); ConnectBmsService(); auto bms = GetBundleManager(); + auto client = ContainerManagerClient::GetInstance(); + if (client == nullptr) { + HILOG_ERROR("%{public}s get ContainerManagerClient null", __func__) + } else { + client->NotifyBootComplete(0); + HILOG_INFO("StartSystemApplication NotifyBootComplete"); + } CHECK_POINTER_IS_NULLPTR(bms); std::vector bundleInfos; if (!IN_PROCESS_CALL( @@ -3850,6 +3877,9 @@ int32_t AbilityManagerService::GetMissionIdByAbilityToken(const sptrGetOwnerMissionUserId(); auto missionListManager = GetListManagerByUserId(userId); if (!missionListManager) { @@ -3894,6 +3924,11 @@ int AbilityManagerService::StartAbilityByCall( CHECK_POINTER_AND_RETURN(connect, ERR_INVALID_VALUE); CHECK_POINTER_AND_RETURN(connect->AsObject(), ERR_INVALID_VALUE); + auto abilityRecord = Token::GetAbilityRecordByToken(callerToken); + if (abilityRecord && !JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } + auto result = interceptorExecuter_ == nullptr ? ERR_INVALID_VALUE : interceptorExecuter_->DoProcess(want, 0, GetUserId(), false); if (result != ERR_OK) { @@ -4201,6 +4236,10 @@ int32_t AbilityManagerService::GetMissionSnapshot(const std::string& deviceId, i void AbilityManagerService::UpdateMissionSnapShot(const sptr& token) { CHECK_POINTER_LOG(currentMissionListManager_, "Current mission manager not init."); + auto abilityRecord = Token::GetAbilityRecordByToken(token); + if (abilityRecord && !JudgeSelfCalled(abilityRecord)) { + return; + } auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); if (!isSaCall) { auto bms = GetBundleManager(); @@ -4755,6 +4794,9 @@ int AbilityManagerService::DoAbilityForeground(const sptr &token, std::lock_guard guard(globalLock_); auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER_AND_RETURN(abilityRecord, ERR_INVALID_VALUE); + if (!JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } int result = JudgeAbilityVisibleControl(abilityRecord->GetAbilityInfo()); if (result != ERR_OK) { HILOG_ERROR("%{public}s JudgeAbilityVisibleControl error.", __func__); @@ -5207,6 +5249,9 @@ int AbilityManagerService::DumpAbilityInfoDone(std::vector &infos, HILOG_ERROR("abilityRecord nullptr"); return ERR_INVALID_VALUE; } + if (!JudgeSelfCalled(abilityRecord)) { + return CHECK_PERMISSION_FAILED; + } abilityRecord->DumpAbilityInfoDone(infos); return ERR_OK; } @@ -5558,7 +5603,7 @@ int AbilityManagerService::IsCallFromBackground(const AbilityRequest &abilityReq } else { auto callerPid = IPCSkeleton::GetCallingPid(); DelayedSingleton::GetInstance()->GetRunningProcessInfoByPid(callerPid, processInfo); - if (processInfo.processName_.empty()) { + if (processInfo.processName_.empty() && !AAFwk::PermissionVerification::GetInstance()->IsGatewayCall()) { HILOG_ERROR("Can not find caller application by callerPid, callerPid: %{private}d.", callerPid); return ERR_INVALID_VALUE; } @@ -5664,6 +5709,9 @@ void AbilityManagerService::CallRequestDone(const sptr &token, co { auto abilityRecord = Token::GetAbilityRecordByToken(token); CHECK_POINTER(abilityRecord); + if (!JudgeSelfCalled(abilityRecord)) { + return; + } abilityRecord->CallRequestDone(callStub); } @@ -5699,12 +5747,61 @@ bool AbilityManagerService::JudgeSelfCalled(const std::shared_ptr auto callingTokenId = IPCSkeleton::GetCallingTokenID(); auto tokenID = abilityRecord->GetApplicationInfo().accessTokenId; - if (callingTokenId != tokenID) { + if (callingTokenId != tokenID && !AAFwk::PermissionVerification::GetInstance()->IsGatewayCall()) { HILOG_ERROR("Is not self, not enabled"); return false; } return true; } + +int AbilityManagerService::SetComponentInterception( + const sptr &componentInterception) +{ + HILOG_DEBUG("%{public}s", __func__); + auto isPerm = AAFwk::PermissionVerification::GetInstance()->IsGatewayCall(); + if (!isPerm) { + HILOG_ERROR("%{public}s: Permission verification failed", __func__); + return CHECK_PERMISSION_FAILED; + } + + std::lock_guard guard(globalLock_); + componentInterception_ = componentInterception; + HILOG_DEBUG("%{public}s, end", __func__); + return ERR_OK; +} + +bool AbilityManagerService::IsComponentInterceptionStart(const Want &want, const sptr &callerToken, + int requestCode, int componentStatus, AbilityRequest &request) +{ + if (componentInterception_ != nullptr) { + HILOG_DEBUG("%{public}s", __func__); + sptr extraParam = new (std::nothrow) Want(); + bool isStart = componentInterception_->AllowComponentStart(want, callerToken, + requestCode, componentStatus, extraParam); + UpdateAbilityRequestInfo(extraParam, request); + if (!isStart) { + HILOG_INFO("not finishing start component because interception"); + return false; + } + } + return true; +} + +void AbilityManagerService::UpdateAbilityRequestInfo(const sptr &want, AbilityRequest &request) +{ + if (want == nullptr) { + return; + } + sptr tempCallBack = want->GetRemoteObject(Want::PARAM_RESV_ABILITY_INFO_CALLBACK); + if (tempCallBack == nullptr) { + return; + } + request.want.SetParam(Want::PARAM_RESV_REQUEST_PROC_CODE, + want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); + request.want.SetParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, + want->GetIntParam(Want::PARAM_RESV_REQUEST_TOKEN_CODE, 0)); + request.abilityInfoCallback = tempCallBack; +} } // namespace AAFwk } // namespace OHOS diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 4192d082c4537570a8f588a5ea865101c3ddc065..2eec84244404854dc6807f05c2b70e35497b2bcb 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -151,6 +151,7 @@ void AbilityManagerStub::ThirdStepInit() requestFuncMap_[REGISTER_WMS_HANDLER] = &AbilityManagerStub::RegisterWindowManagerServiceHandlerInner; requestFuncMap_[COMPLETEFIRSTFRAMEDRAWING] = &AbilityManagerStub::CompleteFirstFrameDrawingInner; #endif + requestFuncMap_[SET_COMPONENT_INTERCEPTION] = &AbilityManagerStub::SetComponentInterceptionInner; } int AbilityManagerStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) @@ -1255,6 +1256,23 @@ int AbilityManagerStub::SetAbilityControllerInner(MessageParcel &data, MessagePa return NO_ERROR; } +int AbilityManagerStub::SetComponentInterceptionInner(MessageParcel &data, MessageParcel &reply) +{ + sptr componentInterception = + iface_cast(data.ReadRemoteObject()); + if (componentInterception == nullptr) { + HILOG_ERROR("AbilityManagerStub: SetComponentInterceptionInner readParcelable failed!"); + return ERR_NULL_OBJECT; + } + int32_t result = SetComponentInterception(componentInterception); + HILOG_INFO("AbilityManagerStub: SetComponentInterceptionInner result = %{public}d", result); + if (!reply.WriteInt32(result)) { + HILOG_ERROR("SetComponentInterceptionInner failed."); + return ERR_INVALID_VALUE; + } + return NO_ERROR; +} + int AbilityManagerStub::IsRunningInStabilityTestInner(MessageParcel &data, MessageParcel &reply) { bool result = IsRunningInStabilityTest(); diff --git a/services/abilitymgr/src/container_manager_client.cpp b/services/abilitymgr/src/container_manager_client.cpp new file mode 100755 index 0000000000000000000000000000000000000000..a704ef707a25265da0e84a2bba0ccb93ddcc4f51 --- /dev/null +++ b/services/abilitymgr/src/container_manager_client.cpp @@ -0,0 +1,104 @@ +/* + * 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 "container_manager_client.h" + +#include "string_ex.h" +#include "icontainer_manager.h" +#include "hilog_wrapper.h" +#include "if_system_ability_manager.h" +#include "ipc_skeleton.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + +namespace OHOS { +namespace AAFwk { +std::shared_ptr ContainerManagerClient::instance_ = nullptr; +std::mutex ContainerManagerClient::mutex_; + +#define CHECK_REMOTE_OBJECT(object) \ + if (!object) { \ + if (ERR_OK != Connect()) { \ + HILOG_ERROR("container manager can't connect."); \ + return; \ + } \ + } + +#define CHECK_REMOTE_OBJECT_AND_RETURN(object, value) \ + if (!object) { \ + if (ERR_OK != Connect()) { \ + HILOG_ERROR("container manager can't connect."); \ + return value; \ + } \ + } + +std::shared_ptr ContainerManagerClient::GetInstance() +{ + if (instance_ == nullptr) { + std::lock_guard lock_l(mutex_); + if (instance_ == nullptr) { + instance_ = std::make_shared(); + } + } + return instance_; +} + +ContainerManagerClient::ContainerManagerClient() +{} + +ContainerManagerClient::~ContainerManagerClient() +{} + +ErrCode ContainerManagerClient::Connect() +{ + std::lock_guard lock(mutex_); + if (remoteObject_ != nullptr) { + return ERR_OK; + } + sptr systemManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemManager == nullptr) { + HILOG_ERROR("Fail to get registry."); + return -1; + } + remoteObject_ = systemManager->GetSystemAbility(19000); + + uint32_t waitCnt = 0; + while (waitCnt < 50 && remoteObject_ == nullptr) { + usleep(100 * 1000); // 100ms + HILOG_ERROR("Fail to connect container manager service."); + remoteObject_ = systemManager->GetSystemAbility(19000); + waitCnt++; + } + + if (remoteObject_ == nullptr) { + HILOG_ERROR("Fail to connect container manager service."); + return -1; + } + + HILOG_DEBUG("Connect container manager service success."); + return ERR_OK; +} + +ErrCode ContainerManagerClient::NotifyBootComplete(int state) +{ + CHECK_REMOTE_OBJECT_AND_RETURN(remoteObject_, -1); + sptr container_manager = iface_cast(remoteObject_); + HILOG_INFO("NotifyBootComplete"); + return container_manager->NotifyBootComplete(state); +} +} // namespace AAFwk +} // namespace AAFwk \ No newline at end of file diff --git a/services/abilitymgr/src/container_manager_proxy.cpp b/services/abilitymgr/src/container_manager_proxy.cpp new file mode 100755 index 0000000000000000000000000000000000000000..50399313c61df83d7a80c602d7ffbca76f77c1ff --- /dev/null +++ b/services/abilitymgr/src/container_manager_proxy.cpp @@ -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. + */ + +#include "container_manager_proxy.h" + +#include "errors.h" +#include "string_ex.h" + +namespace OHOS { +namespace AAFwk { +bool ContainerManagerProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(ContainerManagerProxy::GetDescriptor())) { + HILOG_ERROR("write interface token failed."); + return false; + } + return true; +} + +int ContainerManagerProxy::NotifyBootComplete(int32_t state) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + if (!WriteInterfaceToken(data)) { + return -1; + } + + if (!data.WriteInt32(state)) { + HILOG_ERROR("state write failed."); + return -1; + } + + int error = Remote()->SendRequest(IContainerManager::NOTIFY_BOOT_COMPLETE, data, reply, option); + if (error != NO_ERROR) { + HILOG_ERROR("Send request error: %{public}d", error); + return error; + } + return reply.ReadInt32(); +} +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 9f071d4371c888d821cec17fefa2876cb3952565..29bf0ac385d18a488867cb28fe0d733a92fe28bb 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -171,7 +171,7 @@ void AppMgrServiceInner::LoadAbility(const sptr &token, const spt StartProcess(abilityInfo->applicationName, processName, startFlags, appRecord, appInfo->uid, appInfo->bundleName, bundleIndex); } else { - appRecord->SetRequestProcCode((want == nullptr) ? 0 : want->GetIntParam("requestProcCode", 0)); + appRecord->SetRequestProcCode((want == nullptr) ? 0 : want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); StartAbility(token, preToken, abilityInfo, appRecord, hapModuleInfo, want); } PerfProfile::GetInstance().SetAbilityLoadEndTime(GetTickCount()); @@ -880,7 +880,7 @@ std::shared_ptr AppMgrServiceInner::CreateAppRunningRecord(con } appRecord->SetAppIndex(want->GetIntParam(DLP_PARAMS_INDEX, 0)); appRecord->SetSecurityFlag(want->GetBoolParam(DLP_PARAMS_SECURITY_FLAG, false)); - appRecord->SetRequestProcCode(want->GetIntParam("requestProcCode", 0)); + appRecord->SetRequestProcCode(want->GetIntParam(Want::PARAM_RESV_REQUEST_PROC_CODE, 0)); } if (preToken) { diff --git a/services/common/include/permission_constants.h b/services/common/include/permission_constants.h index d3dd2923b961084f41a10a14020054aa5492a7f6..9e8159bacee12996716fb3317c5bb7b877a50668 100644 --- a/services/common/include/permission_constants.h +++ b/services/common/include/permission_constants.h @@ -34,6 +34,7 @@ constexpr const char* PERMISSION_START_INVISIBLE_ABILITY = "ohos.permission.STAR constexpr const char* PERMISSION_START_ABILITIES_FROM_BACKGROUND = "ohos.permission.START_ABILITIES_FROM_BACKGROUND"; constexpr const char* PERMISSION_START_ABILIIES_FROM_BACKGROUND = "ohos.permission.START_ABILIIES_FROM_BACKGROUND"; constexpr const char* PERMISSION_ABILITY_BACKGROUND_COMMUNICATION = "ohos.permission.ABILITY_BACKGROUND_COMMUNICATION"; +constexpr const char* PERMISSION_MANAGER_ABILITY_FROM_GATEWAY = "ohos.permission.MANAGER_ABILITY_FROM_GATEWAY"; } // namespace PermissionConstants } // namespace AAFwk } // namespace OHOS diff --git a/services/common/include/permission_verification.h b/services/common/include/permission_verification.h index 7723e5732c6a3e69c7539a14ad119bf3bb9cbecc..1ad049bd5f1d6a02082481fcf030d6f34755062f 100644 --- a/services/common/include/permission_verification.h +++ b/services/common/include/permission_verification.h @@ -41,6 +41,8 @@ struct VerificationInfo { bool IsShellCall() const; + bool IsGatewayCall() const; + bool CheckSpecificSystemAbilityAccessPermission() const; bool VerifyRunningInfoPerm() const; diff --git a/services/common/src/permission_verification.cpp b/services/common/src/permission_verification.cpp index ce51e02c72e303090c3c6667a45f213f51c6413c..ce90f42ac2f5511080c1fe6237645c0dd71b346d 100644 --- a/services/common/src/permission_verification.cpp +++ b/services/common/src/permission_verification.cpp @@ -64,6 +64,16 @@ bool PermissionVerification::IsShellCall() const return false; } +bool PermissionVerification::IsGatewayCall() const +{ + if (VerifyCallingPermission(PermissionConstants::PERMISSION_MANAGER_ABILITY_FROM_GATEWAY)) { + HILOG_DEBUG("%{public}s: Permission verification succeeded.", __func__); + return true; + } + HILOG_INFO("%{public}s: Permission verification failed.", __func__); + return false; +} + bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission() const { HILOG_DEBUG("PermissionVerification::CheckSpecifidSystemAbilityAccessToken is called."); diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index db6c7d748d5959d81621c69ae390b428916e23e1..9fae775f8310ce5468c4b0858e5372390676c282 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -317,11 +317,14 @@ group("unittest") { "app_mgr_service_event_handler_test:unittest", "app_mgr_service_inner_test:unittest", "app_mgr_service_test:unittest", + "app_mgr_service_test:unittest", "app_mgr_stub_test:unittest", "app_recovery_test:unittest", "app_running_processes_info_test:unittest", "app_scheduler_test:unittest", "app_spawn_client_test:unittest", + "app_spawn_socket_test:unittest", + "app_state_observer_manager_test:unittest", "appkit:unittest", "atomic_service_status_callback_proxy_test:unittest", "atomic_service_status_callback_stub_test:unittest", @@ -353,6 +356,7 @@ group("unittest") { "frameworks_kits_appkit_native_test:unittest", "free_install_manager_test:unittest", "image_info_test:unittest", + "implicit_start_processor_test:unittest", "lifecycle_deal_test:unittest", "lifecycle_test:unittest", "mission_data_storage_test:unittest", 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 a36bfd2a7050cf3cba16830d2ec3d9bb20dc637b..1846dbd4858da3932b0b21f83e67101803c1b300 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 @@ -45,6 +45,8 @@ struct VerificationInfo { bool IsShellCall() const; + bool IsGatewayCall() const; + bool CheckSpecificSystemAbilityAccessPermission() const; bool VerifyRunningInfoPerm() const; 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 8e0782e9b8ffe430b854e26852af1eb47751eb78..ef7cd01eb6fa2a0e8f75cabf9a8d98e912d45056 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 @@ -31,6 +31,10 @@ bool PermissionVerification::IsShellCall() const { return (MyFlag::flag_ & MyFlag::FLAG::IS_SHELL_CALL); } +bool PermissionVerification::IsGatewayCall() const +{ + return false; +} bool PermissionVerification::CheckSpecificSystemAbilityAccessPermission() const { return !!(MyFlag::flag_); diff --git a/test/unittest/ams_mgr_scheduler_test/BUILD.gn b/test/unittest/ams_mgr_scheduler_test/BUILD.gn index 8ae43c3508a9c65dd05cb1bce7869ed54931dc84..5e64ac71b1a1aa6b8c3bf9034022b301468520d7 100644 --- a/test/unittest/ams_mgr_scheduler_test/BUILD.gn +++ b/test/unittest/ams_mgr_scheduler_test/BUILD.gn @@ -14,9 +14,9 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/appmgrservice" +module_output_path = "ability_runtime/appmgr" -ohos_unittest("AmsMgrSchedulerTest") { +ohos_unittest("ams_mgr_scheduler_test") { module_out_path = module_output_path cflags_cc = [] include_dirs = [ @@ -42,12 +42,28 @@ ohos_unittest("AmsMgrSchedulerTest") { external_deps = [ "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] + + defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } + + if (ability_runtime_graphics) { + defines += [ "SUPPORT_GRAPHICS" ] + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } } group("unittest") { testonly = true - # deps = [ ":AmsMgrSchedulerTest" ] + deps = [ ":ams_mgr_scheduler_test" ] } diff --git a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp index a8972c2df4bf9e1e1b689c41b5f895427ab5515b..7d63777ffb71b8d980c3029172b2d04bff0cfc3f 100644 --- a/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp +++ b/test/unittest/ams_mgr_scheduler_test/ams_mgr_scheduler_test.cpp @@ -203,10 +203,10 @@ HWTEST_F(AmsMgrSchedulerTest, AmsMgrScheduler_004, TestSize.Level1) std::unique_ptr amsMgrScheduler = std::make_unique(mockAppMgrServiceInner, amsEventHandler); sptr token = new MockAbilityToken(); - - EXPECT_CALL(*mockAppMgrServiceInner, TerminateAbility(_)) + bool clearMissionFlag = true; + EXPECT_CALL(*mockAppMgrServiceInner, TerminateAbility(_, _)) .WillOnce(InvokeWithoutArgs(mockAppMgrServiceInner.get(), &MockAppMgrServiceInner::Post)); - amsMgrScheduler->TerminateAbility(token); + amsMgrScheduler->TerminateAbility(token, clearMissionFlag); mockAppMgrServiceInner->Wait(); HILOG_DEBUG("AmsMgrScheduler_004 end."); @@ -393,7 +393,7 @@ HWTEST_F(AmsMgrSchedulerTest, RegisterApplicationStateObserver_001, TestSize.Lev mockAppMgrServiceInner->RegisterApplicationStateObserver(observer); int32_t err = mockAppMgrServiceInner->RegisterApplicationStateObserver(observer); // repeat register return ERR_INVALID_VALUE - EXPECT_EQ(ERR_INVALID_VALUE, err); + EXPECT_EQ(1, err); HILOG_DEBUG("RegisterApplicationStateObserver_001 end"); } @@ -411,11 +411,410 @@ HWTEST_F(AmsMgrSchedulerTest, UnregisterApplicationStateObserver_001, TestSize.L auto mockAppMgrServiceInner = std::make_shared(); int32_t err1 = mockAppMgrServiceInner->UnregisterApplicationStateObserver(observer); // unregister not exist return ERR_INVALID_VALUE - EXPECT_EQ(ERR_INVALID_VALUE, err1); + EXPECT_EQ(1, err1); int32_t err2 = mockAppMgrServiceInner->UnregisterApplicationStateObserver(nullptr); // unregister null return ERR_INVALID_VALUE - EXPECT_EQ(ERR_INVALID_VALUE, err2); + EXPECT_EQ(1, err2); HILOG_DEBUG("UnregisterApplicationStateObserver_001 end"); } + +/* + * Feature: AmsMgrScheduler + * Function: LoadAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler LoadAbility + * EnvConditions: NA + * CaseDescription: Verify LoadAbility + */ +HWTEST_F(AmsMgrSchedulerTest, LoadAbility_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_shared(nullptr, nullptr); + sptr token = nullptr; + sptr preToken = nullptr; + std::shared_ptr abilityInfo = nullptr; + std::shared_ptr appInfo = nullptr; + std::shared_ptr want = nullptr; + amsMgrScheduler->LoadAbility(token, preToken, abilityInfo, appInfo, want); +} + +/* + * Feature: AmsMgrScheduler + * Function: LoadAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler LoadAbility + * EnvConditions: NA + * CaseDescription: Verify LoadAbility + */ +HWTEST_F(AmsMgrSchedulerTest, LoadAbility_002, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_shared(nullptr, nullptr); + sptr token = nullptr; + sptr preToken = nullptr; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr appInfo = nullptr; + std::shared_ptr want = nullptr; + amsMgrScheduler->LoadAbility(token, preToken, abilityInfo, appInfo, want); +} + +/* + * Feature: AmsMgrScheduler + * Function: LoadAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler LoadAbility + * EnvConditions: NA + * CaseDescription: Verify LoadAbility + */ +HWTEST_F(AmsMgrSchedulerTest, LoadAbility_003, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_shared(nullptr, nullptr); + sptr token = nullptr; + sptr preToken = nullptr; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr appInfo = std::make_shared(); + std::shared_ptr want = nullptr; + amsMgrScheduler->LoadAbility(token, preToken, abilityInfo, appInfo, want); +} + +/* + * Feature: AmsMgrScheduler + * Function: LoadAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler LoadAbility + * EnvConditions: NA + * CaseDescription: Verify LoadAbility + */ +HWTEST_F(AmsMgrSchedulerTest, LoadAbility_004, TestSize.Level0) +{ + auto mockAppMgrServiceInner = GetMockAppMgrServiceInner(); + auto amsEventHandler = GetAmsEventHandler(); + std::unique_ptr amsMgrScheduler = + std::make_unique(mockAppMgrServiceInner, amsEventHandler); + sptr token = nullptr; + sptr preToken = nullptr; + std::shared_ptr abilityInfo = std::make_shared(); + std::shared_ptr appInfo = std::make_shared(); + std::shared_ptr want = nullptr; + amsMgrScheduler->LoadAbility(token, preToken, abilityInfo, appInfo, want); +} + +/* + * Feature: AmsMgrScheduler + * Function: UpdateAbilityState + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler UpdateAbilityState + * EnvConditions: NA + * CaseDescription: Verify UpdateAbilityState + */ +HWTEST_F(AmsMgrSchedulerTest, UpdateAbilityState_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + AbilityState state = AbilityState::ABILITY_STATE_READY; + amsMgrScheduler->UpdateAbilityState(token, state); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->UpdateAbilityState(token, state); +} + +/* + * Feature: AmsMgrScheduler + * Function: UpdateExtensionState + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler UpdateExtensionState + * EnvConditions: NA + * CaseDescription: Verify UpdateExtensionState + */ +HWTEST_F(AmsMgrSchedulerTest, UpdateExtensionState_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + ExtensionState state = ExtensionState::EXTENSION_STATE_READY; + amsMgrScheduler->UpdateExtensionState(token, state); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->UpdateExtensionState(token, state); +} + +/* + * Feature: AmsMgrScheduler + * Function: TerminateAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler TerminateAbility + * EnvConditions: NA + * CaseDescription: Verify TerminateAbility + */ +HWTEST_F(AmsMgrSchedulerTest, TerminateAbility_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + bool clearMissionFlag = true; + amsMgrScheduler->TerminateAbility(token, clearMissionFlag); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->TerminateAbility(token, clearMissionFlag); +} + +/* + * Feature: AmsMgrScheduler + * Function: RegisterAppStateCallback + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler RegisterAppStateCallback + * EnvConditions: NA + * CaseDescription: Verify RegisterAppStateCallback + */ +HWTEST_F(AmsMgrSchedulerTest, RegisterAppStateCallback_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr callback = nullptr; + amsMgrScheduler->RegisterAppStateCallback(callback); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->RegisterAppStateCallback(callback); +} + +/* + * Feature: AmsMgrScheduler + * Function: AbilityBehaviorAnalysis + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler AbilityBehaviorAnalysis + * EnvConditions: NA + * CaseDescription: Verify AbilityBehaviorAnalysis + */ +HWTEST_F(AmsMgrSchedulerTest, AbilityBehaviorAnalysis_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + sptr preToken = nullptr; + int32_t visibility = 0; + int32_t perceptibility = 0; + int32_t connectionState = 0; + amsMgrScheduler->AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->AbilityBehaviorAnalysis(token, preToken, visibility, perceptibility, connectionState); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillProcessesByUserId + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillProcessesByUserId + * EnvConditions: NA + * CaseDescription: Verify KillProcessesByUserId + */ +HWTEST_F(AmsMgrSchedulerTest, KillProcessesByUserId_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + int32_t userId = 0; + amsMgrScheduler->KillProcessesByUserId(userId); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillProcessWithAccount + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillProcessWithAccount + * EnvConditions: NA + * CaseDescription: Verify KillProcessWithAccount + */ +HWTEST_F(AmsMgrSchedulerTest, KillProcessWithAccount_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + std::string bundleName = "bundleName"; + int accountId = 0; + int32_t res1 = amsMgrScheduler->KillProcessWithAccount(bundleName, accountId); + EXPECT_EQ(res1, ERR_INVALID_OPERATION); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + int32_t res2 = amsMgrScheduler->KillProcessWithAccount(bundleName, accountId); + EXPECT_NE(res2, ERR_INVALID_OPERATION); +} + +/* + * Feature: AmsMgrScheduler + * Function: AbilityAttachTimeOut + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler AbilityAttachTimeOut + * EnvConditions: NA + * CaseDescription: Verify AbilityAttachTimeOut + */ +HWTEST_F(AmsMgrSchedulerTest, AbilityAttachTimeOut_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + amsMgrScheduler->AbilityAttachTimeOut(token); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->AbilityAttachTimeOut(token); +} + +/* + * Feature: AmsMgrScheduler + * Function: PrepareTerminate + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler PrepareTerminate + * EnvConditions: NA + * CaseDescription: Verify PrepareTerminate + */ +HWTEST_F(AmsMgrSchedulerTest, PrepareTerminate_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + amsMgrScheduler->PrepareTerminate(token); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->PrepareTerminate(token); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillApplication + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillApplication + * EnvConditions: NA + * CaseDescription: Verify KillApplication + */ +HWTEST_F(AmsMgrSchedulerTest, KillApplication_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + std::string bundleName = "bundleName"; + amsMgrScheduler->KillApplication(bundleName); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->KillApplication(bundleName); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillApplicationByUid + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillApplicationByUid + * EnvConditions: NA + * CaseDescription: Verify KillApplicationByUid + */ +HWTEST_F(AmsMgrSchedulerTest, KillApplicationByUid_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + std::string bundleName = "bundleName"; + int uid = 0; + amsMgrScheduler->KillApplicationByUid(bundleName, uid); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->KillApplicationByUid(bundleName, uid); +} + +/* + * Feature: AmsMgrScheduler + * Function: KillApplicationSelf + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler KillApplicationSelf + * EnvConditions: NA + * CaseDescription: Verify KillApplicationSelf + */ +HWTEST_F(AmsMgrSchedulerTest, KillApplicationSelf_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + amsMgrScheduler->KillApplicationSelf(); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->KillApplicationSelf(); +} + +/* + * Feature: AmsMgrScheduler + * Function: GetRunningProcessInfoByToken + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler GetRunningProcessInfoByToken + * EnvConditions: NA + * CaseDescription: Verify GetRunningProcessInfoByToken + */ +HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByToken_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr token = nullptr; + RunningProcessInfo info; + amsMgrScheduler->GetRunningProcessInfoByToken(token, info); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->GetRunningProcessInfoByToken(token, info); +} + +/* + * Feature: AmsMgrScheduler + * Function: GetRunningProcessInfoByPid + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler GetRunningProcessInfoByPid + * EnvConditions: NA + * CaseDescription: Verify GetRunningProcessInfoByPid + */ +HWTEST_F(AmsMgrSchedulerTest, GetRunningProcessInfoByPid_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + pid_t pid = 0; + RunningProcessInfo info; + amsMgrScheduler->GetRunningProcessInfoByPid(pid, info); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->GetRunningProcessInfoByPid(pid, info); +} + +/* + * Feature: AmsMgrScheduler + * Function: StartSpecifiedAbility + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler StartSpecifiedAbility + * EnvConditions: NA + * CaseDescription: Verify StartSpecifiedAbility + */ +HWTEST_F(AmsMgrSchedulerTest, StartSpecifiedAbility_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + Want want; + AbilityInfo abilityInfo; + amsMgrScheduler->StartSpecifiedAbility(want, abilityInfo); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->StartSpecifiedAbility(want, abilityInfo); +} + +/* + * Feature: AmsMgrScheduler + * Function: RegisterStartSpecifiedAbilityResponse + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler RegisterStartSpecifiedAbilityResponse + * EnvConditions: NA + * CaseDescription: Verify RegisterStartSpecifiedAbilityResponse + */ +HWTEST_F(AmsMgrSchedulerTest, RegisterStartSpecifiedAbilityResponse_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + sptr response = nullptr; + amsMgrScheduler->RegisterStartSpecifiedAbilityResponse(response); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + amsMgrScheduler->RegisterStartSpecifiedAbilityResponse(response); +} + +/* + * Feature: AmsMgrScheduler + * Function: GetApplicationInfoByProcessID + * SubFunction: NA + * FunctionPoints: AmsMgrScheduler GetApplicationInfoByProcessID + * EnvConditions: NA + * CaseDescription: Verify GetApplicationInfoByProcessID + */ +HWTEST_F(AmsMgrSchedulerTest, GetApplicationInfoByProcessID_001, TestSize.Level0) +{ + auto amsMgrScheduler = std::make_unique(nullptr, nullptr); + int pid = 0; + ApplicationInfo application; + bool debug = true; + int res1 = amsMgrScheduler->GetApplicationInfoByProcessID(pid, application, debug); + EXPECT_EQ(res1, ERR_INVALID_OPERATION); + amsMgrScheduler->amsMgrServiceInner_ = GetMockAppMgrServiceInner(); + amsMgrScheduler->amsHandler_ = GetAmsEventHandler(); + int res2 = amsMgrScheduler->GetApplicationInfoByProcessID(pid, application, debug); + EXPECT_NE(res2, ERR_INVALID_OPERATION); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_mgr_service_test/BUILD.gn b/test/unittest/app_mgr_service_test/BUILD.gn index f9da12c218c47ccf4780aabab727369279102ffe..76845c65e4ff245bf64c555afc8ec9a497cffac9 100644 --- a/test/unittest/app_mgr_service_test/BUILD.gn +++ b/test/unittest/app_mgr_service_test/BUILD.gn @@ -14,9 +14,9 @@ import("//build/test.gni") import("//foundation/ability/ability_runtime/ability_runtime.gni") -module_output_path = "ability_runtime/appmgrservice" +module_output_path = "ability_runtime/appmgr" -ohos_unittest("AppMgrServiceTest") { +ohos_unittest("app_mgr_service_test") { module_out_path = module_output_path include_dirs = [ "${ability_runtime_test_path}/mock/common/include" ] @@ -53,5 +53,5 @@ ohos_unittest("AppMgrServiceTest") { group("unittest") { testonly = true - deps = [ ":AppMgrServiceTest" ] + deps = [ ":app_mgr_service_test" ] } diff --git a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp index fab5475106f0590b34916cb08f948d319e402fa2..ad1ede0c8a5280abf42c581f21976de399fdcaa7 100644 --- a/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp +++ b/test/unittest/app_mgr_service_test/app_mgr_service_test.cpp @@ -31,6 +31,7 @@ public: static void TearDownTestCase(); void SetUp() override; void TearDown() override; + std::shared_ptr runner_ {nullptr}; }; void AppMgrServiceTest::SetUpTestCase(void) @@ -40,11 +41,621 @@ void AppMgrServiceTest::TearDownTestCase(void) {} void AppMgrServiceTest::SetUp() -{} +{ + runner_ = EventRunner::Create(Constants::APP_MGR_SERVICE_NAME); +} void AppMgrServiceTest::TearDown() {} +/* + * Feature: AppMgrService + * Function: OnStop + * SubFunction: NA + * FunctionPoints: AppMgrService OnStop + * EnvConditions: NA + * CaseDescription: Verify OnStop + */ +HWTEST_F(AppMgrServiceTest, OnStop_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->appMgrServiceInner_ = nullptr; + appMgrService->OnStop(); +} + +/* + * Feature: AppMgrService + * Function: QueryServiceState + * SubFunction: NA + * FunctionPoints: AppMgrService QueryServiceState + * EnvConditions: NA + * CaseDescription: Verify QueryServiceState + */ +HWTEST_F(AppMgrServiceTest, QueryServiceState_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->appMgrServiceInner_ = nullptr; + appMgrService->appMgrServiceState_.serviceRunningState = ServiceRunningState::STATE_RUNNING; + auto res = appMgrService->QueryServiceState(); + EXPECT_EQ(res.serviceRunningState, ServiceRunningState::STATE_RUNNING); +} + +/* + * Feature: AppMgrService + * Function: Init + * SubFunction: NA + * FunctionPoints: AppMgrService Init + * EnvConditions: NA + * CaseDescription: Verify Init + */ +HWTEST_F(AppMgrServiceTest, Init_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->appMgrServiceInner_ = nullptr; + ErrCode res = appMgrService->Init(); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: AttachApplication + * SubFunction: NA + * FunctionPoints: AppMgrService AttachApplication + * EnvConditions: NA + * CaseDescription: Verify AttachApplication + */ +HWTEST_F(AppMgrServiceTest, AttachApplication_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr app = nullptr; + appMgrService->SetInnerService(nullptr); + appMgrService->AttachApplication(app); +} + +/* + * Feature: AppMgrService + * Function: AttachApplication + * SubFunction: NA + * FunctionPoints: AppMgrService AttachApplication + * EnvConditions: NA + * CaseDescription: Verify AttachApplication + */ +HWTEST_F(AppMgrServiceTest, AttachApplication_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr app = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->AttachApplication(app); +} + +/* + * Feature: AppMgrService + * Function: ApplicationForegrounded + * SubFunction: NA + * FunctionPoints: AppMgrService ApplicationForegrounded + * EnvConditions: NA + * CaseDescription: Verify ApplicationForegrounded + */ +HWTEST_F(AppMgrServiceTest, ApplicationForegrounded_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + appMgrService->SetInnerService(nullptr); + appMgrService->ApplicationForegrounded(recordId); +} + +/* + * Feature: AppMgrService + * Function: ApplicationBackgrounded + * SubFunction: NA + * FunctionPoints: AppMgrService ApplicationBackgrounded + * EnvConditions: NA + * CaseDescription: Verify ApplicationBackgrounded + */ +HWTEST_F(AppMgrServiceTest, ApplicationBackgrounded_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + appMgrService->SetInnerService(nullptr); + appMgrService->ApplicationBackgrounded(recordId); +} + +/* + * Feature: AppMgrService + * Function: ApplicationTerminated + * SubFunction: NA + * FunctionPoints: AppMgrService ApplicationTerminated + * EnvConditions: NA + * CaseDescription: Verify ApplicationTerminated + */ +HWTEST_F(AppMgrServiceTest, ApplicationTerminated_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + appMgrService->SetInnerService(nullptr); + appMgrService->ApplicationTerminated(recordId); +} + +/* + * Feature: AppMgrService + * Function: AbilityCleaned + * SubFunction: NA + * FunctionPoints: AppMgrService AbilityCleaned + * EnvConditions: NA + * CaseDescription: Verify AbilityCleaned + */ +HWTEST_F(AppMgrServiceTest, AbilityCleaned_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(nullptr); + appMgrService->AbilityCleaned(nullptr); +} + +/* + * Feature: AppMgrService + * Function: AbilityCleaned + * SubFunction: NA + * FunctionPoints: AppMgrService AbilityCleaned + * EnvConditions: NA + * CaseDescription: Verify AbilityCleaned + */ +HWTEST_F(AppMgrServiceTest, AbilityCleaned_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->AbilityCleaned(nullptr); +} + +/* + * Feature: AppMgrService + * Function: AddAppDeathRecipient + * SubFunction: NA + * FunctionPoints: AppMgrService AddAppDeathRecipient + * EnvConditions: NA + * CaseDescription: Verify AddAppDeathRecipient + */ +HWTEST_F(AppMgrServiceTest, AddAppDeathRecipient_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + pid_t pid = 1; + appMgrService->SetInnerService(nullptr); + appMgrService->AddAppDeathRecipient(pid); +} + +/* + * Feature: AppMgrService + * Function: AddAppDeathRecipient + * SubFunction: NA + * FunctionPoints: AppMgrService AddAppDeathRecipient + * EnvConditions: NA + * CaseDescription: Verify AddAppDeathRecipient + */ +HWTEST_F(AppMgrServiceTest, AddAppDeathRecipient_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + pid_t pid = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->AddAppDeathRecipient(pid); +} + +/* + * Feature: AppMgrService + * Function: StartupResidentProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartupResidentProcess + * EnvConditions: NA + * CaseDescription: Verify StartupResidentProcess + */ +HWTEST_F(AppMgrServiceTest, StartupResidentProcess_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector bundleInfos; + appMgrService->SetInnerService(nullptr); + appMgrService->StartupResidentProcess(bundleInfos); +} + +/* + * Feature: AppMgrService + * Function: StartupResidentProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartupResidentProcess + * EnvConditions: NA + * CaseDescription: Verify StartupResidentProcess + */ +HWTEST_F(AppMgrServiceTest, StartupResidentProcess_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector bundleInfos; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->StartupResidentProcess(bundleInfos); +} + +/* + * Feature: AppMgrService + * Function: ClearUpApplicationData + * SubFunction: NA + * FunctionPoints: AppMgrService ClearUpApplicationData + * EnvConditions: NA + * CaseDescription: Verify ClearUpApplicationData + */ +HWTEST_F(AppMgrServiceTest, ClearUpApplicationData_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->ClearUpApplicationData(bundleName); + EXPECT_EQ(res, ERR_PERMISSION_DENIED); +} + +/* + * Feature: AppMgrService + * Function: GetAllRunningProcesses + * SubFunction: NA + * FunctionPoints: AppMgrService GetAllRunningProcesses + * EnvConditions: NA + * CaseDescription: Verify GetAllRunningProcesses + */ +HWTEST_F(AppMgrServiceTest, GetAllRunningProcesses_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector info; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetAllRunningProcesses(info); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetAllRunningProcesses + * SubFunction: NA + * FunctionPoints: AppMgrService GetAllRunningProcesses + * EnvConditions: NA + * CaseDescription: Verify GetAllRunningProcesses + */ +HWTEST_F(AppMgrServiceTest, GetAllRunningProcesses_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector info; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetAllRunningProcesses(info); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetProcessRunningInfosByUserId + * SubFunction: NA + * FunctionPoints: AppMgrService GetProcessRunningInfosByUserId + * EnvConditions: NA + * CaseDescription: Verify GetProcessRunningInfosByUserId + */ +HWTEST_F(AppMgrServiceTest, GetProcessRunningInfosByUserId_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector info; + int32_t userId = 1; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetProcessRunningInfosByUserId(info, userId); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyMemoryLevel + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyMemoryLevel + * EnvConditions: NA + * CaseDescription: Verify NotifyMemoryLevel + */ +HWTEST_F(AppMgrServiceTest, NotifyMemoryLevel_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t level = 1; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyMemoryLevel(level); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyMemoryLevel + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyMemoryLevel + * EnvConditions: NA + * CaseDescription: Verify NotifyMemoryLevel + */ +HWTEST_F(AppMgrServiceTest, NotifyMemoryLevel_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t level = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->NotifyMemoryLevel(level); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: AddAbilityStageDone + * SubFunction: NA + * FunctionPoints: AppMgrService AddAbilityStageDone + * EnvConditions: NA + * CaseDescription: Verify AddAbilityStageDone + */ +HWTEST_F(AppMgrServiceTest, AddAbilityStageDone_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + appMgrService->SetInnerService(nullptr); + appMgrService->AddAbilityStageDone(recordId); +} + +/* + * Feature: AppMgrService + * Function: AddAbilityStageDone + * SubFunction: NA + * FunctionPoints: AppMgrService AddAbilityStageDone + * EnvConditions: NA + * CaseDescription: Verify AddAbilityStageDone + */ +HWTEST_F(AppMgrServiceTest, AddAbilityStageDone_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->AddAbilityStageDone(recordId); +} + +/* + * Feature: AppMgrService + * Function: RegisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppMgrService RegisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterApplicationStateObserver + */ +HWTEST_F(AppMgrServiceTest, RegisterApplicationStateObserver_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + std::vector bundleNameList; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->RegisterApplicationStateObserver(observer, bundleNameList); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: RegisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppMgrService RegisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterApplicationStateObserver + */ +HWTEST_F(AppMgrServiceTest, RegisterApplicationStateObserver_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + std::vector bundleNameList; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->RegisterApplicationStateObserver(observer, bundleNameList); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: UnregisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppMgrService UnregisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify UnregisterApplicationStateObserver + */ +HWTEST_F(AppMgrServiceTest, UnregisterApplicationStateObserver_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->UnregisterApplicationStateObserver(observer); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetForegroundApplications + * SubFunction: NA + * FunctionPoints: AppMgrService GetForegroundApplications + * EnvConditions: NA + * CaseDescription: Verify GetForegroundApplications + */ +HWTEST_F(AppMgrServiceTest, GetForegroundApplications_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector list; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetForegroundApplications(list); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetForegroundApplications + * SubFunction: NA + * FunctionPoints: AppMgrService GetForegroundApplications + * EnvConditions: NA + * CaseDescription: Verify GetForegroundApplications + */ +HWTEST_F(AppMgrServiceTest, GetForegroundApplications_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::vector list; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetForegroundApplications(list); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: StartUserTestProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartUserTestProcess + * EnvConditions: NA + * CaseDescription: Verify StartUserTestProcess + */ +HWTEST_F(AppMgrServiceTest, StartUserTestProcess_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Want want; + sptr observer = nullptr; + BundleInfo bundleInfo; + int32_t userId = 1; + appMgrService->SetInnerService(nullptr); + int res = appMgrService->StartUserTestProcess(want, observer, bundleInfo, userId); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: StartUserTestProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartUserTestProcess + * EnvConditions: NA + * CaseDescription: Verify StartUserTestProcess + */ +HWTEST_F(AppMgrServiceTest, StartUserTestProcess_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Want want; + sptr observer = nullptr; + BundleInfo bundleInfo; + int32_t userId = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int res = appMgrService->StartUserTestProcess(want, observer, bundleInfo, userId); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: FinishUserTest + * SubFunction: NA + * FunctionPoints: AppMgrService FinishUserTest + * EnvConditions: NA + * CaseDescription: Verify FinishUserTest + */ +HWTEST_F(AppMgrServiceTest, FinishUserTest_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string msg = "msg"; + int64_t resultCode = 1; + std::string bundleName = "bundleName"; + appMgrService->SetInnerService(nullptr); + int res = appMgrService->FinishUserTest(msg, resultCode, bundleName); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: FinishUserTest + * SubFunction: NA + * FunctionPoints: AppMgrService FinishUserTest + * EnvConditions: NA + * CaseDescription: Verify FinishUserTest + */ +HWTEST_F(AppMgrServiceTest, FinishUserTest_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string msg = "msg"; + int64_t resultCode = 1; + std::string bundleName = "bundleName"; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int res = appMgrService->FinishUserTest(msg, resultCode, bundleName); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: ScheduleAcceptWantDone + * SubFunction: NA + * FunctionPoints: AppMgrService ScheduleAcceptWantDone + * EnvConditions: NA + * CaseDescription: Verify ScheduleAcceptWantDone + */ +HWTEST_F(AppMgrServiceTest, ScheduleAcceptWantDone_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + Want want; + std::string flag = "flag"; + appMgrService->SetInnerService(nullptr); + appMgrService->ScheduleAcceptWantDone(recordId, want, flag); +} + +/* + * Feature: AppMgrService + * Function: ScheduleAcceptWantDone + * SubFunction: NA + * FunctionPoints: AppMgrService ScheduleAcceptWantDone + * EnvConditions: NA + * CaseDescription: Verify ScheduleAcceptWantDone + */ +HWTEST_F(AppMgrServiceTest, ScheduleAcceptWantDone_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t recordId = 1; + Want want; + std::string flag = "flag"; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->ScheduleAcceptWantDone(recordId, want, flag); +} + +/* + * Feature: AppMgrService + * Function: GetAbilityRecordsByProcessID + * SubFunction: NA + * FunctionPoints: AppMgrService GetAbilityRecordsByProcessID + * EnvConditions: NA + * CaseDescription: Verify GetAbilityRecordsByProcessID + */ +HWTEST_F(AppMgrServiceTest, GetAbilityRecordsByProcessID_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int pid = 1; + std::vector> tokens; + appMgrService->SetInnerService(nullptr); + int res = appMgrService->GetAbilityRecordsByProcessID(pid, tokens); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetAbilityRecordsByProcessID + * SubFunction: NA + * FunctionPoints: AppMgrService GetAbilityRecordsByProcessID + * EnvConditions: NA + * CaseDescription: Verify GetAbilityRecordsByProcessID + */ +HWTEST_F(AppMgrServiceTest, GetAbilityRecordsByProcessID_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int pid = 1; + std::vector> tokens; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int res = appMgrService->GetAbilityRecordsByProcessID(pid, tokens); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + /** * @tc.name: PreStartNWebSpawnProcess_001 * @tc.desc: prestart nwebspawn process. @@ -53,10 +664,11 @@ void AppMgrServiceTest::TearDown() */ HWTEST_F(AppMgrServiceTest, PreStartNWebSpawnProcess_001, TestSize.Level0) { - auto ams = std::make_shared(); - ams->SetInnerService(std::make_shared()); - int ret = ams->PreStartNWebSpawnProcess(); - EXPECT_EQ(ret, ERR_INVALID_OPERATION); + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int ret = appMgrService->PreStartNWebSpawnProcess(); + EXPECT_NE(ret, ERR_INVALID_OPERATION); } /** @@ -67,10 +679,481 @@ HWTEST_F(AppMgrServiceTest, PreStartNWebSpawnProcess_001, TestSize.Level0) */ HWTEST_F(AppMgrServiceTest, PreStartNWebSpawnProcess_002, TestSize.Level0) { - auto ams = std::make_shared(); - ams->SetInnerService(nullptr); - int ret = ams->PreStartNWebSpawnProcess(); + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(nullptr); + int ret = appMgrService->PreStartNWebSpawnProcess(); EXPECT_EQ(ret, ERR_INVALID_OPERATION); } + +/* + * Feature: AppMgrService + * Function: StartRenderProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartRenderProcess + * EnvConditions: NA + * CaseDescription: Verify StartRenderProcess + */ +HWTEST_F(AppMgrServiceTest, StartRenderProcess_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string renderParam = "renderParam"; + int32_t ipcFd = 1; + int32_t sharedFd = 1; + pid_t renderPid = 1; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: StartRenderProcess + * SubFunction: NA + * FunctionPoints: AppMgrService StartRenderProcess + * EnvConditions: NA + * CaseDescription: Verify StartRenderProcess + */ +HWTEST_F(AppMgrServiceTest, StartRenderProcess_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string renderParam = "renderParam"; + int32_t ipcFd = 1; + int32_t sharedFd = 1; + pid_t renderPid = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->StartRenderProcess(renderParam, ipcFd, sharedFd, renderPid); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: AttachRenderProcess + * SubFunction: NA + * FunctionPoints: AppMgrService AttachRenderProcess + * EnvConditions: NA + * CaseDescription: Verify AttachRenderProcess + */ +HWTEST_F(AppMgrServiceTest, AttachRenderProcess_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr scheduler = nullptr; + appMgrService->SetInnerService(nullptr); + appMgrService->AttachRenderProcess(scheduler); +} + +/* + * Feature: AppMgrService + * Function: AttachRenderProcess + * SubFunction: NA + * FunctionPoints: AppMgrService AttachRenderProcess + * EnvConditions: NA + * CaseDescription: Verify AttachRenderProcess + */ +HWTEST_F(AppMgrServiceTest, AttachRenderProcess_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr scheduler = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + appMgrService->AttachRenderProcess(scheduler); +} + +/* + * Feature: AppMgrService + * Function: GetRenderProcessTerminationStatus + * SubFunction: NA + * FunctionPoints: AppMgrService GetRenderProcessTerminationStatus + * EnvConditions: NA + * CaseDescription: Verify GetRenderProcessTerminationStatus + */ +HWTEST_F(AppMgrServiceTest, GetRenderProcessTerminationStatus_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + pid_t renderPid = 1; + int status = 1; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetRenderProcessTerminationStatus(renderPid, status); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetRenderProcessTerminationStatus + * SubFunction: NA + * FunctionPoints: AppMgrService GetRenderProcessTerminationStatus + * EnvConditions: NA + * CaseDescription: Verify GetRenderProcessTerminationStatus + */ +HWTEST_F(AppMgrServiceTest, GetRenderProcessTerminationStatus_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + pid_t renderPid = 1; + int status = 1; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetRenderProcessTerminationStatus(renderPid, status); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService GetConfiguration + * EnvConditions: NA + * CaseDescription: Verify GetConfiguration + */ +HWTEST_F(AppMgrServiceTest, GetConfiguration_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Configuration config; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->GetConfiguration(config); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: GetConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService GetConfiguration + * EnvConditions: NA + * CaseDescription: Verify GetConfiguration + */ +HWTEST_F(AppMgrServiceTest, GetConfiguration_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Configuration config; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->GetConfiguration(config); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: UpdateConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService UpdateConfiguration + * EnvConditions: NA + * CaseDescription: Verify UpdateConfiguration + */ +HWTEST_F(AppMgrServiceTest, UpdateConfiguration_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Configuration config; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->UpdateConfiguration(config); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: UpdateConfiguration + * SubFunction: NA + * FunctionPoints: AppMgrService UpdateConfiguration + * EnvConditions: NA + * CaseDescription: Verify UpdateConfiguration + */ +HWTEST_F(AppMgrServiceTest, UpdateConfiguration_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + Configuration config; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->UpdateConfiguration(config); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: RegisterConfigurationObserver + * SubFunction: NA + * FunctionPoints: AppMgrService RegisterConfigurationObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterConfigurationObserver + */ +HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->RegisterConfigurationObserver(observer); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: RegisterConfigurationObserver + * SubFunction: NA + * FunctionPoints: AppMgrService RegisterConfigurationObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterConfigurationObserver + */ +HWTEST_F(AppMgrServiceTest, RegisterConfigurationObserver_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->RegisterConfigurationObserver(observer); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: UnregisterConfigurationObserver + * SubFunction: NA + * FunctionPoints: AppMgrService UnregisterConfigurationObserver + * EnvConditions: NA + * CaseDescription: Verify UnregisterConfigurationObserver + */ +HWTEST_F(AppMgrServiceTest, UnregisterConfigurationObserver_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->UnregisterConfigurationObserver(observer); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: UnregisterConfigurationObserver + * SubFunction: NA + * FunctionPoints: AppMgrService UnregisterConfigurationObserver + * EnvConditions: NA + * CaseDescription: Verify UnregisterConfigurationObserver + */ +HWTEST_F(AppMgrServiceTest, UnregisterConfigurationObserver_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + sptr observer = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->UnregisterConfigurationObserver(observer); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +#ifdef ABILITY_COMMAND_FOR_TEST +/* + * Feature: AppMgrService + * Function: BlockAppService + * SubFunction: NA + * FunctionPoints: AppMgrService BlockAppService + * EnvConditions: NA + * CaseDescription: Verify BlockAppService + */ +HWTEST_F(AppMgrServiceTest, BlockAppService_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(nullptr); + int res = appMgrService->BlockAppService(); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: BlockAppService + * SubFunction: NA + * FunctionPoints: AppMgrService BlockAppService + * EnvConditions: NA + * CaseDescription: Verify BlockAppService + */ +HWTEST_F(AppMgrServiceTest, BlockAppService_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int res = appMgrService->BlockAppService(); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} +#endif + +/* + * Feature: AppMgrService + * Function: GetAppRunningStateByBundleName + * SubFunction: NA + * FunctionPoints: AppMgrService GetAppRunningStateByBundleName + * EnvConditions: NA + * CaseDescription: Verify GetAppRunningStateByBundleName + */ +HWTEST_F(AppMgrServiceTest, GetAppRunningStateByBundleName_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + appMgrService->SetInnerService(nullptr); + bool res = appMgrService->GetAppRunningStateByBundleName(bundleName); + EXPECT_FALSE(res); +} + +/* + * Feature: AppMgrService + * Function: GetAppRunningStateByBundleName + * SubFunction: NA + * FunctionPoints: AppMgrService GetAppRunningStateByBundleName + * EnvConditions: NA + * CaseDescription: Verify GetAppRunningStateByBundleName + */ +HWTEST_F(AppMgrServiceTest, GetAppRunningStateByBundleName_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + bool res = appMgrService->GetAppRunningStateByBundleName(bundleName); + EXPECT_FALSE(res); +} + +/* + * Feature: AppMgrService + * Function: NotifyLoadRepairPatch + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyLoadRepairPatch + * EnvConditions: NA + * CaseDescription: Verify NotifyLoadRepairPatch + */ +HWTEST_F(AppMgrServiceTest, NotifyLoadRepairPatch_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyLoadRepairPatch(bundleName, callback); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyLoadRepairPatch + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyLoadRepairPatch + * EnvConditions: NA + * CaseDescription: Verify NotifyLoadRepairPatch + */ +HWTEST_F(AppMgrServiceTest, NotifyLoadRepairPatch_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->NotifyLoadRepairPatch(bundleName, callback); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyHotReloadPage + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyHotReloadPage + * EnvConditions: NA + * CaseDescription: Verify NotifyHotReloadPage + */ +HWTEST_F(AppMgrServiceTest, NotifyHotReloadPage_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyHotReloadPage(bundleName, callback); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyHotReloadPage + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyHotReloadPage + * EnvConditions: NA + * CaseDescription: Verify NotifyHotReloadPage + */ +HWTEST_F(AppMgrServiceTest, NotifyHotReloadPage_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->NotifyHotReloadPage(bundleName, callback); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} + +#ifdef BGTASKMGR_CONTINUOUS_TASK_ENABLE +/* + * Feature: AppMgrService + * Function: SetContinuousTaskProcess + * SubFunction: NA + * FunctionPoints: AppMgrService SetContinuousTaskProcess + * EnvConditions: NA + * CaseDescription: Verify SetContinuousTaskProcess + */ +HWTEST_F(AppMgrServiceTest, SetContinuousTaskProcess_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t pid = 1; + bool isContinuousTask = false; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->SetContinuousTaskProcess(pid, isContinuousTask); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: SetContinuousTaskProcess + * SubFunction: NA + * FunctionPoints: AppMgrService SetContinuousTaskProcess + * EnvConditions: NA + * CaseDescription: Verify SetContinuousTaskProcess + */ +HWTEST_F(AppMgrServiceTest, SetContinuousTaskProcess_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + int32_t pid = 1; + bool isContinuousTask = false; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->SetContinuousTaskProcess(pid, isContinuousTask); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} +#endif + +/* + * Feature: AppMgrService + * Function: NotifyUnLoadRepairPatch + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyUnLoadRepairPatch + * EnvConditions: NA + * CaseDescription: Verify NotifyUnLoadRepairPatch + */ +HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_001, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(nullptr); + int32_t res = appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); + EXPECT_EQ(res, ERR_INVALID_OPERATION); +} + +/* + * Feature: AppMgrService + * Function: NotifyUnLoadRepairPatch + * SubFunction: NA + * FunctionPoints: AppMgrService NotifyUnLoadRepairPatch + * EnvConditions: NA + * CaseDescription: Verify NotifyUnLoadRepairPatch + */ +HWTEST_F(AppMgrServiceTest, NotifyUnLoadRepairPatch_002, TestSize.Level0) +{ + auto appMgrService = std::make_shared(); + std::string bundleName = "bundleName"; + sptr callback = nullptr; + appMgrService->SetInnerService(std::make_shared()); + appMgrService->handler_ = std::make_shared(runner_, appMgrService->appMgrServiceInner_); + int32_t res = appMgrService->NotifyUnLoadRepairPatch(bundleName, callback); + EXPECT_NE(res, ERR_INVALID_OPERATION); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/app_spawn_socket_test/BUILD.gn b/test/unittest/app_spawn_socket_test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..171d7d953965c6842e6f8c0a98f75e380363a3f9 --- /dev/null +++ b/test/unittest/app_spawn_socket_test/BUILD.gn @@ -0,0 +1,69 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgr" + +ohos_unittest("app_spawn_socket_test") { + module_out_path = module_output_path + cflags_cc = [] + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + ] + + sources = + [ "${ability_runtime_services_path}/appmgr/src/ams_mgr_scheduler.cpp" ] + + sources += [ "app_spawn_socket_test.cpp" ] + + configs = [ "${ability_runtime_test_path}/unittest:appmgr_test_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_test_path}/unittest:appmgr_test_source", + ] + + external_deps = [ + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } + + if (ability_runtime_graphics) { + defines += [ "SUPPORT_GRAPHICS" ] + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":app_spawn_socket_test" ] +} diff --git a/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp b/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..378b2ba63deedb5f46ac6d7b33dd347ddddd54d1 --- /dev/null +++ b/test/unittest/app_spawn_socket_test/app_spawn_socket_test.cpp @@ -0,0 +1,192 @@ +/* + * 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 + +#define private public +#include "app_spawn_socket.h" +#undef private + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppSpawn; + +namespace OHOS { +namespace AppExecFwk { +class AppSpawnSocketTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void AppSpawnSocketTest::SetUpTestCase() +{} + +void AppSpawnSocketTest::TearDownTestCase() +{} + +void AppSpawnSocketTest::SetUp() +{} + +void AppSpawnSocketTest::TearDown() +{} + +/* + * Feature: AppSpawnSocket + * Function: OpenAppSpawnConnection + * SubFunction: NA + * FunctionPoints: AppSpawnSocket OpenAppSpawnConnection + * EnvConditions: NA + * CaseDescription: Verify OpenAppSpawnConnection + */ +HWTEST_F(AppSpawnSocketTest, OpenAppSpawnConnection_001, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + ErrCode res1 = appSpawnSocket->OpenAppSpawnConnection(); + EXPECT_EQ(res1, ERR_OK); + appSpawnSocket->clientSocket_ = nullptr; + ErrCode res2 = appSpawnSocket->OpenAppSpawnConnection(); + EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET); +} + +/* + * Feature: AppSpawnSocket + * Function: CloseAppSpawnConnection + * SubFunction: NA + * FunctionPoints: AppSpawnSocket CloseAppSpawnConnection + * EnvConditions: NA + * CaseDescription: Verify CloseAppSpawnConnection + */ +HWTEST_F(AppSpawnSocketTest, CloseAppSpawnConnection_001, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + appSpawnSocket->CloseAppSpawnConnection(); + appSpawnSocket->clientSocket_ = nullptr; + appSpawnSocket->CloseAppSpawnConnection(); +} + +/* + * Feature: AppSpawnSocket + * Function: WriteMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket WriteMessage + * EnvConditions: NA + * CaseDescription: Verify WriteMessage + */ +HWTEST_F(AppSpawnSocketTest, WriteMessage_001, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + const void *buf = nullptr; + int32_t len = 0; + ErrCode res = appSpawnSocket->WriteMessage(buf, len); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AppSpawnSocket + * Function: WriteMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket WriteMessage + * EnvConditions: NA + * CaseDescription: Verify WriteMessage + */ +HWTEST_F(AppSpawnSocketTest, WriteMessage_002, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + const void *buf = nullptr; + int32_t len = 1; + ErrCode res = appSpawnSocket->WriteMessage(buf, len); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AppSpawnSocket + * Function: WriteMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket WriteMessage + * EnvConditions: NA + * CaseDescription: Verify WriteMessage + */ +HWTEST_F(AppSpawnSocketTest, WriteMessage_003, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + char data = 'a'; + const void *buf = &data; + int32_t len = 1; + ErrCode res1 = appSpawnSocket->WriteMessage(buf, len); + EXPECT_EQ(res1, ERR_APPEXECFWK_SOCKET_WRITE_FAILED); + appSpawnSocket->clientSocket_ = nullptr; + ErrCode res2 = appSpawnSocket->WriteMessage(buf, len); + EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_SOCKET); +} + +/* + * Feature: AppSpawnSocket + * Function: ReadMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket ReadMessage + * EnvConditions: NA + * CaseDescription: Verify ReadMessage + */ +HWTEST_F(AppSpawnSocketTest, ReadMessage_001, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + void *buf = nullptr; + int32_t len = 0; + ErrCode res = appSpawnSocket->ReadMessage(buf, len); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AppSpawnSocket + * Function: ReadMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket ReadMessage + * EnvConditions: NA + * CaseDescription: Verify ReadMessage + */ +HWTEST_F(AppSpawnSocketTest, ReadMessage_002, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + void *buf = nullptr; + int32_t len = 1; + ErrCode res = appSpawnSocket->ReadMessage(buf, len); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AppSpawnSocket + * Function: ReadMessage + * SubFunction: NA + * FunctionPoints: AppSpawnSocket ReadMessage + * EnvConditions: NA + * CaseDescription: Verify ReadMessage + */ +HWTEST_F(AppSpawnSocketTest, ReadMessage_003, TestSize.Level0) +{ + auto appSpawnSocket = std::make_shared(true); + char data = 'a'; + void *buf = &data; + int32_t len = 1; + ErrCode res1 = appSpawnSocket->ReadMessage(buf, len); + EXPECT_EQ(res1, ERR_APPEXECFWK_SOCKET_READ_FAILED); + appSpawnSocket->clientSocket_ = nullptr; + ErrCode res2 = appSpawnSocket->ReadMessage(buf, len); + EXPECT_EQ(res2, ERR_APPEXECFWK_BAD_APPSPAWN_CLIENT); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/app_state_observer_manager_test/BUILD.gn b/test/unittest/app_state_observer_manager_test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..aaf7ee8d6399ce3bc9654911c1038e00162fe57c --- /dev/null +++ b/test/unittest/app_state_observer_manager_test/BUILD.gn @@ -0,0 +1,71 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") + +module_output_path = "ability_runtime/appmgr" + +ohos_unittest("app_state_observer_manager_test") { + module_out_path = module_output_path + cflags_cc = [] + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + ] + + sources = + [ "${ability_runtime_services_path}/appmgr/src/ams_mgr_scheduler.cpp" ] + + sources += [ "app_state_observer_manager_test.cpp" ] + + configs = [ "${ability_runtime_test_path}/unittest:appmgr_test_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:perm_verification", + "${ability_runtime_test_path}/unittest:appmgr_test_source", + ] + + external_deps = [ + "bundle_framework:appexecfwk_core", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + defines = [ "AMS_LOG_TAG = \"AppMgrService\"" ] + + if (ability_command_for_test) { + defines += [ "ABILITY_COMMAND_FOR_TEST" ] + } + + if (ability_runtime_graphics) { + defines += [ "SUPPORT_GRAPHICS" ] + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +group("unittest") { + testonly = true + deps = [ ":app_state_observer_manager_test" ] +} diff --git a/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp b/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..bbce247a8de0d56f8263c263228249e419b6fc43 --- /dev/null +++ b/test/unittest/app_state_observer_manager_test/app_state_observer_manager_test.cpp @@ -0,0 +1,927 @@ +/* + * 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 + +#define private public +#include "app_state_observer_manager.h" +#undef private +#include "application_state_observer_stub.h" + +using namespace testing; +using namespace testing::ext; + +namespace OHOS { +namespace AppExecFwk { +namespace { +const int BUNDLE_NAME_LIST_MAX_SIZE = 128; +} +class MockApplicationStateObserver : public IApplicationStateObserver { +public: + MockApplicationStateObserver() = default; + virtual ~MockApplicationStateObserver() = default; + void OnForegroundApplicationChanged(const AppStateData &appStateData) override + {} + void OnAbilityStateChanged(const AbilityStateData &abilityStateData) override + {} + void OnExtensionStateChanged(const AbilityStateData &abilityStateData) override + {} + void OnProcessCreated(const ProcessData &processData) override + {} + void OnProcessStateChanged(const ProcessData &processData) override + {} + void OnProcessDied(const ProcessData &processData) override + {} + void OnApplicationStateChanged(const AppStateData &appStateData) override + {} + void OnAppStateChanged(const AppStateData &appStateData) override + {} + sptr AsObject() override + { + return {}; + } +}; +class AppSpawnSocketTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + std::shared_ptr MockAppRecord(); + sptr observer_ {nullptr}; +}; + +void AppSpawnSocketTest::SetUpTestCase() +{} + +void AppSpawnSocketTest::TearDownTestCase() +{} + +void AppSpawnSocketTest::SetUp() +{ + sptr observer_ = new MockApplicationStateObserver(); +} + +void AppSpawnSocketTest::TearDown() +{} + +std::shared_ptr AppSpawnSocketTest::MockAppRecord() +{ + ApplicationInfo appInfo; + appInfo.accessTokenId = 1; + std::shared_ptr info = std::make_shared(appInfo); + info->accessTokenId = 1; + std::shared_ptr appRecord = std::make_shared(info, 0, "process"); + std::shared_ptr priorityObject = std::make_shared(); + priorityObject->SetPid(1); + appRecord->priorityObject_ = priorityObject; + appRecord->SetUid(1); + appRecord->SetState(ApplicationState::APP_STATE_CREATE); + appRecord->SetContinuousTaskAppState(false); + appRecord->SetKeepAliveAppState(false, false); + appRecord->SetRequestProcCode(1); + appRecord->isFocused_ = false; + return appRecord; +} + +/* + * Feature: AppStateObserverManager + * Function: RegisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterApplicationStateObserver + */ +HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + vector bundleNameList; + int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList); + EXPECT_EQ(res, ERR_PERMISSION_DENIED); +} + +/* + * Feature: AppStateObserverManager + * Function: RegisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager RegisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify RegisterApplicationStateObserver + */ +HWTEST_F(AppSpawnSocketTest, RegisterApplicationStateObserver_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + vector bundleNameList; + while (bundleNameList.size() <= BUNDLE_NAME_LIST_MAX_SIZE) { + bundleNameList.push_back("a"); + } + int32_t res = manager->RegisterApplicationStateObserver(nullptr, bundleNameList); + EXPECT_EQ(res, ERR_INVALID_VALUE); +} + +/* + * Feature: AppStateObserverManager + * Function: UnregisterApplicationStateObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager UnregisterApplicationStateObserver + * EnvConditions: NA + * CaseDescription: Verify UnregisterApplicationStateObserver + */ +HWTEST_F(AppSpawnSocketTest, UnregisterApplicationStateObserver_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + int32_t res = manager->UnregisterApplicationStateObserver(nullptr); + EXPECT_EQ(res, ERR_PERMISSION_DENIED); +} + +/* + * Feature: AppStateObserverManager + * Function: OnAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify OnAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord; + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = false; + manager->OnAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: OnAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify OnAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, OnAppStateChanged_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord; + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = false; + manager->Init(); + manager->OnAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: OnProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnProcessDied + * EnvConditions: NA + * CaseDescription: Verify OnProcessDied + */ +HWTEST_F(AppSpawnSocketTest, OnProcessDied_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord; + manager->OnProcessDied(appRecord); + manager->Init(); + manager->OnProcessDied(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: OnRenderProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnRenderProcessDied + * EnvConditions: NA + * CaseDescription: Verify OnRenderProcessDied + */ +HWTEST_F(AppSpawnSocketTest, OnRenderProcessDied_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr renderRecord; + manager->OnRenderProcessDied(renderRecord); + manager->Init(); + manager->OnRenderProcessDied(renderRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: OnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify OnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, OnProcessStateChanged_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord; + manager->OnProcessStateChanged(appRecord); + manager->Init(); + manager->OnProcessStateChanged(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: OnProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnProcessCreated + * EnvConditions: NA + * CaseDescription: Verify OnProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, OnProcessCreated_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord; + manager->OnProcessCreated(appRecord); + manager->Init(); + manager->OnProcessCreated(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: OnRenderProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager OnRenderProcessCreated + * EnvConditions: NA + * CaseDescription: Verify OnRenderProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, OnRenderProcessCreated_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr renderRecord; + manager->OnRenderProcessCreated(renderRecord); + manager->Init(); + manager->OnRenderProcessCreated(renderRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: StateChangedNotifyObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager StateChangedNotifyObserver + * EnvConditions: NA + * CaseDescription: Verify StateChangedNotifyObserver + */ +HWTEST_F(AppSpawnSocketTest, StateChangedNotifyObserver_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + AbilityStateData abilityStateData; + bool isAbility = false; + manager->StateChangedNotifyObserver(abilityStateData, isAbility); + manager->Init(); + manager->StateChangedNotifyObserver(abilityStateData, isAbility); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_FOREGROUND; + bool needNotifyApp = true; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_BACKGROUND; + bool needNotifyApp = false; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_003, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_BACKGROUND; + bool needNotifyApp = false; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_004, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = false; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_005, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_TERMINATED; + bool needNotifyApp = false; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_006, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = false; + std::string bundleName1 = "com.ohos.unittest1"; + std::string bundleName2 = "com.ohos.unittest2"; + appRecord->mainBundleName_ = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_007, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_CREATE; + bool needNotifyApp = false; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleAppStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleAppStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleAppStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleAppStateChanged_008, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::vector bundleNameList; + std::shared_ptr appRecord = MockAppRecord(); + ApplicationState state = ApplicationState::APP_STATE_END; + bool needNotifyApp = false; + manager->HandleAppStateChanged(appRecord, state, needNotifyApp); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleStateChangedNotifyObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver + * EnvConditions: NA + * CaseDescription: Verify HandleStateChangedNotifyObserver + */ +HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + AbilityStateData abilityStateData; + bool isAbility = true; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + abilityStateData.bundleName = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleStateChangedNotifyObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver + * EnvConditions: NA + * CaseDescription: Verify HandleStateChangedNotifyObserver + */ +HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + AbilityStateData abilityStateData; + bool isAbility = false; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + abilityStateData.bundleName = bundleName; + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleStateChangedNotifyObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver + * EnvConditions: NA + * CaseDescription: Verify HandleStateChangedNotifyObserver + */ +HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_003, TestSize.Level0) +{ + auto manager = std::make_shared(); + AbilityStateData abilityStateData; + bool isAbility = false; + std::vector bundleNameList; + std::string bundleName1 = "com.ohos.unittest1"; + std::string bundleName2 = "com.ohos.unittest2"; + abilityStateData.bundleName = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleStateChangedNotifyObserver + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleStateChangedNotifyObserver + * EnvConditions: NA + * CaseDescription: Verify HandleStateChangedNotifyObserver + */ +HWTEST_F(AppSpawnSocketTest, HandleStateChangedNotifyObserver_004, TestSize.Level0) +{ + auto manager = std::make_shared(); + AbilityStateData abilityStateData; + bool isAbility = false; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + abilityStateData.bundleName = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleStateChangedNotifyObserver(abilityStateData, isAbility); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnAppProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnAppProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnAppProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessCreated_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + manager->HandleOnAppProcessCreated(nullptr); + std::shared_ptr appRecord = MockAppRecord(); + manager->HandleOnAppProcessCreated(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnRenderProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnRenderProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnRenderProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessCreated_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + manager->HandleOnRenderProcessCreated(nullptr); + std::shared_ptr appRecord = MockAppRecord(); + std::shared_ptr renderRecord = std::make_shared(1, "param", 1, 1, appRecord); + renderRecord->SetPid(1); + manager->HandleOnRenderProcessCreated(renderRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + data.bundleName = bundleName; + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessCreated(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + data.bundleName = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessCreated(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_003, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName1 = "com.ohos.unittest"; + std::string bundleName2 = "com.ohos.unittest"; + data.bundleName = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessCreated(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessCreated + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessCreated + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessCreated + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessCreated_004, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + data.bundleName = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleOnProcessCreated(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + manager->HandleOnProcessStateChanged(nullptr); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessStateChanged(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_003, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessStateChanged(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_004, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + std::vector bundleNameList; + std::string bundleName1 = "com.ohos.unittest1"; + std::string bundleName2 = "com.ohos.unittest2"; + appRecord->mainBundleName_ = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleOnProcessStateChanged(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessStateChanged + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessStateChanged + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessStateChanged + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessStateChanged_005, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + appRecord->mainBundleName_ = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleOnProcessStateChanged(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnAppProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnAppProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnAppProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnAppProcessDied_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + manager->HandleOnAppProcessDied(nullptr); + manager->HandleOnAppProcessDied(appRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnRenderProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnRenderProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnRenderProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnRenderProcessDied_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + std::shared_ptr appRecord = MockAppRecord(); + std::shared_ptr renderRecord = std::make_shared(1, "param", 1, 1, appRecord); + renderRecord->SetPid(1); + manager->HandleOnRenderProcessDied(nullptr); + manager->HandleOnRenderProcessDied(renderRecord); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + data.bundleName = bundleName; + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessDied(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName = "com.ohos.unittest"; + data.bundleName = bundleName; + bundleNameList.push_back(bundleName); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessDied(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_003, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName1 = "com.ohos.unittest1"; + std::string bundleName2 = "com.ohos.unittest2"; + data.bundleName = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(observer_, bundleNameList); + manager->HandleOnProcessDied(data); +} + +/* + * Feature: AppStateObserverManager + * Function: HandleOnProcessDied + * SubFunction: NA + * FunctionPoints: AppStateObserverManager HandleOnProcessDied + * EnvConditions: NA + * CaseDescription: Verify HandleOnProcessDied + */ +HWTEST_F(AppSpawnSocketTest, HandleOnProcessDied_004, TestSize.Level0) +{ + auto manager = std::make_shared(); + ProcessData data; + std::vector bundleNameList; + std::string bundleName1 = "com.ohos.unittest1"; + std::string bundleName2 = "com.ohos.unittest2"; + data.bundleName = bundleName1; + bundleNameList.push_back(bundleName2); + manager->appStateObserverMap_.emplace(nullptr, bundleNameList); + manager->HandleOnProcessDied(data); +} + +/* + * Feature: AppStateObserverManager + * Function: ObserverExist + * SubFunction: NA + * FunctionPoints: AppStateObserverManager ObserverExist + * EnvConditions: NA + * CaseDescription: Verify ObserverExist + */ +HWTEST_F(AppSpawnSocketTest, ObserverExist_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + bool res = manager->ObserverExist(nullptr); + EXPECT_FALSE(res); +} + +/* + * Feature: AppStateObserverManager + * Function: ObserverExist + * SubFunction: NA + * FunctionPoints: AppStateObserverManager ObserverExist + * EnvConditions: NA + * CaseDescription: Verify ObserverExist + */ +HWTEST_F(AppSpawnSocketTest, ObserverExist_002, TestSize.Level0) +{ + auto manager = std::make_shared(); + sptr observer = new MockApplicationStateObserver(); + std::vector bundleNameList; + manager->appStateObserverMap_.emplace(observer, bundleNameList); + bool res = manager->ObserverExist(observer); + EXPECT_TRUE(res); +} + +/* + * Feature: AppStateObserverManager + * Function: AddObserverDeathRecipient + * SubFunction: NA + * FunctionPoints: AppStateObserverManager AddObserverDeathRecipient + * EnvConditions: NA + * CaseDescription: Verify AddObserverDeathRecipient + */ +HWTEST_F(AppSpawnSocketTest, AddObserverDeathRecipient_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + manager->AddObserverDeathRecipient(nullptr); + manager->AddObserverDeathRecipient(observer_); +} + +/* + * Feature: AppStateObserverManager + * Function: RemoveObserverDeathRecipient + * SubFunction: NA + * FunctionPoints: AppStateObserverManager RemoveObserverDeathRecipient + * EnvConditions: NA + * CaseDescription: Verify RemoveObserverDeathRecipient + */ +HWTEST_F(AppSpawnSocketTest, RemoveObserverDeathRecipient_001, TestSize.Level0) +{ + auto manager = std::make_shared(); + manager->RemoveObserverDeathRecipient(nullptr); + manager->AddObserverDeathRecipient(observer_); +} +} // namespace AppExecFwk +} // namespace OHOS diff --git a/test/unittest/continuation_test/BUILD.gn b/test/unittest/continuation_test/BUILD.gn index 4cc5c1b1839bca37246a48f917b321d54a16ffd4..23e644265f14b9a2b89293b8121fc10e19d23383 100644 --- a/test/unittest/continuation_test/BUILD.gn +++ b/test/unittest/continuation_test/BUILD.gn @@ -17,6 +17,10 @@ import("//foundation/ability/ability_runtime/ability_runtime.gni") group("unittest") { testonly = true deps = [ + "remote_register_service_test/connect_callback_proxy_test:unittest", + "remote_register_service_test/connect_callback_stub_test:unittest", + "remote_register_service_test/continuation_connector_test:unittest", + "remote_register_service_test/continuation_register_manager_test:unittest", "remote_register_service_test/remote_register_service_proxy_test:unittest", "remote_register_service_test/remote_register_service_stub_test:unittest", ] diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4618db1a32b9af5edf298ea96ffa6fa40f18dfb5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/BUILD.gn @@ -0,0 +1,63 @@ +# 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_runtime/abilitymgr" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("connect_callback_proxy_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ "connect_callback_proxy_test.cpp" ] + + configs = [ ":coverage_flags" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":connect_callback_proxy_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ada9b2f26229d08ed5ca8095f9cd980438884ae5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_proxy_test/connect_callback_proxy_test.cpp @@ -0,0 +1,160 @@ +/* + * 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 +#include + +#define private public +#define protected public +#include "message_parcel.h" +#include "connect_callback_proxy.h" +#include "connect_callback_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ConnectCallbackProxyTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ConnectCallbackProxyTest::SetUpTestCase(void) +{} + +void ConnectCallbackProxyTest::TearDownTestCase(void) +{} + +void ConnectCallbackProxyTest::SetUp(void) +{} + +void ConnectCallbackProxyTest::TearDown(void) +{} + +class MockConnectCallback : public ConnectCallbackStub { +public: + MockConnectCallback() {}; + ~MockConnectCallback() {}; + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + GTEST_LOG_(INFO) << "MockRegisterService::SendRequest called. return value " << returnCode_; + reply.WriteInt32(ERR_NONE); + flag = true; + return returnCode_; + } + + void Connect(const string &deviceId, const string &deviceType) override + { + GTEST_LOG_(INFO) << "MockRegisterService::Connect called."; + return; + } + + void Disconnect(const string &deviceId) override + { + GTEST_LOG_(INFO) << "MockRegisterService::Connect called."; + return; + } + + int32_t returnCode_ = ERR_NONE; + bool flag = false; +}; + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_Connect_001 + * @tc.name: Connect + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_Connect_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Connect_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + std::string deviceId = "7001005458323933328a592135733900"; + std::string deviceType = "rk3568"; + EXPECT_FALSE(object->flag); + testProxy->Connect(deviceId, deviceType); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Connect_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_Disconnect_001 + * @tc.name: Disconnect + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_Disconnect_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Disconnect_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + std::string deviceId = "7001005458323933328a592135733900"; + EXPECT_FALSE(object->flag); + testProxy->Disconnect(deviceId); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_Disconnect_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 + * @tc.name: RemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_RemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + EXPECT_TRUE(testProxy->remoteObject_ != nullptr); + int commandDisconnect = 1; + MessageParcel data = {}; + EXPECT_FALSE(object->flag); + testProxy->RemoteRequest(data, commandDisconnect); + EXPECT_TRUE(object->flag); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 + * @tc.name: RemoteRequest + * @tc.desc: The incoming Remote() is nullptr, and the test program executes as expected without exiting abnormally + */ +HWTEST_F(ConnectCallbackProxyTest, AppExecFwk_ConnectCallbackProxy_RemoteRequest_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 start."; + sptr object = nullptr; + sptr testProxy = new (std::nothrow) ConnectCallbackProxy(object); + EXPECT_TRUE(testProxy != nullptr); + int commandDisconnect = 1; + MessageParcel data = {}; + testProxy->RemoteRequest(data, commandDisconnect); + EXPECT_TRUE(testProxy->remoteObject_ == nullptr); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackProxy_RemoteRequest_002 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a5ec54d6eaa369d12e5d21a582deb810ba30dd22 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/BUILD.gn @@ -0,0 +1,63 @@ +# 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_runtime/abilitymgr" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("connect_callback_stub_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ "connect_callback_stub_test.cpp" ] + + configs = [ ":coverage_flags" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":connect_callback_stub_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..30060629d01d2fb29f7ca7d4604b5d413f7d7df1 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/connect_callback_stub_test/connect_callback_stub_test.cpp @@ -0,0 +1,207 @@ +/* + * 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 +#include + +#define private public +#define protected public +#include "connect_callback_proxy.h" +#include "connect_callback_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ConnectCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ConnectCallbackStubTest::SetUpTestCase(void) +{} + +void ConnectCallbackStubTest::TearDownTestCase(void) +{} + +void ConnectCallbackStubTest::SetUp(void) +{} + +void ConnectCallbackStubTest::TearDown(void) +{} + +class MockConnectCallback : public ConnectCallbackStub { +public: + MockConnectCallback() {}; + ~MockConnectCallback() {}; + + sptr AsObject() override + { + if (!asObject_) { + return nullptr; + } + return this; + }; + + void Connect(const string &deviceId, const string &deviceType) override + { + return; + } + void Disconnect(const string &deviceId) override + { + return; + } + + int32_t returnCode_ = ERR_NONE; + bool asObject_ = true; +}; + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_ConnectInner_001 + * @tc.name: ConnectInner + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_ConnectInner_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_ConnectInner_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + EXPECT_EQ(object->ConnectInner(data, reply), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_ConnectInner_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_DisconnectInner_001 + * @tc.name: DisconnectInner + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_DisconnectInner_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_DisconnectInner_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + EXPECT_EQ(object->DisconnectInner(data, reply), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_DisconnectInner_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 + * @tc.name: OnRemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_CONNECT, data, reply, option), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_001 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 + * @tc.name: OnRemoteRequest + * @tc.desc: Pass in normal parameters, and the test program executes correctly without abnormal exit + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT, data, reply, option), OHOS::ERR_NONE); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_002 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 + * @tc.name: OnRemoteRequest + * @tc.desc: The passed in parameter toukenString is an abnormal value. The test program executes as + * expected and does not exit abnormally + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"123")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_CONNECT, data, reply, option), + OHOS::ERR_INVALID_REPLY); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_003 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 + * @tc.name: OnRemoteRequest + * @tc.desc: The input parameter code is an abnormal value, and the test program executes as expected + * without exiting abnormally + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data; + MessageParcel reply; + MessageOption option; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT + 66, data, reply, option), + OHOS::IPC_STUB_UNKNOW_TRANS_ERR); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_004 end."; +} + +/** + * @tc.number: AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 + * @tc.name: OnRemoteRequest + * @tc.desc: The input parameter code is null ptr, and the test program executes as expected without exception + */ +HWTEST_F(ConnectCallbackStubTest, AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 start."; + sptr object = new (std::nothrow) MockConnectCallback(); + EXPECT_TRUE(object != nullptr); + MessageParcel data = {}; + MessageParcel reply = {}; + MessageOption option = {}; + EXPECT_TRUE(data.WriteInterfaceToken(u"ohos.appexecfwk.iconnectcallback")); + object->memberFuncMap_[MockConnectCallback::COMMAND_DISCONNECT + 1] = nullptr; + EXPECT_EQ(object->OnRemoteRequest(MockConnectCallback::COMMAND_DISCONNECT + 1, data, reply, option), + IPC_STUB_UNKNOW_TRANS_ERR); + GTEST_LOG_(INFO) << "AppExecFwk_ConnectCallbackStub_OnRemoteRequest_005 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5de75636f0482024c86aa8c1942002aa897206d7 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/BUILD.gn @@ -0,0 +1,74 @@ +# 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_runtime/abilitymgr" + +remote_register_path = "${ability_runtime_path}/frameworks/native/ability/native/continuation/remote_register_service" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +ohos_unittest("continuation_connector_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_services_path}/common/include", + ] + + sources = [ + "${remote_register_path}/connect_callback_stub.cpp", + "${remote_register_path}/continuation_connector.cpp", + "${remote_register_path}/continuation_device_callback_proxy.cpp", + "${remote_register_path}/remote_register_service_stub.cpp", + "continuation_connector_test.cpp", + ] + + configs = [ ":coverage_flags" ] + 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", + "c_utils:utils", + "eventhandler:libeventhandler", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":continuation_connector_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db57047e33c73e7ec023ca46a1d13ec47de5b7d5 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_connector_test/continuation_connector_test.cpp @@ -0,0 +1,832 @@ +/* + * 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 +#include + +#define private public +#define protected public +#include "ability.h" +#include "continuation_connector.h" +#include "remote_register_service_stub.h" +#undef private +#undef protected + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ContinuationConnectorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ContinuationConnectorTest::SetUpTestCase(void) +{} +void ContinuationConnectorTest::TearDownTestCase(void) +{} + +void ContinuationConnectorTest::SetUp(void) +{} + +void ContinuationConnectorTest::TearDown(void) +{} + +class MockRegisterService : public RemoteRegisterServiceStub { +public: + MockRegisterService() {}; + virtual ~MockRegisterService() {}; + + int SendRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override + { + GTEST_LOG_(INFO) << "MockRegisterService::SendRequest called. return value " << returnCode_; + reply.WriteInt32(ERR_NONE); + return returnCode_; + } + + int Register(const std::string &bundleName, const sptr &token, const ExtraParams &extras, + const sptr &callback) override + { + return register_; + }; + bool Unregister(int registerToken) override + { + return unregister_; + }; + bool UpdateConnectStatus(int registerToken, const std::string &deviceId, int status) override + { + return updateConnectStatus_; + }; + bool ShowDeviceList(int registerToken, const ExtraParams &extras) override + { + return showDeviceList_; + }; + + sptr AsInterface() override + { + if (!asInterface_) { + return nullptr; + } + + return this; + } + + int32_t returnCode_ = ERR_NONE; + int32_t register_ = ERR_NONE; + bool unregister_ = true; + bool updateConnectStatus_ = true; + bool showDeviceList_ = true; + bool asInterface_ = true; +}; + +class MockRequest : public ContinuationRequest { +public: + MockRequest() {}; + virtual ~MockRequest() {}; + + void Execute() override + { + flag = true; + }; + + bool flag = false; +}; + +class MockContext : public Ability { +public: + MockContext() {}; + virtual ~MockContext() {}; + + ErrCode DisconnectAbility(const sptr &conn) override + { + GTEST_LOG_(INFO) << "Mock DisconnectAbility called."; + return ERR_OK; + } + + bool ConnectAbility(const Want &want, const sptr &conn) override + { + GTEST_LOG_(INFO) << "Mock ConnectAbility called."; + return true; + } +}; + +/* +* @tc.number: AppExecFwk_ContinuationConnector_GetInstance_001 +* @tc.name: GetInstance +* @tc.desc: Verify function GetInstance normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_GetInstance_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ == nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + ContinuationConnector::instance_.clear(); + ContinuationConnector::instance_ = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_GetInstance_002 +* @tc.name: GetInstance +* @tc.desc: Verify function GetInstance normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_GetInstance_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + EXPECT_TRUE(ContinuationConnector::GetInstance(ability) != nullptr); + EXPECT_TRUE(ContinuationConnector::instance_ != nullptr); + ContinuationConnector::instance_.clear(); + ContinuationConnector::instance_ = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_GetInstance_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_TRUE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone abnormal branch, parameter object is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = nullptr; + EXPECT_TRUE(object == nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_FALSE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone abnormal branch, conversion registerService is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->continuationRequestList_.push_back(mockRequest); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + object->asInterface_ = false; + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_FALSE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 +* @tc.name: OnAbilityConnectDone +* @tc.desc: Verify function OnAbilityConnectDone normal branch, member variable requestList is empty +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector->OnAbilityConnectDone(element, object, registerToken); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityConnectDone_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 +* @tc.name: OnAbilityDisconnectDone +* @tc.desc: Verify function OnAbilityDisconnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector->OnAbilityDisconnectDone(element, registerToken); + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 +* @tc.name: OnAbilityDisconnectDone +* @tc.desc: Verify function OnAbilityDisconnectDone normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + AppExecFwk::ElementName element; + constexpr int32_t registerToken = 0; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + testConnector->OnAbilityDisconnectDone(element, registerToken); + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_OnAbilityDisconnectDone_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + std::shared_ptr context = std::make_shared(); + EXPECT_TRUE(context != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(false); + EXPECT_FALSE(testConnector->isConnected_.load()); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility abnormal branch, member variable context_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility abnormal branch, parameter request is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->BindRemoteRegisterAbility(nullptr); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 +* @tc.name: BindRemoteRegisterAbility +* @tc.desc: Verify function BindRemoteRegisterAbility normal branch, member variable isConnected is true +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 start."; + auto mockRequest = std::make_shared(); + EXPECT_TRUE(mockRequest != nullptr); + EXPECT_FALSE(mockRequest->flag); + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->BindRemoteRegisterAbility(mockRequest); + EXPECT_TRUE(testConnector->continuationRequestList_.size() == 0); + EXPECT_TRUE(mockRequest->flag); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_BindRemoteRegisterAbility_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 +* @tc.name: UnbindRemoteRegisterAbility +* @tc.desc: Verify function UnbindRemoteRegisterAbility normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 start."; + std::shared_ptr context = std::make_shared(); + EXPECT_TRUE(context != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->UnbindRemoteRegisterAbility(); + EXPECT_FALSE(testConnector->isConnected_.load()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 +* @tc.name: UnbindRemoteRegisterAbility +* @tc.desc: Verify function UnbindRemoteRegisterAbility abnormal branch, member varable context_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 start."; + std::shared_ptr context = nullptr; + EXPECT_TRUE(context == nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(context); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector->UnbindRemoteRegisterAbility(); + EXPECT_TRUE(testConnector->isConnected_.load()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UnbindRemoteRegisterAbility_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_IsAbilityConnected_001 +* @tc.name: IsAbilityConnected +* @tc.desc: Verify function IsAbilityConnected normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_IsAbilityConnected_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(true); + EXPECT_TRUE(testConnector->IsAbilityConnected()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_IsAbilityConnected_002 +* @tc.name: IsAbilityConnected +* @tc.desc: Verify function IsAbilityConnected normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_IsAbilityConnected_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + testConnector->isConnected_.store(false); + EXPECT_FALSE(testConnector->IsAbilityConnected()); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_IsAbilityConnected_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_001 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + constexpr int32_t registerToken = 100; + object->unregister_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_002 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + constexpr int32_t registerToken = 100; + object->unregister_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_002 end."; +} + +/* + * Feature: AbilityManager + * Function: ContinuationConnector + * SubFunction: Unregister + * FunctionPoints: The parameter of function Unregister. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function Unregister abnormal branch + */ +/* +* @tc.number: AppExecFwk_ContinuationConnector_Unregister_002 +* @tc.name: Unregister +* @tc.desc: Verify function Unregister abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Unregister_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->Unregister(registerToken)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Unregister_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->updateConnectStatus_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->updateConnectStatus_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_UpdateConnectStatus_002 +* @tc.name: UpdateConnectStatus +* @tc.desc: Verify function UpdateConnectStatus abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_UpdateConnectStatus_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + constexpr int32_t stage = 1; + const std::string deviceId = "7001005458323933328a592135733900"; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->UpdateConnectStatus(registerToken, deviceId, stage)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_UpdateConnectStatus_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_001 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_001 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->showDeviceList_ = true; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_TRUE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_002 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_002 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + object->showDeviceList_ = false; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + EXPECT_FALSE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_ShowDeviceList_003 +* @tc.name: ShowDeviceList +* @tc.desc: Verify function ShowDeviceList abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_ShowDeviceList_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_003 start."; + std::shared_ptr ability = nullptr; + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + constexpr int32_t registerToken = 100; + const ExtraParams extra = {}; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + EXPECT_FALSE(testConnector->ShowDeviceList(registerToken, extra)); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_ShowDeviceList_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_001 +* @tc.name: Register +* @tc.desc: Verify function Register normal branch +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_001 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), ERR_NONE); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_001 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_002 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, interface Register return error code +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_002 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + object->register_ = ERR_NONE - 1; + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), ERR_NONE - 1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_002 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_003 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, parameter context is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_003 start."; + std::shared_ptr ability = nullptr; + EXPECT_TRUE(ability == nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_003 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_004 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, member variable remoteRegisterService_ is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_004 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + ability->token_ = object; + EXPECT_TRUE(ability->token_ != nullptr); + testConnector->remoteRegisterService_ = nullptr; + EXPECT_TRUE(testConnector->remoteRegisterService_ == nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_004 end."; +} + +/* +* @tc.number: AppExecFwk_ContinuationConnector_Register_005 +* @tc.name: Register +* @tc.desc: Verify function Register abnormal branch, obtained token is nullptr +*/ +HWTEST_F(ContinuationConnectorTest, AppExecFwk_ContinuationConnector_Register_005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_005 start."; + std::shared_ptr ability = std::make_shared(); + EXPECT_TRUE(ability != nullptr); + sptr testConnector = new (std::nothrow) ContinuationConnector(ability); + EXPECT_TRUE(testConnector != nullptr); + const std::string bundleName = "ABC"; + const ExtraParams extra = {}; + std::shared_ptr callback = nullptr; + sptr object = new (std::nothrow) MockRegisterService(); + EXPECT_TRUE(object != nullptr); + EXPECT_TRUE(ability->token_ == nullptr); + testConnector->remoteRegisterService_ = object; + EXPECT_TRUE(testConnector->remoteRegisterService_ != nullptr); + std::weak_ptr context = ability; + EXPECT_EQ(testConnector->Register(context, bundleName, extra, callback), -1); + testConnector.clear(); + testConnector = nullptr; + GTEST_LOG_(INFO) << "AppExecFwk_ContinuationConnector_Register_005 end."; +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..218e8b3e9a9611169bd7f3dbc579b9a842760a33 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/BUILD.gn @@ -0,0 +1,108 @@ +# 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_runtime/abilitymgr" + +remote_register_path = "${ability_runtime_path}/frameworks/native/ability/native/continuation/remote_register_service" + +config("coverage_flags") { + if (ability_runtime_feature_coverage) { + cflags = [ "--coverage" ] + ldflags = [ "--coverage" ] + } +} + +config("ability_config") { + visibility = [ ":*" ] + include_dirs = [ + "${ability_runtime_path}/interfaces/kits/native/ability/native", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/distributed", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/kits", + "${ability_runtime_path}/interfaces/kits/native/ability/native/continuation/remote_register_service", + "${ability_runtime_path}/interfaces/kits/native/ability/native/distributed_ability_runtime", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${ability_runtime_innerkits_path}/app_manager/include/appmgr", + "${ability_runtime_innerkits_path}/uri/include", + "${ability_runtime_services_path}/abilitymgr/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "${form_fwk_path}/interfaces/kits/native/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/app", + "//third_party/node/src", + "${ability_runtime_innerkits_path}/ability_manager/include/continuation", + "${ability_runtime_path}/interfaces/kits/native/appkit/app/task", + "${ability_runtime_napi_path}/inner/napi_common", + "${ability_runtime_napi_path}/featureAbility", + "//foundation/ability/ability_runtime/interfaces/kits/native/ability/native/continuation/kits", + ] + + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + defines = [ "AMS_LOG_TAG = \"Ability\"" ] + if (target_cpu == "arm64") { + defines += [ "_ARM64_" ] + } + + if (ability_runtime_graphics) { + include_dirs += [ "${form_fwk_path}/interfaces/inner_api/include" ] + defines += [ "SUPPORT_GRAPHICS" ] + } +} + +ohos_unittest("continuation_register_manager_test") { + module_out_path = module_output_path + + sources = [ + "${remote_register_path}/continuation_register_manager.cpp", + "continuation_register_manager_test.cpp", + ] + + configs = [ + ":ability_config", + ":coverage_flags", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "//foundation/ability/ability_runtime/frameworks/native/ability/native:continuation_ipc", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "resource_management:global_resmgr", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + deps = [ ":continuation_register_manager_test" ] +} diff --git a/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..309573d9327c8f72f28d501cfc483e993d8a2fa8 --- /dev/null +++ b/test/unittest/continuation_test/remote_register_service_test/continuation_register_manager_test/continuation_register_manager_test.cpp @@ -0,0 +1,339 @@ +/* + * 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 +#include + +#define private public +#define protected public +#include "continuation_register_manager_proxy.h" +#include "continuation_register_manager.h" +#include "connect_callback_stub.h" +#include "continuation_connector.h" +#undef private +#undef protected +#include "bundle_mgr_interface.h" +#include "ability_manager_interface.h" +#include "iability_controller.h" +#include "pixel_map.h" +#include "ability_info.h" +#include "ability.h" +#include "request_callback.h" + +using namespace testing::ext; +using namespace testing; +using namespace std::chrono; + +namespace OHOS { +namespace AppExecFwk { +class ContinuationRegisterManagerTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ContinuationRegisterManagerTest::SetUpTestCase(void) +{} +void ContinuationRegisterManagerTest::TearDownTestCase(void) +{} + +void ContinuationRegisterManagerTest::SetUp(void) +{} + +void ContinuationRegisterManagerTest::TearDown(void) +{} + +class MockRequestCallback : public RequestCallback { +public: + MockRequestCallback() {}; + virtual ~MockRequestCallback() {}; + + virtual void OnResult(int result) + { + onResult_ = true; + }; + + bool onResult_ = false; +}; + +/* + * @tc.number : ContinuationRegisterManager_Register_001 + * @tc.name : Register + * @tc.desc : Verify that the Register interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Register_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + const std::string bundleName = ""; + ExtraParams parameter; + std::shared_ptr deviceCallback; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Register(bundleName, parameter, deviceCallback, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Register_002 + * @tc.name : Register + * @tc.desc : Verify that the Register interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Register_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + const std::string bundleName = ""; + ExtraParams parameter; + std::shared_ptr deviceCallback; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Register(bundleName, parameter, deviceCallback, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Unregister_001 + * @tc.name : Unregister + * @tc.desc : Verify that the Unregister interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Unregister_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Unregister(token, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Unregister_002 + * @tc.name : Unregister + * @tc.desc : Verify that the Unregister interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Unregister_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->Unregister(token, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_UpdateConnectStatus_001 + * @tc.name : UpdateConnectStatus + * @tc.desc : Verify that the UpdateConnectStatus interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_UpdateConnectStatus_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + const std::string deviceId = ""; + constexpr int32_t status = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->UpdateConnectStatus(token, deviceId, status, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_UpdateConnectStatus_002 + * @tc.name : UpdateConnectStatus + * @tc.desc : Verify that the UpdateConnectStatus interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_UpdateConnectStatus_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + const std::string deviceId = ""; + constexpr int32_t status = 0; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->UpdateConnectStatus(token, deviceId, status, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_ShowDeviceList_001 + * @tc.name : ShowDeviceList + * @tc.desc : Verify that the ShowDeviceList interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_ShowDeviceList_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + ExtraParams parameter; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->ShowDeviceList(token, parameter, requestCallback); + EXPECT_TRUE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_ShowDeviceList_002 + * @tc.name : ShowDeviceList + * @tc.desc : Verify that the ShowDeviceList interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_ShowDeviceList_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + constexpr int32_t token = 0; + ExtraParams parameter; + std::shared_ptr requestCallback = std::make_shared(); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManagerProxy->context_ = context; + continuationRegisterManagerProxy->applicationContext_ = context; + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + continuationRegisterManager->Init(nullptr); + + EXPECT_FALSE(requestCallback->onResult_); + continuationRegisterManager->ShowDeviceList(token, parameter, requestCallback); + EXPECT_FALSE(requestCallback->onResult_); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_001 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_001, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(true); + + EXPECT_TRUE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); + continuationRegisterManager->Disconnect(); + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_002 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_002, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = nullptr; + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_TRUE(true); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_003 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_003, TestSize.Level1) +{ + std::shared_ptr context = std::make_shared(); + auto continuationRegisterManager = std::make_shared(); + auto continuationRegisterManagerProxy = std::make_shared(context); + continuationRegisterManagerProxy->continuatinConnector_ = new (std::nothrow) ContinuationConnector(context); + + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); + continuationRegisterManagerProxy->continuatinConnector_->isConnected_.store(false); + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_FALSE(continuationRegisterManagerProxy->continuatinConnector_->isConnected_.load()); +} + +/* + * @tc.number : ContinuationRegisterManager_Disconnect_004 + * @tc.name : Disconnect + * @tc.desc : Verify that the Disconnect interface is called normally + */ +HWTEST_F(ContinuationRegisterManagerTest, ContinuationRegisterManager_Disconnect_004, TestSize.Level1) +{ + auto continuationRegisterManager = std::make_shared(); + std::shared_ptr continuationRegisterManagerProxy; + continuationRegisterManager->Init(continuationRegisterManagerProxy); + + continuationRegisterManager->Disconnect(); + EXPECT_TRUE(true); +} +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/data_ability_manager_test/data_ability_manager_test.cpp b/test/unittest/data_ability_manager_test/data_ability_manager_test.cpp index 41cd20acd27b6b4c892609261ef253403aa621a5..ca2a9e93592d6737b89aab22e91e7675082b7ae5 100644 --- a/test/unittest/data_ability_manager_test/data_ability_manager_test.cpp +++ b/test/unittest/data_ability_manager_test/data_ability_manager_test.cpp @@ -26,6 +26,7 @@ #include "ability_scheduler_mock.h" #include "mock_app_mgr_client.h" +#include "ability_manager_errors.h" using namespace testing::ext; using namespace testing; @@ -347,6 +348,68 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Acquire_006, TestSize. HILOG_INFO("AaFwk_DataAbilityManager_Acquire_006 end."); } +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Acquire + * FunctionPoints: The parameter of function Acquire. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function Acquire waitforloaded timeout. + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Acquire_007, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = ""; + auto res = dataAbilityManager->Acquire(abilityRequest, true, abilityRecordClient_->GetToken(), false); + EXPECT_EQ(res, nullptr); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Acquire + * FunctionPoints: The parameter of function Acquire. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function Acquire waitforloaded timeout. + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Acquire_008, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->ability_ = abilityRecordClient_; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + dataAbilityRecord->scheduler_ = nullptr; + auto res = dataAbilityManager->Acquire(abilityRequest, true, dataAbilityRecord->GetToken(), true); + EXPECT_EQ(res, nullptr); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Acquire + * FunctionPoints: The parameter of function Acquire. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function Acquire waitforloaded timeout. + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Acquire_009, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->ability_ = abilityRecordClient_; + auto res = dataAbilityManager->Acquire(abilityRequest, true, dataAbilityRecord->GetToken(), true); + EXPECT_EQ(res, nullptr); +} + /* * Feature: AbilityManager * Function: DataAbility @@ -405,6 +468,187 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_003, TestSize. HILOG_INFO("AaFwk_DataAbilityManager_Release_003 end."); } +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_004, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->abilityInfo_.visible = false; + abilityRecord->SetAbilityState(ACTIVE); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ABILITY_VISIBLE_FALSE_DENY_REQUEST); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_005, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->abilityInfo_.visible = true; + abilityRecord->SetAbilityState(ACTIVE); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ERR_UNKNOWN_OBJECT); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_006, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->abilityInfo_.visible = true; + abilityRecord->SetAbilityState(ACTIVE); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + DataAbilityRecord::ClientInfo ci; + ci.client = dataAbilityRecord->GetToken(); + dataAbilityRecord->clients_.push_back(ci); + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ERR_OK); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_007, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = new AbilitySchedulerMock(); + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ERR_UNKNOWN_OBJECT); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_008, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = dataAbilityRecord; + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ERR_UNKNOWN_OBJECT); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: Release + * FunctionPoints: The parameter of function Release. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify Release + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_Release_009, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["bundleName.name"] = nullptr; + int res = dataAbilityManager->Release(abilitySchedulerMock_, dataAbilityRecord->GetToken(), false); + EXPECT_EQ(res, ERR_UNKNOWN_OBJECT); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: ContainsDataAbility + * FunctionPoints: The parameter of function ContainsDataAbility. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify ContainsDataAbility + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_ContainsDataAbility_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityRecord->scheduler_ = new AbilitySchedulerMock(); + dataAbilityManager->dataAbilityRecordsLoaded_["b"] = dataAbilityRecord; + dataAbilityRecord->scheduler_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["c"] = dataAbilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["d"] = nullptr; + int res = dataAbilityManager->ContainsDataAbility(abilitySchedulerMock_); + EXPECT_EQ(res, ERR_OK); +} + /* * Feature: AbilityManager * Function: DataAbility @@ -501,6 +745,156 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_AbilityTransitionDone_ HILOG_INFO("AaFwk_DataAbilityManager_AbilityTransitionDone_002 end."); } +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: OnAbilityDied + * FunctionPoints: The parameter of function OnAbilityDied. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify OnAbilityDied + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_OnAbilityDied_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->OnAbilityDied(abilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: OnAbilityDied + * FunctionPoints: The parameter of function OnAbilityDied. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify OnAbilityDied + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_OnAbilityDied_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->OnAbilityDied(abilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: OnAbilityDied + * FunctionPoints: The parameter of function OnAbilityDied. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify OnAbilityDied + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_OnAbilityDied_003, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->OnAbilityDied(abilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: OnAppStateChanged + * FunctionPoints: The parameter of function OnAppStateChanged. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify OnAppStateChanged + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_OnAppStateChanged_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AppInfo info; + std::string processName = "processName"; + std::string appName = "appName"; + int32_t uid = 0; + AppData data; + data.appName = appName; + data.uid = uid; + info.processName = processName; + info.appData.push_back(data); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord1 = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord1 = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->dataAbilityRecordsLoading_["a"] = nullptr; + abilityRecord1->abilityInfo_.process = processName; + abilityRecord1->applicationInfo_.bundleName = ""; + abilityRecord1->applicationInfo_.name = appName; + abilityRecord1->abilityInfo_.applicationInfo.uid = uid; + dataAbilityRecord1->ability_ = abilityRecord1; + dataAbilityManager->dataAbilityRecordsLoaded_["b"] = dataAbilityRecord1; + dataAbilityManager->dataAbilityRecordsLoading_["b"] = dataAbilityRecord1; + auto dataAbilityRecord2 = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord2 = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord2->abilityInfo_.process = ""; + abilityRecord2->applicationInfo_.bundleName = processName; + abilityRecord2->applicationInfo_.name = ""; + abilityRecord2->abilityInfo_.applicationInfo.uid = 0; + dataAbilityRecord2->ability_ = abilityRecord2; + dataAbilityManager->dataAbilityRecordsLoaded_["c"] = dataAbilityRecord2; + dataAbilityManager->dataAbilityRecordsLoading_["c"] = dataAbilityRecord2; + auto dataAbilityRecord3 = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord3 = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord3->abilityInfo_.process = ""; + abilityRecord3->applicationInfo_.bundleName = ""; + dataAbilityRecord3->ability_ = abilityRecord3; + dataAbilityManager->dataAbilityRecordsLoaded_["d"] = dataAbilityRecord3; + dataAbilityManager->dataAbilityRecordsLoading_["d"] = dataAbilityRecord3; + auto dataAbilityRecord4 = std::make_shared(abilityRequest); + dataAbilityRecord4->ability_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["e"] = dataAbilityRecord4; + dataAbilityManager->dataAbilityRecordsLoading_["e"] = dataAbilityRecord4; + dataAbilityManager->OnAppStateChanged(info); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRecordById + * FunctionPoints: The parameter of function GetAbilityRecordById. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRecordById + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordById_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + int64_t id = 0; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->recordId_ = 1; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["b"] = dataAbilityRecord; + auto res = dataAbilityManager->GetAbilityRecordById(id); + EXPECT_EQ(res, nullptr); +} + /* * Feature: AbilityManager * Function: DataAbility @@ -519,6 +913,31 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordByToke HILOG_INFO("AaFwk_DataAbilityManager_GetAbilityRecordByToken_001 end."); } +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRecordByToken + * FunctionPoints: The parameter of function GetAbilityRecordByToken. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRecordByToken token is nullptr. + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordByToken_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->dataAbilityRecordsLoading_["a"] = nullptr; + dataAbilityManager->dataAbilityRecordsLoading_["b"] = dataAbilityRecord; + auto res = dataAbilityManager->GetAbilityRecordByToken(dataAbilityRecord->GetToken()); + EXPECT_NE(res, nullptr); +} + /* * Feature: AbilityManager * Function: DataAbility @@ -537,6 +956,33 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordBySche HILOG_INFO("AaFwk_DataAbilityManager_GetAbilityRecordByScheduler_001 end."); } +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRecordByScheduler + * FunctionPoints: The parameter of function GetAbilityRecordByScheduler. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRecordByScheduler + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordByScheduler_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = new AbilitySchedulerMock(); + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityRecord->scheduler_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["b"] = dataAbilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["c"] = nullptr; + auto res = dataAbilityManager->GetAbilityRecordByScheduler(abilitySchedulerMock_); + EXPECT_EQ(res, nullptr); +} + /* * Feature: AbilityManager * Function: DataAbility @@ -554,5 +1000,650 @@ HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRecordById_0 HILOG_INFO("AaFwk_DataAbilityManager_GetAbilityRecordById_001 end."); } + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: LoadLocked + * FunctionPoints: The parameter of function LoadLocked. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function LoadLocked + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_LoadLocked_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::string name = "name"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::PAGE; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + dataAbilityManager->dataAbilityRecordsLoading_.clear(); + auto res = dataAbilityManager->LoadLocked(name, abilityRequest); + EXPECT_EQ(res, nullptr); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: LoadLocked + * FunctionPoints: The parameter of function LoadLocked. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function LoadLocked + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_LoadLocked_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::string name = "name"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoading_[name] = dataAbilityRecord; + auto res = dataAbilityManager->LoadLocked(name, abilityRequest); + EXPECT_EQ(res, nullptr); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpLocked + * FunctionPoints: The parameter of function DumpLocked. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpLocked + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpLocked_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + const char func[1] = ""; + int line = 0; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->dataAbilityRecordsLoading_["a"] = nullptr; + dataAbilityManager->DumpLocked(func, line); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpLocked + * FunctionPoints: The parameter of function DumpLocked. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpLocked + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpLocked_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + const char func[2] = "a"; + int line = 0; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->dataAbilityRecordsLoading_["a"] = dataAbilityRecord; + dataAbilityManager->DumpLocked(func, line); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpLocked + * FunctionPoints: The parameter of function DumpLocked. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpLocked + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpLocked_003, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + const char func[2] = "a"; + int line = -1; + dataAbilityManager->dataAbilityRecordsLoaded_.clear(); + dataAbilityManager->dataAbilityRecordsLoading_.clear(); + dataAbilityManager->DumpLocked(func, line); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpState + * FunctionPoints: The parameter of function DumpState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpState_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + std::string args = "args"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = dataAbilityRecord; + dataAbilityManager->DumpState(info, args); + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = nullptr; + dataAbilityManager->DumpState(info, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpState + * FunctionPoints: The parameter of function DumpState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpState_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + std::string args = "args"; + dataAbilityManager->dataAbilityRecordsLoaded_.clear(); + dataAbilityManager->DumpState(info, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpState + * FunctionPoints: The parameter of function DumpState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpState_003, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + std::string args = ""; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["b"] = nullptr; + dataAbilityManager->DumpState(info, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = "args"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->isReady_ = true; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = "args"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->isReady_ = false; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_003, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = "args"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_004, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = "args"; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->scheduler_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_005, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = "args"; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = nullptr; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_006, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = false; + std::string args = "args"; + dataAbilityManager->dataAbilityRecordsLoaded_["args"] = nullptr; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_007, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = false; + std::string args = "args"; + dataAbilityManager->dataAbilityRecordsLoaded_.clear(); + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_008, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = ""; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->isReady_ = true; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_009, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = ""; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->isReady_ = false; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_010, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = ""; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityRecord->scheduler_ = abilitySchedulerMock_; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_011, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = ""; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->scheduler_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_012, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = true; + std::string args = ""; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: DumpSysState + * FunctionPoints: The parameter of function DumpSysState. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function DumpSysState + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_DumpSysState_013, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isClient = false; + std::string args = ""; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->DumpSysState(info, isClient, args); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRunningInfos + * FunctionPoints: The parameter of function GetAbilityRunningInfos. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRunningInfos + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRunningInfos_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isPerm = true; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = nullptr; + dataAbilityManager->GetAbilityRunningInfos(info, isPerm); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRunningInfos + * FunctionPoints: The parameter of function GetAbilityRunningInfos. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRunningInfos + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRunningInfos_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isPerm = true; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityRecord->ability_ = nullptr; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->GetAbilityRunningInfos(info, isPerm); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRunningInfos + * FunctionPoints: The parameter of function GetAbilityRunningInfos. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRunningInfos + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRunningInfos_003, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isPerm = false; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->applicationInfo_.accessTokenId = -1; + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->GetAbilityRunningInfos(info, isPerm); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: GetAbilityRunningInfos + * FunctionPoints: The parameter of function GetAbilityRunningInfos. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function GetAbilityRunningInfos + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_GetAbilityRunningInfos_004, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + bool isPerm = false; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + abilityRecord->applicationInfo_.accessTokenId = IPCSkeleton::GetCallingTokenID(); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->dataAbilityRecordsLoaded_["a"] = dataAbilityRecord; + dataAbilityManager->GetAbilityRunningInfos(info, isPerm); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: RestartDataAbility + * FunctionPoints: The parameter of function RestartDataAbility. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function RestartDataAbility + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_RestartDataAbility_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + std::vector info; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityManager->RestartDataAbility(abilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: ReportDataAbilityAcquired + * FunctionPoints: The parameter of function ReportDataAbilityAcquired. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function ReportDataAbilityAcquired + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_ReportDataAbilityAcquired_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + bool isNotHap = true; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->ReportDataAbilityAcquired(dataAbilityRecord->GetToken(), isNotHap, dataAbilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: ReportDataAbilityAcquired + * FunctionPoints: The parameter of function ReportDataAbilityAcquired. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function ReportDataAbilityAcquired + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_ReportDataAbilityAcquired_002, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + bool isNotHap = true; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + dataAbilityManager->ReportDataAbilityAcquired(nullptr, isNotHap, dataAbilityRecord); +} + +/* + * Feature: AbilityManager + * Function: DataAbility + * SubFunction: ReportDataAbilityReleased + * FunctionPoints: The parameter of function ReportDataAbilityReleased. + * EnvConditions: Can run ohos test framework + * CaseDescription: Verify function ReportDataAbilityReleased + */ +HWTEST_F(DataAbilityManagerTest, AaFwk_DataAbilityManager_ReportDataAbilityReleased_001, TestSize.Level1) +{ + std::unique_ptr dataAbilityManager = std::make_unique(); + bool isNotHap = true; + AbilityRequest abilityRequest; + abilityRequest.abilityInfo.type = AppExecFwk::AbilityType::DATA; + abilityRequest.abilityInfo.bundleName = "bundleName"; + abilityRequest.abilityInfo.name = "name"; + auto dataAbilityRecord = std::make_shared(abilityRequest); + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + dataAbilityRecord->ability_ = abilityRecord; + dataAbilityManager->ReportDataAbilityReleased(dataAbilityRecord->GetToken(), isNotHap, dataAbilityRecord); +} } // namespace AAFwk } // namespace OHOS diff --git a/test/unittest/frameworks_kits_appkit_native_test/ability_start_setting_test.cpp b/test/unittest/frameworks_kits_appkit_native_test/ability_start_setting_test.cpp index b9bf8688155d706e75f2ec92cacd860739d36099..e9f88403afca2a54ced78341289c92e1a85940a1 100644 --- a/test/unittest/frameworks_kits_appkit_native_test/ability_start_setting_test.cpp +++ b/test/unittest/frameworks_kits_appkit_native_test/ability_start_setting_test.cpp @@ -17,7 +17,11 @@ #include #include #include + +#define private public #include "ability_start_setting.h" +#undef private + #include "parcel.h" namespace OHOS { @@ -114,5 +118,24 @@ HWTEST_F(AbilityStartSettingTest, AppExecFwk_IsEmpty_0100, Function | MediumTest GTEST_LOG_(INFO) << "AppExecFwk_AbilityStartSetting_0100 test 6"; } } + +/** + * @tc.number: AbilityStartSetting_Operator_0100 + * @tc.name: operator= + * @tc.desc: Test operator=. + */ +HWTEST_F(AbilityStartSettingTest, AbilityStartSetting_Operator_0100, Function | MediumTest | Level1) +{ + std::shared_ptr setting = AbilityStartSetting::GetEmptySetting(); + AbilityStartSetting abilitySetting = *setting; + AbilityStartSetting newSetting = *setting; + abilitySetting = newSetting; + setting->AddProperty("hello", "world"); + EXPECT_TRUE("world" == setting->GetProperty("hello")); + + Parcel parcel; + parcel.WriteUint32(10001); + EXPECT_TRUE(nullptr == AbilityStartSetting::Unmarshalling(parcel)); +} } // namespace AppExecFwk } // namespace OHOS diff --git a/test/unittest/implicit_start_processor_test/BUILD.gn b/test/unittest/implicit_start_processor_test/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..963ffe7e190a570f9e4fb0a7a3ce2dd51b54e5cb --- /dev/null +++ b/test/unittest/implicit_start_processor_test/BUILD.gn @@ -0,0 +1,77 @@ +# 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. + +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +import( + "//foundation/ability/ability_runtime/services/abilitymgr/abilitymgr.gni") + +module_output_path = "ability_runtime/abilitymgr" + +ohos_unittest("implicit_start_processor_test") { + module_out_path = module_output_path + + include_dirs = [ + "${ability_runtime_test_path}/mock/services_abilitymgr_test/libs/system_ability_mock", + "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/app_scheduler.cpp", + "implicit_start_processor_test.cpp", + ] + + configs = [ + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + "${ability_runtime_test_path}/mock/services_abilitymgr_test:aafwk_mock_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${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", + "//third_party/googletest:gmock_main", + "//third_party/googletest:gtest_main", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "init:libbeget_proxy", + "ipc:ipc_core", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } +} + +group("unittest") { + testonly = true + + deps = [ ":implicit_start_processor_test" ] +} diff --git a/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp b/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp new file mode 100755 index 0000000000000000000000000000000000000000..30416898a3b350fd45d19bc3a7f44b6bad6cd204 --- /dev/null +++ b/test/unittest/implicit_start_processor_test/implicit_start_processor_test.cpp @@ -0,0 +1,266 @@ +/* + * 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 + +#define private public +#define protected public +#include "implicit_start_processor.h" +#undef private +#undef protected + +using namespace testing; +using namespace testing::ext; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace AAFwk { + +class ImplicitStartProcessorTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void ImplicitStartProcessorTest::SetUpTestCase(void) +{} +void ImplicitStartProcessorTest::TearDownTestCase(void) +{} +void ImplicitStartProcessorTest::SetUp() +{} +void ImplicitStartProcessorTest::TearDown() +{} + +/* + * Feature: ImplicitStartProcessor + * Function: ImplicitStartAbility + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor ImplicitStartAbility + * EnvConditions: NA + * CaseDescription: Verify ImplicitStartAbility + */ +HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbility_001, TestSize.Level1) +{ + auto processor = std::make_shared(); + AbilityRequest request; + int32_t userId = 0; + bool res = processor->ImplicitStartAbility(request, userId); + EXPECT_TRUE(res); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CheckImplicitStartExtensionIsValid + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CheckImplicitStartExtensionIsValid + * EnvConditions: NA + * CaseDescription: Verify CheckImplicitStartExtensionIsValid + */ +HWTEST_F(ImplicitStartProcessorTest, CheckImplicitStartExtensionIsValid_001, TestSize.Level1) +{ + auto processor = std::make_shared(); + AbilityRequest request; + ExtensionAbilityInfo extensionInfo; + Want want; + want.SetElementName("bundle", ""); + request.want = want; + bool res = processor->CheckImplicitStartExtensionIsValid(request, extensionInfo); + EXPECT_TRUE(res); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CheckImplicitStartExtensionIsValid + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CheckImplicitStartExtensionIsValid + * EnvConditions: NA + * CaseDescription: Verify CheckImplicitStartExtensionIsValid + */ +HWTEST_F(ImplicitStartProcessorTest, CheckImplicitStartExtensionIsValid_002, TestSize.Level1) +{ + auto processor = std::make_shared(); + AbilityRequest request; + ExtensionAbilityInfo extensionInfo; + Want want; + want.SetElementName("", ""); + request.want = want; + extensionInfo.type = ExtensionAbilityType::WORK_SCHEDULER; + bool res = processor->CheckImplicitStartExtensionIsValid(request, extensionInfo); + EXPECT_FALSE(res); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CheckImplicitStartExtensionIsValid + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CheckImplicitStartExtensionIsValid + * EnvConditions: NA + * CaseDescription: Verify CheckImplicitStartExtensionIsValid + */ +HWTEST_F(ImplicitStartProcessorTest, CheckImplicitStartExtensionIsValid_003, TestSize.Level1) +{ + auto processor = std::make_shared(); + AbilityRequest request; + ExtensionAbilityInfo extensionInfo; + Want want; + want.SetElementName("", ""); + request.want = want; + extensionInfo.type = ExtensionAbilityType::FORM; + bool res = processor->CheckImplicitStartExtensionIsValid(request, extensionInfo); + EXPECT_TRUE(res); +} + +/* + * Feature: ImplicitStartProcessor + * Function: ImplicitStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor ImplicitStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify ImplicitStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbilityInner_001, TestSize.Level1) +{ + auto processor = std::make_shared(); + Want want; + AbilityRequest request; + int32_t userId = 0; + request.callType = AbilityCallType::START_OPTIONS_TYPE; + bool res = processor->ImplicitStartAbilityInner(want, request, userId); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: ImplicitStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor ImplicitStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify ImplicitStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbilityInner_002, TestSize.Level1) +{ + auto processor = std::make_shared(); + Want want; + AbilityRequest request; + int32_t userId = 0; + request.callType = AbilityCallType::START_SETTINGS_TYPE; + bool res = processor->ImplicitStartAbilityInner(want, request, userId); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: ImplicitStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor ImplicitStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify ImplicitStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbilityInner_003, TestSize.Level1) +{ + auto processor = std::make_shared(); + Want want; + AbilityRequest request; + int32_t userId = 0; + request.callType = AbilityCallType::START_EXTENSION_TYPE; + bool res = processor->ImplicitStartAbilityInner(want, request, userId); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: ImplicitStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor ImplicitStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify ImplicitStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, ImplicitStartAbilityInner_004, TestSize.Level1) +{ + auto processor = std::make_shared(); + Want want; + AbilityRequest request; + int32_t userId = 0; + request.callType = AbilityCallType::CALL_REQUEST_TYPE; + bool res = processor->ImplicitStartAbilityInner(want, request, userId); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CallStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CallStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify CallStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, CallStartAbilityInner_001, TestSize.Level1) +{ + auto processor = std::make_shared(); + int32_t userId = 0; + Want want; + ImplicitStartProcessor::StartAbilityClosure callBack = []() -> int32_t { + return 1; + }; + AbilityCallType callType = AbilityCallType::INVALID_TYPE; + bool res = processor->CallStartAbilityInner(userId, want, callBack, callType); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CallStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CallStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify CallStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, CallStartAbilityInner_002, TestSize.Level1) +{ + auto processor = std::make_shared(); + int32_t userId = 0; + Want want; + ImplicitStartProcessor::StartAbilityClosure callBack = []() -> int32_t { + return 1; + }; + AbilityCallType callType = AbilityCallType::CALL_REQUEST_TYPE; + bool res = processor->CallStartAbilityInner(userId, want, callBack, callType); + EXPECT_NE(res, ERR_OK); +} + +/* + * Feature: ImplicitStartProcessor + * Function: CallStartAbilityInner + * SubFunction: NA + * FunctionPoints:ImplicitStartProcessor CallStartAbilityInner + * EnvConditions: NA + * CaseDescription: Verify CallStartAbilityInner + */ +HWTEST_F(ImplicitStartProcessorTest, CallStartAbilityInner_003, TestSize.Level1) +{ + auto processor = std::make_shared(); + int32_t userId = 0; + Want want; + ImplicitStartProcessor::StartAbilityClosure callBack = []() -> int32_t { + return ERR_OK; + }; + AbilityCallType callType = AbilityCallType::CALL_REQUEST_TYPE; + bool res = processor->CallStartAbilityInner(userId, want, callBack, callType); + EXPECT_EQ(res, ERR_OK); +} +} // namespace AAFwk +} // namespace OHOS diff --git a/test/unittest/pending_want_test/pending_want_test.cpp b/test/unittest/pending_want_test/pending_want_test.cpp index 5b607332c093d4f8faf7c772bfef1f9e01cc4003..431a8cca971c881bbc5e80715c48631703112cfe 100644 --- a/test/unittest/pending_want_test/pending_want_test.cpp +++ b/test/unittest/pending_want_test/pending_want_test.cpp @@ -52,6 +52,7 @@ #include "short_wrapper.h" #include "string_wrapper.h" #include "array_wrapper.h" +#include "hilog_wrapper.h" using namespace testing::ext; using namespace OHOS::AAFwk; @@ -62,6 +63,9 @@ using namespace OHOS::AppExecFwk; using vector_str = std::vector; namespace OHOS::AbilityRuntime::WantAgent { +namespace { + constexpr int32_t NOTEQ = -1; +} class PendingWantTest : public testing::Test { public: PendingWantTest() @@ -950,4 +954,418 @@ HWTEST_F(PendingWantTest, PendingWant_5400, Function | MediumTest | Level1) callBackCancelListenerConnt = 0; } +/* + * @tc.number : PendingWant_5500 + * @tc.name : PendingWant GetAbilitys + * @tc.desc : 1.Get pendingWant (context is nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_5500, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_5500 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + std::shared_ptr want2 = std::make_shared(); + ElementName element2("device", "bundleName", "abilityName"); + want2->SetElement(element2); + std::vector> wants; + wants.emplace_back(want); + wants.emplace_back(want2); + bool value = true; + std::string key = "key"; + std::shared_ptr wParams = std::make_shared(); + wParams->SetParam(key, Boolean::Box(value)); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetAbilities(nullptr, requestCode, wants, flags, wParams, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_5500 end."); +} + +/* + * @tc.number : PendingWant_5600 + * @tc.name : PendingWant GetAbilities + * @tc.desc : 1.Get pendingWant (context is not nullptr FLAG_NO_CREATE) + */ +HWTEST_F(PendingWantTest, PendingWant_5600, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_5600 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + std::shared_ptr want2 = std::make_shared(); + ElementName element2("device", "bundleName", "abilityName"); + want2->SetElement(element2); + std::vector> wants; + wants.emplace_back(want); + wants.emplace_back(want2); + bool value = true; + std::string key = "key"; + std::shared_ptr wParams = std::make_shared(); + wParams->SetParam(key, Boolean::Box(value)); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetAbilities(GetAppContext(), requestCode, wants, flags, wParams, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_5600 end."); +} + +/* + * @tc.number : PendingWant_5700 + * @tc.name : PendingWant GetAbilities + * @tc.desc : 1.Get pendingWant (context is not nullptr FLAG_ONE_SHOT) + */ +HWTEST_F(PendingWantTest, PendingWant_5700, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_5700 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + std::shared_ptr want2 = std::make_shared(); + ElementName element2("device", "bundleName", "abilityName"); + want2->SetElement(element2); + std::vector> wants; + wants.emplace_back(want); + wants.emplace_back(want2); + bool value = true; + std::string key = "key"; + std::shared_ptr wParams = std::make_shared(); + wParams->SetParam(key, Boolean::Box(value)); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetAbilities(GetAppContext(), requestCode, wants, flags, wParams, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_5700 end."); +} + +/* + * @tc.number : PendingWant_5800 + * @tc.name : PendingWant GetAbilitie + * @tc.desc : 1.Get pendingWant (context is nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_5800, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_5800 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + bool value = true; + std::string key = "key"; + std::shared_ptr wParams = std::make_shared(); + wParams->SetParam(key, Boolean::Box(value)); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetAbility(nullptr, requestCode, want, flags, wParams, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_5800 end."); +} + +/* + * @tc.number : PendingWant_5800 + * @tc.name : PendingWant GetAbilitie + * @tc.desc : 1.Get pendingWant (context not nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_5900, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_5900 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + bool value = true; + std::string key = "key"; + std::shared_ptr wParams = std::make_shared(); + wParams->SetParam(key, Boolean::Box(value)); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetAbility(GetAppContext(), requestCode, want, flags, wParams, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_5900 end."); +} + +/* + * @tc.number : PendingWant_6000 + * @tc.name : PendingWant GetCommonEvent + * @tc.desc : 1.Get pendingWant (context is nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6000, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6000 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetCommonEvent(nullptr, requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_6000 end."); +} + +/* + * @tc.number : PendingWant_6100 + * @tc.name : PendingWant GetCommonEvent + * @tc.desc : 1.Get pendingWant (context is not nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6100, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6100 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetCommonEvent(GetAppContext(), requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_6100 end."); +} + +/* + * @tc.number : PendingWant_6200 + * @tc.name : PendingWant GetService + * @tc.desc : 1.Get pendingWant (context is nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6200, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6200 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetService(nullptr, requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_6200 end."); +} + +/* + * @tc.number : PendingWant_6300 + * @tc.name : PendingWant GetService + * @tc.desc : 1.Get pendingWant (context is not nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6300, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6300 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetService(nullptr, requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_6300 end."); +} + +/* + * @tc.number : PendingWant_6400 + * @tc.name : PendingWant GetService + * @tc.desc : 1.Get pendingWant (context is not nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6400, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6400 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetService(GetAppContext(), requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_6400 end."); +} + +/* + * @tc.number : PendingWant_6500 + * @tc.name : PendingWant GetService + * @tc.desc : 1.Get pendingWant (context is not nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6500, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6500 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetForegroundService(GetAppContext(), requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_6500 start."); +} + +/* + * @tc.number : PendingWant_6600 + * @tc.name : PendingWant GetService + * @tc.desc : 1.Get pendingWant (context is nullptr) + */ +HWTEST_F(PendingWantTest, PendingWant_6600, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6600 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_NO_CREATE; + std::shared_ptr pendingWant; + ErrCode err = PendingWant::GetForegroundService(nullptr, requestCode, want, flags, pendingWant); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_PARAMETER); + HILOG_INFO("PendingWant_6500 end."); +} + +/* + * @tc.number : PendingWant_6700 + * @tc.name : PendingWant Cancel + * @tc.desc : Cancel a WantAgent + */ +HWTEST_F(PendingWantTest, PendingWant_6700, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6700 start."); + sptr target = nullptr; + std::shared_ptr pendingWant = std::make_shared(); + ErrCode err = pendingWant->Cancel(target); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT); + HILOG_INFO("PendingWant_6700 end."); +} + +/* + * @tc.number : PendingWant_6800 + * @tc.name : PendingWant IsEquals + * @tc.desc : 1.IsEquals + */ +HWTEST_F(PendingWantTest, PendingWant_6800, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6800 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr pendingWant = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want, flags, type, pendingWant); + + sptr target(nullptr); + std::shared_ptr pendingWant2 = std::make_shared(target); + EXPECT_EQ(pendingWant->IsEquals(pendingWant, pendingWant2), ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT); + HILOG_INFO("PendingWant_6800 end."); +} + +/* + * @tc.number : PendingWant_6900 + * @tc.name : PendingWant IsEquals + * @tc.desc : 1.IsEquals + */ +HWTEST_F(PendingWantTest, PendingWant_6900, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_6900 start."); + int requestCode = 10; + std::shared_ptr want = std::make_shared(); + ElementName element("device", "bundleName", "abilityName"); + want->SetElement(element); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr pendingWant = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want, flags, type, pendingWant); + + std::shared_ptr pendingWant2 = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want, flags, type, pendingWant2); + EXPECT_EQ(pendingWant->IsEquals(pendingWant, pendingWant2), ERR_OK); + HILOG_INFO("PendingWant_6900 end."); +} + +/* + * @tc.number : PendingWant_7000 + * @tc.name : PendingWant IsEquals + * @tc.desc : 1.IsEquals + */ +HWTEST_F(PendingWantTest, PendingWant_7000, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_7000 start."); + int requestCode = 10; + std::shared_ptr want1 = std::make_shared(); + ElementName element1("ohos_device", "bundleName", "abilityName"); + want1->SetElement(element1); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr pendingWant = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want1, flags, type, pendingWant); + + std::shared_ptr want2 = std::make_shared(); + ElementName element2("ohos_device", "ohos_bundleName", "ohos_abilityName"); + want2->SetElement(element2); + std::shared_ptr pendingWant2 = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want2, flags, type, pendingWant2); + EXPECT_EQ(pendingWant->IsEquals(pendingWant, pendingWant2), NOTEQ); + HILOG_INFO("PendingWant_7000 end."); +} + +/* + * @tc.number : PendingWant_7100 + * @tc.name : PendingWant GetBundleName + * @tc.desc : 1.GetBundleName + */ +HWTEST_F(PendingWantTest, PendingWant_7100, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_7100 start."); + PendingWant pendingWant(nullptr); + std::string bundleName; + ErrCode err = pendingWant.GetBundleName(nullptr, bundleName); + EXPECT_EQ(err, ERR_ABILITY_RUNTIME_EXTERNAL_INVALID_WANTAGENT); + HILOG_INFO("PendingWant_7100 end."); +} + +/* + * @tc.number : PendingWant_7200 + * @tc.name : PendingWant GetBundleName + * @tc.desc : 1.GetBundleName + */ +HWTEST_F(PendingWantTest, PendingWant_7200, Function | MediumTest | Level1) +{ + HILOG_INFO("PendingWant_7200 start."); + int requestCode = 10; + std::shared_ptr want1 = std::make_shared(); + ElementName element1("ohos_device", "bundleName", "abilityName"); + want1->SetElement(element1); + unsigned int flags = 1; + flags |= FLAG_ONE_SHOT; + WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + std::shared_ptr context = + std::make_shared(); + std::shared_ptr pendingWant = nullptr; + PendingWant::BuildServicePendingWant(context, requestCode, want1, flags, type, pendingWant); + + std::string bundleName; + ErrCode err = pendingWant->GetBundleName(pendingWant->GetTarget(), bundleName); + EXPECT_EQ(err, ERR_OK); + HILOG_INFO("PendingWant_7200 start."); +} } // namespace OHOS::AbilityRuntime::WantAgent