• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License") = 0;
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 #ifndef OHOS_DM_ACCESSTOKEN_KIT_MOCK_H
17 #define OHOS_DM_ACCESSTOKEN_KIT_MOCK_H
18 
19 #include <gmock/gmock.h>
20 
21 #include "accesstoken_kit.h"
22 #include "tokenid_kit.h"
23 
24 using OHOS::Security::AccessToken::ATokenTypeEnum;
25 using OHOS::Security::AccessToken::AccessTokenID;
26 using OHOS::Security::AccessToken::HapTokenInfo;
27 using OHOS::Security::AccessToken::NativeTokenInfo;
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 class DmAccessTokenKit {
32 public:
33     virtual ~DmAccessTokenKit() = default;
34 
35     virtual ATokenTypeEnum GetTokenTypeFlag(AccessTokenID) = 0;
36     virtual int GetHapTokenInfo(AccessTokenID, HapTokenInfo &) = 0;
37     virtual int GetNativeTokenInfo(AccessTokenID, NativeTokenInfo &) = 0;
38     virtual AccessTokenID GetNativeTokenId(const std::string &) = 0;
39     virtual AccessTokenID GetHapTokenID(int32_t, const std::string &, int32_t) = 0;
40     virtual int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) = 0;
41 public:
42     static inline std::shared_ptr<DmAccessTokenKit> accessToken_ = nullptr;
43 };
44 
45 class DmAccessTokenKitMock : public DmAccessTokenKit {
46 public:
47     MOCK_METHOD(ATokenTypeEnum, GetTokenTypeFlag, (AccessTokenID));
48     MOCK_METHOD(int, GetHapTokenInfo, (AccessTokenID, HapTokenInfo &));
49     MOCK_METHOD(int, GetNativeTokenInfo, (AccessTokenID, NativeTokenInfo &));
50     MOCK_METHOD(AccessTokenID, GetNativeTokenId, (const std::string &));
51     MOCK_METHOD(AccessTokenID, GetHapTokenID, (int32_t, const std::string &, int32_t));
52     MOCK_METHOD(int, VerifyAccessToken, (AccessTokenID, const std::string&));
53 };
54 } // namespace DistributedHardware
55 } // namespace OHOS
56 #endif // OHOS_DM_ACCESS_TOKEN_KIT_MOCK_H
57