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