• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2022  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("../../device_usage_statistics.gni")
16module_output_path =
17    "device_usage_statistics/device_usage_statistics/deviceusagestatisticstest"
18
19config("module_private_config") {
20  visibility = [ ":*" ]
21
22  include_dirs = [
23    "../../interfaces/innerkits/include",
24    "../../services/common/include",
25    "../../services/packageusage/include",
26    "../../services/packagegroup/include",
27    "../../utils/include",
28  ]
29}
30
31ohos_unittest("BundleActiveTotalTest") {
32  module_out_path = module_output_path
33  cflags = [
34    "-Dprivate=public",
35    "-Dprotected=public",
36  ]
37
38  sources = [
39    "bundle_active_total_test.cpp",
40    "bundle_active_usage_database_test.cpp",
41  ]
42
43  configs = [ ":module_private_config" ]
44
45  deps = [
46    "../../:usagestatservice_static",
47    "../../:usagestatsinner",
48    "../../:usagestatsutils",
49  ]
50
51  external_deps = [
52    "ability_runtime:app_manager",
53    "ability_runtime:wantagent_innerkits",
54    "access_token:libaccesstoken_sdk",
55    "access_token:libtokenid_sdk",
56    "cJSON:cjson",
57    "ffrt:libffrt",
58    "hilog:libhilog",
59    "init:libbegetutil",
60    "ipc:ipc_single",
61    "relational_store:native_rdb",
62    "safwk:system_ability_fwk",
63    "samgr:samgr_proxy",
64    "time_service:time_client",
65  ]
66  defines = []
67  if (device_usage_statistics_with_powermgr_power_manager_enable) {
68    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
69    external_deps += [ "power_manager:powermgr_client" ]
70  }
71  if (os_account_part_enabled) {
72    external_deps += [ "os_account:os_account_innerkits" ]
73  }
74  if (bgtaskmgr_enable) {
75    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
76    defines += [ "BGTASKMGR_ENABLE" ]
77  }
78  branch_protector_ret = "pac_ret"
79
80  sanitize = {
81    cfi = true
82    cfi_cross_dso = true
83    debug = false
84  }
85}
86
87ohos_unittest("DeviceUsageStatsTest") {
88  module_out_path = module_output_path
89  cflags = [
90    "-Dprivate=public",
91    "-Dprotected=public",
92  ]
93
94  sources = [ "device_usage_statistics_test.cpp" ]
95
96  configs = [ ":module_private_config" ]
97
98  deps = [
99    "../../:usagestatservice_static",
100    "../../:usagestatsinner",
101    "../../:usagestatsutils",
102  ]
103
104  external_deps = [
105    "ability_runtime:app_manager",
106    "ability_runtime:wantagent_innerkits",
107    "access_token:libaccesstoken_sdk",
108    "access_token:libnativetoken",
109    "access_token:libtoken_setproc",
110    "cJSON:cjson",
111    "cJSON:cjson_static",
112    "ffrt:libffrt",
113    "hilog:libhilog",
114    "ipc:ipc_single",
115    "relational_store:native_rdb",
116    "safwk:system_ability_fwk",
117    "samgr:samgr_proxy",
118    "selinux_adapter:librestorecon",
119    "time_service:time_client",
120  ]
121  defines = []
122  if (device_usage_statistics_with_powermgr_power_manager_enable) {
123    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
124    external_deps += [ "power_manager:powermgr_client" ]
125  }
126  if (os_account_part_enabled) {
127    external_deps += [ "os_account:os_account_innerkits" ]
128  }
129  if (bgtaskmgr_enable) {
130    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
131    defines += [ "BGTASKMGR_ENABLE" ]
132  }
133  branch_protector_ret = "pac_ret"
134
135  sanitize = {
136    cfi = true
137    cfi_cross_dso = true
138    debug = false
139  }
140}
141
142ohos_unittest("DeviceUsageStatsMultiTest") {
143  module_out_path = module_output_path
144  cflags = [
145    "-Dprivate=public",
146    "-Dprotected=public",
147  ]
148
149  sources = [ "device_usage_statistics_multi_test.cpp" ]
150
151  configs = [ ":module_private_config" ]
152
153  deps = [
154    "../../:usagestatservice_static",
155    "../../:usagestatsinner",
156    "../../:usagestatsutils",
157  ]
158
159  external_deps = [
160    "ability_runtime:app_manager",
161    "ability_runtime:wantagent_innerkits",
162    "access_token:libaccesstoken_sdk",
163    "access_token:libnativetoken",
164    "access_token:libtoken_setproc",
165    "cJSON:cjson",
166    "cJSON:cjson_static",
167    "ffrt:libffrt",
168    "hilog:libhilog",
169    "ipc:ipc_single",
170    "relational_store:native_rdb",
171    "safwk:system_ability_fwk",
172    "samgr:samgr_proxy",
173    "selinux_adapter:librestorecon",
174    "time_service:time_client",
175  ]
176  defines = []
177  if (device_usage_statistics_with_powermgr_power_manager_enable) {
178    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
179    external_deps += [ "power_manager:powermgr_client" ]
180  }
181  if (os_account_part_enabled) {
182    external_deps += [ "os_account:os_account_innerkits" ]
183  }
184  if (bgtaskmgr_enable) {
185    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
186    defines += [ "BGTASKMGR_ENABLE" ]
187  }
188  branch_protector_ret = "pac_ret"
189
190  sanitize = {
191    cfi = true
192    cfi_cross_dso = true
193    debug = false
194  }
195}
196
197ohos_unittest("DeviceUsageStatsServiceTest") {
198  module_out_path = module_output_path
199  cflags = [
200    "-Dprivate=public",
201    "-Dprotected=public",
202  ]
203
204  sources = [ "device_usage_statistics_service_test.cpp" ]
205
206  configs = [ ":module_private_config" ]
207  resource_config_file =
208      "${usage_statistics_path}/test/resource/deviceUsage/ohos_test.xml"
209
210  deps = [
211    "../../:usagestatservice_static",
212    "../../:usagestatsinner",
213    "../../:usagestatsutils",
214  ]
215
216  external_deps = [
217    "ability_runtime:app_manager",
218    "ability_runtime:wantagent_innerkits",
219    "access_token:libaccesstoken_sdk",
220    "access_token:libnativetoken",
221    "access_token:libtoken_setproc",
222    "cJSON:cjson",
223    "cJSON:cjson_static",
224    "ffrt:libffrt",
225    "hilog:libhilog",
226    "ipc:ipc_single",
227    "relational_store:native_rdb",
228    "safwk:system_ability_fwk",
229    "samgr:samgr_proxy",
230    "selinux_adapter:librestorecon",
231    "time_service:time_client",
232  ]
233  defines = []
234  if (device_usage_statistics_with_powermgr_power_manager_enable) {
235    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
236    external_deps += [ "power_manager:powermgr_client" ]
237  }
238  if (os_account_part_enabled) {
239    external_deps += [ "os_account:os_account_innerkits" ]
240  }
241  if (bgtaskmgr_enable) {
242    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
243    defines += [ "BGTASKMGR_ENABLE" ]
244  }
245
246  sanitize = {
247    cfi = true
248    cfi_cross_dso = true
249    debug = false
250  }
251  branch_protector_ret = "pac_ret"
252}
253
254ohos_unittest("DeviceUsageStatsMockTest") {
255  module_out_path = module_output_path
256  cflags = [
257    "-Dprivate=public",
258    "-Dprotected=public",
259  ]
260
261  sources = [
262    "device_usage_statistics_mock_test.cpp",
263    "mock/bundle_active_account_helper_mock.cpp",
264    "mock/bundle_active_client_mock.cpp",
265    "mock/bundle_active_core_mock.cpp",
266    "mock/bundle_active_usage_database_mock.cpp",
267    "mock/mock_service_registry.cpp",
268  ]
269
270  include_dirs = [ "mock/include" ]
271
272  configs = [ ":module_private_config" ]
273
274  deps = [
275    "../../:usagestatservice_static",
276    "../../:usagestatsinner",
277    "../../:usagestatsutils",
278  ]
279
280  external_deps = [
281    "ability_runtime:app_manager",
282    "ability_runtime:wantagent_innerkits",
283    "access_token:libaccesstoken_sdk",
284    "cJSON:cjson",
285    "ffrt:libffrt",
286    "hilog:libhilog",
287    "ipc:ipc_single",
288    "relational_store:native_rdb",
289    "safwk:system_ability_fwk",
290    "samgr:samgr_proxy",
291    "time_service:time_client",
292  ]
293  defines = []
294  if (device_usage_statistics_with_powermgr_power_manager_enable) {
295    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
296    external_deps += [ "power_manager:powermgr_client" ]
297  }
298  if (os_account_part_enabled) {
299    external_deps += [ "os_account:os_account_innerkits" ]
300  }
301  if (bgtaskmgr_enable) {
302    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
303    defines += [ "BGTASKMGR_ENABLE" ]
304  }
305  branch_protector_ret = "pac_ret"
306
307  sanitize = {
308    cfi = true
309    cfi_cross_dso = true
310    debug = false
311  }
312}
313
314ohos_unittest("DeviceUsagePackageUsageTest") {
315  module_out_path = module_output_path
316  cflags = [
317    "-Dprivate=public",
318    "-Dprotected=public",
319  ]
320
321  sources = [ "package_usage_test.cpp" ]
322
323  configs = [ ":module_private_config" ]
324
325  deps = [
326    "../../:usagestatservice_static",
327    "../../:usagestatsinner",
328    "../../:usagestatsutils",
329  ]
330
331  external_deps = [
332    "ability_runtime:app_manager",
333    "ability_runtime:wantagent_innerkits",
334    "access_token:libaccesstoken_sdk",
335    "cJSON:cjson",
336    "ffrt:libffrt",
337    "hilog:libhilog",
338    "ipc:ipc_single",
339    "relational_store:native_rdb",
340    "safwk:system_ability_fwk",
341    "samgr:samgr_proxy",
342    "time_service:time_client",
343  ]
344  defines = []
345  if (device_usage_statistics_with_powermgr_power_manager_enable) {
346    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
347    external_deps += [ "power_manager:powermgr_client" ]
348  }
349  if (os_account_part_enabled) {
350    external_deps += [ "os_account:os_account_innerkits" ]
351  }
352  if (bgtaskmgr_enable) {
353    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
354    defines += [ "BGTASKMGR_ENABLE" ]
355  }
356  branch_protector_ret = "pac_ret"
357
358  sanitize = {
359    cfi = true
360    cfi_cross_dso = true
361    debug = false
362  }
363}
364
365ohos_unittest("BundleActiveEventReporterTest") {
366  module_out_path = module_output_path
367  cflags = [
368    "-Dprivate=public",
369    "-Dprotected=public",
370  ]
371
372  sources = [ "bundle_active_event_reporter_test.cpp" ]
373
374  configs = [ ":module_private_config" ]
375
376  deps = [
377    "../../:usagestatservice_static",
378    "../../:usagestatsinner",
379    "../../:usagestatsutils",
380  ]
381
382  external_deps = [
383    "ability_runtime:app_manager",
384    "ability_runtime:wantagent_innerkits",
385    "access_token:libaccesstoken_sdk",
386    "cJSON:cjson",
387    "ffrt:libffrt",
388    "hilog:libhilog",
389    "ipc:ipc_single",
390    "relational_store:native_rdb",
391    "safwk:system_ability_fwk",
392    "samgr:samgr_proxy",
393    "time_service:time_client",
394  ]
395  defines = []
396  if (device_usage_statistics_with_powermgr_power_manager_enable) {
397    defines += [ "DEVICE_USAGES_STATISTICS_POWERMANGER_ENABLE" ]
398    external_deps += [ "power_manager:powermgr_client" ]
399  }
400  if (os_account_part_enabled) {
401    external_deps += [ "os_account:os_account_innerkits" ]
402  }
403  if (bgtaskmgr_enable) {
404    external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ]
405    defines += [ "BGTASKMGR_ENABLE" ]
406  }
407  branch_protector_ret = "pac_ret"
408
409  sanitize = {
410    cfi = true
411    cfi_cross_dso = true
412    debug = false
413  }
414}
415
416group("unittest") {
417  testonly = true
418  deps = [
419    ":BundleActiveEventReporterTest",
420    ":BundleActiveTotalTest",
421    ":DeviceUsagePackageUsageTest",
422    ":DeviceUsageStatsMockTest",
423    ":DeviceUsageStatsMultiTest",
424    ":DeviceUsageStatsServiceTest",
425    ":DeviceUsageStatsTest",
426  ]
427}
428