1# Copyright (c) 2022-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("../../../../batterystats.gni")
16
17module_output_path = "${batterystats_part_name}/batterystats"
18
19config("module_private_config") {
20  visibility = [ ":*" ]
21
22  include_dirs = [
23    "${batterystats_root_path}/test/unittest/include",
24    "${batterystats_root_path}/test/unittest/include/servicetest",
25    "${batterystats_root_path}/test/unittest/include/servicetest/utils",
26    "${batterystats_service_native}/include",
27  ]
28}
29
30config("module_mock_private_config") {
31  include_dirs = [
32    "${batterystats_root_path}/test/unittest/include/servicetest/mock",
33    "${batterystats_root_path}/test/unittest/mock/include",
34    "//foundation/communication/ipc/interfaces/innerkits/ipc_core/include/",
35    "//commonlibrary/c_utils/base/include/",
36  ]
37}
38
39deps_ex = [
40  "ability_base:base",
41  "ability_base:want",
42  "battery_manager:batterysrv_client",
43  "common_event_service:cesfwk_innerkits",
44  "config_policy:configpolicy_util",
45  "c_utils:utils",
46  "display_manager:displaymgr",
47  "hisysevent:libhisysevent",
48  "hisysevent:libhisyseventmanager",
49  "hilog:libhilog",
50  "ipc:ipc_core",
51  "power_manager:powermgr_client",
52  "safwk:system_ability_fwk",
53  "samgr:samgr_proxy",
54]
55if (has_batterystats_call_manager_part) {
56  deps_ex += [ "call_manager:tel_call_manager_api" ]
57}
58
59############################service_alarm_test#############################
60ohos_unittest("stats_service_alarm_test") {
61  module_out_path = module_output_path
62
63  sources = [
64    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
65    "stats_service_alarm_test.cpp",
66    "utils/hisysevent_operation.cpp",
67    "utils/stats_service_test_proxy.cpp",
68    "utils/string_filter.cpp",
69  ]
70
71  configs = [
72    ":module_private_config",
73    "${batterystats_utils_path}:coverage_flags",
74  ]
75
76  defines += [ "STATS_SERVICE_UT_TEST" ]
77
78  deps = [
79    "${batterystats_inner_api}:batterystats_client",
80    "${batterystats_service_path}:batterystats_service",
81    "${batterystats_utils_path}:batterystats_utils",
82    "//third_party/googletest:gtest_main",
83    "//third_party/jsoncpp:jsoncpp",
84  ]
85
86  external_deps = deps_ex
87}
88
89############################service_audio_test#############################
90ohos_unittest("stats_service_audio_test") {
91  module_out_path = module_output_path
92
93  sources = [
94    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
95    "stats_service_audio_test.cpp",
96    "utils/hisysevent_operation.cpp",
97    "utils/stats_service_test_proxy.cpp",
98    "utils/string_filter.cpp",
99  ]
100
101  configs = [
102    ":module_private_config",
103    "${batterystats_utils_path}:coverage_flags",
104  ]
105
106  defines += [ "STATS_SERVICE_UT_TEST" ]
107
108  deps = [
109    "${batterystats_inner_api}:batterystats_client",
110    "${batterystats_service_path}:batterystats_service",
111    "${batterystats_utils_path}:batterystats_utils",
112    "//third_party/googletest:gtest_main",
113    "//third_party/jsoncpp:jsoncpp",
114  ]
115
116  external_deps = deps_ex
117}
118
119############################service_bluetooth_test#############################
120ohos_unittest("stats_service_bluetooth_test") {
121  module_out_path = module_output_path
122
123  sources = [
124    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
125    "stats_service_bluetooth_test.cpp",
126    "utils/hisysevent_operation.cpp",
127    "utils/stats_service_test_proxy.cpp",
128    "utils/string_filter.cpp",
129  ]
130
131  configs = [
132    ":module_private_config",
133    "${batterystats_utils_path}:coverage_flags",
134  ]
135
136  defines += [ "STATS_SERVICE_UT_TEST" ]
137
138  deps = [
139    "${batterystats_inner_api}:batterystats_client",
140    "${batterystats_service_path}:batterystats_service",
141    "${batterystats_utils_path}:batterystats_utils",
142    "//third_party/googletest:gtest_main",
143    "//third_party/jsoncpp:jsoncpp",
144  ]
145
146  external_deps = deps_ex
147  external_deps += [ "bluetooth:btframework" ]
148}
149
150############################service_camera_test#############################
151ohos_unittest("stats_service_camera_test") {
152  module_out_path = module_output_path
153
154  sources = [
155    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
156    "stats_service_camera_test.cpp",
157    "utils/hisysevent_operation.cpp",
158    "utils/stats_service_test_proxy.cpp",
159    "utils/string_filter.cpp",
160  ]
161
162  configs = [
163    ":module_private_config",
164    "${batterystats_utils_path}:coverage_flags",
165  ]
166
167  defines += [ "STATS_SERVICE_UT_TEST" ]
168
169  deps = [
170    "${batterystats_inner_api}:batterystats_client",
171    "${batterystats_service_path}:batterystats_service",
172    "${batterystats_utils_path}:batterystats_utils",
173    "//third_party/googletest:gtest_main",
174    "//third_party/jsoncpp:jsoncpp",
175  ]
176
177  external_deps = deps_ex
178}
179
180############################service_display_test#############################
181ohos_unittest("stats_service_display_test") {
182  module_out_path = module_output_path
183
184  sources = [
185    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
186    "stats_service_display_test.cpp",
187    "utils/hisysevent_operation.cpp",
188    "utils/stats_service_test_proxy.cpp",
189    "utils/string_filter.cpp",
190  ]
191
192  configs = [
193    ":module_private_config",
194    "${batterystats_utils_path}:coverage_flags",
195  ]
196
197  defines += [ "STATS_SERVICE_UT_TEST" ]
198
199  deps = [
200    "${batterystats_inner_api}:batterystats_client",
201    "${batterystats_service_path}:batterystats_service",
202    "${batterystats_utils_path}:batterystats_utils",
203    "//third_party/googletest:gtest_main",
204    "//third_party/jsoncpp:jsoncpp",
205  ]
206
207  external_deps = deps_ex
208}
209
210############################service_dump_test#############################
211ohos_unittest("stats_service_dump_test") {
212  module_out_path = module_output_path
213
214  sources = [
215    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
216    "stats_service_dump_test.cpp",
217    "utils/hisysevent_operation.cpp",
218    "utils/stats_service_test_proxy.cpp",
219    "utils/string_filter.cpp",
220  ]
221
222  configs = [
223    ":module_private_config",
224    "${batterystats_utils_path}:coverage_flags",
225  ]
226
227  defines += [ "STATS_SERVICE_UT_TEST" ]
228
229  deps = [
230    "${batterystats_inner_api}:batterystats_client",
231    "${batterystats_service_path}:batterystats_service",
232    "${batterystats_utils_path}:batterystats_utils",
233    "//third_party/googletest:gtest_main",
234    "//third_party/jsoncpp:jsoncpp",
235  ]
236
237  external_deps = deps_ex
238}
239
240############################service_location_test#############################
241ohos_unittest("stats_service_location_test") {
242  module_out_path = module_output_path
243
244  sources = [
245    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
246    "stats_service_location_test.cpp",
247    "utils/hisysevent_operation.cpp",
248    "utils/stats_service_test_proxy.cpp",
249    "utils/string_filter.cpp",
250  ]
251
252  configs = [
253    ":module_private_config",
254    "${batterystats_utils_path}:coverage_flags",
255  ]
256
257  defines += [ "STATS_SERVICE_UT_TEST" ]
258
259  deps = [
260    "${batterystats_inner_api}:batterystats_client",
261    "${batterystats_service_path}:batterystats_service",
262    "${batterystats_utils_path}:batterystats_utils",
263    "//third_party/googletest:gtest_main",
264    "//third_party/jsoncpp:jsoncpp",
265  ]
266
267  external_deps = deps_ex
268}
269
270############################service_phone_test#############################
271ohos_unittest("stats_service_phone_test") {
272  module_out_path = module_output_path
273
274  sources = [
275    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
276    "stats_service_phone_test.cpp",
277    "utils/hisysevent_operation.cpp",
278    "utils/stats_service_test_proxy.cpp",
279    "utils/string_filter.cpp",
280  ]
281
282  configs = [
283    ":module_private_config",
284    "${batterystats_utils_path}:coverage_flags",
285  ]
286
287  defines += [ "STATS_SERVICE_UT_TEST" ]
288
289  deps = [
290    "${batterystats_inner_api}:batterystats_client",
291    "${batterystats_service_path}:batterystats_service",
292    "${batterystats_utils_path}:batterystats_utils",
293    "//third_party/googletest:gtest_main",
294    "//third_party/jsoncpp:jsoncpp",
295  ]
296
297  external_deps = deps_ex
298}
299
300############################service_powermgr_test#############################
301ohos_unittest("stats_service_powermgr_test") {
302  module_out_path = module_output_path
303
304  sources = [
305    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
306    "stats_service_powermgr_test.cpp",
307    "utils/hisysevent_operation.cpp",
308    "utils/stats_service_test_proxy.cpp",
309    "utils/string_filter.cpp",
310  ]
311
312  configs = [
313    ":module_private_config",
314    "${batterystats_utils_path}:coverage_flags",
315  ]
316
317  defines += [ "STATS_SERVICE_UT_TEST" ]
318
319  deps = [
320    "${batterystats_inner_api}:batterystats_client",
321    "${batterystats_service_path}:batterystats_service",
322    "${batterystats_utils_path}:batterystats_utils",
323    "//third_party/googletest:gtest_main",
324    "//third_party/jsoncpp:jsoncpp",
325  ]
326
327  external_deps = deps_ex
328}
329
330############################service_wifi_test#############################
331ohos_unittest("stats_service_wifi_test") {
332  module_out_path = module_output_path
333
334  sources = [
335    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
336    "stats_service_wifi_test.cpp",
337    "utils/hisysevent_operation.cpp",
338    "utils/stats_service_test_proxy.cpp",
339    "utils/string_filter.cpp",
340  ]
341
342  configs = [
343    ":module_private_config",
344    "${batterystats_utils_path}:coverage_flags",
345  ]
346
347  defines += [ "STATS_SERVICE_UT_TEST" ]
348
349  deps = [
350    "${batterystats_inner_api}:batterystats_client",
351    "${batterystats_service_path}:batterystats_service",
352    "${batterystats_utils_path}:batterystats_utils",
353    "//third_party/googletest:gtest_main",
354    "//third_party/jsoncpp:jsoncpp",
355  ]
356
357  external_deps = deps_ex
358  external_deps += [ "wifi:wifi_sdk" ]
359}
360
361############################service_subscriber_test#############################
362ohos_unittest("stats_service_subscriber_test") {
363  module_out_path = module_output_path
364
365  sources = [
366    "${batterystats_service_path}/native/src/battery_stats_parser.cpp",
367    "stats_service_subscriber_test.cpp",
368    "utils/hisysevent_operation.cpp",
369    "utils/stats_service_test_proxy.cpp",
370    "utils/string_filter.cpp",
371  ]
372
373  configs = [
374    ":module_private_config",
375    "${batterystats_utils_path}:coverage_flags",
376  ]
377
378  defines += [ "STATS_SERVICE_UT_TEST" ]
379
380  deps = [
381    "${batterystats_inner_api}:batterystats_client",
382    "${batterystats_service_path}:batterystats_service",
383    "${batterystats_utils_path}:batterystats_utils",
384    "//third_party/googletest:gtest_main",
385    "//third_party/jsoncpp:jsoncpp",
386  ]
387
388  external_deps = deps_ex
389}
390
391############################service_stub_test#############################
392ohos_unittest("stats_service_stub_test") {
393  module_out_path = module_output_path
394
395  sources = [ "stats_service_stub_test.cpp" ]
396
397  configs = [
398    ":module_private_config",
399    "${batterystats_utils_path}:coverage_flags",
400  ]
401
402  deps = [
403    "${batterystats_inner_api}:batterystats_client",
404    "${batterystats_service_path}:batterystats_service",
405    "${batterystats_utils_path}:batterystats_utils",
406    "//third_party/googletest:gtest_main",
407    "//third_party/jsoncpp:jsoncpp",
408  ]
409
410  external_deps = deps_ex
411}
412
413############################service_core_test#############################
414ohos_unittest("stats_service_core_test") {
415  module_out_path = module_output_path
416
417  sources = [ "stats_service_core_test.cpp" ]
418
419  configs = [
420    ":module_private_config",
421    "${batterystats_utils_path}:coverage_flags",
422  ]
423
424  deps = [
425    "${batterystats_inner_api}:batterystats_client",
426    "${batterystats_service_path}:batterystats_service",
427    "${batterystats_utils_path}:batterystats_utils",
428    "//third_party/googletest:gtest_main",
429    "//third_party/jsoncpp:jsoncpp",
430  ]
431
432  external_deps = deps_ex
433}
434
435############################service_test_mock_parcel#############################
436ohos_unittest("stats_service_test_mock_parcel") {
437  module_out_path = module_output_path
438
439  sources = [
440    "${batterystats_root_path}/test/unittest/mock/source/mock_message_parcel.cpp",
441    "${batterystats_root_path}/test/unittest/mock/source/mock_parcel.cpp",
442    "mock/stats_service_test_mock_parcel.cpp",
443    "utils/stats_service_test_proxy.cpp",
444  ]
445
446  configs = [
447    ":module_mock_private_config",
448    ":module_private_config",
449    "${batterystats_utils_path}:coverage_flags",
450  ]
451
452  defines += [ "MESSAGE_PARCEL_WRITE_TOKEN_NORMAL" ]
453
454  deps = [
455    "${batterystats_inner_api}:batterystats_client",
456    "${batterystats_service_path}:batterystats_service",
457    "${batterystats_utils_path}:batterystats_utils",
458    "//third_party/googletest:gtest_main",
459    "//third_party/jsoncpp:jsoncpp",
460  ]
461
462  external_deps = deps_ex
463}
464
465group("unittest") {
466  testonly = true
467  deps = [
468    ":stats_service_alarm_test",
469    ":stats_service_audio_test",
470    ":stats_service_camera_test",
471    ":stats_service_core_test",
472    ":stats_service_display_test",
473    ":stats_service_dump_test",
474    ":stats_service_location_test",
475    ":stats_service_powermgr_test",
476    ":stats_service_stub_test",
477    ":stats_service_subscriber_test",
478    ":stats_service_test_mock_parcel",
479  ]
480  if (has_batterystats_wifi_part) {
481    deps += [ ":stats_service_wifi_test" ]
482  }
483
484  if (has_batterystats_call_manager_part) {
485    deps += [ ":stats_service_phone_test" ]
486  }
487
488  if (has_batterystats_bluetooth_part) {
489    deps += [ ":stats_service_bluetooth_test" ]
490  }
491}
492