# 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("./../../../usbmgr.gni")

declare_args() {
  usb_manage_feature_support_port_change = false
}

module_output_path = "${usb_manager_part_name}/usb_unittest_test"

config("module_private_config") {
  visibility = [ ":*" ]

  include_dirs = [
    "include",
    "${usb_manager_path}/test/common/include/",
  ]
}

ohos_unittest("test_usbdevicepipe") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_device_pipe_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_bulkcallback") {
  module_out_path = module_output_path
  sources = [
    "${usb_manager_path}/test/common/src/usb_callback_test.cpp",
    "src/usb_bulkcallback_test.cpp",
    "src/usb_common_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_usbrequest") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_request_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_usbcore") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_core_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_usbevent") {
  module_out_path = module_output_path
  sources = [ "src/usb_event_test.cpp" ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/cJSON:cjson",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  if (usb_manage_feature_support_port_change) {
    if (defined(defines)) {
      defines += [ "SUPPORT_PORT_CHNAGE_TEST" ]
    } else {
      defines = [ "SUPPORT_PORT_CHNAGE_TEST" ]
    }
  }
}

ohos_unittest("test_usbmanageinterface") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_manage_interface_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_usbdevicestatus") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_device_status_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.1",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("test_usbdfx") {
  module_out_path = module_output_path
  sources = [
    "src/usb_common_test.cpp",
    "src/usb_dfx_test.cpp",
  ]

  configs = [
    "${utils_path}:utils_config",
    ":module_private_config",
  ]

  deps = [
    "${usb_manager_path}/interfaces/innerkits:usbsrv_client",
    "${usb_manager_path}/services:usbservice",
    "//third_party/cJSON:cjson",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "access_token:libaccesstoken_sdk",
    "access_token:libnativetoken",
    "access_token:libtoken_setproc",
    "bundle_framework:appexecfwk_base",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "drivers_interface_usb:libusb_proxy_1.0",
    "eventhandler:libeventhandler",
    "hilog:libhilog",
    "ipc:ipc_core",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

group("unittest") {
  testonly = true
  deps = [
    ":test_bulkcallback",
    ":test_usbcore",
    ":test_usbdevicepipe",
    ":test_usbdevicestatus",
    ":test_usbdfx",
    ":test_usbevent",
    ":test_usbmanageinterface",
    ":test_usbrequest",
  ]
}