# Copyright (c) 2021-2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/ohos.gni")
import("//foundation/aafwk/standard/aafwk.gni")

config("appmgr_test_config") {
  configs = [
    "${services_path}/appmgr:appmgr_config",
    "${aafwk_path}/interfaces/innerkits/app_manager:appmgr_sdk_config",
    "${aafwk_path}/services/test:services_mock_ams_config",
    "${bundlefwk_inner_api_path}/appexecfwk_core:bundlemgr_sdk_config",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base_sdk_config",
  ]

  defines = [
    "AMS_LOG_TAG = \"AppMgrService\"",
    "AMS_LOG_DOMAIN = 0xD00111E",
  ]

  include_dirs = [
    "${services_path}/appmgr/test/mock/include",
    "//base/account/os_account/interfaces/innerkits/osaccount/native/include",
    "${global_path}/i18n/frameworks/intl/include",
    "//base/hiviewdfx/hicollie/interfaces/native/innerkits/include",
  ]
}

ohos_source_set("appmgr_test_source") {
  testonly = true

  sources = [
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_launch_data.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_mgr_proxy.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_mgr_stub.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_process_data.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_record_id.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_host.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_scheduler_proxy.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_host.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_state_callback_proxy.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/app_task_info.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/process_info.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/profile.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_host.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/render_scheduler_proxy.cpp",
    "${aafwk_path}/interfaces/innerkits/app_manager/src/appmgr/running_process_info.cpp",
  ]

  include_dirs = [
    "//third_party/json/include",
    "${aafwk_path}/services/appmgr/include/lmks",
  ]

  public_configs = [
    ":appmgr_test_config",
    "//utils/native/base:utils_config",
  ]

  public_deps = [
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  deps = [
    "${aafwk_path}/interfaces/innerkits/app_manager:app_manager",
    "${ability_base_path}:base",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "${services_path}/common:perm_verification",
  ]

  if (ability_runtime_graphics) {
    deps += [ "${global_path}/i18n/frameworks/intl:intl_util" ]
  }

  external_deps = [
    "ability_base:configuration",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "common_event_service:cesfwk_core",
    "common_event_service:cesfwk_innerkits",
    "hitrace_native:hitrace_meter",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

group("unittest") {
  testonly = true

  deps = [
    "unittest/ams_ability_running_record_test:unittest",
    "unittest/ams_app_death_recipient_test:unittest",
    "unittest/ams_app_life_cycle_test:unittest",
    "unittest/ams_app_mgr_client_test:unittest",
    "unittest/ams_app_running_record_test:unittest",
    "unittest/ams_app_state_callback_test:unittest",
    "unittest/ams_app_workflow_test:unittest",
    "unittest/ams_ipc_interface_test:unittest",
    "unittest/ams_mgr_kill_process_test:unittest",
    "unittest/ams_mgr_proxy_test:unittest",
    "unittest/ams_mgr_scheduler_dump_test:unittest",
    "unittest/ams_mgr_scheduler_test:unittest",
    "unittest/ams_mgr_stub_test:unittest",
    "unittest/ams_recent_app_list_test:unittest",
    "unittest/ams_service_app_spawn_client_test:unittest",
    "unittest/ams_service_app_spawn_msg_wrapper_test:unittest",
    "unittest/ams_service_app_spawn_socket_test:unittest",
    "unittest/ams_service_event_drive_test:unittest",
    "unittest/ams_service_load_ability_process_test:unittest",
    "unittest/ams_service_startup_test:unittest",
    "unittest/app_mgr_proxy_test:unittest",
    "unittest/app_mgr_service_dump_test:unittest",
    "unittest/app_mgr_service_event_handler_test:unittest",
    "unittest/app_mgr_stub_test:unittest",
    "unittest/app_running_processes_info_test:unittest",
  ]
}
