# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
#
# Use of this source code is governed by a BSD-style license
# that can be found in the LICENSE file in the root of the source
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS.  All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.

import("../../webrtc.gni")
if (rtc_enable_protobuf) {
  import("//third_party/protobuf/proto_library.gni")
}

if (rtc_enable_protobuf) {
  proto_library("network_tester_config_proto") {
    sources = [ "network_tester_config.proto" ]
    proto_out_dir = "rtc_tools/network_tester"
  }

  proto_library("network_tester_packet_proto") {
    sources = [ "network_tester_packet.proto" ]
    proto_out_dir = "rtc_tools/network_tester"
  }

  rtc_library("network_tester") {
    sources = [
      "config_reader.cc",
      "config_reader.h",
      "packet_logger.cc",
      "packet_logger.h",
      "packet_sender.cc",
      "packet_sender.h",
      "test_controller.cc",
      "test_controller.h",
    ]

    defines = [ "WEBRTC_NETWORK_TESTER_PROTO" ]

    deps = [
      ":network_tester_config_proto",
      ":network_tester_packet_proto",
      "../../api:sequence_checker",
      "../../api/task_queue",
      "../../api/task_queue:default_task_queue_factory",
      "../../api/task_queue:pending_task_safety_flag",
      "../../api/units:timestamp",
      "../../p2p:rtc_p2p",
      "../../rtc_base:async_packet_socket",
      "../../rtc_base:checks",
      "../../rtc_base:ip_address",
      "../../rtc_base:logging",
      "../../rtc_base:macromagic",
      "../../rtc_base:protobuf_utils",
      "../../rtc_base:rtc_task_queue",
      "../../rtc_base:socket_address",
      "../../rtc_base:socket_server",
      "../../rtc_base:threading",
      "../../rtc_base:timeutils",
      "../../rtc_base/network:received_packet",
      "../../rtc_base/synchronization:mutex",
      "../../rtc_base/system:no_unique_address",
    ]
    absl_deps = [
      "//third_party/abseil-cpp/absl/functional:any_invocable",
      "//third_party/abseil-cpp/absl/types:optional",
    ]
  }

  network_tester_unittests_resources = [
    "../../resources/network_tester/client_config.dat",
    "../../resources/network_tester/server_config.dat",
  ]

  if (is_ios) {
    bundle_data("network_tester_unittests_bundle_data") {
      testonly = true
      sources = network_tester_unittests_resources
      outputs = [ "{{bundle_resources_dir}}/{{source_file_part}}" ]
    }
  }

  rtc_library("network_tester_unittests") {
    testonly = true

    sources = [ "network_tester_unittest.cc" ]

    deps = [
      ":network_tester",
      "../../rtc_base:gunit_helpers",
      "../../rtc_base:random",
      "../../rtc_base:threading",
      "../../test:fileutils",
      "../../test:test_support",
      "//testing/gtest",
    ]

    if (is_ios) {
      deps += [ ":network_tester_unittests_bundle_data" ]
    }

    defines = [ "WEBRTC_NETWORK_TESTER_TEST_ENABLED" ]

    data = network_tester_unittests_resources
  }

  rtc_executable("network_tester_server") {
    sources = [ "server.cc" ]

    deps = [
      ":network_tester",
      "../../rtc_base:null_socket_server",
      "../../rtc_base:threading",
    ]
  }
}

if (is_android) {
  rtc_android_apk("NetworkTesterMobile") {
    testonly = true
    apk_name = "NetworkTesterMobile"
    android_manifest = "androidapp/AndroidManifest.xml"
    min_sdk_version = 21
    target_sdk_version = 24

    deps = [
      ":NetworkTesterMobile_javalib",
      ":NetworkTesterMobile_resources",
      "../../rtc_base:base_java",
    ]

    shared_libraries = [ "../../rtc_tools/network_tester:network_tester_so" ]
  }

  rtc_android_library("NetworkTesterMobile_javalib") {
    testonly = true
    android_manifest = "androidapp/AndroidManifest.xml"

    sources = [
      "androidapp/src/com/google/media/networktester/MainActivity.java",
      "androidapp/src/com/google/media/networktester/NetworkTester.java",
    ]

    resources_package = "com.google.media.networktester"
    deps = [
      ":NetworkTesterMobile_resources",
      "../../rtc_base:base_java",
    ]
  }

  android_resources("NetworkTesterMobile_resources") {
    testonly = true
    custom_package = "com.google.media.networktester"
    sources = [
      "androidapp/res/layout/activity_main.xml",
      "androidapp/res/mipmap-hdpi/ic_launcher.png",
      "androidapp/res/mipmap-mdpi/ic_launcher.png",
      "androidapp/res/mipmap-xhdpi/ic_launcher.png",
      "androidapp/res/mipmap-xxhdpi/ic_launcher.png",
      "androidapp/res/mipmap-xxxhdpi/ic_launcher.png",
      "androidapp/res/values-v17/styles.xml",
      "androidapp/res/values-w820dp/dimens.xml",
      "androidapp/res/values/colors.xml",
      "androidapp/res/values/dimens.xml",
      "androidapp/res/values/strings.xml",
    ]

    # Needed for Bazel converter.
    resource_dirs = [ "androidapp/res" ]
    assert(resource_dirs != [])  # Mark as used.
  }

  rtc_shared_library("network_tester_so") {
    sources = [ "jni.cc" ]

    deps = [
      ":network_tester",
      "../../rtc_base:logging",
      "../../rtc_base:threading",
    ]

    suppressed_configs += [ "//build/config/android:hide_all_but_jni_onload" ]
    configs += [ "//build/config/android:hide_all_but_jni" ]

    output_extension = "so"
  }
}
