• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-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/test.gni")
15import("../../batterymgr.gni")
16
17###############################################################################
18config("module_private_config") {
19  include_dirs = [
20    "include",
21    "include/interface_test",
22    "include/scenario_test",
23    "${battery_service_native}/include",
24    "${battery_service_native}/notification/include",
25    "${battery_service_zidl}/include",
26    "${battery_inner_api}/native/include",
27    "${battery_manager_path}/test/utils",
28    "//third_party/json/single_include",
29    "//third_party/jsoncpp/include",
30  ]
31}
32
33config("module_mock_private_config") {
34  include_dirs = [ "mock/include" ]
35}
36
37##############################unittest##########################################
38ohos_unittest("test_battery_service_interface") {
39  module_out_path = "${module_output_path}"
40  defines = [ "GTEST" ]
41
42  sources = [
43    "${battery_manager_path}/test/utils/test_utils.cpp",
44    "src/interface_test/battery_info_test.cpp",
45    "src/interface_test/battery_service_test.cpp",
46  ]
47
48  configs = [
49    "${battery_utils}:utils_config",
50    ":module_private_config",
51    "${battery_utils}:coverage_flags",
52  ]
53
54  deps = [
55    "${battery_inner_api}:batterysrv_client",
56    "${battery_service_zidl}:batterysrv_stub",
57    "${battery_service}:batteryservice",
58    "//third_party/googletest:gtest_main",
59    "//third_party/jsoncpp:jsoncpp",
60  ]
61
62  external_deps = [
63    "ability_base:want",
64    "access_token:libaccesstoken_sdk",
65    "access_token:libnativetoken",
66    "access_token:libprivacy_sdk",
67    "access_token:libtoken_setproc",
68    "c_utils:utils",
69    "drivers_interface_battery:libbattery_proxy_2.0",
70    "drivers_interface_light:liblight_proxy_1.0",
71    "hdf_core:libhdi",
72    "hilog:libhilog",
73    "ipc:ipc_single",
74  ]
75}
76
77ohos_unittest("test_battery_service_scenario") {
78  module_out_path = "${module_output_path}"
79  defines = [ "GTEST" ]
80
81  sources = [
82    "${battery_manager_path}/test/utils/test_utils.cpp",
83    "src/scenario_test/battery_light_test.cpp",
84    "src/scenario_test/battery_notify_test.cpp",
85  ]
86
87  configs = [
88    "${battery_utils}:utils_config",
89    ":module_private_config",
90    "${battery_utils}:coverage_flags",
91  ]
92
93  deps = [
94    "${battery_inner_api}:batterysrv_client",
95    "${battery_service_zidl}:batterysrv_stub",
96    "${battery_service}:battery_notification",
97    "${battery_service}:batteryservice",
98    "//third_party/googletest:gtest_main",
99    "//third_party/jsoncpp:jsoncpp",
100  ]
101
102  external_deps = [
103    "ability_base:want",
104    "ability_base:zuri",
105    "access_token:libaccesstoken_sdk",
106    "access_token:libnativetoken",
107    "access_token:libprivacy_sdk",
108    "access_token:libtoken_setproc",
109    "c_utils:utils",
110    "drivers_interface_battery:libbattery_proxy_2.0",
111    "drivers_interface_light:liblight_proxy_1.0",
112    "hdf_core:libhdi",
113    "hilog:libhilog",
114    "ipc:ipc_single",
115  ]
116
117  if (battery_manager_feature_enable_wireless_charge) {
118    defines += [ "BATTERY_MANAGER_ENABLE_WIRELESS_CHARGE" ]
119  }
120
121  if (battery_manager_feature_support_notification) {
122    sources += [ "src/scenario_test/battery_notification_test.cpp" ]
123
124    external_deps += [
125      "distributed_notification_service:ans_innerkits",
126      "i18n:intl_util",
127      "image_framework:image_native",
128    ]
129
130    defines += [ "BATTERY_SUPPORT_NOTIFICATION" ]
131  }
132}
133
134ohos_unittest("test_battery_service_inner") {
135  module_out_path = "${module_output_path}"
136  defines = [ "GTEST" ]
137
138  sources = [
139    "${battery_manager_path}/test/utils/test_utils.cpp",
140    "src/battert_service_inner_test.cpp",
141  ]
142
143  configs = [
144    "${battery_utils}:utils_config",
145    ":module_private_config",
146    "${battery_utils}:coverage_flags",
147  ]
148
149  deps = [
150    "${battery_inner_api}:batterysrv_client",
151    "${battery_service_zidl}:batterysrv_stub",
152    "${battery_service}:batteryservice",
153    "//third_party/googletest:gtest_main",
154    "//third_party/jsoncpp:jsoncpp",
155  ]
156
157  external_deps = [
158    "ability_base:want",
159    "access_token:libaccesstoken_sdk",
160    "access_token:libnativetoken",
161    "access_token:libprivacy_sdk",
162    "access_token:libtoken_setproc",
163    "c_utils:utils",
164    "drivers_interface_battery:libbattery_proxy_2.0",
165    "drivers_interface_light:liblight_proxy_1.0",
166    "hdf_core:libhdi",
167    "hilog:libhilog",
168    "ipc:ipc_single",
169  ]
170}
171
172ohos_unittest("test_battery_stub") {
173  module_out_path = "${module_output_path}"
174  defines = [ "GTEST" ]
175
176  sources = [
177    "${battery_manager_path}/test/utils/test_utils.cpp",
178    "src/battery_srv_stub_test.cpp",
179  ]
180
181  configs = [
182    "${battery_utils}:utils_config",
183    ":module_private_config",
184    "${battery_utils}:coverage_flags",
185  ]
186
187  deps = [
188    "${battery_inner_api}:batterysrv_client",
189    "${battery_service_zidl}:batterysrv_stub",
190    "${battery_service}:batteryservice",
191    "//third_party/googletest:gtest_main",
192    "//third_party/jsoncpp:jsoncpp",
193  ]
194
195  external_deps = [
196    "ability_base:want",
197    "access_token:libaccesstoken_sdk",
198    "access_token:libnativetoken",
199    "access_token:libprivacy_sdk",
200    "access_token:libtoken_setproc",
201    "c_utils:utils",
202    "drivers_interface_battery:libbattery_proxy_2.0",
203    "drivers_interface_light:liblight_proxy_1.0",
204    "hdf_core:libhdi",
205    "hilog:libhilog",
206    "ipc:ipc_single",
207  ]
208}
209
210### test exceptions when Remote() return nullptr
211ohos_unittest("test_battery_proxy_mock_iremoteobject") {
212  module_out_path = "${module_output_path}"
213
214  sources = [
215    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
216    "mock/source/mock_peer_holder.cpp",
217    "src/battery_srv_proxy_mock_test.cpp",
218  ]
219
220  configs = [
221    ":module_mock_private_config",
222    ":module_private_config",
223    "${battery_utils}:utils_config",
224    "${battery_utils}:coverage_flags",
225  ]
226
227  deps = [ "//third_party/googletest:gtest_main" ]
228
229  external_deps = [
230    "ability_base:base",
231    "ability_base:want",
232    "c_utils:utils",
233    "common_event_service:cesfwk_innerkits",
234    "hilog:libhilog",
235    "hisysevent:libhisysevent",
236    "ipc:ipc_core",
237    "safwk:system_ability_fwk",
238    "samgr:samgr_proxy",
239  ]
240}
241
242### test exceptions when MessageParcel::WriteInterfaceToken() return false
243ohos_unittest("test_battery_proxy_mock_messageparcel_write_error") {
244  module_out_path = "${module_output_path}"
245
246  sources = [
247    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
248    "mock/source/mock_message_parcel.cpp",
249    "src/battery_srv_proxy_mock_test.cpp",
250  ]
251
252  configs = [
253    ":module_mock_private_config",
254    ":module_private_config",
255    "${battery_utils}:utils_config",
256    "${battery_utils}:coverage_flags",
257  ]
258
259  deps = [ "//third_party/googletest:gtest_main" ]
260
261  external_deps = [
262    "ability_base:base",
263    "ability_base:want",
264    "c_utils:utils",
265    "common_event_service:cesfwk_innerkits",
266    "hilog:libhilog",
267    "hisysevent:libhisysevent",
268    "ipc:ipc_core",
269    "safwk:system_ability_fwk",
270    "samgr:samgr_proxy",
271  ]
272}
273
274### test exceptions when SendRequest() return value not equal ERR_OK
275ohos_unittest("test_battery_proxy_mock_sendrequest_error") {
276  module_out_path = "${module_output_path}"
277  defines = [ "ENABLE_REMOTE_INTERFACE" ]
278
279  sources = [
280    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
281    "mock/source/mock_remote_object.cpp",
282    "src/battery_srv_proxy_mock_test.cpp",
283  ]
284
285  configs = [
286    ":module_mock_private_config",
287    ":module_private_config",
288    "${battery_utils}:utils_config",
289    "${battery_utils}:coverage_flags",
290  ]
291
292  deps = [ "//third_party/googletest:gtest_main" ]
293
294  external_deps = [
295    "ability_base:base",
296    "ability_base:want",
297    "c_utils:utils",
298    "common_event_service:cesfwk_innerkits",
299    "hilog:libhilog",
300    "hisysevent:libhisysevent",
301    "ipc:ipc_core",
302    "safwk:system_ability_fwk",
303    "samgr:samgr_proxy",
304  ]
305}
306
307### test exceptions when read reply MessageParcel error
308ohos_unittest("test_battery_proxy_mock_parcel_read_error") {
309  module_out_path = "${module_output_path}"
310
311  sources = [
312    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
313    "mock/source/mock_parcel.cpp",
314    "src/battery_srv_proxy_mock_test.cpp",
315  ]
316
317  configs = [
318    ":module_mock_private_config",
319    ":module_private_config",
320    "${battery_utils}:utils_config",
321    "${battery_utils}:coverage_flags",
322  ]
323
324  deps = [ "//third_party/googletest:gtest_main" ]
325
326  external_deps = [
327    "ability_base:base",
328    "ability_base:want",
329    "c_utils:utils",
330    "common_event_service:cesfwk_innerkits",
331    "hilog:libhilog",
332    "hisysevent:libhisysevent",
333    "ipc:ipc_core",
334    "safwk:system_ability_fwk",
335    "samgr:samgr_proxy",
336  ]
337}
338
339ohos_unittest("test_batterywakeup") {
340  module_out_path = "${module_output_path}"
341
342  sources = [
343    "${battery_manager_path}/test/utils/test_utils.cpp",
344    "src/scenario_test/battery_plugged_wakeup_test.cpp",
345  ]
346
347  configs = [
348    "${battery_utils}:utils_config",
349    ":module_private_config",
350    "${battery_utils}:coverage_flags",
351  ]
352
353  deps = [
354    "${battery_service}:batteryservice",
355    "//third_party/googletest:gtest_main",
356  ]
357
358  external_deps = [
359    "c_utils:utils",
360    "drivers_interface_battery:libbattery_proxy_2.0",
361    "drivers_interface_light:liblight_proxy_1.0",
362    "hdf_core:libhdi",
363    "hilog:libhilog",
364    "ipc:ipc_core",
365    "power_manager:powermgr_client",
366  ]
367}
368
369ohos_unittest("test_mock_battery_config") {
370  module_out_path = "${module_output_path}"
371
372  sources = [
373    "mock/source/mock_json.cpp",
374    "src/battery_config_mock_test.cpp",
375  ]
376
377  configs = [
378    "${battery_utils}:utils_config",
379    ":module_private_config",
380    "${battery_utils}:coverage_flags",
381  ]
382
383  deps = [
384    "${battery_inner_api}:batterysrv_client",
385    "${battery_service}:batteryservice",
386    "//third_party/googletest:gtest_main",
387  ]
388
389  external_deps = [
390    "config_policy:configpolicy_util",
391    "hilog:libhilog",
392    "jsoncpp:jsoncpp",
393  ]
394}
395
396ohos_unittest("test_batteryclient") {
397  module_out_path = "${module_output_path}"
398  defines = [ "GTEST" ]
399
400  sources = [
401    "${battery_manager_path}/test/utils/test_utils.cpp",
402    "src/interface_test/battery_client_test.cpp",
403  ]
404
405  configs = [
406    "${battery_utils}:utils_config",
407    ":module_private_config",
408    "${battery_utils}:coverage_flags",
409  ]
410
411  deps = [
412    "${battery_inner_api}:batterysrv_client",
413    "//third_party/googletest:gtest_main",
414  ]
415
416  external_deps = [
417    "c_utils:utils",
418    "common_event_service:cesfwk_innerkits",
419    "hilog:libhilog",
420    "ipc:ipc_core",
421    "safwk:system_ability_fwk",
422    "samgr:samgr_proxy",
423  ]
424}
425
426ohos_unittest("test_batteryclient_death") {
427  module_out_path = "${module_output_path}"
428  defines = [ "BATTERYMGR_DEATHRECIPIENT_UNITTEST" ]
429
430  sources = [
431    "${battery_manager_path}/test/utils/test_utils.cpp",
432    "src/interface_test/battery_client_death_recipient_test.cpp",
433  ]
434
435  configs = [
436    "${battery_utils}:utils_config",
437    ":module_private_config",
438    "${battery_utils}:coverage_flags",
439  ]
440
441  deps = [
442    "${battery_inner_api}:batterysrv_client",
443    "//third_party/googletest:gtest_main",
444  ]
445
446  external_deps = [
447    "c_utils:utils",
448    "common_event_service:cesfwk_innerkits",
449    "hilog:libhilog",
450    "ipc:ipc_core",
451    "safwk:system_ability_fwk",
452    "samgr:samgr_proxy",
453  ]
454}
455
456ohos_unittest("battery_common_event_test") {
457  module_out_path = "${module_output_path}"
458  defines = [ "GTEST" ]
459
460  sources = [
461    "${battery_manager_path}/test/utils/test_utils.cpp",
462    "src/battery_event_test.cpp",
463  ]
464
465  configs = [
466    "${battery_utils}:utils_config",
467    ":module_private_config",
468    "${battery_utils}:coverage_flags",
469  ]
470
471  deps = [
472    "${battery_inner_api}:batterysrv_client",
473    "${battery_manager_path}/services:batteryservice",
474    "//third_party/googletest:gtest_main",
475  ]
476
477  external_deps = [
478    "ability_base:want",
479    "c_utils:utils",
480    "common_event_service:cesfwk_innerkits",
481    "hilog:libhilog",
482  ]
483
484  if (battery_manager_feature_support_notification) {
485    defines += [ "BATTERY_SUPPORT_NOTIFICATION" ]
486  }
487}
488