1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "unit_test.h"
17 #include <selinux/selinux.h>
18 #include "selinux_error.h"
19 #include "selinux_parameter.h"
20 #include "test_common.h"
21
22 using namespace testing::ext;
23 using namespace OHOS::Security::SelinuxUnitTest;
24 using namespace Selinux;
25 const static std::string DEFAULT_CONTEXT = "u:object_r:default_param:s0";
26 static const int INVALID_INDEX = -1;
27 const static std::string TEST_NOT_EXIST_PARA_NAME = "unittest.not.exist";
28
SetUpTestCase()29 void SelinuxUnitTest::SetUpTestCase()
30 {
31 int res = InitParamSelinux(0);
32 ASSERT_EQ(res, SELINUX_SUCC);
33 std::cout << "SetUpTestCase: InitParamSelinux" << std::endl;
34 }
35
TearDownTestCase()36 void SelinuxUnitTest::TearDownTestCase() {}
37
SetUp()38 void SelinuxUnitTest::SetUp() {}
39
TearDown()40 void SelinuxUnitTest::TearDown() {}
41
42 /**
43 * @tc.name: GetParamList001
44 * @tc.desc: GetParamList normal branch.
45 * @tc.type: FUNC
46 * @tc.require:AR000GJSDS
47 */
48 HWTEST_F(SelinuxUnitTest, GetParamList001, TestSize.Level1)
49 {
50 ParamContextsList *buff = nullptr;
51 buff = GetParamList();
52 ASSERT_NE(nullptr, buff);
53
54 DestroyParamList(nullptr);
55 DestroyParamList(&buff);
56 ASSERT_EQ(nullptr, buff);
57 }
58
59 /**
60 * @tc.name: GetParamLabel001
61 * @tc.desc: GetParamLabel input invalid.
62 * @tc.type: FUNC
63 * @tc.require:AR000GJSDS
64 */
65 HWTEST_F(SelinuxUnitTest, GetParamLabel001, TestSize.Level1)
66 {
67 ASSERT_EQ(DEFAULT_CONTEXT, GetParamLabel(nullptr));
68
69 ASSERT_EQ(DEFAULT_CONTEXT, GetParamLabel(TEST_NOT_EXIST_PARA_NAME.c_str()));
70 }
71
72 /**
73 * @tc.name: GetParamLabelIndex001
74 * @tc.desc: GetParamLabelIndex input invalid.
75 * @tc.type: FUNC
76 * @tc.require:AR000GJSDS
77 */
78 HWTEST_F(SelinuxUnitTest, GetParamLabelIndex001, TestSize.Level1)
79 {
80 ASSERT_EQ(INVALID_INDEX, GetParamLabelIndex(nullptr));
81 }
82