# 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/aafwk/standard/aafwk.gni")
module_output_path = "ability_runtime/application_test"

ABILITY_INNERKITS_PATH = "${aafwk_path}/interfaces/innerkits"

###############################################################################
config("module_private_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${aafwk_path}/frameworks/kits/appkit/native/ability_runtime/context",
    "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
    "${ability_base_innerapi_path}/uri/include",
    "${bundlefwk_inner_api_path}/appexecfwk_core/include/bundlemgr",
    "${ability_base_innerapi_path}/want/include",
    "${aafwk_path}/frameworks/kits/appkit/native/test/mock/include",
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include",
    "${aafwk_path}/frameworks/kits/ability/native/include",
    "${aafwk_path}/frameworks/kits/appkit/native/app/include/task",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  defines = [
    "AMS_LOG_TAG = \"ApplicationUnitTest\"",
    "AMS_LOG_DOMAIN = 0xD001151",
  ]
}

config("module_context_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${aafwk_path}/interfaces/innerkits/app_manager/include/appmgr",
    "${ability_base_innerapi_path}/uri/include",
    "${ability_base_innerapi_path}/want/include",
    "${aafwk_path}/frameworks/kits/appkit/native/test/mock/include",
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include",
    "${bundlefwk_inner_api_path}/appexecfwk_core/include/bundlemgr",
    "${bundlefwk_inner_api_path}/appexecfwk_base/include",
    "${aafwk_path}/frameworks/kits/appkit/native/app/include/task",
    "${bundlefwk_innerkits_path}/libeventhandler/include",
    "${aafwk_path}/frameworks/kits/ability/native/include",
  ]
  cflags = []
  if (target_cpu == "arm") {
    cflags += [ "-DBINDER_IPC_32BIT" ]
  }
  defines = [
    "AMS_LOG_TAG = \"ApplicationUnitTest\"",
    "AMS_LOG_DOMAIN = 0xD001151",
  ]
}

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

  configs = [ ":module_private_config" ]

  deps = [
    "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${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",
    "//utils/native/base:utils",
  ]

  external_deps = [
    "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 = [
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/app_loader.cpp",
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/application_context.cpp",
    "../app/src/ohos_application.cpp",
    "unittest/ability_stage_test.cpp",
    "unittest/application_test.cpp",
    "unittest/context_impl_test.cpp",
  ]

  configs = [ ":module_private_config" ]

  deps = [
    "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "${aafwk_path}/frameworks/kits/appkit:app_context",
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
    "${aafwk_path}/interfaces/innerkits/app_manager:app_manager",
    "${ability_base_path}:base",
    "${ability_base_path}:base",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",

    #"${aafwk_path}/frameworks/kits/appkit:appkit_native",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_core",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("context_container_test") {
  module_out_path = module_output_path
  sources = [
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp",
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp",
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/app_loader.cpp",
    "../app/src/ohos_application.cpp",
    "unittest/context_container_test.cpp",
  ]

  configs = [ ":module_context_config" ]

  deps = [
    "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_runtime:runtime",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("context_deal_test") {
  module_out_path = module_output_path
  sources = [
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include/mock_bundle_manager.cpp",
    "${aafwk_path}/frameworks/kits/ability/native/test/mock/include/sys_mgr_client_mock.cpp",
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/app_loader.cpp",
    "../app/src/ohos_application.cpp",
    "mock/include/mock_ability_manager_client.cpp",
    "unittest/context_deal_test.cpp",
  ]

  configs = [ ":module_context_config" ]

  deps = [
    "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_runtime:runtime",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

ohos_unittest("application_impl_test") {
  module_out_path = module_output_path
  sources = [
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/app_loader.cpp",
    "${aafwk_path}/frameworks/kits/appkit/native/app/src/application_context.cpp",
    "../app/src/application_impl.cpp",
    "../app/src/ohos_application.cpp",
    "unittest/application_impl_test.cpp",
  ]

  configs = [ ":module_private_config" ]

  deps = [
    "${ABILITY_INNERKITS_PATH}/uri_permission:uri_permission_mgr",
    "${aafwk_path}/frameworks/kits/ability/native:abilitykit_native",
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "${aafwk_path}/interfaces/innerkits/ability_manager:ability_manager",
    "${aafwk_path}/interfaces/innerkits/app_manager:app_manager",
    "${ability_base_path}:base",
    "${ability_base_path}:base",
    "${ability_base_path}:want",
    "${bundlefwk_inner_api_path}/appexecfwk_base:appexecfwk_base",
    "${bundlefwk_innerkits_path}/libeventhandler:libeventhandler",
    "${distributedschedule_path}/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
  ]

  external_deps = [
    "ability_base:configuration",
    "ability_runtime:runtime",
    "bundle_framework:appexecfwk_core",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

config("ability_start_setting_config") {
  visibility = [ ":*" ]
  include_dirs = [
    "${aafwk_path}/frameworks/kits/appkit/native/app/include",
    "//foundation/appexecfwk/common/log/include/",
    "//utils/native/base/include",
    "${aafwk_path}/interfaces/innerkits/ability_manager/include",
  ]
}

ohos_unittest("ability_start_setting_test") {
  module_out_path = module_output_path

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

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

  deps = [
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
    "//utils/native/base:utilsbase",
  ]

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

ohos_unittest("watchdog_test") {
  module_out_path = module_output_path

  include_dirs = [
    "${ability_base_innerapi_path}/want/include",
    "//third_party/json/include",
  ]

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

  sources = [ "unittest/watchdog_test.cpp" ]

  deps = [
    "${aafwk_path}/frameworks/kits/appkit:appkit_native",
    "//third_party/googletest:gtest_main",
    "//utils/native/base:utils",
    "//utils/native/base:utilsbase",
  ]

  external_deps = [
    "ability_base:base",
    "hiviewdfx_hilog_native:libhilog",
    "ipc:ipc_core",
  ]
}

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

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

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

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

group("moduletest") {
  testonly = true

  deps = []

  deps += [ "moduletest/ability_delegator:moduletest" ]
}
###############################################################################
