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("../../batterymgr.gni")
16
17###############################################################################
18config("module_private_config") {
19  include_dirs = [
20    "include",
21    "${battery_service_native}/include",
22    "${battery_service_zidl}/include",
23    "${battery_inner_api}/native/include",
24    "${battery_manager_path}/test/utils",
25    "//third_party/json/single_include",
26    "//third_party/jsoncpp/include",
27  ]
28}
29
30config("module_mock_private_config") {
31  include_dirs = [ "mock/include" ]
32}
33
34##############################unittest##########################################
35ohos_unittest("test_battery") {
36  module_out_path = "${module_output_path}"
37  defines = [ "GTEST" ]
38
39  sources = [
40    "${battery_manager_path}/test/utils/test_utils.cpp",
41    "src/battery_callback_test.cpp",
42    "src/battery_config_test.cpp",
43    "src/battery_dump_test.cpp",
44    "src/battery_info_test.cpp",
45    "src/battery_light_test.cpp",
46    "src/battery_notify_test.cpp",
47    "src/battery_service_test.cpp",
48    "src/battery_srv_stub_test.cpp",
49  ]
50
51  configs = [
52    "${battery_utils}:utils_config",
53    ":module_private_config",
54    "${battery_utils}:coverage_flags",
55  ]
56
57  deps = [
58    "${battery_inner_api}:batterysrv_client",
59    "${battery_service_zidl}:batterysrv_stub",
60    "${battery_service}:batteryservice",
61    "//third_party/googletest:gtest_main",
62    "//third_party/jsoncpp:jsoncpp",
63  ]
64
65  external_deps = [
66    "ability_base:want",
67    "access_token:libaccesstoken_sdk",
68    "access_token:libnativetoken",
69    "access_token:libprivacy_sdk",
70    "access_token:libtoken_setproc",
71    "c_utils:utils",
72    "drivers_interface_battery:libbattery_proxy_2.0",
73    "drivers_interface_light:liblight_proxy_1.0",
74    "hdf_core:libhdi",
75    "hilog:libhilog",
76    "ipc:ipc_single",
77  ]
78}
79
80### test exceptions when Remote() return nullptr
81ohos_unittest("test_battery_proxy_mock_iremoteobject") {
82  module_out_path = "${module_output_path}"
83
84  sources = [
85    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
86    "mock/source/mock_peer_holder.cpp",
87    "src/battery_srv_proxy_mock_test.cpp",
88  ]
89
90  configs = [
91    ":module_mock_private_config",
92    ":module_private_config",
93    "${battery_utils}:utils_config",
94    "${battery_utils}:coverage_flags",
95  ]
96
97  deps = [ "//third_party/googletest:gtest_main" ]
98
99  external_deps = [
100    "ability_base:base",
101    "ability_base:want",
102    "c_utils:utils",
103    "common_event_service:cesfwk_innerkits",
104    "hilog:libhilog",
105    "hisysevent:libhisysevent",
106    "ipc:ipc_core",
107    "safwk:system_ability_fwk",
108    "samgr:samgr_proxy",
109  ]
110}
111
112### test exceptions when MessageParcel::WriteInterfaceToken() return false
113ohos_unittest("test_battery_proxy_mock_messageparcel_write_error") {
114  module_out_path = "${module_output_path}"
115
116  sources = [
117    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
118    "mock/source/mock_message_parcel.cpp",
119    "src/battery_srv_proxy_mock_test.cpp",
120  ]
121
122  configs = [
123    ":module_mock_private_config",
124    ":module_private_config",
125    "${battery_utils}:utils_config",
126    "${battery_utils}:coverage_flags",
127  ]
128
129  deps = [ "//third_party/googletest:gtest_main" ]
130
131  external_deps = [
132    "ability_base:base",
133    "ability_base:want",
134    "c_utils:utils",
135    "common_event_service:cesfwk_innerkits",
136    "hilog:libhilog",
137    "hisysevent:libhisysevent",
138    "ipc:ipc_core",
139    "safwk:system_ability_fwk",
140    "samgr:samgr_proxy",
141  ]
142}
143
144### test exceptions when SendRequest() return value not equal ERR_OK
145ohos_unittest("test_battery_proxy_mock_sendrequest_error") {
146  module_out_path = "${module_output_path}"
147  defines = [ "ENABLE_REMOTE_INTERFACE" ]
148
149  sources = [
150    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
151    "mock/source/mock_remote_object.cpp",
152    "src/battery_srv_proxy_mock_test.cpp",
153  ]
154
155  configs = [
156    ":module_mock_private_config",
157    ":module_private_config",
158    "${battery_utils}:utils_config",
159    "${battery_utils}:coverage_flags",
160  ]
161
162  deps = [ "//third_party/googletest:gtest_main" ]
163
164  external_deps = [
165    "ability_base:base",
166    "ability_base:want",
167    "c_utils:utils",
168    "common_event_service:cesfwk_innerkits",
169    "hilog:libhilog",
170    "hisysevent:libhisysevent",
171    "ipc:ipc_core",
172    "safwk:system_ability_fwk",
173    "samgr:samgr_proxy",
174  ]
175}
176
177### test exceptions when read reply MessageParcel error
178ohos_unittest("test_battery_proxy_mock_parcel_read_error") {
179  module_out_path = "${module_output_path}"
180
181  sources = [
182    "${battery_service}/zidl/src/battery_srv_proxy.cpp",
183    "mock/source/mock_parcel.cpp",
184    "src/battery_srv_proxy_mock_test.cpp",
185  ]
186
187  configs = [
188    ":module_mock_private_config",
189    ":module_private_config",
190    "${battery_utils}:utils_config",
191    "${battery_utils}:coverage_flags",
192  ]
193
194  deps = [ "//third_party/googletest:gtest_main" ]
195
196  external_deps = [
197    "ability_base:base",
198    "ability_base:want",
199    "c_utils:utils",
200    "common_event_service:cesfwk_innerkits",
201    "hilog:libhilog",
202    "hisysevent:libhisysevent",
203    "ipc:ipc_core",
204    "safwk:system_ability_fwk",
205    "samgr:samgr_proxy",
206  ]
207}
208
209ohos_unittest("test_batterywakeup") {
210  module_out_path = "${module_output_path}"
211
212  sources = [
213    "${battery_manager_path}/test/utils/test_utils.cpp",
214    "src/battery_plugged_wakeup_test.cpp",
215  ]
216
217  configs = [
218    "${battery_utils}:utils_config",
219    ":module_private_config",
220    "${battery_utils}:coverage_flags",
221  ]
222
223  deps = [
224    "${battery_service}:batteryservice",
225    "//third_party/googletest:gtest_main",
226  ]
227
228  external_deps = [
229    "c_utils:utils",
230    "drivers_interface_battery:libbattery_proxy_2.0",
231    "drivers_interface_light:liblight_proxy_1.0",
232    "hdf_core:libhdi",
233    "hilog:libhilog",
234    "ipc:ipc_core",
235    "power_manager:powermgr_client",
236  ]
237}
238
239ohos_unittest("test_mock_battery_config") {
240  module_out_path = "${module_output_path}"
241
242  sources = [
243    "mock/source/mock_json.cpp",
244    "src/battery_config_mock_test.cpp",
245  ]
246
247  configs = [
248    "${battery_utils}:utils_config",
249    ":module_private_config",
250    "${battery_utils}:coverage_flags",
251  ]
252
253  deps = [
254    "${battery_inner_api}:batterysrv_client",
255    "${battery_service}:batteryservice",
256    "//third_party/googletest:gtest_main",
257  ]
258
259  external_deps = [
260    "config_policy:configpolicy_util",
261    "hilog:libhilog",
262  ]
263}
264