# Copyright (c) 2023 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/multimedia/av_codec/config.gni")

module_output_path = "av_codec/av_codec/unittest"
dash_test_sources = [
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/base64/base64_utils.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/dash_media_downloader.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/dash_mpd_downloader.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/dash_segment_downloader.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_adpt_set_manager.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_generic_node.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/i_dash_mpd_node.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_manager_util.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_manager.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_parser.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_mpd_util.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_period_manager.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/dash_representation_manager.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/mpd_parser/sidx_box_parser.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/app_client.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/downloader.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/media_source_loading_request.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download/network_client/http_curl_client.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/xml/xml_element.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/xml/xml_parser.cpp",
  "$av_codec_root_dir/test/unittest/common/http_server_demo.cpp",
  "$av_codec_root_dir/services/media_engine/plugins/source/http_source/utils/string_utils.cpp",
]
config("dash_unittest_cfg") {
  defines = [
    "HST_ANY_WITH_NO_RTTI",
    "MEDIA_OHOS",
  ]

  cflags = [
    "-Wno-sign-compare",
    "-fno-exceptions",
    "-fno-common",
    "-fstack-protector-all",
    "-Wshadow",
    "-FPIC",
    "-FS",
    "-O2",
    "-D_FORTIFY_SOURCE=2",
    "-Wformat=2",
    "-Wdate-time",
    "-Dprivate=public",
    "-Dprotected=public",
  ]

  cflags_cc = [
    "-std=c++17",
    "-fno-rtti",
  ]

  include_dirs = [
    "$av_codec_root_dir/interfaces",
    "$av_codec_root_dir/interfaces/inner_api/native",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/download",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/xml",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/base64",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include",
    "$av_codec_root_dir/services/media_engine/plugins/source/http_source/dash/include/mpd_parser",
    "$av_codec_root_dir/test/unittest/common",
  ]
}

ohos_unittest("dash_xml_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_xml_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("dash_mpd_parser_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_mpd_parser_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}

ohos_unittest("dash_media_downloader_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_media_downloader_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  resource_config_file =
      "$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
}

ohos_unittest("dash_mpd_downloader_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_mpd_downloader_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  resource_config_file =
      "$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
}

ohos_unittest("dash_segment_downloader_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_segment_downloader_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  resource_config_file =
      "$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
}

ohos_unittest("dash_adpt_set_manager_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "dash_adpt_set_manager_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  cflags = [
    "-Dprivate=public",
    "-Dprotected=public",
  ]

  resource_config_file =
      "$av_codec_root_dir/test/unittest/resources/ohos_test.xml"
}

ohos_unittest("sidx_box_parser_unit_test") {
  module_out_path = module_output_path
  testonly = true
  configs = [
    ":dash_unittest_cfg",
    "$av_codec_root_dir/services/dfx:av_codec_service_log_dfx_public_config",
  ]
  sources = dash_test_sources + [ "sidx_box_parser_unit_test.cpp" ]
  deps = [ "$av_codec_root_dir/services/dfx:av_codec_service_dfx" ]

  external_deps = [
    "c_utils:utils",
    "certificate_manager:cert_manager_sdk",
    "curl:curl_shared",
    "graphic_surface:surface",
    "hilog:libhilog",
    "hitrace:hitrace_meter",
    "init:libbegetutil",
    "ipc:ipc_single",
    "libxml2:libxml2",
    "media_foundation:media_foundation",
    "netmanager_base:net_conn_manager_if",
    "openssl:libcrypto_shared",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]
}