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

import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
module_output_path = "ability_runtime/application_test"

ABILITY_INNERKITS_PATH = "${ability_runtime_innerkits_path}"

###############################################################################
config("module_private_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/context",
    "${ability_runtime_innerkits_path}/app_manager/include/appmgr",
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
    "${ability_runtime_path}/interfaces/kits/native/ability/native",
    "${ability_runtime_path}/interfaces/kits/native/appkit/app/task",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  defines = [ "AMS_LOG_TAG = \"ApplicationUnitTest\"" ]
}

config("module_context_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${ability_runtime_innerkits_path}/app_manager/include/appmgr",
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
    "${ability_runtime_path}/interfaces/kits/native/appkit/app/task",
    "${ability_runtime_path}/interfaces/kits/native/ability/native",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  defines = [ "AMS_LOG_TAG = \"ApplicationUnitTest\"" ]
}

ohos_unittest("context_deal_interface_test") {
  module_out_path = module_output_path
  sources = [
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include/mock_ability_manager_client_interface1.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include/mock_resourceManager_interface1.cpp",
    "context_deal_interface1_test.cpp",
  ]

  configs = [ ":module_private_config" ]

  deps = [
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_native_path}/ability/native:abilitykit_native",
    "${ability_runtime_native_path}/appkit:appkit_native",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "${global_path}/resource_management/frameworks/resmgr:global_resmgr",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]

  if (ability_runtime_graphics) {
    deps += [ "${multimodalinput_path}/frameworks/proxy:libmmi-client" ]
  }
}

ohos_unittest("application_test") {
  module_out_path = module_output_path
  sources = [
    "${ability_runtime_native_path}/appkit/app/app_context.cpp",
    "${ability_runtime_native_path}/appkit/app/app_loader.cpp",
    "${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
    "ability_stage_test.cpp",
    "application_data_manager_test.cpp",
    "application_test.cpp",
    "context_impl_test.cpp",
  ]

  configs = [ ":module_private_config" ]

  deps = [
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_innerkits_path}/app_manager:app_manager",
    "${ability_runtime_native_path}/ability/native:abilitykit_native",
    "${ability_runtime_native_path}/appkit:app_context",
    "${ability_runtime_native_path}/appkit:appkit_native",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("context_container_test") {
  module_out_path = module_output_path
  sources = [
    "${ability_runtime_native_path}/appkit/app/app_loader.cpp",
    "${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_bundle_manager.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/sys_mgr_client_mock.cpp",
    "context_container_test.cpp",
  ]

  configs = [ ":module_context_config" ]

  deps = [
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_native_path}/ability/native:abilitykit_native",
    "${ability_runtime_native_path}/appkit:app_context",
    "${ability_runtime_native_path}/appkit:appkit_native",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("context_deal_test") {
  module_out_path = module_output_path
  sources = [
    "${ability_runtime_native_path}/appkit/app/app_loader.cpp",
    "${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/mock_bundle_manager.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include/sys_mgr_client_mock.cpp",
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_native_test/include/mock_ability_manager_client.cpp",
    "context_deal_test.cpp",
  ]

  configs = [ ":module_context_config" ]

  deps = [
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_native_path}/ability/native:abilitykit_native",
    "${ability_runtime_native_path}/appkit:app_context",
    "${ability_runtime_native_path}/appkit:appkit_native",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("application_impl_test") {
  module_out_path = module_output_path
  sources = [
    "${ability_runtime_native_path}/appkit/app/app_context.cpp",
    "${ability_runtime_native_path}/appkit/app/app_loader.cpp",
    "${ability_runtime_native_path}/appkit/app/application_impl.cpp",
    "${ability_runtime_native_path}/appkit/app/ohos_application.cpp",
    "application_impl_test.cpp",
  ]

  configs = [ ":module_private_config" ]

  deps = [
    "${ABILITY_INNERKITS_PATH}/uri_permission:uri_permission_mgr",
    "${ability_runtime_innerkits_path}/ability_manager:ability_manager",
    "${ability_runtime_innerkits_path}/app_manager:app_manager",
    "${ability_runtime_native_path}/ability/native:abilitykit_native",
    "${ability_runtime_native_path}/appkit:app_context",
    "${ability_runtime_native_path}/appkit:appkit_native",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_base:want",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

config("ability_start_setting_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${ability_runtime_path}/interfaces/kits/native/appkit/app",
    "//commonlibrary/c_utils/base/include",
    "${ability_runtime_innerkits_path}/ability_manager/include",
  ]
}

ohos_unittest("ability_start_setting_test") {
  module_out_path = module_output_path

  configs = [
    ":module_context_config",
    ":ability_start_setting_config",
  ]

  sources = [
    "${ability_runtime_services_path}/abilitymgr/src/ability_start_setting.cpp",
    "ability_start_setting_test.cpp",
  ]

  deps = [
    "${ability_runtime_native_path}/appkit:appkit_native",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "c_utils:utils",
    "c_utils:utilsbase",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("watchdog_test") {
  module_out_path = module_output_path

  include_dirs = [
    "${ability_runtime_path}/interfaces/kits/native/appkit/app",
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_test/include",
    "${ability_runtime_path}/interfaces/kits/native/appkit/ability_runtime/app",
    "//third_party/json/include",
  ]

  configs = [
    ":module_context_config",
    ":ability_start_setting_config",
  ]

  sources = [
    "${ability_runtime_test_path}/mock/frameworks_kits_appkit_test/include/mock_app_thread.cpp",
    "watchdog_test.cpp",
  ]

  deps = [
    "${ability_runtime_native_path}/appkit:appkit_native",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:base",
    "ability_base:want",
    "bundle_framework:appexecfwk_base",
    "bundle_framework:appexecfwk_core",
    "c_utils:utils",
    "c_utils:utilsbase",
    "eventhandler:libeventhandler",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("mix_stack_dumper_test") {
  module_out_path = module_output_path

  include_dirs = [
    "${ability_runtime_path}/interfaces/kits/native/appkit/app",
    "${ability_runtime_test_path}/mock/frameworks_kits_runtime_test/",
  ]

  sources = [ "mix_stack_dumper_test.cpp" ]

  deps = [
    "${ability_runtime_native_path}/appkit:appkit_native",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_runtime:abilitykit_native",
    "ability_runtime:runtime",
    "faultloggerd:lib_dfx_dump_catcher",
  ]
}

###############################################################################

group("unittest") {
  testonly = true
  deps = []

  deps += [
    ":ability_start_setting_test",
    ":application_impl_test",
    ":application_test",
    ":context_container_test",
    ":context_deal_test",
    ":mix_stack_dumper_test",
    ":watchdog_test",
  ]

  deps += [ "ability_delegator:unittest" ]
}
###############################################################################
