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("../selinux.gni")
16
17config("selinux_unittest_config") {
18  visibility = [ ":*" ]
19  include_dirs = [
20    "../interfaces/policycoreutils/include",
21    "unittest/common",
22  ]
23  cflags = [
24    "-D_GNU_SOURCE",
25    "-w",
26  ]
27}
28
29ohos_unittest("hap_restorecon_unittest") {
30  subsystem_name = "security"
31  part_name = "selinux_adapter"
32  module_out_path = part_name + "/" + part_name
33  public_configs = [ ":selinux_unittest_config" ]
34  sources = [
35    "../interfaces/policycoreutils/src/hap_restorecon.cpp",
36    "../interfaces/policycoreutils/src/sehap_contexts_trie.cpp",
37    "unittest/common/test_common.cpp",
38    "unittest/hap_restorecon/unit_test.cpp",
39  ]
40  deps = [
41    "../:libselinux_error_static",
42    "../:libselinux_hilog_static",
43  ]
44  cflags = [ "-DSELINUX_TEST" ]
45  external_deps = [
46    "c_utils:utils",
47    "googletest:gtest",
48    "hilog:libhilog",
49    "selinux:libselinux",
50  ]
51}
52
53ohos_unittest("paraperm_checker_unittest") {
54  subsystem_name = "security"
55  part_name = "selinux_adapter"
56  module_out_path = part_name + "/" + part_name
57  public_configs = [ ":selinux_unittest_config" ]
58  sources = [
59    "unittest/common/test_common.cpp",
60    "unittest/paraperm_checker/unit_test.cpp",
61  ]
62  external_deps = [
63    "c_utils:utils",
64    "googletest:gtest",
65    "selinux:libselinux",
66    "selinux_adapter:libparaperm_checker",
67  ]
68}
69
70ohos_unittest("service_checker_unittest") {
71  subsystem_name = "security"
72  part_name = "selinux_adapter"
73  module_out_path = part_name + "/" + part_name
74  public_configs = [ ":selinux_unittest_config" ]
75  sources = [
76    "unittest/common/test_common.cpp",
77    "unittest/service_checker/unit_test.cpp",
78  ]
79  external_deps = [
80    "c_utils:utils",
81    "googletest:gtest",
82    "selinux_adapter:libservice_checker",
83  ]
84}
85
86ohos_unittest("parameter_static_unittest") {
87  subsystem_name = "security"
88  part_name = "selinux_adapter"
89  module_out_path = part_name + "/" + part_name
90  public_configs = [ ":selinux_unittest_config" ]
91  sources = [
92    "../interfaces/policycoreutils/src/selinux_map.c",
93    "../interfaces/policycoreutils/src/selinux_share_mem.c",
94    "unittest/common/test_common.cpp",
95    "unittest/parameter_static/unit_test.cpp",
96  ]
97  external_deps = [
98    "c_utils:utils",
99    "googletest:gtest",
100    "selinux:libselinux",
101  ]
102}
103
104ohos_unittest("selinux_common_unittest") {
105  subsystem_name = "security"
106  part_name = "selinux_adapter"
107  module_out_path = part_name + "/" + part_name
108  public_configs = [ ":selinux_unittest_config" ]
109  sources = [
110    "unittest/common/test_common.cpp",
111    "unittest/selinux_common_test/unit_test.cpp",
112  ]
113  deps = [
114    "../:libselinux_hilog_static",
115    "../:libselinux_klog_static",
116  ]
117  external_deps = [
118    "googletest:gtest",
119    "hilog:libhilog",
120    "selinux:libselinux",
121  ]
122}
123
124group("unittest") {
125  testonly = true
126  deps = [
127    ":hap_restorecon_unittest",
128    ":parameter_static_unittest",
129    ":paraperm_checker_unittest",
130    ":selinux_common_unittest",
131    ":service_checker_unittest",
132  ]
133}
134