diff --git a/README_zh.md b/README_zh.md index dff1870de2..f43178e37f 100644 --- a/README_zh.md +++ b/README_zh.md @@ -127,7 +127,7 @@ featureAbility.startAbility( authReadUriPermission: true, // indicates the grant to perform write operations on the URI authWriteUriPermission: true, - // support forward intent result to origin ability + // support forward want result to origin ability abilityForwardResult: true, // used for marking the ability start-up is triggered by continuation abilityContinuation: true, @@ -208,7 +208,7 @@ featureAbility.startAbility( authReadUriPermission: true, // indicates the grant to perform write operations on the URI authWriteUriPermission: true, - // support forward intent result to origin ability + // support forward want result to origin ability abilityForwardResult: true, // used for marking the ability start-up is triggered by continuation abilityContinuation: true, diff --git a/bundle.json b/bundle.json index d53db8f0c4..fc1484c5c0 100644 --- a/bundle.json +++ b/bundle.json @@ -88,17 +88,6 @@ }, "name": "//foundation/aafwk/standard/frameworks/kits/wantagent:wantagent_innerkits" }, - { - "header": { - "header_base": "//foundation/aafwk/standard/interfaces/innerkits/intent/include/", - "header_files": [ - "ohos/aafwk/content/intent.h", - "ohos/aafwk/content/intent_filter.h", - "ohos/aafwk/content/intent_params.h" - ] - }, - "name": "//foundation/aafwk/standard/interfaces/innerkits/intent:intent" - }, { "header": { "header_base": "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", diff --git a/common/task_dispatcher/BUILD.gn b/common/task_dispatcher/BUILD.gn index 6ee102b85d..8ac33fef0d 100644 --- a/common/task_dispatcher/BUILD.gn +++ b/common/task_dispatcher/BUILD.gn @@ -52,11 +52,12 @@ ohos_shared_library("task_dispatcher") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ] + deps = [] external_deps = [ "bundle_framework:appexecfwk_base", "eventhandler:libeventhandler", "hiviewdfx_hilog_native:libhilog", + "utils_base:utils", ] subsystem_name = "aafwk" diff --git a/frameworks/kits/ability/ability_runtime/test/moduletest/BUILD.gn b/frameworks/kits/ability/ability_runtime/test/moduletest/BUILD.gn index cfc37fc7be..70564e8ab7 100644 --- a/frameworks/kits/ability/ability_runtime/test/moduletest/BUILD.gn +++ b/frameworks/kits/ability/ability_runtime/test/moduletest/BUILD.gn @@ -17,8 +17,6 @@ import("//foundation/aafwk/standard/feature.gni") module_output_path = "ability_runtime/ability_call_test" ############################################################################### -#1. intent(c++) get/set test without transport - config("module_private_config") { visibility = [ ":*" ] cflags = [] diff --git a/frameworks/kits/ability/native/BUILD.gn b/frameworks/kits/ability/native/BUILD.gn index b656892554..85eb87fc1e 100644 --- a/frameworks/kits/ability/native/BUILD.gn +++ b/frameworks/kits/ability/native/BUILD.gn @@ -224,7 +224,6 @@ ohos_shared_library("abilitykit_native") { deps = [ ":static_subscriber_ipc", - "${appexecfwk_path}/common:libappexecfwk_common", "${innerkits_path}/dataobs_manager:dataobs_manager", "${kits_path}/appkit:app_context", "${kits_path}/appkit:appkit_delegator", @@ -323,7 +322,7 @@ ohos_shared_library("dummy_classes") { configs = [ ":ability_config" ] public_configs = [ ":ability_public_config" ] - deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ] + deps = [] external_deps = [ "ability_base:want", @@ -344,10 +343,7 @@ ohos_shared_library("service_extension_module") { configs = [ ":ability_config" ] public_configs = [ ":ability_public_config" ] - deps = [ - ":abilitykit_native", - "${appexecfwk_path}/common:libappexecfwk_common", - ] + deps = [ ":abilitykit_native" ] external_deps = [ "ability_base:want", @@ -369,10 +365,7 @@ ohos_shared_library("datashare_ext_ability_module") { configs = [ ":ability_config" ] public_configs = [ ":ability_public_config" ] - deps = [ - ":abilitykit_native", - "${appexecfwk_path}/common:libappexecfwk_common", - ] + deps = [ ":abilitykit_native" ] external_deps = [ "ability_base:want", diff --git a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h index 37f0ed971f..383be48bad 100644 --- a/frameworks/kits/ability/native/include/ability_runtime/js_ability.h +++ b/frameworks/kits/ability/native/include/ability_runtime/js_ability.h @@ -80,7 +80,7 @@ private: JsRuntime &jsRuntime_; std::shared_ptr shellContextRef_; - std::unique_ptr jsAbilityObj_; + std::shared_ptr jsAbilityObj_; sptr remoteCallee_; }; } // namespace AbilityRuntime diff --git a/frameworks/kits/ability/native/include/continuation/remote_register_service/continuation_connector.h b/frameworks/kits/ability/native/include/continuation/remote_register_service/continuation_connector.h index c2768df710..f434fc772b 100644 --- a/frameworks/kits/ability/native/include/continuation/remote_register_service/continuation_connector.h +++ b/frameworks/kits/ability/native/include/continuation/remote_register_service/continuation_connector.h @@ -50,7 +50,7 @@ public: /** * @brief This method is called back to receive the connection result after an ability calls the - * Ability#connectAbility(Intent, IAbilityConnection) method to connect it to a Service ability. + * Ability#connectAbility(Want, IAbilityConnection) method to connect it to a Service ability. * * @param element: Indicates information about the connected Service ability. * @param remote: Indicates the remote proxy object of the Service ability. diff --git a/frameworks/kits/ability/native/src/ability.cpp b/frameworks/kits/ability/native/src/ability.cpp index 466ea33562..73a338ec80 100644 --- a/frameworks/kits/ability/native/src/ability.cpp +++ b/frameworks/kits/ability/native/src/ability.cpp @@ -708,8 +708,8 @@ ErrCode Ability::StartAbilityForResult(const Want &want, int requestCode, Abilit * Starts a new ability with specific start settings. * A Page or Service ability uses this method to start a specific ability. * The system locates the target ability from installed abilities based on - * the value of the intent parameter and then starts it. You can specify the - * ability to start using the intent parameter. + * the value of the want parameter and then starts it. You can specify the + * ability to start using the want parameter. * * @param want Indicates the ability to start. * @param abilityStartSetting Indicates the setting ability used to start. @@ -1633,10 +1633,10 @@ AbilityLifecycleExecutor::LifecycleState Ability::GetState() /** * @brief A Page or Service ability uses this method to start a specific ability. The system locates the target - * ability from installed abilities based on the value of the intent parameter and then starts it. You can specify - * the ability to start using the intent parameter. + * ability from installed abilities based on the value of the want parameter and then starts it. You can specify + * the ability to start using the want parameter. * - * @param intent Indicates the ability to start. + * @param want Indicates the ability to start. * * @return errCode ERR_OK on success, others on failure. */ @@ -1686,7 +1686,7 @@ void Ability::SetMainRoute(const std::string &entry) {} /** - * @brief By binding an action, you can set different action parameters in Intent to present different initial + * @brief By binding an action, you can set different action parameters in Want to present different initial * pages. You must register actions in the profile file. * * @param action Indicates the action to bind. diff --git a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp index 3024f0e780..74e51b1436 100644 --- a/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp +++ b/frameworks/kits/ability/native/src/ability_runtime/js_ability.cpp @@ -560,6 +560,7 @@ std::shared_ptr JsAbility::CreateADelegat property->token_ = GetAbilityContext()->GetToken(); property->name_ = GetAbilityName(); property->lifecycleState_ = GetState(); + property->object_ = jsAbilityObj_; return property; } diff --git a/frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp b/frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp index b2c9f04117..be3d53d17e 100644 --- a/frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp +++ b/frameworks/kits/ability/native/src/continuation/remote_register_service/continuation_connector.cpp @@ -52,7 +52,7 @@ sptr ContinuationConnector::GetInstance(const std::weak_p /** * @brief This method is called back to receive the connection result after an ability calls the - * Ability#connectAbility(Intent, IAbilityConnection) method to connect it to a Service ability. + * Ability#connectAbility(Want, IAbilityConnection) method to connect it to a Service ability. * * @param element: Indicates information about the connected Service ability. * @param remote: Indicates the remote proxy object of the Service ability. diff --git a/frameworks/kits/ability/native/src/data_ability_result.cpp b/frameworks/kits/ability/native/src/data_ability_result.cpp index a78e27fd00..62349376cf 100644 --- a/frameworks/kits/ability/native/src/data_ability_result.cpp +++ b/frameworks/kits/ability/native/src/data_ability_result.cpp @@ -18,7 +18,7 @@ #include #include "hilog_wrapper.h" -#include "parcel_macro.h" +#include "parcel_macro_ability.h" namespace OHOS { namespace AppExecFwk { diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h index 4d3dd09612..1e56e66ca1 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator.h @@ -16,7 +16,9 @@ #ifndef FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H #define FOUNDATION_APPEXECFWK_OHOS_ABILITY_DELEGATOR_H +#include #include +#include #include #include #include @@ -40,58 +42,243 @@ namespace AppExecFwk { class AbilityDelegator : public std::enable_shared_from_this { public: enum class AbilityState : uint8_t { + /** + * Indicates that the ability has not been initialized. + */ UNINITIALIZED = 0, + /** + * Indicates that the ability is in the started state. + */ STARTED, + /** + * Indicates that the ability is in the foreground state. + */ FOREGROUND, + /** + * Indicates that the ability is in the background state. + */ BACKGROUND, + /** + * Indicates that the ability is in the stopped state. + */ STOPPED }; + /** + * Definition of cleanup function. + */ + using ClearFunc = std::function &)>; + public: + /** + * A constructor used to create a AbilityDelegator instance with the input parameter passed. + * + * @param context Indicates the ability runtime context. + * @param runner Indicates the TestRunner object. + * @param observer Indicates the TestObserver object. + */ AbilityDelegator(const std::shared_ptr &context, std::unique_ptr runner, const sptr &observer); + + /** + * Default deconstructor used to deconstruct. + */ ~AbilityDelegator(); + /** + * Adds monitor for monitoring the lifecycle state changes of the ability. + * + * @param monitor, Indicates the monitor object. + */ void AddAbilityMonitor(const std::shared_ptr &monitor); + + /** + * Removes ability monitor. + * + * @param monitor, Indicates the specified monitor object. + */ void RemoveAbilityMonitor(const std::shared_ptr &monitor); + + /** + * Clears all monitors. + */ void ClearAllMonitors(); + + /** + * Obtains the number of monitors. + * + * @return the number of monitors. + */ size_t GetMonitorsNum(); - sptr WaitAbilityMonitor(const std::shared_ptr &monitor); - sptr WaitAbilityMonitor( + /** + * Waits for the specified monitor and return the obtained ability. + * + * @param monitor, Indicates the specified monitor object. + * @return the obtained ability. + */ + std::shared_ptr WaitAbilityMonitor(const std::shared_ptr &monitor); + + /** + * Waits for the specified monitor within the timeout time and return the obtained ability. + * + * @param monitor, Indicates the specified monitor object. + * @param timeoutMs, Indicates the specified time out time, in milliseconds. + * @return the obtained ability. + */ + std::shared_ptr WaitAbilityMonitor( const std::shared_ptr &monitor, const int64_t timeoutMs); + /** + * Obtains the application context. + * + * @return the application context. + */ std::shared_ptr GetAppContext() const; + + /** + * Obtains the lifecycle state of the specified ability. + * + * @param token, Indicates the specified ability. + * @return the lifecycle state of the specified ability. + */ AbilityDelegator::AbilityState GetAbilityState(const sptr &token); - sptr GetCurrentTopAbility(); + + /** + * Obtains the ability that is currently being displayed. + * + * @return the ability that is currently being displayed. + */ + std::shared_ptr GetCurrentTopAbility(); + + /** + * Obtains the name of the thread. + * + * @return the name of the thread. + */ std::string GetThreadName() const; + /** + * Notifies TestRunner to prepare. + */ void Prepare(); + + /** + * Notifies TestRunner to run. + */ void OnRun(); + /** + * Starts an ability based on the given Want. + * + * @param want, Indicates the Want for starting the ability. + * @return the result code. + */ ErrCode StartAbility(const AAFwk::Want &want); + /** + * Transits the specified ability to foreground. + * + * @param token, Indicates the specified ability. + * @return true if succeed; returns false otherwise. + */ bool DoAbilityForeground(const sptr &token); + + /** + * Transits the specified ability to background. + * + * @param token, Indicates the specified ability. + * @return true if succeed; returns false otherwise. + */ bool DoAbilityBackground(const sptr &token); + /** + * Executes the specified shell command. + * + * @param cmd, Indicates the specified shell command. + * @param timeoutSec, Indicates the specified time out time, in seconds. + * @return the result of the specified shell command. + */ std::unique_ptr ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec); + /** + * Prints log information to the console. + * + * @param msg, Indicates the log information to print. + */ void Print(const std::string &msg); + /** + * Saves ability properties when ability is started and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformStart(const std::shared_ptr &ability); + + /** + * Saves ability properties when scence is created and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformScenceCreated(const std::shared_ptr &ability); + + /** + * Saves ability properties when scence is restored and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformScenceRestored(const std::shared_ptr &ability); + + /** + * Saves ability properties when scence is destroyed and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformScenceDestroyed(const std::shared_ptr &ability); + + /** + * Saves ability properties when ability is in the foreground and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformForeground(const std::shared_ptr &ability); + + /** + * Saves ability properties when ability is in the background and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformBackground(const std::shared_ptr &ability); + + /** + * Saves ability properties when ability is stopped and notify monitors of state changes. + * + * @param ability, Indicates the ability properties. + */ void PostPerformStop(const std::shared_ptr &ability); + /** + * Finishes user test. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ void FinishUserTest(const std::string &msg, const int32_t resultCode); + /** + * Registers a function for cleanup. + * + * @param func, Indicates the cleanup function, called when the ability is stopped. + */ + void RegisterClearFunc(ClearFunc func); + private: AbilityDelegator::AbilityState ConvertAbilityState(const AbilityLifecycleExecutor::LifecycleState lifecycleState); void ProcessAbilityProperties(const std::shared_ptr &ability); - std::shared_ptr DoesPropertyExist(const sptr &token); + void RemoveAbilityProperty(const std::shared_ptr &ability); + std::shared_ptr FindPropertyByToken(const sptr &token); + + inline void CallClearFunc(const std::shared_ptr &ability); private: std::shared_ptr appContext_; @@ -102,6 +289,8 @@ private: std::list> abilityProperties_; std::vector> abilityMonitors_; + ClearFunc clearFunc_; + std::mutex mutexMonitor_; std::mutex mutexAbilityProperties_; }; diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h index 930fb46547..0f4f610cdd 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_args.h @@ -25,28 +25,93 @@ namespace OHOS { namespace AppExecFwk { class AbilityDelegatorArgs { public: + /** + * Indicates the key of test bundle name. + */ static const std::string KEY_TEST_BUNDLE_NAME; + /** + * Indicates the key of test package name. + */ static const std::string KEY_TEST_PACKAGE_NAME; + /** + * Indicates the key of test module name. + */ static const std::string KEY_TEST_MODULE_NAME; + /** + * Indicates the key of test runner class name. + */ static const std::string KEY_TEST_RUNNER_CLASS; + /** + * Indicates the key of test case name. + */ static const std::string KEY_TEST_CASE; + /** + * Indicates the key of test wait timeout. + */ static const std::string KEY_TEST_WAIT_TIMEOUT; public: + /** + * Default constructor used to create a AbilityDelegatorArgs instance. + */ AbilityDelegatorArgs(); + + /** + * A constructor used to create a AbilityDelegatorArgs instance with the input parameter passed. + * + * @param want Indicates the Want that contains parameters. + */ explicit AbilityDelegatorArgs(const AAFwk::Want &want); + /** + * Default deconstructor used to deconstruct. + */ ~AbilityDelegatorArgs(); void SetTestBundleName(const std::string &bundleName); + + /** + * Obtains the bundle name of the application being tested. + * + * @return the application bundle name. + */ std::string GetTestBundleName() const; + /** + * Obtains the package name of the application being tested. + * + * @return the application package name. + */ std::string GetTestPackageName() const; + + /** + * Obtains the module name of the application being tested. + * + * @return the application module name. + */ std::string GetTestModuleName() const; + + /** + * Obtains the class name of the test runner used to execute test cases. + * + * @return the class name of the test runner. + */ std::string GetTestRunnerClassName() const; + + /** + * Obtains the test cases name. + * + * @return the test cases name. + */ std::string GetTestCaseName() const; void SetTestParam(const std::map ¶ms); + + /** + * Obtains the test parameters. + * + * @return the test parameters. + */ std::map GetTestParam() const; private: diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h index 24005d7ba9..aa394c67ab 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_infos.h @@ -20,12 +20,19 @@ #include "ability_lifecycle_executor.h" #include "iremote_object.h" +class NativeReference; + namespace OHOS { namespace AppExecFwk { struct ADelegatorAbilityProperty { + // token of ability sptr token_; + // name of ability std::string name_; + // lifecycle state of ability AbilityLifecycleExecutor::LifecycleState lifecycleState_ {AbilityLifecycleExecutor::LifecycleState::UNINITIALIZED}; + // ability object in jsruntime + std::weak_ptr object_; }; } // namespace AppExecFwk } // namespace OHOS diff --git a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h index 87031150b2..5332e5dbdf 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/ability_delegator_registry.h @@ -24,8 +24,27 @@ namespace OHOS { namespace AppExecFwk { class AbilityDelegatorRegistry { public: + /** + * Obtains the AbilityDelegator object of the application. + * + * @return the AbilityDelegator object initialized when the application is started. + */ static std::shared_ptr GetAbilityDelegator(); + + /** + * Obtains test parameters stored in the AbilityDelegatorArgs object. + * + * @return the previously registered AbilityDelegatorArgs object. + */ static std::shared_ptr GetArguments(); + + /** + * Registers the instances of AbilityDelegator and AbilityDelegatorArgs as globally unique instances. + * This method is called during application startup to initialize the test environment. + * + * @param delegator, Indicates the AbilityDelegator object. + * @param args, Indicates the AbilityDelegatorArgs object. + */ static void RegisterInstance( const std::shared_ptr &delegator, const std::shared_ptr &args); diff --git a/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h index 6a530895f6..55e0cffd7a 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/delegator_thread.h @@ -26,13 +26,37 @@ namespace OHOS { namespace AppExecFwk { class DelegatorThread { public: + /** + * Definition of thread task. + */ using DTask = std::function; public: + /** + * A constructor used to create a DelegatorThread instance with the input parameter passed. + * + * @param isMain Indicates whether to use main thread. + */ explicit DelegatorThread(bool isMain = false); + + /** + * Default deconstructor used to deconstruct. + */ ~DelegatorThread() = default; + /** + * Runs specified task. + * + * @param task, Indicates the specified task. + * @return true if succeed, false otherwise. + */ bool Run(const DTask &task); + + /** + * Obtains the name of the thread. + * + * @return the name of the thread. + */ std::string GetThreadName() const; private: diff --git a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h index 8519b1c14c..af5ee49845 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/iability_monitor.h @@ -27,24 +27,89 @@ namespace OHOS { namespace AppExecFwk { class IAbilityMonitor { public: + /** + * Indicates that the default timeout is 5 seconds. + */ static constexpr int64_t MAX_TIME_OUT {5000}; public: + /** + * A constructor used to create a IAbilityMonitor instance with the input parameter passed. + * + * @param abilityName Indicates the specified ability name for monitoring the lifecycle state changes + * of the ability. + */ explicit IAbilityMonitor(const std::string &abilityName); + + /** + * Default deconstructor used to deconstruct. + */ virtual ~IAbilityMonitor() = default; + /** + * Match the monitored Ability objects when newAbility objects are started or + * the lifecycle states of monitored abilities have changed. + * + * @param ability Indicates the ability. + * @param isNotify Indicates whether to notify the matched ability to the object who waited. + * @return true if match is successful; returns false otherwise. + */ virtual bool Match(const std::shared_ptr &ability, bool isNotify = false); + /** + * Waits for and returns the started Ability object that matches the conditions specified in this monitor + * within 5 seconds. + * The current thread will be blocked until the 5-second default timer expires. + * + * @return the Ability object if any object has started is matched within 5 seconds; returns null otherwise. + */ virtual std::shared_ptr WaitForAbility(); + + /** + * Waits for and returns the started Ability object that matches the conditions specified in this monitor + * within the specified time. + * The current thread will be blocked until the timer specified by timeoutMillisecond expires. + * + * @param timeoutMs Indicates the maximum amount of time to wait, in milliseconds. + * The value must be a positive integer. + * @return the Ability object if any object has started is matched within the specified time; + * returns null otherwise. + */ virtual std::shared_ptr WaitForAbility(const int64_t timeoutMs); + /** + * Called when ability is started. + */ virtual void OnAbilityStart(); + + /** + * Called when ability is in foreground. + */ virtual void OnAbilityForeground(); + + /** + * Called when ability is in background. + */ virtual void OnAbilityBackground(); + + /** + * Called when ability is stopped. + */ virtual void OnAbilityStop(); + /** + * Called when window stage is created. + */ virtual void OnWindowStageCreate(); + + /** + * Called when window stage is restored. + */ virtual void OnWindowStageRestore(); + + /** + * Called when window stage is destroyed. + */ virtual void OnWindowStageDestroy(); private: diff --git a/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h b/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h index c784864165..5f9701ac0b 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/runner_runtime/js_test_runner.h @@ -30,12 +30,30 @@ using namespace AbilityRuntime; class JsTestRunner : public TestRunner { public: + /** + * Creates a TestRunner instance with the input parameter passed. + * + * @param runtime Indicates the ability runtime. + * @param args Indicates the AbilityDelegatorArgs object. + * @param bundleInfo Indicates the bundle info. + * @return the TestRunner object if JsTestRunner object is created successfully; returns null otherwise. + */ static std::unique_ptr Create(const std::unique_ptr &runtime, const std::shared_ptr &args, const AppExecFwk::BundleInfo &bundleInfo); + /** + * Default deconstructor used to deconstruct. + */ ~JsTestRunner() override; + /** + * Prepares the testing environment for running test code. + */ void Prepare() override; + + /** + * Runs all test code. + */ void Run() override; private: diff --git a/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h index deda8c7b08..850f0b2665 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/shell_cmd_result.h @@ -23,17 +23,64 @@ namespace OHOS { namespace AppExecFwk { class ShellCmdResult { public: + /** + * Default constructor used to create a ShellCmdResult instance. + */ ShellCmdResult() = default; + + /** + * A constructor used to create a ShellCmdResult instance with the input parameter passed. + * + * @param exitCode Indicates the shell cmd exec result. + * @param stdResult Indicates the cmd standard result. + */ ShellCmdResult(const int32_t exitCode, const std::string &stdResult); + + /** + * Copy constructor used to create a ShellCmdResult instance with the input parameter passed. + * + * @param result Indicates the ShellCommandResult object that already exists. + */ ShellCmdResult(const AAFwk::ShellCommandResult &result); + + /** + * Default deconstructor used to deconstruct. + */ ~ShellCmdResult() = default; + /** + * Sets exit code. + * + * @param exitCode Indicates the exit code. + */ void SetExitCode(const int32_t exitCode); + + /** + * Obtains the exit code. + * + * @return the exit code. + */ int32_t GetExitCode() const; + /** + * Sets standard result. + * + * @param stdResult Indicates the standard result. + */ void SetStdResult(const std::string &stdResult); + + /** + * Obtains the standard result. + * + * @return the standard result. + */ std::string GetStdResult() const; + /** + * Returns a string representation of the object. + * + * @return a string representation of the object. + */ std::string Dump(); private: diff --git a/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h index 502853cf6f..a80c46e8fc 100644 --- a/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h +++ b/frameworks/kits/appkit/native/ability_delegator/include/test_runner.h @@ -27,13 +27,34 @@ class Runtime; namespace AppExecFwk { class TestRunner { public: + /** + * Creates a TestRunner instance with the input parameter passed. + * + * @param runtime Indicates the ability runtime. + * @param args Indicates the AbilityDelegatorArgs object. + * @return the TestRunner object if TestRunner object is created successfully; returns null otherwise. + */ static std::unique_ptr Create( const std::unique_ptr &runtime, const std::shared_ptr &args); + /** + * Default constructor used to create a TestRunner instance. + */ TestRunner() = default; + + /** + * Default deconstructor used to deconstruct. + */ virtual ~TestRunner() = default; + /** + * Prepares the testing environment for running test code. + */ virtual void Prepare(); + + /** + * Runs all test code. + */ virtual void Run(); }; } // namespace AppExecFwk diff --git a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp index a56d4a2917..9ac6fb2663 100644 --- a/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp +++ b/frameworks/kits/appkit/native/ability_delegator/src/ability_delegator.cpp @@ -74,7 +74,8 @@ size_t AbilityDelegator::GetMonitorsNum() return abilityMonitors_.size(); } -sptr AbilityDelegator::WaitAbilityMonitor(const std::shared_ptr &monitor) +std::shared_ptr AbilityDelegator::WaitAbilityMonitor( + const std::shared_ptr &monitor) { if (!monitor) { HILOG_WARN("Invalid input parameter"); @@ -89,10 +90,10 @@ sptr AbilityDelegator::WaitAbilityMonitor(const std::shared_ptrtoken_; + return obtainedAbility; } -sptr AbilityDelegator::WaitAbilityMonitor( +std::shared_ptr AbilityDelegator::WaitAbilityMonitor( const std::shared_ptr &monitor, const int64_t timeoutMs) { if (!monitor) { @@ -108,7 +109,7 @@ sptr AbilityDelegator::WaitAbilityMonitor( return {}; } - return obtainedAbility->token_; + return obtainedAbility; } std::shared_ptr AbilityDelegator::GetAppContext() const @@ -124,7 +125,7 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptr lck(mutexAbilityProperties_); - auto existedProperty = DoesPropertyExist(token); + auto existedProperty = FindPropertyByToken(token); if (!existedProperty) { HILOG_WARN("Unknown ability token"); return AbilityDelegator::AbilityState::UNINITIALIZED; @@ -133,7 +134,7 @@ AbilityDelegator::AbilityState AbilityDelegator::GetAbilityState(const sptrlifecycleState_); } -sptr AbilityDelegator::GetCurrentTopAbility() +std::shared_ptr AbilityDelegator::GetCurrentTopAbility() { sptr topAbilityToken; if (AAFwk::AbilityManagerClient::GetInstance()->GetCurrentTopAbility(topAbilityToken)) { @@ -141,7 +142,14 @@ sptr AbilityDelegator::GetCurrentTopAbility() return {}; } - return topAbilityToken; + std::unique_lock lck(mutexAbilityProperties_); + auto existedProperty = FindPropertyByToken(topAbilityToken); + if (!existedProperty) { + HILOG_WARN("Unknown ability token"); + return {}; + } + + return existedProperty; } std::string AbilityDelegator::GetThreadName() const @@ -455,6 +463,9 @@ void AbilityDelegator::PostPerformStop(const std::shared_ptrOnAbilityStop(); } } + + RemoveAbilityProperty(ability); + CallClearFunc(ability); } AbilityDelegator::AbilityState AbilityDelegator::ConvertAbilityState( @@ -495,7 +506,7 @@ void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptrname_.data(), ability->lifecycleState_); std::unique_lock lck(mutexAbilityProperties_); - auto existedProperty = DoesPropertyExist(ability->token_); + auto existedProperty = FindPropertyByToken(ability->token_); if (existedProperty) { // update existedProperty->lifecycleState_ = ability->lifecycleState_; @@ -505,7 +516,23 @@ void AbilityDelegator::ProcessAbilityProperties(const std::shared_ptr AbilityDelegator::DoesPropertyExist(const sptr &token) +void AbilityDelegator::RemoveAbilityProperty(const std::shared_ptr &ability) +{ + HILOG_INFO("Enter"); + + if (!ability) { + HILOG_WARN("Invalid ability property"); + return; + } + + HILOG_INFO("ability property { name : %{public}s, state : %{public}d }", + ability->name_.data(), ability->lifecycleState_); + + std::unique_lock lck(mutexAbilityProperties_); + abilityProperties_.remove(ability); +} + +std::shared_ptr AbilityDelegator::FindPropertyByToken(const sptr &token) { HILOG_INFO("Enter"); @@ -547,7 +574,26 @@ void AbilityDelegator::FinishUserTest(const std::string &msg, const int32_t resu const auto &bundleName = delegatorArgs->GetTestBundleName(); auto err = AAFwk::AbilityManagerClient::GetInstance()->FinishUserTest(msg, resultCode, bundleName); if (err) { - HILOG_ERROR("MainThread::FinishUserTest is failed %{public}d", err); + HILOG_ERROR("FinishUserTest is failed %{public}d", err); + } +} + +void AbilityDelegator::RegisterClearFunc(ClearFunc func) +{ + HILOG_INFO("Enter"); + if (!func) { + HILOG_ERROR("Invalid func"); + return; + } + + clearFunc_ = func; +} + +inline void AbilityDelegator::CallClearFunc(const std::shared_ptr &ability) +{ + HILOG_INFO("Enter"); + if (clearFunc_) { + clearFunc_(ability); } } } // namespace AppExecFwk diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent.cpp deleted file mode 100644 index 583f818464..0000000000 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent.cpp +++ /dev/null @@ -1,904 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos/aafwk/content/intent.h" -#include "ohos/aafwk/base/array_wrapper.h" -#include "ohos/aafwk/base/base_object.h" -#include "ohos/aafwk/base/bool_wrapper.h" -#include "ohos/aafwk/base/zchar_wrapper.h" -#include "ohos/aafwk/base/byte_wrapper.h" -#include "ohos/aafwk/base/short_wrapper.h" -#include "ohos/aafwk/base/int_wrapper.h" -#include "ohos/aafwk/base/long_wrapper.h" -#include "ohos/aafwk/base/float_wrapper.h" -#include "ohos/aafwk/base/double_wrapper.h" -#include "ohos/aafwk/base/string_wrapper.h" -#include "ohos/aafwk/base/zchar_wrapper.h" -#include "string_ex.h" - -#include -#include - -#include "parcel.h" - -using OHOS::AppExecFwk::ElementName; - -namespace OHOS { -namespace AAFwk { - -const std::string Intent::ACTION_PLAY("action.system.play"); - -const std::string Intent::ENTITY_HOME("entity.system.home"); -const std::string Intent::ENTITY_VIDEO("entity.system.video"); - -const std::string Intent::OCT_EQUALSTO("075"); // '=' -const std::string Intent::OCT_SEMICOLON("073"); // ';' - -static constexpr int HEX_STRING_BUF_LEN = 12; -static constexpr int HEX_STRING_LEN = 10; // "0xffffffff" - -Intent::Intent() : flags_(0) -{} - -std::string Intent::GetAction() const -{ - return action_; -} - -Intent &Intent::SetAction(const std::string &action) -{ - action_ = action; - return *this; -} - -std::string Intent::GetEntity() const -{ - return entity_; -} - -Intent &Intent::SetEntity(const std::string &entity) -{ - entity_ = entity; - return *this; -} - -unsigned int Intent::GetFlags() const -{ - return flags_; -} - -Intent &Intent::SetFlag(const unsigned int flag) -{ - flags_ = flag; - return *this; -} - -Intent &Intent::AddFlag(const unsigned int flag) -{ - flags_ |= flag; - return *this; -} - -void Intent::RemoveFlags(const unsigned int flag) -{ - flags_ &= ~flag; -} - -ElementName Intent::GetElement() const -{ - return element_; -} - -Intent &Intent::SetElement(const ElementName &element) -{ - element_ = element; - return *this; -} - -bool Intent::ParseFlag(const std::string &content, Intent &intent) -{ - std::string contentLower = LowerStr(content); - std::string prefix = "0x"; - if (!contentLower.empty()) { - if (contentLower.find(prefix) != 0) { - return false; - } - - for (std::size_t i = prefix.length(); i < contentLower.length(); i++) { - if (!isxdigit(contentLower[i])) { - return false; - } - } - int base = 16; // hex string - unsigned int flag = (unsigned int)std::stoi(contentLower, nullptr, base); - intent.SetFlag(flag); - } - return true; -} - -std::string Intent::Decode(const std::string &str) -{ - std::string decode; - - for (std::size_t i = 0; i < str.length();) { - if (str[i] == '\\') { - if (++i >= str.length()) { - decode += "\\"; - break; - } - if (str[i] == '\\') { - decode += "\\"; - i++; - } else if (str[i] == '0') { - if (str.compare(i, OCT_EQUALSTO.length(), OCT_EQUALSTO) == 0) { - decode += "="; - i += OCT_EQUALSTO.length(); - } else if (str.compare(i, OCT_SEMICOLON.length(), OCT_SEMICOLON) == 0) { - decode += ";"; - i += OCT_SEMICOLON.length(); - } else { - decode += "\\" + str.substr(i, 1); - i++; - } - } else { - decode += "\\" + str.substr(i, 1); - i++; - } - } else { - decode += str[i]; - i++; - } - } - - return decode; -} - -std::string Intent::Encode(const std::string &str) -{ - std::string encode; - - for (std::size_t i = 0; i < str.length(); i++) { - if (str[i] == '\\') { - encode += "\\\\"; - } else if (str[i] == '=') { - encode += "\\" + OCT_EQUALSTO; - } else if (str[i] == ';') { - encode += "\\" + OCT_SEMICOLON; - } else { - encode += str[i]; - } - } - - return encode; -} - -bool Intent::ParseContent(const std::string &content, std::string &prop, std::string &value) -{ - std::string subString; - std::size_t pos = content.find("="); - if (pos != std::string::npos) { - subString = content.substr(0, pos); - prop = Decode(subString); - subString = content.substr(pos + 1, content.length() - pos - 1); - value = Decode(subString); - return true; - } - return false; -} - -bool Intent::ParseUriInternal(const std::string &content, ElementName &element, Intent &intent) -{ - static constexpr int TYPE_TAG_SIZE = 2; - - std::string prop; - std::string value; - - if (content.empty() || content[0] == '=') { - return true; - } - - if (!ParseContent(content, prop, value)) { - return false; - } - - if (value.empty()) { - return true; - } - - if (prop == "action") { - intent.SetAction(value); - } else if (prop == "entity") { - intent.SetEntity(value); - } else if (prop == "flag") { - if (!ParseFlag(value, intent)) { - return false; - } - } else if (prop == "device") { - element.SetDeviceID(value); - } else if (prop == "bundle") { - element.SetBundleName(value); - } else if (prop == "ability") { - element.SetAbilityName(value); - } else if (prop.length() > TYPE_TAG_SIZE) { - std::string key = prop.substr(TYPE_TAG_SIZE); - if (prop[0] == String::SIGNATURE && prop[1] == '.') { - sptr valueObj = String::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Boolean::SIGNATURE && prop[1] == '.') { - sptr valueObj = Boolean::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Char::SIGNATURE && prop[1] == '.') { - sptr valueObj = Char::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Byte::SIGNATURE && prop[1] == '.') { - sptr valueObj = Byte::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Short::SIGNATURE && prop[1] == '.') { - sptr valueObj = Short::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Integer::SIGNATURE && prop[1] == '.') { - sptr valueObj = Integer::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Long::SIGNATURE && prop[1] == '.') { - sptr valueObj = Long::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Float::SIGNATURE && prop[1] == '.') { - sptr valueObj = Float::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Double::SIGNATURE && prop[1] == '.') { - sptr valueObj = Double::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } else if (prop[0] == Array::SIGNATURE && prop[1] == '.') { - sptr valueObj = Array::Parse(value); - if (valueObj == nullptr) { - return false; - } - intent.parameters_.SetParam(key, valueObj); - } - } - - return true; -} - -Intent *Intent::ParseUri(const std::string &uri) -{ - if (uri.length() <= 0) { - return nullptr; - } - - std::string head = "#Intent;"; - std::string end = ";end"; - - if (uri.find(head) != 0) { - return nullptr; - } - - if (uri.rfind(end) != (uri.length() - end.length())) { - return nullptr; - } - - bool ret = true; - std::string content; - std::size_t pos; - std::size_t begin = head.length(); - ElementName element; - Intent *intent = new Intent(); - - pos = uri.find_first_of(";", begin); - do { - if (pos != std::string::npos) { - content = uri.substr(begin, pos - begin); - ret = ParseUriInternal(content, element, *intent); - if (!ret) { - break; - } - begin = pos + 1; - pos = uri.find(";", begin); - if (pos == std::string::npos) { - break; - } - } else { - break; - } - } while (true); - - if (ret) { - intent->SetElement(element); - } else { - delete intent; - intent = nullptr; - } - - return intent; -} - -std::string Intent::ToUri() -{ - std::string uriString = "#Intent;"; - - if (action_.length() > 0) { - uriString += "action=" + Encode(action_) + ";"; - } - - if (entity_.length() > 0) { - uriString += "entity=" + Encode(entity_) + ";"; - } - - if (flags_ != 0) { - uriString += "flag="; - char buf[HEX_STRING_BUF_LEN]; - int len = snprintf_s(buf, sizeof(buf), HEX_STRING_LEN, "0x%08x", flags_); - if (len == HEX_STRING_LEN) { - std::string flag = buf; - uriString += Encode(flag); - uriString += ";"; - } - } - - std::string device = element_.GetDeviceID(); - if (device.length() > 0) { - uriString += "device=" + Encode(device) + ";"; - } - - std::string bundle = element_.GetBundleName(); - if (bundle.length() > 0) { - uriString += "bundle=" + Encode(bundle) + ";"; - } - - std::string ability = element_.GetAbilityName(); - if (ability.length() > 0) { - uriString += "ability=" + Encode(ability) + ";"; - } - - auto params = parameters_.GetParams(); - auto iter = params.cbegin(); - while (iter != params.cend()) { - sptr o = iter->second; - if (IString::Query(o) != nullptr) { - uriString += String::SIGNATURE; - } else if (IBoolean::Query(o) != nullptr) { - uriString += Boolean::SIGNATURE; - } else if (IChar::Query(o) != nullptr) { - uriString += Char::SIGNATURE; - } else if (IByte::Query(o) != nullptr) { - uriString += Byte::SIGNATURE; - } else if (IShort::Query(o) != nullptr) { - uriString += Short::SIGNATURE; - } else if (IInteger::Query(o) != nullptr) { - uriString += Integer::SIGNATURE; - } else if (ILong::Query(o) != nullptr) { - uriString += Long::SIGNATURE; - } else if (IFloat::Query(o) != nullptr) { - uriString += Float::SIGNATURE; - } else if (IDouble::Query(o) != nullptr) { - uriString += Double::SIGNATURE; - } else if (IArray::Query(o) != nullptr) { - uriString += Array::SIGNATURE; - } - uriString += "." + Encode(iter->first) + "=" + Encode(Object::ToString(*(o.GetRefPtr()))) + ";"; - iter++; - } - - uriString += "end"; - - return uriString; -} - -/* - * Intent format in Parcel. Java side should keep consistent. - * +----------+----+-----+------+-------+----+-----------+---- - * | Action | E1 | Uri | Type | Flags | E2 | Category1 | ... - * +----------+----+-----+------+-------+----+-----------+---- - * ----+-----------+---------+----+---------+----+------------+ - * ... | CategoryN | Package | E3 | Element | E4 | Parameters | - * ----+-----------+---------+----+---------+----+------------+ - * E1: If -1, no Uri after it. - * E2: Category count. If -1, no Category after it. - * E3: if -1, no element after it. - * E4: if -1, no parameters after it. - */ -bool Intent::Marshalling(Parcel &parcel) const -{ - // write action - if (!parcel.WriteString16(Str8ToStr16(action_))) { - return false; - } - - // write entity - if (!parcel.WriteString16(Str8ToStr16(entity_))) { - return false; - } - - // write flags - if (!parcel.WriteUint32(flags_)) { - return false; - } - - // write element - ElementName emptyElement; - if (element_ == emptyElement) { - if (!parcel.WriteInt32(VALUE_NULL)) { - return false; - } - } else { - if (!parcel.WriteInt32(VALUE_OBJECT)) { - return false; - } - if (!parcel.WriteParcelable(&element_)) { - return false; - } - } - - // write parameters - if (parameters_.GetParams().size() == 0) { - if (!parcel.WriteInt32(VALUE_NULL)) { - return false; - } - } else { - if (!parcel.WriteInt32(VALUE_OBJECT)) { - return false; - } - if (!parcel.WriteParcelable(¶meters_)) { - return false; - } - } - - return true; -} - -bool Intent::ReadFromParcel(Parcel &parcel) -{ - // read action - action_ = Str16ToStr8(parcel.ReadString16()); - - // read entity - entity_ = Str16ToStr8(parcel.ReadString16()); - - // read flags - if (!parcel.ReadUint32(flags_)) { - return false; - } - - int empty; - // read element - empty = VALUE_NULL; - if (!parcel.ReadInt32(empty)) { - return false; - } - - if (empty == VALUE_OBJECT) { - auto element = parcel.ReadParcelable(); - if (element != nullptr) { - element_ = *element; - delete element; - } else { - return false; - } - } - - // read parameters - empty = VALUE_NULL; - if (!parcel.ReadInt32(empty)) { - return false; - } - - if (empty == VALUE_OBJECT) { - auto params = parcel.ReadParcelable(); - if (params != nullptr) { - parameters_ = *params; - delete params; - } else { - return false; - } - } - - return true; -} - -Intent *Intent::Unmarshalling(Parcel &parcel) -{ - Intent *intent = new Intent(); - if (intent && !intent->ReadFromParcel(parcel)) { - delete intent; - intent = nullptr; - } - return intent; -} - -bool Intent::HasParameter(const std::string &key) const -{ - return parameters_.HasParam(key); -} - -bool Intent::GetBoolParam(const std::string &key, const bool defaultValue) -{ - auto value = parameters_.GetParam(key); - IBoolean *bo = IBoolean::Query(value); - if (bo != nullptr) { - return Boolean::Unbox(bo); - } - return defaultValue; -} - -Intent &Intent::SetBoolParam(const std::string &key, const bool value) -{ - parameters_.SetParam(key, Boolean::Box(value)); - return *this; -} - -std::vector Intent::GetBoolArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsBooleanArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Boolean::Unbox(IBoolean::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetBoolArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IBoolean); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Boolean::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -Intent &Intent::SetCharParam(const std::string &key, const zchar value) -{ - parameters_.SetParam(key, Char::Box(value)); - return *this; -} - -Intent &Intent::SetCharArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IChar); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Char::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -zchar Intent::GetCharParam(const std::string &key, const zchar defaultValue) -{ - auto value = parameters_.GetParam(key); - IChar *co = IChar::Query(value); - if (co != nullptr) { - return Char::Unbox(co); - } - return defaultValue; -} - -std::vector Intent::GetCharArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsCharArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Char::Unbox(IChar::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetByteParam(const std::string &key, const byte value) -{ - parameters_.SetParam(key, Byte::Box(value)); - return *this; -} - -Intent &Intent::SetByteArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IByte); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Byte::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -byte Intent::GetByteParam(const std::string &key, const byte defaultValue) -{ - auto value = parameters_.GetParam(key); - IByte *bo = IByte::Query(value); - if (bo != nullptr) { - return Byte::Unbox(bo); - } - return defaultValue; -} - -std::vector Intent::GetByteArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsByteArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Byte::Unbox(IByte::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetShortParam(const std::string &key, const short value) -{ - parameters_.SetParam(key, Short::Box(value)); - return *this; -} - -Intent &Intent::SetShortArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IShort); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Short::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -short Intent::GetShortParam(const std::string &key, const short defaultValue) -{ - auto value = parameters_.GetParam(key); - IShort *so = IShort::Query(value); - if (so != nullptr) { - return Short::Unbox(so); - } - return defaultValue; -} - -std::vector Intent::GetShortArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsShortArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Short::Unbox(IShort::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetIntParam(const std::string &key, const int value) -{ - parameters_.SetParam(key, Integer::Box(value)); - return *this; -} - -Intent &Intent::SetIntArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IInteger); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Integer::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -int Intent::GetIntParam(const std::string &key, const int defaultValue) -{ - auto value = parameters_.GetParam(key); - IInteger *io = IInteger::Query(value); - if (io != nullptr) { - return Integer::Unbox(io); - } - return defaultValue; -} - -std::vector Intent::GetIntArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsIntegerArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Integer::Unbox(IInteger::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -long Intent::GetLongParam(const std::string &key, const long defaultValue) -{ - auto value = parameters_.GetParam(key); - ILong *lo = ILong::Query(value); - if (lo != nullptr) { - return Long::Unbox(lo); - } - return defaultValue; -} - -Intent &Intent::SetLongParam(const std::string &key, const long value) -{ - parameters_.SetParam(key, Long::Box(value)); - return *this; -} - -std::vector Intent::GetLongArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsLongArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Long::Unbox(ILong::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetLongArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_ILong); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Long::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -float Intent::GetFloatParam(const std::string &key, const float defaultValue) -{ - auto value = parameters_.GetParam(key); - IFloat *of = IFloat::Query(value); - if (of != nullptr) { - return Float::Unbox(of); - } - return defaultValue; -} - -Intent &Intent::SetFloatParam(const std::string &key, const float value) -{ - parameters_.SetParam(key, Float::Box(value)); - return *this; -} - -std::vector Intent::GetFloatArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsFloatArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Float::Unbox(IFloat::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetFloatArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IFloat); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Float::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -double Intent::GetDoubleParam(const std::string &key, const double defaultValue) -{ - auto value = parameters_.GetParam(key); - IDouble *dbo = IDouble::Query(value); - if (dbo != nullptr) { - return Double::Unbox(dbo); - } - return defaultValue; -} - -Intent &Intent::SetDoubleParam(const std::string &key, const double value) -{ - parameters_.SetParam(key, Double::Box(value)); - return *this; -} - -std::vector Intent::GetDoubleArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsDoubleArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(Double::Unbox(IDouble::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetDoubleArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IDouble); - for (size_t i = 0; i < size; i++) { - ao->Set(i, Double::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -std::string Intent::GetStringParam(const std::string &key) -{ - auto value = parameters_.GetParam(key); - IString *so = IString::Query(value); - if (so != nullptr) { - return String::Unbox(so); - } - return std::string(); -} - -Intent &Intent::SetStringParam(const std::string &key, const std::string &value) -{ - parameters_.SetParam(key, String::Box(value)); - return *this; -} - -std::vector Intent::GetStringArrayParam(const std::string &key) -{ - std::vector array; - auto value = parameters_.GetParam(key); - IArray *ao = IArray::Query(value); - if (ao != nullptr && Array::IsStringArray(ao)) { - auto func = [&](IInterface *object) { array.push_back(String::Unbox(IString::Query(object))); }; - Array::ForEach(ao, func); - } - return array; -} - -Intent &Intent::SetStringArrayParam(const std::string &key, const std::vector &value) -{ - size_t size = value.size(); - sptr ao = new Array(size, g_IID_IString); - for (size_t i = 0; i < size; i++) { - ao->Set(i, String::Box(value[i])); - } - parameters_.SetParam(key, ao); - return *this; -} - -} // namespace AAFwk -} // namespace OHOS diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_filter.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_filter.cpp deleted file mode 100644 index a4fd05cf0c..0000000000 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_filter.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * 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 "ohos/aafwk/content/intent_filter.h" - -#include "string_ex.h" -#include "ohos/aafwk/content/intent.h" - -namespace OHOS { -namespace AAFwk { - -IntentFilter::IntentFilter() -{} - -std::string IntentFilter::GetEntity() const -{ - return entity_; -} - -void IntentFilter::SetEntity(const std::string &entity) -{ - entity_ = entity; -} - -void IntentFilter::AddAction(const std::string &action) -{ - auto it = std::find(actions_.cbegin(), actions_.cend(), action); - if (it == actions_.cend()) { - actions_.push_back(action); - } -} - -int IntentFilter::CountAction() const -{ - return actions_.size(); -} - -std::string IntentFilter::GetAction(int index) const -{ - std::string action; - if (index < static_cast(actions_.size())) { - action = actions_[index]; - } - return action; -} - -void IntentFilter::RemoveAction(const std::string &action) -{ - auto it = std::find(actions_.cbegin(), actions_.cend(), action); - if (it != actions_.cend()) { - actions_.erase(it); - } -} - -bool IntentFilter::HasAction(const std::string &action) const -{ - return std::find(actions_.cbegin(), actions_.cend(), action) != actions_.cend(); -} - -bool IntentFilter::Marshalling(Parcel &parcel) const -{ - // write entity - if (!parcel.WriteString16(Str8ToStr16(entity_))) { - return false; - } - - // write actions - std::vector actionU16; - for (std::vector::size_type i = 0; i < actions_.size(); i++) { - actionU16.push_back(Str8ToStr16(actions_[i])); - } - - return parcel.WriteString16Vector(actionU16); -} - -bool IntentFilter::ReadFromParcel(Parcel &parcel) -{ - // read entity - entity_ = Str16ToStr8(parcel.ReadString16()); - - // read actions - std::vector actionU16; - if (!parcel.ReadString16Vector(&actionU16)) { - return false; - } - - actions_.clear(); - for (std::vector::size_type i = 0; i < actionU16.size(); i++) { - actions_.push_back(Str16ToStr8(actionU16[i])); - } - - return true; -} - -IntentFilter *IntentFilter::Unmarshalling(Parcel &parcel) -{ - IntentFilter *filter = new (std::nothrow) IntentFilter(); - if (filter && !filter->ReadFromParcel(parcel)) { - delete filter; - filter = nullptr; - } - return filter; -} - -bool IntentFilter::MatchAction(const std::string &action) const -{ - return HasAction(action); -} - -bool IntentFilter::MatchEntity(const std::string &entity) const -{ - return entity_ == entity; -} - -bool IntentFilter::Match(const Intent &intent) const -{ - return MatchAction(intent.GetAction()) && MatchEntity(intent.GetEntity()); -} - -} // namespace AAFwk -} // namespace OHOS diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_params.cpp deleted file mode 100644 index e1cb9682b7..0000000000 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/intent_params.cpp +++ /dev/null @@ -1,481 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos/aafwk/content/intent_params.h" - -#include "ohos/aafwk/base/array_wrapper.h" -#include "ohos/aafwk/base/base_object.h" -#include "ohos/aafwk/base/bool_wrapper.h" -#include "ohos/aafwk/base/byte_wrapper.h" -#include "ohos/aafwk/base/short_wrapper.h" -#include "ohos/aafwk/base/int_wrapper.h" -#include "ohos/aafwk/base/long_wrapper.h" -#include "ohos/aafwk/base/float_wrapper.h" -#include "ohos/aafwk/base/double_wrapper.h" -#include "ohos/aafwk/base/string_wrapper.h" -#include "ohos/aafwk/base/zchar_wrapper.h" - -#include "parcel.h" -#include "string_ex.h" - -namespace OHOS { -namespace AAFwk { - -void IntentParams::SetParam(const std::string &key, IInterface *value) -{ - params_[key] = value; -} - -sptr IntentParams::GetParam(const std::string &key) const -{ - auto it = params_.find(key); - if (it == params_.cend()) { - return nullptr; - } - return it->second; -} - -const std::map> &IntentParams::GetParams() const -{ - return params_; -} - -bool IntentParams::HasParam(const std::string &key) const -{ - return params_.count(key) > 0; -} - -template -static void FillArray(IArray *ao, std::vector &array) -{ - auto func = [&](IInterface *object) { array.push_back(T2::Unbox(T3::Query(object))); }; - Array::ForEach(ao, func); -} - -bool IntentParams::WriteArrayToParcel(Parcel &parcel, IArray *ao) const -{ - if (Array::IsStringArray(ao)) { - std::vector array; - auto func = [&](IInterface *object) { - std::string s = String::Unbox(IString::Query(object)); - array.push_back(Str8ToStr16(s)); - }; - Array::ForEach(ao, func); - if (!parcel.WriteInt32(VALUE_TYPE_STRINGARRAY)) { - return false; - } - if (!parcel.WriteString16Vector(array)) { - return false; - } - } else if (Array::IsBooleanArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_BOOLEANARRAY)) { - return false; - } - if (!parcel.WriteInt8Vector(array)) { - return false; - } - } else if (Array::IsByteArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_BYTEARRAY)) { - return false; - } - if (!parcel.WriteInt8Vector(array)) { - return false; - } - } else if (Array::IsCharArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_CHARARRAY)) { - return false; - } - if (!parcel.WriteInt32Vector(array)) { - return false; - } - } else if (Array::IsShortArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_SHORTARRAY)) { - return false; - } - if (!parcel.WriteInt16Vector(array)) { - return false; - } - } else if (Array::IsIntegerArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_INTARRAY)) { - return false; - } - if (!parcel.WriteInt32Vector(array)) { - return false; - } - } else if (Array::IsLongArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_LONGARRAY)) { - return false; - } - if (!parcel.WriteInt64Vector(array)) { - return false; - } - } else if (Array::IsFloatArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_FLOATARRAY)) { - return false; - } - if (!parcel.WriteFloatVector(array)) { - return false; - } - } else if (Array::IsDoubleArray(ao)) { - std::vector array; - FillArray(ao, array); - if (!parcel.WriteInt32(VALUE_TYPE_DOUBLEARRAY)) { - return false; - } - if (!parcel.WriteDoubleVector(array)) { - return false; - } - } - - return true; -} - -bool IntentParams::Marshalling(Parcel &parcel) const -{ - size_t size = params_.size(); - - if (!parcel.WriteInt32(size)) { - return false; - } - - auto iter = params_.cbegin(); - while (iter != params_.cend()) { - std::string key = iter->first; - sptr o = iter->second; - if (!parcel.WriteString16(Str8ToStr16(key))) { - return false; - } - if (IString::Query(o) != nullptr) { - std::string value = String::Unbox(IString::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_STRING)) { - return false; - } - if (!parcel.WriteString16(Str8ToStr16(value))) { - return false; - } - } else if (IBoolean::Query(o) != nullptr) { - bool value = Boolean::Unbox(IBoolean::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_BOOLEAN)) { - return false; - } - if (!parcel.WriteInt8(value)) { - return false; - } - } else if (IByte::Query(o) != nullptr) { - byte value = Byte::Unbox(IByte::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_BYTE)) { - return false; - } - if (!parcel.WriteInt8(value)) { - return false; - } - } else if (IChar::Query(o) != nullptr) { - zchar value = Char::Unbox(IChar::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_CHAR)) { - return false; - } - if (!parcel.WriteInt32(value)) { - return false; - } - } else if (IShort::Query(o) != nullptr) { - short value = Short::Unbox(IShort::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_SHORT)) { - return false; - } - if (!parcel.WriteInt16(value)) { - return false; - } - } else if (IInteger::Query(o) != nullptr) { - int value = Integer::Unbox(IInteger::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_INT)) { - return false; - } - if (!parcel.WriteInt32(value)) { - return false; - } - } else if (ILong::Query(o) != nullptr) { - long value = Long::Unbox(ILong::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_LONG)) { - return false; - } - if (!parcel.WriteInt64(value)) { - return false; - } - } else if (IFloat::Query(o) != nullptr) { - float value = Float::Unbox(IFloat::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_FLOAT)) { - return false; - } - if (!parcel.WriteFloat(value)) { - return false; - } - } else if (IDouble::Query(o) != nullptr) { - double value = Double::Unbox(IDouble::Query(o)); - if (!parcel.WriteInt32(VALUE_TYPE_DOUBLE)) { - return false; - } - if (!parcel.WriteDouble(value)) { - return false; - } - } else { - IArray *ao = IArray::Query(o); - if (ao != nullptr && !WriteArrayToParcel(parcel, ao)) { - return false; - } - } - iter++; - } - - return true; -} - -template -static void SetArray(const InterfaceID &id, const std::vector &value, sptr &ao) -{ - typename std::vector::size_type size = value.size(); - ao = new (std::nothrow) Array(size, id); - if (ao == nullptr) { - return; - } - for (typename std::vector::size_type i = 0; i < size; i++) { - ao->Set(i, T2::Box(value[i])); - } -} - -bool IntentParams::ReadArrayToParcel(Parcel &parcel, int type, sptr &ao) -{ - switch (type) { - case VALUE_TYPE_STRINGARRAY: { - std::vector value; - if (!parcel.ReadString16Vector(&value)) { - return false; - } - std::vector::size_type size = value.size(); - ao = new (std::nothrow) Array(size, g_IID_IString); - if (ao == nullptr) { - return false; - } - for (std::vector::size_type i = 0; i < size; i++) { - ao->Set(i, String::Box(Str16ToStr8(value[i]))); - } - break; - } - case VALUE_TYPE_BOOLEANARRAY: { - std::vector value; - if (!parcel.ReadInt8Vector(&value)) { - return false; - } - SetArray(g_IID_IBoolean, value, ao); - break; - } - case VALUE_TYPE_BYTEARRAY: { - std::vector value; - if (!parcel.ReadInt8Vector(&value)) { - return false; - } - SetArray(g_IID_IByte, value, ao); - break; - } - case VALUE_TYPE_CHARARRAY: { - std::vector value; - if (!parcel.ReadInt32Vector(&value)) { - return false; - } - SetArray(g_IID_IChar, value, ao); - break; - } - case VALUE_TYPE_SHORTARRAY: { - std::vector value; - if (!parcel.ReadInt16Vector(&value)) { - return false; - } - SetArray(g_IID_IShort, value, ao); - break; - } - case VALUE_TYPE_INTARRAY: { - std::vector value; - if (!parcel.ReadInt32Vector(&value)) { - return false; - } - SetArray(g_IID_IInteger, value, ao); - break; - } - case VALUE_TYPE_LONGARRAY: { - std::vector value; - if (!parcel.ReadInt64Vector(&value)) { - return false; - } - SetArray(g_IID_ILong, value, ao); - break; - } - case VALUE_TYPE_FLOATARRAY: { - std::vector value; - if (!parcel.ReadFloatVector(&value)) { - return false; - } - SetArray(g_IID_IFloat, value, ao); - break; - } - case VALUE_TYPE_DOUBLEARRAY: { - std::vector value; - if (!parcel.ReadDoubleVector(&value)) { - return false; - } - SetArray(g_IID_IDouble, value, ao); - break; - } - default: - // ignore - ; - } - - return true; -} - -bool IntentParams::ReadFromParcel(Parcel &parcel) -{ - int32_t size; - - if (!parcel.ReadInt32(size)) { - return false; - } - - for (int32_t i = 0; i < size; i++) { - std::u16string key; - key = parcel.ReadString16(); - - sptr intf = nullptr; - int type; - if (!parcel.ReadInt32(type)) { - return false; - } - - switch (type) { - case VALUE_TYPE_STRING: { - std::u16string value = parcel.ReadString16(); - intf = String::Box(Str16ToStr8(value)); - break; - } - case VALUE_TYPE_BOOLEAN: { - int8_t value; - if (!parcel.ReadInt8(value)) { - return false; - } - intf = Boolean::Box(value); - break; - } - case VALUE_TYPE_BYTE: { - int8_t value; - if (!parcel.ReadInt8(value)) { - return false; - } - intf = Byte::Box(value); - break; - } - case VALUE_TYPE_CHAR: { - int32_t value; - if (!parcel.ReadInt32(value)) { - return false; - } - intf = Char::Box(value); - break; - } - case VALUE_TYPE_SHORT: { - short value; - if (!parcel.ReadInt16(value)) { - return false; - } - intf = Short::Box(value); - break; - } - case VALUE_TYPE_INT: { - int value; - if (!parcel.ReadInt32(value)) { - return false; - } - intf = Integer::Box(value); - break; - } - case VALUE_TYPE_LONG: { - int64_t value; - if (!parcel.ReadInt64(value)) { - return false; - } - intf = Long::Box(value); - break; - } - case VALUE_TYPE_FLOAT: { - float value; - if (!parcel.ReadFloat(value)) { - return false; - } - intf = Float::Box(value); - break; - } - case VALUE_TYPE_DOUBLE: { - double value; - if (!parcel.ReadDouble(value)) { - return false; - } - intf = Double::Box(value); - break; - } - case VALUE_TYPE_NULL: - break; - default: { - // handle array - sptr ao = nullptr; - if (!ReadArrayToParcel(parcel, type, ao)) { - return false; - } - intf = ao; - break; - } - } - - if (intf) { - SetParam(Str16ToStr8(key), intf); - } - } - - return true; -} - -IntentParams *IntentParams::Unmarshalling(Parcel &parcel) -{ - IntentParams *intentParams = new (std::nothrow) IntentParams(); - if (intentParams && !intentParams->ReadFromParcel(parcel)) { - delete intentParams; - intentParams = nullptr; - } - return intentParams; -} - -} // namespace AAFwk -} // namespace OHOS diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp index 8b42a36ff4..a1cfcd6fe0 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp @@ -455,7 +455,7 @@ Want &Want::SetParams(const WantParams &wantParams) /** * @description: Obtains a bool-type value matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @param defaultValue Indicates the default bool-type value. * @return Returns the bool-type value of the parameter matching the given key; * returns the default value if the key does not exist. @@ -472,7 +472,7 @@ bool Want::GetBoolParam(const std::string &key, bool defaultValue) const /** * @description:Obtains a bool-type array matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @return Returns the bool-type array of the parameter matching the given key; * returns null if the key does not exist. */ @@ -530,7 +530,7 @@ Want &Want::SetParam(const std::string &key, const std::vector &value) /** * @description: Obtains a byte-type value matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @param defaultValue Indicates the default byte-type value. * @return Returns the byte-type value of the parameter matching the given key; * returns the default value if the key does not exist. @@ -547,7 +547,7 @@ byte Want::GetByteParam(const std::string &key, const byte defaultValue) const /** * @description: Obtains a byte-type array matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @return Returns the byte-type array of the parameter matching the given key; * returns null if the key does not exist. */ @@ -574,7 +574,7 @@ std::vector Want::GetByteArrayParam(const std::string &key) const * @description: Sets a parameter value of the byte type. * @param key Indicates the key matching the parameter. * @param value Indicates the byte-type value of the parameter. - * @return Returns this Intent object containing the parameter value. + * @return Returns this Want object containing the parameter value. */ Want &Want::SetParam(const std::string &key, byte value) { @@ -586,7 +586,7 @@ Want &Want::SetParam(const std::string &key, byte value) * @description: Sets a parameter value of the byte array type. * @param key Indicates the key matching the parameter. * @param value Indicates the byte array of the parameter. - * @return Returns this Intent object containing the parameter value. + * @return Returns this Want object containing the parameter value. */ Want &Want::SetParam(const std::string &key, const std::vector &value) { @@ -722,7 +722,7 @@ std::vector Want::GetIntArrayParam(const std::string &key) const * @description: Sets a parameter value of the int type. * @param key Indicates the key matching the parameter. * @param value Indicates the int value of the parameter. - * @return Returns this Intent object containing the parameter value. + * @return Returns this Want object containing the parameter value. */ Want &Want::SetParam(const std::string &key, int value) { @@ -734,7 +734,7 @@ Want &Want::SetParam(const std::string &key, int value) * @description: Sets a parameter value of the int array type. * @param key Indicates the key matching the parameter. * @param value Indicates the int array of the parameter. - * @return Returns this Intent object containing the parameter value. + * @return Returns this Want object containing the parameter value. */ Want &Want::SetParam(const std::string &key, const std::vector &value) { @@ -769,7 +769,7 @@ double Want::GetDoubleParam(const std::string &key, double defaultValue) const /** * @description: Obtains a double array matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @return Returns the double array of the parameter matching the given key; * returns null if the key does not exist. */ @@ -796,7 +796,7 @@ std::vector Want::GetDoubleArrayParam(const std::string &key) const * @description: Sets a parameter value of the double type. * @param key Indicates the key matching the parameter. * @param value Indicates the int value of the parameter. - * @return Returns this Intent object containing the parameter value. + * @return Returns this Want object containing the parameter value. */ Want &Want::SetParam(const std::string &key, double value) { @@ -843,7 +843,7 @@ float Want::GetFloatParam(const std::string &key, float defaultValue) const /** * @description: Obtains a float array matching the given key. - * @param key Indicates the key of IntentParams. + * @param key Indicates the key of WantParams. * @return Obtains a float array matching the given key. */ std::vector Want::GetFloatArrayParam(const std::string &key) const diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp index a8ede8dc7c..6fcfc9fd4f 100644 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want_params.cpp @@ -136,9 +136,9 @@ std::string WantParams::GetStringByType(const sptr iIt, int typeId) template static void SetNewArray(const AAFwk::InterfaceID &id, AAFwk::IArray *orgIArray, sptr &ao); /** - * @description: A constructor used to create an IntentParams instance by using the parameters of an existing - * IntentParams object. - * @param intentParams Indicates the existing IntentParams object. + * @description: A constructor used to create an WantParams instance by using the parameters of an existing + * WantParams object. + * @param wantParams Indicates the existing WantParams object. */ WantParams::WantParams(const WantParams &wantParams) { @@ -216,7 +216,7 @@ bool WantParams::NewArrayData(IArray *source, sptr &dest) /** * @description: A WantParams used to * - * @param intentParams Indicates the existing IntentParams object. + * @param other Indicates the existing WantParams object. */ WantParams &WantParams::operator=(const WantParams &other) { @@ -406,9 +406,9 @@ void WantParams::Remove(const std::string &key) } /** - * @description: Checks whether the Intent contains the given key. + * @description: Checks whether the Want contains the given key. * @param key Indicates the key to check. - * @return Returns true if the Intent contains the key; returns false otherwise. + * @return Returns true if the Want contains the key; returns false otherwise. */ bool WantParams::HasParam(const std::string &key) const { @@ -416,7 +416,7 @@ bool WantParams::HasParam(const std::string &key) const } /** - * @description: Obtains the number of parameters contained in this IntentParams object. + * @description: Obtains the number of parameters contained in this WantParams object. * @return Returns the number of parameters. */ int WantParams::Size() const @@ -425,7 +425,7 @@ int WantParams::Size() const } /** - * @description: Checks whether this IntentParams object contains no parameters. + * @description: Checks whether this WantParams object contains no parameters. * @return Returns true if this object does not contain any parameters; returns false otherwise. */ bool WantParams::IsEmpty() const @@ -603,8 +603,8 @@ bool WantParams::DoMarshalling(Parcel &parcel) const } /** - * @description: Marshals an IntentParams object into a Parcel. - * @param Key-value pairs in the IntentParams are marshalled separately. + * @description: Marshals an WantParams object into a Parcel. + * @param Key-value pairs in the WantParams are marshalled separately. * @return If any key-value pair fails to be marshalled, false is returned. */ bool WantParams::Marshalling(Parcel &parcel) const @@ -1273,8 +1273,8 @@ bool WantParams::ReadFromParcel(Parcel &parcel) } /** - * @description: Unmarshals an IntentParams object from a Parcel. - * @param Key-value pairs in the IntentParams are unmarshalled separately. + * @description: Unmarshals an WantParams object from a Parcel. + * @param Key-value pairs in the WantParams are unmarshalled separately. * @return If any key-value pair fails to be unmarshalled, false is returned. */ WantParams *WantParams::Unmarshalling(Parcel &parcel) diff --git a/frameworks/kits/content/cpp/test/BUILD.gn b/frameworks/kits/content/cpp/test/BUILD.gn index 695e893464..db076813e4 100644 --- a/frameworks/kits/content/cpp/test/BUILD.gn +++ b/frameworks/kits/content/cpp/test/BUILD.gn @@ -13,7 +13,7 @@ import("//build/test.gni") -module_output_path = "ability_runtime/intent_test" +module_output_path = "ability_runtime/want_test" ############################################################################### config("module_private_config") { @@ -23,7 +23,6 @@ config("module_private_config") { "//sdk/appexecfwk/appexecfwk_base/include", "//foundation/aafwk/standard/interfaces/innerkits/uri/include", "//foundation/aafwk/standard/interfaces/innerkits/want/include", - "//foundation/aafwk/standard/interfaces/innerkits/intent/include", "//foundation/appexecfwk/standard/common/log/include", ] @@ -48,138 +47,6 @@ config("module_private_want_param_wrapper_config") { ] } -ohos_unittest("intent_parcelable_test") { - module_out_path = module_output_path - sources = [] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "bundle_framework:appexecfwk_base", - "ipc:ipc_core", - ] -} - -ohos_unittest("intent_base_test") { - module_out_path = module_output_path - sources = [] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "bundle_framework:appexecfwk_base", - "ipc:ipc_core", - ] -} - -ohos_unittest("intent_parse_to_uri_test") { - module_out_path = module_output_path - sources = [] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "bundle_framework:appexecfwk_base", - "ipc:ipc_core", - ] -} - -ohos_unittest("intent_parameters_test") { - module_out_path = module_output_path - sources = [ - "../src/ohos/aafwk/content/intent.cpp", - "../src/ohos/aafwk/content/intent_params.cpp", - "unittest/common/intent_parameters_test.cpp", - ] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "ability_base:want", - "ipc:ipc_core", - ] -} - -ohos_unittest("intent_params_test") { - module_out_path = module_output_path - sources = [] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ - "bundle_framework:appexecfwk_base", - "ipc:ipc_core", - ] -} - -ohos_unittest("intent_filter_test") { - module_out_path = module_output_path - sources = [ - "../src/ohos/aafwk/content/intent.cpp", - "../src/ohos/aafwk/content/intent_filter.cpp", - "../src/ohos/aafwk/content/intent_params.cpp", - "unittest/common/intent_filter_test.cpp", - ] - - configs = [ - ":module_private_config", - #"//foundation/aafwk/standard/interfaces/innerkits/intent:intent_public_config", - ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/base:base", - "//third_party/googletest:gtest_main", - "//utils/native/base:utils", - ] - - external_deps = [ "ability_base:want" ] -} - ohos_unittest("operation_test") { module_out_path = module_output_path sources = [ @@ -337,11 +204,6 @@ group("unittest") { deps = [] deps += [ - ":intent_base_test", - ":intent_filter_test", - ":intent_parameters_test", - ":intent_params_test", - ":intent_parse_to_uri_test", ":operation_test", ":patterns_matcher_test", ":skills_test", diff --git a/frameworks/kits/content/cpp/test/unittest/common/intent_filter_test.cpp b/frameworks/kits/content/cpp/test/unittest/common/intent_filter_test.cpp deleted file mode 100644 index b95f41d59b..0000000000 --- a/frameworks/kits/content/cpp/test/unittest/common/intent_filter_test.cpp +++ /dev/null @@ -1,462 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "ohos/aafwk/content/intent.h" -#include "ohos/aafwk/content/intent_filter.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; -using OHOS::Parcel; - -static const int LARGE_STR_LEN = 65534; -static const int SET_COUNT = 20; -static const int LOOP_TEST = 1000; - -class IntentFilterBaseTest : public testing::Test { -public: - IntentFilterBaseTest() : filter_(nullptr) - {} - ~IntentFilterBaseTest() - { - filter_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - - IntentFilter *filter_; - void CompareFilter(IntentFilter &filter1, IntentFilter &filter2); - void SendParcelTest(IntentFilter &filter); -}; - -void IntentFilterBaseTest::SetUpTestCase(void) -{} - -void IntentFilterBaseTest::TearDownTestCase(void) -{} - -void IntentFilterBaseTest::SetUp(void) -{ - filter_ = new (std::nothrow) IntentFilter(); -} - -void IntentFilterBaseTest::TearDown(void) -{ - delete filter_; - filter_ = nullptr; -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string is empty - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_001, TestSize.Level1) -{ - std::string setValue; - filter_->SetEntity(setValue); - EXPECT_EQ(setValue, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string contains special characters - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_002, TestSize.Level1) -{ - std::string setValue("@#ï¿¥#3243adsafdf_中文"); - filter_->SetEntity(setValue); - EXPECT_EQ(setValue, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string has a long size - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_003, TestSize.Level1) -{ - std::string setValue(LARGE_STR_LEN, 's'); - filter_->SetEntity(setValue); - EXPECT_EQ(setValue, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string is overrode - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_004, TestSize.Level1) -{ - std::string setValue1("1234"); - filter_->SetEntity(setValue1); - - std::string setValue2("abcd"); - filter_->SetEntity(setValue2); - - EXPECT_EQ(setValue2, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string is set 20 times - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_005, TestSize.Level1) -{ - std::string setValue("1234"); - for (int i = 0; i < SET_COUNT; i++) { - filter_->SetEntity(setValue); - } - EXPECT_EQ(setValue, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string is default - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_006, TestSize.Level1) -{ - std::string setValue; - EXPECT_EQ(setValue, filter_->GetEntity()); -} - -/* - * Feature: IntentFilter - * Function: SetEntity/GetEntity - * SubFunction: NA - * FunctionPoints: SetEntity/GetEntity - * EnvConditions: NA - * CaseDescription: Verify the function when the input string contains special characters - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Entity_007, TestSize.Level1) -{ - std::string setValue("@#ï¿¥#3243adsafdf_中文"); - for (int i = 0; i < LOOP_TEST; i++) { - filter_->SetEntity(setValue); - EXPECT_EQ(setValue, filter_->GetEntity()); - } -} - -/* - * Feature: IntentFilter - * Function: action - * SubFunction: NA - * FunctionPoints: action - * EnvConditions: NA - * CaseDescription: Verify the function when action is not exist - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_001, TestSize.Level1) -{ - std::string empty; - std::string action = "action.system.test"; - EXPECT_EQ(0, filter_->CountAction()); - EXPECT_EQ(false, filter_->HasAction(action)); - EXPECT_EQ(empty, filter_->GetAction(0)); - - filter_->RemoveAction(action); - EXPECT_EQ(0, filter_->CountAction()); - EXPECT_EQ(false, filter_->HasAction(action)); -} - -/* - * Feature: IntentFilter - * Function: action - * SubFunction: NA - * FunctionPoints: action - * EnvConditions: NA - * CaseDescription: Verify the function when actions are same - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_002, TestSize.Level1) -{ - std::string action = "action.system.test"; - int actionCount = 1; - - for (int i = 0; i < SET_COUNT; i++) { - filter_->AddAction(action); - } - - EXPECT_EQ(actionCount, filter_->CountAction()); - EXPECT_EQ(true, filter_->HasAction(action)); - EXPECT_EQ(action, filter_->GetAction(0)); - - filter_->RemoveAction(action); - EXPECT_EQ(0, filter_->CountAction()); - EXPECT_EQ(false, filter_->HasAction(action)); -} - -/* - * Feature: IntentFilter - * Function: action - * SubFunction: NA - * FunctionPoints: action - * EnvConditions: NA - * CaseDescription: Verify the function when actions are different - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_003, TestSize.Level1) -{ - std::string actionPrefix = "action.system.test"; - - for (int i = 0; i < SET_COUNT; i++) { - std::string action = actionPrefix + std::to_string(i); - filter_->AddAction(action); - } - - EXPECT_EQ(SET_COUNT, filter_->CountAction()); - for (int i = 0; i < SET_COUNT; i++) { - std::string action = actionPrefix + std::to_string(i); - EXPECT_EQ(true, filter_->HasAction(action)); - EXPECT_EQ(action, filter_->GetAction(i)); - } - - int remove = SET_COUNT / 2; - for (int i = 0; i < remove; i++) { - std::string action = actionPrefix + std::to_string(i); - filter_->RemoveAction(action); - } - - EXPECT_EQ(remove, filter_->CountAction()); - for (int i = 0; i < remove; i++) { - std::string action = actionPrefix + std::to_string(i); - EXPECT_EQ(false, filter_->HasAction(action)); - } - - for (int i = remove; i < SET_COUNT; i++) { - std::string action = actionPrefix + std::to_string(i); - EXPECT_EQ(true, filter_->HasAction(action)); - EXPECT_EQ(action, filter_->GetAction(i - remove)); - } -} - -/* - * Feature: IntentFilter - * Function: action - * SubFunction: NA - * FunctionPoints: action - * EnvConditions: NA - * CaseDescription: Verify the function when actions are same - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_Action_004, TestSize.Level1) -{ - std::string action = "action.system.test"; - int actionCount = 1; - - for (int i = 0; i < LOOP_TEST; i++) { - filter_->AddAction(action); - EXPECT_EQ(actionCount, filter_->CountAction()); - EXPECT_EQ(true, filter_->HasAction(action)); - EXPECT_EQ(action, filter_->GetAction(0)); - - filter_->RemoveAction(action); - EXPECT_EQ(0, filter_->CountAction()); - EXPECT_EQ(false, filter_->HasAction(action)); - } -} - -void IntentFilterBaseTest::CompareFilter(IntentFilter &filter1, IntentFilter &filter2) -{ - EXPECT_EQ(filter1.GetEntity(), filter2.GetEntity()); - EXPECT_EQ(filter1.CountAction(), filter2.CountAction()); - - int count = filter1.CountAction(); - for (int i = 0; i < count; i++) { - EXPECT_EQ(filter1.GetAction(i), filter2.GetAction(i)); - } -} - -void IntentFilterBaseTest::SendParcelTest(IntentFilter &filter) -{ - Parcel data; - bool result; - - result = data.WriteParcelable(&filter); - EXPECT_EQ(result, true); - - IntentFilter *filterNew = nullptr; - filterNew = data.ReadParcelable(); - EXPECT_NE(filterNew, nullptr); - - if (filterNew) { - CompareFilter(filter, *filterNew); - delete filterNew; - } -} - -/* - * Feature: IntentFilter - * Function: marshall and unmarshall - * SubFunction: NA - * FunctionPoints: marshall and unmarshall - * EnvConditions: NA - * CaseDescription: Verify marshall and unmarshall when filter is empty - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_001, TestSize.Level0) -{ - SendParcelTest(*filter_); -} - -/* - * Feature: IntentFilter - * Function: marshall and unmarshall - * SubFunction: NA - * FunctionPoints: marshall and unmarshall - * EnvConditions: NA - * CaseDescription: Verify marshall and unmarshall when filter has action and entity - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_002, TestSize.Level0) -{ - filter_->SetEntity("entity.system.test"); - filter_->AddAction("action.system.test1"); - filter_->AddAction("action.system.test2"); - - SendParcelTest(*filter_); -} - -/* - * Feature: IntentFilter - * Function: marshall and unmarshall - * SubFunction: NA - * FunctionPoints: marshall and unmarshall - * EnvConditions: NA - * CaseDescription: Verify marshall and unmarshall. Pressure test. - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_parcelable_003, TestSize.Level0) -{ - filter_->SetEntity("entity.system.test"); - filter_->AddAction("action.system.test1"); - filter_->AddAction("action.system.test2"); - - for (int i = 0; i < LOOP_TEST; i++) { - SendParcelTest(*filter_); - } -} - -/* - * Feature: IntentFilter - * Function: Match - * SubFunction: NA - * FunctionPoints: Match - * EnvConditions: NA - * CaseDescription: Verify the function. Pressure test. - */ -HWTEST_F(IntentFilterBaseTest, AaFwk_IntentFilter_match_005, TestSize.Level1) -{ - for (int i = 0; i < LOOP_TEST; i++) { - Intent intent; - intent.SetAction("action.system.action1"); - intent.SetEntity("entity.system.entity1"); - - filter_->SetEntity("entity.system.entity1"); - filter_->AddAction("action.system.action1"); - filter_->AddAction("action.system.action2"); - - EXPECT_EQ(true, filter_->Match(intent)); - } -} - -using testFilterMatchType = std::tuple; -class IntentFilterMatchTest : public testing::TestWithParam { -public: - IntentFilterMatchTest() : filter_(nullptr) - {} - ~IntentFilterMatchTest() - { - filter_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - IntentFilter *filter_; -}; - -void IntentFilterMatchTest::SetUpTestCase(void) -{} - -void IntentFilterMatchTest::TearDownTestCase(void) -{} - -void IntentFilterMatchTest::SetUp(void) -{ - filter_ = new (std::nothrow) IntentFilter(); -} - -void IntentFilterMatchTest::TearDown(void) -{ - delete filter_; - filter_ = nullptr; -} - -/* - * Feature: IntentFilter - * Function: Match - * SubFunction: NA - * FunctionPoints: Match - * EnvConditions: NA - * CaseDescription: Verify whether parameter change. - * AaFwk_IntentFilter_match_001 - * AaFwk_IntentFilter_match_002 - * AaFwk_IntentFilter_match_003 - * AaFwk_IntentFilter_match_004 - */ - -HWTEST_P(IntentFilterMatchTest, AaFwk_IntentFilter_match, TestSize.Level0) -{ - std::string filterEntity = "entity.system.entity1"; - std::string filterAction1 = "action.system.action1"; - std::string filterAction2 = "action.system.action2"; - std::string intentEntity = std::get<0>(GetParam()); - std::string intentAction = std::get<1>(GetParam()); - bool result = std::get<2>(GetParam()); - - filter_->SetEntity(filterEntity); - filter_->AddAction(filterAction1); - filter_->AddAction(filterAction2); - - Intent intent; - intent.SetEntity(intentEntity); - intent.SetAction(intentAction); - - EXPECT_EQ(result, filter_->Match(intent)); -} - -INSTANTIATE_TEST_CASE_P(IntentFilterMatchTestP, IntentFilterMatchTest, - testing::Values(testFilterMatchType("entity.system.entityA", "action.system.actionA", false), - testFilterMatchType("entity.system.entity1", "action.system.actionA", false), - testFilterMatchType("entity.system.entityA", "action.system.action2", false), - testFilterMatchType("entity.system.entity1", "action.system.action1", true))); diff --git a/frameworks/kits/content/cpp/test/unittest/common/intent_parameters_test.cpp b/frameworks/kits/content/cpp/test/unittest/common/intent_parameters_test.cpp deleted file mode 100644 index 89304940b3..0000000000 --- a/frameworks/kits/content/cpp/test/unittest/common/intent_parameters_test.cpp +++ /dev/null @@ -1,2322 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include - -#include "ohos/aafwk/content/intent.h" - -using namespace testing::ext; -using namespace OHOS::AAFwk; - -using testBoolType = std::tuple; -class IntentParametersBoolTest : public testing::TestWithParam { -public: - IntentParametersBoolTest() : intent_(nullptr) - {} - ~IntentParametersBoolTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersBoolTest::SetUpTestCase(void) -{} - -void IntentParametersBoolTest::TearDownTestCase(void) -{} - -void IntentParametersBoolTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersBoolTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetBoolParam/GetBoolParam - * SubFunction: NA - * FunctionPoints: SetBoolParam/GetBoolParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersBoolTest, AaFwk_Intent_Parameters_Bool, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - bool setValue = std::get<2>(GetParam()); - bool defaultValue = std::get<3>(GetParam()); - bool result = std::get<4>(GetParam()); - intent_->SetBoolParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetBoolParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersBoolTestCaseP, IntentParametersBoolTest, - testing::Values(testBoolType("", "aa", true, true, true), testBoolType("", "aa", true, false, false), - testBoolType("", "", true, true, true), testBoolType("", "", true, false, true), - testBoolType("123", "123", true, false, true), testBoolType("123", "aa", true, false, false), - testBoolType("-~*&%ï¿¥", "-~*&%ï¿¥", true, false, true), testBoolType("-~*&%ï¿¥", "aa", true, false, false), - testBoolType("中文", "中文", true, false, true), testBoolType("中文", "aa", true, false, false), - testBoolType("_中文ddPEJKJ#(&*~#^%", "_中文ddPEJKJ#(&*~#^%", true, false, true), - testBoolType("_中文ddPEJKJ#(&*~#^%", "123", true, false, false))); - -/* - * Feature: Intent - * Function: SetBoolParam/GetBoolParam - * SubFunction: NA - * FunctionPoints: SetBoolParam/GetBoolParam - * EnvConditions: NA - * CaseDescription: Verify when set twice and get twice - */ -HWTEST_F(IntentParametersBoolTest, AaFwk_Intent_Parameters_Bool_001, TestSize.Level1) -{ - std::string firstKey("_中文ddPEJKJ#(&*~#^%"); - std::string secondKey("key33"); - intent_->SetBoolParam(firstKey, true); - intent_->SetBoolParam(secondKey, true); - EXPECT_EQ(true, intent_->GetBoolParam(firstKey, false)); - EXPECT_EQ(true, intent_->GetBoolParam(secondKey, false)); -} - -/* - * Feature: Intent - * Function: SetBoolParam/GetBoolParam - * SubFunction: NA - * FunctionPoints: SetBoolParam/GetBoolParam - * EnvConditions: NA - * CaseDescription: Verify when set 20 times, and get once - */ -HWTEST_F(IntentParametersBoolTest, AaFwk_Intent_Parameters_Bool_002, TestSize.Level1) -{ - std::string keyStr("_中文ddPEJKJ#(&*~#^%"); - for (int i = 0; i < 20; i++) { - intent_->SetBoolParam(keyStr, true); - } - EXPECT_EQ(true, intent_->GetBoolParam(keyStr, false)); -} - -using testBoolArrayType = std::tuple, std::vector, std::vector>; -class IntentParametersBoolArrayTest : public testing::TestWithParam { -public: - IntentParametersBoolArrayTest() : intent_(nullptr) - {} - ~IntentParametersBoolArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersBoolArrayTest::SetUpTestCase(void) -{} - -void IntentParametersBoolArrayTest::TearDownTestCase(void) -{} - -void IntentParametersBoolArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersBoolArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetBoolArrayParam/GetBoolArrayParam - * SubFunction: NA - * FunctionPoints: SetBoolArrayParam/GetBoolArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersBoolArrayTest, AaFwk_Intent_Parameters_BoolArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetBoolArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetBoolArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersBoolArrayTestCaseP, IntentParametersBoolArrayTest, - testing::Values(testBoolArrayType("", "aa", {true, false}, {}, {}), - testBoolArrayType("", "", {true, false}, {}, {true, false}), - testBoolArrayType("1*中_aR", "aa", {true, false}, {}, {}), - testBoolArrayType("1*中_aR", "1*中_aR", {false, true}, {}, {false, true}))); - -/* - * Feature: Intent - * Function: SetBoolArrayParam/GetBoolArrayParam - * SubFunction: NA - * FunctionPoints: SetBoolArrayParam/GetBoolArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is bool array - */ -HWTEST_F(IntentParametersBoolArrayTest, AaFwk_Intent_Parameters_Bool_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetBoolArrayParam(getKey)); -} - -/* - * Feature: Intent - * Function: SetBoolArrayParam/GetBoolArrayParam - * SubFunction: NA - * FunctionPoints: SetBoolArrayParam/GetBoolArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is bool array - */ -HWTEST_F(IntentParametersBoolArrayTest, AaFwk_Intent_Parameters_Bool_Array_002, TestSize.Level1) -{ - std::string emptyStr(""); - std::vector firstValue({true, false}); - std::vector secondValue({true, true}); - std::vector firstDefaultValue({false, true}); - std::string keyStr("aa"); - intent_->SetBoolArrayParam(emptyStr, firstValue); - intent_->SetBoolArrayParam(emptyStr, firstValue); - intent_->SetBoolArrayParam(emptyStr, secondValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetBoolArrayParam(keyStr)); - intent_->SetBoolArrayParam(emptyStr, firstDefaultValue); - EXPECT_EQ(firstDefaultValue, intent_->GetBoolArrayParam(emptyStr)); -} - -/* - * Feature: Intent - * Function: SetBoolArrayParam/GetBoolArrayParam - * SubFunction: NA - * FunctionPoints: SetBoolArrayParam/GetBoolArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is bool array - */ -HWTEST_F(IntentParametersBoolArrayTest, AaFwk_Intent_Parameters_Bool_Array_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - std::vector firstValue({true, false}); - std::vector secondValue({true, true}); - std::string secondKey("aa"); - intent_->SetBoolArrayParam(firstKey, firstValue); - intent_->SetBoolArrayParam(firstKey, firstValue); - intent_->SetBoolArrayParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetBoolArrayParam(firstKey)); - intent_->SetBoolArrayParam(firstKey, firstValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetBoolArrayParam(secondKey)); -} - -using testByteType = std::tuple; -class IntentParametersByteTest : public testing::TestWithParam { -public: - IntentParametersByteTest() : intent_(nullptr) - {} - ~IntentParametersByteTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersByteTest::SetUpTestCase(void) -{} - -void IntentParametersByteTest::TearDownTestCase(void) -{} - -void IntentParametersByteTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersByteTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetByteParam/GetByteParam - * SubFunction: NA - * FunctionPoints: SetByteParam/GetByteParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersByteTest, AaFwk_Intent_Parameters_Byte, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - byte setValue = std::get<2>(GetParam()); - byte defaultValue = std::get<3>(GetParam()); - byte result = std::get<4>(GetParam()); - intent_->SetByteParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetByteParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersByteTestCaseP, IntentParametersByteTest, - testing::Values(testByteType("", "aa", '#', 'U', 'U'), testByteType("", "", 'N', 'K', 'N'), - testByteType("1*中_aR", "aa", 'a', '%', '%'), testByteType("1*中_aR", "1*中_aR", 'a', 'z', 'a'))); - -/* - * Feature: Intent - * Function: SetByteParam/GetByteParam - * SubFunction: NA - * FunctionPoints: SetByteParam/GetByteParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte - */ -HWTEST_F(IntentParametersByteTest, AaFwk_Intent_Parameters_Byte_001, TestSize.Level1) -{ - byte defaultValue = '%'; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetByteParam(getKey, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetByteParam/GetByteParam - * SubFunction: NA - * FunctionPoints: SetByteParam/GetByteParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte - */ -HWTEST_F(IntentParametersByteTest, AaFwk_Intent_Parameters_Byte_002, TestSize.Level1) -{ - std::string emptyStr(""); - byte firstValue = 'a'; - byte secondValue = '1'; - byte thirdValue = '*'; - byte firstDefaultValue = '2'; - byte secondDefaultValue = '!'; - std::string keyStr("aa"); - intent_->SetByteParam(emptyStr, firstValue); - intent_->SetByteParam(emptyStr, firstValue); - intent_->SetByteParam(emptyStr, secondValue); - EXPECT_EQ(firstDefaultValue, intent_->GetByteParam(keyStr, firstDefaultValue)); - intent_->SetByteParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetByteParam(emptyStr, secondDefaultValue)); -} - -/* - * Feature: Intent - * Function: SetByteParam/GetByteParam - * SubFunction: NA - * FunctionPoints: SetByteParam/GetByteParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte - */ -HWTEST_F(IntentParametersByteTest, AaFwk_Intent_Parameters_Byte_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - byte firstValue = 'a'; - byte secondValue = '_'; - byte firstDefaultValue = 'W'; - byte secondDefaultValue = '%'; - std::string secondKey("aa"); - intent_->SetByteParam(firstKey, firstValue); - intent_->SetByteParam(firstKey, firstValue); - intent_->SetByteParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetByteParam(firstKey, firstDefaultValue)); - intent_->SetByteParam(firstKey, firstValue); - EXPECT_EQ(secondDefaultValue, intent_->GetByteParam(secondKey, secondDefaultValue)); -} - -using testByteArrayType = std::tuple, std::vector, std::vector>; -class IntentParametersByteArrayTest : public testing::TestWithParam { -public: - IntentParametersByteArrayTest() : intent_(nullptr) - {} - ~IntentParametersByteArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersByteArrayTest::SetUpTestCase(void) -{} - -void IntentParametersByteArrayTest::TearDownTestCase(void) -{} - -void IntentParametersByteArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersByteArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetByteArrayParam/GetByteArrayParam - * SubFunction: NA - * FunctionPoints: SetByteArrayParam/GetByteArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersByteArrayTest, AaFwk_Intent_Parameters_ByteArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetByteArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetByteArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersByteArrayTestCaseP, IntentParametersByteArrayTest, - testing::Values(testByteArrayType("", "aa", {'*', 'D'}, {}, {}), - testByteArrayType("", "", {'%', ')'}, {}, {'%', ')'}), testByteArrayType("1*中_aR", "aa", {'R', '.'}, {}, {}), - testByteArrayType("1*中_aR", "1*中_aR", {'R', 'b'}, {}, {'R', 'b'}))); - -/* - * Feature: Intent - * Function: GetByteArrayParam - * SubFunction: NA - * FunctionPoints: GetByteArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte array - */ -HWTEST_F(IntentParametersByteArrayTest, AaFwk_Intent_Parameters_Byte_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetByteArrayParam(getKey)); -} - -/* - * Feature: Intent - * Function: SetByteArrayParam/GetByteArrayParam - * SubFunction: NA - * FunctionPoints: SetByteArrayParam/GetByteArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte array - */ -HWTEST_F(IntentParametersByteArrayTest, AaFwk_Intent_Parameters_Byte_Array_002, TestSize.Level1) -{ - std::string emptyStr(""); - std::vector firstValue({'a', '2'}); - std::vector secondValue({'1', 'd'}); - std::vector thirdValue({'t', '3'}); - std::string keyStr("aa"); - intent_->SetByteArrayParam(emptyStr, firstValue); - intent_->SetByteArrayParam(emptyStr, firstValue); - intent_->SetByteArrayParam(emptyStr, secondValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetByteArrayParam(keyStr)); - intent_->SetByteArrayParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetByteArrayParam(emptyStr)); -} - -/* - * Feature: Intent - * Function: SetByteArrayParam/GetByteArrayParam - * SubFunction: NA - * FunctionPoints: SetByteArrayParam/GetByteArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is byte array - */ -HWTEST_F(IntentParametersByteArrayTest, AaFwk_Intent_Parameters_Byte_Array_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - std::vector firstValue({'a', '2'}); - std::vector secondValue({'w', '$'}); - std::vector defaultValue; - std::string secondKey("aa"); - intent_->SetByteArrayParam(firstKey, firstValue); - intent_->SetByteArrayParam(firstKey, firstValue); - intent_->SetByteArrayParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetByteArrayParam(firstKey)); - intent_->SetByteArrayParam(firstKey, firstValue); - EXPECT_EQ(defaultValue, intent_->GetByteArrayParam(secondKey)); -} - -using testCharType = std::tuple; -class IntentParametersCharTest : public testing::TestWithParam { -public: - IntentParametersCharTest() : intent_(nullptr) - {} - ~IntentParametersCharTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersCharTest::SetUpTestCase(void) -{} - -void IntentParametersCharTest::TearDownTestCase(void) -{} - -void IntentParametersCharTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersCharTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetCharParam/GetCharParam - * SubFunction: NA - * FunctionPoints: SetCharParam/GetCharParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersCharTest, AaFwk_Intent_Parameters_Char, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - zchar setValue = std::get<2>(GetParam()); - zchar defaultValue = std::get<3>(GetParam()); - zchar result = std::get<4>(GetParam()); - intent_->SetCharParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetCharParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersCharTestCaseP, IntentParametersCharTest, - testing::Values(testCharType("", "aa", U'#', U'中', U'中'), testCharType("", "", U'中', U'K', U'中'), - testCharType("1*中_aR", "aa", U'a', U'中', U'中'), testCharType("1*中_aR", "1*中_aR", U'中', U'z', U'中'))); - -/* - * Feature: Intent - * Function: SetCharParam/GetCharParam - * SubFunction: NA - * FunctionPoints: SetCharParam/GetCharParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char - */ -HWTEST_F(IntentParametersCharTest, AaFwk_Intent_Parameters_Char_001, TestSize.Level1) -{ - zchar defaultValue = U'æ–‡'; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetCharParam(getKey, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetCharParam/GetCharParam - * SubFunction: NA - * FunctionPoints: SetCharParam/GetCharParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char - */ -HWTEST_F(IntentParametersCharTest, AaFwk_Intent_Parameters_Char_002, TestSize.Level1) -{ - std::string emptyStr(""); - zchar firstValue = U'中'; - zchar secondValue = U'æ–‡'; - zchar thirdValue = U'å­—'; - zchar firstDefaultValue = U'符'; - zchar secondDefaultValue = U'集'; - std::string keyStr("aa"); - intent_->SetCharParam(emptyStr, firstValue); - intent_->SetCharParam(emptyStr, firstValue); - intent_->SetCharParam(emptyStr, secondValue); - EXPECT_EQ(firstDefaultValue, intent_->GetCharParam(keyStr, firstDefaultValue)); - intent_->SetCharParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetCharParam(emptyStr, secondDefaultValue)); -} - -/* - * Feature: Intent - * Function: SetCharParam/GetCharParam - * SubFunction: NA - * FunctionPoints: SetCharParam/GetCharParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char - */ -HWTEST_F(IntentParametersCharTest, AaFwk_Intent_Parameters_Char_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - zchar firstValue = U'中'; - zchar secondValue = U'æ–‡'; - zchar firstDefaultValue = U'å­—'; - zchar secondDefaultValue = U'符'; - std::string secondKey("aa"); - intent_->SetCharParam(firstKey, firstValue); - intent_->SetCharParam(firstKey, firstValue); - intent_->SetCharParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetCharParam(firstKey, firstDefaultValue)); - intent_->SetCharParam(firstKey, firstValue); - EXPECT_EQ(secondDefaultValue, intent_->GetCharParam(secondKey, secondDefaultValue)); -} - -using testCharArrayType = - std::tuple, std::vector, std::vector>; -class IntentParametersCharArrayTest : public testing::TestWithParam { -public: - IntentParametersCharArrayTest() : intent_(nullptr) - {} - ~IntentParametersCharArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersCharArrayTest::SetUpTestCase(void) -{} - -void IntentParametersCharArrayTest::TearDownTestCase(void) -{} - -void IntentParametersCharArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersCharArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetCharArrayParam/GetCharArrayParam - * SubFunction: NA - * FunctionPoints: SetCharArrayParam/GetCharArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersCharArrayTest, AaFwk_Intent_Parameters_CharArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetCharArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetCharArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersCharArrayTestCaseP, IntentParametersCharArrayTest, - testing::Values(testCharArrayType("", "aa", {U'中', U'æ–‡'}, {}, {}), - testCharArrayType("", "", {U'中', U'æ–‡'}, {}, {U'中', U'æ–‡'}), - testCharArrayType("1*中_aR", "aa", {U'中', U'æ–‡'}, {}, {}), - testCharArrayType("1*中_aR", "1*中_aR", {U'中', U'æ–‡'}, {}, {U'中', U'æ–‡'}))); - -/* - * Feature: Intent - * Function: GetCharArrayParam - * SubFunction: NA - * FunctionPoints: GetCharArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char array - */ -HWTEST_F(IntentParametersCharArrayTest, AaFwk_Intent_Parameters_Char_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetCharArrayParam(getKey)); -} - -/* - * Feature: Intent - * Function: SetCharArrayParam/GetCharArrayParam - * SubFunction: NA - * FunctionPoints: SetCharArrayParam/GetCharArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char array - */ -HWTEST_F(IntentParametersCharArrayTest, AaFwk_Intent_Parameters_Char_Array_002, TestSize.Level1) -{ - std::string emptyStr(""); - std::vector firstValue({U'中', U'æ–‡'}); - std::vector secondValue({U'å­—', U'符'}); - std::vector thirdValue({U'集', U'英'}); - std::string keyStr("aa"); - intent_->SetCharArrayParam(emptyStr, firstValue); - intent_->SetCharArrayParam(emptyStr, firstValue); - intent_->SetCharArrayParam(emptyStr, secondValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetCharArrayParam(keyStr)); - intent_->SetCharArrayParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetCharArrayParam(emptyStr)); -} - -/* - * Feature: Intent - * Function: SetCharArrayParam/GetCharArrayParam - * SubFunction: NA - * FunctionPoints: SetCharArrayParam/GetCharArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is char array - */ -HWTEST_F(IntentParametersCharArrayTest, AaFwk_Intent_Parameters_Char_Array_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - std::vector firstValue({U'中', U'æ–‡'}); - std::vector secondValue({U'å­—', U'符'}); - std::vector defaultValue; - std::string secondKey("aa"); - intent_->SetCharArrayParam(firstKey, firstValue); - intent_->SetCharArrayParam(firstKey, firstValue); - intent_->SetCharArrayParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetCharArrayParam(firstKey)); - intent_->SetCharArrayParam(firstKey, firstValue); - EXPECT_EQ(defaultValue, intent_->GetCharArrayParam(secondKey)); -} - -using testShortType = std::tuple; -class IntentParametersShortTest : public testing::TestWithParam { -public: - IntentParametersShortTest() : intent_(nullptr) - {} - ~IntentParametersShortTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersShortTest::SetUpTestCase(void) -{} - -void IntentParametersShortTest::TearDownTestCase(void) -{} - -void IntentParametersShortTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersShortTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetShortParam/GetShortParam - * SubFunction: NA - * FunctionPoints: SetShortParam/GetShortParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersShortTest, AaFwk_Intent_Parameters_Short, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - short setValue = std::get<2>(GetParam()); - short defaultValue = std::get<3>(GetParam()); - short result = std::get<4>(GetParam()); - intent_->SetShortParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetShortParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersShortTestCaseP, IntentParametersShortTest, - testing::Values(testShortType("", "aa", -1, 100, 100), testShortType("", "", -9, -41, -9), - testShortType("1*中_aR", "aa", 50, 5, 5), testShortType("1*中_aR", "1*中_aR", -5000, 5000, -5000))); - -/* - * Feature: Intent - * Function: GetShortParam - * SubFunction: NA - * FunctionPoints: GetShortParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short - */ -HWTEST_F(IntentParametersShortTest, AaFwk_Intent_Parameters_Short_001, TestSize.Level1) -{ - short defaultValue = 200; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetShortParam(getKey, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetShortParam/GetShortParam - * SubFunction: NA - * FunctionPoints: SetShortParam/GetShortParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short - */ -HWTEST_F(IntentParametersShortTest, AaFwk_Intent_Parameters_Short_002, TestSize.Level1) -{ - std::string emptyStr(""); - short firstValue = 1; - short secondValue = 2; - short thirdValue = 4; - short firstDefaultValue = 3; - short secondDefaultValue = 5; - std::string keyStr("aa"); - intent_->SetShortParam(emptyStr, firstValue); - intent_->SetShortParam(emptyStr, firstValue); - intent_->SetShortParam(emptyStr, secondValue); - EXPECT_EQ(firstDefaultValue, intent_->GetShortParam(keyStr, firstDefaultValue)); - intent_->SetShortParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetShortParam(emptyStr, secondDefaultValue)); -} - -/* - * Feature: Intent - * Function: SetShortParam/GetShortParam - * SubFunction: NA - * FunctionPoints: SetShortParam/GetShortParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short - */ -HWTEST_F(IntentParametersShortTest, AaFwk_Intent_Parameters_Short_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - short firstValue = -1; - short secondValue = 0; - short thirdValue = 4; - short firstDefaultValue = 9; - short secondDefaultValue = -10; - std::string secondKey("aa"); - intent_->SetShortParam(firstKey, firstValue); - intent_->SetShortParam(firstKey, firstValue); - intent_->SetShortParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetShortParam(firstKey, firstDefaultValue)); - intent_->SetShortParam(firstKey, thirdValue); - EXPECT_EQ(secondDefaultValue, intent_->GetShortParam(secondKey, secondDefaultValue)); -} - -using testShortArrayType = - std::tuple, std::vector, std::vector>; -class IntentParametersShortArrayTest : public testing::TestWithParam { -public: - IntentParametersShortArrayTest() : intent_(nullptr) - {} - ~IntentParametersShortArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersShortArrayTest::SetUpTestCase(void) -{} - -void IntentParametersShortArrayTest::TearDownTestCase(void) -{} - -void IntentParametersShortArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersShortArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetShortArrayParam/GetShortArrayParam - * SubFunction: NA - * FunctionPoints: SetShortArrayParam/GetShortArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersShortArrayTest, AaFwk_Intent_Parameters_ShortArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetShortArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetShortArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersShortArrayTestCaseP, IntentParametersShortArrayTest, - testing::Values(testShortArrayType("", "aa", {-1, 3, 25, -9}, {}, {}), - testShortArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}), - testShortArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}), - testShortArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000}))); - -/* - * Feature: Intent - * Function: GetShortArrayParam - * SubFunction: NA - * FunctionPoints: GetShortArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short array - */ -HWTEST_F(IntentParametersShortArrayTest, AaFwk_Intent_Parameters_Short_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetShortArrayParam(getKey)); -} - -/* - * Feature: Intent - * Function: SetShortArrayParam/GetShortArrayParam - * SubFunction: NA - * FunctionPoints: SetShortArrayParam/GetShortArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short array - */ -HWTEST_F(IntentParametersShortArrayTest, AaFwk_Intent_Parameters_Short_Array_002, TestSize.Level1) -{ - std::string emptyStr(""); - std::vector firstValue({1, 4, -9}); - std::vector secondValue({1, 8, -9}); - std::vector thirdValue({1, 4, 9}); - std::string keyStr("aa"); - intent_->SetShortArrayParam(emptyStr, firstValue); - intent_->SetShortArrayParam(emptyStr, firstValue); - intent_->SetShortArrayParam(emptyStr, secondValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetShortArrayParam(keyStr)); - intent_->SetShortArrayParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetShortArrayParam(emptyStr)); -} - -/* - * Feature: Intent - * Function: SetShortArrayParam/GetShortArrayParam - * SubFunction: NA - * FunctionPoints: SetShortArrayParam/GetShortArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is short array - */ -HWTEST_F(IntentParametersShortArrayTest, AaFwk_Intent_Parameters_Short_Array_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - std::vector firstValue({-1, -2}); - std::vector secondValue({-1, -2, -1, -2, 0}); - std::vector thirdValue({-1, -2, 100}); - std::string secondKey("aa"); - intent_->SetShortArrayParam(firstKey, firstValue); - intent_->SetShortArrayParam(firstKey, firstValue); - intent_->SetShortArrayParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetShortArrayParam(firstKey)); - intent_->SetShortArrayParam(firstKey, thirdValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetShortArrayParam(secondKey)); -} - -using testIntType = std::tuple; -class IntentParametersIntTest : public testing::TestWithParam { -public: - IntentParametersIntTest() : intent_(nullptr) - {} - ~IntentParametersIntTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersIntTest::SetUpTestCase(void) -{} - -void IntentParametersIntTest::TearDownTestCase(void) -{} - -void IntentParametersIntTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersIntTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetIntParam/GetIntParam - * SubFunction: NA - * FunctionPoints: SetIntParam/GetIntParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersIntTest, AaFwk_Intent_Parameters_Int, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - int setValue = std::get<2>(GetParam()); - int defaultValue = std::get<3>(GetParam()); - int result = std::get<4>(GetParam()); - intent_->SetIntParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetIntParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersIntTestCaseP, IntentParametersIntTest, - testing::Values(testIntType("", "aa", -1, 100, 100), testIntType("", "", -9, -41, -9), - testIntType("1*中_aR", "aa", 50, 5, 5), testIntType("1*中_aR", "1*中_aR", -5000, 5000, -5000))); - -/* - * Feature: Intent - * Function: GetIntParam - * SubFunction: NA - * FunctionPoints: GetIntParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer - */ -HWTEST_F(IntentParametersIntTest, AaFwk_Intent_Parameters_Int_001, TestSize.Level1) -{ - int defaultValue = 200; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetIntParam(getKey, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetIntParam/GetIntParam - * SubFunction: NA - * FunctionPoints: SetIntParam/GetIntParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer - */ -HWTEST_F(IntentParametersIntTest, AaFwk_Intent_Parameters_Int_002, TestSize.Level1) -{ - std::string emptyStr(""); - int firstValue = 1; - int secondValue = 2; - int thirdValue = 4; - int firstDefaultValue = 3; - int secondDefaultValue = 5; - std::string keyStr("aa"); - intent_->SetIntParam(emptyStr, firstValue); - intent_->SetIntParam(emptyStr, firstValue); - intent_->SetIntParam(emptyStr, secondValue); - EXPECT_EQ(firstDefaultValue, intent_->GetIntParam(keyStr, firstDefaultValue)); - intent_->SetIntParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetIntParam(emptyStr, secondDefaultValue)); -} - -/* - * Feature: Intent - * Function: SetIntParam/GetIntParam - * SubFunction: NA - * FunctionPoints: SetIntParam/GetIntParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer - */ -HWTEST_F(IntentParametersIntTest, AaFwk_Intent_Parameters_Int_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - int firstValue = -1; - int secondValue = 0; - int thirdValue = 4; - int firstDefaultValue = 9; - int secondDefaultValue = -10; - std::string secondKey("aa"); - intent_->SetIntParam(firstKey, firstValue); - intent_->SetIntParam(firstKey, firstValue); - intent_->SetIntParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetIntParam(firstKey, firstDefaultValue)); - intent_->SetIntParam(firstKey, thirdValue); - EXPECT_EQ(secondDefaultValue, intent_->GetIntParam(secondKey, secondDefaultValue)); -} - -using testIntArrayType = std::tuple, std::vector, std::vector>; -class IntentParametersIntArrayTest : public testing::TestWithParam { -public: - IntentParametersIntArrayTest() : intent_(nullptr) - {} - ~IntentParametersIntArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersIntArrayTest::SetUpTestCase(void) -{} - -void IntentParametersIntArrayTest::TearDownTestCase(void) -{} - -void IntentParametersIntArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersIntArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetIntArrayParam/GetIntArrayParam - * SubFunction: NA - * FunctionPoints: SetIntArrayParam/GetIntArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersIntArrayTest, AaFwk_Intent_Parameters_IntArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetIntArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetIntArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersIntArrayTestCaseP, IntentParametersIntArrayTest, - testing::Values(testIntArrayType("", "aa", {-1, 3, 25, -9}, {}, {}), - testIntArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}), - testIntArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}), - testIntArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000}))); - -/* - * Feature: Intent - * Function: GetIntArrayParam - * SubFunction: NA - * FunctionPoints: GetIntArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer array - */ -HWTEST_F(IntentParametersIntArrayTest, AaFwk_Intent_Parameters_Int_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string getKey("aa"); - EXPECT_EQ(defaultValue, intent_->GetIntArrayParam(getKey)); -} - -/* - * Feature: Intent - * Function: SetIntArrayParam/GetIntArrayParam - * SubFunction: NA - * FunctionPoints: SetIntArrayParam/GetIntArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer array - */ -HWTEST_F(IntentParametersIntArrayTest, AaFwk_Intent_Parameters_Int_Array_002, TestSize.Level1) -{ - std::string emptyStr(""); - std::vector firstValue({1, 4, -9}); - std::vector secondValue({1, 8, -9}); - std::vector thirdValue({1, 4, 9}); - std::string keyStr("aa"); - intent_->SetIntArrayParam(emptyStr, firstValue); - intent_->SetIntArrayParam(emptyStr, firstValue); - intent_->SetIntArrayParam(emptyStr, secondValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetIntArrayParam(keyStr)); - intent_->SetIntArrayParam(emptyStr, thirdValue); - EXPECT_EQ(thirdValue, intent_->GetIntArrayParam(emptyStr)); -} - -/* - * Feature: Intent - * Function: SetIntArrayParam/GetIntArrayParam - * SubFunction: NA - * FunctionPoints: SetIntArrayParam/GetIntArrayParam - * EnvConditions: NA - * CaseDescription: Verify when the value is integer array - */ -HWTEST_F(IntentParametersIntArrayTest, AaFwk_Intent_Parameters_Int_Array_003, TestSize.Level1) -{ - std::string firstKey("%1uH3"); - std::vector firstValue({-1, -2}); - std::vector secondValue({-1, -2, -1, -2, 0}); - std::vector thirdValue({-1, -2, 100}); - std::string secondKey("aa"); - intent_->SetIntArrayParam(firstKey, firstValue); - intent_->SetIntArrayParam(firstKey, firstValue); - intent_->SetIntArrayParam(firstKey, secondValue); - EXPECT_EQ(secondValue, intent_->GetIntArrayParam(firstKey)); - intent_->SetIntArrayParam(firstKey, thirdValue); - std::vector defaultValue; - EXPECT_EQ(defaultValue, intent_->GetIntArrayParam(secondKey)); -} - -using testLongType = std::tuple; -class IntentParametersLongTest : public testing::TestWithParam { -public: - IntentParametersLongTest() : intent_(nullptr) - {} - ~IntentParametersLongTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersLongTest::SetUpTestCase(void) -{} - -void IntentParametersLongTest::TearDownTestCase(void) -{} - -void IntentParametersLongTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersLongTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetLongParam/GetLongParam - * SubFunction: NA - * FunctionPoints: SetLongParam/GetLongParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersLongTest, AaFwk_Intent_Parameters_Long, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - long setValue = std::get<2>(GetParam()); - long defaultValue = std::get<3>(GetParam()); - long result = std::get<4>(GetParam()); - intent_->SetLongParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetLongParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersLongTestCaseP, IntentParametersLongTest, - testing::Values(testLongType("", "aa", -1, 100, 100), testLongType("", "", -9, -41, -9), - testLongType("1*中_aR", "aa", 50, 5, 5), testLongType("1*中_aR", "1*中_aR", -5000, 5000, -5000))); - -/* - * Feature: Intent - * Function: SetLongParam & GetLongParam - * SubFunction: NA - * FunctionPoints: SetLongParam & GetLongParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersLongTest, AaFwk_Intent_Parameters_Long_001, TestSize.Level1) -{ - long defaultValue = 100; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetLongParam(key, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetLongParam & GetLongParam - * SubFunction: NA - * FunctionPoints: SetLongParam & GetLongParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersLongTest, AaFwk_Intent_Parameters_Long_002, TestSize.Level1) -{ - std::string setKey1 = ""; - std::string setKey2 = "aa"; - long setValue1 = 1; - long setValue2 = 5; - intent_->SetLongParam(setKey1, setValue1); - intent_->SetLongParam(setKey1, setValue1); - setValue1 = 2; - intent_->SetLongParam(setKey1, setValue1); - setValue1 = 3; - EXPECT_EQ(setValue1, intent_->GetLongParam(setKey2, setValue1)); - setValue1 = 4; - intent_->SetLongParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetLongParam(setKey1, setValue2)); -} - -/* - * Feature: Intent - * Function: SetLongParam & GetLongParam - * SubFunction: NA - * FunctionPoints: SetLongParam & GetLongParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersLongTest, AaFwk_Intent_Parameters_Long_003, TestSize.Level1) -{ - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - long setValue1 = -1; - long setValue2 = 9; - intent_->SetLongParam(setKey1, setValue1); - intent_->SetLongParam(setKey1, setValue1); - setValue1 = 0; - intent_->SetLongParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetLongParam(setKey1, setValue2)); - setValue1 = 4; - intent_->SetLongParam(setKey1, setValue1); - setValue1 = -10; - EXPECT_EQ(setValue1, intent_->GetLongParam(setKey2, setValue1)); -} - -using testLongArrayType = std::tuple, std::vector, std::vector>; -class IntentParametersLongArrayTest : public testing::TestWithParam { -public: - IntentParametersLongArrayTest() : intent_(nullptr) - {} - ~IntentParametersLongArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersLongArrayTest::SetUpTestCase(void) -{} - -void IntentParametersLongArrayTest::TearDownTestCase(void) -{} - -void IntentParametersLongArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersLongArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetLongArrayParam/GetLongArrayParam - * SubFunction: NA - * FunctionPoints: SetLongArrayParam/GetLongArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersLongArrayTest, AaFwk_Intent_Parameters_LongArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetLongArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetLongArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersLongArrayTestCaseP, IntentParametersLongArrayTest, - testing::Values(testLongArrayType("", "aa", {-1, 3, 25, -9}, {}, {}), - testLongArrayType("", "", {-41, 0, 0, 9}, {}, {-41, 0, 0, 9}), - testLongArrayType("1*中_aR", "aa", {50, 2, -9}, {}, {}), - testLongArrayType("1*中_aR", "1*中_aR", {-5000}, {}, {-5000}))); - -/* - * Feature: Intent - * Function: SetLongArrayParam & GetLongArrayParam - * SubFunction: NA - * FunctionPoints: SetLongArrayParam & GetLongArrayParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersLongArrayTest, AaFwk_Intent_Parameters_Long_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetLongArrayParam(key)); -} - -/* - * Feature: Intent - * Function: SetLongArrayParam & GetLongArrayParam - * SubFunction: NA - * FunctionPoints: SetLongArrayParam & GetLongArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersLongArrayTest, AaFwk_Intent_Parameters_Long_Array_002, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = ""; - std::string setKey2 = "aa"; - std::vector setValue1 = {1, 2}; - intent_->SetLongArrayParam(setKey1, setValue1); - intent_->SetLongArrayParam(setKey1, setValue1); - setValue1 = {2, 3}; - intent_->SetLongArrayParam(setKey1, setValue1); - EXPECT_EQ(defaultValue, intent_->GetLongArrayParam(setKey2)); - setValue1 = {4, 5}; - intent_->SetLongArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetLongArrayParam(setKey1)); -} - -/* - * Feature: Intent - * Function: SetLongArrayParam & GetLongArrayParam - * SubFunction: NA - * FunctionPoints: SetLongArrayParam & GetLongArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersLongArrayTest, AaFwk_Intent_Parameters_Long_Array_003, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - std::vector setValue1 = {-1, -2}; - intent_->SetLongArrayParam(setKey1, setValue1); - intent_->SetLongArrayParam(setKey1, setValue1); - setValue1 = {0, 1}; - intent_->SetLongArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetLongArrayParam(setKey1)); - setValue1 = {4, 5}; - intent_->SetLongArrayParam(setKey1, setValue1); - EXPECT_EQ(defaultValue, intent_->GetLongArrayParam(setKey2)); -} - -using testFloatType = std::tuple; -class IntentParametersFloatTest : public testing::TestWithParam { -public: - IntentParametersFloatTest() : intent_(nullptr) - {} - ~IntentParametersFloatTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersFloatTest::SetUpTestCase(void) -{} - -void IntentParametersFloatTest::TearDownTestCase(void) -{} - -void IntentParametersFloatTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersFloatTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetFloatParam/GetFloatParam - * SubFunction: NA - * FunctionPoints: SetFloatParam/GetFloatParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersFloatTest, AaFwk_Intent_Parameters_Float, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - float setValue = std::get<2>(GetParam()); - float defaultValue = std::get<3>(GetParam()); - float result = std::get<4>(GetParam()); - intent_->SetFloatParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetFloatParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersFloatTestCaseP, IntentParametersFloatTest, - testing::Values(testFloatType("", "aa", -1.1, 100.1, 100.1), testFloatType("", "", -9.1, -41.1, -9.1), - testFloatType("1*中_aR", "aa", 50.1, 5.1, 5.1), testFloatType("1*中_aR", "1*中_aR", -5000.1, 5000.1, -5000.1))); - -/* - * Feature: Intent - * Function: SetFloatParam & GetFloatParam - * SubFunction: NA - * FunctionPoints: SetFloatParam & GetFloatParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersFloatTest, AaFwk_Intent_Parameters_Float_001, TestSize.Level1) -{ - float defaultValue = 100.1; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetFloatParam(key, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetFloatParam & GetFloatParam - * SubFunction: NA - * FunctionPoints: SetFloatParam & GetFloatParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersFloatTest, AaFwk_Intent_Parameters_Float_002, TestSize.Level1) -{ - std::string setKey1 = ""; - std::string setKey2 = "aa"; - float setValue1 = 1.1; - float setValue2 = 5.1; - intent_->SetFloatParam(setKey1, setValue1); - intent_->SetFloatParam(setKey1, setValue1); - setValue1 = 2.1; - intent_->SetFloatParam(setKey1, setValue1); - setValue1 = 3.1; - EXPECT_EQ(setValue1, intent_->GetFloatParam(setKey2, setValue1)); - setValue1 = 4.1; - intent_->SetFloatParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetFloatParam(setKey1, setValue2)); -} - -/* - * Feature: Intent - * Function: SetFloatParam & GetFloatParam - * SubFunction: NA - * FunctionPoints: SetFloatParam & GetFloatParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersFloatTest, AaFwk_Intent_Parameters_Float_003, TestSize.Level1) -{ - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - float setValue1 = -1.1; - float setValue2 = 9.1; - intent_->SetFloatParam(setKey1, setValue1); - intent_->SetFloatParam(setKey1, setValue1); - setValue1 = 0.1; - intent_->SetFloatParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetFloatParam(setKey1, setValue2)); - setValue1 = 4.1; - intent_->SetFloatParam(setKey1, setValue1); - setValue1 = -10.1; - EXPECT_EQ(setValue1, intent_->GetFloatParam(setKey2, setValue1)); -} - -using testFloatArrayType = - std::tuple, std::vector, std::vector>; -class IntentParametersFloatArrayTest : public testing::TestWithParam { -public: - IntentParametersFloatArrayTest() : intent_(nullptr) - {} - ~IntentParametersFloatArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersFloatArrayTest::SetUpTestCase(void) -{} - -void IntentParametersFloatArrayTest::TearDownTestCase(void) -{} - -void IntentParametersFloatArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersFloatArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetFloatArrayParam/GetFloatArrayParam - * SubFunction: NA - * FunctionPoints: SetFloatArrayParam/GetFloatArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersFloatArrayTest, AaFwk_Intent_Parameters_FloatArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetFloatArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetFloatArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersFloatArrayTestCaseP, IntentParametersFloatArrayTest, - testing::Values(testFloatArrayType("", "aa", {-1.1, -2.1}, {}, {}), - testFloatArrayType("", "", {-41.1, -42.1}, {}, {-41.1, -42.1}), - testFloatArrayType("1*中_aR", "aa", {50.1, 51.1}, {}, {}), - testFloatArrayType("1*中_aR", "1*中_aR", {5000.1, 5001.1}, {}, {5000.1, 5001.1}))); - -/* - * Feature: Intent - * Function: SetFloatArrayParam & GetFloatArrayParam - * SubFunction: NA - * FunctionPoints: SetFloatArrayParam & GetFloatArrayParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersFloatArrayTest, AaFwk_Intent_Parameters_Float_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetFloatArrayParam(key)); -} - -/* - * Feature: Intent - * Function: SetFloatArrayParam & GetFloatArrayParam - * SubFunction: NA - * FunctionPoints: SetFloatArrayParam & GetFloatArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersFloatArrayTest, AaFwk_Intent_Parameters_Float_Array_002, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = ""; - std::string setKey2 = "aa"; - std::vector setValue1 = {1.1, 2.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - intent_->SetFloatArrayParam(setKey1, setValue1); - setValue1 = {2.1, 3.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - EXPECT_EQ(defaultValue, intent_->GetFloatArrayParam(setKey2)); - setValue1 = {4.1, 5.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetFloatArrayParam(setKey1)); -} - -/* - * Feature: Intent - * Function: SetFloatArrayParam & GetFloatArrayParam - * SubFunction: NA - * FunctionPoints: SetFloatArrayParam & GetFloatArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersFloatArrayTest, AaFwk_Intent_Parameters_Float_Array_003, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - std::vector setValue1 = {-1.1, -2.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - intent_->SetFloatArrayParam(setKey1, setValue1); - setValue1 = {0.1, 1.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetFloatArrayParam(setKey1)); - setValue1 = {4.1, 5.1}; - intent_->SetFloatArrayParam(setKey1, setValue1); - EXPECT_EQ(defaultValue, intent_->GetFloatArrayParam(setKey2)); -} - -using testDoubleType = std::tuple; -class IntentParametersDoubleTest : public testing::TestWithParam { -public: - IntentParametersDoubleTest() : intent_(nullptr) - {} - ~IntentParametersDoubleTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersDoubleTest::SetUpTestCase(void) -{} - -void IntentParametersDoubleTest::TearDownTestCase(void) -{} - -void IntentParametersDoubleTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersDoubleTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetDoubleParam/GetDoubleParam - * SubFunction: NA - * FunctionPoints: SetDoubleParam/GetDoubleParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersDoubleTest, AaFwk_Intent_Parameters_Double, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - double setValue = std::get<2>(GetParam()); - double defaultValue = std::get<3>(GetParam()); - double result = std::get<4>(GetParam()); - intent_->SetDoubleParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetDoubleParam(getKey, defaultValue)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersDoubleTestCaseP, IntentParametersDoubleTest, - testing::Values(testDoubleType("", "aa", -1.1, 100.1, 100.1), testDoubleType("", "", -9.1, -41.1, -9.1), - testDoubleType("1*中_aR", "aa", 50.1, 5.1, 5.1), - testDoubleType("1*中_aR", "1*中_aR", -5000.1, 5000.1, -5000.1))); - -/* - * Feature: Intent - * Function: SetDoubleParam & GetDoubleParam - * SubFunction: NA - * FunctionPoints: SetDoubleParam & GetDoubleParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersDoubleTest, AaFwk_Intent_Parameters_Double_001, TestSize.Level1) -{ - double defaultValue = 100.1; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetDoubleParam(key, defaultValue)); -} - -/* - * Feature: Intent - * Function: SetDoubleParam & GetDoubleParam - * SubFunction: NA - * FunctionPoints: SetDoubleParam & GetDoubleParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersDoubleTest, AaFwk_Intent_Parameters_Double_002, TestSize.Level1) -{ - std::string setKey1 = ""; - std::string setKey2 = "aa"; - double setValue1 = 1.1; - double setValue2 = 5.1; - intent_->SetDoubleParam(setKey1, setValue1); - intent_->SetDoubleParam(setKey1, setValue1); - setValue1 = 2.1; - intent_->SetDoubleParam(setKey1, setValue1); - setValue1 = 3.1; - EXPECT_EQ(setValue1, intent_->GetDoubleParam(setKey2, setValue1)); - setValue1 = 4.1; - intent_->SetDoubleParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetDoubleParam(setKey1, setValue2)); -} - -/* - * Feature: Intent - * Function: SetDoubleParam & GetDoubleParam - * SubFunction: NA - * FunctionPoints: SetDoubleParam & GetDoubleParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersDoubleTest, AaFwk_Intent_Parameters_Double_003, TestSize.Level1) -{ - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - double setValue1 = -1.1; - double setValue2 = 9.1; - intent_->SetDoubleParam(setKey1, setValue1); - intent_->SetDoubleParam(setKey1, setValue1); - setValue1 = 0.1; - intent_->SetDoubleParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetDoubleParam(setKey1, setValue2)); - setValue1 = 4.1; - intent_->SetDoubleParam(setKey1, setValue1); - setValue1 = -10.1; - EXPECT_EQ(setValue1, intent_->GetDoubleParam(setKey2, setValue1)); -} - -using testDoubleArrayType = - std::tuple, std::vector, std::vector>; -class IntentParametersDoubleArrayTest : public testing::TestWithParam { -public: - IntentParametersDoubleArrayTest() : intent_(nullptr) - {} - ~IntentParametersDoubleArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersDoubleArrayTest::SetUpTestCase(void) -{} - -void IntentParametersDoubleArrayTest::TearDownTestCase(void) -{} - -void IntentParametersDoubleArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersDoubleArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetDoubleArrayParam/GetDoubleArrayParam - * SubFunction: NA - * FunctionPoints: SetDoubleArrayParam/GetDoubleArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersDoubleArrayTest, AaFwk_Intent_Parameters_DoubleArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetDoubleArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetDoubleArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersDoubleArrayTestCaseP, IntentParametersDoubleArrayTest, - testing::Values(testDoubleArrayType("", "aa", {-1.1, -2.1}, {}, {}), - testDoubleArrayType("", "", {-41.1, -42.1}, {}, {-41.1, -42.1}), - testDoubleArrayType("1*中_aR", "aa", {50.1, 51.1}, {}, {}), - testDoubleArrayType("1*中_aR", "1*中_aR", {5000.1, 5001.1}, {}, {5000.1, 5001.1}))); - -/* - * Feature: Intent - * Function: SetDoubleArrayParam & GetDoubleArrayParam - * SubFunction: NA - * FunctionPoints: SetDoubleArrayParam & GetDoubleArrayParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersDoubleArrayTest, AaFwk_Intent_Parameters_Double_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string key = "aa"; - EXPECT_EQ(defaultValue, intent_->GetDoubleArrayParam(key)); -} - -/* - * Feature: Intent - * Function: SetDoubleArrayParam & GetDoubleArrayParam - * SubFunction: NA - * FunctionPoints: SetDoubleArrayParam & GetDoubleArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersDoubleArrayTest, AaFwk_Intent_Parameters_Double_Array_002, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = ""; - std::string setKey2 = "aa"; - std::vector setValue1 = {1.1, 2.1}; - std::vector setValue2 = {5.1, 6.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - intent_->SetDoubleArrayParam(setKey1, setValue1); - setValue1 = {2.1, 3.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - EXPECT_EQ(defaultValue, intent_->GetDoubleArrayParam(setKey2)); - setValue1 = {4.1, 5.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetDoubleArrayParam(setKey1)); -} - -/* - * Feature: Intent - * Function: SetDoubleArrayParam & GetDoubleArrayParam - * SubFunction: NA - * FunctionPoints: SetDoubleArrayParam & GetDoubleArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersDoubleArrayTest, AaFwk_Intent_Parameters_Double_Array_003, TestSize.Level1) -{ - std::vector defaultValue; - std::string setKey1 = "%1uH3"; - std::string setKey2 = "aa"; - std::vector setValue1 = {-1.1, -2.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - intent_->SetDoubleArrayParam(setKey1, setValue1); - setValue1 = {0.1, 1.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - EXPECT_EQ(setValue1, intent_->GetDoubleArrayParam(setKey1)); - setValue1 = {4.1, 5.1}; - intent_->SetDoubleArrayParam(setKey1, setValue1); - setValue1 = {-10.1, -11.1}; - EXPECT_EQ(defaultValue, intent_->GetDoubleArrayParam(setKey2)); -} - -using testStrType = std::tuple; -class IntentParametersStringTest : public testing::TestWithParam { -public: - IntentParametersStringTest() : intent_(nullptr) - {} - ~IntentParametersStringTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersStringTest::SetUpTestCase(void) -{} - -void IntentParametersStringTest::TearDownTestCase(void) -{} - -void IntentParametersStringTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersStringTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetStringParam/GetStringParam - * SubFunction: NA - * FunctionPoints: SetStringParam/GetStringParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersStringTest, AaFwk_Intent_Parameters_String, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::string setValue = std::get<2>(GetParam()); - std::string defaultValue = std::get<3>(GetParam()); - std::string result = std::get<4>(GetParam()); - intent_->SetStringParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetStringParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersStringTestCaseP, IntentParametersStringTest, - testing::Values(testStrType("", "aa", "1*中_aR", "", ""), testStrType("", "", "1*中_aR", "", "1*中_aR"), - testStrType("1*中_aR", "aa", "aaa", "", ""), testStrType("1*中_aR", "1*中_aR", "aaa", "", "aaa"))); - -/* - * Feature: Intent - * Function: SetStringParam & GetStringParam - * SubFunction: NA - * FunctionPoints: SetStringParam & GetStringParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersStringTest, AaFwk_Intent_Parameters_String_001, TestSize.Level1) -{ - std::string defaultStrValue; - std::string key = "aa"; - EXPECT_EQ(defaultStrValue, intent_->GetStringParam(key)); -} - -/* - * Feature: Intent - * Function: SetStringParam & GetStringParam - * SubFunction: NA - * FunctionPoints: SetStringParam & GetStringParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersStringTest, AaFwk_Intent_Parameters_String_002, TestSize.Level1) -{ - std::string defaultStrValue; - std::string setValue1 = "aaa"; - std::string setValue2 = "1*中_aR"; - std::string key1 = ""; - std::string key2 = "aa"; - intent_->SetStringParam(key1, setValue1); - intent_->SetStringParam(key1, setValue1); - intent_->SetStringParam(key1, setValue2); - EXPECT_EQ(defaultStrValue, intent_->GetStringParam(key2)); - intent_->SetStringParam(key1, setValue1); - EXPECT_EQ(setValue1, intent_->GetStringParam(key1)); -} - -/* - * Feature: Intent - * Function: SetStringParam & GetStringParam - * SubFunction: NA - * FunctionPoints: SetStringParam & GetStringParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersStringTest, AaFwk_Intent_Parameters_String_003, TestSize.Level1) -{ - std::string key1 = "%1uH3"; - std::string defaultStrValue; - std::string setValue1 = "aaa"; - std::string setValue2 = "1*中_aR"; - std::string key2 = "aa"; - intent_->SetStringParam(key1, setValue1); - intent_->SetStringParam(key1, setValue1); - intent_->SetStringParam(key1, setValue2); - EXPECT_EQ("1*中_aR", intent_->GetStringParam(key1)); - intent_->SetStringParam(key1, setValue1); - EXPECT_EQ(defaultStrValue, intent_->GetStringParam(key2)); -} - -using testStrArrayType = - std::tuple, std::vector, std::vector>; -class IntentParametersStringArrayTest : public testing::TestWithParam { -public: - IntentParametersStringArrayTest() : intent_(nullptr) - {} - ~IntentParametersStringArrayTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersStringArrayTest::SetUpTestCase(void) -{} - -void IntentParametersStringArrayTest::TearDownTestCase(void) -{} - -void IntentParametersStringArrayTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersStringArrayTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: SetStringArrayParam/GetStringArrayParam - * SubFunction: NA - * FunctionPoints: SetStringArrayParam/GetStringArrayParam - * EnvConditions: NA - * CaseDescription: Verify when parameter change. - */ -HWTEST_P(IntentParametersStringArrayTest, AaFwk_Intent_Parameters_StringArray, TestSize.Level1) -{ - std::string setKey = std::get<0>(GetParam()); - std::string getKey = std::get<1>(GetParam()); - std::vector setValue = std::get<2>(GetParam()); - std::vector defaultValue = std::get<3>(GetParam()); - std::vector result = std::get<4>(GetParam()); - intent_->SetStringArrayParam(setKey, setValue); - EXPECT_EQ(result, intent_->GetStringArrayParam(getKey)); -} - -INSTANTIATE_TEST_CASE_P(IntentParametersStringArrayTestCaseP, IntentParametersStringArrayTest, - testing::Values(testStrArrayType("", "aa", {"1*中_aR", "dadb"}, {}, {}), - testStrArrayType("", "", {"1*中_aR", "dadb"}, {}, {"1*中_aR", "dadb"}), - testStrArrayType("1*中_aR", "aa", {"1*中_aR", "dadb"}, {}, {}), - testStrArrayType("1*中_aR", "1*中_aR", {"1*中_aR", "dadb"}, {}, {"1*中_aR", "dadb"}))); - -/* - * Feature: Intent - * Function: SetStringArrayParam & GetStringArrayParam - * SubFunction: NA - * FunctionPoints: SetStringArrayParam & GetStringArrayParam - * EnvConditions: NA - * CaseDescription: get param when IntentParam is empty - */ -HWTEST_F(IntentParametersStringArrayTest, AaFwk_Intent_Parameters_String_Array_001, TestSize.Level1) -{ - std::vector defaultValue; - std::string key = "aa"; - std::vector resultValue = intent_->GetStringArrayParam(key); - EXPECT_EQ(defaultValue, resultValue); -} - -/* - * Feature: Intent - * Function: SetStringArrayParam & GetStringArrayParam - * SubFunction: NA - * FunctionPoints: SetStringArrayParam & GetStringArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, but get param of another nonexistent key - */ -HWTEST_F(IntentParametersStringArrayTest, AaFwk_Intent_Parameters_String_Array_002, TestSize.Level1) -{ - std::vector defaultValue; - std::vector setValue1 = {"aaa", "2132"}; - std::vector setValue2 = {"1*中_aR", "dadb"}; - std::string key1 = ""; - std::string key2 = "aa"; - intent_->SetStringArrayParam(key1, setValue1); - intent_->SetStringArrayParam(key1, setValue1); - intent_->SetStringArrayParam(key1, setValue2); - std::vector resultValue = intent_->GetStringArrayParam(key2); - EXPECT_EQ(defaultValue, resultValue); - - intent_->SetStringArrayParam(key1, setValue1); - resultValue = intent_->GetStringArrayParam(key1); - EXPECT_EQ(setValue1, resultValue); -} - -/* - * Feature: Intent - * Function: SetStringArrayParam & GetStringArrayParam - * SubFunction: NA - * FunctionPoints: SetStringArrayParam & GetStringArrayParam - * EnvConditions: NA - * CaseDescription: set empty-string key repeatedly, then get param of the key - */ -HWTEST_F(IntentParametersStringArrayTest, AaFwk_Intent_Parameters_String_Array_003, TestSize.Level1) -{ - std::vector defaultValue; - std::vector setValue = {"aaa", "2132"}; - std::string key1 = "%1uH3"; - std::string key2 = "aa"; - intent_->SetStringArrayParam(key1, setValue); - intent_->SetStringArrayParam(key1, setValue); - setValue = {"1*中_aR", "3#$%"}; - intent_->SetStringArrayParam(key1, setValue); - std::vector resultValue = intent_->GetStringArrayParam(key1); - EXPECT_EQ(setValue, resultValue); - - setValue = {"aaa", "2132"}; - intent_->SetStringArrayParam(key1, setValue); - resultValue = intent_->GetStringArrayParam(key2); - EXPECT_EQ(defaultValue, resultValue); -} - -class IntentParametersHasParamTest : public testing::Test { -public: - IntentParametersHasParamTest() : intent_(nullptr) - {} - ~IntentParametersHasParamTest() - { - intent_ = nullptr; - } - static void SetUpTestCase(void); - static void TearDownTestCase(void); - void SetUp(); - void TearDown(); - Intent *intent_; -}; - -void IntentParametersHasParamTest::SetUpTestCase(void) -{} - -void IntentParametersHasParamTest::TearDownTestCase(void) -{} - -void IntentParametersHasParamTest::SetUp(void) -{ - intent_ = new (std::nothrow) Intent(); -} - -void IntentParametersHasParamTest::TearDown(void) -{ - delete intent_; - intent_ = nullptr; -} - -/* - * Feature: Intent - * Function: HasParameter - * SubFunction: NA - * FunctionPoints: HasParameter - * EnvConditions: NA - * CaseDescription: verify if parameter exists - */ -HWTEST_F(IntentParametersHasParamTest, AaFwk_Intent_Parameters_Has_Parameter_001, TestSize.Level1) -{ - std::string keyBool = "keyBool"; - std::string keyChar = "keyChar"; - std::string keyShort = "keyShort"; - std::string keyInt = "keyInt"; - std::string keyLong = "keyLong"; - std::string keyFloat = "keyFloat"; - std::string keyDouble = "keyDouble"; - std::string keyString = "keyString"; - std::string keyBoolArray = "keyBoolArray"; - std::string keyCharArray = "keyCharArray"; - std::string keyShortArray = "keyShortArray"; - std::string keyIntArray = "keyIntArray"; - std::string keyLongArray = "keyLongArray"; - std::string keyFloatArray = "keyFloatArray"; - std::string keyDoubleArray = "keyDoubleArray"; - std::string keyStringArray = "keyStringArray"; - - std::string keyBoolNotExist = "keyBoolNotExist"; - std::string keyCharNotExist = "keyCharNotExist"; - std::string keyShortNotExist = "keyShortNotExist"; - std::string keyIntNotExist = "keyIntNotExist"; - std::string keyLongNotExist = "keyLongNotExist"; - std::string keyFloatNotExist = "keyFloatNotExist"; - std::string keyDoubleNotExist = "keyDoubleNotExist"; - std::string keyStringNotExist = "keyStringNotExist"; - std::string keyBoolArrayNotExist = "keyBoolArrayNotExist"; - std::string keyCharArrayNotExist = "keyCharArrayNotExist"; - std::string keyShortArrayNotExist = "keyShortArrayNotExist"; - std::string keyIntArrayNotExist = "keyIntArrayNotExist"; - std::string keyLongArrayNotExist = "keyLongArrayNotExist"; - std::string keyFloatArrayNotExist = "keyFloatArrayNotExist"; - std::string keyDoubleArrayNotExist = "keyDoubleArrayNotExist"; - std::string keyStringArrayNotExist = "keyStringArrayNotExist"; - - bool valueBool = false; - zchar valueChar = 1; - short valueShort = 2; - int valueInt = 3; - long valueLong = 4; - float valueFloat = 5.1; - double valueDouble = 6.2; - std::string valueString = "1*中_aRabc"; - std::vector valueBoolArray = {true, false}; - std::vector valueCharArray = {1, 2}; - std::vector valueShortArray = {3, 4}; - std::vector valueIntArray = {5, 6}; - std::vector valueLongArray = {7, 8}; - std::vector valueFloatArray = {9.1, 10.2}; - std::vector valueDoubleArray = {11.3, 12.4}; - std::vector valueStringArray = {"1*中_aRabc", "1*中_aRpinyin"}; - - intent_->SetBoolParam(keyBool, valueBool); - intent_->SetCharParam(keyChar, valueChar); - intent_->SetShortParam(keyShort, valueShort); - intent_->SetIntParam(keyInt, valueInt); - intent_->SetLongParam(keyLong, valueLong); - intent_->SetFloatParam(keyFloat, valueFloat); - intent_->SetDoubleParam(keyDouble, valueDouble); - intent_->SetStringParam(keyString, valueString); - - intent_->SetBoolArrayParam(keyBoolArray, valueBoolArray); - intent_->SetCharArrayParam(keyCharArray, valueCharArray); - intent_->SetShortArrayParam(keyShortArray, valueShortArray); - intent_->SetIntArrayParam(keyIntArray, valueIntArray); - intent_->SetLongArrayParam(keyLongArray, valueLongArray); - intent_->SetFloatArrayParam(keyFloatArray, valueFloatArray); - intent_->SetDoubleArrayParam(keyDoubleArray, valueDoubleArray); - intent_->SetStringArrayParam(keyStringArray, valueStringArray); - - EXPECT_EQ(true, intent_->HasParameter(keyBool)); - EXPECT_EQ(true, intent_->HasParameter(keyChar)); - EXPECT_EQ(true, intent_->HasParameter(keyShort)); - EXPECT_EQ(true, intent_->HasParameter(keyInt)); - EXPECT_EQ(true, intent_->HasParameter(keyLong)); - EXPECT_EQ(true, intent_->HasParameter(keyFloat)); - EXPECT_EQ(true, intent_->HasParameter(keyDouble)); - EXPECT_EQ(true, intent_->HasParameter(keyString)); - EXPECT_EQ(true, intent_->HasParameter(keyBoolArray)); - EXPECT_EQ(true, intent_->HasParameter(keyCharArray)); - EXPECT_EQ(true, intent_->HasParameter(keyShortArray)); - EXPECT_EQ(true, intent_->HasParameter(keyIntArray)); - EXPECT_EQ(true, intent_->HasParameter(keyLongArray)); - EXPECT_EQ(true, intent_->HasParameter(keyFloatArray)); - EXPECT_EQ(true, intent_->HasParameter(keyDoubleArray)); - EXPECT_EQ(true, intent_->HasParameter(keyStringArray)); - - EXPECT_EQ(false, intent_->HasParameter(keyBoolNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyCharNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyShortNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyIntNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyLongNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyFloatNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyDoubleNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyStringNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyBoolArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyCharArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyShortArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyIntArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyLongArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyFloatArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyDoubleArrayNotExist)); - EXPECT_EQ(false, intent_->HasParameter(keyStringArrayNotExist)); -} diff --git a/frameworks/kits/content/cpp/test/unittest/common/skills_test.cpp b/frameworks/kits/content/cpp/test/unittest/common/skills_test.cpp index 0780a86cbc..03876c881a 100644 --- a/frameworks/kits/content/cpp/test/unittest/common/skills_test.cpp +++ b/frameworks/kits/content/cpp/test/unittest/common/skills_test.cpp @@ -735,8 +735,8 @@ HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level std::string filterEntity = "entity.system.entity1"; std::string filterAction1 = "action.system.action1"; std::string filterAction2 = "action.system.action2"; - std::string intentEntity = std::get<0>(GetParam()); - std::string intentAction = std::get<1>(GetParam()); + std::string wantEntity = std::get<0>(GetParam()); + std::string wantAction = std::get<1>(GetParam()); bool result = std::get<2>(GetParam()); skills_->AddEntity(filterEntity); @@ -744,8 +744,8 @@ HWTEST_P(SkillsMatchTest, AaFwk_Skills_match_0100, Function | MediumTest | Level skills_->AddAction(filterAction2); Want want; - want.AddEntity(intentEntity); - want.SetAction(intentAction); + want.AddEntity(wantEntity); + want.SetAction(wantAction); EXPECT_EQ(result, skills_->Match(want)); } diff --git a/frameworks/kits/test/BUILD.gn b/frameworks/kits/test/BUILD.gn index 705e921009..325652a4d3 100644 --- a/frameworks/kits/test/BUILD.gn +++ b/frameworks/kits/test/BUILD.gn @@ -17,8 +17,6 @@ import("//foundation/aafwk/standard/feature.gni") module_output_path = "ability_runtime/aafwk_L2" ############################################################################### -#1. intent(c++) get/set test without transport - config("module_private_config") { visibility = [ ":*" ] cflags = [] diff --git a/frameworks/kits/wantagent/test/unittest/pending_want_test/pending_want_test.cpp b/frameworks/kits/wantagent/test/unittest/pending_want_test/pending_want_test.cpp index 26bb63e37d..afd536915d 100644 --- a/frameworks/kits/wantagent/test/unittest/pending_want_test/pending_want_test.cpp +++ b/frameworks/kits/wantagent/test/unittest/pending_want_test/pending_want_test.cpp @@ -434,8 +434,16 @@ HWTEST_F(PendingWantTest, PendingWant_1800, Function | MediumTest | Level1) */ HWTEST_F(PendingWantTest, PendingWant_1900, Function | MediumTest | Level1) { - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); + 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; + WantAgentConstant::OperationType type = WantAgentConstant::OperationType::START_FOREGROUND_SERVICE; + std::shared_ptr pendingWant = + PendingWant::BuildServicePendingWant(nullptr, requestCode, want, flags, type); + sptr target2(nullptr); std::shared_ptr pendingWant2 = std::make_shared(target2); EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), false); @@ -477,19 +485,6 @@ HWTEST_F(PendingWantTest, PendingWant_2100, Function | MediumTest | Level1) pendingWant.SendAndReturnResult(requestCode, want, nullptr, "Permission", nullptr, nullptr)); } -/* - * @tc.number : PendingWant_2300 - * @tc.name : PendingWant Equals - * @tc.desc : Equals - */ -HWTEST_F(PendingWantTest, PendingWant_2300, Function | MediumTest | Level1) -{ - sptr target(new (std::nothrow) WantSender()); - std::shared_ptr pendingWant = std::make_shared(target); - std::shared_ptr pendingWant2 = std::make_shared(target); - EXPECT_EQ(pendingWant->Equals(pendingWant, pendingWant2), true); -} - /* * @tc.number : PendingWant_2400 * @tc.name : PendingWant GetTarget diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index a457beceab..4c067bdcf1 100644 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -17,7 +17,6 @@ group("innerkits_target") { "ability_manager:ability_manager", "app_manager:app_manager", "dataobs_manager:dataobs_manager", - "intent:intent", "uri_permission:uri_permission_mgr", "want:want", ] diff --git a/interfaces/innerkits/ability_manager/BUILD.gn b/interfaces/innerkits/ability_manager/BUILD.gn index 257d62ab6c..ce39e4303c 100644 --- a/interfaces/innerkits/ability_manager/BUILD.gn +++ b/interfaces/innerkits/ability_manager/BUILD.gn @@ -96,7 +96,6 @@ ohos_shared_library("ability_manager") { ] deps = [ - "${appexecfwk_path}/common:libappexecfwk_common", "${kits_path}/ability/native:dummy_classes", "//third_party/jsoncpp:jsoncpp", ] diff --git a/interfaces/innerkits/app_manager/BUILD.gn b/interfaces/innerkits/app_manager/BUILD.gn index b39a1bf38f..a225fb6057 100644 --- a/interfaces/innerkits/app_manager/BUILD.gn +++ b/interfaces/innerkits/app_manager/BUILD.gn @@ -80,7 +80,7 @@ ohos_shared_library("app_manager") { if (target_cpu == "arm") { cflags += [ "-DBINDER_IPC_32BIT" ] } - deps = [ "${appexecfwk_path}/common:libappexecfwk_common" ] + deps = [] external_deps = [ "ability_base:base", diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp index 31dd800d3f..50427fb188 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp @@ -289,23 +289,20 @@ int32_t AppMgrStub::HandleGetForegroundApplications(MessageParcel &data, Message int32_t AppMgrStub::HandleStartUserTestProcess(MessageParcel &data, MessageParcel &reply) { - AAFwk::Want *want = data.ReadParcelable(); + std::unique_ptr want(data.ReadParcelable()); if (want == nullptr) { HILOG_ERROR("want is nullptr"); return ERR_INVALID_VALUE; } - BundleInfo *bundleInfo = data.ReadParcelable(); + std::unique_ptr bundleInfo(data.ReadParcelable()); if (bundleInfo == nullptr) { HILOG_ERROR("want is nullptr"); - delete want; return ERR_INVALID_VALUE; } auto observer = data.ReadRemoteObject(); int32_t userId = data.ReadInt32(); int32_t result = StartUserTestProcess(*want, observer, *bundleInfo, userId); reply.WriteInt32(result); - delete want; - delete bundleInfo; return result; } diff --git a/interfaces/innerkits/app_manager/src/appmgr/app_process_data.cpp b/interfaces/innerkits/app_manager/src/appmgr/app_process_data.cpp index 3179c2cf91..db93e31755 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/app_process_data.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/app_process_data.cpp @@ -19,7 +19,7 @@ #include "nlohmann/json.hpp" #include "string_ex.h" -#include "parcel_macro.h" +#include "parcel_macro_ability.h" namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp b/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp index f99f566e11..5f0f191663 100644 --- a/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp +++ b/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp @@ -19,7 +19,7 @@ #include "string_ex.h" #include "hilog_wrapper.h" -#include "parcel_macro.h" +#include "parcel_macro_ability.h" namespace OHOS { namespace AppExecFwk { diff --git a/interfaces/innerkits/intent/BUILD.gn b/interfaces/innerkits/intent/BUILD.gn deleted file mode 100644 index d116a0030a..0000000000 --- a/interfaces/innerkits/intent/BUILD.gn +++ /dev/null @@ -1,71 +0,0 @@ -# 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/ohos.gni") -import("//foundation/aafwk/standard/aafwk.gni") - -config("intent_config") { - visibility = [ ":*" ] - cflags = [] - if (target_cpu == "arm") { - cflags += [ "-DBINDER_IPC_32BIT" ] - } - defines = [ - "AMS_LOG_TAG = \"Ability\"", - "AMS_LOG_DOMAIN = 0xD002200", - ] -} - -config("intent_public_config") { - visibility = [ ":*" ] - include_dirs = [ - "//utils/native/base/include", - "${innerkits_path}/intent/include", - "${innerkits_path}/uri/include", - "${services_path}/common/include", - ] -} - -intentImpl = "${kits_path}/content/cpp/src/ohos/aafwk/content" - -ohos_shared_library("intent") { - sources = [ - "${intentImpl}/intent.cpp", - "${intentImpl}/intent_filter.cpp", - "${intentImpl}/intent_params.cpp", - - #"${intentImpl}/operation.cpp", - #"${intentImpl}/patterns_matcher.cpp", - #"${intentImpl}/skills.cpp", - #"${intentImpl}/want_params.cpp", - #"${intentImpl}/want.cpp", - ] - - deps = [] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "ability_base:zuri", - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "safwk:system_ability_fwk", - "samgr_standard:lsamgr", - "utils_base:utils", - ] - - configs = [ ":intent_config" ] - public_configs = [ ":intent_public_config" ] - subsystem_name = "aafwk" - part_name = "ability_runtime" -} diff --git a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent.h b/interfaces/innerkits/intent/include/ohos/aafwk/content/intent.h deleted file mode 100644 index 09cf52afe8..0000000000 --- a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - * 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. - */ -#ifndef OHOS_AAFWK_INTENT_H -#define OHOS_AAFWK_INTENT_H - -#include -#include - -#include "intent_params.h" - -#include "element_name.h" -#include "parcel.h" - -namespace OHOS { -namespace AAFwk { - -class Intent final : public Parcelable { -public: - Intent(); - inline ~Intent() - {} - - static Intent *ParseUri(const std::string &uri); - std::string ToUri(); - - std::string GetAction() const; - Intent &SetAction(const std::string &action); - - unsigned int GetFlags() const; - Intent &SetFlag(const unsigned int flag); - Intent &AddFlag(const unsigned int flag); - void RemoveFlags(const unsigned int flag); - - std::string GetEntity() const; - Intent &SetEntity(const std::string &entity); - - OHOS::AppExecFwk::ElementName GetElement() const; - Intent &SetElement(const OHOS::AppExecFwk::ElementName &element); - - bool GetBoolParam(const std::string &key, const bool defaultValue); - Intent &SetBoolParam(const std::string &key, const bool value); - std::vector GetBoolArrayParam(const std::string &key); - Intent &SetBoolArrayParam(const std::string &key, const std::vector &value); - - zchar GetCharParam(const std::string &key, const zchar defaultValue); - Intent &SetCharParam(const std::string &key, const zchar value); - std::vector GetCharArrayParam(const std::string &key); - Intent &SetCharArrayParam(const std::string &key, const std::vector &value); - - byte GetByteParam(const std::string &key, const byte defaultValue); - Intent &SetByteParam(const std::string &key, const byte value); - std::vector GetByteArrayParam(const std::string &key); - Intent &SetByteArrayParam(const std::string &key, const std::vector &value); - - short GetShortParam(const std::string &key, const short defaultValue); - Intent &SetShortParam(const std::string &key, const short value); - std::vector GetShortArrayParam(const std::string &key); - Intent &SetShortArrayParam(const std::string &key, const std::vector &value); - - int GetIntParam(const std::string &key, const int defaultValue); - Intent &SetIntParam(const std::string &key, const int value); - std::vector GetIntArrayParam(const std::string &key); - Intent &SetIntArrayParam(const std::string &key, const std::vector &value); - - long GetLongParam(const std::string &key, const long defaultValue); - Intent &SetLongParam(const std::string &key, const long value); - std::vector GetLongArrayParam(const std::string &key); - Intent &SetLongArrayParam(const std::string &key, const std::vector &value); - - float GetFloatParam(const std::string &key, const float defaultValue); - Intent &SetFloatParam(const std::string &key, const float value); - std::vector GetFloatArrayParam(const std::string &key); - Intent &SetFloatArrayParam(const std::string &key, const std::vector &value); - - double GetDoubleParam(const std::string &key, const double defaultValue); - Intent &SetDoubleParam(const std::string &key, const double value); - std::vector GetDoubleArrayParam(const std::string &key); - Intent &SetDoubleArrayParam(const std::string &key, const std::vector &value); - - std::string GetStringParam(const std::string &key); - Intent &SetStringParam(const std::string &key, const std::string &value); - std::vector GetStringArrayParam(const std::string &key); - Intent &SetStringArrayParam(const std::string &key, const std::vector &value); - - bool HasParameter(const std::string &key) const; - - virtual bool Marshalling(Parcel &parcel) const; - - static Intent *Unmarshalling(Parcel &parcel); - -public: - // action definition - static const std::string ACTION_PLAY; - - // entity definition - static const std::string ENTITY_HOME; - static const std::string ENTITY_VIDEO; - - // flag definition - static constexpr unsigned int FLAG_ABILITY_NEW_MISSION = 0x00000001; - -private: - std::string action_; - unsigned int flags_; - std::string entity_; - IntentParams parameters_; - - OHOS::AppExecFwk::ElementName element_; - - static const std::string OCT_EQUALSTO; - static const std::string OCT_SEMICOLON; - - // no object in parcel - static constexpr int VALUE_NULL = -1; - // object exist in parcel - static constexpr int VALUE_OBJECT = 1; - -private: - static bool ParseFlag(const std::string &content, Intent &intent); - static std::string Decode(const std::string &str); - static std::string Encode(const std::string &str); - static bool ParseContent(const std::string &content, std::string &prop, std::string &value); - static bool ParseUriInternal(const std::string &content, OHOS::AppExecFwk::ElementName &element, Intent &intent); - bool ReadFromParcel(Parcel &parcel); -}; - -} // namespace AAFwk -} // namespace OHOS - -#endif // OHOS_AAFWK_INTENT_H diff --git a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_filter.h b/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_filter.h deleted file mode 100644 index f45469483c..0000000000 --- a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_filter.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_AAFWK_INTENT_FILTER_H -#define OHOS_AAFWK_INTENT_FILTER_H - -#include -#include - -#include "parcel.h" - -namespace OHOS { -namespace AAFwk { - -class Intent; -class IntentFilter final : public Parcelable { -public: - IntentFilter(); - inline ~IntentFilter() - {} - - std::string GetEntity() const; - - void SetEntity(const std::string &entity); - - void AddAction(const std::string &action); - - int CountAction() const; - - std::string GetAction(int index) const; - - void RemoveAction(const std::string &action); - - bool HasAction(const std::string &action) const; - - bool Match(const Intent &intent) const; - - virtual bool Marshalling(Parcel &parcel) const; - - static IntentFilter *Unmarshalling(Parcel &parcel); - -private: - bool ReadFromParcel(Parcel &parcel); - bool MatchAction(const std::string &action) const; - bool MatchEntity(const std::string &entity) const; - - std::string entity_; - std::vector actions_; -}; - -} // namespace AAFwk -} // namespace OHOS - -#endif // OHOS_AAFWK_INTENT_FILTER_H diff --git a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_params.h b/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_params.h deleted file mode 100644 index 0936f8943f..0000000000 --- a/interfaces/innerkits/intent/include/ohos/aafwk/content/intent_params.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef OHOS_AAFWK_INTENT_PARAMS_H -#define OHOS_AAFWK_INTENT_PARAMS_H - -#include -#include - -#include "ohos/aafwk/base/base_interfaces.h" -#include "refbase.h" -#include "parcel.h" - -namespace OHOS { -namespace AAFwk { - -class IntentParams final : public Parcelable { -public: - void SetParam(const std::string &key, IInterface *value); - - sptr GetParam(const std::string &key) const; - - const std::map> &GetParams() const; - - bool HasParam(const std::string &key) const; - - virtual bool Marshalling(Parcel &parcel) const; - - static IntentParams *Unmarshalling(Parcel &parcel); - -private: - // Java side should keep consistent. - enum { - VALUE_TYPE_NULL = -1, - VALUE_TYPE_BOOLEAN = 1, - VALUE_TYPE_BYTE = 2, - VALUE_TYPE_CHAR = 3, - VALUE_TYPE_SHORT = 4, - VALUE_TYPE_INT = 5, - VALUE_TYPE_LONG = 6, - VALUE_TYPE_FLOAT = 7, - VALUE_TYPE_DOUBLE = 8, - VALUE_TYPE_STRING = 9, - VALUE_TYPE_CHARSEQUENCE = 10, - VALUE_TYPE_BOOLEANARRAY = 11, - VALUE_TYPE_BYTEARRAY = 12, - VALUE_TYPE_CHARARRAY = 13, - VALUE_TYPE_SHORTARRAY = 14, - VALUE_TYPE_INTARRAY = 15, - VALUE_TYPE_LONGARRAY = 16, - VALUE_TYPE_FLOATARRAY = 17, - VALUE_TYPE_DOUBLEARRAY = 18, - VALUE_TYPE_STRINGARRAY = 19, - VALUE_TYPE_CHARSEQUENCEARRAY = 20, - }; - - bool WriteArrayToParcel(Parcel &parcel, IArray *ao) const; - bool ReadArrayToParcel(Parcel &parcel, int type, sptr &ao); - bool ReadFromParcel(Parcel &parcel); - - /* params_ has default construct function, - no need explicit initialization in the construct function */ - std::map> params_; -}; - -} // namespace AAFwk -} // namespace OHOS - -#endif // OHOS_AAFWK_INTENT_PARAMS_H diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h index 2c8d5c138c..3a9cb0eb28 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/ability_monitor.h @@ -29,15 +29,52 @@ namespace AbilityDelegatorJs { using namespace OHOS::AppExecFwk; class AbilityMonitor : public IAbilityMonitor { public: + /** + * A constructor used to create a AbilityMonitor instance with the input parameter passed. + * + * @param name Indicates the specified ability name. + * @param jsAbilityMonitor Indicates the JSAbilityMonitor object. + */ AbilityMonitor(const std::string &name, const std::shared_ptr &jsAbilityMonitor); + + /** + * Default deconstructor used to deconstruct. + */ ~AbilityMonitor() = default; + /** + * Called when ability is started. + */ void OnAbilityStart() override; + + /** + * Called when ability is in foreground. + */ void OnAbilityForeground() override; + + /** + * Called when ability is in background. + */ void OnAbilityBackground() override; + + /** + * Called when ability is stopped. + */ void OnAbilityStop() override; + + /** + * Called when window stage is created. + */ void OnWindowStageCreate() override; + + /** + * Called when window stage is restored. + */ void OnWindowStageRestore() override; + + /** + * Called when window stage is destroyed. + */ void OnWindowStageDestroy() override; private: diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp index f5ffd8e37a..38f9bc83a0 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.cpp @@ -15,6 +15,7 @@ #include "js_ability_delegator.h" +#include #include "ability_delegator_registry.h" #include "ability_runtime/js_ability.h" #include "hilog_wrapper.h" @@ -27,8 +28,8 @@ namespace OHOS { namespace AbilityDelegatorJs { -struct AbilityTokenBox { - sptr token_; +struct AbilityObjectBox { + std::weak_ptr object_; }; struct ShellCmdResultBox { @@ -44,7 +45,33 @@ constexpr int ERROR = -1; using namespace OHOS::AbilityRuntime; std::map, std::shared_ptr> monitorRecord_; -std::map, sptr> ablityRecord_; +std::map, sptr, std::owner_less<>> ablityRecord_; +std::mutex mutexAblityRecord_; + +JSAbilityDelegator::JSAbilityDelegator() +{ + auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); + if (delegator) { + auto clearFunc = [](const std::shared_ptr &property) { + HILOG_INFO("Clear function is called"); + if (!property) { + HILOG_ERROR("Invalid property"); + return; + } + + std::unique_lock lck(mutexAblityRecord_); + for (auto it = ablityRecord_.begin(); it != ablityRecord_.end();) { + if (it->second == property->token_) { + it = ablityRecord_.erase(it); + continue; + } + ++it; + } + }; + + delegator->RegisterClearFunc(clearFunc); + } +} void JSAbilityDelegator::Finalizer(NativeEngine *engine, void *data, void *hint) { @@ -203,38 +230,50 @@ NativeValue *JSAbilityDelegator::OnWaitAbilityMonitor(NativeEngine &engine, Nati return engine.CreateUndefined(); } - auto abilityTokenBox = std::make_shared(); - AsyncTask::ExecuteCallback execute = [monitor, timeout, opt, abilityTokenBox]() { + auto abilityObjectBox = std::make_shared(); + AsyncTask::ExecuteCallback execute = [monitor, timeout, opt, abilityObjectBox]() { HILOG_INFO("OnWaitAbilityMonitor AsyncTask ExecuteCallback is called"); + if (!abilityObjectBox) { + HILOG_ERROR("OnWaitAbilityMonitor AsyncTask ExecuteCallback, Invalid abilityObjectBox"); + return; + } + auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { HILOG_ERROR("OnWaitAbilityMonitor AsyncTask ExecuteCallback, Invalid delegator"); return; } + std::shared_ptr property; if (opt.hasTimeoutPara) { - abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor, timeout); + property = delegator->WaitAbilityMonitor(monitor, timeout); } else { - abilityTokenBox->token_ = delegator->WaitAbilityMonitor(monitor); + property = delegator->WaitAbilityMonitor(monitor); } + + if (!property || property->object_.expired()) { + HILOG_ERROR("Invalid property"); + return; + } + + abilityObjectBox->object_ = property->object_; + + std::unique_lock lck(mutexAblityRecord_); + ablityRecord_.emplace(property->object_, property->token_); }; - AsyncTask::CompleteCallback complete = - [abilityTokenBox, this](NativeEngine &engine, AsyncTask &task, int32_t status) { - HILOG_INFO("OnWaitAbilityMonitor AsyncTask CompleteCallback is called"); - NativeValue *ability = CreateAbilityObject(engine, abilityTokenBox->token_); - if (ability) { - task.Resolve(engine, ability); - } else { - task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed.")); - } - }; + AsyncTask::CompleteCallback complete = [abilityObjectBox](NativeEngine &engine, AsyncTask &task, int32_t status) { + HILOG_INFO("OnWaitAbilityMonitor AsyncTask CompleteCallback is called"); + if (abilityObjectBox && !abilityObjectBox->object_.expired()) { + task.Resolve(engine, abilityObjectBox->object_.lock()->Get()); + } else { + task.Reject(engine, CreateJsError(engine, ERROR, "waitAbilityMonitor failed.")); + } + }; NativeValue *lastParam = nullptr; if (opt.hasCallbackPara) { lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE]; - } else { - lastParam = nullptr; } NativeValue *result = nullptr; @@ -286,6 +325,11 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat auto shellCmdResultBox = std::make_shared(); AsyncTask::ExecuteCallback execute = [cmd, timeoutSecs, shellCmdResultBox]() { HILOG_INFO("OnExecuteShellCommand AsyncTask ExecuteCallback is called"); + if (!shellCmdResultBox) { + HILOG_ERROR("OnExecuteShellCommand AsyncTask ExecuteCallback, Invalid shellCmdResultBox"); + return; + } + auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { HILOG_ERROR("OnExecuteShellCommand AsyncTask ExecuteCallback, Invalid delegator"); @@ -297,6 +341,12 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat AsyncTask::CompleteCallback complete = [shellCmdResultBox](NativeEngine &engine, AsyncTask &task, int32_t status) { HILOG_INFO("OnExecuteShellCommand AsyncTask CompleteCallback is called"); + if (!shellCmdResultBox) { + HILOG_ERROR("OnExecuteShellCommand AsyncTask CompleteCallback, Invalid shellCmdResultBox"); + task.Reject(engine, CreateJsError(engine, ERROR, "executeShellCommand failed.")); + return; + } + NativeValue *result = CreateJsShellCmdResult(engine, shellCmdResultBox->shellCmdResult_); if (result) { task.Resolve(engine, result); @@ -308,8 +358,6 @@ NativeValue *JSAbilityDelegator::OnExecuteShellCommand(NativeEngine &engine, Nat NativeValue *lastParam = nullptr; if (opt.hasCallbackPara) { lastParam = opt.hasTimeoutPara ? info.argv[INDEX_TWO] : info.argv[INDEX_ONE]; - } else { - lastParam = nullptr; } NativeValue *result = nullptr; @@ -376,15 +424,21 @@ NativeValue *JSAbilityDelegator::OnGetCurrentTopAbility(NativeEngine &engine, Na HILOG_INFO("OnGetCurrentTopAbility AsyncTask is called"); auto delegator = AbilityDelegatorRegistry::GetAbilityDelegator(); if (!delegator) { + HILOG_ERROR("Invalid delegator"); task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed.")); return; } - sptr remoteObject = delegator->GetCurrentTopAbility(); - NativeValue *ability = CreateAbilityObject(engine, remoteObject); - if (ability) { - task.Resolve(engine, ability); - } else { + + auto property = delegator->GetCurrentTopAbility(); + if (!property || property->object_.expired()) { + HILOG_ERROR("Invalid property"); task.Reject(engine, CreateJsError(engine, ERROR, "getCurrentTopAbility failed.")); + } else { + { + std::unique_lock lck(mutexAblityRecord_); + ablityRecord_.emplace(property->object_, property->token_); + } + task.Resolve(engine, property->object_.lock()->Get()); } }; @@ -562,12 +616,20 @@ NativeValue *JSAbilityDelegator::ParseAbilityPara( { HILOG_INFO("enter"); - for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end(); ++iter) { - if (value->StrictEquals(iter->first->Get())) { + std::unique_lock lck(mutexAblityRecord_); + for (auto iter = ablityRecord_.begin(); iter != ablityRecord_.end();) { + if (iter->first.expired()) { + iter = ablityRecord_.erase(iter); + continue; + } + + if (value->StrictEquals(iter->first.lock()->Get())) { remoteObject = iter->second; HILOG_INFO("Ablity exist"); return remoteObject ? engine.CreateNull() : nullptr; } + + ++iter; } HILOG_ERROR("Ablity doesn't exist"); @@ -592,6 +654,8 @@ NativeValue *JSAbilityDelegator::CreateAbilityObject(NativeEngine &engine, const std::shared_ptr refence = nullptr; refence.reset(engine.CreateReference(objValue, 1)); + + std::unique_lock lck(mutexAblityRecord_); ablityRecord_[refence] = remoteObject; return objValue; } diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h index c3da1b14d2..d478a16990 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator.h @@ -31,22 +31,132 @@ public: bool hasTimeoutPara; bool hasCallbackPara; }; - JSAbilityDelegator() = default; + + /** + * Default constructor used to create a JSAbilityDelegator instance. + */ + JSAbilityDelegator(); + + /** + * Default deconstructor used to deconstruct. + */ ~JSAbilityDelegator() = default; + /** + * Destory object. + * + * @param engine Indicates the native engine. + * @param data Indicates the object to be destroyed. + * @param hint Indicates the hint. + */ static void Finalizer(NativeEngine *engine, void *data, void *hint); + /** + * Adds ability monitor. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *AddAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Removes ability monitor. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *RemoveAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Waits for the specified monitor. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *WaitAbilityMonitor(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Prints log information to the console. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *Print(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Execute the specified shell command. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *ExecuteShellCommand(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Obtains the application context. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *GetAppContext(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Obtains the lifecycle state of the specified ability. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *GetAbilityState(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Obtains the ability that is currently being displayed. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *GetCurrentTopAbility(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Starts an ability based on the given parameters. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *StartAbility(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Transits the specified ability to foreground. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *DoAbilityForeground(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Transits the specified ability to background. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *DoAbilityBackground(NativeEngine *engine, NativeCallbackInfo *info); + + /** + * Finishes user test. + * + * @param engine Indicates the native engine. + * @param info Indicates the parameters from js. + * @return exec result. + */ static NativeValue *FinishTest(NativeEngine *engine, NativeCallbackInfo *info); private: diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp index 097224eafe..fd4e9dc6b6 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.cpp @@ -15,6 +15,7 @@ #include "js_ability_delegator_registry.h" +#include #include "ability_delegator.h" #include "ability_delegator_registry.h" #include "hilog_wrapper.h" @@ -57,7 +58,14 @@ private: HILOG_ERROR("Failed to get delegator object"); return engine.CreateNull(); } - return CreateJsAbilityDelegator(engine); + + static std::unique_ptr reference; + if (!reference) { + auto value = CreateJsAbilityDelegator(engine); + reference.reset(engine.CreateReference(value, 1)); + } + + return reference->Get(); } NativeValue *OnGetArguments(NativeEngine &engine, NativeCallbackInfo &info) diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.h b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.h index c842072f2e..34af195563 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_delegator_registry.h @@ -21,10 +21,25 @@ namespace OHOS { namespace AbilityDelegatorJs { enum class AbilityLifecycleState { + /** + * Indicates that the ability has not been initialized. + */ UNINITIALIZED, + /** + * Indicates that the ability is in the created state. + */ CREATE, + /** + * Indicates that the ability is in the foreground state. + */ FOREGROUND, + /** + * Indicates that the ability is in the background state. + */ BACKGROUND, + /** + * Indicates that the ability is in the destroyed state. + */ DESTROY, }; diff --git a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_monitor.h b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_monitor.h index fd10d6723b..16c4ada7a0 100644 --- a/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_monitor.h +++ b/interfaces/kits/napi/aafwk/app/ability_delegator/js_ability_monitor.h @@ -29,22 +29,83 @@ namespace AbilityDelegatorJs { using namespace OHOS::AppExecFwk; class JSAbilityMonitor { public: + /** + * A constructor used to create a JSAbilityMonitor instance with the input parameter passed. + * + * @param abilityName Indicates the specified ability name for monitoring the lifecycle state changes + * of the ability. + */ explicit JSAbilityMonitor(const std::string &abilityName); + + /** + * Default deconstructor used to deconstruct. + */ ~JSAbilityMonitor() = default; + /** + * Called when ability is started. + * Then call the corresponding method on the js side through the saved js object. + */ void onAbilityCreate(); + + /** + * Called when ability is in foreground. + * Then call the corresponding method on the js side through the saved js object. + */ void onAbilityForeground(); + + /** + * Called when ability is in background. + * Then call the corresponding method on the js side through the saved js object. + */ void onAbilityBackground(); + + /** + * Called when ability is stopped. + * Then call the corresponding method on the js side through the saved js object. + */ void onAbilityDestroy(); + + /** + * Called when window stage is created. + * Then call the corresponding method on the js side through the saved js object. + */ void onWindowStageCreate(); + + /** + * Called when window stage is restored. + * Then call the corresponding method on the js side through the saved js object. + */ void onWindowStageRestore(); + + /** + * Called when window stage is destroyed. + * Then call the corresponding method on the js side through the saved js object. + */ void onWindowStageDestroy(); + /** + * Sets the js object. + * + * @param jsAbilityMonitor Indicates the js object. + */ void SetJsAbilityMonitor(NativeValue *jsAbilityMonitor); + + /** + * Sets the native engine. + * + * @param engine Indicates the native engine. + */ void SetJsAbilityMonitorEnv(NativeEngine *engine) { engine_ = engine; } + + /** + * Obtains the saved js object. + * + * @return the saved js object. + */ std::unique_ptr &GetJsAbilityMonitor() { return jsAbilityMonitor_; diff --git a/ohos.build b/ohos.build index 05bcbb7bf5..31a64ce2a4 100644 --- a/ohos.build +++ b/ohos.build @@ -19,17 +19,6 @@ ], "inner_kits": [ - { - "header": { - "header_base": "//foundation/aafwk/standard/interfaces/innerkits/intent/include/", - "header_files": [ - "ohos/aafwk/content/intent.h", - "ohos/aafwk/content/intent_filter.h", - "ohos/aafwk/content/intent_params.h" - ] - }, - "name": "//foundation/aafwk/standard/interfaces/innerkits/intent:intent" - }, { "header": { "header_base": "//foundation/aafwk/standard/interfaces/innerkits/ability_manager/include", diff --git a/services/abilitymgr/BUILD.gn b/services/abilitymgr/BUILD.gn index 52024631b9..8f53beff1b 100644 --- a/services/abilitymgr/BUILD.gn +++ b/services/abilitymgr/BUILD.gn @@ -41,8 +41,6 @@ config("abilityms_config") { "${innerkits_path}/uri/include", "${innerkits_path}/want/include", "${innerkits_path}/want/include/ohos/aafwk/content", - "${innerkits_path}/intent/include/ohos/aafwk/content", - "${innerkits_path}/want/include/ohos/aafwk/content", "${services_path}/common/include", "//utils/native/base/include", "//prebuilts/jdk/jdk8/linux-x86/include", diff --git a/services/abilitymgr/src/ability_manager_stub.cpp b/services/abilitymgr/src/ability_manager_stub.cpp index 4563f55d23..9dd6b1e319 100644 --- a/services/abilitymgr/src/ability_manager_stub.cpp +++ b/services/abilitymgr/src/ability_manager_stub.cpp @@ -1250,7 +1250,7 @@ int AbilityManagerStub::IsRunningInStabilityTestInner(MessageParcel &data, Messa int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &reply) { - Want *want = data.ReadParcelable(); + std::unique_ptr want(data.ReadParcelable()); if (want == nullptr) { HILOG_ERROR("want is nullptr"); return ERR_INVALID_VALUE; @@ -1258,7 +1258,6 @@ int AbilityManagerStub::StartUserTestInner(MessageParcel &data, MessageParcel &r auto observer = data.ReadRemoteObject(); int32_t result = StartUserTest(*want, observer); reply.WriteInt32(result); - delete want; return result; } diff --git a/services/appmgr/BUILD.gn b/services/appmgr/BUILD.gn index e1d0d736d3..08200f38b5 100644 --- a/services/appmgr/BUILD.gn +++ b/services/appmgr/BUILD.gn @@ -53,8 +53,6 @@ ohos_shared_library("libams") { ] defines = [ - "APP_LOG_TAG = \"AppMgrService\"", - "LOG_DOMAIN = 0xD001110", "AMS_LOG_TAG = \"AppMgrService\"", "AMS_LOG_DOMAIN = 0xD001110", ] @@ -65,7 +63,6 @@ ohos_shared_library("libams") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${appexecfwk_path}/common:libappexecfwk_common", "${innerkits_path}/uri_permission:uri_permission_mgr", "${services_path}/common:perm_verification", ] diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index d784e551c4..33379c6e45 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -2341,7 +2341,7 @@ int AppMgrServiceInner::VerifyProcessPermission() auto isCallingPerm = AAFwk::PermissionVerification::GetInstance()->VerifyCallingPermission( AAFwk::PermissionConstants::PERMISSION_CLEAN_BACKGROUND_PROCESSES); if (isCallingPerm) { - HILOG_ERROR("%{public}s: Permission verification succeeded", __func__); + HILOG_INFO("%{public}s: Permission verification succeeded", __func__); return ERR_OK; } HILOG_ERROR("%{public}s: Permission verification failed", __func__); diff --git a/services/common/include/parcel_macro_ability.h b/services/common/include/parcel_macro_ability.h new file mode 100644 index 0000000000..0e1ad58dbc --- /dev/null +++ b/services/common/include/parcel_macro_ability.h @@ -0,0 +1,42 @@ +/* + * 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 PARCEL_MACRO_ABILITY_H +#define PARCEL_MACRO_ABILITY_H + +#include "parcel.h" + +#include "hilog_wrapper.h" + +namespace OHOS { +namespace AppExecFwk { +#define READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \ + do { \ + if (!(parcel).Read##type(data)) { \ + HILOG_ERROR("fail to read %{public}s type from parcel", #type); \ + return false; \ + } \ + } while (0) + +#define WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(type, parcel, data) \ + do { \ + if (!(parcel).Write##type(data)) { \ + HILOG_ERROR("fail to write %{public}s type into parcel", #type); \ + return false; \ + } \ + } while (0) +} // namespace AppExecFwk +} // namespace OHOS +#endif // PARCEL_MACRO_ABILITY_H \ No newline at end of file diff --git a/services/formmgr/BUILD.gn b/services/formmgr/BUILD.gn index cebf958138..aa761fc740 100644 --- a/services/formmgr/BUILD.gn +++ b/services/formmgr/BUILD.gn @@ -72,8 +72,6 @@ ohos_shared_library("libfms") { ] defines = [ - "APP_LOG_TAG = \"FormMgrService\"", - "LOG_DOMAIN = 0xD001120", "AMS_LOG_TAG = \"FormMgrService\"", "AMS_LOG_DOMAIN = 0xD001120", ] @@ -87,7 +85,6 @@ ohos_shared_library("libfms") { cflags += [ "-DBINDER_IPC_32BIT" ] } deps = [ - "${appexecfwk_path}/common:libappexecfwk_common", "${kits_path}/appkit:app_context", "${services_path}/common:perm_verification", diff --git a/services/formmgr/include/json_util_form.h b/services/formmgr/include/json_util_form.h new file mode 100644 index 0000000000..2551781434 --- /dev/null +++ b/services/formmgr/include/json_util_form.h @@ -0,0 +1,187 @@ +/* + * 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. + */ + +#ifndef FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H +#define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H + +#include + +#include "appexecfwk_errors.h" +#include "hilog_wrapper.h" +#include "json_serializer.h" + +namespace OHOS { +namespace AppExecFwk { +enum class JsonType { + NULLABLE, + BOOLEAN, + NUMBER, + OBJECT, + ARRAY, + STRING, +}; + +enum class ArrayType { + NUMBER, + OBJECT, + STRING, + NOT_ARRAY, +}; + +template +void CheckArrayType( + const nlohmann::json &jsonObject, const std::string &key, dataType &data, ArrayType arrayType, int32_t &parseResult) +{ + auto arrays = jsonObject.at(key); + if (arrays.empty()) { + HILOG_DEBUG("array is empty"); + return; + } + switch (arrayType) { + case ArrayType::STRING: + for (const auto &array : arrays) { + if (!array.is_string()) { + HILOG_ERROR("array %{public}s is not string type", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + } + } + if (parseResult == ERR_OK) { + data = jsonObject.at(key).get(); + } + break; + case ArrayType::OBJECT: + for (const auto &array : arrays) { + if (!array.is_object()) { + HILOG_ERROR("array %{public}s is not object type", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + } + if (parseResult == ERR_OK) { + data = jsonObject.at(key).get(); + } + break; + case ArrayType::NUMBER: + for (const auto &array : arrays) { + if (!array.is_number()) { + HILOG_ERROR("array %{public}s is not number type", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + } + } + if (parseResult == ERR_OK) { + data = jsonObject.at(key).get(); + } + break; + case ArrayType::NOT_ARRAY: + HILOG_ERROR("array %{public}s is not string type", key.c_str()); + break; + default: + HILOG_ERROR("array %{public}s type error", key.c_str()); + break; + } +} + +template +void GetValueIfFindKey(const nlohmann::json &jsonObject, const nlohmann::detail::iter_impl &end, + const std::string &key, dataType &data, JsonType jsonType, bool isNecessary, int32_t &parseResult, + ArrayType arrayType) +{ + if (parseResult) { + return; + } + if (jsonObject.find(key) != end) { + switch (jsonType) { + case JsonType::BOOLEAN: + if (!jsonObject.at(key).is_boolean()) { + HILOG_ERROR("type is error %{public}s is not boolean", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + data = jsonObject.at(key).get(); + break; + case JsonType::NUMBER: + if (!jsonObject.at(key).is_number()) { + HILOG_ERROR("type is error %{public}s is not number", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + data = jsonObject.at(key).get(); + break; + case JsonType::OBJECT: + if (!jsonObject.at(key).is_object()) { + HILOG_ERROR("type is error %{public}s is not object", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + data = jsonObject.at(key).get(); + break; + case JsonType::ARRAY: + if (!jsonObject.at(key).is_array()) { + HILOG_ERROR("type is error %{public}s is not array", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + CheckArrayType(jsonObject, key, data, arrayType, parseResult); + break; + case JsonType::STRING: + if (!jsonObject.at(key).is_string()) { + HILOG_ERROR("type is error %{public}s is not string", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + break; + } + data = jsonObject.at(key).get(); + break; + case JsonType::NULLABLE: + HILOG_ERROR("type is error %{public}s is nullable", key.c_str()); + break; + default: + HILOG_ERROR("type is error %{public}s is not jsonType", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_PROP_TYPE_ERROR; + } + return; + } + if (isNecessary) { + HILOG_ERROR("profile prop %{public}s is mission", key.c_str()); + parseResult = ERR_APPEXECFWK_PARSE_PROFILE_MISSING_PROP; + } +} + +template +const std::string GetJsonStrFromInfo(T &t) +{ + nlohmann::json json = t; + return json.dump(); +} + +template +bool ParseInfoFromJsonStr(const char *data, T &t) +{ + if (data == nullptr) { + HILOG_ERROR("%{public}s faile due to data is nullptr", __func__); + return false; + } + + nlohmann::json jsonObject = nlohmann::json::parse(data, nullptr, false); + if (jsonObject.is_discarded()) { + HILOG_ERROR("%{public}s faile due to data is discarded", __func__); + return false; + } + + t = jsonObject.get(); + return true; +} +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_JSON_UTIL_FORM_H \ No newline at end of file diff --git a/services/formmgr/src/form_db_info.cpp b/services/formmgr/src/form_db_info.cpp index ef6a587712..daa4107b9c 100644 --- a/services/formmgr/src/form_db_info.cpp +++ b/services/formmgr/src/form_db_info.cpp @@ -15,7 +15,7 @@ #include "form_db_info.h" -#include "json_util.h" +#include "json_util_form.h" namespace OHOS { namespace AppExecFwk { diff --git a/services/test/moduletest/module_test_dump_util/module_test_dump_util.cpp b/services/test/moduletest/module_test_dump_util/module_test_dump_util.cpp index 0818a28da9..de5283a3b1 100644 --- a/services/test/moduletest/module_test_dump_util/module_test_dump_util.cpp +++ b/services/test/moduletest/module_test_dump_util/module_test_dump_util.cpp @@ -35,7 +35,7 @@ std::shared_ptr MTDumpUtil::GetInstance() MTDumpUtil::MTDumpUtil() { - findRgx_["Intent"] = regex(".*intent\\[(.+)\\].*"); + findRgx_["Want"] = regex(".*Want\\[(.+)\\].*"); findRgx_["AbilityName"] = regex(".*main name \\[(.+)\\].*"); findRgx_["AppName"] = regex(".*app name \\[(.+)\\].*"); findRgx_["BundleName"] = regex(".*bundle name \\[(.+)\\].*"); diff --git a/test/fuzztest/IntentParseUri_fuzzer/BUILD.gn b/test/fuzztest/IntentParseUri_fuzzer/BUILD.gn deleted file mode 100644 index d109147402..0000000000 --- a/test/fuzztest/IntentParseUri_fuzzer/BUILD.gn +++ /dev/null @@ -1,57 +0,0 @@ -# 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. - -#####################hydra-fuzz################### -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -module_output_path = "developertest/ability_runtime" - -##############################fuzztest########################################## -ohos_fuzztest("IntentParseUriFuzzTest") { - module_out_path = module_output_path - - include_dirs = - [ "//foundation/aafwk/standard/interfaces/innerkits/intent/include" ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "IntentParseUri_fuzzer.cpp" ] - - deps = [ - "//foundation/aafwk/standard/interfaces/innerkits/intent:intent", - "//foundation/appexecfwk/standard/common:libappexecfwk_common", - ] - - external_deps = [ - "ability_base:base", - "ability_base:want", - "utils_base:utils", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [] - deps += [ - # deps file - ":IntentParseUriFuzzTest", - ] -} -############################################################################### diff --git a/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.cpp b/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.cpp deleted file mode 100644 index a735ab2a83..0000000000 --- a/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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 "IntentParseUri_fuzzer.h" - -#include -#include - -#include "ohos/aafwk/content/intent.h" - -using namespace OHOS::AAFwk; - -namespace OHOS { - bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) - { - Intent *ret = Intent::ParseUri(reinterpret_cast(data)); - - if (ret) { - delete ret; - ret = nullptr; - } - - return true; - } -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DoSomethingInterestingWithMyAPI(data, size); - return 0; -} - diff --git a/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.h b/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.h deleted file mode 100644 index 66a10a9009..0000000000 --- a/test/fuzztest/IntentParseUri_fuzzer/IntentParseUri_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 TEST_FUZZTEST_INTENTPARSEURI_FUZZER_INTENTPARSEURI_FUZZER_H -#define TEST_FUZZTEST_INTENTPARSEURI_FUZZER_INTENTPARSEURI_FUZZER_H - -#define FUZZ_PROJECT_NAME "IntentParseUri_fuzzer" - -#endif \ No newline at end of file diff --git a/test/fuzztest/IntentParseUri_fuzzer/project.xml b/test/fuzztest/IntentParseUri_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cfde..0000000000 --- a/test/fuzztest/IntentParseUri_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/systemtest/common/ams/ams_ability_state_age_manual_test/BUILD.gn b/test/systemtest/common/ams/ams_ability_state_age_manual_test/BUILD.gn index 2027ba2741..4b58dea832 100644 --- a/test/systemtest/common/ams/ams_ability_state_age_manual_test/BUILD.gn +++ b/test/systemtest/common/ams/ams_ability_state_age_manual_test/BUILD.gn @@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/" config("system_test_ams_ability_state_age_manual_test_config") { include_dirs = [ "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", - "${aafwk_path}/interfaces/innerkits/intent/include", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr", "${aafwk_path}/interfaces/innerkits/want/include", "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr", diff --git a/test/systemtest/common/ams/ams_ability_state_test/BUILD.gn b/test/systemtest/common/ams/ams_ability_state_test/BUILD.gn index e49683dc86..edb83421c3 100644 --- a/test/systemtest/common/ams/ams_ability_state_test/BUILD.gn +++ b/test/systemtest/common/ams/ams_ability_state_test/BUILD.gn @@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/" config("system_test_ams_ability_state_test_config") { include_dirs = [ "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", - "${aafwk_path}/interfaces/innerkits/intent/include", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr", "${aafwk_path}/interfaces/innerkits/want/include", "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr", diff --git a/test/systemtest/common/ams/ams_check_service/BUILD.gn b/test/systemtest/common/ams/ams_check_service/BUILD.gn index 2681b567fe..9db8e7a187 100644 --- a/test/systemtest/common/ams/ams_check_service/BUILD.gn +++ b/test/systemtest/common/ams/ams_check_service/BUILD.gn @@ -19,7 +19,6 @@ module_output_path = "appexecfwk_standard/ams/" config("ams_check_service_config") { include_dirs = [ "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", - "${aafwk_path}/interfaces/innerkits/intent/include", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr", "${aafwk_path}/interfaces/innerkits/want/include", "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr", diff --git a/test/systemtest/common/ams/tool/src/module_test_dump_util.cpp b/test/systemtest/common/ams/tool/src/module_test_dump_util.cpp index 0434a5f2b3..872b4c27a5 100644 --- a/test/systemtest/common/ams/tool/src/module_test_dump_util.cpp +++ b/test/systemtest/common/ams/tool/src/module_test_dump_util.cpp @@ -35,7 +35,7 @@ std::shared_ptr MTDumpUtil::GetInstance() MTDumpUtil::MTDumpUtil() { - findRgx_["Intent"] = regex(".*intent\\[(.+)\\].*"); + findRgx_["Want"] = regex(".*Want\\[(.+)\\].*"); findRgx_["AbilityName"] = regex(".*main name \\[(.+)\\].*"); findRgx_["AppName"] = regex(".*app name \\[(.+)\\].*"); findRgx_["BundleName"] = regex(".*bundle name \\[(.+)\\].*"); diff --git a/test/systemtest/common/task_dispatcher/BUILD.gn b/test/systemtest/common/task_dispatcher/BUILD.gn index 841bcf754f..a6579ddf13 100644 --- a/test/systemtest/common/task_dispatcher/BUILD.gn +++ b/test/systemtest/common/task_dispatcher/BUILD.gn @@ -21,7 +21,6 @@ config("system_test_task_dispatcher_config") { "//foundation/aafwk/standard/common/task_dispatcher/include/threading", "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include/task", "//foundation/aafwk/standard/frameworks/kits/appkit/native/app/include", - "${aafwk_path}/interfaces/innerkits/intent/include", "${appexecfwk_path}/interfaces/innerkits/appexecfwk_core/include/bundlemgr", "${aafwk_path}/interfaces/innerkits/want/include", "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr", diff --git a/tools/aa/include/itest_observer.h b/tools/aa/include/itest_observer.h index 69963f2b68..f43e9bfb1f 100644 --- a/tools/aa/include/itest_observer.h +++ b/tools/aa/include/itest_observer.h @@ -25,14 +25,37 @@ class ITestObserver : public IRemoteBroker { public: DECLARE_INTERFACE_DESCRIPTOR(u"ohos.aafwk.ITestObserver"); + /** + * Outputs test status. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestStatus(const std::string &msg, const int &resultCode) = 0; + + /** + * Outputs information and result code that the test has finished. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestFinished(const std::string &msg, const int &resultCode) = 0; - virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutSec) = 0; + + /** + * Executes the specified shell command. + * + * @param cmd, Indicates the specified shell command. + * @param timeoutSec, Indicates the specified time out time, in seconds. + * @return the result of the specified shell command. + */ + virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) = 0; enum class Message { + // ipc id for test status (1) AA_TEST_STATUS = 1, + // ipc id for test finished (2) AA_TEST_FINISHED = 2, + // ipc id for execute shell command (3) AA_EXECUTE_SHELL_COMMAND = 3, }; }; diff --git a/tools/aa/include/test_observer.h b/tools/aa/include/test_observer.h index 405f2cf5c0..e3450b9d1a 100644 --- a/tools/aa/include/test_observer.h +++ b/tools/aa/include/test_observer.h @@ -22,15 +22,47 @@ namespace OHOS { namespace AAFwk { class TestObserver : public TestObserverStub { public: - + /** + * Default constructor used to create a TestObserver instance. + */ TestObserver(); + /** + * Deconstructor used to deconstruct. + */ virtual ~TestObserver() override; + /** + * Outputs test status. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestStatus(const std::string &msg, const int &resultCode) override; + + /** + * Outputs information and result code that the test has finished. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestFinished(const std::string &msg, const int &resultCode) override; - virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutSec) override; + + /** + * Executes the specified shell command. + * + * @param cmd, Indicates the specified shell command. + * @param timeoutSec, Indicates the specified time out time, in seconds. + * @return the result of the specified shell command. + */ + virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) override; + + /** + * Waits for the test to finish. + * + * @param timeoutMs, Indicates the specified time out time, in milliseconds. + * @return true if the test finish within the specified time; returns false otherwise. + */ bool WaitForFinish(const int64_t &timeoutMs); private: diff --git a/tools/aa/include/test_observer_proxy.h b/tools/aa/include/test_observer_proxy.h index fa2644ad26..f257ccb468 100644 --- a/tools/aa/include/test_observer_proxy.h +++ b/tools/aa/include/test_observer_proxy.h @@ -23,12 +23,41 @@ namespace OHOS { namespace AAFwk { class TestObserverProxy : public IRemoteProxy { public: + /** + * A constructor used to create a TestObserverProxy instance with the input parameter object passed. + * @param object Indicates remote object. + */ explicit TestObserverProxy(const sptr &object); + + /** + * Deconstructor used to deconstruct. + */ virtual ~TestObserverProxy() override; + + /** + * Outputs test status. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestStatus(const std::string &msg, const int &resultCode) override; + + /** + * Outputs information and result code that the test has finished. + * + * @param msg, Indicates the status information. + * @param resultCode, Indicates the result code. + */ virtual void TestFinished(const std::string &msg, const int &resultCode) override; - virtual ShellCommandResult ExecuteShellCommand( - const std::string &cmd, const int64_t timeoutSec) override; + + /** + * Executes the specified shell command. + * + * @param cmd, Indicates the specified shell command. + * @param timeoutSec, Indicates the specified time out time, in seconds. + * @return the result of the specified shell command. + */ + virtual ShellCommandResult ExecuteShellCommand(const std::string &cmd, const int64_t timeoutSec) override; private: static inline BrokerDelegator delegator_; diff --git a/tools/aa/include/test_observer_stub.h b/tools/aa/include/test_observer_stub.h index 38698f0ba6..df43ef534d 100644 --- a/tools/aa/include/test_observer_stub.h +++ b/tools/aa/include/test_observer_stub.h @@ -23,8 +23,25 @@ namespace OHOS { namespace AAFwk { class TestObserverStub : public IRemoteStub { public: + /** + * Default constructor. + */ TestObserverStub(); + + /** + * Deconstructor used to deconstruct. + */ virtual ~TestObserverStub() override; + + /** + * Handles ipc request. + * + * @param code, Indicates the ipc id. + * @param data, Indicates the input data. + * @param reply, Indicates the reply data. + * @param option, Indicates the option. + * @return the result of execution. + */ virtual int OnRemoteRequest( uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; diff --git a/tools/aa/src/ability_command.cpp b/tools/aa/src/ability_command.cpp index 2201ca862e..05a4c649e4 100644 --- a/tools/aa/src/ability_command.cpp +++ b/tools/aa/src/ability_command.cpp @@ -1205,10 +1205,10 @@ ErrCode AbilityManagerShellCommand::RunAsTestCommand() for (int i = USER_TEST_COMMAND_START_INDEX; i < argc_; i++) { HILOG_INFO("argv_[%{public}d]: %{public}s", i, argv_[i]); std::string opt = argv_[i]; - if (opt == "-h" || opt == "--help") { + if ((opt == "-h") || (opt == "--help")) { resultReceiver_.append(HELP_MSG_TEST); return OHOS::ERR_OK; - } else if (opt == "-b" || opt == "-w" || opt == "-p" || opt == "-m") { + } else if ((opt == "-b") || (opt == "-w") || (opt == "-p") || (opt == "-m")) { if (i >= argc_ - 1) { return TestCommandError("error: option [" + opt + "] requires a value.\n"); }