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