# 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/filemanagement/dfs_service/distributedfile.gni")

ohos_unittest("battery_status_listener_test") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = true
    blocklist = "${distributedfile_path}/cfi_blocklist.txt"
  }
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/services/cloudsyncservice/src/sync_rule/battery_status_listener.cpp",
    "battery_status_listener_test.cpp",
  ]

  include_dirs = [
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${media_library_path}/interfaces/inner_api/media_library_helper/include",
    "${media_library_path}/frameworks/utils/include",
  ]

  deps = [
    "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit",
    "${services_path}/cloudsyncservice:cloudsync_sa_static",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "netmanager_base:net_conn_manager_if",
    "relational_store:native_rdb",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  defines = [ "private=public" ]
  if (cloudsync_service_resource_schedule) {
    external_deps += [ "resource_schedule_service:ressched_client" ]
    defines += [ "CLOUDSYNC_SERVICE_RESOURCE_SCHEDULE" ]
  }
  use_exceptions = true
}

ohos_unittest("net_conn_callback_observer_test") {
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/services/cloudsyncservice/src/sync_rule/net_conn_callback_observer.cpp",
    "net_conn_callback_observer_test.cpp",
  ]

  include_dirs = [
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
  ]

  deps = [
    "${services_path}/cloudsyncservice:cloudsync_sa_static",
    "${utils_path}:libdistributedfiledentry",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "netmanager_base:net_conn_manager_if",
    "relational_store:native_rdb",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  defines = [ "private=public" ]

  use_exceptions = true
}

ohos_unittest("network_status_test") {
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/data_sync_manager.cpp",
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/net_conn_callback_observer.cpp",
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_status.cpp",
    "${distributedfile_path}/test/unittests/cloudsync_sa/mock/network_set_manager_mock.cpp",
    "network_status_test.cpp",
  ]

  include_dirs = [
    "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner",
    "${innerkits_native_path}/cloud_file_kit_inner",
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
    "${media_library_path}/interfaces/inner_api/media_library_helper/include",
    "${media_library_path}/frameworks/utils/include",
  ]

  deps = [
    "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "data_share:datashare_consumer",
    "dfs_service:cloudsync_kit_inner",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "netmanager_base:net_conn_manager_if",
    "relational_store:native_rdb",
    "samgr:samgr_proxy",
  ]

  defines = [ "private=public" ]
  if (cloudsync_service_resource_schedule) {
    external_deps += [ "resource_schedule_service:ressched_client" ]
    defines += [ "CLOUDSYNC_SERVICE_RESOURCE_SCHEDULE" ]
  }
  use_exceptions = true
}

ohos_unittest("cloud_status_test") {
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/cloud_status.cpp",
    "${distributedfile_path}/utils/log/src/dfs_error.cpp",
    "cloud_status_test.cpp",
  ]

  include_dirs = [
    "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner",
    "${services_path}/cloudsyncservice/include",
    "${media_library_path}/frameworks/utils/include",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
  ]

  deps = [
    "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit",
    "${innerkits_native_path}/cloudsync_kit_inner:cloudsync_kit_inner",
    "${services_path}/cloudsyncservice:cloudsync_sa_static",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "c_utils:utils",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
  ]

  defines = [ "private=public" ]

  use_exceptions = true
}

ohos_unittest("battery_status_test") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = true
    blocklist = "${distributedfile_path}/cfi_blocklist.txt"
  }
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/battery_status.cpp",
    "battery_status_test.cpp",
  ]

  include_dirs = [
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
    "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${media_library_path}/interfaces/inner_api/media_library_helper/include",
    "${media_library_path}/frameworks/utils/include",
  ]

  deps = [
    "${services_path}/cloudsyncservice:cloudsync_sa_static",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:want",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "netmanager_base:net_conn_manager_if",
    "relational_store:native_rdb",
    "safwk:system_ability_fwk",
    "samgr:samgr_proxy",
  ]

  defines = [
    "private=public",
    "LOG_DOMAIN=0xD004310",
    "LOG_TAG=\"CLOUD_SYNC_TEST\"",
  ]

  use_exceptions = true
}

ohos_unittest("network_set_manager_test") {
  branch_protector_ret = "pac_ret"
  sanitize = {
    ubsan = true
    boundary_sanitize = true
    cfi = true
    cfi_cross_dso = true
    debug = true
    blocklist = "${distributedfile_path}/cfi_blocklist.txt"
  }

  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/network_set_manager.cpp",
    "${distributedfile_path}/test/unittests/cloudsync_sa/mock/datashare_helper.cpp",
    "network_set_manager_test.cpp",
  ]

  include_dirs = [
    "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner",
    "${distributedfile_path}/test/unittests/cloudsync_sa/mock",
    "${innerkits_native_path}/cloud_file_kit_inner",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
    "${media_library_path}/interfaces/inner_api/media_library_helper/include",
    "${media_library_path}/frameworks/utils/include",
  ]

  deps = [
    "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "ability_base:zuri",
    "ability_runtime:dataobs_manager",
    "access_token:libtokenid_sdk",
    "c_utils:utils",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "ipc:ipc_single",
    "safwk:system_ability_fwk",
  ]

  defines = [ "private=public" ]

  use_exceptions = true
}

ohos_unittest("system_load_test") {
  module_out_path = "filemanagement/dfs_service"
  sources = [
    "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/sync_rule/system_load.cpp",
    "system_load_test.cpp",
  ]

  include_dirs = [
    "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner",
    "${innerkits_native_path}/cloud_file_kit_inner",
    "${services_path}/cloudsyncservice/include",
    "${services_path}/cloudsyncservice/include/sync_rule",
    "${utils_path}/log/include",
    "${image_framework_path}/mock/native/include/log",
    "${innerkits_native_path}/cloudsync_kit_inner",
    "${distributedfile_path}/adapter/cloud_adapter_example/include",
    "${media_library_path}/interfaces/inner_api/media_library_helper/include",
    "${media_library_path}/frameworks/utils/include",
  ]

  deps = [
    "${innerkits_native_path}/cloud_file_kit_inner:cloudfile_kit",
    "${utils_path}:libdistributedfileutils",
    "//third_party/googletest:gmock_main",
    "//third_party/googletest:gtest_main",
  ]

  external_deps = [
    "access_token:libaccesstoken_sdk",
    "access_token:libtokenid_sdk",
    "c_utils:utils",
    "common_event_service:cesfwk_innerkits",
    "data_share:datashare_consumer",
    "dfs_service:cloudsync_kit_inner",
    "ffrt:libffrt",
    "hilog:libhilog",
    "hisysevent:libhisysevent",
    "init:libbegetutil",
    "ipc:ipc_core",
    "netmanager_base:net_conn_manager_if",
    "relational_store:native_rdb",
    "resource_schedule_service:ressched_client",
    "samgr:samgr_proxy",
  ]

  defines = [ "private=public" ]

  use_exceptions = true
}

group("cloudsync_sa_sync_rule_test") {
  testonly = true
  deps = [
    ":battery_status_listener_test",
    ":battery_status_test",
    ":cloud_status_test",
    ":network_set_manager_test",
    ":network_status_test",
    ":system_load_test",
  ]
}