1 /*
2 * Copyright (c) 2022-2023 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 <gtest/gtest.h>
17 #include <string>
18 #include <vector>
19 #include "iplugin.h"
20 #include "permission_manager.h"
21
22 using namespace testing::ext;
23
24 namespace OHOS {
25 namespace EDM {
26 namespace TEST {
27 class PermissionManagerTest : public testing::Test {
28 protected:
29 // Sets up the test fixture.
30 void SetUp() override;
31
32 // Tears down the test fixture.
33 void TearDown() override;
34 };
35
SetUp()36 void PermissionManagerTest::SetUp()
37 {
38 }
39
TearDown()40 void PermissionManagerTest::TearDown()
41 {
42 PermissionManager::DestroyInstance();
43 }
44
45 /**
46 * @tc.name: TestAddPermission
47 * @tc.desc: Test PermissionManager AddPermission func.
48 * @tc.type: FUNC
49 */
50 HWTEST_F(PermissionManagerTest, TestAddPermission, TestSize.Level1)
51 {
52 ASSERT_EQ(PermissionManager::GetInstance()->AddPermission(
53 std::string("ohos.permission.EDM_TEST_PERMISSION"), IPlugin::PermissionType::NORMAL_DEVICE_ADMIN),
54 ERR_OK);
55 }
56
57 /**
58 * @tc.name: GetReqPermission01
59 * @tc.desc: Test PermissionManager ReqPermission func.
60 * @tc.type: FUNC
61 */
62 HWTEST_F(PermissionManagerTest, GetReqPermission01, TestSize.Level1)
63 {
64 PermissionManager::GetInstance()->AddPermission(
65 std::string("ohos.permission.EDM_TEST_PERMISSION"), IPlugin::PermissionType::NORMAL_DEVICE_ADMIN);
66 std::vector<std::string> permission = {
67 "ohos.permission.EDM_TEST_PERMISSION", "ohos.permission.EMD_TEST_PERMISSION_FAIL" };
68 std::vector<AdminPermission> reqPermission;
69 PermissionManager::GetInstance()->GetReqPermission(permission, reqPermission);
70 ASSERT_TRUE(reqPermission.size() == 1);
71 }
72
73 /**
74 * @tc.name: GetReqPermission02
75 * @tc.desc: Test PermissionManager ReqPermission func.
76 * @tc.type: FUNC
77 */
78 HWTEST_F(PermissionManagerTest, GetReqPermission02, TestSize.Level1)
79 {
80 PermissionManager::GetInstance()->AddPermission(
81 std::string("ohos.permission.EDM_TEST_ENT_PERMISSION"), IPlugin::PermissionType::SUPER_DEVICE_ADMIN);
82 std::vector<std::string> permission = {
83 "ohos.permission.EDM_TEST_ENT_PERMISSION", "ohos.permission.EMD_TEST_PERMISSION_FAIL" };
84 std::vector<EdmPermission> reqPermission;
85 PermissionManager::GetInstance()->GetReqPermission(permission, reqPermission);
86 ASSERT_TRUE(reqPermission.size() == 1);
87 }
88 } // namespace TEST
89 } // namespace EDM
90 } // namespace OHOS
91