# Copyright (c) 2024 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("//base/startup/appspawn/appspawn.gni")
import("//build/test.gni")

ohos_unittest("AppSpawn_client_ut") {
  module_out_path = "appspawn/appspawn"
  deps = []
  if (appspawn_unittest_coverage) {
    cflags = [ "--coverage" ]
    ldflags = [ "--coverage" ]
    cflags_cc = [ "--coverage" ]
  }
  defines = [
    "APPSPAWN_BASE_DIR=\"/data/appspawn_ut\"",
    "APPSPAWN_TEST",
    "APPSPAWN_CLIENT",
    "OHOS_DEBUG",
    "USER_TIMER_TO_CHECK",
    "APPSPAWN_LABEL=\"APPSPAWN_CLENT_UT\"",
  ]

  include_dirs = [
    "${appspawn_path}",
    "${appspawn_path}/common",
    "${appspawn_path}/standard",
    "${appspawn_path}/modules/modulemgr",
    "${appspawn_path}/modules/ace_adapter",
    "${appspawn_path}/modules/common",
    "${appspawn_path}/modules/sandbox",
    "${appspawn_path}/modules/sandbox/normal",
    "${appspawn_path}/modules/module_engine/include",
    "${appspawn_path}/modules/sysevent",
    "${appspawn_innerkits_path}/client",
    "${appspawn_innerkits_path}/include",
    "${appspawn_innerkits_path}/permission",
    "${appspawn_path}/util/include",
    "${appspawn_path}/test/unittest",
    "${appspawn_path}/test/mock",
  ]

  # client
  sources = [
    "${appspawn_innerkits_path}/client/appspawn_client.c",
    "${appspawn_innerkits_path}/client/appspawn_msg.c",
    "${appspawn_innerkits_path}/permission/appspawn_mount_permission.c",
    "${appspawn_path}/modules/sandbox/appspawn_permission.c",
  ]

  # server
  sources += [
    "${appspawn_path}/common/appspawn_server.c",
    "${appspawn_path}/common/appspawn_trace.cpp",
    "${appspawn_path}/modules/common/appspawn_dfx_dump.cpp",
    "${appspawn_path}/modules/modulemgr/appspawn_modulemgr.c",
    "${appspawn_path}/standard/appspawn_appmgr.c",
      "${appspawn_path}/standard/appspawn_fd_manager.c",
    "${appspawn_path}/standard/appspawn_msgmgr.c",
    "${appspawn_path}/standard/appspawn_service.c",
    "${appspawn_path}/util/src/appspawn_utils.c",
    "${appspawn_path}/util/src/appspawndf_utils.cpp",
  ]

  sources += [
    "${appspawn_path}/test/unittest/app_spawn_client_test/app_spawn_client_test.cpp",
    "${appspawn_path}/test/unittest/app_spawn_client_test/app_spawn_interface_test.cpp",
    "${appspawn_path}/test/unittest/app_spawn_test_helper.cpp",
  ]

  if (defined(appspawn_sandbox_new) && appspawn_sandbox_new) {
    defines += [ "APPSPAWN_SANDBOX_NEW" ]
  }

  if (asan_detector || is_asan) {
    defines += [ "ASAN_DETECTOR" ]
  }
  external_deps = [
    "cJSON:cjson",
    "c_utils:utils",
    "config_policy:configpolicy_util",
    "ffrt:libffrt",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
  ]

  if (appspawn_hitrace_option == true) {
    defines += [ "APPSPAWN_HITRACE_OPTION" ]
    external_deps += [ "hitrace:libhitrace_option" ]
  }

  if (enable_appspawn_dump_catcher) {
    external_deps += [ "faultloggerd:libdfx_dumpcatcher" ]
  }
  if (appspawn_report_event) {
    external_deps += [ "hisysevent:libhisysevent" ]
    sources += [
      "${appspawn_path}/modules/sysevent/hisysevent_adapter.cpp",
    ]
  }
  if (build_selinux) {
    defines += [ "WITH_SELINUX" ]
    external_deps += [
      "selinux:libselinux",
      "selinux_adapter:libhap_restorecon",
    ]
  }
}