From 0c585da6a787be5423b17262fb48487bb8ffb507 Mon Sep 17 00:00:00 2001 From: zhaoyuan Date: Tue, 21 Sep 2021 18:17:14 +0000 Subject: [PATCH] fix dataability function Signed-off-by: zhaoyuan --- .../appexecfwk_base/include/ability_info.h | 2 +- .../appexecfwk_base/src/ability_info.cpp | 11 +- .../appexecfwk_base/src/application_info.cpp | 2 +- .../include/dispatcher/base_task_dispatcher.h | 2 +- .../dispatcher/serial_task_dispatcher.h | 78 +-- .../task_dispatcher/include/task/task.h | 34 +- .../include/task/task_listener.h | 6 +- .../include/threading/concurrent_queue.h | 2 +- .../include/threading/worker_pool.h | 2 +- .../src/dispatcher/group_impl.cpp | 2 +- .../parallel_task_dispatcher_base.cpp | 3 +- .../src/dispatcher/serial_task_dispatcher.cpp | 2 +- .../dispatcher/task_dispatcher_context.cpp | 2 + .../src/task/barrier_handler.cpp | 6 +- .../task_dispatcher/src/task/task.cpp | 62 +- .../src/threading/task_executor.cpp | 4 +- .../src/threading/worker_pool.cpp | 38 +- .../barrier_handler_test.cpp | 1 - .../groupImpl_test/groupImpl_test.cpp | 8 +- .../parallel_task_dispatcher_base_test.cpp | 2 - .../spec_task_dispatcher_test.cpp | 9 +- .../global_task_dispatcher_module_test.cpp | 1 + .../serial_task_dispatcher_module_test.cpp | 57 +- .../spec_task_dispatcher_module_test.cpp | 57 +- kits/appkit/napi/bundlemgr/bundle_mgr.cpp | 33 +- .../napi/bundlemgr/permission_callback.cpp | 24 +- .../native/app/include/task_dispatcher.h | 77 +-- .../event_handler_press_module_test.cpp | 4 +- services/appmgr/src/lmks/lmks_utils.cpp | 4 +- services/appmgr/src/process_optimizer.cpp | 5 - .../ams_service_load_ability_process_test.cpp | 70 +- .../bundlemgr/include/bundle_data_storage.h | 6 +- .../include/bundle_data_storage_database.h | 1 + .../bundlemgr/include/bundle_mgr_host_impl.h | 5 +- .../bundle_permissions_changed_monitor.h | 14 +- .../bundlemgr/include/inner_bundle_info.h | 2 +- .../kvstore_death_recipient_callback.h | 7 +- .../include/module_usage_data_storage.h | 47 +- .../permission_changed_death_recipient.h | 8 +- services/bundlemgr/src/bundle_data_mgr.cpp | 3 +- .../bundlemgr/src/bundle_mgr_host_impl.cpp | 6 +- .../bundlemgr/src/bundle_permission_mgr.cpp | 16 +- services/bundlemgr/src/bundle_profile.cpp | 4 +- services/bundlemgr/src/bundle_util.cpp | 10 +- services/bundlemgr/src/inner_bundle_info.cpp | 119 ++-- .../src/installd/installd_host_impl.cpp | 15 +- .../src/kvstore_death_recipient_callback.cpp | 10 +- .../src/module_usage_data_storage.cpp | 4 +- .../test/mock/include/json_constants.h | 2 + .../test/mock/include/mock_ability_mgr_host.h | 2 +- .../test/mock/include/mock_bundle_status.h | 8 +- .../test/mock/include/mock_clean_cache.h | 2 + .../test/mock/include/mock_status_receiver.h | 2 + .../test/mock/src/mock_bundle_status.cpp | 2 + .../test/mock/src/mock_clean_cache.cpp | 2 + .../test/mock/src/mock_status_receiver.cpp | 2 + .../test/mock/src/system_ability_helper.cpp | 3 + .../bms_bundle_installer_test.cpp | 2 + .../bms_bundle_parser_test.cpp | 5 +- .../bms_bundle_permission_test.cpp | 170 +++-- .../bms_bundle_uninstaller_test.cpp | 7 +- .../bms_bundle_updater_test.cpp | 2 +- .../bms_data_mgr_test/bms_data_mgr_test.cpp | 2 + .../bms_install_daemon_test.cpp | 2 + .../bms_service_bundle_scan_test.cpp | 52 +- .../bms_service_startup_test.cpp | 70 +- .../ams_app_life_cycle_module_test.cpp | 30 +- .../ams_app_running_record_module_test.cpp | 8 +- .../ams_ipc_app_scheduler_module_test.cpp | 2 +- ...s_service_app_spawn_client_module_test.cpp | 12 +- .../amssystemtestability/abilitySrc/BUILD.gn | 95 ++- .../abilitySrc/amsAbilityAppendTestA/BUILD.gn | 2 + .../include/main_ability.h | 16 +- .../src/main_ability.cpp | 18 +- .../src/second_ability.cpp | 12 +- .../abilitySrc/amsAbilityAppendTestB/BUILD.gn | 2 + .../src/main_ability.cpp | 12 +- .../amsAbilityAppendTestB/src/test_utils.cpp | 2 +- .../amsAbilityVisibleTestPageA/BUILD.gn | 2 + .../src/amsabilityvisibletestpagea1.cpp | 3 +- .../src/amsabilityvisibletestpagea2.cpp | 3 +- .../src/amsabilityvisibletestpagea3.cpp | 3 +- .../src/amsabilityvisibletestpagea4.cpp | 3 +- .../amsAbilityVisibleTestServiceB/BUILD.gn | 2 + .../src/amsabilityvisibletestpageb1.cpp | 3 +- .../src/amsabilityvisibletestpageb2.cpp | 3 +- .../src/amsabilityvisibletestservice.cpp | 2 +- .../src/amsabilityvisibletestservicea1.cpp | 2 +- .../abilitySrc/amsDataSystemTestA/BUILD.gn | 2 + .../src/ams_st_data_ability_data_a.cpp | 9 +- .../src/ams_st_data_ability_page_a.cpp | 9 +- .../abilitySrc/amsDataSystemTestB/BUILD.gn | 2 + .../src/ams_st_data_ability_data_b.cpp | 12 +- .../src/ams_st_data_ability_page_b.cpp | 12 +- .../abilitySrc/amsDataSystemTestC/BUILD.gn | 2 + .../src/ams_st_data_ability_data_c1.cpp | 14 +- .../src/ams_st_data_ability_data_c2.cpp | 12 +- .../include/kit_test_ability_manager_second.h | 1 + .../src/kit_test_ability_manager_second.cpp | 37 +- .../amsKitSystemTest/include/fifth_ability.h | 1 + .../amsKitSystemTest/include/fourth_ability.h | 3 +- .../include/kit_test_ability_manager.h | 3 +- .../abilitySrc/amsKitSystemTestDataA/BUILD.gn | 2 + .../src/ams_st_kit_data_ability_data_a1.cpp | 2 +- .../src/ams_st_kit_data_ability_data_a2.cpp | 2 +- .../src/ams_st_kit_data_ability_data_a3.cpp | 2 +- .../src/ams_st_kit_data_ability_page_a.cpp | 2 +- .../src/ams_st_kit_data_ability_service_a.cpp | 2 +- .../abilitySrc/amsKitSystemTestDataB/BUILD.gn | 2 + .../src/ams_st_kit_data_ability_data_b.cpp | 2 +- .../src/ams_st_kit_data_ability_page_b.cpp | 2 +- .../src/ams_st_kit_data_ability_service_b.cpp | 2 +- .../include/ability_ability.h | 7 +- .../include/ability_connection_ability.h | 10 +- .../include/ability_context_ability.h | 11 +- .../include/ability_life_cycle_ability.h | 8 +- .../include/life_cycle_call_backs_ability.h | 1 - .../src/ability_ability.cpp | 134 ++-- .../src/ability_connection_ability.cpp | 76 ++- .../src/ability_context_ability.cpp | 87 ++- .../src/ability_life_cycle_ability.cpp | 18 +- .../src/life_cycle_observer_ability.cpp | 6 +- .../amsSystemTestR/src/amsstabilityr2.cpp | 5 +- .../amsSystemTestR/src/amsstabilityr3.cpp | 5 +- .../common/ability_append_test_info.h | 1 - .../abilitySrc/common/kit_test_common_info.h | 1 - .../include/verify_act_first_ability.h | 2 - .../taskDispatcherTestA/include/test_utils.h | 1 - .../taskDispatcherTestA/src/main_ability.cpp | 603 +++++++++--------- .../src/second_ability.cpp | 14 +- .../taskDispatcherTestA/src/test_utils.cpp | 7 +- .../taskDispatcherTestB/include/test_utils.h | 1 - .../taskDispatcherTestB/src/main_ability.cpp | 182 ++++-- .../src/second_ability.cpp | 12 +- .../taskDispatcherTestB/src/test_utils.cpp | 7 +- .../abilitySrc/tools/include/event.h | 2 - .../abilitySrc/tools/include/stoperator.h | 4 - .../tools/include/stpageabilityevent.h | 5 +- .../abilitySrc/tools/src/event.cpp | 2 - .../abilitySrc/tools/src/stoperator.cpp | 3 +- .../thirdPageDemo3/src/pageAbilityDemo.cpp | 3 +- .../stThirdBundle/bmsThirdBundle41.hap | Bin 94238 -> 94208 bytes .../ams_ability_visible_test.cpp | 6 + .../acts_bms_kit_system_test.cpp | 171 +++-- .../bms_compatible_system_test.cpp | 4 +- .../bms_install_system_test.cpp | 6 +- .../bms_launcher_service_system_test.cpp | 315 +++++---- .../bms_search_system_test.cpp | 2 + .../bms_uninstall_system_test.cpp | 2 + 149 files changed, 1851 insertions(+), 1473 deletions(-) diff --git a/interfaces/innerkits/appexecfwk_base/include/ability_info.h b/interfaces/innerkits/appexecfwk_base/include/ability_info.h index 9b0c228a87..4757ef77de 100644 --- a/interfaces/innerkits/appexecfwk_base/include/ability_info.h +++ b/interfaces/innerkits/appexecfwk_base/include/ability_info.h @@ -159,7 +159,7 @@ struct AbilityInfo : public Parcelable { DisplayOrientation orientation = DisplayOrientation::UNSPECIFIED; LaunchMode launchMode = LaunchMode::STANDARD; std::string srcPath; - std::string srcLanguage="js"; + std::string srcLanguage = "js"; std::vector permissions; std::string process; diff --git a/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp b/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp index a71151fa06..cbd638a7fb 100644 --- a/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/ability_info.cpp @@ -79,7 +79,8 @@ const std::string JSON_KEY_LABEL_ID = "labelId"; const std::string JSON_KEY_DESCRIPTION_ID = "descriptionId"; const std::string JSON_KEY_ICON_ID = "iconId"; const std::string JSON_KEY_FORM_ENABLED = "formEnabled"; - +const std::string JSON_KEY_SRC_PATH = "srcPath"; +const std::string JSON_KEY_SRC_LANGUAGE = "srcLanguage"; } // namespace bool AbilityInfo::ReadFromParcel(Parcel &parcel) @@ -103,6 +104,8 @@ bool AbilityInfo::ReadFromParcel(Parcel &parcel) targetAbility = Str16ToStr8(parcel.ReadString16()); readPermission = Str16ToStr8(parcel.ReadString16()); writePermission = Str16ToStr8(parcel.ReadString16()); + srcPath = Str16ToStr8(parcel.ReadString16()); + srcLanguage = Str16ToStr8(parcel.ReadString16()); visible = parcel.ReadBool(); isLauncherAbility = parcel.ReadBool(); isNativeAbility = parcel.ReadBool(); @@ -233,6 +236,8 @@ bool AbilityInfo::Marshalling(Parcel &parcel) const WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(targetAbility)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(readPermission)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(writePermission)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcPath)); + WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(srcLanguage)); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, visible); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isLauncherAbility); WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Bool, parcel, isNativeAbility); @@ -375,6 +380,8 @@ void to_json(nlohmann::json &jsonObject, const AbilityInfo &abilityInfo) {JSON_KEY_SUPPORT_PIP_MODE, abilityInfo.supportPipMode}, {JSON_KEY_READ_PERMISSION, abilityInfo.readPermission}, {JSON_KEY_WRITE_PERMISSION, abilityInfo.writePermission}, + {JSON_KEY_SRC_PATH, abilityInfo.srcPath}, + {JSON_KEY_SRC_LANGUAGE, abilityInfo.srcLanguage}, {JSON_KEY_CONFIG_CHANGES, abilityInfo.configChanges}, {JSON_KEY_FORM_ENTITY, abilityInfo.formEntity}, {JSON_KEY_MIN_FORM_HEIGHT, abilityInfo.minFormHeight}, @@ -449,6 +456,8 @@ void from_json(const nlohmann::json &jsonObject, AbilityInfo &abilityInfo) abilityInfo.supportPipMode = jsonObject.at(JSON_KEY_SUPPORT_PIP_MODE).get(); abilityInfo.readPermission = jsonObject.at(JSON_KEY_READ_PERMISSION).get(); abilityInfo.writePermission = jsonObject.at(JSON_KEY_WRITE_PERMISSION).get(); + abilityInfo.srcPath = jsonObject.at(JSON_KEY_SRC_PATH).get(); + abilityInfo.srcLanguage = jsonObject.at(JSON_KEY_SRC_LANGUAGE).get(); abilityInfo.configChanges = jsonObject.at(JSON_KEY_CONFIG_CHANGES).get>(); abilityInfo.formEntity = jsonObject.at(JSON_KEY_FORM_ENTITY).get(); abilityInfo.minFormHeight = jsonObject.at(JSON_KEY_MIN_FORM_HEIGHT).get(); diff --git a/interfaces/innerkits/appexecfwk_base/src/application_info.cpp b/interfaces/innerkits/appexecfwk_base/src/application_info.cpp index d24b23b86c..41ba13b330 100644 --- a/interfaces/innerkits/appexecfwk_base/src/application_info.cpp +++ b/interfaces/innerkits/appexecfwk_base/src/application_info.cpp @@ -232,7 +232,7 @@ void ApplicationInfo::ConvertToCompatibleApplicationInfo(CompatibleApplicationIn compatibleApplicationInfo.permissions = permissions; compatibleApplicationInfo.moduleInfos = moduleInfos; compatibleApplicationInfo.supportedModes = supportedModes; - compatibleApplicationInfo.enabled = debug; + compatibleApplicationInfo.enabled = enabled; } } // namespace AppExecFwk diff --git a/interfaces/innerkits/task_dispatcher/include/dispatcher/base_task_dispatcher.h b/interfaces/innerkits/task_dispatcher/include/dispatcher/base_task_dispatcher.h index 106b6619b9..96326fb7fd 100644 --- a/interfaces/innerkits/task_dispatcher/include/dispatcher/base_task_dispatcher.h +++ b/interfaces/innerkits/task_dispatcher/include/dispatcher/base_task_dispatcher.h @@ -28,7 +28,7 @@ namespace OHOS { namespace AppExecFwk { /** - *Base implementation for interface of TaskDispatcher. + * Base implementation for interface of TaskDispatcher. */ class BaseTaskDispatcher : public TaskDispatcher { diff --git a/interfaces/innerkits/task_dispatcher/include/dispatcher/serial_task_dispatcher.h b/interfaces/innerkits/task_dispatcher/include/dispatcher/serial_task_dispatcher.h index 9388e9ce0c..af3847c8ca 100644 --- a/interfaces/innerkits/task_dispatcher/include/dispatcher/serial_task_dispatcher.h +++ b/interfaces/innerkits/task_dispatcher/include/dispatcher/serial_task_dispatcher.h @@ -35,51 +35,7 @@ namespace AppExecFwk { * Dispatcher for serial thread model. */ class SerialTaskDispatcher : public BaseTaskDispatcher, public std::enable_shared_from_this { -private: - static std::string DISPATCHER_TAG; - static std::string ASYNC_DISPATCHER_TAG; - static std::string SYNC_DISPATCHER_TAG; - static std::string DELAY_DISPATCHER_TAG; - - std::atomic running_; - ConcurrentQueue> workingTasks_; - - std::shared_ptr executor_; - std::mutex mutex_; - -private: - ErrCode OnNewTaskIn(std::shared_ptr &task); - - ErrCode Prepare(std::shared_ptr &task); - - /** - * Callback for task when finish. - * - */ - void OnTaskDone(); - - bool Schedule(); - - /** - * Do task in turn, until the task queue is empty. - * - * @param isExhausted is an inaccurate judge indicate that the workingTasks is empty. If true, do double-check. - * @return true if has work remain to do else false. - * - */ - bool DoNext(bool isExhausted); - - void DoWork(std::shared_ptr &task); - public: - /** - * Constructs a serial TaskDispatcher using priority. - * - * @param dispatcherName is the identity for dispatcher. It's for debug purpose. - * @param priority is the priority for tasks dispatched by this Dispatcher. - * @param executor contains thread pool(s) for executing tasks concurrently. - * - */ SerialTaskDispatcher( const std::string &dispatcherName, const TaskPriority priority, const std::shared_ptr &executor); ~SerialTaskDispatcher(){}; @@ -127,6 +83,40 @@ public: * */ std::shared_ptr DelayDispatch(const std::shared_ptr &runnable, long delayMs); +private: + ErrCode OnNewTaskIn(std::shared_ptr &task); + + ErrCode Prepare(std::shared_ptr &task); + + /** + * Callback for task when finish. + * + */ + void OnTaskDone(); + + bool Schedule(); + + /** + * Do task in turn, until the task queue is empty. + * + * @param isExhausted is an inaccurate judge indicate that the workingTasks is empty. If true, do double-check. + * @return true if has work remain to do else false. + * + */ + bool DoNext(bool isExhausted); + + void DoWork(std::shared_ptr &task); +private: + static std::string DISPATCHER_TAG; + static std::string ASYNC_DISPATCHER_TAG; + static std::string SYNC_DISPATCHER_TAG; + static std::string DELAY_DISPATCHER_TAG; + + std::atomic running_; + ConcurrentQueue> workingTasks_; + + std::shared_ptr executor_; + std::mutex mutex_; }; } // namespace AppExecFwk diff --git a/interfaces/innerkits/task_dispatcher/include/task/task.h b/interfaces/innerkits/task_dispatcher/include/task/task.h index 82a5c0d4a8..4d58c0e9b4 100644 --- a/interfaces/innerkits/task_dispatcher/include/task/task.h +++ b/interfaces/innerkits/task_dispatcher/include/task/task.h @@ -37,52 +37,52 @@ public: virtual ~Task(); /** - *@brief invoke the function to execute the task + * @brief invoke the function to execute the task */ virtual void Run(); /** - * @brief Gets the priority. - * @return The priority. + * @brief Gets the priority. + * @return The priority. */ TaskPriority GetPriority() const; /** - * @brief Sets the sequence. - * @param sequence The sequence + * @brief Sets the sequence. + * @param sequence The sequence */ void SetSequence(long sequence); /** - *@brief Gets the sequence. - *@return The sequence. + * @brief Gets the sequence. + * @return The sequence. */ long GetSequence() const; /** - *@brief Revoke this task if hasn't run. - *@return true if set revoked or already revoked. False if the task has start executing. + * @brief Revoke this task if hasn't run. + * @return true if set revoked or already revoked. False if the task has start executing. */ bool Revoke() override; /** - *@brief Adds a task listener. - *@param listener The listener + * @brief Adds a task listener. + * @param listener The listener */ void AddTaskListener(const std::shared_ptr &listener); /** - *@brief Called when task is about to run. + * @brief Called when task is about to run. */ void BeforeTaskExecute(); /** - *@brief Called when task is done. + * @brief Called when task is done. */ void AfterTaskExecute(); /** - *@brief Called when task is canceled. + * @brief Called when task is canceled. */ void OnTaskCanceled(); @@ -102,9 +102,9 @@ private: }; /** - *@brief Return true if not executed or revoked, and if not executed or revoked, ensure |EXECUTED| to be set. - *@param - - *@return bool + * @brief Return true if not executed or revoked, and if not executed or revoked, ensure |EXECUTED| to be set. + * @param - + * @return bool */ bool EnterExecute(); diff --git a/interfaces/innerkits/task_dispatcher/include/task/task_listener.h b/interfaces/innerkits/task_dispatcher/include/task/task_listener.h index 4ba73a96b6..27ff313fff 100644 --- a/interfaces/innerkits/task_dispatcher/include/task/task_listener.h +++ b/interfaces/innerkits/task_dispatcher/include/task/task_listener.h @@ -27,9 +27,9 @@ class TaskListener { public: virtual ~TaskListener(){}; /** - *@brief Called when task stage changed. - *@param stage The stage - *@return void + * @brief Called when task stage changed. + * @param stage The stage + * @return void */ virtual void OnChanged(const TaskStage &stage) = 0; }; diff --git a/interfaces/innerkits/task_dispatcher/include/threading/concurrent_queue.h b/interfaces/innerkits/task_dispatcher/include/threading/concurrent_queue.h index 76090d0e4c..6126745ee0 100644 --- a/interfaces/innerkits/task_dispatcher/include/threading/concurrent_queue.h +++ b/interfaces/innerkits/task_dispatcher/include/threading/concurrent_queue.h @@ -24,7 +24,7 @@ namespace OHOS { namespace AppExecFwk { -template +template class ConcurrentQueue { public: ConcurrentQueue() : empty_(){}; diff --git a/interfaces/innerkits/task_dispatcher/include/threading/worker_pool.h b/interfaces/innerkits/task_dispatcher/include/threading/worker_pool.h index eee7721300..edf8a97adc 100644 --- a/interfaces/innerkits/task_dispatcher/include/threading/worker_pool.h +++ b/interfaces/innerkits/task_dispatcher/include/threading/worker_pool.h @@ -80,7 +80,7 @@ private: static bool IsRunning(int ctl); - static int GetStateFromControl(unsigned int ctl); + static int GetStateFromControl(int ctl); static int CombineToControl(unsigned int state, unsigned int count); diff --git a/interfaces/innerkits/task_dispatcher/src/dispatcher/group_impl.cpp b/interfaces/innerkits/task_dispatcher/src/dispatcher/group_impl.cpp index ed3b982aca..578b413272 100644 --- a/interfaces/innerkits/task_dispatcher/src/dispatcher/group_impl.cpp +++ b/interfaces/innerkits/task_dispatcher/src/dispatcher/group_impl.cpp @@ -111,7 +111,7 @@ bool GroupImpl::AddNotification(const std::shared_ptr ¬ification) return true; } /** - * @brief Notify all tasks and remove from queue. + * @brief Notify all tasks and remove from queue. * Attention: Notifications added after all tasks done is not guaranteed. */ void GroupImpl::DrainNotifications() diff --git a/interfaces/innerkits/task_dispatcher/src/dispatcher/parallel_task_dispatcher_base.cpp b/interfaces/innerkits/task_dispatcher/src/dispatcher/parallel_task_dispatcher_base.cpp index de9e3e011b..ddce41c646 100644 --- a/interfaces/innerkits/task_dispatcher/src/dispatcher/parallel_task_dispatcher_base.cpp +++ b/interfaces/innerkits/task_dispatcher/src/dispatcher/parallel_task_dispatcher_base.cpp @@ -122,8 +122,7 @@ std::shared_ptr ParallelTaskDispatcherBase::DelayDispatch( return nullptr; } TracePointBeforePost(innerTask, true, DELAY_DISPATCHER_TAG); - std::function callback = - std::bind(&ParallelTaskDispatcherBase::InterceptedExecute, shared_from_this(), innerTask); + std::function < void()> callback = std::bind(&ParallelTaskDispatcherBase::InterceptedExecute, shared_from_this(), innerTask); bool executeFlag = executor_->DelayExecute(callback, delayMs); if (!executeFlag) { APP_LOGE("ParallelTaskDispatcherBase::DelayDispatch execute failed"); diff --git a/interfaces/innerkits/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp b/interfaces/innerkits/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp index 48e37f068e..42fc5720c7 100644 --- a/interfaces/innerkits/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp +++ b/interfaces/innerkits/task_dispatcher/src/dispatcher/serial_task_dispatcher.cpp @@ -108,7 +108,7 @@ std::shared_ptr SerialTaskDispatcher::DelayDispatch(const std::shared } TracePointBeforePost(innerTask, true, DELAY_DISPATCHER_TAG); // bind parameter to avoid deconstruct. - std::function callback = std::bind(&SerialTaskDispatcher::OnNewTaskIn, this, innerTask); + std::function < void()> callback = std::bind(&SerialTaskDispatcher::OnNewTaskIn, this, innerTask); bool executeFlag = executor_->DelayExecute(callback, delayMs); if (!executeFlag) { APP_LOGE("SerialTaskDispatcher::DelayDispatch execute failed"); diff --git a/interfaces/innerkits/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp b/interfaces/innerkits/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp index 9e22e53a26..e2c737e891 100644 --- a/interfaces/innerkits/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp +++ b/interfaces/innerkits/task_dispatcher/src/dispatcher/task_dispatcher_context.cpp @@ -128,6 +128,8 @@ int TaskDispatcherContext::MapPriorityIndex(TaskPriority priority) const return DEFAULT_PRIORITY_INDEX; case TaskPriority::LOW: return LOW_PRIORITY_INDEX; + default: + return DEFAULT_PRIORITY_INDEX; } APP_LOGE("TaskDispatcherContext.mapPriorityIndex unhandled priority=%{public}d", priority); diff --git a/interfaces/innerkits/task_dispatcher/src/task/barrier_handler.cpp b/interfaces/innerkits/task_dispatcher/src/task/barrier_handler.cpp index a8d0c7a42f..0f4706ac1a 100644 --- a/interfaces/innerkits/task_dispatcher/src/task/barrier_handler.cpp +++ b/interfaces/innerkits/task_dispatcher/src/task/barrier_handler.cpp @@ -171,9 +171,9 @@ bool BarrierHandler::HasTask(const std::set> &tasks) std::set> BarrierHandler::CreateTaskSet(std::shared_ptr &firstTask) { - std::set> newSet; - newSet.insert(firstTask); - return newSet; + std::set> taskSet; + taskSet.insert(firstTask); + return taskSet; } } // namespace AppExecFwk diff --git a/interfaces/innerkits/task_dispatcher/src/task/task.cpp b/interfaces/innerkits/task_dispatcher/src/task/task.cpp index dd23ef89d6..6f73cfc53f 100644 --- a/interfaces/innerkits/task_dispatcher/src/task/task.cpp +++ b/interfaces/innerkits/task_dispatcher/src/task/task.cpp @@ -37,9 +37,9 @@ Task::~Task() {} /** - *@brief invoke the function to execute the task - *@param None - *@return None + * @brief invoke the function to execute the task + * @param None + * @return None */ void Task::Run() { @@ -57,9 +57,9 @@ void Task::Run() } /** - * @brief Gets the priority. - * @param None - * @return The priority. + * @brief Gets the priority. + * @param None + * @return The priority. */ TaskPriority Task::GetPriority() const { @@ -67,10 +67,10 @@ TaskPriority Task::GetPriority() const } /** - * @brief Sets the sequence. - * @param None - * @param sequence The sequence - * @return None + * @brief Sets the sequence. + * @param None + * @param sequence The sequence + * @return None */ void Task::SetSequence(long sequence) { @@ -78,9 +78,9 @@ void Task::SetSequence(long sequence) } /** - *@brief Gets the sequence. - *@param None - *@return The sequence. + * @brief Gets the sequence. + * @param None + * @return The sequence. */ long Task::GetSequence() const { @@ -88,9 +88,9 @@ long Task::GetSequence() const } /** - *@brief Revoke this task if hasn't run. - *@param None - *@return true if set revoked or already revoked. False if the task has start executing. + * @brief Revoke this task if hasn't run. + * @param None + * @return true if set revoked or already revoked. False if the task has start executing. */ bool Task::Revoke() { @@ -107,9 +107,9 @@ bool Task::Revoke() } /** - *@brief Adds a task listener. - *@param listener The listener - *@return None + * @brief Adds a task listener. + * @param listener The listener + * @return None */ void Task::AddTaskListener(const std::shared_ptr &listener) { @@ -118,9 +118,9 @@ void Task::AddTaskListener(const std::shared_ptr &listener) } /** - *@brief Called when task is about to run. - *@param None - *@return None + * @brief Called when task is about to run. + * @param None + * @return None */ void Task::BeforeTaskExecute() { @@ -130,9 +130,9 @@ void Task::BeforeTaskExecute() } /** - *@brief Called when task is done. - *@param None - *@return None + * @brief Called when task is done. + * @param None + * @return None */ void Task::AfterTaskExecute() { @@ -143,9 +143,9 @@ void Task::AfterTaskExecute() } /** - *@brief Called when task is canceled. - *@param None - *@return None + * @brief Called when task is canceled. + * @param None + * @return None */ void Task::OnTaskCanceled() { @@ -154,9 +154,9 @@ void Task::OnTaskCanceled() } /** - *@brief Return true if not executed or revoked, and if not executed or revoked, ensure |EXECUTED| to be set. - *@param None - *@return bool + * @brief Return true if not executed or revoked, and if not executed or revoked, ensure |EXECUTED| to be set. + * @param None + * @return bool */ bool Task::EnterExecute() { diff --git a/interfaces/innerkits/task_dispatcher/src/threading/task_executor.cpp b/interfaces/innerkits/task_dispatcher/src/threading/task_executor.cpp index 406f79dd31..197f1ae4e5 100644 --- a/interfaces/innerkits/task_dispatcher/src/threading/task_executor.cpp +++ b/interfaces/innerkits/task_dispatcher/src/threading/task_executor.cpp @@ -94,7 +94,7 @@ std::shared_ptr TaskExecutor::GetTask(const std::shared_ptr std::shared_ptr nullRunnable = nullptr; std::shared_ptr next = nullptr; - for (;;) { + for(;;) { if (terminated_.load() && pendingTasks_->Empty()) { APP_LOGI("TaskExecutor::GetTask end: loop thread %{public}s is terminated", workerThread->GetThreadName().c_str()); @@ -204,7 +204,7 @@ bool TaskExecutor::EnsureConsumeStarted() void TaskExecutor::Consume() { - for (;;) { + for(;;) { if (terminated_.load() && delayTasks_->Empty()) { APP_LOGI("TaskExecutor::Consume delay task is empty"); break; diff --git a/interfaces/innerkits/task_dispatcher/src/threading/worker_pool.cpp b/interfaces/innerkits/task_dispatcher/src/threading/worker_pool.cpp index 957c392fbd..1376449706 100644 --- a/interfaces/innerkits/task_dispatcher/src/threading/worker_pool.cpp +++ b/interfaces/innerkits/task_dispatcher/src/threading/worker_pool.cpp @@ -237,32 +237,44 @@ bool WorkerPool::AddWorker(const std::shared_ptr &delegate, const std: return added; } std::unique_lock mLock(poolLock_); - std::shared_ptr workerThread = nullptr; - for(;;) { + std::shared_ptr newThread = nullptr; + + for (;;) { unsigned int value = control_.load(); int num = GetWorkingThreadNum(value); if (num >= thread_limit_) { - APP_LOGI("WorkerPool::AddWorker thread count exceed limits, num=%{public}d", num); + APP_LOGI("WorkerPool::AddWorker thread count exceed limits, num=%{public}d, limits=%{public}d", + num, + thread_limit_); break; } if (!IsRunning(value)) { - APP_LOGI("WorkerPool::AddWorker thread pool is not running. value=%{public}d, closing=%{public}d, ", + APP_LOGI("WorkerPool::AddWorker thread pool is not running. value=%{public}d, closing=%{public}d, " + "count_bits=%{public}d", value, - CLOSING); + CLOSING, + COUNT_BITS); break; } + if (CompareAndIncThreadNum(num)) { - workerThread = std::make_shared(delegate, task, factory_); - if (workerThread == nullptr) { + newThread = std::make_shared(delegate, task, factory_); + if (newThread == nullptr) { APP_LOGE("WorkerPool::AddWorker create thread fail"); break; } - workerThread->CreateThread(); - pool_.emplace_back(workerThread); + + newThread->CreateThread(); + + APP_LOGI("WorkerPool::AddWorker create new thread"); + + pool_.emplace_back(newThread); APP_LOGI("WorkerPool::AddWorker pool_ add thread ,POOL SIZE: %{public}zu", pool_.size()); + added = true; break; } + APP_LOGW("WorkerPool::AddWorker set thread state error. retry. "); } return added; @@ -307,7 +319,7 @@ bool WorkerPool::IsRunning(int ctl) return ctl < CLOSING; } -int WorkerPool::GetStateFromControl(unsigned int ctl) +int WorkerPool::GetStateFromControl(int ctl) { return ctl & ~CAPACITY; } @@ -315,7 +327,7 @@ int WorkerPool::GetStateFromControl(unsigned int ctl) void WorkerPool::AdvanceStateTo(unsigned int target) { APP_LOGI("WorkerPool::AdvanceStateTo begin"); - for(;;) { + for (;;) { unsigned int current = control_.load(); if ((current >= target) || CompareAndSet(control_, current, CombineToControl(target, GetWorkingThreadNum(current)))) { @@ -333,7 +345,7 @@ int WorkerPool::CombineToControl(unsigned int state, unsigned int count) bool WorkerPool::CompareAndIncThreadNum(int expect) { - unsigned int ctl = control_.load(); + int ctl = control_.load(); int state = GetStateFromControl(ctl); return CompareAndSet(control_, ctl, CombineToControl(state, expect + 1)); } @@ -355,7 +367,7 @@ bool WorkerPool::CompareAndDecThreadNum(int expect) bool WorkerPool::CompareAndDecNum(int expectCount) { - unsigned int curr = control_.load(); + int curr = control_.load(); int state = GetStateFromControl(curr); int expectControl = CombineToControl(state, expectCount); return CompareAndDecThreadNum(expectControl); diff --git a/interfaces/innerkits/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp b/interfaces/innerkits/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp index 90a170230a..57eedb0cf9 100644 --- a/interfaces/innerkits/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp +++ b/interfaces/innerkits/task_dispatcher/test/unittest/barrier_handler_test/barrier_handler_test.cpp @@ -76,7 +76,6 @@ HWTEST(BarrierHandlerTest, BarrierHandler_interceptTest_001, TestSize.Level0) auto name = std::string("BarrierHandler_interceptTest_001"); GTEST_LOG_(INFO) << name << " start"; std::shared_ptr barrierHandler = CreateBarrierHandler(); - //每次添加组任务, 给任务添加监听,当任务完成时候。。。。。判断任务是否应该执行(前面有屏障时候,不立即执行)。 std::shared_ptr runnable = std::make_shared([&]() { GTEST_LOG_(INFO) << name << " Runnable"; }); std::shared_ptr task = std::make_shared(runnable, TaskPriority::DEFAULT, nullptr); ErrCode result = barrierHandler->Intercept(task); diff --git a/interfaces/innerkits/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp b/interfaces/innerkits/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp index 0daf94b278..2a9931d164 100644 --- a/interfaces/innerkits/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp +++ b/interfaces/innerkits/task_dispatcher/test/unittest/groupImpl_test/groupImpl_test.cpp @@ -175,9 +175,9 @@ HWTEST(GroupImplTest, AppExecFwk_GroupImpl_AddNotification_002, TestSize.Level0) std::make_shared([&]() { GTEST_LOG_(INFO) << "GroupImpl AddNotification"; }); groupPtr->AddNotification(notification); } - std::shared_ptr newNotification = + std::shared_ptr notificationTask = std::make_shared([&]() { GTEST_LOG_(INFO) << "GroupImpl AddNotification"; }); - bool result = groupPtr->AddNotification(newNotification); + bool result = groupPtr->AddNotification(notificationTask); EXPECT_TRUE(result); GTEST_LOG_(INFO) << name << " end"; } @@ -198,9 +198,9 @@ HWTEST(GroupImplTest, AppExecFwk_GroupImpl_AddNotification_003, TestSize.Level0) std::make_shared([&]() { GTEST_LOG_(INFO) << "GroupImpl AddNotification"; }); groupPtr->AddNotification(notification); } - std::shared_ptr newNotification = + std::shared_ptr notificationTask = std::make_shared([&]() { GTEST_LOG_(INFO) << "GroupImpl AddNotification"; }); - bool result = groupPtr->AddNotification(newNotification); + bool result = groupPtr->AddNotification(notificationTask); EXPECT_FALSE(result); GTEST_LOG_(INFO) << name << " end"; } diff --git a/interfaces/innerkits/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp b/interfaces/innerkits/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp index 5347daaca1..a7e924cf02 100644 --- a/interfaces/innerkits/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp +++ b/interfaces/innerkits/task_dispatcher/test/unittest/parallel_task_dispatcher_base_test/parallel_task_dispatcher_base_test.cpp @@ -194,7 +194,6 @@ HWTEST(ParallelTaskDispatcherBaseTest, ParallelTaskDispatcherBase_AsyncGroupDisp CreateParallelTaskDispatcherBase(name, TaskPriority::DEFAULT); std::atomic count(0); EXPECT_EQ(count.load(), 0); - //添加个group1 std::shared_ptr group1 = parallelTaskDispatcherBase->CreateDispatchGroup(); std::shared_ptr group1Run1 = std::make_shared([&]() { std::this_thread::sleep_for(std::chrono::milliseconds(800)); @@ -209,7 +208,6 @@ HWTEST(ParallelTaskDispatcherBaseTest, ParallelTaskDispatcherBase_AsyncGroupDisp GTEST_LOG_(INFO) << name << " Group1 : Runnable2"; }); parallelTaskDispatcherBase->AsyncGroupDispatch(group1, group1Run2); - //添加group2 std::shared_ptr group2 = parallelTaskDispatcherBase->CreateDispatchGroup(); std::shared_ptr group2Run = std::make_shared([&]() { count.fetch_add(1); diff --git a/interfaces/innerkits/task_dispatcher/test/unittest/spec_task_dispatcher_test/spec_task_dispatcher_test.cpp b/interfaces/innerkits/task_dispatcher/test/unittest/spec_task_dispatcher_test/spec_task_dispatcher_test.cpp index 8c4ad4db71..07212360d0 100644 --- a/interfaces/innerkits/task_dispatcher/test/unittest/spec_task_dispatcher_test/spec_task_dispatcher_test.cpp +++ b/interfaces/innerkits/task_dispatcher/test/unittest/spec_task_dispatcher_test/spec_task_dispatcher_test.cpp @@ -59,17 +59,10 @@ void SpecTaskDispatcherTest::SetUp() void SpecTaskDispatcherTest::TearDown() {} -std::string Now() -{ - time_t now = std::time(0); - char mbstr[10]; - std::strftime(mbstr, sizeof(mbstr), "%T", std::localtime(&now)); - return mbstr; -} const std::string Prefix(const std::string &name) { - return std::string(">>> ") + Now() + std::string(" ") + name + std::string(": "); + return std::string(">>> prefix :") + std::string(" ") + name + std::string(": "); } std::shared_ptr CreateSpecTaskDispatcher() diff --git a/interfaces/innerkits/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/global_task_dispatcher_module_test.cpp b/interfaces/innerkits/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/global_task_dispatcher_module_test.cpp index b86f8b0469..6abe4204c1 100644 --- a/interfaces/innerkits/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/global_task_dispatcher_module_test.cpp +++ b/interfaces/innerkits/test/moduletest/task_dispatcher/global_task_dispatcher_module_test/global_task_dispatcher_module_test.cpp @@ -55,6 +55,7 @@ void GlobalTaskDispatcherModuleTest::TearDown() std::shared_ptr GlobalTaskDispatcherModuleTest::GetMtGlobalTaskDispatcher(TaskPriority priority) const { + // TaskDispatcherContext context; std::shared_ptr ptrGlobalTaskDispatcher = context->GetGlobalTaskDispatcher(priority); return ptrGlobalTaskDispatcher; } diff --git a/interfaces/innerkits/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp b/interfaces/innerkits/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp index 21e0da663c..ee540863f7 100644 --- a/interfaces/innerkits/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp +++ b/interfaces/innerkits/test/moduletest/task_dispatcher/serial_task_dispatcher_module_test/serial_task_dispatcher_module_test.cpp @@ -203,35 +203,6 @@ HWTEST_F(SerialTaskDispatcherModuleTest, SerialTaskDispatcher_AsyncDispatchTest_ GTEST_LOG_(INFO) << name + " end"; } -void DelayDispatchTestWait (std::atomic &count){ - { - long wait = 100; - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - } - { - long wait = 1000; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 2); - } - { - long wait = 500; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 2); - } - { - long wait = 1000; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 3); - } -} - /** * @tc.number: SerialTaskDispatcher_DelayDispatchTest_001 * @tc.name: DelayDispatch @@ -272,7 +243,33 @@ HWTEST_F(SerialTaskDispatcherModuleTest, SerialTaskDispatcher_DelayDispatchTest_ }), sleep3); EXPECT_TRUE(count.load() == 0); - DelayDispatchTestWait(count); + + { + long wait = 100; + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + } + { + long wait = 1000; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 2); + } + { + long wait = 500; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 2); + } + { + long wait = 1000; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 3); + } GTEST_LOG_(INFO) << name + " end"; } diff --git a/interfaces/innerkits/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp b/interfaces/innerkits/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp index ce6b5b3336..d251f276dd 100644 --- a/interfaces/innerkits/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp +++ b/interfaces/innerkits/test/moduletest/task_dispatcher/spec_task_dispatcher_module_test/spec_task_dispatcher_module_test.cpp @@ -130,35 +130,6 @@ HWTEST_F(SpecTaskDispatcherModuleTest, SpecTaskDispatcher_AsyncDispatchTest_001, GTEST_LOG_(INFO) << name + " end"; } -void DelayDispatcherTestWait(std::atomic &count){ - { - long wait = 100; - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - } - { - long wait = 1000; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 2); - } - { - long wait = 500; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 2); - } - { - long wait = 1000; - GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); - auto time = std::chrono::milliseconds(wait); - std::this_thread::sleep_for(time); - EXPECT_TRUE(count.load() == 3); - } -} - /** * @tc.number: SpecTaskDispatcher_DelayDispatchTest_001 * @tc.name: DelayDispatch @@ -199,7 +170,33 @@ HWTEST_F(SpecTaskDispatcherModuleTest, SpecTaskDispatcher_DelayDispatchTest_001, }), sleep3); EXPECT_TRUE(count.load() == 0); - DelayDispatcherTestWait(count); + + { + long wait = 100; + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + } + { + long wait = 1000; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 2); + } + { + long wait = 500; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 2); + } + { + long wait = 1000; + GTEST_LOG_(INFO) << ("wait for task, wait= " + std::to_string(wait) + " ms"); + auto time = std::chrono::milliseconds(wait); + std::this_thread::sleep_for(time); + EXPECT_TRUE(count.load() == 3); + } GTEST_LOG_(INFO) << name + " end"; } diff --git a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp index 2f02deeccf..1f7d91b5b6 100644 --- a/kits/appkit/napi/bundlemgr/bundle_mgr.cpp +++ b/kits/appkit/napi/bundlemgr/bundle_mgr.cpp @@ -956,7 +956,7 @@ static napi_value ParseInt(napi_env env, int ¶m, napi_value args) NAPI_CALL(env, napi_typeof(env, args, &valuetype)); HILOG_INFO("param=%{public}d.", valuetype); NAPI_ASSERT(env, valuetype == napi_number, "Wrong argument type. int32 expected."); - int32_t value; + int32_t value = 0; napi_get_value_int32(env, args, &value); HILOG_INFO("param=%{public}d.", value); param = value; @@ -1031,7 +1031,7 @@ napi_value GetApplicationInfos(napi_env env, napi_callback_info info) applicationFlag = ApplicationFlag::GET_BASIC_APPLICATION_INFO; } - AsyncApplicationInfosCallbackInfo *asyncCallbackInfo = new AsyncApplicationInfosCallbackInfo{ + AsyncApplicationInfosCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncApplicationInfosCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .applicationFlag = applicationFlag, .userId = userId}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -1363,7 +1363,7 @@ napi_value GetApplicationInfo(napi_env env, napi_callback_info info) if (flag == static_cast(ApplicationFlag::GET_BASIC_APPLICATION_INFO)) { applicationFlag = ApplicationFlag::GET_BASIC_APPLICATION_INFO; } - AsyncApplicationInfoCallbackInfo *asyncCallbackInfo = new AsyncApplicationInfoCallbackInfo{.env = env, + AsyncApplicationInfoCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncApplicationInfoCallbackInfo{.env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleName = bundleName, @@ -1533,7 +1533,7 @@ napi_value GetBundleInfos(napi_env env, napi_callback_info info) if (flag == static_cast(BundleFlag::GET_BUNDLE_DEFAULT)) { bundleFlag = BundleFlag::GET_BUNDLE_DEFAULT; } - AsyncBundleInfosCallbackInfo *asyncCallbackInfo = new AsyncBundleInfosCallbackInfo{ + AsyncBundleInfosCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncBundleInfosCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleFlag = bundleFlag}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -1665,7 +1665,7 @@ napi_value GetBundleInfo(napi_env env, napi_callback_info info) if (flag == static_cast(BundleFlag::GET_BUNDLE_DEFAULT)) { bundleFlag = BundleFlag::GET_BUNDLE_DEFAULT; } - AsyncBundleInfoCallbackInfo *asyncCallbackInfo = new AsyncBundleInfoCallbackInfo{ + AsyncBundleInfoCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncBundleInfoCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .param = bundleName, .bundleFlag = bundleFlag}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -1798,7 +1798,7 @@ napi_value GetBundleArchiveInfo(napi_env env, napi_callback_info info) if (flag == static_cast(BundleFlag::GET_BUNDLE_DEFAULT)) { bundleFlag = BundleFlag::GET_BUNDLE_DEFAULT; } - AsyncBundleInfoCallbackInfo *asyncCallbackInfo = new AsyncBundleInfoCallbackInfo{ + AsyncBundleInfoCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncBundleInfoCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .param = hapFilePath, .bundleFlag = bundleFlag}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -1983,7 +1983,7 @@ napi_value GetPermissionDef(napi_env env, napi_callback_info info) HILOG_INFO("argc = [%{public}zu]", argc); std::string permissionName; ParseString(env, permissionName, argv[PARAM0]); - AsyncPermissionDefCallbackInfo *asyncCallbackInfo = new AsyncPermissionDefCallbackInfo{ + AsyncPermissionDefCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncPermissionDefCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .permissionName = permissionName}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -2391,7 +2391,7 @@ napi_value Install(napi_env env, napi_callback_info info) ParseStringArray(env, bundleFilePaths, argv[PARAM0]); InstallParam installParam; ParseInstallParam(env, installParam, argv[PARAM1]); - AsyncInstallCallbackInfo *asyncCallbackInfo = new AsyncInstallCallbackInfo{ + AsyncInstallCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncInstallCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, @@ -2553,7 +2553,7 @@ napi_value Uninstall(napi_env env, napi_callback_info info) ParseString(env, bundleName, argv[PARAM0]); InstallParam installParam; ParseInstallParam(env, installParam, argv[PARAM1]); - AsyncInstallCallbackInfo *asyncCallbackInfo = new AsyncInstallCallbackInfo{ + AsyncInstallCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncInstallCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, @@ -2845,7 +2845,7 @@ napi_value GetFormsInfoByModule(napi_env env, napi_callback_info info) ParseString(env, bundleName, argv[PARAM0]); ParseString(env, moduleName, argv[PARAM1]); - AsyncFormInfosByModuleCallbackInfo *asyncCallbackInfo = new AsyncFormInfosByModuleCallbackInfo{ + AsyncFormInfosByModuleCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncFormInfosByModuleCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleName = bundleName, .moduleName = moduleName}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -2969,7 +2969,7 @@ napi_value GetFormsInfoByApp(napi_env env, napi_callback_info info) std::string bundleName; ParseString(env, bundleName, argv[PARAM0]); - AsyncFormInfosByAppCallbackInfo *asyncCallbackInfo = new AsyncFormInfosByAppCallbackInfo{ + AsyncFormInfosByAppCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncFormInfosByAppCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleName = bundleName}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -3111,7 +3111,7 @@ napi_value GetShortcutInfos(napi_env env, napi_callback_info info) HILOG_INFO("ARGCSIZE is =%{public}zu.", argc); std::string bundleName; ParseString(env, bundleName, argv[PARAM0]); - AsyncShortcutInfosCallbackInfo *asyncCallbackInfo = new AsyncShortcutInfosCallbackInfo{ + AsyncShortcutInfosCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncShortcutInfosCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleName = bundleName}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -3253,7 +3253,7 @@ napi_value GetModuleUsageRecords(napi_env env, napi_callback_info info) HILOG_INFO("ARGCSIZE is =%{public}zu.", argc); int number; ParseInt(env, number, argv[PARAM0]); - AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = new AsyncModuleUsageRecordsCallbackInfo{ + AsyncModuleUsageRecordsCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncModuleUsageRecordsCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .number = number}; if (asyncCallbackInfo == nullptr) { return nullptr; @@ -3495,6 +3495,9 @@ napi_value RegisterAllPermissionsChanged(napi_env env, napi_callback_info info) } else if (permissionEvent == ANY_PERMISSION_CHANGE && argc == ARGS_SIZE_TWO) { AsyncRegisterAllPermissions *asyncCallbackInfo = new AsyncRegisterAllPermissions{.env = env, .asyncWork = nullptr}; + if (asyncCallbackInfo == nullptr) { + return nullptr; + } HILOG_INFO("RegisterAllPermissionsChanged anyPermissionChange asyncCallback."); napi_valuetype valuetype = napi_undefined; napi_typeof(env, argv[ARGS_SIZE_ONE], &valuetype); @@ -3616,7 +3619,7 @@ napi_value UnregisterPermissionsChanged(napi_env env, napi_callback_info info) ParseString(env, permissionEvent, argv[PARAM0]); if (permissionEvent == ANY_PERMISSION_CHANGE && argc == ARGS_SIZE_TWO) { - AsyncUnregisterPermissions *asyncCallbackInfo = new AsyncUnregisterPermissions{ + AsyncUnregisterPermissions *asyncCallbackInfo = new (std::nothrow) AsyncUnregisterPermissions{ .env = env, .asyncWork = nullptr, }; @@ -3756,7 +3759,7 @@ napi_value CheckPermission(napi_env env, napi_callback_info info) std::string permission; ParseString(env, permission, argv[PARAM1]); - AsyncPermissionCallbackInfo *asyncCallbackInfo = new AsyncPermissionCallbackInfo{ + AsyncPermissionCallbackInfo *asyncCallbackInfo = new (std::nothrow) AsyncPermissionCallbackInfo{ .env = env, .asyncWork = nullptr, .deferred = nullptr, .bundleName = bundleName, .permission = permission}; if (asyncCallbackInfo == nullptr) { return nullptr; diff --git a/kits/appkit/napi/bundlemgr/permission_callback.cpp b/kits/appkit/napi/bundlemgr/permission_callback.cpp index 57d65185bd..80929431b7 100644 --- a/kits/appkit/napi/bundlemgr/permission_callback.cpp +++ b/kits/appkit/napi/bundlemgr/permission_callback.cpp @@ -38,23 +38,16 @@ void PermissionCallback::OnChanged(const int32_t uid) napi_get_uv_event_loop(env_, &loop); #endif // NAPI_VERSION >= 2 - uv_work_t *work = new (std::nothrow) uv_work_t; - if (work == nullptr) { - HILOG_ERROR("new uv_work_t failed"); - return; - } - CallbackInfo *callbackInfo = new (std::nothrow) CallbackInfo { + uv_work_t *work = new uv_work_t; + CallbackInfo *callbackInfo = new (std::nothrow) CallbackInfo{ .env = env_, .callback = callback_, .uid = uid, }; - if (callbackInfo == nullptr) { - HILOG_ERROR("new CallbackInfo failed"); - return; - } + work->data = (void *)callbackInfo; - int rev = uv_queue_work( + uv_queue_work( loop, work, [](uv_work_t *work) {}, @@ -82,13 +75,6 @@ void PermissionCallback::OnChanged(const int32_t uid) delete event; delete work; }); - if (rev != 0) { - if (callbackInfo != nullptr) { - delete callbackInfo; - } - if (work != nullptr) { - delete work; - } - } + HILOG_INFO("OnChanged, end"); } \ No newline at end of file diff --git a/kits/appkit/native/app/include/task_dispatcher.h b/kits/appkit/native/app/include/task_dispatcher.h index ad06df59ea..4ddee5b983 100644 --- a/kits/appkit/native/app/include/task_dispatcher.h +++ b/kits/appkit/native/app/include/task_dispatcher.h @@ -25,7 +25,7 @@ namespace OHOS { namespace AppExecFwk { -template +template using IteratableTask = std::function; class TaskDispatcher { @@ -33,31 +33,15 @@ public: virtual ~TaskDispatcher() = default; /** - * Dispatches a task and waits until the task is complete in the current thread. + * @brief Dispatches a task and waits until the task is complete in the current thread. * - *

The current thread is blocked before the given task is complete. Therefore, a deadlock occurs in the - * following cases: - *

- *
    - *
  1. - * {@code SyncDispatch} is cyclically called on a serial task dispatcher or a task dispatcher that is dedicated - * to a specific thread. For example, {@code SyncDispatch} is called to dispatch a task from dispatcher A to - * dispatcher A, or to dispatch a task from dispatcher A to dispatcher B and then back to dispatcher A. - *
  2. - *
  3. - * Too many threads are blocked on {@code SyncDispatch}. As a result, the internal thread pool is used up and - * cannot process other tasks any more. - *
  4. - *
- *
* @param runnable Indicates the task to be executed. This parameter includes all information required for the task * execution. - * @since 1 */ virtual ErrCode SyncDispatch(const std::shared_ptr &runnable) = 0; /** - * Asynchronously dispatches a task. + * @brief Asynchronously dispatches a task. * *

This method dispatches a task and returns a value immediately without waiting for the task to execute.

* @@ -65,12 +49,11 @@ public: * execution. * @return Returns a {@link std::shared_ptr} instance used for revoking the given task * if it has not been invoked. - * @since 1 */ virtual std::shared_ptr AsyncDispatch(const std::shared_ptr &runnable) = 0; /** - * Dispatches a task after the given delay. + * @brief Dispatches a task after the given delay. * *

This is an asynchronous execution and returns a value immediately without waiting. The task will be * dispatched to the queue after the given delay specified by {@code delayMs}, and its actual execution time @@ -83,12 +66,11 @@ public: * @param delayMs Indicates the time period that the given task has to wait before being dispatched. * @return Returns a {@link std::shared_ptr} instance used for revoking the given task * if it has not been invoked. - * @since 1 */ virtual std::shared_ptr DelayDispatch(const std::shared_ptr &runnable, long delayMs) = 0; /** - * Sets an execution barrier in a task group for the given task and waits for the task to be executed after all + * @brief Sets an execution barrier in a task group for the given task and waits for the task to be executed after all * tasks in the task group are finished. * *

The current thread is blocked until the given task is complete. Incorrect use of this method may cause a @@ -96,12 +78,11 @@ public: * If too many threads are blocked, resources in the thread pool will be used up.

* * @param runnable Indicates the task to be executed. - * @since 1 */ virtual ErrCode SyncDispatchBarrier(const std::shared_ptr &runnable) = 0; /** - * Sets an execution barrier for the given task to be executed only after all tasks in the task group are + * @brief Sets an execution barrier for the given task to be executed only after all tasks in the task group are * finished. This method does not wait for the given task to execute. * *

Task execution barriers are unavailable on global task dispatchers. Example code for setting a task @@ -122,21 +103,17 @@ public: * std::cout << "after barrier" << std::endl; * })); * - * // Result will be: - * // before barrier - * // Barrier - * // after barrier + * // Result will be: 1.before barrier; 2.Barrier; 3.after barrier. * } * * * @param runnable Indicates the task to be executed. This parameter includes all information required for the task * execution. - * @since 1 */ virtual ErrCode AsyncDispatchBarrier(const std::shared_ptr &runnable) = 0; /** - * Creates a task group. + * @brief Creates a task group. * *

The {@link std::shared_ptr} object returned by this method does not contain any task. * If you need to dispatch tasks asynchronously, you can use {@link #asyncGroupDispatch} to associate this object @@ -170,21 +147,12 @@ public: * std::cout << "2" << std::endl; * } * - * //Possible results are as follows: - * // 1 - * // 2 - * // Finished downloading URL 2 - * // Finished downloading URL 1 - * // All tasks finished. Do shutdown. - * } - * * @return Returns a {@link std::shared_ptr} object. - * @since 1 */ virtual std::shared_ptr CreateDispatchGroup() = 0; /** - * Adds a task to a task group asynchronously. + * @brief Adds a task to a task group asynchronously. * *

This method returns a value immediately without waiting for the task to execute.

* @@ -193,55 +161,34 @@ public: * execution. * @return Returns a {@link std::shared_ptr} instance used for revoking the given task * if it has not been invoked. - * @since 1 */ virtual std::shared_ptr AsyncGroupDispatch( const std::shared_ptr &group, const std::shared_ptr &runnable) = 0; /** - * Waits all tasks in a task group to finish. + * @brief Waits all tasks in a task group to finish. * * @param group Indicates the task group containing the waiting tasks. * @param timeout Indicates the maximum waiting time for a task. * @return Returns {@code true} if all tasks are correctly executed; returns {@code false} if any task times out. - * @since 1 */ virtual bool GroupDispatchWait(const std::shared_ptr &group, long timeout) = 0; /** - * Executes a task after all tasks in the task group are finished. + * @brief Executes a task after all tasks in the task group are finished. * * @param group Indicates the task group containing the waiting tasks. * @param runnable Indicates the task to be executed after all tasks are finished. - * @since 1 */ virtual ErrCode GroupDispatchNotify( const std::shared_ptr &group, const std::shared_ptr &runnable) = 0; /** - * Executes a task multiple times without waiting. - * - *

Example code: - *

{@code
-     * std::string names[] = {"Rafael Nadal", "Novak Djokovic",
-     *         "Stanislas Wawrinka",
-     *         "David Ferrer","Roger Federer",
-     *         "Andy Murray","Tomas Berdych",
-     *         "Juan Martin Del Potro"};
-     * int num = atp.length;
-     * std::shared_ptr dispatcher = context.getGlobalTaskDispatcher(TaskPriority.DEFAULT);
-     * // Concurrently dispatches tasks using names in |names|.
-     * dispatcher->ApplyDispatch([](i) {
-     *     std::cout << names[i] << std::endl;
-     * }, num);
-     * // The result to be returned depends on thread scheduling of the system.
-     * }
-     * 
+ * @brief Executes a task multiple times without waiting. * * @param task Indicates the task to be executed. This parameter includes all information required for the task * execution. * @param iterations Indicates the number of times the task is executed. The value must be a positive integer. - * @since 1 */ virtual ErrCode ApplyDispatch(const std::shared_ptr> &task, long iterations) = 0; }; diff --git a/libs/test/moduletest/common/event_handler/event_handler_press_module_test.cpp b/libs/test/moduletest/common/event_handler/event_handler_press_module_test.cpp index 49dd92d300..3d8f773fff 100644 --- a/libs/test/moduletest/common/event_handler/event_handler_press_module_test.cpp +++ b/libs/test/moduletest/common/event_handler/event_handler_press_module_test.cpp @@ -211,9 +211,9 @@ HWTEST_F(EventHandlerPressModuleTest, FdListenerPress001, TestSize.Level3) auto myRunner = EventRunner::Create(false); auto handler = std::make_shared(myRunner); auto inResult = handler->AddFileDescriptorListener(fds[0], FILE_DESCRIPTOR_INPUT_EVENT, listener); - ASSERT_EQ(inResult, ERR_OK); + EXPECT_EQ(inResult, ERR_OK); auto outResult = handler->AddFileDescriptorListener(fds[1], FILE_DESCRIPTOR_OUTPUT_EVENT, listener); - ASSERT_EQ(outResult, ERR_OK); + EXPECT_EQ(outResult, ERR_OK); int64_t delayTime = 20000; int64_t param = 0; diff --git a/services/appmgr/src/lmks/lmks_utils.cpp b/services/appmgr/src/lmks/lmks_utils.cpp index e64ff67a94..6c0ea2af75 100644 --- a/services/appmgr/src/lmks/lmks_utils.cpp +++ b/services/appmgr/src/lmks/lmks_utils.cpp @@ -108,7 +108,7 @@ std::string LmksUtils::GetProcName(pid_t pid) return name; } - if (strlen(line) < PROC_LINE_MAX && strlen(line) != 0) { + if (strlen(line) + 1 <= PROC_LINE_MAX && strlen(line) != 0) { name = line; } else { HiLog::Error(LABEL, "cmdline no data"); @@ -160,7 +160,7 @@ int LmksUtils::GetProcSize(pid_t pid) return -1; } - if ((strlen(line) < PROC_LINE_MAX && strlen(line) != 0) && (sscanf_s(line, "%d %d ", &total, &rss) > 0)) { + if ((strlen(line) + 1 <= PROC_LINE_MAX && strlen(line) != 0) && (sscanf_s(line, "%d %d ", &total, &rss) > 0)) { HiLog::Info(LABEL, "pid %{public}d total %{public}d rss %{public}d", pid, total, rss); } else { HiLog::Error(LABEL, "strlen or sscanf_s err %{public}s", strerror(errno)); diff --git a/services/appmgr/src/process_optimizer.cpp b/services/appmgr/src/process_optimizer.cpp index 92607f8377..bc5c3dca6d 100644 --- a/services/appmgr/src/process_optimizer.cpp +++ b/services/appmgr/src/process_optimizer.cpp @@ -709,11 +709,6 @@ void ProcessOptimizer::SetAppFreezingTime(int time) suspendTimeout_ = time; // convert seconds to milliseconds suspendTimeout_ *= TIME_ADVANCE_RATE; - if (suspendTimeout_ > INT_MAX) { - suspendTimeout_ = APP_SUSPEND_TIMEOUT_DEFAULT; - APP_LOGE("data overflow"); - return; - } } void ProcessOptimizer::GetAppFreezingTime(int &time) diff --git a/services/appmgr/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp b/services/appmgr/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp index 2ef8359100..65fd2f308a 100644 --- a/services/appmgr/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp +++ b/services/appmgr/test/unittest/ams_service_load_ability_process_test/ams_service_load_ability_process_test.cpp @@ -129,12 +129,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_001, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); APP_LOGI("AmsServiceLoadAbilityProcessTest LoadAbility_001 end"); } @@ -171,13 +171,13 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_002, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = GetMockToken(); @@ -195,10 +195,10 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_002, TestSize.Level1) const uint32_t EXPECT_MAP_SIZE = 2; EXPECT_EQ(recordMap.size(), EXPECT_MAP_SIZE); auto record2 = service_->GetAppRunningRecordByAppName(GetTestAppName() + "_1"); - EXPECT_NE(record2, nullptr); + ASSERT_NE(record2, nullptr); EXPECT_EQ(record2->GetState(), ApplicationState::APP_STATE_CREATE); auto abilityRecord2 = record2->GetAbilityRunningRecordByToken(token2); - EXPECT_NE(abilityRecord2, nullptr); + ASSERT_NE(abilityRecord2, nullptr); EXPECT_EQ(abilityRecord2->GetState(), AbilityState::ABILITY_STATE_CREATE); APP_LOGI("AmsServiceLoadAbilityProcessTest LoadAbility_002 end"); } @@ -348,12 +348,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_007, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); std::shared_ptr mockClientPtr = std::make_shared(); EXPECT_CALL(*mockClientPtr, StartProcess(_, _)).Times(0); @@ -394,12 +394,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_008, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = new MockAbilityToken(); sptr preToken = token; @@ -418,7 +418,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LoadAbility_008, TestSize.Level1) const auto &abilityMap2 = record2->GetAbilities(); EXPECT_EQ(abilityMap2.size(), EXPECT_MAP_SIZE); auto abilityRecord2 = record2->GetAbilityRunningRecordByToken(token2); - EXPECT_NE(abilityRecord2, nullptr); + ASSERT_NE(abilityRecord2, nullptr); EXPECT_EQ(abilityRecord2->GetState(), AbilityState::ABILITY_STATE_CREATE); EXPECT_EQ(abilityRecord2->GetPreToken(), token); APP_LOGI("AmsServiceLoadAbilityProcessTest LoadAbility_008 end"); @@ -455,7 +455,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, RequestProcess_001, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetPriorityObject()->GetPid(), PID); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); APP_LOGI("AmsServiceLoadAbilityProcessTest RequestProcess_001 end"); @@ -582,12 +582,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LaunchMode_001, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); APP_LOGI("AmsServiceLoadAbilityProcessTest LaunchMode_001 end"); } @@ -619,12 +619,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, LaunchMode_002, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); std::shared_ptr mockClientPtr = std::make_shared(); EXPECT_CALL(*mockClientPtr, StartProcess(_, _)).Times(0); @@ -666,12 +666,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_001, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = new MockAbilityToken(); auto abilityInfo2 = std::make_shared(); @@ -690,7 +690,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_001, TestSize.Level1) const auto &abilityMap1 = record1->GetAbilities(); EXPECT_EQ(abilityMap1.size(), (uint32_t)2); auto abilityrecord1 = record1->GetAbilityRunningRecordByToken(token2); - EXPECT_NE(abilityrecord1, nullptr); + ASSERT_NE(abilityrecord1, nullptr); EXPECT_EQ(abilityrecord1->GetState(), AbilityState::ABILITY_STATE_READY); APP_LOGI("AmsServiceLoadAbilityProcessTest StartAbility_001 end"); } @@ -720,12 +720,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_002, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = new MockAbilityToken(); auto abilityInfo2 = std::make_shared(); @@ -773,12 +773,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_003, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = new MockAbilityToken(); @@ -825,12 +825,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_004, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); auto abilityInfo2 = std::make_shared(); abilityInfo2->name = GetTestAbilityName() + "_1"; @@ -876,12 +876,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_005, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); sptr token2 = new MockAbilityToken(); auto abilityInfo2 = std::make_shared(); @@ -898,7 +898,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_005, TestSize.Level1) const auto &abilityMap1 = record1->GetAbilities(); EXPECT_EQ(abilityMap1.size(), (uint32_t)2); auto abilityrecord1 = record1->GetAbilityRunningRecordByToken(token2); - EXPECT_NE(abilityrecord1, nullptr); + ASSERT_NE(abilityrecord1, nullptr); EXPECT_EQ(abilityrecord1->GetState(), AbilityState::ABILITY_STATE_READY); APP_LOGI("AmsServiceLoadAbilityProcessTest StartAbility_005 end"); } @@ -928,12 +928,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartAbility_006, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); EXPECT_EQ(record->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); auto abilityInfo2 = std::make_shared(); abilityInfo2->name = GetTestAbilityName() + "_1"; @@ -983,12 +983,12 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess001, TestSize.Level1) EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record1 = service_->GetAppRunningRecordByAppName(GetTestAppName()); EXPECT_EQ(record1->GetPriorityObject()->GetPid(), PID); - EXPECT_NE(record1, nullptr); + ASSERT_NE(record1, nullptr); EXPECT_EQ(record1->GetState(), ApplicationState::APP_STATE_CREATE); const auto &abilityMap = record1->GetAbilities(); EXPECT_EQ(abilityMap.size(), (uint32_t)1); auto abilityRecord = record1->GetAbilityRunningRecordByToken(token); - EXPECT_NE(abilityRecord, nullptr); + ASSERT_NE(abilityRecord, nullptr); EXPECT_EQ(abilityRecord->GetState(), AbilityState::ABILITY_STATE_CREATE); APP_LOGI("AmsServiceLoadAbilityProcessTest StartProcess001 end"); } @@ -1019,7 +1019,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess002, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record1 = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record1, nullptr); + ASSERT_NE(record1, nullptr); APP_LOGI("AmsServiceLoadAbilityProcessTest StartProcess002 end"); } @@ -1050,7 +1050,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess003, TestSize.Level1) const auto &recordMap = service_->GetRecordMap(); EXPECT_EQ(recordMap.size(), (uint32_t)1); auto record1 = service_->GetAppRunningRecordByAppName(GetTestAppName()); - EXPECT_NE(record1, nullptr); + ASSERT_NE(record1, nullptr); APP_LOGI("AmsServiceLoadAbilityProcessTest StartProcess003 end"); } @@ -1083,7 +1083,7 @@ HWTEST_F(AmsServiceLoadAbilityProcessTest, StartProcess004, TestSize.Level1) .WillOnce(DoAll(SetArgReferee<1>(PID), Return(ERR_TIMED_OUT))); std::shared_ptr record = service_->GetOrCreateAppRunningRecord(token, appInfo, abilityInfo, GetTestAppName(), 0, result); - EXPECT_NE(record, nullptr); + ASSERT_NE(record, nullptr); service_->StartProcess(abilityInfo->applicationName, GetTestAppName(), record); auto record1 = service_->GetAppRunningRecordByAppRecordId(record->GetRecordId()); EXPECT_EQ(record1, nullptr); diff --git a/services/bundlemgr/include/bundle_data_storage.h b/services/bundlemgr/include/bundle_data_storage.h index 22e46e9b4f..13a7cf551b 100644 --- a/services/bundlemgr/include/bundle_data_storage.h +++ b/services/bundlemgr/include/bundle_data_storage.h @@ -47,11 +47,7 @@ public: */ virtual bool DeleteStorageBundleInfo(const std::string &deviceId, const InnerBundleInfo &innerBundleInfo); - virtual bool ResetKvStore() - { - return true; - } - + virtual bool ResetKvStore() { return true;} private: bool KeyToDeviceAndName(const std::string &key, std::string &deviceId, std::string &bundleName) const; void DeviceAndNameToKey(const std::string &deviceId, const std::string &bundleName, std::string &key) const; diff --git a/services/bundlemgr/include/bundle_data_storage_database.h b/services/bundlemgr/include/bundle_data_storage_database.h index 221aad0eef..2011167256 100644 --- a/services/bundlemgr/include/bundle_data_storage_database.h +++ b/services/bundlemgr/include/bundle_data_storage_database.h @@ -69,6 +69,7 @@ private: void DeviceAndNameToKey(const std::string &deviceId, const std::string &bundleName, std::string &key) const; DistributedKv::DistributedKvDataManager dataManager_; std::unique_ptr kvStorePtr_; + // std::shared_ptr dataChangeListener_; mutable std::mutex kvStorePtrMutex_; }; diff --git a/services/bundlemgr/include/bundle_mgr_host_impl.h b/services/bundlemgr/include/bundle_mgr_host_impl.h index 6b2b022642..8c2b84b3af 100644 --- a/services/bundlemgr/include/bundle_mgr_host_impl.h +++ b/services/bundlemgr/include/bundle_mgr_host_impl.h @@ -364,14 +364,13 @@ public: * @return Returns true if GetShortcutInfos successfully; returns false otherwise. */ virtual bool GetShortcutInfos(const std::string &bundleName, std::vector &shortcutInfos) override; - /** + /** * @brief Get module usage record list in descending order of lastLaunchTime. * @param maxNum the return size of the records, must be in range of 1 to 1000. * @param moduleUsageRecords List of ModuleUsageRecord objects if obtained. * @return Returns true if this function is successfully called; returns false otherwise. */ - virtual bool GetModuleUsageRecords( - const int32_t number, std::vector &moduleUsageRecords) override; + virtual bool GetModuleUsageRecords(const int32_t number, std::vector &moduleUsageRecords) override; /** * @brief Notify a specified ability for activity. * @param bundleName Indicates the bundle name of the ability to activity. diff --git a/services/bundlemgr/include/bundle_permissions_changed_monitor.h b/services/bundlemgr/include/bundle_permissions_changed_monitor.h index e3912891c0..ff4bb61f41 100644 --- a/services/bundlemgr/include/bundle_permissions_changed_monitor.h +++ b/services/bundlemgr/include/bundle_permissions_changed_monitor.h @@ -28,6 +28,7 @@ #include "json_serializer.h" #include "app_log_wrapper.h" + #include "bundle_parser.h" #include "installd_client.h" #include "bundle_permission_mgr.h" @@ -36,15 +37,13 @@ namespace OHOS { namespace AppExecFwk { class BundlePermissionsChangedMonitor : public EventFwk::CommonEventSubscriber { public: - BundlePermissionsChangedMonitor( - const std::shared_ptr &dataMgr, const EventFwk::CommonEventSubscribeInfo &sp) - : CommonEventSubscriber(sp) + BundlePermissionsChangedMonitor(const std::shared_ptr &dataMgr, + const EventFwk::CommonEventSubscribeInfo& sp):CommonEventSubscriber(sp) { dataMgr_ = dataMgr; } - ~BundlePermissionsChangedMonitor() - { - if (!dataMgr_) { + ~BundlePermissionsChangedMonitor(){ + if(!dataMgr_){ dataMgr_.reset(); } } @@ -53,11 +52,10 @@ public: OHOS::AAFwk::Want want = data.GetWant(); std::string action = want.GetAction(); int32_t uid = data.GetCode(); - if (dataMgr_ != nullptr && uid >= 0) { + if ( dataMgr_ != nullptr && uid >=0 ) { dataMgr_->NotifyPermissionsChanged(uid); } } - private: std::shared_ptr dataMgr_; }; diff --git a/services/bundlemgr/include/inner_bundle_info.h b/services/bundlemgr/include/inner_bundle_info.h index 838a37b8dd..437c66faa7 100644 --- a/services/bundlemgr/include/inner_bundle_info.h +++ b/services/bundlemgr/include/inner_bundle_info.h @@ -893,7 +893,7 @@ public: void SetProvisionId(const std::string &provisionId) { - baseBundleInfo_.appId = provisionId; + baseBundleInfo_.appId = baseBundleInfo_.name + Constants::FILE_UNDERLINE + provisionId; } std::string GetProvisionId() const diff --git a/services/bundlemgr/include/kvstore_death_recipient_callback.h b/services/bundlemgr/include/kvstore_death_recipient_callback.h index 83e5b287f1..9b575b3ac2 100644 --- a/services/bundlemgr/include/kvstore_death_recipient_callback.h +++ b/services/bundlemgr/include/kvstore_death_recipient_callback.h @@ -27,8 +27,9 @@ public: virtual ~KvStoreDeathRecipientCallback(); virtual void OnRemoteDied() override; + }; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_KVSTORE_DEATH_RECIPIENT_CALLBACK_H \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_KVSTORE_DEATH_RECIPIENT_CALLBACK_H \ No newline at end of file diff --git a/services/bundlemgr/include/module_usage_data_storage.h b/services/bundlemgr/include/module_usage_data_storage.h index d9259a57a0..d8c7e6a159 100644 --- a/services/bundlemgr/include/module_usage_data_storage.h +++ b/services/bundlemgr/include/module_usage_data_storage.h @@ -25,6 +25,7 @@ #include "distributed_kv_data_manager.h" #include "inner_bundle_info.h" + namespace OHOS { namespace AppExecFwk { class DataMgr; @@ -35,36 +36,36 @@ public: virtual ~ModuleUsageRecordStorage(); // add&update - bool AddOrUpdateRecord(ModuleUsageRecord &data, const std::string &deviceId, int32_t userId); + bool AddOrUpdateRecord(ModuleUsageRecord& data, const std::string& deviceId, int32_t userId); bool DeleteRecordByUserId(int32_t userId); - bool DeleteUsageRecord(const InnerBundleInfo &data, int32_t userId); + bool DeleteUsageRecord(const InnerBundleInfo& data, int32_t userId); bool MarkUsageRecordRemoved(const InnerBundleInfo &data, int32_t userId); - bool QueryRecordByNum(int32_t maxNum, std::vector &records, int32_t userId); - void SetDataMgr(const std::weak_ptr &dataMgr) const; + bool QueryRecordByNum(int32_t maxNum, std::vector& records, int32_t userId); + void SetDataMgr(const std::weak_ptr& dataMgr) const; void OnKvStoreDeath(); void RegisterKvStoreDeathListener(); - private: - bool DeleteRecordByKeys(const std::string &bundleName, std::vector &keys); - bool QueryRecordByCondition(DistributedKv::DataQuery &query, std::vector &records); - void AbilityRecordToKey(const std::string &userId, const std::string &deviceId, const std::string &bundleName, - const std::string &moduleName, std::string &key) const; - void InnerBundleInfoToKeys( - const InnerBundleInfo &data, int32_t userId, std::vector &keys) const; - void FillDataStorageKeys(const std::string &userId, const std::string &bundleName, const std::string &moduleName, - std::vector &keys) const; - bool ParseKey(const std::string &key, ModuleUsageRecord &record) const; - void UpdateUsageRecord(const std::string &jsonString, ModuleUsageRecord &data); - void SaveEntries( - const std::vector &allEntries, std::vector &records) const; - void TryTwice(const std::function &func) const; + + bool DeleteRecordByKeys(const std::string& bundleName, std::vector& keys); + bool QueryRecordByCondition(DistributedKv::DataQuery& query, std::vector& records); + void AbilityRecordToKey(const std::string& userId, const std::string& deviceId, + const std::string& bundleName, const std::string& moduleName, std::string& key) const; + void InnerBundleInfoToKeys(const InnerBundleInfo& data, int32_t userId, + std::vector& keys) const; + void FillDataStorageKeys(const std::string& userId, const std::string& bundleName, + const std::string& moduleName, std::vector& keys) const; + bool ParseKey(const std::string& key, ModuleUsageRecord& record) const; + void UpdateUsageRecord(const std::string& jsonString, ModuleUsageRecord& data); + void SaveEntries(const std::vector& allEntries, + std::vector& records) const; + void TryTwice(const std::function& func) const; bool CheckKvStore(); DistributedKv::Status GetKvStore(); bool ResetKvStore(); private: - const DistributedKv::AppId appId_{Constants::APP_ID}; - const DistributedKv::StoreId storeId_{Constants::ABILITY_USAGE_STORE_ID}; + const DistributedKv::AppId appId_ { Constants::APP_ID }; + const DistributedKv::StoreId storeId_ { Constants::ABILITY_USAGE_STORE_ID }; DistributedKv::DistributedKvDataManager dataManager_; std::unique_ptr kvStorePtr_; mutable std::mutex kvStorePtrMutex_; @@ -77,6 +78,6 @@ private: }; }; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_MODULE_USAGE_DATA_STORAGE_H \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_MODULE_USAGE_DATA_STORAGE_H \ No newline at end of file diff --git a/services/bundlemgr/include/permission_changed_death_recipient.h b/services/bundlemgr/include/permission_changed_death_recipient.h index 8c9b0aab41..1f4e04072f 100644 --- a/services/bundlemgr/include/permission_changed_death_recipient.h +++ b/services/bundlemgr/include/permission_changed_death_recipient.h @@ -26,9 +26,9 @@ namespace AppExecFwk { class PermissionChangedDeathRecipient : public IRemoteObject::DeathRecipient { public: - virtual void OnRemoteDied(const wptr &object) override; + virtual void OnRemoteDied(const wptr& object) override; }; -} // namespace AppExecFwk -} // namespace OHOS -#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PERMISSION_CHANGED_DEATH_RECIPIENT_H \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS +#endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_INCLUDE_PERMISSION_CHANGED_DEATH_RECIPIENT_H \ No newline at end of file diff --git a/services/bundlemgr/src/bundle_data_mgr.cpp b/services/bundlemgr/src/bundle_data_mgr.cpp index 4b210e214c..1c61ef2395 100755 --- a/services/bundlemgr/src/bundle_data_mgr.cpp +++ b/services/bundlemgr/src/bundle_data_mgr.cpp @@ -1620,8 +1620,7 @@ bool BundleDataMgr::UnregisterPermissionsChanged(const sptr lock(allPermissionsChangedLock_); - for (auto allPermissionsItem = allPermissionsCallbacks_.begin(); - allPermissionsItem != allPermissionsCallbacks_.end();) { + for (auto allPermissionsItem = allPermissionsCallbacks_.begin(); allPermissionsItem != allPermissionsCallbacks_.end();) { if ((*allPermissionsItem)->AsObject() == callback->AsObject()) { allPermissionsItem = allPermissionsCallbacks_.erase(allPermissionsItem); APP_LOGI("unregister from all permissions callbacks success!"); diff --git a/services/bundlemgr/src/bundle_mgr_host_impl.cpp b/services/bundlemgr/src/bundle_mgr_host_impl.cpp index 03c8fed2c3..a68c60b46b 100755 --- a/services/bundlemgr/src/bundle_mgr_host_impl.cpp +++ b/services/bundlemgr/src/bundle_mgr_host_impl.cpp @@ -486,8 +486,8 @@ bool BundleMgrHostImpl::RequestPermissionFromUser( APP_LOGI("send Permissions Changed event"); BundleInfo info; bool ret_getInfo = GetBundleInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, info); - APP_LOGI("ret_getInfo = %{public}d", ret_getInfo); - if (ret && ret_getInfo) { + APP_LOGI("ret_getInfo = %{public}d",ret_getInfo); + if ( ret && ret_getInfo) { Want want; want.SetAction("PERMISSIONS_CHANGED_EVENT"); EventFwk::CommonEventData commonData; @@ -516,7 +516,7 @@ bool BundleMgrHostImpl::RegisterPermissionsChanged( APP_LOGE("DataMgr is nullptr"); return false; } - return dataMgr->RegisterPermissionsChanged(uids, callback); + return dataMgr->RegisterPermissionsChanged(uids,callback); } bool BundleMgrHostImpl::UnregisterPermissionsChanged(const sptr &callback) diff --git a/services/bundlemgr/src/bundle_permission_mgr.cpp b/services/bundlemgr/src/bundle_permission_mgr.cpp index 524d2e9bb3..91a84da117 100644 --- a/services/bundlemgr/src/bundle_permission_mgr.cpp +++ b/services/bundlemgr/src/bundle_permission_mgr.cpp @@ -59,15 +59,15 @@ bool ConvertPermissionDef( permDef.availableScope = [&defPermission]() -> int { unsigned flag = 0; if (std::find(defPermission.availableScope.begin(), - defPermission.availableScope.end(), - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_SIGNATURE) != - defPermission.availableScope.end()) { + defPermission.availableScope.end(), + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_SIGNATURE) != + defPermission.availableScope.end()) { flag |= Permission::AvailableScope::AVAILABLE_SCOPE_SIGNATURE; } if (std::find(defPermission.availableScope.begin(), - defPermission.availableScope.end(), - ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_RESTRICTED) != - defPermission.availableScope.end()) { + defPermission.availableScope.end(), + ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE_RESTRICTED) != + defPermission.availableScope.end()) { flag |= Permission::AvailableScope::AVAILABLE_SCOPE_RESTRICTED; } if (flag == 0) { @@ -300,8 +300,8 @@ bool BundlePermissionMgr::CheckCallingPermission(const std::string &permissionNa APP_LOGI( "get app bundleName %{public}s and permissionName %{public}s", bundleName.c_str(), permissionName.c_str()); ApplicationInfo appInfo; - bool ret = dataMgr->GetApplicationInfo( - bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, Constants::DEFAULT_USERID, appInfo); + bool ret = dataMgr->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, + Constants::DEFAULT_USERID, appInfo); if (ret && appInfo.isLauncherApp && (permissionName == Constants::PERMISSION_INSTALL_BUNDLE)) { APP_LOGE("launcher app %{public}s pass through", bundleName.c_str()); return true; diff --git a/services/bundlemgr/src/bundle_profile.cpp b/services/bundlemgr/src/bundle_profile.cpp index 596f32c338..4ef30a7e14 100644 --- a/services/bundlemgr/src/bundle_profile.cpp +++ b/services/bundlemgr/src/bundle_profile.cpp @@ -1684,11 +1684,11 @@ bool CheckBundleNameIsValid(const std::string &bundleName) return false; } char head = bundleName.at(0); - if (head < 'A' || (head > 'Z' && head < 'a') || head > 'z') { + if (head < 'A' || ('Z' < head && head < 'a') || head > 'z') { return false; } for (const auto &c : bundleName) { - if (c < '.' || c == '/' || (c > '9' && c < 'A') || (c > 'Z' && c < '_') || c == '`' || c > 'z') { + if (c < '.' || c == '/' || ('9' < c && c < 'A') || ('Z' < c && c < '_') || c == '`' || c > 'z') { return false; } } diff --git a/services/bundlemgr/src/bundle_util.cpp b/services/bundlemgr/src/bundle_util.cpp index c6500946ff..9dd08b4590 100644 --- a/services/bundlemgr/src/bundle_util.cpp +++ b/services/bundlemgr/src/bundle_util.cpp @@ -44,7 +44,7 @@ ErrCode BundleUtil::CheckFilePath(const std::string &bundlePath, std::string &re APP_LOGE("can not access the bundle file path: %{private}s", realPath.c_str()); return ERR_APPEXECFWK_INSTALL_INVALID_BUNDLE_FILE; } - if (!CheckFileSize(realPath, Constants::MAX_HAP_SIZE)) { + if(!CheckFileSize(realPath, Constants::MAX_HAP_SIZE)) { APP_LOGE("file size is larger than max size Max size is: %{public}d", Constants::MAX_HAP_SIZE); return ERR_APPEXECFWK_INSTALL_INVALID_HAP_SIZE; } @@ -83,11 +83,11 @@ bool BundleUtil::CheckFileName(const std::string &fileName) bool BundleUtil::CheckFileSize(const std::string &bundlePath, const int32_t fileSize) { - struct stat fileInfo = {0}; - if (stat(bundlePath.c_str(), &fileInfo) != 0) { + struct stat fileInfo = { 0 }; + if (stat(bundlePath.c_str(), &fileInfo) != 0) { APP_LOGE("call stat error"); - return false; - } + return false; + } if (fileInfo.st_size > fileSize) { return false; } diff --git a/services/bundlemgr/src/inner_bundle_info.cpp b/services/bundlemgr/src/inner_bundle_info.cpp index fe8119bca3..0e4b1182f7 100644 --- a/services/bundlemgr/src/inner_bundle_info.cpp +++ b/services/bundlemgr/src/inner_bundle_info.cpp @@ -74,40 +74,48 @@ InnerBundleInfo::~InnerBundleInfo() void to_json(nlohmann::json &jsonObject, const Distro &distro) { - jsonObject = - nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall}, + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DELIVERY_WITH_INSTALL, distro.deliveryWithInstall}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_NAME, distro.moduleName}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_TYPE, distro.moduleType}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree}}; + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_MODULE_INSTALLATION_FREE, distro.installationFree} + }; } void to_json(nlohmann::json &jsonObject, const UsedScene &usedScene) { - jsonObject = nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_ABILITY, usedScene.ability}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_WHEN, usedScene.when}}; + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_ABILITY, usedScene.ability}, + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_WHEN, usedScene.when} + }; } void to_json(nlohmann::json &jsonObject, const ReqPermission &reqPermission) { - jsonObject = nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_NAME, reqPermission.name}, + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_NAME, reqPermission.name}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_REASON, reqPermission.reason}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_USEDSCENE, reqPermission.usedScene}}; + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_REQ_PERMISSIONS_USEDSCENE, reqPermission.usedScene} + }; } void to_json(nlohmann::json &jsonObject, const DefPermission &defPermission) { - jsonObject = nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_NAME, defPermission.name}, + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_NAME, defPermission.name}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_GRANTMODE, defPermission.grantMode}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_AVAILABLESCOPE, defPermission.availableScope}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL, defPermission.label}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_LABEL_ID, defPermission.labelId}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION, defPermission.description}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION_ID, defPermission.descriptionId}}; + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_DEF_PERMISSIONS_DESCRIPTION_ID, defPermission.descriptionId} + }; } void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) { - jsonObject = nlohmann::json{{MODULE_PACKAGE, info.modulePackage}, + jsonObject = nlohmann::json{ + {MODULE_PACKAGE, info.modulePackage}, {MODULE_NAME, info.moduleName}, {MODULE_PATH, info.modulePath}, {MODULE_DATA_DIR, info.moduleDataDir}, @@ -126,23 +134,28 @@ void to_json(nlohmann::json &jsonObject, const InnerModuleInfo &info) {MODULE_DEF_PERMS, info.defPermissions}, {MODULE_ABILITY_KEYS, info.abilityKeys}, {MODULE_SKILL_KEYS, info.skillKeys}, - {MODULE_MAIN_ABILITY, info.mainAbility}}; + {MODULE_MAIN_ABILITY, info.mainAbility} + }; } void to_json(nlohmann::json &jsonObject, const SkillUri &uri) { - jsonObject = nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme}, + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_SCHEME, uri.scheme}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_HOST, uri.host}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PORT, uri.port}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_PATH, uri.path}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type}}; + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_TYPE, uri.type} + }; } void to_json(nlohmann::json &jsonObject, const Skill &skill) { - jsonObject = nlohmann::json{{ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions}, + jsonObject = nlohmann::json{ + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ACTIONS, skill.actions}, {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_ENTITIES, skill.entities}, - {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris}}; + {ProfileReader::BUNDLE_MODULE_PROFILE_KEY_URIS, skill.uris} + }; } void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const @@ -163,7 +176,7 @@ void InnerBundleInfo::ToJson(nlohmann::json &jsonObject) const jsonObject[MAIN_ABILITY] = mainAbility_; jsonObject[APP_FEATURE] = appFeature_; jsonObject[HAS_ENTRY] = hasEntry_; - jsonObject[MODULE_FORMS] = formInfos_; + jsonObject[MODULE_FORMS] = formInfos_; jsonObject[MODULE_SHORTCUT] = shortcutInfos_; } @@ -578,10 +591,22 @@ int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject) true, ProfileReader::parseResult, ArrayType::NOT_ARRAY); - GetValueIfFindKey( - jsonObject, jsonObjectEnd, UID, uid_, JsonType::NUMBER, true, ProfileReader::parseResult, ArrayType::NOT_ARRAY); - GetValueIfFindKey( - jsonObject, jsonObjectEnd, GID, gid_, JsonType::NUMBER, true, ProfileReader::parseResult, ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + UID, + uid_, + JsonType::NUMBER, + true, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey(jsonObject, + jsonObjectEnd, + GID, + gid_, + JsonType::NUMBER, + true, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); GetValueIfFindKey(jsonObject, jsonObjectEnd, BASE_DATA_DIR, @@ -670,15 +695,15 @@ int32_t InnerBundleInfo::FromJson(const nlohmann::json &jsonObject) true, ProfileReader::parseResult, ArrayType::NOT_ARRAY); - GetValueIfFindKey>>(jsonObject, - jsonObjectEnd, - MODULE_FORMS, - formInfos_, - JsonType::OBJECT, - true, - ProfileReader::parseResult, - ArrayType::NOT_ARRAY); - GetValueIfFindKey>(jsonObject, + GetValueIfFindKey>>(jsonObject, + jsonObjectEnd, + MODULE_FORMS, + formInfos_, + JsonType::OBJECT, + true, + ProfileReader::parseResult, + ArrayType::NOT_ARRAY); + GetValueIfFindKey>(jsonObject, jsonObjectEnd, MODULE_SHORTCUT, shortcutInfos_, @@ -710,7 +735,7 @@ std::optional> InnerBundleInfo::FindSkills(const std::string if (skills.empty()) { return std::nullopt; } - return std::optional>{skills}; + return std::optional> {skills}; } std::optional InnerBundleInfo::FindHapModuleInfo(const std::string &modulePackage) const @@ -935,14 +960,14 @@ void InnerBundleInfo::GetBundleInfo(const BundleFlag flag, BundleInfo &bundleInf [](const auto &p) { return p.name; }); bundleInfo.hapModuleNames.emplace_back(info.second.modulePackage); auto hapmoduleinfo = FindHapModuleInfo(info.second.modulePackage); - if (!hapmoduleinfo) { - APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str()); - } else { + if (hapmoduleinfo) { bundleInfo.hapModuleInfos.emplace_back(*hapmoduleinfo); bundleInfo.moduleNames.emplace_back(info.second.moduleName); bundleInfo.moduleDirs.emplace_back(info.second.modulePath); bundleInfo.modulePublicDirs.emplace_back(info.second.moduleDataDir); bundleInfo.moduleResPaths.emplace_back(info.second.moduleResPath); + } else { + APP_LOGE("can not find hapmoduleinfo %{public}s", info.second.moduleName.c_str()); } if (info.second.isEntry) { bundleInfo.mainEntry = info.second.modulePackage; @@ -974,29 +999,29 @@ bool InnerBundleInfo::CheckSpecialMetaData(const std::string &metaData) const void InnerBundleInfo::GetFormsInfoByModule(const std::string &moduleName, std::vector &formInfos) const { - for (const auto &data : formInfos_) { - for (auto &form : data.second) { - if (form.moduleName == moduleName) { - formInfos.emplace_back(form); - } - } - } + for (const auto &data : formInfos_) { + for (auto &form : data.second) { + if (form.moduleName == moduleName) { + formInfos.emplace_back(form); + } + } + } } void InnerBundleInfo::GetFormsInfoByApp(std::vector &formInfos) const { - for (const auto &data : formInfos_) { - for (auto &form : data.second) { - formInfos.emplace_back(form); - } - } + for (const auto &data : formInfos_) { + for (auto &form : data.second) { + formInfos.emplace_back(form); + } + } } void InnerBundleInfo::GetShortcutInfos(std::vector &shortcutInfos) const { for (const auto &shortcut : shortcutInfos_) { - shortcutInfos.emplace_back(shortcut.second); - } + shortcutInfos.emplace_back(shortcut.second); + } } std::optional InnerBundleInfo::GetInnerModuleInfoByModuleName(const std::string &moduleName) const diff --git a/services/bundlemgr/src/installd/installd_host_impl.cpp b/services/bundlemgr/src/installd/installd_host_impl.cpp index e12775312a..b850b712ab 100644 --- a/services/bundlemgr/src/installd/installd_host_impl.cpp +++ b/services/bundlemgr/src/installd/installd_host_impl.cpp @@ -173,15 +173,24 @@ ErrCode InstalldHostImpl::CreateModuleDataDir( for (auto &abilityDir : abilityDirs) { if (!InstalldOperator::MkOwnerDir( - createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::DATA_DIR, true, uid, gid)) { + createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::DATA_DIR, + true, + uid, + gid)) { return ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED; } if (!InstalldOperator::MkOwnerDir( - createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::CACHE_DIR, true, uid, gid)) { + createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::CACHE_DIR, + true, + uid, + gid)) { return ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED; } if (!InstalldOperator::MkOwnerDir( - createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::DATA_BASE_DIR, true, uid, gid)) { + createDir + abilityDir + Constants::PATH_SEPARATOR + Constants::DATA_BASE_DIR, + true, + uid, + gid)) { return ERR_APPEXECFWK_INSTALLD_CREATE_DIR_FAILED; } if (!InstalldOperator::MkOwnerDir( diff --git a/services/bundlemgr/src/kvstore_death_recipient_callback.cpp b/services/bundlemgr/src/kvstore_death_recipient_callback.cpp index f44f619917..3b1eb834f4 100644 --- a/services/bundlemgr/src/kvstore_death_recipient_callback.cpp +++ b/services/bundlemgr/src/kvstore_death_recipient_callback.cpp @@ -27,9 +27,9 @@ namespace AppExecFwk { namespace { const int32_t CHECK_TIMES = 300; -const int32_t CHECK_INTERVAL = 100000; // 100ms +const int32_t CHECK_INTERVAL = 100000; // 100ms -} // namespace +} // namespace KvStoreDeathRecipientCallback::KvStoreDeathRecipientCallback() { @@ -63,7 +63,7 @@ void KvStoreDeathRecipientCallback::OnRemoteDied() // init kvStore. if (dataStorage && dataStorage->ResetKvStore()) { // register data change listener again. - // dataStorage->RegisterChangeListener(); + //dataStorage->RegisterChangeListener(); APP_LOGI("current times is %{public}d", times); // auto service = DelayedSingleton::GetInstance(); // std::shared_ptr handler = service->GetEventHandler(); @@ -79,5 +79,5 @@ void KvStoreDeathRecipientCallback::OnRemoteDied() APP_LOGI("OnRemoteDied, register data change listener end"); } -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file +} // namespace AppExecFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/src/module_usage_data_storage.cpp b/services/bundlemgr/src/module_usage_data_storage.cpp index 049dd08db2..6a44194147 100644 --- a/services/bundlemgr/src/module_usage_data_storage.cpp +++ b/services/bundlemgr/src/module_usage_data_storage.cpp @@ -320,8 +320,8 @@ Status ModuleUsageRecordStorage::GetKvStore() { Status status; Options options = { - .createIfMissing = true, .encrypt = false, .autoSync = true, .kvStoreType = KvStoreType::SINGLE_VERSION - }; + .createIfMissing = true, .encrypt = false, .autoSync = true, .kvStoreType = KvStoreType::SINGLE_VERSION}; + options.schema = SCHEMA_DEFINE; dataManager_.GetSingleKvStore( options, appId_, storeId_, [this, &status](Status paramStatus, std::unique_ptr singleKvStore) { diff --git a/services/bundlemgr/test/mock/include/json_constants.h b/services/bundlemgr/test/mock/include/json_constants.h index 6a9af870d2..7019d89acf 100644 --- a/services/bundlemgr/test/mock/include/json_constants.h +++ b/services/bundlemgr/test/mock/include/json_constants.h @@ -21,6 +21,7 @@ namespace OHOS { namespace AppExecFwk { namespace JsonConstants { + const nlohmann::json NOT_STRING_TYPE = R"( { "number": 234, @@ -64,6 +65,7 @@ const nlohmann::json NOT_ARRAY_TYPE = R"( "object": {} } )"_json; + } // namespace JsonConstants } // namespace AppExecFwk } // namespace OHOS diff --git a/services/bundlemgr/test/mock/include/mock_ability_mgr_host.h b/services/bundlemgr/test/mock/include/mock_ability_mgr_host.h index e4fe336ac0..df955fb472 100644 --- a/services/bundlemgr/test/mock/include/mock_ability_mgr_host.h +++ b/services/bundlemgr/test/mock/include/mock_ability_mgr_host.h @@ -180,7 +180,7 @@ public: } int SetMissionDescriptionInfo( - const sptr &token, const MissionDescriptionInfo &missionDescInfo) override + const sptr &token, const MissionDescriptionInfo &missionDescriptionInfo) override { return 0; } diff --git a/services/bundlemgr/test/mock/include/mock_bundle_status.h b/services/bundlemgr/test/mock/include/mock_bundle_status.h index 4ee00dce99..fb7057b08b 100644 --- a/services/bundlemgr/test/mock/include/mock_bundle_status.h +++ b/services/bundlemgr/test/mock/include/mock_bundle_status.h @@ -24,6 +24,7 @@ namespace OHOS { namespace AppExecFwk { + class MockBundleStatus : public IBundleStatusCallback { public: MockBundleStatus() = default; @@ -31,9 +32,9 @@ public: virtual void OnBundleStateChanged(const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, const std::string &bundleName) override; - virtual void OnBundleAdded(const std::string &bundleName, const int userId) override{}; - virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override{}; - virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override{}; + virtual void OnBundleAdded(const std::string &bundleName, const int userId) override {}; + virtual void OnBundleUpdated(const std::string &bundleName, const int userId) override {}; + virtual void OnBundleRemoved(const std::string &bundleName, const int userId) override {}; virtual sptr AsObject() override; int32_t GetResultCode(); @@ -42,6 +43,7 @@ private: DISALLOW_COPY_AND_MOVE(MockBundleStatus); }; + } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_INCLUDE_MOCK_BUNDLE_STATUS_H \ No newline at end of file diff --git a/services/bundlemgr/test/mock/include/mock_clean_cache.h b/services/bundlemgr/test/mock/include/mock_clean_cache.h index 337513455d..9dfa562afa 100644 --- a/services/bundlemgr/test/mock/include/mock_clean_cache.h +++ b/services/bundlemgr/test/mock/include/mock_clean_cache.h @@ -24,6 +24,7 @@ namespace OHOS { namespace AppExecFwk { + class MockCleanCache : public ICleanCacheCallback { public: MockCleanCache() = default; @@ -38,6 +39,7 @@ private: DISALLOW_COPY_AND_MOVE(MockCleanCache); }; + } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_INCLUDE_MOCK_CLEAN_CACHE_H \ No newline at end of file diff --git a/services/bundlemgr/test/mock/include/mock_status_receiver.h b/services/bundlemgr/test/mock/include/mock_status_receiver.h index 2eaceceed3..1085c272fc 100644 --- a/services/bundlemgr/test/mock/include/mock_status_receiver.h +++ b/services/bundlemgr/test/mock/include/mock_status_receiver.h @@ -24,6 +24,7 @@ namespace OHOS { namespace AppExecFwk { + class MockStatusReceiver : public IStatusReceiver { public: MockStatusReceiver() = default; @@ -39,6 +40,7 @@ private: DISALLOW_COPY_AND_MOVE(MockStatusReceiver); }; + } // namespace AppExecFwk } // namespace OHOS #endif // FOUNDATION_APPEXECFWK_SERVICES_BUNDLEMGR_TEST_MOCK_INCLUDE_MOCK_STATUS_RECEIVER_H \ No newline at end of file diff --git a/services/bundlemgr/test/mock/src/mock_bundle_status.cpp b/services/bundlemgr/test/mock/src/mock_bundle_status.cpp index f9c356db8a..6797ae0816 100644 --- a/services/bundlemgr/test/mock/src/mock_bundle_status.cpp +++ b/services/bundlemgr/test/mock/src/mock_bundle_status.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void MockBundleStatus::OnBundleStateChanged( const uint8_t installType, const int32_t resultCode, const std::string &resultMsg, const std::string &bundleName) { @@ -38,5 +39,6 @@ int32_t MockBundleStatus::GetResultCode() return future.get(); } } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/mock/src/mock_clean_cache.cpp b/services/bundlemgr/test/mock/src/mock_clean_cache.cpp index 374009c4d0..4440d44bea 100644 --- a/services/bundlemgr/test/mock/src/mock_clean_cache.cpp +++ b/services/bundlemgr/test/mock/src/mock_clean_cache.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void MockCleanCache::OnCleanCacheFinished(bool succeeded) { signal_.set_value(succeeded); @@ -33,5 +34,6 @@ bool MockCleanCache::GetResultCode() future.wait(); return future.get(); } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/mock/src/mock_status_receiver.cpp b/services/bundlemgr/test/mock/src/mock_status_receiver.cpp index 3e843a6d68..cd8b57538f 100644 --- a/services/bundlemgr/test/mock/src/mock_status_receiver.cpp +++ b/services/bundlemgr/test/mock/src/mock_status_receiver.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void MockStatusReceiver::OnFinished(const int32_t resultCode, [[maybe_unused]] const std::string &resultMsg) { signal_.set_value(resultCode); @@ -38,5 +39,6 @@ int32_t MockStatusReceiver::GetResultCode() future.wait(); return future.get(); } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/mock/src/system_ability_helper.cpp b/services/bundlemgr/test/mock/src/system_ability_helper.cpp index 87df614aea..92c65c2890 100644 --- a/services/bundlemgr/test/mock/src/system_ability_helper.cpp +++ b/services/bundlemgr/test/mock/src/system_ability_helper.cpp @@ -24,7 +24,9 @@ namespace OHOS { namespace AppExecFwk { namespace { + std::map> g_abilities; + } // namespace sptr SystemAbilityHelper::GetSystemAbility(const int32_t systemAbilityId) @@ -60,5 +62,6 @@ bool SystemAbilityHelper::RemoveSystemAbility(const int32_t systemAbilityId) // mock helper always return true. return true; } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp index 34eaf96110..58cc1e42ef 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_installer_test/bms_bundle_installer_test.cpp @@ -42,6 +42,7 @@ using namespace OHOS; using OHOS::DelayedSingleton; namespace { + const std::string BUNDLE_NAME = "com.example.l3jsdemo"; const std::string RESOURCE_ROOT_PATH = "/data/test/resource/bms/install_bundle/"; const std::string INVALID_PATH = "/install_bundle/"; @@ -56,6 +57,7 @@ const std::string ROOT_DIR = "/data/accounts"; const int32_t ROOT_UID = 0; const int32_t USERID = 0; const std::string INSTALL_THREAD = "TestInstall"; + } // namespace class BmsBundleInstallerTest : public testing::Test { diff --git a/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp index b2bab7ae5b..8f1aa7514c 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_parser_test/bms_bundle_parser_test.cpp @@ -32,6 +32,7 @@ using namespace OHOS::AppExecFwk::Constants; using namespace OHOS::AppExecFwk::ProfileReader; namespace { + const std::string RESOURCE_ROOT_PATH = "/data/test/resource/bms/parse_bundle/"; const std::string NEW_APP = "new"; const std::string BREAK_ZIP = "break_zip"; @@ -190,6 +191,7 @@ const nlohmann::json CONFIG_JSON = R"( } } )"_json; + } // namespace class BmsBundleParserTest : public testing::Test { @@ -207,7 +209,6 @@ protected: void CheckProfilePermission(const nlohmann::json &checkedProfileJson) const; void CheckProfileForms(const nlohmann::json &checkedProfileJson) const; void CheckProfileShortcut(const nlohmann::json &checkedProfileJson) const; - protected: std::ostringstream pathStream_; }; @@ -893,7 +894,7 @@ HWTEST_F(BmsBundleParserTest, TestParse_2300, Function | SmallTest | Level1) HWTEST_F(BmsBundleParserTest, TestParse_2400, Function | SmallTest | Level1) { nlohmann::json errorFormsJson = CONFIG_JSON; - errorFormsJson[BUNDLE_PROFILE_KEY_MODULE][BUNDLE_MODULE_PROFILE_KEY_ABILITIES] = R"( + errorFormsJson[BUNDLE_PROFILE_KEY_MODULE][BUNDLE_MODULE_PROFILE_KEY_ABILITIES]= R"( [{ "skills": [ { diff --git a/services/bundlemgr/test/unittest/bms_bundle_permission_test/bms_bundle_permission_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_permission_test/bms_bundle_permission_test.cpp index fa94fae361..a0046249e0 100644 --- a/services/bundlemgr/test/unittest/bms_bundle_permission_test/bms_bundle_permission_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_permission_test/bms_bundle_permission_test.cpp @@ -93,62 +93,78 @@ const std::string DEFPERMISSION_NAME18 = "com.myability.permission.MYPERMISSION1 const std::string DEF_LABEL1 = "MockDefPermissionBundleSystemGrant"; const std::string DEF_LABEL2 = "MockDefPermissionBundleUserGrant"; const std::string DEF_LABEL3 = "MockSameDefPermissionNameBundleSystemGrant"; -const DefPermission DEFPERMISSION_SYSTEM1 = {.name = DEFPERMISSION_NAME1, +const DefPermission DEFPERMISSION_SYSTEM1 = { + .name = DEFPERMISSION_NAME1, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SYSTEM2 = {.name = DEFPERMISSION_NAME2, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SYSTEM2 = { + .name = DEFPERMISSION_NAME2, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SYSTEM3 = {.name = DEFPERMISSION_NAME3, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SYSTEM3 = { + .name = DEFPERMISSION_NAME3, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_UPDATE1 = {.name = DEFPERMISSION_NAME1, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_UPDATE1 = { + .name = DEFPERMISSION_NAME1, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 10, .description = DEF_LABEL2, - .descriptionId = 10}; -const DefPermission DEFPERMISSION_UPDATE2 = {.name = DEFPERMISSION_NAME2, + .descriptionId = 10 +}; +const DefPermission DEFPERMISSION_UPDATE2 = { + .name = DEFPERMISSION_NAME2, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 10, .description = DEF_LABEL2, - .descriptionId = 10}; -const DefPermission DEFPERMISSION_UPDATE3 = {.name = DEFPERMISSION_NAME3, + .descriptionId = 10 +}; +const DefPermission DEFPERMISSION_UPDATE3 = { + .name = DEFPERMISSION_NAME3, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 10, .description = DEF_LABEL2, - .descriptionId = 10}; -const DefPermission DEFPERMISSION_EMAIL = {.name = DEFPERMISSION_NAME_EMAIL, + .descriptionId = 10 +}; +const DefPermission DEFPERMISSION_EMAIL = { + .name = DEFPERMISSION_NAME_EMAIL, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_MUSIC = {.name = DEFPERMISSION_NAME_MUSIC, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_MUSIC = { + .name = DEFPERMISSION_NAME_MUSIC, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; + .descriptionId = 1 +}; const DefPermission DEFPERMISSION_APP = {.name = DEFPERMISSION_NAME_APP, .grantMode = "system_grant", .availableScope = {""}, @@ -156,119 +172,173 @@ const DefPermission DEFPERMISSION_APP = {.name = DEFPERMISSION_NAME_APP, .labelId = 1, .description = DEF_LABEL1, .descriptionId = 1}; -const DefPermission DEFPERMISSION_WECHAT = {.name = DEFPERMISSION_NAME_WECHAT, +const DefPermission DEFPERMISSION_WECHAT = { + .name = DEFPERMISSION_NAME_WECHAT, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_NOAVAILIAVLE1 = {.name = DEFPERMISSION_NAME4, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_NOAVAILIAVLE1 = { + .name = DEFPERMISSION_NAME4, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_NOAVAILIAVLE2 = {.name = DEFPERMISSION_NAME5, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_NOAVAILIAVLE2 = { + .name = DEFPERMISSION_NAME5, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_NOAVAILIAVLE3 = {.name = DEFPERMISSION_NAME6, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_NOAVAILIAVLE3 = { + .name = DEFPERMISSION_NAME6, .grantMode = "system_grant", .availableScope = {""}, .label = DEF_LABEL1, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT1 = {.name = DEFPERMISSION_NAME10, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT1 = { + .name = DEFPERMISSION_NAME10, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT2 = {.name = DEFPERMISSION_NAME11, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT2 = { + .name = DEFPERMISSION_NAME11, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT3 = {.name = DEFPERMISSION_NAME12, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT3 = { + .name = DEFPERMISSION_NAME12, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT4 = {.name = DEFPERMISSION_NAME13, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT4 = { + .name = DEFPERMISSION_NAME13, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT5 = {.name = DEFPERMISSION_NAME14, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT5 = { + .name = DEFPERMISSION_NAME14, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_USERGRANT6 = {.name = DEFPERMISSION_NAME15, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_USERGRANT6 = { + .name = DEFPERMISSION_NAME15, .grantMode = "user_grant", .availableScope = {"signature"}, .label = DEF_LABEL2, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SAMENAME1 = {.name = DEFPERMISSION_NAME10, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SAMENAME1 = { + .name = DEFPERMISSION_NAME10, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL3, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SAMENAME2 = {.name = DEFPERMISSION_NAME11, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SAMENAME2 = { + .name = DEFPERMISSION_NAME11, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL3, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SAME2 = {.name = DEFPERMISSION_NAME17, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SAME2 = { + .name = DEFPERMISSION_NAME17, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL3, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SAME1 = {.name = DEFPERMISSION_NAME16, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SAME1 = { + .name = DEFPERMISSION_NAME16, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL3, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; -const DefPermission DEFPERMISSION_SAME3 = {.name = DEFPERMISSION_NAME18, + .descriptionId = 1 +}; +const DefPermission DEFPERMISSION_SAME3 = { + .name = DEFPERMISSION_NAME18, .grantMode = "system_grant", .availableScope = {"signature"}, .label = DEF_LABEL3, .labelId = 1, .description = DEF_LABEL1, - .descriptionId = 1}; + .descriptionId = 1 +}; const ReqPermission REQPERMISSION1 = { - .name = DEFPERMISSION_NAME_EMAIL, .reason = "reason", .usedScene = {.ability = {"ability"}, .when = "when"}}; + .name = DEFPERMISSION_NAME_EMAIL, + .reason = "reason", + .usedScene = { + .ability = {"ability"}, + .when = "when" + } +}; const ReqPermission REQPERMISSION2 = { - .name = DEFPERMISSION_NAME_WECHAT, .reason = "reason", .usedScene = {.ability = {"ability"}, .when = "when"}}; + .name = DEFPERMISSION_NAME_WECHAT, + .reason = "reason", + .usedScene = { + .ability = {"ability"}, + .when = "when" + } +}; const ReqPermission REQPERMISSION3 = { - .name = DEFPERMISSION_NAME_APP, .reason = "reason", .usedScene = {.ability = {"ability"}, .when = "when"}}; + .name = DEFPERMISSION_NAME_APP, + .reason = "reason", + .usedScene = { + .ability = {"ability"}, + .when = "when" + } +}; const ReqPermission REQPERMISSION4 = { - .name = DEFPERMISSION_NAME_MUSIC, .reason = "reason", .usedScene = {.ability = {"ability"}, .when = "when"}}; + .name = DEFPERMISSION_NAME_MUSIC, + .reason = "reason", + .usedScene = { + .ability = {"ability"}, + .when = "when" + } +}; } // namespace class BmsBundlePermissionTest : public testing::Test { diff --git a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp index 46e5dad9c0..4de4e6cd59 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_uninstaller_test/bms_bundle_uninstaller_test.cpp @@ -38,6 +38,7 @@ using namespace OHOS; using namespace OHOS::AppExecFwk; namespace { + const std::string BUNDLE_NAME = "com.example.l3jsdemo"; const std::string MODULE_PACKAGE = "com.example.l3jsdemo"; const std::string MODULE_PACKAGE1 = "com.example.l3jsdemo1"; @@ -54,6 +55,7 @@ const std::string MODULE_CODE_DIR1 = "/data/accounts/account_0/applications/com. const std::string ROOT_DIR = "/data/accounts"; const std::string DB_FILE_PATH = "/data/bundlemgr"; const int32_t ROOT_UID = 0; + } // namespace class BmsBundleUninstallerTest : public testing::Test { @@ -83,7 +85,6 @@ public: const std::shared_ptr GetBundleMgrService() const; void ClearBundleInfoInDb(); void DeleteInstallFiles(); - private: std::shared_ptr installdService_ = std::make_unique(); std::shared_ptr bundleMgrService_ = DelayedSingleton::GetInstance(); @@ -295,11 +296,11 @@ void BmsBundleUninstallerTest::ClearBundleInfoInDb() return; } auto dataMgt = bundleMgrService_->GetDataMgr(); - if (dataMgt == nullptr) { + if(dataMgt == nullptr) { return; } auto dataStorage = dataMgt->GetDataStorage(); - if (dataStorage == nullptr) { + if(dataStorage == nullptr) { return; } InnerBundleInfo innerBundleInfo; diff --git a/services/bundlemgr/test/unittest/bms_bundle_updater_test/bms_bundle_updater_test.cpp b/services/bundlemgr/test/unittest/bms_bundle_updater_test/bms_bundle_updater_test.cpp index 9a17ea4f6f..c305f3712c 100755 --- a/services/bundlemgr/test/unittest/bms_bundle_updater_test/bms_bundle_updater_test.cpp +++ b/services/bundlemgr/test/unittest/bms_bundle_updater_test/bms_bundle_updater_test.cpp @@ -49,7 +49,7 @@ const std::string BUNDLE_CODE_DIR = "/data/accounts/account_0/applications/com.e const std::string ROOT_DIR = "/data/accounts"; const std::string PROFILE_FILE = "config.json"; const std::string SEPARATOR = "/"; -const std::chrono::seconds SLEEP_TIME{2}; +const std::chrono::seconds SLEEP_TIME {2}; const int32_t ROOT_UID = 0; const int32_t USERID = 0; const uint32_t VERSION_1 = 1; diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp index 7248511b66..f276ed52dc 100755 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_data_mgr_test.cpp @@ -30,6 +30,7 @@ using OHOS::Parcel; using OHOS::AAFwk::Want; namespace { + const std::string BUNDLE_NAME = "com.example.l3jsdemo"; const std::string APP_NAME = "com.example.l3jsdemo"; const std::string ABILITY_NAME = "com.example.l3jsdemo.MainAbility"; @@ -47,6 +48,7 @@ const std::string RESOURCE_PATH = "/data/accounts/account_/com.example.l3jsdemo" const std::string LIB_PATH = "/data/accounts/account_/com.example.l3jsdemo"; const bool VISIBLE = true; const int32_t USERID = 0; + } // namespace class BmsDataMgrTest : public testing::Test { diff --git a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_test.cpp b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_test.cpp index e13df47c01..b8c87eb818 100755 --- a/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_test.cpp +++ b/services/bundlemgr/test/unittest/bms_install_daemon_test/bms_install_daemon_test.cpp @@ -27,6 +27,7 @@ using namespace OHOS::AppExecFwk; using namespace OHOS; namespace { + const std::string BUNDLE_FILE = "/data/test/resource/bms/install_daemon/right.hap"; const std::string SYSTEM_DIR = "/sys/com.example.l3jsdemo"; const std::string TEMP_DIR = "/data/accounts/account_0/applications/com.example.l3jsdemo/temp"; @@ -37,6 +38,7 @@ const std::string ROOT_DIR = "/data/accounts"; const int32_t ROOT_UID = 0; const int32_t UID = 1000; const int32_t GID = 1000; + } // namespace class BmsInstallDaemonTest : public testing::Test { diff --git a/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/bms_service_bundle_scan_test.cpp b/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/bms_service_bundle_scan_test.cpp index 822bd0f0bd..b7fbba7d28 100755 --- a/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/bms_service_bundle_scan_test.cpp +++ b/services/bundlemgr/test/unittest/bms_service_bundle_scan_test/bms_service_bundle_scan_test.cpp @@ -30,6 +30,7 @@ using namespace OHOS::AppExecFwk; using OHOS::DelayedSingleton; namespace { + const std::string TEST_DIR = "/data/test/resource"; const std::string BUNDLE_FILENAME_1 = "app1.hap"; const std::string BUNDLE_FILENAME_2 = "app2.hap"; @@ -37,6 +38,7 @@ const std::string BUNDLE_FILENAME_3 = "app3.hap"; const std::string BUNDLE_FILENAME_4 = "app1.ha"; const std::string BUNDLE_FILENAME_5 = "app2..ap"; const std::string BUNDLE_FILENAME_6 = "app3"; + } // namespace class BmsServiceBundleScanTest : public testing::Test { @@ -147,11 +149,11 @@ bool BmsServiceBundleScanTest::IsScanResultContain(const std::string name) const return true; } /** - * @tc.number: BundleScan_0100 - * @tc.name: Scan - * @tc.desc: 1. scan dir not exist - * 2. verify scan result file number is 0 - */ +* @tc.number: BundleScan_0100 +* @tc.name: Scan +* @tc.desc: 1. scan dir not exist +* 2. verify scan result file number is 0 +*/ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0100, Function | SmallTest | Level0) { DeleteDir(TEST_DIR); @@ -159,22 +161,22 @@ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0100, Function | SmallTest | Level EXPECT_EQ(0, number); } /** - * @tc.number: BundleScan_0200 - * @tc.name: Scan - * @tc.desc: 1. scan dir exist, no bundle file - * 2. verify scan result file number is 0 - */ +* @tc.number: BundleScan_0200 +* @tc.name: Scan +* @tc.desc: 1. scan dir exist, no bundle file +* 2. verify scan result file number is 0 +*/ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0200, Function | SmallTest | Level0) { int number = static_cast(TriggerScan()); EXPECT_EQ(0, number); } /** - * @tc.number: BundleScan_0300 - * @tc.name: Scan - * @tc.desc: 1. scan dir exist, 3 legal file exist - * 2. verify scan result file number is 3 and file name correct - */ +* @tc.number: BundleScan_0300 +* @tc.name: Scan +* @tc.desc: 1. scan dir exist, 3 legal file exist +* 2. verify scan result file number is 3 and file name correct +*/ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0300, Function | SmallTest | Level0) { CreateDir(TEST_DIR); @@ -197,11 +199,11 @@ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0300, Function | SmallTest | Level DeleteFile(TEST_FILE_NAME_3); } /** - * @tc.number: BundleScan_0400 - * @tc.name: Scan - * @tc.desc: 1. scan dir exist, 3 illegal file exist - * 2. verify scan result file number is 0 - */ +* @tc.number: BundleScan_0400 +* @tc.name: Scan +* @tc.desc: 1. scan dir exist, 3 illegal file exist +* 2. verify scan result file number is 0 +*/ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0400, Function | SmallTest | Level0) { const std::string TEST_FILE_NAME_4 = TEST_DIR + "/" + BUNDLE_FILENAME_4; @@ -220,11 +222,11 @@ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0400, Function | SmallTest | Level DeleteFile(TEST_FILE_NAME_6); } /** - * @tc.number: BundleScan_0500 - * @tc.name: Scan - * @tc.desc: 1. scan dir exist, 3 illegal and 3 legal file exist - * 2. verify scan result file number is 3 and file name correct - */ +* @tc.number: BundleScan_0500 +* @tc.name: Scan +* @tc.desc: 1. scan dir exist, 3 illegal and 3 legal file exist +* 2. verify scan result file number is 3 and file name correct +*/ HWTEST_F(BmsServiceBundleScanTest, BundleScan_0500, Function | SmallTest | Level0) { const std::string TEST_FILE_NAME_1 = TEST_DIR + "/" + BUNDLE_FILENAME_1; diff --git a/services/bundlemgr/test/unittest/bms_service_startup_test/bms_service_startup_test.cpp b/services/bundlemgr/test/unittest/bms_service_startup_test/bms_service_startup_test.cpp index 9acf9200ec..5605132d41 100755 --- a/services/bundlemgr/test/unittest/bms_service_startup_test/bms_service_startup_test.cpp +++ b/services/bundlemgr/test/unittest/bms_service_startup_test/bms_service_startup_test.cpp @@ -46,11 +46,11 @@ void BmsServiceStartupTest::TearDown() } /** - * @tc.number: Startup_0100 - * @tc.name: test the start function of the BMS service when service is not ready - * @tc.desc: 1. the service is not initialized - * 2. the non initialized BMS service can be started - */ +* @tc.number: Startup_0100 +* @tc.name: test the start function of the BMS service when service is not ready +* @tc.desc: 1. the service is not initialized +* 2. the non initialized BMS service can be started +*/ HWTEST_F(BmsServiceStartupTest, Startup_0100, Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); @@ -62,12 +62,12 @@ HWTEST_F(BmsServiceStartupTest, Startup_0100, Function | SmallTest | Level0) } /** - * @tc.number: Startup_0200 - * @tc.name: test the stop function of the BMS service when service is ready - * @tc.desc: 1. the service is already initialized - * 2. the initialized BMS service can be stopped - */ -HWTEST_F(BmsServiceStartupTest, Startup_0200, Function | SmallTest | Level0) +* @tc.number: Startup_0200 +* @tc.name: test the stop function of the BMS service when service is ready +* @tc.desc: 1. the service is already initialized +* 2. the initialized BMS service can be stopped +*/ +HWTEST_F(BmsServiceStartupTest, Startup_0200,Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); bms->OnStart(); @@ -79,12 +79,12 @@ HWTEST_F(BmsServiceStartupTest, Startup_0200, Function | SmallTest | Level0) } /** - * @tc.number: Startup_0300 - * @tc.name: test the restart function of the BMS service - * @tc.desc: 1. the service is already initialized - * 2. the stopped BMS service can be restarted - */ -HWTEST_F(BmsServiceStartupTest, Startup_0300, Function | SmallTest | Level0) +* @tc.number: Startup_0300 +* @tc.name: test the restart function of the BMS service +* @tc.desc: 1. the service is already initialized +* 2. the stopped BMS service can be restarted +*/ +HWTEST_F(BmsServiceStartupTest, Startup_0300,Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); bms->OnStart(); @@ -99,12 +99,12 @@ HWTEST_F(BmsServiceStartupTest, Startup_0300, Function | SmallTest | Level0) } /** - * @tc.number: Startup_0400 - * @tc.name: test the restart function of the BMS service which is already initialized - * @tc.desc: 1. the service is already initialized - * 2. the recall start function will not affect the initialized BMS service - */ -HWTEST_F(BmsServiceStartupTest, Startup_0400, Function | SmallTest | Level0) +* @tc.number: Startup_0400 +* @tc.name: test the restart function of the BMS service which is already initialized +* @tc.desc: 1. the service is already initialized +* 2. the recall start function will not affect the initialized BMS service +*/ +HWTEST_F(BmsServiceStartupTest, Startup_0400,Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); bms->OnStart(); @@ -116,12 +116,12 @@ HWTEST_F(BmsServiceStartupTest, Startup_0400, Function | SmallTest | Level0) } /** - * @tc.number: GetDataMgr_0100 - * @tc.name: test the dataMgr can be obtained - * @tc.desc: 1. the service is already initialized - * 2. the dataMgr can be obtained - */ -HWTEST_F(BmsServiceStartupTest, GetDataMgr_0100, Function | SmallTest | Level0) +* @tc.number: GetDataMgr_0100 +* @tc.name: test the dataMgr can be obtained +* @tc.desc: 1. the service is already initialized +* 2. the dataMgr can be obtained +*/ +HWTEST_F(BmsServiceStartupTest, GetDataMgr_0100,Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); bms->OnStart(); @@ -131,12 +131,12 @@ HWTEST_F(BmsServiceStartupTest, GetDataMgr_0100, Function | SmallTest | Level0) } /** - * @tc.number: GetBundleInstaller_0100 - * @tc.name: test the installer can be obtained - * @tc.desc: 1. the service is already initialized - * 2. the installer can be obtained - */ -HWTEST_F(BmsServiceStartupTest, GetBundleInstaller_0100, Function | SmallTest | Level0) +* @tc.number: GetBundleInstaller_0100 +* @tc.name: test the installer can be obtained +* @tc.desc: 1. the service is already initialized +* 2. the installer can be obtained +*/ +HWTEST_F(BmsServiceStartupTest, GetBundleInstaller_0100,Function | SmallTest | Level0) { std::shared_ptr bms = DelayedSingleton::GetInstance(); bms->OnStart(); diff --git a/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp b/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp index cbfb126edd..20e10a2cb4 100755 --- a/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp +++ b/services/test/moduletest/common/ams/app_life_cycle_test/ams_app_life_cycle_module_test.cpp @@ -216,7 +216,7 @@ void AmsAppLifeCycleModuleTest::ChangeAbilityStateToForegroud(const sptrUpdateAbilityState(token, AbilityState::ABILITY_STATE_FOREGROUND); if (!isChange) { - EXPECT_NE(appRunningRecord, nullptr); + ASSERT_NE(appRunningRecord, nullptr); int32_t recordId = appRunningRecord->GetRecordId(); serviceInner_->ApplicationForegrounded(recordId); } @@ -235,7 +235,7 @@ void AmsAppLifeCycleModuleTest::ChangeAbilityStateToBackGroud(const sptrUpdateAbilityState(token, AbilityState::ABILITY_STATE_BACKGROUND); if (!isChange) { - EXPECT_NE(appRunningRecord, nullptr); + ASSERT_NE(appRunningRecord, nullptr); int32_t recordId = appRunningRecord->GetRecordId(); serviceInner_->ApplicationBackgrounded(recordId); } @@ -251,7 +251,7 @@ void AmsAppLifeCycleModuleTest::ChangeAppToTerminate(const sptrAbilityTerminated(token); - EXPECT_NE(appRunningRecord, nullptr); + ASSERT_NE(appRunningRecord, nullptr); int32_t recordId = appRunningRecord->GetRecordId(); serviceInner_->ApplicationTerminated(recordId); } else { @@ -269,11 +269,11 @@ void AmsAppLifeCycleModuleTest::ChangeAbilityStateToTerminate( void AmsAppLifeCycleModuleTest::CheckState(const std::shared_ptr &appRunningRecord, const sptr &token, const AbilityState abilityState, const ApplicationState appState) const { - EXPECT_NE(appRunningRecord, nullptr); + ASSERT_NE(appRunningRecord, nullptr); auto abilityRunningRecord = appRunningRecord->GetAbilityRunningRecordByToken(token); ApplicationState getAppState = appRunningRecord->GetState(); EXPECT_EQ(appState, getAppState); - EXPECT_NE(abilityRunningRecord, nullptr); + ASSERT_NE(abilityRunningRecord, nullptr); AbilityState getAbilityState = abilityRunningRecord->GetState(); EXPECT_EQ(abilityState, getAbilityState); } @@ -371,7 +371,7 @@ sptr AmsAppLifeCycleModuleTest::GetAbilityToken() */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_001, TestSize.Level2) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid = 1024; sptr token = GetAbilityToken(); auto abilityInfo = GetAbilityInfo("0", "MainAbility", "p1", "com.ohos.test.helloworld"); @@ -416,7 +416,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_001, TestSize.Level2) HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_002, TestSize.Level3) { pid_t pid = 1023; - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); std::shared_ptr appRunningRecord = nullptr; std::vector> tokens; auto abilityInfo = std::make_shared(); @@ -525,7 +525,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_003, TestSize.Level3) */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_004, TestSize.Level3) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid = 1024; sptr token = GetAbilityToken(); auto abilityInfo = GetAbilityInfo("0", "MainAbility", "p3", "com.ohos.test.helloworld"); @@ -572,7 +572,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_004, TestSize.Level3) */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_005, TestSize.Level2) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid = 1024; sptr token0 = new (std::nothrow) MockAbilityToken(); @@ -635,7 +635,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_005, TestSize.Level2) */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_006, TestSize.Level2) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid = fork(); if (pid == 0) { @@ -692,7 +692,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_006, TestSize.Level2) */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_007, TestSize.Level2) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid = 1024; sptr token = GetAbilityToken(); auto abilityInfo = GetAbilityInfo("0", "MainAbility", "p1", "com.ohos.test.helloworld"); @@ -741,7 +741,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_007, TestSize.Level2) */ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_008, TestSize.Level2) { - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); pid_t pid_0 = 1024; pid_t pid_1 = 2048; sptr token_0 = new (std::nothrow) MockAbilityToken(); @@ -811,7 +811,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_008, TestSize.Level2) HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_009, TestSize.Level3) { pid_t pid = 1025; - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); std::shared_ptr appRunningRecord = nullptr; auto abilityInfo = std::make_shared(); auto appInfo = std::make_shared(); @@ -857,7 +857,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_009, TestSize.Level3) HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_010, TestSize.Level3) { pid_t pid = 1025; - EXPECT_NE(serviceInner_, nullptr); + ASSERT_NE(serviceInner_, nullptr); std::shared_ptr appRunningRecord = nullptr; int32_t recordId[APPLICATION_NUM]; sptr mockAppScheduler[APPLICATION_NUM]; @@ -979,7 +979,7 @@ HWTEST_F(AmsAppLifeCycleModuleTest, StateChange_013, TestSize.Level3) EXPECT_CALL(*mockAppSpawnSocket, OpenAppSpawnConnection()).Times(1).WillOnce(Return(0)); int ret = serviceInner_->OpenAppSpawnConnection(); - EXPECT_EQ(ret, 0); + ASSERT_EQ(ret, 0); EXPECT_EQ(serviceInner_->QueryAppSpawnConnectionState(), SpawnConnectionState::STATE_CONNECTED); EXPECT_CALL(*mockAppSpawnSocket, CloseAppSpawnConnection()).Times(1); diff --git a/services/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp b/services/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp index e28e909dc3..f565d0ef49 100644 --- a/services/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp +++ b/services/test/moduletest/common/ams/app_running_record_test/ams_app_running_record_module_test.cpp @@ -171,7 +171,7 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ApplicationStart_001, TestSize.Level0) RecordQueryResult result; auto record = service_->GetOrCreateAppRunningRecord(GetMockToken(), appInfo, abilityInfo, processName, 0, result); EXPECT_TRUE(record != nullptr) << ",create apprunningrecord fail!"; - EXPECT_FALSE(result.appExists) << ",result is wrong!"; + ASSERT_FALSE(result.appExists) << ",result is wrong!"; // check apprunningrecord int32_t id = record->GetRecordId(); @@ -231,7 +231,7 @@ HWTEST_F(AmsAppRunningRecordModuleTest, MultiApplicationStart_002, TestSize.Leve auto record = service_->GetOrCreateAppRunningRecord(GetMockToken(), appInfo, abilityInfo, processName, 0, result); EXPECT_TRUE(record != nullptr) << "create apprunningrecord fail!"; - EXPECT_FALSE(result.appExists) << "result is wrong!"; + ASSERT_FALSE(result.appExists) << "result is wrong!"; // check abilityrunningrecord & apprunningrecord int32_t id = record->GetRecordId(); @@ -274,7 +274,7 @@ HWTEST_F(AmsAppRunningRecordModuleTest, ScheduleTrimMemory_003, TestSize.Level1) RecordQueryResult result; auto record = service_->GetOrCreateAppRunningRecord(GetMockToken(), appInfo, abilityInfo, processName, 0, result); EXPECT_TRUE(record != nullptr) << "create apprunningrecord fail!"; - EXPECT_FALSE(result.appExists) << "result is wrong!"; + ASSERT_FALSE(result.appExists) << "result is wrong!"; // LaunchApplication sptr mockApplication(new MockApplication()); @@ -322,7 +322,7 @@ HWTEST_F(AmsAppRunningRecordModuleTest, LowMemoryWarning_004, TestSize.Level1) RecordQueryResult result; auto record = service_->GetOrCreateAppRunningRecord(GetMockToken(), appInfo, abilityInfo, processName, 0, result); EXPECT_TRUE(record != nullptr) << "create apprunningrecord fail!"; - EXPECT_FALSE(result.appExists) << "result is wrong!"; + ASSERT_FALSE(result.appExists) << "result is wrong!"; // LaunchApplication sptr mockApplication(new MockApplication()); diff --git a/services/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp b/services/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp index 7b1f332f9f..356d2ba86e 100644 --- a/services/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp +++ b/services/test/moduletest/common/ams/ipc_app_scheduler_test/ams_ipc_app_scheduler_module_test.cpp @@ -265,7 +265,7 @@ HWTEST_F(AmsIpcAppSchedulerModuleTest, ExcuteApplicationIPCInterface_008, TestSi mockApplication->Wait(); bool isEqual = mockApplication->CompareAppLaunchData(launchData); - EXPECT_EQ(true, isEqual) << "excute fail, index is " << i; + ASSERT_EQ(true, isEqual) << "excute fail, index is " << i; } } diff --git a/services/test/moduletest/common/ams/service_app_spawn_client_test/ams_service_app_spawn_client_module_test.cpp b/services/test/moduletest/common/ams/service_app_spawn_client_test/ams_service_app_spawn_client_module_test.cpp index 2080bbeb1f..d50d759ce6 100644 --- a/services/test/moduletest/common/ams/service_app_spawn_client_test/ams_service_app_spawn_client_module_test.cpp +++ b/services/test/moduletest/common/ams/service_app_spawn_client_test/ams_service_app_spawn_client_module_test.cpp @@ -208,8 +208,8 @@ HWTEST_F(AmsServiceAppSpawnClientModuleTest, ConnectAppSpawnDaemon_001, TestSize for (uint32_t i = 0; i < CYCLE_NUMBER; i++) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); appMgrService->OnStart(); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); appMgrService->OnStop(); EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appMgrService->QueryServiceState().connectionState); EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, amsInner->QueryAppSpawnConnectionState()); @@ -243,8 +243,8 @@ HWTEST_F(AmsServiceAppSpawnClientModuleTest, ConnectAppSpawnDaemon_002, TestSize EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, amsInner->QueryAppSpawnConnectionState()); MockedAppSpawnSocket::gConnectSuccess_ = true; appMgrService->OnStart(); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); appMgrService->OnStop(); EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, appMgrService->QueryServiceState().connectionState); EXPECT_EQ(SpawnConnectionState::STATE_NOT_CONNECT, amsInner->QueryAppSpawnConnectionState()); @@ -270,8 +270,8 @@ HWTEST_F(AmsServiceAppSpawnClientModuleTest, ConnectAppSpawnDaemon_003, TestSize for (uint32_t i = 0; i < CYCLE_NUMBER; i++) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); appMgrService->OnStart(); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); - EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); + ASSERT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); appMgrService->OnStart(); EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, appMgrService->QueryServiceState().connectionState); EXPECT_EQ(SpawnConnectionState::STATE_CONNECTED, amsInner->QueryAppSpawnConnectionState()); diff --git a/test/resource/amssystemtestability/abilitySrc/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/BUILD.gn index f8459bf203..f583aff645 100644 --- a/test/resource/amssystemtestability/abilitySrc/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/BUILD.gn @@ -13,53 +13,52 @@ group("ams_system_test_app") { deps = [ - "amsAbilityAppendTestA:amsAbilityAppendTestA", - "amsAbilityAppendTestB:amsAbilityAppendTestB", - "amsAbilityVisibleTestPageA:amsAbilityVisibleTestPageA", - "amsAbilityVisibleTestServiceB:amsAbilityVisibleTestServiceB", - "amsConfigurationUpdatedTest:amsConfigurationUpdatedTest", - "amsDataSystemTestA:amsDataSystemTestA", - "amsDataSystemTestB:amsDataSystemTestB", - "amsDataSystemTestC:amsDataSystemTestC", - "amsKitSTAbilityManager:amsKitSTAbilityManager", - "amsKitSystemTest:amsKitSystemTest", - "amsKitSystemTestA:amsKitSystemTestA", - "amsKitSystemTestB:amsKitSystemTestB", - "amsKitSystemTestDataA:amsKitSystemTestDataA", - "amsKitSystemTestDataB:amsKitSystemTestDataB", - "amsKitSystemTestPageA:amsKitSystemTestPageA", - "amsKitSystemTestService:amsKitSystemTestService", - "amsMissionStackTest:amsMissionStackTest", - "amsMissionStackTestSubsidiary:amsMissionStackTestSubsidiary", - "amsSystemTestA:amsSystemTestA", - "amsSystemTestB:amsSystemTestB", - "amsSystemTestC:amsSystemTestC", - "amsSystemTestD:amsSystemTestD", - "amsSystemTestDFX:amsSystemTestDFX", - "amsSystemTestE:amsSystemTestE", - "amsSystemTestErrorK:amsSystemTestErrorK", - "amsSystemTestErrorL:amsSystemTestErrorL", - "amsSystemTestF:amsSystemTestF", - "amsSystemTestG:amsSystemTestG", - "amsSystemTestH:amsSystemTestH", - "amsSystemTestI:amsSystemTestI", - "amsSystemTestM:amsSystemTestM", - "amsSystemTestN:amsSystemTestN", - "amsSystemTestO:amsSystemTestO", - "amsSystemTestP:amsSystemTestP", - "amsSystemTestQ:amsSystemTestQ", - "amsSystemTestR:amsSystemTestR", - "amsSystemTestServiceA:amsSystemTestServiceA", - "amsSystemTestServiceB:amsSystemTestServiceB", - "amsSystemTestServiceC:amsSystemTestServiceC", - - # "amsSystemTestServiceD:amsSystemTestServiceD", - "amsSystemTestServiceE:amsSystemTestServiceE", - "amsSystemTestServiceF:amsSystemTestServiceF", - "amsSystemTestServiceG:amsSystemTestServiceG", - "amsSystemTestServiceH:amsSystemTestServiceH", - "serviceAbilityA:serviceAbilityA", - "taskDispatcherTestA:taskDispatcherTestA", - "taskDispatcherTestB:taskDispatcherTestB", + #"amsAbilityAppendTestA:amsAbilityAppendTestA", + #"amsAbilityAppendTestB:amsAbilityAppendTestB", + #"amsAbilityVisibleTestPageA:amsAbilityVisibleTestPageA", + #"amsAbilityVisibleTestServiceB:amsAbilityVisibleTestServiceB", + #"amsConfigurationUpdatedTest:amsConfigurationUpdatedTest", + #"amsDataSystemTestA:amsDataSystemTestA", + #"amsDataSystemTestB:amsDataSystemTestB", + #"amsDataSystemTestC:amsDataSystemTestC", + #"amsKitSTAbilityManager:amsKitSTAbilityManager", + #"amsKitSystemTest:amsKitSystemTest", + #"amsKitSystemTestA:amsKitSystemTestA", + #"amsKitSystemTestB:amsKitSystemTestB", + #"amsKitSystemTestDataA:amsKitSystemTestDataA", + #"amsKitSystemTestDataB:amsKitSystemTestDataB", + #"amsKitSystemTestPageA:amsKitSystemTestPageA", + #"amsKitSystemTestService:amsKitSystemTestService", + #"amsMissionStackTest:amsMissionStackTest", + #"amsMissionStackTestSubsidiary:amsMissionStackTestSubsidiary", + #"amsSystemTestA:amsSystemTestA", + #"amsSystemTestB:amsSystemTestB", + #"amsSystemTestC:amsSystemTestC", + #"amsSystemTestD:amsSystemTestD", + #"amsSystemTestDFX:amsSystemTestDFX", + #"amsSystemTestE:amsSystemTestE", + #"amsSystemTestErrorK:amsSystemTestErrorK", + #"amsSystemTestErrorL:amsSystemTestErrorL", + #"amsSystemTestF:amsSystemTestF", + #"amsSystemTestG:amsSystemTestG", + #"amsSystemTestH:amsSystemTestH", + #"amsSystemTestI:amsSystemTestI", + #"amsSystemTestM:amsSystemTestM", + #"amsSystemTestN:amsSystemTestN", + #"amsSystemTestO:amsSystemTestO", + #"amsSystemTestP:amsSystemTestP", + #"amsSystemTestQ:amsSystemTestQ", + #"amsSystemTestR:amsSystemTestR", + #"amsSystemTestServiceA:amsSystemTestServiceA", + #"amsSystemTestServiceB:amsSystemTestServiceB", + #"amsSystemTestServiceC:amsSystemTestServiceC", + ## "amsSystemTestServiceD:amsSystemTestServiceD", + #"amsSystemTestServiceE:amsSystemTestServiceE", + #"amsSystemTestServiceF:amsSystemTestServiceF", + #"amsSystemTestServiceG:amsSystemTestServiceG", + #"amsSystemTestServiceH:amsSystemTestServiceH", + #"serviceAbilityA:serviceAbilityA", + #"taskDispatcherTestA:taskDispatcherTestA", + #"taskDispatcherTestB:taskDispatcherTestB", ] } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/BUILD.gn index 959cca097b..d9fbfd025b 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/BUILD.gn @@ -56,6 +56,8 @@ ohos_shared_library("amsAbilityAppendTestA") { "${innerkits_path}/appexecfwk_core:appexecfwk_core", "${kits_path}:appkit_native", "${services_path}/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/include/main_ability.h b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/include/main_ability.h index ec396c21de..fcbe2e0786 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/include/main_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/include/main_ability.h @@ -47,35 +47,35 @@ public: { [this](int code) { OnSetCallerCase1(code); }, }}, - {(int)AppendApi::TerminateAndRemoveMisson, + {(int)AppendApi::TerminateAndRemoveMisson, { [this](int code) { TerminateAndRemoveMissonCase1(code); }, }}, - {(int)AppendApi::TerminateAbilityResult, + {(int)AppendApi::TerminateAbilityResult, { [this](int code) { TerminateAbilityResultCase1(code); }, }}, - {(int)AppendApi::GetDispalyOrientation, + {(int)AppendApi::GetDispalyOrientation, { [this](int code) { GetDispalyOrientationCase1(code); }, }}, - {(int)AppendApi::GetPreferencesDir, + {(int)AppendApi::GetPreferencesDir, { [this](int code) { GetPreferencesDirCase1(code); }, }}, - {(int)AppendApi::StartAbilities, + {(int)AppendApi::StartAbilities, { [this](int code) { StartAbilitiesCase1(code); }, }}, - {(int)AppendApi::GetColorMode, + {(int)AppendApi::GetColorMode, { [this](int code) { GetColorModeCase1(code); }, }}, - {(int)AppendApi::SetColorMode, + {(int)AppendApi::SetColorMode, { [this](int code) { SetColorModeCase1(code); }, }}, - {(int)AppendApi::IsFirstInMission, + {(int)AppendApi::IsFirstInMission, { [this](int code) { IsFirstInMissionCase1(code); }, }}, diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/main_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/main_ability.cpp index 437d310c7b..0ee7755603 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/main_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/main_ability.cpp @@ -20,12 +20,6 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; -namespace { -constexpr int paramCnt = 3; -constexpr int index_f = 0; -constexpr int index_s = 1; -constexpr int index_t = 2; -} // namespace void MainAbility::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, @@ -116,11 +110,11 @@ void FirstEventSubscriber::OnReceiveEvent(const CommonEventData &data) if (std::strcmp(eventName.c_str(), g_EVENT_REQU_FIRST.c_str()) == 0) { auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); - if (caseInfo.size() < paramCnt) { + if (caseInfo.size() < 3) { return; } - if (mapTestFunc_.find(caseInfo[index_f]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[index_f]](std::stoi(caseInfo[index_s]), std::stoi(caseInfo[index_t]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } @@ -166,11 +160,11 @@ void MainAbility::GetDispalyOrientationCase1(int code) void MainAbility::GetPreferencesDirCase1(int code) { - unsigned int result = true; + bool result = true; string preferencesDir = GetPreferencesDir(); result = !preferencesDir.empty(); - result = result & (unsigned int)preferencesDir.find(this->GetBundleName()); - result = result & (unsigned int)preferencesDir.find("com.ohos.amsst.AppAppendA/files/MainAbility/preferences"); + result = result & (bool)preferencesDir.find(this->GetBundleName()); + result = result & (bool)preferencesDir.find("com.ohos.amsst.AppAppendA/files/MainAbility/preferences"); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/second_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/second_ability.cpp index e34a7a3a65..74d9768f8a 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/second_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestA/src/second_ability.cpp @@ -20,12 +20,6 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; -namespace { -constexpr int paramCnt = 3; -constexpr int index_f = 0; -constexpr int index_s = 1; -constexpr int index_t = 2; -} // namespace void SecondAbility::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, @@ -133,11 +127,11 @@ void SecondEventSubscriber::OnReceiveEvent(const CommonEventData &data) if (std::strcmp(eventName.c_str(), g_EVENT_REQU_SECOND.c_str()) == 0) { auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); - if (caseInfo.size() < paramCnt) { + if (caseInfo.size() < 3) { return; } - if (mapTestFunc_.find(caseInfo[index_f]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[index_f]](std::stoi(caseInfo[index_s]), std::stoi(caseInfo[index_t]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/BUILD.gn index 94db701375..c510161b40 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/BUILD.gn @@ -55,6 +55,8 @@ ohos_shared_library("amsAbilityAppendTestB") { "${innerkits_path}/appexecfwk_core:appexecfwk_core", "${kits_path}:appkit_native", "${services_path}/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/main_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/main_ability.cpp index 8cbcdfb0c3..db038f3117 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/main_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/main_ability.cpp @@ -20,12 +20,6 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; -namespace { -static const int paramCnt = 3; -static const int index_f = 0; -static const int index_s = 1; -static const int index_t = 2; -} // namespace void MainAbility::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, @@ -109,11 +103,11 @@ void FirstEventSubscriber::OnReceiveEvent(const CommonEventData &data) if (std::strcmp(eventName.c_str(), g_EVENT_REQU_FIRSTB.c_str()) == 0) { auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); - if (caseInfo.size() < paramCnt) { + if (caseInfo.size() < 3) { return; } - if (mapTestFunc_.find(caseInfo[index_f]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[index_f]](std::stoi(caseInfo[index_s]), std::stoi(caseInfo[index_t]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/test_utils.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/test_utils.cpp index 29dca59b94..07ebf00c47 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/test_utils.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityAppendTestB/src/test_utils.cpp @@ -47,7 +47,7 @@ Want TestUtils::MakeWant( std::vector TestUtils::split(const std::string &in, const std::string &delim) { - std::regex reg { delim}; + std::regex reg{delim}; return std::vector{ std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator()}; } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/BUILD.gn index 47d0c6613f..edea9e7b84 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/BUILD.gn @@ -52,6 +52,8 @@ ohos_shared_library("amsAbilityVisibleTestPageA") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/appexecfwk/standard/services/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//utils/native/base:utilsbase", ] diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea1.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea1.cpp index b54bb086d5..0c0e041b42 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea1.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { +using namespace OHOS::NativeRdb; void AmsAbilityVisibleTestPageA1::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) @@ -89,7 +90,7 @@ void AmsAbilityVisibleTestPageA1::OnActive() if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + NativeRdb::ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea2.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea2.cpp index 1dd32126b9..169897284c 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea2.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void AmsAbilityVisibleTestPageA2::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) @@ -89,7 +90,7 @@ void AmsAbilityVisibleTestPageA2::OnActive() if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } if (startAbilityType == "TriggerWantAgentPageAbility") { diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea3.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea3.cpp index 8a041eb3f6..3a10f80656 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea3.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea3.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void AmsAbilityVisibleTestPageA3::OnStart(const Want &want) { GetWantInfo(want); @@ -79,7 +80,7 @@ void AmsAbilityVisibleTestPageA3::OnActive() if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea4.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea4.cpp index 2281674974..c122ba32b9 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea4.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestPageA/src/amsabilityvisibletestpagea4.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void AmsAbilityVisibleTestPageA4::OnStart(const Want &want) { GetWantInfo(want); @@ -80,7 +81,7 @@ void AmsAbilityVisibleTestPageA4::OnActive() if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/BUILD.gn index 4985c58073..0eafd1b592 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/BUILD.gn @@ -53,6 +53,8 @@ ohos_shared_library("amsAbilityVisibleTestServiceB") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/appexecfwk/standard/services/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//utils/native/base:utilsbase", ] diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb1.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb1.cpp index c3ab87e077..29a044e5b8 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb1.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void AmsAbilityVisibleTestPageB1::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) @@ -89,7 +90,7 @@ void AmsAbilityVisibleTestPageB1::OnActive() if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb2.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb2.cpp index 2caba9013d..36516ae9a5 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestpageb2.cpp @@ -17,6 +17,7 @@ namespace OHOS { namespace AppExecFwk { + void AmsAbilityVisibleTestPageB2::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) @@ -90,7 +91,7 @@ void AmsAbilityVisibleTestPageB2::OnActive() if (startAbilityType == "Data" || startAbilityType == "DataRelease") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); if (startAbilityType == "DataRelease") { helper->Release(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservice.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservice.cpp index a4ee376ae8..d6c3935407 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservice.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservice.cpp @@ -116,7 +116,7 @@ sptr AmsAbilityVisibleTestService::OnConnect(const Want &want) if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservicea1.cpp b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservicea1.cpp index 208056c525..a7bb23c230 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservicea1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsAbilityVisibleTestServiceB/src/amsabilityvisibletestservicea1.cpp @@ -116,7 +116,7 @@ sptr AmsAbilityVisibleTestServiceA1::OnConnect(const Want &want) if (startAbilityType == "Data") { Uri dataAbilityUri("dataability:///" + startBundleName + "." + startAbilityName); std::shared_ptr helper = DataAbilityHelper::Creator(GetContext()); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; helper->Insert(dataAbilityUri, bucket); } } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/BUILD.gn index 901930e78c..ed06c53138 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/BUILD.gn @@ -57,6 +57,8 @@ ohos_shared_library("amsDataSystemTestA") { "${innerkits_path}/appexecfwk_core:appexecfwk_core", "${kits_path}:appkit_native", "${services_path}/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_data_a.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_data_a.cpp index c71b154d3e..e930e4b026 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_data_a.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_data_a.cpp @@ -25,7 +25,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_DATA_A_CODE = 210; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -39,8 +38,6 @@ static const int DEFAULT_UPDATE_RESULT = 3333; static const std::string ABILITY_TYPE_PAGE = "0"; static const std::string ABILITY_TYPE_SERVICE = "1"; static const std::string ABILITY_TYPE_DATA = "2"; -static const int charCnt = 5; -} // namespace bool AmsStDataAbilityDataA::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -165,7 +162,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -190,9 +187,9 @@ static void GetResult(std::shared_ptr child, std::shared_pt return; } result = std::to_string(fd); - char str[charCnt]; + char str[5]; if (!feof(file)) - fgets(str, charCnt, file); + fgets(str, 5, file); result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_page_a.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_page_a.cpp index bc87bd356b..83c3d4752a 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_page_a.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestA/src/ams_st_data_ability_page_a.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_PAGE_A_CODE = 110; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -34,8 +33,6 @@ static const std::string OPERATOR_UPDATE = "Update"; static const std::string OPERATOR_QUERY = "Query"; static const std::string OPERATOR_GETFILETYPES = "GetFileTypes"; static const std::string OPERATOR_OPENFILE = "OpenFile"; -static const int charCnt = 5; -} // namespace bool AmsStDataAbilityPageA::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -152,7 +149,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -179,9 +176,9 @@ static void GetResult(std::shared_ptr child, std::shared_pt return; } result = std::to_string(fd); - char str[charCnt]; + char str[5]; if (!feof(file)) - fgets(str, charCnt, file); + fgets(str, 5, file); result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/BUILD.gn index 0397152f27..99440ff945 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/BUILD.gn @@ -56,6 +56,8 @@ ohos_shared_library("amsDataSystemTestB") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/appexecfwk/standard/services/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_data_b.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_data_b.cpp index 42b50324f6..8b0a9509b0 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_data_b.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_data_b.cpp @@ -23,7 +23,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_DATA_B_CODE = 220; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -37,8 +36,6 @@ static const int DEFAULT_UPDATE_RESULT = 3333; static const std::string ABILITY_TYPE_PAGE = "0"; static const std::string ABILITY_TYPE_SERVICE = "1"; static const std::string ABILITY_TYPE_DATA = "2"; -static const int charCnt = 5; -} // namespace bool AmsStDataAbilityDataB::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -153,7 +150,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -178,10 +175,9 @@ static void GetResult(std::shared_ptr child, std::shared_pt return; } result = std::to_string(fd); - char str[charCnt]; - if (!feof(file)) { - fgets(str, charCnt, file); - } + char str[5]; + if (!feof(file)) + fgets(str, 5, file); result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_page_b.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_page_b.cpp index 4b883d863e..5d03834da1 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_page_b.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestB/src/ams_st_data_ability_page_b.cpp @@ -26,7 +26,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_PAGE_B_CODE = 120; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -34,8 +33,6 @@ static const std::string OPERATOR_UPDATE = "Update"; static const std::string OPERATOR_QUERY = "Query"; static const std::string OPERATOR_GETFILETYPES = "GetFileTypes"; static const std::string OPERATOR_OPENFILE = "OpenFile"; -static const int charCnt = 5; -} // namespace bool AmsStDataAbilityPageB::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -154,7 +151,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -179,10 +176,9 @@ static void GetResult(std::shared_ptr child, std::shared_pt return; } result = std::to_string(fd); - char str[charCnt]; - if (!feof(file)) { - fgets(str, charCnt, file); - } + char str[5]; + if (!feof(file)) + fgets(str, 5, file); result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/BUILD.gn index 84231830d3..84116a2f76 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/BUILD.gn @@ -56,6 +56,8 @@ ohos_shared_library("amsDataSystemTestC") { "//foundation/appexecfwk/standard/interfaces/innerkits/appexecfwk_core:appexecfwk_core", "//foundation/appexecfwk/standard/kits:appkit_native", "//foundation/appexecfwk/standard/services/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c1.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c1.cpp index e661ad6292..6a71906f66 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c1.cpp @@ -23,7 +23,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_DATA_C1_CODE = 230; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -38,7 +37,6 @@ static const std::string ABILITY_TYPE_PAGE = "0"; static const std::string ABILITY_TYPE_SERVICE = "1"; static const std::string ABILITY_TYPE_DATA = "2"; constexpr int charCnt = 5; -} // namespace bool AmsStDataAbilityDataC1::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -151,7 +149,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -177,9 +175,8 @@ static void GetResult(std::shared_ptr child, std::shared_pt } result = std::to_string(fd); char str[charCnt]; - if (!feof(file)) { + if (!feof(file)) fgets(str, charCnt, file); - } result = str; fclose(file); } @@ -190,7 +187,7 @@ void DataTestDataC1EventSubscriber::GetResultBySelf( { if (child->GetOperatorName() == OPERATOR_INSERT) { APP_LOGI("---------------------Insert--------------------"); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = std::to_string(mainAbility->Insert(dataAbilityUri, bucket)); } else if (child->GetOperatorName() == OPERATOR_DELETE) { APP_LOGI("---------------------Delete--------------------"); @@ -198,7 +195,7 @@ void DataTestDataC1EventSubscriber::GetResultBySelf( result = std::to_string(mainAbility->Delete(dataAbilityUri, predicates)); } else if (child->GetOperatorName() == OPERATOR_UPDATE) { APP_LOGI("---------------------Update--------------------"); - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; AppExecFwk::DataAbilityPredicates predicates; result = std::to_string(mainAbility->Update(dataAbilityUri, bucket, predicates)); } else if (child->GetOperatorName() == OPERATOR_QUERY) { @@ -228,9 +225,8 @@ void DataTestDataC1EventSubscriber::GetResultBySelf( mainAbility_->PublishEvent(abilityEventName, ABILITY_DATA_C1_CODE, "OpenFile"); char str[charCnt]; - if (!feof(file)) { + if (!feof(file)) fgets(str, charCnt, file); - } result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c2.cpp b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c2.cpp index deccd50207..c8bd58b438 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsDataSystemTestC/src/ams_st_data_ability_data_c2.cpp @@ -23,7 +23,6 @@ namespace OHOS { namespace AppExecFwk { -namespace { static const int ABILITY_DATA_C2_CODE = 240; static const std::string OPERATOR_INSERT = "Insert"; static const std::string OPERATOR_DELETE = "Delete"; @@ -37,8 +36,6 @@ static const int DEFAULT_UPDATE_RESULT = 3333; static const std::string ABILITY_TYPE_PAGE = "0"; static const std::string ABILITY_TYPE_SERVICE = "1"; static const std::string ABILITY_TYPE_DATA = "2"; -constexpr int charCnt = 5; -} // namespace bool AmsStDataAbilityDataC2::PublishEvent(const std::string &eventName, const int &code, const std::string &data) { @@ -153,7 +150,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); @@ -178,10 +175,9 @@ static void GetResult(std::shared_ptr child, std::shared_pt return; } result = std::to_string(fd); - char str[charCnt]; - if (!feof(file)) { - fgets(str, charCnt, file); - } + char str[5]; + if (!feof(file)) + fgets(str, 5, file); result = str; fclose(file); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/include/kit_test_ability_manager_second.h b/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/include/kit_test_ability_manager_second.h index f6b888f665..b3f37084fe 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/include/kit_test_ability_manager_second.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/include/kit_test_ability_manager_second.h @@ -139,6 +139,7 @@ public: void KitTerminateAbility(); KitTestAbilityManagerSecond *kitTestAbility_; }; + } // namespace AppExecFwk } // namespace OHOS #endif // _KIT_TEST_ABILITY_MANAGER_SECOND_H_ diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/src/kit_test_ability_manager_second.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/src/kit_test_ability_manager_second.cpp index 62025acc40..d056f2a265 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/src/kit_test_ability_manager_second.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSTAbilityManager/src/kit_test_ability_manager_second.cpp @@ -112,7 +112,8 @@ void KitTestAbilityManagerSecond::ProcessStateNotEqual( void KitTestAbilityManagerSecond::GetAllStackInfo(MissionStackInfo &missionStackInfo, int stackID) { - StackInfo stackInfo = AbilityManager::GetInstance().GetAllStackInfo(); + StackInfo stackInfo; + stackInfo = AbilityManager::GetInstance().GetAllStackInfo(); for (const auto &stackInfo : stackInfo.missionStackInfos) { if (stackInfo.id == stackID) { missionStackInfo = stackInfo; @@ -207,7 +208,7 @@ void KitTestAbilityManagerSecond::AbilityManagerGetAllStackInfoCase4(int code) GetAllStackInfo(missionStackInfo, 1); bool result = false; if (missionStackInfo.missionRecords.size() == 1) { - result = (missionStackInfo.missionRecords[0].abilityRecordInfos.size() == numTwo); + result = (missionStackInfo.missionRecords[0].abilityRecordInfos.size() == 2); } PublishEvent(g_respPageManagerAbilityST, code, std::to_string(result)); } @@ -229,9 +230,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCas { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCase1"); std::vector info; - info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(numThree, RECENT_WITH_EXCLUDED); + info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(3, RECENT_WITH_EXCLUDED); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { if (info[0].baseAbility.GetBundleName() == bundleName) { result = true; } @@ -243,9 +244,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCas { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCase2"); std::vector info; - info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(numThree, RECENT_WITH_EXCLUDED); + info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(3, RECENT_WITH_EXCLUDED); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { result = true; } PublishEvent(g_respPageManagerAbilityST, code, std::to_string(result)); @@ -255,9 +256,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCas { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRecentAbilityMissionInfoCase3"); std::vector info; - info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(numThree, RECENT_WITH_EXCLUDED); + info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(3, RECENT_WITH_EXCLUDED); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { if (info[0].baseAbility.GetBundleName() == bundleName && info[0].baseAbility.GetAbilityName() == topAbilityName) { result = true; @@ -271,9 +272,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCa { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCase1"); std::vector info; - info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(numThree); + info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(3); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { if (info[0].baseAbility.GetBundleName() == bundleName) { result = true; } @@ -285,9 +286,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCa { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCase2"); std::vector info; - info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(numThree); + info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(3); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { result = true; } PublishEvent(g_respPageManagerAbilityST, code, std::to_string(result)); @@ -297,9 +298,9 @@ void KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCa { APP_LOGI("KitTestAbilityManagerSecond::AbilityManagerQueryRunningAbilityMissionInfoCase3"); std::vector info; - info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(numThree); + info = AbilityManager::GetInstance().QueryRunningAbilityMissionInfo(3); bool result = false; - if (info.size() == 1 && info[0].size == numTwo) { + if (1 == info.size() && 2 == info[0].size) { if (info[0].baseAbility.GetBundleName() == bundleName && info[0].baseAbility.GetAbilityName() == topAbilityName) { result = true; @@ -353,7 +354,7 @@ void KitTestAbilityManagerSecond::OnActive() { APP_LOGI("KitTestAbilityManagerSecond::OnActive"); Ability::OnActive(); - if (isMoveMissionToTop == true) { + if (true == isMoveMissionToTop) { PublishEvent(g_respPageManagerAbilityST, moveMissionToTopCode, "1"); isMoveMissionToTop = false; moveMissionToTopCode = -1; @@ -379,10 +380,10 @@ void KitTestAbilityManagerSecond::OnBackground() { APP_LOGI("KitTestAbilityManagerSecond::OnBackground"); Ability::OnBackground(); - if (isMoveMissionToTop == true) { + if (true == isMoveMissionToTop) { std::vector info; - info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(numThree, RECENT_WITH_EXCLUDED); - if (info.size() == 1 && info[0].size == numTwo) { + info = AbilityManager::GetInstance().QueryRecentAbilityMissionInfo(3, RECENT_WITH_EXCLUDED); + if (1 == info.size() && 2 == info[0].size) { GetAbilityManager()->MoveMissionToTop(info[0].id); APP_LOGI("GetAbilityManager()->MoveMissionToTop(info[0].id);%{public}d", static_cast(info[0].id)); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fifth_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fifth_ability.h index 45ee85ed58..310b4dfb4c 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fifth_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fifth_ability.h @@ -239,6 +239,7 @@ public: FifthAbility *fifthAbility; std::unordered_map> mapTestFunc_; }; + } // namespace AppExecFwk } // namespace OHOS #endif // _SECOND_ABILITY_H_ \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fourth_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fourth_ability.h index c9b3d45e1e..903d71ac9a 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fourth_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/fourth_ability.h @@ -43,7 +43,7 @@ public: bool CompareType(const AAFwk::Skills &skills1, const AAFwk::Skills &skills2); bool CompareWantParams(const AAFwk::Skills &skills1, const AAFwk::Skills &skills2); bool CompareSkills(const AAFwk::Skills &skills1, const AAFwk::Skills &skills2); - template + template void SkillsGetWantParams(M params, int code) { AAFwk::Skills skill; @@ -778,6 +778,7 @@ public: private: std::unordered_map> mapTestFunc_; }; + } // namespace AppExecFwk } // namespace OHOS #endif // _THIRD_ABILITY_H_ \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/kit_test_ability_manager.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/kit_test_ability_manager.h index 5bdd1a4489..1bc3c529ed 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/kit_test_ability_manager.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTest/include/kit_test_ability_manager.h @@ -189,6 +189,7 @@ private: std::unordered_map> mapTestFunc_; KitTestAbilityManager *kitTestAbility_; }; + } // namespace AppExecFwk } // namespace OHOS -#endif // _KIT_TEST_ABILITY_MANAGER_H_ +#endif //_KIT_TEST_ABILITY_MANAGER_H_ diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/BUILD.gn index be5a60832a..a93204d574 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/BUILD.gn @@ -60,6 +60,8 @@ ohos_shared_library("amsKitSystemTestDataA") { "${innerkits_path}/appexecfwk_core:appexecfwk_core", "${kits_path}:appkit_native", "${services_path}/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a1.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a1.cpp index 621ddef3b4..e90d848cc0 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a1.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a1.cpp @@ -338,7 +338,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityDataA1 *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a2.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a2.cpp index 9153f1ed29..a55f0cb723 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a2.cpp @@ -337,7 +337,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityDataA2 *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a3.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a3.cpp index 4ba9c1f21c..db581024b1 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a3.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_data_a3.cpp @@ -340,7 +340,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityDataA3 *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_page_a.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_page_a.cpp index 31fa67ba3c..d10c3ddf77 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_page_a.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_page_a.cpp @@ -153,7 +153,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityPageA *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_service_a.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_service_a.cpp index a19b5908fb..23c6068037 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_service_a.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataA/src/ams_st_kit_data_ability_service_a.cpp @@ -179,7 +179,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityServiceA *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/BUILD.gn b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/BUILD.gn index 84cfa990b8..6b0bd12020 100755 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/BUILD.gn +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/BUILD.gn @@ -58,6 +58,8 @@ ohos_shared_library("amsKitSystemTestDataB") { "${innerkits_path}/appexecfwk_core:appexecfwk_core", "${kits_path}:appkit_native", "${services_path}/bundlemgr:libbms", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_dataability:native_dataability", + "//foundation/distributeddatamgr/appdatamgr/interfaces/innerkits/native_rdb:native_rdb", "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri", "//third_party/jsoncpp:jsoncpp", "//utils/native/base:utilsbase", diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_data_b.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_data_b.cpp index 0d7e1d4c45..b15d455f71 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_data_b.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_data_b.cpp @@ -320,7 +320,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityDataB *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_page_b.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_page_b.cpp index 1dd6fd9025..8ceb1505dc 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_page_b.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_page_b.cpp @@ -153,7 +153,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityPageB *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_service_b.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_service_b.cpp index 3761d8412f..a7001d8001 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_service_b.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestDataB/src/ams_st_kit_data_ability_service_b.cpp @@ -179,7 +179,7 @@ static void GetResult(std::shared_ptr child, std::shared_pt AmsStKitDataAbilityServiceB *mainAbility, Uri dataAbilityUri, string &result) { AppExecFwk::DataAbilityPredicates predicates; - AppExecFwk::ValuesBucket bucket; + ValuesBucket bucket; result = "failed"; if (child->GetOperatorName() == OPERATOR_INSERT) { result = std::to_string(helper->Insert(dataAbilityUri, bucket)); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_ability.h index 17c36f5b4f..ef28fca50f 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_ability.h @@ -83,7 +83,12 @@ public: void TestAbilityDisconnectAbility(); void DoTestCase(); - + void CaseIndexOne(); + void CaseIndexTwo(); + void DisconnectCaseIndexOne(); + void DisconnectCaseIndexTwo(); + void AbilityDisconnectCaseIndexOne(); + void AbilityDisconnectCaseIndexTwo(); protected: void Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) override; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_connection_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_connection_ability.h index ca235dbdb8..e094e4e8de 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_connection_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_connection_ability.h @@ -80,6 +80,10 @@ public: void TestDisconnectAbility(); void TestStartAbility(); void TestTerminateAbility(); + void DisconnectCaseIndexOne(); + void DisconnectCaseIndexTwo(); + void ConnectCaseIndexOne(); + void ConnectCaseIndexTwo(); protected: void Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, @@ -97,9 +101,9 @@ protected: bool SubscribeEvent(); private: - Want want_{}; - sptr stub_{}; - sptr connCallback_{}; + Want want_ {}; + sptr stub_ {}; + sptr connCallback_ {}; std::shared_ptr subscriber_ = {}; }; std::string AbilityConnectionAbility::sequenceNumber_ = "0"; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_context_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_context_ability.h index c2b76b14ef..95242ba347 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_context_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_context_ability.h @@ -90,11 +90,14 @@ protected: virtual void OnDisconnect(const Want &want) override; bool SubscribeEvent(); - + void ConnectCaseIndexOne(); + void ConnectCaseIndexTwo(); + void DisconnectCaseIndexOne(); + void DisconnectCaseIndexTwo(); private: - Want want_{}; - sptr stub_{}; - sptr connCallback_{}; + Want want_ {}; + sptr stub_ {}; + sptr connCallback_ {}; std::shared_ptr subscriber_ = {}; }; int AbilityContextAbility::sequenceNumber_ = 0; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_life_cycle_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_life_cycle_ability.h index 3adcabb8db..c52ea2d40f 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_life_cycle_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/ability_life_cycle_ability.h @@ -113,11 +113,11 @@ protected: virtual void OnDisconnect(const Want &want) override; bool SubscribeEvent(); - + void GetLifecycleStateCaseOne(); private: - Want want_{}; - sptr stub_{}; - sptr connCallback_{}; + Want want_ {}; + sptr stub_ {}; + sptr connCallback_ {}; std::shared_ptr subscriber_ = {}; }; int AbilityLifeCycleAbility::sequenceNumber_ = 0; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/life_cycle_call_backs_ability.h b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/life_cycle_call_backs_ability.h index 0da1ab05da..25b50672cc 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/life_cycle_call_backs_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/include/life_cycle_call_backs_ability.h @@ -23,7 +23,6 @@ namespace OHOS { namespace AppExecFwk { - class ServiceLifecycleCallbacks : public AbilityLifecycleCallbacks { public: ServiceLifecycleCallbacks() = default; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_ability.cpp index 282f42fe45..f0756aa5f3 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_ability.cpp @@ -20,6 +20,10 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; +namespace { +constexpr int SLEEP_SECOND = 2; +constexpr int loopCnt = 3; +} AbilityAbility::~AbilityAbility() { @@ -174,6 +178,27 @@ void AbilityAbility::OnNewWant(const Want &want) DoTestCase(); } +void AbilityAbility::CaseIndexOne() { + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(SLEEP_SECOND); + DisconnectAbility(connCallback_); +} + +void AbilityAbility::CaseIndexTwo() { + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + bool ret = ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(SLEEP_SECOND); + DisconnectAbility(connCallback_); +} + void AbilityAbility::TestConnectAbility() { APP_LOGI("AbilityAbility::OnStart sequenceNumber_ = %{public}s %{public}d", @@ -182,23 +207,10 @@ void AbilityAbility::TestConnectAbility() switch ((CaseIndex)std::stoi(AbilityAbility::sequenceNumber_)) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); - DisconnectAbility(connCallback_); + CaseIndexOne(); } break; case CaseIndex::TWO: { - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - bool ret = ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); - DisconnectAbility(connCallback_); + CaseIndexTwo(); } break; case CaseIndex::THREE: { stub_ = new (std::nothrow) AbilityConnectCallback(); @@ -207,7 +219,7 @@ void AbilityAbility::TestConnectAbility() Want want = TestUtils::MakeWant("", "AmsStServiceAbilityA1", "com.ohos.amsst.service.appA", params); bool ret = ConnectAbility(want, connCallback_); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); DisconnectAbility(connCallback_); } break; case CaseIndex::FOUR: { @@ -216,7 +228,7 @@ void AbilityAbility::TestConnectAbility() connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); bool ret = ConnectAbility(want_, connCallback_); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); DisconnectAbility(connCallback_); } } break; @@ -225,7 +237,7 @@ void AbilityAbility::TestConnectAbility() sptr connCallback(new (std::nothrow) AbilityConnectionProxy(stub)); bool ret = ConnectAbility(want_, connCallback); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); DisconnectAbility(connCallback); } break; default: @@ -258,7 +270,7 @@ void AbilityAbility::TestStopAbility() TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestStopAbility"); } break; case CaseIndex::FOUR: { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < loopCnt; i++) { bool ret = StopAbility(want_); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestStopAbility"); } @@ -275,6 +287,25 @@ void AbilityAbility::TestStopAbility() } } +void AbilityAbility::DisconnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + DisconnectAbility(connCallback_); +} + +void AbilityAbility::DisconnectCaseIndexTwo() { + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + DisconnectAbility(connCallback_); +} + void AbilityAbility::TestDisconnectAbility() { APP_LOGI("AbilityAbility::OnStart sequenceNumber_ = %{public}s %{public}d", @@ -283,21 +314,10 @@ void AbilityAbility::TestDisconnectAbility() switch ((CaseIndex)std::stoi(AbilityAbility::sequenceNumber_)) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - DisconnectAbility(connCallback_); + DisconnectCaseIndexOne(); } break; case CaseIndex::TWO: { - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - DisconnectAbility(connCallback_); + DisconnectCaseIndexTwo(); } break; case CaseIndex::THREE: { MAP_STR_STR params; @@ -309,7 +329,7 @@ void AbilityAbility::TestDisconnectAbility() DisconnectAbility(connCallback_); } break; case CaseIndex::FOUR: { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < loopCnt; i++) { stub_ = new (std::nothrow) AbilityConnectCallback(); connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); bool ret = ConnectAbility(want_, connCallback_); @@ -391,7 +411,7 @@ void AbilityAbility::TestTerminateAbility() TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, 1, "TestTerminateAbility"); - sleep(2); + sleep(SLEEP_SECOND); StopAbility(want); TerminateAbility(); } break; @@ -400,7 +420,7 @@ void AbilityAbility::TestTerminateAbility() Want want = TestUtils::MakeWant("", "AmsStServiceAbilityA1", "com.ohos.amsst.service.appA", params); StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, 1, "TestTerminateAbility"); - sleep(2); + sleep(SLEEP_SECOND); StopAbility(want); TerminateAbility(); } break; @@ -415,7 +435,7 @@ void AbilityAbility::TestTerminateAbility() Want want = TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKitx", params); StartAbility(want, 0); - sleep(2); + sleep(SLEEP_SECOND); TerminateAbility(); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, 1, "TestTerminateAbility"); } break; @@ -491,7 +511,7 @@ void AbilityAbility::TestAbilityConnectAbility() TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); bool ret = ConnectAbility(want, connCallback_); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityConnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); DisconnectAbility(connCallback_); } break; case CaseIndex::THREE: { @@ -501,7 +521,7 @@ void AbilityAbility::TestAbilityConnectAbility() Want want = TestUtils::MakeWant("", "AmsStServiceAbilityA1", "com.ohos.amsst.service.appA", params); bool ret = ConnectAbility(want, connCallback_); TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityConnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); DisconnectAbility(connCallback_); } break; case CaseIndex::FOUR: { @@ -612,6 +632,27 @@ void AbilityAbility::TestAbilityGetLifecycle() } } +void AbilityAbility::AbilityDisconnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityDisconnectAbility"); + sleep(1); + DisconnectAbility(connCallback_); +} + +void AbilityAbility::AbilityDisconnectCaseIndexTwo() { + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + stub_ = new (std::nothrow) AbilityConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityDisconnectAbility"); + sleep(1); + DisconnectAbility(connCallback_); +} + void AbilityAbility::TestAbilityDisconnectAbility() { APP_LOGI("AbilityAbility::OnStart sequenceNumber_ = %{public}s %{public}d", @@ -620,23 +661,10 @@ void AbilityAbility::TestAbilityDisconnectAbility() switch ((CaseIndex)std::stoi(AbilityAbility::sequenceNumber_)) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityDisconnectAbility"); - sleep(1); - DisconnectAbility(connCallback_); + AbilityDisconnectCaseIndexOne(); } break; case CaseIndex::TWO: { - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - stub_ = new (std::nothrow) AbilityConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_RESP_EVENT_NAME, ret, "TestAbilityDisconnectAbility"); - sleep(1); - DisconnectAbility(connCallback_); + AbilityDisconnectCaseIndexTwo(); } break; case CaseIndex::THREE: { MAP_STR_STR params; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_connection_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_connection_ability.cpp index 054b04669a..3f9ec8825d 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_connection_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_connection_ability.cpp @@ -126,27 +126,35 @@ void AbilityConnectionAbility::OnDisconnect(const Want &want) APP_ABILITY_CONNECTION_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } +void AbilityConnectionAbility::ConnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(1); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + +void AbilityConnectionAbility::ConnectCaseIndexTwo() { + stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(1); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + void AbilityConnectionAbility::TestConnectAbility() { switch ((CaseIndex)std::stoi(AbilityConnectionAbility::sequenceNumber_)) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(1); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + ConnectCaseIndexOne(); } break; case CaseIndex::TWO: { - stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(1); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + ConnectCaseIndexTwo(); } break; case CaseIndex::THREE: { stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); @@ -219,27 +227,35 @@ void AbilityConnectionAbility::TestStopAbility() } } +void AbilityConnectionAbility::DisconnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + sleep(1); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + +void AbilityConnectionAbility::DisconnectCaseIndexTwo() { + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + sleep(1); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + void AbilityConnectionAbility::TestDisconnectAbility() { switch ((CaseIndex)std::stoi(AbilityConnectionAbility::sequenceNumber_)) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - sleep(1); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + DisconnectCaseIndexOne(); } break; case CaseIndex::TWO: { - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - stub_ = new (std::nothrow) AbilityConnectionConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONNECTION_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - sleep(1); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + DisconnectCaseIndexTwo(); } break; case CaseIndex::THREE: { MAP_STR_STR params; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_context_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_context_ability.cpp index a8155eda53..9f53b7f6cb 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_context_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_context_ability.cpp @@ -21,6 +21,9 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; +namespace { +constexpr int SLEEP_SECOND = 2; +} AbilityContextAbility::~AbilityContextAbility() { @@ -127,27 +130,35 @@ void AbilityContextAbility::OnDisconnect(const Want &want) APP_ABILITY_CONTEXT_RESP_EVENT_NAME, AbilityLifecycleExecutor::LifecycleState::BACKGROUND, "OnDisconnect"); } +void AbilityContextAbility::ConnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityContextConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(SLEEP_SECOND); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + +void AbilityContextAbility::ConnectCaseIndexTwo() { + stub_ = new (std::nothrow) AbilityContextConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestConnectAbility"); + sleep(1); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + void AbilityContextAbility::TestConnectAbility() { switch ((CaseIndex)AbilityContextAbility::sequenceNumber_) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityContextConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(2); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + ConnectCaseIndexOne(); } break; case CaseIndex::TWO: { - stub_ = new (std::nothrow) AbilityContextConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestConnectAbility"); - sleep(1); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + ConnectCaseIndexTwo(); } break; case CaseIndex::THREE: { stub_ = new (std::nothrow) AbilityContextConnectCallback(); @@ -220,26 +231,34 @@ void AbilityContextAbility::TestStopAbility() } } +void AbilityContextAbility::DisconnectCaseIndexOne() { + stub_ = new (std::nothrow) AbilityContextConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + +void AbilityContextAbility::DisconnectCaseIndexTwo() { + MAP_STR_STR params; + Want want = + TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); + stub_ = new (std::nothrow) AbilityContextConnectCallback(); + connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); + bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); + TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); + sleep(SLEEP_SECOND); + BaseAbility::GetContext()->DisconnectAbility(connCallback_); +} + void AbilityContextAbility::TestDisconnectAbility() { switch ((CaseIndex)AbilityContextAbility::sequenceNumber_) { case CaseIndex::ONE: { - stub_ = new (std::nothrow) AbilityContextConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want_, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + DisconnectCaseIndexOne(); } break; case CaseIndex::TWO: { - MAP_STR_STR params; - Want want = - TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); - stub_ = new (std::nothrow) AbilityContextConnectCallback(); - connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); - bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); - TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - sleep(2); - BaseAbility::GetContext()->DisconnectAbility(connCallback_); + DisconnectCaseIndexTwo(); } break; case CaseIndex::THREE: { MAP_STR_STR params; @@ -248,7 +267,7 @@ void AbilityContextAbility::TestDisconnectAbility() connCallback_ = new (std::nothrow) AbilityConnectionProxy(stub_); bool ret = BaseAbility::GetContext()->ConnectAbility(want, connCallback_); TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, ret, "TestDisconnectAbility"); - sleep(2); + sleep(SLEEP_SECOND); BaseAbility::GetContext()->DisconnectAbility(connCallback_); } break; case CaseIndex::FOUR: { @@ -288,7 +307,7 @@ void AbilityContextAbility::TestStartAbility() TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); BaseAbility::GetContext()->StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, 1, "TestStartAbility"); - sleep(2); + sleep(SLEEP_SECOND); BaseAbility::GetContext()->StopAbility(want); } break; case CaseIndex::THREE: { @@ -296,7 +315,7 @@ void AbilityContextAbility::TestStartAbility() Want want = TestUtils::MakeWant("", "AmsStServiceAbilityA1", "com.ohos.amsst.service.appA", params); BaseAbility::GetContext()->StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, 1, "TestStartAbility"); - sleep(2); + sleep(SLEEP_SECOND); BaseAbility::GetContext()->StopAbility(want); } break; case CaseIndex::FOUR: { @@ -330,7 +349,7 @@ void AbilityContextAbility::TestTerminateAbility() TestUtils::MakeWant("", "LifecycleCallbacksAbility", "com.ohos.amsst.service.AppKit", params); BaseAbility::GetContext()->StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, 1, "TestTerminateAbility"); - sleep(2); + sleep(SLEEP_SECOND); BaseAbility::GetContext()->StopAbility(want); BaseAbility::GetContext()->TerminateAbility(); } break; @@ -339,7 +358,7 @@ void AbilityContextAbility::TestTerminateAbility() Want want = TestUtils::MakeWant("", "AmsStServiceAbilityA1", "com.ohos.amsst.service.appA", params); BaseAbility::GetContext()->StartAbility(want, 0); TestUtils::PublishEvent(APP_ABILITY_CONTEXT_RESP_EVENT_NAME, 1, "TestTerminateAbility"); - sleep(2); + sleep(SLEEP_SECOND); BaseAbility::GetContext()->StopAbility(want); BaseAbility::GetContext()->TerminateAbility(); } break; diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_life_cycle_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_life_cycle_ability.cpp index 2ccf0e524b..03392a7352 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_life_cycle_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/ability_life_cycle_ability.cpp @@ -21,7 +21,9 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; - +namespace { +constexpr int loopCnt = 3; +} AbilityLifeCycleAbility::~AbilityLifeCycleAbility() { CommonEventManager::UnSubscribeCommonEvent(subscriber_); @@ -234,7 +236,7 @@ void AbilityLifeCycleAbility::TestStopAbility() TestUtils::PublishEvent(APP_ABILITY_LIFE_CYCLE_RESP_EVENT_NAME, ret, "TestStopAbility"); } break; case CaseIndex::FOUR: { - for (int i = 0; i < 3; i++) { + for (int i = 0; i < loopCnt; i++) { bool ret = BaseAbility::GetContext()->StopAbility(want_); TestUtils::PublishEvent(APP_ABILITY_LIFE_CYCLE_RESP_EVENT_NAME, ret, "TestStopAbility"); } @@ -420,14 +422,18 @@ void AbilityLifeCycleAbility::TestLifeCycleGetLifecycle() } } +void AbilityLifeCycleAbility::GetLifecycleStateCaseOne() { + auto lifecycle = GetLifecycle(); + TestUtils::PublishEvent(APP_ABILITY_LIFE_CYCLE_RESP_EVENT_NAME, + lifecycle->GetLifecycleState(), + "TestLifeCycleGetLifecycleState"); +} + void AbilityLifeCycleAbility::TestLifeCycleGetLifecycleState() { switch ((CaseIndex)AbilityLifeCycleAbility::sequenceNumber_) { case CaseIndex::ONE: { - auto lifecycle = GetLifecycle(); - TestUtils::PublishEvent(APP_ABILITY_LIFE_CYCLE_RESP_EVENT_NAME, - lifecycle->GetLifecycleState(), - "TestLifeCycleGetLifecycleState"); + GetLifecycleStateCaseOne(); } break; case CaseIndex::TWO: { auto lifecycle = GetLifecycle(); diff --git a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/life_cycle_observer_ability.cpp b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/life_cycle_observer_ability.cpp index 4a61746250..a5559b0e1b 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/life_cycle_observer_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsKitSystemTestService/src/life_cycle_observer_ability.cpp @@ -21,7 +21,9 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; - +namespace { +constexpr int loopCnt = 100; +} void LifecycleObserverLifecycleObserver::DoTask() { switch ((CaseIndex)LifeCycleObserverAbility::sequenceNumber_) { @@ -491,7 +493,7 @@ void LifeCycleObserverAbility::TestLifeCycleGetLifecycle() TestUtils::PublishEvent(APP_LIFE_CYCLE_OBSERVER_RESP_EVENT_NAME, 1, "TestLifeCycleGetLifecycle"); } break; case CaseIndex::TWO: { - for (int i = 0; i < 100; i++) { + for (int i = 0; i < loopCnt; i++) { auto lifecycle = GetLifecycle(); } TestUtils::PublishEvent(APP_LIFE_CYCLE_OBSERVER_RESP_EVENT_NAME, 1, "TestLifeCycleGetLifecycle"); diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr2.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr2.cpp index 1d8adb99f2..75ee4caf38 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr2.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr2.cpp @@ -17,6 +17,9 @@ namespace OHOS { namespace AppExecFwk { +namespace { +constexpr uint32_t multiple = 100; +} void AmsStAbilityR2::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, const sptr &token) @@ -98,7 +101,7 @@ void AmsStAbilityR2::OnBackground() { APP_LOGI("AmsStAbilityR2::OnBackground"); Ability::OnBackground(); - std::this_thread::sleep_for(std::chrono::milliseconds(STEventName::BACKGROUND_TIMEOUT * 100)); + std::this_thread::sleep_for(std::chrono::milliseconds(STEventName::BACKGROUND_TIMEOUT * multiple)); std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnBackground; pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnBackgroundCount(), eventData); } diff --git a/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr3.cpp b/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr3.cpp index 32c656679b..f8c1476c1f 100644 --- a/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr3.cpp +++ b/test/resource/amssystemtestability/abilitySrc/amsSystemTestR/src/amsstabilityr3.cpp @@ -17,6 +17,9 @@ namespace OHOS { namespace AppExecFwk { +namespace { +constexpr uint32_t timeoutAdd = 5000; +} void AmsStAbilityR3::OnStart(const Want &want) { GetWantInfo(want); @@ -88,7 +91,7 @@ void AmsStAbilityR3::OnBackground() { APP_LOGI("AmsStAbilityR3::OnBackground"); Ability::OnBackground(); - std::this_thread::sleep_for(std::chrono::milliseconds(STEventName::TERMINATE_TIMEOUT + 5000)); + std::this_thread::sleep_for(std::chrono::milliseconds(STEventName::TERMINATE_TIMEOUT + timeoutAdd)); std::string eventData = GetAbilityName() + STEventName::g_abilityStateOnBackground; pageAbilityEvent.PublishEvent(STEventName::g_eventName, pageAbilityEvent.GetOnBackgroundCount(), eventData); } diff --git a/test/resource/amssystemtestability/abilitySrc/common/ability_append_test_info.h b/test/resource/amssystemtestability/abilitySrc/common/ability_append_test_info.h index 6d178531b3..939b33dde9 100644 --- a/test/resource/amssystemtestability/abilitySrc/common/ability_append_test_info.h +++ b/test/resource/amssystemtestability/abilitySrc/common/ability_append_test_info.h @@ -102,7 +102,6 @@ enum class TestAbilityState { OnRestoreAbilityState, End }; - } // namespace AppExecFwk } // namespace OHOS #endif // ABILITY_APPEND_TEST_INFO_H \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/common/kit_test_common_info.h b/test/resource/amssystemtestability/abilitySrc/common/kit_test_common_info.h index ab1dc4dc87..c6c6a41b6d 100644 --- a/test/resource/amssystemtestability/abilitySrc/common/kit_test_common_info.h +++ b/test/resource/amssystemtestability/abilitySrc/common/kit_test_common_info.h @@ -423,7 +423,6 @@ enum class WantParamsApi { SetParam, End, }; - } // namespace AppExecFwk } // namespace OHOS #endif // KIT_TEST_COMMON_INFO_H \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/include/verify_act_first_ability.h b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/include/verify_act_first_ability.h index 4f4926ec6e..c13a82e29e 100644 --- a/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/include/verify_act_first_ability.h +++ b/test/resource/amssystemtestability/abilitySrc/serviceAbilityA/include/verify_act_first_ability.h @@ -55,7 +55,6 @@ class AbilityContextStartAbilityTest : public EventFwk::CommonEventSubscriber { public: AbilityContextStartAbilityTest(const EventFwk::CommonEventSubscribeInfo &sp) : EventFwk::CommonEventSubscriber(sp){}; - virtual ~AbilityContextStartAbilityTest() = default; virtual void OnReceiveEvent(const EventFwk::CommonEventData &data); }; class ConnectServiceAbilityTest : public EventFwk::CommonEventSubscriber { @@ -67,7 +66,6 @@ public: abilityContext_ = abilityContext; conne_ = conne; }; - virtual ~ConnectServiceAbilityTest() = default; virtual void OnReceiveEvent(const EventFwk::CommonEventData &data) override; std::shared_ptr abilityContext_ = nullptr; diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/include/test_utils.h b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/include/test_utils.h index e32f3c5521..f0ffaa1953 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/include/test_utils.h +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/include/test_utils.h @@ -19,7 +19,6 @@ namespace OHOS { namespace AppExecFwk { - class TestUtils { public: TestUtils() = default; diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/main_ability.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/main_ability.cpp index cd1ad9aae0..af5f914a38 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/main_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/main_ability.cpp @@ -27,7 +27,7 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; using namespace OHOS::STtools; - +namespace { int terminated_task_num = 0; std::condition_variable cv; std::mutex cv_mutex; @@ -48,6 +48,11 @@ std::string innerDelimiter = "-"; std::string task_execution_sequence = delimiter; std::vector> allDispatchers; std::mutex dispatcher_mutex; +constexpr int numZero = 0; +constexpr int numOne = 1; +constexpr int numTwo = 2; +constexpr int numThree = 3; +} bool Wait(const int task_num) { @@ -360,14 +365,11 @@ void FirstEventSubscriber::OnReceiveEvent(const CommonEventData &data) auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo.size()=%{public}zu", caseInfo.size()); - if (caseInfo.size() < 3) { + if (caseInfo.size() < numThree) { return; } - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[0]=%{public}s", caseInfo[0].c_str()); - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[1]=%{public}s", caseInfo[1].c_str()); - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[2]=%{public}s", caseInfo[2].c_str()); - if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[numZero]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[numZero]](std::stoi(caseInfo[numOne]), std::stoi(caseInfo[numTwo]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } @@ -383,72 +385,41 @@ void MainAbility::TestDispatcher(int apiIndex, int caseIndex, int code) } } -int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) -{ - APP_LOGI("-- -- -- -- -- --MainAbility::Dispatch begin"); - std::string outerName = "outerDispatcher"; - std::string innerName = "innerDispatcher"; +void SetInnerTask(TaskList innerDispatcher, TestSetting innerSetting, std::string outerTaskId, int innerTaskSeq) { + std::string innerTaskId = outerTaskId + innerDelimiter + std::to_string(innerTaskSeq); + auto innerTask = std::make_shared([=]() { TestTask(innerTaskId); }); + innerDispatcher.addOperation(innerSetting.op); + if (innerSetting.op == TestOperation::APPLY && innerSetting.apply > 0) { + innerDispatcher.addApply(innerSetting.apply); + } + if (innerSetting.op == TestOperation::DELAY && innerSetting.delay > 0) { + innerDispatcher.addDelay(innerSetting.delay); + } + innerDispatcher.addFunc(innerTask); +} - std::string outerTaskId; - auto context = GetContext(); - TaskList outerDispatcher{outerSetting.dispatcher, context, outerName}; - if (outerSetting.create_group) { - outerDispatcher.addOperation(TestOperation::CREATE_GROUP); +void SetInnerTaskOther(TaskList innerDispatcher, TestSetting innerSetting, int outerTaskSeq) { + if (innerSetting.sync_barrier) { + std::string taskId = innerSyncBarrierId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); } - for (int i = 0; i < testTaskCount; i++) { - outerTaskId = std::to_string(i); - auto outerTask = std::make_shared([=]() { - auto context = this->GetContext(); - TaskList innerDispatcher{innerSetting.dispatcher, context, innerName + std::to_string(i)}; - if (innerSetting.create_group) { - innerDispatcher.addOperation(TestOperation::CREATE_GROUP); - } - for (int j = 0; j < testTaskCount; j++) { - std::string innerTaskId = outerTaskId + innerDelimiter + std::to_string(j); - auto innerTask = std::make_shared([=]() { TestTask(innerTaskId); }); - innerDispatcher.addOperation(innerSetting.op); - if (innerSetting.op == TestOperation::APPLY && innerSetting.apply > 0) { - innerDispatcher.addApply(innerSetting.apply); - } - if (innerSetting.op == TestOperation::DELAY && innerSetting.delay > 0) { - innerDispatcher.addDelay(innerSetting.delay); - } - innerDispatcher.addFunc(innerTask); - } - if (innerSetting.sync_barrier) { - std::string taskId = innerSyncBarrierId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); - } - if (innerSetting.async_barrier) { - std::string taskId = innerAsyncBarrierId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); - } - if (innerSetting.group_wait) { - innerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(innerSetting.group_timeout); - } - if (innerSetting.group_notify) { - std::string taskId = innerGroupNotifyId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); - } - innerDispatcher.executedTask(); - { - std::lock_guard lock(dispatcher_mutex); - allDispatchers.push_back(innerDispatcher.getDispatcher()); - } - TestTask(outerTaskId); - }); - outerDispatcher.addOperation(outerSetting.op); - if (outerSetting.op == TestOperation::APPLY && outerSetting.apply > 0) { - outerDispatcher.addApply(outerSetting.apply); - } - if (outerSetting.op == TestOperation::DELAY && outerSetting.delay > 0) { - outerDispatcher.addDelay(outerSetting.delay); - } - outerDispatcher.addFunc(outerTask); + if (innerSetting.async_barrier) { + std::string taskId = innerAsyncBarrierId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); } + if (innerSetting.group_wait) { + innerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(innerSetting.group_timeout); + } + if (innerSetting.group_notify) { + std::string taskId = innerGroupNotifyId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); + } +} + +void SetOuterTaskOther(TaskList outerDispatcher, TestSetting outerSetting) { if (outerSetting.sync_barrier) { auto task = std::make_shared([=]() { TestTask(outerSyncBarrierId); }); outerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); @@ -464,11 +435,9 @@ int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) auto task = std::make_shared([=]() { TestTask(outerGroupNotifyId); }); outerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); } - outerDispatcher.executedTask(); - { - std::lock_guard lock(dispatcher_mutex); - allDispatchers.push_back(outerDispatcher.getDispatcher()); - } +} + +int CountTask(TestSetting outerSetting, TestSetting innerSetting) { int taskCount = 0; taskCount = (innerSetting.op == TestOperation::APPLY) ? (innerSetting.apply * testTaskCount) : testTaskCount; if (innerSetting.sync_barrier) { @@ -492,7 +461,54 @@ int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) if (outerSetting.group_notify) { taskCount++; } - APP_LOGI("-- -- -- -- -- --MainAbility::Dispatch end taskCount:%{public}d", taskCount); + return taskCount; +} + +int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) +{ + std::string outerName = "outerDispatcher"; + std::string innerName = "innerDispatcher"; + std::string outerTaskId; + auto context = GetContext(); + TaskList outerDispatcher {outerSetting.dispatcher, context, outerName}; + if (outerSetting.create_group) { + outerDispatcher.addOperation(TestOperation::CREATE_GROUP); + } + for (int i = 0; i < testTaskCount; i++) { + outerTaskId = std::to_string(i); + auto outerTask = std::make_shared([=]() { + auto context = this->GetContext(); + TaskList innerDispatcher {innerSetting.dispatcher, context, innerName + std::to_string(i)}; + if (innerSetting.create_group) { + innerDispatcher.addOperation(TestOperation::CREATE_GROUP); + } + for (int j = 0; j < testTaskCount; j++) { + SetInnerTask(innerDispatcher, innerSetting, outerTaskId, j); + } + SetInnerTaskOther(innerDispatcher, innerSetting, i); + innerDispatcher.executedTask(); + { + std::lock_guard lock(dispatcher_mutex); + allDispatchers.push_back(innerDispatcher.getDispatcher()); + } + TestTask(outerTaskId); + }); + outerDispatcher.addOperation(outerSetting.op); + if (outerSetting.op == TestOperation::APPLY && outerSetting.apply > 0) { + outerDispatcher.addApply(outerSetting.apply); + } + if (outerSetting.op == TestOperation::DELAY && outerSetting.delay > 0) { + outerDispatcher.addDelay(outerSetting.delay); + } + outerDispatcher.addFunc(outerTask); + } + SetOuterTaskOther(outerDispatcher, outerSetting); + outerDispatcher.executedTask(); + { + std::lock_guard lock(dispatcher_mutex); + allDispatchers.push_back(outerDispatcher.getDispatcher()); + } + int taskCount = CountTask(outerSetting, innerSetting); return taskCount; } @@ -1820,7 +1836,6 @@ void MainAbility::GlobalCase50(int code) // level1:global, group level2:serial, delay void MainAbility::GlobalCase51(int code) { - APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); TestSetting outerSetting; @@ -8973,7 +8988,7 @@ void MainAbility::HybridCase1(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; std::vector operationList = { TestOperation::SYNC, TestOperation::ASYNC, @@ -9003,7 +9018,7 @@ void MainAbility::HybridCase2(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::PARALLEL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::PARALLEL, context, "parallel"}; std::vector operationList = { TestOperation::SYNC, TestOperation::ASYNC, @@ -9037,7 +9052,7 @@ void MainAbility::HybridCase3(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList serialDispatcher = TaskList{TestDispatcher::SERIAL, context, "serial"}; + TaskList serialDispatcher = TaskList {TestDispatcher::SERIAL, context, "serial"}; std::vector operationList = { TestOperation::SYNC, TestOperation::ASYNC, @@ -9064,7 +9079,7 @@ void MainAbility::HybridCase4(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; std::vector operationList = { TestOperation::SYNC, TestOperation::ASYNC, @@ -9091,12 +9106,12 @@ void MainAbility::HybridCase5(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; globalDispatcher.addOperation(TestOperation::SYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) @@ -9137,12 +9152,12 @@ void MainAbility::HybridCase6(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; globalDispatcher.addOperation(TestOperation::ASYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) @@ -9183,12 +9198,12 @@ void MainAbility::HybridCase7(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; const long delay = 10; globalDispatcher.addOperation(TestOperation::DELAY) @@ -9236,12 +9251,12 @@ void MainAbility::HybridCase8(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; globalDispatcher.addOperation(TestOperation::CREATE_GROUP) .addOperation(TestOperation::ASYNC_GROUP) @@ -9285,12 +9300,12 @@ void MainAbility::HybridCase9(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; globalDispatcher.addOperation(TestOperation::CREATE_GROUP) .addOperation(TestOperation::ASYNC_GROUP) @@ -9334,12 +9349,12 @@ void MainAbility::HybridCase10(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; const long delay = 10; globalDispatcher.addOperation(TestOperation::CREATE_GROUP) @@ -9387,12 +9402,12 @@ void MainAbility::HybridCase11(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; globalDispatcher.addOperation(TestOperation::CREATE_GROUP) .addOperation(TestOperation::ASYNC_GROUP) @@ -9400,21 +9415,21 @@ void MainAbility::HybridCase11(int code) .addOperation(TestOperation::GROUP_NOTIFY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); - taskId += 2; + taskId += numTwo; parallelDispatcher1.addOperation(TestOperation::CREATE_GROUP) .addOperation(TestOperation::ASYNC_GROUP) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .addOperation(TestOperation::GROUP_NOTIFY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); - taskId += 2; + taskId += numTwo; parallelDispatcher2.addOperation(TestOperation::CREATE_GROUP) .addOperation(TestOperation::ASYNC_GROUP) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .addOperation(TestOperation::GROUP_NOTIFY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); - taskId += 2; + taskId += numTwo; serialDispatcher1.addOperation(TestOperation::ASYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -9442,12 +9457,12 @@ void MainAbility::HybridCase12(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9502,12 +9517,12 @@ void MainAbility::HybridCase13(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 1; @@ -9559,12 +9574,12 @@ void MainAbility::HybridCase14(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9618,12 +9633,12 @@ void MainAbility::HybridCase15(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9635,7 +9650,7 @@ void MainAbility::HybridCase15(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; parallelDispatcher1.addOperation(TestOperation::SYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -9679,12 +9694,12 @@ void MainAbility::HybridCase16(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9707,7 +9722,7 @@ void MainAbility::HybridCase16(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; serialDispatcher1.addOperation(TestOperation::ASYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -9740,12 +9755,12 @@ void MainAbility::HybridCase17(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9795,12 +9810,12 @@ void MainAbility::HybridCase18(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9852,12 +9867,12 @@ void MainAbility::HybridCase19(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9910,12 +9925,12 @@ void MainAbility::HybridCase20(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9938,7 +9953,7 @@ void MainAbility::HybridCase20(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; serialDispatcher1.addOperation(TestOperation::DELAY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .addDelay(delay) @@ -9971,12 +9986,12 @@ void MainAbility::HybridCase21(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -9988,7 +10003,7 @@ void MainAbility::HybridCase21(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; parallelDispatcher1.addOperation(TestOperation::ASYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -10031,12 +10046,12 @@ void MainAbility::HybridCase22(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -10091,12 +10106,12 @@ void MainAbility::HybridCase23(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -10120,7 +10135,7 @@ void MainAbility::HybridCase23(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; serialDispatcher1.addOperation(TestOperation::APPLY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -10153,12 +10168,12 @@ void MainAbility::HybridCase24(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const long apply = 2; @@ -10169,8 +10184,8 @@ void MainAbility::HybridCase24(int code) .addOperation(TestOperation::GROUP_NOTIFY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); - taskId += 2; - taskCount += 2; + taskId += numTwo; + taskCount += numTwo; parallelDispatcher1.addOperation(TestOperation::DELAY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .addDelay(delay) @@ -10219,12 +10234,12 @@ void MainAbility::HybridCase25(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; globalDispatcher.addOperation(TestOperation::ASYNC) @@ -10245,7 +10260,7 @@ void MainAbility::HybridCase25(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; serialDispatcher1.addOperation(TestOperation::ASYNC) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .executedTask(); @@ -10276,12 +10291,12 @@ void MainAbility::HybridCase26(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -10332,12 +10347,12 @@ void MainAbility::HybridCase27(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; - TaskList parallelDispatcher1 = TaskList{TestDispatcher::PARALLEL, context, "parallel1"}; - TaskList parallelDispatcher2 = TaskList{TestDispatcher::PARALLEL, context, "parallel2"}; - TaskList serialDispatcher1 = TaskList{TestDispatcher::SERIAL, context, "serial1"}; - TaskList serialDispatcher2 = TaskList{TestDispatcher::SERIAL, context, "serial2"}; - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; + TaskList parallelDispatcher1 = TaskList {TestDispatcher::PARALLEL, context, "parallel1"}; + TaskList parallelDispatcher2 = TaskList {TestDispatcher::PARALLEL, context, "parallel2"}; + TaskList serialDispatcher1 = TaskList {TestDispatcher::SERIAL, context, "serial1"}; + TaskList serialDispatcher2 = TaskList {TestDispatcher::SERIAL, context, "serial2"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; int taskId = 0; int taskCount = 0; const int apply = 2; @@ -10354,7 +10369,7 @@ void MainAbility::HybridCase27(int code) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId + 1)); })) .executedTask(); taskId++; - taskCount += 2; + taskCount += numTwo; parallelDispatcher2.addOperation(TestOperation::APPLY) .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) .addApply(apply) @@ -10395,7 +10410,7 @@ void MainAbility::MultiAppCase1(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -10427,7 +10442,7 @@ void MainAbility::MultiAppCase2(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::PARALLEL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::PARALLEL, context, "parallel"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -10459,7 +10474,7 @@ void MainAbility::MultiAppCase3(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList serialDispatcher = TaskList{TestDispatcher::SERIAL, context, "serial"}; + TaskList serialDispatcher = TaskList {TestDispatcher::SERIAL, context, "serial"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -10491,7 +10506,7 @@ void MainAbility::MultiAppCase4(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList mainDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList mainDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -10524,17 +10539,17 @@ void MainAbility::ExtraCase1(int code) Reset(); auto context = GetContext(); int taskId = 0; - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; bool result = globalDispatcher.addOperation(TestOperation::SYNC) - .addFunc(std::make_shared([=]() { - std::string targetBundleName = "com.ohos.TaskDispatcherA"; - std::string targetAbility = "SecondAbility"; - Want want; - want.SetElementName(targetBundleName, targetAbility); - StartAbility(want); - TestTask(std::to_string(taskId)); - })) - .executedTask(); + .addFunc(std::make_shared([=]() { + std::string targetBundleName = "com.ohos.TaskDispatcherA"; + std::string targetAbility = "SecondAbility"; + Want want; + want.SetElementName(targetBundleName, targetAbility); + StartAbility(want); + TestTask(std::to_string(taskId)); + })) + .executedTask(); taskId++; Wait(taskId); result = task_execution_sequence.size() > 1; @@ -10547,7 +10562,7 @@ void MainAbility::FillInDispathcer() const int fullThreadNum = 32; const int waitTime = 2; auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::PARALLEL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::PARALLEL, context, "parallel"}; parallelDispatcher.setTaskPriority(AppExecFwk::TaskPriority::HIGH); parallelDispatcher.addOperation(TestOperation::ASYNC).addFunc(std::make_shared([=]() { sleep(waitTime - 1); @@ -10565,9 +10580,9 @@ void MainAbility::PriorityCase1(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList globalDispatcherLow = TaskList{TestDispatcher::GLOBAL, context, "globalLow"}; - TaskList globalDispatcherDefault = TaskList{TestDispatcher::GLOBAL, context, "globalDefault"}; - TaskList globalDispatcherHigh = TaskList{TestDispatcher::GLOBAL, context, "globalHigh"}; + TaskList globalDispatcherLow = TaskList {TestDispatcher::GLOBAL, context, "globalLow"}; + TaskList globalDispatcherDefault = TaskList {TestDispatcher::GLOBAL, context, "globalDefault"}; + TaskList globalDispatcherHigh = TaskList {TestDispatcher::GLOBAL, context, "globalHigh"}; int taskId = 0; globalDispatcherLow.setTaskPriority(AppExecFwk::TaskPriority::LOW) .addOperation(TestOperation::ASYNC) @@ -10592,7 +10607,7 @@ void MainAbility::PriorityCase1(int code) for (auto index : outerTaskIndex) { result = result && (index != std::string::npos); } - result = result && (outerTaskIndex[0] > outerTaskIndex[1]) && (outerTaskIndex[1] > outerTaskIndex[2]); + result = result && (outerTaskIndex[numZero] > outerTaskIndex[numOne]) && (outerTaskIndex[numOne] > outerTaskIndex[numTwo]); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } void MainAbility::PriorityCase2(int code) @@ -10601,9 +10616,9 @@ void MainAbility::PriorityCase2(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList parallelDispatcherLow = TaskList{TestDispatcher::PARALLEL, context, "parallelLow"}; - TaskList parallelDispatcherDefault = TaskList{TestDispatcher::PARALLEL, context, "parallelDefault"}; - TaskList parallelDispatcherHigh = TaskList{TestDispatcher::PARALLEL, context, "parallelHigh"}; + TaskList parallelDispatcherLow = TaskList {TestDispatcher::PARALLEL, context, "parallelLow"}; + TaskList parallelDispatcherDefault = TaskList {TestDispatcher::PARALLEL, context, "parallelDefault"}; + TaskList parallelDispatcherHigh = TaskList {TestDispatcher::PARALLEL, context, "parallelHigh"}; int taskId = 0; parallelDispatcherLow.setTaskPriority(AppExecFwk::TaskPriority::LOW) .addOperation(TestOperation::ASYNC) @@ -10628,7 +10643,7 @@ void MainAbility::PriorityCase2(int code) for (auto index : outerTaskIndex) { result = result && (index != std::string::npos); } - result = result && (outerTaskIndex[0] > outerTaskIndex[1]) && (outerTaskIndex[1] > outerTaskIndex[2]); + result = result && (outerTaskIndex[numZero] > outerTaskIndex[numOne]) && (outerTaskIndex[numOne] > outerTaskIndex[numTwo]); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } void MainAbility::PriorityCase3(int code) @@ -10637,9 +10652,9 @@ void MainAbility::PriorityCase3(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList serialDispatcherLow = TaskList{TestDispatcher::SERIAL, context, "serialLow"}; - TaskList serialDispatcherDefault = TaskList{TestDispatcher::SERIAL, context, "serialDefault"}; - TaskList serialDispatcherHigh = TaskList{TestDispatcher::SERIAL, context, "serialHigh"}; + TaskList serialDispatcherLow = TaskList {TestDispatcher::SERIAL, context, "serialLow"}; + TaskList serialDispatcherDefault = TaskList {TestDispatcher::SERIAL, context, "serialDefault"}; + TaskList serialDispatcherHigh = TaskList {TestDispatcher::SERIAL, context, "serialHigh"}; int taskId = 0; serialDispatcherLow.setTaskPriority(AppExecFwk::TaskPriority::LOW) .addOperation(TestOperation::ASYNC) @@ -10664,7 +10679,7 @@ void MainAbility::PriorityCase3(int code) for (auto index : outerTaskIndex) { result = result && (index != std::string::npos); } - result = result && (outerTaskIndex[0] > outerTaskIndex[1]) && (outerTaskIndex[1] > outerTaskIndex[2]); + result = result && (outerTaskIndex[numZero] > outerTaskIndex[numOne]) && (outerTaskIndex[numOne] > outerTaskIndex[numTwo]); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } void MainAbility::PriorityCase4(int code) @@ -10673,9 +10688,9 @@ void MainAbility::PriorityCase4(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList parallelDispatcherLow = TaskList{TestDispatcher::PARALLEL, context, "parallelLow"}; - TaskList parallelDispatcherDefault = TaskList{TestDispatcher::PARALLEL, context, "parallelDefault"}; - TaskList mainDispatcherHigh = TaskList{TestDispatcher::MAIN, context, "mainHigh"}; + TaskList parallelDispatcherLow = TaskList {TestDispatcher::PARALLEL, context, "parallelLow"}; + TaskList parallelDispatcherDefault = TaskList {TestDispatcher::PARALLEL, context, "parallelDefault"}; + TaskList mainDispatcherHigh = TaskList {TestDispatcher::MAIN, context, "mainHigh"}; int taskId = 0; parallelDispatcherLow.setTaskPriority(AppExecFwk::TaskPriority::LOW) .addOperation(TestOperation::ASYNC) @@ -10699,7 +10714,7 @@ void MainAbility::PriorityCase4(int code) for (auto index : outerTaskIndex) { result = result && (index != std::string::npos); } - result = result && (outerTaskIndex[0] > outerTaskIndex[1]) && (outerTaskIndex[1] > outerTaskIndex[2]); + result = result && (outerTaskIndex[numZero] > outerTaskIndex[numOne]) && (outerTaskIndex[numOne] > outerTaskIndex[numTwo]); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } void MainAbility::PriorityCase5(int code) @@ -10708,9 +10723,9 @@ void MainAbility::PriorityCase5(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList globalDispatcherLow = TaskList{TestDispatcher::GLOBAL, context, "globallLow"}; - TaskList parallelDispatcherDefault = TaskList{TestDispatcher::PARALLEL, context, "parallelDefault"}; - TaskList globalDispatcherHigh = TaskList{TestDispatcher::GLOBAL, context, "globalHigh"}; + TaskList globalDispatcherLow = TaskList {TestDispatcher::GLOBAL, context, "globallLow"}; + TaskList parallelDispatcherDefault = TaskList {TestDispatcher::PARALLEL, context, "parallelDefault"}; + TaskList globalDispatcherHigh = TaskList {TestDispatcher::GLOBAL, context, "globalHigh"}; int taskId = 0; globalDispatcherLow.setTaskPriority(AppExecFwk::TaskPriority::LOW) .addOperation(TestOperation::ASYNC) @@ -10735,7 +10750,7 @@ void MainAbility::PriorityCase5(int code) for (auto index : outerTaskIndex) { result = result && (index != std::string::npos); } - result = result && (outerTaskIndex[0] > outerTaskIndex[1]) && (outerTaskIndex[1] > outerTaskIndex[2]); + result = result && (outerTaskIndex[numZero] > outerTaskIndex[numOne]) && (outerTaskIndex[numOne] > outerTaskIndex[numTwo]); TestUtils::PublishEvent(g_EVENT_RESP_FIRST, code, std::to_string(result)); } void MainAbility::RevokeCase1(int code) @@ -10744,13 +10759,13 @@ void MainAbility::RevokeCase1(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::ASYNC) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .addOperation(TestOperation::REVOCABLE) - .addRevokeTask(1) - .executedTask(); + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .addOperation(TestOperation::REVOCABLE) + .addRevokeTask(1) + .executedTask(); taskId++; result = !result || Wait(taskId); result = result || task_execution_sequence.size() > 1; @@ -10762,11 +10777,11 @@ void MainAbility::RevokeCase2(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::ASYNC) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .executedTask(); + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .executedTask(); taskId++; result = result && Wait(taskId); result = result && !parallelDispatcher.addOperation(TestOperation::REVOCABLE).addRevokeTask(1).executedTask(); @@ -10779,14 +10794,14 @@ void MainAbility::RevokeCase3(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::DELAY) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .addDelay(delayMs) - .addOperation(TestOperation::REVOCABLE) - .addRevokeTask(1) - .executedTask(); + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .addDelay(delayMs) + .addOperation(TestOperation::REVOCABLE) + .addRevokeTask(1) + .executedTask(); taskId++; result = !result || Wait(taskId); result = result || task_execution_sequence.size() > 1; @@ -10798,12 +10813,12 @@ void MainAbility::RevokeCase4(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::DELAY) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .addDelay(delayMs) - .executedTask(); + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .addDelay(delayMs) + .executedTask(); taskId++; result = result && Wait(taskId); result = result && !parallelDispatcher.addOperation(TestOperation::REVOCABLE).addRevokeTask(1).executedTask(); @@ -10817,14 +10832,14 @@ void MainAbility::RevokeCase5(int code) FillInDispathcer(); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::CREATE_GROUP) - .addOperation(TestOperation::ASYNC_GROUP) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .addOperation(TestOperation::REVOCABLE) - .addRevokeTask(1) - .executedTask(); + .addOperation(TestOperation::ASYNC_GROUP) + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .addOperation(TestOperation::REVOCABLE) + .addRevokeTask(1) + .executedTask(); taskId++; result = !result || Wait(taskId); result = result || task_execution_sequence.size() > 1; @@ -10836,12 +10851,12 @@ void MainAbility::RevokeCase6(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList parallelDispatcher = TaskList{TestDispatcher::GLOBAL, context, "parallel"}; + TaskList parallelDispatcher = TaskList {TestDispatcher::GLOBAL, context, "parallel"}; int taskId = 0; bool result = parallelDispatcher.addOperation(TestOperation::CREATE_GROUP) - .addOperation(TestOperation::ASYNC_GROUP) - .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) - .executedTask(); + .addOperation(TestOperation::ASYNC_GROUP) + .addFunc(std::make_shared([=]() { TestTask(std::to_string(taskId)); })) + .executedTask(); taskId++; result = result && Wait(taskId); result = result && !parallelDispatcher.addOperation(TestOperation::REVOCABLE).addRevokeTask(1).executedTask(); diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/second_ability.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/second_ability.cpp index 74b750fe7f..57b1eff8c0 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/second_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/second_ability.cpp @@ -20,6 +20,14 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; +namespace +{ +constexpr int numZero = 0; +constexpr int numOne = 1; +constexpr int numTwo = 2; +constexpr int numThree = 3; +} // namespace + void SecondAbility::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, @@ -109,11 +117,11 @@ void SecondEventSubscriber::OnReceiveEvent(const CommonEventData &data) if (std::strcmp(eventName.c_str(), g_EVENT_REQU_SECOND.c_str()) == 0) { auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); - if (caseInfo.size() < 3) { + if (caseInfo.size() < numThree) { return; } - if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[numZero]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[numZero]](std::stoi(caseInfo[numOne]), std::stoi(caseInfo[numTwo]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/test_utils.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/test_utils.cpp index 07ebf00c47..3e75bdf815 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/test_utils.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestA/src/test_utils.cpp @@ -47,9 +47,10 @@ Want TestUtils::MakeWant( std::vector TestUtils::split(const std::string &in, const std::string &delim) { - std::regex reg{delim}; - return std::vector{ - std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator()}; + std::regex reg {delim}; + return std::vector { + std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator() + }; } } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/include/test_utils.h b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/include/test_utils.h index e32f3c5521..f0ffaa1953 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/include/test_utils.h +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/include/test_utils.h @@ -19,7 +19,6 @@ namespace OHOS { namespace AppExecFwk { - class TestUtils { public: TestUtils() = default; diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/main_ability.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/main_ability.cpp index e80ab723aa..5d6ca20816 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/main_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/main_ability.cpp @@ -25,7 +25,7 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; using namespace OHOS::STtools; - +namespace { int terminated_task_num = 0; std::condition_variable cv; std::mutex cv_mutex; @@ -38,17 +38,28 @@ std::string outerSyncBarrierId = "outerSyncBarrierId"; std::string outerAsyncBarrierId = "outerAsyncBarrierId"; std::string outerGroupWaitId = "outerGroupWaitId"; std::string outerGroupNotifyId = "outerGroupNotifyId"; - std::string delimiter = "_"; std::string innerDelimiter = "-"; std::string task_execution_sequence = delimiter; +std::vector> allDispatchers; +std::mutex dispatcher_mutex; +constexpr int numZero = 0; +constexpr int numOne = 1; +constexpr int numTwo = 2; +constexpr int numThree = 3; +} bool Wait(const int task_num) { APP_LOGI("-- -- -- -- -- --MainAbility::Wait"); std::unique_lock ulock(cv_mutex); using namespace std::chrono_literals; - return cv.wait_for(ulock, 5000ms, [task_num] { return terminated_task_num == task_num; }); + bool result = cv.wait_for(ulock, 5000ms, [task_num] { return terminated_task_num == task_num; }); + if (result) { + allDispatchers.clear(); + } + APP_LOGI("-- -- -- -- -- --MainAbility::Wait result:%{public}d", result); + return result; } void TestTask(const std::string &task_id) @@ -68,6 +79,7 @@ void Reset() APP_LOGI("-- -- -- -- -- --MainAbility::Reset"); terminated_task_num = 0; task_execution_sequence = delimiter; + allDispatchers.clear(); } bool IsAscend(const std::vector &vec) @@ -268,14 +280,11 @@ void FirstEventSubscriber::OnReceiveEvent(const CommonEventData &data) auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo.size()=%{public}zu", caseInfo.size()); - if (caseInfo.size() < 3) { + if (caseInfo.size() < numThree) { return; } - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[0]=%{public}s", caseInfo[0].c_str()); - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[1]=%{public}s", caseInfo[1].c_str()); - APP_LOGI("FirstEventSubscriber::OnReceiveEvent:caseInfo[2]=%{public}s", caseInfo[2].c_str()); - if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[numZero]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[numZero]](std::stoi(caseInfo[numOne]), std::stoi(caseInfo[numTwo]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } @@ -291,15 +300,92 @@ void MainAbility::TestDispatcher(int apiIndex, int caseIndex, int code) } } +void SetInnerTask(TaskList innerDispatcher, TestSetting innerSetting, std::string outerTaskId, int innerTaskSeq) { + std::string innerTaskId = outerTaskId + innerDelimiter + std::to_string(innerTaskSeq); + auto innerTask = std::make_shared([=]() { TestTask(innerTaskId); }); + innerDispatcher.addOperation(innerSetting.op); + if (innerSetting.op == TestOperation::APPLY && innerSetting.apply > 0) { + innerDispatcher.addApply(innerSetting.apply); + } + if (innerSetting.op == TestOperation::DELAY && innerSetting.delay > 0) { + innerDispatcher.addDelay(innerSetting.delay); + } + innerDispatcher.addFunc(innerTask); +} + +void SetInnerTaskOther(TaskList innerDispatcher, TestSetting innerSetting, int outerTaskSeq) { + if (innerSetting.sync_barrier) { + std::string taskId = innerSyncBarrierId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); + } + if (innerSetting.async_barrier) { + std::string taskId = innerAsyncBarrierId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); + } + if (innerSetting.group_wait) { + innerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(innerSetting.group_timeout); + } + if (innerSetting.group_notify) { + std::string taskId = innerGroupNotifyId + std::to_string(outerTaskSeq); + auto task = std::make_shared([=]() { TestTask(taskId); }); + innerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); + } +} + +void SetOuterTaskOther(TaskList outerDispatcher, TestSetting outerSetting) { + if (outerSetting.sync_barrier) { + auto task = std::make_shared([=]() { TestTask(outerSyncBarrierId); }); + outerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); + } + if (outerSetting.async_barrier) { + auto task = std::make_shared([=]() { TestTask(outerAsyncBarrierId); }); + outerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); + } + if (outerSetting.group_wait) { + outerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(outerSetting.group_timeout); + } + if (outerSetting.group_notify) { + auto task = std::make_shared([=]() { TestTask(outerGroupNotifyId); }); + outerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); + } +} + +int CountTask(TestSetting outerSetting, TestSetting innerSetting) { + int taskCount = 0; + taskCount = (innerSetting.op == TestOperation::APPLY) ? (innerSetting.apply * testTaskCount) : testTaskCount; + if (innerSetting.sync_barrier) { + taskCount++; + } + if (innerSetting.async_barrier) { + taskCount++; + } + if (innerSetting.group_notify) { + taskCount++; + } + taskCount = (outerSetting.op == TestOperation::APPLY) + ? (outerSetting.apply * testTaskCount + outerSetting.apply * testTaskCount * taskCount) + : (testTaskCount + testTaskCount * taskCount); + if (outerSetting.sync_barrier) { + taskCount++; + } + if (outerSetting.async_barrier) { + taskCount++; + } + if (outerSetting.group_notify) { + taskCount++; + } + return taskCount; +} + int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) { - APP_LOGI("-- -- -- -- -- --MainAbility::Dispatch begin"); std::string outerName = "outerDispatcher"; std::string innerName = "innerDispatcher"; - std::string outerTaskId; auto context = GetContext(); - TaskList outerDispatcher{outerSetting.dispatcher, context, outerName}; + TaskList outerDispatcher {outerSetting.dispatcher, context, outerName}; if (outerSetting.create_group) { outerDispatcher.addOperation(TestOperation::CREATE_GROUP); } @@ -307,41 +393,19 @@ int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) outerTaskId = std::to_string(i); auto outerTask = std::make_shared([=]() { auto context = this->GetContext(); - TaskList innerDispatcher{innerSetting.dispatcher, context, innerName + std::to_string(i)}; + TaskList innerDispatcher {innerSetting.dispatcher, context, innerName + std::to_string(i)}; if (innerSetting.create_group) { innerDispatcher.addOperation(TestOperation::CREATE_GROUP); } for (int j = 0; j < testTaskCount; j++) { - std::string innerTaskId = outerTaskId + innerDelimiter + std::to_string(j); - auto innerTask = std::make_shared([=]() { TestTask(innerTaskId); }); - innerDispatcher.addOperation(innerSetting.op); - if (innerSetting.op == TestOperation::APPLY && innerSetting.apply > 0) { - innerDispatcher.addApply(innerSetting.apply); - } - if (innerSetting.op == TestOperation::DELAY && innerSetting.delay > 0) { - innerDispatcher.addDelay(innerSetting.delay); - } - innerDispatcher.addFunc(innerTask); - } - if (innerSetting.sync_barrier) { - std::string taskId = innerSyncBarrierId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); - } - if (innerSetting.async_barrier) { - std::string taskId = innerAsyncBarrierId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); - } - if (innerSetting.group_wait) { - innerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(innerSetting.group_timeout); - } - if (innerSetting.group_notify) { - std::string taskId = innerGroupNotifyId + std::to_string(i); - auto task = std::make_shared([=]() { TestTask(taskId); }); - innerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); + SetInnerTask(innerDispatcher, innerSetting, outerTaskId, j); } + SetInnerTaskOther(innerDispatcher, innerSetting, i); innerDispatcher.executedTask(); + { + std::lock_guard lock(dispatcher_mutex); + allDispatchers.push_back(innerDispatcher.getDispatcher()); + } TestTask(outerTaskId); }); outerDispatcher.addOperation(outerSetting.op); @@ -353,29 +417,13 @@ int MainAbility::Dispatch(TestSetting outerSetting, TestSetting innerSetting) } outerDispatcher.addFunc(outerTask); } - if (outerSetting.sync_barrier) { - auto task = std::make_shared([=]() { TestTask(outerSyncBarrierId); }); - outerDispatcher.addOperation(TestOperation::SYNC_BARRIER).addFunc(task); - } - if (outerSetting.async_barrier) { - auto task = std::make_shared([=]() { TestTask(outerAsyncBarrierId); }); - outerDispatcher.addOperation(TestOperation::ASYNC_BARRIER).addFunc(task); - } - if (outerSetting.group_wait) { - outerDispatcher.addOperation(TestOperation::GROUP_WAIT).addWaitTime(outerSetting.group_timeout); - } - if (outerSetting.group_notify) { - auto task = std::make_shared([=]() { TestTask(outerGroupNotifyId); }); - outerDispatcher.addOperation(TestOperation::GROUP_NOTIFY).addFunc(task); - } + SetOuterTaskOther(outerDispatcher, outerSetting); outerDispatcher.executedTask(); - int taskCount = 0; - taskCount = (innerSetting.op == TestOperation::APPLY) ? (innerSetting.apply * testTaskCount) : testTaskCount; - taskCount = (outerSetting.op == TestOperation::APPLY) - ? (innerSetting.apply * testTaskCount + innerSetting.apply * testTaskCount * taskCount) - : (testTaskCount + testTaskCount * taskCount); - - APP_LOGI("-- -- -- -- -- --MainAbility::Dispatch end"); + { + std::lock_guard lock(dispatcher_mutex); + allDispatchers.push_back(outerDispatcher.getDispatcher()); + } + int taskCount = CountTask(outerSetting, innerSetting); return taskCount; } @@ -403,7 +451,7 @@ void MainAbility::MultiAppCase1(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::GLOBAL, context, "global"}; + TaskList globalDispatcher = TaskList {TestDispatcher::GLOBAL, context, "global"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -435,7 +483,7 @@ void MainAbility::MultiAppCase2(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::PARALLEL, context, "parallel"}; + TaskList globalDispatcher = TaskList {TestDispatcher::PARALLEL, context, "parallel"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -467,7 +515,7 @@ void MainAbility::MultiAppCase3(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::SERIAL, context, "serial"}; + TaskList globalDispatcher = TaskList {TestDispatcher::SERIAL, context, "serial"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, @@ -499,7 +547,7 @@ void MainAbility::MultiAppCase4(int code) APP_LOGI("-- -- -- -- -- --MainAbility::%{public}s", __FUNCTION__); Reset(); auto context = GetContext(); - TaskList globalDispatcher = TaskList{TestDispatcher::MAIN, context, "main"}; + TaskList globalDispatcher = TaskList {TestDispatcher::MAIN, context, "main"}; std::vector operationList = { TestOperation::ASYNC, TestOperation::ASYNC, diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/second_ability.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/second_ability.cpp index 67a8ed8c7c..9c770b1249 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/second_ability.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/second_ability.cpp @@ -20,6 +20,12 @@ namespace OHOS { namespace AppExecFwk { using namespace OHOS::EventFwk; +namespace { +constexpr int numZero = 0; +constexpr int numOne = 1; +constexpr int numTwo = 2; +constexpr int numThree = 3; +} void SecondAbility::Init(const std::shared_ptr &abilityInfo, const std::shared_ptr &application, std::shared_ptr &handler, @@ -103,11 +109,11 @@ void SecondEventSubscriber::OnReceiveEvent(const CommonEventData &data) if (std::strcmp(eventName.c_str(), g_EVENT_REQU_SECOND_B.c_str()) == 0) { auto target = data.GetData(); auto caseInfo = TestUtils::split(target, "_"); - if (caseInfo.size() < 3) { + if (caseInfo.size() < numThree) { return; } - if (mapTestFunc_.find(caseInfo[0]) != mapTestFunc_.end()) { - mapTestFunc_[caseInfo[0]](std::stoi(caseInfo[1]), std::stoi(caseInfo[2]), data.GetCode()); + if (mapTestFunc_.find(caseInfo[numZero]) != mapTestFunc_.end()) { + mapTestFunc_[caseInfo[numZero]](std::stoi(caseInfo[numOne]), std::stoi(caseInfo[numTwo]), data.GetCode()); } else { APP_LOGI("OnReceiveEvent: CommonEventData error(%{public}s)", target.c_str()); } diff --git a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/test_utils.cpp b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/test_utils.cpp index 07ebf00c47..3e75bdf815 100644 --- a/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/test_utils.cpp +++ b/test/resource/amssystemtestability/abilitySrc/taskDispatcherTestB/src/test_utils.cpp @@ -47,9 +47,10 @@ Want TestUtils::MakeWant( std::vector TestUtils::split(const std::string &in, const std::string &delim) { - std::regex reg{delim}; - return std::vector{ - std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator()}; + std::regex reg {delim}; + return std::vector { + std::sregex_token_iterator(in.begin(), in.end(), reg, -1), std::sregex_token_iterator() + }; } } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/tools/include/event.h b/test/resource/amssystemtestability/abilitySrc/tools/include/event.h index 00ced74199..4e659a7bd7 100644 --- a/test/resource/amssystemtestability/abilitySrc/tools/include/event.h +++ b/test/resource/amssystemtestability/abilitySrc/tools/include/event.h @@ -18,7 +18,6 @@ #include namespace STtools { - class Event { public: Event(); @@ -38,5 +37,4 @@ private: int WaitCompleted(Event &event, const std::string &eventName, const int code, const int timeout = 60); void Completed(Event &event, const std::string &eventName, const int code); void CleanMsg(Event &event); - } // namespace STtools \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/tools/include/stoperator.h b/test/resource/amssystemtestability/abilitySrc/tools/include/stoperator.h index c0683c1ae4..f7a8f367f0 100644 --- a/test/resource/amssystemtestability/abilitySrc/tools/include/stoperator.h +++ b/test/resource/amssystemtestability/abilitySrc/tools/include/stoperator.h @@ -20,11 +20,8 @@ namespace STtools { using std::string; class StOperator; - std::vector SerializationStOperatorToVector(StOperator &ParentOperator); - void DeserializationStOperatorFromVector(StOperator &ParentOperator, std::vector &vectorOperator); - class StOperator { private: std::vector> g_childOperator; @@ -57,5 +54,4 @@ public: std::vector> GetChildOperator(); std::vector> PopChildOperator(); }; - } // namespace STtools diff --git a/test/resource/amssystemtestability/abilitySrc/tools/include/stpageabilityevent.h b/test/resource/amssystemtestability/abilitySrc/tools/include/stpageabilityevent.h index 0ac76a4b9f..7c441e4f4d 100644 --- a/test/resource/amssystemtestability/abilitySrc/tools/include/stpageabilityevent.h +++ b/test/resource/amssystemtestability/abilitySrc/tools/include/stpageabilityevent.h @@ -27,7 +27,6 @@ namespace OHOS { namespace AppExecFwk { - namespace STEventName { const std::string g_eventName = "resp_st_page_ability_callback"; const std::string g_eventNameProcessMemory = "resp_st_process_memory_info"; @@ -129,8 +128,6 @@ private: std::string callBackPath_; std::string abilityStatus_; }; - } // namespace AppExecFwk } // namespace OHOS - -#endif //_AMS_ST_PAGE_ABILITY_EVENT_H_ \ No newline at end of file +#endif // _AMS_ST_PAGE_ABILITY_EVENT_H_ \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/tools/src/event.cpp b/test/resource/amssystemtestability/abilitySrc/tools/src/event.cpp index a51291b4b2..933a13149c 100644 --- a/test/resource/amssystemtestability/abilitySrc/tools/src/event.cpp +++ b/test/resource/amssystemtestability/abilitySrc/tools/src/event.cpp @@ -17,7 +17,6 @@ #include namespace STtools { - int WaitCompleted(Event &event, const std::string &eventName, const int code, const int timeout) { return event.WaitingMessage(std::to_string(code) + eventName, timeout, false); @@ -98,5 +97,4 @@ void Event::Clean() waiting_message_ = ""; complete_message_.clear(); } - } // namespace STtools \ No newline at end of file diff --git a/test/resource/amssystemtestability/abilitySrc/tools/src/stoperator.cpp b/test/resource/amssystemtestability/abilitySrc/tools/src/stoperator.cpp index 2c7ea20bc5..c441c6cedf 100644 --- a/test/resource/amssystemtestability/abilitySrc/tools/src/stoperator.cpp +++ b/test/resource/amssystemtestability/abilitySrc/tools/src/stoperator.cpp @@ -75,7 +75,8 @@ void DeserializationStOperatorFromVector(StOperator &ParentOperator, std::vector int StOperator::countChild = 0; StOperator::StOperator() - : g_parentOperator(nullptr), g_abilityType("0"), g_bundleName(""), g_abilityName(""), g_operatorName(""), g_message("") + : g_parentOperator(nullptr), g_abilityType("0"), + g_bundleName(""), g_abilityName(""), g_operatorName(""), g_message("") { g_childOperator.clear(); StOperator::countChild++; diff --git a/test/resource/bmssystemtestability/abilitySrc/thirdPageDemo3/src/pageAbilityDemo.cpp b/test/resource/bmssystemtestability/abilitySrc/thirdPageDemo3/src/pageAbilityDemo.cpp index bce1ad6f00..2ed39e4dc0 100644 --- a/test/resource/bmssystemtestability/abilitySrc/thirdPageDemo3/src/pageAbilityDemo.cpp +++ b/test/resource/bmssystemtestability/abilitySrc/thirdPageDemo3/src/pageAbilityDemo.cpp @@ -19,7 +19,6 @@ namespace OHOS { namespace AppExecFwk { const std::string BUNDLE_DATA_ROOT_PATH = "/data/accounts/account_0/appdata/"; -const int DIR_DEPTH = 7; void PageAbilityDemo::OnStart(const Want &want) { APP_LOGI("PageAbilityDemo::onStart"); @@ -27,7 +26,7 @@ void PageAbilityDemo::OnStart(const Want &want) const std::string appName = "com.third.hiworld.example1"; std::string path = BUNDLE_DATA_ROOT_PATH + appName + "/cache/"; APP_LOGI("PageAbilityDemo::CreateDir"); - for (int i = 1; i < DIR_DEPTH; i++) { + for (int i = 1; i < 7; i++) { path += "dir" + std::to_string(i) + "/"; APP_LOGI("PageAbilityDemo::CreateDir %{public}s", path.c_str()); CreateDir(path); diff --git a/test/resource/bundlemgrsst/stThirdBundle/bmsThirdBundle41.hap b/test/resource/bundlemgrsst/stThirdBundle/bmsThirdBundle41.hap index 6939058dc68e2c0bd987a944d293c410e6acae60..05035ff2a8d5b96887346b15f6473e2f8e197b3f 100644 GIT binary patch delta 693 zcmV;m0!sa!;01u-1&}U(ls#|4Fc604An_lN)e%JnHa6O+ODEJ0RaH6hK~8n-$abIz z@!xAF0b-L-Xv7fiUf;)a7w?CIk$ng)3Nqi(B-Slgb@v+<{kVl)}1Oi7HPjnM*Sn2X@hkjK` zE~vqTyAU%kG%-}I!8rTLe5l`!!3l#6rtmDq3fF#Y>sry08{Zn9&m}9X)a{c6O~2{d zTKkE{na{LlK$2W9o&2eq%hZ$9r7m}cOZO2lG#e6PO{r?({PaShHcEDkhyh1Cz}-8V z>_uopIkzgKN(iHW*Nq=H$AHx)$kFUbx3a05fG}#;J!U)SDg=Ud9qxP9#Ao!im|SGU zv|1GMkOM{1b_W-;Tq6boga$icP<}aR6 z2gsY9vWxBj7oDgT?#8{z2Y)p% zH!(3XH!?U{FfRrPDuzgg_YDCF1Ti86Am(`EI|f4)znC}d;W7`-taPkl?l;p=V?svk z12i)X)-VhP2r7n1&OHPJ0tEmBM=(VKAppi~6n_r2`Ha7gT8OTIpL2>m5`a$uNN$HD zS3ij1#$f^=JqPiOI9KJ|eb&RFYZK2BcfnwVYzwgW`GbO)$Q3Z?GM8p=0Wb->hfF@U b0RRAQm!EF|P6G1*m+x-@DF$e70RR91ayK*i delta 709 zcmV;$0y_PG;02!G1&}U(RL@VsFcdzIg#Upw9?cZEaYMa$@q~IX#&qk0z1X!&+ku4e zzuRsD*Rr9wa2W6V`hI-hTX)03$UcM?1)1&YKUE+p1>^8Ub0D)3No5|J3>Awr+(^Y) z3|}-aIE=}4>(Ckmlgb@v-~d$`rLb_TP=%zDxiaJHATFBn8JZDcno3#Fd}hLQ7h5<442uxnyNkx_z>s=_g&; zXuqOy=4)DOK$2W99R05HW#UolRu|jCm3s>`G;0#dno`x0^W95@+9=s!5d)6a!0juV z>``b#IkzmMN(i%m*MlE6$AIM~$kA*`H?!%RfG}#?ZL{^cN`au=gu9+K@iqFGk54LM zS}h8>%7G!BX(2a>n@bW*vEpECwU8$j+DYwV)}53>7m(r- zft^rIlZ;VAPry>)0c-S~-P}}LWfhMZVx}$92juc zgh^QG5+lx=G3hho5<@OD#WTig>b|^A&To1~9YRLEDo(>1(H|v@{;|u^U$u)a5H32Z zR=6AR1U;))>$YmH+2O$cz5!562MG5$KHk&;006#&@Bz2*0RabPATK}Q#I~v8Z-a3< z<<$nnNJ)=t^5x<4^vKlvE!IFU{I?fp0iOpuIWaXcF)}bTGg>e&1_>&LNQU# zA_O49_S{zFpn_A=7i--O|B8p%%W^@c)XrMy*u6qu7CHBq@ooVVL?Bt6T*GTJ0juBP z0DAG8KJ1~!QjO(ajq>7kIUr_5Ub6xr0KS)n*CV_ZS5cxe(7@8w3MbxqrA_5hkY!&1 r&08uAU6)920Wb;oIX>Rh0RRBLmw|5qP681Em(gzlDF%jb0RR917C==t diff --git a/test/systemtest/common/ams/ams_ability_visible_test/ams_ability_visible_test.cpp b/test/systemtest/common/ams/ams_ability_visible_test/ams_ability_visible_test.cpp index a5e0b79835..22a703ffbd 100644 --- a/test/systemtest/common/ams/ams_ability_visible_test/ams_ability_visible_test.cpp +++ b/test/systemtest/common/ams/ams_ability_visible_test/ams_ability_visible_test.cpp @@ -174,11 +174,13 @@ public: static sptr abilityMs_; static STtools::Event event_; static std::shared_ptr subscriber_; + static int *memTestValue_; }; sptr AmsAbilityVisibleTest::appMs_ = nullptr; sptr AmsAbilityVisibleTest::abilityMs_ = nullptr; STtools::Event AmsAbilityVisibleTest::event_ = STtools::Event(); +int *AmsAbilityVisibleTest::memTestValue_ = nullptr; std::shared_ptr AmsAbilityVisibleTest::subscriber_ = nullptr; size_t AmsAbilityVisibleTest::AbilityConnectCallback::onAbilityConnectDoneCount = 0; int AmsAbilityVisibleTest::AbilityConnectCallback::resultConnectCode = 0; @@ -215,6 +217,10 @@ void AmsAbilityVisibleTest::SetUp(void) void AmsAbilityVisibleTest::TearDown(void) { GTEST_LOG_(INFO) << "void AmsAbilityVisibleTest::TearDown(void)"; + if (memTestValue_) { + delete[] memTestValue_; + } + std::vector bundleNames = GetBundleNames(bundleNameBase, bundleNameSuffix); STAbilityUtil::UninstallBundle(bundleNames); diff --git a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp index 11805537bf..f1136e725d 100644 --- a/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp +++ b/test/systemtest/common/bms/acts_bms_kit_system_test/acts_bms_kit_system_test.cpp @@ -53,6 +53,7 @@ const int TARGETVERSION = 3; namespace OHOS { namespace AppExecFwk { + class BundleStatusCallbackImpl : public BundleStatusCallbackHost { public: BundleStatusCallbackImpl(); @@ -193,6 +194,7 @@ public: void CheckFileNonExist(const std::string &bundleName, const std::string &modulePackage) const; static StressTestLevel stLevel_; }; + StressTestLevel ActsBmsKitSystemTest::stLevel_{}; void ActsBmsKitSystemTest::SetUpTestCase() @@ -226,7 +228,7 @@ void ActsBmsKitSystemTest::Install( InstallParam installParam; installParam.installFlag = installFlag; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); resvec.push_back(statusReceiver->GetResultMsg()); @@ -247,7 +249,7 @@ void ActsBmsKitSystemTest::Uninstall(const std::string &bundleName, std::vector< } else { InstallParam installParam; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Uninstall(bundleName, installParam, statusReceiver); resvec.push_back(statusReceiver->GetResultMsg()); @@ -270,7 +272,7 @@ void ActsBmsKitSystemTest::HapUninstall( } else { InstallParam installParam; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Uninstall(bundleName, modulePackage, installParam, statusReceiver); resvec.push_back(statusReceiver->GetResultMsg()); @@ -2427,8 +2429,11 @@ HWTEST_F(ActsBmsKitSystemTest, GetHapModuleInfo_0200, Function | MediumTest | Le std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle2.hap"; std::string appName = BASE_BUNDLE_NAME + "1"; Install(bundleFilePath, InstallFlag::NORMAL, resvec); + CommonTool commonTool; - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + AbilityInfo abilityInfo; abilityInfo.bundleName = appName; abilityInfo.package = BASE_BUNDLE_NAME + ".h1"; @@ -2457,7 +2462,8 @@ HWTEST_F(ActsBmsKitSystemTest, GetHapModuleInfo_0200, Function | MediumTest | Le } resvec.clear(); Uninstall(appName, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; if (!queryResult) { APP_LOGI("GetHapModuleInfo_0200 failed - cycle count: %{public}d", i); @@ -2465,6 +2471,7 @@ HWTEST_F(ActsBmsKitSystemTest, GetHapModuleInfo_0200, Function | MediumTest | Le } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("GetHapModuleInfo_0200 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -3074,6 +3081,7 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0700, Function | MediumTest | Level1) std::string firstAppName = BASE_BUNDLE_NAME + "1"; std::string secondFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle7.hap"; std::string secondAppName = BASE_BUNDLE_NAME + "2"; + CommonTool commonTool; sptr firstBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(firstBundleStatusCallback, nullptr); @@ -3085,28 +3093,37 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0700, Function | MediumTest | Level1) } bundleMgrProxy->RegisterBundleStatusCallback(firstBundleStatusCallback); Install(firstFilePath, InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string firstinstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(firstinstallResult, "Success") << "install fail!"; + resvec.clear(); sptr secondBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(secondBundleStatusCallback, nullptr); secondBundleStatusCallback->SetBundleName(secondAppName); bundleMgrProxy->RegisterBundleStatusCallback(secondBundleStatusCallback); Install(secondFilePath, InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string secondinstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(secondinstallResult, "Success") << "install fail!"; + bool clearResult = bundleMgrProxy->ClearBundleStatusCallback(firstBundleStatusCallback); EXPECT_TRUE(clearResult); + std::vector resvec2; Uninstall(firstAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; resvec2.clear(); Uninstall(secondAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (!clearResult) { APP_LOGI("Callback_0700 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("Callback_0700 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -3135,6 +3152,7 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0800, Function | MediumTest | Level1) std::string firstAppName = BASE_BUNDLE_NAME + "1"; std::string secondFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle7.hap"; std::string secondAppName = BASE_BUNDLE_NAME + "2"; + CommonTool commonTool; sptr firstBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(firstBundleStatusCallback, nullptr); @@ -3148,6 +3166,7 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0800, Function | MediumTest | Level1) Install(firstFilePath, InstallFlag::NORMAL, resvec); std::string firstinstallResult = commonTool.VectorToStr(resvec); EXPECT_EQ(firstinstallResult, "Success") << "install fail!"; + resvec.clear(); sptr secondBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(secondBundleStatusCallback, nullptr); @@ -3156,20 +3175,26 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0800, Function | MediumTest | Level1) Install(secondFilePath, InstallFlag::NORMAL, resvec); std::string secondinstallResult = commonTool.VectorToStr(resvec); EXPECT_EQ(secondinstallResult, "Success") << "install fail!"; + bool clearResult = bundleMgrProxy->ClearBundleStatusCallback(secondBundleStatusCallback); EXPECT_TRUE(clearResult); + std::vector resvec2; Uninstall(firstAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; resvec2.clear(); Uninstall(secondAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (!clearResult) { APP_LOGI("Callback_0800 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("Callback_0800 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -3199,6 +3224,7 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0900, Function | MediumTest | Level1) std::string firstAppName = BASE_BUNDLE_NAME + "1"; std::string secondFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle7.hap"; std::string secondAppName = BASE_BUNDLE_NAME + "2"; + CommonTool commonTool; sptr firstBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(firstBundleStatusCallback, nullptr); @@ -3210,30 +3236,39 @@ HWTEST_F(ActsBmsKitSystemTest, Callback_0900, Function | MediumTest | Level1) } bundleMgrProxy->RegisterBundleStatusCallback(firstBundleStatusCallback); Install(firstFilePath, InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string firstinstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(firstinstallResult, "Success") << "install fail!"; + resvec.clear(); sptr secondBundleStatusCallback = (new (std::nothrow) BundleStatusCallbackImpl()); EXPECT_NE(secondBundleStatusCallback, nullptr); secondBundleStatusCallback->SetBundleName(secondAppName); bundleMgrProxy->RegisterBundleStatusCallback(secondBundleStatusCallback); Install(secondFilePath, InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string secondinstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(secondinstallResult, "Success") << "install fail!"; + bool clearResult1 = bundleMgrProxy->ClearBundleStatusCallback(firstBundleStatusCallback); EXPECT_TRUE(clearResult1); bool clearResult2 = bundleMgrProxy->ClearBundleStatusCallback(secondBundleStatusCallback); EXPECT_TRUE(clearResult2); + std::vector resvec2; Uninstall(firstAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; resvec2.clear(); Uninstall(secondAppName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (!clearResult1 && !clearResult2) { APP_LOGI("Callback_0900 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("Callback_0900 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -3446,6 +3481,7 @@ HWTEST_F(ActsBmsKitSystemTest, CleanBundleCacheFiles_0400, Function | MediumTest std::vector resvec; std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle45.hap"; std::string appName = BASE_BUNDLE_NAME + "1"; + CommonTool commonTool; Install(bundleFilePath, InstallFlag::NORMAL, resvec); std::string installResult = commonTool.VectorToStr(resvec); @@ -3475,15 +3511,19 @@ HWTEST_F(ActsBmsKitSystemTest, CleanBundleCacheFiles_0400, Function | MediumTest EXPECT_NE(name1Exist, 0) << "the cache test dir1 exists."; name2Exist = access(testCacheDir2.c_str(), F_OK); EXPECT_NE(name2Exist, 0) << "the cache test dir2 exists."; + resvec.clear(); Uninstall(appName, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (!cleanCacheResult) { APP_LOGI("CleanBundleCacheFiles_0400 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("CleanBundleCacheFiles_0400 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -3943,8 +3983,11 @@ HWTEST_F(ActsBmsKitSystemTest, AbilityDump_0100, Function | MediumTest | Level0) std::string appName = BASE_BUNDLE_NAME + "1"; std::string abilityName = "bmsThirdBundle_A1"; Install(bundleFilePath, InstallFlag::NORMAL, resvec); + CommonTool commonTool; - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + Want want; ElementName name; name.SetAbilityName(abilityName); @@ -3960,6 +4003,7 @@ HWTEST_F(ActsBmsKitSystemTest, AbilityDump_0100, Function | MediumTest | Level0) bool queryResult = bundleMgrProxy->QueryAbilityInfo(want, abilityInfo); EXPECT_EQ(abilityInfo.name, abilityName); EXPECT_TRUE(queryResult); + std::string path = "/data/test/abilityInfo.txt"; std::ofstream file(path); file.close(); @@ -3970,15 +4014,19 @@ HWTEST_F(ActsBmsKitSystemTest, AbilityDump_0100, Function | MediumTest | Level0) long length = lseek(fd, 0, SEEK_END); EXPECT_GT(length, 0); close(fd); + resvec.clear(); Uninstall(appName, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (!queryResult) { APP_LOGI("AbilityDump_0100 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("AbilityDump_0100 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -4432,10 +4480,14 @@ HWTEST_F(ActsBmsKitSystemTest, ApplicationInfo_0100, Function | MediumTest | Lev bool result = false; for (int i = 1; i <= stLevel_.BMSLevel; i++) { std::vector resvec; + std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; std::string appName = BASE_BUNDLE_NAME + "1"; - Install(THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap", InstallFlag::NORMAL, resvec); + Install(bundleFilePath, InstallFlag::NORMAL, resvec); + CommonTool commonTool; - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + ApplicationInfo appInfo; int userId = Constants::DEFAULT_USERID; sptr bundleMgrProxy = GetBundleMgrProxy(); @@ -4453,7 +4505,8 @@ HWTEST_F(ActsBmsKitSystemTest, ApplicationInfo_0100, Function | MediumTest | Lev file.close(); int fd = open(path.c_str(), O_RDWR); EXPECT_NE(fd, -1) << "open file error"; - pAppInfo->Dump("[pAppInfo]", fd); + std::string prefix = "[pAppInfo]"; + pAppInfo->Dump(prefix, fd); long length = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); std::string strAppInfo; @@ -4464,15 +4517,19 @@ HWTEST_F(ActsBmsKitSystemTest, ApplicationInfo_0100, Function | MediumTest | Lev std::string cacheDir = BUNDLE_DATA_ROOT_PATH + appName + "/cache"; EXPECT_TRUE(IsSubStr(strAppInfo, cacheDir)); close(fd); + resvec.clear(); Uninstall(appName, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; + if (retVal <= 0) { APP_LOGI("ApplicationInfo_0100 failed - cycle count: %{public}d", i); break; } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("ApplicationInfo_0100 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -4624,7 +4681,7 @@ HWTEST_F(ActsBmsKitSystemTest, Uninstall_KeepData_0100, Function | MediumTest | installParam.installFlag = InstallFlag::NORMAL; installParam.userId = Constants::DEFAULT_USERID; installParam.isKeepData = false; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); std::string installMsg = statusReceiver->GetResultMsg(); @@ -4661,7 +4718,7 @@ HWTEST_F(ActsBmsKitSystemTest, Uninstall_KeepData_0200, Function | MediumTest | installParam.installFlag = InstallFlag::NORMAL; installParam.userId = Constants::DEFAULT_USERID; installParam.isKeepData = true; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); std::string installMsg = statusReceiver->GetResultMsg(); @@ -4698,14 +4755,14 @@ HWTEST_F(ActsBmsKitSystemTest, Uninstall_KeepData_0300, Function | MediumTest | installParam.installFlag = InstallFlag::NORMAL; installParam.userId = Constants::DEFAULT_USERID; installParam.isKeepData = false; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); std::string installMsg = statusReceiver->GetResultMsg(); EXPECT_EQ(installMsg, "Success") << "install fail!"; bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle4.hap"; - sptr statusReceiver2 = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver2 = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver2, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver2); installMsg = statusReceiver2->GetResultMsg(); @@ -4749,14 +4806,14 @@ HWTEST_F(ActsBmsKitSystemTest, Uninstall_KeepData_0400, Function | MediumTest | installParam.installFlag = InstallFlag::NORMAL; installParam.userId = Constants::DEFAULT_USERID; installParam.isKeepData = true; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); std::string installMsg = statusReceiver->GetResultMsg(); EXPECT_EQ(installMsg, "Success") << "install fail!"; bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle4.hap"; - sptr statusReceiver2 = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver2 = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver2, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver2); installMsg = statusReceiver2->GetResultMsg(); @@ -4795,20 +4852,24 @@ HWTEST_F(ActsBmsKitSystemTest, GetBundlesForUid_0100, Function | MediumTest | Le APP_LOGE("bundle mgr proxy is nullptr."); EXPECT_EQ(bundleMgrProxy, nullptr); } + std::string installResult; CommonTool commonTool; for (int i = 6; i <= 8; i++) { std::vector resvec; std::string hapFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle" + std::to_string(i) + ".hap"; + std::cout << "begin install" << hapFilePath << std::endl; Install(hapFilePath, InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; } bool ret; for (int i = 1; i <= 3; i++) { std::string appName = BASE_BUNDLE_NAME + std::to_string(i); BundleInfo bundleInfo; bundleMgrProxy->GetBundleInfo(appName, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo); + int uid = bundleInfo.uid; std::vector bundleNames; - ret = bundleMgrProxy->GetBundlesForUid(bundleInfo.uid, bundleNames); + ret = bundleMgrProxy->GetBundlesForUid(uid, bundleNames); EXPECT_TRUE(ret); for (auto bundleName : bundleNames) { EXPECT_EQ(bundleName, appName); @@ -4818,7 +4879,8 @@ HWTEST_F(ActsBmsKitSystemTest, GetBundlesForUid_0100, Function | MediumTest | Le std::vector resvec; std::string appName = BASE_BUNDLE_NAME + std::to_string(i); Uninstall(appName, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; } if (!ret) { APP_LOGI("GetBundlesForUid_0100 failed - cycle count: %{public}d", i); @@ -4923,39 +4985,55 @@ HWTEST_F(ActsBmsKitSystemTest, GetNameForUid_0100, Function | MediumTest | Level bool result = false; for (int i = 1; i <= stLevel_.BMSLevel; i++) { CommonTool commonTool; + std::string installResult; std::vector resvec; - std::string name1, name2; - Install(THIRD_BUNDLE_PATH + "bmsThirdBundle6.hap", InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + std::string bundleFilePath1 = THIRD_BUNDLE_PATH + "bmsThirdBundle6.hap"; + std::string bundleFilePath2 = THIRD_BUNDLE_PATH + "bmsThirdBundle7.hap"; + std::string appName1 = BASE_BUNDLE_NAME + '1'; + std::string appName2 = BASE_BUNDLE_NAME + '2'; + std::string name1; + std::string name2; + Install(bundleFilePath1, InstallFlag::NORMAL, resvec); + installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; resvec.clear(); sptr bundleMgrProxy = GetBundleMgrProxy(); if (!bundleMgrProxy) { APP_LOGE("bundle mgr proxy is nullptr."); EXPECT_EQ(bundleMgrProxy, nullptr); } + BundleInfo bundleInfo1; - bundleMgrProxy->GetBundleInfo(BASE_BUNDLE_NAME + '1', BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1); - bool ret = bundleMgrProxy->GetNameForUid(bundleInfo1.uid, name1); + bundleMgrProxy->GetBundleInfo(appName1, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo1); + int uid1 = bundleInfo1.uid; + bool ret = bundleMgrProxy->GetNameForUid(uid1, name1); EXPECT_TRUE(ret); - Uninstall(BASE_BUNDLE_NAME + '1', resvec); + + Uninstall(appName1, resvec); EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "uninstall fail!"; resvec.clear(); - Install(THIRD_BUNDLE_PATH + "bmsThirdBundle7.hap", InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + Install(bundleFilePath2, InstallFlag::NORMAL, resvec); + installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; resvec.clear(); - Install(THIRD_BUNDLE_PATH + "bmsThirdBundle6.hap", InstallFlag::NORMAL, resvec); - EXPECT_EQ(commonTool.VectorToStr(resvec), "Success") << "install fail!"; + + Install(bundleFilePath1, InstallFlag::NORMAL, resvec); + installResult = commonTool.VectorToStr(resvec); + EXPECT_EQ(installResult, "Success") << "install fail!"; + BundleInfo bundleInfo2; - bundleMgrProxy->GetBundleInfo(BASE_BUNDLE_NAME + '1', BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2); - ret = bundleMgrProxy->GetNameForUid(bundleInfo2.uid, name2); + bundleMgrProxy->GetBundleInfo(appName1, BundleFlag::GET_BUNDLE_DEFAULT, bundleInfo2); + int uid2 = bundleInfo2.uid; + ret = bundleMgrProxy->GetNameForUid(uid2, name2); EXPECT_TRUE(ret); - EXPECT_NE(bundleInfo1.uid, bundleInfo2.uid); + EXPECT_NE(uid1, uid2); EXPECT_EQ(name1, name2); for (int i = 1; i <= 2; i++) { std::string appName = BASE_BUNDLE_NAME + std::to_string(i); std::vector resvec2; Uninstall(appName, resvec2); - EXPECT_EQ(commonTool.VectorToStr(resvec2), "Success") << "uninstall fail!"; + std::string uninstallResult = commonTool.VectorToStr(resvec2); + EXPECT_EQ(uninstallResult, "Success") << "uninstall fail!"; } if (!ret) { APP_LOGI("GetNameForUid_0100 failed - cycle count: %{public}d", i); @@ -4963,6 +5041,7 @@ HWTEST_F(ActsBmsKitSystemTest, GetNameForUid_0100, Function | MediumTest | Level } result = true; } + if (result && stLevel_.BMSLevel > 1) { APP_LOGI("GetNameForUid_0100 success - cycle count: %{public}d", stLevel_.BMSLevel); } @@ -5753,4 +5832,4 @@ HWTEST_F(ActsBmsKitSystemTest, IsApplicationEnabled_0300, Function | MediumTest std::cout << "END IsApplicationEnabled_0300" << std::endl; } } // namespace AppExecFwk -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/bms/bms_compatible_system_test/bms_compatible_system_test.cpp b/test/systemtest/common/bms/bms_compatible_system_test/bms_compatible_system_test.cpp index eeb0dcf876..b0287ef45e 100644 --- a/test/systemtest/common/bms/bms_compatible_system_test/bms_compatible_system_test.cpp +++ b/test/systemtest/common/bms/bms_compatible_system_test/bms_compatible_system_test.cpp @@ -49,6 +49,7 @@ const int MIN_WIDTH = 100; const int DEFAULT_HEIGHT = 100; const int DEFAULT_WIDTH = 200; const int FORM_NUM = 3; + } // namespace using OHOS::AAFwk::Want; using namespace testing::ext; @@ -151,7 +152,7 @@ void BmsCompatibleSystemTest::Uninstall(const std::string &bundleName, std::stri } else { InstallParam installParam; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Uninstall(bundleName, installParam, statusReceiver); uninstallMessage = statusReceiver->GetResultMsg(); @@ -724,5 +725,6 @@ HWTEST_F(BmsCompatibleSystemTest, BMS_QueryAbilityInfoByUri_0300, Function | Med EXPECT_EQ(abilityInfo.uri, ""); GTEST_LOG_(INFO) << "END BMS_QueryAbilityInfoByUri_0300"; } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp b/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp index 3c2cf82c4e..b018a324f7 100755 --- a/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp +++ b/test/systemtest/common/bms/bms_install_system_test/bms_install_system_test.cpp @@ -31,6 +31,7 @@ using namespace testing::ext; using namespace std::chrono_literals; namespace { + const std::string THIRD_BUNDLE_PATH = "/data/test/bms_bundle/"; const std::string CODE_ROOT_PATH = "/data/accounts/account_0/applications/"; const std::string DATA_ROOT_PATH = "/data/accounts/account_0/appdata/"; @@ -40,7 +41,6 @@ const std::string SYSTEM_BASE_BUNDLE_NAME = "com.system.hiworld.example"; const std::string MSG_SUCCESS = "[SUCCESS]"; const std::string OPERATION_FAILURE = "Failure"; const std::string OPERATION_SUCCESS = "Success"; -const int TIMEOUT = 10; } // namespace namespace OHOS { @@ -87,7 +87,7 @@ void StatusReceiverImpl::OnFinished(const int32_t resultCode, const std::string std::string StatusReceiverImpl::GetResultMsg() const { auto future = resultMsgSignal_.get_future(); - std::chrono::seconds timeout(TIMEOUT); + std::chrono::seconds timeout(10); if (future.wait_for(timeout) == std::future_status::timeout) { return OPERATION_FAILURE + " timeout"; } @@ -103,7 +103,6 @@ public: explicit SubscriberTest(const CommonEventSubscribeInfo &sp) : CommonEventSubscriber(sp){}; virtual void OnReceiveEvent(const CommonEventData &data) override; std::string GetSubscriberResultMsg() const; - virtual ~SubscriberTest() = default; private: mutable std::promise subscriberMsgSignal_; @@ -2446,5 +2445,6 @@ HWTEST_F(BmsInstallSystemTest, BMS_DFX_0400, Function | MediumTest | Level2) EXPECT_FALSE(getInfoResult); std::cout << "END BMS_DFX_0400" << std::endl; } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/bms/bms_launcher_service_system_test/bms_launcher_service_system_test.cpp b/test/systemtest/common/bms/bms_launcher_service_system_test/bms_launcher_service_system_test.cpp index 30137f71ee..3fa58800fc 100644 --- a/test/systemtest/common/bms/bms_launcher_service_system_test/bms_launcher_service_system_test.cpp +++ b/test/systemtest/common/bms/bms_launcher_service_system_test/bms_launcher_service_system_test.cpp @@ -44,7 +44,7 @@ const std::string BUNDLE_ADD = "Bundle Add Success"; const std::string BUNDLE_UPDATE = "Bundle Update Success"; const std::string BUNDLE_REMOVE = "Bundle Remove Success"; constexpr uint32_t WAIT_SECONDS = 5; -const unsigned int LIST_SIZE = 2; + } // namespace using OHOS::AAFwk::Want; using namespace testing::ext; @@ -173,7 +173,7 @@ void BmsLauncherServiceSystemTest::Install( InstallParam installParam; installParam.installFlag = installFlag; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Install(bundleFilePath, installParam, statusReceiver); installMessage = statusReceiver->GetResultMsg(); @@ -194,7 +194,7 @@ void BmsLauncherServiceSystemTest::Uninstall(const std::string &bundleName, std: } else { InstallParam installParam; installParam.userId = Constants::DEFAULT_USERID; - sptr statusReceiver = new (std::nothrow) StatusReceiverImpl(); + sptr statusReceiver = (new (std::nothrow) StatusReceiverImpl()); EXPECT_NE(statusReceiver, nullptr); installerProxy->Uninstall(bundleName, installParam, statusReceiver); uninstallMessage = statusReceiver->GetResultMsg(); @@ -294,13 +294,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_Register_0100, Function | MediumTest std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; std::string bundleName = "com.example.third1"; std::string message; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); sptr callback = new TestBundleStatusCallback(); - launcherservice.RegisterCallback(callback); + launcherservice->RegisterCallback(callback); Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; EXPECT_TRUE(Wait(BUNDLE_ADD)); - launcherservice.UnRegisterCallback(); + launcherservice->UnRegisterCallback(); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; GTEST_LOG_(INFO) << "END BMS_Register_0100"; @@ -316,15 +316,15 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_Register_0200, Function | MediumTest std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; std::string bundleName = "com.example.third1"; std::string message; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); sptr callback = new TestBundleStatusCallback(); - launcherservice.RegisterCallback(callback); + launcherservice->RegisterCallback(callback); Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; Uninstall(bundleName, message); EXPECT_TRUE(Wait(BUNDLE_REMOVE)); EXPECT_EQ(message, "Success") << "uninstall fail!"; - launcherservice.UnRegisterCallback(); + launcherservice->UnRegisterCallback(); GTEST_LOG_(INFO) << "END BMS_Register_0200"; } /** @@ -339,16 +339,16 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_Register_0300, Function | MediumTest std::string bundleFilePath1 = THIRD_BUNDLE_PATH + "bmsThirdBundle1.hap"; std::string bundleFilePath2 = THIRD_BUNDLE_PATH + "bmsThirdBundle4.hap"; std::string message; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); sptr callback = new TestBundleStatusCallback(); - launcherservice.RegisterCallback(callback); + launcherservice->RegisterCallback(callback); Install(bundleFilePath1, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; EXPECT_TRUE(Wait(BUNDLE_ADD)); Install(bundleFilePath2, InstallFlag::REPLACE_EXISTING, message); EXPECT_EQ(message, "Success") << "install fail!"; EXPECT_TRUE(Wait(BUNDLE_UPDATE)); - launcherservice.UnRegisterCallback(); + launcherservice->UnRegisterCallback(); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; GTEST_LOG_(INFO) << "END BMS_Register_0300"; @@ -364,10 +364,10 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_Register_0400, Function | MediumTest std::string bundleName = THIRD_BASE_BUNDLE_NAME + "2"; std::string bundleFilePath = THIRD_BUNDLE_PATH + "bmsThirdBundle2.hap"; std::string message; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); sptr callback = new TestBundleStatusCallback(); - launcherservice.RegisterCallback(callback); - launcherservice.UnRegisterCallback(); + launcherservice->RegisterCallback(callback); + launcherservice->UnRegisterCallback(); Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; EXPECT_FALSE(Wait(BUNDLE_ADD)); @@ -392,9 +392,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0100, Function | Mediu Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); std::vector launcherAbilityInfos; - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result) << "Get ability list failed"; EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; EXPECT_EQ(launcherAbilityInfos[0].name, abilityName); @@ -425,9 +429,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0200, Function | Mediu Install(bundleFilePath2, InstallFlag::REPLACE_EXISTING, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); std::vector launcherAbilityInfos; - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result) << "Get ability list failed"; EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; EXPECT_EQ(launcherAbilityInfos[0].name, abilityName); @@ -454,12 +462,15 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0300, Function | Mediu Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result) << "Get ability list failed"; EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; - EXPECT_EQ(launcherAbilityInfos.size(), LIST_SIZE); + EXPECT_GE(launcherAbilityInfos.size(), 1); EXPECT_EQ(launcherAbilityInfos[0].name, abilityName1); EXPECT_EQ(launcherAbilityInfos[1].name, abilityName2); Uninstall(bundleName, message); @@ -489,12 +500,15 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0400, Function | Mediu Install(bundleFilePath2, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result) << "Get ability list failed"; EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; - EXPECT_EQ(launcherAbilityInfos.size(), LIST_SIZE); + EXPECT_GE(launcherAbilityInfos.size(), 1); EXPECT_EQ(launcherAbilityInfos[0].name, abilityName1); EXPECT_EQ(launcherAbilityInfos[1].name, abilityName2); Uninstall(bundleName, message); @@ -513,9 +527,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0500, Function | Mediu int userId = Constants::DEFAULT_USERID; std::vector launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_GetAbilityList_0500"; } @@ -537,10 +554,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0600, Function | Mediu Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); std::vector launcherAbilityInfos; - - bool result1 = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result1 = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result1) << "Get ability list failed"; EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; EXPECT_EQ(launcherAbilityInfos[0].name, abilityName); @@ -548,7 +568,7 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0600, Function | Mediu Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; - bool result2 = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + bool result2 = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_FALSE(result2); GTEST_LOG_(INFO) << "END BMS_GetAbilityList_0600"; } @@ -565,9 +585,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityList_0700, Function | Mediu int userId = Constants::DEFAULT_USERID; std::vector launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityList(bundleName, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityList(bundleName, userId, launcherAbilityInfos); EXPECT_TRUE(result); EXPECT_FALSE(launcherAbilityInfos.empty()) << "Launcher ability infos is empty"; EXPECT_EQ(launcherAbilityInfos[0].name, abilityName); @@ -599,9 +622,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityInfo_0100, Function | Mediu want.SetElement(name); LauncherAbilityInfo launcherAbilityInfo; - LauncherService launcherservice; - - bool Result = launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool Result = launcherservice->GetAbilityInfo(want, userId, launcherAbilityInfo); EXPECT_TRUE(Result); EXPECT_EQ(launcherAbilityInfo.name, abilityName); @@ -632,9 +658,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityInfo_0200, Function | Mediu want.SetElement(name); LauncherAbilityInfo launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityInfo(want, userId, launcherAbilityInfos); EXPECT_TRUE(result) << "Get ability list failed"; EXPECT_EQ(launcherAbilityInfos.name, abilityName); Uninstall(bundleName, message); @@ -668,9 +697,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityInfo_0300, Function | Mediu name.SetBundleName(bundleName); want.SetElement(name); LauncherAbilityInfo launcherAbilityInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityInfo(want, userId, launcherAbilityInfo); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END GetAbilityInfo_0300"; } @@ -692,9 +724,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityInfo_0400, Function | Mediu want.SetElement(name); LauncherAbilityInfo launcherAbilityInfo; - LauncherService launcherservice; - - bool Result = launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool Result = launcherservice->GetAbilityInfo(want, userId, launcherAbilityInfo); EXPECT_TRUE(Result); EXPECT_EQ(launcherAbilityInfo.name, abilityName); @@ -729,9 +764,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetAbilityInfo_0500, Function | Mediu want.SetElement(name); LauncherAbilityInfo launcherAbilityInfos; - LauncherService launcherservice; - - bool result = launcherservice.GetAbilityInfo(want, userId, launcherAbilityInfos); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetAbilityInfo(want, userId, launcherAbilityInfos); EXPECT_TRUE(result); EXPECT_EQ(launcherAbilityInfos.name, abilityName); Uninstall(bundleName, message); @@ -752,11 +790,14 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0100, Function | M int userId = Constants::DEFAULT_USERID; Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo appInfo; ApplicationFlag flag = ApplicationFlag::GET_BASIC_APPLICATION_INFO; - bool result = launcherservice.GetApplicationInfo(bundleName, flag, userId, appInfo); + bool result = launcherservice->GetApplicationInfo(bundleName, flag, userId, appInfo); EXPECT_TRUE(result); EXPECT_EQ(appInfo.name, bundleName); Uninstall(bundleName, message); @@ -779,10 +820,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0200, Function | M Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo applicationInfo; - bool Result = launcherservice.GetApplicationInfo( + bool Result = launcherservice->GetApplicationInfo( bundleName, ApplicationFlag::GET_APPLICATION_INFO_WITH_PERMS, userId, applicationInfo); EXPECT_TRUE(Result); @@ -805,10 +849,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0300, Function | M std::string bundleName = SYSTEM_BASE_BUNDLE_NAME + "1"; int userId = Constants::DEFAULT_USERID; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo applicationInfo; - bool Result = launcherservice.GetApplicationInfo( + bool Result = launcherservice->GetApplicationInfo( bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, applicationInfo); EXPECT_TRUE(Result); EXPECT_EQ(applicationInfo.name, bundleName); @@ -835,10 +882,13 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0400, Function | M Install(bundleFilePath2, InstallFlag::REPLACE_EXISTING, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo applicationInfo; - bool Result = launcherservice.GetApplicationInfo( + bool Result = launcherservice->GetApplicationInfo( bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, applicationInfo); EXPECT_TRUE(Result); EXPECT_EQ(applicationInfo.name, bundleName); @@ -863,11 +913,14 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0500, Function | M Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo appInfo; bool result = - launcherservice.GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); + launcherservice->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_GetApplicationInfo_0500"; } @@ -883,11 +936,14 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetApplicationInfo_0600, Function | M std::string bundleName = ""; int userId = Constants::DEFAULT_USERID; - LauncherService launcherservice; - + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } ApplicationInfo appInfo; bool result = - launcherservice.GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); + launcherservice->GetApplicationInfo(bundleName, ApplicationFlag::GET_BASIC_APPLICATION_INFO, userId, appInfo); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_GetApplicationInfo_0600"; } @@ -908,9 +964,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsAbilityEnabled_0100, Function | Med AbilityInfo abilityInfo; abilityInfo.bundleName = bundleName; abilityInfo.name = abilityName; - LauncherService launcherservice; - - bool result = launcherservice.IsAbilityEnabled(abilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsAbilityEnabled(abilityInfo); EXPECT_TRUE(result); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; @@ -934,9 +993,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsAbilityEnabled_0200, Function | Med APP_LOGE("bundle mgr proxy is nullptr."); EXPECT_EQ(bundleMgrProxy, nullptr); } - LauncherService launcherservice; - - bool result = launcherservice.IsAbilityEnabled(abilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsAbilityEnabled(abilityInfo); EXPECT_TRUE(result); GTEST_LOG_(INFO) << "END BMS_IsAbilityEnabled_0200"; } @@ -953,9 +1015,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsAbilityEnabled_0300, Function | Med AbilityInfo abilityInfo; abilityInfo.bundleName = bundleName; abilityInfo.name = abilityName; - LauncherService launcherservice; - - bool result = launcherservice.IsAbilityEnabled(abilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsAbilityEnabled(abilityInfo); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_IsAbilityEnabled_0300"; } @@ -984,9 +1049,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsAbilityEnabled_0400, Function | Med } bool ret = bundleMgrProxy->SetAbilityEnabled(abilityInfo, true); EXPECT_TRUE(ret); - LauncherService launcherservice; - - bool result = launcherservice.IsAbilityEnabled(abilityInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsAbilityEnabled(abilityInfo); EXPECT_TRUE(result); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; @@ -1005,9 +1073,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsBundleEnabled_0100, Function | Medi std::string bundleName = THIRD_BASE_BUNDLE_NAME + "1"; Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; - - bool result = launcherservice.IsBundleEnabled(bundleName); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsBundleEnabled(bundleName); EXPECT_TRUE(result); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; @@ -1027,12 +1098,15 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsBundleEnabled_0200, Function | Medi std::string bundleName = THIRD_BASE_BUNDLE_NAME + "1"; Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; - LauncherService launcherservice; + std::shared_ptr launcherservice = std::make_shared(); sptr bundleMgrProxy = GetBundleMgrProxy(); - + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } bool ret = bundleMgrProxy->SetApplicationEnabled(bundleName, false); EXPECT_TRUE(ret); - bool result = launcherservice.IsBundleEnabled(bundleName); + bool result = launcherservice->IsBundleEnabled(bundleName); EXPECT_FALSE(result); Uninstall(bundleName, message); EXPECT_EQ(message, "Success") << "uninstall fail!"; @@ -1047,9 +1121,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsBundleEnabled_0300, Function | Medi { GTEST_LOG_(INFO) << "START BMS_IsBundleEnabled_0300"; std::string bundleName = SYSTEM_BASE_BUNDLE_NAME + "1"; - LauncherService launcherservice; - - bool result = launcherservice.IsBundleEnabled(bundleName); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsBundleEnabled(bundleName); EXPECT_TRUE(result); GTEST_LOG_(INFO) << "END BMS_IsBundleEnabled_0300"; } @@ -1062,9 +1139,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_IsBundleEnabled_0400, Function | Medi { GTEST_LOG_(INFO) << "START BMS_IsBundleEnabled_0400"; std::string bundleName = ""; - LauncherService launcherservice; - - bool result = launcherservice.IsBundleEnabled(bundleName); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcherservice is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->IsBundleEnabled(bundleName); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_IsBundleEnabled_0400"; } @@ -1084,9 +1164,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetShortcutInfos_0100, Function | Med Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherShortcutInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetShortcutInfos(bundleName, launcherShortcutInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetShortcutInfos(bundleName, launcherShortcutInfo); EXPECT_TRUE(result) << "Get shortcut info failed"; EXPECT_FALSE(launcherShortcutInfo.empty()) << "Launcher shortcut infos is empty"; EXPECT_EQ(launcherShortcutInfo[0].bundleName, bundleName); @@ -1117,12 +1200,15 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetShortcutInfos_0200, Function | Med Install(bundleFilePath2, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherShortcutInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetShortcutInfos(bundleName, launcherShortcutInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetShortcutInfos(bundleName, launcherShortcutInfo); EXPECT_TRUE(result) << "Get shortcut info failed"; EXPECT_FALSE(launcherShortcutInfo.empty()) << "Launcher shortcut infos is empty"; - EXPECT_EQ(launcherShortcutInfo.size(), LIST_SIZE); + EXPECT_GE(launcherShortcutInfo.size(), 1); EXPECT_EQ(launcherShortcutInfo[0].shortcutid, shortcutId1); EXPECT_EQ(launcherShortcutInfo[1].shortcutid, shortcutId2); Uninstall(bundleName, message); @@ -1144,9 +1230,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetShortcutInfos_0300, Function | Med Install(bundleFilePath, InstallFlag::NORMAL, message); EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherShortcutInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetShortcutInfos(bundleName, launcherShortcutInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetShortcutInfos(bundleName, launcherShortcutInfo); EXPECT_FALSE(result); EXPECT_TRUE(launcherShortcutInfo.empty()); Uninstall(bundleName, message); @@ -1163,9 +1252,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetShortcutInfos_0400, Function | Med GTEST_LOG_(INFO) << "START BMS_GetShortcutInfos_0400"; std::string bundleName = ""; std::vector launcherShortcutInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetShortcutInfos(bundleName, launcherShortcutInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetShortcutInfos(bundleName, launcherShortcutInfo); EXPECT_FALSE(result); GTEST_LOG_(INFO) << "END BMS_GetShortcutInfos_0400"; } @@ -1191,9 +1283,12 @@ HWTEST_F(BmsLauncherServiceSystemTest, BMS_GetShortcutInfos_0500, Function | Med EXPECT_EQ(message, "Success") << "install fail!"; std::vector launcherShortcutInfo; - LauncherService launcherservice; - - bool result = launcherservice.GetShortcutInfos(bundleName, launcherShortcutInfo); + std::shared_ptr launcherservice = std::make_shared(); + if (!launcherservice) { + APP_LOGE("launcher service is nullptr."); + EXPECT_EQ(launcherservice, nullptr); + } + bool result = launcherservice->GetShortcutInfos(bundleName, launcherShortcutInfo); EXPECT_TRUE(result); EXPECT_FALSE(launcherShortcutInfo.empty()) << "Launcher shortcut info is empty"; EXPECT_EQ(launcherShortcutInfo[0].bundleName, bundleName); diff --git a/test/systemtest/common/bms/bms_search_system_test/bms_search_system_test.cpp b/test/systemtest/common/bms/bms_search_system_test/bms_search_system_test.cpp index 27164f0e94..3ed774b217 100644 --- a/test/systemtest/common/bms/bms_search_system_test/bms_search_system_test.cpp +++ b/test/systemtest/common/bms/bms_search_system_test/bms_search_system_test.cpp @@ -45,6 +45,7 @@ const std::string OPERATION_SUCCESS = "Success"; namespace OHOS { namespace AppExecFwk { + class BundleStatusCallbackImpl : public BundleStatusCallbackHost { public: BundleStatusCallbackImpl(); @@ -1426,5 +1427,6 @@ HWTEST_F(BmsSearchSystemTest, BMS_Search_3900, Function | MediumTest | Level1) EXPECT_NE(name2Exist, 0) << "the test file2 exists."; std::cout << "END BMS_SEARCH_3900" << std::endl; } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file diff --git a/test/systemtest/common/bms/bms_uninstall_system_test/bms_uninstall_system_test.cpp b/test/systemtest/common/bms/bms_uninstall_system_test/bms_uninstall_system_test.cpp index e74303550a..aff2267f59 100755 --- a/test/systemtest/common/bms/bms_uninstall_system_test/bms_uninstall_system_test.cpp +++ b/test/systemtest/common/bms/bms_uninstall_system_test/bms_uninstall_system_test.cpp @@ -47,6 +47,7 @@ const int32_t MAX_BUNDLE_NAME = 6; namespace OHOS { namespace AppExecFwk { + class StatusReceiverImpl : public StatusReceiverHost { public: StatusReceiverImpl(); @@ -1368,5 +1369,6 @@ HWTEST_F(BmsUninstallSystemTest, BMS_DFX_0500, Function | MediumTest | Level2) EXPECT_EQ(uninstallMsg, "Success") << "uninstall fail!"; std::cout << "END BMS_DFX_0500" << std::endl; } + } // namespace AppExecFwk } // namespace OHOS \ No newline at end of file -- Gitee