• 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 "common_event_permission_manager.h"
17 
18 #include <algorithm>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 namespace {
24     bool g_mockGetEventPermissionRet = true;
25     OHOS::EventFwk::PermissionState g_mockPermissionState = OHOS::EventFwk::PermissionState::OR;
26     int32_t g_mockPermissionSize = 1;
27 }
28 
29 namespace OHOS {
30 namespace EventFwk {
MockGetEventPermission(bool mockRet,PermissionState mockState,int32_t permissionSize)31 void MockGetEventPermission(bool mockRet, PermissionState mockState, int32_t permissionSize)
32 {
33     g_mockGetEventPermissionRet = mockRet;
34     g_mockPermissionState = mockState;
35     g_mockPermissionSize = permissionSize;
36 }
37 
GetEventPermission(const std::string & event)38 Permission CommonEventPermissionManager::GetEventPermission(const std::string &event)
39 {
40     Permission per;
41     if (true == g_mockGetEventPermissionRet) {
42         for (int32_t i = 0; i < g_mockGetEventPermissionRet; i++) {
43             per.names.emplace_back("permision_" + std::to_string(i));
44         }
45         per.state = g_mockPermissionState;
46         return per;
47     }
48     return per;
49 }
50 }  // namespace EventFwk
51 }  // namespace OHOS
52