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