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