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