# Copyright 2018 The PDFium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build_overrides/build.gni")
import("../../pdfium.gni")
import("../../testing/test.gni")

source_set("fxcrt") {
  visibility = [
    "../*",
    "../../:*",
    "../../fpdfsdk/*",
    "../../fxbarcode:*",
    "../../fxjs:*",
    "../../testing:*",
    "../../testing/fuzzers/*",
    "../../testing/image_diff/*",
    "../../third_party:fx_agg",
    "../../third_party:fx_lcms2",
    "../../third_party:fx_libopenjpeg",
    "../../third_party:fx_tiff",
    "../../xfa/*",
  ]
  sources = [
    "autonuller.h",
    "autorestorer.h",
    "binary_buffer.cpp",
    "binary_buffer.h",
    "byteorder.h",
    "bytestring.cpp",
    "bytestring.h",
    "cfx_bitstream.cpp",
    "cfx_bitstream.h",
    "cfx_datetime.cpp",
    "cfx_datetime.h",
    "cfx_read_only_span_stream.cpp",
    "cfx_read_only_span_stream.h",
    "cfx_read_only_string_stream.cpp",
    "cfx_read_only_string_stream.h",
    "cfx_read_only_vector_stream.cpp",
    "cfx_read_only_vector_stream.h",
    "cfx_seekablestreamproxy.cpp",
    "cfx_seekablestreamproxy.h",
    "cfx_timer.cpp",
    "cfx_timer.h",
    "check.h",
    "check_op.h",
    "code_point_view.h",
    "component_export.h",
    "containers/adapters.h",
    "containers/contains.h",
    "data_vector.h",
    "debug/alias.cc",
    "debug/alias.h",
    "fileaccess_iface.h",
    "fixed_size_data_vector.h",
    "fx_2d_size.h",
    "fx_bidi.cpp",
    "fx_bidi.h",
    "fx_codepage.cpp",
    "fx_codepage.h",
    "fx_codepage_forward.h",
    "fx_coordinates.cpp",
    "fx_coordinates.h",
    "fx_extension.cpp",
    "fx_extension.h",
    "fx_folder.h",
    "fx_memcpy_wrappers.h",
    "fx_memory.cpp",
    "fx_memory.h",
    "fx_memory_wrappers.h",
    "fx_number.cpp",
    "fx_number.h",
    "fx_random.cpp",
    "fx_random.h",
    "fx_safe_types.h",
    "fx_stream.cpp",
    "fx_stream.h",
    "fx_string.cpp",
    "fx_string.h",
    "fx_string_wrappers.h",
    "fx_system.cpp",
    "fx_system.h",
    "fx_types.h",
    "fx_unicode.cpp",
    "fx_unicode.h",
    "immediate_crash.h",
    "mask.h",
    "maybe_owned.h",
    "notreached.h",
    "numerics/checked_math.h",
    "numerics/checked_math_impl.h",
    "numerics/clamped_math.h",
    "numerics/clamped_math_impl.h",
    "numerics/safe_conversions.h",
    "numerics/safe_conversions_arm_impl.h",
    "numerics/safe_conversions_impl.h",
    "numerics/safe_math.h",
    "numerics/safe_math_arm_impl.h",
    "numerics/safe_math_clang_gcc_impl.h",
    "numerics/safe_math_shared_impl.h",
    "observed_ptr.cpp",
    "observed_ptr.h",
    "pauseindicator_iface.h",
    "ptr_util.h",
    "raw_span.h",
    "retain_ptr.h",
    "scoped_set_insertion.h",
    "shared_copy_on_write.h",
    "span.h",
    "span_util.h",
    "stl_util.h",
    "string_data_template.cpp",
    "string_data_template.h",
    "string_pool_template.h",
    "string_template.cpp",
    "string_template.h",
    "string_view_template.h",
    "template_util.h",
    "tree_node.h",
    "unowned_ptr.h",
    "utf16.h",
    "weak_ptr.h",
    "widestring.cpp",
    "widestring.h",
    "widetext_buffer.cpp",
    "widetext_buffer.h",
    "xml/cfx_xmlchardata.cpp",
    "xml/cfx_xmlchardata.h",
    "xml/cfx_xmldocument.cpp",
    "xml/cfx_xmldocument.h",
    "xml/cfx_xmlelement.cpp",
    "xml/cfx_xmlelement.h",
    "xml/cfx_xmlinstruction.cpp",
    "xml/cfx_xmlinstruction.h",
    "xml/cfx_xmlnode.cpp",
    "xml/cfx_xmlnode.h",
    "xml/cfx_xmlparser.cpp",
    "xml/cfx_xmlparser.h",
    "xml/cfx_xmltext.cpp",
    "xml/cfx_xmltext.h",
    "zip.h",
  ]
  configs += [
    "../../:pdfium_strict_config",
    "../../:pdfium_noshorten_config",
  ]
  deps = [ "//third_party/fast_float" ]
  public_deps = [
    "../../:freetype_common",
    "//third_party/abseil-cpp:absl",
    "//third_party/icu:icuuc",
  ]
  if (pdf_use_partition_alloc) {
    sources += [ "fx_memory_pa.cpp" ]
    public_deps += [ "../../third_party:pdfium_pa" ]
  } else {
    sources += [ "fx_memory_malloc.cpp" ]
  }
  if (is_posix) {
    sources += [
      "cfx_fileaccess_posix.cpp",
      "cfx_fileaccess_posix.h",
      "fx_folder_posix.cpp",
    ]
  }
  if (is_win) {
    sources += [
      "cfx_fileaccess_windows.cpp",
      "cfx_fileaccess_windows.h",
      "code_point_view.cpp",
      "fx_folder_windows.cpp",
      "win/scoped_select_object.h",
      "win/win_util.cc",
      "win/win_util.h",
    ]
  }
  if (pdf_enable_xfa) {
    sources += [
      "cfx_memorystream.cpp",
      "cfx_memorystream.h",
    ]
  }
}

source_set("test_support") {
  testonly = true
  sources = [
    "fx_coordinates_test_support.cpp",
    "fx_coordinates_test_support.h",
    "string_test_support.cpp",
  ]
  configs += [ "../../:pdfium_strict_config" ]
  deps = [ ":fxcrt" ]
}

source_set("unit_test_support") {
  testonly = true
  sources = [
    "fake_time_test.cpp",
    "fake_time_test.h",
  ]
  configs += [ "../../:pdfium_strict_config" ]
  deps = [
    ":fxcrt",
    ":test_support",
    "//testing/gtest",
  ]
}

pdfium_unittest_source_set("unittests") {
  sources = [
    "autonuller_unittest.cpp",
    "autorestorer_unittest.cpp",
    "binary_buffer_unittest.cpp",
    "byteorder_unittest.cpp",
    "bytestring_unittest.cpp",
    "cfx_bitstream_unittest.cpp",
    "cfx_datetime_unittest.cpp",
    "cfx_seekablestreamproxy_unittest.cpp",
    "cfx_timer_unittest.cpp",
    "code_point_view_unittest.cpp",
    "fixed_size_data_vector_unittest.cpp",
    "fx_bidi_unittest.cpp",
    "fx_coordinates_unittest.cpp",
    "fx_extension_unittest.cpp",
    "fx_memcpy_wrappers_unittest.cpp",
    "fx_memory_unittest.cpp",
    "fx_memory_wrappers_unittest.cpp",
    "fx_number_unittest.cpp",
    "fx_random_unittest.cpp",
    "fx_safe_types_unittest.cpp",
    "fx_string_unittest.cpp",
    "fx_string_wrappers_unittest.cpp",
    "fx_system_unittest.cpp",
    "mask_unittest.cpp",
    "maybe_owned_unittest.cpp",
    "observed_ptr_unittest.cpp",
    "pdfium_span_unittest.cpp",
    "retain_ptr_unittest.cpp",
    "scoped_set_insertion_unittest.cpp",
    "shared_copy_on_write_unittest.cpp",
    "span_util_unittest.cpp",
    "stl_util_unittest.cpp",
    "string_pool_template_unittest.cpp",
    "tree_node_unittest.cpp",
    "unowned_ptr_unittest.cpp",
    "utf16_unittest.cpp",
    "weak_ptr_unittest.cpp",
    "widestring_unittest.cpp",
    "widetext_buffer_unittest.cpp",
    "xml/cfx_xmlchardata_unittest.cpp",
    "xml/cfx_xmldocument_unittest.cpp",
    "xml/cfx_xmlelement_unittest.cpp",
    "xml/cfx_xmlinstruction_unittest.cpp",
    "xml/cfx_xmlnode_unittest.cpp",
    "xml/cfx_xmlparser_unittest.cpp",
    "xml/cfx_xmltext_unittest.cpp",
    "zip_unittest.cpp",
  ]
  deps = [
    ":test_support",
    ":unit_test_support",
  ]
  pdfium_root_dir = "../../"
  if (pdf_use_partition_alloc) {
    deps += [ "//base/allocator/partition_allocator/src/partition_alloc" ]
  }
  if (pdf_enable_xfa) {
    sources += [ "cfx_memorystream_unittest.cpp" ]
    deps += [ "../fpdfapi/parser" ]
  }
}
