• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2021-2025 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_inner_api}/native/include",
26    "${battery_manager_path}/test/utils",
27  ]
28}
29
30config("module_private_config_without_json") {
31  include_dirs = [
32    "include",
33    "include/interface_test",
34    "include/scenario_test",
35    "${battery_service_native}/include",
36    "${battery_service_native}/notification/include",
37    "${battery_inner_api}/native/include",
38    "${battery_manager_path}/test/utils",
39    "${battery_manager_path}/charger/include",
40    "${battery_manager_path}/charger/include/dev",
41    "${battery_utils}/native/include",
42  ]
43}
44
45config("module_mock_private_config") {
46  include_dirs = [ "mock/include" ]
47}
48
49##############################unittest##########################################
50ohos_unittest("test_battery_service_interface") {
51  module_out_path = "${module_output_path}"
52  defines = [ "GTEST" ]
53
54  sanitize = {
55    cfi = true
56    cfi_cross_dso = true
57    debug = false
58  }
59
60  sources = [
61    "${battery_manager_path}/test/utils/test_utils.cpp",
62    "${battery_utils}/native/src/battery_xcollie.cpp",
63    "src/interface_test/battery_info_test.cpp",
64    "src/interface_test/battery_service_test.cpp",
65  ]
66
67  configs = [
68    "${battery_utils}:utils_config",
69    ":module_private_config",
70    "${battery_utils}:coverage_flags",
71  ]
72
73  deps = [
74    "${battery_inner_api}:batterysrv_client",
75    "${battery_service_zidl}:batterysrv_stub",
76    "${battery_service}:batteryservice",
77  ]
78
79  external_deps = [
80    "ability_base:want",
81    "access_token:libaccesstoken_sdk",
82    "access_token:libnativetoken",
83    "access_token:libprivacy_sdk",
84    "access_token:libtoken_setproc",
85    "cJSON:cjson",
86    "c_utils:utils",
87    "common_event_service:cesfwk_innerkits",
88    "drivers_interface_battery:libbattery_proxy_2.0",
89    "eventhandler:libeventhandler",
90    "googletest:gtest_main",
91    "hdf_core:libhdi",
92    "hicollie:libhicollie",
93    "hilog:libhilog",
94    "ipc:ipc_single",
95    "safwk:system_ability_fwk",
96  ]
97
98  if (has_drivers_interface_light_part) {
99    external_deps += [ "drivers_interface_light:liblight_proxy_1.0" ]
100  }
101}
102
103ohos_unittest("test_battery_service_scenario") {
104  module_out_path = "${module_output_path}"
105  defines = [ "GTEST" ]
106
107  sanitize = {
108    cfi = true
109    cfi_cross_dso = true
110    debug = false
111  }
112
113  sources = [
114    "${battery_manager_path}/test/utils/test_utils.cpp",
115    "src/scenario_test/battery_light_test.cpp",
116    "src/scenario_test/battery_notify_test.cpp",
117  ]
118
119  configs = [
120    "${battery_utils}:utils_config",
121    ":module_private_config",
122    "${battery_utils}:coverage_flags",
123  ]
124
125  deps = [
126    "${battery_inner_api}:batterysrv_client",
127    "${battery_service_zidl}:batterysrv_stub",
128    "${battery_service}:battery_notification",
129    "${battery_service}:batteryservice",
130  ]
131
132  external_deps = [
133    "ability_base:want",
134    "ability_base:zuri",
135    "access_token:libaccesstoken_sdk",
136    "access_token:libnativetoken",
137    "access_token:libprivacy_sdk",
138    "access_token:libtoken_setproc",
139    "cJSON:cjson",
140    "c_utils:utils",
141    "drivers_interface_battery:libbattery_proxy_2.0",
142    "googletest:gtest_main",
143    "hdf_core:libhdi",
144    "hilog:libhilog",
145    "ipc:ipc_single",
146    "safwk:system_ability_fwk",
147  ]
148
149  if (has_drivers_interface_light_part) {
150    external_deps += [ "drivers_interface_light:liblight_proxy_1.0" ]
151  }
152
153  if (battery_manager_feature_enable_charging_sound) {
154    deps += [ "${battery_service}:charging_sound" ]
155    defines += [ "BATTERY_MANAGER_ENABLE_CHARGING_SOUND" ]
156    external_deps += [
157      "ffrt:libffrt",
158      "power_manager:power_ffrt",
159    ]
160  }
161
162  if (battery_manager_feature_enable_wireless_charge) {
163    defines += [ "BATTERY_MANAGER_ENABLE_WIRELESS_CHARGE" ]
164  }
165
166  if (battery_manager_feature_support_notification) {
167    sources += [ "src/scenario_test/battery_notification_test.cpp" ]
168
169    external_deps += [
170      "distributed_notification_service:ans_innerkits",
171      "i18n:intl_util",
172      "image_framework:image_native",
173    ]
174
175    defines += [ "BATTERY_SUPPORT_NOTIFICATION" ]
176  }
177}
178
179ohos_unittest("test_battery_service_inner") {
180  module_out_path = "${module_output_path}"
181  defines = [ "GTEST" ]
182
183  sources = [
184    "${battery_manager_path}/test/utils/test_utils.cpp",
185    "src/battert_service_inner_test.cpp",
186  ]
187
188  configs = [
189    "${battery_utils}:utils_config",
190    ":module_private_config",
191    "${battery_utils}:coverage_flags",
192  ]
193
194  deps = [
195    "${battery_inner_api}:batterysrv_client",
196    "${battery_service_zidl}:batterysrv_stub",
197    "${battery_service}:batteryservice",
198  ]
199
200  external_deps = [
201    "ability_base:want",
202    "access_token:libaccesstoken_sdk",
203    "access_token:libnativetoken",
204    "access_token:libprivacy_sdk",
205    "access_token:libtoken_setproc",
206    "cJSON:cjson",
207    "c_utils:utils",
208    "drivers_interface_battery:libbattery_proxy_2.0",
209    "googletest:gtest_main",
210    "hdf_core:libhdi",
211    "hilog:libhilog",
212    "ipc:ipc_single",
213    "safwk:system_ability_fwk",
214  ]
215
216  if (has_drivers_interface_light_part) {
217    external_deps += [ "drivers_interface_light:liblight_proxy_1.0" ]
218  }
219}
220
221ohos_unittest("test_battery_charger") {
222  module_out_path = "${module_output_path}"
223  defines = [ "GTEST" ]
224
225  sources = [ "src/battery_charger_test.cpp" ]
226
227  configs = [
228    "${battery_utils}:utils_config",
229    ":module_private_config_without_json",
230    "${battery_utils}:coverage_flags",
231  ]
232
233  external_deps = [
234    "c_utils:utils",
235    "drivers_interface_battery:libbattery_proxy_2.0",
236    "googletest:gtest_main",
237    "hilog:libhilog",
238    "init:libbegetutil",
239  ]
240
241  if (has_drivers_interface_display_part && has_drivers_interface_light_part &&
242      has_graphic_surface_part && has_ui_lite_part && has_graphic_utils_lite_part &&
243      battery_manager_feature_enable_charger) {
244    defines += [ "ENABLE_CHARGER" ]
245    external_deps += [ "libdrm:libdrm" ]
246    sources += [
247      "${battery_manager_path}/charger/src/dev/drm_driver.cpp",
248      "${battery_manager_path}/charger/src/dev/fbdev_driver.cpp",
249      "${battery_manager_path}/charger/src/dev/graphic_dev.cpp",
250      "${battery_manager_path}/charger/src/power_supply_provider.cpp",
251    ]
252  }
253}
254
255ohos_unittest("test_battery_callback") {
256  module_out_path = "${module_output_path}"
257  defines = [ "GTEST" ]
258
259  sanitize = {
260    cfi = true
261    cfi_cross_dso = true
262    debug = false
263  }
264
265  sources = [ "src/scenario_test/battery_callback_test.cpp" ]
266
267  configs = [
268    "${battery_utils}:utils_config",
269    ":module_private_config_without_json",
270    "${battery_utils}:coverage_flags",
271  ]
272
273  deps = [
274    "${battery_service_zidl}:batterysrv_stub",
275    "${battery_service}:batteryservice",
276  ]
277
278  external_deps = [
279    "ability_base:want",
280    "c_utils:utils",
281    "drivers_interface_battery:libbattery_proxy_2.0",
282    "eventhandler:libeventhandler",
283    "googletest:gtest_main",
284    "hdf_core:libhdi",
285    "hilog:libhilog",
286    "ipc:ipc_single",
287    "safwk:system_ability_fwk",
288  ]
289}
290
291ohos_unittest("test_battery_config") {
292  module_out_path = "${module_output_path}"
293  defines = [ "GTEST" ]
294
295  sources = [ "src/scenario_test/battery_config_test.cpp" ]
296
297  configs = [
298    "${battery_utils}:utils_config",
299    ":module_private_config_without_json",
300    "${battery_utils}:coverage_flags",
301  ]
302
303  deps = [ "${battery_service}:batteryservice" ]
304
305  external_deps = [
306    "cJSON:cjson",
307    "c_utils:utils",
308    "googletest:gtest_main",
309    "hilog:libhilog",
310  ]
311}
312
313ohos_unittest("test_battery_dump") {
314  module_out_path = "${module_output_path}"
315  defines = [ "GTEST" ]
316
317  sources = [ "src/scenario_test/battery_dump_test.cpp" ]
318
319  configs = [
320    "${battery_utils}:utils_config",
321    ":module_private_config_without_json",
322    "${battery_utils}:coverage_flags",
323  ]
324
325  deps = [ "${battery_service}:batteryservice" ]
326
327  external_deps = [
328    "ability_base:want",
329    "cJSON:cjson",
330    "c_utils:utils",
331    "drivers_interface_battery:libbattery_proxy_2.0",
332    "eventhandler:libeventhandler",
333    "googletest:gtest_main",
334    "hdf_core:libhdi",
335    "hilog:libhilog",
336    "safwk:system_ability_fwk",
337  ]
338}
339
340ohos_unittest("test_battery_stub") {
341  module_out_path = "${module_output_path}"
342  defines = [ "GTEST" ]
343
344  sanitize = {
345    cfi = true
346    cfi_cross_dso = true
347    debug = false
348  }
349
350  sources = [
351    "${battery_manager_path}/test/utils/test_utils.cpp",
352    "src/battery_srv_stub_test.cpp",
353  ]
354
355  configs = [
356    "${battery_utils}:utils_config",
357    ":module_private_config",
358    "${battery_utils}:coverage_flags",
359  ]
360
361  deps = [
362    "${battery_inner_api}:batterysrv_client",
363    "${battery_service_zidl}:batterysrv_stub",
364    "${battery_service}:batteryservice",
365  ]
366
367  external_deps = [
368    "ability_base:want",
369    "access_token:libaccesstoken_sdk",
370    "access_token:libnativetoken",
371    "access_token:libprivacy_sdk",
372    "access_token:libtoken_setproc",
373    "cJSON:cjson",
374    "c_utils:utils",
375    "drivers_interface_battery:libbattery_proxy_2.0",
376    "eventhandler:libeventhandler",
377    "googletest:gtest_main",
378    "hdf_core:libhdi",
379    "hilog:libhilog",
380    "ipc:ipc_single",
381    "safwk:system_ability_fwk",
382  ]
383
384  if (has_drivers_interface_light_part) {
385    external_deps += [ "drivers_interface_light:liblight_proxy_1.0" ]
386  }
387}
388
389# test exceptions when Remote() return nullptr
390ohos_unittest("test_battery_proxy_mock_iremoteobject") {
391  sanitize = {
392    cfi = true
393    cfi_cross_dso = true
394    debug = false
395  }
396
397  module_out_path = "${module_output_path}"
398
399  sources = [
400    "mock/source/mock_peer_holder.cpp",
401    "src/battery_srv_proxy_mock_test.cpp",
402  ]
403
404  configs = [
405    ":module_mock_private_config",
406    ":module_private_config",
407    "${battery_service_zidl}:batterysrv_public_config",
408    "${battery_utils}:utils_config",
409    "${battery_utils}:coverage_flags",
410  ]
411
412  deps = [ "${battery_service_zidl}:batterysrv_proxy" ]
413
414  external_deps = [
415    "ability_base:base",
416    "ability_base:want",
417    "cJSON:cjson",
418    "c_utils:utils",
419    "common_event_service:cesfwk_innerkits",
420    "googletest:gtest_main",
421    "hilog:libhilog",
422    "hisysevent:libhisysevent",
423    "ipc:ipc_core",
424    "safwk:system_ability_fwk",
425    "samgr:samgr_proxy",
426  ]
427}
428
429# test exceptions when MessageParcel::WriteInterfaceToken() return false
430ohos_unittest("test_battery_proxy_mock_messageparcel_write_error") {
431  sanitize = {
432    cfi = true
433    cfi_cross_dso = true
434    debug = false
435  }
436
437  module_out_path = "${module_output_path}"
438
439  sources = [
440    "mock/source/mock_message_parcel.cpp",
441    "src/battery_srv_proxy_mock_test.cpp",
442  ]
443
444  configs = [
445    ":module_mock_private_config",
446    ":module_private_config",
447    "${battery_service_zidl}:batterysrv_public_config",
448    "${battery_utils}:utils_config",
449    "${battery_utils}:coverage_flags",
450  ]
451
452  deps = [ "${battery_service_zidl}:batterysrv_proxy" ]
453
454  external_deps = [
455    "ability_base:base",
456    "ability_base:want",
457    "cJSON:cjson",
458    "c_utils:utils",
459    "common_event_service:cesfwk_innerkits",
460    "googletest:gtest_main",
461    "hilog:libhilog",
462    "ipc:ipc_core",
463    "safwk:system_ability_fwk",
464    "samgr:samgr_proxy",
465  ]
466}
467
468# test exceptions when SendRequest() return value not equal ERR_OK
469ohos_unittest("test_battery_proxy_mock_sendrequest_error") {
470  sanitize = {
471    cfi = true
472    cfi_cross_dso = true
473    debug = false
474  }
475
476  module_out_path = "${module_output_path}"
477  defines = [ "ENABLE_REMOTE_INTERFACE" ]
478
479  sources = [
480    "mock/source/mock_remote_object.cpp",
481    "src/battery_srv_proxy_mock_test.cpp",
482  ]
483
484  configs = [
485    ":module_mock_private_config",
486    ":module_private_config",
487    "${battery_service_zidl}:batterysrv_public_config",
488    "${battery_utils}:utils_config",
489    "${battery_utils}:coverage_flags",
490  ]
491
492  deps = [ "${battery_service_zidl}:batterysrv_proxy" ]
493
494  external_deps = [
495    "ability_base:base",
496    "ability_base:want",
497    "cJSON:cjson",
498    "c_utils:utils",
499    "common_event_service:cesfwk_innerkits",
500    "googletest:gtest_main",
501    "hilog:libhilog",
502    "hisysevent:libhisysevent",
503    "ipc:ipc_core",
504    "safwk:system_ability_fwk",
505    "samgr:samgr_proxy",
506  ]
507}
508
509# test exceptions when read reply MessageParcel error
510ohos_unittest("test_battery_proxy_mock_parcel_read_error") {
511  sanitize = {
512    cfi = true
513    cfi_cross_dso = true
514    debug = false
515  }
516
517  module_out_path = "${module_output_path}"
518
519  sources = [
520    "mock/source/mock_parcel.cpp",
521    "src/battery_srv_proxy_mock_test.cpp",
522  ]
523
524  configs = [
525    ":module_mock_private_config",
526    ":module_private_config",
527    "${battery_service_zidl}:batterysrv_public_config",
528    "${battery_utils}:utils_config",
529    "${battery_utils}:coverage_flags",
530  ]
531
532  deps = [ "${battery_service_zidl}:batterysrv_proxy" ]
533
534  external_deps = [
535    "ability_base:base",
536    "ability_base:want",
537    "cJSON:cjson",
538    "c_utils:utils",
539    "common_event_service:cesfwk_innerkits",
540    "googletest:gtest_main",
541    "hilog:libhilog",
542    "hisysevent:libhisysevent",
543    "ipc:ipc_core",
544    "safwk:system_ability_fwk",
545    "samgr:samgr_proxy",
546  ]
547}
548
549ohos_unittest("test_batterywakeup") {
550  module_out_path = "${module_output_path}"
551
552  sources = [
553    "${battery_manager_path}/test/utils/test_utils.cpp",
554    "src/scenario_test/battery_plugged_wakeup_test.cpp",
555  ]
556
557  configs = [
558    "${battery_utils}:utils_config",
559    ":module_private_config",
560    "${battery_utils}:coverage_flags",
561  ]
562
563  deps = [ "${battery_service}:batteryservice" ]
564
565  external_deps = [
566    "ability_base:want",
567    "cJSON:cjson",
568    "c_utils:utils",
569    "drivers_interface_battery:libbattery_proxy_2.0",
570    "eventhandler:libeventhandler",
571    "googletest:gtest_main",
572    "hdf_core:libhdi",
573    "hilog:libhilog",
574    "ipc:ipc_core",
575    "power_manager:powermgr_client",
576    "safwk:system_ability_fwk",
577  ]
578
579  if (has_drivers_interface_light_part) {
580    external_deps += [ "drivers_interface_light:liblight_proxy_1.0" ]
581  }
582}
583
584ohos_unittest("test_mock_battery_config") {
585  module_out_path = "${module_output_path}"
586
587  sources = [
588    "src/battery_config_mock_test.cpp",
589  ]
590
591  configs = [
592    "${battery_utils}:utils_config",
593    ":module_private_config",
594    "${battery_utils}:coverage_flags",
595  ]
596
597  deps = [
598    "${battery_inner_api}:batterysrv_client",
599    "${battery_service}:batteryservice",
600  ]
601
602  external_deps = [
603    "cJSON:cjson",
604    "c_utils:utils",
605    "config_policy:configpolicy_util",
606    "googletest:gtest_main",
607    "hilog:libhilog",
608  ]
609}
610
611ohos_unittest("test_batteryclient") {
612  module_out_path = "${module_output_path}"
613  defines = [ "GTEST" ]
614
615  sources = [
616    "${battery_manager_path}/test/utils/test_utils.cpp",
617    "mock/source/mock_battery_srv_proxy.cpp",
618    "mock/source/mock_remote_object.cpp",
619    "src/interface_test/battery_client_test.cpp",
620  ]
621
622  configs = [
623    "${battery_utils}:utils_config",
624    ":module_mock_private_config",
625    ":module_private_config",
626    "${battery_utils}:coverage_flags",
627  ]
628
629  deps = [ "${battery_inner_api}:batterysrv_client" ]
630
631  external_deps = [
632    "cJSON:cjson",
633    "c_utils:utils",
634    "common_event_service:cesfwk_innerkits",
635    "googletest:gtest_main",
636    "hilog:libhilog",
637    "ipc:ipc_core",
638    "safwk:system_ability_fwk",
639    "samgr:samgr_proxy",
640  ]
641
642  if (battery_manager_feature_set_low_capacity_threshold) {
643    defines += [ "PC_TEST" ]
644  }
645}
646
647ohos_unittest("test_batteryclient_death") {
648  module_out_path = "${module_output_path}"
649  defines = [ "BATTERYMGR_DEATHRECIPIENT_UNITTEST" ]
650
651  sources = [
652    "${battery_manager_path}/test/utils/test_utils.cpp",
653    "src/interface_test/battery_client_death_recipient_test.cpp",
654  ]
655
656  configs = [
657    "${battery_utils}:utils_config",
658    ":module_private_config",
659    "${battery_utils}:coverage_flags",
660  ]
661
662  deps = [ "${battery_inner_api}:batterysrv_client" ]
663
664  external_deps = [
665    "cJSON:cjson",
666    "c_utils:utils",
667    "common_event_service:cesfwk_innerkits",
668    "googletest:gtest_main",
669    "hilog:libhilog",
670    "ipc:ipc_core",
671    "safwk:system_ability_fwk",
672    "samgr:samgr_proxy",
673  ]
674}
675
676ohos_unittest("battery_common_event_test") {
677  module_out_path = "${module_output_path}"
678  defines = [ "GTEST" ]
679
680  sources = [
681    "${battery_manager_path}/test/utils/test_utils.cpp",
682    "src/battery_event_test.cpp",
683  ]
684
685  configs = [
686    "${battery_utils}:utils_config",
687    ":module_private_config",
688    "${battery_utils}:coverage_flags",
689  ]
690
691  deps = [
692    "${battery_inner_api}:batterysrv_client",
693    "${battery_manager_path}/services:batteryservice",
694  ]
695
696  external_deps = [
697    "ability_base:want",
698    "cJSON:cjson",
699    "c_utils:utils",
700    "common_event_service:cesfwk_innerkits",
701    "googletest:gtest_main",
702    "hilog:libhilog",
703  ]
704
705  if (battery_manager_feature_support_notification) {
706    defines += [ "BATTERY_SUPPORT_NOTIFICATION" ]
707  }
708}
709
710ohos_unittest("battery_common_event_part2_test") {
711  module_out_path = "${module_output_path}"
712  defines = [ "GTEST" ]
713
714  sources = [
715    "${battery_manager_path}/test/utils/test_utils.cpp",
716    "mock/source/mock_common_event_manager.cpp",
717    "mock/source/mock_remote_object.cpp",
718    "mock/source/mock_sa_manager.cpp",
719    "src/battery_event_test_part2.cpp",
720  ]
721
722  configs = [
723    "${battery_utils}:utils_config",
724    ":module_private_config_without_json",
725    ":module_mock_private_config",
726    "${battery_utils}:coverage_flags",
727  ]
728
729  deps = [
730    "${battery_inner_api}:batterysrv_client",
731    "${battery_manager_path}/services:batteryservice",
732  ]
733
734  external_deps = [
735    "ability_base:want",
736    "c_utils:utils",
737    "common_event_service:cesfwk_innerkits",
738    "googletest:gmock_main",
739    "googletest:gtest_main",
740    "hilog:libhilog",
741    "ipc:ipc_core",
742    "samgr:samgr_proxy",
743  ]
744
745  if (battery_manager_feature_support_notification) {
746    defines += [ "BATTERY_SUPPORT_NOTIFICATION" ]
747  }
748}
749
750ohos_unittest("battery_hookmgr_test") {
751  module_out_path = "${module_output_path}"
752
753  sources = [ "src/battery_hookmgr_test.cpp" ]
754
755  configs = [
756    "${battery_utils}:utils_config",
757    ":module_private_config_without_json",
758    "${battery_utils}:coverage_flags",
759  ]
760
761  deps = [ "${battery_utils}/hookmgr:battery_hookmgr" ]
762  external_deps = [
763    "c_utils:utils",
764    "googletest:gtest_main",
765    "hilog:libhilog",
766    "init:libbegetutil",
767  ]
768}
769