1 /* 2 * Copyright (c) 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 #ifndef DFSU_ACCESS_TOKEN_HELPER_MOCK 17 #define DFSU_ACCESS_TOKEN_HELPER_MOCK 18 19 #include "dfsu_access_token_helper.h" 20 #include <gmock/gmock.h> 21 #include <string> 22 23 namespace OHOS::FileManagement::CloudSync { 24 25 class DfsuAccessToken { 26 public: 27 virtual bool CheckCallerPermission(const std::string &permissionName); 28 virtual int32_t GetCallerBundleName(std::string &bundleName); 29 virtual bool CheckPermission(uint32_t tokenId, const std::string &permissionName); 30 virtual bool CheckUriPermission(const std::string &uri); 31 virtual int32_t GetBundleNameByToken(uint32_t tokenId, std::string &bundleName); 32 virtual bool IsSystemApp(); 33 virtual int32_t GetUserId(); 34 virtual int32_t GetPid(); 35 36 public: 37 DfsuAccessToken() = default; 38 virtual ~DfsuAccessToken() = default; 39 static inline std::shared_ptr<DfsuAccessToken> dfsuAccessToken = nullptr; 40 }; 41 42 class DfsuAccessTokenMock : public DfsuAccessToken { 43 public: 44 MOCK_METHOD1(CheckCallerPermission, bool(const std::string &permissionName)); 45 MOCK_METHOD1(GetCallerBundleName, int32_t(std::string &bundleName)); 46 MOCK_METHOD2(CheckPermission, bool(uint32_t tokenId, const std::string &permissionName)); 47 MOCK_METHOD1(CheckUriPermission, bool(const std::string &uri)); 48 MOCK_METHOD2(GetBundleNameByToken, int32_t(uint32_t tokenId, std::string &bundleName)); 49 MOCK_METHOD0(IsSystemApp, bool()); 50 MOCK_METHOD0(GetUserId, int32_t()); 51 MOCK_METHOD0(GetPid, int32_t()); 52 }; 53 54 } // namespace OHOS::FileManagement::CloudSync 55 #endif