1# Copyright (c) 2021-2023 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/test.gni")
15import("../../../bundletool.gni")
16
17module_output_path = "bundle_tool/tools"
18
19config("tools_bm_config_mock") {
20  include_dirs = [
21    "${inner_api_path}/appexecfwk_base/include",
22    "${inner_api_path}/appexecfwk_base/include/quick_fix",
23    "${inner_api_path}/appexecfwk_core/include/bundlemgr",
24    "${bundle_framework_path}/services/bundlemgr/include",
25    "${bundle_framework_path}/services/bundlemgr/include/quick_fix",
26    "${bundle_framework_path}/services/bundlemgr/include/rdb",
27    "${bundle_framework_path}/services/bundlemgr/include/sandbox_app",
28    "${bundle_framework_path}/services/bundlemgr/include/shared",
29    "${bundle_framework_path}/services/bundlemgr/include/uninstall_data_mgr",
30    "${bundletool_test_path}/mock",
31    "//third_party/googletest/googlemock/include",
32    "//third_party/json/single_include",
33  ]
34}
35
36tools_bm_mock_sources = [
37  "${bundletool_test_path}/mock/mock_bundle_installer_host.cpp",
38  "${bundletool_test_path}/mock/mock_bundle_mgr_host.cpp",
39]
40
41ohos_unittest("bm_command_dump_test") {
42  module_out_path = module_output_path
43
44  include_dirs = []
45
46  sources = [
47    "${bundletool_path}/src/bundle_command.cpp",
48    "${bundletool_path}/src/bundle_command_common.cpp",
49    "${bundletool_path}/src/quick_fix_command.cpp",
50    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
51    "${bundletool_path}/src/shell_command.cpp",
52    "${bundletool_path}/src/status_receiver_impl.cpp",
53    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
54    "bm_command_dump_test.cpp",
55  ]
56  sources += tools_bm_mock_sources
57
58  configs = [
59    "${bundletool_path}:tools_bm_config",
60    ":tools_bm_config_mock",
61  ]
62
63  cflags = []
64  if (target_cpu == "arm") {
65    cflags += [ "-DBINDER_IPC_32BIT" ]
66  }
67
68  deps = [
69    "${bundle_framework_path}/services/bundlemgr:libbms",
70    "//third_party/googletest:gmock_main",
71    "//third_party/googletest:gtest_main",
72  ]
73
74  external_deps = [
75    "ability_base:want",
76    "ability_runtime:app_manager",
77    "ability_runtime:quickfix_manager",
78    "access_token:libaccesstoken_sdk",
79    "appverify:libhapverify",
80    "bundle_framework:appexecfwk_base",
81    "bundle_framework:appexecfwk_core",
82    "bundle_framework:bundle_napi_common",
83    "bundle_framework:libappexecfwk_common",
84    "c_utils:utils",
85    "common_event_service:cesfwk_innerkits",
86    "eventhandler:libeventhandler",
87    "hilog:libhilog",
88    "init:libbegetutil",
89    "ipc:ipc_core",
90    "kv_store:distributeddata_inner",
91    "os_account:os_account_innerkits",
92    "relational_store:native_rdb",
93    "samgr:samgr_proxy",
94  ]
95
96  external_deps += bm_install_external_deps
97}
98
99ohos_unittest("bm_command_dump_dependencies_test") {
100  module_out_path = module_output_path
101
102  include_dirs = []
103
104  sources = [
105    "${bundletool_path}/src/bundle_command.cpp",
106    "${bundletool_path}/src/bundle_command_common.cpp",
107    "${bundletool_path}/src/quick_fix_command.cpp",
108    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
109    "${bundletool_path}/src/shell_command.cpp",
110    "${bundletool_path}/src/status_receiver_impl.cpp",
111    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
112    "bm_command_dump_dependencies_test.cpp",
113  ]
114  sources += tools_bm_mock_sources
115
116  configs = [
117    "${bundletool_path}:tools_bm_config",
118    ":tools_bm_config_mock",
119  ]
120
121  cflags = []
122  if (target_cpu == "arm") {
123    cflags += [ "-DBINDER_IPC_32BIT" ]
124  }
125
126  deps = [
127    "${bundle_framework_path}/services/bundlemgr:libbms",
128    "//third_party/googletest:gmock_main",
129    "//third_party/googletest:gtest_main",
130  ]
131
132  external_deps = [
133    "ability_base:want",
134    "ability_runtime:app_manager",
135    "ability_runtime:quickfix_manager",
136    "access_token:libaccesstoken_sdk",
137    "appverify:libhapverify",
138    "bundle_framework:appexecfwk_base",
139    "bundle_framework:appexecfwk_core",
140    "bundle_framework:bundle_napi_common",
141    "bundle_framework:libappexecfwk_common",
142    "c_utils:utils",
143    "common_event_service:cesfwk_innerkits",
144    "eventhandler:libeventhandler",
145    "hilog:libhilog",
146    "init:libbegetutil",
147    "ipc:ipc_core",
148    "kv_store:distributeddata_inner",
149    "os_account:os_account_innerkits",
150    "relational_store:native_rdb",
151    "samgr:samgr_proxy",
152  ]
153
154  external_deps += bm_install_external_deps
155}
156
157ohos_unittest("bm_command_install_test") {
158  module_out_path = module_output_path
159
160  include_dirs = []
161
162  sources = [
163    "${bundletool_path}/src/bundle_command.cpp",
164    "${bundletool_path}/src/bundle_command_common.cpp",
165    "${bundletool_path}/src/quick_fix_command.cpp",
166    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
167    "${bundletool_path}/src/shell_command.cpp",
168    "${bundletool_path}/src/status_receiver_impl.cpp",
169    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
170    "bm_command_install_test.cpp",
171  ]
172  sources += tools_bm_mock_sources
173
174  configs = [
175    "${bundletool_path}:tools_bm_config",
176    ":tools_bm_config_mock",
177  ]
178
179  cflags = []
180  if (target_cpu == "arm") {
181    cflags += [ "-DBINDER_IPC_32BIT" ]
182  }
183
184  deps = [
185    "${bundle_framework_path}/services/bundlemgr:libbms",
186    "//third_party/googletest:gmock_main",
187    "//third_party/googletest:gtest_main",
188  ]
189
190  external_deps = [
191    "ability_base:want",
192    "ability_runtime:app_manager",
193    "ability_runtime:quickfix_manager",
194    "access_token:libaccesstoken_sdk",
195    "appverify:libhapverify",
196    "bundle_framework:appexecfwk_base",
197    "bundle_framework:appexecfwk_core",
198    "bundle_framework:bundle_napi_common",
199    "bundle_framework:libappexecfwk_common",
200    "c_utils:utils",
201    "common_event_service:cesfwk_innerkits",
202    "eventhandler:libeventhandler",
203    "hilog:libhilog",
204    "init:libbegetutil",
205    "ipc:ipc_core",
206    "kv_store:distributeddata_inner",
207    "os_account:os_account_innerkits",
208    "relational_store:native_rdb",
209    "samgr:samgr_proxy",
210  ]
211
212  external_deps += bm_install_external_deps
213}
214
215ohos_unittest("bm_command_test") {
216  module_out_path = module_output_path
217
218  include_dirs = []
219
220  sources = [
221    "${bundletool_path}/src/bundle_command.cpp",
222    "${bundletool_path}/src/bundle_command_common.cpp",
223    "${bundletool_path}/src/quick_fix_command.cpp",
224    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
225    "${bundletool_path}/src/shell_command.cpp",
226    "${bundletool_path}/src/status_receiver_impl.cpp",
227    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
228    "bm_command_test.cpp",
229  ]
230  sources += tools_bm_mock_sources
231
232  configs = [
233    "${bundletool_path}:tools_bm_config",
234    ":tools_bm_config_mock",
235  ]
236
237  cflags = []
238  if (target_cpu == "arm") {
239    cflags += [ "-DBINDER_IPC_32BIT" ]
240  }
241
242  deps = [
243    "${bundle_framework_path}/services/bundlemgr:libbms",
244    "//third_party/googletest:gmock_main",
245    "//third_party/googletest:gtest_main",
246  ]
247
248  external_deps = [
249    "ability_base:want",
250    "ability_runtime:app_manager",
251    "ability_runtime:quickfix_manager",
252    "access_token:libaccesstoken_sdk",
253    "appverify:libhapverify",
254    "bundle_framework:appexecfwk_base",
255    "bundle_framework:appexecfwk_core",
256    "bundle_framework:bundle_napi_common",
257    "bundle_framework:libappexecfwk_common",
258    "c_utils:utils",
259    "common_event_service:cesfwk_innerkits",
260    "eventhandler:libeventhandler",
261    "hilog:libhilog",
262    "init:libbegetutil",
263    "ipc:ipc_core",
264    "kv_store:distributeddata_inner",
265    "os_account:os_account_innerkits",
266    "relational_store:native_rdb",
267    "samgr:samgr_proxy",
268  ]
269
270  external_deps += bm_install_external_deps
271  defines = []
272  if (account_enable_bm) {
273    external_deps += [ "os_account:os_account_innerkits" ]
274    defines += [ "ACCOUNT_ENABLE" ]
275  }
276}
277
278ohos_unittest("bm_command_uninstall_test") {
279  module_out_path = module_output_path
280
281  include_dirs = []
282
283  sources = [
284    "${bundletool_path}/src/bundle_command.cpp",
285    "${bundletool_path}/src/bundle_command_common.cpp",
286    "${bundletool_path}/src/quick_fix_command.cpp",
287    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
288    "${bundletool_path}/src/shell_command.cpp",
289    "${bundletool_path}/src/status_receiver_impl.cpp",
290    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
291    "bm_command_uninstall_test.cpp",
292  ]
293  sources += tools_bm_mock_sources
294
295  configs = [
296    "${bundletool_path}:tools_bm_config",
297    ":tools_bm_config_mock",
298  ]
299
300  cflags = []
301  if (target_cpu == "arm") {
302    cflags += [ "-DBINDER_IPC_32BIT" ]
303  }
304
305  deps = [
306    "${bundle_framework_path}/services/bundlemgr:libbms",
307    "//third_party/googletest:gmock_main",
308    "//third_party/googletest:gtest_main",
309  ]
310
311  external_deps = [
312    "ability_base:want",
313    "ability_runtime:app_manager",
314    "ability_runtime:quickfix_manager",
315    "access_token:libaccesstoken_sdk",
316    "appverify:libhapverify",
317    "bundle_framework:appexecfwk_base",
318    "bundle_framework:appexecfwk_core",
319    "bundle_framework:bundle_napi_common",
320    "bundle_framework:libappexecfwk_common",
321    "c_utils:utils",
322    "common_event_service:cesfwk_innerkits",
323    "eventhandler:libeventhandler",
324    "hilog:libhilog",
325    "init:libbegetutil",
326    "ipc:ipc_core",
327    "kv_store:distributeddata_inner",
328    "os_account:os_account_innerkits",
329    "relational_store:native_rdb",
330    "samgr:samgr_proxy",
331  ]
332
333  external_deps += bm_install_external_deps
334}
335
336ohos_unittest("bm_command_quickfix_test") {
337  module_out_path = module_output_path
338
339  include_dirs = []
340
341  sources = [
342    "${bundletool_path}/src/bundle_command.cpp",
343    "${bundletool_path}/src/bundle_command_common.cpp",
344    "${bundletool_path}/src/quick_fix_command.cpp",
345    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
346    "${bundletool_path}/src/shell_command.cpp",
347    "${bundletool_path}/src/status_receiver_impl.cpp",
348    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
349    "bm_command_quickfix_test.cpp",
350  ]
351  sources += tools_bm_mock_sources
352
353  configs = [
354    "${bundletool_path}:tools_bm_config",
355    ":tools_bm_config_mock",
356  ]
357
358  cflags = []
359  if (target_cpu == "arm") {
360    cflags += [ "-DBINDER_IPC_32BIT" ]
361  }
362
363  deps = [
364    "${bundle_framework_path}/services/bundlemgr:libbms",
365    "//third_party/googletest:gmock_main",
366    "//third_party/googletest:gtest_main",
367  ]
368
369  external_deps = [
370    "ability_base:want",
371    "ability_runtime:app_manager",
372    "ability_runtime:quickfix_manager",
373    "access_token:libaccesstoken_sdk",
374    "appverify:libhapverify",
375    "bundle_framework:appexecfwk_base",
376    "bundle_framework:appexecfwk_core",
377    "bundle_framework:bundle_napi_common",
378    "bundle_framework:libappexecfwk_common",
379    "c_utils:utils",
380    "common_event_service:cesfwk_innerkits",
381    "eventhandler:libeventhandler",
382    "hilog:libhilog",
383    "init:libbegetutil",
384    "ipc:ipc_core",
385    "kv_store:distributeddata_inner",
386    "os_account:os_account_innerkits",
387    "relational_store:native_rdb",
388    "samgr:samgr_proxy",
389  ]
390
391  external_deps += bm_install_external_deps
392}
393
394ohos_unittest("bm_command_overlay_test") {
395  module_out_path = module_output_path
396
397  include_dirs = []
398
399  sources = [
400    "${bundletool_path}/src/bundle_command.cpp",
401    "${bundletool_path}/src/bundle_command_common.cpp",
402    "${bundletool_path}/src/quick_fix_command.cpp",
403    "${bundletool_path}/src/quick_fix_status_callback_host_impl.cpp",
404    "${bundletool_path}/src/shell_command.cpp",
405    "${bundletool_path}/src/status_receiver_impl.cpp",
406    "${kits_path}/js/bundlemgr/bundle_death_recipient.cpp",
407    "bm_command_overlay_test.cpp",
408  ]
409  sources += tools_bm_mock_sources
410
411  configs = [
412    "${bundletool_path}:tools_bm_config",
413    ":tools_bm_config_mock",
414  ]
415
416  cflags = []
417  if (target_cpu == "arm") {
418    cflags += [ "-DBINDER_IPC_32BIT" ]
419  }
420
421  deps = [
422    "${bundle_framework_path}/services/bundlemgr:libbms",
423    "//third_party/googletest:gmock_main",
424    "//third_party/googletest:gtest_main",
425  ]
426
427  external_deps = [
428    "ability_base:want",
429    "ability_runtime:app_manager",
430    "ability_runtime:quickfix_manager",
431    "access_token:libaccesstoken_sdk",
432    "appverify:libhapverify",
433    "bundle_framework:appexecfwk_base",
434    "bundle_framework:appexecfwk_core",
435    "bundle_framework:bundle_napi_common",
436    "bundle_framework:libappexecfwk_common",
437    "c_utils:utils",
438    "common_event_service:cesfwk_innerkits",
439    "eventhandler:libeventhandler",
440    "hilog:libhilog",
441    "init:libbegetutil",
442    "ipc:ipc_core",
443    "kv_store:distributeddata_inner",
444    "os_account:os_account_innerkits",
445    "relational_store:native_rdb",
446    "samgr:samgr_proxy",
447  ]
448
449  external_deps += bm_install_external_deps
450
451  defines = []
452  if (overlay_install_bm) {
453    defines += [ "BUNDLE_FRAMEWORK_OVERLAY_INSTALLATION" ]
454  }
455}
456
457group("unittest") {
458  testonly = true
459
460  deps = [
461    ":bm_command_dump_dependencies_test",
462    ":bm_command_dump_test",
463    ":bm_command_install_test",
464    ":bm_command_overlay_test",
465    ":bm_command_quickfix_test",
466    ":bm_command_test",
467    ":bm_command_uninstall_test",
468  ]
469}
470