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
22namespace OHOS {
23namespace Security {
24namespace SelinuxUnitTest {
25using namespace testing::ext;
26using namespace Selinux;
27const static std::string DEFAULT_CONTEXT = "u:object_r:default_param:s0";
28static const int INVALID_INDEX = -1;
29const static std::string TEST_NOT_EXIST_PARA_NAME = "unittest.not.exist";
30
31void SelinuxUnitTest::SetUpTestCase()
32{
33    int res = InitParamSelinux(0);
34    ASSERT_EQ(res, SELINUX_SUCC);
35    std::cout << "SetUpTestCase: InitParamSelinux" << std::endl;
36}
37
38void SelinuxUnitTest::TearDownTestCase() {}
39
40void SelinuxUnitTest::SetUp() {}
41
42void SelinuxUnitTest::TearDown() {}
43
44/**
45 * @tc.name: GetParamList001
46 * @tc.desc: GetParamList normal branch.
47 * @tc.type: FUNC
48 * @tc.require:AR000GJSDS
49 */
50HWTEST_F(SelinuxUnitTest, GetParamList001, TestSize.Level1)
51{
52    ParamContextsList *buff = nullptr;
53    buff = GetParamList();
54    ASSERT_NE(nullptr, buff);
55
56    DestroyParamList(nullptr);
57    DestroyParamList(&buff);
58    ASSERT_EQ(nullptr, buff);
59}
60
61/**
62 * @tc.name: GetParamLabel001
63 * @tc.desc: GetParamLabel input invalid.
64 * @tc.type: FUNC
65 * @tc.require:AR000GJSDS
66 */
67HWTEST_F(SelinuxUnitTest, GetParamLabel001, TestSize.Level1)
68{
69    ASSERT_EQ(DEFAULT_CONTEXT, GetParamLabel(nullptr));
70
71    ASSERT_EQ(DEFAULT_CONTEXT, GetParamLabel(TEST_NOT_EXIST_PARA_NAME.c_str()));
72}
73
74/**
75 * @tc.name: GetParamLabelIndex001
76 * @tc.desc: GetParamLabelIndex input invalid.
77 * @tc.type: FUNC
78 * @tc.require:AR000GJSDS
79 */
80HWTEST_F(SelinuxUnitTest, GetParamLabelIndex001, TestSize.Level1)
81{
82    ASSERT_EQ(INVALID_INDEX, GetParamLabelIndex(nullptr));
83}
84} // namespace SelinuxUnitTest
85} // namespace Security
86} // namespace OHOS
87