# Copyright (c) 2021 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("//foundation/arkui/napi/napi.gni")

import("//build/config/components/ace_engine/ace_gen_obj.gni")
import("//build/test.gni")
import("//foundation/arkui/napi/test/unittest/ut.gni")

config("ace_napi_unittest_config") {
  include_dirs = common_include
  cflags = [ "-g3" ]
  defines = [ "NAPI_TEST" ]
  if (!is_mingw && !is_mac && !is_linux && is_ohos_standard_system) {
    defines += [ "ENABLE_EVENT_HANDLER" ]
  }
}

template("test_ark_unittest") {
  assert(defined(invoker.target_name), "Must provides a target_name")
  assert(defined(invoker.sources), "Must provides test sources")

  ohos_unittest("test_ark_unittest_${target_name}") {
    module_out_path = module_output_path
    configs = [ ":ace_napi_unittest_config" ]

    sources = [ "engine/test_ark.cpp" ]
    sources += invoker.sources

    deps = [ "../..:ace_napi" ]
    external_deps = [
      "bounds_checking_function:libsec_shared",
      "c_utils:utils",
      "eventhandler:libeventhandler",
      "googletest:gtest",
      "googletest:gtest_main",
      "hilog:libhilog",
      "libuv:uv",
    ]
  }
}

test_ark_unittest("base") {
  sources = [
    "test_napi.cpp",
    "test_napi_context.cpp",
    "test_napi_global_ref_track.cpp",
    "test_sendable_napi.cpp",
  ]
}

test_ark_unittest("hybrid") {
  sources = [ "test_napi_hybrid.cpp" ]
}

test_ark_unittest("idle_monitor") {
  sources = [ "test_ark_idle_monitor.cpp" ]
}

test_ark_unittest("threadsafe") {
  sources = [ "test_napi_threadsafe.cpp" ]
}

ohos_unittest("test_unittest_sendevent") {
  module_out_path = module_output_path

  configs = [ ":ace_napi_unittest_config" ]
  sources = [
    "engine/test_ark.cpp",
    "test_napi_sendevent.cpp",
  ]

  deps = [ "../..:ace_napi" ]

  external_deps = [
    "bounds_checking_function:libsec_shared",
    "c_utils:utils",
    "eventhandler:libeventhandler",
    "googletest:gtest",
    "googletest:gtest_main",
    "hilog:libhilog",
    "libuv:uv",
  ]
}

ohos_unittest("test_worker_manager") {
  module_out_path = module_output_path

  cflags = [ "-g3" ]

  sources = [ "test_worker_manager.cpp" ]

  defines = [ "NAPI_TEST" ]

  deps = [ "../..:ace_napi" ]

  external_deps = [
    "googletest:gtest",
    "googletest:gtest_main",
    "hilog:libhilog",
  ]
}

test_ark_unittest("errorcode") {
  sources = [
    "test_napi_errorcode.cpp",
    "test_napi_pendingexception.cpp",
  ]
}

test_ark_unittest("critical") {
  sources = [ "test_napi_critical.cpp" ]
}

test_ark_unittest("hook_list") {
  sources = [ "test_ark_hook_list.cpp" ]
}

group("unittest") {
  testonly = true
  deps = [
    ":test_ark_unittest_base",
    ":test_ark_unittest_critical",
    ":test_ark_unittest_errorcode",
    ":test_ark_unittest_hybrid",
    ":test_ark_unittest_hook_list",
    ":test_ark_unittest_idle_monitor",
    ":test_ark_unittest_threadsafe",
    ":test_unittest_sendevent",
    ":test_worker_manager",
    "cj_native:cj_native_unittest",
  ]
}