1# Copyright (c) 2023-2024 Huawei Device Co., Ltd.
2# Licensed under the Apache License, Version 2.0 (the "License");
3# you may not use this file except in compliance with the License.
4# You may obtain a copy of the License at
5#
6#     http://www.apache.org/licenses/LICENSE-2.0
7#
8# Unless required by applicable law or agreed to in writing, software
9# distributed under the License is distributed on an "AS IS" BASIS,
10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14import("//build/ohos.gni")
15import("//build/test.gni")
16import("//foundation/communication/netstack/netstack_config.gni")
17
18NETSTACK_NAPI_ROOT = "$SUBSYSTEM_DIR/netstack/frameworks/js/napi/"
19
20utils_include = [
21  "$SUBSYSTEM_DIR/netstack/utils/common_utils/include",
22  "$SUBSYSTEM_DIR/netstack/utils/http_over_curl/include",
23  "$SUBSYSTEM_DIR/netstack/utils/log/include",
24  "$THIRD_PARTY_ROOT/curl/include",
25]
26
27common_external_deps = [
28  "c_utils:utils",
29  "hilog:libhilog",
30]
31
32ohos_unittest("http_unittest") {
33  sanitize = {
34    cfi = true
35    cfi_cross_dso = true
36    debug = false
37  }
38
39  branch_protector_ret = "pac_ret"
40
41  module_out_path = "netstack/http_unittest"
42
43  include_dirs = [
44    "$NETSTACK_NAPI_ROOT/http/async_context/include",
45    "$NETSTACK_NAPI_ROOT/http/async_work/include",
46    "$NETSTACK_NAPI_ROOT/http/cache/base64/include",
47    "$NETSTACK_NAPI_ROOT/http/cache/cache_constant/include",
48    "$NETSTACK_NAPI_ROOT/http/cache/cache_proxy/include",
49    "$NETSTACK_NAPI_ROOT/http/cache/cache_strategy/include",
50    "$NETSTACK_NAPI_ROOT/http/cache/lru_cache/include",
51    "$NETSTACK_NAPI_ROOT/http/constant/include",
52    "$NETSTACK_NAPI_ROOT/http/http_exec/include",
53    "$NETSTACK_NAPI_ROOT/http/http_module/include",
54    "$NETSTACK_NAPI_ROOT/http/options/include",
55    "$SUBSYSTEM_DIR/netstack/utils/profiler_utils/include",
56    "$SUBSYSTEM_DIR/netstack/utils/tlv_utils/include",
57    "$THIRD_PARTY_ROOT/curl/include",
58  ]
59  include_dirs += utils_include
60
61  if (defined(global_parts_info) &&
62      defined(global_parts_info.communication_netmanager_base) &&
63      global_parts_info.communication_netmanager_base) {
64    include_dirs += [
65      "$NETMANAGER_BASE_INNERKITS_DIR/include",
66      "$NETMANAGER_BASE_INNERKITS_DIR/netconnclient/include",
67    ]
68  }
69
70  external_deps = common_external_deps
71  external_deps += [ "curl:curl_shared" ]
72  sources = [
73    "$NETSTACK_NAPI_ROOT/http/async_context/src/request_context.cpp",
74    "$NETSTACK_NAPI_ROOT/http/constant/src/constant.cpp",
75    "$NETSTACK_NAPI_ROOT/http/http_exec/src/http_exec.cpp",
76    "$NETSTACK_NAPI_ROOT/http/options/src/http_request_options.cpp",
77    "$NETSTACK_NAPI_ROOT/http/options/src/http_response.cpp",
78    "$SUBSYSTEM_DIR/netstack/utils/common_utils/src/netstack_common_utils.cpp",
79    "$SUBSYSTEM_DIR/netstack/utils/http_over_curl/src/epoll_request_handler.cpp",
80    "$SUBSYSTEM_DIR/netstack/utils/profiler_utils/src/netstack_network_profiler.cpp",
81    "$SUBSYSTEM_DIR/netstack/utils/tlv_utils/src/tlv_utils.cpp",
82    "HttpExecTest.cpp",
83    "HttpRequestOptionsTest.cpp",
84  ]
85
86  deps = [ "$SUBSYSTEM_DIR/netstack/utils/napi_utils:napi_utils" ]
87  if (is_mingw || is_mac) {
88    sources +=
89        [ "$NETSTACK_DIR/utils/common_utils/src/netstack_common_utils.cpp" ]
90    deps += [
91      "$ARKUI_ROOT/napi:ace_napi",
92      "$NETSTACK_DIR/utils/napi_utils:napi_utils_static",
93      "$THIRD_PARTY_ROOT/bounds_checking_function:libsec_static",
94    ]
95  } else {
96    deps += [
97      "$NETSTACK_DIR/utils:stack_utils_common",
98      "$NETSTACK_DIR/utils/napi_utils:napi_utils",
99    ]
100    external_deps += [
101      "ability_runtime:wantagent_innerkits",
102      "hilog:libhilog",
103      "hiprofiler:libnetwork_profiler",
104      "hitrace:hitrace_meter",
105      "napi:ace_napi",
106      "time_service:time_client",
107    ]
108    if (netstack_http_boringssl) {
109      deps += [
110        "//vendor/open_source/boringssl:crypto_boringssl",
111        "//vendor/open_source/boringssl:ssl_boringssl",
112      ]
113    } else {
114      external_deps += [
115        "openssl:libcrypto_shared",
116        "openssl:libssl_shared",
117      ]
118    }
119    if (defined(global_parts_info) &&
120        defined(global_parts_info.communication_netmanager_base) &&
121        global_parts_info.communication_netmanager_base) {
122      external_deps += [ "netmanager_base:net_conn_manager_if" ]
123      external_deps += [ "netmanager_base:netsys_client" ]
124      defines = [ "HAS_NETMANAGER_BASE=1" ]
125    } else {
126      defines = [ "HAS_NETMANAGER_BASE=0" ]
127    }
128    if (product_name != "ohos-sdk") {
129      external_deps += [ "init:libbegetutil" ]
130    }
131  }
132
133  part_name = "netstack"
134  subsystem_name = "communication"
135}
136
137group("unittest") {
138  testonly = true
139  deps = [ ":http_unittest" ]
140}
141